X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=perl%2Flib%2FSys%2FGuestfs.pm;h=083a0172cc341b1ef0484340208e4b50008a8d44;hp=5aac2e91c9a78c9b2ce6198659278d7a2fc58fe0;hb=0884d8bbae6d76a603ec1385ada2938f88981c5c;hpb=15e0fd573a87488c66cb3a6f0da01f3ab5f2f6ed diff --git a/perl/lib/Sys/Guestfs.pm b/perl/lib/Sys/Guestfs.pm index 5aac2e9..083a017 100644 --- a/perl/lib/Sys/Guestfs.pm +++ b/perl/lib/Sys/Guestfs.pm @@ -97,6 +97,11 @@ This function adds a virtual CD-ROM disk image to the guest. This is equivalent to the qemu parameter C<-cdrom filename>. +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C<$h-Econfig> call instead. + =item $h->add_drive ($filename); This function adds a virtual machine disk image C to the @@ -110,7 +115,31 @@ for whatever operations you want to perform (ie. read access if you just want to read the image or write access if you want to modify the image). -This is equivalent to the qemu parameter C<-drive file=filename>. +This is equivalent to the qemu parameter C<-drive file=filename,cache=off>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C<$h-Econfig> call instead. + +=item $h->add_drive_ro ($filename); + +This adds a drive in snapshot mode, making it effectively +read-only. + +Note that writes to the device are allowed, and will be seen for +the duration of the guestfs handle, but they are written +to a temporary file which is discarded as soon as the guestfs +handle is closed. We don't currently have any method to enable +changes to be committed, although qemu can support this. + +This is equivalent to the qemu parameter +C<-drive file=filename,snapshot=on>. + +Note that this call checks for the existence of C. This +stops you from specifying other types of drive which are supported +by qemu such as C and C URLs. To specify those, use +the general C<$h-Econfig> call instead. =item $h->aug_close (); @@ -403,7 +432,16 @@ or compatible processor architecture). The single parameter is an argv-style list of arguments. The first element is the name of the program to run. Subsequent elements are parameters. The list must be -non-empty (ie. must contain a program name). +non-empty (ie. must contain a program name). Note that +the command runs directly, and is I invoked via +the shell (see C<$h-Esh>). + +The return value is anything printed to I by +the command. + +If the command returns a non-zero exit status, then +this function returns an error message. The error message +string is the content of I from the command. The C<$PATH> environment variable will contain at least C and C. If you require a program from @@ -416,11 +454,21 @@ correct places. It is the caller's responsibility to ensure all filesystems that are needed are mounted at the right locations. +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + =item @lines = $h->command_lines (\@arguments); This is the same as C<$h-Ecommand>, but splits the result into a list of lines. +See also: C<$h-Esh_lines> + +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + =item $h->config ($qemuparam, $qemuvalue); This can be used to add arbitrary qemu command line parameters @@ -452,6 +500,23 @@ There is no comprehensive help for this command. You have to look at the file C in the libguestfs source to find out what you can do. +=item $output = $h->df (); + +This command runs the C command to report disk space used. + +This command is mostly useful for interactive sessions. It +is I intended that you try to parse the output string. +Use C from programs. + +=item $output = $h->df_h (); + +This command runs the C command to report disk space used +in human-readable format. + +This command is mostly useful for interactive sessions. It +is I intended that you try to parse the output string. +Use C from programs. + =item $kmsgs = $h->dmesg (); This returns the kernel messages (C output) from @@ -484,6 +549,27 @@ Setting C to 3 should drop everything. This automatically calls L before the operation, so that the maximum guest memory is freed. +=item $sizekb = $h->du ($path); + +This command runs the C command to estimate file space +usage for C. + +C can be a file or a directory. If C is a directory +then the estimate includes the contents of the directory and all +subdirectories (recursively). + +The result is the estimated size in I +(ie. units of 1024 bytes). + +=item $h->e2fsck_f ($device); + +This runs C, ie. runs the ext2/ext3 +filesystem checker on C, noninteractively (C<-p>), +even if the filesystem appears to be clean (C<-f>). + +This command is only needed because of C<$h-Eresize2fs> +(q.v.). Normally you should use C<$h-Efsck>. + =item $h->end_busy (); This sets the state to C, or if in C then it leaves the @@ -516,6 +602,33 @@ The exact command which runs is C. Note in particular that the filename is not prepended to the output (the C<-b> option). +=item @names = $h->find ($directory); + +This command lists out all files and directories, recursively, +starting at C. It is essentially equivalent to +running the shell command C but some +post-processing happens on the output, described below. + +This returns a list of strings I. Thus +if the directory structure was: + + /tmp/a + /tmp/b + /tmp/c/d + +then the returned list from C<$h-Efind> C would be +4 elements: + + a + b + c + c/d + +If C is not a directory, then this command returns +an error. + +The returned list is sorted. + =item $status = $h->fsck ($fstype, $device); This runs the filesystem checker (fsck) on C which @@ -546,6 +659,13 @@ Checking or repairing NTFS volumes is not supported This command is entirely equivalent to running C. +=item $append = $h->get_append (); + +Return the additional kernel options which are added to the +guest kernel command line. + +If C then no options are added. + =item $autosync = $h->get_autosync (); Get the autosync flag. @@ -560,6 +680,18 @@ C. This returns the ext2/3/4 filesystem UUID of the filesystem on C. +=item $memsize = $h->get_memsize (); + +This gets the memory size in megabytes allocated to the +qemu subprocess. + +If C<$h-Eset_memsize> was not called +on this handle, and if C was not set, +then this returns the compiled-in default value for memsize. + +For more information on the architecture of libguestfs, +see L. + =item $path = $h->get_path (); Return the current search path. @@ -585,11 +717,47 @@ For more information on states, see L. This returns the verbose messages flag. +=item @paths = $h->glob_expand ($pattern); + +This command searches for all the pathnames matching +C according to the wildcard expansion rules +used by the shell. + +If no paths match, then this returns an empty list +(note: not an error). + +It is just a wrapper around the C L function +with flags C. +See that manual page for more details. + =item $h->grub_install ($root, $device); This command installs GRUB (the Grand Unified Bootloader) on C, with the root directory being C. +=item @lines = $h->head ($path); + +This command returns up to the first 10 lines of a file as +a list of strings. + +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + +=item @lines = $h->head_n ($nrlines, $path); + +If the parameter C is a positive number, this returns the first +C lines of the file C. + +If the parameter C is a negative number, this returns lines +from the file C, excluding the last C lines. + +If the parameter C is zero, this returns an empty list. + +Because of the message protocol, there is a transfer limit +of somewhere between 2MB and 4MB. To transfer large files you should use +FTP. + =item $dump = $h->hexdump ($path); This runs C on the given C. The result is @@ -599,6 +767,18 @@ Because of the message protocol, there is a transfer limit of somewhere between 2MB and 4MB. To transfer large files you should use FTP. +=item @filenames = $h->initrd_list ($path); + +This command lists out files contained in an initrd. + +The files are listed without any initial C character. The +files are listed in the order they appear (not necessarily +alphabetical). Directory names are listed as separate items. + +Old Linux kernels (2.4 and earlier) used a compressed ext2 +filesystem as initrd. We I support the newer initramfs +format (compressed cpio files). + =item $busy = $h->is_busy (); This returns true iff this handle is busy processing a command @@ -718,6 +898,12 @@ the path to the LV, such as C. You can also remove all LVs in a volume group by specifying the VG name, C. +=item $h->lvresize ($device, $mbytes); + +This resizes (expands or shrinks) an existing LVM logical +volume to C. When reducing, data in the reduced part +is lost. + =item @logvols = $h->lvs (); List all the logical volumes detected. This is the equivalent @@ -742,12 +928,73 @@ Create a directory named C. Create a directory named C, creating any parent directories as necessary. This is like the C shell command. +=item $dir = $h->mkdtemp ($template); + +This command creates a temporary directory. The +C