summaryrefslogtreecommitdiffstats
path: root/src/launch-appliance.c
Commit message (Collapse)AuthorAgeFilesLines
* launch: appliance: Handle non-\0 terminated buffer correctly.Richard W.M. Jones2012-11-241-1/+1
| | | | | | | | | | | | | | The read_all function is used as a callback for guestfs___cmd_set_stdout_callback (cmd, read_all, [str], CMD_STDOUT_FLAG_WHOLE_BUFFER); As noted in the documentation for CMD_STDOUT_FLAG_WHOLE_BUFFER, the buffer returned is not \0-terminated, and so using memdup will create an unterminated string, and therefore potentially a memory overrun when reading or searching the string. Use strndup instead so the final string is \0-terminated.
* appliance: Pass lpj=... on the appliance command line (thanks Marcelo Tosatti).Richard W.M. Jones2012-11-241-1/+1
| | | | | | | | | | | | | | | | | | | | | Try to get the host's loops_per_jiffy value and pass this on the command line to the guest. In theory this should avoid the appliance having to recalculate this value in a VM with TCG (which is generally error-prone). This should avoid timing issues. We only do this when we are certain that the guest will be TCG. Currently we only have enough information to do this from the libvirt attach-method. So mostly this will only affect people using Fedora in a VM. The host loops_per_jiffy value is not exported by the kernel. It is only printed by the kernel early during boot, so if boot messages have "scrolled off" the kernel ring buffer, it won't be available. Some operating systems save early kernel messages in /var/log/dmesg but (a) Fedora 18+ seem to have abandoned this file and (b) on Ubuntu this file is unreadable for spurious "security" reasons. I have submitted a patch to make lpj available through /proc/cpuinfo.
* launch: Refactor duplicate code which constructs the appliance command line.Richard W.M. Jones2012-11-231-34/+7
| | | | Move this into a common file.
* lib: Fix memory leak and simplify command code.Richard W.M. Jones2012-11-231-4/+3
| | | | | | | | | | | | | | | | | | | Fix the following memory leak found by valgrind: ==13629== 498 (112 direct, 386 indirect) bytes in 1 blocks are definitely lost in loss record 99 of 110 ==13629== at 0x4A06B2F: calloc (vg_replace_malloc.c:593) ==13629== by 0x4CA564E: guestfs_safe_calloc (alloc.c:71) ==13629== by 0x4CA9B02: guestfs___new_command (command.c:143) ==13629== by 0x4CA66E9: guestfs___build_appliance (appliance.c:690) ==13629== by 0x4CBD1B9: launch_libvirt (launch-libvirt.c:188) ==13629== by 0x402E7E: main (virt-filesystems.c:349) Also adjust the command code in several places to make it simpler. We can almost always call guestfs___cmd_close right after guestfs___cmd_run, avoiding any need to close the handle along error paths. Tested by running the test suite under valgrind.
* launch: appliance: Use command mini-library to parse output of qemu -help etc.Richard W.M. Jones2012-10-181-64/+48
|
* launch: Add add_drive 'label' option.Richard W.M. Jones2012-10-081-1/+5
| | | | | | | | | | | | | | | | | | | | | New API: list-disk-labels Allow the user to pass an optional disk label when adding a drive. This is passed through to qemu / libvirt using the disk serial field, and from there to the appliance which exposes it through udev, creating a special alias of the device /dev/disk/guestfs/<label>. Partitions are named /dev/disk/guestfs/<label><partnum>. virtio-blk and virtio-scsi limit the serial field to 20 bytes. We further limit the name to maximum 20 ASCII characters in [a-zA-Z]. list-devices and list-partitions are not changed: these calls still return raw block device names. However a new call, list-disk-labels, returns a hash table allowing callers to map between disk labels, and block device and partition names. This commit also includes a test.
* launch: Make g->drives into an array (was a linked list).Richard W.M. Jones2012-10-081-10/+10
| | | | Using an array simplifies the implementation of hotplugging.
* launch: Make the "launched failed" message more explanatory.Richard W.M. Jones2012-09-201-2/+2
| | | | | | | Since this is the most common error seen by people who have installation problems, buggy qemu, etc, and since no one reads the FAQ, describe in this error message what resources are available to debug launch problems.
* Fix multiple errors where jump skips variable initialization.Richard W.M. Jones2012-09-171-3/+3
| | | | | | | <file>: error: jump skips variable initialization [-Werror=jump-misses-init] This has only just appeared, possibly related to previous gnulib update. In any case, this is just code motion / cleanup.
* syntax: Remove PATH_MAX-sized buffers allocated on the stack.Richard W.M. Jones2012-09-151-2/+3
| | | | | | | | | | | | | | On Linux PATH_MAX is 4096, but on some platforms it can be much larger or even not defined (ie. unlimited). Therefore using a PATH_MAX-sized stack buffer is not a great idea for portable programs. This change removes use of PATH_MAX-sized stack-allocated buffers. This change only applies to the library and standalone programs. Inside the daemon, memory allocation is much more complicated so I have not changed those (yet). Found by 'make syntax-check'.
* shutdown: Add 'check_for_errors' hint along the shutdown path.Richard W.M. Jones2012-09-041-1/+1
| | | | | | | | This hint tells the backend whether anyone cares about errors when the appliance is shut down. Currently this only has any effect on the libvirt backend, where it controls whether or not we use the VIR_DOMAIN_DESTROY_GRACEFUL flag.
* proto: Don't set g->fd[] to /dev/null in direct mode, fixing virt-rescue ↵Richard W.M. Jones2012-09-041-13/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (RHBZ#853159). https://bugzilla.redhat.com/show_bug.cgi?id=853159 git bisect pointed to the following commit: commit ec8e3b6cad170d08ac18b580792dfb137eb171dc Author: Richard W.M. Jones <rjones@redhat.com> Date: Fri Jul 20 14:24:10 2012 +0100 launch: Abstract attach method operations. g->attach_ops points to a structure which contains the operations supported by each attach method backend (ie. appliance, unix, etc.). Since that commit was essentially just code motion, it wasn't clear why virt-rescue should be affected by it. In fact the reason is as follows: (1) In direct mode, we don't need g->fd[] (which would normally be connected to the stdin/stdout of qemu). So we opened them on /dev/null so they had some value. (2) accept_from_daemon / read_log_message_or_eof reads from g->fd[1]. Since this is connected to /dev/null, it always reads EOF. (3) This would cause child_cleanup to be called. This is completely unintentional: we don't want to cleanup the child at this point, even in direct mode. (4) Prior to the commit above, child_cleanup first waited for the process to exit (ie. waitpid). This happened to work, since we are effectively waiting for the user to exit virt-rescue. (5) After the commit above, the order of operations was changed so that we first killed qemu before waiting for it. This broke virt-rescue. The fix is to change direct mode so that it leaves g->fd[]'s as -1. The rest of the protocol code can deal with this situation -- it ignores the log fd instead of trying to read from it.
* Revert "appliance: Add '-drive detect-zero=on' flag if qemu supports it."Richard W.M. Jones2012-08-011-2/+1
| | | | This reverts commit fe2253088ff51b51e2586f27a9408a38655170e3.
* appliance: Add '-drive detect-zero=on' flag if qemu supports it.Richard W.M. Jones2012-07-261-1/+2
| | | | | | | NB: The patch to implement this feature in qemu is not upstream, and may never make it upstream. However this is so useful for virt-sparsify that I decided to add this to libguestfs while we see what qemu decides to do.
* lib: Use <sys/socket.h> and <sys/un.h> for sockaddr_unMasami HIRATA2012-07-241-0/+2
| | | | Signed-off-by: Masami HIRATA <msmhrt@gmail.com>
* launch: Make get-pid and max-disks APIs into virtual methods of the current ↵Richard W.M. Jones2012-07-231-12/+11
| | | | attach-method.
* tests: Move debug-drives testing API to launch.c and change the output.Richard W.M. Jones2012-07-231-21/+0
| | | | It should work with any attach-method.
* launch: Make 'drive_name' into a common function.Richard W.M. Jones2012-07-211-5/+4
| | | | This is just code motion.
* appliance: Push appliance building lock into guestfs___build_appliance.Richard W.M. Jones2012-07-211-14/+2
| | | | | | | | | Since we will be calling guestfs___build_appliance from the libvirt code in future, there's no point having two places where we have to acquire the lock. Push the lock down into this function instead. Because "glthread/lock.h" includes <errno.h> we have to add this header to the file too.
* launch: Abstract attach method operations.Richard W.M. Jones2012-07-201-42/+109
| | | | | | g->attach_ops points to a structure which contains the operations supported by each attach method backend (ie. appliance, unix, etc.).
* launch: Move the command line building code entirely into launch-appliance.c.Richard W.M. Jones2012-07-201-38/+18
| | | | | Although we still use the handle as convenient temporary storage.
* launch: Move guestfs_config API and build list of qemu parameters in handle.Richard W.M. Jones2012-07-201-32/+8
| | | | | | Move and rewrite guestfs_config so it accumulates a list of qemu parameters in the handle. These are added to the appliance at launch time (with attach method == unix:... you'll now get an error).
* launch: Move launch timing / messages code into launch.c.Richard W.M. Jones2012-07-201-72/+2
|
* launch: Remove some dead code from the appliance method.Richard W.M. Jones2012-07-191-42/+0
|
* lib: Split launch.c into separate files.Richard W.M. Jones2012-07-191-0/+1164
launch-appliance.c contains the code associated with the 'appliance' attach-method. Mostly. In fact there are a few APIs which don't fit so nicely: - config: deprecated API which fiddles with the qemu command line directly - max-disks: depends on the qemu implementation (virtio-scsi or not) - debug-drives: used for testing only launch-unix.c contains the code associated with 'unix:<path>'. launch.c is the common code for launching, along with a few other APIs such as guestfs_add_drive_opts. This commit also reduces the number of headers to just those which are required.