]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agoRevert "dbus: correctly build reply message"
Michal Privoznik [Fri, 6 Sep 2019 15:20:40 +0000 (17:20 +0200)]
Revert "dbus: correctly build reply message"

This reverts commit 39dded7bb61444bb608fadd3f82f6fe93d08fd0e.

This commit broke virpolkittest on Ubuntu 18 which has an old
dbus (v1.12.2). Any other distro with the recent one works
(v1.12.16) which hints its a bug in dbus somewhere. Revert the
commit to stop tickling it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
5 years agolib: Define and use autofree for virConfPtr
Michal Privoznik [Mon, 9 Sep 2019 15:56:26 +0000 (17:56 +0200)]
lib: Define and use autofree for virConfPtr

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agolxcParseConfigString: Don't return success if post parse callback fails
Michal Privoznik [Mon, 9 Sep 2019 15:45:28 +0000 (17:45 +0200)]
lxcParseConfigString: Don't return success if post parse callback fails

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_conf: Use more of VIR_AUTOUNREF()
Michal Privoznik [Mon, 9 Sep 2019 15:14:25 +0000 (17:14 +0200)]
qemu_conf: Use more of VIR_AUTOUNREF()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_conf: Use more of VIR_AUTOFREE()
Michal Privoznik [Mon, 9 Sep 2019 15:07:28 +0000 (17:07 +0200)]
qemu_conf: Use more of VIR_AUTOFREE()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_conf: Drop a pair of needless 'cleanup' labels
Michal Privoznik [Mon, 9 Sep 2019 15:24:22 +0000 (17:24 +0200)]
qemu_conf: Drop a pair of needless 'cleanup' labels

There are two 'cleanup' labels - one in
virQEMUDriverConfigHugeTLBFSInit() and the other in
virQEMUDriverConfigSetDefaults() that do nothing more than
return and integer value. No memory freeing or anything important
is done there. Drop them in favour of returning immediately.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu_conf.c: Fix naming of *AddRemove* functions
Michal Privoznik [Mon, 9 Sep 2019 14:58:58 +0000 (16:58 +0200)]
qemu_conf.c: Fix naming of *AddRemove* functions

Our naming rules prefer qemuObjectOperation() scheme rather than
qemuOperationObject() for function names. These were not honoured
in recent commits to qemu_conf.c.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: support unmanaged macvtap devices with <interface type='ethernet'>
Laine Stump [Mon, 26 Aug 2019 17:05:19 +0000 (13:05 -0400)]
qemu: support unmanaged macvtap devices with <interface type='ethernet'>

Traditionally, macvtap devices are supported using <interface
type='direct'>, but that type requires specifying a source device name
and macvtap mode which can't be altered after the initial device
creation (and may not even be available to the management software
that's creating the XML config to feed to libvirt).

But the attributes in the <source> are essentially describing how the
device will be connected to the network, and if libvirt is to be
supplied with the name of a macvtap device that has already been
created, that device will also already be connected to the network
(and the connection can't be changed). Thus it seems more appropriate
to use type='ethernet', which was created explicitly for this purpose
- for devices that have already been (or will be) connected to the
external network by someone/something outside of libvirt. The fact
that it is a *macv*tap rather than a contentional tap device is just a
detail.

This patch supports using an existing macvtap device with <interface
type='ethernet'> by checking the supplied target dev name to see if it
is a macvtap device and, when this is the case, calling
virNetDevMacVLanTapOpen() instead of virNetDevTapCreate(). For
consistency, this is only done when target managed='no'.

Resolves: https://bugzilla.redhat.com/1723367 (partially)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: support unmanaged target tap dev for <interface type='ethernet'>
Laine Stump [Mon, 26 Aug 2019 04:24:34 +0000 (00:24 -0400)]
qemu: support unmanaged target tap dev for <interface type='ethernet'>

If managed='no', then the tap device must already exist, and setting
of MAC address and online status (IFF_UP) is skipped.

NB: we still set IFF_VNET_HDR and IFF_MULTI_QUEUE as appropriate,
because those bits must be properly set in the TUNSETIFF we use to set
the tap device name of the handle we've opened - if IFF_VNET_HDR has
not been set and we set it the request will be honored even when
running libvirtd unprivileged; if IFF_MULTI_QUEUE is requested to be
different than how it was created, that will result in an error from
the kernel. This means that you don't need to pay attention to
IFF_VNET_HDR when creating the tap devices, but you *do* need to set
IFF_MULTI_QUEUE if you're going to use multiple queues for your tap
device.

NB2: /dev/vhost-net normally has permissions 600, so it can't be
opened by an unprivileged process. This would normally cause a warning
message when using a virtio net device from an unprivileged
libvirtd. I've found that setting the permissions for /dev/vhost-net
permits unprivileged libvirtd to use vhost-net for virtio devices, but
have no idea what sort of security implications that has. I haven't
changed libvrit's code to avoid *attempting* to open /dev/vhost-net -
if you are concerned about the security of opening up permissions of
/dev/vhost-net (probably a good idea at least until we ask someone who
knows about the code) then add <driver name='qemu'/> to the interface
definition and you'll avoid the warning message.

Note that virNetDevTapCreate() is the correct function to call in the
case of an existing device, because the same ioctl() that creates a
new tap device will also open an existing tap device.

Resolves: https://bugzilla.redhat.com/1723367 (partially)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: new "managed" attribute for target dev of <interface type='ethernet'>
Laine Stump [Wed, 21 Aug 2019 20:42:41 +0000 (16:42 -0400)]
conf: new "managed" attribute for target dev of <interface type='ethernet'>

Although <interface type='ethernet'> has always been able to use an
existing tap device, this is just a coincidence due to the fact that
the same ioctl is used to create a new tap device or get a handle to
an existing device.

Even then, once we have the handle to the device, we still insist on
doing extra setup to it (setting the MAC address and IFF_UP).  That
*might* be okay if libvirtd is running as a privileged process, but if
libvirtd is running as an unprivileged user, those attempted
modifications to the tap device will fail (yes, even if the tap is set
to be owned by the user running libvirtd). We could avoid this if we
knew that the device already existed, but as stated above, an existing
device and new device are both accessed in the same manner, and
anyway, we need to preserve existing behavior for those who are
already using pre-existing devices with privileged libvirtd (and
allowing/expecting libvirt to configure the pre-existing device).

In order to cleanly support the idea of using a pre-existing and
pre-configured tap device, this patch introduces a new optional
attribute "managed" for the interface <target> element. This
attribute is only valid for <interface type='ethernet'> (since all
other interface types have mandatory config that doesn't apply in the
case where we expect the tap device to be setup before we
get it). The syntax would look something like this:

   <interface type='ethernet'>
      <target dev='mytap0' managed='no'/>
      ...
   </interface>

This patch just adds managed to the grammar and parser for <target>,
but has no functionality behind it.

(NB: when managed='no' (the default when not specified is 'yes'), the
target dev is always a name explicitly provided, so we don't
auto-remove it from the config just because it starts with "vnet"
(VIR_NET_GENERATED_TAP_PREFIX); this makes it possible to use the
same pattern of names that libvirt itself uses when it automatically
creates the tap devices.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: use virXMLFormatElement for interface <target>
Laine Stump [Wed, 21 Aug 2019 02:53:11 +0000 (22:53 -0400)]
conf: use virXMLFormatElement for interface <target>

This will simplify addition of another attribute to the <target> element

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: reorganize qemuInterfaceEthernetConnect()
Laine Stump [Tue, 27 Aug 2019 16:18:35 +0000 (12:18 -0400)]
qemu: reorganize qemuInterfaceEthernetConnect()

This just moves around a few things in qemuInterfaceConnect() with no
functional difference (except that a few failures that would have
previously resulted in a "success" audit log will now properly produce
a "fail" audit). The change is so that adding support for unmanaged
tap/macvtap devices will be more easily reviewable.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: make a couple virNetDevMacVlan*() functions public
Laine Stump [Mon, 26 Aug 2019 05:51:40 +0000 (01:51 -0400)]
util: make a couple virNetDevMacVlan*() functions public

In virNetDevMacVLanOpen(), The "retries" arg has been removed and the
value hardcoded as 10, since previously the function was only called
from one place, so it was always 10.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: new function virNetDevMacVLanIsMacvtap()
Laine Stump [Mon, 26 Aug 2019 05:24:08 +0000 (01:24 -0400)]
util: new function virNetDevMacVLanIsMacvtap()

This function returns T if the given name is a macvtap device. This is
determined by 1) getting the ifindex of the device with that name (if
there is one), and 2) checking for existence of /dev/tapXX, where "XX"
is the ifindex learned in (1).

It's also possible to learn this by getting a netlink dump of the
interface and parsing through it to look for some attributes, but that
is complicated to figure out, takes longer to execute, and I'm lazy.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: Add a baseline test for multifunction pci device use case
Shivaprasad G Bhat [Thu, 29 Aug 2019 19:19:02 +0000 (16:19 -0300)]
tests: Add a baseline test for multifunction pci device use case

There are already good number of test cases with hostdevices,
few have multifunction devices but none having more than one
than one multifunction cards.

This patch adds a case where there are two multifunction cards
and two Virtual functions part of the same XML.

0001:01:00.X & 0005:09:00.X - are Multifunction PCI cards.
0000:06:12.[5|6] - are SRIOV Virtual functions

Future commits will improve on automatically detecting the
multifunction cards and auto-assinging the addresses
appropriately.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirpcimock.c: simplify getrealpath() usage
Daniel Henrique Barboza [Thu, 29 Aug 2019 19:19:01 +0000 (16:19 -0300)]
virpcimock.c: simplify getrealpath() usage

Previous patch had to add '/sys/kernel/' prefix in opendir() because
the path, which is being mocked, wasn't being considered due to
an 'if SYSFS_PCI_PREFIX' guarding the call to getrealpath().

In fact, all current getrealpath() callers are guarding it with a
conditional to ensure that the function will never be called with
a non-mocked path. In this case, an extra non-NULL verification is
needed for the 'newpath' string to use the variable - which is
counterintuitive, given that getrealpath() will always write the
'newpath' string in any non-error conditon.

However, simply removing the guard of all getrealpath() instances
causes an abort in init_env(). This happens because tests will
execute access() to non-mocked paths even before the
LIBVIRT_FAKE_ROOT_DIR variable is declared in the test files. We
don't need 'fakerootdir' to be created at this point though.

This patch does the following changes to simplify getrealpath()
usage:

- getrealpath() will now guard the init_env() call by checking if
both fakeroot isn't created and the required path is being mocked.
This ensures that we're not failing inside init_env() because
we're too early and LIBVIRT_FAKE_ROOT_DIR wasn't defined yet;

- remove all conditional guards to call getrealpath() from
access(), virMockStatRedirect(), open(), open_2(), opendir()
and virFileCanonicalizePath(). As a bonus, remove all ternary
conditionals with 'newpath';

- a new 'pathPrefixIsMocked()' helper to aggregate all the prefixes
we're mocking, making it easier to add/remove them. If a prefix
is added inside this function, we can be sure that all functions
are mocking them.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: Add test case for QEMU pci-hostdev hotplug
Shivaprasad G Bhat [Thu, 29 Aug 2019 19:19:00 +0000 (16:19 -0300)]
tests: Add test case for QEMU pci-hostdev hotplug

This patch adds hostdev test cases in qemuhotplugtest.c.

Note: the small tweak inside virpcimock.c was needed because
the new tests added a code path in which virHostHasIOMMU()
(virutil.c) started being called, and the mocked '/sys/kernel/'
prefix that is mocked in virpcimock.c wasn't being considered
in the opendir() mock. An alternative to avoid these situations
in virpcimock.c is implemented in the next patch.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirpcimock: Mock the SRIOV Virtual functions
Shivaprasad G Bhat [Thu, 29 Aug 2019 19:18:59 +0000 (16:18 -0300)]
virpcimock: Mock the SRIOV Virtual functions

The softlink to physfn is the way to know if the device is
VF or not. So, the patch softlinks 'physfn' to the parent function.
The multifunction PCI devices dont have 'physfn' softlinks.

The patch adds few Virtual functions to the mock environment and
changes the existing VFIO test xmls using the VFs to use the newly
added VFs for their use case.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirpcimock.c: mock /dev/vfio
Daniel Henrique Barboza [Thu, 29 Aug 2019 19:18:58 +0000 (16:18 -0300)]
virpcimock.c: mock /dev/vfio

This patch adds mock of the /dev/vfio path, needed for proper
implementation of the support for multifunction/multiple devices
per iommu groups.

To do that, the existing bind and unbind operations were adapted
to operate with the mocked filesystem as well.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Adjust max memlock on mdev hotplug
Eric Farman [Tue, 3 Sep 2019 20:09:48 +0000 (22:09 +0200)]
qemu: Adjust max memlock on mdev hotplug

When starting a domain, we use the presence of a vfio-pci or
mdev hostdev to determine if the memlock maximum needs to be
increased.  But if we hotplug either of these devices, only the
vfio-pci path gets that love.  This means that attaching a, say,
vfio-ccw device will appear to succeed but the device may be
unusable as the guest may see I/O errors on long CCW chains.
The host, meanwhile, would be flooded with these messages:

  vfio_pin_page_external: Task qemu-system-s39 (11584) RLIMIT_MEMLOCK (65536) exceeded

Let's adjust the maximum memlock value in the mdev hotplug path,
so that the domain has the same value as if it were started with
one or more mdev devices in its configuration.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: Reset the maximum locked memory on hotplug fail
Eric Farman [Tue, 3 Sep 2019 20:09:47 +0000 (22:09 +0200)]
qemu: Reset the maximum locked memory on hotplug fail

If attaching a PCI hostdev fails, there are several things that
need to be un-done as part of the cleanup.  One thing that is
not done is re-calculating/re-setting the maximum amount of locked
memory for the domain, since we may have changed that.

Let's fix that, just to ensure everything is back the way it was.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: Refactor the max memlock routine
Eric Farman [Tue, 3 Sep 2019 20:09:46 +0000 (22:09 +0200)]
qemu: Refactor the max memlock routine

Let's pull this hunk out into a function, so it can be reused
in another codepath that needs to do the same thing.

Signed-off-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agovirhostdev: Don't unref @pcidevs twice
Michal Privoznik [Mon, 9 Sep 2019 14:20:07 +0000 (16:20 +0200)]
virhostdev: Don't unref @pcidevs twice

In f08e6883cb4 I've made @pcidevs in
virHostdevReAttachPCIDevices() to be automatically unrefed using
VIR_AUTOUNREF() but I forgot to remove the line that explicitly
unrefs the object at the end of the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodocs: remove devhelp API docs
Daniel P. Berrangé [Thu, 5 Sep 2019 12:07:59 +0000 (13:07 +0100)]
docs: remove devhelp API docs

We currently generate two completely separate API references for the
libvirt public API. One at 'docs/html/' and one at 'docs/devhelp/'.
Both are published on the website, but we only link to content in
the 'docs/html/' pages.

Both are installed in the libvirt-docs sub-RPM, with a full copy
of the website including 'docs/html/' in /usr/share/docs/libvirt-docs,
while the 'docs/devhelp/' content goes to /usr/share/gtk-doc/. The
latter was broken for years until:

  commit ca6f602546cb28658db05f29bc840e04d22d0947
  Author: Andrea Bolognani <abologna@redhat.com>
  Date:   Fri May 10 14:54:52 2019 +0200

    docs: Introduce $(devhelphtml_generated)

    Our XSLT magic generates one Devhelp-compatible HTML file
    per documentation module, but so far we have only shipped
    and installed documentation for virterror.

    Now that we have $(modules), however, we can generate the
    list of files the same way we do for regular documentation
    and make sure we always ship and install everything.

That this bug went unnoticed for so long is a sign of how few
people are using the devhelp docs. The only commits to the devhelp
code since it was first introduced have been fixing various build
problems that hit.

The only obvious difference between the two sets of docs is the CSS
styling in use. Overall devhelp does not look compelling enough to
justify having two duplicated sets of API docs. Eliminating it will
reduce the amount of XSL code we are carrying in the tree which is
an attractive benefit.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal
Daniel Henrique Barboza [Tue, 3 Sep 2019 23:06:07 +0000 (20:06 -0300)]
qemu_conf.c: introduce qemuAddRemoveSharedDeviceInternal

After the previous commits, qemuAddSharedDevice() and
qemuRemoveSharedDevice() are now the same code with a different
flag to call the internal functions.

This patch aggregates the common code into a new function called
qemuAddRemoveSharedDeviceInternal() to further reduce
code repetition. Both qemuAddSharedDevice() and
qemuRemoveSharedDevice() are kept since they are public
functions used elsewhere.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu_conf.c: introduce qemuAddRemoveSharedDiskInternal
Daniel Henrique Barboza [Tue, 3 Sep 2019 23:06:06 +0000 (20:06 -0300)]
qemu_conf.c: introduce qemuAddRemoveSharedDiskInternal

Following the same idea of avoid code repetition from the
previous patch, this commit introduces a new function that
aggregates the functions of qemuAddSharedDisk() and
qemuRemoveSharedDisk() into a single place, using a flag to
switch between add/remove operations.

Both qemuAddSharedDisk() and qemuRemoveSharedDisk() are
public, so keep them around to avoid changing other files
due to an internal qemu_conf.c refactory.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu_conf.c: introduce qemuAddRemoveSharedHostdevInternal
Daniel Henrique Barboza [Tue, 3 Sep 2019 23:06:05 +0000 (20:06 -0300)]
qemu_conf.c: introduce qemuAddRemoveSharedHostdevInternal

qemuAddSharedHostdev() has a code similar to
qemuRemoveSharedHostdev(), with exception of one line that
defines the operation (add or remove).

This patch introduces a new function that aggregates the common
code, using a flag to switch between the operations, avoiding
code repetition.

No functional change was made.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoqemu: update threading info about domain object refs
Jonathon Jongsma [Wed, 4 Sep 2019 17:23:30 +0000 (12:23 -0500)]
qemu: update threading info about domain object refs

Since commit fd9ef3b31e, virDomainFindByUUIDRef() no longer exists and
all virDomainObjListFindBy*() functions now increment the reference
count.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
5 years agoremote: fix UNIX socket path being incorrectly built for libvirtd
eater [Fri, 6 Sep 2019 21:36:17 +0000 (23:36 +0200)]
remote: fix UNIX socket path being incorrectly built for libvirtd

As a result of changes in

      commit d5f0c1b6dd51f0fbab2f8a25733c55d8be6b937b
      Author: Daniel P. Berrangé <berrange@redhat.com>
      Date:   Thu Jul 18 12:30:22 2019 +0100

        remote: stop trying to print help as giant blocks of text

The socket path built would be libvirt//var/run/libvirt-sock
instead of /var/run/libvirt/libvirt-sock. Fortunately this only
affects users who have set the 'unix_sock_dir' config parameter
in /etc/libvirt/libvirtd.conf, which is pretty rare/unusual.

Signed-off-by: eater <=@eater.me>
Exception made for the psuedonym above since patch is considered
trivial & thus non-copyrightable material.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agolib: Grab write lock when modifying list of domains
Michal Privoznik [Fri, 6 Sep 2019 11:59:59 +0000 (13:59 +0200)]
lib: Grab write lock when modifying list of domains

In some places where virDomainObjListForEach() is called the
passed callback calls virDomainObjListRemoveLocked(). Well, this
is unsafe, because the former only grabs a read lock but the
latter modifies the list.
I've identified the following unsafe calls:

- qemuProcessReconnectAll()
- libxlReconnectDomains()

The rest seem to be safe.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirdomainobjlist: Document virDomainObjListForEach()
Michal Privoznik [Fri, 6 Sep 2019 11:50:39 +0000 (13:50 +0200)]
virdomainobjlist: Document virDomainObjListForEach()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirsh: Fix help for net-port-delete
Jonathon Jongsma [Tue, 3 Sep 2019 16:47:29 +0000 (11:47 -0500)]
virsh: Fix help for net-port-delete

Apparently a copy/paste error. The net-port-delete help string was in
fact from net-port-dumpxml.

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
5 years agoqemu_slirp: Drop unused variable in qemuSlirpStart()
Michal Privoznik [Fri, 6 Sep 2019 12:14:21 +0000 (14:14 +0200)]
qemu_slirp: Drop unused variable in qemuSlirpStart()

The @cmdstr variable is not used really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
5 years agolibxl: Fix libxlDomainPMSuspendForDuration domain active check
Marek Marczykowski-Górecki [Fri, 6 Sep 2019 14:12:55 +0000 (16:12 +0200)]
libxl: Fix libxlDomainPMSuspendForDuration domain active check

virDomainObjCheckActive() returns -1 if domain is not active, not 0.

Fixes cb50436c6f "libxl: implement virDomainPM* functions"
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
5 years agoutil: Set backing file name for LOOP_GET_STATUS64 queries.
Julio Faracco [Mon, 2 Sep 2019 17:00:27 +0000 (14:00 -0300)]
util: Set backing file name for LOOP_GET_STATUS64 queries.

This is an issue for LXC loop devices when you are trying to get loop
devices info using `ioctl`. Modern apps uses `/sys/dev/block` to grab
information about devices, but if you use the method mention you won't
be able to retrive the associated file with that loop device. See
example below from cryptsetup sources:

    static char *_ioctl_backing_file(const char *loop)
    {
        struct loop_info64 lo64 = {0};
        int loop_fd;

        loop_fd = open(loop, O_RDONLY);
        if (loop_fd < 0)
            return NULL;

        if (ioctl(loop_fd, LOOP_GET_STATUS64, &lo64) < 0) {
            close(loop_fd);
            return NULL;
        }

        lo64.lo_file_name[LO_NAME_SIZE-2] = '*';
        lo64.lo_file_name[LO_NAME_SIZE-1] = 0;

        close(loop_fd);
        return strdup((char*)lo64.lo_file_name);
    }

It will return an empty string because lo_file_name was not set.
Function `virFileLoopDeviceOpenSearch()` is using `ioctl` to query data,
but it is not checking `lo_file_name` field.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
5 years agotests: add slirp-helper qemuxml2argv test
Marc-André Lureau [Thu, 8 Aug 2019 14:55:14 +0000 (18:55 +0400)]
tests: add slirp-helper qemuxml2argv test

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-hotplug: handle hotplugging of slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:13 +0000 (18:55 +0400)]
qemu-hotplug: handle hotplugging of slirp-helper

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-process: prepare slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:12 +0000 (18:55 +0400)]
qemu-process: prepare slirp-helper

When the network interface is of "user" type, and QEMU has the "-net
socket,fd=" datagram support, call qemuInterfacePrepareSlirp() to
probe and associate a slirp-helper with the interface.

The usage of automated slirp-helper can be prevented with
disableSlirp (in particular when resuming a
VM that didn't start with slirp-helper before).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-command: use -net socket, fd= with slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:11 +0000 (18:55 +0400)]
qemu-command: use -net socket, fd= with slirp-helper

If a slirp-helper is associated with a network interface (after
probing & preparing succesfully), pass the socket fd to QEMU and use
"-net socket,fd=".

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-extdevice: prepare, start and stop slirp-helper
Marc-André Lureau [Thu, 8 Aug 2019 14:55:10 +0000 (18:55 +0400)]
qemu-extdevice: prepare, start and stop slirp-helper

If a slirp-helper is associated with a network interface,
prepare/start/stop the process via qemu-extdevice.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-migration: prevent migration if slirp cannot be migrated
Marc-André Lureau [Thu, 8 Aug 2019 14:55:09 +0000 (18:55 +0400)]
qemu-migration: prevent migration if slirp cannot be migrated

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-migration: prevent migration if dbus-vmstate is required
Marc-André Lureau [Thu, 8 Aug 2019 14:55:08 +0000 (18:55 +0400)]
qemu-migration: prevent migration if dbus-vmstate is required

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add a flag to the cookie to prevent slirp-helper setup
Marc-André Lureau [Thu, 8 Aug 2019 14:55:07 +0000 (18:55 +0400)]
qemu: add a flag to the cookie to prevent slirp-helper setup

For VM started and migrated/saved without slirp-helpers, let's prevent
the automatic setup (as it would fail to migrate otherwise).

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-domain: save and restore slirp state
Marc-André Lureau [Thu, 8 Aug 2019 14:55:06 +0000 (18:55 +0400)]
qemu-domain: save and restore slirp state

Save & restore the slirp helper PID associated with a network
interface & the probed features.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add slirp helper unit
Marc-André Lureau [Thu, 8 Aug 2019 14:55:05 +0000 (18:55 +0400)]
qemu: add slirp helper unit

The unit provides the functions associated with a slirp-helper:
- probing / checking capabilities
- opening the socketpair
- starting / stoping the helper
- registering for dbus-vmstate migration

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-conf: add slirp state dir
Marc-André Lureau [Thu, 8 Aug 2019 14:55:04 +0000 (18:55 +0400)]
qemu-conf: add slirp state dir

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-conf: add configurable slirp-helper location
Marc-André Lureau [Thu, 8 Aug 2019 14:55:03 +0000 (18:55 +0400)]
qemu-conf: add configurable slirp-helper location

A slirp helper is a process that provides user-mode networking through
a unix domain socket. It is expected to follow the following
specification:
https://gitlab.freedesktop.org/slirp/libslirp-rs/blob/master/src/bin/README.rst

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add qemuDomainNetworkPrivate
Marc-André Lureau [Thu, 8 Aug 2019 14:55:02 +0000 (18:55 +0400)]
qemu: add qemuDomainNetworkPrivate

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodomain-conf: add network def private data
Marc-André Lureau [Thu, 8 Aug 2019 14:55:01 +0000 (18:55 +0400)]
domain-conf: add network def private data

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add dbus-vmstate
Marc-André Lureau [Thu, 8 Aug 2019 14:55:00 +0000 (18:55 +0400)]
qemu: add dbus-vmstate

Add dbusVMStates to keep a list of dbus-vmstate objects needed for
migration. They are populated on the command line during start or
qemuDBusVMStateAdd/Remove() will hotplug them as needed.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu-security: add qemuSecurityCommandRun()
Marc-André Lureau [Thu, 8 Aug 2019 14:54:59 +0000 (18:54 +0400)]
qemu-security: add qemuSecurityCommandRun()

Add a generic way to run a command through the security management.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: reset VM id after external devices stop
Marc-André Lureau [Thu, 8 Aug 2019 14:54:58 +0000 (18:54 +0400)]
qemu: reset VM id after external devices stop

pid filenames (from swtpm and other helpers from this series) are
based on VM shortname, which is derived from VM id. If the id is reset
to early, the state filenames will not be found.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add dbus-vmstate capability
Marc-André Lureau [Thu, 8 Aug 2019 14:54:57 +0000 (18:54 +0400)]
qemu: add dbus-vmstate capability

This object is being proposed to qemu upstream "Add dbus-vmstate
object". It handles data migration of external processes.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: add socket datagram capability
Marc-André Lureau [Thu, 8 Aug 2019 14:54:56 +0000 (18:54 +0400)]
qemu: add socket datagram capability

Datagram socket is available since qemu 4.0, commit
fdec16e3c2a614e2861f3086b05d444b5d8c3406 ("net/socket: learn to talk
with a unix dgram socket").

Required for slirp-helper communication.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: replace logCtxt with qemuDomainLogAppendMessage()
Marc-André Lureau [Thu, 8 Aug 2019 14:54:55 +0000 (18:54 +0400)]
qemu: replace logCtxt with qemuDomainLogAppendMessage()

Once QEMU is started, the qemuDomainLogContext is owned by it, and can
no longer be used from libvirt. Instead, use
qemuDomainLogAppendMessage() which will redirect the log.

This is not strictly necessary for swtpm, but the following patches
are going to reuse qemuExtDeviceLogCommand().

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agodbus: correctly build reply message
Marc-André Lureau [Thu, 8 Aug 2019 14:54:54 +0000 (18:54 +0400)]
dbus: correctly build reply message

dbus_message_new() does not construct correct replies by itself, it is
recommended to use dbus_message_new_method_return() instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: fix xml2xml tpm-emulator.xml test
Marc-André Lureau [Thu, 8 Aug 2019 14:54:53 +0000 (18:54 +0400)]
tests: fix xml2xml tpm-emulator.xml test

It is failing, because it ends up being parsed with version='default'
and expects '1.2' instead.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoAdd .editorconfig
Marc-André Lureau [Thu, 8 Aug 2019 14:54:52 +0000 (18:54 +0400)]
Add .editorconfig

Consistent code style across editors.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: qapi: Limit traversal depth for QAPI schema queries
Peter Krempa [Mon, 12 Aug 2019 16:31:44 +0000 (18:31 +0200)]
qemu: qapi: Limit traversal depth for QAPI schema queries

Implicitly the query depth is limited by the length of the QAPI schema
query, but 'alternate' and 'array' QAPI meta-types don't consume a part
of the query string thus a loop on such types would get our traversal
code stuck in an infinite loop. Prevent this from happening by limiting
the nesting depth to 1000.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: maintain user alias for video type 'none'
Jonathon Jongsma [Thu, 5 Sep 2019 16:17:38 +0000 (11:17 -0500)]
qemu: maintain user alias for video type 'none'

After parsing a video device with a model type of
VIR_DOMAIN_VIDEO_TYPE_NONE, all device info is cleared (see
virDomainDefPostParseVideo()) in order to avoid formatting any
auto-generated values for the XML. Subsequently, however, an alias is
generated for the video device (e.g. 'video0'), which results in an
alias property being formatted in the XML output anyway. This creates
confusion if the user has explicitly provided an alias for the video
device since the alias will change.

To avoid this, don't clear the user-defined alias for video devices of
type "none".

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agovircgroupv2: fix setting cpu.max period
Pavel Hrdina [Thu, 5 Sep 2019 09:22:11 +0000 (11:22 +0200)]
vircgroupv2: fix setting cpu.max period

When we set cpu.max period we need to parse the cpu.max file first as
it contains both quota and period values separated by space.  When only
a single number is written to that file it will set quota.  However,
in order to change period we need to write both values.

The code was prepared for that but mistakenly used new line to end the
string with the first value.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
5 years agoqemu: migration: Switch to blockdev mode for non-shared storage migration
Peter Krempa [Wed, 4 Sep 2019 11:20:41 +0000 (13:20 +0200)]
qemu: migration: Switch to blockdev mode for non-shared storage migration

When blockdev is used we always should use the blockdev mode for
non-shared storage migration.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopy
Peter Krempa [Wed, 4 Sep 2019 10:23:16 +0000 (12:23 +0200)]
qemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopy

Use VIR_AUTOUNREF and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopyDriveMirror
Peter Krempa [Wed, 4 Sep 2019 10:23:16 +0000 (12:23 +0200)]
qemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopyDriveMirror

Use VIR_AUTOFREE and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopyBlockdev
Peter Krempa [Wed, 4 Sep 2019 10:23:16 +0000 (12:23 +0200)]
qemu: migration: Refactor cleanup in qemuMigrationSrcNBDStorageCopyBlockdev

Remove the cleanup label as it's empty.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: Defer support checks for external active snapshots to blockdev code or qemu
Peter Krempa [Tue, 13 Aug 2019 11:37:17 +0000 (13:37 +0200)]
qemu: Defer support checks for external active snapshots to blockdev code or qemu

Remove libvirt's support check for the target of an external snapshot to
the blockdev code or qemu. This will potentially require a more complex
cleanup but removes a level of hardcoded feature checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Add -blockdev support for external snapshots
Peter Krempa [Mon, 17 Dec 2018 17:31:29 +0000 (18:31 +0100)]
qemu: Add -blockdev support for external snapshots

Use the code for creating or attaching new storage source in the
snapshot code and switch to 'blockdev-snapshot' for creating the
snapshot itself.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: snapshot: Skip overlay file creation/interogation if unsupported
Peter Krempa [Tue, 13 Aug 2019 10:23:00 +0000 (12:23 +0200)]
qemu: snapshot: Skip overlay file creation/interogation if unsupported

With blockdev we'll be able to support protocols which are not supported
by the storage backends in libvirt. This means that we have to be able
to skip the creation and relative storage path reading if it's not
supported. This will make it impossible to use relative backing for
network protocols but that would be almost insane anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Merge use of 'reuse' flag in qemuDomainSnapshotDiskPrepareOne
Peter Krempa [Tue, 13 Aug 2019 10:28:00 +0000 (12:28 +0200)]
qemu: Merge use of 'reuse' flag in qemuDomainSnapshotDiskPrepareOne

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Disband qemuDomainSnapshotCreateSingleDiskActive
Peter Krempa [Mon, 12 Aug 2019 13:11:36 +0000 (15:11 +0200)]
qemu: Disband qemuDomainSnapshotCreateSingleDiskActive

After we always assume support for the 'transaction' command
(c358adc57113b) and follow-up cleanups
qemuDomainSnapshotCreateSingleDiskActive lost its value. Move the code
into appropriate helpers and remove the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: snapshot: Rename external disk snapshot handling functions
Peter Krempa [Wed, 28 Aug 2019 15:20:36 +0000 (17:20 +0200)]
qemu: snapshot: Rename external disk snapshot handling functions

Fix and unify the naming of external snapshot preparation functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: snapshot: Move error preservation to qemuDomainSnapshotDiskDataCleanup
Peter Krempa [Wed, 28 Aug 2019 07:33:27 +0000 (09:33 +0200)]
qemu: snapshot: Move error preservation to qemuDomainSnapshotDiskDataCleanup

Make qemuDomainSnapshotDiskDataCleanup cleanup section friendly by
moving the error preservation code inside it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: snapshot: Save status and config XMLs only on success
Peter Krempa [Wed, 28 Aug 2019 07:31:28 +0000 (09:31 +0200)]
qemu: snapshot: Save status and config XMLs only on success

We changed to always saving the status and config XMLs to simplify
code. After a few more refactors it's now possible to move it to the
appropriate place and save the XMLs only on success again.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: snapshot: Fix image lock handling when taking a snapshot
Peter Krempa [Wed, 28 Aug 2019 07:30:33 +0000 (09:30 +0200)]
qemu: snapshot: Fix image lock handling when taking a snapshot

When we take a snapshot we must properly remove our locking
infrastructure locks. This was broken by commit 3817fa10c4ad9 which
attempted to properly track the readonly state for the image as the
locking code was executed after this change. Since we forced the image
which was locked as read-write to read-only prior to unlocking it the
write lock was not dropped.

Fix it by moving the locking code prior to modifying the readonly flag.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: driver: Fix shallow non-reuse block copy
Peter Krempa [Tue, 3 Sep 2019 12:26:20 +0000 (14:26 +0200)]
qemu: driver: Fix shallow non-reuse block copy

The code preparing data for creating/attaching the target image of block
copy didn't use the correct reference to the existing backing chain in
case when the copy should inherit it. This meant that qemu actually
opened a second copy of the chain and operated on that.

This would de-sync qemu from libvirt's view of node names. Luckily this
is only hypothetical at this point since it happens only when -blockdev
is enabled.

Fix it by passing 'mirrorBacking' which has the proper data as the
backing store when calling
qemuBuildStorageSourceChainAttachPrepareBlockdevTop.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Explicitly pass backing store to qemuBuildStorageSourceChainAttachPrepareBlockd...
Peter Krempa [Tue, 3 Sep 2019 12:22:41 +0000 (14:22 +0200)]
qemu: Explicitly pass backing store to qemuBuildStorageSourceChainAttachPrepareBlockdevTop

In some cases we'll need to pass in a backing store which is not
recorded as the backing store of @src. Export backingStore as variable
and fix all callers to pass in the backing store. No semantic changes
for now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: explicitly pass backing store to qemuBlockStorageSourceAttachPrepareBlockdev
Peter Krempa [Tue, 3 Sep 2019 11:58:34 +0000 (13:58 +0200)]
qemu: block: explicitly pass backing store to qemuBlockStorageSourceAttachPrepareBlockdev

Pass backing store as an argument rather than extracting it locally and
fix the callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: command: Refactor qemuBuildStorageSourceChainAttachPrepareBlockdevInternal
Peter Krempa [Tue, 3 Sep 2019 11:43:57 +0000 (13:43 +0200)]
qemu: command: Refactor qemuBuildStorageSourceChainAttachPrepareBlockdevInternal

Extract the loop and supporting infrastructure to the caller as only one
of the two callers actually cares about looping and rename the helper to
qemuBuildStorageSourceChainAttachPrepareBlockdevOne.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: Explicitly specify backingStore when creating format layer props
Peter Krempa [Tue, 3 Sep 2019 11:27:52 +0000 (13:27 +0200)]
qemu: block: Explicitly specify backingStore when creating format layer props

Pass in backing store explicitly to qemuBlockStorageSourceGetBlockdevProps
and fix the callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: Unify conditions to format backing store of format node definition
Peter Krempa [Tue, 3 Sep 2019 11:16:39 +0000 (13:16 +0200)]
qemu: block: Unify conditions to format backing store of format node definition

Move all bits of the formatting of the 'backing' attribute to a single
condition and make it use a single extracted copy of the backing store.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Prevent storage causing too much nested XML
Peter Krempa [Wed, 4 Sep 2019 14:58:08 +0000 (16:58 +0200)]
qemu: Prevent storage causing too much nested XML

Since libvirt stores the backing chain into the XML in a nested way it
is the prime possibility to hit libxml2's parsing limit of 256 layers.

Introduce code which will crawl the backing chain and verify that it's
not too deep. The maximum nesting is set to 200 layers so that there's
still some space left for additional properties or nesting into snapshot
XMLs.

The check is applied to all disk use cases (starting, hotplug, media
change) as well as block copy which changes image and snapshots.

We simply report an error and refuse the operation.

Without this check a restart of libvirtd would result in the status XML
failing to be parsed and thus losing the VM.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: domain: Refactor cleanup in qemuDomainDetermineDiskChain
Peter Krempa [Wed, 4 Sep 2019 13:18:37 +0000 (15:18 +0200)]
qemu: domain: Refactor cleanup in qemuDomainDetermineDiskChain

Use VIR_AUTOUNREF 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: hotplug: Setup disk throttling with blockdev
Peter Krempa [Thu, 5 Sep 2019 13:09:50 +0000 (15:09 +0200)]
qemu: hotplug: Setup disk throttling with blockdev

With blockdev we must issue the block_set_io_throttle QMP command to
setup disk throttling as we currently can't do it with the 'throttle'
layer.

Unfortunately there's nothing we can do if it fails.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: hotplug: Use VIR_AUTOFREE in qemuDomainAttachDiskGeneric
Peter Krempa [Thu, 5 Sep 2019 12:48:20 +0000 (14:48 +0200)]
qemu: hotplug: Use VIR_AUTOFREE in qemuDomainAttachDiskGeneric

Get rid of the last manually freed var.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: hotplug: Simplify cleanup in qemuDomainChangeMediaLegacy
Peter Krempa [Thu, 5 Sep 2019 12:47:10 +0000 (14:47 +0200)]
qemu: hotplug: Simplify cleanup in qemuDomainChangeMediaLegacy

Switch to using VIR_AUTOFREE and remove the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Fix qemuDomainObjTaint with virtlogd
Jiri Denemark [Thu, 5 Sep 2019 13:35:35 +0000 (15:35 +0200)]
qemu: Fix qemuDomainObjTaint with virtlogd

When virtlogd is used to capture QEMU's stdout, qemuDomainObjTaint would
always fail to write the message to the log file when QEMU is already
running (i.e., outside qemuProcessLaunch). This can happen during device
hotplug or by sending a custom QEMU guest agent command:

    warning : qemuDomainObjTaint:8757 : Domain id=9 name='blaf'
        uuid=9cfa4e37-2930-405b-bcb4-faac1829dad8 is tainted:
        custom-ga-command
    error : virLogHandlerDomainOpenLogFile:388 : Cannot open log file:
        '/var/log/libvirt/qemu/blaf.log': Device or resource busy
    error : virNetClientProgramDispatchError:172 : Cannot open log file:
        '/var/log/libvirt/qemu/blaf.log': Device or resource busy

The fix is easy, we just need to use the right API for appending a
message to QEMU log file instead of creating a new log context.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: domain: Fix tpm <encryption> comment
Cole Robinson [Wed, 4 Sep 2019 17:32:31 +0000 (13:32 -0400)]
conf: domain: Fix tpm <encryption> comment

The attribute is named 'secret', not 'uuid'

Signed-off-by: Cole Robinson <crobinso@redhat.com>
5 years agonews: rewording wrt NSS, virt-login-shell & split daemons
Daniel P. Berrangé [Tue, 3 Sep 2019 15:12:03 +0000 (16:12 +0100)]
news: rewording wrt NSS, virt-login-shell & split daemons

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: monitor: Fix formatting of 'offset' in qemuMonitorJSONSaveMemory
Peter Krempa [Fri, 30 Aug 2019 14:37:46 +0000 (16:37 +0200)]
qemu: monitor: Fix formatting of 'offset' in qemuMonitorJSONSaveMemory

The offset is unsigned long long thus 'U' must be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: qemublock: Use bigger numbers as dummy capacity/physical
Peter Krempa [Fri, 30 Aug 2019 14:36:15 +0000 (16:36 +0200)]
tests: qemublock: Use bigger numbers as dummy capacity/physical

Actually test that the full range is available.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: block: Use correct type when creating image size JSON entries
Peter Krempa [Fri, 30 Aug 2019 14:33:48 +0000 (16:33 +0200)]
qemu: block: Use correct type when creating image size JSON entries

The 'u' modifier creates an unsigned int JSON attribute but the disk size
and capacity fields are unsigned long long. If the size of the created
image would be more than 4GiB we'd overflow and create sub-4G image.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agonews: Mention removal of xenapi driver
Jim Fehlig [Tue, 3 Sep 2019 04:46:00 +0000 (22:46 -0600)]
news: Mention removal of xenapi driver

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoxenapi: remove driver
Jim Fehlig [Tue, 3 Sep 2019 04:24:00 +0000 (22:24 -0600)]
xenapi: remove driver

The xenapi driver has not seen any development since its initial
contribution 9 years ago. There have been no bug reports, no patches,
and no queries about the driver on the developer or user mailing lists.
Remove the driver from the libvirt sources.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agomaint: Post-release version bump to 5.8.0
Jim Fehlig [Tue, 3 Sep 2019 21:19:22 +0000 (15:19 -0600)]
maint: Post-release version bump to 5.8.0

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
5 years agoRelease of libvirt 5.7.0
Daniel Veillard [Tue, 3 Sep 2019 15:19:02 +0000 (17:19 +0200)]
Release of libvirt 5.7.0

* docs/news.xml: updated for release

Signed-off-by: Daniel Veillard <veillard@redhat.com>
5 years agonews: document new libxml version requirement
Daniel P. Berrangé [Tue, 3 Sep 2019 12:24:27 +0000 (13:24 +0100)]
news: document new libxml version requirement

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: domain: Fix potential NULL deref when parsing job private data
Peter Krempa [Mon, 2 Sep 2019 14:11:46 +0000 (16:11 +0200)]
qemu: domain: Fix potential NULL deref when parsing job private data

A specially crafted XML which would reference a non-existing disk but
request the mirror to be registered with the blockjob could potentially
make the parser dereference NULL. Fix it by moving the code slightly and
just treat it as a wrong job XML. Found by Coverity.

Reported-by: John Ferlan <jferlan@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
5 years agonews: Update for 5.7.0 release
Michal Privoznik [Tue, 3 Sep 2019 12:09:06 +0000 (14:09 +0200)]
news: Update for 5.7.0 release

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agonews: Rename --precopy-bandwidth migration option
Jiri Denemark [Mon, 2 Sep 2019 15:00:32 +0000 (17:00 +0200)]
news: Rename --precopy-bandwidth migration option

The (pre-copy) bandwidth was historically the only bandwidth we
supported and thus it is called just "bandwidth" in all other places.
E.g., virsh migrate-setspeed or in the migration typed parameter name.
Let's make the new option for virsh migrate consistent.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirsh: Rename --precopy-bandwidth migration option
Jiri Denemark [Mon, 2 Sep 2019 15:00:32 +0000 (17:00 +0200)]
virsh: Rename --precopy-bandwidth migration option

The (pre-copy) bandwidth was historically the only bandwidth we
supported and thus it is called just "bandwidth" in all other places.
E.g., virsh migrate-setspeed or in the migration typed parameter name.
Let's make the new option for virsh migrate consistent.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>