]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
4 years agovirhostdev.c: virHostdevGetPCIHostDevice() now reports missing device
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:30 +0000 (09:54 -0300)]
virhostdev.c: virHostdevGetPCIHostDevice() now reports missing device

Gitlab issue #72 [1] reports that removing SR-IOVs VFs before
removing the devices from the running domains can have strange
consequences. QEMU might be able to hotunplug the device inside the
guest, but Libvirt will not be aware of that, and then the guest is
now inconsistent with the domain definition.

There's also the possibility of the VFs removal not succeeding
while the domain is running but then, as soon as the domain
is shutdown, all the VFs are removed. Libvirt can't handle
the removal of the PCI devices while trying to reattach the
hostdevs, and the Libvirt daemon can be left in an inconsistent
state (see [2]).

This patch starts to address the issue related in Gitlab #72, most
notably the issue described in [2]. When shutting down a domain
with SR-IOV hostdevs that got missing, virHostdevReAttachPCIDevices()
is failing the whole process and failing to reattach all the
PCI devices, including the ones that aren't related to the VFs that
went missing. Let's make it more resilient with host changes by
changing virHostdevGetPCIHostDevice() to return an exclusive error
code '-2' for this case. virHostdevGetPCIHostDeviceList() can then
tell when virHostdevGetPCIHostDevice() failed to find the PCI
device of a hostdev and continue to make the list of PCI devices.

virHostdevReAttachPCIDevices() will now be able to proceed reattaching
all other valid PCI devices, at least. The 'ghost hostdevs' will be
handled later on.

[1] https://gitlab.com/libvirt/libvirt/-/issues/72
[2] https://gitlab.com/libvirt/libvirt/-/issues/72#note_459032148

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirpci: introduce virPCIDeviceExists()
Daniel Henrique Barboza [Mon, 4 Jan 2021 12:54:29 +0000 (09:54 -0300)]
virpci: introduce virPCIDeviceExists()

We're going to add logic to handle the case where a previously
existing PCI device does not longer exist in the host.

The logic was copied from virPCIDeviceNew(), which verifies if a
PCI device exists in the host, returning NULL and throwing an
error if it doesn't. The NULL is used for other errors as well
(product/vendor id read errors, dev id overflow), meaning that we
can't re-use virPCIDeviceNew() for the purpose of detecting
if the device exists.

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoUse g_steal_pointer where possible
Kristina Hanicova [Tue, 23 Feb 2021 13:58:29 +0000 (14:58 +0100)]
Use g_steal_pointer where possible

Via coccinelle (not the handbag!)
spatches used:
@ rule1 @
identifier a, b;
symbol NULL;
@@

- b = a;
  ... when != a
- a = NULL;
+ b = g_steal_pointer(&a);

@@

- *b = a;
  ... when != a
- a = NULL;
+ *b = g_steal_pointer(&a);

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemuBackupJobTerminate: Don't calculate backup job stats if VM isn't active
Peter Krempa [Thu, 25 Feb 2021 12:33:39 +0000 (13:33 +0100)]
qemuBackupJobTerminate: Don't calculate backup job stats if VM isn't active

If the VM isn't active calculating the job stats doesn't make sense.
Additionally this prevents a crash of libvirtd if qemu terminates while
libvirt wasn't running:

Thread 28 "init-backup-tes" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffb9310640 (LWP 3201116)]
qemuDomainJobInfoUpdateTime (jobInfo=0x0) at ../../../libvirt/src/qemu/qemu_domainjob.c:275
275     if (!jobInfo->started)
(gdb) bt
 #0  qemuDomainJobInfoUpdateTime (jobInfo=0x0) at ../../../libvirt/src/qemu/qemu_domainjob.c:275
 #1  0x00007fffcba1a12d in qemuBackupJobTerminate (vm=0x7fff9c1bc840, jobstatus=QEMU_DOMAIN_JOB_STATUS_CANCELED) at ../../../libvirt/src/qemu/qemu_backup.c:563
 #2  0x00007fffcbaefcae in qemuProcessStop
    (driver=0x7fff9c144ff0, vm=0x7fff9c1bc840, reason=VIR_DOMAIN_SHUTOFF_DAEMON, asyncJob=QEMU_ASYNC_JOB_NONE, flags=<optimized out>)
    at ../../../libvirt/src/qemu/qemu_process.c:7812
 #3  0x00007fffcbaf2a10 in qemuProcessReconnect (opaque=<optimized out>) at ../../../libvirt/src/qemu/qemu_process.c:8578
 #4  0x00007ffff7c46bb5 in virThreadHelper (data=<optimized out>) at ../../../libvirt/src/util/virthread.c:233
 #5  0x00007ffff6e453f9 in start_thread () at /lib64/libpthread.so.0
 #6  0x00007ffff766fb53 in clone () at /lib64/libc.so.6

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuBackupJobTerminate: Move cleanup of temp files earlier
Peter Krempa [Thu, 25 Feb 2021 12:32:10 +0000 (13:32 +0100)]
qemuBackupJobTerminate: Move cleanup of temp files earlier

Upcoming patch will remove unnecessary actions if the VM crashed. The
cleanup needs to be performed always, thus needs to be moved earlier.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStorageVolDefFormat: Don't format empty <source>
Peter Krempa [Thu, 25 Feb 2021 13:11:05 +0000 (14:11 +0100)]
virStorageVolDefFormat: Don't format empty <source>

If there are no source extents the volume XML has an empty <source>
element. Remove it if there's nothing in it by using
virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirStorageVolDefFormat: Extract formatting of source extents
Peter Krempa [Thu, 25 Feb 2021 13:03:15 +0000 (14:03 +0100)]
virStorageVolDefFormat: Extract formatting of source extents

Move the extent formatting code into
virStorageVolDefFormatSourceExtents.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agostorageBackendProbeTarget: Don't fail if backing store can't be parsed
Peter Krempa [Thu, 25 Feb 2021 12:51:51 +0000 (13:51 +0100)]
storageBackendProbeTarget: Don't fail if backing store can't be parsed

When the backing store of the image can't be parsed
virStorageSourceNewFromBacking returns -1. storageBackendProbeTarget
then also fails which makes the pool refresh fail or even the storage
pool becomes inactive after (re)start of libvirtd.

In situations when we can't access the backing store via network we
just report the backing store string, thus we can do the same thing for
unparsable backing store to prevent the pool from going offline.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agostorageBackendProbeTarget: Check return value of virStorageSourceNewFromBacking
Peter Krempa [Thu, 25 Feb 2021 10:22:58 +0000 (11:22 +0100)]
storageBackendProbeTarget: Check return value of virStorageSourceNewFromBacking

Commit bc3a78f61a2aaac3 errorneously removed the return value check from
virStorageSourceNewFromBacking. In cases when we e.g. can't parse the
backing store string this leads to a crash:

 #0  virStorageSourceGetActualType (def=0x0) at ../../../libvirt/src/conf/storage_source_conf.c:1014
 #1  0x00007ffff7cee4f9 in virStorageSourceIsLocalStorage (src=<optimized out>) at ../../../libvirt/src/conf/storage_source_conf.c:1026
 #2  0x00007ffff455c97c in storageBackendProbeTarget (encryption=0x7fff9c122ce8, target=0x7fff9c122c68) at ../../../libvirt/src/storage/storage_util.c:3443
 #3  virStorageBackendRefreshVolTargetUpdate (vol=0x7fff9c122c30) at ../../../libvirt/src/storage/storage_util.c:3519
 #4  0x00007ffff455cdc0 in virStorageBackendRefreshLocal (pool=0x7fff9c010ea0) at ../../../libvirt/src/storage/storage_util.c:3593
 #5  0x00007ffff454f0a1 in storagePoolRefreshImpl
    (backend=backend@entry=0x7ffff4711180 <virStorageBackendDirectory>, obj=obj@entry=0x7fff9c010ea0, stateFile=stateFile@entry=0x7fff9c111a90 "/var/run/libvirt/storage/tmp.xml") at ../../../libvirt/src/storage/storage_driver.c:103
 #6  0x00007ffff4550ea5 in storagePoolUpdateStateCallback (obj=0x7fff9c010ea0, opaque=<optimized out>) at ../../../libvirt/src/storage/storage_driver.c:165
 #7  0x00007ffff7cefef4 in virStoragePoolObjListForEachCb (payload=<optimized out>, name=<optimized out>, opaque=0x7fffc8a489c0)
    at ../../../libvirt/src/conf/virstorageobj.c:435
 #8  0x00007ffff7c03195 in virHashForEachSafe
    (table=<optimized out>, iter=iter@entry=0x7ffff7cefec0 <virStoragePoolObjListForEachCb>, opaque=opaque@entry=0x7fffc8a489c0)
    at ../../../libvirt/src/util/virhash.c:414
 #9  0x00007ffff7cf0520 in virStoragePoolObjListForEach
    (pools=<optimized out>, iter=iter@entry=0x7ffff4550e10 <storagePoolUpdateStateCallback>, opaque=opaque@entry=0x0)
    at ../../../libvirt/src/conf/virstorageobj.c:468
 #10 0x00007ffff454f43a in storagePoolUpdateAllState () at ../../../libvirt/src/storage/storage_driver.c:184
 #11 storageStateInitialize (privileged=<optimized out>, root=<optimized out>, callback=<optimized out>, opaque=<optimized out>)
    at ../../../libvirt/src/storage/storage_driver.c:315
 #12 0x00007ffff7e10c04 in virStateInitialize
    (opaque=0x555555621820, callback=0x55555557b1d0 <daemonInhibitCallback>, root=0x0, mandatory=<optimized out>, privileged=true)
    at ../../../libvirt/src/libvirt.c:656
 #13 virStateInitialize
    (privileged=<optimized out>, mandatory=mandatory@entry=false, root=root@entry=0x0, callback=callback@entry=0x55555557b1d0 <daemonInhibitCallback>, opaque=opaque@entry=0x555555621820) at ../../../libvirt/src/libvirt.c:638
 #14 0x000055555557b230 in daemonRunStateInit (opaque=0x555555621820) at ../../../libvirt/src/remote/remote_daemon.c:605
 #15 0x00007ffff7c46bb5 in virThreadHelper (data=<optimized out>) at ../../../libvirt/src/util/virthread.c:233
 #16 0x00007ffff6e453f9 in start_thread () at /lib64/libpthread.so.0
 #17 0x00007ffff766fb53 in clone () at /lib64/libc.so

An invalid image can be easily created by:

$ qemu-img create -f qcow2 -F qcow2 -b 'json:{' -u img.qcow2 10M

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoPost-release version bump to 7.2.0
Jiri Denemark [Mon, 1 Mar 2021 10:58:58 +0000 (11:58 +0100)]
Post-release version bump to 7.2.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoRelease of libvirt-7.1.0
Jiri Denemark [Mon, 1 Mar 2021 10:55:46 +0000 (11:55 +0100)]
Release of libvirt-7.1.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Ricky Tigg [Thu, 25 Feb 2021 10:40:18 +0000 (11:40 +0100)]
Translated using Weblate (Finnish)

Currently translated at 15.5% (1638 of 10545 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/fi/

Co-authored-by: Ricky Tigg <ricky.tigg@gmail.com>
Signed-off-by: Ricky Tigg <ricky.tigg@gmail.com>
4 years agoqemu_monitor: Document qemuMonitorUnregister()
Michal Privoznik [Wed, 24 Feb 2021 12:55:33 +0000 (13:55 +0100)]
qemu_monitor: Document qemuMonitorUnregister()

The most important bit is that the caller is expected to pass
locked monitor.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agoqemu_domainjob: Make copy of owner API
Jiri Denemark [Wed, 24 Feb 2021 18:10:21 +0000 (19:10 +0100)]
qemu_domainjob: Make copy of owner API

Using the job owner API name directly works fine as long as it is a
static string or the owner's thread is still running. However, this is
not always the case. For example, when the owner API name is filled in a
job when we're reconnecting to existing domains after daemon restart,
the dynamically allocated owner name will disappear with the
reconnecting thread. Any follow up usage of the pointer will read random
memory.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agodocs: fix bad cut/paste in <teaming> example
Laine Stump [Tue, 23 Feb 2021 22:30:51 +0000 (17:30 -0500)]
docs: fix bad cut/paste in <teaming> example

When the parser and docs were enhanced to support a <teaming> element
in a generic <hostdev>, the example XML for formatdomain.rst was
cut/pasted from the example for <interface type='hostdev'>. In my
haste I neglected to remove the <mac address='blah'/> element (which
is unused/ignored for generic <hostdev> and change the closing tag
from </interface> to </hostdev>

https://bugzilla.redhat.com/1927984

Fixes: db64acfbda59ad22b671580fda13968c60bb8c1a
Reported-by: Yalan Zhang <yalzhang@redhat.com>
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: allow migration of generic <hostdev> with <teaming>
Laine Stump [Tue, 23 Feb 2021 22:21:56 +0000 (17:21 -0500)]
qemu: allow migration of generic <hostdev> with <teaming>

Commit 010ed0856b and commit db64acfbda introduced the ability to use
the <teaming> element in a generic <hostdev> (previously it could only
be used with <interface type='hostdev'>). However, the patch omitted
one crucial detail - along with parsing the <teaming> element in
<hostdev>, and adding the necessary info to the qemu commandline, we
also need to modify qemuMigrationSrcIsAllowedHostdev() to allow
migration when the generic <hostdev> has a <teaming> element.

https://bugzilla.redhat.com/1927984

Fixes: 010ed0856bb06f439e6fdf44e4f529f53441c398
Reported-by: Yalan Zhang <yalzhang@redhat.com>
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoNEWS: Mention some bug fixes for the 7.1.0 dev cycle
Jim Fehlig [Wed, 24 Feb 2021 01:34:50 +0000 (18:34 -0700)]
NEWS: Mention some bug fixes for the 7.1.0 dev cycle

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
4 years agoqemu: Add missing lock in qemuProcessHandleMonitorEOF
Peng Liang [Wed, 24 Feb 2021 11:28:23 +0000 (19:28 +0800)]
qemu: Add missing lock in qemuProcessHandleMonitorEOF

qemuMonitorUnregister will be called in multiple threads (e.g. threads
in rpc worker pool and the vm event thread).  In some cases, it isn't
protected by the monitor lock, which may lead to call g_source_unref
more than one time and a use-after-free problem eventually.

Add the missing lock in qemuProcessHandleMonitorEOF (which is the only
position missing lock of monitor I found).

Suggested-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Peng Liang <liangpeng10@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoTranslated using Weblate (Ukrainian)
Yuri Chornoivan [Mon, 22 Feb 2021 14:52:11 +0000 (15:52 +0100)]
Translated using Weblate (Ukrainian)

Currently translated at 100.0% (10545 of 10545 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/uk/

Co-authored-by: Yuri Chornoivan <yurchor@ukr.net>
Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
4 years agoUpdate translation files
Weblate [Mon, 22 Feb 2021 14:52:09 +0000 (15:52 +0100)]
Update translation files

Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/

Co-authored-by: Weblate <noreply@weblate.org>
Signed-off-by: Fedora Weblate Translation <i18n@lists.fedoraproject.org>
4 years agolibxl: Add lock process indicator to libxlDomainObjPrivate object
Jim Fehlig [Fri, 19 Feb 2021 21:58:19 +0000 (14:58 -0700)]
libxl: Add lock process indicator to libxlDomainObjPrivate object

The libvirt libxl driver has no access to FDs associated with VM disks.
The disks are opened by libxl.so and any related FDs are not exposed to
applications. The prevents using virtlockd's auto-release feature to
release locks when the FD is closed. Acquiring and releasing locks is
explicitly handled by the libxl driver.

The current logic is structured such that locks are acquired in
libxlDomainStart and released in libxlDomainCleanup. This works well
except for migration, where the locks must be released on the source
host before the domain can be started on the destination host, but the
domain cannot be cleaned up until the migration confirmation stage.
When libxlDomainCleanup if finally called in the confirm stage, locks
are again released resulting in confusing errors from virtlockd and
libvirtd

virtlockd[8095]: resource busy: Lockspace resource 'xxxxxx' is not locked
libvirtd[8050]: resource busy: Lockspace resource 'xxxxxx' is not locked
libvirtd[8050]: Unable to release lease on testvm

The error is also encountered in some error cases, e.g. when
libxlDomainStart fails before acquiring locks and libxlDomainCleanup
is still used for cleanup.

In lieu of a mechanism to check if a lock has been acquired, this patch
takes an easy approach to fixing the unnecessary lock releases by adding
an indicator to the libxlDomainPrivate object that can be set when the
lock is acquired and cleared when the lock is released. libxlDomainCleanup
can then skip releasing the lock in cases where it was previously released
or never acquired in the first place.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoNEWS: mention cgroups on hosts with systemd bug fix
Pavel Hrdina [Mon, 22 Feb 2021 15:08:35 +0000 (16:08 +0100)]
NEWS: mention cgroups on hosts with systemd bug fix

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
4 years agolibxl: Fix domain shutdown
Jim Fehlig [Fri, 19 Feb 2021 23:29:10 +0000 (16:29 -0700)]
libxl: Fix domain shutdown

Commit fa30ee04a2 caused a regression in normal domain shutown.
Initiating a shutdown from within the domain or via 'virsh shutdown'
does cause the guest OS running in the domain to shutdown, but libvirt
never reaps the domain so it is always shown in a running state until
calling 'virsh destroy'.

The shutdown thread is also an internal user of the driver shutdown
machinery and eventually calls libxlDomainDestroyInternal where
the ignoreDeathEvent inhibitor is set, but running in a thread
introduces the possibility of racing with the death event from
libxl. This can be prevented by setting ignoreDeathEvent before
running the shutdown thread.

An additional improvement is to handle the destroy event synchronously
instead of spawning a thread. The time consuming aspects of destroying
a domain have been completed when the destroy event is delivered.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoNEWS: mention support for vhost-user-blk
Pavel Hrdina [Mon, 22 Feb 2021 14:18:27 +0000 (15:18 +0100)]
NEWS: mention support for vhost-user-blk

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoNEWS: Mention snapshot quiesce rollback bugfix
Peter Krempa [Mon, 22 Feb 2021 13:59:07 +0000 (14:59 +0100)]
NEWS: Mention snapshot quiesce rollback bugfix

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agodocs: use proper cpu quota value in our documentation
Pavel Hrdina [Fri, 19 Feb 2021 18:49:28 +0000 (19:49 +0100)]
docs: use proper cpu quota value in our documentation

Commit <d505b8af58912ae1e1a211fabc9995b19bd40828> changed the cpu quota
value that reflects what kernel allows but did not update our
documentation.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agodomain_validate: use defines for cpu period and quota limits
Pavel Hrdina [Fri, 19 Feb 2021 18:41:59 +0000 (19:41 +0100)]
domain_validate: use defines for cpu period and quota limits

Commints <bc760f4d7c4f964fadcb2a73e126b0053e7a9b06> and
<98a09ca48ed4fc011abf2aa290e02ce1b8f1bb5f> fixed the code to use
defines instead of magic numbers but missed this place.

Following commit <ed1ba69f5a8132f8c1e73d2a1f142d70de0b564a> changed
the cpu quota limit to reflect what kernel actually allows so using
the defines fixes XML validations as well.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agopo: Refresh potfile for v7.1.0
Jiri Denemark [Mon, 22 Feb 2021 12:07:23 +0000 (13:07 +0100)]
po: Refresh potfile for v7.1.0

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoTranslated using Weblate (Chinese (Simplified) (zh_CN))
Pany [Sun, 21 Feb 2021 08:40:16 +0000 (09:40 +0100)]
Translated using Weblate (Chinese (Simplified) (zh_CN))

Currently translated at 56.0% (5859 of 10451 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/zh_CN/

Co-authored-by: Pany <geekpany@gmail.com>
Signed-off-by: Pany <geekpany@gmail.com>
4 years agoqemu*xml2*test: Cache capabilities between tests
Peter Krempa [Fri, 19 Feb 2021 15:46:45 +0000 (16:46 +0100)]
qemu*xml2*test: Cache capabilities between tests

Invoking the XML parser every time is quite expensive. Since we have a
deep copy function for 'virQEMUCapsPtr' object, we can cache the parsed
results lazily.

This brings significant speedup to qemuxml2argvtest:

real 0m2.234s
user 0m2.140s
sys 0m0.089s

vs.

real 0m1.161s
user 0m1.087s
sys 0m0.072s

qemuxml2xmltest benefits too:

real 0m0.879s
user 0m0.801s
sys 0m0.071s

vs.

real 0m0.466s
user 0m0.424s
sys 0m0.040s

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agotestQemuInfoSetArgs: Use curly braces in else section
Peter Krempa [Fri, 19 Feb 2021 15:31:42 +0000 (16:31 +0100)]
testQemuInfoSetArgs: Use curly braces in else section

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agotestCompareXMLToArgvValidateSchema: Improve and fix helper for testing everything
Peter Krempa [Fri, 19 Feb 2021 15:25:29 +0000 (16:25 +0100)]
testCompareXMLToArgvValidateSchema: Improve and fix helper for testing everything

The schema validator has a comment which allows checking all xml2argv
input files for schema validity by forcing the latest schema onto files
which don't have any schema. Fix it so that it works properly with the
caching introduced in previous commit.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agoqemuxml2argvtest: Cache QAPI schema between tests
Peter Krempa [Fri, 19 Feb 2021 15:19:09 +0000 (16:19 +0100)]
qemuxml2argvtest: Cache QAPI schema between tests

It's quite wasteful to reparse the QAPI schema for each _CAPS_ test.

Add a simple cache filled lazily by encountered schemas.

The time saving on my box is quite significant:

real 0m3.318s
user 0m3.203s
sys 0m0.107s

vs

real 0m2.223s
user 0m2.134s
sys 0m0.084s

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
4 years agovirJSONParserInsertValue: Take double pointer for @value
Peter Krempa [Fri, 12 Feb 2021 15:26:09 +0000 (16:26 +0100)]
virJSONParserInsertValue: Take double pointer for @value

The function calls virJSONValueObjectAppend/virJSONValueArrayAppend, so
by taking a double pointer we can drop the pointer clearing from
callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueNewNumber: Take ownership of passed string
Peter Krempa [Fri, 12 Feb 2021 13:34:16 +0000 (14:34 +0100)]
virJSONValueNewNumber: Take ownership of passed string

Avoid pointless copies of temporary strings when constructing number
JSON objects.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONParserHandle*: Refactor memory cleanup and drop NULL checks
Peter Krempa [Fri, 12 Feb 2021 14:25:34 +0000 (15:25 +0100)]
virJSONParserHandle*: Refactor memory cleanup and drop NULL checks

virJSONValueNew* won't return error nowadays so NULL checks are not
necessary. The memory can be cleared via g_autoptr.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuAgentSetVCPUsCommand: Refactor cleanup
Peter Krempa [Fri, 12 Feb 2021 11:18:54 +0000 (12:18 +0100)]
qemuAgentSetVCPUsCommand: Refactor cleanup

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuMonitorJSONTransactionAdd: Refactor cleanup
Peter Krempa [Fri, 12 Feb 2021 10:51:59 +0000 (11:51 +0100)]
qemuMonitorJSONTransactionAdd: Refactor cleanup

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueArrayAppend: Clear pointer when taking ownership of passed value
Peter Krempa [Thu, 11 Feb 2021 16:57:45 +0000 (17:57 +0100)]
virJSONValueArrayAppend: Clear pointer when taking ownership of passed value

The parent array takes ownership of the inserted value once all checks
pass. Don't make the callers second-guess when that happens and modify
the function to take a double pointer so that it can be cleared once the
ownership is taken.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agotestQEMUSchemaValidateObjectMergeVariantMember: Fix theoretical leak
Peter Krempa [Fri, 12 Feb 2021 10:36:30 +0000 (11:36 +0100)]
testQEMUSchemaValidateObjectMergeVariantMember: Fix theoretical leak

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirMACMapHashDumper: Refactor array addition
Peter Krempa [Fri, 12 Feb 2021 10:34:22 +0000 (11:34 +0100)]
virMACMapHashDumper: Refactor array addition

Use automatic memory freeing and don't check return value of
virJSONValueNewString as it can't fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuAgentMakeStringsArray: Refactor cleanup
Peter Krempa [Fri, 12 Feb 2021 10:32:46 +0000 (11:32 +0100)]
qemuAgentMakeStringsArray: Refactor cleanup

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueObjectAppend: Clear pointer when taking ownership of passed value
Peter Krempa [Thu, 11 Feb 2021 16:57:45 +0000 (17:57 +0100)]
virJSONValueObjectAppend: Clear pointer when taking ownership of passed value

The parent object takes ownership of the inserted value once all checks
pass. Don't make the callers second-guess when that happens and modify
the function to take a double pointer so that it can be cleared once the
ownership is taken.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueObjectAddVArgs: Use autofree for the temporary bitmap
Peter Krempa [Fri, 12 Feb 2021 09:56:49 +0000 (10:56 +0100)]
virJSONValueObjectAddVArgs: Use autofree for the temporary bitmap

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueNewArrayFromBitmap: Refactor cleanup
Peter Krempa [Fri, 12 Feb 2021 09:55:56 +0000 (10:55 +0100)]
virJSONValueNewArrayFromBitmap: Refactor cleanup

Use g_autoptr for the JSON value objects and remove the cleanup label
and inline freeing of objects.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValue(Array|Object)Append*: Simplify handling of appended object
Peter Krempa [Fri, 12 Feb 2021 09:51:31 +0000 (10:51 +0100)]
virJSONValue(Array|Object)Append*: Simplify handling of appended object

Use g_autofree for the pointer of the added object and remove the NULL
checks for values returned by virJSONValueNew* (except
virJSONValueNewNumberDouble) since they can't fail nowadays.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueCopy: Don't use virJSONValue(Object|Array)Append
Peter Krempa [Fri, 12 Feb 2021 09:44:49 +0000 (10:44 +0100)]
virJSONValueCopy: Don't use virJSONValue(Object|Array)Append

We know the exact number of keys or array members for the copied objects
so we can pre-allocate the arrays rather than inserting into them in a
loop incurring realloc copy penalty.

Also virJSONValueCopy now can't fail since all of the functions
allocating the different cases use just g_new/g_strdup internally so we
can remove the NULL checks from the recursive calls.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirJSONValueObjectInsert: Clear @value on successful insertion
Peter Krempa [Thu, 11 Feb 2021 16:29:29 +0000 (17:29 +0100)]
virJSONValueObjectInsert: Clear @value on successful insertion

The function takes ownership of @value on success so the proper
semantics will be to clear out the @value pointer. Convert @value to a
double pointer to do this.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemuAgentMakeCommand: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
qemuAgentMakeCommand: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirLockSpacePreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virLockSpacePreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirNetServerPreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virNetServerPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirNetServerPreExecRestart: Drop error reporting from virJSONValueObjectAppend* calls
Peter Krempa [Thu, 11 Feb 2021 19:32:00 +0000 (20:32 +0100)]
virNetServerPreExecRestart: Drop error reporting from virJSONValueObjectAppend* calls

The functions report errors already and the error can nowadays only
happen on programmer errors (if the passed virJSONValue isn't an
object), which won't happen. Remove the reporting.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirNetServerClientPreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virNetServerClientPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirNetServerServicePreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virNetServerServicePreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirNetDaemonPreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virNetDaemonPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirLogHandlerPreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virLogHandlerPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirLogDaemonPreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virLogDaemonPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirLockDaemonPreExecRestart: Refactor memory cleanup
Peter Krempa [Thu, 11 Feb 2021 17:29:40 +0000 (18:29 +0100)]
virLockDaemonPreExecRestart: Refactor memory cleanup

Switch to using the 'g_auto*' helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: capabilities: Enable QEMU_CAPS_INCREMENTAL_BACKUP
Peter Krempa [Wed, 16 Oct 2019 11:57:49 +0000 (13:57 +0200)]
qemu: capabilities: Enable QEMU_CAPS_INCREMENTAL_BACKUP

For incremental backup we need QEMU_CAPS_BLOCKDEV,
QEMU_CAPS_BLOCKDEV_REOPEN, QEMU_CAPS_MIGRATION_PARAM_BLOCK_BITMAP_MAPPING.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: migration: Migrate block dirty bitmaps corresponding to checkpoints
Peter Krempa [Mon, 8 Feb 2021 10:37:50 +0000 (11:37 +0100)]
qemu: migration: Migrate block dirty bitmaps corresponding to checkpoints

Preserve block dirty bitmaps after migration with
QEMU_MONITOR_MIGRATE_NON_SHARED_(DISK|INC).

This patch implements functions which offer the bitmaps to the
destination, check for eligibility on destination and then configure
source for the migration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: migration: Clean up temporary bitmaps when cancelling a migration
Peter Krempa [Mon, 8 Feb 2021 16:01:36 +0000 (17:01 +0100)]
qemu: migration: Clean up temporary bitmaps when cancelling a migration

In case when the block migration job required temporary bitmaps for
merging the appropriate checkpoints we need to clean them up when
cancelling the job. On success we don't need to do that though as the
bitmaps are just temporary thus are not written to disk.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agotests: qemumigrationcookie: Add testing for block dirty bitmap migration
Peter Krempa [Wed, 10 Feb 2021 19:37:28 +0000 (20:37 +0100)]
tests: qemumigrationcookie: Add testing for block dirty bitmap migration

Test the XML infrastructure for <blockDirtyBitmaps> migration cookie
element as well as the conversion to migration parameters for QMP schema
validation.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agotests: qemustatusxml2xml: Add status XML from migration with bitmaps
Peter Krempa [Wed, 10 Feb 2021 19:37:20 +0000 (20:37 +0100)]
tests: qemustatusxml2xml: Add status XML from migration with bitmaps

The XML sample shows the status XML when migrating with bitmaps
including the <tempBlockDirtyBitmaps> element added in previous commit.

It will also be used for the migration cookie test.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: domain: Store list of temporary bitmaps for migration in status XML
Peter Krempa [Mon, 8 Feb 2021 15:08:27 +0000 (16:08 +0100)]
qemu: domain: Store list of temporary bitmaps for migration in status XML

Add status XML infrastructure for storing a list of block dirty bitmaps
which are temporarily used when migrating a VM with
VIR_MIGRATE_NON_SHARED_DISK for cleanup after a libvirtd restart during
migration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: migration_cookie: Add helpers for transforming the cookie into migration params
Peter Krempa [Mon, 8 Feb 2021 10:19:10 +0000 (11:19 +0100)]
qemu: migration_cookie: Add helpers for transforming the cookie into migration params

'qemuMigrationCookieBlockDirtyBitmapsMatchDisks' maps the bitmaps from
the migration cookie to actual disk objects definition pointers.

'qemuMigrationCookieBlockDirtyBitmapsToParams' converts the bitmap
definitions from the migration cookie into parameters for the
'block-bitmap-mapping' migration parameter.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: migration_cookie: Add XML handling for setting up bitmap migration
Peter Krempa [Mon, 8 Feb 2021 10:12:35 +0000 (11:12 +0100)]
qemu: migration_cookie: Add XML handling for setting up bitmap migration

In cases where we are copying the storage we need to ensure that also
bitmaps are copied properly. This patch adds migration cookie XML
infrastructure which will allow the migration sides reach consensus on
which bitmaps to migrate.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: migration_params: Add infrastructure for 'dirty-bitmaps' migration feature
Peter Krempa [Mon, 8 Feb 2021 09:42:28 +0000 (10:42 +0100)]
qemu: migration_params: Add infrastructure for 'dirty-bitmaps' migration feature

Add the migration capability flag and the propagation of the
corresponding mapping configuration. The mapping will be produced from
the bitmaps on disk depending on both sides of the migration and the
necessity to perform merges.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: blockjob: Use qemuMonitorBitmapRemove for single bitmap removal
Peter Krempa [Tue, 9 Feb 2021 11:33:26 +0000 (12:33 +0100)]
qemu: blockjob: Use qemuMonitorBitmapRemove for single bitmap removal

There's no need in the cleanup steps to invoke a transaction to delete a
single bitmap.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: monitor: Introduce qemuMonitorBitmapRemove
Peter Krempa [Mon, 8 Feb 2021 15:58:53 +0000 (16:58 +0100)]
qemu: monitor: Introduce qemuMonitorBitmapRemove

The non-transaction wrapper is useful for code paths which want to
delete individual bitmaps or for cleanup after a failed job where we
want to attempt to delete every bitmap individually to prevent a failure
from cleaning up the rest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: migration: Create qcow2 v3 images for VIR_MIGRATE_NON_SHARED_DISK
Peter Krempa [Wed, 17 Feb 2021 13:45:49 +0000 (14:45 +0100)]
qemu: migration: Create qcow2 v3 images for VIR_MIGRATE_NON_SHARED_DISK

Use the new format when pre-creating the image for the user. Users
wishing to use the legacy format can always provide their own images or
use shared storage.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Probe whether an image is 'qcow2 v2' from query-named-block-nodes
Peter Krempa [Fri, 29 Jan 2021 13:35:57 +0000 (14:35 +0100)]
qemu: Probe whether an image is 'qcow2 v2' from query-named-block-nodes

Such images don't support stuff like dirty bitmaps. Note that the
synthetic test for detecting bitmaps is used as an example to prevent
adding additional test cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: capabilities: Introduce QEMU_CAPS_MIGRATION_PARAM_BLOCK_BITMAP_MAPPING
Peter Krempa [Fri, 7 Aug 2020 09:29:18 +0000 (11:29 +0200)]
qemu: capabilities: Introduce QEMU_CAPS_MIGRATION_PARAM_BLOCK_BITMAP_MAPPING

The capability represents qemu's ability to setup mappings for migrating
block dirty bitmaps and is based on presence of the 'transform' property
of the 'block-bitmap-mapping' property of 'migrate-set-parameters' QMP
command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemucapabilitiesdata: Update test data for qemu-6.0 on x86_64
Peter Krempa [Wed, 10 Feb 2021 15:31:59 +0000 (16:31 +0100)]
qemucapabilitiesdata: Update test data for qemu-6.0 on x86_64

Include the 'transform' member of 'block-bitmap-mapping'. This is based
on qemu commit v5.2.0-2208-gc79f01c945

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoqemu: Fix libvirt hang due to early TPM device stop
Stefan Berger [Fri, 19 Feb 2021 15:57:41 +0000 (10:57 -0500)]
qemu: Fix libvirt hang due to early TPM device stop

This patch partially reverts commit 5cde9dee where the qemuExtDevicesStop()
was moved to a location before the QEMU process is stopped. It may be
alright to tear down some devices before QEMU is stopped, but it doesn't work
for the external TPM (swtpm) which assumes that QEMU sends it a signal to stop
it before libvirt may try to clean it up. So this patch moves the
virFileDeleteTree() calls after the call to qemuExtDevicesStop() so that the
pid file of virtiofsd is not deleted before that call.

Afftected libvirt versions are 6.10 and 7.0.

Fixes: 5cde9dee8c70b17c458d031ab6cf71dce476eea2
Cc: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoevent-test: Properly terminate strings printed from callbacks
Kristina Hanicova [Fri, 19 Feb 2021 13:07:53 +0000 (14:07 +0100)]
event-test: Properly terminate strings printed from callbacks

Stdio was buffering strings in functions:
myDomainEventBlockJobCallback,
myDomainEventBlockThresholdCallback,
myDomainEventMemoryFailureCallback. It caused flushing the
printed strings from callbacks at the end of a run, not
gradually. The solution is to add \n at the end of each string.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_validate: Allow kvm hint-dedicated on non-passthrough VMs
Tim Wiederhake [Fri, 19 Feb 2021 09:54:00 +0000 (10:54 +0100)]
qemu_validate: Allow kvm hint-dedicated on non-passthrough VMs

A VM defined similar to:
  ...
  <features><kvm><hint-dedicated state='on'/></kvm></features>
  <cpu mode="host-model"/>
  ...
is currently invalid, as hint-dedicated is only allowed if cpu mode
is host-passthrough or maximum. This restriction is unnecessary, see
https://bugzilla.redhat.com/show_bug.cgi?id=1857671

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agovirsh: Add virshKeycodeNameCompleter
Kristina Hanicova [Thu, 18 Feb 2021 18:11:22 +0000 (19:11 +0100)]
virsh: Add virshKeycodeNameCompleter

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agovirsh: reindent virshCodesetNameCompleter prototype
Kristina Hanicova [Thu, 18 Feb 2021 18:11:22 +0000 (19:11 +0100)]
virsh: reindent virshCodesetNameCompleter prototype

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agohyperv: check return value of virUUIDGenerate
Ján Tomko [Thu, 18 Feb 2021 13:51:12 +0000 (14:51 +0100)]
hyperv: check return value of virUUIDGenerate

Fixes: fa66bd8cad2359b7d21676e0fd69bec472b36514
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agoqemu: monitor: clear cpu props properly in CPUInfoClear
Ján Tomko [Thu, 18 Feb 2021 13:23:22 +0000 (14:23 +0100)]
qemu: monitor: clear cpu props properly in CPUInfoClear

Stay true to the name of the function and clear the pointer
after freeing it.

This also silences a bogus Coverity report about a double
free in qemuMonitorGetCPUInfo where qemuMonitorCPUInfoClear
is called right after allocating a new qemuMonitorCPUInfo
to fill out the non-zero defaults.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agoqemu: saveimage: only steal domXML on success
Ján Tomko [Thu, 18 Feb 2021 13:16:36 +0000 (14:16 +0100)]
qemu: saveimage: only steal domXML on success

The comment and the caller assume virQEMUSaveDataNew only steals
domXML on success, but it is copied even on failure.

Also remove the misleading g_steal_pointer call on a local variable.

Reported by coverity.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agosecurity: dac: remove leftover virPCIDeviceFree
Ján Tomko [Thu, 18 Feb 2021 13:10:10 +0000 (14:10 +0100)]
security: dac: remove leftover virPCIDeviceFree

The switch to g_auto left this one call behind.

Reported by Coverity.

Fixes: 4ab0d1844a1e60def576086edc8b2c3775e7c10d
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
4 years agoqemu_driver.c: Coverity fix in qemuNodeDeviceDetachFlags()
Daniel Henrique Barboza [Thu, 18 Feb 2021 12:21:06 +0000 (09:21 -0300)]
qemu_driver.c: Coverity fix in qemuNodeDeviceDetachFlags()

Commit 76f47889326c4 made qemuNodeDeviceDetachFlags() unusable due to an
'if then else if' chain that will always results in a 'return -1',
regardless of 'driverName' input.

Found by Coverity.

Fixes: 76f47889326c45d2732711bc6dd5751aaf6e5194
Reported-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoesx: use g_autofree for datastoreRelatedPath
Ján Tomko [Thu, 18 Feb 2021 12:52:27 +0000 (13:52 +0100)]
esx: use g_autofree for datastoreRelatedPath

Reported by Coverity.

Fixes: 213662813cd846d045be8857dc7b917d33a40989
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Ricky Tigg [Thu, 18 Feb 2021 11:40:16 +0000 (12:40 +0100)]
Translated using Weblate (Finnish)

Currently translated at 15.5% (1621 of 10451 strings)

Translation: libvirt/libvirt
Translate-URL: https://translate.fedoraproject.org/projects/libvirt/libvirt/fi/

Co-authored-by: Ricky Tigg <ricky.tigg@gmail.com>
Signed-off-by: Ricky Tigg <ricky.tigg@gmail.com>
4 years agoqemuBlockDiskDetectNodes: just return when alias is null
Yi Li [Thu, 18 Feb 2021 02:43:33 +0000 (10:43 +0800)]
qemuBlockDiskDetectNodes: just return when alias is null

Just return when alias is null and Remove the 'ret' variable.

Signed-off-by: Yi Li <yili@winhong.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoscripts/check-aclrules.py: check ACL for domain_driver.c ACL callers
Daniel Henrique Barboza [Tue, 2 Feb 2021 20:44:34 +0000 (17:44 -0300)]
scripts/check-aclrules.py: check ACL for domain_driver.c ACL callers

This script works under two specific conditions. For each opened file,
search for all functions that has ACL calls and store them, and see
if there is a vir*DriverPtr struct declared in it. For each implementation
found, check if there is an ACL verification inside it, and error out if
none was found. The script also supports the concept of stub, where another
function takes the responsibility for the ACL call instead of the
original API.

Unfortunately this is not enough to cover the new scenario we have now,
with domain_driver.c containing helper functions that execute the ACL
calls. The script does not store state between files because, until now,
it wasn't needed to - APIs and stubs and vir*DriverPtr declarations were
always in the same file. Also, the script will not check for ACL in functions
that does not belong to a vir*DriverPtr interface. What we have now in
domain_driver.c breaks both assumptions: the functions are in a different
file, and there is no vir*DriverPtr being implemented in the file that
uses these functions.

This patch changes check-aclrules.py to accomodate this scenario. The helpers
that have ACL checks are stored beforehand in aclFuncHelpers, allowing other
files to use them to recognize a stub situation. In case the current file
being analyzed is domain_driver.c itself, we'll do a manual check using
aclFuncHelpers to verify that these functions indeed have ACL checks.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_driver.c: use g_auto* in virDomainDriverNodeDeviceDetachFlags()
Daniel Henrique Barboza [Sat, 30 Jan 2021 17:29:34 +0000 (14:29 -0300)]
domain_driver.c: use g_auto* in virDomainDriverNodeDeviceDetachFlags()

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu, libxl, hypervisor: use virDomainDriverNodeDeviceDetachFlags() helper
Daniel Henrique Barboza [Sat, 30 Jan 2021 17:23:41 +0000 (14:23 -0300)]
qemu, libxl, hypervisor: use virDomainDriverNodeDeviceDetachFlags() helper

libxlNodeDeviceDetachFlags() and qemuNodeDeviceDetachFlags() are mostly
equal, aside from how the virHostdevmanager pointer is retrieved and
the PCI stub driver used.

Now that the PCI stub driver verification is done early in both functions,
we can use the virDomainDriverNodeDeviceDetachFlags() helper to reduce
code duplication between them. 'driverName' is checked inside the helper
to set the appropriate stub driver.

The helper is named with the 'Flags' suffix, even when the helper itself
isn't receiving the flags from the callers, to be compliant with the
ACL function virNodeDeviceDetachFlagsEnsureACL() that is being called
inside it and was called from the original functions. Renaming the helper
would implicate in renaming REMOTE_PROC_NODE_DEVICE_DETACH_FLAGS, and all the
related structs inside remote_protocol.x, to be compliant with the ACL
rules.

This is not being checked at this moment, but we'll fix check-aclrules.py to
verify all the helpers that calls ACL functions in domain_driver.c shortly.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu_driver.c: validate 'driverName' earlier in qemuNodeDeviceDetachFlags()
Daniel Henrique Barboza [Sat, 30 Jan 2021 17:08:33 +0000 (14:08 -0300)]
qemu_driver.c: validate 'driverName' earlier in qemuNodeDeviceDetachFlags()

The validation of 'driverName' does not depend on any other state and can be
done right on the start of the function. We can fail earlier while avoiding
a cleanup jump.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agolibxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags()
Daniel Henrique Barboza [Sat, 30 Jan 2021 16:59:06 +0000 (13:59 -0300)]
libxl_driver.c: validate 'driverName' earlier in libxlNodeDeviceDetachFlags()

The validation of 'driverName' does not depend on any other state and can be
done right on the start of the function. We can fail earlier while avoiding
a cleanup jump.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_driver.c: use g_auto* in virDomainDriverNodeDeviceReAttach()
Daniel Henrique Barboza [Sat, 30 Jan 2021 16:57:04 +0000 (13:57 -0300)]
domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReAttach()

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu, libxl, hypervisor: use virDomainDriverNodeDeviceReAttach() helper
Daniel Henrique Barboza [Sat, 30 Jan 2021 16:40:35 +0000 (13:40 -0300)]
qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReAttach() helper

libxlNodeDeviceReAttach() and qemuNodeDeviceReAttach() are mostly equal,
differing only how the virHostdevManager pointer is retrieved.

Put the common code into virDomainDriverNodeDeviceReAttach() to reduce
code duplication.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_driver.c: use g_auto* in virDomainDriverNodeDeviceReset()
Daniel Henrique Barboza [Sat, 30 Jan 2021 16:30:37 +0000 (13:30 -0300)]
domain_driver.c: use g_auto* in virDomainDriverNodeDeviceReset()

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodatatypes.h: register AUTOPTR_CLEANUP_FUNC for virNodeDevicePtr
Daniel Henrique Barboza [Sat, 30 Jan 2021 16:26:02 +0000 (13:26 -0300)]
datatypes.h: register AUTOPTR_CLEANUP_FUNC for virNodeDevicePtr

Next patch will use g_autoptr() with virNodeDevicePtr for cleanups.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu, libxl, hypervisor: use virDomainDriverNodeDeviceReset() helper
Daniel Henrique Barboza [Sat, 30 Jan 2021 01:19:29 +0000 (22:19 -0300)]
qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReset() helper

libxlNodeDeviceReset() and qemuNodeDeviceReset() are mostly equal,
differing only how the virHostdevManager pointer is retrieved.

Put the common code into virDomainDriverNodeDeviceReset() to reduce
code duplication.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agorpc: avoid crash when system time jump back
BiaoXiang Ye [Wed, 10 Feb 2021 05:58:05 +0000 (05:58 +0000)]
rpc: avoid crash when system time jump back

 Setting the system time backward would lead to a
 multiplication overflow in function virKeepAliveStart.
 The function virKeepAliveTimerInternal got the same bug too.

 Backtrace below:
 #0  0x0000ffffae898470 in raise () from /usr/lib64/libc.so.6
 #1  0x0000ffffae89981c in abort () from /usr/lib64/libc.so.6
 #2  0x0000ffffaf9a36a8 in __mulvsi3 () from /usr/lib64/libvirt.so.0
 #3  0x0000ffffaf8fd9e8 in virKeepAliveStart (ka=0xaaaaf954ce10, interval=interval entry=0,
     count=count entry=0) at ../../src/rpc/virkeepalive.c:283
 #4  0x0000ffffaf908560 in virNetServerClientStartKeepAlive (client=0xaaaaf954cbe0)
     at ../../src/rpc/virnetserverclient.c:1628
 #5  0x0000aaaac57eb6dc in remoteDispatchConnectSupportsFeature (server=0xaaaaf95309d0,
     msg=0xaaaaf9549d90, ret=0xffff8c007fc0, args=0xffff8c002e70, rerr=0xffff9ea054a0,
     client=0xaaaaf954cbe0) at ../../src/remote/remote_daemon_dispatch.c:5063
 #6  remoteDispatchConnectSupportsFeatureHelper (server=0xaaaaf95309d0, client=0xaaaaf954cbe0,
     msg=0xaaaaf9549d90, rerr=0xffff9ea054a0, args=0xffff8c002e70, ret=0xffff8c007fc0)
     at ./remote/remote_daemon_dispatch_stubs.h:3503
 #7  0x0000ffffaf9053a4 in virNetServerProgramDispatchCall(msg=0xaaaaf9549d90, client=0xaaaaf954cbe0,
     server=0x0, prog=0xaaaaf953a170) at ../../src/rpc/virnetserverprogram.c:451
 #8  virNetServerProgramDispatch (prog=0xaaaaf953a170, server=0x0, server entry=0xaaaaf95309d0,
     client=0xaaaaf954cbe0, msg=0xaaaaf9549d90) at ../../src/rpc/virnetserverprogram.c:306
 #9  0x0000ffffaf90a6bc in virNetServerProcessMsg (msg=<optimized out>, prog=<optimized out>,
     client=<optimized out>, srv=0xaaaaf95309d0) at ../../src/rpc/virnetserver.c:137
 #10 virNetServerHandleJob (jobOpaque=0xaaaaf950df80, opaque=0xaaaaf95309d0)
     at ../../src/rpc/virnetserver.c:154
 #11 0x0000ffffaf812e14 in virThreadPoolWorker (opaque=<optimized out>)
     at ../../src/util/virthreadpool.c:163
 #12 0x0000ffffaf81237c in virThreadHelper (data=<optimized out>) at ../../src/util/virthread.c:246
 #13 0x0000ffffaea327ac in ?? () from /usr/lib64/libpthread.so.0
 #14 0x0000ffffae93747c in ?? () from /usr/lib64/libc.so.6
 (gdb) frame 3
 #3  0x0000ffffaf8fd9e8 in virKeepAliveStart (ka=0xaaaaf954ce10, interval=interval entry=0,
     count=count entry=0) at ../../src/rpc/virkeepalive.c:283
 283            timeout = ka->interval - delay;
 (gdb) list
 278    now = time(NULL);
 279    delay = now - ka->lastPacketReceived; <='delay' got a negative value
 280    if (delay > ka->interval)
 281        timeout = 0;
 282    else
 283        timeout = ka->interval - delay;
 284    ka->intervalStart = now - (ka->interval - timeout);
 285    ka->timer = virEventAddTimeout(timeout * 1000, virKeepAliveTimer, <= multiplication overflow
 286                                   ka, virObjectFreeCallback);
 287    if (ka->timer < 0)
 (gdb) p now
 $2 = 18288001
 (gdb) p ka->lastPacketReceived
 $3 = 1609430405

Signed-off-by: BiaoXiang Ye <yebiaoxiang@huawei.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agolibxl: Use g_autofree for char* where easily possible
Jim Fehlig [Wed, 17 Feb 2021 01:37:09 +0000 (18:37 -0700)]
libxl: Use g_autofree for char* where easily possible

All of these strings are allocated once, freed once, and are never
returned out of the function where they are declared.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoutil: Fix file descriptor passing on 64-bit FreeBSD and NetBSD.
Bruno Haible [Wed, 17 Feb 2021 02:47:56 +0000 (03:47 +0100)]
util: Fix file descriptor passing on 64-bit FreeBSD and NetBSD.

* src/util/virsocket.c (virSocketRecvFD): Set msg.msg_controllen as documented
in the man pages.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoci: Makefile: Expose CI_IMAGE_PREFIX and CI_IMAGE_TAG in 'ci-help'
Erik Skultety [Mon, 15 Feb 2021 12:07:08 +0000 (13:07 +0100)]
ci: Makefile: Expose CI_IMAGE_PREFIX and CI_IMAGE_TAG in 'ci-help'

Using locally built images is a useful feature; our commentaries even
mention overriding them may be useful in some scenarios. Expose the
variables in the help to let users know they can use the feature.

Formatting would definitely break, so this patch adds more spacing for
proper alignment.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>