Commit Graph

18144 Commits

Author SHA1 Message Date
Michal Privoznik
ca1ac6643e qemuDomainAttachNetDevice: Avoid @originalError leak
Coverity identified that this variable might be leaked. And it's
right. If an error occurred and we have to roll back the control
jumps to try_remove label where we save the current error (see
0e82fa4c34 for more info). However, inside the code a jump onto
other label is possible thus leaking the error object.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-14 10:58:58 +01:00
Erik Skultety
e555ed6f7b admin: Use the newly introduced close callback handling helpers
Use the newly introduced close callback helpers to make the code look just a
bit cleaner and more importantly, to fix the following memleak regarding a
dangling virAdmConnect object reference caused by assigning NULL to the close
callback data once the catch-disconnect routine used the callback followed
by a comparison of NULL to the originally defined close callback (which at that
moment had already been NULL'd by remoteAdminClientCloseFunc) in
virAdmConnectCloseCallbackUnregister.

717 (88 direct, 629 indirect) bytes in 1 blocks are definitely lost record
 110 of 141
    at 0x4C2A988: calloc (vg_replace_malloc.c:711)
    by 0x530696F: virAllocVar (viralloc.c:560)
    by 0x53689E6: virObjectNew (virobject.c:193)
    by 0x5368B5E: virObjectLockableNew (virobject.c:219)
    by 0x4E3E7EE: virAdmConnectNew (datatypes.c:900)
    by 0x4E398BB: virAdmConnectOpen (libvirt-admin.c:220)
    by 0x10D3E3: vshAdmConnect (virt-admin.c:161)
    by 0x10D624: vshAdmReconnect (virt-admin.c:215)
    by 0x10DB0A: cmdConnect (virt-admin.c:353)
    by 0x11288F: vshCommandRun (vsh.c:1313)
    by 0x10FDB6: main (virt-admin.c:1439)

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

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-11-14 10:18:56 +01:00
Erik Skultety
7cea74a3b2 datatypes: Introduce some admin-related close callback handling helpers
Well, there were three different spots where closeCallback->freeCallback was
called, not looking the same --> potential for bugs - and there indeed is a bug
with refcounting of the @conn object. So this patch partially follows the path
set by commit 24dbb69f by introducing some close callback helpers both to
replace all the spots where we call clean the close callback data with a
dedicated function and to be able to fix the refcounting bug causing a memleak.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-11-14 10:18:56 +01:00
Erik Skultety
d46a1e5d45 admin: Remove unnecessary @conn object locking
The only place we change the @conn object is actually virAdmConnectOpen
routine, thus at the moment we don't really need to lock it, given the fact that
what we're trying to do here is to change the closeCallback object which is a
lockable object itself, so that should be enough to avoid races.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
2016-11-14 10:18:56 +01:00
Eric Farman
85b0721095 Cleanup switch statements on the hostdev subsystem type
As was suggested in an earlier review comment[1], we can
catch some additional code points by cleaning up how we use the
hostdev subsystem type in some switch statements.

[1] End of https://www.redhat.com/archives/libvir-list/2016-September/msg00399.html

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-11-11 16:58:56 -05:00
Peter Krempa
b7798a07f9 qemu: Generate memory device aliases according to slot number
The memory device alias needs to be treated as machine ABI as qemu is
using it in the migration stream for section labels. To simplify this
generate the alias from the slot number unless an existing broken
configuration is detected.

With this patch the aliases are predictable and even certain
configurations which would not be migratable previously are fixed.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1359135
2016-11-10 17:36:55 +01:00
Peter Krempa
ce1ee02a25 qemu: Assign slots to memory devices prior to usage
As with other devices assign the slot number right away when adding the
device. This will make the slot numbers static as we do with other
addressing elements and it will ultimately simplify allocation of the
alias in a static way which does not break with qemu.
2016-11-10 17:36:55 +01:00
Peter Krempa
93d9ff3da0 qemu: process: detect if dimm aliases are broken on reconnect
Detect on reconnect to a running qemu VM whether the alias of a
hotpluggable memory device (dimm) does not match the dimm slot number
where it's connected to. This is necessary as qemu is actually
considering the alias as machine ABI used to connect the backend object
to the dimm device.

This will require us to keep them consistent so that we can reliably
restore them on migration. In some situations it was currently possible
to create a mismatched configuration and qemu would refuse to restore
the migration stream.

To avoid breaking existing VMs we'll need to keep the old algorithm
though.
2016-11-10 17:36:55 +01:00
Peter Krempa
810e9a8061 conf: Allow specifying only the slot number for hotpluggable memory
Simplify handling of the 'dimm' address element by allowing to specify
the slot number only. This will allow libvirt to allocate slot numbers
before starting qemu.
2016-11-10 17:36:55 +01:00
Daniel P. Berrange
b353cc3c3a xen: remove legacy hack for RHEL-5 Xen
We dropped support for RHEL-5 vintage Xen a while ago,
but forgot to remove some of the hacks for it.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-11-10 16:00:02 +00:00
John Ferlan
ec00fc016a qemu: Remove erroneously placed comments for numerical ordering
Commit id '74bbb8c2ec' seems to have mismerged a bit - adding 240 comments
out of place.  Just clean that up.
2016-11-10 10:55:31 -05:00
Michal Privoznik
21db4ab052 qemuDomainAttachNetDevice: Enable multiqueue for vhost-user
https://bugzilla.redhat.com/show_bug.cgi?id=1386976

We have everything ready. Actually the only limitation was our
check that denied hotplug of vhost-user.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-10 16:47:32 +01:00
Michal Privoznik
0e82fa4c34 qemuDomainAttachNetDevice: Don't overwrite error on rollback
If there is an error hotpluging a net device (for whatever
reason) a rollback operation is performed. However, whilst doing
so various helper functions that are called report errors on
their own. This results in the original error to be overwritten
and thus misleading the user.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-10 16:47:32 +01:00
Martin Kletzander
5672a265ce qemu: Make sure shmem memory is shared
Even though using /dev/shm/asdf as the backend, we still need to make
the mapping shared.  The original patch forgot to add that parameter.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-10 08:31:19 +01:00
Michal Privoznik
c5492563da lxc.conf: s/QEMU/LXC/
There's one copy paste error where a comment mentions QEMU
instead of LXC driver.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-09 18:56:15 +01:00
Pavel Hrdina
b2260f93e2 qemu_capabilities: fix build with for old gcc
../../src/qemu/qemu_capabilities.c:3757: error: declaration of
'basename' shadows a global declaration [-Wshadow]

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-11-09 18:43:39 +01:00
Martin Kletzander
cca34e38fd qemu: Fix double free when live-attaching shmem
Function qemuDomainAttachShmemDevice() steals the device data if the
hotplug was successful, but the condition checked for unsuccessful
execution otherwise.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-09 17:52:17 +01:00
Prasanna Kumar Kalever
e66603539b qemu: command: Add debug option for gluster volumes
Propagate the selected or default level to qemu if it's supported.

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

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2016-11-09 16:52:40 +01:00
Prasanna Kumar Kalever
a944bd9259 qemu: conf: add option for tuning debug logging level
This helps in selecting log level of the gluster gfapi, output to stderr.
The option is 'gluster_debug_level', can be tuned by editing
'/etc/libvirt/qemu.conf'

Debug levels ranges 0-9, with 9 being the most verbose, and 0
representing no debugging output.  The default is the same as it was
before, which is a level of 4.  The current logging levels defined in
the gluster gfapi are:

    0 - None
    1 - Emergency
    2 - Alert
    3 - Critical
    4 - Error
    5 - Warning
    6 - Notice
    7 - Info
    8 - Debug
    9 - Trace

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2016-11-09 16:52:40 +01:00
Prasanna Kumar Kalever
74bbb8c2ec qemu: capabilities: Detect support for gluster debug setting
Teach qemu driver to detect whether qemu supports specifying debug level
for gluster volumes.

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2016-11-09 16:52:40 +01:00
Peter Krempa
70c7025d3b qemu: capabilities: Add support for QMP schema introspection
Allow detecting capabilities according to the qemu QMP schema. This is
necessary as sometimes the availability of certain options depends on
the presence of a field in the schema.

This patch adds support for loading the QMP schema when detecting qemu
capabilities and adds a very simple query language to allow traversing
the schema and selecting a certain element from it.

The infrastructure in this patch uses a query path to set a specific
capability flag according to the availability of the given element in
the schema.
2016-11-09 16:51:54 +01:00
Peter Krempa
1683535a33 qemu: monitor: Add code to retrieve and store QMP schema data
Call 'query-qmp-schema' and store the returned types in a hash table
keyed by the 'name' field so that the capabilities code can traverse it.
2016-11-09 16:50:32 +01:00
Peter Krempa
edf33d1a65 util: json: add helper to iterate and steal members of json array
Simplifies cases where JSON array members need to be transferred to a
different structure.
2016-11-09 16:47:08 +01:00
Michal Privoznik
c6b6e737e8 test driver: Deny some operations on inactive domains
Some operations like reboot, save, coreDump, blockStats,
ifaceStats make sense iff domain is running. While it is
technically possible for our test driver to return success
regardless of domain state, we should copy constraints from
other drivers and thus deny these operations over inactive
domains.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-08 13:59:44 +01:00
John Ferlan
f694f3ff6b qemu: Only allow 'raw' format for scsi-block using virtio-scsi
https://bugzilla.redhat.com/show_bug.cgi?id=1379196

Add check in qemuCheckDiskConfig for an invalid combination
of using the 'scsi' bus for a block 'lun' device and any disk
source format other than 'raw'.
2016-11-08 06:32:12 -05:00
Daniel P. Berrange
bfdefc0f02 Add vbox 5.1 driver file
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-11-08 11:19:02 +00:00
Dawid Zamirski
4fd7194248 vbox: hookup the 5.1 C API to the unified driver 2016-11-08 09:56:33 +00:00
Dawid Zamirski
15209649bd vbox: add vbox 5.1 C API header file.
extracted from VirutalBox SDK and reindented with cppi.
2016-11-08 09:55:55 +00:00
Félix Bouliane
27a37f1670 test driver: error out when domain destroy twice
Fixes the behavior when destroying a domain more than once.
VIR_ERR_OPERATION_INVALID should be raised when destroying an
already destroyed domain.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-11-08 09:34:25 +01:00
Jiri Denemark
2d649f800f qemu: Fix build on RHEL-6
Commit c29e6d4805 cause build failure on RHEL-6:

../../src/qemu/qemu_capabilities.c: In function 'virQEMUCapsIsValid':
../../src/qemu/qemu_capabilities.c:4085: error: declaration of 'ctime'
shadows a global declaration [-Wshadow]
/usr/include/time.h:258: error: shadowed declaration is here [-Wshadow]

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-04 13:19:00 +01:00
Jiri Denemark
c29e6d4805 qemu: Unify cached caps validity checks
Let's keep all run time validation of cached QEMU capabilities in
virQEMUCapsIsValid and call it whenever we access the cache.
virQEMUCapsInitCached should keep only the checks which do not make
sense once the cache is loaded in memory.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-04 09:38:25 +01:00
Jiri Denemark
729aa67db7 qemu: Store loaded QEMU binary ctime in qemuCaps
virQEMUCapsLoadCache loads QEMU capabilities from a file, but strangely
enough it returns the loaded QEMU binary ctime in qemuctime parameter
instead of storing it in qemuCaps.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-04 09:25:58 +01:00
Pavel Timofeev
478ddedc12 loopback is not always just lo
On BSD family OSes (Free/Net/Open/DragonFlyBSD, Mac OS) and
 Solaris loopback interface is called 'lo0' instead of just 'lo'.
2016-11-02 18:10:39 +00:00
Martin Kletzander
fb2d0cc633 qemu: Add support for hot/cold-(un)plug of shmem devices
This is needed in order to migrate a domain with shmem devices as that
is not allowed to migrate.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-02 17:36:50 +01:00
Martin Kletzander
06524fd52c qemu: Support newer ivshmem device variants
QEMU added support for ivshmem-plain and ivshmem-doorbell.  Those are
reworked varians of legacy ivshmem that are compatible from the guest
POV, but not from host's POV and have sane specification and handling.

Details about the newer device type can be found in qemu's commit
5400c02b90bb:

  http://git.qemu.org/?p=qemu.git;a=commit;h=5400c02b90bb

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-02 17:36:17 +01:00
Martin Kletzander
acf0ec024a qemu: Save various defaults for shmem
We're keeping some things at default and that's not something we want to
do intentionally.  Let's save some sensible defaults upfront in order to
avoid having problems later.  The details for the defaults (of the newer
implementation) can be found in qemu's commit 5400c02b90bb:

  http://git.qemu.org/?p=qemu.git;a=commit;h=5400c02b90bb

Since we are merely saving the defaults it will not change the guest ABI
and thanks to the fact that we're doing it in the PostParse callback it
will not break the ABI stability checks.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-02 16:05:39 +01:00
Martin Kletzander
22d94ca46d qemu: Add capabilities for ivshmem-{plain,doorbell}
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-02 16:05:39 +01:00
Martin Kletzander
3c06aa7b30 conf, qemu: Add newer shmem models
The old ivshmem is deprecated in QEMU, so let's use the better
ivshmem-{plain,doorbell} variants instead.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-02 16:05:39 +01:00
Martin Kletzander
64530a9c66 conf, qemu: Add support for shmem model
Just the default one now, new ones will be added in following commits.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2016-11-02 16:05:39 +01:00
Jiri Denemark
fe1dd39087 qemu: Reset post-copy capability after migration
Unlike other migration capabilities, post-copy is also set on the
destination host which means it doesn't disappear once domain is
migrated. As a result of that other functionality which internally uses
migration to a file (virDomainManagedSave, virDomainSave,
virDomainCoreDump) may fail after migration because the post-copy
capability is still set.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-11-02 15:50:44 +01:00
Laine Stump
bbb333e481 network: fix endless loop when starting network with multiple IPs and no dhcp
commit 9065cfaa added the ability to disable DNS services for a
libvirt virtual network. If neither DNS nor DHCP is needed for a
network, then we don't need to start dnsmasq, so code was added to
check for this.

Unfortunately, it was written with a great lack of attention to detail
(I can say that, because I was the author), and the loop that checked
if DHCP is needed for the network would never end if the network had
multiple IP addresses and the first <ip> had no <dhcp> subelement
(which would have contained a <range> or <host> subelement, thus
requiring DHCP services).

This patch rewrites the check to be more compact and (more
importantly) finite.

This bug was present in release 2.2.0 and 2.3.0, so will need to be
backported to any relevant maintainence branches.

Reported here:
  https://www.redhat.com/archives/libvirt-users/2016-October/msg00032.html
  https://www.redhat.com/archives/libvirt-users/2016-October/msg00045.html
2016-10-28 13:59:17 -04:00
Chen Hanxiao
3b782ce572 qemu_driver: unlink new domain cfg file when rollback
If we failed to unlink old dom cfg file, we goto rollback.
But inside rollback, we fogot to unlink the new dom cfg file.
This patch fixes this issue.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-10-28 04:13:05 -07:00
Michal Privoznik
65462b2944 qemu: Minimalize global driver accesses
Whilst working on another issue, I've noticed that in some
functions we have a local @driver variable among with access to
global @qemu_driver variable. This makes no sense.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-10-27 18:48:39 -07:00
Nikolay Shirokovskiy
97338eaa7b qemu: Fix crash during qemuStateCleanup
Rather than waiting until we've free'd up all the resources, cause the
'workerPool' thread pool to flush as soon as possible during stateCleanup.
Otherwise, it's possible something waiting to run will SEGV such as is the
case during race conditions of simultaneous exiting libvirtd and qemu process.
Resolves the following crash:

[1] crash backtrace: (bt is shortened a bit):

0  0x00007ffff7282f2b in virClassIsDerivedFrom
   (klass=0xdeadbeef, parent=0x55555581d650) at util/virobject.c:169
1  0x00007ffff72835fd in virObjectIsClass
   (anyobj=0x7fffd024f580, klass=0x55555581d650) at util/virobject.c:365
2  0x00007ffff7283498 in virObjectLock
   (anyobj=0x7fffd024f580) at util/virobject.c:317
3  0x00007ffff722f0a3 in virCloseCallbacksUnset
   (closeCallbacks=0x7fffd024f580, vm=0x7fffd0194db0,
    cb=0x7fffdf1af765 <qemuProcessAutoDestroy>)
   at util/virclosecallbacks.c:164
4  0x00007fffdf1afa7b in qemuProcessAutoDestroyRemove
   (driver=0x7fffd00f3a60, vm=0x7fffd0194db0) at qemu/qemu_process.c:6365
5  0x00007fffdf1adff1 in qemuProcessStop
   (driver=0x7fffd00f3a60, vm=0x7fffd0194db0, reason=VIR_DOMAIN_SHUTOFF_CRASHED,
    asyncJob=QEMU_ASYNC_JOB_NONE, flags=0)
   at qemu/qemu_process.c:5877
6  0x00007fffdf1f711c in processMonitorEOFEvent
   (driver=0x7fffd00f3a60, vm=0x7fffd0194db0) at qemu/qemu_driver.c:4545
7  0x00007fffdf1f7313 in qemuProcessEventHandler
   (data=0x555555832710, opaque=0x7fffd00f3a60) at qemu/qemu_driver.c:4589
8  0x00007ffff72a84c4 in virThreadPoolWorker
   (opaque=0x555555805da0) at util/virthreadpool.c:167

Thread 1 (Thread 0x7ffff7fb1880 (LWP 494472)):
1  0x00007ffff72a7898 in virCondWait
   (c=0x7fffd01c21f8, m=0x7fffd01c21a0) at util/virthread.c:154
2  0x00007ffff72a8a22 in virThreadPoolFree
   (pool=0x7fffd01c2160) at util/virthreadpool.c:290
3  0x00007fffdf1edd44 in qemuStateCleanup ()
   at qemu/qemu_driver.c:1102
4  0x00007ffff736570a in virStateCleanup ()
   at libvirt.c:807
5  0x000055555556f991 in main (argc=1, argv=0x7fffffffe458) at libvirtd.c:1660
2016-10-27 15:58:52 -04:00
Maxim Nestratov
29594f2675 vz: remove Bridged network name and rename Routed
It's funny, but Routed network name was incorrect. We should use
host-routed instead.
2016-10-27 17:25:50 +03:00
Maxim Nestratov
0e094a4495 vz: support type=bridge network interface type correctly
Recently, libprlsdk got a separate flag PNA_BRIDGE corresponding to
type=bridge libvirt network interfaces. Let's use it and get rid of
all workarounds previously added to  support it.

Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
2016-10-27 17:25:50 +03:00
Chen Hanxiao
8b035c84d8 qemu: Forbid pinning vCPUs for TCG domain
We don't support cpu pinning for TCG domains because QEMU runs them in
one thread only.  But vcpupin command was able to set them, which
resulted in a failed startup, so make sure that doesn't happen.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2016-10-27 15:21:03 +02:00
Ján Tomko
dc67d00cd2 Recreate the USB address cache at reconnect
When starting a new domain, we allocate the USB addresses and keep
an address cache in the domain object's private data.

However this data is lost on libvirtd restart.

Also generate the address cache if all the addresses have been
specified, so that devices hotplugged after libvirtd restart
also get theirs assigned.

https://bugzilla.redhat.com/show_bug.cgi?id=1387666
2016-10-27 13:38:56 +02:00
Ján Tomko
244ebb8f2b Do not try to release virtio serial addresses
Return 0 instead of 1, so that qemuDomainAttachChrDevice does not
assume the address neeeds to be released on error.

No functional change, since qemuDomainReleaseDeviceAddress has been a noop
for virtio serial addresses since the address cache was removed
in commit 19a148b.
2016-10-27 11:16:42 +02:00
Ján Tomko
00c5386c86 Fix crash on usb-serial hotplug
For domains with no USB address cache, we should not attempt
to generate a USB address.

https://bugzilla.redhat.com/show_bug.cgi?id=1387665
2016-10-27 11:15:33 +02:00