]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
5 years agoqemuDomainValidateStorageSource: Validate new network storage parameters
Peter Krempa [Thu, 5 Mar 2020 16:59:04 +0000 (17:59 +0100)]
qemuDomainValidateStorageSource: Validate new network storage parameters

Ensure that the new fields are allowed only when -blockdev is used or
when they are in the detected part of the backing chain where qemu will
handle them internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Add support for setting timeout and readahead size for network disks
Peter Krempa [Thu, 5 Mar 2020 15:50:46 +0000 (16:50 +0100)]
conf: Add support for setting timeout and readahead size for network disks

Some disk backends support configuring the readahead buffer or timeout
for requests. Add the knobs to the XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Add support for cookies for HTTP based disks
Peter Krempa [Tue, 9 May 2017 12:52:40 +0000 (14:52 +0200)]
conf: Add support for cookies for HTTP based disks

Add possibility to specify one or more cookies for http based disks.
This patch adds the config parser, storage and validation of the
cookies.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoconf: Add support for modifying ssl validation for https/ftps disks
Peter Krempa [Fri, 28 Apr 2017 10:24:46 +0000 (12:24 +0200)]
conf: Add support for modifying ssl validation for https/ftps disks

To allow turning off verification of SSL cerificates add a new element
<ssl> to the disk source XML which will allow configuring the validation
process using the 'verify' attribute.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainGetSecretAESAlias: Replace outstanding uses with qemuAliasForSecret
Peter Krempa [Mon, 9 Mar 2020 07:03:34 +0000 (08:03 +0100)]
qemuDomainGetSecretAESAlias: Replace outstanding uses with qemuAliasForSecret

There are two last callers of this function. Replace them by
qemuAliasForSecret and delete qemuDomainGetSecretAESAlias.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretStorageSourcePrepare: Change aliases for disk secrets
Peter Krempa [Mon, 9 Mar 2020 05:58:57 +0000 (06:58 +0100)]
qemuDomainSecretStorageSourcePrepare: Change aliases for disk secrets

Originally there was only the secret for authentication so we didn't use
any suffix to tell it apart. With the introduction of encryption we
added a 'luks' suffix for the encryption secrets. Since encryption is
really generic and authentication is not the only secret modify the
aliases for the secrets to better describe what they are used for.

This is possible as we store the disk secrets in the status XML thus
only new machines will use the new secrets.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretAESSetupFromSecret: Use 'qemuAliasForSecret'
Peter Krempa [Mon, 9 Mar 2020 05:56:04 +0000 (06:56 +0100)]
qemuDomainSecretAESSetupFromSecret: Use 'qemuAliasForSecret'

Replace qemuDomainGetSecretAESAlias by the new function so that we can
reuse qemuDomainSecretAESSetupFromSecret also for setting up other kinds
of objects.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Split out initialization of secrets for 'iscsi' hostdevs
Peter Krempa [Mon, 9 Mar 2020 06:31:53 +0000 (07:31 +0100)]
qemu: Split out initialization of secrets for 'iscsi' hostdevs

Currently we don't have infrastructure to remember the secret aliases
for hostdevs. Since an upcoming patch is going to change aliases for
the disks, initialize the iscsi hostdevs separately so that we can keep
the alias. At the same time let's use qemuAliasForSecret instead of
qemuDomainGetSecretAESAlias when unplugging the iscsi hostdev.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainDeviceDiskDefPostParseRestoreSecAlias: Hardcode restored aliases
Peter Krempa [Fri, 6 Mar 2020 14:28:18 +0000 (15:28 +0100)]
qemuDomainDeviceDiskDefPostParseRestoreSecAlias: Hardcode restored aliases

In order to be able to change the function generating the alias and thus
also the aliases itself, we must hardcode the old format for the case of
upgrading form libvirt which didn't record them in the status XML yet.

Note that this code path is tested by
'tests/qemustatusxml2xmldata/disk-secinfo-upgrade-in.xml'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretStorageSourcePrepare: Fix naming of alias variables
Peter Krempa [Fri, 6 Mar 2020 14:13:21 +0000 (15:13 +0100)]
qemuDomainSecretStorageSourcePrepare: Fix naming of alias variables

The naming of the variables was tied to what they are used for not what
the alias represents. Since we'll need to use some of the aliases for
another type of secrets fix the name so that it makes sense.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Introduce another helper for creating alias for a 'secret' object
Peter Krempa [Fri, 6 Mar 2020 14:36:42 +0000 (15:36 +0100)]
qemu: Introduce another helper for creating alias for a 'secret' object

qemuAliasForSecret is meant as a replacement qemuDomainGetSecretAESAlias
with saner API. The sub-type we are creating the alias for is passed in
as a string rather than the unflexible 'isLuks' boolean.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agobuild: workaround behaviour regression in gnu make 4.3
Daniel P. Berrangé [Fri, 13 Mar 2020 18:39:25 +0000 (18:39 +0000)]
build: workaround behaviour regression in gnu make 4.3

We need the "$(space)" variable to contain a single whitespace
character. We do this by assigning and then appending an empty
string to the variable. Variable appends get separated by a
single whitespace historically, but GNU make 4.3 introduced a
behaviour regression.

  https://lists.gnu.org/archive/html/bug-make/2020-01/msg00057.html

[quote]
* WARNING: Backward-incompatibility!
  Previously appending using '+=' to an empty variable would
  result in a value starting with a space.  Now the initial
  space is only added if the variable already contains some
  value.  Similarly, appending an empty string does not
  add a trailing space.
[/quote]

This patch tries a new trick to get a single whitespace by
getting make to expand two non-existant variables separated
by a space.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoRemove qemuDomainSecretInfoNew
Peter Krempa [Mon, 16 Mar 2020 09:42:36 +0000 (10:42 +0100)]
Remove qemuDomainSecretInfoNew

Replace it by a direct call to qemuDomainSecretAESSetupFromSecret.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretAESSetup: Split out lookup of secret data
Peter Krempa [Mon, 16 Mar 2020 09:37:26 +0000 (10:37 +0100)]
qemuDomainSecretAESSetup: Split out lookup of secret data

Split out the lookup of the secret from the secret driver into
qemuDomainSecretAESSetupFromSecret so that we can also instantiate
secret objects in qemu with data from other sources.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretAESSetup: Allocate and return 'secinfo' here
Peter Krempa [Mon, 16 Mar 2020 09:23:24 +0000 (10:23 +0100)]
qemuDomainSecretAESSetup: Allocate and return 'secinfo' here

Rather than passing in an empty qemuDomainSecretInfoPtr allocate it
in this function and return it. This is done by absorbing the check from
qemuDomainSecretInfoNew and removing the internals of
qemuDomainSecretInfoNew.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretAESSetup: Automatically free non-secret locals
Peter Krempa [Mon, 16 Mar 2020 09:13:38 +0000 (10:13 +0100)]
qemuDomainSecretAESSetup: Automatically free non-secret locals

Use g_autofree for the ciphertext and init vector as they are not
secret and thus don't have to be cleared and use g_new0 to allocate the
iv for parity.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainSecretInfo: Register autoptr cleanup function
Peter Krempa [Mon, 16 Mar 2020 08:47:17 +0000 (09:47 +0100)]
qemuDomainSecretInfo: Register autoptr cleanup function

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuMigrationParamsResetTLS: Fix comment
Peter Krempa [Mon, 9 Mar 2020 07:04:54 +0000 (08:04 +0100)]
qemuMigrationParamsResetTLS: Fix comment

The comment mentioned that the function resets migration params, but
that is not true as of commit eb54cb473a8d140e0dd4a7bd42e8bcd72b056368

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuMigrationParamsResetTLS: Adapt to modern memory management
Peter Krempa [Mon, 9 Mar 2020 07:03:49 +0000 (08:03 +0100)]
qemuMigrationParamsResetTLS: Adapt to modern memory management

Use g_autofree instead of VIR_FREE and delete the comment mentioning
possible failure to allocate memory.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: Don't take double pointer in qemuDomainSecretInfoFree
Peter Krempa [Fri, 6 Mar 2020 13:44:43 +0000 (14:44 +0100)]
qemu: Don't take double pointer in qemuDomainSecretInfoFree

Using a double pointer prevents the function from being used as the
automatic cleanup function for the given type.

Remove the double pointer use by replacing the calls with
g_clear_pointer which ensures that the pointer is cleared.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuBlockStorageSourceDetachPrepare: Get rid of cleanup section
Peter Krempa [Fri, 6 Mar 2020 08:45:45 +0000 (09:45 +0100)]
qemuBlockStorageSourceDetachPrepare: Get rid of cleanup section

Use g_new0 to completely avoid the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirt-host-validate: warn if kvm_hv is not loaded for POWER hosts
Daniel Henrique Barboza [Fri, 13 Mar 2020 17:48:03 +0000 (14:48 -0300)]
virt-host-validate: warn if kvm_hv is not loaded for POWER hosts

POWER hosts does not implement CPU virtualization extensions like
x86 or s390x. Instead, all bare-metal POWER hosts are considered
to be virtualization ready.

For POWER, the validation is done by checking if the virtualization
module kvm_hv is loaded in the host. If not, we should warn the
user about it.

Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agonews: Mention regression in virDomainBlockCopy with shallow+reuse flags
Peter Krempa [Fri, 13 Mar 2020 13:24:35 +0000 (14:24 +0100)]
news: Mention regression in virDomainBlockCopy with shallow+reuse flags

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Kashyap Chamarthy <kchamart@redhat.com>
5 years agodocs: update virt-admin.rst for server-update-tls
Zhang Bo [Sat, 7 Mar 2020 11:31:04 +0000 (19:31 +0800)]
docs: update virt-admin.rst for server-update-tls

Update the manpage for the 'server-update-tls' command

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wu Qingliang <wuqingliang4@huawei.com>
5 years agovirt-admin: Introduce command srv-update-tls
Zhang Bo [Sat, 7 Mar 2020 11:31:03 +0000 (19:31 +0800)]
virt-admin: Introduce command srv-update-tls

wire-up virAdmServerUpdateTlsFiles API into virt-admin client.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wu Qingliang <wuqingliang4@huawei.com>
5 years agoadmin: Introduce virAdmServerUpdateTlsFiles
Zhang Bo [Sat, 7 Mar 2020 11:31:02 +0000 (19:31 +0800)]
admin: Introduce virAdmServerUpdateTlsFiles

The server needs to use CA certificate, CRL, server certificate/key to
complete the TLS handshake. If these files change, we needed to restart
libvirtd for them to take effect. This API can update the TLS context
*ONLINE* without restarting libvirtd.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wu Qingliang <wuqingliang4@huawei.com>
5 years agotls: Add a mutex lock on 'tlsCtxt'
Zhang Bo [Sat, 7 Mar 2020 11:31:01 +0000 (19:31 +0800)]
tls: Add a mutex lock on 'tlsCtxt'

Prevent the handshake function from reading 'tlsCtxt' while
updating 'tlsCtxt'.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wu Qingliang <wuqingliang4@huawei.com>
5 years agovirnetserver: Introduce virNetServerUpdateTlsFiles
Zhang Bo [Sat, 7 Mar 2020 11:31:00 +0000 (19:31 +0800)]
virnetserver: Introduce virNetServerUpdateTlsFiles

Add an API to update server's tls context.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Wu Qingliang <wuqingliang4@huawei.com>
5 years agodocs: hacking: move virStrerror to removed functions
Ján Tomko [Mon, 9 Mar 2020 20:01:11 +0000 (21:01 +0100)]
docs: hacking: move virStrerror to removed functions

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotools: vsh.c: remove virstrerror.h include
Ján Tomko [Mon, 9 Mar 2020 20:03:38 +0000 (21:03 +0100)]
tools: vsh.c: remove virstrerror.h include

This was only used to pull in virStrerror.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoutil: remove virStrerror
Ján Tomko [Mon, 9 Mar 2020 20:01:51 +0000 (21:01 +0100)]
util: remove virStrerror

Now that we use g_strerror exclusively, remove this unused
function.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoUse g_strerror instead of virStrerror
Ján Tomko [Wed, 26 Feb 2020 17:57:34 +0000 (18:57 +0100)]
Use g_strerror instead of virStrerror

Remove lots of stack-allocated buffers.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: blockcopy: Allow late opening of the backing chain of a shallow copy
Peter Krempa [Wed, 19 Feb 2020 07:38:49 +0000 (08:38 +0100)]
qemu: blockcopy: Allow late opening of the backing chain of a shallow copy

oVirt used a quirk in the pre-blockdev semantics of drive-mirror which
opened the backing chain of the mirror destination only once
'block-job-complete' was called.

Our introduction of blockdev made qemu open the backing chain images
right at the start of the job. This broke oVirt's usage of this API
because they copy the data into the backing chain during the time the
block copy job is running.

Re-introduce late open of the backing chain if qemu allows us to use
blockdev-snapshot on write-only nodes as it can be used to install the
backing chain even for an existing image now.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: capabilities: Introduce QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY
Peter Krempa [Thu, 5 Mar 2020 13:28:50 +0000 (14:28 +0100)]
qemu: capabilities: Introduce QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY

The capability is based on qemu's support of using blockdev-snapshot to
install backing chain also for images which are in use by a block-copy
job.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemuDomainBlockCopyCommon: Record updated flags to block job
Peter Krempa [Thu, 27 Feb 2020 14:50:08 +0000 (15:50 +0100)]
qemuDomainBlockCopyCommon: Record updated flags to block job

For a long time we've masked out VIR_DOMAIN_BLOCK_COPY_SHALLOW if
there's no backing chain for the copied disk to simplify the code.

One of the refactors of the block copy code caused that we no longer
update the 'flags' variable just the local copies. This was okay until
in ccd4228afff we started storing the job flags in the block job data.

Given that we modify how we call qemu we also should modify @flags so
that the correct value is recorded in the block job data.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemuDomainBlockPivot: Move check prior to executing the pivot steps
Peter Krempa [Tue, 18 Feb 2020 16:10:46 +0000 (17:10 +0100)]
qemuDomainBlockPivot: Move check prior to executing the pivot steps

Move the check whether the job is already synchronised to the beginning
of the function so that we don't try to do some of the steps necessary
for pivoting prior to actually wanting to pivot.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoqemu: capabilities: Update qemu-5.0.0 capabilities for x86_64
Peter Krempa [Thu, 5 Mar 2020 13:25:39 +0000 (14:25 +0100)]
qemu: capabilities: Update qemu-5.0.0 capabilities for x86_64

Update to v4.2.0-2265-g67923a7ea6 to pick up recent addition of
'allow-write-only-overlay' feature of 'blockdev-snapshot' command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
5 years agoutil: ensure min/maj are initialized in virGetDeviceID
Daniel P. Berrangé [Thu, 12 Mar 2020 18:39:35 +0000 (18:39 +0000)]
util: ensure min/maj are initialized in virGetDeviceID

The stub impl of virGetDeviceID just returns ENOSYS and does not
initialize the min/maj output parameters. This lead to a false
positive warning on mingw about possible use of uninitialized
variables.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: fix double unlock of monitor in hotplug test
Daniel P. Berrangé [Thu, 12 Mar 2020 18:33:51 +0000 (18:33 +0000)]
tests: fix double unlock of monitor in hotplug test

The qemuMonitorTestNew() function returns with the monitor object
locked, and expects it to still be locked when qemuMonitorTestFree
is called.  The qemuhotplug test, however, explicitly unlocks the
monitor, but then forgets to lock it again. As a result the
qemuMonitorTestFree function is unlocking a mutex it doesn't own.

This bug has existed forever, but since we use normal POSIX mutexes
and don't check the return value of pthread_mutex_lock/unlock we
didn't see the error. It was harmless until the switch to the per
monitor event loop which requires the thread synchronization to
work reliably, whereupon it started crashing.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoconf: Don't generate machine names with a dot
Michal Privoznik [Fri, 28 Feb 2020 16:12:41 +0000 (17:12 +0100)]
conf: Don't generate machine names with a dot

According to the linked BZ, machined expects either valid
hostname or valid FQDN (see systemd commit
v239-3092-gd65652f1f2). While in case of multiple dots, a
trailing one doesn't violate FQDN, it does violate the rule in
case of something simple, like "domain.". But it's safe to remove
it in both cases.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1808499
Fixes: 45464db8ba502764cf37ec9335770248bdb3d9a8
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuDomainGetGuestInfo: Don't try to free a negative number of entries
Peter Krempa [Thu, 12 Mar 2020 15:37:11 +0000 (16:37 +0100)]
qemuDomainGetGuestInfo: Don't try to free a negative number of entries

'nfs' variable was set to -1 or -2 on agent failure. Cleanup then tried
to free 'nfs' elements of the array which resulted into a crash.

Make 'nfs' size_t and assign it only on successful agent call.

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

Broken by commit 599ae372d8cf092

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuAgentFSInfoFormatParams: Remove pointless returned value
Peter Krempa [Thu, 12 Mar 2020 15:34:28 +0000 (16:34 +0100)]
qemuAgentFSInfoFormatParams: Remove pointless returned value

The only caller doesn't check the value and also there are no real
errors to report anyways.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirQEMUCaps: Drop unused usedQMP member
Michal Privoznik [Wed, 11 Mar 2020 15:55:24 +0000 (16:55 +0100)]
virQEMUCaps: Drop unused usedQMP member

The virQEMUCaps structure has usedQMP member which in the past
used to tell if qemu we are dealing with is capable of QMP. Well,
we don't support HMP anymore (minus a few HMP passthrough
commands, which are wrapped into QMP anyways) and the member is
not used really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu: remove redundant needReply argument of qemuAgentCommand
Nikolay Shirokovskiy [Thu, 5 Mar 2020 14:47:02 +0000 (17:47 +0300)]
qemu: remove redundant needReply argument of qemuAgentCommand

needReply added in [1] looks redundant. Indeed it is set to false only
when mon->await_event is set too (the only exception qemuAgentFSTrim
which is mistaken).

However it fixes the issue when qemuAgentCommand exits on error path and
mon->await_event is not reset. Let's instead reset mon->await_event properly.

Also remove "Woken up by event" debug message as it can be misleading.
We can get it also if monitor is closed due to serial changed event
currently. Anyway both qemuAgentClose and qemuAgentNotifyEvent log
itself.

[1] qemu: make sure agent returns error when required data are missing

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: agent: sync once if qemu has serial port event
Nikolay Shirokovskiy [Thu, 5 Mar 2020 14:47:01 +0000 (17:47 +0300)]
qemu: agent: sync once if qemu has serial port event

Sync was introduced in [1] to check for ga presence. This
check is racy but in the era before serial events are available
there was not better solution I guess.

In case we have the events the sync function is different. It allows us
to flush stateless ga channel from remnants of previous communications.
But we need to do it only once. Until we get timeout on issued command
channel state is ok.

[1] qemu_agent: Issue guest-sync prior to every command

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Create multipath targets for PRs
Michal Privoznik [Wed, 13 Nov 2019 14:34:50 +0000 (15:34 +0100)]
qemu: Create multipath targets for PRs

If a disk has persistent reservations enabled, qemu-pr-helper
might open not only /dev/mapper/control but also individual
targets of the multipath device. We are already querying for them
in CGroups, but now we have to create them in the namespace too.
This was brought up in [1].

1: https://bugzilla.redhat.com/show_bug.cgi?id=1711045#c61

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Lin Ma <LMa@suse.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
5 years agoqemu: convert agent to use the per-VM event loop
Daniel P. Berrangé [Wed, 12 Feb 2020 14:54:19 +0000 (14:54 +0000)]
qemu: convert agent to use the per-VM event loop

This converts the QEMU agent APIs to use the per-VM
event loop, which involves switching from virEvent APIs
to GMainContext / GSource APIs.

A GSocket is used as a convenient way to create a GSource
for a socket, but is not yet used for actual I/O.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: fix variable naming in agent code
Daniel P. Berrangé [Wed, 12 Feb 2020 17:31:20 +0000 (17:31 +0000)]
qemu: fix variable naming in agent code

We are dealing with the QEMU agent, not the monitor.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: convert monitor to use the per-VM event loop
Daniel P. Berrangé [Wed, 12 Feb 2020 14:54:19 +0000 (14:54 +0000)]
qemu: convert monitor to use the per-VM event loop

This converts the QEMU monitor APIs to use the per-VM
event loop, which involves switching from virEvent APIs
to GMainContext / GSource APIs.

A GSocket is used as a convenient way to create a GSource
for a socket, but is not yet used for actual I/O.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotests: start/stop an event thread for QEMU monitor/agent tests
Daniel P. Berrangé [Wed, 12 Feb 2020 14:56:29 +0000 (14:56 +0000)]
tests: start/stop an event thread for QEMU monitor/agent tests

Tests which are using the QEMU monitor / agent need to have an
event thread running a private GMainContext.

There is already a thread running the main libvirt event loop
but this can't be eliminated yet as it is used for more than
just the monitor client I/O.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: start/stop an event thread for QMP probing
Daniel P. Berrangé [Wed, 12 Feb 2020 12:51:30 +0000 (12:51 +0000)]
qemu: start/stop an event thread for QMP probing

In common with regular QEMU guests, the QMP probing
will need an event loop for handling monitor I/O
operations.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: start/stop an event loop thread for domains
Daniel P. Berrangé [Wed, 12 Feb 2020 12:26:11 +0000 (12:26 +0000)]
qemu: start/stop an event loop thread for domains

The event loop thread will be responsible for handling
any per-domain I/O operations, most notably the QEMU
monitor and agent sockets.

We start this event loop when launching QEMU, but stopping
the event loop is a little more complicated. The obvious
idea is to stop it in qemuProcessStop(), but if we do that
we risk loosing the final events from the QEMU monitor, as
they might not have been read by the event thread at the
time we tell the thread to stop.

The solution is to delay shutdown of the event thread until
we have seen EOF from the QEMU monitor, and thus we know
there are no further events to process.

Note that this assumes that we don't have events to process
from the QEMU agent.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: introduce an abstraction for running event loops
Daniel P. Berrangé [Thu, 13 Feb 2020 15:53:15 +0000 (15:53 +0000)]
src: introduce an abstraction for running event loops

We want a way to easily run a private GMainContext in a
thread, with correct synchronization between startup
and shutdown of the thread.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agovirbpf: Set errno instead of reporting errors
Michal Privoznik [Wed, 26 Feb 2020 08:24:27 +0000 (09:24 +0100)]
virbpf: Set errno instead of reporting errors

The virbpf module wraps syscalls to BPF. However, if the kernel
headers used at the compile time don't have support for BPF the
module offers stubs which return a negative one to signal error
to the caller. But there is a slight discrepancy between real
functions and these stubs. While the former set errno and return
-1 the latter report an error (without setting the errno) and
return -1. This is not optimal because the caller might see stale
errno and overwrite the error message with a less accurate one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirCgroupV2DevicesAvailable: Print stringified errno in the debug log
Michal Privoznik [Mon, 9 Mar 2020 12:14:07 +0000 (13:14 +0100)]
virCgroupV2DevicesAvailable: Print stringified errno in the debug log

In the virCgroupV2DevicesAvailable() function we try to determine
whether CGroups version 2 are available. We do this by opening
what we believe is the CGroup mount point and issuing a BPF call.
When the call fails, a debug message is printed. However, the BPF
call sets errno too. Include it in the debug message to help us
with debugging.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirDomainDiskTranslateSourcePool: Check for disk type correctly
Michal Privoznik [Mon, 9 Mar 2020 15:40:57 +0000 (16:40 +0100)]
virDomainDiskTranslateSourcePool: Check for disk type correctly

When rewriting the virDomainDiskTranslateSourcePool() function in
v6.1.0-rc1~184 a typo was introduced. Previously, we allowed
startup policy only for those volumes which translated to
VIR_STORAGE_TYPE_FILE. But starting with the referenced commit,
the value we checked for was changed to VIR_STORAGE_VOL_FILE
which comes from a different enum and has a different value too.
This is wrong, because virStorageSourceGetActualType() returns a
value from the original enum.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agocputest: Add data for Intel(R) Core(TM) i7-8550U CPU without TSX
Jiri Denemark [Fri, 6 Mar 2020 09:50:11 +0000 (10:50 +0100)]
cputest: Add data for Intel(R) Core(TM) i7-8550U CPU without TSX

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
5 years agoqemumonitorjsontest: GetCPUModelBaseline: use g_auto
Ján Tomko [Fri, 21 Feb 2020 23:55:50 +0000 (00:55 +0100)]
qemumonitorjsontest: GetCPUModelBaseline: use g_auto

Use g_autoptr for the virCPUDef variables.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemumonitorjsontest: GetCPUModelComparison: use g_auto
Ján Tomko [Fri, 21 Feb 2020 23:55:50 +0000 (00:55 +0100)]
qemumonitorjsontest: GetCPUModelComparison: use g_auto

Use g_autoptr for the virCPUDef variables and get rid
of the cleanup label.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agovirsystemdtest: do not leak socket path
Ján Tomko [Fri, 21 Feb 2020 23:57:33 +0000 (00:57 +0100)]
virsystemdtest: do not leak socket path

Use an autofree'd helper variable to store the socket path
and free it after the function finishes.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: 5b8569dd6e284b9159c701e8bffafb196983fc4a
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemumonitorjsontest: use virCPUDefNew()
Ján Tomko [Sat, 22 Feb 2020 00:06:51 +0000 (01:06 +0100)]
qemumonitorjsontest: use virCPUDefNew()

virCPUDefPtr uses refcounting internally and must be allocated
using virCPUDefNew, otherwise virCPUDefFree would be a no-op.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: fa2404bf4f91813431beb797fc30a1237a743823
Fixes: eee09435eec46553aac4fdf1c2d8f3214167bded
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemumonitorjsontest: do not leak qapiData.schema
Ján Tomko [Fri, 21 Feb 2020 23:57:07 +0000 (00:57 +0100)]
qemumonitorjsontest: do not leak qapiData.schema

Free the x86_64 schema before overwriting it with s390x schema.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: eee09435eec46553aac4fdf1c2d8f3214167bded
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: valgrind: do not trace system binaries
Ján Tomko [Fri, 21 Feb 2020 23:51:41 +0000 (00:51 +0100)]
tests: valgrind: do not trace system binaries

Add /usr/bin/* to -trace-children-skip

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agotests: valgrind.supp: suppress g_type_register_static leaks
Ján Tomko [Fri, 21 Feb 2020 23:48:27 +0000 (00:48 +0100)]
tests: valgrind.supp: suppress g_type_register_static leaks

When a type is registered, it holds allocated memory until
the program exits.

Add an exception to valgrind.supp to make the output of
  make -C tests valgrind
more readable.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
5 years agoqemu: Tell secdrivers which images are top parent
Michal Privoznik [Thu, 27 Feb 2020 10:20:51 +0000 (11:20 +0100)]
qemu: Tell secdrivers which images are top parent

When preparing images for block jobs we modify their seclabels so
that QEMU can open them. However, as mentioned in the previous
commit, secdrivers base some it their decisions whether the image
they are working on is top of of the backing chain. Fortunately,
in places where we call secdrivers we know this and the
information can be passed to secdrivers.

The problem is the following: after the first blockcommit from
the base to one of the parents the XATTRs on the base image are
not cleared and therefore the second attempt to do another
blockcommit fails. This is caused by blockcommit code calling
qemuSecuritySetImageLabel() over the base image, possibly
multiple times (to ensure RW/RO access). A naive fix would be to
call the restore function. But this is not possible, because that
would deny QEMU the access to the base image.  Fortunately, we
can use the fact that seclabels are remembered only for the top
of the backing chain and not for the rest of the backing chain.
And thanks to the previous commit we can tell secdrivers which
images are top of the backing chain.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agosecurity: Introduce VIR_SECURITY_DOMAIN_IMAGE_PARENT_CHAIN_TOP flag
Michal Privoznik [Thu, 27 Feb 2020 10:06:22 +0000 (11:06 +0100)]
security: Introduce VIR_SECURITY_DOMAIN_IMAGE_PARENT_CHAIN_TOP flag

Our decision whether to remember seclabel for a disk image
depends on a few factors. If the image is readonly or shared or
not the chain top the remembering is suppressed for the image.
However, the virSecurityManagerSetImageLabel() is too low level
to determine whether passed @src is chain top or not. Even though
the function has the @parent argument it does not necessarily
reflect the chain top - it only points to the top level image in
the chain we want to relabel and not to the topmost image of the
whole chain. And this can't be derived from the passed domain
definition reliably neither - in some cases (like snapshots or
block copy) the @src is added to the definition only after the
operation succeeded. Therefore, introduce a flag which callers
can use to help us with the decision.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agorpc: getaddrinfo: also accept IPv4-mapped IPv6 addresses
Zhimin Feng [Mon, 2 Mar 2020 08:26:51 +0000 (16:26 +0800)]
rpc: getaddrinfo: also accept IPv4-mapped IPv6 addresses

If only IPv6 is configured on the host, getaddrinfo with AI_ADDRCONFIG
in hints would return EAI_ADDRFAMILY for nodenames that resolve to IPv4.

Also pass AI_V4MAPPED to accept IPv4-mapped addresses on IPv6-only
systems.

Signed-off-by: Zhimin Feng <fengzhimin1@huawei.com>
[rewrote the commit message - jtomko]
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agologging: Use default timeout of 120 seconds for virtlogd
Andrea Bolognani [Thu, 5 Mar 2020 16:39:23 +0000 (17:39 +0100)]
logging: Use default timeout of 120 seconds for virtlogd

This is the same timeout of all other daemons, and just like them
virtlogd is socket-activated, so it will automatically be started
on demand whenever that's necessary.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agosrc: fix mixup of stack and heap allocated data in auth callback
Daniel P. Berrangé [Thu, 5 Mar 2020 15:42:53 +0000 (15:42 +0000)]
src: fix mixup of stack and heap allocated data in auth callback

In the following recent change:

  commit db72866310d1e520efa8ed2d4589bdb5e76a1c95
  Author: Daniel P. Berrangé <berrange@redhat.com>
  Date:   Tue Jan 14 10:40:52 2020 +0000

    util: add API for reading password from the console

the fact that "bufptr" pointer may point to either heap or stack
allocated data was overlooked. As a result, when the strdup was
removed, we ended up returning a pointer to the local stack to
the caller. When the caller referenced this stack pointer they
got out garbage which fairly quickly resulted in a crash.

We need to copy the stack buffer into heap memory in the username
case.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoutil: viraudit: remove unnecessary includes
Ján Tomko [Wed, 26 Feb 2020 17:56:46 +0000 (18:56 +0100)]
util: viraudit: remove unnecessary includes

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoutil: audit: drop support for old libaudit
Ján Tomko [Wed, 26 Feb 2020 17:51:19 +0000 (18:51 +0100)]
util: audit: drop support for old libaudit

Virtualization event types were added in 2.0.5:
https://github.com/linux-audit/audit-userspace/commit/3755e9ff

Even Ubuntu 14.04 (which we don't support) has 2.3.2.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agovirthread: Free thread name only after worker has finished
Michal Privoznik [Fri, 6 Mar 2020 15:11:09 +0000 (16:11 +0100)]
virthread: Free thread name only after worker has finished

When spawning a thread via our virThread APIs we let pthread
spawn this helper thread which sets couple of thread local
variables (e.g. thread job name or thread worker name) and as of
v6.1.0-40-gc85256b31b it also sets pthread name (which is then
visible in `ps' output for instance). Only after these steps the
intended function is called. However, just before calling it we
free the buffer that holds the thread name which results in
invalid memory reads:

==47027== Invalid read of size 1
==47027==    at 0x48389C2: strlen (vg_replace_strmem.c:459)
==47027==    by 0x58BB3D6: __vfprintf_internal (vfprintf-internal.c:1645)
==47027==    by 0x58CE6E0: __vasprintf_internal (vasprintf.c:57)
==47027==    by 0x574BA28: g_vasprintf (in /usr/lib64/libglib-2.0.so.0.6000.7)
==47027==    by 0x57240CC: g_strdup_vprintf (in /usr/lib64/libglib-2.0.so.0.6000.7)
==47027==    by 0x48E0EFA: vir_g_strdup_vprintf (glibcompat.c:209)
==47027==    by 0x493AA05: virLogVMessage (virlog.c:573)
==47027==    by 0x493A8FE: virLogMessage (virlog.c:513)
==47027==    by 0x4992FC7: virThreadJobClear (virthreadjob.c:121)
==47027==    by 0x4992844: virThreadHelper (virthread.c:237)
==47027==    by 0x5817496: start_thread (pthread_create.c:486)
==47027==    by 0x59563CE: clone (clone.S:95)

The problem is that neither virThreadJobSetWorker() nor
virThreadJobSet() create a copy of passed name. They just set a
thread local variable to point to the buffer which is then
freed. Moving the free towards the end of the wrapper function
solves the issue.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agotest: fix leak of authentication info
Daniel P. Berrangé [Thu, 5 Mar 2020 15:41:49 +0000 (15:41 +0000)]
test: fix leak of authentication info

The 'auths' struct in the test driver was not free()d. This was easy to
miss because the default XML doesn't include auth info.

Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoaa-helper: use g_autofree in create_profile
Ján Tomko [Thu, 5 Mar 2020 16:21:54 +0000 (17:21 +0100)]
aa-helper: use g_autofree in create_profile

'template' might be used uninitialized.

Use g_autofree for everything and remove all the custom labels.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovz: use g_autofree in prlsdkConvertCpuInfo
Ján Tomko [Thu, 5 Mar 2020 16:17:55 +0000 (17:17 +0100)]
vz: use g_autofree in prlsdkConvertCpuInfo

Convert the function to use g_autofree to silence -Wmaybe-uninitialized.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agovirmacmap: Use g_autofree in virMacMapWriteFileLocked
Ján Tomko [Thu, 5 Mar 2020 16:16:29 +0000 (17:16 +0100)]
virmacmap: Use g_autofree in virMacMapWriteFileLocked

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agodocs: add page describing the libvirt daemons
Daniel P. Berrangé [Mon, 14 Oct 2019 09:54:22 +0000 (10:54 +0100)]
docs: add page describing the libvirt daemons

Now that we have more than just the libvirtd daemon, we should be
explaining to users what they are all for & important aspects of their
configuration.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoVIR_FREE: Replace internals by g_clear_pointer
Peter Krempa [Thu, 5 Mar 2020 08:42:23 +0000 (09:42 +0100)]
VIR_FREE: Replace internals by g_clear_pointer

Our implementation masks GCC warnings of uninitialized use of the passed
argument. After changing this I got a load of following warnings:

src/conf/virnetworkportdef.c: In function 'virNetworkPortDefSaveStatus':
/usr/include/glib-2.0/glib/gmem.h:136:8: error: 'path' may be used uninitialized in this function [-Werror=maybe-uninitialized]
  136 |     if (_p)                \
      |        ^
src/conf/virnetworkportdef.c:447:11: note: 'path' was declared here
  447 |     char *path;
      |           ^~~~

For the curious, g_clear_pointer is still safe for arguments with
side-effect. Here's the pre-processed output of trying to do a
VIR_FREE(*(test2++)):

 do {
     typedef char _GStaticAssertCompileTimeAssertion_1[(sizeof *(&(*(test2++))) == sizeof (gpointer)) ? 1 : -1] __attribute__((__unused__));
     __typeof__((&(*(test2++)))) _pp = (&(*(test2++)));
     __typeof__(*(&(*(test2++)))) _ptr = *_pp;

     *_pp = ((void *)0);
     if (_ptr)
        (g_free) (_ptr);
 } while (0) ;

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotestQemuMonitorJSONqemuMonitorJSONGetTargetArch: Fix uninitialized use of 'arch'
Peter Krempa [Thu, 5 Mar 2020 08:33:55 +0000 (09:33 +0100)]
testQemuMonitorJSONqemuMonitorJSONGetTargetArch: Fix uninitialized use of 'arch'

Refactor the cleanup control flow and use g_autofree for 'arch' so that
it's mandated that it's initialized.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agocmdDomHostname: Fix uninitialized use of 'hostname' by refactoring cleanup
Peter Krempa [Thu, 5 Mar 2020 08:29:02 +0000 (09:29 +0100)]
cmdDomHostname: Fix uninitialized use of 'hostname' by refactoring cleanup

Use 'g_autoptr' which mandates initialization for 'hostname' and also
for 'domain' to allow full refactor of the cleanup path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirLXCProcessSetupNamespaceName: Fix potential uninitialized free of 'path'
Peter Krempa [Thu, 5 Mar 2020 08:25:35 +0000 (09:25 +0100)]
virLXCProcessSetupNamespaceName: Fix potential uninitialized free of 'path'

'path' could be accessed uninitialized. Fix it by using g_autofree which
also mandates initialization.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agovirNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring...
Peter Krempa [Thu, 5 Mar 2020 08:20:48 +0000 (09:20 +0100)]
virNetworkPortDefSaveStatus: Fix potentially uninitialized 'path' by refactoring cleanup

Use 'g_autofree' to clean both 'path' and 'xml' which mandates
initialization 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>
5 years agosrc: add pthread_np.h include for FreeBSD
Daniel P. Berrangé [Thu, 5 Mar 2020 15:13:45 +0000 (15:13 +0000)]
src: add pthread_np.h include for FreeBSD

On FreeBSD the non-portable pthread APIs need to be obtained
via the pthread_np.h header.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: improve thread naming with human targetted names
Daniel P. Berrangé [Fri, 14 Feb 2020 11:20:10 +0000 (11:20 +0000)]
src: improve thread naming with human targetted names

Historically threads are given a name based on the C function,
and this name is just used inside libvirt. With OS level thread
naming this name is now visible to debuggers, but also has to
fit in 15 characters on Linux, so function names are too long
in some cases.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agosrc: set the OS level thread name
Daniel P. Berrangé [Fri, 14 Feb 2020 10:44:01 +0000 (10:44 +0000)]
src: set the OS level thread name

Setting the thread name makes it easier to debug libvirtd
when many threads are running.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: drop ability to open monitor from FD
Daniel P. Berrangé [Wed, 12 Feb 2020 14:08:01 +0000 (14:08 +0000)]
qemu: drop ability to open monitor from FD

The qemuMonitorOpenFD method has not been used since it
was first introduced.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemu: drop support for agent connections on PTYs
Daniel P. Berrangé [Wed, 12 Feb 2020 11:45:10 +0000 (11:45 +0000)]
qemu: drop support for agent connections on PTYs

Libvirt has never configured the QEMU agent to support
running on a PTY implicitly. In theory an end user may
have written such an XML config, but this is reasonably
unlikely since when a bare <channel> is provided, libvirt
will auto-expand it to a UNIX socket backend.

With this change a user who has use the PTY backend will
have to switch to the UNIX backend if they wish to use
libvirt APIs for interacting with the agent. This will
not have guest ABI impact.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoqemuhotplugtestcpus: Always use 'query-cpus-fast'
Peter Krempa [Wed, 4 Mar 2020 11:19:39 +0000 (12:19 +0100)]
qemuhotplugtestcpus: Always use 'query-cpus-fast'

Use the new command in the test suite by asserting the capability
and adjusting test data to the correct field names as they changed
compared to 'query-cpus'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemuMonitorJSONSetMigrationParams: Refactor command construction and cleanup
Peter Krempa [Wed, 4 Mar 2020 09:10:56 +0000 (10:10 +0100)]
qemuMonitorJSONSetMigrationParams: Refactor command construction and cleanup

qemuMonitorJSONMakeCommandInternal does the full command construction if
you pass in what would become the value of the 'arguments' key. Refactor
the open-coded implementation to use the helper and use modern cleanup
helpers at the same time.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoutil: json: Convert virJSONValueNewObject() to g_new0
Peter Krempa [Wed, 4 Mar 2020 09:04:33 +0000 (10:04 +0100)]
util: json: Convert virJSONValueNewObject() to g_new0

Make it obvious that the function always returns a valid pointer and fix
all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
5 years agoqemu_shim: Ignore SIGPIPE
Michal Privoznik [Fri, 28 Feb 2020 14:36:49 +0000 (15:36 +0100)]
qemu_shim: Ignore SIGPIPE

I've found that if my virtlogd is socket activated but the daemon
doesn't run yet, then the virt-qemu-run is killed right after it
tries to start the domain. The problem is that because the default
setting is to use virtlogd, the domain create code tries to
connect to virtlogd socket, which in turn tries to detect who is
connecting (virNetSocketGetUNIXIdentity()) and as a part of it,
it will try to open /proc/${PID_OF_SHIM}/stat which is denied by
SELinux:

  type=AVC msg=audit(1582903501.927:323): avc:  denied  { search } for  \
  pid=1210 comm="virtlogd" name="1843" dev="proc" ino=37224 \
  scontext=system_u:system_r:virtlogd_t:s0-s0:c0.c1023 \
  tcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 tclass=dir \
  permissive=0

Virtlogd reacts by closing the connection which the shim sees as
SIGPIPE. Since the default response to the signal is Term, we
don't even get to reporting any error nor to removing the
temporary directory.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu_shim: Allow other users to enter the root dir
Michal Privoznik [Fri, 28 Feb 2020 13:42:44 +0000 (14:42 +0100)]
qemu_shim: Allow other users to enter the root dir

When virt-qemu-run is ran without any root directory specified on
the command line, a temporary directory is made and used instead.
But since we are using g_dir_make_tmp() to create the directory
it is going to have 0700 mode. So even though we create the whole
directory structure under it and label everything, QEMU is very
likely to not have the access. This is because in this case there
is no qemu.conf and thus distro default UID:GID is used to run
QEMU (e.g. qemu:kvm on Fedora). Change the mode of the temporary
directory so that everybody has eXecute permission.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
5 years agoqemu: Don't compare local and remote hostnames on migration
Michal Privoznik [Tue, 25 Feb 2020 14:53:12 +0000 (15:53 +0100)]
qemu: Don't compare local and remote hostnames on migration

Libvirt tries to forbid migration onto the same host and it does
that by checking if local and remote hostnames are the same and
whether local and remote UUIDs are the same. Well, the latter
makes sense but the former doesn't really because libvirtd can be
running inside an UTS namespace and hostnames can appear the same
on both sides of migration. On the other hand, host UUIDs are
unique, so rely on them when trying to prevent migration onto the
same host.

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

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
5 years agoadmin: use g_autofree
Gaurav Agrawal [Wed, 4 Mar 2020 18:06:13 +0000 (23:36 +0530)]
admin: use g_autofree

Signed-off-by: Gaurav Agrawal <agrawalgaurav@gnome.org>
[removed dead assignment]
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agotests: do not include skipped tests in failedTests
Ján Tomko [Wed, 4 Mar 2020 15:48:27 +0000 (16:48 +0100)]
tests: do not include skipped tests in failedTests

We recognize three return values from tests:
* OK    -> 0
* SKIP  -> EXIT_AM_SKIP
* ERROR -> anything else

Also check for EXIT_AM_SKIP when building a bitmap of failed tests,
otherwise the skipped tests would be printed in the suggested range
of tests that shoud be re-run.

Reported-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Fixes: cebb468ef5e82b8d4253e27ef70c67812cf93c5a
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
5 years agoqemu: Don't request nested entries in qemuBlockGetNamedNodeData
Peter Krempa [Tue, 21 Jan 2020 15:51:40 +0000 (16:51 +0100)]
qemu: Don't request nested entries in qemuBlockGetNamedNodeData

Use the 'flat' flag for 'query-named-block-nodes' if qemu supports
QEMU_CAPS_QMP_QUERY_NAMED_BLOCK_NODES_FLAT in qemuBlockGetNamedNodeData.

We don't need the data so plumb in whether qemu supports the
'flat' output.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Add 'flat' parameter for qemuMonitorJSONQueryNamedBlockNodes
Peter Krempa [Tue, 21 Jan 2020 15:42:49 +0000 (16:42 +0100)]
qemu: monitor: Add 'flat' parameter for qemuMonitorJSONQueryNamedBlockNodes

Modern qemu allows to skip the nested redundant data in the output of
query-named-block-nodes. Plumb in the support for the argument that
enables it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemuCheckpointDiscardBitmaps: Use qemuBlockGetNamedNodeData
Peter Krempa [Wed, 26 Feb 2020 11:50:53 +0000 (12:50 +0100)]
qemuCheckpointDiscardBitmaps: Use qemuBlockGetNamedNodeData

Replace qemuMonitorBlockGetNamedNodeData by qemuBlockGetNamedNodeData.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: monitor: Refactor variable cleanup in qemuMonitorJSONQueryNamedBlockNodes
Peter Krempa [Tue, 21 Jan 2020 15:33:12 +0000 (16:33 +0100)]
qemu: monitor: Refactor variable cleanup in qemuMonitorJSONQueryNamedBlockNodes

Use g_autoptr to get rid of the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
5 years agoqemu: capabilities: Add capability for the 'flat' argument of 'query-named-block...
Peter Krempa [Tue, 21 Jan 2020 14:13:47 +0000 (15:13 +0100)]
qemu: capabilities: Add capability for the 'flat' argument of 'query-named-block-nodes'

Detect the presence of the flag and make it available internally as
QEMU_CAPS_QMP_QUERY_NAMED_BLOCK_NODES_FLAT.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>