]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
12 years agoblockjob: avoid segv on early error
Eric Blake [Sat, 20 Oct 2012 03:13:37 +0000 (21:13 -0600)]
blockjob: avoid segv on early error

Gcc with optimization warns:
../../src/qemu/qemu_driver.c: In function 'qemuDomainBlockCommit':
../../src/qemu/qemu_driver.c:12813:46: error: 'disk' may be used uninitialized in this function [-Werror=maybe-uninitialized]
../../src/qemu/qemu_driver.c:12698:25: note: 'disk' was declared here
cc1: all warnings being treated as errors

so obviously I had only been testing with optimization off.

* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Guard cleanup.

12 years agoblockjob: properly label disks for qemu block-commit
Eric Blake [Tue, 16 Oct 2012 14:46:41 +0000 (08:46 -0600)]
blockjob: properly label disks for qemu block-commit

I finally have all the pieces in place to perform a block-commit with
SELinux enforcing.  There's still missing cleanup work when the commit
completes, but doing that requires tracking both the backing chain and
the base and top files within that chain in domain XML across libvirtd
restarts.  Furthermore, from a security standpoint, once you have
granted access, you must assume any damage that can be done will be
done; later revoking access is nice to minimize the window of damage,
but less important as it does not affect the fact that damage can be
done in the first place.  Therefore, deferring the revoke efforts until
we have better XML tracking of what chain operations are in effect,
including across a libvirtd restart, is reasonable.

* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Label disks as
needed.
(qemuDomainPrepareDiskChainElement): Cast away const.

12 years agoblockjob: refactor qemu disk chain permission grants
Eric Blake [Wed, 17 Oct 2012 21:48:14 +0000 (15:48 -0600)]
blockjob: refactor qemu disk chain permission grants

Previously, snapshot code did its own permission granting (lock
manager, cgroup device controller, and security manager labeling)
inline.  But now that we are adding block-commit and block-copy
which also have to change permissions, it's better to reuse
common code for the task.  While snapshot should fall back to
no access if read-write access failed, block-commit will want to
fall back to read-only access.  The common code doesn't know
whether failure to grant read-write access should revert to no
access (snapshot, block-copy) or read-only access (block-commit).
This code can also be used to revoke access to unused files after
block-pull.

It might be nice to clean things up in a future patch by adding
new functions to the lock manager, cgroup manager, and security
manager that takes a single file name and applies context of a
disk to that file, rather than the current semantics of applying
context to the entire chain already associated to a disk.  That
way, we could avoid the games this patch plays of temporarily
swapping out the disk->src and related fields of the disk.  But
that would involve more code changes, so this patch really is
the smallest hack for doing the necessary work; besides, this
patch is more or less code motion (the hack was already employed
by the snapshot creation code, we are just making it reusable).

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Refactor labeling hacks...
(qemuDomainPrepareDiskChainElement): ...into new function.

12 years agoblockjob: implement shallow commit flag in qemu
Eric Blake [Sat, 13 Oct 2012 13:12:31 +0000 (07:12 -0600)]
blockjob: implement shallow commit flag in qemu

Now that we can crawl the chain of backing files, we can do
argument validation and implement the 'shallow' flag.  In
testing this, I discovered that it can be handy to pass the
shallow flag and an explicit base, as a means of validating
that the base is indeed the file we expected.

* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Crawl through
chain to implement shallow flag.
* src/libvirt.c (virDomainBlockCommit): Relax API.

12 years agoblockjob: wire up online qemu block-commit
Eric Blake [Wed, 3 Oct 2012 18:54:09 +0000 (12:54 -0600)]
blockjob: wire up online qemu block-commit

This is the bare minimum to kick off a block commit.  In particular,
flags support is missing (shallow requires us to crawl the backing
chain to determine the file name to pass to the qemu monitor command;
delete requires us to track what needs to be deleted at the time
the completion event fires).  Also, we are relying on qemu to do
error checking (such as validating 'top' and 'base' as being members
of the backing chain), including the fact that the current qemu code
does not support committing the active layer (although it is still
planned to add that before qemu 1.3).  Since the active layer won't
change, we have it easy and do not have to alter the domain XML.
Additionally, this will fail if SELinux is enforcing, because we fail
to grant qemu proper read/write access to the files it will modify.

* src/qemu/qemu_driver.c (qemuDomainBlockCommit): New function.
(qemuDriver): Register it.

12 years agoblockjob: manage qemu block-commit monitor command
Eric Blake [Wed, 3 Oct 2012 21:13:21 +0000 (15:13 -0600)]
blockjob: manage qemu block-commit monitor command

qemu 1.3 will be adding a 'block-commit' monitor command, per
qemu.git commit ed61fc1.  It matches nicely to the libvirt API
virDomainBlockCommit.

* src/qemu/qemu_capabilities.h (QEMU_CAPS_BLOCK_COMMIT): New bit.
* src/qemu/qemu_capabilities.c (qemuCapsProbeQMPCommands): Set it.
* src/qemu/qemu_monitor.h (qemuMonitorBlockCommit): New prototype.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONBlockCommit):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorBlockCommit): Implement it.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockCommit):
Likewise.
(qemuMonitorJSONHandleBlockJobImpl)
(qemuMonitorJSONGetBlockJobInfoOne): Handle new event type.

12 years agoblockjob: remove unused parameters after previous patch
Eric Blake [Wed, 17 Oct 2012 20:22:24 +0000 (14:22 -0600)]
blockjob: remove unused parameters after previous patch

Minor cleanup made possible by previous simplifications.

* src/qemu/qemu_cgroup.h (qemuSetupDiskCgroup)
(qemuTeardownDiskCgroup): Alter signature.
* src/qemu/qemu_cgroup.c (qemuSetupDiskCgroup)
(qemuTeardownDiskCgroup, qemuSetupCgroup): Update all uses.
* src/qemu/qemu_hotplug.c (qemuDomainDetachPciDiskDevice)
(qemuDomainDetachDiskDevice): Likewise.
* src/qemu/qemu_driver.c (qemuDomainAttachDeviceDiskLive)
(qemuDomainChangeDiskMediaLive)
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.

12 years agostorage: use cache to walk backing chain
Eric Blake [Tue, 9 Oct 2012 22:08:14 +0000 (16:08 -0600)]
storage: use cache to walk backing chain

We used to walk the backing file chain at least twice per disk,
once to set up cgroup device whitelisting, and once to set up
security labeling.  Rather than walk the chain every iteration,
which possibly includes calls to fork() in order to open root-squashed
NFS files, we can exploit the cache of the previous patch.

* src/conf/domain_conf.h (virDomainDiskDefForeachPath): Alter
signature.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Require caller
to supply backing chain via disk, if recursion is desired.
* src/security/security_dac.c
(virSecurityDACSetSecurityImageLabel): Adjust caller.
* src/security/security_selinux.c
(virSecuritySELinuxSetSecurityImageLabel): Likewise.
* src/security/virt-aa-helper.c (get_files): Likewise.
* src/qemu/qemu_cgroup.c (qemuSetupDiskCgroup)
(qemuTeardownDiskCgroup): Likewise.
(qemuSetupCgroup): Pre-populate chain.

12 years agostorage: cache backing chain while qemu domain is live
Eric Blake [Tue, 9 Oct 2012 22:08:14 +0000 (16:08 -0600)]
storage: cache backing chain while qemu domain is live

Technically, we should not be re-probing any file that qemu might
be currently writing to.  As such, we should cache the backing
file chain prior to starting qemu.  This patch adds the cache,
but does not use it until the next patch.

Ultimately, we want to also store the chain in domain XML, so that
it is remembered across libvirtd restarts, and so that the only
kosher way to modify the backing chain of an offline domain will be
through libvirt API calls, but we aren't there yet.  So for now, we
merely invalidate the cache any time we do a live operation that
alters the chain (block-pull, block-commit, external disk snapshot),
as well as tear down the cache when the domain is not running.

* src/conf/domain_conf.h (_virDomainDiskDef): New field.
* src/conf/domain_conf.c (virDomainDiskDefFree): Clean new field.
* src/qemu/qemu_domain.h (qemuDomainDetermineDiskChain): New
prototype.
* src/qemu/qemu_domain.c (qemuDomainDetermineDiskChain): New
function.
* src/qemu/qemu_driver.c (qemuDomainAttachDeviceDiskLive)
(qemuDomainChangeDiskMediaLive): Pre-populate chain.
(qemuDomainSnapshotCreateSingleDiskActive): Uncache chain before
snapshot.
* src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Update
chain after block pull.

12 years agostorage: make it easier to find file within chain
Eric Blake [Fri, 12 Oct 2012 22:29:14 +0000 (16:29 -0600)]
storage: make it easier to find file within chain

In order to temporarily label files read/write during a commit
operation, we need to crawl the backing chain and find the absolute
file name that needs labeling in the first place, as well as the
name of the file that owns the backing file.

* src/util/storage_file.c (virStorageFileChainLookup): New
function.
* src/util/storage_file.h: Declare it.
* src/libvirt_private.syms (storage_file.h): Export it.

12 years agostorage: remember relative names in backing chain
Eric Blake [Tue, 9 Oct 2012 23:47:42 +0000 (17:47 -0600)]
storage: remember relative names in backing chain

In order to search for a backing file name as literally present
in a chain, we need to remember if the chain had relative names.
Also, searching for absolute names is easier if we only have
to canonicalize once, rather than on every iteration.

* src/util/storage_file.h (_virStorageFileMetadata): Add field.
* src/util/storage_file.c (virStorageFileGetMetadataFromBuf):
(virStorageFileFreeMetadata): Manage it
(absolutePathFromBaseFile): Store absolute names in canonical form.

12 years agostorage: don't require caller to pre-allocate metadata struct
Eric Blake [Sat, 13 Oct 2012 17:01:27 +0000 (11:01 -0600)]
storage: don't require caller to pre-allocate metadata struct

Requiring pre-allocation was an unusual idiom.  It allowed iteration
over the backing chain to use fewer mallocs, but made one-shot
clients harder to read.  Also, this makes it easier for a future
patch to move away from opening fds on every iteration over the chain.

* src/util/storage_file.h (virStorageFileGetMetadataFromFD): Alter
signature.
* src/util/storage_file.c (virStorageFileGetMetadataFromFD): Allocate
return value.
 (virStorageFileGetMetadata): Update clients.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.

12 years agostorage: get entire metadata chain in one call
Eric Blake [Sat, 13 Oct 2012 16:47:15 +0000 (10:47 -0600)]
storage: get entire metadata chain in one call

Previously, no one was using virStorageFileGetMetadata, and for good
reason - it couldn't support root-squash NFS.  Change the signature
and make it useful to future patches, including enhancing the metadata
to recursively track the entire chain.

* src/util/storage_file.h (_virStorageFileMetadata): Add field.
(virStorageFileGetMetadata): Alter signature.
* src/util/storage_file.c (virStorageFileGetMetadata): Rewrite.
(virStorageFileGetMetadataRecurse): New function.
(virStorageFileFreeMetadata): Handle recursion.

12 years agostorage: don't probe non-files
Eric Blake [Tue, 9 Oct 2012 23:50:14 +0000 (17:50 -0600)]
storage: don't probe non-files

Backing chains can end on a network protocol, such as nbd:xxx; we
should not attempt to probe the file system in this case.

* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Only probe files.

12 years agostorage: use enum for snapshot driver type
Eric Blake [Tue, 2 Oct 2012 16:57:06 +0000 (10:57 -0600)]
storage: use enum for snapshot driver type

This is the last use of raw strings for disk formats throughout
the src/conf directory.

* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Store enum
rather than string for disk type.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear)
(virDomainSnapshotDiskDefParseXML, virDomainSnapshotDefFormat):
Adjust users.
* src/qemu/qemu_driver.c (qemuDomainSnapshotDiskPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.

12 years agostorage: use enum for disk driver type
Eric Blake [Mon, 15 Oct 2012 21:47:42 +0000 (15:47 -0600)]
storage: use enum for disk driver type

Actually use the enum in the domain conf structure.

* src/conf/domain_conf.h (_virDomainDiskDef): Store enum rather
than string for disk type.
* src/conf/domain_conf.c (virDomainDiskDefFree)
(virDomainDiskDefParseXML, virDomainDiskDefFormat)
(virDomainDiskDefForeachPath): Adjust users.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenFormatSxprDisk):
Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* src/vbox/vbox_tmpl.c (vboxAttachDrives): Likewise.
* src/libxl/libxl_conf.c (libxlMakeDisk): Likewise.

12 years agostorage: use enum for default driver type
Eric Blake [Fri, 28 Sep 2012 21:06:33 +0000 (15:06 -0600)]
storage: use enum for default driver type

Express the default disk type as an enum, for easier handling.

* src/conf/capabilities.h (_virCaps): Store enum rather than
string for disk type.
* src/conf/domain_conf.c (virDomainDiskDefParseXML): Adjust
clients.
* src/qemu/qemu_driver.c (qemuCreateCapabilities): Likewise.

12 years agostorage: match RNG to supported driver types
Eric Blake [Fri, 28 Sep 2012 18:57:54 +0000 (12:57 -0600)]
storage: match RNG to supported driver types

At one point, the code passed through arbitrary strings for file
formats, which supposedly lets qemu handle a new file type even
before libvirt has been taught to handle it.  However, to properly
label files, libvirt has to learn the file type anyway, so we
might as well make our life easier by only accepting file types
that we are prepared to handle.  This patch lets the RNG validation
ensure that only known strings are let through.

* docs/schemas/domaincommon.rng (driverFormat): Limit to list of
supported strings.
* docs/schemas/domainsnapshot.rng (driver): Likewise.

12 years agostorage: treat 'aio' like 'raw' at parse time
Eric Blake [Fri, 28 Sep 2012 23:48:58 +0000 (17:48 -0600)]
storage: treat 'aio' like 'raw' at parse time

We have historically allowed 'aio' as a synonym for 'raw' for
back-compat to xen, but since a future patch will move to using
an enum value, we have to pick one to be our preferred output
name.  This is a slight change in the output XML, but the sexpr
and xm outputs should still be identical, and the input XML can
still use either form.

* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Move aio
back-compat...
(virDomainDiskDefParseXML): ...to parse time.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenFormatSxprDisk): ...and
to output time.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/sexpr2xmldata/sexpr2xml-*.xml: Update tests.

12 years agostorage: list more file types
Eric Blake [Fri, 28 Sep 2012 17:11:07 +0000 (11:11 -0600)]
storage: list more file types

When an image has no backing file, using VIR_STORAGE_FILE_AUTO
for its type is a bit confusing.  Additionally, a future patch
would like to reserve a default value for the case of no file
type specified in the XML, but different from the current use
of -1 to imply probing, since probing is not always safe.

Also, a couple of file types were missing compared to supported
code: libxl supports 'vhd', and qemu supports 'fat' for directories
passed through as a file system.

* src/util/storage_file.h (virStorageFileFormat): Add
VIR_STORAGE_FILE_NONE, VIR_STORAGE_FILE_FAT, VIR_STORAGE_FILE_VHD.
* src/util/storage_file.c (virStorageFileMatchesVersion): Match
documentation when version probing not supported.
(cowGetBackingStore, qcowXGetBackingStore, qcow1GetBackingStore)
(qcow2GetBackingStoreFormat, qedGetBackingStore)
(virStorageFileGetMetadataFromBuf)
(virStorageFileGetMetadataFromFD): Take NONE into account.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Likewise.
* src/conf/storage_conf.c (virStorageVolumeFormatFromString): New
function.
(poolTypeInfo): Use it.

12 years agoAutogenerate AUTHORS
Cole Robinson [Fri, 12 Oct 2012 23:50:19 +0000 (19:50 -0400)]
Autogenerate AUTHORS

AUTHORS.in tracks the maintainers, as well as some folks who were
previously in AUTHORS but don't have a git commit with proper
attribution.

Generated output is sorted alphabetically and lacks pretty spacing, so
tweak AUTHORS.in to follow the same format.

Additionally, drop the syntax-check rule that previously validated
AUTHORS against git log.

12 years agoselinux: relabel tapfd in qemuPhysIfaceConnect
Guannan Ren [Fri, 19 Oct 2012 08:44:30 +0000 (16:44 +0800)]
selinux: relabel tapfd in qemuPhysIfaceConnect

Relabeling tapfd right after the tap device is created.
qemuPhysIfaceConnect is common function called both for static
netdevs and for hotplug netdevs.

12 years agoqemu: Do not require hostuuid in migration cookie
Jiri Denemark [Fri, 19 Oct 2012 13:08:29 +0000 (15:08 +0200)]
qemu: Do not require hostuuid in migration cookie

Having hostuuid in migration cookie is a nice bonus since it provides an
easy way of detecting migration to the same host. However, requiring it
breaks backward compatibility with older libvirt releases.

12 years agoqemu: Allow migration with host USB devices
Jiri Denemark [Fri, 19 Oct 2012 11:36:33 +0000 (13:36 +0200)]
qemu: Allow migration with host USB devices

Recently, patches were added support for (managed)saving, restoring, and
migrating domains with host USB devices. However, qemu driver would
still forbid migration of such domains because qemuMigrationIsAllowed
was not updated.

12 years agoqemu: Set arch to i686 if qemu-system-i386 is found
Guido Günther [Thu, 18 Oct 2012 23:14:15 +0000 (01:14 +0200)]
qemu: Set arch to i686 if qemu-system-i386 is found

If we can't probe the architecture from QMP we parse the architecture
from the qemu binaries name. This results in the architecture being i386
instead of i686 which then results in QEMU_CAPS_PCI_MULTIBUS being unset
which gives a broken qemu command line.

This probably didn't show up earlier since most of the time there's also
a /usr/bin/qemu around which results in i686 capabilities.

12 years agoqemu: Don't fail without emulatorpin or cpumask
Guido Günther [Thu, 18 Oct 2012 22:29:17 +0000 (00:29 +0200)]
qemu: Don't fail without emulatorpin or cpumask

This unbreaks qemu:///session that got broken by
ba63d8f7d843461f77a8206c1ef9da38388713e5.

12 years agonetwork: Set to NULL after virNetworkDefFree()
Michal Privoznik [Thu, 18 Oct 2012 14:28:35 +0000 (16:28 +0200)]
network: Set to NULL after virNetworkDefFree()

which frees all allocated memory but doesn't set the passed pointer to
NULL.  Therefore, we must do it ourselves. This is causing actual
libvirtd crash: Basically, when doing 'virsh net-edit' the newDef should
be dropped.  And the memory is freed, indeed. However, the pointer is
not set to NULL but kept instead. And the next duo of calls 'virsh
net-start' and 'virsh net-destroy' starts the disaster. The latter one
does the same as 'virsh destroy'; it sees that newDef is nonNULL so it
replaces def with newDef (which has been freed already as said a few
lines above). Therefore any subsequent call accessing def will hit the ground.

12 years agodist: added cpu/cpu_ppc_data.h to Makefile.am
Viktor Mihajlovski [Thu, 18 Oct 2012 14:28:04 +0000 (16:28 +0200)]
dist: added cpu/cpu_ppc_data.h to Makefile.am

Missing entry for cpu_ppc_data.h added to fix RPM build.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agoqemu: Always format CPU topology
Jiri Denemark [Tue, 16 Oct 2012 19:11:29 +0000 (21:11 +0200)]
qemu: Always format CPU topology

When libvirt cannot find a suitable CPU model for host CPU (easily
reproducible by running libvirt in a guest), it would not provide CPU
topology in capabilities XML either. Even though CPU topology is known
and can be queried by virNodeGetInfo. With this patch, CPU topology will
always be provided in capabilities XML regardless on the presence of CPU
model.

12 years agospec: Fix dependency for lock-sanlock subpackage
Jiri Denemark [Thu, 18 Oct 2012 11:03:26 +0000 (13:03 +0200)]
spec: Fix dependency for lock-sanlock subpackage

This should not make a big difference in real world since libvirt-daemon,
which is already required by libvirt-lock-sanlock, requires
libvirt-client and thus libvirt-lock-sanlock gets this dependency
transitively. However, since libvirt-lock-sanlock contains
sanlock_helper binary linked to libvirt.so, we should start requiring
libvirt-client directly.

12 years agoqemu: Add support for HyperV Enlightenment feature "relaxed"
Peter Krempa [Wed, 17 Oct 2012 12:55:18 +0000 (14:55 +0200)]
qemu: Add support for HyperV Enlightenment feature "relaxed"

This patch adds QEMU support for the "relaxed" feature implemented by
previous patch.

12 years agoconf: Add support for HyperV Enlightenment features
Peter Krempa [Tue, 16 Oct 2012 16:25:56 +0000 (18:25 +0200)]
conf: Add support for HyperV Enlightenment features

Hypervisors are starting to support HyperV Enlightenment features that
improve behavior of guests running Microsoft Windows operating systems.

This patch adds support for the "relaxed" feature that improves timer
behavior and also establishes a framework to add these features in
future.

12 years agoconf: Make tri-state feature options more universal
Peter Krempa [Tue, 16 Oct 2012 14:28:22 +0000 (16:28 +0200)]
conf: Make tri-state feature options more universal

The apic-eoi feature enum and implementation can be made more universal
to allow re-use of the enum for other features.

12 years agoqemu: Correctly wait for spice to migrate
Michal Privoznik [Thu, 18 Oct 2012 07:38:41 +0000 (09:38 +0200)]
qemu: Correctly wait for spice to migrate

Currently we query-spice after the main migration has completed
before moving to next state. Qemu reports this as boolean (not
enclosed within quotes). Therefore it is not correct to use
virJSONValueObjectGetString but virJSONValueObjectGetBoolean instead.

12 years agoqemu: Fixed default machine detection in qemuCapsParseMachineTypesStr
Viktor Mihajlovski [Wed, 17 Oct 2012 14:48:42 +0000 (16:48 +0200)]
qemu: Fixed default machine detection in qemuCapsParseMachineTypesStr

The machine in the last output line of <qemu-binary> -M ?
was always reported as default machine even if this wasn't the
actual default. Trivial fix.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agoqemu: Pin the emulator when only cpuset is specified
Martin Kletzander [Wed, 17 Oct 2012 14:39:31 +0000 (16:39 +0200)]
qemu: Pin the emulator when only cpuset is specified

According to our recent changes (clarifications), we should be pinning
qemu's emulator processes using the <vcpu> 'cpuset' attribute in case
there is no <emulatorpin> specified.  This however doesn't work
entirely as expected and this patch should resolve all the remaining
issues.

12 years agoqemu: Clear async job when p2p migration fails early
Jiri Denemark [Wed, 17 Oct 2012 12:08:17 +0000 (14:08 +0200)]
qemu: Clear async job when p2p migration fails early

When p2p migration fails early because qemuMigrationIsAllowed or
qemuMigrationIsSafe say migration should be cancelled, we fail to clear
the migration-out async job. As a result of that, further APIs called
for the same domain may fail with Timed out during operation: cannot
acquire state change lock.

Reported by Guido Winkelmann.

12 years agointerface: add virInterfaceGetXMLDesc() in udev
Doug Goldstein [Sun, 14 Oct 2012 22:02:33 +0000 (17:02 -0500)]
interface: add virInterfaceGetXMLDesc() in udev

Added support for retrieving the XML defining a specific interface via
the udev based backend to virInterface. Implement the following APIs
for the udev based backend:
* virInterfaceGetXMLDesc()

Note: Does not support bond devices.

12 years agoAUTHORS: Remove double entry
Michal Privoznik [Wed, 17 Oct 2012 09:53:13 +0000 (11:53 +0200)]
AUTHORS: Remove double entry

I've accidentally added Li Zhang <zhlcindy@linux.vnet.ibm.com> to
AUTHORS, even if he already was there.

12 years agoDoc-fix for PowerPC CPU model driver
Li Zhang [Mon, 15 Oct 2012 09:07:51 +0000 (17:07 +0800)]
Doc-fix for PowerPC CPU model driver

There are some descriptions not right in PowerPC CPU model driver.
This patch is to fix them.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
12 years agoImplement CPU model driver for PowerPC
Li Zhang [Mon, 15 Oct 2012 09:07:50 +0000 (17:07 +0800)]
Implement CPU model driver for PowerPC

Currently, the CPU model driver is not implemented for PowerPC.
Host's CPU information is needed to exposed to guests' XML file some
time.

This patch is to implement the callback functions of CPU model driver.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
12 years agoAdd one file cpu_ppc_data.h to define CPU data for PPC
Li Zhang [Mon, 15 Oct 2012 09:07:49 +0000 (17:07 +0800)]
Add one file cpu_ppc_data.h to define CPU data for PPC

CPU version can be got by PVR on PowerPC. So this PVR is defined in
the CPU data in cpuData structure.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
12 years agoselinux: remove unused variables in socket labelling
Guannan Ren [Wed, 17 Oct 2012 03:28:28 +0000 (11:28 +0800)]
selinux: remove unused variables in socket labelling

12 years agoselinux: fix wrong tapfd relablling
Guannan Ren [Wed, 17 Oct 2012 03:23:19 +0000 (11:23 +0800)]
selinux: fix wrong tapfd relablling

It should relabel tapfd of virtual network of type VIR_DOMAIN_NET_TYPE_DIRECT
rather than VIR_DOMAIN_NET_TYPE_NETWORK and VIR_DOMAIN_NET_TYPE_BRIDGE
(commit ae368ebfcc4923d0b32e83d4ca96a6f599625785 introduced this bug)

Caution: The context of the two hunks is identical other than indentation.
Please be extremely cautious of where the patch gets applied.

12 years agostorage: lvm: lvcreate fails with allocation=0, don't do that
Cole Robinson [Wed, 17 Oct 2012 00:30:23 +0000 (20:30 -0400)]
storage: lvm: lvcreate fails with allocation=0, don't do that

On F17 at least, this command fails:

$ sudo /usr/sbin/lvcreate --name sparsetest -L 0K --virtualsize 16384K vgvirt
  Unable to create new logical volume with no extents

Which is unfortunate since allocation=0 is what virt-manager tries to use
by default.

Rather than telling the user 'don't do that', let's just give them the
smallest allocation possible if alloc=0 is requested.

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

12 years agostorage: lvm: Don't overwrite lvcreate errors
Cole Robinson [Wed, 17 Oct 2012 00:25:41 +0000 (20:25 -0400)]
storage: lvm: Don't overwrite lvcreate errors

Before:
$ sudo virsh vol-create-as --pool vgvirt sparsetest --capacity 16M --allocation 0
error: Failed to create vol sparsetest
error: internal error Child process (/usr/sbin/lvchange -aln vgvirt/sparsetest) unexpected exit status 5:   One or more specified logical volume(s) not found.

After:
$ sudo virsh vol-create-as --pool vgvirt sparsetest --capacity 16M --allocation 0
error: Failed to create vol sparsetest
error: internal error Child process (/usr/sbin/lvcreate --name sparsetest -L 0K --virtualsize 16384K vgvirt) unexpected exit status 5:   Unable to create new logical volume with no extents

12 years agospec: Require newer sanlock on recent distros 2
Jiri Denemark [Tue, 16 Oct 2012 21:54:18 +0000 (23:54 +0200)]
spec: Require newer sanlock on recent distros 2

The previous commit was incomplete. We need to also add explicit
Requires for the newer version since RPM's automatic dependencies won't
work with sanlock.

12 years agospec: Add runtime requirement for libssh2
Peter Krempa [Tue, 16 Oct 2012 12:34:35 +0000 (14:34 +0200)]
spec: Add runtime requirement for libssh2

libssh2 unfortunately doesn't support symbol versioning so RPM can't
figure out what version is needed for the currently installed libvirt
package. This patch adds a runtime requirement, so that the correct
version of libssh2 can be installed along with libvirt.

12 years agospec: Require newer sanlock on recent distros
Jiri Denemark [Tue, 16 Oct 2012 10:45:27 +0000 (12:45 +0200)]
spec: Require newer sanlock on recent distros

Make sure libvirt is build with sanlock >= 2.4 on distros that are new
enough to provide it.

12 years agolocking: Fix build with sanlock < 2.4
Jiri Denemark [Tue, 16 Oct 2012 10:41:20 +0000 (12:41 +0200)]
locking: Fix build with sanlock < 2.4

libvirt started using sanlock_killpath to implement on_lockfailure
action. Since sanlock_killpath was introduced in sanlock 2.4, libvirt
fails to build with older sanlock.

12 years agoFix typo in previous commit s/lik/like/
Daniel P. Berrange [Tue, 16 Oct 2012 15:37:26 +0000 (16:37 +0100)]
Fix typo in previous commit s/lik/like/

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoMake virInitialize thread safe
Daniel P. Berrange [Wed, 10 Oct 2012 15:11:43 +0000 (16:11 +0100)]
Make virInitialize thread safe

Currently there is a restriction that multi-threaded applications
must manually call virInitialize, before threads start using
libvirt, because it is not thread-safe. By switching it to use
a virOnceControl initializer we gain thread safety, and thus
applications no longer need to manually call it. They can rely
on virConnectOpen invoking it for them.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix virProcessKillPainfully on Win32
Daniel P. Berrange [Tue, 16 Oct 2012 14:46:12 +0000 (15:46 +0100)]
Fix virProcessKillPainfully on Win32

Win32 platforms don't have SIGKILL defined, but they do have
SIGABRT. Since our virProcess wrapper treats anything which
isn't SIGTERM/SIGINT as equivalent to SIGKILL, just use
SIGABRT on Win32.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd JSON serialization of virNetServerPtr objects for process re-exec()
Daniel P. Berrange [Thu, 9 Aug 2012 11:54:54 +0000 (12:54 +0100)]
Add JSON serialization of virNetServerPtr objects for process re-exec()

Add two new APIs virNetServerNewPostExecRestart and
virNetServerPreExecRestart which allow a virNetServerPtr
object to be created from a JSON object and saved to a
JSON object, for the purpose of re-exec'ing a process.

This includes serialization of all registered services
and clients

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd JSON serialization of virNetServerClientPtr objects for process re-exec()
Daniel P. Berrange [Thu, 9 Aug 2012 11:54:54 +0000 (12:54 +0100)]
Add JSON serialization of virNetServerClientPtr objects for process re-exec()

Add two new APIs virNetServerClientNewPostExecRestart and
virNetServerClientPreExecRestart which allow a virNetServerClientPtr
object to be created from a JSON object and saved to a
JSON object, for the purpose of re-exec'ing a process.

This includes serialization of the connected socket associated
with the client

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd JSON serialization of virNetServerServicePtr objects for process re-exec()
Daniel P. Berrange [Thu, 9 Aug 2012 11:54:54 +0000 (12:54 +0100)]
Add JSON serialization of virNetServerServicePtr objects for process re-exec()

Add two new APIs virNetServerServiceNewPostExecRestart and
virNetServerServicePreExecRestart which allow a virNetServerServicePtr
object to be created from a JSON object and saved to a
JSON object, for the purpose of re-exec'ing a process.

This includes serialization of the listening sockets associated
with the service

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd JSON serialization of virNetSocketPtr objects for process re-exec()
Daniel P. Berrange [Thu, 9 Aug 2012 11:54:54 +0000 (12:54 +0100)]
Add JSON serialization of virNetSocketPtr objects for process re-exec()

Add two new APIs virNetSocketNewPostExecRestart and
virNetSocketPreExecRestart which allow a virNetSocketPtr
object to be created from a JSON object and saved to a
JSON object, for the purpose of re-exec'ing a process.

As well as saving the state in JSON format, the second
method will disable the O_CLOEXEC flag so that the open
file descriptors are preserved across the process re-exec()

Since it is not possible to serialize SASL or TLS encryption
state, an error will be raised if attempting to perform
serialization on non-raw sockets

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd JSON serialization of virLockSpacePtr objects for process re-exec()
Daniel P. Berrange [Thu, 9 Aug 2012 10:54:37 +0000 (11:54 +0100)]
Add JSON serialization of virLockSpacePtr objects for process re-exec()

Add two new APIs virLockSpaceNewPostExecRestart and
virLockSpacePreExecRestart which allow a virLockSpacePtr
object to be created from a JSON object and saved to a
JSON object, for the purposes of re-exec'ing a process.

As well as saving the state in JSON format, the second
method will disable the O_CLOEXEC flag so that the open
file descriptors are preserved across the process re-exec()

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoIntroduce an internal API for handling file based lockspaces
Daniel P. Berrange [Thu, 2 Aug 2012 16:02:40 +0000 (17:02 +0100)]
Introduce an internal API for handling file based lockspaces

The previously introduced virFile{Lock,Unlock} APIs provide a
way to acquire/release fcntl() locks on individual files. For
unknown reason though, the POSIX spec says that fcntl() locks
are released when *any* file handle referring to the same path
is closed. In the following sequence

  threadA: fd1 = open("foo")
  threadB: fd2 = open("foo")
  threadA: virFileLock(fd1)
  threadB: virFileLock(fd2)
  threadB: close(fd2)

you'd expect threadA to come out holding a lock on 'foo', and
indeed it does hold a lock for a very short time. Unfortunately
when threadB does close(fd2) this releases the lock associated
with fd1. For the current libvirt use case for virFileLock -
pidfiles - this doesn't matter since the lock is acquired
at startup while single threaded an never released until
exit.

To provide a more generally useful API though, it is necessary
to introduce a slightly higher level abstraction, which is to
be referred to as a "lockspace".  This is to be provided by
a virLockSpacePtr object in src/util/virlockspace.{c,h}. The
core idea is that the lockspace keeps track of what files are
already open+locked. This means that when a 2nd thread comes
along and tries to acquire a lock, it doesn't end up opening
and closing a new FD. The lockspace just checks the current
list of held locks and immediately returns VIR_ERR_RESOURCE_BUSY.

NB, the API as it stands is designed on the basis that the
files being locked are not being otherwise opened and used
by the application code. One approach to using this API is to
acquire locks based on a hash of the filepath.

eg to lock /var/lib/libvirt/images/foo.img the application
might do

   virLockSpacePtr lockspace = virLockSpaceNew("/var/lib/libvirt/imagelocks");
   lockname = md5sum("/var/lib/libvirt/images/foo.img");
   virLockSpaceAcquireLock(lockspace, lockname);

NB, in this example, the caller should ensure that the path
is canonicalized before calculating the checksum.

It is also possible to do locks directly on resources by
using a NULL lockspace directory and then using the file
path as the lock name eg

   virLockSpacePtr lockspace = virLockSpaceNew(NULL);
   virLockSpaceAcquireLock(lockspace, "/var/lib/libvirt/images/foo.img");

This is only safe to do though if no other part of the process
will be opening the files. This will be the case when this
code is used inside the soon-to-be-reposted virlockd daemon

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agotests: Fix domain-events python test
Martin Kletzander [Tue, 16 Oct 2012 14:24:41 +0000 (16:24 +0200)]
tests: Fix domain-events python test

There was a missing method in python implementation of domain-events
test and this patch adds that.

12 years agomaint: prepare for next release number
Eric Blake [Mon, 15 Oct 2012 21:17:34 +0000 (15:17 -0600)]
maint: prepare for next release number

Given Daniel's announcement[1], code targetting the next release will
be in 1.0.0, not 0.10.3.  Changed mechanically with:

for f in $(git grep -l '0\(.\)10\13\b') ; do
   sed -i -e 's/0\(.\)10\13/1\10\10/g' $f
done

[1]https://www.redhat.com/archives/libvir-list/2012-October/msg00403.html

* docs/formatdomain.html.in: Use 1.0.0 for next release.
* src/interface/interface_backend_udev.c: Likewise.

12 years agomaint: fix license on polkit script
Eric Blake [Mon, 15 Oct 2012 20:09:05 +0000 (14:09 -0600)]
maint: fix license on polkit script

As approved here:
https://www.redhat.com/archives/libvir-list/2012-October/msg00701.html

* daemon/libvirtd.policy.in: Use LGPLv2+ license.

12 years agoconf: add test for boot dev and order
Martin Kletzander [Tue, 16 Oct 2012 10:25:32 +0000 (12:25 +0200)]
conf: add test for boot dev and order

Add test for 280b8c9e7c94db1decdca08d169c88554c09fa19.

12 years agoconf: Fix crash with cleanup
Martin Kletzander [Tue, 16 Oct 2012 09:15:04 +0000 (11:15 +0200)]
conf: Fix crash with cleanup

There was a crash possible when both <boot dev... and <boot
order... were specified due to virDomainDefParseBootXML() erroring out
before setting *tmp (which was free'd in cleanup).  As a fix, I
created this cleanup that uses one pointer for all the temporary
stored XPath strings and values, plus this pointer is correctly
initialized to NULL.

12 years agoselinux: Use raw contexts 2
Martin Kletzander [Mon, 15 Oct 2012 12:04:36 +0000 (14:04 +0200)]
selinux: Use raw contexts 2

In commit 9674f2c637114fa6ac0680fe5658a41a62bb34a8, I forgot to change
selabel_lookup with the other functions, so this one-liner does exactly
that.

12 years agomaint: drop spurious semicolons
Eric Blake [Mon, 15 Oct 2012 15:08:19 +0000 (09:08 -0600)]
maint: drop spurious semicolons

Detected with:
git grep ';;$' -- '**/*.[ch]'

* src/network/bridge_driver.c (networkRadvdConfContents): Fix
harmless typo.
* src/phyp/phyp_driver.c (phypUUIDTable_Pull): Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONDriveDel):
Likewise.

12 years agoselinux: add security selinux function to label tapfd
Guannan Ren [Mon, 15 Oct 2012 09:03:49 +0000 (17:03 +0800)]
selinux: add security selinux function to label tapfd

BZ:https://bugzilla.redhat.com/show_bug.cgi?id=851981
When using macvtap, a character device gets first created by
kernel with name /dev/tapN, its selinux context is:
system_u:object_r:device_t:s0

Shortly, when udev gets notification when new file is created
in /dev, it will then jump in and relabel this file back to the
expected default context:
system_u:object_r:tun_tap_device_t:s0

There is a time gap happened.
Sometimes, it will have migration failed, AVC error message:
type=AVC msg=audit(1349858424.233:42507): avc:  denied  { read write } for
pid=19926 comm="qemu-kvm" path="/dev/tap33" dev=devtmpfs ino=131524
scontext=unconfined_u:system_r:svirt_t:s0:c598,c908
tcontext=system_u:object_r:device_t:s0 tclass=chr_file

This patch will label the tapfd device before qemu process starts:
system_u:object_r:tun_tap_device_t:MCS(MCS from seclabel->label)

12 years agoAdd support for SUSPEND_DISK event
Martin Kletzander [Fri, 12 Oct 2012 19:13:39 +0000 (21:13 +0200)]
Add support for SUSPEND_DISK event

This patch adds support for SUSPEND_DISK event; both lifecycle and
separated.  The support is added for QEMU, machines are changed to
PMSUSPENDED, but as QEMU sends SHUTDOWN afterwards, the state changes
to shut-off.  This and much more needs to be done in order for libvirt
to work with transient devices, wake-ups etc.  This patch is not
aiming for that functionality.

12 years agoutil: switch virLogEatParams to virLogSource
Ján Tomko [Mon, 15 Oct 2012 07:14:26 +0000 (09:14 +0200)]
util: switch virLogEatParams to virLogSource

Commit e8fd8757c89abbd38571092bbb987650b7658aec changed 'const char *'
category to virLogSource enum. This changes it in virLogEatParams as
well, thus fixing the build with --disable-debug.
--
Hopefully moving the enum declarations is less ugly than using int.

12 years agonode_memory: Add new parameter field to tune the new sysfs knob
Osier Yang [Fri, 12 Oct 2012 08:25:42 +0000 (16:25 +0800)]
node_memory: Add new parameter field to tune the new sysfs knob

Upstream kernel introduced new sysfs knob "merge_across_nodes" to
specify if pages from different numa nodes can be merged. When set
to 0, only pages which physically reside in the memory area of
same NUMA node can be merged. When set to 1, pages from all nodes
can be merged.

This patch supports the tuning by adding new param field
"shm_merge_across_nodes".

12 years agoqemu: reorganize qemuDomainChangeNet and qemuDomainChangeNetBridge
Laine Stump [Wed, 10 Oct 2012 19:38:00 +0000 (15:38 -0400)]
qemu: reorganize qemuDomainChangeNet and qemuDomainChangeNetBridge

This patch resolves:

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

to the extent that it can be resolved with current qemu functionality.
It attempts to detect as many situations as possible when the simple
operation of disconnecting an existing tap device from one bridge and
attaching it to another will satisfy the change requested in
virDomainUpdateDeviceFlags() for a network device. Before this patch,
that situation could only be detected if the pre-change interface
*and* the post-change interface definition were both "type='bridge'".
After this patch, it can also be detected if the before or after
interfaces are any combination of type='bridge' and type='network'
(the networks can be <forward mode='nat|route|bridge'>, as long as
they use a Linux host bridge and not macvtap connections).

This extra effort is especially useful since the recent discovery that
a netdev_del+netdev_add combo (to reconnect the network device with
completely different hostside configuration) doesn't work properly
with current qemu (1.2) unless it is accompanied by the matching
device_del+device_add - see this mailing list message for details:

  http://lists.nongnu.org/archive/html/qemu-devel/2012-10/msg02355.html

(A slight modification of the patch referenced there has been prepared
to apply on top of this patch, but won't be pushed until qemu can be
made to work with it.)

* qemuDomainChangeNet needs access to the virDomainDeviceDef that
holds the new netdef (so that it can clear out the virDomainDeviceDef
if it ends up using the NetDef to replace the original), so the
virDomainNetDefPtr arg is replaced with a virDomainDeviceDefPtr.

* qemuDomainChangeNet previously checked for *some* changes to the
interface config, but this check was by no means complete. It was also
a bit disorganized.

This refactoring of the code is (I believe) complete in its check of
all NetDef attributes that might be changed, and either returns a
failure (for changes that are simply impossible), or sets one of three
flags:

  needLinkStateChange - if the device link state needs to go up/down
  needBridgeChange    - if everything else is the same, but it needs
                        to be connected to a difference linux host
                        bridge
  needReconnect       - if the entire host side of the device needs
                        to be torn down and reconstructed (currently
                        non-working, as mentioned above)

Note that this function will refuse to make any change that requires
the *guest* side of the device to be detached (e.g. changing the PCI
address or mac address). Those would be disruptive enough to the guest
that it's reasonable to require an explicit detach/attach sequence
from the management application.

* As mentioned above, qemuDomainChangeNet also does its best to
understand when a simple change in attached bridge for the existing
tap device will work vs. the need to completely tear down/reconstruct
the host side of the device (including tap device).

This patch *does not* implement the "reconnect" code anyway - there is
a placeholder that turns that into an error. Rather, the purpose of
this patch is to replicate existing behavior with code that is ready
to have that functionality plugged in in a later patch.

* The expanded uses for qemuDomainChangeNetBridge meant that it needed
to be enhanced as well - it no longer replaces the original brname
string in olddev with the new brname; instead, it relies on the
caller to replace the *entire* olddev with newdev (since we've gone
to great lengths to assure they are functionally identical other
than the name of the bridge, this is now not only safe, but more
correct). Additionally, qemuDomainNetChangeBridge can now set the
bridge for type='network' interfaces as well as plain type='bridge'
interfaces. (Note that I had to make this change simultaneous to the
reorganization of qemuDomainChangeNet because the two are too
closely intertwined to separate).

12 years agoAvoid straying </cpuset>
Guido Günther [Mon, 15 Oct 2012 07:58:28 +0000 (09:58 +0200)]
Avoid straying </cpuset>

by using the same condition as for the <cpuset>.

Fixes "make check" found by
    http://honk.sigxcpu.org:8001/job/libvirt-check/160/

12 years agoconf: virDomainDeviceInfoCopy utility function
Laine Stump [Thu, 11 Oct 2012 05:09:00 +0000 (01:09 -0400)]
conf: virDomainDeviceInfoCopy utility function

This does a shallow copy of all the bits, then strdups the two items
that are actually allocated separately.

12 years agoconf: fix virDevicePCIAddressEqual args
Laine Stump [Thu, 11 Oct 2012 16:34:14 +0000 (12:34 -0400)]
conf: fix virDevicePCIAddressEqual args

This function really should have been taking virDevicePCIAddress*
instead of the inefficient virDevicePCIAddress (results in copying two
entire structs onto the stack rather than just two pointers), and
returning a bool true/false (not matching is not necessarily a
"failure", as a -1 return would imply, and also using "if
(!virDevicePCIAddressEqual(x, y))" to mean "if x == y" is just a bit
counterintuitive).

12 years agoFix tab vs space
Guido Günther [Mon, 15 Oct 2012 07:15:14 +0000 (09:15 +0200)]
Fix tab vs space

that broke "make syntax-check"

found by http://honk.sigxcpu.org:8001/job/libvirt-syntax-check/157/

Pushed under the build breaker rule.

12 years agoqemu: Ignore def->cpumask if emulatorpin is specified
Osier Yang [Fri, 12 Oct 2012 09:50:49 +0000 (17:50 +0800)]
qemu: Ignore def->cpumask if emulatorpin is specified

If the vcpu placement is "static", it's just fine to ignore the
def->cpumask if emulatorpin is specified.

12 years agoconf: Ignore emulatorpin if vcpu placement is auto
Osier Yang [Fri, 12 Oct 2012 14:44:35 +0000 (22:44 +0800)]
conf: Ignore emulatorpin if vcpu placement is auto

When vcpu placement is "auto", the domain process will be pinned
to advisory nodeset from querying numad, While emulatorpin will
override the pinning. That means both of them are to set the
pinning policy for domain process, but conflicts with each other.

This patch ingore emulatorpin if vcpu placement is "auto", because
<vcpu> placement can't be simply ignored for <numatune> placement
could default to it.

12 years agoqemu: Initialize cpuset for hotplugged vcpu as def->cpuset
Osier Yang [Fri, 12 Oct 2012 09:50:47 +0000 (17:50 +0800)]
qemu: Initialize cpuset for hotplugged vcpu as def->cpuset

The onlined vcpu pinning policy should inherit def->cpuset if
it's not specified explicitly, and the affinity should be set
in this case. Oppositely, the offlined vcpu pinning policy should
be free()'ed.

12 years agoqemu: Create or remove cgroup when doing vcpu hotpluging
Osier Yang [Fri, 12 Oct 2012 09:50:46 +0000 (17:50 +0800)]
qemu: Create or remove cgroup when doing vcpu hotpluging

Various APIs use cgroup to either set or get the statistics of
host or guest. Hotplug or hot unplug new vcpus without creating
or removing the cgroup for the vcpus could cause problems for
those APIs. E.g.

% virsh vcpucount dom
maximum      config        10
maximum      live          10
current      config         1
current      live           1

% virsh setvcpu dom 2

% virsh schedinfo dom --set vcpu_quota=1000
Scheduler      : posix
error: Unable to find vcpu cgroup for rhel6.2(vcpu: 1): No such file or
directory

This patch fixes the problem by creating cgroups for each of the
onlined vcpus, and destroying cgroups for each of the offlined
vcpus.

12 years agoconf: Initialize the pinning policy for vcpus
Osier Yang [Fri, 12 Oct 2012 09:50:45 +0000 (17:50 +0800)]
conf: Initialize the pinning policy for vcpus

Document for <vcpu>'s "cpuset" says:

Since 0.4.4, this element can contain an optional cpuset attribute,
which is a comma-separated list of physical CPU numbers that virtual
CPUs can be pinned to.

However, it's not the truth, libvirt actually pins the domain
process to the specified pCPUs by "cpuset" of <vcpu>. And the
vcpu thread are pinned to all available pCPUs if no <vcpupin>
is specified for it.

This patch is to implement the codes to inherit <vcpu>'s "cpuset" for
vcpu that doesn't have <vcpupin> specified, and <vcpupin>
for these vcpu will be ignored when formating. Underlying
driver implementation will make sure the vcpu thread pinned
to correct pCPUs.

12 years agoconf: Ignore vcpupin for not onlined vcpus when parsing
Osier Yang [Fri, 12 Oct 2012 13:52:07 +0000 (21:52 +0800)]
conf: Ignore vcpupin for not onlined vcpus when parsing

Setting pinning policy for vcpu which exceeds current vcpus number
just makes no sense, however, it could cause various problems, E.g.

<vcpu current='1'>4</vcpu>
<cputune>
  <vcpupin vcpuid='3' cpuset='4'/>
</cputune>

% virsh start linux
error: Failed to start domain linux
error: cannot set CPU affinity on process 32534: No such process

We must have some odd codes underlying which produces the
"on process 32534", but the point is why we not to prevent
earlier when parsing? Note that this is only one of the
problem it could cause.

This patch is to ignore the <vcpupin> for not onlined vcpus.

12 years agodoc: Sort out the relationship between <vcpu>, <vcpupin>, and <emulatorpin>
Osier Yang [Fri, 12 Oct 2012 09:50:43 +0000 (17:50 +0800)]
doc: Sort out the relationship between <vcpu>, <vcpupin>, and <emulatorpin>

These 3 elements conflicts with each other in either the doc
or the underlying codes.

Current problems:

Problem 1:

The doc shouldn't simply say "These settings are superseded
by CPU tuning. " for element <vcpu>. As except the tuning, <vcpu>
allows to specify the current, maxmum vcpu number. Apart from that,
<vcpu> also allows to specify the placement as "auto", which binds
the domain process to the advisory nodeset from numad.

Problem 2:

Doc for <vcpu> says its "cpuset" specify the physical CPUs
that the vcpus can be pinned. But it's not the truth, as
actually it only pin domain process to the specified physical
CPUs. So either it's a document bug, or code bug.

Problem 3:

Doc for <vcpupin> says it supersed "cpuset" of <vcpu>, it's
not quite correct, as each <vcpupin> specify the pinning policy
only for one vcpu. How about the ones which doesn't have
<vcpupin> specified? it says the vcpu will be pinned to all
available physical CPUs, but what's the meaning of attribute
"cpuset" of <vcpu> then?

Problem 4:

Doc for <emulatorpin> says it pin the emulator threads (domain
process in other context, perhaps another follow up patch to
cleanup the inconsistency is needed) to the physical CPUs
specified its attribute "cpuset". Which conflicts with
<vcpu>'s "cpuset". And actually in the underlying codes,
it set the affinity for domain process twice if both
"cpuset" for <vcpu> and <emulatorpin> are specified,
and <emulatorpin>'s pinning will override <vcpu>'s.

Problem 5:

When "placement" of <vcpu> is "auto" (I.e. uses numad to
get the advisory nodeset to which the domain process is
pinned to), it will also be overridden by <emulatorpin>,

This patch is trying to sort out the conflicts or bugs by:

1) Don't say <vcpu> is superseded by <cputune>

2) Keep the semanteme for "cpuset" of <vcpu> (I.e. Still says it
   specify the physical CPUs the virtual CPUs). But modifying it
   to mention it also set the pinning policy for domain process,
   and the CPU placement of domain process specified by "cpuset"
   of <vcpu> will be ingored if <emulatorpin> specified, and
   similary, the CPU placement of vcpu thread will be ignored
   if it has <vcpupin> specified, for vcpu which doesn't have
   <vcpupin> specified, it inherits "cpuset" of <vcpu>.

3) Don't say <vcpu> is supersed by <vcpupin>. If neither <vcpupin>
   nor "cpuset" of <vcpu> is specified, the vcpu will be pinned
   to all available pCPUs.

4) If neither <emulatorpin> nor "cpuset" of <vcpu> is specified,
   the domain process (emulator threads in the context) will be
   pinned to all available pCPUs.

5) If "placement" of <vcpu> is "auto", <emulatorpin> is not allowed.

6) hotplugged vcpus will also inherit "cpuset" of <vcpu>

Codes changes according to above document changes:

1) Inherit def->cpumask for each vcpu which doesn't have <vcpupin>
   specified, during parsing.

2) ping the vcpu which doesn't have <vcpupin> specified to def->cpumask
   either by cgroup for sched_setaffinity(2), which is actually done
   by 1).

3) Error out if "placement" == "auto", and <emulatorpin> is specified.
   Otherwise, <emulatorpin> is honored, and "cpuset" of <cpuset> is
   ignored.

4) Setup cgroup for each hotplugged vcpu, and setup the pinning policy
   by either cgroup or sched_setaffinity(2).

5) Remove cgroup and <vcpupin> for each hot unplugged vcpu.

Patches are following (6 in total except this patch)

12 years agoTweak comments in the policykit rules file
Cole Robinson [Fri, 12 Oct 2012 15:56:17 +0000 (11:56 -0400)]
Tweak comments in the policykit rules file

- Add the XML header so vim gives us syntax highlighting
- polkit-policy-file-validate hasn't existed for 3 years
- Permissions comment was not accurate

12 years agoOnly keep one polkit rules file
Cole Robinson [Fri, 12 Oct 2012 14:51:48 +0000 (10:51 -0400)]
Only keep one polkit rules file

Just tweak it at build time depending on what polkit version we are
building for.

12 years agodaemon: Use $(AM_V_GEN) in a few more places
Cole Robinson [Sat, 13 Oct 2012 14:12:04 +0000 (10:12 -0400)]
daemon: Use $(AM_V_GEN) in a few more places

12 years agoProperly parse (unsigned) long long
Guido Günther [Fri, 12 Oct 2012 23:05:40 +0000 (01:05 +0200)]
Properly parse (unsigned) long long

This fixes problems on platforms where sizeof(long) != sizeof(long long)
like ia32.

12 years agospec: Add support for libssh2 transport
Peter Krempa [Fri, 12 Oct 2012 14:50:42 +0000 (16:50 +0200)]
spec: Add support for libssh2 transport

Libssh2 transport support was enabled lately but the spec file wasn't
updated to take this into account. This caused libvirt to be built
without libssh2 support in Red Hat based OSes.

12 years agoselinux: Use raw contexts
Martin Kletzander [Fri, 5 Oct 2012 14:41:22 +0000 (16:41 +0200)]
selinux: Use raw contexts

We are currently able to work only with non-translated SELinux
contexts, but we are using functions that work with translated
contexts throughout the code.  This patch swaps all SELinux context
translation relative calls with their raw sisters to avoid parsing
problems.

The problems can be experienced with mcstrans for example.  The
difference is that if you have translations enabled (yum install
mcstrans; service mcstrans start), fgetfilecon_raw() will get you
something like 'system_u:object_r:virt_image_t:s0', whereas
fgetfilecon() will return 'system_u:object_r:virt_image_t:SystemLow'
that we cannot parse.

I was trying to confirm that the _raw variants were here since the dawn of
time, but the only thing I see now is that it was imported together in
the upstream repo [1] from svn, so before 2008.

Thanks Laurent Bigonville for finding this out.

[1] http://oss.tresys.com/git/selinux.git

12 years agoconf: Mark missing optional USB devices in domain XML
Jiri Denemark [Thu, 11 Oct 2012 20:33:46 +0000 (22:33 +0200)]
conf: Mark missing optional USB devices in domain XML

When startupPolicy set for a USB devices allows such device to be
missing, there was no way this could be detected from domain XML. With
this patch, libvirt emits a new missing='yes' attribute for such devices
when active domain XML is generated.

12 years agovirsh: remove reference to migration in blockcopy
Ján Tomko [Thu, 11 Oct 2012 15:14:39 +0000 (17:14 +0200)]
virsh: remove reference to migration in blockcopy

12 years agovirsh: block SIGINT while getting BlockJobInfo
Ján Tomko [Thu, 11 Oct 2012 15:12:13 +0000 (17:12 +0200)]
virsh: block SIGINT while getting BlockJobInfo

SIGINT hasn't been blocked, which could lead to losing it somewhere in
virDomainGetBlockJobInfo and not aborting the job.

12 years agoVarious typos and misspellings
Ján Tomko [Thu, 11 Oct 2012 16:31:20 +0000 (18:31 +0200)]
Various typos and misspellings

12 years agoqemu: Fix misleading comment for qemuDomainObjBeginJobWithDriver()
Peter Krempa [Thu, 27 Sep 2012 09:17:19 +0000 (11:17 +0200)]
qemu: Fix misleading comment for qemuDomainObjBeginJobWithDriver()

The comment stated that you may call qemuDomainObjBeginJobWithDriver
without passing qemud_driver to signal it's not locked.
qemuDomainObjBeginJobWithDriver still accesses the qemud_driver
structure and the lock singaling is done through a separate parameter.

12 years agoqemu: Make save/restore with USB devices usable
Jiri Denemark [Tue, 9 Oct 2012 11:15:46 +0000 (13:15 +0200)]
qemu: Make save/restore with USB devices usable

Save/restore with passed through USB devices currently only works if the
USB device can be found at the same USB address where it used to be
before saving a domain. This makes sense in case a user explicitly
configure the USB address in domain XML. However, if the device was
found automatically by vendor/product identification, we should try to
search for that device when restoring the domain and use any device we
find as long as there is only one available. In other words, the USB
device can now be removed and plugged again or the host can be rebooted
between saving and restoring the domain.

12 years agoAdd MIGRATABLE flag for virDomainGetXMLDesc
Jiri Denemark [Mon, 8 Oct 2012 09:58:05 +0000 (11:58 +0200)]
Add MIGRATABLE flag for virDomainGetXMLDesc

Using VIR_DOMAIN_XML_MIGRATABLE flag, one can request domain's XML
configuration that is suitable for migration or save/restore. Such XML
may contain extra run-time stuff internal to libvirt and some default
configuration may be removed for better compatibility of the XML with
older libvirt releases.

This flag may serve as an easy way to get the XML that can be passed
(after desired modifications) to APIs that accept custom XMLs, such as
virDomainMigrate{,ToURI}2 or virDomainSaveFlags.

12 years agoqemu: Implement startupPolicy for USB passed through devices
Jiri Denemark [Thu, 4 Oct 2012 14:18:16 +0000 (16:18 +0200)]
qemu: Implement startupPolicy for USB passed through devices

12 years agoqemu: Add option to treat missing USB devices as success
Jiri Denemark [Wed, 3 Oct 2012 14:57:28 +0000 (16:57 +0200)]
qemu: Add option to treat missing USB devices as success

All USB device lookup functions emit an error when they cannot find the
requested device. With this patch, their caller can choose if a missing
device is an error or normal condition.

12 years agoqemu: Introduce qemuFindHostdevUSBDevice
Jiri Denemark [Wed, 3 Oct 2012 11:55:35 +0000 (13:55 +0200)]
qemu: Introduce qemuFindHostdevUSBDevice

The code which looks up a USB device specified by hostdev is duplicated
in two places. This patch creates a dedicated function that can be
called in both places.

12 years agoconf: Add support for startupPolicy for USB devices
Jiri Denemark [Tue, 2 Oct 2012 13:14:02 +0000 (15:14 +0200)]
conf: Add support for startupPolicy for USB devices

USB devices can disappear without OS being mad about it, which makes
them ideal for startupPolicy. With this attribute, USB devices can be
configured to be mandatory (the default), requisite (will disappear
during migration if they cannot be found), or completely optional.

12 years agolocking: Implement lock failure action in sanlock driver
Jiri Denemark [Tue, 18 Sep 2012 11:41:26 +0000 (13:41 +0200)]
locking: Implement lock failure action in sanlock driver

While the changes to sanlock driver should be stable, the actual
implementation of sanlock_helper is supposed to be replaced in the
future. However, before we can implement a better sanlock_helper, we
need an administrative interface to libvirtd so that the helper can just
pass a "leases lost" event to the particular libvirt driver and
everything else will be taken care of internally. This approach will
also allow libvirt to pass such event to applications and use
appropriate reasons when changing domain states.

The temporary implementation handles all actions directly by calling
appropriate libvirt APIs (which among other things means that it needs
to know the credentials required to connect to libvirtd).