]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
4 years agoqemuDomainGetBlockJobInfo: Work stats for unfinished pre-blockdev blockjob
Peter Krempa [Fri, 4 Dec 2020 15:08:02 +0000 (16:08 +0100)] 
qemuDomainGetBlockJobInfo: Work stats for unfinished pre-blockdev blockjob

If the job has finished, but we didn't yet process the completion fake
that it's still incomplete so that apps which decided to poll
qemuDomainGetBlockJobInfo rather than use events can be sure that the
XML update was completed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu: monitor: Remove unused qemuMonitorGetBlockJobInfo
Peter Krempa [Fri, 4 Dec 2020 15:08:01 +0000 (16:08 +0100)] 
qemu: monitor: Remove unused qemuMonitorGetBlockJobInfo

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemuDomainGetBlockJobInfo: Use qemuMonitorGetAllBlockJobInfo
Peter Krempa [Fri, 4 Dec 2020 15:08:00 +0000 (16:08 +0100)] 
qemuDomainGetBlockJobInfo: Use qemuMonitorGetAllBlockJobInfo

Replace qemuMonitorGetBlockJobInfo by qemuMonitorGetAllBlockJobInfo and
hash table lookup. This basically open-codes qemuMonitorGetBlockJobInfo,
but it will be removed in next patch.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemuBlockJobInfoTranslate: Use explicit comparison against 0
Peter Krempa [Fri, 4 Dec 2020 15:07:59 +0000 (16:07 +0100)] 
qemuBlockJobInfoTranslate: Use explicit comparison against 0

Using ! on integers is misleading.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemuMonitorBlockJobInfo: Store 'ready' and 'ready_present' separately
Peter Krempa [Fri, 4 Dec 2020 15:07:58 +0000 (16:07 +0100)] 
qemuMonitorBlockJobInfo: Store 'ready' and 'ready_present' separately

Don't make the logic confusing by representing the 3 options using an
integer with negative values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agovirDomainGetBlockJobInfo: Reword docs for fallback values
Peter Krempa [Fri, 4 Dec 2020 15:07:57 +0000 (16:07 +0100)] 
virDomainGetBlockJobInfo: Reword docs for fallback values

Explicitly state that if 'end == 1' the data doesn't represent actual
progress in most cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agovirDomainGetBlockJobInfo: Discourage polling for block job completion detection
Peter Krempa [Fri, 4 Dec 2020 15:07:56 +0000 (16:07 +0100)] 
virDomainGetBlockJobInfo: Discourage polling for block job completion detection

Add a note saying that polling virDomainGetBlockJobInfo is not a good
idea. Use events instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
4 years agolxc: Cleanup after failed startup
Michal Privoznik [Wed, 11 Nov 2020 12:51:21 +0000 (13:51 +0100)] 
lxc: Cleanup after failed startup

If starting an container fails, the virLXCProcessStop() is
called. But since vm->def->id is not set until libvirt_lxc is
spawned (the domain's ID is PID of that process),
virLXCProcessStop() returns early as virDomainObjIsActive()
returns false. But doing so leaves behind resources reserved for
the containers during the startup process. Most notably, hostdevs
are not re-attached to the host, the domain's transient XML is
not removed, etc.

To resolve this, virLXCProcessCleanup() is called in this case.
However, it is modified to accept @flags which allows caller to
run only specific cleanups (depending how far in container
creation the failure occurred). There is plenty of cleanups which
don't need this guard because either they detect a NULL pointer
or try to release an unique resource.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
4 years agoqemu_monitor_json: Don't leak "option" in qemuMonitorJSONGetCommandLineOptions()
Michal Privoznik [Mon, 7 Dec 2020 08:32:27 +0000 (09:32 +0100)] 
qemu_monitor_json: Don't leak "option" in qemuMonitorJSONGetCommandLineOptions()

In recent commit of bf8bd93df0 (and friends) we switched the way
we process queried command line arguments: from string lists to
virJSONValue stored in a hash table. To achieve this
qemuMonitorJSONGetCommandLineOptions() helper was introduced
which executes the "query-command-line-options" monitor command
and then calls virJSONValueArrayForeachSteal() to process the
output. The array process function is also given
qemuMonitorJSONGetCommandLineOptionsWorker() as the callback
which is called over each item of the returned array. This
callback then steals "parameters" attribute of each array iteam
storing it in the hash table, but it leaves behind "option"
attribute (because it's g_strdup()-ed). After all of this, the
callback returns 0 which is a signal to the array processing
function that the callback took ownership of the array item. But
this is not true. While it removed "parameters" it did not take
the rest ("option" for instance). And therefore, it leads to a
memory leak:

 5,347 (1,656 direct, 3,691 indirect) bytes in 69 blocks are definitely lost in loss record 2,752 of 2,794
 at 0x483BEC5: calloc (vg_replace_malloc.c:760)
 by 0x4E25A10: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6400.5)
 by 0x4943317: virJSONValueNewObject (virjson.c:569)
 by 0x4945692: virJSONParserHandleStartMap (virjson.c:1768)
 by 0x5825A86: yajl_do_parse (in /usr/lib64/libyajl.so.2.1.0)
 by 0x4945BFA: virJSONValueFromString (virjson.c:1896)
 by 0xAF5C115: qemuMonitorJSONIOProcessLine (qemu_monitor_json.c:224)
 by 0xAF5C45E: qemuMonitorJSONIOProcess (qemu_monitor_json.c:279)
 by 0xAF4BB6C: qemuMonitorIOProcess (qemu_monitor.c:342)
 by 0xAF4C444: qemuMonitorIO (qemu_monitor.c:574)
 by 0x4FEF846: socket_source_dispatch (in /usr/lib64/libgio-2.0.so.0.6400.5)
 by 0x4E1F727: g_main_context_dispatch (in /usr/lib64/libglib-2.0.so.0.6400.5)

The callback must return 1 so that the array item is properly
freed.

Fixes: ebeff6cd57d07c89d42e191ed0085a9dd89835c5
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agodomain_conf, qemu: move virDomainNVDimmAlignSizePseries to qemu_domain.c
Daniel Henrique Barboza [Fri, 4 Dec 2020 19:08:56 +0000 (16:08 -0300)] 
domain_conf, qemu: move virDomainNVDimmAlignSizePseries to qemu_domain.c

Since the function is now only used in qemu_domain.c, move it from
domain_conf.c and rename it.

This reverts the work done in commit ace5931553c87beebb6b3cd994061742b3f88238
(conf, qemu: move qemuDomainNVDimmAlignSizePseries to domain_conf.c).

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu_domain.c: align all pSeries mem modules when PARSE_ABI_UPDATE
Daniel Henrique Barboza [Wed, 18 Nov 2020 19:58:34 +0000 (16:58 -0300)] 
qemu_domain.c: align all pSeries mem modules when PARSE_ABI_UPDATE

qemuDomainAlignMemorySizes() has an operation order problem. We are
calculating 'initialmem' without aligning the memory modules first.
Since we're aligning the dimms afterwards this can create inconsistencies
in the end result. x86 has alignment of 1-2MiB and it's not severely
impacted by it, but pSeries works with 256MiB alignment and the difference
is noticeable.

This is the case of the existing 'memory-hotplug-ppc64-nonuma' test.
The test consists of a 2GiB (aligned value) guest with 2 ~520MiB dimms,
both unaligned. 'initialmem' is calculated by taking total_mem and
subtracting the dimms size (via virDomainDefGetMemoryInitial()), which
wil give us 2GiB - 520MiB - 520MiB, ending up with a little more than
an 1GiB of 'initialmem'. Note that this value is now unaligned, and
will be aligned up via VIR_ROUND_UP(), and we'll end up with 'initialmem'
of 1GiB + 256MiB. Given that the dimms are aligned later on, the end
result for QEMU is that the guest will have a 'mem' size of 1310720k,
plus the two 512 MiB dimms, exceeding in 256MiB the desired 2GiB
memory and currentMemory specified in the XML.

Existing guests can't be fixed without breaking ABI, but we have
code already in place to align pSeries NVDIMM modules for new guests.
Let's extend it to align all pSeries mem modules.

A new test, 'memory-hotplug-ppc64-nonuma-abi-update', a copy of the
existing 'memory-hotplug-ppc64-nonuma', was added to demonstrate the
result for new pSeries guests. For the same unaligned XML mentioned
above, after applying this patch:

- starting QEMU mem size without PARSE_ABI_UPDATE:
    -m size=1310720k,slots=16,maxmem=4194304k \ (no changes)

- starting QEMU mem size with PARSE_ABI_UPDATE:
    -m size=1048576k,slots=16,maxmem=4194304k \ (size fixed)

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu_domain.c: post parse pSeries NVDIMM align with PARSE_ABI_UPDATE
Daniel Henrique Barboza [Wed, 18 Nov 2020 19:58:33 +0000 (16:58 -0300)] 
qemu_domain.c: post parse pSeries NVDIMM align with PARSE_ABI_UPDATE

A previous patch removed the pSeries NVDIMM align that wasn't
being done properly. This patch reintroduces it in the right
fashion, making it reliant on VIR_DOMAIN_DEF_PARSE_ABI_UPDATE.
This makes it complying with the intended design defined by
commit c7d7ba85a624.

Since the PARSE_ABI_UPDATE is more restrictive than checking for
!migrate && !snapshot, like is being currently done with
qemuDomainAlignMemorySizes(), this means that we'll align the
pSeries NVDIMMs in two places - in post parse time for new
guests, and in qemuDomainAlignMemorySizes() for all guests
that aren't migrating or in a snapshot.

Another difference is that the logic is now in the QEMU driver
instead of domain_conf.c. This was necessary because all
considerations made about the PARSE_ABI_UPDATE flag were done
under QEMU. Given that no other driver supports ppc64 there is no
impact in this change.

A new test was added to exercise what we're doing. It consists
of a a copy of the existing 'memory-hotplug-nvdimm-ppc64' xml2xml
test, called with the PARSE_ABI_UPDATE flag. As intended, we're
not changing QEMU command line or any XML without the flag,
while the pseries NVDIMM memory is being aligned when the
flag is used.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoRevert "domain_conf.c: auto-align pSeries NVDIMM in virDomainMemoryDefPostParse()"
Daniel Henrique Barboza [Wed, 18 Nov 2020 19:58:31 +0000 (16:58 -0300)] 
Revert "domain_conf.c: auto-align pSeries NVDIMM in virDomainMemoryDefPostParse()"

The code to align ppc64 NVDIMMs on post parse was introduced in
commit d3f3c2c97f9b. That commit failed to realize that we
can't align memory unconditionally. As of commit c7d7ba85a624
("qemu: command: Align memory sizes only on fresh starts"),
all memory alignment should be executed only when we're not
migrating or in a snapshot.

This revert does not break any guests in the wild, given that
ppc64 NVDIMMs are still being aligned in qemuDomainAlignMemorySizes().

Next patch will introduce a mechanism where we can have post
parse NVDIMM alignment for pSeries without breaking the
intended design, as defined by c7d7ba85a624.

This reverts commit d3f3c2c97f9b92c982ff809479495f44614edb88.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoapparmor: Drop needless check in AppArmorSetMemoryLabel()
Michal Privoznik [Fri, 4 Dec 2020 15:04:16 +0000 (16:04 +0100)] 
apparmor: Drop needless check in AppArmorSetMemoryLabel()

The AppArmorSetMemoryLabel() is a callback that is called from
qemuSecuritySetMemoryLabel() which never passes NULL as @mem.
Therefore, there is no need to check whether @mem is NULL. Also,
no other driver does that and just dereference it immediately.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu: Drop @qemuCaps argument from qemuDomainDefValidateMemoryHotplug()
Michal Privoznik [Fri, 4 Dec 2020 13:50:48 +0000 (14:50 +0100)] 
qemu: Drop @qemuCaps argument from qemuDomainDefValidateMemoryHotplug()

After previous cleanup the @qemuCaps argument in
qemuDomainDefValidateMemoryHotplug() is unused and thus doesn't
need to be passed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agolibvirt_recover_xattrs: Allow fixing multiple PATHs
Peter Krempa [Wed, 2 Dec 2020 09:55:01 +0000 (10:55 +0100)] 
libvirt_recover_xattrs: Allow fixing multiple PATHs

Loop for multiple PATH arguments to support shell pattern expansion.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agolibvirt_recover_xattrs: Add unsafe operation mode
Peter Krempa [Thu, 26 Nov 2020 16:19:43 +0000 (17:19 +0100)] 
libvirt_recover_xattrs: Add unsafe operation mode

In some cases you want to fix a certain directory while you don't really
care whether there are other VMs running. Add a option to disable the
check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agolibvirt_recover_xattrs: Use only the correct xattr prefix
Peter Krempa [Wed, 2 Dec 2020 09:24:21 +0000 (10:24 +0100)] 
libvirt_recover_xattrs: Use only the correct xattr prefix

Linux and FreeBSD have different prefix. In the current state we've
tried to reset the labels for both systems which resulted in errors like
this:

Fixing /tmp/bitmaps2.qcow2
setfattr: /tmp/bitmaps2.qcow2: Operation not supported
setfattr: /tmp/bitmaps2.qcow2: Operation not supported
setfattr: /tmp/bitmaps2.qcow2: Operation not supported
setfattr: /tmp/bitmaps2.qcow2: Operation not supported
setfattr: /tmp/bitmaps2.qcow2: Operation not supported
setfattr: /tmp/bitmaps2.qcow2: Operation not supported

The 6 failed 'setfattrs' correspond to the wrong prefix.

Select the correct prefix based on the kernel name and modify the code
appropriately.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agolibvirt_recover_xattrs: Avoid backticks for subshell
Peter Krempa [Wed, 2 Dec 2020 08:57:30 +0000 (09:57 +0100)] 
libvirt_recover_xattrs: Avoid backticks for subshell

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu_command: Move dimm into qemuBuildDeviceAddressStr()
Michal Privoznik [Tue, 3 Nov 2020 16:31:27 +0000 (17:31 +0100)] 
qemu_command: Move dimm into qemuBuildDeviceAddressStr()

So far our memory modules could go only into DIMM slots. But with
virtio model this assumption is no longer true - virtio-pmem goes
onto PCI bus. But for formatting PCI address onto command line we
already have a function - qemuBuildDeviceAddressStr(). Therefore,
mode DIMM address generation into it so that we don't have to
special case address building later on.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agoqemu: Move mem validation into post parse validator
Michal Privoznik [Fri, 20 Nov 2020 08:49:18 +0000 (09:49 +0100)] 
qemu: Move mem validation into post parse validator

There is this function qemuDomainDefValidateMemoryHotplug() which
is called explicitly from hotplug path and the qemu's domain def
validator. This is not really necessary because we can move the
part that validates feature against qemuCaps into device
validator which is called implicitly (from qemu driver's POV).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agovirDomainMemoryTargetDefFormat: Utilize virXMLFormatElement()
Michal Privoznik [Fri, 20 Nov 2020 11:16:58 +0000 (12:16 +0100)] 
virDomainMemoryTargetDefFormat: Utilize virXMLFormatElement()

The virDomainMemoryTargetDefFormat() uses good old style of
formatting child buffer (virBufferAdjustIndent()). When switched
to virXMLFormatElement() we can save a couple of lines

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agovirDomainMemorySourceDefFormat: Utilize virXMLFormatElement()
Michal Privoznik [Sun, 1 Nov 2020 10:08:32 +0000 (11:08 +0100)] 
virDomainMemorySourceDefFormat: Utilize virXMLFormatElement()

The virDomainMemorySourceDefFormat() uses good old style of
formatting child buffer (virBufferAdjustIndent()). When switched
to virXMLFormatElement() we can save a couple of lines.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agodomain_conf: Fix virDomainMemoryModel type
Michal Privoznik [Sat, 31 Oct 2020 20:24:08 +0000 (21:24 +0100)] 
domain_conf: Fix virDomainMemoryModel type

The virDomainMemoryModel structure has a @type member which is
really type of virDomainMemoryModel but we store it as int
because the virDomainMemoryModelTypeFromString() call stores its
retval right into it. Then, to have compiler do compile time
check for us, every switch() typecasts the @type. This is
needlessly verbose because the parses already has @val - a
variable to store temporary values. Switch @type in the struct to
virDomainMemoryModel and drop all typecasts.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agoconf: Require nvdimm path in validate step
Michal Privoznik [Wed, 4 Nov 2020 15:09:39 +0000 (16:09 +0100)] 
conf: Require nvdimm path in validate step

Our code expects that a nvdimm has a path defined always. And the
parser does check for that. Well, not fully - only when parsing
<source/> (which is an optional element). So if the element is
not in the XML then the check is not performed and the assumption
is broken. Verify in the memory def validator that a path was
set.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agoqemu_domain_address: Reformat qemuDomainAssignS390Addresses()
Michal Privoznik [Tue, 3 Nov 2020 14:49:02 +0000 (15:49 +0100)] 
qemu_domain_address: Reformat qemuDomainAssignS390Addresses()

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agodomain_conf: Check NVDIMM UUID in ABI stability
Michal Privoznik [Wed, 25 Nov 2020 10:38:22 +0000 (11:38 +0100)] 
domain_conf: Check NVDIMM UUID in ABI stability

The UUID is guest visible and thus shouldn't change if we want to
not break guest ABI.

Fixes: 08ed673901bb5b4f419b37bcce9b11d31ce370e6
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agodocs: Fix nvdimm example wrt to <uuid/>
Michal Privoznik [Mon, 2 Nov 2020 10:59:08 +0000 (11:59 +0100)] 
docs: Fix nvdimm example wrt to <uuid/>

On PPC platform it is required that a NVDIMM has an UUID. If none
is provided then libvirt generates one during parsing (see
v6.2.0-rc1~96 and friends). However, the example provided in our
documentation is not valid XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agointernal.h: Introduce and use VIR_IS_POW2()
Michal Privoznik [Wed, 4 Nov 2020 18:41:27 +0000 (19:41 +0100)] 
internal.h: Introduce and use VIR_IS_POW2()

This macro checks whether given number is an integer power of
two. At the same time, I've identified two places where we check
for pow2 and I'm replacing them with the macro.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agoviruuid: Rework virUUIDIsValid()
Michal Privoznik [Tue, 24 Nov 2020 10:12:27 +0000 (11:12 +0100)] 
viruuid: Rework virUUIDIsValid()

The only test we do when checking for UUID validity is that
whether all bytes are the same (invalid UUID) or not (valid
UUID). The algorithm we use is needlessly complicated.

Also, the checked UUID is not modified and hence the argument can
be of 'const' type.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Tested-by: Han Han <hhan@redhat.com>
4 years agoconf: checkpoint: Don't require <domain> when redefining checkpoints
Peter Krempa [Wed, 2 Dec 2020 13:18:40 +0000 (14:18 +0100)] 
conf: checkpoint: Don't require <domain> when redefining checkpoints

The domain definition stored with a checkpoint isn't used currently
apart from matching disks when creating a new checkpoints.

As some users of the incremental backup API want to provide backups in
offline mode under their control (obviously while compying with our
documentation on how the on-disk state should be handled) and then want
to define the checkpoint for live use, supplying a <domain> sub-element
is overly complex and not actually needed by the code.

Relax the restriction when re-defining a checkpoint so that <domain> is
not necessary and add (alibistic) documentation saying that future
actions may not work if it's missing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoconf: checkpoint: Prepare internals for missing domain definition
Peter Krempa [Wed, 2 Dec 2020 13:13:17 +0000 (14:13 +0100)] 
conf: checkpoint: Prepare internals for missing domain definition

Conditionalize code which assumes that the domain definition stored in
the checkpoint is present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirDomainCheckpointRedefineCommit: Don't check ABI of definition in checkpoint
Peter Krempa [Wed, 2 Dec 2020 12:35:29 +0000 (13:35 +0100)] 
virDomainCheckpointRedefineCommit: Don't check ABI of definition in checkpoint

Checking the definition ABI when redefining checkpoints doesn't make
much sense for the following reasons:

* the domain definition in the checkpoint is mostly unused (a relic
  adopted from the snapshot code)

* can be very easily overridden by deleting the checkpoint metadata
  before redefinition

Rather than complicating the logic when we'll be taking into account
that the domain definition may be missing, let's just remove the check.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirDomainCheckpointDefParse: Use 'unsigned int' for flags
Peter Krempa [Wed, 2 Dec 2020 13:33:21 +0000 (14:33 +0100)] 
virDomainCheckpointDefParse: Use 'unsigned int' for flags

Fix the type for a variable holding flags to the usual 'unsigned int'
and change the name to be more appropriate to its use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirDomainCheckpointDefParse: Don't extract unused domain type
Peter Krempa [Wed, 2 Dec 2020 13:29:30 +0000 (14:29 +0100)] 
virDomainCheckpointDefParse: Don't extract unused domain type

We can extract './domain' directly and let the parser deal with the
type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agotests: Simplify some ppc64 tests
Andrea Bolognani [Wed, 2 Dec 2020 19:02:52 +0000 (20:02 +0100)] 
tests: Simplify some ppc64 tests

We can leave out things like USB controller, memballoon device,
kernel and initrd since they're not the focus of the tests.

Propagating some information from the output files back to the
input files makes it easier to compare them, as it reduces the
resulting diff, and in the case of the qemuxml2xml test for
memory-hotplug-ppc64-nonuma it allows us to convert the output
file into a symlink, since in the specific case the XML doesn't
change at all.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agotests: Sync some ppc64 tests
Andrea Bolognani [Wed, 2 Dec 2020 18:56:57 +0000 (19:56 +0100)] 
tests: Sync some ppc64 tests

The ppc64 tests

  memory-hotplug-ppc64-nonuma
  memory-hotplug-nvdimm-ppc64

are not passed the same information for qemuxml2argv and
qemuxml2xml tests; the former, in particular, doesn't show up
at all in qemuxml2xml. Address this inconsistency.

Note that one of the new output files had been introduced with
5540acb9a2bd despite not being actually used as of that commit.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agocpu_map: Fix Icelake Server model number
Tim Wiederhake [Wed, 2 Dec 2020 10:38:22 +0000 (11:38 +0100)] 
cpu_map: Fix Icelake Server model number

See arch/x86/include/asm/intel-family.h in the Kernel:
  #define INTEL_FAM6_ICELAKE_X 0x6A

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
4 years agoapparmor: Allow lxc processes to receive signals from libvirt
Jim Fehlig [Wed, 2 Dec 2020 23:24:21 +0000 (16:24 -0700)] 
apparmor: Allow lxc processes to receive signals from libvirt

LXC processes confined by apparmor are not permitted to receive signals
from libvirtd. Attempting to destroy such a process fails

virsh --connect lxc:/// destroy distro_apparmor
 error: Failed to destroy domain distro_apparmor
 error: Failed to kill process 29491: Permission denied

And from /var/log/audit/audit.log

type=AVC msg=audit(1606949706.142:6345): apparmor="DENIED"
operation="signal" profile="libvirt-314b7109-fdce-48dc-ad28-7c47958a27c1"
pid=29390 comm="libvirtd" requested_mask="receive" denied_mask="receive"
signal=term peer="libvirtd"

Similar to the libvirt-qemu abstraction, add a rule to the libvirt-lxc
abstraction allowing reception of signals from libvirtd.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
4 years agoqemuxml2xmltest.c: honor ARG_PARSEFLAGS
Daniel Henrique Barboza [Wed, 18 Nov 2020 16:28:09 +0000 (13:28 -0300)] 
qemuxml2xmltest.c: honor ARG_PARSEFLAGS

At this moment,  it is not possible to create a test specifying
ARG_PARSEFLAGS because info->parseFlags is not being forwarded to
testCompareDomXML2XMLFiles(). Let's fix it now so next patch can
make use of it.

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: move memory size align to qemuProcessPrepareDomain()
Daniel Henrique Barboza [Wed, 18 Nov 2020 18:12:51 +0000 (15:12 -0300)] 
qemu: move memory size align to qemuProcessPrepareDomain()

qemuBuildCommandLine() is calling qemuDomainAlignMemorySizes(),
which is an operation that changes live XML and domain and has
little to do with the command line build process.

Move it to qemuProcessPrepareDomain() where we're supposed to
make live XML and domain changes before launch. qemuProcessStart()
is setting VIR_QEMU_PROCESS_START_NEW if !migrate && !snapshot,
same conditions used in qemuBuildCommandLine() to call
qemuDomainAlignMemorySizes(), making this change seamless.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu_process.c: check migrateURI when setting VIR_QEMU_PROCESS_START_NEW
Daniel Henrique Barboza [Wed, 18 Nov 2020 17:56:24 +0000 (14:56 -0300)] 
qemu_process.c: check migrateURI when setting VIR_QEMU_PROCESS_START_NEW

qemuProcessCreatePretendCmdPrepare() is setting the
VIR_QEMU_PROCESS_START_NEW regardless of whether this is
a migration case or not. This behavior differs from what we're
doing in qemuProcessStart(), where the flag is set only
if !migrate && !snapshot.

Fix it by making the flag setting consistent with what we're
doing in qemuProcessStart().

Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: Pass / fill niothreads for qemuMonitorGetIOThreads
John Ferlan [Wed, 2 Dec 2020 17:34:24 +0000 (12:34 -0500)] 
qemu: Pass / fill niothreads for qemuMonitorGetIOThreads

Let's pass along / fill @niothreads rather than trying to make dual
use as a return value and thread count.

This resolves a Coverity issue detected in qemuDomainGetIOThreadsMon
where if qemuDomainObjExitMonitor failed, then a -1 was returned and
overwrite @niothreads causing a memory leak.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoutil: squelch G_DEFINE_TYPE volatile warnings with GCC 11
Daniel P. Berrangé [Thu, 3 Dec 2020 11:33:29 +0000 (11:33 +0000)] 
util: squelch G_DEFINE_TYPE volatile warnings with GCC 11

In this previous commit:

  commit 65491a2dfe00bfcf9f09a8d6eab60234b56c8cc4
  Author: Martin Kletzander <mkletzan@redhat.com>
  Date:   Thu Nov 12 13:58:53 2020 +0100

    Do not disable incompatible-pointer-types-discards-qualifiers

We selectively rewrite G_DEFINE_TYPE to avoid warnings about
mismatched volatile/non-volatile pointers that appeared with
CLang when using GLib2 >= 2.67

We have now just hit the reverse problem, GCC >= 11 has started
warning about mismatched volatile/non-volatile pointers but only
with GLib2 < 2.67. The new GLib2 avoids the warning, as does
older GCC.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agosrc: use singular form instead of plural, for guest disk info
Daniel P. Berrangé [Wed, 2 Dec 2020 12:08:14 +0000 (12:08 +0000)] 
src: use singular form instead of plural, for guest disk info

Existing practice with the filesystem fields reported for the
virDomainGetGuestInfo API is to use the singular form for
field names. Ensure the disk info follows this practice.

Fixes

  commit 05a75ca2ce743bc0bb119fb8d532ff84646fafa3
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Fri Nov 20 22:09:46 2020 +0400

    domain: add disk informations to virDomainGetGuestInfo

  commit 0cb2d9f05d00497a715352f6ea28cf8fb6921731
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Fri Nov 20 22:09:47 2020 +0400

    qemu_driver: report guest disk informations

  commit 172b8304352b1945e328394e61290a24446280dd
  Author: Marc-André Lureau <marcandre.lureau@redhat.com>
  Date:   Fri Nov 20 22:09:48 2020 +0400

    virsh: add --disk informations to guestinfo command

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agovirDomainSnapshotAlignDisks: Use virDomainDiskByName
Peter Krempa [Tue, 1 Dec 2020 16:55:54 +0000 (17:55 +0100)] 
virDomainSnapshotAlignDisks: Use virDomainDiskByName

We don't need the index that virDomainDiskIndexByName returns.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: Use virDomainDiskByName
Peter Krempa [Tue, 1 Dec 2020 16:55:54 +0000 (17:55 +0100)] 
virDomainCheckpointAlignDisks: Use virDomainDiskByName

We don't need the index that virDomainDiskIndexByName returns.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainDiskByName: Remove ternary operator
Peter Krempa [Tue, 1 Dec 2020 16:54:41 +0000 (17:54 +0100)] 
virDomainDiskByName: Remove ternary operator

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointDiskDef: Remove unused 'idx' field
Peter Krempa [Wed, 2 Dec 2020 12:08:31 +0000 (13:08 +0100)] 
virDomainCheckpointDiskDef: Remove unused 'idx' field

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: refactor extension to all disks
Peter Krempa [Tue, 1 Dec 2020 17:10:00 +0000 (18:10 +0100)] 
virDomainCheckpointAlignDisks: refactor extension to all disks

Similarly to d3c029bb105 where we've refactored
virDomainSnapshotAlignDisks, modify the extension algorithm to avoid use
of the 'idx' variable and sorting of the array.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: Extract domain disk def pointer to 'domdisk'
Peter Krempa [Tue, 1 Dec 2020 17:03:47 +0000 (18:03 +0100)] 
virDomainCheckpointAlignDisks: Extract domain disk def pointer to 'domdisk'

Add a local variable holding the pointer instead of indexing the array
multiple times.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: Use 'chkdisk' instead of 'disk'
Peter Krempa [Tue, 1 Dec 2020 16:22:21 +0000 (17:22 +0100)] 
virDomainCheckpointAlignDisks: Use 'chkdisk' instead of 'disk'

Clarify that the variable refers to the definition of the disk from the
checkpoint definition.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: rename 'def' to 'chkdef'
Peter Krempa [Tue, 1 Dec 2020 16:20:10 +0000 (17:20 +0100)] 
virDomainCheckpointAlignDisks: rename 'def' to 'chkdef'

In most cases 'def' is used for the domain definition. Rename it to
chkdef to prevent confusion.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: Use 'domdef' for domain definition
Peter Krempa [Tue, 1 Dec 2020 16:18:44 +0000 (17:18 +0100)] 
virDomainCheckpointAlignDisks: Use 'domdef' for domain definition

Extract the pointer and use a local variable throughout the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: Unbreak error message
Peter Krempa [Tue, 1 Dec 2020 16:57:23 +0000 (17:57 +0100)] 
virDomainCheckpointAlignDisks: Unbreak error message

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirDomainCheckpointAlignDisks: Refactor cleanup
Peter Krempa [Tue, 1 Dec 2020 16:04:03 +0000 (17:04 +0100)] 
virDomainCheckpointAlignDisks: Refactor cleanup

Use g_autoptr for virBitmap and get rid of the 'cleanup:' label and ret
variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoconf: Fix segfault when parsing mdev types
Jonathon Jongsma [Wed, 2 Dec 2020 17:52:39 +0000 (11:52 -0600)] 
conf: Fix segfault when parsing mdev types

Commit f1b0890 introduced a potential crash due to incorrect operator
precedence when accessing an element from a pointer to an array.

Backtrace below:

  #0  virNodeDeviceGetMdevTypesCaps (sysfspath=0x7fff801661e0 "/sys/devices/pci0000:00/0000:00:02.0", mdev_types=0x7fff801c9b40, nmdev_types=0x7fff801c9b48) at ../src/conf/node_device_conf.c:2676
  #1  0x00007ffff7caf53d in virNodeDeviceGetPCIDynamicCaps (sysfsPath=0x7fff801661e0 "/sys/devices/pci0000:00/0000:00:02.0", pci_dev=0x7fff801c9ac8) at ../src/conf/node_device_conf.c:2705
  #2  0x00007ffff7cae38f in virNodeDeviceUpdateCaps (def=0x7fff80168a10) at ../src/conf/node_device_conf.c:2342
  #3  0x00007ffff7cb11c0 in virNodeDeviceObjMatch (obj=0x7fff84002e50, flags=0) at ../src/conf/virnodedeviceobj.c:850
  #4  0x00007ffff7cb153d in virNodeDeviceObjListExportCallback (payload=0x7fff84002e50, name=0x7fff801cbc20 "pci_0000_00_02_0", opaque=0x7fffe2ffc6a0) at ../src/conf/virnodedeviceobj.c:909
  #5  0x00007ffff7b69146 in virHashForEach (table=0x7fff9814b700 = {...}, iter=0x7ffff7cb149e <virNodeDeviceObjListExportCallback>, opaque=0x7fffe2ffc6a0) at ../src/util/virhash.c:394
  #6  0x00007ffff7cb1694 in virNodeDeviceObjListExport (conn=0x7fff98013170, devs=0x7fff98154430, devices=0x7fffe2ffc798, filter=0x7ffff7cf47a1 <virConnectListAllNodeDevicesCheckACL>, flags=0)
          at ../src/conf/virnodedeviceobj.c:943
  #7  0x00007fffe00694b2 in nodeConnectListAllNodeDevices (conn=0x7fff98013170, devices=0x7fffe2ffc798, flags=0) at ../src/node_device/node_device_driver.c:228
  #8  0x00007ffff7e703aa in virConnectListAllNodeDevices (conn=0x7fff98013170, devices=0x7fffe2ffc798, flags=0) at ../src/libvirt-nodedev.c:130
  #9  0x000055555557f796 in remoteDispatchConnectListAllNodeDevices (server=0x555555627080, client=0x5555556bf050, msg=0x5555556c0000, rerr=0x7fffe2ffc8a0, args=0x7fffd4008470, ret=0x7fffd40084e0)
          at src/remote/remote_daemon_dispatch_stubs.h:1613
  #10 0x000055555557f6f9 in remoteDispatchConnectListAllNodeDevicesHelper (server=0x555555627080, client=0x5555556bf050, msg=0x5555556c0000, rerr=0x7fffe2ffc8a0, args=0x7fffd4008470, ret=0x7fffd40084e0)
          at src/remote/remote_daemon_dispatch_stubs.h:1591
  #11 0x00007ffff7ce9542 in virNetServerProgramDispatchCall (prog=0x555555690c10, server=0x555555627080, client=0x5555556bf050, msg=0x5555556c0000) at ../src/rpc/virnetserverprogram.c:428
  #12 0x00007ffff7ce90bd in virNetServerProgramDispatch (prog=0x555555690c10, server=0x555555627080, client=0x5555556bf050, msg=0x5555556c0000) at ../src/rpc/virnetserverprogram.c:302
  #13 0x00007ffff7cf042b in virNetServerProcessMsg (srv=0x555555627080, client=0x5555556bf050, prog=0x555555690c10, msg=0x5555556c0000) at ../src/rpc/virnetserver.c:137
  #14 0x00007ffff7cf04eb in virNetServerHandleJob (jobOpaque=0x5555556b66b0, opaque=0x555555627080) at ../src/rpc/virnetserver.c:154
  #15 0x00007ffff7bd912f in virThreadPoolWorker (opaque=0x55555562bc70) at ../src/util/virthreadpool.c:163
  #16 0x00007ffff7bd8645 in virThreadHelper (data=0x55555562bc90) at ../src/util/virthread.c:233
  #17 0x00007ffff6d90432 in start_thread () at /lib64/libpthread.so.0
  #18 0x00007ffff75c5913 in clone () at /lib64/libc.so.6

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoTranslated using Weblate (Finnish)
Ricky Tigg [Thu, 3 Dec 2020 06:30:59 +0000 (07:30 +0100)] 
Translated using Weblate (Finnish)

Currently translated at 8.8% (921 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 8.7% (914 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 7.6% (797 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 6.6% (695 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 6.2% (657 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 4.7% (501 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 4.7% (493 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 4.7% (491 of 10440 strings)

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

Translated using Weblate (Finnish)

Currently translated at 4.6% (489 of 10440 strings)

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

Co-authored-by: Ricky Tigg <ricky.tigg@gmail.com>
Signed-off-by: Ricky Tigg <ricky.tigg@gmail.com>
4 years agoTranslated using Weblate (Swedish)
Göran Uddeborg [Thu, 3 Dec 2020 06:30:58 +0000 (07:30 +0100)] 
Translated using Weblate (Swedish)

Currently translated at 11.9% (1250 of 10440 strings)

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

Translated using Weblate (Swedish)

Currently translated at 11.6% (1220 of 10440 strings)

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

Co-authored-by: Göran Uddeborg <goeran@uddeborg.se>
Signed-off-by: Göran Uddeborg <goeran@uddeborg.se>
4 years agoqemu: support logfile on live attaching chardev
Nikolay Shirokovskiy [Wed, 2 Dec 2020 11:44:38 +0000 (14:44 +0300)] 
qemu: support logfile on live attaching chardev

Currently it is simply ignored.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agoqemu: support append param on live attaching file chardev
Nikolay Shirokovskiy [Wed, 2 Dec 2020 11:43:25 +0000 (14:43 +0300)] 
qemu: support append param on live attaching file chardev

Currently it is simply ignored.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agocoding-style: Document 100 chars limit for line length
Michal Privoznik [Mon, 30 Nov 2020 12:55:12 +0000 (13:55 +0100)] 
coding-style: Document 100 chars limit for line length

The idea is to have it like a soft limit: if possible then break
lines, if not then have a long line instead of some creative
approach.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemu: Fix some issues in virQEMUDriverConfigLoadNVRAMEntry
John Ferlan [Wed, 2 Dec 2020 12:43:21 +0000 (07:43 -0500)] 
qemu: Fix some issues in virQEMUDriverConfigLoadNVRAMEntry

Commit c4f4e195 fixed a double free, but if the code returns before
we realloc the list and virFirmwareFreeList was called with cfg->nfirmwares
> 0 (e.g. during virQEMUDriverConfigDispose), then it would be rather
disastrous. So let's reinitialize that too to indicate the list is empty.

Coverity pointed out that using nvram[0] as a guard to reallocating the
list could lead to a possible NULL deref. While nvram[0] may always be
true in this case, if it wasn't then the subsequent for loop would fail.
Just reallocate always regardless - even if nfirmwares == 0 as
virFirmwareFreeList will free it for us anyway.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agolocking: Resolve mem leak in virLockDaemonPreExecRestart
John Ferlan [Wed, 2 Dec 2020 12:43:20 +0000 (07:43 -0500)] 
locking: Resolve mem leak in virLockDaemonPreExecRestart

Initialize and free @magic since virJSONValueObjectAppendString
does not free it for us eventually.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agologging: Resolve mem leak in virLogDaemonPreExecRestart
John Ferlan [Wed, 2 Dec 2020 12:43:19 +0000 (07:43 -0500)] 
logging: Resolve mem leak in virLogDaemonPreExecRestart

Initialize and free @magic since virJSONValueObjectAppendString
does not free it for us eventually.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agodocs: Fix link for virConnectGetStoragePoolCapabilities
John Ferlan [Wed, 2 Dec 2020 12:43:17 +0000 (07:43 -0500)] 
docs: Fix link for virConnectGetStoragePoolCapabilities

The API is in the storage family not the domain family

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoutil: Fix memory leak in virNetDevOpenvswitchInterfaceGetMaster
John Ferlan [Wed, 2 Dec 2020 12:43:15 +0000 (07:43 -0500)] 
util: Fix memory leak in virNetDevOpenvswitchInterfaceGetMaster

Since 032548c4 @cmd was never autofree'd. Perhaps as a result of
VIR_AUTOPTR type changes occurring at roughly the same time so the
copy pasta missed this.

Found by Coverity.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu: Drop qemuMonitorGetVirtType()
Michal Privoznik [Wed, 2 Dec 2020 14:47:02 +0000 (15:47 +0100)] 
qemu: Drop qemuMonitorGetVirtType()

It's unused since v5.5.0-rc1~113.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirstring: Drop VIR_AUTOSTRINGLIST
Michal Privoznik [Tue, 1 Dec 2020 08:22:55 +0000 (09:22 +0100)] 
virstring: Drop VIR_AUTOSTRINGLIST

Now that no one uses VIR_AUTOSTRINGLIST it can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agolib: Replace VIR_AUTOSTRINGLIST with GStrv
Michal Privoznik [Tue, 1 Dec 2020 08:21:32 +0000 (09:21 +0100)] 
lib: Replace VIR_AUTOSTRINGLIST with GStrv

Glib provides g_auto(GStrv) which is in-place replacement of our
VIR_AUTOSTRINGLIST.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemuDomainGetGuestInfo: Exit early if getting info fails
Michal Privoznik [Tue, 1 Dec 2020 10:47:13 +0000 (11:47 +0100)] 
qemuDomainGetGuestInfo: Exit early if getting info fails

If there is an error getting info from guest agent, then the
control on qemuDomainGetGuestInfo() jumps onto 'exitagent' label
and subsequently continues on 'endagentjob'. Both labels are hit
also in success case too. The control then continues by
attempting to match fetched info (e.g. disk addresses) with
domain def. But this is needless - the API will return error
regardless.

To return early from the function move both 'exitagent' and
'endagentjob' labels at the end of the function and jump straight
onto 'cleanup' afterwards. This allows us to set 'ret = 0' later
- only when we know we succeeded.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agomeson: add winsock2 library on windows builds
Daniel P. Berrangé [Tue, 1 Dec 2020 20:15:20 +0000 (20:15 +0000)] 
meson: add winsock2 library on windows builds

If building for windows with curl disabled we get build failures due to
missing ws2_32 library needed for winsock2.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoscripts: ignore whitespace in pdwtags output
Daniel P. Berrangé [Wed, 2 Dec 2020 10:20:44 +0000 (10:20 +0000)] 
scripts: ignore whitespace in pdwtags output

The pdwtags program changed its whitespace formatting for enum
values in release 1.19:

  @@ -145,22 +145,22 @@
           u_int                      flags;
   };
   enum admin_procedure {
  -        ADMIN_PROC_CONNECT_OPEN = 1,
  -        ADMIN_PROC_CONNECT_CLOSE = 2,
  -        ADMIN_PROC_CONNECT_GET_LIB_VERSION = 3,
  -        ADMIN_PROC_CONNECT_LIST_SERVERS = 4,
  -        ADMIN_PROC_CONNECT_LOOKUP_SERVER = 5,
  +        ADMIN_PROC_CONNECT_OPEN                     = 1,
  +        ADMIN_PROC_CONNECT_CLOSE                    = 2,
  +        ADMIN_PROC_CONNECT_GET_LIB_VERSION          = 3,
  +        ADMIN_PROC_CONNECT_LIST_SERVERS             = 4,
  +        ADMIN_PROC_CONNECT_LOOKUP_SERVER            = 5,

Workaround this by telling diff to ignore whitespace changes.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agoqemuMonitorGetCommandLineOptionParameters: remove the unused function and helpers
Peter Krempa [Mon, 30 Nov 2020 17:13:32 +0000 (18:13 +0100)] 
qemuMonitorGetCommandLineOptionParameters: remove the unused function and helpers

Remove the function along with helpers for caching the reply and tests.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovirQEMUCapsProbeQMPCommandLine: Rewrite using qemuMonitorGetCommandLineOptions
Peter Krempa [Mon, 30 Nov 2020 17:05:23 +0000 (18:05 +0100)] 
virQEMUCapsProbeQMPCommandLine: Rewrite using qemuMonitorGetCommandLineOptions

Use the new handler to fetch the required data and do the extraction
locally without conversion to string list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: monitor: Implement new handlers for 'query-command-line-options'
Peter Krempa [Mon, 30 Nov 2020 16:54:25 +0000 (17:54 +0100)] 
qemu: monitor: Implement new handlers for 'query-command-line-options'

Add a new set hander for getting the data for
'query-command-line-options' which returns everything at once and lets
the caller extract the data. This way we don't need to cache the output
of the monitor command for repeated calls.

Note that we will have enough testing of this code path via
qemucapabilitiestest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agogitlab: Add issue template for a feature request
Peter Krempa [Thu, 26 Nov 2020 13:16:16 +0000 (14:16 +0100)] 
gitlab: Add issue template for a feature request

Try to motivate the users to describe what they want to achieve before
diving down into technical specifics.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agogitlab: Add issue template for reporting a bug
Peter Krempa [Thu, 26 Nov 2020 13:09:46 +0000 (14:09 +0100)] 
gitlab: Add issue template for reporting a bug

When reporting an issue in gitlab, the project can define a template for
various scenarios which are meant to guide the users to add the relevant
information the project needs to the reported issue.

Add a template for a bug report against libvirt. The template adds
sections which motivate users to add version information and also link
to documentation about fetching logs and such.

Note that markdown seems to be the only supported format for now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
4 years agodomain_conf.c: modernize virDomainDefControllersParse()
Daniel Henrique Barboza [Tue, 24 Nov 2020 14:22:00 +0000 (11:22 -0300)] 
domain_conf.c: modernize virDomainDefControllersParse()

The 'error' label is just returning -1, so let's 'return -1'
directly.

Use g_autoptr() with virDomainControllerDefPtr to remove the
need to call virDomainControllerDefFree() in the error path.

There is no need to VIR_FREE(nodes) explictly since 'nodes'
is using g_autofree.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: modernize virDomainControllerDefParseXML()
Daniel Henrique Barboza [Tue, 24 Nov 2020 14:12:51 +0000 (11:12 -0300)] 
domain_conf.c: modernize virDomainControllerDefParseXML()

Let's register AUTOPTR_CLEANUP_FUNC for virDomainControllerDefPtr
and modernize this function, removing the 'error' label using
g_autoptr().

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: remove 'error' label in virDomainDefTunablesParse()
Daniel Henrique Barboza [Mon, 23 Nov 2020 13:06:55 +0000 (10:06 -0300)] 
domain_conf.c: remove 'error' label in virDomainDefTunablesParse()

The 'error' label is just doing a 'return -1'.

There's also a couple of 'VIR_FREE(nodes)' calls that are happening
right before exiting on error, but 'nodes' is already set for
autocleanup. These calls can also be removed.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: modernize virDomainSmartcardDefParseXML
Daniel Henrique Barboza [Fri, 20 Nov 2020 19:09:13 +0000 (16:09 -0300)] 
domain_conf.c: modernize virDomainSmartcardDefParseXML

Register a AUTOPTR_CLEANUP_FUNC for virDomainSmartcardDef and use
g_autoptr() to eliminate the 'error' label.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf: modernize virDomainDiskDefParseXML()
Daniel Henrique Barboza [Thu, 19 Nov 2020 21:05:21 +0000 (18:05 -0300)] 
domain_conf: modernize virDomainDiskDefParseXML()

Register an AUTOPTR_CLEANUP_FUNC for virDomainDiskDefPtr, then
use g_autoptr() in virDomainDiskDef and virStorageEncryption
pointers to get rid of the 'cleanup' and 'error' labels.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agovirstorageencryption.h: add AUTOPTR_CLEANUP_FUNC for virStorageEncryptionPtr
Daniel Henrique Barboza [Thu, 19 Nov 2020 21:03:42 +0000 (18:03 -0300)] 
virstorageencryption.h: add AUTOPTR_CLEANUP_FUNC for virStorageEncryptionPtr

This will open an opportunity to modernize virDomainDiskDefParseXML()
in the next patch.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: use g_autoptr() with virDomainVideoDefPtr
Daniel Henrique Barboza [Thu, 19 Nov 2020 20:02:35 +0000 (17:02 -0300)] 
domain_conf.c: use g_autoptr() with virDomainVideoDefPtr

This will modernize virDomainVideoDefParseXML() and
virDomainDefAddImplicitVideo() by removing unneeded
cleanup labels.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: do not leak 'video' in virDomainDefParseXML()
Daniel Henrique Barboza [Thu, 19 Nov 2020 16:57:43 +0000 (13:57 -0300)] 
domain_conf.c: do not leak 'video' in virDomainDefParseXML()

The 'video' pointer is only being freed on error path, meaning
that we're leaking it after each loop restart.

There are more opportunities for auto cleanups of virDomainVideoDef
pointers, so let's register AUTOPTR_CLEANUP_FUNC for it to use
g_autoptr() later on.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: modernize virDomainDefBootOrderPostParse()
Daniel Henrique Barboza [Mon, 16 Nov 2020 20:40:17 +0000 (17:40 -0300)] 
domain_conf.c: modernize virDomainDefBootOrderPostParse()

Use g_autoptr() with the hash and remove the 'cleanup' label.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agodomain_conf.c: use g_autofree in 'dev' in virDomainDefParseBootXML()
Daniel Henrique Barboza [Mon, 16 Nov 2020 20:34:00 +0000 (17:34 -0300)] 
domain_conf.c: use g_autofree in 'dev' in virDomainDefParseBootXML()

This spares us of 2 explicit VIR_FREE() calls.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
4 years agotestsutilsqemu: check return value of virQEMUCapsNewCopy
Ján Tomko [Fri, 20 Nov 2020 12:39:37 +0000 (13:39 +0100)] 
testsutilsqemu: check return value of virQEMUCapsNewCopy

While for virQEMUCapsNew this should not be needed
(the possible failures in VIR_CLASS_NEW are only hit
 on bad API usage which we don't do here),
virQEMUCapsNewCopy calls into many other functions,
some of which actually fail.

Check the return value of both.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu: use qemuVirCommandGetDevSet less
Ján Tomko [Tue, 24 Nov 2020 13:49:19 +0000 (14:49 +0100)] 
qemu: use qemuVirCommandGetDevSet less

Do not look up the index of the passed FD in places where
we already have it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoqemu: introduce qemuBuildFDSet
Ján Tomko [Tue, 24 Nov 2020 13:42:58 +0000 (14:42 +0100)] 
qemu: introduce qemuBuildFDSet

An alternative to qemuVirCommandGetFDSet that takes the index
into the passed FD set as an argument and does not try to look it up.

Use it as well ass virCommandPassFDIndex in qemuBuildChrChardevFileStr
and qemuBuildInterfaceCommandLine.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoutil: introduce virCommandPassFDIndex
Ján Tomko [Tue, 24 Nov 2020 13:11:36 +0000 (14:11 +0100)] 
util: introduce virCommandPassFDIndex

Just like virCommandPassFD, but it also returns an index of
the passed FD in the FD set.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
4 years agoudevConnectListAllInterfaces: delete pointless cleanup code
Ján Tomko [Fri, 20 Nov 2020 13:10:58 +0000 (14:10 +0100)] 
udevConnectListAllInterfaces: delete pointless cleanup code

We only jump to cleanup before allocating any lists.

Drop the dead code.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoudevConnectListAllInterfaces: initialize ret
Ján Tomko [Fri, 20 Nov 2020 13:05:54 +0000 (14:05 +0100)] 
udevConnectListAllInterfaces: initialize ret

Currently, ret is only used in the 'cleanup' section
and initialized right before the jump.

Switch to the customary initialization to -1 and only
leave in the 'ret = 0' statement on an empty list.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agoqemu: Use virJSONValueObjectGetStringArray() more
Michal Privoznik [Tue, 1 Dec 2020 10:47:30 +0000 (11:47 +0100)] 
qemu: Use virJSONValueObjectGetStringArray() more

In a few commit back (v6.10.0-5-gb3dad96972) a new helper for
obtaining string arrays from a virJSONObject was introduced:
virJSONValueObjectGetStringArray(). I've identified three places
where it can be used instead of open coding it:
qemuAgentSSHGetAuthorizedKeys(),
qemuMonitorJSONGetStringListProperty() and
qemuMonitorJSONGetCPUDefinitions().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovirJSONValueObjectGetStringArray: Report error if @key is not an array
Michal Privoznik [Tue, 1 Dec 2020 11:10:34 +0000 (12:10 +0100)] 
virJSONValueObjectGetStringArray: Report error if @key is not an array

The virJSONValueObjectGetStringArray() function is given a @key
which is supposed to be an array inside given @object. Well, if
it's not then an error state is returned (NULL), but no error
message is set.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agodocs: Update language bindings spotlight
Andrea Bolognani [Tue, 1 Dec 2020 15:30:52 +0000 (16:30 +0100)] 
docs: Update language bindings spotlight

We should highlight the language bindings that are actively
maintained, keep up with the core library's development pace,
have good API coverage and are relevant to people looking to
integrate libvirt into their projects today: based on these
criteria, it makes sense to highlight the Go binding instead
of the Java one.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agoqemu_conf: Fix double free problem for cfg->firmwares
Tuguoyi [Tue, 24 Nov 2020 03:12:00 +0000 (03:12 +0000)] 
qemu_conf: Fix double free problem for cfg->firmwares

cfg->firmwares still points to the original memory address after being
freed by virFirmwareFreeList(). As cfg get freed, it will be freed again
even if cfg->nfirmwares=0 which eventually lead to crash.

The patch fix it by setting cfg->firmwares to NULL explicitly after
virFirmwareFreeList() returns

Signed-off-by: Guoyi Tu<tu.guoyi@h3c.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
4 years agovircgroupv2: fix virCgroupV2DenyDevice
Pavel Hrdina [Wed, 25 Nov 2020 16:21:49 +0000 (17:21 +0100)] 
vircgroupv2: fix virCgroupV2DenyDevice

The original logic is incorrect. We would delete the device entry
from eBPF map only if the newval would be same as current val in the
map. In case that the device was allowed only as read-only but later
we remove all permissions for that device it would remain in the table
with empty values.

The old code would still deny the device but it's not working as
intended. Instead we will update the value in advance. If the updated
value is 0 it means that we are removing all permissions so it should
be removed from the map, otherwise we will update the value in map.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
4 years agovircgroup: fix cpu quota maximum limit
Pavel Hrdina [Wed, 25 Nov 2020 11:41:16 +0000 (12:41 +0100)] 
vircgroup: fix cpu quota maximum limit

Kernel commit <d505b8af58912ae1e1a211fabc9995b19bd40828> added proper
check for cpu quota maximum limit to prevent internal overflow.

Even though this change is not present in all kernels it makes sense
to enforce the same limit in libvirt.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>