]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agosnapshot: simplify indentation of network xml
Eric Blake [Thu, 22 Sep 2011 18:00:45 +0000 (12:00 -0600)]
snapshot: simplify indentation of network xml

More simplifications possible due to auto-indent.  Also,
<bandwidth> within <actual> was only using 6 instead of 8 spaces.

* src/util/network.h (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter signature.
* src/util/network.c (virVirtualPortProfileFormat)
(virBandwidthDefFormat): Alter indentation.
(virBandwidthChildDefFormat): Tweak to make use easier.
* src/conf/network_conf.c (virPortGroupDefFormat)
(virNetworkDefFormat): Adjust callers.
* src/conf/domain_conf.c (virDomainNetDefFormat): Likewise.
(virDomainActualNetDefFormat): Likewise, and fix bandwidth
indentation.

13 years agosnapshot: simplify indentation of cpu features
Eric Blake [Wed, 21 Sep 2011 23:42:07 +0000 (17:42 -0600)]
snapshot: simplify indentation of cpu features

Auto-indent makes life a bit easier; this patch also drops unused
arguments and replaces a misspelled flag name with two entry points
instead, so that callers don't have to worry about how much spacing
is present when embedding cpu elements.

* src/conf/cpu_conf.h (virCPUFormatFlags): Delete.
(virCPUDefFormat): Drop unused argument.
(virCPUDefFormatBuf): Alter signature.
(virCPUDefFormatBufFull): New prototype.
* src/conf/cpu_conf.c (virCPUDefFormatBuf): Split...
(virCPUDefFormatBufFull): ...into new function.
(virCPUDefFormat): Adjust caller.
* src/conf/domain_conf.c (virDomainDefFormatInternal): Likewise.
* src/conf/capabilities.c (virCapabilitiesFormatXML): Likewise.
* src/cpu/cpu.c (cpuBaselineXML): Likewise.
* tests/cputest.c (cpuTestCompareXML): Likewise.

13 years agosnapshot: simplify indentation of sysinfo
Eric Blake [Wed, 21 Sep 2011 23:28:01 +0000 (17:28 -0600)]
snapshot: simplify indentation of sysinfo

The improvements to virBuffer, along with a paradigm shift to pass
the original buffer through rather than creating a second buffer,
allow us to shave off quite a few lines of code.

* src/util/sysinfo.h (virSysinfoFormat): Alter signature.
* src/util/sysinfo.c (virSysinfoFormat, virSysinfoBIOSFormat)
(virSysinfoSystemFormat, virSysinfoProcessorFormat)
(virSysinfoMemoryFormat): Change indentation parameter.
* src/conf/domain_conf.c (virDomainSysinfoDefFormat): Adjust
caller.
* src/qemu/qemu_driver.c (qemuGetSysinfo): Likewise.

13 years agosnapshot: test domainsnapshot indentation
Eric Blake [Thu, 22 Sep 2011 20:29:00 +0000 (14:29 -0600)]
snapshot: test domainsnapshot indentation

Add a test for the simple parts of my indentation changes, and
fix the fallout.

* tests/domainsnapshotxml2xmltest.c: New test.
* tests/Makefile.am (domainsnapshotxml2xmltest_SOURCES): Build it.
* src/conf/domain_conf.c (virDomainSnapshotDefFormat): Avoid NULL
deref, match documented order.
* src/conf/domain_conf.h (virDomainSnapshotDefFormat): Add const.
* tests/domainsnapshotxml2xmlout/all_parameters.xml: Tweak output.
* tests/domainsnapshotxml2xmlout/disk_snapshot.xml: Likewise.
* tests/domainsnapshotxml2xmlout/full_domain.xml: Likewise.
* .gitignore: Exempt new binary.

13 years agosnapshot: indent domain xml when nesting
Eric Blake [Sat, 17 Sep 2011 12:57:30 +0000 (06:57 -0600)]
snapshot: indent domain xml when nesting

<domainsnapshot> is the first public instance of <domain> being
used as a sub-element, although we have two other private uses
(runtime state, and migration cookie).  Although indentation has
no effect on XML parsing, using it makes the output more consistent.

This uses virBuffer auto-indentation to obtain the effect, for all
but the portions of <domain> that are not generated a line at a
time into the same virBuffer.  Further patches will clean up the
remaining problems.

* src/conf/domain_conf.h (virDomainDefFormatInternal): New prototype.
* src/conf/domain_conf.c (virDomainDefFormatInternal): Export.
(virDomainObjFormat, virDomainSnapshotDefFormat): Update callers.
* src/libvirt_private.syms (domain_conf.h): Add new export.
* src/qemu/qemu_migration.c (qemuMigrationCookieXMLFormat): Use
new function.
(qemuMigrationCookieXMLFormatStr): Update caller.

13 years agovirbuf: add auto-indentation support
Eric Blake [Thu, 20 Oct 2011 21:48:47 +0000 (15:48 -0600)]
virbuf: add auto-indentation support

Rather than having to adjust all callers in a chain to deal with
indentation, it is nicer to have virBuffer do auto-indentation.

* src/util/buf.h (_virBuffer): Increase size.
(virBufferAdjustIndent, virBufferGetIndent): New prototypes.
* src/libvirt_private.syms (buf.h): Export new functions.
* src/util/buf.c (virBufferAdjustIndent, virBufferGetIndent): New
functions.
(virBufferSetError, virBufferAdd, virBufferAddChar)
(virBufferVasprintf, virBufferStrcat, virBufferURIEncodeString):
Implement auto-indentation.
* tests/virbuftest.c (testBufAutoIndent): Test it.
(testBufInfiniteLoop): Don't rely on internals.
Idea by Daniel P. Berrange.

13 years agovirbuf: more detailed error reporting
Eric Blake [Tue, 27 Sep 2011 19:37:23 +0000 (13:37 -0600)]
virbuf: more detailed error reporting

The next patch wants to add some sanity checking, which would
be a different error than ENOMEM.  Many existing callers blindly
report OOM failure if virBuf reports an error, and this will be
wrong in the (unlikely) case that they actually had a usage error
instead; but since the most common error really is ENOMEM, I'm
not going to fix all callers.  Meanwhile, new discriminating
callers can react differently depending on what failure happened.

* src/util/buf.c (virBufferSetError): Add parameter.
(virBufferGrow, virBufferVasprintf, virBufferEscapeString)
(virBufferEscapeSexpr, virBufferEscapeShell): Adjust callers.

13 years agovirbuf: improve testsuite reporting
Eric Blake [Sat, 17 Sep 2011 13:57:26 +0000 (07:57 -0600)]
virbuf: improve testsuite reporting

I had some temporary test failures while working on virbuf
improvements in later patches, with output that looked like:

Expected [<]
Actual [  <]

which is pretty hard to figure out.  Adding an Offset designation
made it much easier to find which particular '<' was at the
wrong indentation, to fix the right part of the code.

* tests/testutils.c (virtTestDifference): Make it easier to
diagnose test failures.

13 years agovirbuf: fix const-correctness
Eric Blake [Tue, 27 Sep 2011 19:50:03 +0000 (13:50 -0600)]
virbuf: fix const-correctness

Although the compiler wasn't complaining (since it was the pointer,
rather than what was being pointed to, that was actually const), it
looks quite suspicious to call a function with an argument labeled
const when the nature of the pointer (virBufferPtr) is hidden behind
a typedef.  Dropping const makes the function declarations easier
to read.

* src/util/buf.h: Drop const from all functions that modify buffer
argument.
* src/util/buf.c (virBufferSetError, virBufferAdd)
(virBufferContentAndReset, virBufferFreeAndReset)
(virBufferAsprintf, virBufferVasprintf, virBufferEscapeString)
(virBufferEscapeSexpr, virBufferEscape): Fix fallout.

13 years agodocs: fix incorrect info about routed networks
Laine Stump [Thu, 20 Oct 2011 19:26:30 +0000 (15:26 -0400)]
docs: fix incorrect info about routed networks

In a recent expansion of the documentation on network forward modes, I
incorrectly stated that incoming sessions to guests on routed networks
were blocked. This is true for guests on NATed networks, but not
routed. This patch corrects that error, and adds a pointer to the
nwfilter page for those who do want to restrict incoming sessions to
hosts on routed networks.

13 years agoqemu: allow json in domxml-to-native
tangchen [Thu, 20 Oct 2011 10:37:52 +0000 (18:37 +0800)]
qemu: allow json in domxml-to-native

There is a little difference between the output of domxml-to-native and the actual commandline.
No matter qemu is in control or readline mode, domxml-to-native always converts it to readline mode.

That is because the parameter "monitor_json" for qemuBuildCommandLine() is always set to false
in qemuDomainXMLToNative().

Signed-off-by: tangchen <tangchen@cn.fujitsu.com>
13 years agodocs: document managed=yes of hostdev passthrough
Eric Blake [Fri, 14 Oct 2011 22:59:16 +0000 (16:59 -0600)]
docs: document managed=yes of hostdev passthrough

Clarify some of the effects of managed passthrough <hostdev> devices;
with recent changes (commit d093547), a nodedev-reattach is only needed
to pair up to an explicit nodedev-dettach (but beware that older
virt-manager has a bug where it uses explicit nodedev-dettach under the
hood when using the gui to hotplug a hostdev device).

* docs/formatdomain.html.in: Mention reattach.
* tools/virsh.pod (nodedev): Mention managed mode.

13 years agoFix virFileOpenTty definition on Win32
Daniel P. Berrange [Thu, 20 Oct 2011 09:02:27 +0000 (10:02 +0100)]
Fix virFileOpenTty definition on Win32

Stub out a complete impl of virFileOpenTty to avoid unused
parameter warnings

* src/util/util.c: Fix virFileOpenTty on Win32

13 years agosupport setting bandwidth from virsh attach-interface
Hu Tao [Tue, 18 Oct 2011 07:32:30 +0000 (15:32 +0800)]
support setting bandwidth from virsh attach-interface

Adds two options, inbound and outbound, to attach-interface to set
bandwidth when attaching interfaces

13 years agolxc: use hand-rolled code in place of unlockpt and grantpt
Serge E. Hallyn [Wed, 19 Oct 2011 01:39:57 +0000 (20:39 -0500)]
lxc: use hand-rolled code in place of unlockpt and grantpt

The glibc ones (intentionally) cannot handle ptys opened in a
devpts not mounted at /dev/pts.

Drop the (un-exported, unused) virFileOpenTtyAt.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agobuild: ignore test executable
Eric Blake [Wed, 19 Oct 2011 19:49:59 +0000 (13:49 -0600)]
build: ignore test executable

* .gitignore: Add exemption.

13 years agoqemu: Test name-space handling
Philipp Hahn [Tue, 18 Oct 2011 19:16:01 +0000 (21:16 +0200)]
qemu: Test name-space handling

Add test cases for parsing the qemu-name-space.
This is based on qemuxml2argv{test,data/}, but can not reside in
qemuxml2argv{test,data/} because ...

1. qemuxmlns-qemu-ns-domain.xml is not schema-valid and breaks
domainschematest. The test is still important to detect xmlns:qemu
bindings to a name-space other than
http://libvirt.org/schemas/domain/qemu/1.0

2. they break qemuxml2xml, because the xmlns:qemu binding is moved to
the top-level <domain> element when converting from argv to xml.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoqemu: Fix name-space handling
Philipp Hahn [Tue, 18 Oct 2011 16:22:49 +0000 (18:22 +0200)]
qemu: Fix name-space handling

The XML parser for the qemu specific extensions expects the qemu name-space
to be bound to the 'qemu' prefix. This is too strict, since the name of the
name-space-prefix is only meant as an internal lookup key. Only the associated
URI is relevant.
<domain>...
  <qemu:commandline xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
  ...</qemu:commandline>
</domain>

<domain xmlns:ns0="http://libvirt.org/schemas/domain/qemu/1.0">...
  <ns0:commandline>
  ...</ns0:commandline>
</domain>

<domain xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">
  <qemu:commandline xmlns:qemu="urn:foo">
  ...</qemu:commandline>
</domain>

Remove the test for checking the name-space binding on the top-level <domain>
element. Registering the name-space with XPath is enough.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agocompile: fix undefined reference to gnutls_x509_crt_get_dn with gcc-4.6.1
Xu He Jie [Tue, 18 Oct 2011 08:06:44 +0000 (08:06 +0000)]
compile: fix undefined reference to gnutls_x509_crt_get_dn with gcc-4.6.1

When I compile libvirt with gcc-4.6.1 in ubuntu 11.10, got error as below:

  CCLD   libvirtd
/usr/bin/ld: ../src/.libs/libvirt_driver_qemu.a(libvirt_driver_qemu_la-qemu_migration.o): undefined reference to symbol 'gnutls_x509_crt_get_dn@@GNUTLS_1_4'
/usr/bin/ld: note: 'gnutls_x509_crt_get_dn@@GNUTLS_1_4' is defined in DSO /usr/lib/x86_64-linux-gnu/libgnutls.so so try adding it to the linker command line
/usr/lib/x86_64-linux-gnu/libgnutls.so: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
make[3]: *** [libvirtd] Error 1

It can compile with gcc-4.5.2 in ubuntu 11.04, but it can not compile with gcc-4.6.1 in ubuntu 11.10.

I didn't find reason. Does Anyone know the reason or the different between gcc-4.5.2 and gcc-4.6.1?

I still provide a patch for this. Just make it is working now.

Signed-off-by: soulxu <soulxu@soulxu-ThinkPad-T410.(none)>
13 years agoReplace virBufferAdd with virBufferAddLit for const string
Daniel P. Berrange [Wed, 19 Oct 2011 08:44:08 +0000 (09:44 +0100)]
Replace virBufferAdd with virBufferAddLit for const string

The statement

        virBufferAdd(buf, "''", 2);

triggers a syntax-check warning

* src/util/buf.c: Replace virBufferAdd with virBufferAddLit

13 years agodocumentation: trivial spelling fix
Philipp Hahn [Tue, 18 Oct 2011 14:53:55 +0000 (16:53 +0200)]
documentation: trivial spelling fix

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoAllow for URI aliases when connecting to libvirt
Daniel P. Berrange [Thu, 13 Oct 2011 10:49:45 +0000 (11:49 +0100)]
Allow for URI aliases when connecting to libvirt

This adds support for a libvirt client configuration file
either /etc/libvirt/libvirt.conf for privileged clients,
or $HOME/.libvirt/libvirt.conf for unprivileged clients.

It allows one parameter

 uri_aliases = [
   "hail=qemu+ssh://root@hail.cloud.example.com/system",
   "sleet=qemu+ssh://root@sleet.cloud.example.com/system",
 ]

Any call to virConnectOpen with a non-NULL URI will first
attempt to match against the uri_aliases list. An application
can disable this by using VIR_CONNECT_NO_ALIASES

* docs/uri.html.in: Document URI aliases
* include/libvirt/libvirt.h.in: Add VIR_CONNECT_NO_ALIASES
* libvirt.spec.in, mingw32-libvirt.spec.in: Add /etc/libvirt/libvirt.conf
* src/Makefile.am: Install default config file
* src/libvirt.c: Add support for URI aliases
* src/remote/remote_driver.c: Don't try to handle URIs
  with no scheme and which clearly are not paths
* src/util/conf.c: Don't raise error on virConfFree(NULL)
* src/xen/xen_driver.c: Don't raise error on URIs
  with no scheme

13 years agoAdd support for autodestroy of guests to the LXC and UML drivers
Daniel P. Berrange [Wed, 13 Jul 2011 11:21:54 +0000 (12:21 +0100)]
Add support for autodestroy of guests to the LXC and UML drivers

We recently added support for VIR_DOMAIN_START_AUTODESTROY and
an impl to the QEMU driver. It is very desirable to support in
other drivers, so this adds it to LXC and UML

* src/lxc/lxc_conf.h, src/lxc/lxc_driver.c,
  src/uml/uml_conf.h, src/uml/uml_driver.c: Wire up autodestroy
  functions

13 years agoUse virBufferEscapeShell in cmdEcho
Guido Günther [Thu, 13 Oct 2011 20:49:15 +0000 (22:49 +0200)]
Use virBufferEscapeShell in cmdEcho

13 years agoqemu: replace qemuMonitorEscapeShell by virBufferEscapeShell
Guido Günther [Tue, 18 Oct 2011 19:09:13 +0000 (21:09 +0200)]
qemu: replace qemuMonitorEscapeShell by virBufferEscapeShell

13 years agovirBufferEscapeShell: Emit quotes for the empty string
Guido Günther [Thu, 13 Oct 2011 21:48:40 +0000 (23:48 +0200)]
virBufferEscapeShell: Emit quotes for the empty string

Make the empty string return '' to match cmdEcho's behavior.

13 years agosnapshot: detect when qemu lacks disk-snapshot support
Eric Blake [Tue, 18 Oct 2011 21:28:47 +0000 (15:28 -0600)]
snapshot: detect when qemu lacks disk-snapshot support

Noticed when testing new libvirt against old qemu that lacked the
snapshot_blkdev HMP command.  Libvirt was mistakenly treating the
command as successful, and re-writing the domain XML to use the
just-created 0-byte file, rendering the domain broken on restart.

* src/qemu/qemu_monitor_text.c (qemuMonitorTextDiskSnapshot):
Notice another possible error message.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive): Don't keep 0-byte file
on failure.

13 years agovirBufferEscapeShell: Fix escaping of single quotes.
Guido Günther [Tue, 18 Oct 2011 07:07:41 +0000 (09:07 +0200)]
virBufferEscapeShell: Fix escaping of single quotes.

When checking if we need to escape a single quote we were looking at the
character after the quote instead of at the quote itself.

13 years agocompile: Add a missing function 'pciDeviceListFind' to libvirt_private.syms
Xu He Jie [Tue, 18 Oct 2011 02:46:38 +0000 (02:46 +0000)]
compile: Add a missing function 'pciDeviceListFind' to libvirt_private.syms

compile error:
./src/.libs/libvirt_driver_qemu.a(libvirt_driver_qemu_la-qemu_hostdev.o): In function `qemuPrepareHostdevPCIDevices':
/home/soulxu/data/work-code/libvirt/src/qemu/qemu_hostdev.c:183: undefined reference to `pciDeviceListFind'
/home/soulxu/data/work-code/libvirt/src/qemu/qemu_hostdev.c:230: undefined reference to `pciDeviceListFind'
./src/.libs/libvirt_driver_qemu.a(libvirt_driver_qemu_la-qemu_hostdev.o): In function `qemuGetActivePciHostDeviceList':
/home/soulxu/data/work-code/libvirt/src/qemu/qemu_hostdev.c:102: undefined reference to `pciDeviceListFind'
./src/.libs/libvirt_driver_qemu.a(libvirt_driver_qemu_la-qemu_hostdev.o): In function `qemuDomainReAttachHostdevDevices':
/home/soulxu/data/work-code/libvirt/src/qemu/qemu_hostdev.c:370: undefined reference to `pciDeviceListFind'

Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
13 years agoqemu: Do not wait if the PCI device is not managed when reattaching
Osier Yang [Mon, 17 Oct 2011 10:19:58 +0000 (18:19 +0800)]
qemu: Do not wait if the PCI device is not managed when reattaching

Waiting for qemu-kvm cleaning up the PCI bar(s) mapping with long time
while the device is not managed is just waste of time.

13 years agoAdd AHCI support to qemu driver
Jim Fehlig [Wed, 28 Sep 2011 03:46:08 +0000 (21:46 -0600)]
Add AHCI support to qemu driver

Tested with multiple AHCI controllers and multiple disks attached
to a controller. E.g.,

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/test/disk0.raw'/>
      <target dev='sda' bus='sata'/>
      <address type='drive' controller='0' bus='0' unit='0'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/test/disk1.raw'/>
      <target dev='sdb' bus='sata'/>
      <address type='drive' controller='0' bus='0' unit='1'/>
    </disk>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/test/disk2.raw'/>
      <target dev='sdc' bus='sata'/>
      <address type='drive' controller='1' bus='0' unit='0'/>
    </disk>
    <controller type='sata' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
    </controller>
    <controller type='sata' index='1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>

13 years agosnapshot: implement LIST_LEAVES flag in esx
Eric Blake [Sat, 8 Oct 2011 02:30:14 +0000 (20:30 -0600)]
snapshot: implement LIST_LEAVES flag in esx

Relatively straight-forward filtering.

* src/esx/esx_vi.h (esxVI_GetNumberOfSnapshotTrees)
(esxVI_GetSnapshotTreeNames): Add parameter.
* src/esx/esx_vi.c (esxVI_GetNumberOfSnapshotTrees)
(esxVI_GetSnapshotTreeNames): Allow leaf filtering.
* src/esx/esx_driver.c (esxDomainSnapshotNum)
(esxDomainSnapshotListNames, esxDomainSnapshotNumChildren)
(esxDomainSnapshotListChildrenNames): Pass new flag through.

13 years agoFix virt-sanlock-cleanup documentation
Philipp Hahn [Mon, 17 Oct 2011 16:21:54 +0000 (18:21 +0200)]
Fix virt-sanlock-cleanup documentation

The referenced page does not exist, but locking.html has a section about
sanlock.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoFix VPATH build
Jiri Denemark [Mon, 17 Oct 2011 15:42:47 +0000 (17:42 +0200)]
Fix VPATH build

probes.h is generated in build directory; setting a dependency on
probes.h from source directory doesn't work well in VPATH builds. Caused
by commit 1afcfbdda0cac112faa61f74ec943e46aa43f2f5

13 years agoqemu: Relax -no-shutdown check to [0.14.0, 0.15.0]
Jiri Denemark [Mon, 17 Oct 2011 10:15:20 +0000 (12:15 +0200)]
qemu: Relax -no-shutdown check to [0.14.0, 0.15.0]

The patch that fixes SIGTERM handling with -no-shutdown was taken into
0.15.1 stable release of qemu.

13 years agoFix two comments related to error handling
Philipp Hahn [Mon, 17 Oct 2011 15:02:33 +0000 (17:02 +0200)]
Fix two comments related to error handling

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agobuild: fix 'make dist' error
Wen Congyang [Thu, 13 Oct 2011 07:18:31 +0000 (15:18 +0800)]
build: fix 'make dist' error

When I run 'make dist', I receive the following error messages:
make[1]: Entering directory `/home/wency/source/libvirt/src'
  GEN    remote/remote_protocol.h
  GEN    remote/remote_protocol.c
  GEN    remote/qemu_protocol.h
  GEN    remote/qemu_protocol.c
  GEN    remote/qemu_client_bodies.h
  CC     libvirt_driver_remote_la-remote_protocol.lo
In file included from ./remote/remote_protocol.h:16,
                 from ./remote/remote_protocol.c:7:
/internal.h:249:23: error: probes.h: No such file or directory
make[1]: *** [libvirt_driver_remote_la-remote_protocol.lo] Error 1
make[1]: Leaving directory `/home/wency/source/libvirt/src'
make: *** [distdir] Error 1

The reason is that we use probes.h before generating it.

13 years agoAdd missing strdup return value check
Roopa Prabhu [Fri, 14 Oct 2011 22:25:28 +0000 (15:25 -0700)]
Add missing strdup return value check

Check strdup return value and fail if error

Signed-off-by: Roopa Prabhu <roprabhu@cisco.com>
13 years agoqemu: Honor the orginal PCI dev properties when reattaching
Osier Yang [Thu, 13 Oct 2011 08:30:21 +0000 (16:30 +0800)]
qemu: Honor the orginal PCI dev properties when reattaching

BZ# https://bugzilla.redhat.com/show_bug.cgi?id=736214

The problem is caused by the original info of domain's PCI dev is
maintained by qemu_driver->activePciHostdevs list, (E.g. dev->reprobe,
which stands for whether need to reprobe driver for the dev when do
reattachment). The fields (dev->reprobe, dev->unbind_from_stub, and
dev->remove_slot) are initialized properly when preparing the PCI
device for managed attachment. However, when do reattachment, it
construct a complete new "pciDevice" without honoring the original
dev info, and thus the dev won't get the original driver or can get
other problem.

This patch is to fix the problem by get the devs from list
driver->activePciHostdevs.

Tested with following 3 scenarios:
  * the PCI was bound to some driver not pci-stub before attaching

    result: the device will be bound to the original driver

  * the PCI was bound to pci-stub before attaching

    result: no driver reprobing, and still bound to pci-stub

  * The PCI was not bound to any driver

    result: no driver reprobing, and still not bound to any driver.

13 years agomacvtap: avoid invalid free
Roopa Prabhu [Fri, 14 Oct 2011 20:41:46 +0000 (13:41 -0700)]
macvtap: avoid invalid free

Commit 0472f39 plugged a leak, but introduced another bug:

Actually looks like physfndev is conditionally allocated in getPhysfnDev
Its better to modify getPhysfnDev to allocate physfndev every time.

13 years agodocs: fix network XML documentation
Laine Stump [Fri, 14 Oct 2011 18:35:32 +0000 (14:35 -0400)]
docs: fix network XML documentation

A few people have attempted to use the new forwarding modes with older
versions of libvirt. The docs where the modes are described have
always stated the minimum required libvirt version, but the examples
at the end didn't, which I believe is what has caused the confusion.

Similarly, the section on portgroups now has a version tag added at
the beginning.

I also noticed that there was no example of defining a <dns> hostname,
so I added one, as well as making the domain name example more
recognizable (by adding ".com" to the domain).

13 years agoClarify semantics of virDomainMigrate2
Jiri Denemark [Fri, 14 Oct 2011 19:24:18 +0000 (21:24 +0200)]
Clarify semantics of virDomainMigrate2

Explicitly disallow conflicts between domain name from dxml and dname.

13 years agoqemu: Do not reattach PCI device used by other domain when shutdown
Osier Yang [Thu, 13 Oct 2011 04:05:04 +0000 (12:05 +0800)]
qemu: Do not reattach PCI device used by other domain when shutdown

When failing on starting a domain, it tries to reattach all the PCI
devices defined in the domain conf, regardless of whether the devices
are still used by other domain. This will cause the devices to be deleted
from the list qemu_driver->activePciHostdevs, thus the devices will be
thought as usable even if it's not true. And following commands
nodedev-{reattach,reset} will be successful.

How to reproduce:
  1) Define two domains with same PCI device defined in the confs.
  2) # virsh start domain1
  3) # virsh start domain2
  4) # virsh nodedev-reattach $pci_device

You will see the device will be reattached to host successfully.
As pciDeviceReattach just check if the device is still used by
other domain via checking if the device is in list driver->activePciHostdevs,
however, the device is deleted from the list by step 2).

This patch is to prohibit the bug by:
  1) Prohibit a domain starting or device attachment right at
     preparation period (qemuPrepareHostdevPCIDevices) if the
     device is in list driver->activePciHostdevs, which means
     it's used by other domain.

  2) Introduces a new field for struct _pciDevice, (const char *used_by),
     it will be set as the domain name at preparation period,
     (qemuPrepareHostdevPCIDevices). Thus we can prohibit deleting
     the device from driver->activePciHostdevs if it's still used by
     other domain when stopping the domain process.

* src/pci.h (define two internal functions, pciDeviceSetUsedBy and
    pciDevceGetUsedBy)
* src/pci.c (new field "const char *used_by" for struct _pciDevice,
    implementations for the two new functions)
* src/libvirt_private.syms (Add the two new internal functions)
* src/qemu_hostdev.h (Modify the definition of functions
    qemuPrepareHostdevPCIDevices, and qemuDomainReAttachHostdevDevices)
* src/qemu_hostdev.c (Prohibit preparation and don't delete the
    device from activePciHostdevs list if it's still used by other domain)
* src/qemu_hotplug.c (Update function usage, as the definitions are
    changed)

Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoXen: Fake versions in xencapstest
Philipp Hahn [Fri, 14 Oct 2011 12:10:26 +0000 (14:10 +0200)]
Xen: Fake versions in xencapstest

virInitialize() → xenRegister() → xenhypervisorInit() determines the
version of the Hypervisor. This breaks xencapstest when building as root
on a dom0 system, since xenHypervisorBuildCapabilities() adds the "hap"
and "viridian" features based on the detected version.

Add an optional parameter to xenhypervisorInit() to disable automatic
detection of the Hypervisor version. The passed in arguments are used
instead.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoXen: move versions to struct
Philipp Hahn [Fri, 14 Oct 2011 10:58:01 +0000 (12:58 +0200)]
Xen: move versions to struct

Calling virInitialize() → xenRegister() → xenhypervisorInit() directly
opens a connection to the Xen Hypervisor, which breaks some unit tests.

Move all static variables into a struct to make it easier to override
them when testing.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoesx: drop dead code to silence Coverity
Eric Blake [Thu, 13 Oct 2011 22:06:38 +0000 (16:06 -0600)]
esx: drop dead code to silence Coverity

Coverity detected that the only way to get to the cleanup label
is if objectSpec had been successfully allocated, so the null
check was dead code.

* src/esx/esx_vi.c (esxVI_LookupObjectContentByType): Drop
redundant null check.

13 years agoutil: Fix typo in virGetHostname description
Jiri Denemark [Fri, 14 Oct 2011 14:25:50 +0000 (16:25 +0200)]
util: Fix typo in virGetHostname description

13 years agoFix syntax problem in mingw32-libvirt.spec.in
Daniel P. Berrange [Fri, 14 Oct 2011 09:01:56 +0000 (10:01 +0100)]
Fix syntax problem in mingw32-libvirt.spec.in

When defining macros, you can't put comments on the end of the
line because they will get included in the macro definition

* mingw32-libvirt.spec.in: Fix comment about hyperv

13 years agomacvtap: plug memory leak for 802.1Qbh
Eric Blake [Thu, 13 Oct 2011 22:45:58 +0000 (16:45 -0600)]
macvtap: plug memory leak for 802.1Qbh

Detected by Coverity.  Leak present since commit ca3b22b.

* src/util/macvtap.c (doPortProfileOp8021Qbh): Release device name.

13 years agoqemu: plug memory leak on migration
Eric Blake [Thu, 13 Oct 2011 22:19:44 +0000 (16:19 -0600)]
qemu: plug memory leak on migration

Detected by Coverity.  Leak introduced in commit 72de0d2.

* src/qemu/qemu_migration.c (qemuMigrationCookieGraphicsXMLParse):
Clean up on success.

13 years agoconf: plug memory leak on error
Eric Blake [Thu, 13 Oct 2011 22:10:47 +0000 (16:10 -0600)]
conf: plug memory leak on error

Detected by Coverity.  Leak present since commit 874e65a; and
while commit d50bb45 tried to fix the issue, it missed a path.

* src/conf/domain_conf.c (virDomainDefParseBootXML): Always clean
up useserial.

13 years agoUse virBufferEscapeShell in virNetSocketNewConnectSSH
Guido Günther [Thu, 13 Oct 2011 19:49:01 +0000 (21:49 +0200)]
Use virBufferEscapeShell in virNetSocketNewConnectSSH

to escape the netcat command since it's passed to the shell. Adjust
expected test case output accordingly.

13 years agoAdd virBufferEscapeShell
Guido Günther [Thu, 28 Jul 2011 13:25:00 +0000 (15:25 +0200)]
Add virBufferEscapeShell

Escape strings so they're safe to pass to the shell. It's based on
virsh's cmdEcho.

13 years agoAutodetect if the remote nc command supports the -q option
Guido Günther [Fri, 8 Jul 2011 19:07:29 +0000 (21:07 +0200)]
Autodetect if the remote nc command supports the -q option

Based on a patch by Marc Deslauriers <marc.deslauriers@ubuntu.com>

RH: https://bugzilla.redhat.com/show_bug.cgi?id=562176
Ubuntu: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/517478
Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=573172

13 years agostorage: plug memory leak on error
Eric Blake [Thu, 13 Oct 2011 21:06:01 +0000 (15:06 -0600)]
storage: plug memory leak on error

Detected by Coverity.  Present since commit 82c1740.

* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol): Fix leak.

13 years agoutil: Make getaddrinfo failure nonfatal in virGetHostname
Jiri Denemark [Thu, 13 Oct 2011 14:19:37 +0000 (16:19 +0200)]
util: Make getaddrinfo failure nonfatal in virGetHostname

Setting a hostname that cannot be resolved is not the best configuration
but since virGetHostname only calls getaddrinfo to get host's canonical
name and we do not fail if the returned canonical name is NULL or
"localhost", there is no reason why we should fail if getaddrinfo itself
fails.

13 years agoqemu: Make sure BeginJob is always followed by EndJob
Jiri Denemark [Thu, 13 Oct 2011 10:51:02 +0000 (12:51 +0200)]
qemu: Make sure BeginJob is always followed by EndJob

Otherwise we can end up with a dangling job that can only be cleared by
restarting libvirtd.

13 years agoqemu: Log debug messages when changing job
Jiri Denemark [Thu, 13 Oct 2011 10:32:38 +0000 (12:32 +0200)]
qemu: Log debug messages when changing job

Log debug messages anytime we call *BeginJob* or *EndJob* so that it's
easier to spot incorrect usage of domain job APIs.

13 years agoqemu: fix text block info parsing
Eric Blake [Thu, 13 Oct 2011 00:27:20 +0000 (18:27 -0600)]
qemu: fix text block info parsing

Detected by Coverity.  p (the pointer to the string) is always true;
when in reality, we wanted to know whether the integer value of the
just-parsed string is '0' or '1'.  Logic bug since commit b1b5b51.

* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetBlockInfo): Set
results to proper value.

13 years agoqemu: avoid text monitor null deref
Eric Blake [Thu, 13 Oct 2011 00:19:28 +0000 (18:19 -0600)]
qemu: avoid text monitor null deref

Detected by Coverity.  If, for some reason, our text monitor input
does not match our assumptions, we end up incrementing p while it
is NULL, then dereferencing the pointer 0x1, which will fault.

* src/qemu/qemu_monitor_text.c
(qemuMonitorTextGetBlockStatsParamsNumber): Rewrite to avoid
deref of strchr failure.  Fix indentation.

13 years agoqemu: check for json allocation failure
Eric Blake [Thu, 13 Oct 2011 00:10:24 +0000 (18:10 -0600)]
qemu: check for json allocation failure

Detected by Coverity.  Introduced in commit b1b5b51.

* src/qemu/qemu_monitor_json.c (qemuMonitorJSONGetBlockInfo):
Avoid null dereference.

13 years agobuild: add compiler attributes to virUUIDParse
Eric Blake [Wed, 12 Oct 2011 23:24:52 +0000 (17:24 -0600)]
build: add compiler attributes to virUUIDParse

Coverity complained that most, but not all, clients of virUUIDParse
were checking for errors.  Silence those coverity warnings by
explicitly marking the cases where we trust the input, and fixing
one instance that really should have been checking.  In particular,
this silences a rather large percentage of the warnings I saw on my
most recent Coverity analysis run.

* src/util/uuid.h (virUUIDParse): Enforce rules.
* src/util/uuid.c (virUUIDParse): Drop impossible check; at least
Coverity will detect if we break rules and pass NULL.
* src/xenapi/xenapi_driver.c (xenapiDomainCreateXML)
(xenapiDomainLookupByID, xenapiDomainLookupByName)
(xenapiDomainDefineXML): Ignore return when we trust data source.
* src/vbox/vbox_tmpl.c (nsIDtoChar, vboxIIDToUUID_v3_x)
(vboxCallbackOnMachineStateChange)
(vboxCallbackOnMachineRegistered, vboxStoragePoolLookupByName):
Likewise.
* src/node_device/node_device_hal.c (gather_system_cap): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxpr): Check for errors.

13 years agovirFDStream: close also given errfd (fd leak)
Marc-André Lureau [Thu, 13 Oct 2011 11:47:58 +0000 (13:47 +0200)]
virFDStream: close also given errfd (fd leak)

In virFDStreamOpenFileInternal(), a errfd pipe is opened by
virCommandRunAsync() and given to virFDStreamOpenInternal().

It seems virFDStream should close errfd, just like the other
fd it is given.

This fixes screenshots leaking FDs:
http://bugzilla.redhat.com/show_bug.cgi?id=745761

13 years agocommand: avoid fd leak on failure
Eric Blake [Tue, 12 Jul 2011 20:01:05 +0000 (14:01 -0600)]
command: avoid fd leak on failure

virCommandTransferFD promises that the fd is no longer owned by
the caller.  Normally, we want the fd to remain open until the
child runs, but in error situations, we must close it earlier.

* src/util/command.c (virCommandTransferFD): Close fd now if we
can't track it to close later.
(virCommandKeepFD): Adjust helper to make this easier.

13 years agoFix typo in lxc_controller
Serge E. Hallyn [Thu, 13 Oct 2011 02:32:03 +0000 (21:32 -0500)]
Fix typo in lxc_controller

s/Mouting/Mounting.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
13 years agospec: mingw cleanups
Eric Blake [Tue, 27 Sep 2011 14:52:47 +0000 (08:52 -0600)]
spec: mingw cleanups

* libvirt.spec.in (%configure): Drop unused %{one} macro.
* mingw32-libvirt.spec.in (%{rhel}): Compile ESX but not HyperV on
mingw build for RHEL.
(%build): Make configure honor spec conditionals.  Reorder to
match libvirt.spec.
* autobuild.sh (mingw): Update list to match.
Suggested by Daniel P. Berrange.

13 years agobuild: update to latest gnulib
Eric Blake [Wed, 12 Oct 2011 23:53:11 +0000 (17:53 -0600)]
build: update to latest gnulib

358 changes; most probably have no impact on libvirt, but we
might as well stay current.

* .gnulib: Update to latest.

13 years agoqemu: Check for domain being active on successful job acquire
Michal Privoznik [Tue, 11 Oct 2011 08:40:36 +0000 (10:40 +0200)]
qemu: Check for domain being active on successful job acquire

As this is needed. Although some functions check for domain
being active before obtaining job, we need to check it after,
because obtaining job unlocks domain object, during which
a state of domain can be changed.

13 years agoevents: Propose a separate lock for event queue
Michal Privoznik [Thu, 6 Oct 2011 16:44:13 +0000 (18:44 +0200)]
events: Propose a separate lock for event queue

Currently, push & pop from event queue (both server & client side)
rely on lock from higher levels, e.g. on driver lock (qemu),
private_data (remote), ...; This alone is not sufficient as not
every function that interacts with this queue can/does lock,
esp. in client where we have a different approach, "passing
the buck".

Therefore we need a separate lock just to protect event queue.

For more info see:
https://bugzilla.redhat.com/show_bug.cgi?id=743817

13 years agoqemu: Implement VIR_DUMP_RESET
Michal Privoznik [Mon, 26 Sep 2011 12:39:59 +0000 (14:39 +0200)]
qemu: Implement VIR_DUMP_RESET

This patch extends qemudDomainCoreDump so it supports new VIR_DUMP_RESET
flag. If this flag is set, domain is reset on successful dump. However,
this is needed to be done after we start CPUs.

13 years agovirDomainCoreDump: Introduce VIR_DUMP_RESET flag
Michal Privoznik [Mon, 26 Sep 2011 12:39:16 +0000 (14:39 +0200)]
virDomainCoreDump: Introduce VIR_DUMP_RESET flag

This flag is intended to allow user to do so called system reset
after dump, instead of sending ACPI reboot event.

13 years agoexample: Support debug output and loop switch
Philipp Hahn [Wed, 12 Oct 2011 15:13:30 +0000 (17:13 +0200)]
example: Support debug output and loop switch

Add support for enabling debug output via command line option.
Allow to toggle the loop implementation between pure-Python and
native-C.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoexample: Redirect --help output to stdout/stderr
Philipp Hahn [Wed, 12 Oct 2011 15:11:58 +0000 (17:11 +0200)]
example: Redirect --help output to stdout/stderr

When --help is requested, print usage() to stdout.
When an illegal option is passed, print usage to stderr.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoexample: Fix argument handling
Philipp Hahn [Wed, 12 Oct 2011 14:54:40 +0000 (16:54 +0200)]
example: Fix argument handling

sys.argv contains the original command line arguments, while args only
contains the arguments not handled by getopt(). Currently this is no
problem since --help is the only command line option passable, which
terminates the process, so the code is never reached. Any option added
in the future will reveal the bug.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agosnapshot: implement LIST_LEAVES flag in qemu
Eric Blake [Sat, 8 Oct 2011 01:57:39 +0000 (19:57 -0600)]
snapshot: implement LIST_LEAVES flag in qemu

With the recent refactoring of qemu snapshot relationships, it
is now trivial to filter on leaves.

* src/conf/domain_conf.c (virDomainSnapshotObjListCount)
(virDomainSnapshotObjListCopyNames): Handle new flag.
* src/qemu/qemu_driver.c (qemuDomainSnapshotListNames)
(qemuDomainSnapshotNum, qemuDomainSnapshotListChildrenNames)
(qemuDomainSnapshotNumChildren): Pass new flag through.

13 years agosnapshot: add API for filtering by leaves
Eric Blake [Fri, 30 Sep 2011 23:36:00 +0000 (17:36 -0600)]
snapshot: add API for filtering by leaves

Counterpart to --roots.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_LIST_LEAVES):
New flag.
* src/libvirt.c (virDomainSnapshotNum, virDomainSnapshotListNames)
(virDomainSnapshotNumChildren)
(virDomainSnapshotListChildrenNames): Document it.
* tools/virsh.c (cmdSnapshotList): Expose it.
* tools/virsh.pod (snapshot-list): Document --leaves.

13 years agoxen: Return tap2 for tap2 disks
Philipp Hahn [Wed, 12 Oct 2011 08:55:37 +0000 (10:55 +0200)]
xen: Return tap2 for tap2 disks

For some versions of Xen the difference between "tap" and "tap2" is
important. When converting back from xen-sxpr to libvirt-xml, that
information is lost, which breaks re-defining the domain using that
data.

Explicitly return "tap2" for disks defined as "device/tap2".

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoxen: fix PyGrub boot device order
Philipp Hahn [Wed, 12 Oct 2011 08:26:46 +0000 (10:26 +0200)]
xen: fix PyGrub boot device order

When PyGrub is used as the bootloader in Xen, it gets passed the first
bootable disk. Xend supports a "bootable"-flag for this, which isn't
explicitly supported by libvirt.
When converting libvirt-xml to xen-sxpr the "bootable"-flag gets
implicitly set by xen.xend.XenConfig.device_add() for the first disk
(marked as "Compat hack -- mark first disk bootable").
When converting back xen-sxpr to libvirt-xml, the disks are returned in
the internal order used by Xend ignoring the "bootable"-flag, which
loses the original order. When the domain is then re-defined, the order
of disks is changed, which breaks PyGrub, since a different disk gets
passed.

When converting xen-sxpr to libvirt-xml, use the "bootable"-flag to
determine the first disk.

This isn't perfect, since several disks can be marked as bootable using
the Xend-API, but that is not supported by libvirt. In all known cases
relevant to libvirt exactly one disk is marked as bootable.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agotests: Add support for skipping tests
Philipp Hahn [Wed, 12 Oct 2011 08:08:33 +0000 (10:08 +0200)]
tests: Add support for skipping tests

AM_TESTS has support for skipping tests, while the C-implementation
virtTestRun() does not support that feature.

Print "_" or "SKIP" in verbose mode for tests returning EXIT_AM_SKIP=77.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoIntroduce <driver> under <filesystem> to support open-by-handle
Harsh Prateek Bora [Tue, 11 Oct 2011 11:30:40 +0000 (17:00 +0530)]
Introduce <driver> under <filesystem> to support open-by-handle

VirtFS allows the user to choose between path/handle based fs driver.
As of now, libvirt hardcoded path based driver only. This patch provides
a solution to allow user to choose between path/handle based fs driver.

Sample:

    <filesystem type='mount'>
      <driver type='handle'/>
      <source dir='/folder/to/share1'/>
      <target dir='mount_tag1'/>
    </filesystem>

    <filesystem type='mount'>
      <driver type='path'/>
      <source dir='/folder/to/share2'/>
      <target dir='mount_tag2'/>
    </filesystem>

Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agobuf: implement generic virBufferEscape
Sage Weil [Tue, 20 Sep 2011 04:13:42 +0000 (21:13 -0700)]
buf: implement generic virBufferEscape

Implement a generic helper to escape a given set of characters with a
leading '\'.  Generalizes virBufferEscapeSexpr().

Signed-off-by: Sage Weil <sage@newdream.net>
13 years agodaemon: Always advertise libvirtd service
Osier Yang [Tue, 11 Oct 2011 12:48:42 +0000 (20:48 +0800)]
daemon: Always advertise libvirtd service

This is a regression introduced by new RPC codes, previously
we advertise the service via ssh even if the daemon doesn't
listen on TLS port (TCP is not choosed). Now the service is
only advertised when it listens on TLS or TCP port. This breaks
upper layer apps which intends to discover the service, such
as virt-manager.

13 years agosnapshot: drop dead parameters
Eric Blake [Tue, 11 Oct 2011 23:34:19 +0000 (17:34 -0600)]
snapshot: drop dead parameters

The previous optimizations lead to some follow-on cleanups.

* src/conf/domain_conf.c (virDomainSnapshotForEachChild)
(virDomainSnapshotForEachDescendant): Drop dead parameter.
(virDomainSnapshotActOnDescendant)
(virDomainSnapshotObjListNumFrom)
(virDomainSnapshotObjListGetNamesFrom): Update callers.
* src/qemu/qemu_driver.c (qemuDomainSnapshotNumChildren)
(qemuDomainSnapshotListChildrenNames, qemuDomainSnapshotDelete):
Likewise.
* src/conf/domain_conf.h: Update prototypes.

13 years agosnapshot: take advantage of new relations
Eric Blake [Fri, 7 Oct 2011 21:25:18 +0000 (15:25 -0600)]
snapshot: take advantage of new relations

Among other improvements, virDomainSnapshotForEachDescendant is
changed from iterative O(n^2) to recursive O(n).  A bit better
than the O(n^3) implementation in virsh snapshot-list!

* src/conf/domain_conf.c (virDomainSnapshotObjListNum)
(virDomainSnapshotObjListNumFrom)
(virDomainSnapshotObjeListGetNames, virDomainSnapshotForEachChild)
(virDomainSnapshotForEachDescendant): Optimize.
(virDomainSnapshotActOnDescendant): Tweak.
(virDomainSnapshotActOnChild, virDomainSnapshotMarkDescendant):
Delete, now that they are unused.

13 years agosnapshot: track qemu snapshot relations
Eric Blake [Fri, 7 Oct 2011 21:00:03 +0000 (15:00 -0600)]
snapshot: track qemu snapshot relations

Maintain the parent/child relationships of all qemu snapshots.

* src/qemu/qemu_driver.c (qemuDomainSnapshotLoad): Populate
relationships after loading.
(qemuDomainSnapshotCreateXML): Set relations on creation; tweak
redefinition to reuse existing object.
(qemuDomainSnapshotReparentChildren, qemuDomainSnapshotDelete):
Clear relations on delete.

13 years agosnapshot: framework for more efficient relation traversal
Eric Blake [Fri, 7 Oct 2011 18:41:50 +0000 (12:41 -0600)]
snapshot: framework for more efficient relation traversal

No one was using virDomainSnapshotHasChildren, but that was an
O(n) function.  Exposing and tracking a bit more metadata for each
snapshot will allow the same query to be made with an O(1) query
of the member field.  For single snapshot operations (create,
delete), callers can be trusted to maintain the metadata themselves,
but for reloading, we can't compute parents as we go since there
is no guarantee that parents were parsed before children, so we also
provide a function to refresh the relationships, and which can
be used to detect if the user has ignored our warnings and been
directly modifying files in /var/lib/libvirt/qemu/snapshot.  This
patch only adds metadata; later patches will actually use it.

This layout intentionally hardcodes the size of each snapshot struct,
by tracking sibling pointers, rather than having to deal with the
headache of yet more memory management by directly sticking a
dynamically sized child[] on each parent.

* src/conf/domain_conf.h (_virDomainSnapshotObj)
(_virDomainSnapshotObjList): Add members.
(virDomainSnapshotUpdateRelations, virDomainSnapshotDropParent):
New prototypes.
(virDomainSnapshotHasChildren): Delete.
* src/conf/domain_conf.c (virDomainSnapshotSetRelations)
(virDomainSnapshotUpdateRelations, virDomainSnapshotDropParent):
New functions.
(virDomainSnapshotHasChildren): Drop unused function.
* src/libvirt_private.syms (domain_conf): Update exports.

13 years agosnapshot: use correct qmp monitor command
Eric Blake [Mon, 10 Oct 2011 20:20:38 +0000 (14:20 -0600)]
snapshot: use correct qmp monitor command

To date, JSON disk snapshots worked by accident, as they were always
using hmp fallback due to a typo in commit e702b5b not picking up
on the (intentional) difference in command names between the two
monitor protocols.

* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDiskSnapshot):
Spell QMP command correctly.
Reported by Luiz Capitulino.

13 years agosnapshot: virsh shorthand for operating on current snap
Eric Blake [Thu, 6 Oct 2011 21:01:18 +0000 (15:01 -0600)]
snapshot: virsh shorthand for operating on current snap

Rather than having to do:

$ virsh snapshot-revert dom $(virsh snapshot-current dom --name)

I thought it would be nice to do:

$ virsh snapshot-revert dom --current

I didn't add 'virsh snapshot-dumpxml --current' since we already have
'virsh snapshot-current' for the same task.  snapshot-list accepted
a name but did not require it, and that remains the case, with
--current serving in place of that name.  For all other commands,
name used to be required, and can now be replaced by --current;
I intentionally made it so that omitting both --current and a name
is an error (having the absence of a name imply --current seems
just a bit too magic, so --current must be explicit).  I also had
to keep snapshot-edit backwards-compatible, as the only command
that already had a --current argument alongside a name, which still
works to both edit a named snapshot and make it current.

* tools/virsh.c (vshLookupSnapshot): New helper function.
(cmdSnapshotEdit, cmdSnapshotList, cmdSnapshotParent)
(cmdSnapshotDelete, cmdDomainSnapshotRevert): Use it, adding an
option where needed.
* tools/virsh.pod (snapshot-delete, snapshot-edit)
(snapshot-list, snapshot-parent, snapshot-revert): Document
use of --current.
(snapshot-dumpxml): Mention alternative.

13 years agobuild: fix mingw build without sasl
Eric Blake [Tue, 11 Oct 2011 22:22:44 +0000 (16:22 -0600)]
build: fix mingw build without sasl

Detected by autogen.sh on a cross-mingw build:

Creating library file: .libs/libvirt.dll.a
Cannot export virNetSASLContextCheckIdentity: symbol not defined
Cannot export virNetSASLContextNewServer: symbol not defined
...

* src/libvirt_private.syms (virnetsaslcontext.h): Move symbols...
* src/libvirt_sasl.syms: ...to new file.
* src/Makefile.am (USED_SYM_FILES) [HAVE_SASL]: Use new file.
(EXTRA_DIST): Ship it.

13 years agobuild: fix 'make rpm'
Eric Blake [Tue, 11 Oct 2011 21:44:55 +0000 (15:44 -0600)]
build: fix 'make rpm'

Since commit ddf3bd3, 'make rpm' failed with:

RPM build errors:
    File not found: /home/remote/eblake/rpmbuild/BUILDROOT/libvirt-0.9.6-1.fc14.eblake1318366440.x86_64/usr/share/systemtap/tapset/libvirtd.stp

* libvirt.spec.in (with_dtrace): Match installed .stp files.

13 years agobuild: fix 'make distcheck'
Eric Blake [Tue, 11 Oct 2011 21:10:17 +0000 (15:10 -0600)]
build: fix 'make distcheck'

I got these distcheck failures with sanlock enabled:

ERROR: files left in build directory after distclean:
./tools/virt-sanlock-cleanup
./src/locking/qemu-sanlock.conf

* src/Makefile.am (DISTCLEANFILES) [HAVE_SANLOCK]: Clean built
file.
* tools/Makefile.am (DISTCLEANFILES): Likewise.

13 years agobuild: ship helper scripts
Eric Blake [Tue, 11 Oct 2011 20:33:43 +0000 (14:33 -0600)]
build: ship helper scripts

Otherwise, 'make rpm' fails with:

  GEN    libvirt_qemu.def
make[2]: *** No rule to make target `dtrace2systemtap.pl', needed by `libvirt_probes.stp'.  Stop.

* src/Makefile.am (EXTRA_DIST): Add recent script additions.

13 years agodisable xenlight for non-Xen platforms
Dan Horák [Tue, 11 Oct 2011 15:30:50 +0000 (17:30 +0200)]
disable xenlight for non-Xen platforms

when building libvirt in Fedora/s390x I've found that xenlight needs to
be explicitly disabled in the spec file. Configure properly sets the
library as non-existent, but the %files section still wants to package
the 3 /var/*/libvirt/libxl directories. See also
https://bugzilla.redhat.com/show_bug.cgi?id=745020

13 years agobuild: fix 'make check' linkage with dtrace
Eric Blake [Tue, 11 Oct 2011 19:18:37 +0000 (13:18 -0600)]
build: fix 'make check' linkage with dtrace

Building on Linux with dtrace enabled was failing 'make check':

  CCLD   nodeinfotest
../src/.libs/libvirt_test.a(libvirt_net_rpc_client_la-virnetclient.o): In function `virNetClientNew':
/home/remote/eblake/libvirt/src/rpc/virnetclient.c:162: undefined reference to `libvirt_rpc_client_new_semaphore'

On looking further, I see some earlier warnings emitted from libtool:

*** Warning: Linking the shared library libvirt.la against the non-libtool
*** objects  probes.o is not portable!

Since src/probes.o is only built on Linux, and even then, only when
dtrace is enabled, this failure does not affect other platforms, and
despite libtool warning that it is not generally portable, it is not
a problem for our use-case in libvirt.la.  But it turns out that while
libtool is willing to jam raw .o files into an installed shared
library (libvirt.la becomes libvirt.so), it is NOT willing to jam
the same .o file into the convenience library libvirt_test.la.
Perhaps this is a bug in libtool, but even if we get libtool fixed,
libvirt must continue to build on platforms with older libtool.  So,
the fix is the same as we are already using for the libvirt_lxc
executable - don't rely on the .o file being in the convenience
library, but instead use LDADD to pull it in directly.

* tests/Makefile.am (PROBES_O): New macro.
(LDADDS): Use it to fix link errors.

13 years agobuild: Fix VPATH build with new probes
Jiri Denemark [Tue, 11 Oct 2011 14:45:57 +0000 (16:45 +0200)]
build: Fix VPATH build with new probes

13 years agoFix deps for probes.o to ensure correct build ordering
Daniel P. Berrange [Tue, 11 Oct 2011 15:43:58 +0000 (16:43 +0100)]
Fix deps for probes.o to ensure correct build ordering

13 years agoUpdate examples for probing with systemtap
Daniel P. Berrange [Fri, 7 Oct 2011 15:36:05 +0000 (16:36 +0100)]
Update examples for probing with systemtap

This removes the old example for legacy probes and adds two
new scripts demonstrating many of the new probe point facilities.

The rpc-monitor.stp script will print out friendly details of all
RPC traffic between a libvirt client/server. This is incredibly
useful in seeing what RPC calls are being made, and also debugging
problems in the RPC protocol code

The events.stp script will print out lots of info about the poll
event loop, which is useful for debugging event handling problems

* examples/systemtap/events.stp, examples/systemtap/rpc-monitor.stp:
  New examples
* examples/systemtap/client.stp: Remove obsolete example

13 years agoRewrite all the DTrace/SystemTAP probing
Daniel P. Berrange [Fri, 30 Sep 2011 13:40:23 +0000 (14:40 +0100)]
Rewrite all the DTrace/SystemTAP probing

The libvirtd daemon had a few crude system tap probes. Some of
these were broken during the RPC rewrite. The new modular RPC
code is structured in a way that allows much more effective
tracing. Instead of trying to hook up the original probes,
define a new set of probes for the RPC and event code.

The master probes file is now src/probes.d.  This contains
probes for virNetServerClientPtr, virNetClientPtr, virSocketPtr
virNetTLSContextPtr and virNetTLSSessionPtr modules. Also add
probes for the poll event loop.

The src/dtrace2systemtap.pl script can convert the probes.d
file into a libvirt_probes.stp file to make use from systemtap
much simpler.

The src/rpc/gensystemtap.pl script can generate a set of
systemtap functions for translating RPC enum values into
printable strings. This works for all RPC header enums (program,
type, status, procedure) and also the authentication enum

The PROBE macro will automatically generate a VIR_DEBUG
statement, so any place with a PROBE can remove any existing
manual DEBUG statements.

* daemon/libvirtd.stp, daemon/probes.d: Remove obsolete probing
* daemon/libvirtd.h: Remove probe macros
* daemon/Makefile.am: Remove all probe buildings/install
* daemon/remote.c: Update authentication probes
* src/dtrace2systemtap.pl, src/rpc/gensystemtap.pl: Scripts
  to generate STP files
* src/internal.h: Add probe macros
* src/probes.d: Master list of probes
* src/rpc/virnetclient.c, src/rpc/virnetserverclient.c,
  src/rpc/virnetsocket.c, src/rpc/virnettlscontext.c,
  src/util/event_poll.c: Insert probe points, removing any
  DEBUG statements that duplicate the info

13 years agoFix missing lock calls on virNetTLSContextRef
Daniel P. Berrange [Fri, 7 Oct 2011 15:42:54 +0000 (16:42 +0100)]
Fix missing lock calls on virNetTLSContextRef

The virNetTLSContextRef API forgot to acquire/release the lock
while changing ctxt->refs

* src/rpc/virnettlscontext.c: Add lock calls

13 years agoRefactor TLS to facilitate dynamic probing
Daniel P. Berrange [Fri, 7 Oct 2011 15:42:41 +0000 (16:42 +0100)]
Refactor TLS to facilitate dynamic probing

Pull the call to gnutls_x509_crt_get_dn up into a higher function
so that the 'dname' variable will be available for probe points

* src/rpc/virnettlscontext.c: Pull gnutls_x509_crt_get_dn up
  one level