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