]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agosnapshot: use new API for less work
Eric Blake [Thu, 8 Sep 2011 12:16:57 +0000 (13:16 +0100)]
snapshot: use new API for less work

This has the added benefit of making 'snapshot-create dom --no-metadata'
now able to tell you the name of the just-generated snapshot.

* tools/virsh.c (vshSnapshotCreate, cmdSnapshotCurrent): Don't get
XML just for name.

13 years agosnapshot: new APIs for inspecting snapshot object
Eric Blake [Thu, 8 Sep 2011 11:19:25 +0000 (12:19 +0100)]
snapshot: new APIs for inspecting snapshot object

These functions access internals of the opaque object, and do
not need any rpc counterpart.  It could be argued that we should
have provided these when snapshot objects were first introduced,
since all the other vir*Ptr objects have at least a GetName accessor.

* include/libvirt/libvirt.h.in (virDomainSnapshotGetName)
(virDomainSnapshotGetDomain, virDomainSnapshotGetConnect): Declare.
* src/libvirt.c (virDomainSnapshotGetName)
(virDomainSnapshotGetDomain, virDomainSnapshotGetConnect): New
functions.
* src/libvirt_public.syms: Export them.

13 years agoDon't treat pci_system_init failure as fatal if no PCI bus is present
Soren Hansen [Mon, 5 Sep 2011 19:29:06 +0000 (21:29 +0200)]
Don't treat pci_system_init failure as fatal if no PCI bus is present

Xen PV domU's have no PCI bus. node_device_udev.c calls pci_system_init
which looks for /sys/bus/pci. If it does not find /sys/bus/pci (which it
won't in a Xen PV domU) it returns unsuccesfully (ENOENT), which libvirt
considers fatal. This makes libvirt unusable in this environment, even
though there are plenty of valid virtualisation options that work
there (LXC, UML, and QEmu spring to mind)

https://bugzilla.redhat.com/show_bug.cgi?id=709471

Signed-off-by: Soren Hansen <soren@linux2go.dk>
13 years agodoc: fix incorrect option in send-key
Alex Jia [Wed, 7 Sep 2011 16:53:46 +0000 (00:53 +0800)]
doc: fix incorrect option in send-key

* tools/virsh.pod: fix a option typo of send-key section.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agovirsh: fix typo in opts_send_key
Alex Jia [Thu, 8 Sep 2011 03:11:27 +0000 (11:11 +0800)]
virsh: fix typo in opts_send_key

* tools/virsh.c: millseconds should be milliseconds in opts_send_key.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agorpc: avoid memory leak on virNetTLSContextValidCertificate
Alex Jia [Sun, 4 Sep 2011 15:48:42 +0000 (23:48 +0800)]
rpc: avoid memory leak on virNetTLSContextValidCertificate

* src/rpc/virnettlscontext.c: fix memory leak on
  virNetTLSContextValidCertificate.

* Detected in valgrind run:

==25667==
==25667== 6,085 (44 direct, 6,041 indirect) bytes in 1 blocks are definitely
lost in loss record 326 of 351
==25667==    at 0x4005447: calloc (vg_replace_malloc.c:467)
==25667==    by 0x4F2791F3: _asn1_add_node_only (structure.c:53)
==25667==    by 0x4F27997A: _asn1_copy_structure3 (structure.c:421)
==25667==    by 0x4F276A50: _asn1_append_sequence_set (element.c:144)
==25667==    by 0x4F2743FF: asn1_der_decoding (decoding.c:1194)
==25667==    by 0x4F22B9CC: gnutls_x509_crt_import (x509.c:229)
==25667==    by 0x805274B: virNetTLSContextCheckCertificate
(virnettlscontext.c:1009)
==25667==    by 0x804DE32: testTLSSessionInit (virnettlscontexttest.c:693)
==25667==    by 0x804F14D: virtTestRun (testutils.c:140)
==25667==
==25667== 23,188 (88 direct, 23,100 indirect) bytes in 11 blocks are definitely
lost in loss record 346 of 351
==25667==    at 0x4005447: calloc (vg_replace_malloc.c:467)
==25667==    by 0x4F22B841: gnutls_x509_crt_init (x509.c:50)
==25667==    by 0x805272B: virNetTLSContextCheckCertificate
(virnettlscontext.c:1003)
==25667==    by 0x804DDD1: testTLSSessionInit (virnettlscontexttest.c:673)
==25667==    by 0x804F14D: virtTestRun (testutils.c:140)

* How to reproduce?
% cd libvirt && ./configure && make && make -C tests valgrind
or
% valgrind -v --leak-check=full ./tests/virnettlscontexttest

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agotests: avoid memory leak on testTLSSessionInit
Alex Jia [Sun, 4 Sep 2011 15:48:41 +0000 (23:48 +0800)]
tests: avoid memory leak on testTLSSessionInit

* tests/virnettlscontexttest: fix memory leak on virnettlscontext test case.

* Detected in valgrind run:

==25667==
==25667== 86,651 (34,680 direct, 51,971 indirect) bytes in 10 blocks are
definitely lost in loss record 350 of 351
==25667==    at 0x4005447: calloc (vg_replace_malloc.c:467)
==25667==    by 0x4F1F515D: gnutls_init (gnutls_state.c:270)
==25667==    by 0x8053432: virNetTLSSessionNew (virnettlscontext.c:1181)
==25667==    by 0x804DD24: testTLSSessionInit (virnettlscontexttest.c:624)
==25667==    by 0x804F14D: virtTestRun (testutils.c:140)
==25667==
==25667== 100,578 (38,148 direct, 62,430 indirect) bytes in 11 blocks are
definitely lost in loss record 351 of 351
==25667==    at 0x4005447: calloc (vg_replace_malloc.c:467)
==25667==    by 0x4F1F515D: gnutls_init (gnutls_state.c:270)
==25667==    by 0x8053432: virNetTLSSessionNew (virnettlscontext.c:1181)
==25667==    by 0x804DD3C: testTLSSessionInit (virnettlscontexttest.c:625)
==25667==    by 0x804F14D: virtTestRun (testutils.c:140)

* How to reproduce?
% cd libvirt && ./configure && make && make -C tests valgrind
or
% valgrind -v --leak-check=full ./tests/virnettlscontexttest

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agolibxl: avoid a dereference of a null pointer
Alex Jia [Sun, 4 Sep 2011 17:01:03 +0000 (01:01 +0800)]
libxl: avoid a dereference of a null pointer

Variable 'l_disk' initialized to a null pointer value, control jumps to 'case
VIR_DOMAIN_DISK_DEVICE_DISK and then taking false branch, Within the expansion
of the macro 'libxlError': Field access results in a dereference of a null
pointer (loaded from variable 'l_disk').

* src/libxl/libxl_driver.c: Field access results in a dereference of a null
  pointer (loaded from variable 'l_disk')

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoblockinfo: fix qemu regression in handling disk name
Eric Blake [Thu, 8 Sep 2011 09:10:14 +0000 (10:10 +0100)]
blockinfo: fix qemu regression in handling disk name

Regression introduced in commit 89b6284fd, due to an incorrect
conversion to the new means of converting disk names back to
the correct object.

* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Avoid NULL deref.

13 years agoesx: Fix managed object lookup with optional occurrence
Matthias Bolte [Tue, 6 Sep 2011 17:05:08 +0000 (19:05 +0200)]
esx: Fix managed object lookup with optional occurrence

Exit early if managed object is not found, instead of dereferencing
a NULL pointer and triggering a segfault.

13 years agoThreadpool: Initialize new dynamic workers
Michal Privoznik [Wed, 7 Sep 2011 12:08:14 +0000 (14:08 +0200)]
Threadpool: Initialize new dynamic workers

Although we were initializing worker threads during pool creating,
we missed this during virThreadPoolSendJob. This bug led to segmenation
fault as worker thread free() given argument.

13 years agomingw: Don't use interface as an identifier
Matthias Bolte [Tue, 6 Sep 2011 13:43:15 +0000 (15:43 +0200)]
mingw: Don't use interface as an identifier

Because it's a define used in MSCOM and its usage as
identifier results in a compile error.

13 years agolink-state: virsh: Add wrapper commands for changing link state
Peter Krempa [Tue, 6 Sep 2011 08:31:59 +0000 (16:31 +0800)]
link-state: virsh: Add wrapper commands for changing link state

Two new commands are added to virsh that wrap usage of
virDomainUpdateDeviceFlags for changing link state of domain's network
interfaces. These wrappers extract network devices's xml configuration
and modify the link state for easy manipulation from an user's perspective.

 - domif-setlink - set link state of a domains virtual network interface
 - domif-getlink - get link state

* tools/virsh.c   - Add functionality to virsh
* tools/virsh.pod - Manpage documentation

13 years agolink-state: qemu: Add net intf modification to virUpdateDeviceFlags
Peter Krempa [Tue, 6 Sep 2011 08:23:47 +0000 (16:23 +0800)]
link-state: qemu: Add net intf modification to virUpdateDeviceFlags

This patch enables modifying network device configuration using the
virUpdateDeviceFlags API method. Matching of devices is accomplished
using MAC addresses.

While updating live configuration of a running domain, the user is
allowed only to change link state of the interface. Additional
modifications may be added later. For now the code checks for
unsupported changes and thereafter changes the link state, if
applicable.

When updating persistent configuration of guest's network interface the
whole configuration (except for the MAC address) may be modified and
is stored for the next startup.

* src/qemu/qemu_driver.c   - Add dispatching of virUpdateDevice for
                             network devices update (live/config)
* src/qemu/qemu_hotplug.c  - add setting of initial link state on live
                             device addition
                           - add function to change network device
                             configuration. By now it supports only
                             changing of link state
* src/qemu/qemu_hotplug.h  - Headers to above functions
* src/qemu/qemu_process.c  - set link states before virtual machine
                             start. Qemu does not support setting of
                             this on the command line.

13 years agolink-state: qemu: Add monitor handling for link state modification
Peter Krempa [Tue, 6 Sep 2011 08:18:57 +0000 (16:18 +0800)]
link-state: qemu: Add monitor handling for link state modification

This patch adds handlers for modification of guest's interface
link state. Both HMP and QMP commands are supported, but as the
link state functionality is from the beginning supported in QMP
the HMP code will probably never be used.

13 years agolink-state: conf: Add element to XML for controling link state
Peter Krempa [Tue, 6 Sep 2011 08:08:15 +0000 (16:08 +0800)]
link-state: conf: Add element to XML for controling link state

A new element is introduced to XML that allows to control
state of virtual network interfaces in hypervisors.

Live modification of the link state allows networking tools
propagate topology changes to guest OS or testing of
scenarios in complex (virtual) networks.

This patch adds elements to XML grammars and parsing and generating
code.

13 years agolink-state: util: Add equality comparison functions for structures
Peter Krempa [Tue, 6 Sep 2011 08:05:53 +0000 (16:05 +0800)]
link-state: util: Add equality comparison functions for structures

This patch adds functions to compare structures containing network
device configuration for equality. They serve for the purpose of
disallowing unsupported changes to live network devices.

13 years agoXML: Improve XML parsing error messages
Peter Krempa [Tue, 6 Sep 2011 07:48:22 +0000 (15:48 +0800)]
XML: Improve XML parsing error messages

This patch modifies error handling function for the XML parser provided
by libxml2.

Originaly only a line number and error message were logged. With this
new error handler function, the user is provided with a more complex
description of the parsing error.

Context of the error is printed in libXML2 style and filename of the
file, that caused the error is printed. Example of an parse error:

13:41:36.262: 16032: error : catchXMLError:706 :
/etc/libvirt/qemu/rh_bad.xml:58: Opening and ending tag mismatch: name
line 2 and domain
</domain>
---------^

Context of the error gives the user hints that may help to quickly
locate a corrupt xml file.

fixes BZs:
----------
Bug 708735 - [RFE] Show column and line on XML parsing error
https://bugzilla.redhat.com/show_bug.cgi?id=708735

Bug 726771 - libvirt does not specify problem file if persistent xml is
invalid
https://bugzilla.redhat.com/show_bug.cgi?id=726771

13 years agoredirdev: allows to specify device address
Marc-André Lureau [Tue, 6 Sep 2011 07:06:59 +0000 (15:06 +0800)]
redirdev: allows to specify device address

It is important to be able to attach USB redirected devices to a
particular controller (one that supports USB2 for instance).
Without this patch, only the default bus was used.

     <redirdev bus='usb' type='spicevmc'>
       <address type='usb' bus='0' port='4'/>
     </redirdev>

13 years agolatency: fix make check for remote protocol structs and numbers
Daniel Veillard [Tue, 6 Sep 2011 07:11:44 +0000 (15:11 +0800)]
latency: fix make check for remote protocol structs and numbers

13 years agolatency: Update virsh command domblkstat to use new API
Osier Yang [Mon, 5 Sep 2011 08:24:51 +0000 (16:24 +0800)]
latency: Update virsh command domblkstat to use new API

The modified function fallbacks to use virDomainBlockStats if
virDomainBlockStatsFlags is not supported by the hypervisor driver.
If the new API is supported, it will be invoked instead of the
old API.

13 years agolatency: Expose the new API for Python binding
Osier Yang [Mon, 5 Sep 2011 08:24:21 +0000 (16:24 +0800)]
latency: Expose the new API for Python binding

13 years agolatency: Implemente internal API for qemu driver
Osier Yang [Mon, 5 Sep 2011 08:22:58 +0000 (16:22 +0800)]
latency: Implemente internal API for qemu driver

13 years agolatency: Update monitor functions for new latency fields
Osier Yang [Mon, 5 Sep 2011 08:22:17 +0000 (16:22 +0800)]
latency: Update monitor functions for new latency fields

The mainly changes are:

1) Update qemuMonitorGetBlockStatsInfo and it's children (Text/JSON)
   functions to return the value of new latency fields.
2) Add new function qemuMonitorGetBlockStatsParamsNumber, which is
   to count how many parameters the underlying QEMU supports.
3) Update virDomainBlockStats in src/qemu/qemu_driver.c to be
   compatible with the changes by 1).

13 years agolatency: Wire up the remote protocol
Osier Yang [Mon, 5 Sep 2011 08:20:03 +0000 (16:20 +0800)]
latency: Wire up the remote protocol

13 years agolatency: Implemente the public API
Osier Yang [Mon, 5 Sep 2011 08:16:03 +0000 (16:16 +0800)]
latency: Implemente the public API

13 years agolatency: Define the internal driver callback
Osier Yang [Mon, 5 Sep 2011 08:15:14 +0000 (16:15 +0800)]
latency: Define the internal driver callback

13 years agolatency: Define new public API and structure
Osier Yang [Mon, 5 Sep 2011 08:14:29 +0000 (16:14 +0800)]
latency: Define new public API and structure

13 years agoqemu: Deal with stucked qemu on daemon startup
Michal Privoznik [Tue, 16 Aug 2011 10:51:36 +0000 (12:51 +0200)]
qemu: Deal with stucked qemu on daemon startup

If libvirt daemon gets restarted and there is (at least) one
unresponsive qemu, the startup procedure hangs up. This patch creates
one thread per vm in which we try to reconnect to monitor. Therefore,
blocking in one thread will not affect other APIs.

13 years agoqemu: Introduce job queue size limit
Michal Privoznik [Fri, 12 Aug 2011 13:29:37 +0000 (15:29 +0200)]
qemu: Introduce job queue size limit

This patch creates an optional BeginJob queue size limit. When
active, all other attempts above level will fail. To set this
feature assign desired value to max_queued variable in qemu.conf.
Setting it to 0 turns it off.

13 years agodaemon: Create priority workers pool
Michal Privoznik [Fri, 12 Aug 2011 12:04:31 +0000 (14:04 +0200)]
daemon: Create priority workers pool

This patch annotates APIs with low or high priority.
In low set MUST be all APIs which might eventually access monitor
(and thus block indefinitely). Other APIs may be marked as high
priority. However, some must be (e.g. domainDestroy).

For high priority calls (HPC), there are some high priority workers
(HPW) created in the pool. HPW can execute only HPC, although normal
worker can process any call regardless priority. Therefore, only those
APIs which are guaranteed to end in reasonable small amount of time
can be marked as HPC.

The size of this HPC pool is static, because HPC are expected to end
quickly, therefore jobs assigned to this pool will be served quickly.
It can be configured in libvirtd.conf via prio_workers variable.
Default is set to 5.

To mark API with low or high priority, append priority:{low|high} to
it's comment in src/remote/remote_protocol.x. This is similar to
autogen|skipgen. If not marked, the generator assumes low as default.

13 years agosnapshot: use SELinux and lock manager with external snapshots
Eric Blake [Tue, 23 Aug 2011 23:14:55 +0000 (17:14 -0600)]
snapshot: use SELinux and lock manager with external snapshots

With this, it is now possible to create external snapshots even
when SELinux is enforcing, and to protect the new file with a
lock manager.

* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive): Create and register
new file with proper permissions and locks.
(qemuDomainSnapshotCreateDiskActive): Update caller.

13 years agosnapshot: wire up live qemu disk snapshots
Eric Blake [Sat, 20 Aug 2011 04:33:13 +0000 (22:33 -0600)]
snapshot: wire up live qemu disk snapshots

Lots of earlier patches led up to this point - the qemu snapshot_blkdev
monitor command can now be controlled by libvirt!  Well, insofar as
SELinux doesn't prevent qemu from open(O_CREAT) on the files.  There's
still some followup work before things work with SELinux enforcing,
but this patch is big enough to post now.

There's still room for other improvements, too (for example, taking a
disk snapshot of an inactive domain, by using qemu-img for both internal
and external snapshots; wiring up delete and revert control, including
additional flags from my RFC; supporting active QED disk snapshots;
supporting per-storage-volume snapshots such as LVM or btrfs snapshots;
etc.).  But this patch is the one that proves the new XML works!

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Wire in
active disk snapshots.
(qemuDomainSnapshotDiskPrepare)
(qemuDomainSnapshotCreateDiskActive)
(qemuDomainSnapshotCreateSingleDiskActive): New functions.

13 years agosnapshot: wire up new qemu monitor command
Eric Blake [Mon, 15 Aug 2011 23:25:54 +0000 (17:25 -0600)]
snapshot: wire up new qemu monitor command

No one uses this yet, but it will be important once
virDomainSnapshotCreateXML learns a VIR_DOMAIN_SNAPSHOT_DISK_ONLY
flag, and the xml allows passing in the new file names.

* src/qemu/qemu_monitor.h (qemuMonitorDiskSnapshot): New prototype.
* src/qemu/qemu_monitor_text.h (qemuMonitorTextDiskSnapshot):
Likewise.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDiskSnapshot):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorDiskSnapshot): New
function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskSnapshot):
Likewise.

13 years agosnapshot: make it possible to audit external snapshot
Eric Blake [Mon, 22 Aug 2011 19:49:10 +0000 (13:49 -0600)]
snapshot: make it possible to audit external snapshot

Snapshots alter the set of disk image files opened by qemu, so
they must be audited.  But they don't involve a full disk definition
structure, just the new filename.  Make the next patch easier by
refactoring the audit routines to just operate on file name.

* src/conf/domain_audit.h (virDomainAuditDisk): Update prototype.
* src/conf/domain_audit.c (virDomainAuditDisk): Act on strings,
not definition structures.
(virDomainAuditStart): Update caller.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainAttachPciDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUsbMassstorageDevice)
(qemuDomainDetachPciDiskDevice, qemuDomainDetachDiskDevice):
Likewise.

13 years agosnapshot: reject unimplemented disk snapshot features
Eric Blake [Mon, 22 Aug 2011 20:26:52 +0000 (14:26 -0600)]
snapshot: reject unimplemented disk snapshot features

My RFC for snapshot support [1] proposes several rules for when it is
safe to delete or revert to an external snapshot, predicated on
the existence of new API flags.  These will be incrementally added
in future patches, but until then, blindly mishandling a disk
snapshot risks corrupting internal state, so it is better to
outright reject the attempts until the other pieces are in place,
thus incrementally relaxing the restrictions added in this patch.

[1] https://www.redhat.com/archives/libvir-list/2011-August/msg00361.html

* src/qemu/qemu_driver.c (qemuDomainSnapshotCountExternal): New
function.
(qemuDomainUndefineFlags, qemuDomainSnapshotDelete): Use it to add
safety valve.
(qemuDomainRevertToSnapshot, qemuDomainSnapshotCreateXML): Add safety
valve.

13 years agosnapshot: wire up disk-only flag to snapshot-create
Eric Blake [Mon, 22 Aug 2011 23:12:56 +0000 (17:12 -0600)]
snapshot: wire up disk-only flag to snapshot-create

Expose the disk-only flag through virsh.  Additionally, make
virsh snapshot-create-as take an arbitrary number of diskspecs,
which can be used to build up the xml for <domainsnapshot>.

* tools/virsh.c (cmdSnapshotCreate): Add --disk-only.
(cmdSnapshotCreateAs): Likewise, and add argv diskspec.
(vshParseSnapshotDiskspec): New helper function.
(vshCmddefGetOption): Allow naming of argv field.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
them.
* tests/virsh-optparse: Test snapshot-create-as parsing.

13 years agosnapshot: add flag for requesting disk snapshot
Eric Blake [Sat, 20 Aug 2011 04:03:38 +0000 (22:03 -0600)]
snapshot: add flag for requesting disk snapshot

Prior to this patch, <domainsnapshot>/<disks> was ignored.  This
changes it to be an error unless an explicit disk snapshot is
requested (a future patch may relax things if it turns out to
be useful to have a <disks> specification alongside a system
checkpoint).

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY): New flag.
* src/libvirt.c (virDomainSnapshotCreateXML): Document it.
* src/esx/esx_driver.c (esxDomainSnapshotCreateXML): Disk
snapshots not supported yet.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Likewise.

13 years agosnapshot: add virsh domblklist command
Eric Blake [Sat, 20 Aug 2011 13:04:24 +0000 (07:04 -0600)]
snapshot: add virsh domblklist command

This adds a convenience function to virsh that parses out block
information from the domain xml, making it much easier to see
what strings can be used in all other contexts that demand a
specific block name, especially when given the previous patch
that allows using either target or unique source name.

As an example on a domain with one disk and an empty cdrom drive:

Target     Source
-------------------------------------------
vda        /var/lib/libvirt/images/fedora_12.img
hdc        -

* tools/virsh.c (cmdDomblklist): New function.
* tools/virsh.pod (domblklist): Document it.

13 years agosnapshot: also support disks by path
Eric Blake [Sat, 20 Aug 2011 02:38:36 +0000 (20:38 -0600)]
snapshot: also support disks by path

I got confused when 'virsh domblkinfo dom disk' required the
path to a disk (which can be ambiguous, since a single file
can back multiple disks), rather than the unambiguous target
device name that I was using in disk snapshots.  So, in true
developer fashion, I went for the best of both worlds - all
interfaces that operate on a disk (aka block) now accept
either the target name or the unambiguous path to the backing
file used by the disk.

* src/conf/domain_conf.h (virDomainDiskIndexByName): Add
parameter.
(virDomainDiskPathByName): New prototype.
* src/libvirt_private.syms (domain_conf.h): Export it.
* src/conf/domain_conf.c (virDomainDiskIndexByName): Also allow
searching by path, and decide whether ambiguity is okay.
(virDomainDiskPathByName): New function.
(virDomainDiskRemoveByName, virDomainSnapshotAlignDisks): Update
callers.
* src/qemu/qemu_driver.c (qemudDomainBlockPeek)
(qemuDomainAttachDeviceConfig, qemuDomainUpdateDeviceConfig)
(qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.
* src/qemu/qemu_process.c (qemuProcessFindDomainDiskByPath):
Likewise.
* src/libxl/libxl_driver.c (libxlDomainAttachDeviceDiskLive)
(libxlDomainDetachDeviceDiskLive, libxlDomainAttachDeviceConfig)
(libxlDomainUpdateDeviceConfig): Likewise.
* src/uml/uml_driver.c (umlDomainBlockPeek): Likewise.
* src/xen/xend_internal.c (xenDaemonDomainBlockPeek): Likewise.
* docs/formatsnapshot.html.in: Update documentation.
* tools/virsh.pod (domblkstat, domblkinfo): Likewise.
* docs/schemas/domaincommon.rng (diskTarget): Tighten pattern on
disk targets.
* docs/schemas/domainsnapshot.rng (disksnapshot): Update to match.
* tests/domainsnapshotxml2xmlin/disk_snapshot.xml: Update test.

13 years agosnapshot: add <disks> to snapshot xml
Eric Blake [Thu, 18 Aug 2011 23:33:36 +0000 (17:33 -0600)]
snapshot: add <disks> to snapshot xml

Adds an optional element to <domainsnapshot>, which will be used
to give user control over external snapshot filenames on input,
and specify generated filenames on output.

For now, no driver accepts this element; that will come later.

<domainsnapshot>
  ...
  <disks>
    <disk name='vda' snapshot='no'/>
    <disk name='vdb' snapshot='internal'/>
    <disk name='vdc' snapshot='external'>
      <driver type='qcow2'/>
      <source file='/path/to/new'/>
    </disk>
  </disks>
  <domain>
    ...
    <devices>
      <disk ...>
        <driver name='qemu' type='raw'/>
        <target dev='vdc'/>
        <source file='/path/to/old'/>
      </disk>
    </devices>
  </domain>
</domainsnapshot>

* src/conf/domain_conf.h (_virDomainSnapshotDiskDef): New type.
(_virDomainSnapshotDef): Add new elements.
(virDomainSnapshotAlignDisks): New prototype.
* src/conf/domain_conf.c (virDomainSnapshotDiskDefClear)
(virDomainSnapshotDiskDefParseXML, disksorter)
(virDomainSnapshotAlignDisks): New functions.
(virDomainSnapshotDefParseString): Parse new fields.
(virDomainSnapshotDefFree): Clean them up.
(virDomainSnapshotDefFormat): Output them.
* src/libvirt_private.syms (domain_conf.h): Export new function.
* docs/schemas/domainsnapshot.rng (domainsnapshot, disksnapshot):
Add more xml.
* docs/formatsnapshot.html.in: Document it.
* tests/domainsnapshotxml2xmlin/disk_snapshot.xml: New test.
* tests/domainsnapshotxml2xmlout/disk_snapshot.xml: Update.

13 years agosnapshot: support extra state in snapshots
Eric Blake [Fri, 19 Aug 2011 00:14:40 +0000 (18:14 -0600)]
snapshot: support extra state in snapshots

In order to distinguish disk snapshots from system checkpoints, a
new state value that is only valid for snapshots is helpful.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_LAST): New placeholder.
* src/conf/domain_conf.h (virDomainSnapshotState): New enum mapping.
(VIR_DOMAIN_DISK_SNAPSHOT): New internal enum value.
* src/conf/domain_conf.c (virDomainState): Use placeholder.
(virDomainSnapshotState): Extend mapping by one for use in snapshot.
(virDomainSnapshotDefParseString, virDomainSnapshotDefFormat):
Handle new state.
(virDomainObjSetState, virDomainStateReasonToString)
(virDomainStateReasonFromString): Avoid compiler warnings.
* tools/virsh.c (vshDomainState, vshDomainStateReasonToString):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Export new functions.
* docs/schemas/domainsnapshot.rng: Tighten state definition.
* docs/formatsnapshot.html.in: Document it.
* tests/domainsnapshotxml2xmlout/disk_snapshot.xml: New test.

13 years agosnapshot: expose halt-after-creation in virsh
Eric Blake [Thu, 18 Aug 2011 14:37:26 +0000 (08:37 -0600)]
snapshot: expose halt-after-creation in virsh

Easy enough to emulate even with older servers.

* tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Add
--halt flag.
(vshSnapshotCreate): Emulate halt when flag is unsupported.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
it.

13 years agosnapshot: allow halting after snapshot
Eric Blake [Thu, 1 Sep 2011 23:23:29 +0000 (17:23 -0600)]
snapshot: allow halting after snapshot

Since a snapshot is fully recoverable, it is useful to have a
snapshot as a means of hibernating a guest, then reverting to
the snapshot to wake the guest up.  This mode of usage is
similar to 'virsh save/virsh restore', except that virsh
save uses an external file while virsh snapshot keeps the
vm state internal to a qcow2 file.  However, it only works on
persistent domains.

In the usage pattern of snapshot/revert for hibernating a guest,
there is no need to keep the guest running between the two points
in time, especially since that would generate runtime state that
would just be discarded.  Add a flag to make it possible to
stop the domain after the snapshot has completed.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_CREATE_HALT):
New flag.
* src/libvirt.c (virDomainSnapshotCreateXML): Document it.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML)
(qemuDomainSnapshotCreateActive): Implement it.

13 years agosnapshot: expose new delete flag in virsh
Eric Blake [Tue, 16 Aug 2011 22:48:04 +0000 (16:48 -0600)]
snapshot: expose new delete flag in virsh

It would technically be possible to have virsh compute the list
of descendants of a given snapshot, then delete those one at
a time.  But it's complex, and not worth writing for a first
cut at implementing the new flags.

* tools/virsh.c (cmdSnapshotDelete): Add --children-only,
--metadata.
* tools/virsh.pod (snapshot-delete): Document them.

13 years agosnapshot: introduce new deletion flag
Eric Blake [Tue, 16 Aug 2011 22:23:45 +0000 (16:23 -0600)]
snapshot: introduce new deletion flag

Reverting to a state prior to an external snapshot risks
corrupting any other branches in the snapshot hierarchy that
were using the snapshot as a read-only backing file.  So
disk snapshot code will default to preventing reverting to
a snapshot that has any children, meaning that deleting just
the children of a snapshot becomes a useful operation in
preparing that snapshot for being a future reversion target.
The code for the new flag is simple - it's one less deletion,
plus a tweak to keep the current snapshot correct.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY): New flag.
* src/libvirt.c (virDomainSnapshotDelete): Document it, and
enforce mutual exclusion.
* src/qemu/qemu_driver.c (qemuDomainSnapshotDelete): Implement
it.

13 years agosnapshot: reject transient disks where code is not ready
Eric Blake [Sat, 13 Aug 2011 21:42:48 +0000 (15:42 -0600)]
snapshot: reject transient disks where code is not ready

The previous patch introduced new config, but if a hypervisor does
not support that new config, someone can write XML that does not
behave as documented.  This prevents some of those cases by
explicitly rejecting transient disks for several hypervisors.

Disk snapshots will require a new flag to actually affect a snapshot
creation, so there's not much to reject there.

* src/qemu/qemu_command.c (qemuBuildDriveStr): Reject transient
disks for now.
* src/libxl/libxl_conf.c (libxlMakeDisk): Likewise.
* src/xenxs/xen_sxpr.c (xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenFormatXMDisk): Likewise.

13 years agosnapshot: additions to domain xml for disks
Eric Blake [Sat, 13 Aug 2011 19:20:21 +0000 (13:20 -0600)]
snapshot: additions to domain xml for disks

As discussed here:
https://www.redhat.com/archives/libvir-list/2011-August/msg00361.html
https://www.redhat.com/archives/libvir-list/2011-August/msg00552.html

Adds snapshot attribute and transient sub-element:

<devices>
  <disk type=... snapshot='no|internal|external'>
    ...
    <transient/>
  </disk>
</devices>

* docs/schemas/domaincommon.rng (snapshot): New define.
(disk): Add snapshot and persistent attributes.
* docs/formatdomain.html.in: Document them.
* src/conf/domain_conf.h (virDomainDiskSnapshot): New enum.
(_virDomainDiskDef): New fields.
* tests/qemuxml2argvdata/qemuxml2argv-disk-transient.xml: New
test of rng, no args counterpart until qemu support is complete.
* tests/qemuxml2argvdata/qemuxml2argv-disk-snapshot.args: New
file, snapshot attribute does not affect args.
* tests/qemuxml2argvdata/qemuxml2argv-disk-snapshot.xml: Likewise.
* tests/qemuxml2argvtest.c (mymain): Run new test.

13 years agoCheck for source conflicts in storage pools
Lei Li [Mon, 5 Sep 2011 07:52:03 +0000 (15:52 +0800)]
Check for source conflicts in storage pools

Fix bug #611823 storage driver should prohibit pools with duplicate
underlying storage.

Add internal API virStoragePoolSourceFindDuplicate() to do uniqueness
check based on source location infomation for pool type.

* AUTHORS: add Lei Li

13 years agoAdd a usb1 & usb2 qemuxml2argv test
Marc-André Lureau [Mon, 5 Sep 2011 07:07:01 +0000 (15:07 +0800)]
Add a usb1 & usb2 qemuxml2argv test

13 years agoDefault USB device is on slot 1 function 2
Marc-André Lureau [Mon, 5 Sep 2011 07:03:27 +0000 (15:03 +0800)]
Default USB device is on slot 1 function 2

Fix qemuAssignDevicePCISlots() and the associated regression tests

13 years agoPIIX3 USB controller is on function 2
Marc-André Lureau [Mon, 5 Sep 2011 06:48:56 +0000 (14:48 +0800)]
PIIX3 USB controller is on function 2

Current code reserves slot 1 function 2 even if there is a user
defined PIIX3 USB controller there.

13 years agoFix localtime handling for Xen-PV domains
Philipp Hahn [Mon, 5 Sep 2011 06:22:36 +0000 (14:22 +0800)]
Fix localtime handling for Xen-PV domains

At least Xen-3.4.3 translates the /vm/localtime SXPR value to
/domain/platform/localtime and /domain/image/{linux,hvm}/localtime when
the domain is defined.  When reading back that information libvirt only
handles HVM domains, but not PV domains: This results in libvirtd always
returning
    <clock offset="utc"/>
while Xend used (localtime 1).

For PV domains use /domain/image/linux/localtime.

13 years agosnapshot: store qemu domain details in xml
Eric Blake [Sat, 13 Aug 2011 03:20:04 +0000 (21:20 -0600)]
snapshot: store qemu domain details in xml

When reverting to a snapshot, the inactive domain configuration
has to be rolled back to what it was at the time of the snapshot.
Additionally, if the VM is active and the snapshot was active,
this now adds a failure if the two configurations are ABI
incompatible, rather than risking qemu confusion.

A future patch will add a VIR_DOMAIN_SNAPSHOT_FORCE flag, which
will be required for two risky code paths - reverting to an
older snapshot that lacked full domain information, and reverting
from running to a live snapshot that requires starting a new qemu
process.  Any reverting that stops a running vm is also a form
of data loss (discarding the current running state to go back in
time), but as that is what reversion usually implies, it is
probably not worth requiring a force flag.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Copy out
domain.
(qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot): Perform
ABI compatibility checks.

13 years agosnapshot: update rng to support full domain in xml
Eric Blake [Sat, 13 Aug 2011 01:33:15 +0000 (19:33 -0600)]
snapshot: update rng to support full domain in xml

This patch will probably cause merge conflicts to those trying
to do backports.  The end goal is simple - domaincommon.rng
should be the state of domain.rng pre-patch, with a few lines
tweaked in the header, while domain.rng post-patch is now just
a shell that includes domaincommon.rng and sets the <start>.

* docs/schemas/domain.rng: Move guts...
* docs/schemas/domaincommon.rng: ...to new file.
* docs/schemas/domainsnapshot.rng: Allow new xml.
* docs/schemas/Makefile.am (schema_DATA): Distribute new file.
* tests/domainsnapshotxml2xmlout/full_domain.xml: New test.
* libvirt.spec.in (%files client): Ship new file.  Sort lines.
* mingw32-libvirt.spec.in: Likewise.

13 years agosnapshot: correctly escape generated xml
Eric Blake [Fri, 19 Aug 2011 16:56:57 +0000 (10:56 -0600)]
snapshot: correctly escape generated xml

Commit 69278878 fixed one direction of arbitrarily-named snapshots,
but not the round trip path.  While auditing domain_conf, I found
a couple other instances that weren't escaping arbitrary strings.

* src/conf/domain_conf.c (virDomainFSDefFormat)
(virDomainGraphicsListenDefFormat, virDomainSnapshotDefFormat):
Escape arbitrary strings.

13 years agosnapshot: allow full domain xml in snapshot
Eric Blake [Sat, 13 Aug 2011 01:19:47 +0000 (19:19 -0600)]
snapshot: allow full domain xml in snapshot

Just like VM saved state images (virsh save), snapshots MUST
track the inactive domain xml to detect any ABI incompatibilities.

The indentation is not perfect, but functionality comes before form.

Later patches will actually supply a full domain; for now, this
wires up the storage to support one, but doesn't ever generate one
in dumpxml output.

Happily, libvirt.c was already rejecting use of VIR_DOMAIN_XML_SECURE
from read-only connections, even though before this patch, there was
no information to be secured by the use of that flag.

And while we're at it, mark the libvirt snapshot metadata files
as internal-use only.

* src/libvirt.c (virDomainSnapshotGetXMLDesc): Document flag.
* src/conf/domain_conf.h (_virDomainSnapshotDef): Add member.
(virDomainSnapshotDefParseString, virDomainSnapshotDefFormat):
Update signature.
* src/conf/domain_conf.c (virDomainSnapshotDefFree): Clean up.
(virDomainSnapshotDefParseString): Optionally parse domain.
(virDomainSnapshotDefFormat): Output full domain.
* src/esx/esx_driver.c (esxDomainSnapshotCreateXML)
(esxDomainSnapshotGetXMLDesc): Update callers.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML)
(vboxDomainSnapshotGetXMLDesc): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML)
(qemuDomainSnapshotLoad, qemuDomainSnapshotGetXMLDesc)
(qemuDomainSnapshotWriteMetadata): Likewise.
* docs/formatsnapshot.html.in: Rework doc example.
Based on a patch by Philipp Hahn.

13 years agosnapshot: refactor domain xml output
Eric Blake [Sat, 13 Aug 2011 00:58:21 +0000 (18:58 -0600)]
snapshot: refactor domain xml output

Minor semantic change - allow domain xml to be generated in place
within a larger buffer, rather than having to go through a
temporary string.

* src/conf/domain_conf.c (virDomainDefFormatInternal): Add
parameter.
(virDomainDefFormat, virDomainObjFormat): Update callers.

13 years agosnapshot: prevent migration from stranding snapshot data
Eric Blake [Fri, 12 Aug 2011 19:23:09 +0000 (13:23 -0600)]
snapshot: prevent migration from stranding snapshot data

Migration is another case of stranding metadata.  And since
snapshot metadata is arbitrarily large, there's no way to
shoehorn it into the migration cookie of migration v3.

This patch consolidates two existing locations for migration
validation into one helper function, then enhances that function
to also do the new checks.  If we could always trust the source
to validate migration, then the destination would not have to
do anything; but since older servers that did not do checking
can migrate to newer destinations, we have to repeat some of
the same checks on the destination; meanwhile, we want to
detect failures as soon as possible.  With migration v2, this
means that validation will reject things at Prepare on the
destination if the XML exposes the problem, otherwise at Perform
on the source; with migration v3, this means that validation
will reject things at Begin on the source, or if the source
is old and the XML exposes the problem, then at Prepare on the
destination.

This patch is necessarily over-strict.  Once a later patch
properly handles auto-cleanup of snapshot metadata on the
death of a transient domain, then the only time we actually
need snapshots to prevent migration is when using the
--undefinesource flag on a persistent source domain.

It is possible to recreate snapshot metadata on the destination
with VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE and
VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT.  But for now, that is limited,
since if we delete the snapshot metadata prior to migration,
then we won't know the name of the current snapshot to pass
along; and if we delete the snapshot metadata after migration
and use the v3 migration cookie to pass along the name of the
current snapshot, then we need a way to bypass the fact that
this patch refuses migration with snapshot metadata present.

So eventually, we may have to introduce migration protocol v4
that allows feature negotiation and an arbitrary number of
handshake exchanges, so as to pass as many rpc calls as needed
to transfer all the snapshot xml hierarchy.

But all of that is thoughts for the future; for now, the best
course of action is to quit early, rather than get into a
funky state of stale metadata; then relax restrictions later.

* src/qemu/qemu_migration.h (qemuMigrationIsAllowed): Make static.
* src/qemu/qemu_migration.c (qemuMigrationIsAllowed): Alter
signature, and allow checks for both outgoing and incoming.
(qemuMigrationBegin, qemuMigrationPrepareAny)
(qemuMigrationPerformJob): Update callers.

13 years agosnapshot: support new undefine flags in qemu
Eric Blake [Fri, 12 Aug 2011 16:20:24 +0000 (10:20 -0600)]
snapshot: support new undefine flags in qemu

A nice benefit of deleting all snapshots at undefine time is that
you don't have to do any reparenting or subtree identification - since
everything goes, this is an O(n) process, whereas using multiple
virDomainSnapshotDelete calls would be O(n^2) or worse.  But it is
only doable for snapshot metadata, where we are in control of the
data being deleted; for the actual snapshots, there's too much
likelihood of something going wrong, and requiring even more API
calls to figure out what failed in the meantime, so callers are
better off deleting the snapshot data themselves one snapshot at
a time where they can deal with failures as they happen.

* src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Honor new flags.

13 years agosnapshot: cache qemu-img location
Eric Blake [Fri, 12 Aug 2011 16:12:47 +0000 (10:12 -0600)]
snapshot: cache qemu-img location

As more clients start to want to know this information, doing
a PATH stat walk and malloc for every client adds up.

We are only caching the location, not the capabilities, so even
if qemu-img is updated in the meantime, it will still probably
live in the same location.  So there is no need to worry about
clearing this particular cache.

* src/qemu/qemu_conf.h (qemud_driver): Add member.
* src/qemu/qemu_driver.c (qemudShutdown): Cleanup.
(qemuFindQemuImgBinary): Add an argument, and cache result.
(qemuDomainSnapshotForEachQcow2, qemuDomainSnapshotDiscard)
(qemuDomainSnapshotCreateInactive, qemuDomainSnapshotRevertInactive)
(qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot): Update
callers.

13 years agosnapshot: refactor some qemu code
Eric Blake [Fri, 12 Aug 2011 15:52:08 +0000 (09:52 -0600)]
snapshot: refactor some qemu code

Prepare for code sharing.  No semantic change.

* src/qemu/qemu_driver.c (qemuFindQemuImgBinary)
(qemuDomainSnapshotWriteMetadata)
(qemuDomainSnapshotDiscard)
(qemuDomainSnapshotForEachQcow2): Float up.
(qemuDomainSnapshotDiscardDescendant): Likewise, and rename...
(qemuDomainSnapshotDiscardAll): ...for generic use.
(qemuDomainSnapshotDelete): Update caller.

13 years agosnapshot: teach virsh about new undefine flags
Eric Blake [Fri, 12 Aug 2011 02:24:19 +0000 (20:24 -0600)]
snapshot: teach virsh about new undefine flags

Similar to 'undefine --managed-save' (commit 83e849c1), we must
assume that the old API is unsafe; however, we cannot emulate
metadata-only deletion on older servers.  Additionally, we have
the wrinkle that while virDomainUndefineFlags and managed save
cleanup were introduced in 0.9.4, it wasn't until 0.9.5 that
snapshots block undefine of a domain.  Do the best we can given
the server we are talking to.

* tools/virsh.c (cmdUndefine): Add --snapshots-metadata flag.
* tools/virsh.pod (undefine, destroy, shutdown): Document effect
of snapshots.

13 years agosnapshot: prevent stranding snapshot data on domain destruction
Eric Blake [Fri, 12 Aug 2011 15:07:08 +0000 (09:07 -0600)]
snapshot: prevent stranding snapshot data on domain destruction

Just as leaving managed save metadata behind can cause problems
when creating a new domain that happens to collide with the name
of the just-deleted domain, the same is true of leaving any
snapshot metadata behind.  For safety sake, extend the semantic
change of commit b26a9fa9 to also cover snapshot metadata as a
reason to reject undefining an inactive domain.  A future patch
will make sure that shutdown of a transient domain automatically
deletes snapshot metadata (whether by destroy, shutdown, or
guest-initiated action).  Management apps of transient domains
should take care to capture xml of snapshots, if it is necessary
to recreate the snapshot metadata on a later transient domain
with the same name and uuid.

This also documents a new flag that hypervisors can choose to
support as a shortcut for taking care of the metadata as part of
the undefine process; however, nontrivial driver support for these
flags will be deferred to future patches.

Note that ESX and VBox can never be transient; therefore, they
do not have to worry about automatic cleanup after shutdown
(the persistent domain still remains); likewise they never
store snapshot metadata, so the undefine flag is trivial.
The nontrivial work remaining is thus in the qemu driver.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA): New flag.
* src/libvirt.c (virDomainUndefine, virDomainUndefineFlags):
Document new limitations and flag.
* src/esx/esx_driver.c (esxDomainUndefineFlags): Trivial
implementation.
* src/vbox/vbox_tmpl.c (vboxDomainUndefineFlags): Likewise.
* src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Enforce
the limitations.

13 years agosnapshot: add qemu snapshot redefine support
Eric Blake [Thu, 1 Sep 2011 22:50:17 +0000 (16:50 -0600)]
snapshot: add qemu snapshot redefine support

Redefining a qemu snapshot requires a bit of a tweak to the common
snapshot parsing code, but the end result is quite nice.

Be careful that redefinitions do not introduce circular parent
chains.  Also, we don't want to allow conversion between online
and offline existing snapshots.  We could probably do some more
validation for snapshots that don't already exist to make sure
they are even feasible, by parsing qemu-img output, but that
can come later.

* src/conf/domain_conf.h (virDomainSnapshotParseFlags): New
internal flags.
* src/conf/domain_conf.c (virDomainSnapshotDefParseString): Alter
signature to take internal flags.
* src/esx/esx_driver.c (esxDomainSnapshotCreateXML): Update caller.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Support
new public flags.

13 years agosnapshot: add qemu snapshot creation without metadata
Eric Blake [Thu, 1 Sep 2011 21:47:03 +0000 (15:47 -0600)]
snapshot: add qemu snapshot creation without metadata

Supporting NO_METADATA on snapshot creation is interesting - we must
still return a valid opaque snapshot object, but the user can't get
anything out of it (unless we add a virDomainSnapshotGetName()),
since it is no longer registered with the domain.

Also, virsh now tries to query for secure xml, in anticipation of
when we store <domain> xml inside <domainsnapshot>; for now, we
can trivially support it, since we have nothing secure.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Support
new flag.
(qemuDomainSnapshotGetXMLDesc): Trivially support VIR_DOMAIN_XML_SECURE.

13 years agosnapshot: improve virsh snapshot-create, add snapshot-edit
Eric Blake [Thu, 1 Sep 2011 20:21:28 +0000 (14:21 -0600)]
snapshot: improve virsh snapshot-create, add snapshot-edit

Wire up the new snapshot creation flags in virsh.  For convenience,
teach 'snapshot-current' how to make an existing snapshot become
current (can be used after upgrading to newer libvirt to recover
from the fact that the older libvirt lost track of the current
snapshot after a restart).  The snapshot-create-as command is
intentionally not taught --redefine or --current, as this would
imply adding a lot of other options for everything else that can
appear in the <domainsnapshot> xml, but which is normally read-only.
Besides, redefining will usually be done on files created by
snapshot-dumpxml, rather than something built up by hand on the
command line.  And now that we can redefine, we can edit.

* tools/virsh.c (cmdSnapshotCreate): Add --redefine, --current,
and --no-metadata.
(cmdSnapshotCreateAs): Add --no-metadata.
(cmdSnapshotCurrent): Add snapshotname to alter current snapshot.
(cmdSnapshotEdit): New command.
* tools/virsh.pod (snapshot-create, snapshot-create-as)
(snapshot-current, snapshot-edit):  Document these.

13 years agosnapshot: refactor virsh snapshot creation
Eric Blake [Thu, 18 Aug 2011 20:07:43 +0000 (14:07 -0600)]
snapshot: refactor virsh snapshot creation

The next patch will make snapshot creation more complex, so it's
better to avoid repetition of the complexity.

* tools/virsh.c (vshSnapshotCreate): New helper function.
(cmdSnapshotCreate, cmdSnapshotCreateAs): Use it.

13 years agosnapshot: allow recreation of metadata
Eric Blake [Wed, 31 Aug 2011 01:02:46 +0000 (19:02 -0600)]
snapshot: allow recreation of metadata

The first two flags are essential for being able to replicate
snapshot hierarchies across multiple hosts, which will come in
handy for supervised migrations.  It also allows a management app
to take a snapshot of a transient domain, save the metadata, stop
the domain, recreate a new transient domain by the same name,
redefine the snapshot, then revert to it.

This is not quite as convenient as leaving the metadata behind
after a domain is no longer around, but doing that has a few
problems: 1. the libvirt API can only delete snapshot metadata
if there is a valid domain handle to use to get to that snapshot
object - if stale data is left behind without a domain, there is
no way to request that the data be cleaned up. 2. creating a new
domain with the same name but different uuid than the older
domain where a snapshot existed cannot use the older snapshot
data; this risks confusing libvirt, and forbidding the stale
data is similar to the recent patch to forbid stale managed save.

The first two flags might be useful on hypervisors with no metadata,
but only for modifying the notion of the current snapshot;
however, I don't know how to do that for ESX or VBox.

The third flag is a convenience option, to combine a creation with
a delete metadata into one step.  It is trivial for hypervisors
with no metadata.

The qemu changes will be involved enough to warrant a separate patch.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)
(VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT)
(VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA): New flags.
* src/libvirt.c (virDomainSnapshotCreateXML): Document them, and
enforce mutual exclusion.
* src/esx/esx_driver.c (esxDomainSnapshotCreateXML): Trivial
implementation.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotCreateXML): Likewise.
* docs/formatsnapshot.html.in: Document re-creation.

13 years agosnapshot: identify qemu snapshot roots
Eric Blake [Sat, 13 Aug 2011 17:18:44 +0000 (11:18 -0600)]
snapshot: identify qemu snapshot roots

Filtering for roots is pretty easy to do.

* src/conf/domain_conf.h (virDomainSnapshotObjListGetNames)
(virDomainSnapshotObjListNum): Update prototype.
* src/conf/domain_conf.c (virDomainSnapshotObjListCopyNames)
(virDomainSnapshotObjListGetNames, virDomainSnapshotObjListCount)
(virDomainSnapshotObjListNum): Support filtering.
* src/qemu/qemu_driver.c (qemuDomainSnapshotNum)
(qemuDomainSnapshotListNames): Update callers.

13 years agosnapshot: reflect new dumpxml and list options in virsh
Eric Blake [Tue, 16 Aug 2011 19:34:22 +0000 (13:34 -0600)]
snapshot: reflect new dumpxml and list options in virsh

New flag bits are worth exposing via virsh.  In the case of
snapshot-list --roots, it's possible to emulate this even when
talking to an older server that lacks the bit; whereas
--metadata requires a newer server.

Although we don't use --security-info yet, the flag is already
documented for other dumpxml operations, and turning it on now
will make it useful when a future patch actually has to honor it.

* tools/virsh.c (cmdSnapshotDumpXML, cmdSnapshotCurrent): Add
--security-info.
(cmdSnapshotList): Add --roots, --metadata.
* tools/virsh.pod (snapshot-dumpxml, snapshot-current)
(snapshot-list): Document these.

13 years agosnapshot: identify which snapshots have metadata
Eric Blake [Fri, 12 Aug 2011 14:51:15 +0000 (08:51 -0600)]
snapshot: identify which snapshots have metadata

To make it easier to know when undefine will fail because of existing
snapshot metadata, we need to know how many snapshots have metadata.

Also, it is handy to filter the list of snapshots to just those that
have no parents; document that flag now, but implement it in later patches.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_LIST_ROOTS)
(VIR_DOMAIN_SNAPSHOT_LIST_METADATA): New flags.
* src/libvirt.c (virDomainSnapshotNum)
(virDomainSnapshotListNames): Document them.
* src/esx/esx_driver.c (esxDomainSnapshotNum)
(esxDomainSnapshotListNames): Implement trivial flag.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotNum)
(vboxDomainSnapshotListNames): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSnapshotNum)
(qemuDomainSnapshotListNames): Likewise.

13 years agosnapshot: let qemu discard only snapshot metadata
Eric Blake [Fri, 12 Aug 2011 13:21:47 +0000 (07:21 -0600)]
snapshot: let qemu discard only snapshot metadata

Adding this was trivial compared to the previous patch for fixing
qemu snapshot deletion in the first place.

* src/qemu/qemu_driver.c (qemuDomainSnapshotDiscard): Add
parameter.
(qemuDomainSnapshotDiscardDescendant, qemuDomainSnapshotDelete):
Update callers.

13 years agosnapshot: allow deletion of just snapshot metadata
Eric Blake [Fri, 12 Aug 2011 03:12:05 +0000 (21:12 -0600)]
snapshot: allow deletion of just snapshot metadata

A future patch will make it impossible to remove a domain if it
would leave behind any libvirt-tracked metadata about snapshots,
since stale metadata interferes with a new domain by the same name.
But requiring snaphot contents to be deleted before removing a
domain is harsh; with qemu, qemu-img can still make use of the
contents after the libvirt domain is gone.  Therefore, we need
an option to get rid of libvirt tracking information, but not
the actual contents.  For hypervisors that do not track any
metadata in libvirt, the implementation is trivial; all remaining
hypervisors (really, just qemu) will be dealt with separately.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_DELETE_METADATA_ONLY): New flag.
* src/libvirt.c (virDomainSnapshotDelete): Document it.
* src/esx/esx_driver.c (esxDomainSnapshotDelete): Trivially
supported when there is no libvirt metadata.
* src/vbox/vbox_tmpl.c (vboxDomainSnapshotDelete): Likewise.

13 years agosnapshot: simplify acting on just children
Eric Blake [Sat, 13 Aug 2011 17:56:15 +0000 (11:56 -0600)]
snapshot: simplify acting on just children

Similar to the last patch in isolating the filtering from the
client actions, so that clients don't have to reinvent the
filtering.

* src/conf/domain_conf.h (virDomainSnapshotForEachChild): New
prototype.
* src/libvirt_private.syms (domain_conf.h): Export it.
* src/conf/domain_conf.c (virDomainSnapshotActOnChild)
(virDomainSnapshotForEachChild): New functions.
(virDomainSnapshotCountChildren): Delete.
(virDomainSnapshotHasChildren): Simplify.
* src/qemu/qemu_driver.c (qemuDomainSnapshotReparentChildren)
(qemuDomainSnapshotDelete): Likewise.

13 years agosnapshot: track current domain across deletion of children
Eric Blake [Wed, 24 Aug 2011 20:25:46 +0000 (14:25 -0600)]
snapshot: track current domain across deletion of children

Deleting a snapshot and all its descendants had problems with
tracking the current snapshot.  The deletion does not necessarily
proceed in depth-first order, so a parent could be deleted
before a child, wreaking havoc on passing the notion of the
current snapshot to the parent.  Furthermore, even if traversal
were depth-first, doing multiple file writes to pass current up
the chain one snapshot at a time is wasteful, comparing to a
single update to the current snapshot at the end of the algorithm.

* src/qemu/qemu_driver.c (snap_remove): Add field.
(qemuDomainSnapshotDiscard): Add parameter.
(qemuDomainSnapshotDiscardDescendant): Adjust accordingly.
(qemuDomainSnapshotDelete): Properly reset current.

13 years agosnapshot: avoid crash when deleting qemu snapshots
Eric Blake [Fri, 12 Aug 2011 13:05:50 +0000 (07:05 -0600)]
snapshot: avoid crash when deleting qemu snapshots

This one's nasty.  Ever since we fixed virHashForEach to prevent
nested hash iterations for safety reasons (commit fba550f6),
virDomainSnapshotDelete with VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN
has been broken for qemu: it deletes children, while leaving
grandchildren intact but pointing to a no-longer-present parent.
But even before then, the code would often appear to succeed to
clean up grandchildren, but risked memory corruption if you have
a large and deep hierarchy of snapshots.

For acting on just children, a single virHashForEach is sufficient.
But for acting on an entire subtree, it requires iteration; and
since we declared recursion as invalid, we have to switch to a
while loop.  Doing this correctly requires quite a bit of overhaul,
so I added a new helper function to isolate the algorithm from the
actions, so that callers do not have to reinvent the iteration.

Note that this _still_ does not handle CHILDREN correctly if one
of the children is the current snapshot; that will be next.

* src/conf/domain_conf.h (_virDomainSnapshotDef): Add mark.
(virDomainSnapshotForEachDescendant): New prototype.
* src/libvirt_private.syms (domain_conf.h): Export it.
* src/conf/domain_conf.c (virDomainSnapshotMarkDescendant)
(virDomainSnapshotActOnDescendant)
(virDomainSnapshotForEachDescendant): New functions.
* src/qemu/qemu_driver.c (qemuDomainSnapshotDiscardChildren):
Replace...
(qemuDomainSnapshotDiscardDescenent): ...with callback that
doesn't nest hash traversal.
(qemuDomainSnapshotDelete): Use new function.

13 years agosnapshot: speed up snapshot location
Eric Blake [Wed, 24 Aug 2011 19:38:42 +0000 (13:38 -0600)]
snapshot: speed up snapshot location

Each snapshot lookup was iterating over the entire hash table, O(n),
instead of honing in directly on the hash key, amortized O(1).

Besides, fixing this means that virDomainSnapshotFindByName can now
be used inside another virHashForeach iteration (without this patch,
attempts to lookup a snapshot by name during a hash iteration will
fail due to nested iteration).

* src/conf/domain_conf.c (virDomainSnapshotFindByName): Simplify.
(virDomainSnapshotObjListSearchName): Delete unused function.

13 years agosnapshot: add snapshot-list --parent to virsh
Eric Blake [Tue, 16 Aug 2011 19:34:22 +0000 (13:34 -0600)]
snapshot: add snapshot-list --parent to virsh

Even though I recently added 'virsh snapshot-parent', doing it one
snapshot at a time is painful, so make it possible to expand the
snapshot-list table at once.

* tools/virsh.c (cmdSnapshotList): Add --parent.
* tools/virsh.pod (snapshot-list): Document it.

13 years agosnapshot: fine-tune qemu snapshot revert states
Eric Blake [Sat, 27 Aug 2011 19:48:19 +0000 (13:48 -0600)]
snapshot: fine-tune qemu snapshot revert states

For a system checkpoint of a running or paused domain, it's fairly
easy to honor new flags for altering which state to use after the
revert.  For an inactive snapshot, the revert has to be done while
there is no qemu process, so do back-to-back transitions; this also
lets us revert to inactive snapshots even for transient domains.

* src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Support new
flags.

13 years agosnapshot: properly revert qemu to offline snapshots
Eric Blake [Fri, 26 Aug 2011 22:17:41 +0000 (16:17 -0600)]
snapshot: properly revert qemu to offline snapshots

Commit 5e47785 broke reverts to offline system checkpoint snapshots
with older qemu, since there is no longer any code path to use
qemu -loadvm on next boot.  Meanwhile, reverts to offline system
checkpoints have been broken for newer qemu, both before and
after that commit, since -loadvm no longer works to revert to
disk state without accompanying vm state.  Fix both of these by
using qemu-img to revert disk state.

Meanwhile, consolidate the (now 3) clients of a qemu-img iteration
over all disks of a VM into one function, so that any future
algorithmic fixes to the FIXMEs in that function after partial
loop iterations are dealt with at once.  That does mean that this
patch doesn't handle partial reverts very well, but we're not
making the situation any worse in this patch.

* src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Use
qemu-img rather than 'qemu -loadvm' to revert to offline snapshot.
(qemuDomainSnapshotRevertInactive): New helper.
(qemuDomainSnapshotCreateInactive): Factor guts...
(qemuDomainSnapshotForEachQcow2): ...into new helper.
(qemuDomainSnapshotDiscard): Use it.

13 years agosnapshot: improve reverting to qemu paused snapshots
Eric Blake [Thu, 25 Aug 2011 21:17:10 +0000 (15:17 -0600)]
snapshot: improve reverting to qemu paused snapshots

If you take a checkpoint snapshot of a running domain, then pause
qemu, then restore the snapshot, the result should be a running
domain, but the code was leaving things paused.  Furthermore, if
you take a checkpoint of a paused domain, then run, then restore,
there was a brief but non-deterministic window of time where the
domain was running rather than paused.  Fix both of these
discrepancies by always pausing before restoring.

Also, check that the VM is active every time lock is dropped
between two monitor calls.

Finally, straighten out the events that get emitted on each
transition.

* src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Always
pause before reversion, and improve events.

13 years agosnapshot: fine-tune qemu saved images starting paused
Eric Blake [Sat, 27 Aug 2011 13:12:32 +0000 (07:12 -0600)]
snapshot: fine-tune qemu saved images starting paused

Implement the new running/paused overrides for saved state management.

Unfortunately, for virDomainSaveImageDefineXML, the saved state
updates are write-only - I don't know of any way to expose a way
to query the current run/pause setting of an existing save image
file to the user without adding a new API or modifying the domain
xml of virDomainSaveImageGetXMLDesc to include a new element to
reflect the state bit encoded into the save image.  However, I
don't think this is a show-stopper, since the API is designed to
leave the state bit alone unless an explicit flag is used to
change it.

* src/qemu/qemu_driver.c (qemuDomainSaveInternal)
(qemuDomainSaveImageOpen): Adjust signature.
(qemuDomainSaveFlags, qemuDomainManagedSave)
(qemuDomainRestoreFlags, qemuDomainSaveImageGetXMLDesc)
(qemuDomainSaveImageDefineXML, qemuDomainObjRestore): Adjust
callers.

13 years agosnapshot: expose --running and --paused in virsh
Eric Blake [Sat, 27 Aug 2011 14:16:04 +0000 (08:16 -0600)]
snapshot: expose --running and --paused in virsh

Pretty straight-forward exposure of new flags.  For most commands,
we let the API reject mutually exclusive flags; but for save-image-edit,
we do the sanity check ourselves to avoid looping on flag failure if
the edit cycle is ever enhanced to allow the user to retry an edit
to fix up an xml validation error.

* tools/virsh.c (cmdManagedSave, cmdRestore, cmdSave)
(cmdSaveImageDefine, cmdSaveImageEdit): Add new flags.
* tools/virsh.pod (managedsave, restore, save, save-image-define)
(save-image-edit): Document them.

13 years agosnapshot: fine-tune ability to start paused
Eric Blake [Fri, 26 Aug 2011 21:27:50 +0000 (15:27 -0600)]
snapshot: fine-tune ability to start paused

While it is nice that snapshots and saved images remember whether
the domain was running or paused, sometimes the restoration phase
wants to guarantee a particular state (paused to allow hot-plugging,
or running without needing to call resume).  This introduces new
flags to allow the control, and a later patch will implement the
flags for qemu.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SAVE_RUNNING)
(VIR_DOMAIN_SAVE_PAUSED, VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING)
(VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED): New flags.
* src/libvirt.c (virDomainSaveFlags, virDomainRestoreFlags)
(virDomainManagedSave, virDomainSaveImageDefineXML)
(virDomainRevertToSnapshot): Document their use, and enforce
mutual exclusion.

13 years agosnapshot: better events when starting paused
Eric Blake [Fri, 5 Aug 2011 22:05:50 +0000 (16:05 -0600)]
snapshot: better events when starting paused

There are two classes of management apps that track events - one
that only cares about on/off (and only needs to track EVENT_STARTED
and EVENT_STOPPED), and one that cares about paused/running (also
tracks EVENT_SUSPENDED/EVENT_RESUMED).  To keep both classes happy,
any transition that can go from inactive to paused must emit two
back-to-back events - one for started and one for suspended (since
later resuming of the domain will only send RESUMED, but the first
class isn't tracking that).

This also fixes a bug where virDomainCreateWithFlags with the
VIR_DOMAIN_START_PAUSED flag failed to start paused when restoring
from a managed save image.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_EVENT_SUSPENDED_RESTORED)
(VIR_DOMAIN_EVENT_SUSPENDED_FROM_SNAPSHOT)
(VIR_DOMAIN_EVENT_RESUMED_FROM_SNAPSHOT): New sub-events.
* src/qemu/qemu_driver.c (qemuDomainRevertToSnapshot): Use them.
(qemuDomainSaveImageStartVM): Likewise, and add parameter.
(qemudDomainCreate, qemuDomainObjStart): Send suspended event when
starting paused.
(qemuDomainObjRestore): Add parameter.
(qemuDomainObjStart, qemuDomainRestoreFlags): Update callers.
* examples/domain-events/events-c/event-test.c
(eventDetailToString): Map new detail strings.

13 years agoLearn to use spicevmc as a redirection type for usb-redir
Marc-André Lureau [Fri, 2 Sep 2011 15:19:11 +0000 (23:19 +0800)]
Learn to use spicevmc as a redirection type for usb-redir

13 years agoAdd "redirdev" redirection device
Marc-André Lureau [Fri, 2 Sep 2011 15:09:14 +0000 (23:09 +0800)]
Add "redirdev" redirection device

- create a new "redirdev" element for this purpose

13 years agoqemu: Don't append 0 at usb id, so that it is compatible with legacy -usb
Marc-André Lureau [Fri, 2 Sep 2011 14:49:42 +0000 (22:49 +0800)]
qemu: Don't append 0 at usb id, so that it is compatible with legacy -usb

QEMU uses USB bus name "usb.0" when using the legacy -usb argument.
If we want to allow USB devices to specify their addresses with legacy
-usb, we should either in case of legacy bus name drop the 0 from the
address bus, or just drop the 0 from device id. This patch does the
later.

Another solution would be to permit addressing on non-legacy USB
controllers only.

13 years agoqemu: don't reserve slot 1 if a PIIX3 USB controller is defined there
Marc-André Lureau [Fri, 2 Sep 2011 14:42:09 +0000 (22:42 +0800)]
qemu: don't reserve slot 1 if a PIIX3 USB controller is defined there

Applies only to piix3 and check if piix3 controller is on correct
address, or report error

13 years agoModify USB port to be defined as a port path
Marc-André Lureau [Fri, 2 Sep 2011 14:31:26 +0000 (22:31 +0800)]
Modify USB port to be defined as a port path

So that devices can be attached to hubs. Example, to attach to first
port of a usb-hub on port 1.

      <hub type='usb'>
         <address type='usb' bus='0' port='1'/>
      </hub>

      <input type='mouse' type='usb'>
         <address type='usb' bus='0' port='1.1'/>
      </hub>

also add a test entry

13 years agoAdd USB hub device
Marc-André Lureau [Fri, 2 Sep 2011 14:20:40 +0000 (22:20 +0800)]
Add USB hub device

domain parsing and serialization code, qemu driver backend and
a couple of test

13 years agoAdd USB companion controllers support
Marc-André Lureau [Fri, 2 Sep 2011 14:03:51 +0000 (22:03 +0800)]
Add USB companion controllers support

Companion controllers take an extra 'master' attribute to associate
them.

Also add tests for this

13 years agoUSB devices gain a new USB address child element
Marc-André Lureau [Fri, 2 Sep 2011 13:28:27 +0000 (21:28 +0800)]
USB devices gain a new USB address child element

Expand the domain and the QEmu driver code
Adds a couple of tests

13 years agotest: USB controller can have a PCI address child element
Marc-André Lureau [Fri, 2 Sep 2011 13:26:55 +0000 (21:26 +0800)]
test: USB controller can have a PCI address child element

add a few tests for the new constructs

13 years agoAdd a new controller type 'usb' with optionnal 'model'
Marc-André Lureau [Fri, 2 Sep 2011 13:21:23 +0000 (21:21 +0800)]
Add a new controller type 'usb' with optionnal 'model'

The model by default is piix3-uchi.

Example:
<controller type='usb' index='0' model='ich9-ehci'/>

13 years agoAdd USB controller models
Marc-André Lureau [Fri, 2 Sep 2011 13:14:29 +0000 (21:14 +0800)]
Add USB controller models

List is: piix3-uhci piix4-uhci ehci ich9-ehci1 ich9-uhci1 ich9-uhci2
ich9-uhci3 vt82c686b-uhci pci-ohci

13 years agoRename virDomainControllerModel to virDomainControllerModelSCSI
Marc-André Lureau [Fri, 2 Sep 2011 13:06:15 +0000 (21:06 +0800)]
Rename virDomainControllerModel to virDomainControllerModelSCSI

Since we are about to add USB controller support let's remove the
ambiguity

13 years agoAdd various USB devices QEMU_CAPS
Marc-André Lureau [Fri, 2 Sep 2011 12:56:50 +0000 (20:56 +0800)]
Add various USB devices QEMU_CAPS

13 years agosnapshot: fix corner case on OOM during creation
Eric Blake [Thu, 1 Sep 2011 21:22:02 +0000 (15:22 -0600)]
snapshot: fix corner case on OOM during creation

Commit 6766ff10 introduced a corner case bug with snapshot creation:
if a snapshot is created, but then we hit OOM while trying to
create the return value of the function, then we have polluted the
internal directory with the snapshot metadata with no way to clean
it up from the running libvirtd.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Don't
write metadata file on OOM condition.