9424ec2b898b94a1f906ef0a7e86bade6083e78c
[libguestfs.git] / guestfs.pod
1 =encoding utf8
2
3 =head1 NAME
4
5 guestfs - Library for accessing and modifying virtual machine images
6
7 =head1 SYNOPSIS
8
9  #include <guestfs.h>
10
11  guestfs_h *handle = guestfs_create ();
12  guestfs_add_drive (handle, "guest.img");
13  guestfs_launch (handle);
14  guestfs_mount (handle, "/dev/sda1", "/");
15  guestfs_touch (handle, "/hello");
16  guestfs_sync (handle);
17  guestfs_close (handle);
18
19 =head1 DESCRIPTION
20
21 Libguestfs is a library for accessing and modifying guest disk images.
22 Amongst the things this is good for: making batch configuration
23 changes to guests, getting disk used/free statistics (see also:
24 virt-df), migrating between virtualization systems (see also:
25 virt-p2v), performing partial backups, performing partial guest
26 clones, cloning guests and changing registry/UUID/hostname info, and
27 much else besides.
28
29 Libguestfs uses Linux kernel and qemu code, and can access any type of
30 guest filesystem that Linux and qemu can, including but not limited
31 to: ext2/3/4, btrfs, FAT and NTFS, LVM, many different disk partition
32 schemes, qcow, qcow2, vmdk.
33
34 Libguestfs provides ways to enumerate guest storage (eg. partitions,
35 LVs, what filesystem is in each LV, etc.).  It can also run commands
36 in the context of the guest.  Also you can access filesystems over FTP.
37
38 Libguestfs is a library that can be linked with C and C++ management
39 programs (or management programs written in OCaml, Perl, Python, Ruby, Java
40 or Haskell).  You can also use it from shell scripts or the command line.
41
42 You don't need to be root to use libguestfs, although obviously you do
43 need enough permissions to access the disk images.
44
45 =head1 CONNECTION MANAGEMENT
46
47 If you are using the high-level API, then you should call the
48 functions in the following order:
49
50  guestfs_h *handle = guestfs_create ();
51
52  guestfs_add_drive (handle, "guest.img");
53  /* call guestfs_add_drive additional times if the guest has
54   * multiple disks
55   */
56
57  guestfs_launch (handle);
58
59  /* now you can examine what partitions, LVs etc are available
60   * you have to mount / at least
61   */
62  guestfs_mount (handle, "/dev/sda1", "/");
63
64  /* now you can perform actions on the guest disk image */
65  guestfs_touch (handle, "/hello");
66
67  /* you only need to call guestfs_sync if you have made
68   * changes to the guest image
69   */
70  guestfs_sync (handle);
71
72  guestfs_close (handle);
73
74 C<guestfs_launch> and all of the actions including C<guestfs_sync>
75 are blocking calls.
76
77 All functions that return integers, return C<-1> on error.  See
78 section L</ERROR HANDLING> below for how to handle errors.
79
80 =head2 guestfs_h *
81
82 C<guestfs_h> is the opaque type representing a connection handle.
83 Create a handle by calling C<guestfs_create>.  Call C<guestfs_close>
84 to free the handle and release all resources used.
85
86 For information on using multiple handles and threads, see the section
87 L</MULTIPLE HANDLES AND MULTIPLE THREADS> below.
88
89 =head2 guestfs_create
90
91  guestfs_h *guestfs_create (void);
92
93 Create a connection handle.
94
95 You have to call C<guestfs_add_drive> on the handle at least once.
96
97 This function returns a non-NULL pointer to a handle on success or
98 NULL on error.
99
100 After configuring the handle, you have to call C<guestfs_launch>.
101
102 You may also want to configure error handling for the handle.  See
103 L</ERROR HANDLING> section below.
104
105 =head2 guestfs_close
106
107  void guestfs_close (guestfs_h *handle);
108
109 This closes the connection handle and frees up all resources used.
110
111 =head1 ERROR HANDLING
112
113 The convention in all functions that return C<int> is that they return
114 C<-1> to indicate an error.  You can get additional information on
115 errors by calling C<guestfs_last_error> and/or by setting up an error
116 handler with C<guestfs_set_error_handler>.
117
118 The default error handler prints the information string to C<stderr>.
119
120 Out of memory errors are handled differently.  The default action is
121 to call L<abort(3)>.  If this is undesirable, then you can set a
122 handler using C<guestfs_set_out_of_memory_handler>.
123
124 =head2 guestfs_last_error
125
126  const char *guestfs_last_error (guestfs_h *handle);
127
128 This returns the last error message that happened on C<handle>.  If
129 there has not been an error since the handle was created, then this
130 returns C<NULL>.
131
132 The lifetime of the returned string is until the next error occurs, or
133 C<guestfs_close> is called.
134
135 The error string is not localized (ie. is always in English), because
136 this makes searching for error messages in search engines give the
137 largest number of results.
138
139 =head2 guestfs_set_error_handler
140
141  typedef void (*guestfs_error_handler_cb) (guestfs_h *handle,
142                                            void *data,
143                                            const char *msg);
144  void guestfs_set_error_handler (guestfs_h *handle,
145                                  guestfs_error_handler_cb cb,
146                                  void *data);
147
148 The callback C<cb> will be called if there is an error.  The
149 parameters passed to the callback are an opaque data pointer and the
150 error message string.
151
152 Note that the message string C<msg> is freed as soon as the callback
153 function returns, so if you want to stash it somewhere you must make
154 your own copy.
155
156 The default handler prints messages on C<stderr>.
157
158 If you set C<cb> to C<NULL> then I<no> handler is called.
159
160 =head2 guestfs_get_error_handler
161
162  guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *handle,
163                                                      void **data_rtn);
164
165 Returns the current error handler callback.
166
167 =head2 guestfs_set_out_of_memory_handler
168
169  typedef void (*guestfs_abort_cb) (void);
170  int guestfs_set_out_of_memory_handler (guestfs_h *handle,
171                                         guestfs_abort_cb);
172
173 The callback C<cb> will be called if there is an out of memory
174 situation.  I<Note this callback must not return>.
175
176 The default is to call L<abort(3)>.
177
178 You cannot set C<cb> to C<NULL>.  You can't ignore out of memory
179 situations.
180
181 =head2 guestfs_get_out_of_memory_handler
182
183  guestfs_abort_fn guestfs_get_out_of_memory_handler (guestfs_h *handle);
184
185 This returns the current out of memory handler.
186
187 =head1 PATH
188
189 Libguestfs needs a kernel and initrd.img, which it finds by looking
190 along an internal path.
191
192 By default it looks for these in the directory C<$libdir/guestfs>
193 (eg. C</usr/local/lib/guestfs> or C</usr/lib64/guestfs>).
194
195 Use C<guestfs_set_path> or set the environment variable
196 C<LIBGUESTFS_PATH> to change the directories that libguestfs will
197 search in.  The value is a colon-separated list of paths.  The current
198 directory is I<not> searched unless the path contains an empty element
199 or C<.>.  For example C<LIBGUESTFS_PATH=:/usr/lib/guestfs> would
200 search the current directory and then C</usr/lib/guestfs>.
201
202 =head1 API OVERVIEW
203
204 This section provides additional documentation for groups of API
205 calls, which may not be obvious from reading about the individual
206 calls below.
207
208 =head2 LVM2
209
210 Libguestfs provides access to a large part of the LVM2 API.  It won't
211 make much sense unless you familiarize yourself with the concepts of
212 physical volumes, volume groups and logical volumes.
213
214 This author strongly recommends reading the LVM HOWTO, online at
215 L<http://tldp.org/HOWTO/LVM-HOWTO/>.
216
217 =head2 PARTITIONING
218
219 In the common case where you want to create a single partition
220 covering the whole disk, you should use the C<guestfs_part_disk>
221 call:
222
223  const char *parttype = "mbr";
224  if (disk_is_larger_than_2TB)
225    parttype = "gpt";
226  guestfs_part_disk (g, "/dev/sda", parttype);
227
228 In general MBR partitions are both unnecessarily complicated and
229 depend on archaic details, namely the Cylinder-Head-Sector (CHS)
230 geometry of the disk.  C<guestfs_sfdiskM> can be used to
231 create more complex arrangements where the relative sizes are
232 expressed in megabytes instead of cylinders, which is a small win.
233 C<guestfs_sfdiskM> will choose the nearest cylinder to approximate the
234 requested size.  There's a lot of crazy stuff to do with IDE and
235 virtio disks having different, incompatible CHS geometries, that you
236 probably don't want to know about.
237
238 My advice: make a single partition to cover the whole disk, then use
239 LVM on top.
240
241 =head2 UPLOADING
242
243 For small, single files, use C<guestfs_write_file>.  In some versions
244 of libguestfs there was a bug which limited this call to text files
245 (not containing ASCII NUL characters).
246
247 To upload a single file, use C<guestfs_upload>.  This call has no
248 limits on file content or size (even files larger than 4 GB).
249
250 To upload multiple files, see C<guestfs_tar_in> and C<guestfs_tgz_in>.
251
252 However the fastest way to upload I<large numbers of arbitrary files>
253 is to turn them into a squashfs or CD ISO (see L<mksquashfs(8)> and
254 L<mkisofs(8)>), then attach this using C<guestfs_add_drive_ro>.  If
255 you add the drive in a predictable way (eg. adding it last after all
256 other drives) then you can get the device name from
257 C<guestfs_list_devices> and mount it directly using
258 C<guestfs_mount_ro>.  Note that squashfs images are sometimes
259 non-portable between kernel versions, and they don't support labels or
260 UUIDs.  If you want to pre-build an image or you need to mount it
261 using a label or UUID, use an ISO image instead.
262
263 =head2 DOWNLOADING
264
265 Use C<guestfs_cat> to download small, text only files.  This call
266 is limited to files which are less than 2 MB and which cannot contain
267 any ASCII NUL (C<\0>) characters.  However it has a very simple
268 to use API.
269
270 C<guestfs_read_file> can be used to read files which contain
271 arbitrary 8 bit data, since it returns a (pointer, size) pair.
272 However it is still limited to "small" files, less than 2 MB.
273
274 C<guestfs_download> can be used to download any file, with no
275 limits on content or size (even files larger than 4 GB).
276
277 To download multiple files, see C<guestfs_tar_out> and
278 C<guestfs_tgz_out>.
279
280 =head2 RUNNING COMMANDS
281
282 Although libguestfs is a primarily an API for manipulating files
283 inside guest images, we also provide some limited facilities for
284 running commands inside guests.
285
286 There are many limitations to this:
287
288 =over 4
289
290 =item *
291
292 The kernel version that the command runs under will be different
293 from what it expects.
294
295 =item *
296
297 If the command needs to communicate with daemons, then most likely
298 they won't be running.
299
300 =item *
301
302 The command will be running in limited memory.
303
304 =item *
305
306 Only supports Linux guests (not Windows, BSD, etc).
307
308 =item *
309
310 Architecture limitations (eg. won't work for a PPC guest on
311 an X86 host).
312
313 =item *
314
315 For SELinux guests, you may need to enable SELinux and load policy
316 first.  See L</SELINUX> in this manpage.
317
318 =back
319
320 The two main API calls to run commands are C<guestfs_command> and
321 C<guestfs_sh> (there are also variations).
322
323 The difference is that C<guestfs_sh> runs commands using the shell, so
324 any shell globs, redirections, etc will work.
325
326 =head2 LISTING FILES
327
328 C<guestfs_ll> is just designed for humans to read (mainly when using
329 the L<guestfish(1)>-equivalent command C<ll>).
330
331 C<guestfs_ls> is a quick way to get a list of files in a directory
332 from programs.
333
334 C<guestfs_readdir> is a programmatic way to get a list of files in a
335 directory, plus additional information about each one.
336
337 C<guestfs_find> can be used to recursively list files.
338
339 =head2 SELINUX
340
341 We support SELinux guests.  To ensure that labeling happens correctly
342 in SELinux guests, you need to enable SELinux and load the guest's
343 policy:
344
345 =over 4
346
347 =item 1.
348
349 Before launching, do:
350
351  guestfs_set_selinux (g, 1);
352
353 =item 2.
354
355 After mounting the guest's filesystem(s), load the policy.  This
356 is best done by running the L<load_policy(8)> command in the
357 guest itself:
358
359  guestfs_sh (g, "/usr/sbin/load_policy");
360
361 (Older versions of C<load_policy> require you to specify the
362 name of the policy file).
363
364 =item 3.
365
366 Optionally, set the security context for the API.  The correct
367 security context to use can only be known by inspecting the
368 guest.  As an example:
369
370  guestfs_setcon (g, "unconfined_u:unconfined_r:unconfined_t:s0");
371
372 =back
373
374 This will work for running commands and editing existing files.
375
376 When new files are created, you may need to label them explicitly,
377 for example by running the external command
378 C<restorecon pathname>.
379
380 =head1 HIGH-LEVEL API ACTIONS
381
382 =head2 ABI GUARANTEE
383
384 We guarantee the libguestfs ABI (binary interface), for public,
385 high-level actions as outlined in this section.  Although we will
386 deprecate some actions, for example if they get replaced by newer
387 calls, we will keep the old actions forever.  This allows you the
388 developer to program in confidence against libguestfs.
389
390 @ACTIONS@
391
392 =head1 STRUCTURES
393
394 @STRUCTS@
395
396 =head1 STATE MACHINE AND LOW-LEVEL EVENT API
397
398 Internally, libguestfs is implemented by running a virtual machine
399 using L<qemu(1)>.  QEmu runs as a child process of the main program,
400 and most of this discussion won't make sense unless you understand
401 that the complexity is dealing with the (asynchronous) actions of the
402 child process.
403
404                             child process
405   ___________________       _________________________
406  /                   \     /                         \
407  | main program      |     | qemu +-----------------+|
408  |                   |     |      | Linux kernel    ||
409  +-------------------+     |      +-----------------+|
410  | libguestfs     <-------------->| guestfsd        ||
411  |                   |     |      +-----------------+|
412  \___________________/     \_________________________/
413
414 The diagram above shows libguestfs communicating with the guestfsd
415 daemon running inside the qemu child process.  There are several
416 points of failure here: qemu can fail to start, the virtual machine
417 inside qemu can fail to boot, guestfsd can fail to start or not
418 establish communication, any component can start successfully but fail
419 asynchronously later, and so on.
420
421 =head2 STATE MACHINE
422
423 libguestfs uses a state machine to model the child process:
424
425                          |
426                     guestfs_create
427                          |
428                          |
429                      ____V_____
430                     /          \
431                     |  CONFIG  |
432                     \__________/
433                      ^ ^   ^  \
434                     /  |    \  \ guestfs_launch
435                    /   |    _\__V______
436                   /    |   /           \
437                  /     |   | LAUNCHING |
438                 /      |   \___________/
439                /       |       /
440               /        |  guestfs_launch
441              /         |     /
442     ______  /        __|____V
443    /      \ ------> /        \
444    | BUSY |         | READY  |
445    \______/ <------ \________/
446
447 The normal transitions are (1) CONFIG (when the handle is created, but
448 there is no child process), (2) LAUNCHING (when the child process is
449 booting up), (3) alternating between READY and BUSY as commands are
450 issued to, and carried out by, the child process.
451
452 The guest may be killed by C<guestfs_kill_subprocess>, or may die
453 asynchronously at any time (eg. due to some internal error), and that
454 causes the state to transition back to CONFIG.
455
456 Configuration commands for qemu such as C<guestfs_add_drive> can only
457 be issued when in the CONFIG state.
458
459 The high-level API offers two calls that go from CONFIG through
460 LAUNCHING to READY.  C<guestfs_launch> blocks until the child process
461 is READY to accept commands (or until some failure or timeout).
462 C<guestfs_launch> internally moves the state from CONFIG to LAUNCHING
463 while it is running.
464
465 High-level API actions such as C<guestfs_mount> can only be issued
466 when in the READY state.  These high-level API calls block waiting for
467 the command to be carried out (ie. the state to transition to BUSY and
468 then back to READY).  But using the low-level event API, you get
469 non-blocking versions.  (But you can still only carry out one
470 operation per handle at a time - that is a limitation of the
471 communications protocol we use).
472
473 Finally, the child process sends asynchronous messages back to the
474 main program, such as kernel log messages.  Mostly these are ignored
475 by the high-level API, but using the low-level event API you can
476 register to receive these messages.
477
478 =head2 SETTING CALLBACKS TO HANDLE EVENTS
479
480 The child process generates events in some situations.  Current events
481 include: receiving a log message, the child process exits.
482
483 Use the C<guestfs_set_*_callback> functions to set a callback for
484 different types of events.
485
486 Only I<one callback of each type> can be registered for each handle.
487 Calling C<guestfs_set_*_callback> again overwrites the previous
488 callback of that type.  Cancel all callbacks of this type by calling
489 this function with C<cb> set to C<NULL>.
490
491 =head2 guestfs_set_log_message_callback
492
493  typedef void (*guestfs_log_message_cb) (guestfs_h *g, void *opaque,
494                                          char *buf, int len);
495  void guestfs_set_log_message_callback (guestfs_h *handle,
496                                         guestfs_log_message_cb cb,
497                                         void *opaque);
498
499 The callback function C<cb> will be called whenever qemu or the guest
500 writes anything to the console.
501
502 Use this function to capture kernel messages and similar.
503
504 Normally there is no log message handler, and log messages are just
505 discarded.
506
507 =head2 guestfs_set_subprocess_quit_callback
508
509  typedef void (*guestfs_subprocess_quit_cb) (guestfs_h *g, void *opaque);
510  void guestfs_set_subprocess_quit_callback (guestfs_h *handle,
511                                             guestfs_subprocess_quit_cb cb,
512                                             void *opaque);
513
514 The callback function C<cb> will be called when the child process
515 quits, either asynchronously or if killed by
516 C<guestfs_kill_subprocess>.  (This corresponds to a transition from
517 any state to the CONFIG state).
518
519 =head2 guestfs_set_launch_done_callback
520
521  typedef void (*guestfs_launch_done_cb) (guestfs_h *g, void *opaque);
522  void guestfs_set_launch_done_callback (guestfs_h *handle,
523                                         guestfs_ready_cb cb,
524                                         void *opaque);
525
526 The callback function C<cb> will be called when the child process
527 becomes ready first time after it has been launched.  (This
528 corresponds to a transition from LAUNCHING to the READY state).
529
530 =head1 BLOCK DEVICE NAMING
531
532 In the kernel there is now quite a profusion of schemata for naming
533 block devices (in this context, by I<block device> I mean a physical
534 or virtual hard drive).  The original Linux IDE driver used names
535 starting with C</dev/hd*>.  SCSI devices have historically used a
536 different naming scheme, C</dev/sd*>.  When the Linux kernel I<libata>
537 driver became a popular replacement for the old IDE driver
538 (particularly for SATA devices) those devices also used the
539 C</dev/sd*> scheme.  Additionally we now have virtual machines with
540 paravirtualized drivers.  This has created several different naming
541 systems, such as C</dev/vd*> for virtio disks and C</dev/xvd*> for Xen
542 PV disks.
543
544 As discussed above, libguestfs uses a qemu appliance running an
545 embedded Linux kernel to access block devices.  We can run a variety
546 of appliances based on a variety of Linux kernels.
547
548 This causes a problem for libguestfs because many API calls use device
549 or partition names.  Working scripts and the recipe (example) scripts
550 that we make available over the internet could fail if the naming
551 scheme changes.
552
553 Therefore libguestfs defines C</dev/sd*> as the I<standard naming
554 scheme>.  Internally C</dev/sd*> names are translated, if necessary,
555 to other names as required.  For example, under RHEL 5 which uses the
556 C</dev/hd*> scheme, any device parameter C</dev/sda2> is translated to
557 C</dev/hda2> transparently.
558
559 Note that this I<only> applies to parameters.  The
560 C<guestfs_list_devices>, C<guestfs_list_partitions> and similar calls
561 return the true names of the devices and partitions as known to the
562 appliance.
563
564 =head2 ALGORITHM FOR BLOCK DEVICE NAME TRANSLATION
565
566 Usually this translation is transparent.  However in some (very rare)
567 cases you may need to know the exact algorithm.  Such cases include
568 where you use C<guestfs_config> to add a mixture of virtio and IDE
569 devices to the qemu-based appliance, so have a mixture of C</dev/sd*>
570 and C</dev/vd*> devices.
571
572 The algorithm is applied only to I<parameters> which are known to be
573 either device or partition names.  Return values from functions such
574 as C<guestfs_list_devices> are never changed.
575
576 =over 4
577
578 =item *
579
580 Is the string a parameter which is a device or partition name?
581
582 =item *
583
584 Does the string begin with C</dev/sd>?
585
586 =item *
587
588 Does the named device exist?  If so, we use that device.
589 However if I<not> then we continue with this algorithm.
590
591 =item *
592
593 Replace initial C</dev/sd> string with C</dev/hd>.
594
595 For example, change C</dev/sda2> to C</dev/hda2>.
596
597 If that named device exists, use it.  If not, continue.
598
599 =item *
600
601 Replace initial C</dev/sd> string with C</dev/vd>.
602
603 If that named device exists, use it.  If not, return an error.
604
605 =back
606
607 =head2 PORTABILITY CONCERNS
608
609 Although the standard naming scheme and automatic translation is
610 useful for simple programs and guestfish scripts, for larger programs
611 it is best not to rely on this mechanism.
612
613 Where possible for maximum future portability programs using
614 libguestfs should use these future-proof techniques:
615
616 =over 4
617
618 =item *
619
620 Use C<guestfs_list_devices> or C<guestfs_list_partitions> to list
621 actual device names, and then use those names directly.
622
623 Since those device names exist by definition, they will never be
624 translated.
625
626 =item *
627
628 Use higher level ways to identify filesystems, such as LVM names,
629 UUIDs and filesystem labels.
630
631 =back
632
633 =head1 INTERNALS
634
635 =head2 COMMUNICATION PROTOCOL
636
637 Don't rely on using this protocol directly.  This section documents
638 how it currently works, but it may change at any time.
639
640 The protocol used to talk between the library and the daemon running
641 inside the qemu virtual machine is a simple RPC mechanism built on top
642 of XDR (RFC 1014, RFC 1832, RFC 4506).
643
644 The detailed format of structures is in C<src/guestfs_protocol.x>
645 (note: this file is automatically generated).
646
647 There are two broad cases, ordinary functions that don't have any
648 C<FileIn> and C<FileOut> parameters, which are handled with very
649 simple request/reply messages.  Then there are functions that have any
650 C<FileIn> or C<FileOut> parameters, which use the same request and
651 reply messages, but they may also be followed by files sent using a
652 chunked encoding.
653
654 =head3 ORDINARY FUNCTIONS (NO FILEIN/FILEOUT PARAMS)
655
656 For ordinary functions, the request message is:
657
658  total length (header + arguments,
659       but not including the length word itself)
660  struct guestfs_message_header (encoded as XDR)
661  struct guestfs_<foo>_args (encoded as XDR)
662
663 The total length field allows the daemon to allocate a fixed size
664 buffer into which it slurps the rest of the message.  As a result, the
665 total length is limited to C<GUESTFS_MESSAGE_MAX> bytes (currently
666 4MB), which means the effective size of any request is limited to
667 somewhere under this size.
668
669 Note also that many functions don't take any arguments, in which case
670 the C<guestfs_I<foo>_args> is completely omitted.
671
672 The header contains the procedure number (C<guestfs_proc>) which is
673 how the receiver knows what type of args structure to expect, or none
674 at all.
675
676 The reply message for ordinary functions is:
677
678  total length (header + ret,
679       but not including the length word itself)
680  struct guestfs_message_header (encoded as XDR)
681  struct guestfs_<foo>_ret (encoded as XDR)
682
683 As above the C<guestfs_I<foo>_ret> structure may be completely omitted
684 for functions that return no formal return values.
685
686 As above the total length of the reply is limited to
687 C<GUESTFS_MESSAGE_MAX>.
688
689 In the case of an error, a flag is set in the header, and the reply
690 message is slightly changed:
691
692  total length (header + error,
693       but not including the length word itself)
694  struct guestfs_message_header (encoded as XDR)
695  struct guestfs_message_error (encoded as XDR)
696
697 The C<guestfs_message_error> structure contains the error message as a
698 string.
699
700 =head3 FUNCTIONS THAT HAVE FILEIN PARAMETERS
701
702 A C<FileIn> parameter indicates that we transfer a file I<into> the
703 guest.  The normal request message is sent (see above).  However this
704 is followed by a sequence of file chunks.
705
706  total length (header + arguments,
707       but not including the length word itself,
708       and not including the chunks)
709  struct guestfs_message_header (encoded as XDR)
710  struct guestfs_<foo>_args (encoded as XDR)
711  sequence of chunks for FileIn param #0
712  sequence of chunks for FileIn param #1 etc.
713
714 The "sequence of chunks" is:
715
716  length of chunk (not including length word itself)
717  struct guestfs_chunk (encoded as XDR)
718  length of chunk
719  struct guestfs_chunk (encoded as XDR)
720    ...
721  length of chunk
722  struct guestfs_chunk (with data.data_len == 0)
723
724 The final chunk has the C<data_len> field set to zero.  Additionally a
725 flag is set in the final chunk to indicate either successful
726 completion or early cancellation.
727
728 At time of writing there are no functions that have more than one
729 FileIn parameter.  However this is (theoretically) supported, by
730 sending the sequence of chunks for each FileIn parameter one after
731 another (from left to right).
732
733 Both the library (sender) I<and> the daemon (receiver) may cancel the
734 transfer.  The library does this by sending a chunk with a special
735 flag set to indicate cancellation.  When the daemon sees this, it
736 cancels the whole RPC, does I<not> send any reply, and goes back to
737 reading the next request.
738
739 The daemon may also cancel.  It does this by writing a special word
740 C<GUESTFS_CANCEL_FLAG> to the socket.  The library listens for this
741 during the transfer, and if it gets it, it will cancel the transfer
742 (it sends a cancel chunk).  The special word is chosen so that even if
743 cancellation happens right at the end of the transfer (after the
744 library has finished writing and has started listening for the reply),
745 the "spurious" cancel flag will not be confused with the reply
746 message.
747
748 This protocol allows the transfer of arbitrary sized files (no 32 bit
749 limit), and also files where the size is not known in advance
750 (eg. from pipes or sockets).  However the chunks are rather small
751 (C<GUESTFS_MAX_CHUNK_SIZE>), so that neither the library nor the
752 daemon need to keep much in memory.
753
754 =head3 FUNCTIONS THAT HAVE FILEOUT PARAMETERS
755
756 The protocol for FileOut parameters is exactly the same as for FileIn
757 parameters, but with the roles of daemon and library reversed.
758
759  total length (header + ret,
760       but not including the length word itself,
761       and not including the chunks)
762  struct guestfs_message_header (encoded as XDR)
763  struct guestfs_<foo>_ret (encoded as XDR)
764  sequence of chunks for FileOut param #0
765  sequence of chunks for FileOut param #1 etc.
766
767 =head3 INITIAL MESSAGE
768
769 Because the underlying channel (QEmu -net channel) doesn't have any
770 sort of connection control, when the daemon launches it sends an
771 initial word (C<GUESTFS_LAUNCH_FLAG>) which indicates that the guest
772 and daemon is alive.  This is what C<guestfs_launch> waits for.
773
774 =head1 QEMU WRAPPERS
775
776 If you want to compile your own qemu, run qemu from a non-standard
777 location, or pass extra arguments to qemu, then you can write a
778 shell-script wrapper around qemu.
779
780 There is one important rule to remember: you I<must C<exec qemu>> as
781 the last command in the shell script (so that qemu replaces the shell
782 and becomes the direct child of the libguestfs-using program).  If you
783 don't do this, then the qemu process won't be cleaned up correctly.
784
785 Here is an example of a wrapper, where I have built my own copy of
786 qemu from source:
787
788  #!/bin/sh -
789  qemudir=/home/rjones/d/qemu
790  exec $qemudir/x86_64-softmmu/qemu-system-x86_64 -L $qemudir/pc-bios "$@"
791
792 Save this script as C</tmp/qemu.wrapper> (or wherever), C<chmod +x>,
793 and then use it by setting the LIBGUESTFS_QEMU environment variable.
794 For example:
795
796  LIBGUESTFS_QEMU=/tmp/qemu.wrapper guestfish
797
798 Note that libguestfs also calls qemu with the -help and -version
799 options in order to determine features.
800
801 =head1 ENVIRONMENT VARIABLES
802
803 =over 4
804
805 =item LIBGUESTFS_APPEND
806
807 Pass additional options to the guest kernel.
808
809 =item LIBGUESTFS_DEBUG
810
811 Set C<LIBGUESTFS_DEBUG=1> to enable verbose messages.  This
812 has the same effect as calling C<guestfs_set_verbose (handle, 1)>.
813
814 =item LIBGUESTFS_MEMSIZE
815
816 Set the memory allocated to the qemu process, in megabytes.  For
817 example:
818
819  LIBGUESTFS_MEMSIZE=700
820
821 =item LIBGUESTFS_PATH
822
823 Set the path that libguestfs uses to search for kernel and initrd.img.
824 See the discussion of paths in section PATH above.
825
826 =item LIBGUESTFS_QEMU
827
828 Set the default qemu binary that libguestfs uses.  If not set, then
829 the qemu which was found at compile time by the configure script is
830 used.
831
832 See also L</QEMU WRAPPERS> above.
833
834 =item LIBGUESTFS_TRACE
835
836 Set C<LIBGUESTFS_TRACE=1> to enable command traces.  This
837 has the same effect as calling C<guestfs_set_trace (handle, 1)>.
838
839 =item TMPDIR
840
841 Location of temporary directory, defaults to C</tmp>.
842
843 If libguestfs was compiled to use the supermin appliance then each
844 handle will require rather a large amount of space in this directory
845 for short periods of time (~ 80 MB).  You can use C<$TMPDIR> to
846 configure another directory to use in case C</tmp> is not large
847 enough.
848
849 =back
850
851 =head1 SEE ALSO
852
853 L<guestfish(1)>,
854 L<qemu(1)>,
855 L<febootstrap(1)>,
856 L<http://libguestfs.org/>.
857
858 Tools with a similar purpose:
859 L<fdisk(8)>,
860 L<parted(8)>,
861 L<kpartx(8)>,
862 L<lvm(8)>,
863 L<disktype(1)>.
864
865 =head1 BUGS
866
867 To get a list of bugs against libguestfs use this link:
868
869 L<https://bugzilla.redhat.com/buglist.cgi?component=libguestfs&product=Virtualization+Tools>
870
871 To report a new bug against libguestfs use this link:
872
873 L<https://bugzilla.redhat.com/enter_bug.cgi?component=libguestfs&product=Virtualization+Tools>
874
875 When reporting a bug, please check:
876
877 =over 4
878
879 =item *
880
881 That the bug hasn't been reported already.
882
883 =item *
884
885 That you are testing a recent version.
886
887 =item *
888
889 Describe the bug accurately, and give a way to reproduce it.
890
891 =item *
892
893 Run libguestfs-test-tool and paste the B<complete, unedited>
894 output into the bug report.
895
896 =back
897
898 =head1 AUTHORS
899
900 Richard W.M. Jones (C<rjones at redhat dot com>)
901
902 =head1 COPYRIGHT
903
904 Copyright (C) 2009 Red Hat Inc.
905 L<http://libguestfs.org/>
906
907 This library is free software; you can redistribute it and/or
908 modify it under the terms of the GNU Lesser General Public
909 License as published by the Free Software Foundation; either
910 version 2 of the License, or (at your option) any later version.
911
912 This library is distributed in the hope that it will be useful,
913 but WITHOUT ANY WARRANTY; without even the implied warranty of
914 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
915 Lesser General Public License for more details.
916
917 You should have received a copy of the GNU Lesser General Public
918 License along with this library; if not, write to the Free Software
919 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA