Commit Graph

42321 Commits

Author SHA1 Message Date
Daniel P. Berrangé
191b3b81b1 remote: extract logic for probing for modular daemons
When virtproxyd gets a NULL URI, it needs to implement probing logic
similar to that found in virConnectOpen. The latter can't be used
directly since it relied on directly calling into the internal drivers
in libvirtd. virtproxyd approximates this behaviour by looking to see
what modular daemon sockets exist, or what daemon binaries are installed.

This same logic is also going to be needed when the regular libvirt
remote client switches to prefer modular daemons by default, as we
don't want to continue spawning libvirtd going forward.

Tested-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-06-18 16:19:42 +01:00
Daniel P. Berrangé
ce410b6ea9 remote: fix prefix for libxl Xen driver
The libxl driver supports xen:///system URLs and the daemon socket
uses 'virtxend' as the socket prefix.

Reported-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-06-18 15:24:56 +01:00
Peter Krempa
b396e9dd9d qemuSnapshotCreateActiveExternal: Don't unlink memory snapshot image if it was existing before
When writing the memory snapshot into an existing file don't remove it
if the snapshot fails later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
b30a8ee67d conf: snapshot: rename variable holding memory snapshot file location
'file' is too generic to know what's going on. Rename it to
'memorysnapshotfile'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
308aafe289 qemuSnapshotPrepareDiskExternal: Refactor existing file check
Use the snapshot disk type from the definition now that we validate that
it matches.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
919b129603 qemuSnapshotPrepareDiskExternal: Enforce match between snapshot type and existing file type
The code executed later when creating a snapshot makes all decisions
based on the configured type rather than the actual type of the existing
file, while the check whether the file exists is based solely on the
on-disk type.

Since a block device is allowed to exist even when not reusing existing
files in contrast to regular files this creates a potential for a block
device to squeak past the check but then be influenced by other code
executed later. Specifically this is a problem when creating a snapshot
with the following XML:

  <domainsnapshot>
    <disks>
      <disk name='vdb' type='file'>
        <source file='/dev/sdb'/>
      </disk>
    </disks>
  </domainsnapshot>

If the snapshot creation fails, '/dev/sdb' will be removed because it's
considered to be a regular file by the cleanup code.

Add a check that will force that the configured type matches the on-disk
state.

Additional supporting reason is that qemu stopped to accept block
devices with the 'file' backend, thus the above configuration will not
work any more. This allows us to fail sooner.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1972145
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
66adff17a8 qemuSnapshotPrepareDiskExternal: Reject creation of block devices sooner
In case when the snapshot target is of VIR_STORAGE_TYPE_BLOCK type and
doesn't exist libvirt won't be able to create it. Reject such a config
sooner.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
a96cc845d7 qemuSnapshotPrepareDiskExternal: Avoid condition squashing
Separate the 'else if' branches into nested conditions so that it's more
obvious when we'll be adding additional checks later.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
006821a809 qemuSnapshotPrepareDiskExternal: Move temp variables into the block using them
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
c3e578b2ef qemu: capabilities: Fill egl-headless graphics support only when it's really supported
virQEMUCapsFillDomainDeviceGraphicsCaps fills data needed both for
validation of the graphics type and also for correct display in the
(dom)capablities XML.

Signal the support for egl-headless only when qemu has the capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
4c3127695d tests: qemuxml2*: Add QEMU_CAPS_EGL_HEADLESS to fake-caps tests using egl-headless graphics
Next commit will modify the code so that it validates whether
egl-headless is present. Certain tests need to get the egl-headless
capability to keep working properly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2021-06-18 09:16:16 +02:00
Peter Krempa
4808323994 qemu: capabilities: Un-retire QEMU_CAPS_EGL_HEADLESS
egl-headless graphics can be compiled out in qemu so we need to be able
to know whether the given qemu version support it.

Base the capability on the presence of the 'egl-headless' member in
'query-display-options' or imply it if 'query-display-options' is not
supported as we implied it before for all versions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2021-06-18 09:16:16 +02:00
Jim Fehlig
68940b3fb3 Xen: Bump minimum supported Xen version to 4.9
Platforms supported by libvirt have the following Xen versions

openSUSE Leap 15.2: 4.13
openSUSE Leap 15.3: 4.14
         Fedora 33: 4.14
      Ubuntu 18.04: 4.9
      Ubuntu 20.04: 4.11
     Debian Stable: 4.11

Bumping the minimum version doesn't allow us to drop much code, but it
does provide better alignment with libvirt's platform support statement.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-06-17 10:11:56 -06:00
Michal Privoznik
70a2b618bb qemu: Deduplicate code in qemuSecurityChownCallback()
The DAC security driver has an option to register a callback that
is called instead of chown(). So far QEMU is the only user of
this feature and it's used to set labels on non-local disks (like
gluster), where exists notion of owners but regular chown() can't
be used.

However, this callback (if set) is called always, even for local
disks. And thus the QEMU's implementation duplicated parts of the
DAC driver to deal with chown().

If the DAC driver would call the callback only for non-local
disks then the QEMU's callback can be shorter.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:49:17 +02:00
Michal Privoznik
6fba030fed virSecurityDACSetOwnershipInternal: Fix WIN32 code
I must admit, I have no idea why we build such POSIX dependent
code as DAC driver for something such not POSIX as WIN32. Anyway,
the code which is supposed to set error is not doing that. The
proper way is to mimic what chown() does:

  On error, -1 is returned, and errno is set to indicate the error.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:49:12 +02:00
Michal Privoznik
b332c2cf89 virSecurityDACSetOwnershipInternal: Don't overwrite @path argument
As shown in the previous commit, @path can be NULL. However, in
that case @src->path is also NULL. Therefore, trying to "fix"
@path to be not NULL is not going to succeed. The real value of
NULLSTR() is in providing a non-NULL string for error reporting.
Well, that can be done in the error reporting without overwriting
argument.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:49:07 +02:00
Michal Privoznik
5cfb3369b1 virSecurityDACSetOwnershipInternal: Drop dead code
The virSecurityDACSetOwnershipInternal() function accepts two
arguments (among others): @path and @src. The idea being that in
some cases @path is NULL and @src is not and then @path is filled
from @src->path. However, this is done in both callers already
(because of seclabel remembering/recall). Therefore, this code in
virSecurityDACSetOwnershipInternal() is dead, effectively.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:49:02 +02:00
Michal Privoznik
4ac78b95d3 security_dac: Don't check for !priv in virSecurityDACSetOwnershipInternal()
The virSecurityDACSetOwnershipInternal() has two callers and in
both the private data (@priv) is obtained via
virSecurityManagerGetPrivateData(). But in case of DAC driver the
private data can never be NULL. This is because the private data
is allocated in virSecurityManagerNewDriver() according to
.privateDataLen attribute of secdriver. In case of DAC driver the
attribute is set to sizeof(virSecurityDACData).

NB, no other function within DAC driver checks for !priv.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:48:56 +02:00
Michal Privoznik
1740f33bc8 security_dac: Introduce g_autoptr for virSecurityDACChownList
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:48:52 +02:00
Michal Privoznik
0782c4dcb3 security_dac: Introduce virSecurityDACChownItemFree()
Introduce a function that frees individual items on the chown
list and declare and use g_autoptr() for it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:48:44 +02:00
Michal Privoznik
91b5ced2f7 security_dac: Use g_autofree
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-17 15:48:10 +02:00
Ján Tomko
e8863b91fb conf: require target for external virtiofsd
When adding support for externally launched virtiofsd,
I was too liberal and did not require a target.

But the target is required, because it's passed to the
QEMU device, not to virtiofsd.

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

Fixes: 12967c3e13
Fixes: 56dcdec1ac
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-17 10:51:24 +02:00
Ján Tomko
2dabd16588 conf: move filesystem target validation
Check the presence of the target in the validation phase.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-17 10:51:24 +02:00
Michal Privoznik
fb1289c155 qemu: Don't set NVRAM label when creating it
The NVRAM label is set in qemuSecuritySetAllLabel(). There's no
need to set its label upfront. In fact, setting it twice creates
an imbalance because it's unset only once which mangles seclabel
remembering. However, plain removal of the
qemuSecurityDomainSetPathLabel() undoes the fix for the original
bug (when dynamic ownership is off then the NVRAM is not created
with cfg->user and cfg->group but as root:root). Therefore, we
have to switch to virFileOpenAs() and pass cfg->user and
cfg->group and VIR_FILE_OPEN_FORCE_OWNER flag. There's no need to
pass VIR_FILE_OPEN_FORCE_MODE because the file will be created
with the proper mode.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1969347
Fixes: bcdaa91a27
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-06-17 09:15:09 +02:00
Ján Tomko
56dcdec1ac conf: reject duplicate virtiofs tags
https://gitlab.com/libvirt/libvirt/-/issues/178

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-16 16:57:57 +02:00
Ján Tomko
9e2a2f4d6d docs: fix filesystem schema indentation
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-16 16:57:57 +02:00
Peter Krempa
e4054d4cd4 gitlab-ci: Don't build docs in 'sanitizer' jobs
Docs are not sanitized, thus there's no point in building them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2021-06-16 13:05:37 +02:00
Lee Yarwood
b722f36e92 qemu_hotplug: Report VIR_ERR_DEVICE_MISSING when device is not found
126db34a81 had previously switched various
flows over to this from VIR_ERR_OPERATION_FAILED.

This change simply does the same for qemuDomainDetachPrepDisk,
qemuDomainDetachPrepInput and qemuDomainDetachPrepVsock to allow
management apps to centralise their error handling on just
VIR_ERR_DEVICE_MISSING for missing devices during a detach.

Signed-off-by: Lee Yarwood <lyarwood@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-16 13:01:36 +02:00
Lin Ma
16c43b2d49 virsh-volume: Apply virshStorageVolNameCompleter to vol-{key,path} commands
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-16 10:32:43 +02:00
Lin Ma
6a1bf268d9 virsh-volume: Apply virshStorageVolKeyCompleter to vol-{name,pool} commands
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-16 10:32:42 +02:00
Lin Ma
64818c9ec1 virsh-volume: Add macros VIRSH_COMMON_OPT_VOL_*
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-16 10:32:39 +02:00
Lin Ma
254504adc3 virsh-volume: Introduce virshStorageVolKeyCompleter
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-16 10:32:36 +02:00
Lin Ma
64787c80fc virsh-pool: Remove static from virshStoragePoolList{Free,Collect}
The functions will be used by next patch.

Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-16 10:32:33 +02:00
Michal Privoznik
9a51edebf8 virFindFileInPath: Don't pass NULL to g_canonicalize_filename()
If given file is not found in $PATH then g_find_program_in_path()
returns NULL. However, g_canonicalize_filename() does not accept
NULL as input.

Fixes: 65c2901906
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-15 21:14:03 +02:00
Peter Krempa
49d47342b3 virStorageBackendRBDGetVolNames: Refactor cleanup in 'rbd_list' version
Use automatic memory freeing for the string list so that we can remove
the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
361a18f405 virStorageBackendRBDGetVolNames: Fix memory leak in 'rbd_list2' version
The 'rbd_image_spec_t' struct has two string members 'id' and
'name'. We only stole the 'name' members thus the 'id's as well as the
whole list would be leaked on success.

Restructure the code so that we copy out the image names and call
rbd_image_spec_list_cleanup on success rather than on error.

The error path is then handled by using g_autofree for 'images'.

Since we no longer have a error path after allocating the returned
string list we can completely remove its cleanup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
7d50abb805 qemuMonitorJSONGetStringListProperty: Don't return element count
The only caller doesn't care about the number of elements in the string
list so we don't have to calculate it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
99908b930d qemuMonitorJSONGetStringArray: Don't return element count
There's just one caller who cares (testQemuMonitorJSONGetTPMModels). Fix
it and remove the counting of elements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
a5bc5f0ecf virQEMUCapsProbeQMPTPM: Refactor handling of string lists
This refactors multiple aspects of the function:

1) Use automatic memory freeing
2) Remove need to check element count in the returned arrays
3) Fixes questionable code linebreaks
4) Removes reuse of variables

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
b20ef5e6de virQEMUCapsProcessStringFlags: Don't require 'nvalues'
All callers pass in NULL-terminated string lists. Remove the 'nvalues'
argument and fix all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
651f77f898 qemu: capabilities: Use g_auto(GStrv) instead of virStringListFreeCount
All the capability getters which return a string list do in fact return
a NULL-terminated list so we can use g_auto(GStrv) to free it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
d30548aa48 testQemuMonitorJSONGetTPMModels: Refactor cleanup
Use automatic memory freeing and remove the cleanup section.t

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
d5578879a8 testQemuMonitorJSONGetCommands: Refactor cleanup
Use g_auto(GStrv) for clearing the string list and thus remove the
'cleanup' section and 'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
ed4c75c4da qemuMonitorJSONGetObjectTypes: Refactor cleanup
Use automatic memory clearing to simplify the control flow.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
1a468c01a8 qemuMonitorJSONGetStringArray: Refactor cleanup
Use automatic memory clearing to simplify the control flow.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
ea0b164367 qemuMonitorJSONGetCommands: Refactor cleanup
Use automatic memory freeing to simplify the control flow.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
675755e044 qemuMonitorJSONGetMigrationCapabilities: Refactor cleanup
Use automatic memory clearing and remove the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
d0f60b89f3 qemuMonitorJSONGetObjectProps: Refactor cleanup
Use 'g_autoptr' for the two temporary JSON objects and remove the
cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
b408580960 qemuMonitorJSONParsePropsList: Refactor cleanup
Use 'g_auto' for @proplist and remove @ret.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-06-15 16:58:23 +02:00
Peter Krempa
599b17d580 qemu: capabilities: Fill SDL graphics support only when it's really supported
virQEMUCapsFillDomainDeviceGraphicsCaps fills data needed both for
validation of the graphics type and also for correct display in the
(dom)capablities XML.

Signal the support for SDL only when qemu has the capability.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
2021-06-15 16:58:23 +02:00