]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
12 years agoSupport custom 'svirt_tcg_t' context for TCG based guests
Daniel P. Berrange [Wed, 12 Dec 2012 11:47:19 +0000 (11:47 +0000)]
Support custom 'svirt_tcg_t' context for TCG based guests

The current SELinux policy only works for KVM guests, since
TCG requires the 'execmem' privilege. There is a 'virt_use_execmem'
boolean to turn this on globally, but that is unpleasant for users.
This changes libvirt to automatically use a new 'svirt_tcg_t'
context for TCG based guests. This obsoletes the previous
boolean tunable and makes things 'just work(tm)'

Since we can't assume we run with new enough policy, I also
make us log a warning message (once only) if we find the policy
lacks support. In this case we fallback to the normal label and
expect users to set the boolean tunable

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agodocs: Replace </br> with <br/> in docs/news.html.in
Peter Krempa [Mon, 17 Dec 2012 10:01:16 +0000 (11:01 +0100)]
docs: Replace </br> with <br/> in docs/news.html.in

12 years agotests: add one -device video device testcase
Guannan Ren [Fri, 14 Dec 2012 07:09:17 +0000 (15:09 +0800)]
tests: add one -device video device testcase

The testcase is for testing non-fixed PCI address for primary
video device and using video args to -deivce qemu option.

12 years agoqemu: use newer -device video device in qemu commandline
Guannan Ren [Fri, 14 Dec 2012 07:08:01 +0000 (15:08 +0800)]
qemu: use newer -device video device in qemu commandline

'-device VGA' maps to '-vga std'
'-device cirrus-vga' maps to '-vga cirrus'
'-device qxl-vga' maps to '-vga qxl'
             (there is also '-device qxl' for secondary devices)
'-device vmware-svga' maps to '-vga vmware'

For qemu(>=1.2), we can use -device to replace -vga for video
device. For the primary video device, the patch tries to use 0x2
slot for matching old qemu. If the 0x2 slot is allocated already,
the addr property could help for using any available slot.
For qemu(< 1.2), we keep using -vga for primary device.

12 years agoconf: add optional attribte primary to video <model> element
Guannan Ren [Mon, 17 Dec 2012 06:01:20 +0000 (14:01 +0800)]
conf: add optional attribte primary to video <model> element

If there are multiple video devices
primary = 'yes' marks this video device as the primary one.
The rest are secondary video devices. No more than one could be
mark as primary. If none of them has primary attribute, the first
one will be the primary by default like what it was.
The reason of this changing is that for qemu, only one primary video
device is permitted which can be of any type. For secondary video
devices, only qxl is allowd. Primary attribute removes the restriction
that the first have to be the primary one.

We always put the primary video device into the first position of
video device structure array after parsing.

12 years agoqemu: add qemu vga devices caps and one cap to mark them usable
Guannan Ren [Fri, 14 Dec 2012 07:06:31 +0000 (15:06 +0800)]
qemu: add qemu vga devices caps and one cap to mark them usable

QEMU_CAPS_DEVICE_QXL          -device qxl
QEMU_CAPS_DEVICE_VGA          -device VGA
QEMU_CAPS_DEVICE_CIRRUS_VGA   -device cirrus-vga
QEMU_CAPS_DEVICE_VMWARE_SVGA  -device vmware-svga

QEMU_CAPS_DEVICE_VIDEO_PRIMARY  /* safe to use -device XXX
                                 for primary video device */

Fix a typo in qemuCapsObjectTypes, the string 'qxl' here
should be -device qxl rather than -vga [...|qxl|..]

12 years agoRelease of libvirt-1.0.1
Daniel Veillard [Mon, 17 Dec 2012 03:36:37 +0000 (11:36 +0800)]
Release of libvirt-1.0.1

- configure.ac docs/news.html.in: update for the release
- po/*.po: updated from transifex

12 years agobuild: minor build fixes for BSD
Eric Blake [Fri, 14 Dec 2012 19:02:10 +0000 (12:02 -0700)]
build: minor build fixes for BSD

Noticed these while building on FreeBSD.

* src/qemu/qemu_monitor.c (qemuMonitorBlockInfoLookup): Rename
variable to avoid 'devname' collision.
* src/qemu/qemu_driver.c (qemuDomainInterfaceStats): Mark unused
variable.

12 years agoSocket identity support for FreeBSD.
Roman Bogorodskiy [Fri, 14 Dec 2012 18:06:33 +0000 (22:06 +0400)]
Socket identity support for FreeBSD.

This adds an implementation of virNetSocketGetUNIXIdentity()
using LOCAL_PEERCRED socket option and xucred struct, defined
in <sys/ucred.h> on systems that have it.

12 years agonetwork: fix (non)update of dnsmasq config during virDomainUpdateDeviceFlags
Laine Stump [Fri, 14 Dec 2012 17:44:03 +0000 (12:44 -0500)]
network: fix (non)update of dnsmasq config during virDomainUpdateDeviceFlags

A forgotten "!" in recently-modified code at the top of
networkRefreshDaemon() meant an improper early return, which led to 1)
dnsmasq config files not being updated from the newly modified config,
and 2) dnsmasq not being sent a SIGHUP so that it could learn about
the changes to the config.

virNetworkDefGetIpByIndex() returns NULL if there are no ip objects of
the requested type, and if there are no IP elements, then dnsmasq
shouldn't be running, so we can return early. Otherwise we should
rewrite the config files and send a SIGHUP.

12 years agoRequire SANLK_INQ_WAIT for inq_lockspace support
Guido Günther [Thu, 13 Dec 2012 16:21:54 +0000 (17:21 +0100)]
Require SANLK_INQ_WAIT for inq_lockspace support

since compilation breaks otherwise with older libsanlock.

12 years agodocs: fix some typos in examples
Eric Blake [Fri, 14 Dec 2012 15:28:57 +0000 (08:28 -0700)]
docs: fix some typos in examples

As detected in https://bugzilla.redhat.com/show_bug.cgi?id=887187

* docs/formatdomain.html.in: Fix XML typos.

12 years agosanlock: Re-add lockspace unconditionally
Michal Privoznik [Fri, 14 Dec 2012 11:17:55 +0000 (12:17 +0100)]
sanlock: Re-add lockspace unconditionally

Currently, if sanlock is already registering a lockspace other
libvirtd instances (from other hosts) obtain -EINPROGRESS. On
sufficiently new sanlock, sanlock_inq_lockspace() is called,
which suspend execution until lockspace state is changed. With
current libvirt implementation, we fail to retry adding the
lockspace again but continue in error path. Therefore we produce
meaningless error message:

virLockManagerSanlockSetupLockspace:363 : Unable to add lockspace
/var/lib/libvirt/sanlock/__LIBVIRT__DISKS__: Success
qemudLoadDriverConfig:558 : Failed to load lock manager sanlock

We should try to re-add the lockspace after its state change to
be sure it was added successfully. In fact, with sufficiently new
sanlock we can just avoid dummy usleep() which is used if there's
no inquire API.

12 years agoinstall: fix virtlockd installation
Eric Blake [Thu, 13 Dec 2012 23:28:27 +0000 (16:28 -0700)]
install: fix virtlockd installation

The virtlockd daemon scripts were lousy, when compared to their
counterparts in daemon/Makefile.am.  In particular, when init
scripts were selected, this resulted in 'make distcheck' failing
due to failure to clean up src/virtlockd.init.

* src/Makefile.am (install-systemd): Fix dependencies.  Use MKDIR_P.
(uninstall-systemd): Remove empty directory.  Use fewer processes.
(install-init, install-sysconfig): Use MKDIR_P.
(uninstall-init): Remove correct file, and also empty directory.
(uninstall-sysconfig): Remove empty directory.
(DISTCLEANFILES): Clean up trivially built sources.

12 years agodocs: Fix location of libvirt.conf and auth.conf
Michał Łomnicki [Fri, 14 Dec 2012 02:52:17 +0000 (03:52 +0100)]
docs: Fix location of libvirt.conf and auth.conf

For a unprivileged user libvirt.conf and auth.conf are looked up in
$XDG_CONFIG_HOME but the docs incorrectly state that it's $XDG_CONFIG_DIR.

12 years agoqemu: don't fail update netdev on bridge detach failure
Laine Stump [Fri, 14 Dec 2012 00:09:51 +0000 (19:09 -0500)]
qemu: don't fail update netdev on bridge detach failure

When a network device's bridge connection is changed by
virDomainUpdateDevice, libvirt first removes the netdev's tap from its
old bridge, then adds it to the new bridge. Sometimes, due to a
network being destroyed while a guest device is still attached, the
tap may already be "removed" from the old bridge (or the old bridge
may not even exist any more); the existing code was needlessly failing
the update when this happened, making it impossible to recover from
the situation without completely detaching (i.e. removing) the netdev
from the guest and re-attaching.

Instead of failing the entire operation when removal of the tap from
the old bridge fails, this patch changes qemuDomainChangeNetBridge to
just log a warning and continue, allowing a reasonable recover from
the situation.

(you'll appreciate this change if you ever accidentally destroy a
network while your guests are still using it).

12 years agospec: Include lockd files in libvirt-daemon package
Jiri Denemark [Fri, 14 Dec 2012 10:57:27 +0000 (11:57 +0100)]
spec: Include lockd files in libvirt-daemon package

12 years agobuild: Install both qemu-lockd.conf and qemu-sanlock.conf
Jiri Denemark [Fri, 14 Dec 2012 10:54:16 +0000 (11:54 +0100)]
build: Install both qemu-lockd.conf and qemu-sanlock.conf

With sanlock enabled, only one of those files was installed.

12 years agobuild: use fewer cat processes
Eric Blake [Thu, 13 Dec 2012 22:43:39 +0000 (15:43 -0700)]
build: use fewer cat processes

* src/Makefile.am (libvirt.syms): Let cat loop for us.

12 years agoselinux: fix NULL dereference in GetSecurityMountOptions
Ján Tomko [Thu, 13 Dec 2012 10:44:37 +0000 (11:44 +0100)]
selinux: fix NULL dereference in GetSecurityMountOptions

In the case of an OOM error in virDomainDefGetSecurityLabelDef, secdef
is set to NULL, then dereferenced while printing the debug message.

12 years agobuild: Distribute more files
Jiri Denemark [Thu, 13 Dec 2012 22:13:21 +0000 (23:13 +0100)]
build: Distribute more files

12 years agolocking: Fix VPATH build and distribute generated files
Jiri Denemark [Thu, 13 Dec 2012 16:00:17 +0000 (17:00 +0100)]
locking: Fix VPATH build and distribute generated files

12 years agonetwork: prevent dnsmasq from listening on localhost
Laine Stump [Thu, 13 Dec 2012 06:46:40 +0000 (01:46 -0500)]
network: prevent dnsmasq from listening on localhost

This patch resolves the problem reported in:

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

The source of the problem was the fix for CVE 2011-3411:

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

which was originally committed upstream in commit
753ff83a50263d6975f88d6605d4b5ddfcc97560. That commit improperly
removed the "--except-interface lo" from dnsmasq commandlines when
--bind-dynamic was used (based on comments in the latter bug).

It turns out that the problem reported in the CVE could be eliminated
without removing "--except-interface lo", and removing it actually
caused each instance of dnsmasq to listen on localhost on port 53,
which created a new problem:

If another instance of dnsmasq using "bind-interfaces" (instead of
"bind-dynamic") had already been started (or if another instance
started later used "bind-dynamic"), this wouldn't have any immediately
visible ill effects, but if you tried to start another dnsmasq
instance using "bind-interfaces" *after* starting any libvirt
networks, the new dnsmasq would fail to start, because there was
already another process listening on port 53.

(Subsequent to the CVE fix, another patch changed the network driver
to put dnsmasq options in a conf file rather than directly on the
dnsmasq commandline, but preserved the same options.)

This patch changes the network driver to *always* add
"except-interface=lo" to dnsmasq conf files, regardless of whether we use
bind-dynamic or bind-interfaces. This way no libvirt dnsmasq instances
are listening on localhost (and the CVE is still fixed).

The actual code change is miniscule, but must be propogated through all
of the test files as well.

12 years agobuild: Fix VPATH build
Jiri Denemark [Thu, 13 Dec 2012 15:38:48 +0000 (16:38 +0100)]
build: Fix VPATH build

$(srcdir) is already part of $$file since commit f1f9a7ac7e.

12 years agovirsh: use vshReconnect for non-default connections too
Ján Tomko [Thu, 13 Dec 2012 13:08:01 +0000 (14:08 +0100)]
virsh: use vshReconnect for non-default connections too

For non-default connections (specified by the environment variable or
the command line option) we call virConnectOpenAuth without registering
the vshCatchDisconnect callback.

This calls vshReconnect instead which takes care of it.

12 years agovirsh: don't lie about reconnection in vshReconnect
Ján Tomko [Thu, 13 Dec 2012 13:08:00 +0000 (14:08 +0100)]
virsh: don't lie about reconnection in vshReconnect

Since we (ab)use vshReconnect for the default URI connection, if it
fails it might print 'Failed to reconnect to the hypervisor' even if we
were never connected before.

This changes it to only mention reconnection on the first try after
getting disconnected.

12 years agoAdd support for locking based on SCSI volume ID
Daniel P. Berrange [Tue, 11 Dec 2012 16:39:50 +0000 (16:39 +0000)]
Add support for locking based on SCSI volume ID

12 years agoAdd support for locking based on LVM volume uuid
Daniel P. Berrange [Tue, 11 Dec 2012 16:39:50 +0000 (16:39 +0000)]
Add support for locking based on LVM volume uuid

12 years agoAdd ability to maintain disk leases indirectly
Daniel P. Berrange [Tue, 14 Aug 2012 15:46:08 +0000 (16:46 +0100)]
Add ability to maintain disk leases indirectly

The default lockd driver behavour is to acquire leases
directly on the disk files. This introduces an alternative
mode, where leases are acquire indirectly on a file that
is based on a SHA256 hash of the disk filename.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd a virtlockd client as a lock driver impl
Daniel P. Berrange [Wed, 6 Jul 2011 16:30:08 +0000 (17:30 +0100)]
Add a virtlockd client as a lock driver impl

This adds a 'lockd' lock driver which is just a client which
talks to the lockd daemon to perform all locking. This will
be the default lock driver for any hypervisor which needs one.

* src/Makefile.am: Add lockd.so plugin
* src/locking/lock_driver_lockd.c: Lockd driver impl

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd support for re-exec() of virtlockd upon SIGUSR1
Daniel P. Berrange [Tue, 7 Aug 2012 11:13:26 +0000 (12:13 +0100)]
Add support for re-exec() of virtlockd upon SIGUSR1

The virtlockd daemon maintains file locks on behalf of libvirtd
and any VMs it is running. These file locks must be held for as
long as any VM is running. If virtlockd itself ever quits, then
it is expected that a node would be fenced/rebooted. Thus to
allow for software upgrads on live systemd, virtlockd needs the
ability to re-exec() itself.

Upon receipt of SIGUSR1, virtlockd will save its current live
state out to a file /var/run/virtlockd-restart-exec.json
It then re-exec()'s itself with exactly the same argv as it
originally had, and loads the state file, reconstructing any
objects as appropriate.

The state file contains information about all locks held and
all network services and clients currently active. An example
state document is

 {
    "server": {
        "min_workers": 1,
        "max_workers": 20,
        "priority_workers": 0,
        "max_clients": 20,
        "keepaliveInterval": 4294967295,
        "keepaliveCount": 0,
        "keepaliveRequired": false,
        "services": [
            {
                "auth": 0,
                "readonly": false,
                "nrequests_client_max": 1,
                "socks": [
                    {
                        "fd": 6,
                        "errfd": -1,
                        "pid": 0,
                        "isClient": false
                    }
                ]
            }
        ],
        "clients": [
            {
                "auth": 0,
                "readonly": false,
                "nrequests_max": 1,
                "sock": {
                    "fd": 9,
                    "errfd": -1,
                    "pid": 0,
                    "isClient": true
                },
                "privateData": {
                    "restricted": true,
                    "ownerPid": 1722,
                    "ownerId": 6,
                    "ownerName": "f18x86_64",
                    "ownerUUID": "97586ba9-df27-9459-c806-f016c8bbd224"
                }
            },
            {
                "auth": 0,
                "readonly": false,
                "nrequests_max": 1,
                "sock": {
                    "fd": 10,
                    "errfd": -1,
                    "pid": 0,
                    "isClient": true
                },
                "privateData": {
                    "restricted": true,
                    "ownerPid": 1784,
                    "ownerId": 7,
                    "ownerName": "f16x86_64",
                    "ownerUUID": "7b8e5e42-b875-61e9-b981-91ad8fa46979"
                }
            }
        ]
    },
    "defaultLockspace": {
        "resources": [
            {
                "name": "/var/lib/libvirt/images/f16x86_64.raw",
                "path": "/var/lib/libvirt/images/f16x86_64.raw",
                "fd": 14,
                "lockHeld": true,
                "flags": 0,
                "owners": [
                    1784
                ]
            },
            {
                "name": "/var/lib/libvirt/images/shared.img",
                "path": "/var/lib/libvirt/images/shared.img",
                "fd": 12,
                "lockHeld": true,
                "flags": 1,
                "owners": [
                    1722,
                    1784
                ]
            },
            {
                "name": "/var/lib/libvirt/images/f18x86_64.img",
                "path": "/var/lib/libvirt/images/f18x86_64.img",
                "fd": 11,
                "lockHeld": true,
                "flags": 0,
                "owners": [
                    1722
                ]
            }
        ]
    },
    "lockspaces": [

    ],
    "magic": "30199"
 }

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoEnable systemd socket activation with virtlockd
Daniel P. Berrange [Thu, 7 Jul 2011 14:02:32 +0000 (15:02 +0100)]
Enable systemd socket activation with virtlockd

This enhancement virtlockd so that it can receive a pre-opened
UNIX domain socket from systemd at launch time, and adds the
systemd service/socket unit files

* daemon/libvirtd.service.in: Require virtlockd to be running
* libvirt.spec.in: Add virtlockd systemd files
* src/Makefile.am: Install systemd files
* src/locking/lock_daemon.c: Support socket activation
* src/locking/virtlockd.service.in, src/locking/virtlockd.socket.in:
  systemd unit files
* src/rpc/virnetserverservice.c, src/rpc/virnetserverservice.h:
  Add virNetServerServiceNewFD() method
* src/rpc/virnetsocket.c, src/rpc/virnetsocket.h: Add virNetSocketNewListenFD
  method

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoImplement dispatch functions for lock protocol in virtlockd
Daniel P. Berrange [Fri, 3 Aug 2012 09:27:07 +0000 (10:27 +0100)]
Implement dispatch functions for lock protocol in virtlockd

Introduce a lock_daemon_dispatch.c file which implements the
server side dispatcher the RPC APIs previously defined in the
lock protocol.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoDefine a wire protocol for talking to the virtlockd daemon
Daniel P. Berrange [Wed, 6 Jul 2011 16:20:04 +0000 (17:20 +0100)]
Define a wire protocol for talking to the virtlockd daemon

The virtlockd daemon will be responsible for managing locks
on virtual machines. Communication will be via the standard
RPC infrastructure. This provides the XDR protocol definition

* src/locking/lock_protocol.x: Wire protocol for virtlockd
* src/Makefile.am: Include lock_protocol.[ch] in virtlockd

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoIntroduce basic infrastructure for virtlockd daemon
Daniel P. Berrange [Thu, 2 Aug 2012 19:06:50 +0000 (20:06 +0100)]
Introduce basic infrastructure for virtlockd daemon

The virtlockd daemon will maintain locks on behalf of libvirtd.
There are two reasons for it to be separate

 - Avoid risk of other libvirtd threads accidentally
   releasing fcntl() locks by opening + closing a file
   that is locked
 - Ensure locks can be preserved across libvirtd restarts.
   virtlockd will need to be able to re-exec itself while
   maintaining locks. This is simpler to achieve if its
   sole job is maintaining locks

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoRefactor creation of lock manager plugins
Daniel P. Berrange [Tue, 11 Dec 2012 15:59:21 +0000 (15:59 +0000)]
Refactor creation of lock manager plugins

Refactor virLockManagerPluginNew() so that the caller does
not need to pass in the config file path itself - just the
config directory and driver name.

Fix QEMU to actually pass in a config file when creating the
default lock manager plugin, rather than NULL.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix error reporting when fetching SCSI/LVM keys
Daniel P. Berrange [Tue, 11 Dec 2012 19:10:51 +0000 (19:10 +0000)]
Fix error reporting when fetching SCSI/LVM keys

The current  virStorageFileGet{LVM,SCSI}Key methods return
the key as the return value. Unfortunately it is desirable
for "NULL" to be a valid return value, as well as an error
indicator. Thus the returned key must instead be provided
as an out-parameter.

When we invoke lvs or scsi_id to extract ID for block devices,
we don't want virCommandWait logging errors messages. Thus we
must explicitly check 'status != 0', rather than letting
virCommandWait do it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoSupport network boot for HVM guests in libxl
Jim Fehlig [Wed, 12 Dec 2012 21:28:24 +0000 (14:28 -0700)]
Support network boot for HVM guests in libxl

The libxl driver ignored boot devices in the domain config,
preventing PXE booting HVM domains.  This patch accounts for
user-specified boot devices when building the libxl domain
configuration.

12 years agoFix probing of QED file format
Daniel P. Berrange [Thu, 13 Dec 2012 14:25:10 +0000 (14:25 +0000)]
Fix probing of QED file format

The QED file format is non-versioned, so although the magic
value matched, libvirt rejected it due to lack of a version
number to compare against. We need to distinguish this case
by allowing a value of '-2' to indicate a non-versioned file
where only the magic is required to match

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd lots of debugging to storage file probing code
Daniel P. Berrange [Thu, 13 Dec 2012 14:23:50 +0000 (14:23 +0000)]
Add lots of debugging to storage file probing code

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoLog warning if storage magic matches, but version does not
Daniel P. Berrange [Thu, 13 Dec 2012 14:22:51 +0000 (14:22 +0000)]
Log warning if storage magic matches, but version does not

To help us detect when new storage file versions come into
existance log a warning if the storage file magic matches,
but the version does not

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoFix memory leak in QEMU QMP capabilities initialization
Daniel P. Berrange [Tue, 4 Dec 2012 13:16:07 +0000 (13:16 +0000)]
Fix memory leak in QEMU QMP capabilities initialization

The qemuCapsInitQMP method never frees the QEMU 'package'
version string.

12 years agoChange virCgroupGetAppRoot stub on non-Linux to avoid unused param warning
Daniel P. Berrange [Thu, 13 Dec 2012 13:10:19 +0000 (13:10 +0000)]
Change virCgroupGetAppRoot stub on non-Linux to avoid unused param warning

Fully stub out the virCgroupGetAppRoot method as done with other
methods in the file, rather than just the body. This lets us
annotate the unused parameter to avoid a warning

12 years agonetwork: match xml warning message
Eric Blake [Wed, 12 Dec 2012 22:03:40 +0000 (15:03 -0700)]
network: match xml warning message

I noticed that /var/lib/libvirt/dnsmasq/*.conf used the wrong word;
it was intended to match the wording in src/util/xml.c.

* src/network/bridge_driver.c (networkDnsmasqConfContents): Fix typo.
* tests/networkxml2confdata/*.conf: Update accordingly.

12 years agoQemu FreeBSD: fix compilation
Roman Bogorodskiy [Wed, 12 Dec 2012 07:44:21 +0000 (11:44 +0400)]
Qemu FreeBSD: fix compilation

* Autotools changes:
  - Don't assume Qemu is Linux-only
  - Check Linux headers only on Linux
  - Disable firewalld on FreeBSD
* Initctl:
  Initctl seem to present only on Linux, so stub it on other platforms
* Raw I/O: Linux-only as well
* Headers cleanup

12 years agoDrop mntent.h include.
Roman Bogorodskiy [Wed, 12 Dec 2012 07:44:20 +0000 (11:44 +0400)]
Drop mntent.h include.

It's no longer used and also causes build fail on FreeBSD.

12 years agoFix make check with different object directory
Viktor Mihajlovski [Wed, 12 Dec 2012 16:15:25 +0000 (16:15 +0000)]
Fix make check with different object directory

make check fails in check-symsorting if configure is not run in
the source directory. Prefixing symfile names with $(srcdir)
fixes this.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agoqemu: Improve error reporting from qemuDomainManagedSaveRemove
Peter Krempa [Tue, 11 Dec 2012 18:34:16 +0000 (19:34 +0100)]
qemu: Improve error reporting from qemuDomainManagedSaveRemove

Report an error if unlink of the managedsave file fails.

12 years agoqemu: Small code cleanups in the managedsave functions
Peter Krempa [Tue, 11 Dec 2012 18:30:12 +0000 (19:30 +0100)]
qemu: Small code cleanups in the managedsave functions

Save a few lines moving assignments into conditions and fix braces
position.

12 years agoqemu: Refactor managed save functions to use domain lookup helpers
Peter Krempa [Tue, 11 Dec 2012 18:28:17 +0000 (19:28 +0100)]
qemu: Refactor managed save functions to use domain lookup helpers

12 years agoqemu: Add a new domain lookup helper and improve the docs
Peter Krempa [Tue, 11 Dec 2012 18:20:53 +0000 (19:20 +0100)]
qemu: Add a new domain lookup helper and improve the docs

This patch adds a new domain lookup helper qemuDomObjFromDomainDriver
that lookups the domain and leaves the driver locked. The driver is
returned as the second argument of that function. If the lookup fails
the driver is unlocked to help avoid cleanup codepaths.

This patch also improves docs for the helpers.

12 years agoutil: Fix warning message in previous patch
Peter Krempa [Wed, 12 Dec 2012 13:19:03 +0000 (14:19 +0100)]
util: Fix warning message in previous patch

I didn't notice the extra "does" in the previous patch. Remove it.

12 years agoutil: rework error reporting in virGet(User|Group)IDByName
Peter Krempa [Tue, 11 Dec 2012 20:26:52 +0000 (21:26 +0100)]
util: rework error reporting in virGet(User|Group)IDByName

This patch gets rid of the undeterministic error reporting code done on
return values of get(pw|gr)nam_r. With this patch, if the group record
is not returned by the corresponding function this error is not
considered fatal even if errno != 0. The error is logged in such case.

12 years agoRefactor virDomainHostdevFind method
Daniel P. Berrange [Tue, 27 Nov 2012 13:50:13 +0000 (13:50 +0000)]
Refactor virDomainHostdevFind method

Move the code for matching hostdev instances out of virDomainHostdevFind
and into virDomainHostdevMatch method, which in turn calls out to other
helper methods depending on the type of hostdev.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoSlightly refactor hostdev parsing / formating
Daniel P. Berrange [Fri, 23 Nov 2012 12:04:12 +0000 (12:04 +0000)]
Slightly refactor hostdev parsing / formating

Rename virDomainHostdevPartsParse to virDomainHostdevDefParseSubsys
to reflect the fact that it only deals with hostdevs uing the
traditional mode=subsystem, and not mode=capabilities

Rename virDomainHostSourceFormat to virDomainHostdevDefFormatSubsys
for the same reason.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoRemove bogus const return values in storage file APIs
Daniel P. Berrange [Tue, 11 Dec 2012 16:39:00 +0000 (16:39 +0000)]
Remove bogus const return values in storage file APIs

virStorageFileGetLVMKey and virStorageFileGetSCSIKey
both return heap allocated strings, so the return value
should not be marked const.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoAdd missing export of virStorageFileGetLVMKey & virStorageFileGetSCSIKey
Daniel P. Berrange [Tue, 11 Dec 2012 19:12:13 +0000 (19:12 +0000)]
Add missing export of virStorageFileGetLVMKey & virStorageFileGetSCSIKey

12 years agoFix sorting of libvirt_private.syms and add syntax check rule
Daniel P. Berrange [Tue, 11 Dec 2012 22:21:17 +0000 (22:21 +0000)]
Fix sorting of libvirt_private.syms and add syntax check rule

Add check-symsorting.pl to perform case-insensitive alphabetical
sorting of groups of symbols. Fix all violations it reports

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agouml: Report error if inotify fails on driver startup
Cole Robinson [Sun, 9 Dec 2012 01:40:43 +0000 (20:40 -0500)]
uml: Report error if inotify fails on driver startup

12 years agotools: Only install guests init script if --with-init=script=redhat
Cole Robinson [Sun, 21 Oct 2012 02:29:51 +0000 (22:29 -0400)]
tools: Only install guests init script if --with-init=script=redhat

Most of this deals with moving the libvirt-guests.sh script which
does all the work to /usr/libexec, so it can be shared by both
systemd and traditional init. Previously systemd depended on
the script being in /etc/init.d

Required to fix https://bugzilla.redhat.com/show_bug.cgi?id=789747

12 years agoadd vnc unix sockets to apparmor policy
Serge Hallyn [Tue, 11 Dec 2012 20:20:30 +0000 (20:20 +0000)]
add vnc unix sockets to apparmor policy

When using vnc gaphics over a unix socket, virt-aa-helper needs to provide
access for the qemu domain to access the sockfile.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
12 years agoadd security hook for permitting hugetlbfs access
Serge Hallyn [Tue, 11 Dec 2012 20:20:29 +0000 (20:20 +0000)]
add security hook for permitting hugetlbfs access

When a qemu domain is backed by huge pages, apparmor needs to grant the domain
rw access to files under the hugetlbfs mount point.  Add a hook, called in
qemu_process.c, which ends up adding the read-write access through
virt-aa-helper.  Qemu will be creating a randomly named file under the
mountpoint and unlinking it as soon as it has mmap()d it, therefore we
cannot predict the full pathname, but for the same reason it is generally
safe to provide access to $path/**.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
12 years agomaint: mention when HACKING is rebuilt during make
Eric Blake [Thu, 6 Dec 2012 23:33:07 +0000 (16:33 -0700)]
maint: mention when HACKING is rebuilt during make

I noticed that on Fedora 18, xlstproc decides to regenerate
HACKING with additional whitespace.  I haven't figured out why
that is happening (although fixing it would probably be a task
for xlstproc), but in the process of investigating, I noticed
that 'make HACKING' was completely silent, for no good reason.

* Makefile.am (gen-ChangeLog, gen-AUTHORS, NEWS)
($(top_srcdir)/HACKING): Mention which files we are generating.

12 years agodocs: Document offline migration
Jiri Denemark [Tue, 11 Dec 2012 14:30:07 +0000 (15:30 +0100)]
docs: Document offline migration

12 years agoqemu: reuse qemuMigrationIsAllowed when doing save and managedsave
Peter Krempa [Fri, 7 Dec 2012 11:12:56 +0000 (12:12 +0100)]
qemu: reuse qemuMigrationIsAllowed when doing save and managedsave

Save and managedsave both use migration to file. This patch reuses
qemuMigrationIsAllowed to check if the migration could happen before
trying.

12 years agoqemu: snapshot: Report better error message if migration isn't allowed
Peter Krempa [Fri, 7 Dec 2012 11:06:30 +0000 (12:06 +0100)]
qemu: snapshot: Report better error message if migration isn't allowed

Qemu doesn't support migration on guests with host devices. This patch
adds a check to ensure migration is safe before actually doing so.

12 years agoqemu: Make qemuMigrationIsAllowed more reusable
Peter Krempa [Fri, 7 Dec 2012 10:59:24 +0000 (11:59 +0100)]
qemu: Make qemuMigrationIsAllowed more reusable

This patch exports qemuMigrationIsAllowed and adds a new parameter to it
to denote if it's a remote migration or a local migration. Local
migrations are used in snapshots and saving of the machine state and
have fewer restrictions. This patch also adjusts callers of the function
and tweaks some error messages to be more universal.

12 years agoqemu: assume seccomp sandbox is supported since qemu 1.2
Ján Tomko [Mon, 10 Dec 2012 15:28:55 +0000 (16:28 +0100)]
qemu: assume seccomp sandbox is supported since qemu 1.2

Currently there is no way to detect it via QMP and requesting "-sandbox
off" works correctly even if it was compiled out, so this will work
unless someone both requests the sandbox in qemu.conf and builds QEMU
without the support for it.

12 years agodomain: Keep assigned class_id in domstatus XML
Michal Privoznik [Tue, 4 Dec 2012 15:38:02 +0000 (16:38 +0100)]
domain: Keep assigned class_id in domstatus XML

Interfaces keeps a class_id, which is an ID from which bridge
part of QoS settings is derived. We need to store class_id
in domain status file, so we can later pass it to
virNetDevBandwidthUnplug.

12 years agonetwork: Create real network status files
Michal Privoznik [Sun, 18 Nov 2012 15:59:21 +0000 (16:59 +0100)]
network: Create real network status files

Currently, we are only keeping a inactive XML configuration
in status dir. This is no longer enough as we need to keep
this class_id attribute so we don't overwrite old entries
when the daemon restarts. However, since there has already
been release which has just <network/> as root element,
and we want to keep things compatible, detect that loaded
status file is older one, and don't scream about it.

12 years agobandwidth: Create network bandwidth (un)plug functions
Michal Privoznik [Fri, 16 Nov 2012 13:29:01 +0000 (14:29 +0100)]
bandwidth: Create network bandwidth (un)plug functions

Network should be notified if we plug in or unplug an
interface, so it can perform some action, e.g. set/unset
network part of QoS. However, we are doing this in very
early stage, so iface->ifname isn't filled in yet. So
whenever we want to report an error, we must use a different
identifier, e.g. the MAC address.

12 years agobandwidth: Create rate update function
Michal Privoznik [Fri, 16 Nov 2012 11:52:44 +0000 (12:52 +0100)]
bandwidth: Create rate update function

This will be used whenever a NIC with guaranteed throughput is to
be plugged into a bridge. It will adjust the average throughput of
non guaranteed NICs (classid 1:2) to meet new requirements.

12 years agobandwidth: Create (un)plug functions
Michal Privoznik [Fri, 16 Nov 2012 11:37:51 +0000 (12:37 +0100)]
bandwidth: Create (un)plug functions

These set bridge part of QoS when bringing domain's interface up.
Long story short, if there's a 'floor' set, a new QoS class is created.
ClassID MUST be unique within the bridge and should be kept for
unplug phase.

12 years agobandwidth: Create hierarchical shaping classes
Michal Privoznik [Fri, 16 Nov 2012 10:36:02 +0000 (11:36 +0100)]
bandwidth: Create hierarchical shaping classes

These classes can borrow unused bandwidth. Basically,
only egress qdsics can have classes, therefore we can
do this kind of traffic shaping only on host's outgoing,
that is domain's incoming traffic.

12 years agobandwidth: add new 'floor' attribute
Michal Privoznik [Fri, 16 Nov 2012 09:37:15 +0000 (10:37 +0100)]
bandwidth: add new 'floor' attribute

This is however supported only on domain interfaces with
type='network'. Moreover, target network needs to have at least
inbound QoS set. This is required by hierarchical traffic shaping.

From now on, the required attribute for <inbound/> is either 'average'
(old) or 'floor' (new). This new attribute can be used just for
interfaces type of network (<interface type='network'/>) currently.

12 years agobandwidth: Attach sfq to leaf node
Michal Privoznik [Mon, 19 Nov 2012 11:16:07 +0000 (12:16 +0100)]
bandwidth: Attach sfq to leaf node

Stochastic Fairness Queuing (SFQ) is queuing discipline
(qdisc) which doesn't really shape any traffic but 'just'
re-arrange packets in sending buffer so no stream starve.
The goal is to ensure fairness. There is basically only one
configuration parameter (perturb) which is set to advised
value of 10.

12 years agoparallels: handle network adapters of type 'routed'
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:49 +0000 (14:59 +0400)]
parallels: handle network adapters of type 'routed'

Network adapters of type 'routed' is a special case. Other adapters
have 'network' parameter in prlctl's output instead.

Routed network adapters should be connected to 'routed' network
from libvirt's view.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add routed pseudo network
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:48 +0000 (14:59 +0400)]
parallels: add routed pseudo network

Historically if traffic from the adapter is routed to LAN without
NAT, it isn't connected to any virtual networks, but has a 'type'
instead. Sinse libvirt has special virtual network type for such case,
let's add pseudo network 'routed' to fit libvirt's API well.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: parse virtual network properties
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:47 +0000 (14:59 +0400)]
parallels: parse virtual network properties

Fill bridge name and mac for bridged network and
DHCP server parameter for host-only network.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add network driver
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:45 +0000 (14:59 +0400)]
parallels: add network driver

Parallels Cloud Server uses virtual networks model for network
configuration. It uses own tools for virtual network management.
So add network driver, which will be responsible for listing
virtual networks and performing different operations on them
(in consequent patched).

This patch only allows listing virtual network names, without
any parameters like DHCP server settings.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: move parallelsParseError to parallels_utils.h
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:44 +0000 (14:59 +0400)]
parallels: move parallelsParseError to parallels_utils.h

This macro will be used in another file in the next
patch, so move it to common header file.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: add support of network interfaces to parallelsDomainDefineXML
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:43 +0000 (14:59 +0400)]
parallels: add support of network interfaces to parallelsDomainDefineXML

Allow changing network interfaces in domain configuration.

ifname is used as iterface identifier: if there is interface
with some ifname in old config and there are no interfaces with
such name in the new config - issue prlctl command to delete
the network interface. And vice versa - if interface with
some ifname exists only in new config - issue prlctl command
to create it.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoparallels: parse information about network interfaces
Dmitry Guryanov [Tue, 11 Dec 2012 10:59:42 +0000 (14:59 +0400)]
parallels: parse information about network interfaces

Parse network interfaces info from prlctl output.

Parallels Cloud Server uses virtual networks model for
network configuration: You can add network adapter to
VM and connect it to some predefined virtual network.

Fill type, mac, network name and linkstate fields of
virDomainNetDef structure.

Signed-off-by: Dmitry Guryanov <dguryanov@parallels.com>
12 years agoqemu: snapshot: Remove memory image if external checkpoint fails
Peter Krempa [Tue, 11 Dec 2012 11:02:16 +0000 (12:02 +0100)]
qemu: snapshot: Remove memory image if external checkpoint fails

When the disk snapshot part of an external system checkpoint fails the
memory image is retained. This patch adds code to remove the image in
such case.

12 years agoqemu: snapshot: Don't leak XML definition if restarting of CPUs fails
Peter Krempa [Tue, 11 Dec 2012 10:59:58 +0000 (11:59 +0100)]
qemu: snapshot: Don't leak XML definition if restarting of CPUs fails

In case the snapshot code isn't able to restart CPUs after an external
checkpoint we would leak a copy of the domains XML definition. This
patch fixes the cleanup path.

12 years agoqemu: fix uninitialized variable warning in doPeer2PeerMigrate
Ján Tomko [Tue, 11 Dec 2012 11:50:53 +0000 (12:50 +0100)]
qemu: fix uninitialized variable warning in doPeer2PeerMigrate

False positive, but it breaks the build with gcc-4.6.3.

qemu/qemu_migration.c:2931:37: error: 'offline' may be used
uninitialized in this function [-Werror=uninitialized]
qemu/qemu_migration.c:2887:10: note: 'offline' was declared here

12 years agoconf: Remove duplicate declaration of virNetworkDNSDefPtr
Jiri Denemark [Tue, 11 Dec 2012 12:27:53 +0000 (13:27 +0100)]
conf: Remove duplicate declaration of virNetworkDNSDefPtr

12 years agoexamples: Fix balloon event callback
Jiri Denemark [Tue, 11 Dec 2012 11:07:34 +0000 (12:07 +0100)]
examples: Fix balloon event callback

12 years agonetwork: put dnsmasq parameters in conf-file instead of command line
Gene Czarcinski [Thu, 6 Dec 2012 17:20:39 +0000 (12:20 -0500)]
network: put dnsmasq parameters in conf-file instead of command line

This patch changes how parameters are passed to dnsmasq.  Instead of
being on the command line, the parameters are put into a file (one
parameter per line) and a commandline --conf-file= specifies the
location of the file.  The file is located in the same directory as
the leases file.

Putting the dnsmasq parameters into a configuration file
allows them to be examined and more easily understood than
examining the command lines displayed by "ps ax".  This is
especially true when a number of networks have been started.

When the use of dnsmasq was originally done, the required command line
was simple, but it has gotten more complicated over time and will
likely become even more complicated in the future.

Note: The test conf files have all been renamed .conf instead of
.argv, and tests/networkxml2xmlargvdata was moved to
tests/networkxml2xmlconfdata.

12 years agonetwork: add support for DHCPv6
Gene Czarcinski [Thu, 6 Dec 2012 17:20:38 +0000 (12:20 -0500)]
network: add support for DHCPv6

The DHCPv6 support includes IPV6 dhcp-range and dhcp-host for one
IPv6 subnetwork on one interface.  This support will only work
if dnsmasq version >= 2.64; otherwise an error occurs if
dhcp-range or dhcp-host is specified for an IPv6 address.

Essentially, this change provides the same DHCP support for IPv6
that has been available for IPv4.

With dnsmasq >= 2.64, support for the RA service is also now provided
by dnsmasq (radvd is no longer used/started). (Although at least one
version of dnsmasq prior to 2.64 "supported" IPv6 Router
Advertisement, there were bugs (fixed in 2.64) that rendered it
unusable.)

Documentation and the network schema has been updated
to reflect the new support.

12 years agoconf: split <forward> parser/clear into separate functions
Laine Stump [Sun, 11 Nov 2012 22:57:16 +0000 (17:57 -0500)]
conf: split <forward> parser/clear into separate functions

virNetworkDefUpdateForward requires separate functions to parse and
clear a virNetworkForwardDef by itself, but they were previously just
inlined in the virNetworkDef parse and free functions. This patch
makes them into separate functions.

12 years agoconf: put data for network <forward> element into its own struct
Laine Stump [Thu, 8 Nov 2012 02:16:17 +0000 (21:16 -0500)]
conf: put data for network <forward> element into its own struct

The attributes of a <network> element's <forward> element were
previously stored directly in the virNetworkDef object, but
virNetworkUpdateForward() needs to operate on a <forward> in
isolation, so this patchs pulls out all those attributes into a
separate virNetworkForwardDef struct (and shortens their names
appropriately). This new object is contained in the virNetworkDef, not
pointed to by it, so there is no extra memory management.

This patch makes no functional changes, it only changes, e.g.,
"nForwardIfs" to "forward.nifs".

12 years agoconf: make virNetworkIpDefClear consistent with other functions
Laine Stump [Sun, 11 Nov 2012 15:27:55 +0000 (10:27 -0500)]
conf: make virNetworkIpDefClear consistent with other functions

The other clear functions in network_conf.c that clear out arrays of
sub-objects do so by using the n[itemname]s value as a counter going
down to 0. Make this one consistent. There's no functional value, just
makes the style more consistent with the rest of the file.

12 years agoconf: rename some labels and functions in network_conf
Laine Stump [Sun, 11 Nov 2012 23:55:12 +0000 (18:55 -0500)]
conf: rename some labels and functions in network_conf

This makes some function names and arg lists for consistent with other
parse functions in network_conf.c. While modifying
virNetworkIPParseXML(), also change its "error" label to "cleanup",
since the code at that label is executed on success as well as
failure.

12 years agonetwork: backend functions for updating network dns host/srv/txt
Laine Stump [Mon, 12 Nov 2012 21:18:02 +0000 (16:18 -0500)]
network: backend functions for updating network dns host/srv/txt

These three functions are very similar - none allow a MODIFY
operation; you can only add or delete.

The biggest difference between them (other than the data itself) is in
the criteria for determining a match, and whether or not multiple
matches are possible:

1) for HOST records, it's considered a match if the IP address or any
of the hostnames of an existing record matches.

2) for SRV records, it's a match if all of
domain+service+protocol+target *which have been specified* are
matched.

3) for TXT records, there is only a single field to match - name
(value can be the same for multiple records, and isn't considered a
search term), so by definition there can be no ambiguous matches.

In all three cases, if any matches are found, ADD will fail; if
multiple matches are found, it means the search term was ambiguous,
and a DELETE will fail.

The upper level code in bridge_driver.c is already implemented for
these functions - appropriate conf files will be re-written, and
dnsmasq will be SIGHUPed or restarted as appropriate.

12 years agoconf: clear and parse functions for dns host/srv/txt records
Laine Stump [Mon, 12 Nov 2012 00:00:22 +0000 (19:00 -0500)]
conf: clear and parse functions for dns host/srv/txt records

Since there is only a single virNetworkDNSDef for any virNetworkDef,
and it's trivial to determine whether or not it contains any real
data, it's much simpler (and fits more uniformly with the parse
function calling sequence of the parsers for many other objects that
are subordinates of virNetworkDef) if virNetworkDef *contains* an
virNetworkDNSDef rather than pointing to one.

Since it is now just a part of another object rather than its own
object, it no longer makes sense to have a *Free() function, so that
is changed to a *Clear() function.

More importantly though, ParseXML and Clear functions are needed for
the individual items contained in a virNetworkDNSDef (srv, txt, and
host records), but none of them have a *Clear(), and only two of the
three had *ParseXML() functions (both of which used a non-uniform
arglist). Those problems are cleared up by this patch - it splits the
higher-level Clear function into separate functions for each of the
three, creates a parse for txt records, and cleans up the srv and host
parsers, so we now have all the utility functions necessary to
implement virNetworkDefUpdateDNS(Host|Srv|Txt).

12 years agoconf: rename network dns host/srv/txt arrays
Laine Stump [Sun, 11 Nov 2012 23:59:28 +0000 (18:59 -0500)]
conf: rename network dns host/srv/txt arrays

This shortens the name of the structs for srv and txt, and their
instances in virNetworkDNSDef, to be more compact and uniform with the
naming of the dns host array. It also changes the type of ntxts, etc
from unsigned int to size_t, so that they can be used directly as args
to VIR_*_ELEMENT.

12 years agoconf: use VIR_(INSERT|DELETE)_ELEMENT in virNetworkUpdate backend
Laine Stump [Mon, 8 Oct 2012 17:42:21 +0000 (13:42 -0400)]
conf: use VIR_(INSERT|DELETE)_ELEMENT in virNetworkUpdate backend

The already-written backend functions for virNetworkUpdate that add
and delete items into lists within the a network were already debugged
to work properly, but future such functions will use
VIR_(INSERT|DELETE)_ELEMENT instead, so these are changed for
uniformity.

12 years agoutil: add VIR_(APPEND|INSERT|DELETE)_ELEMENT
Laine Stump [Mon, 8 Oct 2012 17:33:35 +0000 (13:33 -0400)]
util: add VIR_(APPEND|INSERT|DELETE)_ELEMENT

I noticed when writing the backend functions for virNetworkUpdate that
I was repeating the same sequence of memmove, VIR_REALLOC, nXXX-- (and
messed up the args to memmove at least once), and had seen the same
sequence in a lot of other places, so I decided to write a few
utility functions/macros - see the .h file for full documentation.

The intent is to reduce the number of lines of code, but more
importantly to eliminate the need to check the element size and
element count arithmetic every time we need to do this (I *always*
make at least one mistake.)

VIR_INSERT_ELEMENT: insert one element at an arbitrary index within an
  array of objects. The size of each object is determined
  automatically by the macro using sizeof(*array). The new element's
  contents are copied into the inserted space, then the original copy
  of contents are 0'ed out (if everything else was
  successful). Compile-time assignment and size compatibility between
  the array and the new element is guaranteed (see explanation below
  [*])

VIR_INSERT_ELEMENT_COPY: identical to VIR_INSERT_ELEMENT, except that
  the original contents of newelem are not cleared to 0 (i.e. a copy
  is made).

VIR_APPEND_ELEMENT: This is just a special case of VIR_INSERT_ELEMENT
  that "inserts" one past the current last element.

VIR_APPEND_ELEMENT_COPY: identical to VIR_APPEND_ELEMENT, except that
  the original contents of newelem are not cleared to 0 (i.e. a copy
  is made).

VIR_DELETE_ELEMENT: delete one element at an arbitrary index within an
  array of objects. It's assumed that the element being deleted is
  already saved elsewhere (or cleared, if that's what is appropriate).

All five of these macros have an _INPLACE variant, which skips the
memory re-allocation of the array, assuming that the caller has
already done it (when inserting) or will do it later (when deleting).

Note that VIR_DELETE_ELEMENT* can return a failure, but only if an
invalid index is given (index + amount to delete is > current array
size), so in most cases you can safely ignore the return (that's why
the helper function virDeleteElementsN isn't declared with
ATTRIBUTE_RETURN_CHECK). A warning is logged if this ever happens,
since it is surely a coding error.

[*] One initial problem with the INSERT and APPEND macros was that,
due to both the array pointer and newelem pointer being cast to void*
when passing to virInsertElementsN(), any chance of type-checking was
lost. If we were going to move in newelem with a memmove anyway, we
would be no worse off for this. However, most current open-coded
insert/append operations use direct struct assignment to move the new
element into place (or just populate the new element directly) - thus
use of the new macros would open a possibility for new usage errors
that didn't exist before (e.g. accidentally sending &newelemptr rather
than newelemptr - I actually did this quite a lot in my test
conversions of existing code).

But thanks to Eric Blake's clever thinking, I was able to modify the
INSERT and APPEND macros so that they *do* check for both assignment
and size compatibility of *ptr (an element in the array) and newelem
(the element being copied into the new position of the array). This is
done via clever use of the C89-guaranteed fact that the sizeof()
operator must have *no* side effects (so an assignment inside sizeof()
is checked for validity, but not actually evaluated), and the fact
that virInsertElementsN has a "# of new elements" argument that we
want to always be 1.

12 years agoqemu: Restart CPUs with valid async job type when doing external snapshots
Peter Krempa [Fri, 7 Dec 2012 10:50:52 +0000 (11:50 +0100)]
qemu: Restart CPUs with valid async job type when doing external snapshots

When restarting CPUs after an external snapshot, the restarting function
was called without the appropriate async job type. This caused that a
new sync job wasn't created and allowed races in the monitor.