36338 Commits

Author SHA1 Message Date
Michal Privoznik
291186daa3 apparmor: Allow SGX if configured
If SGX memory model is configured for domain then we need to
allow QEMU access some additional files:

  1) /dev/sgx_vepc needs to be RW
  2) /dev/sgx_provision needs to be RO

We already do this in SELinux driver but not in AppArmor.

Resolves: https://gitlab.com/libvirt/libvirt/-/issues/751

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-25 12:48:24 +01:00
Jiri Denemark
5c78395bad cpu: Do not call g_strv_contains on NULL list
When virCPUx86UpdateLive checks whether a feature was added to a CPU
model after the model was already released (vmx-* features in most Intel
models), the following assert could be logged by glib:

    g_strv_contains: assertion 'strv != NULL' failed

While most of our CPU models have a non-empty list of added feature, new
models added in 2024 and versioned variants of older models have
addedFeatures == NULL.

Fixes: e622970c8785ec1f7e142d72f792d89f870e07d0
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-02-25 09:35:26 +01:00
Laine Stump
be5332c81d schema: fix <interleave> errors when validating <domain> subelements
I first noticed a problem when I added a <memoryBacking> element at an
unusual (but still correct) place in the domain XML, and validation
failed. Then I tried adding that element in several different places
and it failed in many, but not all of them.

(NB: from here on, I will use '' for the names of attributes in the
domain XML, <> for elements in the domain XML, and "" for the names of
grammar rule definitions in the RNG file, and "<>" for the names of
elements in the RNG file's own XML. Confused yet? If so, please tell
me a better way - everything I know about RNG I've picked up
informally by looking at examples in already existing RNG files)

Starting from the top level of the grammar for <domain>
("domaincontents" in domaincommon.rng), I noticed that

1) the "<attribute>" for the 'id' attribute of <domain> is defined
   inside an "<interleave>" down in the definition of "ids" (which is
   referenced from "domaincontents") (I'm not familiar with the
   nomenclature - does that make it a "sub-grammer", "child-grammar",
   ???)

2) although the definition of "ids", had all of its
   "<attribute>"s/"<element>"s inside an "<interleave>",
   "domaincontents" already had the reference to "ids" inside an
   "<interleave>", so there were nested "<interleave>"s.

It's not clear to me how an "<attribute>" or "<interleave>" inside
another "<interleave>" is supposed to behave, but they both seemed a
bit suspicious.

I tried all of the below modifications:

1) moving the grammar for the 'id' attribute out of the "<interleave>"
   but still inside "ids"

2) moving the grammer for the 'id' attribute directly into
   "domaincontents" (and outside of its "interleave"

3) removing the "<interleave>" that was inside "ids"

4) (2) + (3)

5) move the entire grammar rule "ids" up directly in place of <ref
   name="ids"> in "domaincontents".

6) (5), but with the grammar for the 'id' attribute moved outside of
   the "<interleave>"

(6) was the only change that allowed all of the following (using
modifications to the subelements of <domain> in
net-vhostuser-passt.xml as example):

a) a <memoryBacking> element in between *any* two existing elements

b) moving <name> in between any two elements

c) oddly, in addition to the problem with putting <memoryBacking> in
   odd places, I also found that the original RNG did not allow the
   <clock> element to be placed in between <on_poweroff> and
   <on_reboot>, but once I'd made the change in (6), this was no
   longer problematic. Why should this have any effect? No idea, but
   it works :-/

(NB: there are many other cases of referencing "sub-grammar" from
inside an "<interleave>", and they all seem to work just fine;
possibly in this case it was problematic because the sub-grammar a)
also contained an "<interleave>", b) had an "<attribute>" at its
toplevel, or c) had multiple "<element>"s.)

(inexplicably (to me) at one point during my experimentation, I tried
reordering the references to "clock", "resources", "features", and
"events", and that *also* made it legal to put a <clock> element in
between the <on_*> elements:-O)

Since I was no longer able to reproduce the error described in (c)
once I had made mod (6) (move all of "ids" directly into
"domaincontent", I decided it was pointless for me to spend any more
time randomly poking and just add that to the new test case for that
in case some other random change to the RNG causes it to start failing
again.

(I thought of writing a test program that would try all possible
orderings of the subelements of <domain>, but since doing that for
even 10 subelements would mean testing > 3.2 million different XML
documents, I decided we could continue in this adhoc manner, just
adding a single new test case if/when a new validation failure is
found.)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-02-21 13:52:52 -05:00
Peter Krempa
d78260cd3f conf: Validate that iothreads are used only with 'virtio-scsi' controllers
The documentation states:

 ``iothread``
    Supported for controller type ``scsi`` using model ``virtio-scsi`` for
    ``address`` types ``pci`` and ``ccw`` :since:`since 1.3.5 (QEMU 2.4)`. The

The code itself didn't validate if iothread is specified for any other
controller type.

Add test case showing the issue on one example.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:45 +01:00
Peter Krempa
1b4e451dcb conf: schemas: Rename 'diskDriverIothreads' to 'iothreadMapping'
The schema definition will be reused when adding iothread<->virtqueue
mapping for 'virtio-scsi'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:45 +01:00
Peter Krempa
e1c3fead7d qemuValidateCheckSCSIControllerIOThreads: Return '0' and '-1' instead of bools
The function reports libvirt errors so stick with the usual '0' and '-1'
return values.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:45 +01:00
Peter Krempa
a2183d9a13 qemu: validate: Extract iothread mapping validation code
Extract the code to 'qemuDomainValidateIothreadMapping'. It will be
reused to validate the mapping for 'virtio-scsi' iothreads.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:45 +01:00
Peter Krempa
a21319bb94 qemu: command: Rename 'qemuBuildDiskDeviceIothreadMappingProps' to 'qemuBuildIothreadMappingProps'
Prepare for reuse of the code for 'virtio-scsi' controller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:45 +01:00
Peter Krempa
3313ab3932 hypervisor: domain: Extract code for checking iothread usage
The code will be also needed for 'virtio-scsi' controller definitions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:44 +01:00
Peter Krempa
79c68ae313 conf: domain: Extract code for parsing and formatting iothread mapping definition
The code will be also needed for 'virtio-scsi' controller definitions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:44 +01:00
Peter Krempa
4b651cf890 conf: Rename 'virDomainDiskIothreadDef' to 'virDomainIothreadMappingDef'
The iothread mapping will be also possible for 'virtio-scsi' controllers
so rename the corresponding structs to a generic name.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:21:44 +01:00
Peter Krempa
f0c9c34d58 qemuDomainGetStats: Convert worker functions to void
The presence of a return value made it seem that it's expected to fail
on errors which is not the case. The function is designed to skip
anything it can't fill and not fail when fetching individual stats.

Convert the workers to void to make it clear that it's expected not
to fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:41 +01:00
Peter Krempa
4086f9ed5c qemuDomainGetStatsDirtyRate: Don't error out
The bulk domain stats API is meant to collect as much data as possible
without erroring out.

If fetching of the dirty rate stats fails just skip outputting them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:41 +01:00
Peter Krempa
a0122665c6 qemuDomainGetStatsMemoryBandwidth: Don't error out
The bulk domain stats API is meant to collect as much data as possible
without erroring out.

If fetching of the memory bandwidth stats fails just skip outputting them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:41 +01:00
Peter Krempa
a761c44b90 qemuDomainGetStatsIOThread: Don't error out if fetching iothread info fails
The bulk domain stats API is meant to collect as much data as possible
without erroring out. Ignore errors from 'qemuDomainGetIOThreadsMon()'
and skip the data if an error happens.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:41 +01:00
Peter Krempa
f05f54d8fb qemuDomainGetStatsPerfOneEvent: Ignore erros from 'virPerfReadEvent'
The bulk domain stats API is meant to collect as much data as possible
without erroring out. Skip the perf stats if we can't fetch them instead
of erroring out.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
613901baec virPerfReadEvent: Refactor to return -errno on failure
The function didn't comply with libvirt's error reporting scheme as it
reported libvirt errors only sometimes. As callers may want to ignore
errors convert it to returning -errno on failure instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
a4c0c6fd9f qemuDomainGetStatsCpuCache: Don't error out
The bulk domain stats API is meant to collect as much data as possible
without erroring out.

If fetching of the cache stats fails just skip outputting them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
f660984273 qemuDomainGetStatsCpuHaltPollTime: Remove return value
The function can't fail. Remove return value and refactor callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
acad77f04b qemuDomainGetStatsCpuProc: Remove return value
The function can't fail. Remove return value and refactor callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
a90df14a35 qemuDomainGetStatsCpuCgroup: Remove return value
The function can't fail. Remove return value and refactor callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
3518f46cba virBitmapFormat: Don't check return value
'virBitmapFormat' always returns a string; remove pointless checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:40 +01:00
Peter Krempa
a44a48b681 virDomainCputuneDefFormat: Refactor bitmap formatting
Use g_autofree for the temporary variables, remove error checks for
virBitmapFormat and simplify formatting of multiple attributes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
5e4262b9ac virDomainResctrlMonDefParse: Refactor temporary variables
Decrease scope of temporary variables so that they don't have to be
autofreed and VIR_FREE()d at the same time.

Remove unneeded checks and temporary variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
13c54c8945 virBitmapFormat: Clarify returned values
NULL can't be returned; don't mention it in the docs.

Avoid extra cofusing variable when returning copy of empty string.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
3c6d78aff7 qemuDomainGetStatsBlockExportHeader: Remove return value
The function always returns 0. Remove return value and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
a4b5ef9c87 qemuDomainStorageAlias: Remove NULL checks from callers
'qemuDomainStorageAlias' always returns non-NULL pointer if it gets a
non-NULL string on input. Remove unneeded checks from callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
f5e4c2a508 qemuDomainGetStatsOneBlock: Remove return value
The function always returns 0. Remove return value and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
e5b0612021 qemuDomainGetStatsOneBlockFallback: Remove return value
The function always returns 0. Remove return value and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
924805d29c qemuDomainGetStatsBlockExportBackendStorage: Remove return value
The function always returns 0. Remove return value and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
016fa9d73c qemuDomainGetStatsBlockExportFrontend: Remove return value
The function always returns 0. Remove return value and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:39 +01:00
Peter Krempa
b14968e6bd qemuDomainGetStatsBlockExportHeader: Remove return value
The function always returns 0. Remove return value and fix callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-20 15:15:38 +01:00
Jiri Denemark
43eae1b707 qemu: Avoid crash in qemuDomainCheckCPU with unknown host CPU
When we don't have any information about host CPU (for example when
running on an aarch64 host), the virQEMUCapsGetHostModel would return
NULL.

Fixes: f928eb5fc80ca0ed7277f2513b63aed36c09d275
Fixes: https://gitlab.com/libvirt/libvirt/-/issues/747
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Tested-by: Jaroslav Suchanek <jsuchane@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2025-02-18 12:08:14 +01:00
Laine Stump
08db3e8dc2 util: fix compile warning in virsystemd.c during mingw builds
A function was changed from having no arguments to having a single
argument, but the entire body of the function was #ifdefed out for
windows builds, leaving that new argument unused. Surprisingly this
didn't cause the build to fail, but I happened to notice it flit by
during an rpm build.

Fixes: 785cd56e5803fbbf60715fb6c7536360df5b4b9e
Signed-off-by: Laine Stump <laine@redhat.com>
2025-02-17 23:25:45 -05:00
Andrea Bolognani
f2023e8018 utils: Canonicalize paths before comparing them
In virFileIsSharedFSOverride() we compare a path against a list
of overrides looking for a match.

All overrides are canonicalized ahead of time though, so e.g.
/var/run/foo will be turned into /run/foo due to /var/run being
a symlink on modern Linux systems. But the path we're trying to
match with the overrides doesn't get the same treatment, so in
this scenario the comparison will always fail.

Canonicalizing the path as well solves the issue.

Resolves: https://issues.redhat.com/browse/RHEL-79165
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2025-02-17 18:30:35 +01:00
Laine Stump
70bce2e6ee qemu: fail validation if a domain def has vhostuser/passt but no shared mem
This can/should also be done for a traditional vhost-user interface
(ie not backend type='passt') but that will be a separate change.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-17 00:02:11 -05:00
Laine Stump
1e9054b9c7 qemu: complete vhostuser + passt support
<interface type='vhostuser'><backend type='passt'/> needs to run the
passt command just as is done for interface type='user', but then add
vhostuser bits to the qemu commandline/monitor command.

There are some changes to the parsing/validation along with changes to
the vhostuser codepath do do the extra stuff for passt. I tried
keeping them separated into different patches, but then the unit test
failed in a strange way deep down in the bowels of the commandline
generation, so this patch both 1) makes the final changes to
parsing/formatting and 2) adds passt stuff at appropriate places for
vhostuser (as well as making a couple of things *not* happen when the
passt backend is chosen). The result is that you can now have:

    <interface type='vhostuser'>
      <backend type='passt'/>
      ...
    </interface>

Then as long as you also have the following as a subelement of
<domain>:

    <memoryBacking>
      <access mode='shared'/>
    </memoryBacking>

your passt interfaces will benefit from the greatly improved
efficiency of a vhost-user data path, and all without requiring
special privileges or capabilities *anywhere* (i.e. it works for
unprivileged libvirt (qemu:///session) as well as privileged libvirt).

Resolves: https://issues.redhat.com/browse/RHEL-69455
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-17 00:00:37 -05:00
Laine Stump
7b7c56c3b8 qemu: make qemuPasstCreateSocketPath() public
When passt is used with vhostuser, the vhostuser code that builds the
qemu commandline will need to have the same socket path that is given
to the passt command, so this patch makes it visible outside of
qemu_passt.c.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
6fe3d765e5 qemu: use switch instead of if in qemuProcessPrepareDomainNetwork()
qemuProcessPrepareDomain()'s comments say that it should be the only
place to change the "live XML" of a domain (i.e. the public parts of
the virDomainDef object that is shown in the domain's status
XML), and that seems like a reasonable idea (although there aren't
many users of it to date).

qemuProcessPrepareDomainNetwork() is called by the aforementioned
qemuProcessPrepareDomain() - this patch changes the "if (type ==
HOSTDEV)" in that function to a "switch(type)" so it's simpler to add
DomainDef modifications for various other types of virDomainNetDef,
and also so that anyone who adds a new interface type is forced to
look at the code and decide if anything needs to be done here for the
new type.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
fb4bfa7858 conf/qemu: make <source> element *almost* optional for type=vhostuser
For some reason, when vhostuser interface support was added in 2014,
the parser required that the XML for the <interface> have a <source>
element with type, mode, and path, all 3 also required. This in spite
of the fact that 'unix' is the only possible valid setting for type,
and 95% of the time the mode is set to 'client' (as I understand from
comments in the code, normally a guest will use mode='client' to
connect to an existing socket that is precreated (by OVS?), and the
only use for mode='server' is for test setups where one guest is setup
with a listening vhostuser socket (i.e. 'server') and another guest
connects to that socket (i.e. 'client')). (or maybe one guest connects
to OVS in server mode, and all the others connect in client mode, not
sure - I don't claim to be an expert on vhost-user.)

So from the point of view of existing vhost-user functionality, it
seems reasonable to make 'type' and 'mode' optional, and by default
fill in the vhostuser part of the NetDef as if they were 'unix' and
'client'.

In theory, the <source> element itself is also not *directly* required
after this patch, however, the path attribute of <source> *is*
required (for now), so effectively the <source> element is still
required.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
56f4cc167a qemu: do all vhostuser attribute validation in qemu driver
Since vhostuser is only used/supported by the QEMU driver, and all the
rest of the vhostuser-specific validation is done in QEMU's
validation, lets move the final check (to see if they've tried to
enable auto-reconnect when this interface is on the server side of the
vhostuser socket) to the QEMU validate.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
c4746418d7 qemu: automatically set model type='virtio' for interface type='vhostuser'
Both vdpa and vhostuser require that the guest device be virtio, and
for interface type='vdpa', we already set <model type='virtio'/> if it
is unspecified in the input XML, so let's be just as courteous for
interface type='vhostuser'.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
154d44a585 qemu: validate that model is virtio for vhostuser and vdpa interfaces in the same place
Both vhostuser and vdpa interface types must use the virtio model in
the guest (because part of the functionality is implemented in the
guest virtio driver). Due to ["because that's the way it happened"]
this has been validated for vhostuser in the hypervisor-agnostic
validate function, but for vdpa it has been done in the QEMU-specific
validate. Since these interface models are only supported by QEMU
anyway, validate for both of them in the QEMU validation function.

Take advantage of this change to switch to using
virDomainNetIsVirtioModel(net) instead of "net->model ==
VIR_DOMAIN_NET_MODEL_VIRTIO" (the former also matches
...VIRTIO_TRANSITIONAL and ...VIRTIO_NON_TRANSITIONAL, so is more
correct).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
6345ee60d8 qemu: fix qemu validation to forbid guest-side IP address for type='vdpa'
Because all the checks for VIR_DOMAIN_NET_TYPE_VDPA were inside an
else-if clause that was immediately followed by another else-if clause
that forbid setting guestIP.ips or guestIP.routes, we've been allowing
users to set guestIP.* for vdpa interfaces (but then not doing
validation of the attributes that should have been done if we *did*
support setting IPs for vdpa (but we don't anyway, so 🤷.)

This can be fixed by turning the vdpa else-if clause into a top-level
if - this way vdpa interfaces will hit the "else if
(net->guestIP.nips)" clause and reject guest-side IP address setting.

Also, since there are currently *no* interface types for QEMU that
support adding guest-side routes, we put that check by itself (I think
it may be possible to set some guest routes for passt interfaces, but
we don't do that)

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Laine Stump
956c668411 conf: change virDomainHostdevInsert() to return void
We haven't checked for memalloc failure in many years, and that was
the only reason this function would have ever failed.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2025-02-16 23:58:35 -05:00
Michal Privoznik
715bfc5e54 remote_daemon: Silence DBus errors
When a daemon (like libvirtd, virtqemud, etc.) is started as an
unprivileged user (which is exactly how KubeVirt does it), then
it tries to register on both session and system DBus-es so that
it can shut itself down (e.g. when system is powering off or user
logs out). It's worth noting that this is just opportunistic and
if no DBus is available then no error is reported.

Or at least that's what we thought. Because the way our
virGDBusGetSessionBus() and virGDBusGetSystemBus() are written an
error is actually reported every time the daemon starts.

Use virGDBusHasSessionBus() and virGDBusHasSystemBus() to check
if corresponding bus is available.

Resolves: https://issues.redhat.com/browse/RHEL-79088
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2025-02-13 15:20:34 +01:00
Michal Privoznik
0428c69b09 virgdbus: Introduce virGDBusHasSessionBus()
This is just like virGDBusHasSystemBus() except it checks for the
session bus instead of the system one.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2025-02-13 15:20:34 +01:00
Daniel P. Berrangé
bccbb592de qemu: add 'auto_start_delay' configuration parameter
This allows a user specified delay between autostart of each VM, giving
parity with the equivalent feature of libvirt-guests.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-02-12 18:06:02 +00:00
Daniel P. Berrangé
1e9d58ef49 hypervisor: add support for delay interval during autostart
This delay can reduce the CPU/IO load storm when autostarting many
guests.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-02-12 18:05:56 +00:00
Daniel P. Berrangé
c23554fc34 src: convert drivers over to use new autostart helper
This eliminates some duplicated code patterns aross drivers.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2025-02-12 18:05:55 +00:00