Commit Graph

44816 Commits

Author SHA1 Message Date
Peter Krempa
2a273072b6 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>
2022-02-14 09:45:29 +01:00
Peter Krempa
e51c0ac891 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>
2022-02-14 09:45:28 +01:00
Tim Wiederhake
6ccafcb53e qemumonitortestutils: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:35 +01:00
Tim Wiederhake
8e5b04e332 qemusecuritymock: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:32 +01:00
Tim Wiederhake
883cd98498 tools: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:29 +01:00
Tim Wiederhake
f9c863237f vbox: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:26 +01:00
Tim Wiederhake
ae24a63ef8 virtpm: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:24 +01:00
Tim Wiederhake
db7eede6b4 virlockspace: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:21 +01:00
Tim Wiederhake
bc27d34e3b secret: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:18 +01:00
Tim Wiederhake
53850638d8 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>
2022-02-11 16:03:15 +01:00
Tim Wiederhake
ee0bc89470 vmware: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:12 +01:00
Tim Wiederhake
5305908789 vz: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 16:03:02 +01:00
Jiri Denemark
a7d77e2587 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>
2022-02-11 15:06:49 +01:00
Jiri Denemark
3a311593e5 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>
2022-02-11 15:06:19 +01:00
Jiri Denemark
d116f187c6 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>
2022-02-11 15:06:19 +01:00
Jiri Denemark
6752bfdbc4 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>
2022-02-11 15:06:19 +01:00
Michal Privoznik
1c7c759f5b 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>
2022-02-11 15:01:19 +01:00
Michal Privoznik
9a98ad6ddb 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>
2022-02-11 14:00:07 +01:00
Michal Privoznik
2ddb3bf0e1 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>
2022-02-11 13:59:45 +01:00
Michal Privoznik
18b9a7ac98 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>
2022-02-11 13:59:21 +01:00
Michal Privoznik
d295c14258 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>
2022-02-11 13:57:44 +01:00
Michal Privoznik
04ed251850 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>
2022-02-11 13:16:40 +01:00
Michal Privoznik
70f8299285 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>
2022-02-11 13:14:02 +01:00
Tim Wiederhake
a99d876a0f node_device: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:04:10 +01:00
Tim Wiederhake
fb48d87765 bhyve_driver: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:04:07 +01:00
Tim Wiederhake
a71341fad7 network: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:04:04 +01:00
Tim Wiederhake
6f3c0480b1 ch: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:04:01 +01:00
Tim Wiederhake
0a6ff46c9e ch: Prepare virCHDriverGetCapabilities for automatic mutex management
No functional change intended. This change makes the refactoring to
automatic mutex management easier to follow.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:03:58 +01:00
Tim Wiederhake
241c13a7e5 lxc: Use automatic mutex management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:03:54 +01:00
Tim Wiederhake
370fc9f47c lxc: Prepare virLXCDriverGetCapabilities for automatic mutex management
No functional change intended. This change makes the recfatoring to
automatic mutex management easier to follow.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:03:50 +01:00
Tim Wiederhake
621fa350ab libxl: Use automatic memory management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:03:47 +01:00
Tim Wiederhake
8278ca919e virthreadpool: Cleanup
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:03:44 +01:00
Tim Wiederhake
b05cca197f virthreadpool: Use automatic memory management
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-11 11:03:31 +01:00
Michal Privoznik
83cf648ced ch_process: Check whether domain is already running before starting it
There are two places where a domain can be started in CH driver:
chDomainCreateXML() and chDomainCreateWithFlags(). Both acquire a
job (good), but neither of them checks whether the domain isn't
already running. This is wrong. Fortunately, both function call
the very same virCHProcessStart() rendering it the best place for
such check.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:48:39 +01:00
Michal Privoznik
22a96eac7c ch_driver: Introduce and use virCHDomainRemoveInactive()
There are few places where a call to virDomainObjListRemove() is
guarded with !vm->persistent check. And there are some places
which are missing this check completely (leading us to losing a
domain). To prevent such mistakes introduce
virCHDomainRemoveInactive() which does the check for us. Also
replace all occurrences of virDomainObjListRemove() with the call
to the new function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:48:35 +01:00
Michal Privoznik
3d13f6abcd ch_driver: End job properly on failed chDomainCreateXML()
When creating a domain failed, then the virCHDomainObjEndJob()
would be jumped over. Fix this by creating enjob label and fixing
one goto.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:48:32 +01:00
Michal Privoznik
b928e0d80c chDomainCreateXML: Drop spurious driver unlock
Inside chDomainCreateXML(), towards the end, the driver is
unlocked even though there is no corresponding driver lock call
before that. Drop it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:48:02 +01:00
Michal Privoznik
b1e7807711 ch_driver: Don't lock driver when looking up domains
There is no need to lock whole driver when accessing
virDomainObjList. Those APIs were specifically tailored to be
thread safe (when we were dropping QEMU driver lock). Don't
resurrect old history.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:47:48 +01:00
Michal Privoznik
31ef66f12e ch_driver: Don't lock driver when getting version
In chConnectGetVersion() the CH driver is locked in order to read
driver->version. This is needless, because not only is the
version set with driver unlocked (chStateInitialize() calls
chExtractVersion() which sets the version), but the version is
practically immutable. Once driver initialized itself it's never
changed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-11 10:46:49 +01:00
Michal Privoznik
d192e522ef qemuFirmwareFillDomain: Use FW descriptors to lookup template when resetting NVRAM
If VIR_QEMU_PROCESS_START_RESET_NVRAM flag is passed when
starting a domain, then user requested to overwrite the domain
specific NVRAM with the one from template. But it is very likely
that the path to the template is not stored in the domain
definition, which in turn makes the copy function
(qemuPrepareNVRAM()) fail.

The solution is simple - when preparing domain, specifically when
deciding whether the path to the template should be autofilled,
ignore any existing NVRAM file.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-11 09:03:20 +01:00
Michal Privoznik
f21166c814 qemu_process: Accept VIR_QEMU_PROCESS_START_RESET_NVRAM flag when starting a domain
In one of my previous commits I've fixed the value of
VIR_QEMU_PROCESS_START_RESET_NVRAM flag (which was masking
another value). But what I forgot to do is update virCheckFlags()
calls in two places where the flag is passed: qemuProcessLaunch()
and qemuProcessStart().

Fixes: 1b636593c7
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-11 09:03:16 +01:00
Andrea Bolognani
2ac78307af docs: Clarify our stance on backported packages
The repositories containing them are usually offered with lower
guarantees, so we don't consider them when it comes to figuring
out the minimum targeted version of our dependencies.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-10 22:39:58 +01:00
Peter Krempa
775cd951e2 qemuMonitorOpen: Refactor cleanup
Use VIR_AUTOCLOSE to avoid a 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-10 13:13:28 +01:00
Peter Krempa
0e01846dbf qemuMonitorOpenUnix: Refactor cleanup
Use VIR_AUTOFREE for the temp socket so that the 'error:' label can be
removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-02-10 13:13:28 +01:00
Peter Krempa
ee51ab86c2 virNetDevOpenvswitchUpdateVlan: Use space for indentation
Breaks syntax-check:

TAB_in_indentation
/home/pipo/libvirt/src/util/virnetdevopenvswitch.c:610:	if (virtVlan && virtVlan->nTags > 0)
/home/pipo/libvirt/src/util/virnetdevopenvswitch.c:611:		virCommandAddArgList(cmd, "--", "--if-exists", "set", "Port", ifname, NULL);
make: Leaving directory '/home/pipo/build/libvirt/gcc/build-aux'

Fixes: 21c55a45ef
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2022-02-10 13:10:35 +01:00
tuqiang
21c55a45ef virNetDevOpenvswitchUpdateVlan: fix vlan tag update error
We try to update vlan tag by running virsh update-device command,
libvirtd will report ovs-vsctl arguments error. Vlan tag update
funtion does't consider the xml with no vlan configured circumstances.

The steps to reproduce the problem:
1 define and start domain with its vlan configured as:
    <interface type='bridge'>
      <mac address='52:54:00:9e:bb:ac'/>
      <source bridge='ovs-br0'/>
      <vlan>
        <tag id='10'/>
      </vlan>
      <virtualport type='openvswitch'>
      </virtualport>
      <target dev='vnet4.0'/>
      <model type='virtio'/>
      <driver name='vhost'/>
    </interface>
2 define and run virsh update-device command with no vlan configured as:
    <interface type='bridge'>
      <mac address='52:54:00:9e:bb:ac'/>
      <source bridge='ovs-br0'/>
      <virtualport type='openvswitch'>
      </virtualport>
      <target dev='vnet4.0'/>
      <model type='virtio'/>
      <driver name='vhost'/>
    </interface>
   #virsh update-device dom-id novlan.xml
3 virsh command returned error, and we got an error in libvirtd.log:
  error : virCommandWait:2584 : internal error: exit status 1: ovs-vsctl: 'set' command requires at least 3 arguments
  . Child process (ovs-vsctl --timeout=5 -- --if-exists clear Port vnet4.0 tag -- --if-exists clear Port vnet4.0 trunk
  -- --if-exists clear Port vnet4.0 vlan_mode -- --if-exists set Port vnet4.0) unexpected
  error : virNetDevOpenvswitchUpdateVlan:540 : internal error: Unable to set vlan configuration on port vnet4.0

Signed-off-by: Tu Qiang <tu.qiang35@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-10 13:02:10 +01:00
Jing Qi
89b8b3662e docs: Fix HMAT example
There are dupliacated and non-continuous CPU IDs used in HMAT
example. Fix that.

Signed-off-by: Jing Qi <jinqi@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-10 12:43:36 +01:00
Jiri Denemark
558f00397a qemu: Ignore missing vm.unprivileged_userfaultfd sysctl
Older kernels did not support this sysctl, but they did not restrict
userfaultfd in any way so everything worked as if
vm.unprivileged_userfaultfd was set to 1. Thus we can safely ignore
errors when setting the value.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-09 13:03:33 +01:00
Michal Privoznik
da393034c9 qemu_process: Fix theoretical overflow in uint to bool typecast
The qemuPrepareNVRAM() function accepts three arguments and the
last one being a boolean type. However, when the function is
called from qemuProcessPrepareHost() the argument passed is a
result of logical and of @flags (unsigned int) and
VIR_QEMU_PROCESS_START_RESET_NVRAM value. In theory this is
unsafe to do because if the value of the flag is ever changed
then this expression might overflow. Do what we do elsewhere:
double negation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-09 09:31:54 +01:00
Michal Privoznik
1b636593c7 qemu_process.c: Fix VIR_QEMU_PROCESS_START_RESET_NVRAM value
In one of recent commits qemuProcessStartFlags enum gained new
value: VIR_QEMU_PROCESS_START_RESET_NVRAM but due to a typo it
has the same value as another member of the enum. Fix that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-09 09:30:15 +01:00