Commit Graph

47664 Commits

Author SHA1 Message Date
Peter Krempa
c9cfc3876e virDomainDeviceDefParse: Separate code for parsing type
Move the code into a new function named virDomainDeviceDefParseType. The
separation will make it easier to change the type of the 'type' field in
side of virDomainDeviceDef.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-06 13:34:28 +01:00
Peter Krempa
6198c44338 qemuDomainGetStatsVcpu: Refactor cleanup
Automatically free 'cpuinfo' and remove the cleanup label and ret
variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-06 13:34:06 +01:00
Peter Krempa
66f0dd63b4 qemu: agent: Use virJSONValueObjectGetArray
Replace virJSONValueObjectGet + virJSONValueIsArray by the single API
which returns only an array.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-06 13:34:06 +01:00
Peter Krempa
1d05a04821 qemu_monitor_json: Replace simplify fetching Array from JSON object
Replace instances of virJSONValueObjectGet + virJSONValueIsArray by
virJSONValueObjectGetArray.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-06 13:34:06 +01:00
Peter Krempa
d7c1be7975 qemuMonitorJSONQueryStats: Simplify logic to construct 'provider_list'
Simplify construction of a single provider by using
virJSONValueObjectAdd and restructuring the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-06 13:34:06 +01:00
Peter Krempa
72e3100e82 virbitmap: Allow NULL bitmap in functions returning index of a set/clear bit
virBitmapNextSetBit/virBitmapLastSetBit/virBitmapNextClearBit can be
used for iteration of a bitmap. Allow NULL bitmap so that iteration of a
bitmap can be simplified in certain cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-06 13:34:06 +01:00
Peter Krempa
d9e4075d4e conf: Store 'origstates' of PCI hostdevs in a bitmap
Refactor the code to use a bitmap with an enum.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Peter Krempa
e506b0ad37 qemustatusxml2xmltest: Add test data for testing '<origstates>' of PCI hostdev
The <origstates> XML element captures private data of a PCI device
needed to restore it after a VM is started. Unfortunately at the point
when it was added we didn't yet have the existing private data
infrastructure.

Since the element is parsed only in cases similar to the status XML we
need to test it there.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Peter Krempa
f836947a91 virBitmapIsBitSet: Allow NULL bitmap
The virBitmapIsBitSet API is a permissive one which returns false when
the bit is not set or is out of range. We can do the same if the bitmap
is NULL to aid certain situations when this can happen, but we don't
want to add extra checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Peter Krempa
9598c3c684 virNetworkDHCPHostDefParseXML: Use virXMLNodeGetSubelement to find 'lease'
This also prevents a potential memleak when multiple elements would be
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Peter Krempa
7bd0e8674c virNetworkDHCPRangeDefParseXML: Use virXMLNodeGetSubelement to find 'lease'
This also prevents a potential memleak when multiple elements would be
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Peter Krempa
4088b5afa3 virNetDevVPortProfileParse: Use virXMLNodeGetSubelement to find '<parameters>'
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Peter Krempa
76f7378193 virPCIDeviceAddressParseXML: Use virXMLNodeGetSubelement to find 'zpci'
Use the helper designed to find the subelement. A slight semantic
difference after this patch is that the first <zpci> element will be
considered instead of the last, but only one is expected in a valid XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-06 09:14:00 +01:00
Jim Fehlig
0f350a4d07 tools: Fix detection of remote libvirt access in virt-qemu-sev-validate
The VM's firmware path is not extracted from the XML when invoking
virt-qemu-sev-validate in insecure mode and connecting to the local libvirt

virt-qemu-sev-validate --insecure --tk tek-tik.bin --domain test-sev-es
ERROR: Cannot access firmware path remotely

The test for remote access compares the return value from socket.gethostname()
to the return value from conn.getHostname(). The former doesn't always return
the fqdn, whereas the latter does. Use socket.getfqdn() instead.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2023-02-03 11:28:56 -07:00
Jim Fehlig
8eb54255ec docs: Fix examples in virt-qemu-sev-validate man page
Some of the examples refer to virt-dom-sev-validate. Replace them with
the proper name.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2023-02-03 11:28:27 -07:00
Martin Kletzander
f2d379e7cb .gitignore: Ignore cscope and other *tags files
Commit f7114e61db cleaned up way too much and now that I have cscope
working again I noticed there are some files that ought to stay ignored.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-02 16:59:15 +01:00
Ján Tomko
9e79904b1a tools: use g_autofree more
Remove some obvious uses of VIR_FREE in favor of automatic cleanup.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2023-02-02 16:18:08 +01:00
Peter Krempa
4ad60f9b29 schema: storage: Allow interleaving of 'cipher' and 'ivgen' elements
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 18:01:53 +01:00
Peter Krempa
615c1c21b6 schema: nodedev: Allow interleaving sub-elements of 'css' address type
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 18:01:53 +01:00
Peter Krempa
04bda51cb2 schema: nodedev: Allow interleaving of sub-elements of 'device'
Note that the schema doesn't allow us to represent the two branches of
optional <devnode type='dev'> and zero or more <devnode type='link'>
definitions, so I've merged them under the <zeroOrMore> case.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 18:01:53 +01:00
Peter Krempa
85108bad37 schema: domain: Allow interleaving of 'inituser/initgroup' in 'osexe' definition
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 18:01:53 +01:00
Peter Krempa
e4e189bb2f schema: domain: Allow interleaving of elements in 'osxen' definition
The 'osxen' RNG type defines options for the <os> element in certain
modes. Allow interleaving of subelements recursively.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 18:01:53 +01:00
Peter Krempa
9132cc635b schema: domain: Allow interleave of 'smartcard' subelements
Allow interleave of the top level sub-elements as well as the
subelements in the 'host-certificates' mode. Note that '<interleave>'
doesn't work properly if there's multiple definitions of the same
sub-element in the interleave so for this patch I chose to '<group>' the
'certificate' subelements. Another options would require us to stop
enforcing that there's exactly 3 of them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 18:01:53 +01:00
Michal Privoznik
61d1b9e659 qemu: Don't remove macvtaps on failed start
If a domain is configured to create a macvtap/macvlan but the
target link already exists, startup fails (as expected) with:

  error: error creating macvtap interface test@eth0 (52:54:00:d9:0b:db): File exists

Okay, we could make that error message better, but that's not the
point. Since this error originated while generating cmd line
(the caller is qemuProcessStart(), transitively), the cleanup
after failed start is performed (qemuProcessStop()). Here,
virNetDevMacVLanDeleteWithVPortProfile() is called which removes
the macvtap interface we did not create (as it made us fail in
the first place).

Therefore, we need to track which macvtap/macvlan interface was
created successfully and remove only those.

You'll notice that only qemuProcessStop() has the new check. For
the (failed) hotplug case (qemuDomainAttachNetDevice()) this
function is already in place (the @iface_connected variable), or
not needed (qemuDomainRemoveNetDevice() - we're removing an
interface that was already attached to QEMU).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2166235
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 15:44:26 +01:00
Michal Privoznik
db4ea3986a conf: Format and parse private data for virDomainNetDef
The virDomainNetDef struct has privateData (which is currently
used by QEMU driver to store FDs opened during cmd line building
phase and pass them onto cmd line).

Soon, we will need to store additional information that needs to
survive daemon restart. Let's introduce machinery for parsing and
formatting privateData.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 15:44:22 +01:00
Michal Privoznik
c0f671e7c9 virnetdevmacvlan: Drop G_GNUC_WARN_UNUSED_RESULT annotation for virNetDevMacVLanDeleteWithVPortProfile()
Every single caller of the
virNetDevMacVLanDeleteWithVPortProfile() function is calling it
wrapped inside of ignore_value() macro. This is because the
function is annotated as G_GNUC_WARN_UNUSED_RESULT. This makes no
sense. Drop the annotation and the macro envelope.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 15:44:20 +01:00
Michal Privoznik
714af1a50c domain_conf: Rewrite virDomainChrSourceModeTypeFromString() using VIR_ENUM_IMPL()
In domain_conf.c there's virDomainChrSourceModeTypeFromString()
which is open coded. Let's rewrite it using VIR_ENUM_DECL() +
VIR_ENUM_IMPL() combo.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 15:44:18 +01:00
Michal Privoznik
69db3bd954 domain_conf: Move virDomainNetVhostuserMode enum declaration
While it's true that the virDomainNetVhostuserMode enum is used
solely in virDomainNetDefParseXML(), its placement just above the
function is rather unfortunate. Let's put it at the beginning of
the file with the rest of the enum declarations/implementations.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 15:44:02 +01:00
Ján Tomko
b40b307889 qemu: fix a typo
s/usw/use/

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2023-02-01 13:12:20 +01:00
Peter Krempa
3b8d669d55 qemu: block: Properly handle FD-passed disk hot-(un-)plug
The hotplug code paths need to be able to pass the FDs to the monitor to
ensure that hotplug works.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
f730b1e4f2 qemu: domain: Store fdset ID for disks passed to qemu via FD
To ensure that we can hot-unplug the disk including the associated fdset
we need to store the fdset ID in the status XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
5598c10c64 qemu: fd: Add helpers allowing storing FD set data in status XML
Rollback of FD sets passed to qemu is also needed after possible restart
of libvirtd when we need to serialize the data into status XML. For this
purpose we need to access the fdset ID once it was passed to qemu and
potentially re-create a 'qemuFDPass' struct in passed state.

Introduce 'qemuFDPassNewPassed' and 'qemuFDPassIsPassed'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
3b7b201b95 qemuFDPassTransferCommand: Mark that FD was passed
Until now the code didn't expect that we'd want to rollback/detach a FD
passed on the commandline, but whith disk backend FD passing this can
happen.

Properly mark the 'qemuFDPass' object as passed to qemu even when it was
done on the commandline.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
65f14232fb qemu: command: Handle FD passing commandline via qemuBuildBlockStorageSourceAttachDataCommandline
Copy the pointer to qemuFDPass into struct qemuBlockStorageSourceAttachData
so that it can be used from qemuBuildBlockStorageSourceAttachDataCommandline
rather than looping again in qemuBuildDiskSourceCommandLineFDs.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
531adf3274 qemuStorageSourcePrivateDataFormat: Rename 'tmp' to 'objectsChildBuf'
Be consistent with other children buffer variable naming scheme.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
51dc38fe31 qemu_fd: Remove declaration for 'qemuFDPassNewDirect'
The function doesn't exist any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:17:41 +01:00
Peter Krempa
bb3b309386 storageBackendCreateQemuImgSecretPath: Refactor cleanup
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Peter Krempa
c655601d69 libxlMakeNetworkDiskSrc: Refactor cleanup
Automatically unref the 'conn' object and remove the 'cleanup' section
and 'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Peter Krempa
014b71a3a7 virStorageBackendISCSIDirectSetAuth: Use 'g_strndup' to '\0' terminate data
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Peter Krempa
2811fdaf3e virStorageBackendISCSIDirectSetAuth: Refactor cleanup
Use automatic pointer for 'conn' and remove the 'cleanup' label and
'ret' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Peter Krempa
edd644e7a8 virStorageBackendISCSISetAuth: Use g_strndup to '\0' terminate data
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Peter Krempa
fbb323fe61 virStorageBackendISCSISetAuth: Refactor cleanup
Automatically free 'conn' and remove the 'cleanup' section and 'ret'
variable. 'datatypes.h' contains the declaration of the autoptr cleanup
function for virConnect.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Peter Krempa
880cd081de virCryptoEncryptDataAESgnutls: Restructure control flow
Prepare the buffer for encryption only after initializing the cipher, so
that there's just one failure point. This allows to remove the 'error'
label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2023-02-01 09:16:17 +01:00
Michal Privoznik
dd8a2cffd6 virDomainNetDefFormat: Modernize <mac/> formatting
The <source/> child element of <mac/> is formatted the old way.
Switch to virXMLFormatElement().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:33 +01:00
Michal Privoznik
8a652c72b3 virDomainNetDefFormat: Simplify @sourceAttrBuf handling for some types of VIR_DOMAIN_NET
For VIR_DOMAIN_NET_TYPE_{SERVER,CLIENT,MCAST,UDP} we need to put
(optionally) 'address' attribute and 'port' attributes of
<source/> element. But the way we currently do that is
particularly verbose. It can be shortened using
virBufferEscapeString().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:31 +01:00
Michal Privoznik
95c5ff9890 virDomainNetDefFormat: Modernize <source/> formatting
The <source/> child element of <interface/> is formatted the old
way. Switch to virXMLFormatElement().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:28 +01:00
Michal Privoznik
3a7c6e0c4c virDomainNetDefFormat: Modernize <guest/> formatting
The <guest/> child element of <interface/> is formatted the old
way. Switch to virXMLFormatElement(). Since this element is used
in LXC driver, this part of the function is tested by
lxcxml2xmltest (specifically lxc-ethernet* test cases).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:26 +01:00
Michal Privoznik
86d10e6259 virDomainNetDefFormat: Modernize <tune/> formatting
The <tune/> child element of <interface/> is formatted the old
way. Switch to virXMLFormatElement().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:24 +01:00
Michal Privoznik
58e0bd73e0 virDomainNetDefFormat: Rename @attrBuf to @targetAttrBuf
The @attrBuf variable in virDomainNetDefFormat() is named too
broadly. It holds attribute buffer to the <target/> element.
Rename it to @targetAttrBuf then.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:22 +01:00
Michal Privoznik
97e4b5e1e7 qemuxml2xmloutdata: Turn net-mtu.xml into a symlink
There's nothing specific about net-mtu test. In fact, if device
addresses are filled in (and some elements reordered), we get the
same XML. Make those changes to the input XML and turn the output
XML to be a symlink.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2023-02-01 08:36:14 +01:00