Commit Graph

5133 Commits

Author SHA1 Message Date
Daniel P. Berrange
c212160260 Fix reference handling leak on qemuMonitor
The current code pattern requires that callers of qemuMonitorClose
check for the return value == 0, and if so, set priv->mon = NULL
and release the reference held on the associated virDomainObjPtr

The change d84bb6d6a3 violated that
requirement, meaning that priv->mon never gets set to NULL, and
a reference count is leaked on virDomainObjPtr.

This design was a bad one, so remove the need to check the return
valueof qemuMonitorClose(). Instead allow registration of a
callback that's invoked just when the last reference on qemuMonitorPtr
is released.

Finally there was a potential reference leak in qemuConnectMonitor
in the failure path.

* src/qemu/qemu_monitor.c, src/qemu/qemu_monitor.h: Add a destroy
  callback invoked from qemuMonitorFree
* src/qemu/qemu_driver.c: Use the destroy callback to release the
  reference on virDomainObjPtr when the monitor is freed. Fix other
  potential reference count leak in connecting to monitor
2010-06-23 14:08:05 +01:00
Daniel P. Berrange
8d616decc5 Make checks for inactive QEMU guest more robust
Before issuing monitor commands it is neccessary to check whether
the guest is still running. Most places use virDomainIsActive()
correctly, but a few relied on 'priv->mon != NULL'. In theory
these should be equivalent, but the release of the last reference
count on priv->mon can be delayed a small amount of time until
the event handler is finally deregistered. A further ref counting
bug also means that priv->mon might be never released. In such a
case, code could mistakenly issue a monitor command and wait for
a response that will never arrive, effectively leaving the QEMU
driver waiting on virCondWait() forever..

To protect against these possibilities, make sure all code uses
virDomainIsActive(), not 'priv->mon != NULL'

* src/qemu/qemu_driver.c: Replace 'priv->mon != NULL' with
  calls to 'priv->mon != NULL'()
2010-06-23 14:08:05 +01:00
Daniel P. Berrange
9b0244ae38 Improve some error messages about unsupported APIs/URIs
If there is no driver for a URI we report

  "no hypervisor driver available"

This is bad because not all virt drivers are hypervisors (ie container
based virt).

If there is no driver support for an API we report

  "this function is not supported by the hypervisor"

This is bad for the same reason, and additionally because it is
also used for the network, interface & storage drivers.

* src/util/virterror.c: Improve error messages
2010-06-23 14:07:39 +01:00
Jiri Denemark
6c267f01b1 Don't leak open fd to virsh in libvirt-guests init script
Running virsh while having /var/lib/libvirt/libvirt-guests file open
makes SELinux emit messages about preventing virsh from reading that
file. Since virsh doesn't really want to read anything, it's better to
run it with /dev/null on stdin to prevent those messages.
2010-06-22 17:48:14 +02:00
Stefan Berger
cab5a52aa2 nwfilter: fix loadable module support
Following Daniel Berrange's multiple helpful suggestions for improving
this patch and introducing another driver interface, I now wrote the
below patch where the nwfilter driver registers the functions to
instantiate and teardown the nwfilters with a function in
conf/domain_nwfilter.c called virDomainConfNWFilterRegister. Previous
helper functions that were called from qemu_driver.c and qemu_conf.c
were move into conf/domain_nwfilter.h with slight renaming done for
consistency. Those functions now call the function expored by
domain_nwfilter.c, which in turn call the functions of the new driver
interface, if available.
2010-06-21 14:18:31 -04:00
Justin Clift
c7a33939bc virsh: remove a doubled up include for errno.h 2010-06-21 10:11:34 +02:00
Jiri Denemark
d147b18de2 Misc cleanups
- Fix documentation for virGetStorageVol: it has 'key' argument instead
  of 'uuid'.
- Remove TODO comment from virReleaseStorageVol: we use volume key as an
  identifier instead of UUID.
- Print human-readable UUID string in debug message in virReleaseSecret.
2010-06-21 10:11:34 +02:00
Jiri Denemark
72a7f8b2a9 Do not free static buffer with UUID
As anywhere else, uuid is defined as a fixed size array inside
_virSecret structure; we shouldn't try to free it.
2010-06-21 10:11:34 +02:00
Jiri Denemark
c5ec45a3a4 Remove unnecessary check for non-NULL uuid
The first thing we do in all these functions is to check uuid != NULL
and fail if it isn't.
2010-06-21 10:11:34 +02:00
Jiri Denemark
30ec755ecb Index hashes by UUID instead of name
Per-connection hashes for domains, networks, storage pools and network
filter pools were indexed by names which was not the best choice. UUIDs
are better identifiers, so lets use them.
2010-06-21 10:11:34 +02:00
Philipp Hahn
ff5f7d7204 Allow one-or-more <boot dev="..."/> entries
According to docs/formatdomain.html.in, "The boot element can be
repeated multiple times to setup a priority list of boot devices to try
in turn." The Relax-NG schema required / allowed exactly one entry.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2010-06-21 10:11:33 +02:00
Stefan Berger
7057f39c51 nwfilter: extensions of docs with
As requested, here a couple of paragraphs about the recently added statematch attribute and some advanced (and tricky) traffic filtering topics.
2010-06-18 13:44:17 -04:00
Cole Robinson
9edceb3233 Add ACK'd v2 changes for previous commit 2010-06-18 11:56:04 -04:00
Cole Robinson
58406dd54e qemu: Fix crash on failed VM startup
If VM startup fails early enough (can't find a referenced USB device),
libvirtd will crash trying to clear the VNC port bit, since port = 0,
which overflows us out of the bitmap bounds.

Fix this by being more defensive in the bitmap operations, and only
clearing a previously set VNC port.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
2010-06-18 10:14:34 -04:00
Philipp Hahn
08fee18cc2 Fix description of virStorageVolGetInfo()
Probably a copy-paste-bug in python/libvirt-override-api.xml:
virStorageVolGetInfo() extracts information about a "storage volume",
not the "storage pool" as virStoragePoolGetInfo() does.

Signed-off-by: Philipp Hahn <hahn@univention.de>
2010-06-18 12:57:54 +02:00
Justin Clift
2b39cd355a virsh: add --uuid option to vol-pool
Adds an optional switch, --uuid, for telling the virsh vol-pool command
to return the pool UUID rather than pool name.
2010-06-17 14:45:34 -06:00
Eric Blake
322b1fd44b qemu: reduce file padding requirements
Followup to https://bugzilla.redhat.com/show_bug.cgi?id=599091,
commit 20206a4b, to reduce disk waste in padding.

* src/qemu/qemu_monitor.h (QEMU_MONITOR_MIGRATE_TO_FILE_BS): Drop
back to 4k.
(QEMU_MONITOR_MIGRATE_TO_FILE_TRANSFER_SIZE): New macro.
* src/qemu/qemu_driver.c (qemudDomainSaveFlag): Update comment.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextMigrateToFile): Use
two invocations of dd to output non-aligned large blocks.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMigrateToFile):
Likewise.
2010-06-17 13:29:16 -06:00
Stefan Berger
51d3fb0276 nwfilter: add XML attribute to control iptables state match
This patch adds an optional XML attribute to a nwfilter rule to give the user control over whether the rule is supposed to be using the iptables state match or not. A rule may now look like shown in the XML below with the statematch attribute either having value '0' or 'false' (case-insensitive).

[...]
<rule action='accept' direction='in' statematch='false'>
<tcp srcmacaddr='1:2:3:4:5:6'
           srcipaddr='10.1.2.3' srcipmask='32'
           dscp='33'
           srcportstart='20' srcportend='21'
           dstportstart='100' dstportend='1111'/>
</rule>
[...]

I am also extending the nwfilter schema and add this attribute to a test case.
2010-06-17 14:12:34 -04:00
Justin Clift
c2160b137d virsh: ensure persistence and autostart are shown for dominfo and pool-info
This patch adds the persistence status (yes/no) to the output of the virsh
dominfo and pool-info commands.  This patch also adds the autostart status
to the output of the virsh pool-info command.

Red Hat BZ for this:

  https://bugzilla.redhat.com/show_bug.cgi?id=603696
2010-06-17 11:57:54 -06:00
Eduardo Otubo
788269e970 phyp: adding support for IVM
Use virBuffer* API to conditionally keep the portion of the command
line specific to HMC, so that IVM can work.

Signed-off-by: Eric Blake <eblake@redhat.com>
2010-06-17 11:49:09 -06:00
Stefan Berger
2dce970162 nwfilter: use match target on incoming traffic
The following patch enables the iptables match target to be used by
default for incoming traffic. So far it has only be used for outgoing
traffic.
2010-06-17 07:15:20 -04:00
Stefan Berger
045a5722ab macvtap: work-around for 2.6.32 and older kernels
This patch works around a recent extension of the netlink driver I had made use of when building the netlink messages. Unfortunately older kernels don't accept IFLA_IFNAME + name of interface as a replacement for the interface's index, so this patch now gets the interface index ifindex if it's not provided (ifindex <= 0).
2010-06-17 07:05:38 -04:00
Justin Clift
07be2403b6 virsh: change printf() calls to vshPrint()
Trivial fix changing printf() calls to vshPrint() where the ctl
variable is available.
2010-06-16 17:17:08 -06:00
Justin Clift
7d38d7b49b virsh: improve help text for vol query commands
Improves the help text for vol-path, vol-name, and vol-key, which
previously referred to volume UUIDs.

Addresses BZ # 598365.
2010-06-16 16:32:05 -06:00
Justin Clift
31495ef6a1 virsh: add pool support to vol-key command
Presently the vol-key command only supports being provided with
a volume path.

This patch adds support for providing it with a pool and volume
identifier pair as well.

    virsh # vol-key --pool <pool-name-or-uuid> <vol-name-or-path>
2010-06-16 16:32:05 -06:00
Matthias Bolte
08d42b52f1 Add several missing vir*Free calls in libvirtd's remote code
Justin Clift reported a problem with adding virStoragePoolIsPersistent
to virsh's pool-info command, resulting in a strange problem. Here's
an example:

    virsh # pool-create-as images_dir3 dir - - - - "/home/images2"
    Pool images_dir3 created

    virsh # pool-info images_dir3
    Name:           images_dir3
    UUID:           90301885-94eb-4ca7-14c2-f30b25a29a36
    State:          running
    Capacity:       395.20 GB
    Allocation:     30.88 GB
    Available:      364.33 GB

    virsh # pool-destroy images_dir3
    Pool images_dir3 destroyed

At this point the images_dir3 pool should be gone (because it was
transient) and we should be able to create a new pool with the same name:

    virsh # pool-create-as images_dir3 dir - - - - "/home/images2"
    Pool images_dir3 created

    virsh # pool-info images_dir3
    Name:           images_dir3
    UUID:           90301885-94eb-4ca7-14c2-f30b25a29a36
    error: Storage pool not found

The new pool got the same UUID as the first one, but we didn't specify
one. libvirt should have picked a random UUID, but it didn't.

It turned out that virStoragePoolIsPersistent leaks a reference to the
storage pool object (actually remoteDispatchStoragePoolIsPersistent does).
As a result, pool-destroy doesn't remove the virStoragePool for the
"images_dir3" pool from the virConnectPtr's storagePools hash on libvirtd's
side. Then the second pool-create-as get's the stale virStoragePool object
associated with the "images_dir3" name. But this object has the old UUID.

This commit ensures that all get_nonnull_* and make_nonnull_* calls for
libvirt objects are matched properly with vir*Free calls. This fixes the
reference leaks and the reported problem.

All remoteDispatch*IsActive and remoteDispatch*IsPersistent functions were
affected. But also remoteDispatchDomainMigrateFinish2 was affected in the
success path. I wonder why that didn't surface earlier. Probably because
domainMigrateFinish2 is executed on the destination host and in the common
case this connection is opened especially for the migration and gets closed
after the migration is done. So there was no chance to run into a problem
because of the leaked reference.
2010-06-16 23:06:12 +02:00
Matthias Bolte
02d57c2bce esx: Update case insensitive .vmx tests
Commit b9efc7dc3b made virFileHasSuffix
case insensitive. Honor this in the tests by switching vmdk to VMDK.
2010-06-16 23:06:12 +02:00
Matthias Bolte
b0f414c67b esx: Accept 'disk' as harddisk device type in .vmx files 2010-06-16 23:06:12 +02:00
Eric Blake
02988742b7 phyp: sed cleanups
* src/phyp/phyp_driver.c (phypNumDomainsGeneric): Avoid glob
collision by quoting sed argument.
(phypDomainSetCPU): Avoid non-portable \+ in sed.
(phypGetVIOSPartitionID, phypDiskType, phypListDomainsGeneric)
(phypListDefinedDomains): Micro-optimize anchored substitutions.
2010-06-16 14:08:44 -06:00
Justin Clift
043f05fda4 virsh: mark autostart answers for translation
This is a trivial fix for several autostart yes/no strings that
weren't correctly marked for translation.
2010-06-15 15:36:27 -06:00
Eric Blake
cbe6ebdb53 virsh: add start --paused support
Make 'start --paused' mirror 'create --paused'.

* tools/virsh.c (cmdStart): Use new virDomainCreateWithFlags API
when needed.
* tools/virsh.pod (start): Document --paused.
2010-06-15 09:50:58 -06:00
Eric Blake
d024d2ba36 qemu: support starting persistent domain paused
Match earlier change for qemu pause support with virDomainCreateXML.

* src/qemu/qemu_driver.c (qemudDomainObjStart): Add parameter; all
callers changed.
(qemudDomainStartWithFlags): Implement flag support.
2010-06-15 09:37:11 -06:00
Eric Blake
de3aadaa71 drivers: add virDomainCreateWithFlags if virDomainCreate exists
* src/esx/esx_driver.c (esxDomainCreate): Move guts...
(esxDomainCreateWithFlags): ...to new function.
(esxDriver): Trivially support the new API.
* src/lxc/lxc_driver.c (lxcDomainStart, lxcDomainStartWithFlags)
(lxcDriver): Likewise.
* src/opennebula/one_driver.c (oneDomainStart)
(oneDomainStartWithFlags, oneDriver): Likewise.
* src/openvz/openvz_driver.c (openvzDomainCreate)
(openvzDomainCreateWithFlags, openvzDriver): Likewise.
* src/qemu/qemu_driver.c (qemudDomainStart)
(qemudDomainStartWithFlags, qemuDriver): Likewise.
* src/test/test_driver.c (testDomainCreate)
(testDomainCreateWithFlags, testDriver): Likewise.
* src/uml/uml_driver.c (umlDomainStart, umlDomainStartWithFlags)
(umlDriver): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainCreate)
(vboxDomainCreateWithFlags, Driver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDomainCreate)
(xenUnifiedDomainCreateWithFlags, xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDomainCreate)
(xenapiDomainCreateWithFlags, xenapiDriver): Likewise.
2010-06-15 09:37:11 -06:00
Eric Blake
6c83e7ca6f remote: protocol implementation for virDomainCreateWithFlags
Define the wire format for the new virDomainCreateWithFlags
API, and implement client and server side of marshaling code.

* daemon/remote.c (remoteDispatchDomainCreateWithFlags): Add
server side dispatch for virDomainCreateWithFlags.
* src/remote/remote_driver.c (remoteDomainCreateWithFlags)
(remote_driver): Client side serialization.
* src/remote/remote_protocol.x
(remote_domain_create_with_flags_args)
(remote_domain_create_with_flags_ret)
(REMOTE_PROC_DOMAIN_CREATE_WITH_FLAGS): Define wire format.
* daemon/remote_dispatch_args.h: Regenerate.
* daemon/remote_dispatch_prototypes.h: Likewise.
* daemon/remote_dispatch_table.h: Likewise.
* src/remote/remote_protocol.c: Likewise.
* src/remote/remote_protocol.h: Likewise.
* src/remote_protocol-structs: Likewise.
2010-06-15 09:37:04 -06:00
Eric Blake
460ca88b98 libvirt: introduce domainCreateWithFlags API
Persistent domain creation needs the same features as transient
domains, but virDomainCreate lacks the flags argument present in
virDomainCreateXML.  virDomainCreateFlags is already claimed as
a public enum, so we have to break convention and expose
virDomainCreateWithFlags.

* include/libvirt/libvirt.h.in (virDomainCreateWithFlags): Add.
* src/driver.h (virDrvDomainCreateWithFlags): Internal API.
* src/libvirt.c (virDomainCreateWithFlags): Glue public API to
driver API.
* src/libvirt_public.syms (LIBVIRT_0.8.2): Expose public API.
* src/esx/esx_driver.c (esxDriver): Add stub for driver.
* src/lxc/lxc_driver.c (lxcDriver): Likewise.
* src/opennebula/one_driver.c (oneDriver): Likewise.
* src/openvz/openvz_driver.c (openvzDriver): Likewise.
* src/phyp/phyp_driver.c (phypDriver): Likewise.
* src/qemu/qemu_driver.c (qemuDriver): Likewise.
* src/remote/remote_driver.c (remote_driver): Likewise.
* src/test/test_driver.c (testDriver): Likewise.
* src/uml/uml_driver.c (umlDriver): Likewise.
* src/vbox/vbox_tmpl.c (Driver): Likewise.
* src/xen/xen_driver.c (xenUnifiedDriver): Likewise.
* src/xenapi/xenapi_driver.c (xenapiDriver): Likewise.
2010-06-15 07:32:41 -06:00
Eric Blake
fb8552f83a maint: simplify some ignore files
* .hgignore: Delete, no longer used.
* examples/python/.gitignore: Delete, covered globally.
* include/.gitignore: Likewise.
* python/tests/.gitignore: Likewise.
* docs/schemas/.gitignore: Likewise.
* tests/xml2sexprdata/.gitignore: Likewise.
* tests/sexpr2xmldata/.gitignore: Likewise.
* tests/confdata/.gitignore: Likewise.
* tests/xencapsdata/.gitignore: Likewise.
* tests/xmconfigdata/.gitignore: Likewise.
* tests/xml2sexprdata/.gitignore: Likewise.
2010-06-15 07:31:10 -06:00
Eric Blake
352b6df34d parthelper: fix compilation without optimization
Daniel's patch works with gcc and CFLAGS containing -O (the
autoconf default), but fails with non-gcc or with other
CFLAGS (such as -g), since c-ctype.h declares c_isdigit as
a macro only for certain compilation settings.

* src/Makefile.am (libvirt_parthelper_LDFLAGS): Add gnulib
library, for when c_isdigit is not a macro.
* src/storage/parthelper.c (main): Avoid out-of-bounds
dereference, noticed by Jim Meyering.
2010-06-14 15:11:49 -06:00
Daniel P. Berrange
bc8d9f2077 Fix enumeration of partitions in disks with a trailing digit in path
Disks with a trailing digit in their path (eg /dev/loop0 or
/dev/dm0) have an extra 'p' appended before the partition
number (eg, to form /dev/loop0p1 not /dev/loop01). Fix the
partition lookup to append this extra 'p' when required

* src/storage/parthelper.c: Add a 'p' before partition
  number if required
2010-06-14 14:55:23 -06:00
Eric Blake
582c75ec45 uml: sanity check external data before using it
Otherwise, a malicious packet could cause a DoS via spurious
out-of-memory failure.

* src/uml/uml_driver.c (umlMonitorCommand): Validate that incoming
data is reliable before using it to allocate/dereference memory.
Don't report bogus errno on short read.
Reported by Jim Meyering.
2010-06-11 10:33:09 -06:00
Matthias Bolte
d0dabc2bf8 Improve error message for disabled client-side drivers
Report that libvirt was built without that driver instead of
trying to connect to a libvirtd, when we know that this is
going to fail.
2010-06-11 18:24:13 +02:00
Matthias Bolte
1443cbe840 vbox: check getenv("DISPLAY") for NULL in vboxDomainDumpXML
Otherwise this will segfault if DISPLAY is not defined.
2010-06-10 22:39:49 +02:00
Matthias Bolte
fc1da688c0 Check getenv("PATH") for NULL in virFindFileInPath
Otherwise this will segfault if PATH is not defined.

Reported by Emre Erenoglu
2010-06-10 22:39:11 +02:00
Justin Clift
b28a068b43 virsh: add snapshot backing store support to vol-create-as
This patch adds two new parameters to the vol-create-as command:

 --backing-vol <volume-name-or-key-or-path>
 --backing-vol-format <format-of-backing-vol>

  virsh # vol-create-as guest_images_lvm snapvol1 5G --backing-vol \
              rhel6vm1lun1
  Vol snapvol1 created

  virsh # vol-create-as image_dir qcow2snap2 5G --format qcow2 \
              --backing-vol imagevol1.qcow2 \
              --backing-vol-format qcow2
  Vol qcow2snap2 created

Additionally, the virsh man page update fixes incorrect snapshot
parameters that were included in my prior bulk volume command patch.
2010-06-10 12:03:13 -06:00
Eric Blake
3cf642a0f9 build: fix some mingw issues
On Fedora 13 with sufficient mingw32-* packages installed, running
./autobuild.sh failed to cross-compile to mingw because
mingw32-pthreads installed a broken <pthread.h>.  With that
issue fixed, the build still failed due to use of O_SYNC.
Meanwhile, recent .spec.in changes got out of sync.

* bootstrap.conf (gnulib_modules): Add fcntl-h, for O_SYNC.
* .gnulib: Update to latest, to work around buggy pthreads-win32
library.
* bootstrap: Import latest from gnulib.
* mingw32-libvirt.spec.in: Distribute new file.
2010-06-10 06:05:31 -06:00
Eric Blake
6e5a04f034 build: avoid pthreads-win32 on mingw
* src/util/threads.c (includes) [WIN32]: On mingw, favor native
threading over pthreads-win32 library.
* src/util/thread.h [WIN32] Likewise.
Suggested by Daniel P. Berrange.
2010-06-10 06:05:31 -06:00
Daniel P. Berrange
c37c321cc2 Fix cgroup setup code to cope with root squashing NFS
When a disk is on a root squashed NFS server, it may not be
possible to stat() the disk file in virCgroupAllowDevice.
The virStorageFileGetMeta method may also fail to extract
the parent backing store. Both of these errors have to be
ignored to avoid breaking NFS deployments

* src/qemu/qemu_driver.c: Ignore errors in cgroup setup to
   keep root squash NFS happy
2010-06-09 09:44:20 -04:00
Justin Clift
c09f663a47 virsh: fixed trivial comment and debug message in vshCommandOptVolBy function 2010-06-09 06:16:54 -06:00
Justin Clift
74231267f8 virsh: remove xen reference in header comment
With libvirt and virsh now being used for much more than Xen, this
patch removes the outdated reference to Xen in the file header.
2010-06-09 05:18:27 -06:00
Matthias Bolte
46c14d2045 esx: Add proxy query parameter
Allow to specify a proxy to be used by libcurl.
2010-06-09 12:55:02 +02:00
Matthias Bolte
070f61002f esx: Refactor esxUtil_ParseQuery's parameter handling
Pass a struct containing the parameters instead of passing each
one individually. This make future extensions a bit simpler.
2010-06-09 11:29:09 +02:00