]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
12 years agovirsh: migrate: Don't disallow --p2p and --migrateuri
Cole Robinson [Tue, 28 May 2013 19:37:53 +0000 (15:37 -0400)] 
virsh: migrate: Don't disallow --p2p and --migrateuri

Because it's a valid combination. p2p still uses a separate channel
for qemu migration, so there's value in letting the user specify a manual
migrate URI for overriding auto-port, or libvirt's FQDN lookup.

What _isn't_ allowed is --migrateuri and TUNNELLED, since there is
no separate migration channel. Disallow that instead
(cherry picked from commit 5e1de4fcdd86aceba610e9b77f6e62fc6525883b)

12 years agoqemu: migration: error if tunnelled + storage specified
Cole Robinson [Tue, 28 May 2013 19:27:45 +0000 (15:27 -0400)] 
qemu: migration: error if tunnelled + storage specified

Since as the code indicates it doesn't work yet, so let's be
explicit about it.
(cherry picked from commit 98bbda00cfa58c3fb73220e4a7c5d33938c0cb74)

12 years agoqemu: migration: Improve p2p error if we can't open conn
Cole Robinson [Tue, 28 May 2013 19:12:01 +0000 (15:12 -0400)] 
qemu: migration: Improve p2p error if we can't open conn

By actually showing the Open() error to the user
(cherry picked from commit 5751fc4f4efe25e6abb158fc86c61230303ce280)

12 years agoAdd a virGetLastErrorMessage() function
Daniel P. Berrange [Fri, 10 May 2013 17:09:44 +0000 (18:09 +0100)] 
Add a virGetLastErrorMessage() function

Apps using libvirt will often have code like

   if (virXXXX() < 0) {
      virErrorPtr err = virGetLastError();
      fprintf(stderr, "Something failed: %s\n",
              err && err->message ? err->message :
              "unknown error");
      return -1;
   }

Checking for a NULL error object or message leads to very
verbose code. A virGetLastErrorMessage() helper from libvirt
can simplify this to

   if (virXXXX() < 0) {
      fprintf(stderr, "Something failed: %s\n",
              virGetLastErrorMessage());
      return -1;
   }

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 69c6a58a1d3906fdb3ee7929a03ce9b59f33e1c3)

12 years agoqemu: Don't report error on successful media eject
Cole Robinson [Tue, 28 May 2013 14:23:00 +0000 (10:23 -0400)] 
qemu: Don't report error on successful media eject

If we are just ejecting media, ret == -1 even after the retry loop
determines that the tray is open, as requested. This means media
disconnect always report's error.

Fix it, and fix some other mini issues:

- Don't overwrite the 'eject' error message if the retry loop fails
- Move the retries decrement inside the loop, otherwise the final loop
  might succeed, yet retries == 0 and we will raise error
- Setting ret = -1 in the disk->src check is unneeded
- Fix comment typos

cc: mprivozn@redhat.com
(cherry picked from commit 406d8a980973cfd4caebbc886f5b283233409a64)

12 years agoqemuDomainChangeEjectableMedia: Unlock domain while waiting for event
Michal Privoznik [Mon, 20 May 2013 17:26:14 +0000 (19:26 +0200)] 
qemuDomainChangeEjectableMedia: Unlock domain while waiting for event

In 84c59ffa I've tried to fix changing ejectable media process. The
process should go like this:

1) we need to call 'eject' on the monitor
2) we should wait for 'DEVICE_TRAY_MOVED' event
3) now we can issue 'change' command

However, while waiting in step 2) the domain monitor was locked. So
even if qemu reported the desired event, the proper callback was not
called immediately. The monitor handling code needs to lock the
monitor in order to read the event. So that's the first lock we must
not hold while waiting. The second one is the domain lock. When
monitor handling code reads an event, the appropriate callback is
called then. The first thing that each callback does is locking the
corresponding domain as a domain or its device is about to change
state. So we need to unlock both monitor and VM lock. Well, holding
any lock while sleep()-ing is not the best thing to do anyway.
(cherry picked from commit 543af79a14f06cd16844c28887210bbb93a455fa)

12 years agostorage: Ensure 'qemu-img resize' size arg is a 512 multiple
Christophe Fergeau [Tue, 14 May 2013 13:48:21 +0000 (15:48 +0200)] 
storage: Ensure 'qemu-img resize' size arg is a 512 multiple

qemu-img resize will fail with "The new size must be a multiple of 512"
if libvirt doesn't round it first.
This fixes rhbz#951495

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
(cherry picked from commit 9a8f39d097448b2b43c4a05d0edc213eacfc9ea6)

12 years agonwfilter: grab driver lock earlier during init (bz96649)
Stefan Berger [Tue, 4 Jun 2013 18:50:20 +0000 (14:50 -0400)] 
nwfilter: grab driver lock earlier during init (bz96649)

This patch is in relation to Bug 966449:

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

This is a patch addressing the coredump.

Thread 1 must be calling  nwfilterDriverRemoveDBusMatches(). It does so with
nwfilterDriverLock held. In the patch below I am now moving the
nwfilterDriverLock(driverState) further up so that the initialization, which
seems to either take a long time or is entirely stuck, occurs with the lock
held and the shutdown cannot occur at the same time.

Remove the lock in virNWFilterDriverIsWatchingFirewallD to avoid
double-locking.

(cherry picked from commit 0ec376c20a42b9eb365c1f9a5596366023c20c35)

12 years agoFix use of VIR_STRDUP vs strdup
Doug Goldstein [Sun, 9 Jun 2013 22:23:35 +0000 (17:23 -0500)] 
Fix use of VIR_STRDUP vs strdup

Commit 894f784948a93760629de3cb195c69ef4f4b831f broke the v1.0.5-maint
branch because VIR_STRDUP() didn't exist in the v1.0.5 release so the
resulting build is missing that symbol.

This patch is only for the v1.0.5-maint branch.

12 years agoqemu: Fix crash in migration of graphics-less guests.
Viktor Mihajlovski [Thu, 16 May 2013 12:41:29 +0000 (14:41 +0200)] 
qemu: Fix crash in migration of graphics-less guests.

Commit 7f15ebc7a2b599ab10dbc15bca6f823591213e67 introduced a bug
happening when guests without a <graphics> element are migrated.
The initialization of listenAddress happens unconditionally
from the cookie even if the cookie->graphics pointer was NULL.
Moved the initialization to where it is safe.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
(cherry picked from commit 9684bb11fd3832582308d0bcdb649041fd6584e2)

12 years agoqemu: prevent termination of guests w/hostdev on driver reconnect
Laine Stump [Fri, 31 May 2013 18:30:09 +0000 (14:30 -0400)] 
qemu: prevent termination of guests w/hostdev on driver reconnect

This should resolve:

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

The problem was that qemuUpdateActivePciHostdevs was returning 0
(success) when no hostdevs were present, but would otherwise return -1
(failure) even when it completed successfully. It is only called from
qemuProcessReconnect(), and when qemuProcessReconnect got back an
error, it would not only stop reconnecting, but would terminate the
guest qemu process "to remove danger of it ending up running twice if
user tries to start it again later".

(This bug was introduced in commit 011cf7ad, which was pushed between
v1.0.2 and v1.0.3, so all maintenance branches from v1.0.3 up to 1.0.5
will need this one line patch applied.)
(cherry picked from commit 2ea45647bcde23cff5da48f725561ff5ba3fba39)

12 years agoqemu: escape literal IPv6 address in NBD migration
Ján Tomko [Fri, 31 May 2013 11:24:06 +0000 (13:24 +0200)] 
qemu: escape literal IPv6 address in NBD migration

A literal IPv6 must be escaped, otherwise migration fails with:
unable to execute QEMU command 'drive-mirror': address resolution failed
for f0::0d:5901: Servname not supported for ai_socktype
since QEMU treats everything after the first ':' as the port.
(cherry picked from commit 2136327e23a7c87e7a75e4fd69faa5b2e8771d38)

12 years agobuild: fix build with older gcc
Eric Blake [Tue, 28 May 2013 23:30:30 +0000 (17:30 -0600)] 
build: fix build with older gcc

gcc 4.1.2 (hello, RHEL 5!) fails to build on 32-bit platforms with:

conf/domain_conf.c: In function 'virDomainDefParseXML':
conf/domain_conf.c:10581: warning: integer constant is too large for 'long' type

Problem introduced in commit f8e3221f9.

* src/conf/domain_conf.c (virDomainDefParseXML): Mark large constants.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit f6817c70b430c1cfdbdc7795cf09626c1fa810d8)

12 years agoqemu: fix NBD migration to hosts with IPv6 enabled
Ján Tomko [Thu, 23 May 2013 13:51:05 +0000 (15:51 +0200)] 
qemu: fix NBD migration to hosts with IPv6 enabled

Since f03dcc5 we use [::] as the listening address both on qemu
command line in -incoming and in nbd-server-start QMP command.
However the latter requires just :: without the braces.
(cherry picked from commit 2326006410a921bba38c0ce67a367cd1ea88cc33)

12 years agocgroup: be robust against cgroup movement races
Eric Blake [Tue, 21 May 2013 02:30:30 +0000 (20:30 -0600)] 
cgroup: be robust against cgroup movement races

https://bugzilla.redhat.com/show_bug.cgi?id=965169 documents a
problem starting domains when cgroups are enabled; I was able
to reliably reproduce the race about 5% of the time when I added
hooks to domain startup by 3 seconds (as that seemed to be about
the length of time that qemu created and then closed a temporary
thread, probably related to aio handling of initially opening
a disk image).  The problem has existed since we introduced
virCgroupMoveTask in commit 9102829 (v0.10.0).

There are some inherent TOCTTOU races when moving tasks between
kernel cgroups, precisely because threads can be created or
completed in the window between when we read a thread id from the
source and when we write to the destination.  As the goal of
virCgroupMoveTask is merely to move ALL tasks into the new
cgroup, it is sufficient to iterate until no more threads are
being created in the old group, and ignoring any threads that
die before we can move them.

It would be nicer to start the threads in the right cgroup to
begin with, but by default, all child threads are created in
the same cgroup as their parent, and we don't want vcpu child
threads in the emulator cgroup, so I don't see any good way
of avoiding the move.  It would also be nice if the kernel were
to implement something like rename() as a way to atomically move
a group of threads from one cgroup to another, instead of forcing
a window where we have to read and parse the source, then format
and write back into the destination.

* src/util/vircgroup.c (virCgroupAddTaskStrController): Ignore
ESRCH, because a thread ended between read and write attempts.
(virCgroupMoveTask): Loop until all threads have moved.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 83e4c77547f5b721afad19a452f41c31daeee8c5)

12 years agoPrep for release 1.0.5.1 v1.0.5.1
Cole Robinson [Sun, 19 May 2013 22:01:21 +0000 (18:01 -0400)] 
Prep for release 1.0.5.1

12 years agotests: use portable shell code
Eric Blake [Thu, 9 May 2013 17:36:58 +0000 (11:36 -0600)] 
tests: use portable shell code

'make check' fails since commit 470d5c46 on any system with dash
as /bin/sh, because '<<<' is a bash extension.  For example:

nwfilterschematest: 23: /home/eblake/libvirt/tests/schematestutils.sh: Syntax error: redirection unexpected

Also, there is no need to spawn a grep process when shell globbing
can do the same.

* tests/schematestutils.sh: Replace bashism and subprocess with a
faster and portable construct.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 1d21b884a3603d0a776d365e3ba311ffc6960445)

12 years agoqemu: Fix cgroup handling when setting VCPU BW
Martin Kletzander [Thu, 16 May 2013 12:37:54 +0000 (14:37 +0200)] 
qemu: Fix cgroup handling when setting VCPU BW

Commit 632f78c introduced a regression which causes schedinfo being
unable to set some parameters.  When migrating to priv->cgroup there
was missing variable left out and due to passed NULL to underlying
function, the setting failed.

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

12 years agodaemon: fix leak after listing all volumes
Ján Tomko [Fri, 12 Apr 2013 15:30:56 +0000 (17:30 +0200)] 
daemon: fix leak after listing all volumes

CVE-2013-1962

remoteDispatchStoragePoolListAllVolumes wasn't freeing the pool.
The pool also held a reference to the connection, preventing it from
getting freed and closing the netcf interface driver, which held two
sockets open.
(cherry picked from commit ca697e90d5bd6a6dfb94bfb6d4438bdf9a44b739)

12 years agoFix iohelper usage with streams opened for read
Daniel P. Berrange [Fri, 10 May 2013 13:45:05 +0000 (14:45 +0100)] 
Fix iohelper usage with streams opened for read

bz #960879

In b2878ed860ceceec3cd6481424fed0b543b687cd we added the O_NOCTTY
flag when opening files in the stream code. Unfortunately a later
piece of code was comparing the flags == O_RDONLY, without masking
out the non-access mode flags. This broke the iohelper when used
with streams for read, since it caused us to attach the stream
output pipe to the stream input FD instead of output FD :-(

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit a2214c5257d3bd7b086ce04aca1648e8ff05ee96)

12 years agoutil: fix virFileOpenAs return value and resulting error logs
Laine Stump [Wed, 8 May 2013 19:02:14 +0000 (15:02 -0400)] 
util: fix virFileOpenAs return value and resulting error logs

This resolves:

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

The first problem was that virFileOpenAs was returning fd (-1) in one
of the error cases rather than ret (-errno), so the caller thought
that the error was EPERM rather than ENOENT.

The second problem was that some log messages in the general purpose
qemuOpenFile() function would always say "Failed to create" even if
the caller hadn't included O_CREAT (i.e. they were trying to open an
existing file).

This fixes virFileOpenAs to jump down to the error return (which
returns ret instead of fd) in the previously mentioned incorrect
failure case of virFileOpenAs(), removes all error logging from
virFileOpenAs() (since the callers report it), and modifies
qemuOpenFile to appropriately use "open" or "create" in its log
messages.

NB: I seriously considered removing logging from all callers of
virFileOpenAs(), but there is at least one case where the caller
doesn't want virFileOpenAs() to log any errors, because it's just
going to try again (qemuOpenFile()). We can't simply make a silent
variation of virFileOpenAs() though, because qemuOpenFile() can't make
the decision about whether or not it wants to retry until after
virFileOpenAs() has already returned an error code.

Likewise, I also considered changing virFileOpenAs() to return -1 with
errno set on return, and may still do that, but only as a separate
patch, as it obscures the intent of this patch too much.
(cherry picked from commit a2c1bedbd8fa977dc733266e88a1b57e28b50dd3)

12 years agoiscsi: don't leak portal string when starting a pool
Ján Tomko [Mon, 6 May 2013 12:36:23 +0000 (14:36 +0200)] 
iscsi: don't leak portal string when starting a pool

(cherry picked from commit 413274f63b8f2da3b1a4adfdf1cbc0df7a0e0316)

12 years agodon't mention disk controllers in generic controller errors
Ján Tomko [Thu, 9 May 2013 09:39:21 +0000 (11:39 +0200)] 
don't mention disk controllers in generic controller errors

The controller element supports non-disk controller types too.

https://bugzilla.redhat.com/show_bug.cgi?id=960958
(cherry picked from commit c075f89fa291478e5244d64cf528ca3e80705d26)

12 years agoconf: don't crash on a tpm device with no backends
Ján Tomko [Thu, 9 May 2013 10:33:11 +0000 (12:33 +0200)] 
conf: don't crash on a tpm device with no backends

Print an error instead of crashing when a TPM device without
a backend is specified.

Add a test for tpm device with no backend, which should fail
with a parse error.

https://bugzilla.redhat.com/show_bug.cgi?id=961252
(cherry picked from commit 1d96440a060869fb4c26ce35fe165e6e68168885)

12 years agotests: files named '.*-invalid.xml' should fail validation
Ján Tomko [Thu, 9 May 2013 11:43:32 +0000 (13:43 +0200)] 
tests: files named '.*-invalid.xml' should fail validation

Currently, using an invalid XML in tests fails, because
the schema test expects all of them to be valid.

Treat files with -invalid.xml suffix as invalid and expect
them to fail validation.
(cherry picked from commit 470d5c4654b512d101a8665754b13866925eeaa2)

12 years agoqemu: allocate network connections sooner during domain startup
Laine Stump [Mon, 6 May 2013 19:43:56 +0000 (15:43 -0400)] 
qemu: allocate network connections sooner during domain startup

VFIO device assignment requires a cgroup ACL to be setup for access to
the /dev/vfio/nn "group" device for any devices that will be assigned
to a guest. In the case of a host device that is allocated from a
pool, it was being allocated during qemuBuildCommandLine(), which is
called by qemuProcessStart() *after* the all-encompassing
qemuSetupCgroup() was called, meaning that the standard Cgroup ACL
setup wasn't creating ACLs for these devices allocated from pools.

One possible solution was to manually add a single ACL down inside
qemuBuildCommandLine() when networkAllocateActualDevice() is called,
but that has two problems: 1) the function that adds the cgroup ACL
requires a virDomainObjPtr, which isn't available in
qemuBuildCommandLine(), and 2) we really shouldn't be doing network
device setup inside qemuBuildCommandLine() anyway.

Instead, I've created a new function called
qemuNetworkPrepareDevices() which is called just before
qemuPrepareHostDevices() during qemuProcessStart() (explanation of
ordering in the comments), i.e. well before the call to
qemuSetupCgroup(). To minimize code churn in a patch that will be
backported to 1.0.5-maint, qemuNetworkPrepareDevices only does
networkAllocateActualDevice() and the bare amount of setup required
for type='hostdev network devices, but it eventually should do *all*
device setup for guest network devices.

Note that some of the code that was previously needed in
qemuBuildCommandLine() is no longer required when
networkAllocateActualDevice() is called earlier:

 * qemuAssignDeviceHostdevAlias() is already done further down in
   qemuProcessStart().

 * qemuPrepareHostdevPCIDevices() is called by
   qemuPrepareHostDevices() which is called after
   qemuNetworkPrepareDevices() in qemuProcessStart().

As hinted above, this new function should be moved into a separate
qemu_network.c (or similarly named) file along with
qemuPhysIfaceConnect(), qemuNetworkIfaceConnect(), and
qemuOpenVhostNet(), and expanded to call those functions as well, then
the nnets loop in qemuBuildCommandLine() should be reduced to only
build the commandline string (which itself can be in a separate
qemuInterfaceBuilldCommandLine() function as suggested by
Michal). However, this will require storing away an array of tapfd and
vhostfd that are needed for the commandline, so I would rather do that
in a separate patch and leave this patch at the minimum to fix the
bug.
(cherry picked from commit 8cd40e7e0d92a0edbe08941fdf728a81c2e6cf15)

12 years agoMake detect_scsi_host_caps a function on all architectures
Guido Günther [Fri, 3 May 2013 06:03:26 +0000 (08:03 +0200)] 
Make detect_scsi_host_caps a function on all architectures

In the non linux case some callers like gather_scsi_host_caps needed the
return code of -1 while others like update_caps needed an empty
statement (to avoid a "statement without effect" warning). This is much
simpler solved by using a function instead of a define.
(cherry picked from commit 58662f44165ccbffee95b4911a7eec49975bde0b)

12 years agoFixup rpcgen code on kFreeBSD too
Guido Günther [Fri, 3 May 2013 05:17:18 +0000 (07:17 +0200)] 
Fixup rpcgen code on kFreeBSD too

since it uses glibc's rpcgen.
(cherry picked from commit b562d7b7e4a9c82900cc5e7b2a6760b27fc4096c)

12 years agoFix release of resources with lockd plugin
Daniel P. Berrange [Fri, 3 May 2013 11:00:15 +0000 (12:00 +0100)] 
Fix release of resources with lockd plugin

The lockd plugin for the lock manager was not correctly
handling the release of resource locks. This meant that
during migration, or when pausing a VM, the locks would
not get released. This in turn made it impossible to
resume the domain, or finish migration
(cherry picked from commit 8dc93ffadcca0cc9813ba04036b7139922c55400)

12 years agobuild: avoid non-portable cast of pthread_t
Eric Blake [Thu, 2 May 2013 20:23:02 +0000 (14:23 -0600)] 
build: avoid non-portable cast of pthread_t

POSIX says pthread_t is opaque.  We can't guarantee if it is scaler
or a pointer, nor what size it is; and BSD differs from Linux.
We've also had reports of gcc complaining on attempts to cast it,
if we use a cast to the wrong type (for example, pointers have to be
cast to void* or intptr_t before being narrowed; while casting a
function return of scalar pthread_t to void* triggers a different
warning).

Give up on casts, and use unions to get at decent bits instead.  And
rather than futz around with figuring which 32 bits of a potentially
64-bit pointer are most likely to be unique, convert the rest of
the code base to use 64-bit values when using a debug id.

Based on a report by Guido Günther against kFreeBSD, but with a
fix that doesn't regress commit 4d970fd29 for FreeBSD.

* src/util/virthreadpthread.c (virThreadSelfID, virThreadID): Use
union to get at a decent bit representation of thread_t bits.
* src/util/virthread.h (virThreadSelfID, virThreadID): Alter
signature.
* src/util/virthreadwin32.c (virThreadSelfID, virThreadID):
Likewise.
* src/qemu/qemu_domain.h (qemuDomainJobObj): Alter type of owner.
* src/qemu/qemu_domain.c (qemuDomainObjTransferJob)
(qemuDomainObjSetJobPhase, qemuDomainObjReleaseAsyncJob)
(qemuDomainObjBeginNestedJob, qemuDomainObjBeginJobInternal): Fix
clients.
* src/util/virlog.c (virLogFormatString): Likewise.
* src/util/vireventpoll.c (virEventPollInterruptLocked):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 22d12905e612de93944b4413ae3fbd278df52fe8)

12 years agoFix potential use of undefined variable in remote dispatch code
Daniel P. Berrange [Thu, 2 May 2013 11:35:47 +0000 (12:35 +0100)] 
Fix potential use of undefined variable in remote dispatch code

If an early dispatch check caused a jump to the 'cleanup' branch
then virTypeParamsFree() would be called with an uninitialized
'nparams' variable. Fortunately 'params' is initialized to NULL,
so the uninitialized 'nparams' variable would not be used.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit 31dbbb667f7c711a18bd106358226685674c0605)

12 years agobuild: fix mingw build of virprocess.c
Eric Blake [Thu, 2 May 2013 21:46:19 +0000 (15:46 -0600)] 
build: fix mingw build of virprocess.c

Commit 776d49f4 added a static function that is only called
conditionally; leading to this compile error on mingw:

  CC       libvirt_util_la-virprocess.lo
../../src/util/virprocess.c:624:26: error: 'struct rlimit' declared inside parameter list [-Werror]
../../src/util/virprocess.c:624:26: error: its scope is only this definition or declaration, which is probably not what you want [-Werror]
../../src/util/virprocess.c:622:1: error: 'virProcessPrLimit' defined but not used [-Werror=unused-function]

* src/util/virprocess.c (virProcessPrLimit): Only declare
virProcessPrLimit when used.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 05f79a3894a04b305c18993bedf117c6b6e41d52)

12 years agoFix F_DUPFD_CLOEXEC operation args
Daniel P. Berrange [Fri, 3 May 2013 10:10:50 +0000 (11:10 +0100)] 
Fix F_DUPFD_CLOEXEC operation args

The F_DUPFD_CLOEXEC operation with fcntl() expects a single
int argument, specifying the minimum FD number for the newly
dup'd file descriptor. We were not specifying that causing
random stack data to be accessed as the FD number. Sometimes
that worked, sometimes it didn't.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
(cherry picked from commit d6670a64e1067f29da3c3e032739e140280b763d)

12 years agospec: proper soft static allocation of qemu uid
Eric Blake [Wed, 1 May 2013 20:28:43 +0000 (14:28 -0600)] 
spec: proper soft static allocation of qemu uid

https://bugzilla.redhat.com/show_bug.cgi?id=924501 tracks a
problem that occurs if uid 107 is already in use at the time
libvirt is first installed.  In response that problem, Fedora
packaging guidelines were recently updated.  This fixes the
spec file to comply with the new guidelines:
https://fedoraproject.org/wiki/Packaging:UsersAndGroups

* libvirt.spec.in (daemon): Follow updated Fedora guidelines.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit a2584d58f6f7d941b960f996c8e26df8294b79b9)

12 years agobuild: clean up stray files found by 'make distcheck'
Eric Blake [Mon, 6 May 2013 16:21:55 +0000 (10:21 -0600)] 
build: clean up stray files found by 'make distcheck'

'make distcheck' complained:

ERROR: files left in build directory after distclean:
./python/libvirt.pyc
./tests/commandhelper.log

Problems introduced in commits f015495 and 25ea8e4 (both v1.0.3).

* tests/commandtest.c (test21): Check (and clean) log file.
* tests/commanddata/test21.log: New file.
* python/Makefile.am (CLEANFILES): Clean up compiled python files.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit c21c38d71b31f0b119d615cc16800eee9fe0bb10)

12 years agobuild: always include libvirt_lxc.syms in tarball
Eric Blake [Thu, 2 May 2013 23:35:50 +0000 (17:35 -0600)] 
build: always include libvirt_lxc.syms in tarball

On a mingw build, 'make distcheck' fails with:

  GEN      libvirt_qemu.def
make[3]: *** No rule to make target `../../src/libvirt_lxc.syms', needed by `libvirt_lxc.def'.  Stop.

I traced it to a missing entry in EXTRA_DIST.  But rather than keep
the entire list in sync, it is easier to list the three syms files
that drive .so files directly, and then reuse existing makefile
variables for the remaining files (that is, I validated that all
remaining files are added to SYM_FILES, possibly via USED_SYM_FILES,
according to makefile conditionals).

Problem introduced in commit 3d1596b (v1.0.2).

* src/Makefile.am (EXTRA_DIST): Ensure all syms files are shipped.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit ed11ab93fa683df5669fe36f16a79cff396a9c03)

12 years agoqemu: fix stupid typos in VFIO cgroup setup/teardown
Laine Stump [Fri, 3 May 2013 18:30:55 +0000 (14:30 -0400)] 
qemu: fix stupid typos in VFIO cgroup setup/teardown

I must have looked at this a couple dozen times before I noticed it
had "!=" instead of "==". Not doing this setup prevented qemu from
doing anything with the vfio group device.
(cherry picked from commit 52ba0f6e1cf29e791be4e079408c0de851100b65)

12 years agobuild: always include sanitytest in tarball
Eric Blake [Thu, 2 May 2013 17:56:34 +0000 (11:56 -0600)] 
build: always include sanitytest in tarball

The libvirt 1.0.5 tarball is missing a file which renders 'make
check' broken; first reported on list by Guido Günther.

* python/Makefile.am (EXTRA_DIST): Hoist sanitytest.py out of
HAVE_PYTHON conditional.

Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 5a3487dadb04bbba4bec9aed102ac83568d47363)

12 years agovirInitctlRequest: unbreak make syntax check
Guido Günther [Thu, 2 May 2013 07:17:44 +0000 (09:17 +0200)] 
virInitctlRequest: unbreak make syntax check

introduced by dcf97846d54b9ae20181f0f29c684b6ae4de89ee

To trigger this cppi needs to be installed.
(cherry picked from commit ca75c44310521ed5b987fc33014a8eeae652bad3)

12 years agovirInitctlRequest: unbreak make syntax check
Guido Günther [Thu, 2 May 2013 07:17:44 +0000 (09:17 +0200)] 
virInitctlRequest: unbreak make syntax check

introduced by dcf97846d54b9ae20181f0f29c684b6ae4de89ee
(cherry picked from commit a1365d7351b292fceabc2ddfc75b567ca894e97c)

12 years agonetwork: fix network driver startup for qemu:///session
Laine Stump [Thu, 2 May 2013 17:59:52 +0000 (13:59 -0400)] 
network: fix network driver startup for qemu:///session

This should resolve https://bugzilla.redhat.com/show_bug.cgi?id=958907

Recent new addition of code to read/write active network state to the
NETWORK_STATE_DIR in the network driver broke startup for
qemu:///session. The network driver had several state file paths
hardcoded to /var, which could never possibly work in session mode.

This patch modifies *all* state files to use a variable string that is
set differently according to whether or not we're running
privileged. (It turns out that logDir was never used, so it's been
completely eliminated.)

There are very definitely other problems preventing dnsmasq and radvd
from running in non-privileged mode, but it's more consistent to have
the directories used by them be determined in the same fashion.

NB: I've noted before that the network driver is storing its state
(including dnsmasq and radvd state) in /var/lib, while qemu stores its
state in /var/run. It would probably have been better if the two
matched, but it's been this way for a long time, and changing it would
break running installations during an upgrade, so it's best to just
leave it as it is.
(cherry picked from commit 2ffd87d8204c209b81610b56ee5161ae71b58b8c)

Conflicts:
src/network/bridge_driver.c - code removed by this patch had
                                      been modified upstream.

12 years agoRelease of libvirt-1.0.5 v1.0.5
Daniel Veillard [Thu, 2 May 2013 06:58:48 +0000 (14:58 +0800)] 
Release of libvirt-1.0.5

* configure.ac docs/news.html.in libvirt.spec.in: updated for the release
* po/*.po*: pulled and merged a number of new localization updates

12 years agovirInitctlRequest: Don't hardcode 384 bytes size
Guido Günther [Wed, 1 May 2013 20:35:44 +0000 (22:35 +0200)] 
virInitctlRequest: Don't hardcode 384 bytes size

When MAXHOSTNAMELEN is set we have to take it's value into account.
Otherwise the build fails on kFreeBSD (FreeBSD kernel and GNU userland)

12 years agopci: autolearn name of stub driver, remove from arglist
Laine Stump [Wed, 1 May 2013 18:44:10 +0000 (14:44 -0400)] 
pci: autolearn name of stub driver, remove from arglist

virPCIDeviceReattach and virPCIDeviceUnbindFromStub (called by
virPCIDeviceReattach) had previously required the name of the stub
driver as input. This is unnecessary, because the name of the driver
the device is currently bound to can be found by looking at the link:

  /sys/bus/pci/dddd:bb:ss.ff/driver

Instead of requiring that the name of the expected stub driver name
and only unbinding if that one name is matched, we no longer take a
driver name in the arglist for either of these
functions. virPCIDeviceUnbindFromStub just compares the name of the
currently bound driver to a list of "well known" stubs (right now
contains "pci-stub" and "vfio-pci" for qemu, and "pciback" for xen),
and only performs the unbind if it's one of those devices.

This allows virsh nodedevice-reattach to work properly across a
libvirtd restart, and fixes a couple of cases where we were
erroneously still hard-coding "pci-stub" as the drive name.

For some unknown reason, virPCIDeviceReattach had been calling
modprobe on the stub driver prior to unbinding the device. This was
problematic because we no longer know the name of the stub driver in
that function. However, it is pointless to probe for the stub driver
at that time anyway - because the device is bound to the stub driver,
we are guaranteed that it is already loaded, and so that call to
modprobe has been removed.

12 years agospec: collect all BuildRequires into one area
Eric Blake [Wed, 1 May 2013 20:16:10 +0000 (14:16 -0600)] 
spec: collect all BuildRequires into one area

Conditional BuildRequires: should be at the top level, rather
than appearing in conditional sub-package sections.  This
appears to be the only offender.

* libvirt.spec.in (BuildRequires): Move libblkid-devel into
correct area.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agodocs: Fix closing tag in snapshot documentation
Christophe Fergeau [Wed, 1 May 2013 17:59:56 +0000 (19:59 +0200)] 
docs: Fix closing tag in snapshot documentation

Commit cc6d19f3 added text containing "<code>snapshot<code>" to
formatsnapshot.html.in. The closing tag is missing '/' which causes
the documentation to misrender.

12 years agoESX: Fix DISPATCH_FREE generation code to free all extended objects
Ata E Husain Bohra [Wed, 2 Jan 2013 06:22:28 +0000 (22:22 -0800)] 
ESX: Fix DISPATCH_FREE generation code to free all extended objects

Python code generator "generate_source" section that handles
code generation to "free" inherited objects needs to generate
DISPATCH_FREE calls for all extended_by objects.

12 years agoS390: Do not generate a default USB controller
Viktor Mihajlovski [Mon, 29 Apr 2013 16:11:29 +0000 (18:11 +0200)] 
S390: Do not generate a default USB controller

For s390 we don't want to have a default USB device generated even
if QEMU is silently tolerating -usb on the command line. This may change
in the future.
Another reason to avoid the USB controller is that it implies a PCI
bus which might cause a regression at some later point in time.
The following change will set the USB controller model to 'none'
unless a model or address has been specified, which can be the case
if a legacy definition is loaded or the XML writer knows what
she/he's doing.
Requiring the user to explicitly disable USB on systems not supporting
it seems cumbersome.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agoS390: Mention changed USB behavior
Viktor Mihajlovski [Mon, 29 Apr 2013 16:11:28 +0000 (18:11 +0200)] 
S390: Mention changed USB behavior

Add a line saying that no USB controllers are generated by default
on s390.

12 years agoqemu: fix failure to start with spice graphics and no tls
Laine Stump [Tue, 30 Apr 2013 18:04:59 +0000 (14:04 -0400)] 
qemu: fix failure to start with spice graphics and no tls

Commit eca3fdf inadvertantly caused a failure to start for any domain
with the following in its config:

    <graphics type='spice' autoport='yes'/>

The problem is that when tlsPort == 0 and defaultMode == "any" (which
is the default for defaultMode), this would be flagged in the code as
"needTLSPort", and if there was then no spice tls config, the new
error+fail would happen.

This patch checks for the case of defaultMode == "any", and in that
case simply doesn't allocate a TLS port (since that's probably not
what the user wanted, and it would have failed later anyway.). It does
leave the error in place for cases when the user specifically asked to
use tls in one way or another, though.

12 years agobuild: fix cygwin build in virnetdev
Eric Blake [Tue, 30 Apr 2013 19:42:59 +0000 (13:42 -0600)] 
build: fix cygwin build in virnetdev

On cygwin, compilation failed because SIOCSIFHWADDR is undefined.

* src/util/virnetdev.c (virNetDevSetMAC): Cygwin can query but not
set mac address.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agoNeed to call virFreeError after virSaveLastError
John Ferlan [Tue, 30 Apr 2013 17:39:28 +0000 (13:39 -0400)] 
Need to call virFreeError after virSaveLastError

12 years agoResolve valgrind error
John Ferlan [Mon, 29 Apr 2013 11:52:49 +0000 (07:52 -0400)] 
Resolve valgrind error

As a result of commit id '19c345f2', 'make -C tests valgrind' has the
following for qemuxml2argvtest:

==22482== 197 (80 direct, 117 indirect) bytes in 1 blocks are definitely lost in loss record 101 of 120
==22482==    at 0x4A06B6F: calloc (vg_replace_malloc.c:593)
==22482==    by 0x4C6F301: virAlloc (viralloc.c:124)
==22482==    by 0x4C840FC: virSaveLastError (virerror.c:308)
==22482==    by 0x431882: qemuBuildCommandLine (qemu_command.c:8204)
==22482==    by 0x41E8F0: testCompareXMLToArgvHelper (qemuxml2argvtest.c:155)
==22482==    by 0x41FE9F: virtTestRun (testutils.c:157)
==22482==    by 0x419DEB: mymain (qemuxml2argvtest.c:654)
==22482==    by 0x4204DA: virtTestMain (testutils.c:719)
==22482==    by 0x39D0821A04: (below main) (libc-start.c:225)
==22482==

12 years agolibvirt-guests: status: return non-zero when stopped
Ján Tomko [Tue, 30 Apr 2013 11:44:33 +0000 (13:44 +0200)] 
libvirt-guests: status: return non-zero when stopped

Return 3 when the service is stopped, whether there
are saved guests or not, to conform with the LSB standards:

http://refspecs.linuxbase.org/LSB_3.1.1/LSB-Core-generic/LSB-Core-generic/iniscrptact.html

12 years agoportability: handle ifreq differences in virnetdev
Roman Bogorodskiy [Sat, 27 Apr 2013 15:50:19 +0000 (19:50 +0400)] 
portability: handle ifreq differences in virnetdev

FreeBSD (and maybe other BSDs) have different member
names in struct ifreq when compared to Linux, such as:

 - uses ifr_data instead of ifr_newname for setting
   interface names
 - uses ifr_index instead of ifr_ifindex for interface
   index

Also, add a check for SIOCGIFHWADDR for virNetDevValidateConfig().

Use AF_LOCAL if AF_PACKET is not available.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agosecurity driver: eliminate memory leaks in failure paths
Laine Stump [Tue, 30 Apr 2013 14:59:29 +0000 (10:59 -0400)] 
security driver: eliminate memory leaks in failure paths

If virPCIDeviceGetVFIOGroupDev() failed,
virSecurity*(Set|Restore)HostdevLabel() would fail to free a
virPCIDevice that had been allocated.

These leaks were all introduced (by me) very recently, in commit
f0bd70a.

12 years agolibxl: Fix double-dispose of libxl domain config
Jim Fehlig [Mon, 29 Apr 2013 23:04:55 +0000 (17:04 -0600)] 
libxl: Fix double-dispose of libxl domain config

libxlBuildDomainConfig() was disposing the libxl_domain_config object
on error, only to have it disposed again by libxlBuildDomainConfig()'s
caller, which resulted in a segfault.  Leave disposing of the config
object to it's owner.

12 years agoesx: Support virtualHW version 9
Martin Kletzander [Tue, 30 Apr 2013 12:46:54 +0000 (14:46 +0200)] 
esx: Support virtualHW version 9

We already support ESX 5.1, but virtualHW version used by such
hypervisor [1] wasn't taken into account.

[1] http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&externalId=1003746

12 years agoFix typo in augeas comment
Martin Kletzander [Tue, 30 Apr 2013 14:28:20 +0000 (16:28 +0200)] 
Fix typo in augeas comment

12 years agobuild: mark conditionally unused variables
Eric Blake [Tue, 30 Apr 2013 14:21:26 +0000 (08:21 -0600)] 
build: mark conditionally unused variables

These fixes solve a compilation failure on FreeBSD:

util/virnetdevtap.c: In function 'virNetDevTapGetName':
util/virnetdevtap.c:56: warning: unused parameter 'tapfd' [-Wunused-parameter]
util/virnetdevtap.c:56: warning: unused parameter 'ifname' [-Wunused-parameter]

* src/util/virnetdevtap.c (virNetDevTapGetName): Add attributes
when TUNGETIFF is not present.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agovirsh: clarify vol-{down,up}load description
Ján Tomko [Tue, 30 Apr 2013 12:19:49 +0000 (14:19 +0200)] 
virsh: clarify vol-{down,up}load description

Mention file/volume contents instead of just 'file'/'volume'.

Also change Download->download in vol-download help,
to be consistent with other volume commands.

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

12 years agoqemu: report an error if memballoon has wrong address type
Ján Tomko [Mon, 29 Apr 2013 18:01:19 +0000 (20:01 +0200)] 
qemu: report an error if memballoon has wrong address type

qemuBuildMemballoonDevStr returns NULL if memballoon doesn't have
the right address type, but it doesn't report an error, leading to:
error: An error occurred, but the cause is unknown

Report a helpful error message instead, e.g.:
error: XML error: memballoon unsupported with address type 'usb'

12 years agoqemu: assign addresses when converting xml to native
Ján Tomko [Mon, 29 Apr 2013 17:54:07 +0000 (19:54 +0200)] 
qemu: assign addresses when converting xml to native

This adds addresses to domxml-to-native output and chooses
the correct virtio devices for ccw and s390 machines.

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

12 years agovirsh: fix incorrect argument errors for long options
Ján Tomko [Mon, 29 Apr 2013 17:12:17 +0000 (19:12 +0200)] 
virsh: fix incorrect argument errors for long options

For long options, print:
* the option as specified by the user if it's unknown
* the canonical long option if its argument is not
  a number (and should be)

And for missing arguments, print both the short and
the long option name.
(Doing only one of those would require either parsing
argv ourselves or let getopt print the errors, since
we can't tell long and short options apart by optopt
or longindex)

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

Unsupported long option:

$ virsh --pm
Before:
error: unsupported option '-
After:
error: unsupported option '--pm'. See --help.

Missing parameter:

$ virsh --deb
Before:
error: option '-d' requires an argument
After:
error: option '-d'/'--debug' requires an argument

$ virsh -rd
Before:
error: option '-d' requires an argument
After:
error: option '-d'/'--debug' requires an argument

Non-numeric parameter:

$ virsh --deb duck
Before:
error: option -d takes a numeric argument
After:
error: option --debug takes a numeric argument

12 years agoqemu: Error out if spice port autoallocation is requested, but disabled
Peter Krempa [Mon, 29 Apr 2013 11:41:27 +0000 (13:41 +0200)] 
qemu: Error out if spice port autoallocation is requested, but disabled

When a user requests auto-allocation of the spice TLS port but spice TLS
is disabled in qemu.conf, we start the machine and let qemu fail instead
of erroring out sooner.

Add an error message so that this doesn't happen.

12 years agonetwork: Don't remove transient network if creating of config file fails
Peter Krempa [Mon, 22 Apr 2013 09:10:39 +0000 (11:10 +0200)] 
network: Don't remove transient network if creating of config file fails

On the off-chance that creation of persistent configuration file would
fail when defining a network that is already started as transient, the
code would remove the transient data structure and thus the network.

This patch changes the code so that in such case, the network is again
marked as transient and left behind.

12 years agoqemu: put usb cgroup setup in common function
Laine Stump [Mon, 29 Apr 2013 20:19:19 +0000 (16:19 -0400)] 
qemu: put usb cgroup setup in common function

The USB-specific cgroup setup had been inserted inline in
qemuDomainAttachHostUsbDevice and qemuSetupCgroup, but now there is a
common cgroup setup function called for all hostdevs, so it makes sens
to put the usb-specific setup there and just rely on that function
being called.

The one thing I'm uncertain of here (and a reason for not pushing
until after release) is that previously hostdev->missing was checked
only when starting a domain (and cgroup setup for the device skipped
if missing was true), but with this consolidation, it is now checked
in the case of hotplug as well. I don't know if this will have any
practical effect (does it make sense to hotplug a "missing" usb
device?)

12 years agoqemu: add vfio devices to cgroup ACL when appropriate
Laine Stump [Mon, 29 Apr 2013 17:15:26 +0000 (13:15 -0400)] 
qemu: add vfio devices to cgroup ACL when appropriate

PCIO device assignment using VFIO requires read/write access by the
qemu process to /dev/vfio/vfio, and /dev/vfio/nn, where "nn" is the
VFIO group number that the assigned device belongs to (and can be
found with the function virPCIDeviceGetVFIOGroupDev)

/dev/vfio/vfio can be accessible to any guest without danger
(according to vfio developers), so it is added to the static ACL.

The group device must be dynamically added to the cgroup ACL for each
vfio hostdev in two places:

1) for any devices in the persistent config when the domain is started
   (done during qemuSetupCgroup())

2) at device attach time for any hotplug devices (done in
   qemuDomainAttachHostDevice)

The group device must be removed from the ACL when a device it
"hot-unplugged" (in qemuDomainDetachHostDevice())

Note that USB devices are already doing their own cgroup setup and
teardown in the hostdev-usb specific function. I chose to make the new
functions generic and call them in a common location though. We can
then move the USB-specific code (which is duplicated in two locations)
to this single location. I'll be posting a followup patch to do that.

12 years agoqemu: honor allowDiskFormatProbing when parsing command line
Ján Tomko [Mon, 29 Apr 2013 13:42:45 +0000 (15:42 +0200)] 
qemu: honor allowDiskFormatProbing when parsing command line

My commit 024e9af broke this.

12 years agoconf: add missing error on OOM
Ján Tomko [Fri, 26 Apr 2013 16:12:58 +0000 (18:12 +0200)] 
conf: add missing error on OOM

I removed it in 5c3d5b2 by accident.

12 years agoqemu: prevent invalid reads in qemuAssignDevicePCISlots
Ján Tomko [Fri, 26 Apr 2013 16:05:46 +0000 (18:05 +0200)] 
qemu: prevent invalid reads in qemuAssignDevicePCISlots

Don't reserve slot 2 for video if the machine has no PCI buses.
Error out when the user specifies a video device without
a PCI address when there are no PCI buses.

(This wouldn't work on a machine with no PCI bus anyway since
we do add PCI addresses for video devices to the command line)

12 years agoqemu: don't always reserve PCI addresses for implicit controllers
Ján Tomko [Fri, 26 Apr 2013 15:50:36 +0000 (17:50 +0200)] 
qemu: don't always reserve PCI addresses for implicit controllers

In the past we automatically added a USB controller and assigned
it a PCI address (0:0:1.2) even on machines without a PCI bus.
This didn't break machines with no PCI bus  because the command
line for it is just '-usb', with no mention of the PCI bus.

The implicit IDE controller (reserved address 0:0:1.1) has
no command line at all.

Commit b33eb0dc removed the ability to reserve PCI addresses
on machines without a PCI bus. This made them stop working,
since there would always be the implicit USB controller.

Skip the reservation of addresses for these controllers when
there is no PCI bus, instead of failing.

12 years agoconf: remove extraneous _TYPE from driver backend enums
Laine Stump [Fri, 26 Apr 2013 20:44:05 +0000 (16:44 -0400)] 
conf: remove extraneous _TYPE from driver backend enums

This isn't strictly speaking a bugfix, but I realized I'd gotten a bit
too verbose when I chose the names for
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_*. This shortens them all a bit.

12 years agonetwork: support <driver name='vfio'/> in network definitions
Laine Stump [Fri, 26 Apr 2013 20:23:27 +0000 (16:23 -0400)] 
network: support <driver name='vfio'/> in network definitions

I remembered to document this bit, but somehow forgot to implement it.

This adds <driver name='kvm|vfio'/> as a subelement to the <forward>
element of a network (this puts it parallel to the match between
mode='hostdev' attribute in a network and type='hostdev' in an
<interface>).

Since it's already documented, only the parser, formatter, backend
driver recognition (it just translates/moves the flag into the
<interface> at the appropriate time), and a test case were needed.

(I used a separate enum for the values both because the original is
defined in domain_conf.h, which is unavailable from network_conf.h,
and because in the future it's possible that we may want to support
other non-hostdev oriented driver names in the network parser; this
makes sure that one can be expanded without the other).

12 years agoqemu: launch bridge helper from libvirtd
Paolo Bonzini [Sat, 20 Apr 2013 09:11:25 +0000 (11:11 +0200)] 
qemu: launch bridge helper from libvirtd

<source type='bridge'> uses a helper application to do the necessary
TUN/TAP setup to use an existing network bridge, thus letting
unprivileged users use TUN/TAP interfaces.

However, libvirt should be preventing QEMU from running any setuid
programs at all, which would include this helper program.  From
a security POV, any setuid helper needs to be run by libvirtd itself,
not QEMU.

This is what this patch does.  libvirt now invokes the setuid helper,
gets the TAP fd and then passes it to QEMU in the normal manner.
The path to the helper is specified in qemu.conf.

As a small advantage, this adds a <target dev='tap0'/> element to the
XML of an active domain using <interface type='bridge'>.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12 years agovirnetdevtap: add virNetDevTapGetName
Paolo Bonzini [Sat, 20 Apr 2013 09:11:24 +0000 (11:11 +0200)] 
virnetdevtap: add virNetDevTapGetName

This will be used on a tap file descriptor returned by the bridge helper
to populate the <target> element, because the helper does not provide
the interface name.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
12 years agoqemu: don't assign a PCI address to 'none' USB controller
Ján Tomko [Fri, 26 Apr 2013 17:52:43 +0000 (19:52 +0200)] 
qemu: don't assign a PCI address to 'none' USB controller

Adjust the usb-none test, since it gives the memballoon a lower PCI slot now.
Add a test for 'none' controller on s390, which doesn't have PCI buses.

12 years agofix segfault during virsh save in pv guest
Bamvor Jian Zhang [Fri, 26 Apr 2013 14:53:42 +0000 (22:53 +0800)] 
fix segfault during virsh save in pv guest

this patch fix the wrong sequence for fd and timeout register. the sequence
was right in dfa1e1dd for fd register, but it changed in e0622ca2.
in this patch, set priv, xl_priv in info and increase info->priv ref count
before virEventAddHandle. if do this after virEventAddHandle, the fd
callback or fd deregister maybe got the empty priv, xl_priv or wrong ref
count.

after apply this patch, test more than 100 rounds passed compare to fail
within 3 rounds without this patch. each round includes define -> start ->
destroy -> create -> suspend -> resume -> reboot -> shutdown -> save ->
resotre -> dump -> destroy -> create -> setmem -> setvcpus -> destroy.

Signed-off-by: Bamvor Jian Zhang <bjzhang@suse.com>
12 years agoqemu: set qemu process' RLIMIT_MEMLOCK when VFIO is used
Laine Stump [Thu, 25 Apr 2013 16:45:55 +0000 (12:45 -0400)] 
qemu: set qemu process' RLIMIT_MEMLOCK when VFIO is used

VFIO requires all of the guest's memory and IO space to be lockable in
RAM. The domain's max_balloon is the maximum amount of memory the
domain can have (in KiB). We add a generous 1GiB to that for IO space
(still much better than KVM device assignment, where the KVM module
actually *ignores* the process limits and locks everything anyway),
and convert from KiB to bytes.

In the case of hotplug, we are changing the limit for the already
existing qemu process (prlimit() is used under the hood), and for
regular commandline additions of vfio devices, we schedule a call to
setrlimit() that will happen after the qemu process is forked.

12 years agoqemu: use new virCommandSetMax(Processes|Files)
Laine Stump [Thu, 25 Apr 2013 16:16:25 +0000 (12:16 -0400)] 
qemu: use new virCommandSetMax(Processes|Files)

These were previously being set in a custom hook function, but now
that virCommand directly supports setting them, we can eliminate that
part of the hook and call the APIs directly.

12 years agoutil: new virCommandSetMax(MemLock|Processes|Files)
Laine Stump [Thu, 25 Apr 2013 16:10:10 +0000 (12:10 -0400)] 
util: new virCommandSetMax(MemLock|Processes|Files)

This patch adds two sets of functions:

1) lower level virProcessSet*() functions that will immediately set
the RLIMIT_MEMLOCK. RLIMIT_NPROC, or RLIMIT_NOFILE of either the
current process (using setrlimit()) or any other process (using
prlimit()). "current process" is indicated by passing a 0 for pid.

2) functions for virCommand* that will setup a virCommand object to
set those limits at a later time just after it has forked a new
process, but before it execs the new program.

configure.ac has prlimit and setrlimit added to the list of functions
to check for, and the low level functions log an "unsupported" error)
on platforms that don't support those functions.

12 years agoDo proper escaping of cgroup resource partitions
Daniel P. Berrange [Fri, 26 Apr 2013 09:50:24 +0000 (10:50 +0100)] 
Do proper escaping of cgroup resource partitions

If a user cgroup name begins with "cgroup.", "_" or with any of
the controllers from /proc/cgroups followed by a dot, then they
need to be prefixed with a single underscore. eg if there is
an object "cpu.service", then this would end up as "_cpu.service"
in the cgroup filesystem tree, however, "waldo.service" would
stay "waldo.service", at least as long as nobody comes up with
a cgroup controller called "waldo".

Since we require a '.XXXX' suffix on all partitions, there is
no scope for clashing with the kernel 'tasks' and 'release_agent'
files.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoEnsure all cgroup partitions have a suffix of ".partition"
Daniel P. Berrange [Fri, 26 Apr 2013 09:23:51 +0000 (10:23 +0100)] 
Ensure all cgroup partitions have a suffix of ".partition"

If the partition named passed in the XML does not already have
a suffix, ensure it gets a '.partition' added to each component.
The exceptions are /machine, /user and /system which do not need
to have a suffix, since they are fixed partitions at the top
level.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoChange VM cgroup suffix from '{lxc,qemu}.libvirt' to 'libvirt-{lxc,qemu}'
Daniel P. Berrange [Fri, 26 Apr 2013 08:52:47 +0000 (09:52 +0100)] 
Change VM cgroup suffix from '{lxc,qemu}.libvirt' to 'libvirt-{lxc,qemu}'

Recently we changed to create VM cgroups with the naming pattern
$VMNAME.$DRIVER.libvirt. Following discussions with the systemd
community it was decided that only having a single '.' in the
names is preferrable. So this changes the naming scheme to be
$VMNAME.libvirt-$DRIVER. eg for LXC 'mycontainer.libvirt-lxc' or
for KVM 'myvm.libvirt-qemu'.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agotest: Add JSON test for query-tpm-types
Stefan Berger [Fri, 26 Apr 2013 11:13:05 +0000 (07:13 -0400)] 
test: Add JSON test for query-tpm-types

Add a test case for query-tpm-models QMP command.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
12 years agovirsh: suppress aliases in group help
Eric Blake [Fri, 26 Apr 2013 10:20:29 +0000 (04:20 -0600)] 
virsh: suppress aliases in group help

'virsh help | grep nodedev-det' shows only nodedev-detach, but
'virsh help nodedev | grep nodedev-det' also shows the old alias
nodedev-dettach that we intentionally hid in commit af3f9aab.

See also commit 787f4fe and this bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=956966

* tools/virsh.c (vshCmdGrpHelp): Copy suppression of vshCmdHelp.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agosecurity: update hostdev labelling functions for VFIO v1.0.5-rc1
Laine Stump [Thu, 25 Apr 2013 10:37:21 +0000 (06:37 -0400)] 
security: update hostdev labelling functions for VFIO

Legacy kvm style pci device assignment requires changes to the
labelling of several sysfs files for each device, but for vfio device
assignment, the only thing that needs to be relabelled/chowned is the
"group" device for the group that contains the device to be assigned.

12 years agoutil: new function virPCIDeviceGetVFIOGroupDev
Laine Stump [Thu, 25 Apr 2013 10:34:43 +0000 (06:34 -0400)] 
util: new function virPCIDeviceGetVFIOGroupDev

Given a virPCIDevice, this function returns the path for the device
that controls the vfio group the device belongs to,
e.g. "/dev/vfio/15".

12 years agovirsh: use new virNodeDeviceDetachFlags
Laine Stump [Wed, 24 Apr 2013 18:22:36 +0000 (14:22 -0400)] 
virsh: use new virNodeDeviceDetachFlags

The virsh nodedev-detach command has a new --driver option. If it's
given virsh will attempt to use the new virNodeDeviceDetachFlags API
instead of virNodeDeviceDettach. Validation of the driver name string
is left to the hypervisor (qemu accepts "kvm" or "vfio". The only
other hypervisor that implements these functions is xen, and it only
accepts NULL).

12 years agoxen: implement virNodeDeviceDetachFlags backend
Laine Stump [Wed, 24 Apr 2013 18:06:42 +0000 (14:06 -0400)] 
xen: implement virNodeDeviceDetachFlags backend

This was the only hypervisor driver other than qemu that implemented
virNodeDeviceDettach. It doesn't currently support multiple pci device
assignment driver backends, but it is simple to plug in this new API,
which will make it easier for Xen people to fill it in later when they
decide to support VFIO (or whatever other) device assignment. Also it
means that management applications will have the same API available to
them for both hypervisors on any given version of libvirt.

The only acceptable value for driverName in this case is NULL, since
there is no alternate, and I'm not willing to pick a name for the
default driver used by Xen.

12 years agoqemu: implement virNodeDeviceDetachFlags backend
Laine Stump [Wed, 24 Apr 2013 18:03:39 +0000 (14:03 -0400)] 
qemu: implement virNodeDeviceDetachFlags backend

The differences from virNodeDeviceDettach are very minor:

1) Check that the flags are 0.

2) Set the virPCIDevice's stubDriver according to the driverName that
   is passed in.

3) Call virPCIDeviceDetach with a NULL stubDriver, indicating it
   should get the name of the stub driver from the virPCIDevice
   object.

12 years agohypervisor api: implement RPC calls for virNodeDeviceDetachFlags
Laine Stump [Wed, 24 Apr 2013 17:42:04 +0000 (13:42 -0400)] 
hypervisor api: implement RPC calls for virNodeDeviceDetachFlags

This requires a custom function for remoteNodeDeviceDetachFlags,
because it is named *NodeDevice, but it goes through the hypervisor
driver rather than nodedevice driver, and so it uses privateData
instead of nodeDevicePrivateData. (It has to go through the hypervisor
driver, because that is the driver that knows about the backend drivers
that will perform the pci device assignment).

12 years agohypervisor api: new virNodeDeviceDetachFlags
Laine Stump [Wed, 24 Apr 2013 16:56:10 +0000 (12:56 -0400)] 
hypervisor api: new virNodeDeviceDetachFlags

The existing virNodeDeviceDettach() assumes that there is only a
single PCI device assignment backend driver appropriate for any
hypervisor. This is no longer true, as the qemu driver is getting
support for PCI device assignment via VFIO. The new API
virNodeDeviceDetachFlags adds a driverName arg that should be set to
the exact same string set in a domain <hostdev>'s <driver name='x'/>
element (i.e. "vfio", "kvm", or NULL for default). It also adds a
flags arg for good measure (and because it's possible we may need it
when we start dealing with VFIO's "device groups").

12 years agoqemu: bind/unbind stub driver according to config <driver name='x'/>
Laine Stump [Tue, 23 Apr 2013 18:53:36 +0000 (14:53 -0400)] 
qemu: bind/unbind stub driver according to config <driver name='x'/>

If the config for a device has specified <driver name='vfio'/>,
"backend" in the pci part of the hostdev object will be set to
..._VFIO. In this case, when creating a virPCIDevice set the
stubDriver to "vfio-pci", otherwise set it to "pci-stub". We will rely
on the lower levels to report an error if the vfio driver isn't
loaded.

The detach/attach functions in virpci.c will pay attention to the
stubDriver setting in the device, and bind/unbind the appropriate
driver when preparing hostdevs for the domain.

Note that we don't yet attempt to do anything to mark active any other
devices in the same vfio "group" as a single device that is being
marked active. We do need to do that, but in order to get basic VFIO
functionality testing sooner rather than later, initially we'll just
live with more cryptic errors when someone tries to do that.

12 years agopci: keep a stubDriver in each virPCIDevice
Laine Stump [Tue, 23 Apr 2013 18:50:15 +0000 (14:50 -0400)] 
pci: keep a stubDriver in each virPCIDevice

This can be set when the virPCIDevice is created and placed on a list,
then used later when traversing the list to determine which stub
driver to bind/unbind for managed devices.

The existing Detach and Attach functions' signatures haven't been
changed (they still accept a stub driver name in the arg list), but if
the arg list has NULL for stub driver and one is available in the
device's object, that will be used. (we may later deprecate and remove
the arg from those functions).

12 years agoqemu: use vfio-pci on commandline when appropriate
Laine Stump [Thu, 25 Apr 2013 11:58:37 +0000 (07:58 -0400)] 
qemu: use vfio-pci on commandline when appropriate

The device option for vfio-pci is nearly identical to that for
pci-assign - only the configfd parameter isn't supported (or needed).

Checking for presence of the bootindex parameter is done separately
from constructing the commandline, similar to how it is done for
pci-assign.

This patch contains tests to check for proper commandline
construction. It also includes tests for parser-formatter-parser
roundtrips (xml2xml), because those tests use the same data files, and
would have failed had they been included before now.

qemu: xml/args tests for VFIO hostdev and <interface type='hostdev'/>

These should be squashed in with the patch that adds commandline
handling of vfio (they would fail at any earlier time).

12 years agoconf: formatter/parser/RNG/docs for hostdev <driver name='kvm|vfio'/>
Laine Stump [Fri, 15 Mar 2013 19:15:14 +0000 (15:15 -0400)] 
conf: formatter/parser/RNG/docs for hostdev <driver name='kvm|vfio'/>

A domain's <interface> or <hostdev>, as well as a <network>'s
<forward>, can now have an optional <driver name='kvm|vfio'/>
element. As of this patch, there is no functionality behind this new
knob - this patch adds support to the domain and network
formatter/parser, and to the RNG and documentation.

When the backend is added, legacy KVM PCI device assignment will
continue to be used when no driver name is specified (or if <driver
name='kvm'/> is specified), but if driver name is 'vfio', the new UEFI
Secure Boot compatible VFIO device assignment will be used.

Note that the parser doesn't automatically insert the current default
value of this setting. This is done on purpose because the two
possibilities are functionally equivalent from the guest's point of
view, and we want to be able to automatically start using vfio as the
default (even for existing domains) at some time in the future. This
is similar to what was done with the "vhost" driver option in
<interface>.

12 years agoconf: put hostdev pci address in a struct
Laine Stump [Mon, 18 Mar 2013 19:56:12 +0000 (15:56 -0400)] 
conf: put hostdev pci address in a struct

There will soon be other items related to pci hostdevs that need to be
in the same part of the hostdevsubsys union as the pci address (which
is currently a single member called "pci". This patch replaces the
single member named pci with a struct named pci that contains a single
member named "addr".

12 years agoqemu: detect vfio-pci device and its bootindex parameter
Laine Stump [Wed, 17 Apr 2013 18:16:28 +0000 (14:16 -0400)] 
qemu: detect vfio-pci device and its bootindex parameter

QEMU_CAPS_DEVICE_VFIO_PCI is set if the device named "vfio-pci" is
supported in the qemu binary.

QEMU_CAPS_VFIO_PCI_BOOTINDEX is set if the vfio-pci device supports
the "bootindex" parameter;  for some reason, the bootindex parameter
wasn't included in early versions of vfio support (qemu 1.4) so we
have to check for it separately from vfio itself.

12 years agobuild: avoid unsafe functions in libgen.h
Eric Blake [Thu, 25 Apr 2013 20:24:42 +0000 (14:24 -0600)] 
build: avoid unsafe functions in libgen.h

POSIX says that both basename() and dirname() may return static
storage (aka they need not be thread-safe); and that they may but
not must modify their input argument.  Furthermore, <libgen.h>
is not available on all platforms.  For these reasons, you should
never use these functions in a multi-threaded library.

Gnulib instead recommends a way to avoid the portability nightmare:
gnulib's "dirname.h" provides useful thread-safe counterparts.  The
obvious dir_name() and base_name() are GPL (because they malloc(),
but call exit() on failure) so we can't use them; but the LGPL
variants mdir_name() (malloc's or returns NULL) and last_component
(always points into the incoming string without modifying it,
differing from basename semantics only on corner cases like the
empty string that we shouldn't be hitting in the first place) are
already in use in libvirt.  This finishes the swap over to the safe
functions.

* cfg.mk (sc_prohibit_libgen): New rule.
* src/util/vircgroup.c: Fix offenders.
* src/parallels/parallels_storage.c (parallelsPoolAddByDomain):
Likewise.
* src/parallels/parallels_network.c (parallelsGetBridgedNetInfo):
Likewise.
* src/node_device/node_device_udev.c (udevProcessSCSIHost)
(udevProcessSCSIDevice): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskDeleteVol): Likewise.
* src/util/virpci.c (virPCIGetDeviceAddressFromSysfsLink):
Likewise.
* src/util/virstoragefile.h (_virStorageFileMetadata): Avoid false
positive.

Signed-off-by: Eric Blake <eblake@redhat.com>