]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
11 years agoutil: fix uint parsing on 64-bit platforms
Eric Blake [Wed, 30 Apr 2014 20:46:18 +0000 (14:46 -0600)]
util: fix uint parsing on 64-bit platforms

Commit f22b7899 called to light a long-standing latent bug: the
behavior of virStrToLong_ui was different on 32-bit platforms
than on 64-bit platforms.  Curse you, C type promotion and
narrowing rules, and strtoul specification.  POSIX says that for
a 32-bit long, strtol handles only 2^32 values [LONG_MIN to
LONG_MAX] while strtoul handles 2^33 - 1 values [-ULONG_MAX to
ULONG_MAX] with twos-complement wraparound for negatives.  Thus,
parsing -1 as unsigned long produces ULONG_MAX, rather than a
range error.  We WANT[1] this same shortcut for turning -1 into
UINT_MAX when parsing to int; and get it for free with 32-bit
long.  But with 64-bit long, ULONG_MAX is outside the range
of int and we were rejecting it as invalid; meanwhile, we were
silently treating -18446744073709551615 as 1 even though it
textually exceeds INT_MIN.  Too bad there's not a strtoui() in
libc that does guaranteed parsing to int, regardless of the size
of long.

The bug has been latent since 2007, introduced by Jim Meyering
in commit 5d25419 in the attempt to eradicate unsafe use of
strto[u]l when parsing ints and longs.  How embarrassing that we
are only discovering it now - so I'm adding a testsuite to ensure
that it covers all the corner cases we care about.

[1] Ideally, we really want the caller to be able to choose whether
to allow negative numbers to wrap around to their 2s-complement
counterpart, as in strtoul, or to force a stricter input range
of [0 to UINT_MAX] by rejecting negative signs; this will be added
in a later patch for all three int types.

This patch is tested on both 32- and 64-bit; the enhanced
virstringtest passes on both platforms, while virstoragetest now
reliably fails on both platforms instead of just 32-bit platforms.
That test will be fixed later.

* src/util/virstring.c (virStrToLong_ui): Ensure same behavior
regardless of platform long size.
* tests/virstringtest.c (testStringToLong): New function.
(mymain): Comprehensively test string to long parsing.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoMisc error reporting bugs in QEMU cli builder
Daniel P. Berrange [Thu, 1 May 2014 16:24:45 +0000 (17:24 +0100)]
Misc error reporting bugs in QEMU cli builder

A couple of places in the QEMU XML -> ARGV conversion code
raised an error but then forgot to return an error status
due to missing gotos. While fixing this also tweak style
of a couple of other error reports

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoqemu: fix crash when removing <filterref> from interface with update-device
Laine Stump [Thu, 1 May 2014 08:40:41 +0000 (11:40 +0300)]
qemu: fix crash when removing <filterref> from interface with update-device

If a domain network interface that contains a <filterref> is modified
"live" using "virsh update-device --live", libvirtd would crash. This
was because the code supporting live update of an interface's
filterref was assuming that a filterref might be added or modified,
but didn't account for removing the filterref, resulting in a null
dereference of the filter name.

Introduced with commit 258fb278, which was first in libvirt v1.0.1.

This addresses https://bugzilla.redhat.com/show_bug.cgi?id=1093301

11 years agostorage: Clear all data allocated about backing store before reparsing
Peter Krempa [Sat, 26 Apr 2014 06:27:58 +0000 (08:27 +0200)]
storage: Clear all data allocated about backing store before reparsing

To avoid memory leak of the "backingStoreRaw" field when reparsing
backing chains a new function is being introduced by this patch that
shall be used to clear backing store information.

The memory leak was introduced in commit 8823272d41a259c1246c05d.

11 years agonwfilter: Tear down temp. filters when tearing all filters
Stefan Berger [Wed, 30 Apr 2014 16:51:38 +0000 (12:51 -0400)]
nwfilter: Tear down temp. filters when tearing all filters

Refactor the ebiptablesTearNewRules function so that the teardown of temporary
filters can also be called by the ebiptablesAllTeardown function.

This fixes a problem that leaves temporary filters behind when a VM shuts down
while its filters are modified.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
v1->v2:
  - test cases adjusted to expect more commands

11 years agoDevice{Attach,Detach}: Document S4 limitations
Michal Privoznik [Wed, 30 Apr 2014 13:50:34 +0000 (15:50 +0200)]
Device{Attach,Detach}: Document S4 limitations

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

Well, libvirt doesn't distinguish between domain poweroff and
hibernation (S4). It's hard to differentiate these two on a real
machine anyway. As a result, any device that is hot(un-)plugged is
lost (appears again) when domain is started again as from our POV
it is a fresh cold boot. Instead of doing anything wise here, we
should just document this as known limitation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
11 years agoSet mknod permission in device ACL for LXC USB devices
Daniel P. Berrange [Wed, 30 Apr 2014 13:57:51 +0000 (14:57 +0100)]
Set mknod permission in device ACL for LXC USB devices

The LXC controller itself needs to mknod the USB device
node in /dev/bus/usb, so we can't block mknod permission
from the cgroup.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agonwfilter: Validate rule after parsing
Stefan Berger [Wed, 30 Apr 2014 15:41:18 +0000 (11:41 -0400)]
nwfilter: Validate rule after parsing

An IP or IPv6 rule with port specification but without protocol
specification cannot be instantiated by ebtables. The documentation
points to 'protocol' being required but implementation does not
enforce it to be given.

Implement a rule validation function that checks whether the rule is
valid when it is defined. This for example prevents the definition
of rules like:

<ip dstportstart='53'>

where a protocol attribute would be required for it to be valid and for
ebtables to be able to instantiate it. A valid rule then is:

<ip protocol='udp' dstportstart='53'>

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
11 years agoAdd a new example to illustrate domain migration
Sahid Orentino Ferdjaoui [Fri, 11 Apr 2014 18:44:32 +0000 (18:44 +0000)]
Add a new example to illustrate domain migration

This commit adds a new example to illustrate peer to
peer domain migration with virDomainMigrateToURI.

Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
11 years agoAdd support for QEMU migration to use SASL authentication
Sahid Orentino Ferdjaoui [Fri, 11 Apr 2014 19:17:47 +0000 (19:17 +0000)]
Add support for QEMU migration to use SASL authentication

This commit provides the ability to virDomainMigrateToURI to
check for SASL credentials when attempts to migrate a domain
with the driver QEMU.

Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@cloudwatt.com>
11 years agonetworkxml2firewalltest: fix build failure on freebsd
Pavel Hrdina [Wed, 30 Apr 2014 08:16:09 +0000 (10:16 +0200)]
networkxml2firewalltest: fix build failure on freebsd

We need to include the testutils.h also for freebsd.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
11 years agovirfirewall: fix build on freebsd
Pavel Hrdina [Wed, 30 Apr 2014 06:51:29 +0000 (08:51 +0200)]
virfirewall: fix build on freebsd

Freebsd doesn't know ENODATA so we have to use different EINVAL
error code.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
11 years agoconf: avoid null deref during storage probe
Eric Blake [Tue, 29 Apr 2014 03:26:10 +0000 (21:26 -0600)]
conf: avoid null deref during storage probe

Commit 5c43e2e introduced a NULL deref if there is a failure
in virStorageFileGetMetadataInternal.

* src/util/virstoragefile.c (virStorageFileGetMetadataFromBuf):
Fix error handling.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoDisable libvirtd by default when building on Win32
Daniel P. Berrange [Mon, 28 Apr 2014 12:30:36 +0000 (13:30 +0100)]
Disable libvirtd by default when building on Win32

We don't support building libvirtd on Win32 since we lack the
fork/exec feature needed for the stateful drivers. Disable this
by default, so users can just do 'mingw32-configure' with no
special args required.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoDon't use SO_REUSEADDR on Win32 platforms
Daniel P. Berrange [Fri, 25 Apr 2014 16:47:08 +0000 (17:47 +0100)]
Don't use SO_REUSEADDR on Win32 platforms

SO_REUSEADDR on Windows is actually akin to SO_REUSEPORT
on Linux/BSD. ie it allows 2 apps to listen to the same
port at once. Thus we must not set it on Win32 platforms

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms740621.aspx

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoqemu: properly quit migration with abort_on_error
Martin Kletzander [Thu, 24 Apr 2014 14:28:36 +0000 (16:28 +0200)]
qemu: properly quit migration with abort_on_error

When EIO comes to qemu while it's replying to
qemuMigrationUpdateJobStatus(), qemu blocks, the migration of RAM can
complete in the meantime, and when qemu unblocks, it sends us
BLOCK_IO_ERROR plus migrations "status": "complete".  Even though we
act upon the BLOCK_IO_ERROR by setting the proper state of the domain,
the call still waits for the proper reply on monitor for query_migrate
and after it gets it, it checks that migration is completed and the
migration is finished.  This is what abort_on_error flag was meant for
(we can migrate with these errors, but this flag must inhibit such
behaviour).  Changing the order of the steps guarantees the flag works
properly.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agoqemu: don't call virFileExists() for network type disks
Martin Kletzander [Tue, 29 Apr 2014 07:20:26 +0000 (09:20 +0200)]
qemu: don't call virFileExists() for network type disks

Based on suggestion from Eric [1], because it might not get cleaned up
before the release, so to avoid potential errors.

[1] https://www.redhat.com/archives/libvir-list/2014-April/msg00929.html

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agodocs: update docs for setting the QEMU BIOS path
Chen Hanxiao [Tue, 29 Apr 2014 07:47:26 +0000 (15:47 +0800)]
docs: update docs for setting the QEMU BIOS path

commit ddf2dfa1f79af0405df5ca10583764a497c7a0db
provided a way to determine which bios files to use.
But we need to update related docs.

disccussed at:
http://www.redhat.com/archives/libvir-list/2012-June/msg01286.html

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agostorage_backend_rbd: Correct argument order to rbd_create3
Steven McDonald [Tue, 29 Apr 2014 02:19:01 +0000 (12:19 +1000)]
storage_backend_rbd: Correct argument order to rbd_create3

The stripe_unit and stripe_count arguments are passed to rbd_create3 in
the wrong order, resulting in a stripe size of 1 byte with 4194304
stripes on newly created RBD volumes.

https://bugzilla.redhat.com/show_bug.cgi?id=1092208
Signed-off-by: Steven McDonald <steven.mcdonald@anchor.net.au>
11 years agoenforce sane readdir usage
Eric Blake [Mon, 21 Apr 2014 22:33:15 +0000 (16:33 -0600)]
enforce sane readdir usage

Now that all clients have been adjusted, ensure that no future
misuse of readdir is introduced into the code base.

* cfg.mk (sc_prohibit_readdir): New rule.
* src/util/virfile.c (virDirRead): Exempt the wrapper.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agonetwork: use virDirRead in networkMigrateStateFiles
Laine Stump [Mon, 28 Apr 2014 10:45:15 +0000 (13:45 +0300)]
network: use virDirRead in networkMigrateStateFiles

This attempts to follow the same variable name and usage patterns as
the other conversions to virDirRead().

11 years agostorage: use virDirRead API
Eric Blake [Thu, 24 Apr 2014 21:48:55 +0000 (15:48 -0600)]
storage: use virDirRead API

More instances of failure to report (unlikely) readdir errors.
In one case, I chose to ignore them, given that a readdir error
would be no different than timing out on the loop, where the
fallback path behaves correctly either way.

* src/storage/storage_backend.c (virStorageBackendStablePath):
Ignore readdir errors.
* src/storage/storage_backend_fs.c
(virStorageBackendFileSystemRefresh): Report readdir errors.
* src/storage/storage_backend_iscsi.c
(virStorageBackendISCSIGetHostNumber): Likewise.
* src/storage/storage_backend_scsi.c (getNewStyleBlockDevice)
(getBlockDevice, virStorageBackendSCSIFindLUs): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agodrivers: use virDirRead API
Eric Blake [Sat, 26 Apr 2014 04:11:05 +0000 (22:11 -0600)]
drivers: use virDirRead API

Convert all remaining clients of readdir to use the new
interface, so that we can ensure (unlikely) errors while
reading a directory are reported.

* src/openvz/openvz_conf.c (openvzAssignUUIDs): Use new
interface.
* src/parallels/parallels_storage.c (parallelsFindVolumes)
(parallelsFindVmVolumes): Report readdir failures.
* src/qemu/qemu_driver.c (qemuDomainSnapshotLoad): Ignore readdir
failures.
* src/secret/secret_driver.c (loadSecrets): Likewise.
* src/qemu/qemu_hostdev.c
(qemuHostdevHostSupportsPassthroughVFIO): Report readdir failures.
* src/xen/xen_inotify.c (xenInotifyOpen): Likewise.
* src/xen/xm_internal.c (xenXMConfigCacheRefresh): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoutil: use virDirRead API
Eric Blake [Fri, 25 Apr 2014 20:45:49 +0000 (14:45 -0600)]
util: use virDirRead API

In making the conversion to the new API, I fixed a couple bugs:
virSCSIDeviceGetSgName would leak memory if a directory
unexpectedly contained multiple entries;
virNetDevTapGetRealDeviceName could report a spurious error
from a stale errno inherited before starting the readdir search.

The decision on whether to store the result of virDirRead into
a variable is based on whether the end of the loop falls through
to cleanup code automatically.  In some cases, we have loops that
are documented to return NULL on failure, and which raise an
error on most failure paths but not in the case where the directory
was unexpectedly empty; it may be worth a followup patch to
explicitly report an error if readdir was successful but the
directory was empty, so that a NULL return always has an error set.

* src/util/vircgroup.c (virCgroupRemoveRecursively): Use new
interface.
(virCgroupKillRecursiveInternal, virCgroupSetOwner): Report
readdir failures.
* src/util/virfile.c (virFileLoopDeviceOpenSearch)
(virFileNBDDeviceFindUnused, virFileDeleteTree): Use new
interface.
* src/util/virnetdevtap.c (virNetDevTapGetRealDeviceName):
Properly check readdir errors.
* src/util/virpci.c (virPCIDeviceIterDevices)
(virPCIDeviceFileIterate, virPCIGetNetName): Report readdir
failures.
(virPCIDeviceAddressIOMMUGroupIterate): Use new interface.
* src/util/virscsi.c (virSCSIDeviceGetSgName): Report readdir
failures, and avoid memory leak.
(virSCSIDeviceGetDevName): Report readdir failures.
* src/util/virusb.c (virUSBDeviceSearch): Report readdir
failures.
* src/util/virutil.c (virGetFCHostNameByWWN)
(virFindFCHostCapableVport): Report readdir failures.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoconf: use virDirRead API
Eric Blake [Thu, 24 Apr 2014 04:27:44 +0000 (22:27 -0600)]
conf: use virDirRead API

When reading configuration files, we were silently ignoring
directory read failures.  While unlikely, we might as well
report them.

* src/conf/domain_conf.c (virDomainObjListLoadAllConfigs): Report
readdir errors.
* src/conf/network_conf.c (virNetworkLoadAllState)
(virNetworkLoadAllConfigs): Likewise.
* src/conf/nwfilter_conf.c (virNWFilterLoadAllConfigs): Likewise.
* src/conf/storage_conf.c (virStoragePoolLoadAllConfigs):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agonodeinfo: use virDirRead API
Natanael Copa [Sun, 20 Apr 2014 11:53:46 +0000 (13:53 +0200)]
nodeinfo: use virDirRead API

This makes sure that errno is reset before readdir is called, even if
the loop does a 'continue'.

This fixes issue with musl libc which sets errno on sscanf. The
following 'continue' makes the errno be set before calling readdir.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agoutil: introduce virDirRead wrapper for readdir
Natanael Copa [Sun, 20 Apr 2014 11:53:45 +0000 (13:53 +0200)]
util: introduce virDirRead wrapper for readdir

Introduce a wrapper for readdir. This helps us make sure that we always
set errno before calling readdir and it will make sure errors are
properly logged.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agotests: remove hostdevmgr directory on cleanup
Martin Kletzander [Mon, 28 Apr 2014 13:34:52 +0000 (15:34 +0200)]
tests: remove hostdevmgr directory on cleanup

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agoxen: ensure /usr/sbin/xend exists before checking status
Jim Fehlig [Mon, 28 Apr 2014 18:35:44 +0000 (12:35 -0600)]
xen: ensure /usr/sbin/xend exists before checking status

With xend on the way out, installations may not even have
/usr/sbin/xend, which results in the following error when the
drivers are probed

2014-04-28 18:21:19.271+0000: 22129: error : virCommandWait:2426 :
internal error: Child process (/usr/sbin/xend status) unexpected exit
status 127: libvirt:  error : cannot execute binary /usr/sbin/xend:
No such file or directory

Check for existence of /usr/sbin/xend before trying to run it with
the 'status' option.

11 years agoRemove bogus ATTRIBUTE_NONNULL from virFirewallAddRuleFull
Daniel P. Berrange [Mon, 28 Apr 2014 13:17:15 +0000 (14:17 +0100)]
Remove bogus ATTRIBUTE_NONNULL from virFirewallAddRuleFull

The virFirewallAddRuleFull method originally had a single
compulsory virFirewallQueryCallback parameter. During dev
work though the ignoreErrors parameter was added and the
callback parameter made optional. The ATTRIBUTE_NONNULL
annotation was never removed though.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoMake autostart of virtlockd actually work
Daniel P. Berrange [Fri, 25 Apr 2014 11:21:57 +0000 (12:21 +0100)]
Make autostart of virtlockd actually work

The virnetsocket.c API is hardcoded to pass --timeout=30 to
any daemon it auto-starts. For inexplicable reasons the virtlockd
daemon did not implement the --timeout option, so it would
immediately exit on autostart with an error.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate virtlockd daemon
Daniel P. Berrange [Fri, 25 Apr 2014 10:55:32 +0000 (11:55 +0100)]
Use virFileFindResource to locate virtlockd daemon

Make the lock plugin use virFileFindResource to find the
virtlockd daemon path, so that it executes the in-builddir
daemon if run from source tree.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate libvirtd daemon
Daniel P. Berrange [Fri, 25 Apr 2014 10:55:32 +0000 (11:55 +0100)]
Use virFileFindResource to locate libvirtd daemon

Make the remote driver use virFileFindResource to find the
libvirt daemon path, so that it executes the in-builddir
daemon if run from source tree.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRecheck disk backing chains after snapshot
Jiri Denemark [Fri, 25 Apr 2014 13:07:37 +0000 (15:07 +0200)]
Recheck disk backing chains after snapshot

When a snapshot operation finishes we have to recheck the backing chain
of all disks involved in the snapshot. And we need to do that even if
the operation failed because some of the disks might have changed if
QEMU did not support transactions.

11 years agonetwork: centralize check for active network during interface attach
Laine Stump [Thu, 10 Apr 2014 11:44:07 +0000 (14:44 +0300)]
network: centralize check for active network during interface attach

The check for a network being active during interface attach was being
done individually in several places (by both the lxc driver and the
qemu driver), but those places were too specific, leading to it *not*
being checked when allocating a connection/device from a macvtap or
hostdev network.

This patch puts a single check in networkAllocateActualDevice(), which
is always called before the any network interface is attached to any
type of domain. It also removes all the other now-redundant checks
from the lxc and qemu drivers.

NB: the following patches are prerequisites for this patch, in the
case that it is backported to any branch:

  440beeb network: fix virNetworkObjAssignDef and persistence
  8aaa5b6 network: create statedir during driver initialization
  b9e9549 network: change location of network state xml files
  411c548 network: set macvtap/hostdev networks active if their state
          file exists

This fixes:

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

11 years agonetwork: set macvtap/hostdev networks active if their state file exists
Laine Stump [Wed, 9 Apr 2014 14:16:45 +0000 (17:16 +0300)]
network: set macvtap/hostdev networks active if their state file exists

libvirt attempts to determine at startup time which networks are
already active, and set their active flags. Previously it has done
this by assuming that all networks are inactive, then setting the
active flag if the network has a bridge device associated with it and
that bridge device exists. This is not useful for macvtap and hostdev
based networks, since they do not use a bridge device.

Of course the reason that such a check had to be done was that the
presence of a status file in the network "stateDir" couldn't be
trusted as an indicator of whether or not a network was active. This
was due to the network driver mistakenly using
/var/lib/libvirt/network to store the status files, rather than
/var/run/libvirt/network (similar to what is done by every other
libvirt driver that stores status xml for its objects). The difference
is that /var/run is cleared out when the host reboots, so you can be
assured that the state file you are seeing isn't just left over from a
previous boot of the host.

Now that the network driver has been switched to using
/var/run/libvirt/network for status, we can also modify it to assume
that any network with an existing status file is by definition active
- we do this when reading the status file. To fine tune the results,
networkFindActiveConfigs() is changed to networkUpdateAllState(),
and only sets active = 0 if the conditions for particular network
types are *not* met.

The result is that during the first run of libvirtd after the host
boots, there are no status files, so no networks are active. Any time
libvirtd is restarted, any network with a status file will be marked
as active (unless the network uses a bridge device and that device for
some reason doesn't exist).

11 years agonetwork: change location of network state xml files
Laine Stump [Fri, 4 Apr 2014 13:48:54 +0000 (16:48 +0300)]
network: change location of network state xml files

For some reason these have been stored in /var/lib, although other
drivers (e.g. qemu and lxc) store their state files in /var/run.

It's much nicer to store state files in /var/run because it is
automatically cleared out when the system reboots. We can then use
existence of the state file as a convenient indicator of whether or
not a particular network is active.

Since changing the location of the state files by itself will cause
problems in the case of a *live* upgrade from an older libvirt that
uses /var/lib (because current status of active networks will be
lost), the network driver initialization has been modified to migrate
any network state files from /var/lib to /var/run.

This will not help those trying to *downgrade*, but in practice this
will only be problematic in two cases

1) If there are networks with network-wide bandwidth limits configured
   *and in use* by a guest during a downgrade to "old" libvirt. In this
   case, the class ID's used for that network's tc rules, as well as
   the currently in-use bandwidth "floor" will be forgotten.

2) If someone does this: 1) upgrade libvirt, 2) downgrade libvirt, 3)
   modify running state of network (e.g. add a static dhcp host, etc),
   4) upgrade. In this case, the modifications to the running network
   will be lost (but not any persistent changes to the network's
   config).

11 years agonetwork: create statedir during driver initialization
Laine Stump [Fri, 4 Apr 2014 11:21:13 +0000 (14:21 +0300)]
network: create statedir during driver initialization

This directory should be created when the network driver is first
started up, not just when a dhcp daemon is run. This hasn't posed a
problem in the past, because the directory has always been
pre-existing.

11 years agonetwork: fix virNetworkObjAssignDef and persistence
Laine Stump [Tue, 22 Apr 2014 13:48:54 +0000 (16:48 +0300)]
network: fix virNetworkObjAssignDef and persistence

Experimentation showed that if virNetworkCreateXML() was called for a
network that was already defined, and then the network was
subsequently shutdown, the network would continue to be persistent
after the shutdown (expected/desired), but the original config would
be lost in favor of the transient config sent in with
virNetworkCreateXML() (which would then be the new persistent config)
(obviously unexpected/not desired).

To fix this, virNetworkObjAssignDef() has been changed to

1) properly save/free network->def and network->newDef for all the
various combinations of live/active/persistent, including some
combinations that were previously considered to be an error but didn't
need to be (e.g. setting a "live" config for a network that isn't yet
active but soon will be - that was previously considered an error,
even though in practice it can be very useful).

2) automatically set the persistent flag whenever a new non-live
config is assigned to the network (and clear it when the non-live
config is set to NULL). the libvirt network driver no longer directly
manipulates network->persistent, but instead relies entirely on
virNetworkObjAssignDef() to do the right thing automatically.

After this patch, the following sequence will behave as expected:

virNetworkDefineXML(X)
virNetworkCreateXML(X') (same name but some config different)
virNetworkDestroy(X)

At the end of these calls, the network config will remain as it was
after the initial virNetworkDefine(), whereas previously it would take
on the changes given during virNetworkCreateXML().

Another effect of this tighter coupling between a) setting a !live def
and b) setting/clearing the "persistent" flag, is that future patches
which change the details of network lifecycle management
(e.g. upcoming patches to fix detection of "active" networks when
libvirtd is restarted) will find it much more difficult to break
persistence functionality.

11 years agobuild: -avoid-version on libvirt_driver_nwfilter
Dwight Engen [Fri, 25 Apr 2014 19:10:00 +0000 (15:10 -0400)]
build: -avoid-version on libvirt_driver_nwfilter

This fixes the following make rpm warning:

warning: Installed (but unpackaged) file(s) found:
   /usr/lib64/libvirt/connection-driver/libvirt_driver_nwfilter.so.0
   /usr/lib64/libvirt/connection-driver/libvirt_driver_nwfilter.so.0.0.0

introduced in comit 8d559864

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agolibxl: Support PV consoles
Ian Campbell [Fri, 25 Apr 2014 15:54:20 +0000 (16:54 +0100)]
libxl: Support PV consoles

Currently the driver only exposes the ability to connect to the serial console
of a Xen guest, which doesn't work for a PV guest. Since for an HVM guest the
serial devices are duplicated as consoles it is sufficient to just use the
console devices unconditionally.

Tested with the following bit of config XML:

<domain type='xen'>
  ...
  <devices>
    <console type='pty'>
      <target type='xen'/>
    </console>
  </devices>
</domain>

I have observed and tested this on ARM but I believe it also applies to x86 PV
guests.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: Jim Fehlig <jfehlig@suse.com>
Cc: Dario Faggioli <dario.faggioli@citrix.com>
Cc: Clark Laughlin <clark.laughlin@linaro.org>
11 years agobuild: add nwfilterxml2firewalldata to dist
Dwight Engen [Fri, 25 Apr 2014 16:46:02 +0000 (12:46 -0400)]
build: add nwfilterxml2firewalldata to dist

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
11 years agoConditionalize include of dlfcn.h in virmock.h
Daniel P. Berrange [Fri, 25 Apr 2014 14:48:30 +0000 (15:48 +0100)]
Conditionalize include of dlfcn.h in virmock.h

dlfcn.h does not exist on Win32 so must only be used
conditionally

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd a test suite for nwfilter ebiptables tech driver
Daniel P. Berrange [Tue, 1 Apr 2014 06:19:38 +0000 (07:19 +0100)]
Add a test suite for nwfilter ebiptables tech driver

Create a nwfilterxml2firewalltest to exercise the
ebiptables_driver.applyNewRules method with a variety of
different XML input files. The XML input files are taken
from the libvirt-tck nwfilter tests. While the nwfilter
tests verify the final state of the iptables chains, this
test verifies the set of commands invoked to create the
chains.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove last trace of direct firewall command exection
Daniel P. Berrange [Mon, 31 Mar 2014 12:01:04 +0000 (13:01 +0100)]
Remove last trace of direct firewall command exection

Remove all the left over code related to the direct invocation
of firewall-cmd/iptables/ip6tables/ebtables. This is all handled
by the virFirewallPtr APIs now.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert ebiptablesDriverProbeStateMatch to virFirewall
Daniel P. Berrange [Mon, 31 Mar 2014 11:58:20 +0000 (12:58 +0100)]
Convert ebiptablesDriverProbeStateMatch to virFirewall

Conver the ebiptablesDriverProbeStateMatch initialization
check to use the virFirewall APIs for querying iptables
version.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebiptablesApplyNewRules to virFirewall
Daniel P. Berrange [Tue, 25 Mar 2014 14:33:19 +0000 (14:33 +0000)]
Convert nwfilter ebiptablesApplyNewRules to virFirewall

Convert the nwfilter ebtablesApplyNewRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebtablesApplyDropAllRules to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 16:27:39 +0000 (16:27 +0000)]
Convert nwfilter ebtablesApplyDropAllRules to virFirewall

Convert the nwfilter ebtablesApplyDropAllRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebtablesApplyDHCPOnlyRules to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 16:25:12 +0000 (16:25 +0000)]
Convert nwfilter ebtablesApplyDHCPOnlyRules to virFirewall

Convert the nwfilter ebtablesApplyDHCPOnlyRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebtablesApplyBasicRules to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 12:58:18 +0000 (12:58 +0000)]
Convert nwfilter ebtablesApplyBasicRules to virFirewall

Convert the nwfilter ebtablesApplyBasicRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebiptablesTearNewRules to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 12:48:33 +0000 (12:48 +0000)]
Convert nwfilter ebiptablesTearNewRules to virFirewall

Convert the nwfilter ebiptablesTearNewRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebtablesRemoveBasicRules to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 12:14:13 +0000 (12:14 +0000)]
Convert nwfilter ebtablesRemoveBasicRules to virFirewall

Convert the nwfilter ebtablesRemoveBasicRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebiptablesTearOldRules to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 12:05:00 +0000 (12:05 +0000)]
Convert nwfilter ebiptablesTearOldRules to virFirewall

Convert the nwfilter ebiptablesTearOldRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert nwfilter ebiptablesAllTeardown to virFirewall
Daniel P. Berrange [Fri, 14 Mar 2014 11:53:06 +0000 (11:53 +0000)]
Convert nwfilter ebiptablesAllTeardown to virFirewall

Convert the nwfilter ebiptablesAllTeardown method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert ebtables code over to use firewall APIs
Daniel P. Berrange [Fri, 7 Mar 2014 17:46:19 +0000 (17:46 +0000)]
Convert ebtables code over to use firewall APIs

Convert the virebtables.{c,h} files to use the new virFirewall
APIs for changing ebtables rules.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd test for converting network XML to iptables rules
Daniel P. Berrange [Thu, 20 Mar 2014 10:30:44 +0000 (10:30 +0000)]
Add test for converting network XML to iptables rules

Using the virCommand dry run capability, capture iptables rules
created by various network XML documents.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoReplace virNetworkObjPtr with virNetworkDefPtr in network platform APIs
Daniel P. Berrange [Wed, 19 Mar 2014 16:56:35 +0000 (16:56 +0000)]
Replace virNetworkObjPtr with virNetworkDefPtr in network platform APIs

The networkCheckRouteCollision, networkAddFirewallRules and
networkRemoveFirewallRules APIs all take a virNetworkObjPtr
instance, but only ever access the 'def' member. It thus
simplifies testing if the APIs are changed to just take a
virNetworkDefPtr instead

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoConvert bridge driver over to use new firewall APIs
Daniel P. Berrange [Thu, 6 Mar 2014 17:01:13 +0000 (17:01 +0000)]
Convert bridge driver over to use new firewall APIs

Update the iptablesXXXX methods so that instead of directly
executing iptables commands, they populate rules in an
instance of virFirewallPtr. The bridge driver can thus
construct the ruleset and then invoke it in one operation
having rollback handled automatically.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoIntroduce an object for managing firewall rulesets
Daniel P. Berrange [Mon, 4 Mar 2013 16:30:40 +0000 (16:30 +0000)]
Introduce an object for managing firewall rulesets

The network and nwfilter drivers both have a need to update
firewall rules. The currently share no code for interacting
with iptables / firewalld. The nwfilter driver is fairly
tied to the concept of creating shell scripts to execute
which makes it very hard to port to talk to firewalld via
DBus APIs.

This patch introduces a virFirewallPtr object which is able
to represent a complete sequence of rule changes, with the
ability to have multiple transactional checkpoints with
rollbacks. By formally separating the definition of the rules
to be applied from the mechanism used to apply them, it is
also possible to write a firewall engine that uses firewalld
DBus APIs natively instead of via the slow firewalld-cmd.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoPreserve error when tearing down nwfilter rules
Daniel P. Berrange [Mon, 31 Mar 2014 11:25:17 +0000 (12:25 +0100)]
Preserve error when tearing down nwfilter rules

When a VM fails to launch due to error creating nwfilter
rules, we must avoid overwriting the original error when
tearing down the partially created rules.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove two-stage construction of commands in nwfilter
Daniel P. Berrange [Tue, 25 Mar 2014 16:10:56 +0000 (16:10 +0000)]
Remove two-stage construction of commands in nwfilter

The nwfilter ebiptables driver will build up commands to run in
two phases. The first phase contains all of the command, except
for the '-A' part. Instead it has a '%c' placeholder, along with
a '%s' placeholder for a position arg. The second phase than
substitutes these placeholders. The only values ever used for
these substitutions though is '-A' and '', so it is entirely
pointless. Remove the second phase entirely, since it will make
it harder to convert to the new firewall APIs

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoMerge nwfilter createRuleInstance driver into applyNewRules
Daniel P. Berrange [Tue, 25 Mar 2014 13:44:50 +0000 (13:44 +0000)]
Merge nwfilter createRuleInstance driver into applyNewRules

The current nwfilter tech driver API has a 'createRuleInstance' method
which populates virNWFilterRuleInstPtr with a command line string
containing variable placeholders. The 'applyNewRules' method then
expands the variables and executes the commands. This split of
responsibility won't work when switching to the virFirewallPtr
APIs, since we can't just build up command line strings. This patch
this merges the functionality of 'createRuleInstance' into the
applyNewRules method.

The virNWFilterRuleInstPtr struct is changed from holding an array
of opaque pointers, into holding generic metadata about the rules
to be processed. In essence this is the result of taking a linked
set of virNWFilterDefPtr's and flattening the tree to get a list
of virNWFilterRuleDefPtr's. At the same time we must keep track of
any nested virNWFilterObjPtr instances, so that the locks are held
for the duration of the 'applyNewRules' method.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoPush virNWFilterRuleInstPtr out of (eb|ip)tablesCreateRuleInstance
Daniel P. Berrange [Tue, 25 Mar 2014 10:32:55 +0000 (10:32 +0000)]
Push virNWFilterRuleInstPtr out of (eb|ip)tablesCreateRuleInstance

Later refactoring will change use of the virNWFilterRuleInstPtr struct.
Prepare for this by pushing use of the virNWFilterRuleInstPtr parameter
out of the ebtablesCreateRuleInstance and iptablesCreateRuleInstance
methods. Instead they simply string(s) with the constructed rule data.
The ebiptablesCreateRuleInstance method will make use of the
virNWFilterRuleInstPtr struct instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd helper methods for determining what protocol layer is used
Daniel P. Berrange [Tue, 25 Mar 2014 11:50:18 +0000 (11:50 +0000)]
Add helper methods for determining what protocol layer is used

Add virNWFilterRuleIsProtocol{Ethernet,IPv4,IPv6} helper methods
to avoid having to write a giant switch statements with many cases.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove nwfilter tech driver 'displayRuleInstance' callback
Daniel P. Berrange [Tue, 25 Mar 2014 11:38:16 +0000 (11:38 +0000)]
Remove nwfilter tech driver 'displayRuleInstance' callback

The 'displayRuleInstance' callback in the nwfilter tech driver
is never invoked, so can be deleted.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove nwfilter tech driver 'removeRules' callback
Daniel P. Berrange [Mon, 24 Mar 2014 17:05:42 +0000 (17:05 +0000)]
Remove nwfilter tech driver 'removeRules' callback

The 'removeRules' callback in the nwfilter tech driver is never
invoked, so can be deleted.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove pointless storage of var names in virNWFilterHashTable
Daniel P. Berrange [Mon, 24 Mar 2014 16:35:23 +0000 (16:35 +0000)]
Remove pointless storage of var names in virNWFilterHashTable

The virNWFilterHashTable struct contains a virHashTable and
then a 'char **names' field which keeps a copy of all the
hash keys. Presumably this was intended to record the ordering
of the hash keys. No code ever uses this and the ordering is
mangled whenever a variable is removed from the hash, because
the last element in the list is copied into the middle of the
list when shrinking the array.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoRemove virDomainNetType parameter from nwfilter drivers
Daniel P. Berrange [Mon, 24 Mar 2014 12:27:03 +0000 (12:27 +0000)]
Remove virDomainNetType parameter from nwfilter drivers

The 'virDomainNetType' is unused in every impl of the
virNWFilterRuleCreateInstance driver method. Remove it
from the code to avoid the dependancy on the external
enum.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoMove virNWFilterTechDriver struct out of nwfilter_conf.h
Daniel P. Berrange [Mon, 24 Mar 2014 12:32:37 +0000 (12:32 +0000)]
Move virNWFilterTechDriver struct out of nwfilter_conf.h

The virNWFilterTechDriver struct is nothing to do with the nwfilter
XML configuration. It stores data specific to the driver implementation
so should be in a header in the driver directory instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoFix leak on OOM in virNWFilterVarValueCreateSimpleCopyValue
Daniel P. Berrange [Tue, 8 Apr 2014 14:43:45 +0000 (15:43 +0100)]
Fix leak on OOM in virNWFilterVarValueCreateSimpleCopyValue

If virNWFilterVarValueCreateSimple fails with OOM, then
'val' will be leaked by virNWFilterVarValueCreateSimpleCopyValue

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoqemu: Avoid overflow when setting migration speed on inactive domains
Jiri Denemark [Fri, 11 Apr 2014 09:24:51 +0000 (11:24 +0200)]
qemu: Avoid overflow when setting migration speed on inactive domains

Commit c4206d7 fixed the overflow for running domains. However, we need
a similar check when setting migration speed on inactive domains.

At first look, it may seem the check in c4206d7 is now redundant but
qemuDomainMigrateSetMaxSpeed is not the only caller of
qemuMonitorSetMigrationSpeed so we need to check the bandwidth in both
places.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoUse virFileFindResource to locate CPU map XML
Daniel P. Berrange [Thu, 24 Apr 2014 15:59:37 +0000 (16:59 +0100)]
Use virFileFindResource to locate CPU map XML

Replace use of cpuMapOverride with virFileFindResource
to locate CPU map from build dir.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate driver plugins
Daniel P. Berrange [Thu, 24 Apr 2014 15:45:49 +0000 (16:45 +0100)]
Use virFileFindResource to locate driver plugins

Replace virDriverModuleInitialize with virFileFindResource
usage.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate lock manager plugins
Daniel P. Berrange [Thu, 24 Apr 2014 15:45:49 +0000 (16:45 +0100)]
Use virFileFindResource to locate lock manager plugins

Replace virLockManagerSetPluginDir with virFileFindResource
usage.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate iohelper for fdstream
Nehal J Wani [Tue, 25 Mar 2014 08:23:15 +0000 (13:53 +0530)]
Use virFileFindResource to locate iohelper for fdstream

Instead of hardcoding LIBEXECDIR as the location of the libvirt_iohelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate parthelper for storage backend
Nehal J Wani [Tue, 25 Mar 2014 08:23:14 +0000 (13:53 +0530)]
Use virFileFindResource to locate parthelper for storage backend

Instead of hardcoding LIBEXECDIR as the location of the libvirt_parthelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate libvirt_lxc for capabilities
Nehal J Wani [Tue, 25 Mar 2014 08:23:13 +0000 (13:53 +0530)]
Use virFileFindResource to locate libvirt_lxc for capabilities

Instead of hardcoding LIBEXECDIR as the location of the libvirt_lxc
binary set in the LXC driver capabilities, use virFileFindResource
to optionally find it in the current build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoUse virFileFindResource to locate iohelper for virFileWrapperFdNew
Nehal J Wani [Tue, 25 Mar 2014 08:23:12 +0000 (13:53 +0530)]
Use virFileFindResource to locate iohelper for virFileWrapperFdNew

Instead of hardcoding LIBEXECDIR as the location of the libvirt_iohelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoActivate build dir overrides in libvirtd, virtlockd, virsh & tests
Daniel P. Berrange [Thu, 24 Apr 2014 14:57:36 +0000 (15:57 +0100)]
Activate build dir overrides in libvirtd, virtlockd, virsh & tests

Add calls to virFileActivateDirOverride so that the build dir
overrides are activated.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd helpers for resolving path to resources in build tree
Daniel P. Berrange [Thu, 24 Apr 2014 14:05:42 +0000 (15:05 +0100)]
Add helpers for resolving path to resources in build tree

Add virFileFindResource which will try to locate files
in the local build tree if the calling binary (eg libvirtd or
test suite) is being run from the build tree. The corresponding
virFileActivateDirOverride should be called at startup passing
in argv[0]. This will be examined for evidence of libtool magic
binary prefix / sub-directory in order to activate the override.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd test suite for viralloc APIs
Daniel P. Berrange [Tue, 8 Apr 2014 14:44:40 +0000 (15:44 +0100)]
Add test suite for viralloc APIs

In debugging a crash on OOM, I thought that the virInsert APIs
might be at fault, but couldn't isolate them as a cause. While
the viralloc APIs are used in many test suites, this is as a
side-effect, they are not directly tested :-)

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoAdd support for addressing backing stores by index
Jiri Denemark [Fri, 18 Apr 2014 12:35:33 +0000 (14:35 +0200)]
Add support for addressing backing stores by index

Each backing store of a given disk is associated with a unique index
(which is also formatted in domain XML) for easier addressing of any
particular backing store. With this patch, any backing store can be
addressed by its disk target and the index. For example, "vdc[4]"
addresses the backing store with index equal to 4 of the disk identified
by "vdc" target. Such shorthand can be used in any API in place for a
backing file path:

    virsh blockcommit domain vda --base vda[3] --top vda[2]

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agovirStorageFileChainLookup: Return virStorageSourcePtr
Jiri Denemark [Fri, 18 Apr 2014 13:25:19 +0000 (15:25 +0200)]
virStorageFileChainLookup: Return virStorageSourcePtr

Returning both virStorageSourcePtr and its path member does not make a
lot of sense.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoqemuDomainBlockCommit: Track virStorageSourcePtr for base
Jiri Denemark [Fri, 18 Apr 2014 12:44:51 +0000 (14:44 +0200)]
qemuDomainBlockCommit: Track virStorageSourcePtr for base

virStorageFileChainLookup is able to give use virStorageSourcePtr which
contains the pointer to its canonical path. Let's use a more general
virStorageSourcePtr instead of just canonical path.

Former base_canon maps to baseSource->path.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoqemuDomainBlockCommit: Don't track top_canon path separately
Jiri Denemark [Fri, 18 Apr 2014 12:38:49 +0000 (14:38 +0200)]
qemuDomainBlockCommit: Don't track top_canon path separately

virStorageFileChainLookup is able to give use virStorageSourcePtr which
contains the pointer to its canonical path. There's no need for the
caller to store both of them.

Former top_meta maps to topSource and top_canon maps to topSource->path.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agobuild: avoid 'index' as variable name
Eric Blake [Thu, 24 Apr 2014 21:41:47 +0000 (15:41 -0600)]
build: avoid 'index' as variable name

Once again, gcc 4.4.7 (hello RHEL) rears its ugly head:

conf/domain_conf.c: In function 'virDomainDiskBackingStoreFormat':
conf/domain_conf.c:14940: error: declaration of 'index' shadows a global declaration [-Wshadow]
/usr/include/string.h:489: error: shadowed declaration is here [-Wshadow]

* src/conf/domain_conf.c (virDomainDiskBackingStoreFormat): Pacify
older gcc.

Signed-off-by: Eric Blake <eblake@redhat.com>
11 years agodocs: document nmdm type console
Roman Bogorodskiy [Mon, 21 Apr 2014 13:16:58 +0000 (17:16 +0400)]
docs: document nmdm type console

* Add nmdm type device to domain format documnetation
* Add a section about nmdm console usage to the bhyve driver
  documentation

11 years agoqemu: don't check for backing chains for formats w/o snapshot support
Martin Kletzander [Wed, 16 Apr 2014 15:31:50 +0000 (17:31 +0200)]
qemu: don't check for backing chains for formats w/o snapshot support

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1019926
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=868673

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
11 years agotests: Test backing store XML formatting and parsing
Jiri Denemark [Thu, 17 Apr 2014 13:37:51 +0000 (15:37 +0200)]
tests: Test backing store XML formatting and parsing

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agotests: More output options for xml2xml tests
Jiri Denemark [Thu, 17 Apr 2014 13:23:21 +0000 (15:23 +0200)]
tests: More output options for xml2xml tests

So far, qemuxml2xml test was only able to check if the result matches
the original or the appropriate XML in qemuxml2xmloutdata regardless on
flags used to format the XML. Since the result can be different
depending on VIR_DOMAIN_XML_INACTIVE flag being used or not, this patch
adds support for qemuxml2xmlout-%s-active.xml and
qemuxml2xmlout-%s-inactive.xml output files. If the file specific to the
flag used exists, it is used in preference to the generic
qemuxml2xmlout-%s.xml file when reading the expected output.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoconf: Format and parse backing chains in domain XML
Jiri Denemark [Thu, 17 Apr 2014 13:22:32 +0000 (15:22 +0200)]
conf: Format and parse backing chains in domain XML

This patch implements formating and parsing code for the backing store
schema defined and documented by the previous patch.

This patch does not aim at providing full persistent storage of disk
backing chains yet. The formatter is supposed to provide the backing
chain detected when starting a domain and thus it is not formatted into
an inactive domain XML. The parser is implemented mainly for the purpose
of testing the XML generated by the formatter and thus it does not
distinguish between no backingStore element and an empty backingStore
element. This will have to change once we fully implement support for
user-supplied backing chains.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoconf: Output disk backing store details in domain XML
Jiri Denemark [Wed, 16 Apr 2014 13:28:10 +0000 (15:28 +0200)]
conf: Output disk backing store details in domain XML

The XML for quite a longish backing chain is shown below:

  <disk type='network' device='disk'>
    <driver name='qemu' type='qcow2'/>
    <source protocol='nbd' name='bar'>
      <host transport='unix' socket='/var/run/nbdsock'/>
    </source>
    <backingStore type='block' index='1'>
      <format type='qcow2'/>
      <source dev='/dev/HostVG/QEMUGuest1'/>
      <backingStore type='file' index='2'>
        <format type='qcow2'/>
        <source file='/tmp/image2.qcow'/>
        <backingStore type='file' index='3'>
          <format type='qcow2'/>
          <source file='/tmp/image3.qcow'/>
          <backingStore type='file' index='4'>
            <format type='qcow2'/>
            <source file='/tmp/image4.qcow'/>
            <backingStore type='file' index='5'>
              <format type='qcow2'/>
              <source file='/tmp/image5.qcow'/>
              <backingStore type='file' index='6'>
                <format type='raw'/>
                <source file='/tmp/Fedora-17-x86_64-Live-KDE.iso'/>
                <backingStore/>
              </backingStore>
            </backingStore>
          </backingStore>
        </backingStore>
      </backingStore>
    </backingStore>
    <target dev='vdb' bus='virtio'/>
  </disk>

Various disk types and formats can be mixed in one chain. The
<backingStore/> empty element marks the end of the backing chain and it
is there mostly for future support of parsing the chain provided by a
user. If it's missing, we are supposed to probe for the rest of the
chain ourselves, otherwise complete chain was provided by the user. The
index attributes of backingStore elements can be used to unambiguously
identify a specific part of the image chain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11 years agoFix pci bus naming for PPC
Daniel P. Berrange [Wed, 23 Apr 2014 15:35:37 +0000 (16:35 +0100)]
Fix pci bus naming for PPC

Recent discussions around naming of 'pci' vs 'pci.0' for PPC
made me go back and look at the PPC emulator in every historical
version of QEMU since 1.0. The results were worse than I imagined.
This patch adds the logic required to make libvirt work with PPC
correctly with naming variations across all versions & machine
types.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
11 years agoutil: storage: Invert the way recursive metadata retrieval works
Peter Krempa [Fri, 18 Apr 2014 12:49:54 +0000 (14:49 +0200)]
util: storage: Invert the way recursive metadata retrieval works

To avoid having the root of a backing chain present twice in the list we
need to invert the working of virStorageFileGetMetadataRecurse.

Until now the recursive worker created a new backing chain element from
the name and other information passed as arguments. This required us to
pass the data of the parent in a deconstructed way and the worker
created a new entry for the parent.

This patch converts this function so that it just fills in metadata
about the parent and creates a backing chain element from those. This
removes the duplication of the first element.

To avoid breaking the test suite, virstoragetest now calls a wrapper
that creates the parent structure explicitly and pre-fills it with the
test data with same function signature as previously used.

11 years agoutil: virstoragefile: Don't mangle data stored about directories
Peter Krempa [Fri, 18 Apr 2014 08:07:41 +0000 (10:07 +0200)]
util: virstoragefile: Don't mangle data stored about directories

Don't remove detected metadata about directory based storage volumes.

11 years agostorage: Move disk->backingChain to the recursive disk->src.backingStore
Peter Krempa [Thu, 17 Apr 2014 21:20:22 +0000 (23:20 +0200)]
storage: Move disk->backingChain to the recursive disk->src.backingStore

Switch over to storing of the backing chain as a recursive
virStorageSource structure.

This is a string based move. Currently the first element will be present
twice in the backing chain as currently the retrieval function stores
the parent in the newly detected chain. This will be fixed later.

11 years agoutil: virstoragefile: Rename backingMeta to backingStore
Peter Krempa [Thu, 17 Apr 2014 20:46:18 +0000 (22:46 +0200)]
util: virstoragefile: Rename backingMeta to backingStore

To conform with the naming of the planned XML output rename the metadata
variable name.

s/backingMeta/backingStore/g

11 years agoutil: virstorage: Kill struct virStorageFileMetadata
Peter Krempa [Thu, 17 Apr 2014 14:15:45 +0000 (16:15 +0200)]
util: virstorage: Kill struct virStorageFileMetadata

Remove the now unused pieces of the structure.

11 years agomaint: Switch over from struct virStorageFileMetadata to virStorageSource
Peter Krempa [Thu, 17 Apr 2014 14:05:16 +0000 (16:05 +0200)]
maint: Switch over from struct virStorageFileMetadata to virStorageSource

Replace the old structure with the new one. This change is a trivial
name change operation (along with change of the freeing function).

11 years agoutil: storagefile: Add fields from virStorageMetadata to virStorageSource
Peter Krempa [Thu, 17 Apr 2014 14:04:33 +0000 (16:04 +0200)]
util: storagefile: Add fields from virStorageMetadata to virStorageSource

Add the required fields that are missing from the new structure that
will allow us to switch the storage file metadata code entirely to the
new structure.

Add "relPath" and "relDir" and the raw backing store name. Also allow
creating linked lists of virStorageSourcePtrs to express backing chains.