]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
12 years agorun: license as LGPL
Eric Blake [Sat, 23 Feb 2013 00:10:48 +0000 (17:10 -0700)]
run: license as LGPL

It makes no sense to prohibit reuse of the wrapper in other LGPL
projects, since most of libvirt is designed to be LGPL.  Of
course, when using the wrapper to wrap a GPL program, the combined
result is still effectively GPL, but that shouldn't force us to
license the wrapper as GPL in isolation.

* run.in: Relicense to LGPLv2+.

12 years agoqemu_migration: Cancel running jobs on failed migration
Michal Privoznik [Wed, 30 Jan 2013 16:53:37 +0000 (17:53 +0100)]
qemu_migration: Cancel running jobs on failed migration

If a migration fails, we need to stop all block jobs running so
qemu doesn't try to send data to destination over and over again.

12 years agoqemu_migration: Stop NBD server at Finish phase
Michal Privoznik [Tue, 27 Nov 2012 15:34:24 +0000 (16:34 +0100)]
qemu_migration: Stop NBD server at Finish phase

At the end of migration, it is important to stop NBD
server and thus release all allocated resources.

12 years agoqemu_migration: Introduce qemuMigrationDriveMirror
Michal Privoznik [Fri, 23 Nov 2012 14:42:51 +0000 (15:42 +0100)]
qemu_migration: Introduce qemuMigrationDriveMirror

This function does the source part of NBD magic. It
invokes drive-mirror on each non shared and RW disk with
a source and wait till the mirroring process completes.
When it does we can proceed with migration.

Currently, an active waiting is done: every 500ms libvirt
asks qemu if block-job is finished or not.  However, once
the job finishes, qemu doesn't report its progress so we
can only assume if the job finished successfully or not.
The better solution would be to listen to the event which
is sent as soon as the job finishes. The event does
contain the result of job.

12 years agoqemu_migration: Introduce qemuMigrationStartNBDServer()
Michal Privoznik [Thu, 31 Jan 2013 13:48:06 +0000 (14:48 +0100)]
qemu_migration: Introduce qemuMigrationStartNBDServer()

We need to start NBD server and feed it with all non-<shared/>,
RW and source-full disks. Moreover, with new virPortAllocator we
must ensure the borrowed port for NBD server will be returned if
either migration completes or qemu process is torn down.

12 years agoqemu: Introduce nbd-server-stop command
Michal Privoznik [Thu, 31 Jan 2013 13:47:49 +0000 (14:47 +0100)]
qemu: Introduce nbd-server-stop command

This will be used after all migration work is done
to stop NBD server running on destination.  It
doesn't take any arguments, just issues a command.

12 years agoqemu: Introduce nbd-server-add command
Michal Privoznik [Thu, 22 Nov 2012 15:17:13 +0000 (16:17 +0100)]
qemu: Introduce nbd-server-add command

This will be used with new migration scheme.
This patch creates basically just monitor stub
functions. Wiring them into something useful
is done in later patches.

12 years agoqemu: Introduce nbd-server-start command
Michal Privoznik [Thu, 22 Nov 2012 15:08:52 +0000 (16:08 +0100)]
qemu: Introduce nbd-server-start command

This will be used with new migration scheme.
This patch creates basically just monitor stub
functions. Wiring them into something useful
is done in later patches.

12 years agoIntroduce NBD migration cookie
Michal Privoznik [Tue, 29 Jan 2013 12:38:50 +0000 (13:38 +0100)]
Introduce NBD migration cookie

This migration cookie is meant for two purposes. The first is to be sent
in begin phase from source to destination to let it know we support new
implementation of VIR_MIGRATE_NON_SHARED_{DISK,INC} so destination can
start NBD server. Then, the second purpose is, destination can let us
know, on which port the NBD server is running.

12 years agoqemu: Introduce NBD_SERVER capability
Michal Privoznik [Wed, 21 Nov 2012 13:28:44 +0000 (14:28 +0100)]
qemu: Introduce NBD_SERVER capability

This just keeps track whether qemu knows nbd-server-* commands
so we can use it during migration or not.

12 years agoAdd support for <option> tag in network config
Pieter Hollants [Thu, 21 Feb 2013 22:40:17 +0000 (23:40 +0100)]
Add support for <option> tag in network config

This patch adds support for a new <option>-Tag in the <dhcp> block of
network configs, based on a subset of the fifth proposal by Laine
Stump in the mailing list discussion at
https://www.redhat.com/archives/libvir-list/2012-November/msg01054.html.
Any such defined option will result in a dhcp-option=<number>,"<value>"
statement in the generated dnsmasq configuration file.

Currently, DHCP options can be specified by number only and there is
no whitelisting or blacklisting of option numbers, which should
probably be added.

Signed-off-by: Pieter Hollants <pieter@hollants.com>
Signed-off-by: Laine Stump <laine@laine.org>
12 years agorun: use portable shell
Eric Blake [Sat, 23 Feb 2013 00:10:48 +0000 (17:10 -0700)]
run: use portable shell

Nothing in run required bash, except for the shebang.  On systems
where /bin/bash doesn't exist (I hit it on FreeBSD), using /bin/sh
instead fixes a 'make check' failure:
gmake[3]: Entering directory `/usr/home/dummy/libvirt/python'
  GEN    check-local
/usr/local/bin/bash: ../run: /bin/bash: bad interpreter: No such file or directory

* run.in: Use /bin/sh, not bash.

12 years agostorage: use f_frsize, not f_bsize, for calculating available space
Sage Weil [Fri, 22 Feb 2013 23:43:00 +0000 (15:43 -0800)]
storage: use f_frsize, not f_bsize, for calculating available space

The bfree and blocks fields are supposed to be in units of frsize.  We were
calculating capacity correctly using those units, but the available
calculation was using bsize instead.  Most file systems report these as the
same value specifically because many programs are buggy, but that is no
reason to rely on that behavior, or to behave inconsistently.

This bug has been present since e266ded (2008) and aa296e6c, when the code
was originally introduced (the latter via cut and paste).

Signed-off-by: Sage Weil <sage@newdream.net>
12 years agomaint: check all symfiles for sorting
Eric Blake [Fri, 22 Feb 2013 23:46:25 +0000 (16:46 -0700)]
maint: check all symfiles for sorting

On FreeBSD, I got a 'make check' failure:
  GEN    check-symsorting
Symbol block at ./libvirt_atomic.syms:4: viratomic.h not found

* src/Makefile.am (SYM_FILES): New define.
(check-symsorting): Check on all symfiles, even when not used.
* src/libvirt_atomic.syms: Fix offender.

12 years agoqemu: Implement virDomainMigrate*CompressionCache
Jiri Denemark [Mon, 18 Feb 2013 20:54:58 +0000 (21:54 +0100)]
qemu: Implement virDomainMigrate*CompressionCache

12 years agovirsh: Add migrate-compcache command
Jiri Denemark [Mon, 18 Feb 2013 20:14:49 +0000 (21:14 +0100)]
virsh: Add migrate-compcache command

This is a command wrapping virDomainMigrateGetCompressionCache and
virDomainMigrateSetCompressionCache.

12 years agoremote: Implement virDomainMigrate*CompressionCache
Jiri Denemark [Mon, 18 Feb 2013 19:20:04 +0000 (20:20 +0100)]
remote: Implement virDomainMigrate*CompressionCache

12 years agopython: Implement virDomainMigrateGetCompressionCache wrapper
Jiri Denemark [Mon, 18 Feb 2013 22:20:48 +0000 (23:20 +0100)]
python: Implement virDomainMigrateGetCompressionCache wrapper

12 years agoIntroduce virDomainMigrate*CompressionCache APIs
Jiri Denemark [Mon, 18 Feb 2013 16:31:08 +0000 (17:31 +0100)]
Introduce virDomainMigrate*CompressionCache APIs

Introduce virDomainMigrateGetCompressionCache and
virDomainMigrateSetCompressionCache APIs.

12 years agoqemu: Implement virDomainGetJobStats
Jiri Denemark [Tue, 12 Feb 2013 19:29:17 +0000 (20:29 +0100)]
qemu: Implement virDomainGetJobStats

12 years agoqemu: Parse more fields from query-migrate QMP command
Jiri Denemark [Fri, 8 Feb 2013 08:58:03 +0000 (09:58 +0100)]
qemu: Parse more fields from query-migrate QMP command

As a side effect, this also fixes reporting disk migration process.
It was added to memory migration progress, which was wrong. Disk
progress has dedicated fields in virDomainJobInfo structure.

12 years agovirsh: Use virDomainGetJobStats in domjobinfo if available
Jiri Denemark [Fri, 8 Feb 2013 08:55:17 +0000 (09:55 +0100)]
virsh: Use virDomainGetJobStats in domjobinfo if available

12 years agoremote: Implement virDomainGetJobStats
Jiri Denemark [Wed, 30 Jan 2013 09:49:28 +0000 (10:49 +0100)]
remote: Implement virDomainGetJobStats

12 years agoremote: Auto-allocate params in remoteDeserializeTypedParameters
Jiri Denemark [Wed, 30 Jan 2013 09:28:54 +0000 (10:28 +0100)]
remote: Auto-allocate params in remoteDeserializeTypedParameters

remoteDeserializeTypedParameters can now be called with either
preallocated params array (size of which is announced by nparams) or it
can allocate params array according to the number of parameters received
from the server.

12 years agopython: Implement virDomainGetJobStats wrapper
Jiri Denemark [Mon, 18 Feb 2013 22:20:08 +0000 (23:20 +0100)]
python: Implement virDomainGetJobStats wrapper

12 years agoIntroduce virDomainGetJobStats API
Jiri Denemark [Fri, 25 Jan 2013 23:30:49 +0000 (00:30 +0100)]
Introduce virDomainGetJobStats API

This is an extensible version of virDomainGetJobInfo.

12 years agoqemu: Add support for compressed migration
Jiri Denemark [Mon, 14 Jan 2013 11:45:20 +0000 (12:45 +0100)]
qemu: Add support for compressed migration

12 years agoIntroduce VIR_MIGRATE_COMPRESSED flag
Jiri Denemark [Thu, 10 Jan 2013 12:39:34 +0000 (13:39 +0100)]
Introduce VIR_MIGRATE_COMPRESSED flag

This flag may be used with migration APIs to request compression of
migration data.

12 years agos/arm/armv7l/ in caps-qemu-kvm.xml
Daniel P. Berrange [Fri, 22 Feb 2013 15:49:51 +0000 (15:49 +0000)]
s/arm/armv7l/ in caps-qemu-kvm.xml

Fix the caps-qemu-kvm.xml test data file to refer to correct
arm arch name.

12 years agoUpdate arch names in RNG schema to match virarch.c
Daniel P. Berrange [Thu, 21 Feb 2013 11:20:25 +0000 (11:20 +0000)]
Update arch names in RNG schema to match virarch.c

When the virarch.c file was introduced to formalize the arch
list, we forgot to update the RNG schema with the new arches.

12 years agoconf: Don't leak 'ram' video property on error
Christophe Fergeau [Thu, 21 Feb 2013 15:21:31 +0000 (16:21 +0100)]
conf: Don't leak 'ram' video property on error

It's only freed on normal returns from virDomainVideoDefParseXML,
but not when erroring out.

12 years agoconf: Don't leak 'primary' video property on error
Christophe Fergeau [Thu, 21 Feb 2013 15:21:31 +0000 (16:21 +0100)]
conf: Don't leak 'primary' video property on error

It's only freed on normal returns from virDomainVideoDefParseXML,
but not when erroring out.

12 years agointerface: dev type support for bond interfaces
Doug Goldstein [Wed, 20 Feb 2013 06:48:56 +0000 (00:48 -0600)]
interface: dev type support for bond interfaces

Patch has been accepted into net-next's 3.9 queue to correctly expose
bond interfaces with the 'bond' devtype.

12 years agointerface: add bond support to udev backend
Doug Goldstein [Sun, 17 Feb 2013 21:34:17 +0000 (15:34 -0600)]
interface: add bond support to udev backend

The udev backend now supports bond interfaces.

12 years agointerface: Improve udev backend device type id
Doug Goldstein [Fri, 15 Feb 2013 22:48:07 +0000 (16:48 -0600)]
interface: Improve udev backend device type id

Refactored the interface device type identification to make it more
clear about the operations. Add support for udev devtype to detect
VLANs on Linux 3.7 and newer. Move VLAN detection based on device
name to fallback case.

12 years agointerface: Refactor interface vlan to helper func
Doug Goldstein [Fri, 15 Feb 2013 22:32:34 +0000 (16:32 -0600)]
interface: Refactor interface vlan to helper func

Mechanical move to break up udevIfaceGetIfaceDef() into different
helpers for each of the interface types to hopefully make the code
easier to follow. This moves the vlan code to
udevIfaceGetIfaceDefVlan().

12 years agointerface: udev bridge code error handling updates
Doug Goldstein [Wed, 20 Feb 2013 06:39:37 +0000 (00:39 -0600)]
interface: udev bridge code error handling updates

Based on feedback from Laine Stump, improve a number of the error
handling cases to report the issue to the user instead of not generating
data or giving vague errors. Added the bridge device name to every error
message as well to make it clear which bridge failed.

12 years agointerface: Refactor udev bridge to helper func
Doug Goldstein [Fri, 15 Feb 2013 16:49:08 +0000 (10:49 -0600)]
interface: Refactor udev bridge to helper func

Mechanical move to break up udevIfaceGetIfaceDef() into different
helpers for each of the interface types to hopefully make the code
easier to follow. This moves the bridge code to
udevIfaceGetIfaceDefBridge().

12 years agoqemu: check backing chains even when cgroup is omitted
Eric Blake [Wed, 20 Feb 2013 22:34:48 +0000 (15:34 -0700)]
qemu: check backing chains even when cgroup is omitted

https://bugzilla.redhat.com/show_bug.cgi?id=896685 points out
a regression caused by commit 38c4a9c - libvirt only labels
the backing chain if the backing chain cache is populated, but
the code to populate the cache was only conditionally performed
if cgroup labeling was necessary.

* src/qemu/qemu_cgroup.c (qemuSetupCgroup): Hoist cache setup...
* src/qemu/qemu_process.c (qemuProcessStart): ...earlier into
caller, where it is now unconditional.

12 years agodocs: Add missing 'vram' in QXL video device doc
Christophe Fergeau [Thu, 21 Feb 2013 14:59:39 +0000 (15:59 +0100)]
docs: Add missing 'vram' in QXL video device doc

12 years agoconf: Refactor ABI stability checking and break long lines
Peter Krempa [Tue, 19 Feb 2013 13:07:10 +0000 (14:07 +0100)]
conf: Refactor ABI stability checking and break long lines

Get rid of the "identical" variable in the ABI stability checks in favor
of return statements and break or refactor very long lines where
possible.

12 years agoconf: Refactor cpumask handling
Peter Krempa [Tue, 19 Feb 2013 10:51:11 +0000 (11:51 +0100)]
conf: Refactor cpumask handling

Declare local variables at the start of the block and fix trivial
formatting issues.

12 years agoconf: Reformat many function headers in domain_conf.c
Peter Krempa [Tue, 19 Feb 2013 10:50:03 +0000 (11:50 +0100)]
conf: Reformat many function headers in domain_conf.c

Many of the headers were using the old style and even overflowing the 80
column mark.

12 years agoconf: Fix label naming in virDomainDefFormatInternal
Peter Krempa [Tue, 19 Feb 2013 10:46:45 +0000 (11:46 +0100)]
conf: Fix label naming in virDomainDefFormatInternal

The label named "cleanup" was used in error cases only. Change it to
"error".

12 years agoconf: Ensure that new devices are added to conf copy function
Peter Krempa [Tue, 19 Feb 2013 10:08:05 +0000 (11:08 +0100)]
conf: Ensure that new devices are added to conf copy function

Use the correct type and get rid of "default" label in switch to make
the compiler complain if a new device type is added.

12 years agoqemu: Refactor error paths in virQEMUDriverCreateCapabilities
Peter Krempa [Tue, 19 Feb 2013 09:56:06 +0000 (10:56 +0100)]
qemu: Refactor error paths in virQEMUDriverCreateCapabilities

Change the error label to "error" and simplify some error paths.

12 years agoconf: Improve core dump config error message
Peter Krempa [Wed, 20 Feb 2013 15:31:14 +0000 (16:31 +0100)]
conf: Improve core dump config error message

The message didn't seem to be much helpful

12 years agodocs: Fix HTML errors
Jiri Denemark [Thu, 21 Feb 2013 09:32:36 +0000 (10:32 +0100)]
docs: Fix HTML errors

<pre> is forbidden inside <p>

12 years agoqemu: Avoid deadlock in autodestroy
Jiri Denemark [Fri, 15 Feb 2013 14:11:47 +0000 (15:11 +0100)]
qemu: Avoid deadlock in autodestroy

Since closeCallbacks were turned into virObjectLockable, we can no
longer call virQEMUCloseCallbacks APIs from within a registered close
callback.

12 years agoqemu: Turn closeCallbacks into virObjectLockable
Jiri Denemark [Fri, 15 Feb 2013 12:05:12 +0000 (13:05 +0100)]
qemu: Turn closeCallbacks into virObjectLockable

To avoid having to hold the qemu driver lock while iterating through
close callbacks and calling them. This fixes a real deadlock when a
domain which is being migrated from another host gets autodestoyed as a
result of broken connection to the other host.

12 years agoqemu: fix an off-by-one error in qemuDomainGetPercpuStats
Guannan Ren [Wed, 20 Feb 2013 11:28:13 +0000 (19:28 +0800)]
qemu: fix an off-by-one error in qemuDomainGetPercpuStats

The max value of number of cpus to compute(id) should not
be equal or greater than max cpu number.
The bug ocurrs when id value is equal to max cpu number which
leads to the off-by-one error in the following for loop.

 # virsh  cpu-stats guest --start 1
 error: Failed to virDomainGetCPUStats()

 error: internal error cpuacct parse error

12 years agoqemu: Fix the memory leak
Osier Yang [Thu, 21 Feb 2013 02:32:15 +0000 (10:32 +0800)]
qemu: Fix the memory leak

Found by John Ferlan (coverity script)

12 years agokeepalive: Guard against integer overflow
John Ferlan [Tue, 5 Feb 2013 22:58:25 +0000 (17:58 -0500)]
keepalive: Guard against integer overflow

Don't allow interval to be > MAX_INT/1000 in virKeepAliveStart()

Guard against possible overflow in virKeepAliveTimeout() by setting the
timeout to be MAX_INT/1000 since the math following will multiply it by 1000.

12 years agolibxl: Fix setting of disk backend
Jim Fehlig [Wed, 20 Feb 2013 20:02:28 +0000 (13:02 -0700)]
libxl: Fix setting of disk backend

The libxl driver was setting the backend field of libxl_device_disk
structure to LIBXL_DISK_BACKEND_TAP when the driver element of disk
configuration was not specified.  This needlessly forces the use of
blktap driver, which may not be loaded in dom0

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

Ian Campbell suggested that LIBXL_DISK_BACKEND_UNKNOWN is a better
default in this case

https://www.redhat.com/archives/libvir-list/2013-February/msg01126.html

12 years agoRemove a couple of misplaced VIR_FREE
John Ferlan [Wed, 20 Feb 2013 17:43:00 +0000 (12:43 -0500)]
Remove a couple of misplaced VIR_FREE

12 years agoqemu: Run lzop with '--ignore-warn'
Michal Privoznik [Tue, 19 Feb 2013 17:07:58 +0000 (18:07 +0100)]
qemu: Run lzop with '--ignore-warn'

Currently, if lzop decompression binary produces a warning, it
doesn't exit with zero status but 2 instead. Terrifying, but
true. However, warnings may be ignored using '--ignore-warn'
command line argument.  Moreover, in which case, the exit status
will be zero.

12 years agoFix memory leak in virNetClientIOWriteMessage
Sergey Fionov [Sun, 17 Feb 2013 14:20:59 +0000 (18:20 +0400)]
Fix memory leak in virNetClientIOWriteMessage

Commit 18937c3ae0990b4417a43aa07a2c35aaf8cb6ec2 introduced the
memory leak when client->msg.fds is copied to thecall->msg
and then never freed.

12 years agoqemu: Remove the shared disk entry if the operation is ejecting or updating
Osier Yang [Tue, 19 Feb 2013 12:27:45 +0000 (20:27 +0800)]
qemu: Remove the shared disk entry if the operation is ejecting or updating

For both AttachDevice and UpdateDevice APIs, if the disk device
is 'cdrom' or 'floppy', the operations could be ejecting, updating,
and inserting. For either ejecting or updating, the shared disk
entry of the original disk src has to be removed, because it's
not useful anymore.

And since the original disk def will be changed, new disk def passed
as argument will be free'ed in qemuDomainChangeEjectableMedia, so
we need to copy the orignal disk def before
qemuDomainChangeEjectableMedia, to use it for qemuRemoveSharedDisk.

12 years agoqemu: Move the shared disk adding and sgio setting prior to attaching
Osier Yang [Tue, 19 Feb 2013 12:27:44 +0000 (20:27 +0800)]
qemu: Move the shared disk adding and sgio setting prior to attaching

The disk def could be free'ed by qemuDomainChangeEjectableMedia,
which can thus cause crash if we reference the disk pointer. On
the other hand, we have to remove the added shared disk entry from
the table on error codepath.

12 years agoqemu: Update shared disk table when reconnecting qemu process
Osier Yang [Tue, 19 Feb 2013 12:27:43 +0000 (20:27 +0800)]
qemu: Update shared disk table when reconnecting qemu process

12 years agoqemu: Record names of domain which uses the shared disk in hash table
Osier Yang [Wed, 20 Feb 2013 07:43:55 +0000 (15:43 +0800)]
qemu: Record names of domain which uses the shared disk in hash table

The hash entry is changed from "ref" to {ref, @domains}. With this, the
caller can simply call qemuRemoveSharedDisk, without afraid of removing
the entry belongs to other domains. qemuProcessStart will obviously
benifit from it on error codepath (which calls qemuProcessStop to do
the cleanup).

12 years agoqemu: Merge qemuCheckSharedDisk into qemuAddSharedDisk
Osier Yang [Tue, 19 Feb 2013 12:27:41 +0000 (20:27 +0800)]
qemu: Merge qemuCheckSharedDisk into qemuAddSharedDisk

Based on moving various checking into qemuAddSharedDisk, this
avoids the caller using it in wrong ways. Also this adds two
new checking for qemuCheckSharedDisk (disk device not 'lun'
and kernel doesn't support unpriv_sgio simply returns 0).

12 years agoqemu: Add checking in helpers for sgio setting
Osier Yang [Tue, 19 Feb 2013 12:27:40 +0000 (20:27 +0800)]
qemu: Add checking in helpers for sgio setting

This moves the various checking into the helpers, to avoid the
callers missing the checking.

12 years agomaint: enforce private symbol section sorting
Eric Blake [Wed, 20 Feb 2013 00:59:20 +0000 (17:59 -0700)]
maint: enforce private symbol section sorting

Automating a sorting check is the only way to ensure we don't
regress.  Suggested by Dan Berrange.

* src/check-symsorting.pl (check_sorting): Add a parameter,
validate that groups are in order, and that files exist.
* src/Makefile.am (check-symsorting): Adjust caller.
* src/libvirt_private.syms: Fix typo.
* src/libvirt_linux.syms: Fix file name.
* src/libvirt_vmx.syms: Likewise.
* src/libvirt_xenxs.syms: Likewise.
* src/libvirt_sasl.syms: Likewise.
* src/libvirt_libssh2.syms: Likewise.
* src/libvirt_esx.syms: Mention file name.
* src/libvirt_openvz.syms: Likewise.

12 years agoqemu: Do not ignore mandatory features in migration cookie
Jiri Denemark [Wed, 20 Feb 2013 09:30:38 +0000 (10:30 +0100)]
qemu: Do not ignore mandatory features in migration cookie

Due to "feature"/"features" nasty typo, any features marked as mandatory
by one side of a migration are silently considered optional by the other
side. The following is the code that formats mandatory features in
migration cookie:

    for (i = 0 ; i < QEMU_MIGRATION_COOKIE_FLAG_LAST ; i++) {
        if (mig->flagsMandatory & (1 << i))
            virBufferAsprintf(buf, "  <feature name='%s'/>\n",
                              qemuMigrationCookieFlagTypeToString(i));
    }

12 years agoqemu: switch PCI address alocation to use virDevicePCIAddress
Ján Tomko [Fri, 15 Feb 2013 06:48:49 +0000 (07:48 +0100)]
qemu: switch PCI address alocation to use virDevicePCIAddress

Some functions were using virDomainDeviceInfo where virDevicePCIAddress
would suffice. Some were only using integers for slots and functions,
assuming the bus numbers are always 0.

Switch from virDomainDeviceInfoPtr to virDevicePCIAddressPtr:
qemuPCIAddressAsString
qemuDomainPCIAddressCheckSlot
qemuDomainPCIAddressReserveAddr
qemuDomainPCIAddressReleaseAddr

Switch from int slot to virDevicePCIAddressPtr:
qemuDomainPCIAddressReserveSlot
qemuDomainPCIAddressReleaseSlot
qemuDomainPCIAddressGetNextSlot

Deleted functions (they would take the same parameters
as ReserveAddr/ReleaseAddr do now.)
qemuDomainPCIAddressReserveFunction
qemuDomainPCIAddressReleaseFunction

12 years agovirsh: distinguish errors between missing argument and wrong option
Guannan Ren [Tue, 19 Feb 2013 08:50:59 +0000 (16:50 +0800)]
virsh: distinguish errors between missing argument and wrong option

Specifying ':' to suppress the error messages printed by getopt().
Then, distinguish the two types of errors.

Before:
 # virsh -c
   virsh: option requires an argument -- 'c'
   error: unsupported option '-?'. See --help.

After:
 # virsh -c
   error: option '-c' requires an argument

 # virsh -x
   error: unsupported option '-x'. See --help.

12 years agomaint: sort private syms to reflect recent header renames
Eric Blake [Sat, 16 Feb 2013 03:34:42 +0000 (20:34 -0700)]
maint: sort private syms to reflect recent header renames

Purely mechanical (roughly, s/\n/~/; s/~~/\n/; sort by line;
s/~/\n/)

* src/libvirt_private.syms: Sort sections by header file name.

12 years agomaint: fix header file owners of private symbols
Eric Blake [Sat, 16 Feb 2013 03:25:09 +0000 (20:25 -0700)]
maint: fix header file owners of private symbols

Recent renames were not reflected into the comments of
libvirt_private.syms; furthermore, since we mix private headers from
several directories into this file, knowing where the file lives
can be helpful.

* src/libvirt_private.sym: Reflect recent names.

12 years agonet: use structs for address and port ranges
Natanael Copa [Tue, 19 Feb 2013 10:44:16 +0000 (11:44 +0100)]
net: use structs for address and port ranges

We pass over the address/port start/end values many times so we put
them in structs.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Laine Stump <laine@laine.org>
12 years agonet: add support for specifying port range for forward mode nat
Natanael Copa [Tue, 19 Feb 2013 10:44:15 +0000 (11:44 +0100)]
net: add support for specifying port range for forward mode nat

Let users set the port range to be used for forward mode NAT:

...
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
...

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Laine Stump <laine@laine.org>
12 years agonet: support set public ip range for forward mode nat
Natanael Copa [Tue, 19 Feb 2013 10:44:14 +0000 (11:44 +0100)]
net: support set public ip range for forward mode nat

Support setting which public ip to use for NAT via attribute
address in subelement <nat> in <forward>:

...
  <forward mode='nat'>
      <address start='1.2.3.4' end='1.2.3.10'/>
  </forward>
...

This will construct an iptables line using:

  '-j SNAT --to-source <start>-<end>'

instead of:

  '-j MASQUERADE'

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Signed-off-by: Laine Stump <laine@laine.org>
12 years agoqemu: Use atomic ops for driver->nactive
Jiri Denemark [Tue, 19 Feb 2013 13:57:46 +0000 (14:57 +0100)]
qemu: Use atomic ops for driver->nactive

12 years agorpc: Avoid deadlock when closing client connection
Jiri Denemark [Mon, 18 Feb 2013 14:10:04 +0000 (15:10 +0100)]
rpc: Avoid deadlock when closing client connection

We need to drop the server lock before calling virObjectUnlock(client)
since in case we had the last reference to the client, its dispose
callback would be called and that could possibly try to lock the server
and cause a deadlock. This is exactly what happens when there is only
one QEMU domain running and it is marked to be autodestroyed when the
connection dies. This results in qemuProcessAutoDestroy ->
qemuProcessStop -> virNetServerRemoveShutdownInhibition call sequence,
where the last function locks the server.

12 years agoAvoid resetting errors in virTypedParamsFree
Jiri Denemark [Mon, 18 Feb 2013 14:07:48 +0000 (15:07 +0100)]
Avoid resetting errors in virTypedParamsFree

The function does not report any errors so there should be no need too
reset an existing error first. Moreover, virTypedParamsFree is mostly
called in cleanup phase where it has the potential to reset any useful
reported earlier.

12 years agovirsh: Always print capacity unit
Jiri Denemark [Thu, 14 Feb 2013 13:45:48 +0000 (14:45 +0100)]
virsh: Always print capacity unit

It doesn't make sense to print the unit (B) only with Ki, Mi, ...
prefixes. Even those poor bytes under 1 KiB are still bytes :-)

12 years agobuild: force correct gcc syntax for attribute_nonnull
Eric Blake [Mon, 18 Feb 2013 20:34:58 +0000 (13:34 -0700)]
build: force correct gcc syntax for attribute_nonnull

Gcc lets you do:

int ATTRIBUTE_NONNULL(1) foo(void *param);
int foo(void *param) ATTRIBUTE_NONNULL(1);
int ATTRIBUTE_NONNULL(1) foo(void *param) { ... }

but chokes on:

int foo(void *param) ATTRIBUTE_NONNULL(1) { ... }

However, since commit eefb881, we have intentionally been disabling
ATTRIBUTE_NONNULL because of lame gcc handling of the attribute (that
is, gcc doesn't do decent warning reporting, then compiles code that
mysteriously fails if you break the contract of the attribute, which
is surprisingly easy to do), leaving it on only for Coverity (which
does a much better job of improved static analysis when the attribute
is present).

But completely eliding the macro makes it too easy to write code that
uses the fourth syntax option, if you aren't using Coverity.  So this
patch forces us to avoid syntax errors, even when not using the
attribute under gcc.  It also documents WHY we disable the warning
under gcc, rather than forcing you to find the commit log.

* src/internal.h (ATTRIBUTE_NONNULL): Expand to empty attribute,
rather than nothing, when on gcc.

12 years agoqemu: pass "-1" as uid/gid for unprivileged qemu
Guido Günther [Sun, 17 Feb 2013 17:33:08 +0000 (18:33 +0100)]
qemu: pass "-1" as uid/gid for unprivileged qemu

so we don't try to change uid/git to 0 when probing capabilities.

12 years agoAdd capabilities bit for -no-kvm-pit-reinjection
Doug Goldstein [Mon, 18 Feb 2013 05:46:29 +0000 (23:46 -0600)]
Add capabilities bit for -no-kvm-pit-reinjection

The conversion to qemuCaps dropped the ability with qemu{,-kvm} 1.2 and
newer to set the lost tick policy for the PIT. While the
-no-kvm-pit-reinjection option is depreacated, it is still supported at
least through 1.4, it is better to not lose the functionality.

12 years agointerface: fix udev backend use after free
Doug Goldstein [Mon, 18 Feb 2013 04:26:38 +0000 (22:26 -0600)]
interface: fix udev backend use after free

udevIfaceListAllInterface() used the udev_device after it had its ref
count decremented which results in a use after free issue.

12 years agoAdd autogenerated lxc_protocol.[ch] to gitignore
Doug Goldstein [Mon, 18 Feb 2013 05:04:17 +0000 (23:04 -0600)]
Add autogenerated lxc_protocol.[ch] to gitignore

/src/lxc/lxc_protocol.[ch] is autogenerated so add it to .gitignore

12 years agosecurity: Remove unnecessary checks for mgr == NULL
John Ferlan [Wed, 13 Feb 2013 13:11:39 +0000 (08:11 -0500)]
security: Remove unnecessary checks for mgr == NULL

Coverity found the DACGenLabel was checking for mgr == NULL after a
possible dereference; however, in order to get into the function the
virSecurityManagerGenLabel would have already dereferenced sec_managers[i]
so the check was unnecessary. Same check is made in SELinuxGenSecurityLabel.

12 years agovirsh: Resolve possible NULL dereference
John Ferlan [Wed, 13 Feb 2013 12:49:29 +0000 (07:49 -0500)]
virsh: Resolve possible NULL dereference

Coverity found that commit '41b5e845' had a possible NULL dereference on
arg->data processing

12 years agovircommand: Remove unnecessary sa_assert
John Ferlan [Fri, 15 Feb 2013 14:31:24 +0000 (09:31 -0500)]
vircommand: Remove unnecessary sa_assert

Changes from commit '3178df9a' removed the need for the sa_assert(infd).

12 years agocommandtest: Resolve some coverity resource leaks
John Ferlan [Mon, 14 Jan 2013 15:35:45 +0000 (10:35 -0500)]
commandtest: Resolve some coverity resource leaks

12 years agodrivermodule: Ignore coverity warning about leaked_storage
John Ferlan [Mon, 14 Jan 2013 15:35:08 +0000 (10:35 -0500)]
drivermodule: Ignore coverity warning about leaked_storage

12 years agoFix libvirt upgrade path when nwfilter is used
Stefan Berger [Sat, 16 Feb 2013 02:33:37 +0000 (21:33 -0500)]
Fix libvirt upgrade path when nwfilter is used

Between revision 65fb9d49 and before this patch, an upgrade of libvirt while
VMs are running and instantiating iptables filtering rules due to nwfilter
rules, may leave stray iptables rules behind when shutting VMs down.
Left-over iptables rules may look like this:

Chain FP-vnet0 (1 references)
target     prot opt source               destination
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp spt:122
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0

[...]

Chain libvirt-out (1 references)
target     prot opt source               destination
FO-vnet0   all  --  0.0.0.0/0            0.0.0.0/0           [goto]  PHYSDEV match --physdev-out vnet0

The reason is that the recent nwfilter code only removed filtering rules in
the libvirt-out chain that contain the --physdev-is-bridged parameter.
Older rules didn't match and were not removed.

Note that the user-defined chain FO-vnet0 could not be removed due to the
reference from the rule in libvirt-out.

Often the work around may be done through

service iptables restart
kill -SIGHUP $(pidof libvirtd)

This patch now also removes older libvirt versions' iptables rules.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
12 years agostorage: test backing chain traversal
Eric Blake [Wed, 13 Feb 2013 18:04:05 +0000 (11:04 -0700)]
storage: test backing chain traversal

Testing our backing chain handling will make it much easier to
ensure that we avoid issues in the future.  If only I had written
this test before I first caused several regressions...

* tests/virstoragetest.c: New test.
* tests/Makefile.am (test_programs): Build it.
* .gitignore: Ignore new files.

12 years agostorage: don't follow backing chain symlinks too eagerly
Eric Blake [Wed, 6 Feb 2013 22:48:15 +0000 (15:48 -0700)]
storage: don't follow backing chain symlinks too eagerly

If you have a qcow2 file /path1/to/file pointed to by symlink
/path2/symlink, and pass qemu /path2/symlink, then qemu treats
a relative backing file in the qcow2 metadata as being relative
to /path2, not /path1/to.  Yes, this means that it is possible
to create a qcow2 file where the choice of WHICH directory and
symlink you access its contents from will then determine WHICH
backing file (if any) you actually find; the results can be
rather screwy, but we have to match what qemu does.

Libvirt and qemu default to creating absolute backing file
names, so most users don't hit this.  But at least VDSM uses
symlinks and relative backing names alongside the
--reuse-external flags to libvirt snapshot operations, with the
result that libvirt was failing to follow the intended chain of
backing files, and then backing files were not granted the
necessary sVirt permissions to be opened by qemu.

See https://bugzilla.redhat.com/show_bug.cgi?id=903248 for
more gory details.  This fixes a regression introduced in
commit 8250783.

I tested this patch by creating the following chain:

ls /home/eblake/Downloads/Fedora.iso # raw file for base
cd /var/lib/libvirt/images
qemu-img create -f qcow2 \
  -obacking_file=/home/eblake/Downloads/Fedora.iso,backing_fmt=raw one
mkdir sub
cd sub
ln -s ../one onelink
qemu-img create -f qcow2 \
  -obacking_file=../sub/onelink,backing_fmt=qcow2 two
mv two ..
ln -s ../two twolink
qemu-img create -f qcow2 \
  -obacking_file=../sub/twolink,backing_fmt=qcow2 three
mv three ..
ln -s ../three threelink

then pointing my domain at /var/lib/libvirt/images/sub/threelink.
Prior to this patch, I got complaints about missing backing
files; afterwards, I was able to verify that the backing chain
(and hence DAC and SELinux relabels) of the entire chain worked.

* src/util/virstoragefile.h (_virStorageFileMetadata): Add
directory member.
* src/util/virstoragefile.c (absolutePathFromBaseFile): Drop,
replaced by...
(virFindBackingFile): ...better function.
(virStorageFileGetMetadataInternal): Add an argument.
(virStorageFileGetMetadataFromFD, virStorageFileChainLookup)
(virStorageFileGetMetadata): Update callers.

12 years agostorage: refactor metadata lookup
Eric Blake [Wed, 6 Feb 2013 23:33:45 +0000 (16:33 -0700)]
storage: refactor metadata lookup

Prior to this patch, we had the callchains:
external users
  \-> virStorageFileGetMetadataFromFD
      \-> virStorageFileGetMetadataFromBuf
virStorageFileGetMetadataRecurse
  \-> virStorageFileGetMetadataFromFD
      \-> virStorageFileGetMetadataFromBuf

However, a future patch wants to add an additional parameter to
the bottom of the chain, for use by virStorageFileGetMetadataRecurse,
without affecting existing external callers.  Since there is only a
single caller of the internal function, we can repurpose it to fit
our needs, with this patch giving us:

external users
  \-> virStorageFileGetMetadataFromFD
      \-> virStorageFileGetMetadataInternal
virStorageFileGetMetadataRecurse /
  \-> virStorageFileGetMetadataInternal

* src/util/virstoragefile.c (virStorageFileGetMetadataFromFD):
Move most of the guts...
(virStorageFileGetMetadataFromBuf): ...here, and rename...
(virStorageFileGetMetadataInternal): ...to this.
(virStorageFileGetMetadataRecurse): Use internal helper.

12 years agostorage: prepare for refactoring
Eric Blake [Sat, 9 Feb 2013 13:41:01 +0000 (06:41 -0700)]
storage: prepare for refactoring

virStorageFileGetMetadataFromFD is the only caller of
virStorageFileGetMetadataFromBuf; and it doesn't care about the
difference between a return of 0 (total success) or 1
(metadata was inconsistent, but pointer was populated as best
as possible); only about a return of -1 (could not read metadata
or out of memory).  Changing the return type, and normalizing
the variable names used, will make merging the functions easier
in the next commit.

* src/util/virstoragefile.c (virStorageFileGetMetadataFromBuf):
Change return value, and rename some variables.
(virStorageFileGetMetadataFromFD): Rename some variables.

12 years agostorage: rearrange functions
Eric Blake [Wed, 6 Feb 2013 23:54:08 +0000 (16:54 -0700)]
storage: rearrange functions

No semantic change; done so the next patch doesn't need a forward
declaration of a static function.

* src/util/virstoragefile.c (virStorageFileProbeFormatFromBuf):
Hoist earlier.

12 years agobuild: more mingw fixes
Eric Blake [Fri, 15 Feb 2013 22:39:33 +0000 (15:39 -0700)]
build: more mingw fixes

More mingw build failures:

  CCLD     libvirt-lxc.la
/usr/lib64/gcc/i686-w64-mingw32/4.7.2/../../../../i686-w64-mingw32/bin/ld: cannot find libvirt_lxc.def: No such file or directory

  CC       virportallocatortest-virportallocatortest.o
../../tests/virportallocatortest.c: In function 'main':
../../tests/virportallocatortest.c:195:1: error: implicit declaration of function 'setenv' [-Werror=implicit-function-declaration]

* src/Makefile.am (GENERATED_SYM_FILES): Also generate
libvirt_lxc.def.
* bootstrap.conf (gnulib_modules): Import setenv.

12 years agobuild: fix mingw build
Eric Blake [Fri, 15 Feb 2013 22:01:44 +0000 (15:01 -0700)]
build: fix mingw build

Commits 2025356 and ba72cb12 introduced typos.

* src/util/virpci.c (virPCIIsVirtualFunction) [!__linux__]: Fix
function name.
* src/util/virutil.c (virGetDeviceID): Fix attribute spelling.

12 years agobuild: fix vircommand build on mingw
Eric Blake [Fri, 15 Feb 2013 20:13:47 +0000 (13:13 -0700)]
build: fix vircommand build on mingw

  CC       libvirt_util_la-vircommand.lo
../../src/util/vircommand.c:2358:1: error: 'virCommandHandshakeChild' defined but not used [-Werror=unused-function]

The function is only implemented inside #ifndef WIN32.

* src/util/vircommand.c (virCommandHandshakeChild): Hoist earlier,
so that win32 build doesn't hit an unused forward declaration.

12 years agoregex: gnulib guarantees that we have regex support
Eric Blake [Mon, 11 Feb 2013 22:12:16 +0000 (15:12 -0700)]
regex: gnulib guarantees that we have regex support

No need to use HAVE_REGEX_H - our use of gnulib guarantees that
the header exists and works, regardless of platform.  Similarly,
we can unconditionally assume a compiling <sys/wait.h> (although
the mingw version of this header is not full-featured).

* src/storage/storage_backend.c: Drop useless conditional.
* tests/testutils.c: Likewise.

12 years agovbox: Don't overwrite errors returned by virDomainDeviceDefParse
Jiri Denemark [Thu, 14 Feb 2013 08:05:36 +0000 (09:05 +0100)]
vbox: Don't overwrite errors returned by virDomainDeviceDefParse

12 years agoutil: maintain caps when running command with uid != 0
Laine Stump [Thu, 7 Feb 2013 16:45:27 +0000 (11:45 -0500)]
util: maintain caps when running command with uid != 0

virCommand was previously calling virSetUIDGID() to change the uid and
gid of the child process, then separately calling
virSetCapabilities(). This did not work if the desired uid was != 0,
since a setuid to anything other than 0 normally clears all
capabilities bits.

The solution is to use the new virSetUIDGIDWithCaps(), sending it the
uid, gid, and capabilities bits. This will get the new process setup
properly.

Since the static functions virSetCapabilities() and
virClearCapabilities are no longer called, they have been removed.

NOTE: When combined with "filecap $path-to-qemu sys_rawio", this patch
will make CAP_SYS_RAWIO (which is required for passthrough of generic
scsi commands to a guest - see commits e8daeeb177db08397e6a7, and
74e0349) be retained by qemu when necessary. Apparently that
capability has been broken for non-root qemu ever since it was
originally added.

12 years agoutil: virSetUIDGIDWithCaps - change uid while keeping caps
Laine Stump [Tue, 5 Feb 2013 15:30:32 +0000 (10:30 -0500)]
util: virSetUIDGIDWithCaps - change uid while keeping caps

Normally when a process' uid is changed to non-0, all the capabilities
bits are cleared, even those explicitly set with calls to
capng_update()/capng_apply() made immediately before setuid. And
*after* the process' uid has been changed, it no longer has the
necessary privileges to add capabilities back to the process.

In order to set a non-0 uid while still maintaining any capabilities
bits, it is necessary to either call capng_change_id() (which
unfortunately doesn't currently call initgroups to setup auxiliary
group membership), or to perform the small amount of calisthenics
contained in the new utility function virSetUIDGIDWithCaps().

Another very important difference between the capabilities
setting/clearing in virSetUIDGIDWithCaps() and virCommand's
virSetCapabilities() (which it will replace in the next patch) is that
the new function properly clears the capabilities bounding set, so it
will not be possible for a child process to set any new
capabilities.

A short description of what is done by virSetUIDGIDWithCaps():

1) clear all capabilities then set all those desired by the caller (in
capBits) plus CAP_SETGID, CAP_SETUID, and CAP_SETPCAP (which is needed
to change the capabilities bounding set).

2) call prctl(), telling it that we want to maintain current
capabilities across an upcoming setuid().

3) switch to the new uid/gid

4) again call prctl(), telling it we will no longer want capabilities
maintained if this process does another setuid().

5) clear the capabilities that we added to allow us to
setuid/setgid/change the bounding set (unless they were also requested
by the caller via the virCommand API).

Because the modification/maintaining of capabilities is intermingled
with setting the uid, this is necessarily done in a single function,
rather than having two independent functions.

Note that, due to the way that effective capabilities are computed (at
time of execve) for a process that has uid != 0, the *file*
capabilities of the binary being executed must also have the desired
capabilities bit(s) set (see "man 7 capabilities"). This can be done
with the "filecap" command. (e.g. "filecap /usr/bin/qemu-kvm sys_rawio").

12 years agoutil: drop capabilities immediately after changing uid/gid of child
Laine Stump [Fri, 1 Feb 2013 21:26:25 +0000 (16:26 -0500)]
util: drop capabilities immediately after changing uid/gid of child

This is an interim measure to make sure everything still works in this
order. The next step will be to perform capabilities drop and
setuid/gid as a single operation (which is the only way to keep any
capabilities when switching to a non-root uid).