]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
6 years agoqemu: vfio-ap device support
Boris Fiuczynski [Thu, 18 Oct 2018 14:54:07 +0000 (16:54 +0200)]
qemu: vfio-ap device support

Adjusting domain format documentation, adding device address
support and adding command line generation for vfio-ap.
Since only one mediated hostdev with model vfio-ap is supported a check
disallows to define domains with more than one such hostdev device.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Chris Venteicher <cventeic@redhat.com>
6 years agoqemu: add vfio-ap capability
Boris Fiuczynski [Thu, 18 Oct 2018 14:54:06 +0000 (16:54 +0200)]
qemu: add vfio-ap capability

Introduce vfio-ap capability.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Chris Venteicher <cventeic@redhat.com>
6 years agodocs: fix repology link for qemu-kvm package
Pavel Hrdina [Tue, 23 Oct 2018 15:16:36 +0000 (16:16 +0100)]
docs: fix repology link for qemu-kvm package

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agodocs: Fix minimum supported version
Martin Kletzander [Tue, 23 Oct 2018 09:21:04 +0000 (10:21 +0100)]
docs: Fix minimum supported version

We already have that in the code (commit c1bc9c662b411), we just forgot to
mention that in the docs.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6 years agoutil: Fix typo vcups -> vcpus
Martin Kletzander [Mon, 22 Oct 2018 13:37:54 +0000 (14:37 +0100)]
util: Fix typo vcups -> vcpus

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
6 years agoqemu: Fix IOThread pids lost after qemuProcessReconnect
Jie Wang [Wed, 17 Oct 2018 17:14:42 +0000 (01:14 +0800)]
qemu: Fix IOThread pids lost after qemuProcessReconnect

IOThread pids info will lost after libvirtd restart, then
if we call pinIOThread, sched_setaffinity will be called with
pid 0, not IOThread pid. So pinIOThread cannot work normally.

Signed-off-by: Jie Wang <wangjie88.huawei.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoqemu: Avoid memleak on failure to format blockjobs
Eric Blake [Thu, 18 Oct 2018 20:05:22 +0000 (15:05 -0500)]
qemu: Avoid memleak on failure to format blockjobs

virXMLFormatElement() frees attrBuf on success, but not necessarily
on failure. Most other callers of this function take the time to
reset attrBuf afterwords, but qemuDomainObjPrivateXMLFormatBlockjobs()
was relying on it succeeding, and could thus result in a memory leak.

Signed-off-by: Eric Blake <eblake@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agovirfile: Take symlink into account in virFileIsSharedFixFUSE
Michal Privoznik [Thu, 18 Oct 2018 12:57:19 +0000 (14:57 +0200)]
virfile: Take symlink into account in virFileIsSharedFixFUSE

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

Weirdly enough, there can be symlinks in the path we are trying
to fix. If it is the case our clever algorithm that finds matches
against mount table won't work. Canonicalize path at the
beginning then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agovirFileInData: Preserve errno on error
Michal Privoznik [Mon, 8 Oct 2018 15:36:10 +0000 (17:36 +0200)]
virFileInData: Preserve errno on error

The virFileInData() function should return to the caller if the
current position the passed file is in is a data section or a
hole (and also how long the current section is). At any rate,
upon return from this function (be it successful or not) the
original position in the file is restored. This may mess up with
errno which might have been set earlier. Save the errno into a
local variable so it can be restored for the caller's sake.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
6 years agoqemu: qemuProcessInit: Drop unused config variable
Bjoern Walk [Thu, 18 Oct 2018 08:08:04 +0000 (10:08 +0200)]
qemu: qemuProcessInit: Drop unused config variable

The QEMU @cfg config variable is unused in context of qemuProcessInit,
let's drop it.

Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
6 years agonwfilter: Fix learning address thread shutdown
Nikolay Shirokovskiy [Fri, 12 Oct 2018 07:23:07 +0000 (10:23 +0300)]
nwfilter: Fix learning address thread shutdown

If the learning thread is configured to learn on all ethernet frames
(which is hardcoded) then chances are high that there is a packet on
every iteration of inspecting frames loop. As result we will hang on
shutdown because we don't check threadsTerminate if there is packet.

Let's just check termination conditions on every iteration. Since
we'll check each iteration, the check after pcap_next essentially
is unnecessary since on failure we'd loop back to the top and timeout
and then fail.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agoutil: Fix a typo in comments of virresctrl.c
Wang Huaqiang [Wed, 17 Oct 2018 08:27:36 +0000 (16:27 +0800)]
util: Fix a typo in comments of virresctrl.c

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agoconf: Fix typos in pcie controllers' name
Han Han [Wed, 17 Oct 2018 01:10:57 +0000 (09:10 +0800)]
conf: Fix typos in pcie controllers' name

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agoqemu: Put format=raw onto cmd line for SCSI passthrough
Michal Privoznik [Fri, 12 Oct 2018 09:09:56 +0000 (11:09 +0200)]
qemu: Put format=raw onto cmd line for SCSI passthrough

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

When doing a SCSI passthrough we don't put format= onto the
command line. This causes qemu to probe the format automatically
which ends up in a warning in the domain log and possible qemu
disabling writes to the first block (according to the warning
message).

Based-on-work-of: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
6 years agoconf: Fix bug in finding alloc through matching vcpus
Wang Huaqiang [Fri, 12 Oct 2018 10:24:54 +0000 (18:24 +0800)]
conf: Fix bug in finding alloc through matching vcpus

The @alloc object returned by virDomainResctrlVcpuMatch is not
properly referenced and un-referenced in virDomainCachetuneDefParse.

This patch fixes this problem.

Signed-off-by: Wang Huaqiang <huaqiang.wang@intel.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
6 years agotests: use real capabilities for net-vhostuser
Ján Tomko [Thu, 4 Oct 2018 17:44:55 +0000 (19:44 +0200)]
tests: use real capabilities for net-vhostuser

Commit ed5aa85f371aebb0103e712f9a103d011ab9ae43
    qemu: don't use chardev FD passing for vhostuser backend
altered the legacy DO_TEST macro.

Run the test against capabilities of QEMU 2.5.0 (which did not
support QEMU_CAPS_CHARDEV_FD_PASS) as well as the latest version.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: add virtio-rng-egd-unix
Ján Tomko [Thu, 4 Oct 2018 17:27:17 +0000 (19:27 +0200)]
tests: add virtio-rng-egd-unix

Test RNG devices connected to EGD via UNIX sockets.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: add usb-redir-unix
Ján Tomko [Thu, 4 Oct 2018 17:24:01 +0000 (19:24 +0200)]
tests: add usb-redir-unix

Test USB redirdevs backed by UNIX sockets.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: add console-virtio-unix
Ján Tomko [Thu, 4 Oct 2018 17:15:15 +0000 (19:15 +0200)]
tests: add console-virtio-unix

Test a virtio console backed by a UNIX socket.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: add channel-unix-guestfwd
Ján Tomko [Thu, 4 Oct 2018 17:11:43 +0000 (19:11 +0200)]
tests: add channel-unix-guestfwd

Test guestfwd channels backed by UNIX sockets.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: add parallel-unix-chardev
Ján Tomko [Thu, 4 Oct 2018 17:03:12 +0000 (19:03 +0200)]
tests: add parallel-unix-chardev

Test creating a parallel port backed by a UNIX socket.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agotests: add smartcard-passthrough-unix
Ján Tomko [Thu, 4 Oct 2018 16:24:53 +0000 (18:24 +0200)]
tests: add smartcard-passthrough-unix

Test CCID smartcard passthrough from a unix listen socket.
Use the capabilities of QEMU 2.5.0 which did not support
chardev FD passing and the latest one, which (at the time
of this commit) it does.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoutil: storage: Properly parse URIs with missing trailing slash
Peter Krempa [Thu, 11 Oct 2018 10:22:21 +0000 (12:22 +0200)]
util: storage: Properly parse URIs with missing trailing slash

The URI parser used by libvirt does not populate uri->path if the
trailing slash is missing. The code virStorageSourceParseBackingURI
would then not populate src->path.

As only NBD network disks are allowed to have the 'name' field in the
XML defining the disk source omitted we'd generate an invalid XML which
we'd not parse again.

Fix it by populating src->path with an empty string if the uri is
lacking slash.

As pointed out above NBD is special in this case since we actually allow
it being NULL. The URI path is used as export name. Since an empty
export does not make sense the new approach clears the src->path if the
trailing slash is present but nothing else.

Add test cases now to cover all the various cases for NBD and non-NBD
uris as there was to time only 1 test abusing the quirk witout slash for
NBD and all other URIs contained the slash or in case of NBD also the
export name.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoutil: storage: Rename '@path' argument of virStorageSourceParseBackingURI
Peter Krempa [Thu, 11 Oct 2018 10:18:39 +0000 (12:18 +0200)]
util: storage: Rename '@path' argument of virStorageSourceParseBackingURI

The name is misleading. Change it to 'uristr' so that 'path' can be
reused in the proper context later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agovirsh: Fix regression with duplicated error messages
Eric Blake [Thu, 11 Oct 2018 16:29:58 +0000 (11:29 -0500)]
virsh: Fix regression with duplicated error messages

Commit 4f4c3b13 (v3.3) fixed an issue where performing cleanup of
libvirt objects could sometimes lose error messages, by adding code
to copy the libvirt error into last_error prior to cleanup paths.
However, it caused a regression: on other paths, some errors are now
printed twice, if libvirt still remembers in its thread-local
storage that an error was set even after virsh cleared last_error.
For example:

$ virsh -c test:///default snapshot-delete test blah
error: Domain snapshot not found: no domain snapshot with matching name 'blah'
error: Domain snapshot not found: no domain snapshot with matching name 'blah'

Fix things by telling libvirt to discard any thread-local errors at
the same time virsh prints an error message (whether or not the libvirt
error is the same as what is stored in last_error).

Update the virsh-undefine testsuite (partially reverting portions of
commit b620bdee, by removing -q, to more easily pinpoint which commands
are causing which messages), now that there is only one error message
instead of two.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
6 years agorpc: reproducible genprotocol output
Olaf Hering [Wed, 10 Oct 2018 09:15:37 +0000 (11:15 +0200)]
rpc: reproducible genprotocol output

If the same source gets built twice ('build same source on different
hosts at different times') the resulting files may differ.
Fix this by sorting the hash keys before usage.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
6 years agoqemu: Remove unused qemuProcessAutostartAll
John Ferlan [Thu, 11 Oct 2018 22:26:00 +0000 (18:26 -0400)]
qemu: Remove unused qemuProcessAutostartAll

The function was never defined in source, just the protoype.

Signed-off-by: John Ferlan <jferlan@redhat.com>
6 years agovirfiletest: Load mock on Linux only
Michal Privoznik [Thu, 11 Oct 2018 08:36:02 +0000 (10:36 +0200)]
virfiletest: Load mock on Linux only

The mock is built on Linux only. Therefore we should load it only
on Linux too. This fixes the FreeBSD build.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
6 years agovirfile: Rework virFileIsSharedFixFUSE
Michal Privoznik [Tue, 9 Oct 2018 11:08:07 +0000 (13:08 +0200)]
virfile: Rework virFileIsSharedFixFUSE

There are couple of things wrong with the current implementation.
The first one is that in the first loop the code tries to build a
list of fuse.glusterfs mount points. Well, since the strings are
allocated in a temporary buffer and are not duplicated this
results in wrong decision made later in the code.

The second problem is that the code does not take into account
subtree mounts. For instance, if there's a fuse.gluster mounted
at /some/path and another FS mounted at /some/path/subdir the
code would not recognize this subdir mount.

Reported-by: Han Han <hhan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
6 years agovirFileIsSharedFSType: Detect direct mount points
Michal Privoznik [Tue, 9 Oct 2018 13:23:10 +0000 (15:23 +0200)]
virFileIsSharedFSType: Detect direct mount points

If the given path is already a mount point (e.g. a bind mount of
a file, or simply a direct mount point of a FS), then our code
fails to detect that because the first thing it does is cutting
off part after last slash '/'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
6 years agovirfiletst: Test virFileIsSharedFS
Michal Privoznik [Tue, 9 Oct 2018 11:06:00 +0000 (13:06 +0200)]
virfiletst: Test virFileIsSharedFS

Introduce some basic test cases for virFileIsSharedFS(). More
will be added later. In order to achieve desired result, mocks
for setmntent() and statfs() need to be invented because the
first thing that virFileIsSharedFS() does is calling the latter.
If it finds a FUSE mount it'll call the former.

The mock might look a bit complicated, but in fact it's quite
simple. The test sets LIBVIRT_MTAB env variable to hold the
absolute path to a file containing mount table. Then, statfs()
returns matching FS it finds, and setmntent() is there just to
replace /proc/mounts with the file the test wants to load.

Adding this test also exposed a bug we have - because we assume
the given path points to a file we cut off what we assume is a
file name to obtain directory path and only then we call
statfs(). This is buggy because the passed path could be already
a mount point.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
6 years agovirfiletest: Fix test name prefix for virFileInData test
Michal Privoznik [Tue, 9 Oct 2018 12:50:53 +0000 (14:50 +0200)]
virfiletest: Fix test name prefix for virFileInData test

Because of lacking virTestCounterReset() call, the old test cases
name was preserved.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
6 years agovirfile: fix cast-align error
Marc Hartmayer [Wed, 10 Oct 2018 08:04:04 +0000 (10:04 +0200)]
virfile: fix cast-align error

On s390x the struct member f_type of statsfs is hard coded to 'unsigned
int'. Change virFileIsSharedFixFUSE() to take a 'long long int' and use
a temporary to avoid pointer-casting.

This fixes the following error:
../../src/util/virfile.c:3578:38: error: cast increases required alignment of target type [-Werror=cast-align]
         virFileIsSharedFixFUSE(path, (long *) &sb.f_type);

Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com>
Signed-off-by: Bjoern Walk <bwalk@linux.ibm.com>
6 years agovirresctrl: remove bogus virResetLastError
Ján Tomko [Fri, 5 Oct 2018 14:34:51 +0000 (16:34 +0200)]
virresctrl: remove bogus virResetLastError

virFileReadValueUint does not log errors for non-existient files,
it merely returns -2.

Commit 12093f1 introduced this.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
6 years agoqemu: use "id" instead of deprecated "name" for -net
Ján Tomko [Mon, 8 Oct 2018 14:36:05 +0000 (16:36 +0200)]
qemu: use "id" instead of deprecated "name" for -net

-net name= will be deprecated in QEMU 3.1:
commit 101625a4d4ac7e96227a156bc5f6d21a9cc383cd
    net: Deprecate the "name" parameter of -net
git describe: v3.0.0-791-g101625a4d4

Use the id option instead, supported since QEMU 1.2:
commit 6687b79d636cd60ed9adb1177d0d946b58fa7717
    convert net_client_init() to OptsVisitor
git describe: v1.0-3564-g6687b79d63 contains: v1.2.0-rc0~142^2~8

Thankfully, libvirt only uses -net for non-PCI, non-virtio NICs
on ARM.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
6 years agoqemu: hotplug: Refactor qemuDomainAttachDeviceDiskLiveInternal
Peter Krempa [Tue, 25 Sep 2018 13:07:01 +0000 (15:07 +0200)]
qemu: hotplug: Refactor qemuDomainAttachDeviceDiskLiveInternal

We now explicitly handle media change elsewhere so we can drop the
switch statement. This will also make it more intuitive once CDROM
device hotplug might be supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Split out media change code from disk hotplug
Peter Krempa [Tue, 25 Sep 2018 12:47:36 +0000 (14:47 +0200)]
qemu: hotplug: Split out media change code from disk hotplug

Disk hotplug has slightly different semantics from media changing. Move
the media change code out and add proper initialization of the new
source object and proper cleanups if something fails.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: conf: Export qemuAddSharedDisk
Peter Krempa [Tue, 25 Sep 2018 13:02:25 +0000 (15:02 +0200)]
qemu: conf: Export qemuAddSharedDisk

In cases where we know the device is a disk we can avoid using the full
device definition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Add wrapper for disk hotplug code
Peter Krempa [Tue, 25 Sep 2018 12:23:08 +0000 (14:23 +0200)]
qemu: hotplug: Add wrapper for disk hotplug code

The disk hotplug code also overloads media change which is not ideal.
This will allow splitting out of the media change code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Prepare disk source for media changing
Peter Krempa [Thu, 27 Sep 2018 14:50:55 +0000 (16:50 +0200)]
qemu: hotplug: Prepare disk source for media changing

The disk storage source needs to be prepared if we want to use -blockdev
or secrets for the new media image. It does not hurt to do the same for
the legacy hotplug code as well.

Unfortunately helpers like qemuDomainPrepareDiskSource take
virDomainDiskDef as an argument and it would be hard to fix them to take
an explicit source, so the function also temporarily replaces disk->src
for the new source in this function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Be explicit about old/new sources when changing media
Peter Krempa [Thu, 4 Oct 2018 15:56:46 +0000 (17:56 +0200)]
qemu: hotplug: Be explicit about old/new sources when changing media

Some functions require us to replace disk->src with the new source for
them to work properly. To avoid confusion all places which allow
explicit virStorageSource should get the appropriate definition.

The legacy code fortunately does not need anything from the old source
so that does not require modifications.

Blockdev does require the old definition so we'll pass it explicitly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Allow specifying explicit source for disk backend hotplug code
Peter Krempa [Thu, 4 Oct 2018 15:49:00 +0000 (17:49 +0200)]
qemu: hotplug: Allow specifying explicit source for disk backend hotplug code

Since the code is also used when changing media we need to allow
specifying explicit source for which we are going to prepare. With this
change callers don't have to replace disk->src with the new source
definition for generating these.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Remove code handling possible missing disk source format
Peter Krempa [Thu, 4 Oct 2018 13:32:37 +0000 (15:32 +0200)]
qemu: hotplug: Remove code handling possible missing disk source format

qemu media changing code tried to assume old media's format for the new
one if that was not specified. Since the format will always be present
it does not make sense to keep the code around.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoqemu: hotplug: Don't pretend that we support secrets for media change
Peter Krempa [Thu, 4 Oct 2018 12:34:01 +0000 (14:34 +0200)]
qemu: hotplug: Don't pretend that we support secrets for media change

Old media changing code does not bother setting up the secrets for new
media or actually removing/adding of the corresponding objects.

Additionally it uses secrets setup for the old image to be removed as
the secret for the new image which is wrong.

Remove the support for secrets while changing media for the legacy
approach. The only reasonable way to fix it is when using blockdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoRevert "qemu: hotplug: consolidate media change code paths"
Peter Krempa [Tue, 25 Sep 2018 12:21:27 +0000 (14:21 +0200)]
Revert "qemu: hotplug: consolidate media change code paths"

While the idea was good the implementation not so much as we need to
take into account the old disk data and the new source. The code will be
consolidated later in a different way.

This reverts commit 663b1d55de652201b19d875f0eff730dc28e689e.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agoRevert "qemu: hotplug: Prepare disk source in qemuDomainAttachDeviceDiskLive"
Peter Krempa [Mon, 24 Sep 2018 14:49:01 +0000 (16:49 +0200)]
Revert "qemu: hotplug: Prepare disk source in qemuDomainAttachDeviceDiskLive"

Preparing the storage source prior to assigning the alias will not work
as the names of the certain objects depend on the alias for the legacy
hotplug case as we generate the object names for the secrets based on
the alias.

This reverts commit 192fdaa614e3800255048a8a70c1292ccf18397a.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
6 years agovirt-host-validate: Fix build on non-Linux
Michal Privoznik [Mon, 8 Oct 2018 07:10:07 +0000 (09:10 +0200)]
virt-host-validate: Fix build on non-Linux

For non-Linux platforms we have
virHostValidateCGroupControllers() stub which only reports an
error. But we are not marking the ignored arguments the way we
should.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovirt-host-validate: require freezer for LXC
Pavel Hrdina [Sat, 29 Sep 2018 19:47:50 +0000 (21:47 +0200)]
virt-host-validate: require freezer for LXC

Cgroup freezer support for LXC was added in libvirt-0.7.2.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovirt-host-validate: rewrite cgroup detection to use util/vircgroup
Pavel Hrdina [Sat, 29 Sep 2018 19:37:22 +0000 (21:37 +0200)]
virt-host-validate: rewrite cgroup detection to use util/vircgroup

This removes code duplication and simplifies cgroup detection.
As a drawback we will not have separate messages to enable cgroup
controller in kernel or to mount it.  On the other side the rewrite
adds support for cgroup v2.

The kernel config support was wrong because it was parsing
'/proc/self/cgroup' instead of '/proc/cgroups/' file.

The mount suggestion is removed as well because it will not work
with cgroup v2.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: add hybrid tests
Pavel Hrdina [Tue, 18 Sep 2018 07:43:47 +0000 (09:43 +0200)]
vircgrouptest: add hybrid tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: add cgroup v2 tests
Pavel Hrdina [Tue, 18 Sep 2018 07:43:09 +0000 (09:43 +0200)]
vircgrouptest: add cgroup v2 tests

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: prepare validateCgroup for cgroupv2
Pavel Hrdina [Tue, 18 Sep 2018 07:41:44 +0000 (09:41 +0200)]
vircgrouptest: prepare validateCgroup for cgroupv2

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: add detect mounts test for hybrid cgroups
Pavel Hrdina [Tue, 18 Sep 2018 08:09:20 +0000 (10:09 +0200)]
vircgrouptest: add detect mounts test for hybrid cgroups

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: add detect mounts test for cgroup v2
Pavel Hrdina [Tue, 18 Sep 2018 08:08:35 +0000 (10:08 +0200)]
vircgrouptest: add detect mounts test for cgroup v2

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: prepare testCgroupDetectMounts for cgroup v2
Pavel Hrdina [Mon, 24 Sep 2018 10:28:04 +0000 (12:28 +0200)]
vircgrouptest: prepare testCgroupDetectMounts for cgroup v2

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgrouptest: introduce initFakeFS and cleanupFakeFS helpers
Pavel Hrdina [Mon, 24 Sep 2018 10:22:54 +0000 (12:22 +0200)]
vircgrouptest: introduce initFakeFS and cleanupFakeFS helpers

We need to configure multiple env variables for each set of tests so
create helper functions to do that.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroupmock: add support to test cgroup v2
Pavel Hrdina [Tue, 18 Sep 2018 10:33:21 +0000 (12:33 +0200)]
vircgroupmock: add support to test cgroup v2

We need to create the cgroup v2 sysfs the same way as we do for
cgroup v1.

This introduces new VIR_CGROUP_MOCK_MODE env variable which will
configure which cgroup mode each test requires.  There are three
different modes:

    - legacy: only cgroup v1 is available and it's the default mode
    - hybrid: both cgroup v1 and cgroup v2 are available and have some
        controllers
    - unified: only cgroup v2 is available

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroupmock: change cgroup prefix
Pavel Hrdina [Tue, 18 Sep 2018 07:28:54 +0000 (09:28 +0200)]
vircgroupmock: change cgroup prefix

Remove the trailing '/' from prefix.  This change is required in order
to introduce tests for unified cgroups.  They are usually mounted in
'/sys/fs/cgroup'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: add support for hybrid configuration
Pavel Hrdina [Fri, 28 Sep 2018 17:53:05 +0000 (19:53 +0200)]
vircgroup: add support for hybrid configuration

This enables to use both cgroup v1 and v2 at the same time together
with libvirt.  It is supported by kernel and there is valid use-case,
not all controllers are implemented in cgroup v2 so there might be
configurations where administrator would enable these missing
controllers in cgroup v1.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: register cgroup v2 backend
Pavel Hrdina [Sat, 15 Sep 2018 09:13:13 +0000 (11:13 +0200)]
vircgroup: register cgroup v2 backend

All mandatory callbacks are implemented for cgroup v2 backend so we
can register it now.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetCpuacctStat
Pavel Hrdina [Fri, 17 Aug 2018 15:00:00 +0000 (17:00 +0200)]
vircgroup: introduce virCgroupV2GetCpuacctStat

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetCpuacctUsage
Pavel Hrdina [Fri, 17 Aug 2018 14:59:49 +0000 (16:59 +0200)]
vircgroup: introduce virCgroupV2GetCpuacctUsage

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2SupportsCpuBW
Pavel Hrdina [Fri, 17 Aug 2018 14:59:27 +0000 (16:59 +0200)]
vircgroup: introduce virCgroupV2SupportsCpuBW

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)CpuCfsQuota
Pavel Hrdina [Fri, 17 Aug 2018 14:59:02 +0000 (16:59 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)CpuCfsQuota

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)CpuCfsPeriod
Pavel Hrdina [Fri, 17 Aug 2018 14:58:40 +0000 (16:58 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)CpuCfsPeriod

In order to set CPU cfs period using cgroup v2 'cpu.max' interface
we need to load the current value of CPU cfs quota first because
format of 'cpu.max' interface is '$quota $period' and in order to
change 'period' we need to write 'quota' as well.  Writing only one
number changes only 'quota'.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)CpuShares
Pavel Hrdina [Fri, 17 Aug 2018 14:58:15 +0000 (16:58 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)CpuShares

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetMemSwapUsage
Pavel Hrdina [Fri, 17 Aug 2018 14:57:52 +0000 (16:57 +0200)]
vircgroup: introduce virCgroupV2GetMemSwapUsage

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)MemSwapHardLimit
Pavel Hrdina [Fri, 17 Aug 2018 14:57:30 +0000 (16:57 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)MemSwapHardLimit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)MemorySoftLimit
Pavel Hrdina [Fri, 17 Aug 2018 14:57:00 +0000 (16:57 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)MemorySoftLimit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)MemoryHardLimit
Pavel Hrdina [Fri, 17 Aug 2018 14:56:31 +0000 (16:56 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)MemoryHardLimit

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetMemoryUsage
Pavel Hrdina [Fri, 17 Aug 2018 14:56:00 +0000 (16:56 +0200)]
vircgroup: introduce virCgroupV2GetMemoryUsage

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetMemoryStat
Pavel Hrdina [Fri, 17 Aug 2018 14:55:34 +0000 (16:55 +0200)]
vircgroup: introduce virCgroupV2GetMemoryStat

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2SetMemory
Pavel Hrdina [Fri, 17 Aug 2018 14:54:59 +0000 (16:54 +0200)]
vircgroup: introduce virCgroupV2SetMemory

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteBps
Pavel Hrdina [Fri, 17 Aug 2018 14:54:36 +0000 (16:54 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteBps

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadBps
Pavel Hrdina [Fri, 17 Aug 2018 14:54:11 +0000 (16:54 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadBps

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteIops
Pavel Hrdina [Fri, 17 Aug 2018 14:53:45 +0000 (16:53 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWriteIops

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadIops
Pavel Hrdina [Fri, 17 Aug 2018 14:53:17 +0000 (16:53 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceReadIops

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWeight
Pavel Hrdina [Fri, 17 Aug 2018 14:52:50 +0000 (16:52 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)BlkioDeviceWeight

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetBlkioIoDeviceServiced
Pavel Hrdina [Fri, 17 Aug 2018 14:52:24 +0000 (16:52 +0200)]
vircgroup: introduce virCgroupV2GetBlkioIoDeviceServiced

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetBlkioIoServiced
Pavel Hrdina [Fri, 17 Aug 2018 14:51:54 +0000 (16:51 +0200)]
vircgroup: introduce virCgroupV2GetBlkioIoServiced

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2(Set|Get)BlkioWeight
Pavel Hrdina [Fri, 17 Aug 2018 14:51:28 +0000 (16:51 +0200)]
vircgroup: introduce virCgroupV2(Set|Get)BlkioWeight

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2SetOwner
Pavel Hrdina [Fri, 17 Aug 2018 14:50:57 +0000 (16:50 +0200)]
vircgroup: introduce virCgroupV2SetOwner

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2BindMount
Pavel Hrdina [Fri, 28 Sep 2018 18:40:11 +0000 (20:40 +0200)]
vircgroup: introduce virCgroupV2BindMount

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2HasEmptyTasks
Pavel Hrdina [Fri, 17 Aug 2018 14:49:57 +0000 (16:49 +0200)]
vircgroup: introduce virCgroupV2HasEmptyTasks

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2AddTask
Pavel Hrdina [Fri, 17 Aug 2018 14:49:33 +0000 (16:49 +0200)]
vircgroup: introduce virCgroupV2AddTask

In cgroups v2 we need to handle threads and processes differently.
If you need to move a process you need to write its pid into
cgrou.procs file and it will move the process with all its threads
as well.  The whole process will be moved if you use tid of any thread.

In order to move only threads at first we need to create threaded group
and after that we can write the relevant thread tids into cgroup.threads
file.  Threads can be moved only into cgroups that are children of
cgroup of its process.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2Remove
Pavel Hrdina [Fri, 17 Aug 2018 14:49:08 +0000 (16:49 +0200)]
vircgroup: introduce virCgroupV2Remove

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2MakeGroup
Pavel Hrdina [Tue, 18 Sep 2018 15:49:19 +0000 (17:49 +0200)]
vircgroup: introduce virCgroupV2MakeGroup

When creating cgroup hierarchy we need to enable controllers in the
parent cgroup in order to be usable.  That means writing "+{controller}"
into cgroup.subtree_control file.  We can enable only controllers that
are enabled for parent cgroup, that means we need to do that for the
whole cgroup tree.

Cgroups for threads needs to be handled differently in cgroup v2.  There
are two types of controllers:

    - domain controllers: these cannot be enabled for threads
    - threaded controllers: these can be enabled for threads

In addition there are multiple types of cgroups:

    - domain: normal cgroup
    - domain threaded: a domain cgroup that serves as root for threaded
                       cgroups
    - domain invalid: invalid cgroup, can be changed into threaded, this
                      is the default state if you create subgroup inside
                      domain threaded group or threaded group
    - threaded: threaded cgroup which can have domain threaded or
                threaded as parent group

In order to create threaded cgroup it's sufficient to write "threaded"
into cgroup.type file, it will automatically make parent cgroup
"domain threaded" if it was only "domain".  In case the parent cgroup
is already "domain threaded" or "threaded" it will modify only the type
of current cgroup.  After that we can enable threaded controllers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2PathOfController
Pavel Hrdina [Sun, 19 Aug 2018 17:45:49 +0000 (19:45 +0200)]
vircgroup: introduce virCgroupV2PathOfController

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2GetAnyController
Pavel Hrdina [Sun, 19 Aug 2018 17:43:04 +0000 (19:43 +0200)]
vircgroup: introduce virCgroupV2GetAnyController

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2HasController
Pavel Hrdina [Sun, 19 Aug 2018 17:40:15 +0000 (19:40 +0200)]
vircgroup: introduce virCgroupV2HasController

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2DetectControllers
Pavel Hrdina [Tue, 25 Sep 2018 12:37:21 +0000 (14:37 +0200)]
vircgroup: introduce virCgroupV2DetectControllers

Cgroup v2 has only single mount point for all controllers.  The list
of controllers is stored in cgroup.controllers file, name of controllers
are separated by space.

In cgroup v2 there is no cpuacct controller, the cpu.stat file always
exists with usage stats.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2StealPlacement
Pavel Hrdina [Tue, 18 Sep 2018 07:21:53 +0000 (09:21 +0200)]
vircgroup: introduce virCgroupV2StealPlacement

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2ValidatePlacement
Pavel Hrdina [Tue, 18 Sep 2018 07:17:24 +0000 (09:17 +0200)]
vircgroup: introduce virCgroupV2ValidatePlacement

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2DetectPlacement
Pavel Hrdina [Fri, 14 Sep 2018 21:46:42 +0000 (23:46 +0200)]
vircgroup: introduce virCgroupV2DetectPlacement

If the placement was copied from parent or set to absolute path
there is nothing to do, otherwise set the placement based on
process placement from /proc/self/cgroup or /proc/{pid}/cgroup.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2DetectMounts
Pavel Hrdina [Tue, 25 Sep 2018 12:34:47 +0000 (14:34 +0200)]
vircgroup: introduce virCgroupV2DetectMounts

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2CopyPlacement
Pavel Hrdina [Tue, 25 Sep 2018 12:34:01 +0000 (14:34 +0200)]
vircgroup: introduce virCgroupV2CopyPlacement

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2CopyMounts
Pavel Hrdina [Fri, 17 Aug 2018 14:42:17 +0000 (16:42 +0200)]
vircgroup: introduce virCgroupV2CopyMounts

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2ValidateMachineGroup
Pavel Hrdina [Fri, 14 Sep 2018 16:19:53 +0000 (18:19 +0200)]
vircgroup: introduce virCgroupV2ValidateMachineGroup

When reconnecting to a domain we are validating the cgroup name.
In case of cgroup v2 we need to validate only the new format for host
without systemd '{machinename}.libvirt-{drivername}' or scope name
generated by systemd.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agovircgroup: introduce virCgroupV2Available
Pavel Hrdina [Fri, 17 Aug 2018 14:28:11 +0000 (16:28 +0200)]
vircgroup: introduce virCgroupV2Available

We cannot detect only mount points to figure out whether cgroup v2
is available because systemd uses cgroup v2 for process tracking and
all controllers are mounted as cgroup v1 controllers.

To make sure that this is no the situation we need to check
'cgroup.controllers' file if it's not empty to make sure that cgroup
v2 is not mounted only for process tracking.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
6 years agoutil: introduce cgroup v2 files
Pavel Hrdina [Tue, 18 Sep 2018 15:48:33 +0000 (17:48 +0200)]
util: introduce cgroup v2 files

Place cgroup v2 backend type before cgroup v1 to make it obvious
that cgroup v2 is preferred implementation.

Following patches will introduce support for hybrid configuration
which will allow us to use both at the same time, but we should
prefer cgroup v2 regardless.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>