Commit Graph
100 Commits
Author SHA1 Message Date
Michal Privoznik 4984c5bd02 ci: regenerate with 'lcitool manifest'
This drops Debian 12 and introduces Debian 13, since Debian 12
reached its EOL on 2026-06-10 [1]. However, Debian 13 dropped
official support for mipsel and mips64el, but introduced riscv64
support. Reflect this changes in supported arches in the manifest
file and regenerate with the latest lcitool.

1: https://www.debian.org/releases/
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-06-02 12:22:05 +02:00
Michal Privoznik 648c59735a qemu_nbdkit: Fix format when printing time_t values
The time_t type can be 32bit or 64bit signed integer. There are
systems where it's defined as long, or long long (32bit systems
usually). Therefore, using just 'l' length modifier is not good
enough. Also, using 'u' conversion specifier is also wrong
(though, values stored in qemuNbdkitCaps struct reflect mtime of
some files, so there won't be a negative value).

Anyway, do what we already do for virQEMUCaps - use '%lld' printf
format and typecast to long long.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-28 15:21:30 +02:00
Michal Privoznik 6dfb398620 NEWS: Document features/improvements/bug fixes I've participated in
There are some features/improvements/bug fixes I've either
contributed or reviewed/merged. Document them for upcoming
release.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-28 10:19:54 +02:00
Michal Privoznik 99276efe0c tests: Link qemuxml2argvmock with test_utils_lib
When running qemuxmlconftest under valgrind, it fails with a
symbol lookup error:

  valgrind: symbol lookup error: libvirt.git/_build/tests/libqemuxml2argvmock.so: undefined symbol: virTestMakeDummyFD

This occurs because qemuxml2argvmock uses the
virTestMakeDummyFD() function (implemented in testutils.c) but
does not explicitly link against test_utils_lib. Fix this by
linking the test utils library to the mock library, statically.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-27 15:24:22 +02:00
Michal Privoznik b0c097dde0 conf: Assert virDomainChrDeviceState and virConnectDomainEventAgentLifecycleState enums are in sync
When QEMU driver emits agent connected/disconnected events (inside of
processSerialChangedEvent()) it declares a variable of
virDomainChrDeviceState enum, and then passes this variable to
virDomainEventAgentLifecycleNewFromObj(). But we document the agent
lifecycle state to be of virConnectDomainEventAgentLifecycleState enum.

Therefore, make sure values from
virConnectDomainEventAgentLifecycleState enum are of the same value as
those in virDomainChrDeviceState enum.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-20 14:32:16 +02:00
Michal Privoznik 4817d1003b virauth: Verify virConnectAuth::cb is set in virAuthGetPasswordPath()
Simirarly to virAuthGetUsernamePath() check whether callback used
to collect credentials is actually set before calling it. This
bug is easily reproducible, for instance as:

  int credtype[] = { VIR_CRED_PASSPHRASE };
  virConnectPtr conn = virConnectOpenAuth("esx://root@example.com/",
                                          &(virConnectAuth){
                                          .credtype = credtype,
                                          .ncredtype = 1,
                                          .cb = NULL
                                          },
                                          0);

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-18 15:00:57 +02:00
Michal Privoznik b489eb8d6b virsh: Provide no auth callbacks for bash completer
Our bash completion script parses (partially incomplete) command
line and looks for two arguments: --readonly and --connect
because in the next step it executes virsh with those two
arguments like this:

  virsh --readonly --connect $URI complete -- "text to complete"

Now, whenever virsh sees connection URI specified on its cmd line
it connects to it right away (before executing any command). This
happens inside virshConnect(). Here, virConnectOpenAuth() is
called with the default auth callback (virConnectAuthPtrDefault).
In majority of the cases this is desirable, as it might ask user
for credentials (password for example). But in case of bash
completion this is not desired because bash completion script
must not expect users to input anything (that's why we even
close stdin in cmdComplete()).

Therefore, when connecting from virsh that's executed by the bash
completion script provide no auth callbacks to prevent virsh from
asking for credentials.

Resolves: https://gitlab.com/libvirt/libvirt/-/work_items/879
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Tested-by: Richrad W.M. Jones <rjones@redhat.com>
2026-05-18 09:58:55 +02:00
Michal Privoznik ebf353f3c4 virnetlibsshsession: Check later for auth callback in virNetLibsshAuthenticatePassword()
The first thing that virNetLibsshAuthenticatePassword() does is
read password from config file. For this it does not need auth
callback. If that password fails to authenticate then
corresponding callback from the auth callback is called. This is
actual place where auth callback should be checked for.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Tested-by: Richrad W.M. Jones <rjones@redhat.com>
2026-05-18 09:58:55 +02:00
Michal Privoznik 1147fb79b7 virnetsshsession: Don't check for auth callbacks in virNetSSHAuthenticatePassword()
For the VIR_NET_SSH_AUTH_PASSWORD authentication mechanism the
virNetSSHAuthenticatePassword() is called. Inside it,
virAuthGetPasswordPath() is called to obtain password. Firstly
reading from our auth.conf file is attempted and if that fails
then corresponding callback from virConnectAuthCallbackPtr is
called. But virAuthGetPasswordPath() checks whether the callback
is NULL or not. There is no need for
virNetSSHAuthenticatePassword() to check it too. Drop the
duplicate check.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Tested-by: Richrad W.M. Jones <rjones@redhat.com>
2026-05-18 09:58:55 +02:00
Michal Privoznik 77bd314656 cputest: Detect unused files
Use newly introduced testutils APIs to detect unused files.
This is pretty much straightforward, except for one small thing:
some test cases depend on QEMU (and are NOP if built without it).
Hence the condition in testCaseEnumerate().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-14 14:25:28 +02:00
Michal Privoznik d654789e46 cputestdata: Drop unused files
There are couple of files under tests/cputestdata/ that are not
used by any test case:

1) ppc64-guest-host-model.xml - unused since its introduction in
   v1.2.19-rc1~31
2) ppc64-host+guest-host-model.xml - Same
3) x86_64-bogus-vendor.xml - Introduced in v0.8.7~195 under
   slightly different name, then renamed to the current name (in
   v3.1.0-rc1~3) but never used actually.

Just drop these three files.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-14 14:25:28 +02:00
Michal Privoznik 7a3f0273b7 networkxmlconftest: Detect unused files
Use newly introduced testutils APIs to detect unused files.
This is pretty much straightforward except for one test case:
hostdev. This test case queries sysfs under the hood and thus is
expected to succeed on Linux and fail everywhere else. Though,
hostdev.expect.xml is thus used on Linux only. Therefore, do not
collect it on non-Linux platforms.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-14 14:25:28 +02:00
Michal Privoznik ca3c863a1e networkxmlconfdata: Remove passthrough-pf.conf
The passthrough-pf.conf file is not used really, because the test
case is defined as:

  DO_TEST_VALIDATE_ERROR("passthrough-pf");

meaning the test is expected to fail in XML validation phase.
Hence, no .conf file is ever generated for it. Remove the file.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-14 14:25:28 +02:00
Michal Privoznik 5e7265d97c qemuxmlconftest: Switch to virTestEnumerateTestCases()
The qemuxmlconftest detects unused files in qemuxmlconfdata/
directory. But it uses its own implementation for that. But now
that there's a generic implementation available, switch to that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-14 14:25:28 +02:00
Michal Privoznik 3d60ba0685 testutils: Introduce unused file detection
This is basically a generalized version of what we have in
qemuxmlconftest (functions testConfXMLEnumerate(),
testQemuConfMarkUsed() and testConfXMLCheck()). The idea is to
reuse the code in other tests.

There's one slight difference to the original - while
qemuxmlconftest always allocated the hash table, in this
generalized version NULL table is okay.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-05-14 14:25:28 +02:00
Michal Privoznik d19d088a3f qemu: capabilities: Bump minimum qemu to qemu-7.2
Following minimum versions are needed based on our support policy:

           Alpine Linux 3.23: 9.0
             CentOS Stream 9: 10.1
                   Debian 12: 7.2
                   Fedora 43: 10.1
          openSUSE Leap 15.6: 8.2
                Ubuntu 24.04: 8.2
               FreeBSD ports: 11.0
              macOS homebrew: 11.0
              macOS macports: 11.0

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:13 +02:00
Michal Privoznik 3fb4292016 qemucapabilitiesdata: domaincapsdata: Drop old capabilities
Soon the minimal version is going to be bumped to QEMU-7.2. Drop
older capabilities, which are unused anyways, thanks to previous
cleanups.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:13 +02:00
Michal Privoznik ba6e82c14c qemuxmlconftest: Switch sgx-epc to 11.0.0
The sgx-epc test case is currently pinned to capabilities of that
QEMU-7.0. Well, soon the minimal version of QEMU is going to be
bumped. But thanks to previous commit the capabilities of 11.0.0
version support SGX too. Switch the test case to the newer
capabilities.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:13 +02:00
Michal Privoznik 06bbb14170 qemucapabilitiesdata: Add SGX support to caps_11.0.0_x86_64
Detecting SGX support is done in two ways and both have to
succeed in order for caps to have the capability:

  1) the sgx-epc device needs to be present,
  2) the query-sgx-capabilities command needs to return data
     instead of an error.

So far, the only caps file that meets both requirements is
caps_7.0.0_x86_64. Soon the minimal version is going to be bumped
to QEMU-7.2. But caps_11.0.0_x86_64 has the device and the only
thing missing is the proper reply to the monitor command.
Therefore, create new qemu_11.0.0_x86_64+sgx capabilities with
reply to query-sgx-capabilities command copied from caps_7.0.0.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:13 +02:00
Michal Privoznik 142675a00a qemuxmlconftest: Drop ppc64-default-cpu-kvm-pseries-2.7 test cases
Both ppc64-default-cpu-kvm-pseries-2.7 and
ppc64-default-cpu-tcg-pseries-2.7 test cases rely on pseries-2.7
machine type. It was removed in QEMU-7.2. Soon the minimal
version is going to be bumped to QEMU-7.2 rendering those tests
obsolete. Drop them.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:12 +02:00
Michal Privoznik 3f922292c0 qemuxmlconftest: Drop old cpu model expansion tests
Soon the minimal version is going to be bumped to QEMU-7.2. Drop
older cpu model expansion test cases (6.2.0, 7.0.0, 7.1.0).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:12 +02:00
Michal Privoznik 642d4e7b41 qemuxmlconftest: Drop disk-network-tlsx509-nbd-hostname test for 6.2.0
Setting TLS hostname for NBD disks was introduced in QEMU-7.0.0.
Soon the minimal version is going to be bumped to QEMU-7.2. Drop
old test.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:12 +02:00
Michal Privoznik 83bbf72d60 qemuxmlconftest: Drop machine-i8042-{on/off} tests for 6.2.0
Toggling PS/2 state is available from QEMU-7.0 onwards. Soon the
minimal version is going to be bumped to QEMU-7.2. Drop old
tests.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:47:12 +02:00
Michal Privoznik 9dd28f4b7a ci: regenerate with 'lcitool manifest'
This picks up a fix of FreeBSD 15 image name.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-06 10:46:50 +02:00
Michal Privoznik 64e7822145 qemuxmlconftest: Add new cpu host model expansions tests
In qemuxmlconftest there's a section which aim on testing
'host-model' cpu mode expansion. Since this depends on what QEMU
reports (and thus can change with its version) we have a test
case for each QEMU version supported. Unfortunately, when adding
capabilities for new QEMUs this section was forgotten. Add
missing test cases (10.2.0 and 11.0.0).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-05 15:16:14 +02:00
Michal Privoznik af0debefcc ci: regenerate with 'lcitool manifest'
Notable changes:
- Drop Fedora 42, add Fedora 44
- Drop Freebsd 13, add Freebsd 15
- Drop Ubuntu 22.04, add Ubuntu 26.04

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-05-05 14:11:54 +02:00
Michal Privoznik 90d8175d13 virt-host-validate: Suggest different resolution for 'devices' and non-root user
Here's the deal: the 'devices' controller as such does not exist
in CGroupsV2. The alternative is to load eBPF program that mimics
the controller's behavior from CGroupsV1. But, only privileged
user can load such program. This means that virt-host-validate
(when ran as a regular user) claims 'devices' controller missing
(rightfully so), and suggests enabling it in Kconfig. This last
bit might be misleading to users [1].

Now, to fix this ideally, all three conditions should be checked
(CGroupsV2, 'devices' controller and regular user), but our
virCgroup module deliberately hides the version of CGroups. So
check for the other two conditions.

1: https://lists.libvirt.org/archives/list/users@lists.libvirt.org/thread/USDFFRJK74GYHRGMXOE2FSAA4PQD23RE/
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <pavel@hrdina.info>
2026-05-04 09:05:34 +02:00
Michal Privoznik 8acb8b4780 vircgroupv2: Implement freezer controller
With CGroupsV2 the freezer controller is split into two files:

1) cgroup.freeze where an integer is written to thaw(0)/freeze(1)
   processes within the cgroup, and
2) cgroup.events where the frozen status can be read.

Now, freezing/thawing a cgroup is as simple as writing
corresponding integer into cgroup.freeze. But similarly to
CGroupsV1, it may take some time to actually freeze all processes
inside the cgroup. So read both file and map combination of their
values according to this table:

              | frozen from cgroup.events
cgroup.freeze |     0      |     1
--------------+------------+-------------
            0 |   THAWED   |    N/A
            --+------------+-------------
            1 |  FREEZING  |   FROZEN

Resolves: https://gitlab.com/libvirt/libvirt/-/work_items/870
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <pavel@hrdina.info>
2026-05-04 09:05:34 +02:00
Michal Privoznik fda330bb8a vircgroupv2: Freezer controller is implicit
The freezer controller in CGroupsV2 is always present (under
cgroup.freeze file). Make our vircgroupv2 backend aware of it.

NB, because of the way our backends are ordered (v2 is prefered)
the v1 freezer is never going to be used when CGroupsV2 are
detected. Hence the change to tests.

NB2, this also fixes output of virt-host-validate which complains
that the 'freezer' controller is not present for LXC driver.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <pavel@hrdina.info>
2026-05-04 09:05:34 +02:00
Michal Privoznik 289e69d95e src: Introduce virCgroupFreezerState enum
So far, only vircgroupv1 implements freezer controller related
callbacks and both work with strings ("THAWED", "FROZEN",
"FREEZING"). This works well with v1 but with CGroupsV2 there are
just two states and they are represented by a number.

Therefore, introduce an enum and implement enum <-> string
conversion for each backend separately.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <pavel@hrdina.info>
2026-05-04 09:05:34 +02:00
Michal Privoznik 5ba6bb85b0 NEWS: Document features/improvements/bug fixes I've participated in
There are some features/improvements/bug fixes I've either
contributed or reviewed/merged. Document them for upcoming
release.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-04-29 08:41:31 +02:00
Michal Privoznik e52ca27026 virnetdevmacvlan: Drop udev busy loop from virNetDevMacVLanTapOpen()
Now that after previous commit the wait for udev to settle down
is done right after device creation, there's no need to have
additional wait in virNetDevMacVLanTapOpen(). It's effectively a
dead code. Remove it.

Tested-by: Johannes Segitz <jsegitz@suse.de>
Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2026-04-14 10:02:19 +02:00
Michal Privoznik 44bcb77ef4 virnetdevmacvlan: Wait for udev to settle after creating macvtap
When a macvtap interface is created (e.g. during domain startup
or on device hotplug) libvirt then open corresponding /dev/tapNN
in order to pass FDs to the hypervisor. These FDs are labelled
before passing, but if creating the interface and open() happen
in quick succession, i.e. when udev did not had chance to run,
then the /dev/tapNN node might have default SELinux label
(device_t) instead of correct one (tun_tap_device_t). This then
leads to AVC messages, like the following:

  type=AVC msg=audit(1774535384.365:1238): avc:  denied  { open } for  pid=6765
  comm="rpc-virtqemud" path="/dev/tap33" dev="devtmpfs" ino=805
  scontext=system_u:system_r:virtqemud_t:s0
  tcontext=system_u:object_r:device_t:s0 tclass=chr_file permissive=1

Therefore, allow udev to settle down after macvtap is created (by
calling virWaitForDevices()).

Resolves: https://gitlab.com/libvirt/libvirt/-/work_items/866
Tested-by: Johannes Segitz <jsegitz@suse.de>
Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2026-04-14 09:59:37 +02:00
Michal Privoznik e68e67ab1d hyperv: Implement virDomainGetGuestInfo()
The hyperv hypervisor also has guest agent, in fact multiple ones
[1][2]. The first one, KVP, is for storing Key-Value Pairs and in
fact it's already used by our hyperv driver when querying
domifaddr (see v12.1.0-rc1~148 for more info). Anyhow, the KVP
service is capable of more, it can provide guest OS info, guest
FQDN and others. These informations are exposed via
GuestIntrinsicExchangeItems member of the
Msvm_KvpExchangeComponent struct [3]. You may have noticed the
member is an array of strings, well those strings are in fact XML
documents. For instance:

  <INSTANCE CLASSNAME="Msvm_KvpExchangeDataItem">
    <PROPERTY NAME="Caption" TYPE="string"/>
    <PROPERTY NAME="Data" TYPE="string">
      <VALUE>6.12.61-1-lts</VALUE>
    </PROPERTY>
    <PROPERTY NAME="Description" TYPE="string"/>
    <PROPERTY NAME="ElementName" TYPE="string"/>
    <PROPERTY NAME="InstanceID" TYPE="string"/>
    <PROPERTY NAME="Name" TYPE="string">
      <VALUE>OSBuildNumber</VALUE>
    </PROPERTY>
    <PROPERTY NAME="Source" TYPE="uint16">
      <VALUE>2</VALUE>
    </PROPERTY>
  </INSTANCE>

This is a bit messy to work with, because it's not like in QEMU's
world where each type of guest info (virDomainGuestInfoTypes)
corresponds 1:1 to a guest agent command. Hence the lookupTable
in hypervGetServicesProcessOne().

NB, the original jira issue asks for exposing plain fact whether
KVP daemon is running inside the guest and this commit implements
seemingly different feature. Well, thing is, in case of QEMU
there's a domain XML part where guest agent is configured and
where we expose whether there's somebody listening inside the
guest. But in case of hyperv there's no <channel/> to be
configured as communication with KVP daemon happens through
vmbus [4]. Users are advised to call the virDomainGetGuestInfo()
API with non-zero 'types' argument and if they get an error with
VIR_ERR_AGENT_UNRESPONSIVE code then the KVP daemon is not
running.

1: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/hv/hv_kvp_daemon.c
2: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/hv/hv_vss_daemon.c
3: https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-kvpexchangecomponent
4: https://docs.kernel.org/virt/hyperv/vmbus.html
Resolves: https://redhat.atlassian.net/browse/RHEL-147661
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2026-04-07 10:06:59 +02:00
Michal Privoznik 46479568b8 security: Don't error out on seclabels of type='none'
Ever since of commit v1.2.13-rc1~66 the model attribute of a
<seclabel/> is validated against secdriver names enabled. In
nearly all cases this is something users want so that domain XML
does not claim to set seclabels of a model that's not enabled.
However, consider the following seclabel:

  <seclabel type='none' model='selinux'/>

It tells us to not bother setting selinux labels on given domain.
A mgmt app might format this into domain XML if it sees selinux
is disabled on the host. But if that's the case, selinux driver
is not loaded and this virSecurityManagerCheckModel() doesn't
find it and reports an error.

Well, the error doesn't need to be reported as we will just
ignore selinux as each driver callback checks if relabel is false
(which it is for type='none'). This is true for other secdrivers
too.

Resolves: https://redhat.atlassian.net/browse/RHEL-156689
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-04-02 09:42:30 +02:00
Michal Privoznik 21d573706a security: Rewrite virSecurityManagerCheckModel() to use g_autofree
Let's use automatic memory freeing inside of
virSecurityManagerCheckModel() as it will simplify future
commits.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-04-02 09:42:28 +02:00
Michal Privoznik 6a74d90fb9 conf: Fix seclabel type parsing wrt default value
Prior to v7.10.0-rc1~26 seclabels defaulted to
VIR_DOMAIN_SECLABEL_DYNAMIC (type='dynamic'). But after switching
the parser to virXMLPropEnum() the type is overwritten to
VIR_DOMAIN_SECLABEL_DEFAULT because the first thing that the
helper function does is to set variable that holds the result to
zero. Switch to virXMLPropEnumDefault() to restore the previous
behavior.

Fixes: f7ff8556ad
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Richard W.M. Jones <rjones@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-04-02 09:42:17 +02:00
Michal Privoznik 473b1d917c NEWS: Document features/improvements/bug fixes I've participated in
There are some features/improvements/bug fixes I've either
contributed or reviewed/merged. Document them for upcoming
release.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-03-31 14:16:01 +02:00
Michal Privoznik 0f52d35b1b virxml: Fix virXMLPropTristateBoolAllowDefault() documentation
The documentation to virXMLPropTristateBoolAllowDefault() refers
to itself while it meant to refer to virXMLPropTristateBool().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-03-26 12:43:43 +01:00
Michal Privoznik 1a528a4d29 network: Don't enable ip_forward for VIR_NETWORK_FORWARD_OPEN
For a network that's <forward mode="open"/> there are no firewall
rules added. We should not assume that users will configure NAT,
and if they do it should be their responsibility to enable IP
forwarding too.

Resolves: https://gitlab.com/libvirt/libvirt/-/work_items/863
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-18 14:32:43 +01:00
Michal Privoznik 70b3053057 qemuhotplug: Introduce interface-network-hostdev
Inspired by commit of v12.1.0-37-g25662b3700.
We already have a test case for <interface type='hostdev'/>, but
what we are missing is <interface type='network'/> where the
network is of a <forward mode='hostdev'/>. Apparently, we had a
crasher there too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-18 14:23:53 +01:00
Michal Privoznik 685f359eaf qemuhotplugtest: Use fake drivers
Hotplugging a device may require talking to other drivers (e.g.
network), similar to when starting a domain anew
(qemuxmlconftest). Register fake drivers for future benefit of
the test.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-18 14:23:47 +01:00
Michal Privoznik 605112c584 virnetworkportxml2xmldata: Use different PCI address in plug-hostdev-pci.xml
Inside of plug-hostdev-pci.xml there's a PCI address of an
allocated PCI device for an <interface type='network'/>.
Currently, there's some made up address. But this specific file
is going to be used from qemuhotplugtest soon and as such it
needs an PCI address that virpcimock creates. Switch it to
0000:06:12.2.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-18 14:23:39 +01:00
Michal Privoznik b01baffbb2 qemuxmlconftest: Separate fake drivers into a separate file
One of the tests that qemuxmlconftest does is generate cmd line
for given domain XML. This process might involve talking to other
drivers (secret/storage/nwfilter/network). To produce predictable
output the test comes with fake implementation of APIs of those
drivers. Well, move that implementation into a separate file so
that it can be reused by other tests (notably, qemuhotplugtest is
going to use it).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-18 14:23:21 +01:00
Michal Privoznik 6d6da1cbac tests: Drop WITH_QEMU from qemu specific tests binaries/libraries
Inside of tests/meson.build there is a section that builds QEMU
related tests conditionally (for instance
qemudomaincheckpointxml2xmltest). It makes no sense to have the
same check inside source file. Or even provide alternative
implementation for cases when building without QEMU
(EXIT_AM_SKIP). When building without QEMU driver the test is not
even compiled, so EXIT_AM_SKIP is dead code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-18 13:57:16 +01:00
Michal Privoznik cd6a1ba222 networkxmlconftest: s/fail/cleanup/
Inside of testCompareXMLtoXMLFiles() the 'fail' label is used in
both successful and error runs. If that's the case, our coding
standard mandates the label to be named 'cleanup'. Change it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-03-17 17:25:03 +01:00
Michal Privoznik d9b34ad12b network: Format <ip/> element using virXMLFormatElement()
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-03-17 17:24:59 +01:00
Michal Privoznik 05cdfcf568 src: Drop NULL check before calling virBufferEscapeString()
There's no need to check if any of the three arguments passed to
virBufferEscapeString() is NULL as the function does so itself.
Well, in a few places we're comparing the last argument against
NULL. Drop the comparison then.

Generated using the following spatch:

  @@
  expression X, Y, E;
  @@
  - if (E) virBufferEscapeString(X, Y, E);
  + virBufferEscapeString(X, Y, E);

  @@
  expression X, Y, E;
  @@
  - if (E) {
    virBufferEscapeString(X, Y, E);
  - }

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-03-17 17:24:49 +01:00
Michal Privoznik e25b82c5f8 tests: Create fake root dirs later
In one of previous commits the virTestMain() function was changed
to actually create fake HOME, XDG_RUNTIME_DIR, ... directories
instead of setting spoofed values in the environment. But
alongside with this, the call to virTestFakeRootDirInit() was
moved (to location where environment was poisoned). And this
would not matter if it wasn't for mocking. Because what we ended
up with is virTestFakeRootDirInit() is called and then
(optionally) the process re-execs itself (with mocks loaded).
This means that previously created root dirs are never cleaned
up and just pollute builddir.

Therefore, restore original location from which the function was
called.

Fixes: 79d97d2b4f
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2026-03-11 14:06:04 +01:00
Michal Privoznik 83621dcb33 qemuhotplugtest: Run "interface-hostdev" test cases only on Linux
In one of my previous commits, I've introduced
"interface-hostdev" attach and detach test cases to
qemuhotplugtest. And they work flawlessly, on Linux. But on
anything else they fail because our virpci.c module is basically
just a bunch of stub functions that do nothing but report an
error, rendering my changes to virpcimock futile.

BTW: this is similar to what I had done in v12.1.0-rc1~199.

Fixes: f9bb819fc4
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-03-09 16:44:12 +01:00
Michal Privoznik f9bb819fc4 qemuhotplugtest: Introduce interface-hostdev test case
While our qemuhotplugtest already does a PCI hotplug and unlpug
("hostdev-pci") there is another way to hotplug a PCI device,
esp. if it's a NIC: <interface type='hostdev'/>. This has been
missing and as shown in v12.1.0-rc1-4-gfe782ed334 can be
potentially dangerous as some different paths are taken.
Introduce a test case for interface-hostdev.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-09 13:13:47 +01:00
Michal Privoznik 662b1f4eb3 virnetdevmock: Mock virNetDevSaveNetConfig() and virNetDevSetNetConfig()
We really don't want our test suite talking to kernel and setting
various attributes on NICs.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-09 13:13:47 +01:00
Michal Privoznik e9798b8397 virpcimock: Create net/ subdir for devices
A PCI device that is a network interface card also has 'net/'
subdir with interface name it corresponds to. For instance:

  # ls -l /sys/bus/pci/devices/0000\:00\:1f.6/net/
  total 0
  drwxr-xr-x 5 root root 0 Feb 26 16:51 eth0

Allow setting interface name for PCI devices.
Now, in real life the net/$IFNAME/ is a directory, but since our
code opens net/ dir and then just reads dentries creating file
instead of full blown dir is okay.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-09 13:13:47 +01:00
Michal Privoznik 542230251b virpcimock: Create sriov_totalvfs file and virtfnN symlinks
In case of an SRIOV device the sysfs struct looks like this:

-r--r--r--. 1 root root 4096 Feb 26 14:40 /sys/bus/pci/devices/0000:82:00.0/sriov_totalvfs
lrwxrwxrwx. 1 root root    0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0/virtfn0 -> ../0000:82:10.0
lrwxrwxrwx. 1 root root    0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0/virtfn1 -> ../0000:82:10.4
lrwxrwxrwx. 1 root root    0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0/virtfn2 -> ../0000:82:11.0
lrwxrwxrwx. 1 root root    0 Feb 25 22:51 /sys/bus/pci/devices/0000:82:00.0/virtfn3 -> ../0000:82:11.4

Of course, there is much more, I've just picked up files that our
code touches during hotplug of an <interface type='hostdev'/>.

The first file 'sriov_totalvfs' contains the maximum number of
VFs supported. Then, for each VF created there's 'virtfnN'
symlink to individual VFs.

Teach our virpcimock to create the file and symlinks.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-03-09 13:13:47 +01:00
Michal Privoznik b0e57a2b35 NEWS: Document features/improvements/bug fixes I've participated in
There are some features/improvements/bug fixes I've either
contributed or reviewed/merged. Document them for upcoming
release.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-02-27 15:49:48 +01:00
Michal Privoznik e9b931d3e4 virpci: Report an error if virPCIGetVirtualFunctionIndex() fails
Either an error should be returned in all error paths in a
function or in none (leaving it up to caller). Well,
virPCIGetVirtualFunctionIndex() breaks this pattern. Fix it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2026-02-20 10:57:44 +01:00
Michal Privoznik 6c2c9e21ac virstorageobj: Make virStoragePoolObjAddVol() report an error on failure
Adding a storage volume into a pool is done by calling
virStoragePoolObjAddVol(). This function may fail if another
volume already exists with the same key/name/target. In some
cases the storage driver does check for duplicates before calling
the function. But in some cases (e.g. when refreshing an RBD pool
in virStorageBackendRBDRefreshPool()) it doesn't.

The problem here is that the function reports no error upon
failure and leaves it as an exercise for caller. Well, no caller
does that.

Therefore, make the function report an error. The advantage of
this approach is - the function can report more accurate error
message than any caller ever could.

NB¸ this stems from a discussion on the users list [1], and while
this does NOT solve the original issue, it fixes one of the
symptoms.

1: https://lists.libvirt.org/archives/list/users@lists.libvirt.org/message/BALVNCRQM4KBKGV4RQ7BMKSX7UIJKLQH/
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2026-02-19 12:31:02 +01:00
Michal Privoznik 11057abfd1 qemu: Wire up new hyperv host-model mode behavior
Since some hyperv features might be already enabled/disabled when
entering qemuProcessEnableDomainFeatures() only those which are
not set in domain XML (i.e. are VIR_TRISTATE_SWITCH_ABSENT)
should be modified. Furthermore, some features are not a simple
on/off switch, but a number or a string even. Well, that doesn't
matter really as the logic for setting them is the same: only set
their value iff they are not already set.

Resolves: https://issues.redhat.com/browse/RHEL-148219
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-13 13:32:45 +01:00
Michal Privoznik 380fb89390 conf: Parse hyperv features even for host-model
As it turns out, some users of the hyperv "host-model" mode might
want to override the hypervisor defaults. For instance disable a
feature that's on by default, or vice versa. Currently, this is
not possible because as soon as our XML parser sees the
"host-model" mode it exits early and skips parsing of individual
features (for "custom" mode). Well, do not return early and parse
the rest.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-13 09:08:45 +01:00
Michal Privoznik aa802b8723 hyperv: Implement virDomainInterfaceAddresses()
The virDomainInterfaceAddresses() API accepts @source argument,
but since this is hyperv, we can't really use _SRC_LEASE (we
didn't spawn any dnsmasq there), not _SRC_ARP. The only source
that's more or less usable is _SRC_AGENT. Okay, there's no QEMU
guest agent running, but hyperv has its own guest agent. In my
testing (with Linux guest) I had to install 'hyperv' package and
then enable 'hv_kvp_daemon.service'. After that,
Msvm_GuestNetworkAdapterConfiguration struct [1] contained guest
IP addresses.

There's one caveat though: the interface name
(virDomainInterface::name). We don't fetch that one even for
hypervDomainGetXMLDesc() case. And there's no <target dev=''/>
either nor device alias (v12.0.0-43-g4009126f17). So just put
InstanceID there for now, which is this long path, with some
UUIDs, e.g.:

   Microsoft:5C58E5F2-946E-490F-B81D-6E2A7328640D\C85554E0-2B3B-487C-A557-D230BFF5F9E6\

But hey, at least it's unique.

1: https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/msvm-guestnetworkadapterconfiguration
Resolves: https://issues.redhat.com/browse/RHEL-145306
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-12 15:55:30 +01:00
Michal Privoznik a422ebb178 hyperv: Move MAC parsing into a separate function
When constructing a domain definition, NICs are fetched from WMI
and their MAC addresses are then parsed. Move this code into a
separate function so that it can be reused later.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-12 15:55:30 +01:00
Michal Privoznik 7fdc9111d2 virsocketaddr: Introduce virSocketAddrSubnetToPrefix()
The aim of this helper is to convert subnet mask to prefix. For
instance for input "255.0.0.0" to return 8. Additionally, if the
input string is already a prefix (with optional leading slash
character) just return that number parsed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-12 15:55:30 +01:00
Michal Privoznik fb317b296d datatypes: Declare autofree func for virDomainInterface type
The virDomainInterface type (struct _virDomainInterface) is
defined in our public header and even has a public free function
(virDomainInterfaceFree()). But in our code we will want to use
automatic memory freeing for it. Hence, make appropriate
declaration in datatypes.h.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-12 15:55:29 +01:00
Michal Privoznik afe6e5d260 virsh: Switch cmdDomIfAddr() to vshTable
The aim of cmdDomIfAddr() is to obtain IP addresses for given
domain and then print (ifName, MAC, type, IP Address) tuple.
Preferably in an aligned table. This is hard to do with printf
style of spacing ("%-NNs") since the interface name (ifName) can
vary a lot in length. Fortunately, we have vshTable which is
designed to handle this case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-02-09 10:52:59 +01:00
Michal Privoznik 9373d8da6a qemu_command: Generate granule prop for virtio-iommu
Resolves: https://issues.redhat.com/browse/RHEL-76269
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:43 +01:00
Michal Privoznik 2eea8e3829 qemu_validate: Check whether granule of virtio-iommu is supported
Just like with other features, check whether QEMU supports them
based on capabilities. Now, instead of inventing a new QEMU
capability, an existing one can be used:
QEMU_CAPS_VIRTIO_IOMMU_AW_BITS.

This is because the aw-bits and granule attributes were
introduced into QEMU in close succession (v9.0.0-rc0~9^2~7
v9.0.0-rc0~9^2~11), neither can be disabled at compile time and
backporting just one without the other makes almost no sense.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:42 +01:00
Michal Privoznik 43892d9915 conf: Introduce granule attribute for virtio-iommu
In PCI assignment scenario the virtio-iommu needs to know the
guest page size also known as granule. Expose it as an attribute
to the <driver/> element of a virtio-iommu.

This is possibly interesting only for aarch64 since it supports
virtio-iommu and also supports running guests with different page
size than the host.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:37 +01:00
Michal Privoznik 17693931e6 qemu_command: Generate aw_bits prop for virtio-iommu
Resolves: https://issues.redhat.com/browse/RHEL-76269
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:35 +01:00
Michal Privoznik 2fccdda851 conf: Allow aw_bits for virtio-iommu
Introduced in QEMU commit of v9.0.0-rc0~9^2~7 the virtio-iommu
device is also capable of using different addres width. The
corresponding attribute is also called 'aw-bits', just like in
case of intel-iommu. Wire up the missing pieces.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:34 +01:00
Michal Privoznik befdd44bf8 qemu_capabilities: Introduce QEMU_CAPS_VIRTIO_IOMMU_AW_BITS
This capability tracks whether the virtio-iommu device has
aw-bits attribute.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:33 +01:00
Michal Privoznik e1c6e3fef0 conf: Teach virDomainParseMemory() new retval
So far, virDomainParseMemory() returns either 0 or -1. While this
allows callers to distinguish a success case from an error it
doesn't allow them to differentiate the case when no value was
provided in the XML, thus nothing was parsed and nothing was
required. Therefore, make virDomainParseMemory() return 1 on
success, 0 in case nothing was parsed and nothing was required,
and -1 on failure.

Arguably, no caller needs this distinction currently, but that is
about to change.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2026-02-06 16:13:27 +01:00
Michal Privoznik b4c792313a hyperv: Avoid memleak in hypervDomainDefParsePhysicalDisk
When parsing a physical disk, the @hostResouce is escaped once
with the retval being stored into @hostEscaped. Then, it's
escaped again, but the retval is stored into the very same
variable, leading to a leak where intermediate value is lost.

256 bytes in 1 blocks are definitely lost in loss record 469 of 483
   at 0x49543A0: realloc (vg_replace_malloc.c:1804)
   by 0x516C251: g_realloc (in /usr/lib64/libglib-2.0.so.0.8400.4)
   by 0x518BB7E: g_string_expand (in /usr/lib64/libglib-2.0.so.0.8400.4)
   by 0x518BFF9: g_string_insert_len (in /usr/lib64/libglib-2.0.so.0.8400.4)
   by 0x4A58B5F: g_string_append_len_inline (gstring.h:247)
   by 0x4A58B5F: virBufferAdd (virbuffer.c:164)
   by 0x4AFDA71: virStringReplace (virstring.c:708)
   by 0x4DA4381: hypervDomainDefParsePhysicalDisk (hyperv_driver.c:1375)
   by 0x4DA4A18: hypervDomainDefParseStorage (hyperv_driver.c:1487)
   by 0x4DA9E31: hypervDomainGetXMLDesc (hyperv_driver.c:2761)
   by 0x4DFB3E5: virDomainGetXMLDesc (libvirt-domain.c:2898)
   by 0x406D39B: cmdDumpXML (virsh-domain.c:10787)
   by 0x40B13B1: vshCommandRun (vsh.c:1383)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-02-06 15:40:59 +01:00
Michal Privoznik 29aa558642 bhyvexml2xmltest: Avoid leaking driver caps
Driver capabilities are allocated at the beginning of mymain(),
but roughly in the middle the architecture is switched to aarch64
and capabilities are constructed again. Without freeing the old
ones.

704 (288 direct, 416 indirect) bytes in 1 blocks are definitely lost in loss record 328 of 332
   at 0x4885098: calloc (vg_replace_malloc.c:1682)
   by 0x4EE35CA: g_malloc0 (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x53314B8: g_type_create_instance (in /usr/local/lib/libgobject-2.0.so.0.8400.4)
   by 0x531A263: ??? (in /usr/local/lib/libgobject-2.0.so.0.8400.4)
   by 0x531975E: g_object_new (in /usr/local/lib/libgobject-2.0.so.0.8400.4)
   by 0x4AA9AB6: virObjectNew (virobject.c:252)
   by 0x4AF0BBA: virCapabilitiesNew (capabilities.c:87)
   by 0x401797B: virBhyveCapsBuild (bhyve_capabilities.c:51)
   by 0x4012F57: mymain (bhyvexml2xmltest.c:60)
   by 0x4016872: virTestMain (testutils.c:913)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik 720f71c1da bhyvexml2argvtest: Avoid leaking firmwareDir
The firmwareDir member of driver config is set at the beginning
of mymain(). But then, roughly in the middle of test cases it is
overwritten to fakefirmwareemptydir. But this means the old value
must be freed. Or reassigned back to its original variable which
is freed automatically.

16 bytes in 1 blocks are definitely lost in loss record 190 of 505
   at 0x4883224: malloc (vg_replace_malloc.c:451)
   by 0x4EE6562: g_malloc (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4F0100F: g_strdup (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4013E26: g_strdup_inline (gstrfuncs.h:321)
   by 0x4013E26: mymain (bhyvexml2argvtest.c:151)
   by 0x40189A2: virTestMain (testutils.c:913)
   by 0x4013DE6: main (bhyvexml2argvtest.c:354)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik 210cae66e0 bhyvexml2argvtest: Don't leak parts of driver config
At the beginning of mymain() the virBhyveDriverConfigNew() is
called which inits driver config with some paths. These are
then overwritten to produce stable test output. Well, the old
ones should be freed first.

128 bytes in 1 blocks are definitely lost in loss record 453 of 508
   at 0x4883224: malloc (vg_replace_malloc.c:451)
   by 0x506BD16: vasprintf_l (in /lib/libc.so.7)
   by 0x4F39073: g_vasprintf (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4F01288: g_strdup_printf (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x401F75B: virBhyveDriverConfigNew (bhyve_conf.c:62)
   by 0x4013FAA: mymain (bhyvexml2argvtest.c:164)
   by 0x4018892: virTestMain (testutils.c:913)
   by 0x4013DC6: main (bhyvexml2argvtest.c:352)

25 bytes in 1 blocks are definitely lost in loss record 206 of 508
   at 0x4883224: malloc (vg_replace_malloc.c:451)
   by 0x4EE6562: g_malloc (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4F0100F: g_strdup (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x401F715: g_strdup_inline (gstrfuncs.h:321)
   by 0x401F715: virBhyveDriverConfigNew (bhyve_conf.c:60)
   by 0x4013FAA: mymain (bhyvexml2argvtest.c:164)
   by 0x4018892: virTestMain (testutils.c:913)
   by 0x4013DC6: main (bhyvexml2argvtest.c:352)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik f0af542077 bhyvexml2argvtest: Avoid leaking driver caps
Driver capabilities are allocated at the beginning of mymain(),
but roughly in the middle the architecture is switched to aarch64
and capabilities are constructed again. Without freeing the old
ones.

1,583 (288 direct, 1,295 indirect) bytes in 1 blocks are definitely lost in loss record 520 of 536
   at 0x4888098: calloc (vg_replace_malloc.c:1682)
   by 0x4EE65CA: g_malloc0 (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x53344B8: g_type_create_instance (in /usr/local/lib/libgobject-2.0.so.0.8400.4)
   by 0x531D263: ??? (in /usr/local/lib/libgobject-2.0.so.0.8400.4)
   by 0x531C75E: g_object_new (in /usr/local/lib/libgobject-2.0.so.0.8400.4)
   by 0x4AAC806: virObjectNew (virobject.c:252)
   by 0x4AF366A: virCapabilitiesNew (capabilities.c:87)
   by 0x401998B: virBhyveCapsBuild (bhyve_capabilities.c:51)
   by 0x4013E93: mymain (bhyvexml2argvtest.c:155)
   by 0x4018882: virTestMain (testutils.c:913)
   by 0x4013DC6: main (bhyvexml2argvtest.c:351)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik fcc5910557 bhyvexml2argvmock: Provide virCPUProbeHost()
The bhyvexml2argvmock is loaded by bhyvexml2argvtest which calls
virBhyveCapsBuild() which in turn calls virCPUProbeHost(). To
make our test environment stable, it shouldn't depend on actual
CPU and thus mocked implementation for virCPUProbeHost should be
offered. Surprisingly, this is done in bhyveargv2xmlmock but not
in bhyvexml2argvmock. Until now.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik 2f1421d83b bhyve_command: Avoid memleak in bhyveBuildNetArgStr()
Inside of bhyveBuildNetArgStr() there is @nic_model which is
allocated, appended into cmd line and then freed under cleanup
label. Firstly, There are few cases where instead of jumping onto
the label there's a return statement (this alone can lead to a
memory leak), but more importantly - the variable doesn't need
dynamically allocated string. It's the same story with @brname.
After making them both const strings, the return statements can
be used more freely (up until first possible allocation).

6 bytes in 1 blocks are definitely lost in loss record 4 of 508
   at 0x4883224: malloc (vg_replace_malloc.c:451)
   by 0x4EE6562: g_malloc (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4F0100F: g_strdup (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x401BC02: g_strdup_inline (gstrfuncs.h:321)
   by 0x401BC02: bhyveBuildNetArgStr (bhyve_command.c:64)
   by 0x401B362: virBhyveProcessBuildBhyveCmd (bhyve_command.c:1033)
   by 0x4015F15: testCompareXMLToArgvFiles (bhyvexml2argvtest.c:72)
   by 0x4015BB9: testCompareXMLToArgvHelper (bhyvexml2argvtest.c:144)
   by 0x4016598: virTestRun (testutils.c:143)
   by 0x4015121: mymain (bhyvexml2argvtest.c:275)
   by 0x4018892: virTestMain (testutils.c:913)
   by 0x4013DC6: main (bhyvexml2argvtest.c:352)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik df2cb810a3 bhyve_command: Avoid leaking @buf in virBhyveProcessBuildBhyveCmd()
When building OS loader part of bhyve command line, there's @buf
declared and it is even correctly annotated with g_auto() to be
freed automatically. But then, the buffer contents is appended
onto the command line using virBufferContentAndReset() which
leads to a memleak because the buffer is reset. It's
virBufferCurrentContent() that should have been used instead.

128 bytes in 1 blocks are definitely lost in loss record 476 of 536
   at 0x48882B1: realloc (vg_replace_malloc.c:1810)
   by 0x4EE6622: g_realloc (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4F048BC: g_string_new (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4A59E1E: virBufferInitialize (virbuffer.c:121)
   by 0x4A5A63C: virBufferVasprintf (virbuffer.c:321)
   by 0x4A5A5DE: virBufferAsprintf (virbuffer.c:303)
   by 0x401B22F: virBhyveProcessBuildBhyveCmd (bhyve_command.c:1021)
   by 0x4015F05: testCompareXMLToArgvFiles (bhyvexml2argvtest.c:72)
   by 0x4015BA9: testCompareXMLToArgvHelper (bhyvexml2argvtest.c:144)
   by 0x4016588: virTestRun (testutils.c:143)
   by 0x4015919: mymain (bhyvexml2argvtest.c:341)
   by 0x4018882: virTestMain (testutils.c:913)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik 1ce8c35c29 bhyve: Avoid leaking @addrs in bhyveDomainAssignPCIAddresses()
Inside of bhyveDomainAssignPCIAddresses() the @addr variable is
allocated and in a few cases stolen into domain private data. But
in all other cases the associated memory is never freed.

12,800 (3,200 direct, 9,600 indirect) bytes in 100 blocks are definitely lost in loss record 533 of 538
   at 0x4888098: calloc (vg_replace_malloc.c:1682)
   by 0x4EE67D9: g_malloc0_n (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4AFD4AC: virDomainPCIAddressSetAlloc (domain_addr.c:1011)
   by 0x4020F68: bhyveDomainPCIAddressSetCreate (bhyve_device.c:65)
   by 0x40210BD: bhyveDomainAssignPCIAddresses (bhyve_device.c:219)
   by 0x402180C: bhyveDomainAssignAddresses (bhyve_device.c:241)
   by 0x4020083: bhyveDomainDefAssignAddresses (bhyve_domain.c:230)
   by 0x4B71820: virDomainDefPostParse (domain_postparse.c:1503)
   by 0x4B28282: virDomainDefParseNode (domain_conf.c:20565)
   by 0x4B2810B: virDomainDefParse (domain_conf.c:20502)
   by 0x4B281DF: virDomainDefParseFile (domain_conf.c:20549)
   by 0x4015D6B: testCompareXMLToArgvFiles (bhyvexml2argvtest.c:47)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik 1779a8600f bhyve: Avoid memleak in bhyveParsePassthru()
The aim of bhyveParsePassthru() is to parse PCI address from
bhyve command line. The PCI address might be of a form
bus:slot:function or bus/slot/function. If the former isn't found
the latter is parsed (both using g_strsplit()). But after the
first call, g_strsplit() just returns a string list containing
but the whole input duplicated. Therefore, calling plain g_free()
is not enough, the array must be freed too.

6 bytes in 1 blocks are definitely lost in loss record 1 of 325
   at 0x4863224: malloc (vg_replace_malloc.c:451)
   by 0x4EC6562: g_malloc (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4EE28D9: g_strsplit (in /usr/local/lib/libglib-2.0.so.0.8400.4)
   by 0x4011297: bhyveParsePassthru (bhyve_parse_command.c:699)
   by 0x4010082: bhyveParseBhyvePCIArg (bhyve_parse_command.c:800)
   by 0x400EE14: bhyveParseBhyveCommandLine (bhyve_parse_command.c:862)
   by 0x400DF9C: bhyveParseCommandLineString (bhyve_parse_command.c:1058)
   by 0x4008CA0: testCompareXMLToArgvFiles (bhyveargv2xmltest.c:39)
   by 0x4008B29: testCompareXMLToArgvHelper (bhyveargv2xmltest.c:105)
   by 0x4009288: virTestRun (testutils.c:143)
   by 0x40085AC: mymain (bhyveargv2xmltest.c:164)
   by 0x400B582: virTestMain (testutils.c:913)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2026-02-04 08:29:38 +01:00
Michal Privoznik 864a70114f rpcgen: Pass XDRPROC_T_3ARGS to test_demo.c
In previous commit of v12.0.0-85-g2c66b6d72c we've tried to solve
a problem where xdrproc_t is a prototype of a function which
takes only two arguments instead of three. See original commit
for more info. The fix consists of a config time check and
setting XDRPROC_T_3ARGS accordingly (in meson-config.h). This
works for nearly all of our code, except rpcgen which is
intentionally independent of the rest of the code. Therefore, the
macro has to be set extra - by specifying it on the compiler cmd
line.

Fixes: 2c66b6d72c
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2026-02-03 12:38:57 +01:00
Michal Privoznik ca98f39e64 networkxmlconftest: Expect success for "hostdev" case only on Linux
Our network has multiple means of forwarding the traffic and
'hostdev' is one of them. This mode means that the network is
configured to use a set of PCI devices which are then assigned to
individual domains to use (PCI device assignment). Now, as of
v12.0.0-61-gecb2e06bdf our test runners
(testCompareXMLToXMLFiles() and testCompareXMLToConfFiles()) call
networkValidateTests(). For aforementioned type of network this
means checking that the specified set of devices contains only
VFs (see v3.2.0-rc1~24 for more info). It is true that our
virpcimock is preloaded which mimics VFs, but our utils module
(virpci.c specifically) talks to sysfs to check various PCI
device attributes, including whether it's a VF.

This obviously works on Linux and doesn't work anywhere else.
Therefore, until our utils module is taught how to check PCI
attribs on other systems, make the "hostdev" test case expect
validation failure on non-Linux systems.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2026-01-30 15:23:52 +01:00
Michal Privoznik e7c6f06747 ci: regenerate with 'lcitool manifest'
Update Alpine to 3.23.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2026-01-29 15:11:00 +01:00
Michal Privoznik 240deda72c tests: Rename networkxml2xmltest to networkxmlconftest
Now that networkxml2xmltest does both XML -> XML and XML -> conf
tests its name became misleading. Rename it to networkxmlconftest
and move its data into networkxmlconfdata/ dir.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:23 +01:00
Michal Privoznik 8f5e0903d6 tests: Drop networkxml2conftest
Now that networkxml2xmltest does XML->conf tests the
networkxml2conftest is redundant. Drop it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:20 +01:00
Michal Privoznik c26c7b1cd3 networkxml2xmltest: Do conf test
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:16 +01:00
Michal Privoznik ee8381e729 networkxml2xmltest: Sync test cases with networkxml2conftest
The networkxml2xmltest does basic parse -> format tests.
The networkxml2conftest does parse -> conf tests.

Now, majority of XMLs are the same. That is, output XMLs of
networkxml2xmltest and input XMls of networkxml2conftest. There
are only a few differences. This is actually great, because it
will allow either tests to do both test cases.

There are some (subtle) differences in individual test cases
though:

1) some test cases exist only in networkxml2conftest and not
   networkxml2xmltest, or
2) some test cases in networkxml2conftest have more values, i.e.
   extra elements, extra attributes. or
3) some test cases in networkxml2conftest have less values.

For cases from 1) they were just copied over. For cases from 2)
those extra elements/attributes were added, and for cases from 3)
those extra attributes were removed (to minimize changes to .conf
files in near future).

One caveat though: networkxml2xmlupdatetest uses input XMLs of
networkxml2xmltest too (hence changes under
networkxml2xmlupdateout/ dir). This means that the
"delete-srv-record-protocol" test started failing, because the
input network XML now has more <srv/> records than the test case
anticipated. But this is easy to fix - hence seemingly unrelated
change under networkxml2xmlupdatein/ dir.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:12 +01:00
Michal Privoznik 369020180a networkxml2xmltest: Store parsed def for future tests
Soon, the testRun() will run more than one test case. The input
network XML, however, stays the same. Instead of parsing it and
throwing away immediately, store it temporarily.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:09 +01:00
Michal Privoznik 2d6a376ec0 networkxml2xmltest: Dynamically allocate testInfo struct
So far, the testInfo struct contained immutable data (from its
lifetime point of view). But that is about to change. For
instance, it will hold parsed network definition (virNetworkDef)
and in order to avoid leaking dynamically allocated data
corresponding free function must be introduced (or clear
function, doesn't really matter). At this point, the structure
might as well be dynamically allocated entirely.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:07 +01:00
Michal Privoznik 5b2ed0d137 networkxml2xmltest: Move path generation into testRun()
This effectively dissolves testCompareXMLToXMLHelper() into
testRun(). Motivation is that parts of data generated inside of
testCompareXMLToXMLHelper() is going to be reused from the caller
(testRun()).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:04 +01:00
Michal Privoznik c24157056f networkxml2xmltest: Introduce testRun()
This is a beginning of something bigger. The idea is that one
DO_TEST_FULL() macro (and its friends) will run multiple test
cases (just like qemuxmlconftest does). But in order to do that
in a readable fashion, the macro should merely just expand to a
function call. The function will then call virTestRunLog(),
multiple times possibly.

This is the first step in that direction.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:39:02 +01:00
Michal Privoznik 04034eeb34 networkxml2xmltest: Don't recreate xmlopt object
The aim of virNetworkXMLOption object is to provide some
immutable data to XML parser (e.g. various callbacks). Since the
object is immutable, it can be created once and then reused by
all test cases.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:59 +01:00
Michal Privoznik eff3431dca networkxml2conftest: Allow regenerating more in one run
Currently, there are two calls to virTestCompareToFile() inside
of testCompareXMLToConfFiles(). If the first one fails the
control jumps directly onto the fail label and skips the second
one. This means that When regenerating test case output
(VIR_TEST_REGENERATE_OUTPUT) the test binary has to be called
twice to regenerate all the files. Suboptimal. Try harder to call
both compare helpers.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:57 +01:00
Michal Privoznik 30baa49454 networkxml2conftest: Allow regenerating hosts file
Inside of testCompareXMLToConfFiles() the
networkDnsmasqConfContents() is called. This may also produce
contents of corresponding hosts file. This is then compared to
expected contents stored on disk as ${testname}.hostsfile. But
due to additional checks virTestCompareToFile() might not even be
called. Problem with that is when there's actual content but the
file doesn't exist the compare helper is not called and thus
VIR_TEST_REGENERATE_OUTPUT trick doesn't work. Let's call the
helper more often as it is perfectly capable of handling this
edge case. What it is not capable of handling is when the file
shouldn't exist at all. So handling of that case is kept.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:55 +01:00
Michal Privoznik 319bbb5c84 networkxml2conftest: Avoid potential leak
Inside of testCompareXMLToConfFiles() the network definition is
parsed and if that succeeds a virNetworkObj is created by calling
virNetworkObjNew(). But if the latter fails, the control jumps
onto the fail label where only the object is freed but not
already parsed definition leading to a leak.

Swapping these two steps ensures that if either of them fails no
memleak occurs.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:49 +01:00
Michal Privoznik ecb2e06bdf test: wire up networkValidateTests()
Our network driver calls networkValidate() right after a network
XML is parsed. This is similar to domain validation step when
parsing domain XML. But it's not that convoluted in network
driver. Regardless, any network related test should mimic real
life scenario as close as possible and thus
networkValidateTests() should be called right after domain XML is
parsed.

Now, networkValidate() might query sysfs wrt to PCI devices and
thus tests must start using virpcimock. The function will also
generate random MAC addresses, if needed, hence virrandommock.

With this change, passthrough-pf and passthrough-address-crash
test cases of networkxml2xmltest started failing but looking at
corresponding XMLs those test cases were designed to test just
XML parsing. They were never designed to showcase a "real"
network XML. So mark them as expected fail.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:45 +01:00
Michal Privoznik 4b98a649b3 network: Introduce networkValidateTests()
The aim of this internal API is to wrap networkValidate() and it
is meant to be called from our tests.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:42 +01:00
Michal Privoznik 7c9b883eb3 networkxml2xmltest: Update couple of test cases
Soon, individual test cases of networkxml2xmltest will be subject
to networkValidate() call. This means, that input XMLs must be
valid (or marked as expected fail). Anyway, there are couple of
offenders:

1) 8021Qbh-net.xml setting vlan for <forward mode='private'/> is
   unsupported,
2) hostdev.xml networkValidate() will check if hostdevs specified
   for <forward mode='hostdev'/> are VFs. Use PCI addresses from
   virpcimock.
3) openvswitch-net.xml for <forward mode='bridge'/> only
   openvswitch type of virtualports is allowed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:39 +01:00
Michal Privoznik d07d7a6842 networkxml2conftest: Fail tests where no dnsmasq would be spawned
If network config does not require dnsmasq then none is spawned.
Having a test case that would still require generating dnsmasq
config is weird and can lead to spurious results. Just fail such
test case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2026-01-29 13:38:37 +01:00