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