]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
5 years agoqemu: snapshot: Don't update current snapshot until we're done
Peter Krempa [Mon, 30 Sep 2019 14:22:08 +0000 (16:22 +0200)] 
qemu: snapshot: Don't update current snapshot until we're done

Since commit f105627992e we store whether a snapshot is current globally
rather than locally in the snapshot object.

This means that we don't have to unset the current snapshot prior to
taking/reverting the snapshot and we can do it only when everything is
done successfully.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoclarify the xml example for NVDIMM more clealy
Luyao Zhong [Mon, 23 Sep 2019 10:06:22 +0000 (18:06 +0800)] 
clarify the xml example for NVDIMM more clealy

The NVDIMM backend file can be a normal file or a real device file,
Current xml example and explainations may mislead users. So add more
info about the NVDIMM related elements and update the xml examples.

Signed-off-by: Luyao Zhong <luyao.zhong@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agosecurity: AppArmor profile fixes for swtpm
Chris Coulson [Tue, 24 Sep 2019 19:25:14 +0000 (20:25 +0100)] 
security: AppArmor profile fixes for swtpm

The AppArmor profile generated by virt-aa-helper is too strict for swtpm.
This change contains 2 small fixes:
- Relax append access to swtpm's log file to permit write access instead.
Append access is insufficient because the log is opened with O_CREAT.
- Permit swtpm to acquire a lock on its lock file.

Signed-off-by: Chris Coulson <chris.coulson@canonical.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: sanity check vhost user FD before passing to QEMU
Daniel P. Berrangé [Mon, 30 Sep 2019 11:39:17 +0000 (12:39 +0100)] 
qemu: sanity check vhost user FD before passing to QEMU

Ensure that the FD we're passing to QEMU is actually open, so we get a
sane error message upfront instead of telling QEMU to use a closed FD.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: ensure vhostuser FD is initialized to -1
Daniel P. Berrangé [Fri, 27 Sep 2019 16:34:44 +0000 (17:34 +0100)] 
qemu: ensure vhostuser FD is initialized to -1

The video private data was not initializing the vhostuser FD
causing us to attempt to close FD 0 many times over.

Fixes

  commit ca60ecfa8cc1bd85baf7137dd1864d5f00f019f0
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Mon Sep 23 14:44:36 2019 +0400

      qemu: add qemuDomainVideoPrivate

Since the test suite does not invoke qemuExtDevicesStart(), no
vhost_user_fd will be present when generating test XML. To deal
with this we can must a fake FD number. While the current XML
is using FD == 0, we pick a very interesting number that's unlikely
to be a real FD, so that we're more likely to see any mistakes
closing the invalid FD.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: monitor: unexport qemuMonitorJSONTransactionAdd
Peter Krempa [Thu, 26 Sep 2019 14:37:44 +0000 (16:37 +0200)] 
qemu: monitor: unexport qemuMonitorJSONTransactionAdd

Now it's not used outside of qemu_monitor_json.c.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Replace open-coded transaction action generators
Peter Krempa [Thu, 26 Sep 2019 14:36:15 +0000 (16:36 +0200)] 
qemu: checkpoint: Replace open-coded transaction action generators

Use the generators provided by the monitor code instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: block: Replace snapshot transaction action generator
Peter Krempa [Thu, 26 Sep 2019 14:33:43 +0000 (16:33 +0200)] 
qemu: block: Replace snapshot transaction action generator

Use the new generator residing in the monitor code rather than directly
using qemuMonitorJSONTransactionAdd.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agotests: qemumonitor: Add testing for the 'transaction' command and generators
Peter Krempa [Thu, 26 Sep 2019 14:12:20 +0000 (16:12 +0200)] 
tests: qemumonitor: Add testing for the 'transaction' command and generators

Validate all the commands against the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: monitor: Add transaction generators for snapshot APIs
Peter Krempa [Thu, 26 Sep 2019 14:03:46 +0000 (16:03 +0200)] 
qemu: monitor: Add transaction generators for snapshot APIs

Unify with other code that generates parameters for the 'transaction'
command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: monitor: Add transaction generators for dirty bitmap APIs
Peter Krempa [Thu, 26 Sep 2019 13:53:39 +0000 (15:53 +0200)] 
qemu: monitor: Add transaction generators for dirty bitmap APIs

Rather than generating the transaction contents in random places add a
unified set of APIs to generate the contents for a 'transaction' for the
dirty bitmap APIs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: domain: Base block job interlocking on QEMU_CAPS_INCREMENTAL_BACKUP
Peter Krempa [Thu, 26 Sep 2019 12:08:11 +0000 (14:08 +0200)] 
qemu: domain: Base block job interlocking on QEMU_CAPS_INCREMENTAL_BACKUP

The QEMU_CAPS_INCREMENTAL_BACKUP will be enabled once all bits of the
incremental backup feature work as expected which means also properly
interacting with blockjobs and snapshots.

Thus we can allow blockjobs and snapshots if QEMU_CAPS_INCREMENTAL_BACKUP
is present even when checkpoints exist.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: Aggregate interlocking of blockjobs by checkpoints in one place
Peter Krempa [Thu, 26 Sep 2019 11:54:15 +0000 (13:54 +0200)] 
qemu: Aggregate interlocking of blockjobs by checkpoints in one place

Rather than having to fix 5 places once we support the combination, add
a function called by all the blockjob/snapshot APIs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Forbid creating checkpoints until we support backups
Peter Krempa [Thu, 26 Sep 2019 11:25:40 +0000 (13:25 +0200)] 
qemu: checkpoint: Forbid creating checkpoints until we support backups

Checkpoints by themselves are not very useful for anything else than
testing the few bitmap interactions that are currently implemented.

It's very unlikely that anybody used this feature and thus we can
disable it until we have a more complete implementation ready.

Additionally the code for deleting checkpoints has many broken failure
scenarios which should be fixed first. This will require support of
deleting a bitmap in a qemu 'transaction' which was not released yet.

Curious users obviously can use the qemu namespace in the XML to enable
this for experiments:

  <domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
    ...
    <qemu:capabilities>
      <qemu:add capability='incremental-backup'/>
    </qemu:capabilities>
  </domain>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: caps: Add capability for incremental backup support
Peter Krempa [Thu, 26 Sep 2019 11:01:30 +0000 (13:01 +0200)] 
qemu: caps: Add capability for incremental backup support

Add a new all-covering capability which will be used to interlock
incremental backup support until all bits are ready.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: Don't repeat virDomainObjEndAPI in qemuDomainBlockPull
Peter Krempa [Thu, 26 Sep 2019 11:50:16 +0000 (13:50 +0200)] 
qemu: Don't repeat virDomainObjEndAPI in qemuDomainBlockPull

Add a 'cleanup' label and use jumps as we do in other places.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Remove open-ended TODOs
Peter Krempa [Thu, 26 Sep 2019 11:21:00 +0000 (13:21 +0200)] 
qemu: checkpoint: Remove open-ended TODOs

Once somebody is motivated enough to add the support for the quiesce
flag or offline checkpoint deletion they are welcome to do so but we
don't need to have a reminder.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Refactor cleanup in qemuCheckpointCreateXML
Peter Krempa [Thu, 26 Sep 2019 11:19:40 +0000 (13:19 +0200)] 
qemu: checkpoint: Refactor cleanup in qemuCheckpointCreateXML

Use VIR_AUTO* helpers and get rid of the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: driver: Don't pull in qemu_monitor_json.h directly
Peter Krempa [Fri, 20 Sep 2019 11:49:55 +0000 (13:49 +0200)] 
qemu: driver: Don't pull in qemu_monitor_json.h directly

There's nothing that uses it directly now. Also not allowing direct use
will promote our layering.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: domain: Move checkpoint related code to qemu_checkpoint.c
Peter Krempa [Fri, 20 Sep 2019 11:47:04 +0000 (13:47 +0200)] 
qemu: domain: Move checkpoint related code to qemu_checkpoint.c

Finish the refactor by moving and renaming functions from qemu_domain.c

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: driver: Move checkpoint-related code to qemu_checkpoint.c
Peter Krempa [Thu, 19 Sep 2019 14:49:21 +0000 (16:49 +0200)] 
qemu: driver: Move checkpoint-related code to qemu_checkpoint.c

Move all extensive functions to a new file so that we don't just pile
everything in the common files. This obviously isn't possible with
straight code movement as we still need stubs in qemu_driver.c

Additionally some functions e.g. for looking up a checkpoint by name
were so short that moving the impl didn't make sense.

Note that in the move the new file also doesn't use
virQEMUMomentReparent but rather an stripped down copy. As I plan to
split out snapshot code into a separate file the unification doesn't
make sense any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: checkpoint: Do ACL check prior to snapshot interlocking
Peter Krempa [Fri, 27 Sep 2019 08:00:39 +0000 (10:00 +0200)] 
qemu: checkpoint: Do ACL check prior to snapshot interlocking

The interlocking with snapshots is executed prior to the ACL check so if
a VM has snapshots invoking the checkpoint API may leak it's existance.

Introduced with the qemuDomainCheckpointCreateXML API implementation in
commit 5f4e0796503.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agotools: fix regression passing command with virt-login-shell
Daniel P. Berrangé [Fri, 27 Sep 2019 16:18:24 +0000 (17:18 +0100)] 
tools: fix regression passing command with virt-login-shell

It is documented that a command to run inside the container can be
passed with the -c arg.

  virt-login-shell -c "ls -l /"

This fixes

  commit 4feeb2d986b98013ebfb1d41ab6b9007b6cce6e2
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Thu Aug 1 10:58:31 2019 +0100

    tools: split virt-login-shell into two binaries

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoremote: fix systemd IP socket activation with virtproxyd
Daniel P. Berrangé [Fri, 20 Sep 2019 15:18:41 +0000 (16:18 +0100)] 
remote: fix systemd IP socket activation with virtproxyd

We recently forbid the use of --listen with socket activation:

  commit 3a6a725b8f575890ee6c151ad1f46ea0ceea1f3b
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Thu Aug 22 14:52:16 2019 +0100

      remote: forbid the --listen arg when systemd socket activation

In this change we forgot that virtproxyd doesn't have a --listen
parameter, and instead behaves as if it was always present. Thus
when systemd socket activation is present, we must disable this
built-in default

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotools: Record NSS dependency on symbols file
Michal Privoznik [Tue, 16 Jul 2019 10:06:20 +0000 (12:06 +0200)] 
tools: Record NSS dependency on symbols file

If a symbol file for either of NSS modules is changed then
subsequent 'make' doesn't regenerate the library, because there
is no implicit dependency between the library and symbols file.
Put an explicit dependency into the Makefile then. Unfortunately,
setting _DEPENDENCIES makes us lose automake's generated
dependencies (see src/Makefile.am:592 for details). But
fortunately, the only dependency we had was _LIBADD variable.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agolibvirt_nss.h: Separate function declarations with an empty line
Michal Privoznik [Tue, 16 Jul 2019 10:05:27 +0000 (12:05 +0200)] 
libvirt_nss.h: Separate function declarations with an empty line

I find it more readable that way.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agonss: Don't leak @addr in gethostbyname4()
Michal Privoznik [Sat, 28 Sep 2019 18:42:29 +0000 (20:42 +0200)] 
nss: Don't leak @addr in gethostbyname4()

Similarly to gethostbyname3(), the @addr must be freed on return
from the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agonss: Drop needless free() in gethostbyname3()
Michal Privoznik [Sat, 28 Sep 2019 19:24:53 +0000 (21:24 +0200)] 
nss: Drop needless free() in gethostbyname3()

The findLease() function allocates @addr array iff no error
occurred and at least one satisfactory record was found.
Therefore, there is no need to call free() if findLease() failed,
or did not find any records as addr == NULL.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agonss: Compare addresses iff their family matches
Michal Privoznik [Sat, 28 Sep 2019 18:46:08 +0000 (20:46 +0200)] 
nss: Compare addresses iff their family matches

When parsing leases file, appendAddr() is called to append parsed
tuple (address, expiry time, family) into an array. Whilst doing
so, the array is searched for possible duplicate. This is done by
comparing each item of the array by passed @family: if @family is
AF_INET then the item is viewed as IPv4 address. Similarly, if
@family is AF_INET6 then the item is viewed as IPv6 address. This
is not exactly right - the array can contain addresses of both
families and thus the address family of each item of the array
must be considered.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agovircgroup: Add some VIR_DEBUG statements
Cole Robinson [Thu, 26 Sep 2019 19:25:52 +0000 (15:25 -0400)] 
vircgroup: Add some VIR_DEBUG statements

These helped with debugging
https://bugzilla.redhat.com/show_bug.cgi?id=1612383

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agovircgroupv2: Fix VM startup when legacy cgroups are defined
Cole Robinson [Thu, 26 Sep 2019 19:00:55 +0000 (15:00 -0400)] 
vircgroupv2: Fix VM startup when legacy cgroups are defined

On Fedora 31, starting a 'mock' build alters /proc/$pid/cgroup,
probably due to usage of systemd-nspawn.

Before:
$ cat /proc/self/cgroup
0::/user.slice/user-1000.slice/...

After:
$ cat /proc/self/cgroup
1:name=systemd:/
0::/user.slice/user-1000.slice/...

The cgroupv2 code mishandles that first line in the second case, which
causes VM startup to fail with: Unable to read from
'/sys/fs/cgroup/machine/cgroup.controllers': No such file or directory

The kernel docs[1] say that the cgroupv2 path will always start with
'0::', which in the code here controllers="". Only set the v2 placement
path when we see that cgroup file entry.

[1] https://www.kernel.org/doc/html/v5.3/admin-guide/cgroup-v2.html#processes

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

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: driver: Remove misplaced qemuDomainObjEndJob in qemuDomainCheckpointGetXMLDesc
Peter Krempa [Fri, 20 Sep 2019 07:08:05 +0000 (09:08 +0200)] 
qemu: driver: Remove misplaced qemuDomainObjEndJob in qemuDomainCheckpointGetXMLDesc

The code that gets the job to refresh disk sizes was not merged yet so
remove this artifact.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoconf: Drop pointless 'domain' argument from virDomainSnapshotRedefinePrep
Peter Krempa [Fri, 20 Sep 2019 10:25:51 +0000 (12:25 +0200)] 
conf: Drop pointless 'domain' argument from virDomainSnapshotRedefinePrep

'vm' is passed in which contains the definition which contains the UUID
so we don't need another parameter for this.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Drop pointless 'domain' argument from virDomainCheckpointRedefinePrep
Peter Krempa [Fri, 20 Sep 2019 10:25:51 +0000 (12:25 +0200)] 
conf: Drop pointless 'domain' argument from virDomainCheckpointRedefinePrep

'vm' is passed in which contains the definition which contains the UUID
so we don't need another parameter for this.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Move, rename and export qemuDomObjFromDomain
Peter Krempa [Fri, 20 Sep 2019 09:03:08 +0000 (11:03 +0200)] 
qemu: Move, rename and export qemuDomObjFromDomain

Move it to qemu_domain.c and rename it to qemuDomainObjFromDomain. This
will allow reusing it after splitting out checkpoint code from
qemu_driver.c.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agodocs: document that C & Python are the preferred languages
Daniel P. Berrangé [Thu, 5 Sep 2019 11:41:30 +0000 (12:41 +0100)] 
docs: document that C & Python are the preferred languages

Blacklist Perl and Shell code in favour of Python for
sake of readability and portability.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu_monitor: s/size_t/ULL/ in qemuMonitorSave{Virtual,Physical}Memory
Michal Privoznik [Fri, 27 Sep 2019 11:29:53 +0000 (13:29 +0200)] 
qemu_monitor: s/size_t/ULL/ in qemuMonitorSave{Virtual,Physical}Memory

As it turns out, on my 32bit ARM machine size_t is not the same
size as ULL. However, @length argument for both functions is type
of size_t but it's treated as ULL - for instance when passed to
qemuMonitorJSONMakeCommand(). The problem is that because of
"U:size" the virJSONValueObjectAddVArgs() expects an ULL argument
but on the stack there are size_t and char * arguments (which
coincidentally add up to size of ULL). So the created command has
only two arguments "val" and incorrect "size" and no "path" which
is required.

I've tried to find other occurrences of this pattern but at the
rest of places where size_t is used it tracks size of an array so
that's safe.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agorpm: stop compressing the ChangeLog file
Daniel P. Berrangé [Fri, 20 Sep 2019 12:21:31 +0000 (13:21 +0100)] 
rpm: stop compressing the ChangeLog file

We stopped generating a giant ChangeLog file in

  commit ce97c33a795dec053f1e85c65ecd924b8c6ec4ba
  Author: Andrea Bolognani <abologna@redhat.com>
  Date:   Mon Apr 1 17:33:03 2019 +0200

      maint: Stop generating ChangeLog from git

so there is no reason to compress it anymore.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: Simplify argument list of qemuDomainBlockPullCommon
Peter Krempa [Thu, 26 Sep 2019 11:47:54 +0000 (13:47 +0200)] 
qemu: Simplify argument list of qemuDomainBlockPullCommon

Drop the 'driver' argument since it can be extracted from private data
to shorten the argument list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agotests: qemucapabilities: Update caps of qemu-4.1 to released version
Peter Krempa [Fri, 27 Sep 2019 05:27:57 +0000 (07:27 +0200)] 
tests: qemucapabilities: Update caps of qemu-4.1 to released version

Now that qemu 4.1 was released we can update the capabilities to the
final form.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agotests: add qemu capabilities data for qemu 4.2
Peter Krempa [Tue, 17 Sep 2019 14:49:03 +0000 (16:49 +0200)] 
tests: add qemu capabilities data for qemu 4.2

Add capabilities test data for upcoming qemu 4.2.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
5 years agoconf: refresh network ports missing from network driver on restart
Laine Stump [Fri, 20 Sep 2019 22:15:19 +0000 (18:15 -0400)] 
conf: refresh network ports missing from network driver on restart

Before the refactoring that properly separated the network driver from
the hypervisor driver and forced all interaction to go through public
APIs, all network usage counters were zeroed when the network driver
was initialized, and the network driver's now-deprecated
"semi-private" API networkNotifyActualDevice() was called for every
interface of every domain as each hypervisor "reconnected" its domains
during a libvirtd restart, and this would refresh the usage count for
each network.

Post-driver-split, during libvirtd restart/reconnection of the running
domains, the function virDomainNetNotifyActualDevice() is called by
each hypervisor driver for every interface of every domain restart,
and this function has code to re-register interfaces, but it only
calls into the network driver to re-register those ports that don't
already have a valid portid (ie. one that is not simply all 0),
assuming that those with valid portids are already known (and counted)
by the network driver.

commit 7ab9bdd47 recently modified the network driver so that, in most
cases, it properly resyncs each network's connection count during
libvirtd (or maybe virtnetworkd) restart by iterating through the
network's port list. This doesn't account for the case where a network
is destroyed and restarted while there are running domains that have
active ports on the network. In that case, the entire port list and
connection count for that network is lost, and now even a restart of
libvirtd/virtnetworkd/virtqemud, which in the past would resync the
connection count, doesn't help (the network driver thinks there are no
active ports, while the hypervisor driver knows about all the active
ports, but mistakenly believes that the network driver also knows).

The solution to this is to not just bypass valid portids during the
call to virDomainNetworkNotifyActualDevice(). Instead, we query the
network driver about the portid that was preserved in the domain
status, and if it is not registered, we register it.

(NB: while it would technically be correct to just generate a new
portid for these cases, it makes for less churn in portids (and thus
may make troubleshooting simpler) if we make the small fix to
virDomainNetDefActualToNetworkPort() that preserves existing valid
portids rather than unconditionally generating a new one.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoconf: take advantage of VIR_AUTOPTR for virNetworkPortDefPtr
Laine Stump [Mon, 23 Sep 2019 01:03:51 +0000 (21:03 -0400)] 
conf: take advantage of VIR_AUTOPTR for virNetworkPortDefPtr

define a VIR_DEFINE_AUTOPTR_FUNC() to autofree virNetworkPortDefs, and
convert all uses of virNetworkPortDefPtr that are appropriate to use
it.

This coincidentally fixes multiple potential memory leaks (in failure
cases) in networkPortCreateXML()

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovbox_driver.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:46 +0000 (11:56 -0300)] 
vbox_driver.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovbox_common.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:45 +0000 (11:56 -0300)] 
vbox_common.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_driver.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:44 +0000 (11:56 -0300)] 
qemu_driver.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agodriver.c: change URI validation to handle QEMU and vbox case
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:43 +0000 (11:56 -0300)] 
driver.c: change URI validation to handle QEMU and vbox case

The existing QEMU and vbox URI path validation consider
that a privileged user can use both a "/system" and a
"/session" URI. This differs from all the other drivers
that forbids the root user to use "/session" URI.

Let's update virConnectValidateURIPath() to handle these
cases as exceptions, using the already existent 'entityName'
value to handle "QEMU" and "vbox" differently. This allows
us to use the validateURI function in these cases without
changing the existing behavior of other drivers.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agostorage_driver.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:42 +0000 (11:56 -0300)] 
storage_driver.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agosecret_driver.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:41 +0000 (11:56 -0300)] 
secret_driver.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agonode_device_driver.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:40 +0000 (11:56 -0300)] 
node_device_driver.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agobridge_driver.c: virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:39 +0000 (11:56 -0300)] 
bridge_driver.c: virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agointerface_backend_udev.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:38 +0000 (11:56 -0300)] 
interface_backend_udev.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agointerface_backend_netcf.c: use virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:37 +0000 (11:56 -0300)] 
interface_backend_netcf.c: use virConnectValidateURIPath()

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agosrc/driver.c: add virConnectValidateURIPath()
Daniel Henrique Barboza [Thu, 26 Sep 2019 14:56:36 +0000 (11:56 -0300)] 
src/driver.c: add virConnectValidateURIPath()

The code to validate the URI path is repeated across several
files. This patch creates a common validation code to be
used across all of them.

Reviewed-by: Cole Robinson <crobinso@redhat.com>
Suggested-by: Cole Robinson <crobinso@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoconf: utility function to update entry in def->nets array
Laine Stump [Wed, 25 Sep 2019 16:42:51 +0000 (12:42 -0400)] 
conf: utility function to update entry in def->nets array

A virDomainNetDef object in a domain's nets array might contain a
virDomainHostdevDef, and when this is the case, the domain's hostdevs
array will also have a pointer to this embedded hostdev (this is done
so that internal functions that need to perform some operation on all
hostdevs won't leave out the type='hostdev' network interfaces).

When a network device was updated with virDomainUpdateDeviceFlags(),
we were replacing the entry in the nets array (and free'ing the
original) but forgetting about the pointer in the hostdevs array
(which would then point to the now-free'd hostdev contained in the old
net object.) This often resulted in a libvirtd crash.

The solution is to add a function, virDomainNetUpdate(), called by
qemuDomainUpdateDeviceConfig(), that updates the hostdevs array
appropriately along with the nets array.

Resolves: https://bugzilla.redhat.com/1558934

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodomain_conf: Unref video private data in virDomainVideoDefClear()
Michal Privoznik [Thu, 26 Sep 2019 14:17:49 +0000 (16:17 +0200)] 
domain_conf: Unref video private data in virDomainVideoDefClear()

The private data for video definition is created in
virDomainVideoDefNew() and we attempt to free it in
virDomainVideoDefFree(). This seems to work, except
the free function calls clear function which zeroes
out the whole structure and thus virObjectUnref()
which is called on private data does nothing.

2,568 bytes in 107 blocks are definitely lost in loss record 207 of 213
   at 0x4A35476: calloc (vg_replace_malloc.c:752)
   by 0x50A6048: virAllocVar (viralloc.c:346)
   by 0x513CC5A: virObjectNew (virobject.c:243)
   by 0x4DC1DEE: qemuDomainVideoPrivateNew (qemu_domain.c:1337)
   by 0x51A6BD6: virDomainVideoDefNew (domain_conf.c:2831)
   by 0x51B9F06: virDomainVideoDefParseXML (domain_conf.c:15541)
   by 0x51CB761: virDomainDefParseXML (domain_conf.c:21158)
   by 0x51C5973: virDomainDefParseNode (domain_conf.c:21708)
   by 0x51C583A: virDomainDefParse (domain_conf.c:21663)
   by 0x51C58AE: virDomainDefParseFile (domain_conf.c:21688)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agospec: Drop unittest overrides
Cole Robinson [Tue, 24 Sep 2019 17:21:13 +0000 (13:21 -0400)] 
spec: Drop unittest overrides

nodinfotest.c doesn't exist anymore

seclabeltest.c has changed substantially since this behavior was
added to the spec, and in my testing doesn't have any problems
running in mock

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: driver: Remove unused cleanup labels in stats gathering functions
Peter Krempa [Thu, 19 Sep 2019 09:32:09 +0000 (11:32 +0200)] 
qemu: driver: Remove unused cleanup labels in stats gathering functions

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsBlockExportFro...
Peter Krempa [Thu, 19 Sep 2019 09:01:48 +0000 (11:01 +0200)] 
qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsBlockExportFrontend

The macro now became unused so it was deleted.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsBlockExportBac...
Peter Krempa [Thu, 19 Sep 2019 09:01:48 +0000 (11:01 +0200)] 
qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsBlockExportBackendStorage

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsOneBlock
Peter Krempa [Thu, 19 Sep 2019 09:01:48 +0000 (11:01 +0200)] 
qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsOneBlock

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsOneBlockFallback
Peter Krempa [Thu, 19 Sep 2019 09:01:48 +0000 (11:01 +0200)] 
qemu: driver: Stop using QEMU_ADD_BLOCK_PARAM_ULL in qemuDomainGetStatsOneBlockFallback

The open-coded version does not take much more space and additionally we
get rid of the hidden goto.

This also requires us to remove the 'cleanup' section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Use virTypedParamList in the bulk stats gathering functions
Peter Krempa [Thu, 19 Sep 2019 08:36:28 +0000 (10:36 +0200)] 
qemu: Use virTypedParamList in the bulk stats gathering functions

The bulk stats functions are specific as they pass around the list into
many sub-functions and also a substantial amount of the entries uses
formatted names for indexing purposes. This makes them ideal to be
converted to the new virTypedParamList helpers.

Unfortunately given how the functions are used this requires a big-bang
rewrite of all of the calls to add entries to the parameter list.

Given that a substantial simplification is achieved as well as a pretty
significant change to the original code is required some macros which
were used only sporadically were replaced by inline calls rather than
tweaking the macros first and deleting them later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Remove QEMU_ADD_BLOCK_PARAM_LL macro
Peter Krempa [Thu, 15 Aug 2019 09:38:08 +0000 (11:38 +0200)] 
qemu: driver: Remove QEMU_ADD_BLOCK_PARAM_LL macro

Use QEMU_ADD_BLOCK_PARAM_ULL instead since all parameters are now
unsigned.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Don't return anything from qemuDomainBlockStatsGatherTotals
Peter Krempa [Mon, 16 Sep 2019 16:58:25 +0000 (18:58 +0200)] 
qemu: driver: Don't return anything from qemuDomainBlockStatsGatherTotals

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Remove pointless macro QEMU_BLOCK_STAT_TOTAL
Peter Krempa [Mon, 16 Sep 2019 16:57:53 +0000 (18:57 +0200)] 
qemu: driver: Remove pointless macro QEMU_BLOCK_STAT_TOTAL

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Change fields in qemuBlockStats to 'unsigned'
Peter Krempa [Thu, 15 Aug 2019 09:32:28 +0000 (11:32 +0200)] 
qemu: monitor: Change fields in qemuBlockStats to 'unsigned'

None of the fields actually return negative values. The internal
implementation of BlockAcctStats struct in qemu uses uint64_t and the
last place using -1 in libvirt was in the HMP monitor code which was
deleted.

Change the internal type to unsigned long long and ensure that all
public conversions don't overflow.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Refactor cleanup in qemuMonitorJSONGetAllBlockStatsInfo
Peter Krempa [Mon, 16 Sep 2019 14:19:33 +0000 (16:19 +0200)] 
qemu: monitor: Refactor cleanup in qemuMonitorJSONGetAllBlockStatsInfo

Use VIR_AUTOPTR and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Refactor cleanup in qemuMonitorJSONGetOneBlockStatsInfo
Peter Krempa [Mon, 16 Sep 2019 14:19:33 +0000 (16:19 +0200)] 
qemu: monitor: Refactor cleanup in qemuMonitorJSONGetOneBlockStatsInfo

Use VIR_AUTOFREE and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Refactor cleanup in qemuMonitorJSONBlockStatsCollectData
Peter Krempa [Mon, 16 Sep 2019 14:19:33 +0000 (16:19 +0200)] 
qemu: monitor: Refactor cleanup in qemuMonitorJSONBlockStatsCollectData

Use VIR_AUTOFREE and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Remove stale comment for qemuDomainBlockStats
Peter Krempa [Mon, 16 Sep 2019 14:18:21 +0000 (16:18 +0200)] 
qemu: Remove stale comment for qemuDomainBlockStats

We no longer use HMP for this API.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Simplify handling of lists of typed parameters
Peter Krempa [Thu, 19 Sep 2019 07:20:49 +0000 (09:20 +0200)] 
util: typedparam: Simplify handling of lists of typed parameters

Introduce a new set of helpers including a new data structure which
simplifies keeping and construction of lists of typed parameters.

The use of VIR_RESIZE_N in the virTypedParamsAdd API has performance
benefits but requires passing around 3 arguments. Use of them lead to a
set of macros with embedded jumps used in the qemu statistics code.

This patch introduces 'virTypedParamList' type which aggregates the
necessary list-keeping variables and also a new set of functions to add
new typed parameters to a list.

These new helpers use printf-like format string and arguments to format
the argument name as the stats code often uses indexed typed parameters.

The accessor function then allows extracting the typed parameter list in
the same format as virTypedParamsAdd* functions would do.

One additional benefit is also that the list function can easily be used
with VIR_AUTOPTR.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Optionally copy strings passed to virTypedParameterAssignValue
Peter Krempa [Wed, 14 Aug 2019 12:52:46 +0000 (14:52 +0200)] 
util: typedparam: Optionally copy strings passed to virTypedParameterAssignValue

Some code paths already pass in pointers to strings which should be
added directly as the value of the typed parameter. To allow more
universal use of virTypedParameterAssignValue add a flag which allows to
copy the value in place.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Separate code to assign value to typed parameter
Peter Krempa [Wed, 14 Aug 2019 11:00:13 +0000 (13:00 +0200)] 
util: typedparam: Separate code to assign value to typed parameter

The code will be reused in other function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Remove pointless cleanup label from virTypedParameterAssignFromStr
Peter Krempa [Tue, 17 Sep 2019 17:55:37 +0000 (19:55 +0200)] 
util: typedparam: Remove pointless cleanup label from virTypedParameterAssignFromStr

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Move and unexport virTypedParameterAssignFromStr
Peter Krempa [Tue, 17 Sep 2019 17:45:39 +0000 (19:45 +0200)] 
util: typedparam: Move and unexport virTypedParameterAssignFromStr

The function is only used as a helper in virTypedParamsAddFromString.
Make it static and move it to virtypedparam-public.c.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Purge public bits from virTypedParamsGetStringList
Peter Krempa [Tue, 17 Sep 2019 17:35:51 +0000 (19:35 +0200)] 
util: typedparam: Purge public bits from virTypedParamsGetStringList

The function is not exported in the public API thus the error
dispatching is not required.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoutil: typedparam: Split out public APIs into a separate file
Peter Krempa [Tue, 17 Sep 2019 17:21:14 +0000 (19:21 +0200)] 
util: typedparam: Split out public APIs into a separate file

Some of the typed parameter APIs are exported publicly, but the
implementation was intermixed with private functions. Introduce
virtypedparam-public.c, move all public API functions there and purge
the comments stating that some functions are public.

This will decrease the likelihood of messing up the expectations as well
as it will become more clear which of them are actually public.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu_blockjob: Remove secdriver metadata for whole backing chain on job completion
Michal Privoznik [Mon, 16 Sep 2019 10:28:48 +0000 (12:28 +0200)] 
qemu_blockjob: Remove secdriver metadata for whole backing chain on job completion

Turns out, block mirror is not the only job a disk can have. It
can also do commits of one layer into the other. Or possibly some
other tricks too. Problem is that while we set seclabels on given
layers of backing chain when the job is starting (via
qemuDomainStorageSourceAccessAllow()) we don't restore them when
job finishes. This leaves XATTRs set and corresponding images
unusable.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
5 years agodomain_conf: Fix str2enum translation of video driver name
Michal Privoznik [Wed, 25 Sep 2019 07:54:49 +0000 (09:54 +0200)] 
domain_conf: Fix str2enum translation of video driver name

In bc1e924cf0d we've introduced video driver name and whilst
doing so we've utilized VIR_ENUM_IMPL() macro. Then, in domain
XML parsing code the generated
virDomainVideoBackendTypeFromString() is called and its return
value is assigned directly to an unsigned int variable which is
wrong. Also, the video driver enum has 'default' value which is
not formatted into domain XML but is accepted during parsing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: checkpoint: Don't forbid checkpoint when VM is marked for autodestroy
Peter Krempa [Tue, 24 Sep 2019 12:42:27 +0000 (14:42 +0200)] 
qemu: checkpoint: Don't forbid checkpoint when VM is marked for autodestroy

The check was copied from the snapshot code and makes even less sense
here.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: snapshot: Don't forbid snapshot if autodestroy is registered
Peter Krempa [Tue, 24 Sep 2019 12:39:21 +0000 (14:39 +0200)] 
qemu: snapshot: Don't forbid snapshot if autodestroy is registered

Semantically VIR_DOMAIN_START_AUTODESTROY doesn't really clash with
snapshot operations as the VM stays on the same host and thus bound to
the same connection. Saving the state also doesn't differ from modifying
the state of the VM which is allowed.

Remove the check as it doesn't make much sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: migration: Forbid only remote migration if autodestroy is active for VM
Peter Krempa [Tue, 24 Sep 2019 12:59:04 +0000 (14:59 +0200)] 
qemu: migration: Forbid only remote migration if autodestroy is active for VM

Semantically we can't guarantee that we'll be able to destroy the VM on
the remote host, thus we can't allow remote migration. All other forms
of migration (e.g. saving to file) are okay though as they don't clash
with semantics of the flag.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agolib: Lessen restrictions on VIR_DOMAIN_START_AUTODESTROY
Peter Krempa [Tue, 24 Sep 2019 12:55:15 +0000 (14:55 +0200)] 
lib: Lessen restrictions on VIR_DOMAIN_START_AUTODESTROY

Apart from migrating the VM to a remote host where we can't honour the
VIR_DOMAIN_START_AUTODESTROY flag properly, restricting APIs which just
modify the state of the VM does not make much sense.

Change the wording of the documentation for VIR_DOMAIN_START_AUTODESTROY
so that snapshots and saving to a file may be permitted as they
semantically don't clash with the flag itself. Otherwise we'd have to
forbid other APIs, such as virDomainDestroy as well.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agotests: add vhost-user-gpu xml2argv tests
Marc-André Lureau [Mon, 23 Sep 2019 10:44:43 +0000 (14:44 +0400)] 
tests: add vhost-user-gpu xml2argv tests

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: build vhost-user GPU devices
Marc-André Lureau [Mon, 23 Sep 2019 10:44:42 +0000 (14:44 +0400)] 
qemu: build vhost-user GPU devices

For each vhost-user GPUs,
- build a socket chardev, and pass the vhost-user socket to it
- build a vhost-user video device and associate it with the chardev

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: start/stop the vhost-user-gpu external device
Marc-André Lureau [Mon, 23 Sep 2019 10:44:41 +0000 (14:44 +0400)] 
qemu: start/stop the vhost-user-gpu external device

Each vhost-user-gpu needs its own helper gpu process.
Start/stop them, and apply the emulator cgroup controller.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: prepare domain for vhost-user GPU
Marc-André Lureau [Mon, 23 Sep 2019 10:44:40 +0000 (14:44 +0400)] 
qemu: prepare domain for vhost-user GPU

Call qemuExtVhostUserGPUPrepareDomain() to fill the domain with the
location of the vhost-user binary to start.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agotests: wrap vhost-user paths in qemuxml2argvtest
Marc-André Lureau [Mon, 23 Sep 2019 10:44:39 +0000 (14:44 +0400)] 
tests: wrap vhost-user paths in qemuxml2argvtest

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agotests: mock execv/execve
Marc-André Lureau [Mon, 23 Sep 2019 10:44:38 +0000 (14:44 +0400)] 
tests: mock execv/execve

Learn to override the paths to the program to execute (vhost-user
helpers are executed to check for runtime capabilities).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: add vhost-user-gpu helper unit
Marc-André Lureau [Mon, 23 Sep 2019 10:44:37 +0000 (14:44 +0400)] 
qemu: add vhost-user-gpu helper unit

Similar to the qemu_tpm.c, add a unit with a few functions to
start/stop and setup the cgroup of the external vhost-user-gpu
process. See function documentation.

The vhost-user connection fd is set on qemuDomainVideoPrivate struct.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: add qemuDomainVideoPrivate
Marc-André Lureau [Mon, 23 Sep 2019 10:44:36 +0000 (14:44 +0400)] 
qemu: add qemuDomainVideoPrivate

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoconf: add privateData to virDomainVideoDef
Marc-André Lureau [Mon, 23 Sep 2019 10:44:35 +0000 (14:44 +0400)] 
conf: add privateData to virDomainVideoDef

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: add qemuSecurityStartVhostUserGPU helper
Marc-André Lureau [Mon, 23 Sep 2019 10:44:34 +0000 (14:44 +0400)] 
qemu: add qemuSecurityStartVhostUserGPU helper

See function documentation. Used in a following patch.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: add vhost-user helpers
Marc-André Lureau [Mon, 23 Sep 2019 10:44:33 +0000 (14:44 +0400)] 
qemu: add vhost-user helpers

Add qemuVhostUserFetchConfigs() to discover vhost-user helpers.

qemuVhostUserFillDomainGPU() will find the first matching GPU helper
with the required capabilities and set the associated
vhost_user_binary.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: restrict 'virgl=' option to non-vhostuser video type
Marc-André Lureau [Mon, 23 Sep 2019 10:44:32 +0000 (14:44 +0400)] 
qemu: restrict 'virgl=' option to non-vhostuser video type

vhost-user device doesn't have a virgl option, it is passed to the
vhost-user-gpu helper process instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: validate virtio-gpu with vhost-user
Marc-André Lureau [Mon, 23 Sep 2019 10:44:31 +0000 (14:44 +0400)] 
qemu: validate virtio-gpu with vhost-user

Check qemu capability, and accept 3d acceleration. 3d acceleration
support is checked when looking for a suitable vhost-user helper.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
5 years agoqemu: check that qemu is vhost-user-vga capable
Marc-André Lureau [Mon, 23 Sep 2019 10:44:30 +0000 (14:44 +0400)] 
qemu: check that qemu is vhost-user-vga capable

To support virtio VGA with vhost-user, vhost-user-vga device is necessary.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: add vhost-user-gpu capabilities checks
Marc-André Lureau [Mon, 23 Sep 2019 10:44:29 +0000 (14:44 +0400)] 
qemu: add vhost-user-gpu capabilities checks

Those new devices are available since QEMU 4.1.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu-cgroup: allow accel rendernode access
Marc-André Lureau [Mon, 23 Sep 2019 10:44:28 +0000 (14:44 +0400)] 
qemu-cgroup: allow accel rendernode access

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>