]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
3 years agoinclude: Introduce virDomainDirtyRateCalcFlags
Hyman Huang(黄勇) [Sun, 20 Feb 2022 13:28:11 +0000 (21:28 +0800)]
include: Introduce virDomainDirtyRateCalcFlags

Introduce virDomainDirtyRateCalcFlags to get ready for
adding mode parameter to qemuDomainStartDirtyRateCalc.

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_capabilities: Introduce QEMU_CAPS_DIRTYRATE_MODE capability
Hyman Huang(黄勇) [Sun, 20 Feb 2022 13:28:10 +0000 (21:28 +0800)]
qemu_capabilities: Introduce QEMU_CAPS_DIRTYRATE_MODE capability

mode option of calc-dirty-rate command since qemu >=6.2.0.
Introduce QEMU_CAPS_DIRTYRATE_MODE capability definition.

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_driver: Probe capability before calculating dirty page rate
Hyman Huang(黄勇) [Sun, 20 Feb 2022 13:28:09 +0000 (21:28 +0800)]
qemu_driver: Probe capability before calculating dirty page rate

Probing QEMU_CAPS_CALC_DIRTY_RATE capability in advance
in case of failure when calculating dirty page rate.

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_capabilities: Introduce QEMU_CAPS_CALC_DIRTY_RATE capability
Hyman Huang(黄勇) [Sun, 20 Feb 2022 13:28:08 +0000 (21:28 +0800)]
qemu_capabilities: Introduce QEMU_CAPS_CALC_DIRTY_RATE capability

calc-dirty-rate command was introduced since qemu >=5.2.0.
Introduce QEMU_CAPS_CALC_DIRTY_RATE capability definition.

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agolibxl: Fix libvirtd crash on domain restore
Jim Fehlig [Thu, 17 Feb 2022 18:48:13 +0000 (11:48 -0700)]
libxl: Fix libvirtd crash on domain restore

Commit cc2a3c2a94 missed one case in the libxl driver where virDomainDef
is returned from libxlDomainSaveImageOpen and a g_steal_pointer is needed.
Without it, the virDomainDef object is freed and the driver crashes later
in the restore process when accessing the object.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirsh-domain: Move and rename cmdStartGetFDs to virshFetchPassFdsList
Peter Krempa [Thu, 27 Jan 2022 16:22:04 +0000 (17:22 +0100)]
virsh-domain: Move and rename cmdStartGetFDs to virshFetchPassFdsList

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agocmdStartGetFDs: Modernize
Peter Krempa [Thu, 27 Jan 2022 16:14:32 +0000 (17:14 +0100)]
cmdStartGetFDs: Modernize

Calculate the length of the FD list beforehand to avoid multiple
expansions and mainly simplify the code and use automatic freeing to
remove the error code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirsystemdtest: remove unused 'demo_socket_path'
Peter Krempa [Thu, 17 Feb 2022 13:17:04 +0000 (14:17 +0100)]
virsystemdtest: remove unused 'demo_socket_path'

Commit b56a833243ca7324 removed bunch of old code after which
'demo_socket_path' in 'testActivationFDNames' is no longer used

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
3 years agoutil: drop support for obsolete systemd in RHEL-7
Daniel P. Berrangé [Wed, 16 Feb 2022 14:57:05 +0000 (14:57 +0000)]
util: drop support for obsolete systemd in RHEL-7

The systemd version in RHEL-7 lacked support for the LISTEN_FDNAMES env
variable with socket activation. Since we stopped targetting RHEL-7 we
can drop some considerable amount of compatibility code.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agovirDomainCreate(XML)WithFiles: Add check for VIR_DRV_FEATURE_FD_PASSING
Peter Krempa [Wed, 16 Feb 2022 15:33:22 +0000 (16:33 +0100)]
virDomainCreate(XML)WithFiles: Add check for VIR_DRV_FEATURE_FD_PASSING

All APIs using FD passing have this check to prevent sending a
'VIR_NET_CALL_WITH_FDS' to an older daemon but
virDomainCreateXMLWithFiles was missing it.

Now the LXC driver was historically not exposing
VIR_DRV_FEATURE_FD_PASSING, but that is not a problem as LXC always goes
through the remote driver which intercepts it and injects
VIR_DRV_FEATURE_FD_PASSING when it was implemented.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_FD_PASSING
Peter Krempa [Wed, 16 Feb 2022 15:26:31 +0000 (16:26 +0100)]
virDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_FD_PASSING

The feature implies that fd passing works with RPC. Non-remote impls
thus should always report support.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER
Peter Krempa [Wed, 16 Feb 2022 15:24:01 +0000 (16:24 +0100)]
virDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER

The fix was on RPC level so everything should advertise it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_TYPED_PARAM_STRING
Peter Krempa [Wed, 16 Feb 2022 15:20:23 +0000 (16:20 +0100)]
virDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_TYPED_PARAM_STRING

This was a lockout to make strings in typed parameters compatible with
versions which didn't have them. Now all drivers need to expose this
capability.

This namely enables it for 'esx' and 'vz' drivers, while they don't seem
to be implementing any parameters for now, they might later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_REMOTE_(CLOSE|EVENT)_CALLBACK
Peter Krempa [Wed, 16 Feb 2022 12:38:56 +0000 (13:38 +0100)]
virDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_REMOTE_(CLOSE|EVENT)_CALLBACK

They are features of the RPC; drivers must say that it's not supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_PROGRAM_KEEPALIVE
Peter Krempa [Wed, 16 Feb 2022 12:38:56 +0000 (13:38 +0100)]
virDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_PROGRAM_KEEPALIVE

keepalive is a RPC feature, drivers must say that it's not supported.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_REMOTE
Peter Krempa [Wed, 16 Feb 2022 12:20:53 +0000 (13:20 +0100)]
virDriverFeatureIsGlobal: Handle VIR_DRV_FEATURE_REMOTE

VIR_DRV_FEATURE_REMOTE is a special flag which is asserted only when the
connection is remote. All drivers implementing it must return 0 for it
to work. Handle it in the global handler and add a comment why.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agodriver: Introduce global driver feature flag handling function
Peter Krempa [Wed, 16 Feb 2022 12:01:39 +0000 (13:01 +0100)]
driver: Introduce global driver feature flag handling function

The 'virDrvFeature' has a combination of features which are asserted by
the specific driver and features which are actually global.

In many cases the implementation was cargo-culted into newer drivers
without re-assesing whether it makes sense.

This patch introduces a global function which will specifically handle
these global flags and defer the rest to the driver.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agoqemu: Fix crash at the end of migration
Jiri Denemark [Thu, 17 Feb 2022 08:36:48 +0000 (09:36 +0100)]
qemu: Fix crash at the end of migration

The destination daemon would crash in Finish phase due to NULL
dereference which I missed in my review of commit
v8.0.0-428-g0301db44e2

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: fix excluding disk from internal inactive snapshot
Nikolay Shirokovskiy [Wed, 16 Feb 2022 08:05:01 +0000 (11:05 +0300)]
qemu: fix excluding disk from internal inactive snapshot

'qemuDomainSnapshotForEachQcow2Raw' doesn't properly handle the
'VIR_DOMAIN_SNAPSHOT_LOCATION_NONE' setting and thus doesn't skip disks
which were excluded from the snapshot due to being read-only.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoTranslated using Weblate (Swedish)
Göran Uddeborg [Tue, 15 Feb 2022 08:57:03 +0000 (09:57 +0100)]
Translated using Weblate (Swedish)

Currently translated at 32.8% (3434 of 10455 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>
3 years agoTranslated using Weblate (Polish)
Piotr Drąg [Tue, 15 Feb 2022 08:57:02 +0000 (09:57 +0100)]
Translated using Weblate (Polish)

Currently translated at 22.4% (2345 of 10455 strings)

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

Co-authored-by: Piotr Drąg <piotrdrag@gmail.com>
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
3 years agoopenrc: Make init scripts executable on install
Michal Privoznik [Tue, 15 Feb 2022 16:22:15 +0000 (17:22 +0100)]
openrc: Make init scripts executable on install

When installing openrc init scripts, we take whatever mode the
generated files are in an copy them under /etc/init.d/. This is
not ideal, because those files are not executable and they should
be.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/250
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agotests: Drop domcaps test data for qemu < 2.11
Michal Privoznik [Tue, 15 Feb 2022 15:10:36 +0000 (16:10 +0100)]
tests: Drop domcaps test data for qemu < 2.11

The minimal supported version of QEMU is 2.11. And after capabilities
for older QEMUs were dropped in v7.3.0-17-g184de10c1d we have some
domaincapsdata/ files that are never read. This is because
domaincapstest uses testQemuCapsIterate() which iterates over
qemucapabilitiesdata/caps_*.xml files.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agolibxl: use virDomainJobData instead of virDomainJobInfo
Kristina Hanicova [Fri, 11 Feb 2022 13:49:07 +0000 (14:49 +0100)]
libxl: use virDomainJobData instead of virDomainJobInfo

This transition will make it easier for me to generalize jobs in
the future as they will always use virDomainJobData and
virDomainJobInfo will be only used in the public api..

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
3 years agoqemu: make separate function for setting statsType of privateData
Kristina Hanicova [Fri, 11 Feb 2022 13:49:06 +0000 (14:49 +0100)]
qemu: make separate function for setting statsType of privateData

We only need to set statsType in almost every case of setting
something from private data, so it seems unnecessary to pull
privateData out of current / completed job for just this one
thing every time. I think this patch keeps the code cleaner
without variables used just once.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
3 years agoqemu: use generalized virDomainJobData instead of qemuDomainJobInfo
Kristina Hanicova [Fri, 11 Feb 2022 13:49:05 +0000 (14:49 +0100)]
qemu: use generalized virDomainJobData instead of qemuDomainJobInfo

This patch includes:
* introducing new files: src/hypervisor/domain_job.c and src/hypervisor/domain_job.h
* new struct virDomainJobData, which is almost the same as
  qemuDomainJobInfo - the only differences are moving qemu specific
  job stats into the qemuDomainJobDataPrivate and adding jobType
  (possibly more attributes in the future if needed).
* moving qemuDomainJobStatus to the domain_job.h and renaming it
  as virDomainJobStatus
* moving and renaming qemuDomainJobStatusToType
* adding callback struct virDomainJobDataPrivateDataCallbacks
  taking care of allocation, copying and freeing of private data
  of virDomainJobData
* adding functions for virDomainJobDataPrivateDataCallbacks for
  qemu hypervisor
* adding 'public' (public between the different hypervisors) functions
  taking care of init, copy, free of virDomainJobData
* renaming every occurrence of qemuDomainJobInfo *info to
  virDomainJobData *data

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
3 years agoci: Regenerate with new lcitool
Peter Krempa [Mon, 14 Feb 2022 16:45:19 +0000 (17:45 +0100)]
ci: Regenerate with new lcitool

Regenerate with lcitool as of:

  commit f83b916d5efa4bd33fbf4b7ea41bf6d535cc63fb
  Author: Alex Bennée <alex.bennee@linaro.org>
  Date:   Fri Feb 11 09:39:30 2022 +0000

      mappings: skip multipath-tools for cross Debian

      This package is both a mix of library files, headers and native
      binaries so cannot be installed in a cross environment. For now skip
      it for cross targets.

      See: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1005323

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoci: Move from 'centos-8' to 'almalinux-8'
Peter Krempa [Mon, 14 Feb 2022 16:44:12 +0000 (17:44 +0100)]
ci: Move from 'centos-8' to 'almalinux-8'

Upstream lcitool suggests that as a solution to 'centos-8' being
removed.

Move also the website and other jobs to depend on
'x86_64-almalinux-8-container'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoci: Regenerate with new lcitool
Peter Krempa [Mon, 14 Feb 2022 16:41:24 +0000 (17:41 +0100)]
ci: Regenerate with new lcitool

Re-generate our CI infra with 'lcitool' as of:

  commit b346752e98bd12395233ebba8c9312e08212b639 (HEAD)
  Author: Erik Skultety <eskultet@redhat.com>
  Date:   Tue Feb 1 10:48:53 2022 +0100

      tests: Replace CentOS 8 with AlmaLinux 8 in test scenarios

      Switch the test target before actually dropping CentOS 8.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This is prior to upstream lcitool dropping 'centos-8' support to
minimize the differences.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemuhotplugtest: Assume QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE
Peter Krempa [Mon, 14 Feb 2022 15:51:20 +0000 (16:51 +0100)]
qemuhotplugtest: Assume QEMU_CAPS_CHARDEV_FD_PASS_COMMANDLINE

All modern QEMU versions use FD passing for listening unix sockets so
the test should reflect this. This will later help when removing the
legacy code paths when we drop support for old QEMUs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuhotplugmock: Mock fd passing to qemu via 'SCM_RIGHTS'
Peter Krempa [Mon, 14 Feb 2022 14:51:37 +0000 (15:51 +0100)]
qemuhotplugmock: Mock fd passing to qemu via 'SCM_RIGHTS'

We don't want to be dealing with real FDs thus we mock
'qemuMonitorIOWriteWithFD' to do the same thing as when no FD is being
passed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agosyntax-check: sc_avoid_write: Don't use blanket file exceptions
Peter Krempa [Mon, 14 Feb 2022 15:39:00 +0000 (16:39 +0100)]
syntax-check: sc_avoid_write: Don't use blanket file exceptions

Adding an exception for the whole file usually defeats the purpose of a
syntax check and is also likely to get forgotten once the file is
removed.

In case of the suggestion of using 'safewrite' instead of write even the
comment for safewrite states that the function needs to be used only in
certain cases.

Remove the blanket exceptions for files and use an exclude string
instead. The only instance where we keep the full file exception is for
src/libvirt-stream.c as there are multiple uses in example code in
comments where I couldn't find a nicer targetted wapproach.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: monitor: Move declaration of struct _qemuMonitor to qemu_monitor_priv.h
Peter Krempa [Mon, 14 Feb 2022 15:07:41 +0000 (16:07 +0100)]
qemu: monitor: Move declaration of struct _qemuMonitor to qemu_monitor_priv.h

In order to mock the SCM_RIGHTS sendmsg to simulate sending
filedescriptors to fake qemu in tests we need access to some fields of
'struct _qemuMonitor'. Move its declaration to the private header file.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Make 'struct _qemuMonitorMessage' private
Peter Krempa [Mon, 14 Feb 2022 14:57:21 +0000 (15:57 +0100)]
qemu: Make 'struct _qemuMonitorMessage' private

Move the declaration of the struct into 'qemu_monitor_priv.h' as other
code has no business in peeking into the monitor messages.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: monitor: Drop old monitor fields from 'struct _qemuMonitorMessage'
Peter Krempa [Mon, 14 Feb 2022 15:02:29 +0000 (16:02 +0100)]
qemu: monitor: Drop old monitor fields from 'struct _qemuMonitorMessage'

The fields are no longer used since we've deleted support for HMP-only
qemus. The HMP command pass-through works via a QMP command.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Add newer variant of 'launch-security-sev-missing-platform-info'
Peter Krempa [Thu, 10 Feb 2022 09:01:36 +0000 (10:01 +0100)]
qemuxml2argvtest: Add newer variant of 'launch-security-sev-missing-platform-info'

Upcoming patches will remove support for qemu-2.12. Since tests of
'sev' use hacked data we need to use our capability dump of qemu-6.0 as
it has the required fields.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Bump versioned test variants for pre-blockdev disk tests to 4.1.0
Peter Krempa [Thu, 10 Feb 2022 08:47:19 +0000 (09:47 +0100)]
qemuxml2argvtest: Bump versioned test variants for pre-blockdev disk tests to 4.1.0

Originally when I started working on '-blockdev' support I added version
locked variants of all the relevant disk tests locked to qemu-2.12, but
blockdev was finally enabled with qemu-4.2.

This patch bumps the rest of the test cases with no functional changes
related to disks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Update disk test cases having 'device_id' argument of SCSI disk
Peter Krempa [Mon, 14 Feb 2022 14:08:26 +0000 (15:08 +0100)]
qemuxml2argvtest: Update disk test cases having 'device_id' argument of SCSI disk

The 'device_id' property was added in qemu-4.0. Since upcoming patch
will be modernizing all disk test cases we specifically want to preserve
the instance of 'device_id' not being used with qemu-3.1 and earlier.

Change the 'disk-cache' and 'disk-shared' cases to have a qemu-3.1 and a
qemu-4.1 version for testing pre-'device_id' and pre-blockdev scenarios.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Add pre-blockdev post-werror-move version of 'disk-error-policy'
Peter Krempa [Mon, 14 Feb 2022 13:22:04 +0000 (14:22 +0100)]
qemuxml2argvtest: Add pre-blockdev post-werror-move version of 'disk-error-policy'

Starting with qemu-3.0 release we use the 'werror' and 'rerror'
properties with the frontend (device) rather than the storage backend
(with a minor caveat of s390, where we use it earlier as it doesn't
 support USB disks, and other disk types supported it earlier).

Add specific test cases after the change, but before '-blockdev' was
enabled.

This is done separately from the changes in the next commit which simply
moves all other disk tests to the last pre-blockdev qemu as we have a
semantic change happening after 2.12.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: command: Inline qemuBuildDiskFrontendAttributeErrorPolicy
Peter Krempa [Mon, 14 Feb 2022 12:33:41 +0000 (13:33 +0100)]
qemu: command: Inline qemuBuildDiskFrontendAttributeErrorPolicy

Commit dc481f11a61 which converted the function generating properties
for disk '-device' argument to JSON removed the only other use of
qemuBuildDiskFrontendAttributeErrorPolicy, so we can now inline it into
qemuBuildDriveStr.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildTPMCommandLine: Use 'qemuPassFD' infrastructure
Peter Krempa [Wed, 9 Feb 2022 14:09:36 +0000 (15:09 +0100)]
qemuBuildTPMCommandLine: Use 'qemuPassFD' infrastructure

Remove the last code path using hardcoded fdsets.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildTPMOpenBackendFDs: Construct 'cancel_path' internally
Peter Krempa [Wed, 9 Feb 2022 12:49:03 +0000 (13:49 +0100)]
qemuBuildTPMOpenBackendFDs: Construct 'cancel_path' internally

Since 'cancel_path' is constructed from the 'tpmdev' argument, we can
push it down into the function opening the FDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirTPMCreateCancelPath: Refactor value returning
Peter Krempa [Wed, 9 Feb 2022 12:44:06 +0000 (13:44 +0100)]
virTPMCreateCancelPath: Refactor value returning

Automatically free 'path' inside the loop which fills it and return the
values directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Honour 'virtlogd' use when hotplugging chardevs
Peter Krempa [Wed, 9 Feb 2022 14:43:03 +0000 (15:43 +0100)]
qemu: Honour 'virtlogd' use when hotplugging chardevs

Setup the chardev similarly to how we do it on startup so that virtlogd
is properly used with chardevs which are hotplugged to a VM.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: process: Add a hotplug version of qemuProcessPrepareHostBackendChardev
Peter Krempa [Thu, 3 Feb 2022 10:04:56 +0000 (11:04 +0100)]
qemu: process: Add a hotplug version of qemuProcessPrepareHostBackendChardev

When hotplugging a chardev we need the same form of setup for the
character device. Export a version which takes a 'virDomainDeviceDef'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONTestAttachChardev: Add tests for FD passing of file backend
Peter Krempa [Wed, 9 Feb 2022 12:10:57 +0000 (13:10 +0100)]
qemuMonitorJSONTestAttachChardev: Add tests for FD passing of file backend

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotests: Move testPrepareHostBackendChardevOne into test utils
Peter Krempa [Wed, 9 Feb 2022 11:30:25 +0000 (12:30 +0100)]
tests: Move testPrepareHostBackendChardevOne into test utils

Move the function doing the fake setup of chardev backend for FD passing
into the collection of qemu test helpers so that it can be used in
qemumonitorjsontest.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONAttachCharDevGetProps: Properly handle private data
Peter Krempa [Tue, 8 Feb 2022 14:47:12 +0000 (15:47 +0100)]
qemuMonitorJSONAttachCharDevGetProps: Properly handle private data

FD passing and TLS is normally setup via private data for the chardev
source. The monitor implementation didn't support it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONTestAttachChardev: Add logfile to some tests
Peter Krempa [Wed, 9 Feb 2022 09:19:56 +0000 (10:19 +0100)]
qemuMonitorJSONTestAttachChardev: Add logfile to some tests

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONTestAttachChardev: Add test for TLS-secured TCP chardev
Peter Krempa [Tue, 8 Feb 2022 18:58:07 +0000 (19:58 +0100)]
qemuMonitorJSONTestAttachChardev: Add test for TLS-secured TCP chardev

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemumonitorjsontest: Refactor chardev hotplug testing
Peter Krempa [Tue, 8 Feb 2022 15:41:33 +0000 (16:41 +0100)]
qemumonitorjsontest: Refactor chardev hotplug testing

The main objective of this patch is to use a proper instance of
virDomainChrSourceDef allocated with the private data.

To achieve this the test cases are grouped into blocks by how much they
fill in the chardev definition. Some test cases are moved around so
that the resulting sequence doesn't need extra clearing.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemumonitorjsontest: chardev: Remove need to allow unused commands
Peter Krempa [Tue, 8 Feb 2022 15:11:06 +0000 (16:11 +0100)]
qemumonitorjsontest: chardev: Remove need to allow unused commands

Don't add the command to the test monitor when we don't expect to invoke
it rather than bypassing the test monitor.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDomainRemoveChrDevice: Detach fdset after chardev hot-unplug
Peter Krempa [Thu, 3 Feb 2022 09:35:03 +0000 (10:35 +0100)]
qemuDomainRemoveChrDevice: Detach fdset after chardev hot-unplug

Our code uses fdsets for the pipe passed from virtlogd to qemu, but the
chardev hot-unplug code neglected to detach the fdset after the chardev
was removed. This kept the FDs open by qemu even after they were not
used any more.

After the refactor to use qemuFDPass for chardevs we now configure the
'opaque' field for fdsets used for chardevs so we can use
qemuHotplugRemoveFDSet to remove the unused fdset.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Rewrite chardev startup code to use qemuFDPass
Peter Krempa [Wed, 2 Feb 2022 16:31:29 +0000 (17:31 +0100)]
qemu: Rewrite chardev startup code to use qemuFDPass

Rewrite the parts which already pass FDs via fdset or directly to use
the new infrastructure.

Apart from simpler code this also adds the appropriate names to the fds
in the fdsets which will allow us to properly remove the fdsets won
hot-unplug of chardevs, which we didn't do for now and resulted in
leaking the FDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildInterfaceCommandLine: Use new pattern for naming the VDPA fdset
Peter Krempa [Mon, 31 Jan 2022 17:25:18 +0000 (18:25 +0100)]
qemuBuildInterfaceCommandLine: Use new pattern for naming the VDPA fdset

Prefix the file descriptor name with the alias of the network device so
that it's similar to other upcoming use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoQEMUHotplugRemoveFDSet: Prepare for proper FD unplug handling
Peter Krempa [Wed, 2 Feb 2022 15:30:36 +0000 (16:30 +0100)]
QEMUHotplugRemoveFDSet: Prepare for proper FD unplug handling

For now we have only one code path ('vdpa' interface) which actually
cleans up the fdset after it's done, but there are more device types
using fdsets.

In order to unify the handling of fdsets the removal code will now be
able to remove fdsets based on a prefix of the 'opaque' field, which
we'll always prefix with a device alias or e.g. node name once fdsets
are also used for disk backing.

To keep compatibility with old QEMUs, retain the possibility for the
VDPA interface to use the path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: hotplug: Extract code for unplugging fdsets
Peter Krempa [Tue, 11 Jan 2022 15:15:34 +0000 (16:15 +0100)]
qemu: hotplug: Extract code for unplugging fdsets

The code unplugging the fdset for a 'vdpa' network device can be later
reused. Extract it into 'qemuHotplugRemoveFDSet'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildInterfaceCommandLine: Use qemuFDPass for the vdpa fd
Peter Krempa [Mon, 31 Jan 2022 17:22:35 +0000 (18:22 +0100)]
qemuBuildInterfaceCommandLine: Use qemuFDPass for the vdpa fd

Use the new helpers for passing of the file descriptor needed for 'vdpa'
interfaces.

Apart from the simplification in this case it will allow further changes
to unify all fdset handling.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Introduce helper functions for passing FDs to qemu
Peter Krempa [Mon, 24 Jan 2022 16:24:55 +0000 (17:24 +0100)]
qemu: Introduce helper functions for passing FDs to qemu

The existing helpers we have are very clumsy and there's no integration
with the monitor.

This patch introduces new helpers to bridge the gap and simplify handing
of fdsets and classic FD passing when generating commandline/hotplug
arguments.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: domain: Add helper for generating 'fdset' ids for VM startup
Peter Krempa [Mon, 24 Jan 2022 15:53:27 +0000 (16:53 +0100)]
qemu: domain: Add helper for generating 'fdset' ids for VM startup

When starting a VM we must assign unique IDs for fdsets we add via
'-add-fd'. For now it was done by using the index of the filedescriptor
passed to the virCommand. That approach is not very flexible, because
you need to have already passed the 'fd' to virCommand before generating
the fdset path, and also won't nicely work with fdsets containing two or
more fds.

This patch introduces a counter into the private data of a qemu domain
so that we can allocate unique ids without relying on virCommand.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: monitor: Make 'id' in 'struct _qemuMonitorFdsetInfo' unsigned
Peter Krempa [Mon, 24 Jan 2022 15:30:13 +0000 (16:30 +0100)]
qemu: monitor: Make 'id' in 'struct _qemuMonitorFdsetInfo' unsigned

Similarly to the 'qemuMonitorRemoveFdset', it doesn't make sense
to store it as signed when only unsigned values are expected.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorRemoveFdset: Convert @fdset to unsigned int to avoid error
Peter Krempa [Mon, 24 Jan 2022 14:58:37 +0000 (15:58 +0100)]
qemuMonitorRemoveFdset: Convert @fdset to unsigned int to avoid error

'qemuMonitorRemoveFdset' validates that the 'fdset' argument isn't less
than 0. We can turn it to unsigned and thus avoid the error message
completely.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONQueryFdsetsParse: Don't check value passed to g_strdup
Peter Krempa [Tue, 11 Jan 2022 13:58:08 +0000 (14:58 +0100)]
qemuMonitorJSONQueryFdsetsParse: Don't check value passed to g_strdup

'g_strdup()' is NULL-tolerant.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuProcessPrepareHostBackendChardev: Drop unneeded arguments
Peter Krempa [Thu, 3 Feb 2022 10:00:29 +0000 (11:00 +0100)]
qemuProcessPrepareHostBackendChardev: Drop unneeded arguments

Caller passes 'driver->securityManager', and 'priv->qemuCaps' as
arguments along with 'vm', but both aforementioned objects are
accessible directly from 'vm'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuProcessPrepareHostBackendChardevFileHelper: Always use FD passing
Peter Krempa [Mon, 7 Feb 2022 16:12:31 +0000 (17:12 +0100)]
qemuProcessPrepareHostBackendChardevFileHelper: Always use FD passing

Code paths which don't wish to use FD passing are supposed to not call
the function which sets up the chardev for FD passing.

This is ensured by calling it only in the host prepare step.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoscripts/mock-noinline: Use full name of the required annotation in error message
Peter Krempa [Wed, 9 Feb 2022 15:12:58 +0000 (16:12 +0100)]
scripts/mock-noinline: Use full name of the required annotation in error message

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: domain: Change 'Id' to 'ID' in qemuDomainStorageIdNew/Reset
Peter Krempa [Mon, 14 Feb 2022 09:56:41 +0000 (10:56 +0100)]
qemu: domain: Change 'Id' to 'ID' in qemuDomainStorageIdNew/Reset

In a patch adding similarly named APIs I was asked to use 'ID' instead
of 'Id'. Since the code is being put together fix
qemuDomainStorageIdNew/Reset first.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: domain: Move and unexport 'qemuDomainStorageIdNew/Reset'
Peter Krempa [Mon, 24 Jan 2022 16:09:41 +0000 (17:09 +0100)]
qemu: domain: Move and unexport 'qemuDomainStorageIdNew/Reset'

They're used only inside qemu_domain.c. Move it before their usage,
and unexport them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirnetsockettest: Increase coverage
Andrea Bolognani [Wed, 9 Feb 2022 18:32:49 +0000 (19:32 +0100)]
virnetsockettest: Increase coverage

Add test cases for quotes appearing in the netcat parameter,
for the default behavior of proxy=auto where virt-ssh-helper
is used if available, and for proxy=native.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirnetsockettest: Allow changing the proxy parameter
Andrea Bolognani [Fri, 11 Feb 2022 17:10:32 +0000 (18:10 +0100)]
virnetsockettest: Allow changing the proxy parameter

Currently the test cases all follow the proxy=auto behavior, but
we want to add coverage for other proxy modes as well.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirnetsockettest: Tweak input for test 7
Andrea Bolognani [Thu, 10 Feb 2022 09:48:09 +0000 (10:48 +0100)]
virnetsockettest: Tweak input for test 7

The important part of the value we assign to "netcat" is that it
contains whitespace, so drop everything else to highlight this
fact.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirnetsockettest: Improve indentation
Andrea Bolognani [Wed, 9 Feb 2022 18:54:34 +0000 (19:54 +0100)]
virnetsockettest: Improve indentation

Having the actual script indented and the closing quote on a
separate line, like

  sh -c '
    if foo; then
      bar;
    fi
  '

makes things more readable and easier to scan visually.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirnetsockettest: Move opening quote
Andrea Bolognani [Wed, 9 Feb 2022 18:23:42 +0000 (19:23 +0100)]
virnetsockettest: Move opening quote

Make this test case consistent with all the other ones.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirnetsockettest: Drop unnecessary backslash
Andrea Bolognani [Wed, 9 Feb 2022 18:16:56 +0000 (19:16 +0100)]
virnetsockettest: Drop unnecessary backslash

No need to escape a single quote.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirbuffer: Simplify virBufferEscapeShell()
Andrea Bolognani [Fri, 11 Feb 2022 16:14:52 +0000 (17:14 +0100)]
virbuffer: Simplify virBufferEscapeShell()

We can exit early when the input is an empty string, and we can
avoid storing the string length in a variable since we only use
that information once.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirbuftest: Increase coverage
Andrea Bolognani [Fri, 11 Feb 2022 14:48:02 +0000 (15:48 +0100)]
virbuftest: Increase coverage

Test the behavior of virBufferEscapeShell for different types of
quotes as well as the empty string.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoutil: Fix getting CPU frequency on Apple Silicon
Andrea Bolognani [Thu, 10 Feb 2022 08:42:01 +0000 (09:42 +0100)]
util: Fix getting CPU frequency on Apple Silicon

The hw.cpufrequency sysctl, which we use to obtain the CPU
frequency on macOS, is not available when running on Apple
Silicon, and as a consequence we currently report an error
whenever such information is requested.

The virNodeInfo.mhz field, where the CPU frequency gets stored,
is documented as being zero when the information could not be
obtained, and we already do that for Linux on aarch64. Extend
this behavior to macOS on Apple Silicon.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemucapabilitiestest: Hack/fix version in qemu-3.1 tests
Peter Krempa [Thu, 3 Feb 2022 12:23:33 +0000 (13:23 +0100)]
qemucapabilitiestest: Hack/fix version in qemu-3.1 tests

The test dumps for x86_64 and ppc64 were generated from pre-release
qemu-3.0-rc1/rc2 and thus wouldn't pass our minimum version check.

As these are very old, fix the version info we use for our check to 3.1
without re-generating them and keep the version tag intact.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2xmltest: Remove unnecessary versioned invocation of 'disk-cache'
Peter Krempa [Thu, 10 Feb 2022 09:19:57 +0000 (10:19 +0100)]
qemuxml2xmltest: Remove unnecessary versioned invocation of 'disk-cache'

The 'disk-cache' output file is identical in the interesting parts
(everything besides CPU config) to the '-latest' version, so the
versioned invocation can be dropped.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemumonitortestutils: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 14:31:35 +0000 (15:31 +0100)]
qemumonitortestutils: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemusecuritymock: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 14:17:30 +0000 (15:17 +0100)]
qemusecuritymock: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agotools: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 13:59:30 +0000 (14:59 +0100)]
tools: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovbox: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 13:53:06 +0000 (14:53 +0100)]
vbox: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirtpm: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 13:50:12 +0000 (14:50 +0100)]
virtpm: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovirlockspace: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 13:45:36 +0000 (14:45 +0100)]
virlockspace: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agosecret: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 13:36:59 +0000 (14:36 +0100)]
secret: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agosecret: Factor out mutex
Tim Wiederhake [Tue, 8 Feb 2022 13:26:25 +0000 (14:26 +0100)]
secret: Factor out mutex

If the mutex is part of the `driver` object, it cannot guard that
object's creation and destruction perfectly.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovmware: Use automatic mutex management
Tim Wiederhake [Tue, 8 Feb 2022 10:36:25 +0000 (11:36 +0100)]
vmware: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agovz: Use automatic mutex management
Tim Wiederhake [Mon, 7 Feb 2022 13:22:32 +0000 (14:22 +0100)]
vz: Use automatic mutex management

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoconf: Avoid NULL-dereference in virDomainObjGetMessages
Jiri Denemark [Fri, 11 Feb 2022 12:56:29 +0000 (13:56 +0100)]
conf: Avoid NULL-dereference in virDomainObjGetMessages

All callers currently guarantee flags passed to virDomainObjGetMessages
are either zero or contain at least one of the supported flags. But it
doesn't mean we should not check for the possibility an unknown flag was
the only one passed to virDomainObjGetMessages.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_migration_cookie: Properly fetch cert DN
Jiri Denemark [Thu, 10 Feb 2022 15:16:48 +0000 (16:16 +0100)]
qemu_migration_cookie: Properly fetch cert DN

If 1024 was not enough to fit the DN, gnutls_x509_crt_get_dn would store
the required size in subjectlen. And since we're not checking the return
value of this function, we would happily overwrite some random memory.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoqemu_migration_cookie: Rename ret in qemuDomainExtractTLSSubject
Jiri Denemark [Thu, 10 Feb 2022 15:00:52 +0000 (16:00 +0100)]
qemu_migration_cookie: Rename ret in qemuDomainExtractTLSSubject

We use 'ret' for storing values to be returned from a function. Return
values from called functions that are not supposed to be returned
further are usually called 'rv' (or 'rc').

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotests: Fix fd leaks in virpcivpdtest
Jiri Denemark [Thu, 10 Feb 2022 10:32:00 +0000 (11:32 +0100)]
tests: Fix fd leaks in virpcivpdtest

Tests testVirPCIVPDReadVPDBytes and testVirPCIVPDParseFullVPDInvalid
failed to properly close open fildescriptors in some cases. Let's fix it
by switching to VIR_AUTOCLOSE in the whole file.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agosrc: Initialize stack allocated virPCIDeviceAddress variables
Michal Privoznik [Fri, 11 Feb 2022 13:30:09 +0000 (14:30 +0100)]
src: Initialize stack allocated virPCIDeviceAddress variables

There are few places where a virPCIDeviceAddress typed variable
is allocated on the stack but it's not initialized. This can lead
to random values of its members which in turn can lead to a
random behaviour.

Generated with help of the following spatch:

  @@
  identifier I;
  @@
  - virPCIDeviceAddress I;
  + virPCIDeviceAddress I = { 0 };

And then fixing bhyveAssignDevicePCISlots() which does declare
the variable and then explicitly zero it by calling memset() only
to set a specific member afterwards.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
3 years agoqemuPrepareNVRAM: Drop cleanup label
Michal Privoznik [Fri, 11 Feb 2022 08:31:48 +0000 (09:31 +0100)]
qemuPrepareNVRAM: Drop cleanup label

After previous commits, the cleanup label shrank to plain
'return' statement. There's no point in having such label, so
drop it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemuPrepareNVRAM: Switch to VIR_AUTOCLOSE
Michal Privoznik [Fri, 11 Feb 2022 08:28:11 +0000 (09:28 +0100)]
qemuPrepareNVRAM: Switch to VIR_AUTOCLOSE

Nothing inside the qemuPrepareNVRAM function relies on @srcFD
being closed early and nothing closes it early. It's okay then to
close it automatically when leaving the function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoqemuPrepareNVRAM: Us virFileRewrite() to write NVRAM
Michal Privoznik [Wed, 9 Feb 2022 08:59:24 +0000 (09:59 +0100)]
qemuPrepareNVRAM: Us virFileRewrite() to write NVRAM

After previous commits there is no need for qemuPrepareNVRAM() to
open code virFileRewrite(). Deduplicate the code by calling the
function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agovirFileRewrite: Move error reporting into callback
Michal Privoznik [Wed, 9 Feb 2022 12:43:19 +0000 (13:43 +0100)]
virFileRewrite: Move error reporting into callback

When rewriting a file using virFileRewrite() and error occurs
while writing into a temporary file it's actually the callback
that can report the most accurate error. Move error reporting
into very few callback we have currently. Those callbacks are
trivial so the benefit of this change is not obvious, but this
will change shortly when slightly more complicated callback is
introduced.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agovirFileRewrite: Allow setting owner
Michal Privoznik [Wed, 9 Feb 2022 11:22:00 +0000 (12:22 +0100)]
virFileRewrite: Allow setting owner

Currently, due to the way virFileRewrite() works, the rewritten
file is owned by user and group that the daemon runs under. So
far, this is not a problem, because the function is used to write
XML files or secrets for persistent objects (domains, networks,
etc.) and we don't need other users to read/write those files.

But shortly, this function is going to be used for creating files
for QEMU domains. There we want the QEMU process (i.e. different
user) to read the file.

Therefore, introduce two new arguments: @uid and @gid that allow
setting desired owner of the file. Pass -1 to preserve current
behaviour (i.e. create the file owned by the user running the
daemon).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agoch: Report VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER as supported
Michal Privoznik [Wed, 9 Feb 2022 12:45:28 +0000 (13:45 +0100)]
ch: Report VIR_DRV_FEATURE_NETWORK_UPDATE_HAS_CORRECT_ORDER as supported

Even though the CH driver doesn't implement virNetworkUpdate()
API, when it does it will see the arguments in correct order.
This is similar to other drivers that don't implement the API,
like ESX, libxl, LXC, etc. Enabling this driver feature stops
clients from swapping the arguments (see comment in the API for
more info).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>