Commit Graph

47015 Commits

Author SHA1 Message Date
Peter Krempa
e40f8649bf conf: domain: Refactor cleanup in virSysinfoSystemParseXML
Register automatic cleanup for virSysinfoSystemDef and use it to
refactor the cleanup code paths in virSysinfoSystemParseXML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:22:55 +01:00
Peter Krempa
a574b8cd87 conf: domain: Reformat XPath queries in virSysinfoSystemParseXML
Remove the unneeded linebreaks after assignment operator. Only one line
exceeds 80 colums and just by 4 characters.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:22:55 +01:00
Peter Krempa
1f5863ec46 conf: domain: Remove pointless XML node name validation in virSysinfoBIOSParseXML
The only caller passes 'node' argument originating from an XPath lookup
for the 'bios' element, so there's no point in checking it once more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:22:55 +01:00
Peter Krempa
407c4b12c7 conf: domain: Refactor cleanup in virSysinfoBIOSParseXML
Register automatic cleanup for virSysinfoBIOSDef and use it to refactor
the cleanup code paths in virSysinfoBIOSParseXML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:22:55 +01:00
Peter Krempa
45029ffa54 util: xml: Remove unused virXPathULong*
Remove the now-unused functions for parsing 'unsigned long' values via
XPath.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:59 +01:00
Peter Krempa
111a21c21f cpu_arm: Avoid use of 'unsigned long'
Covert all use of 'unsigned long' to 'unsigned long long'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
423d93967a virDomainJobObj: Use 'unsigned int' instead of 'unsigned long' for 'apiFlags' field
The callers store only an 'unsigned int' in the field. Convert it to the
proper type including parser/formatter.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
08c5c48124 qemuDomainObjPrivateXMLParseBlockjobData: Use virXMLPropUInt instead of virXPathULongHex
Use the function for the proper type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
5033e5efce ppc64ModelParse: Switch to virXMLPropUInt from virXPathULongHex
We don't need to do the extra XPath lookups and we can use the proper
type right away.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
053415a649 virDomainSEVDefParseXML: Use virXPathUIntBase instead of virXPathULongHex
Use the proper function for an unsigned int.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
cf479bcbb6 virDomainNetDef: Change type of 'tune.sndbuf'
Use 'unsigned long long' instead of 'unsigned long' and fix the parser
and formatter.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
3bd5ceb68a virDomainTimerDefParseXML: Use virXMLProp instead of virXPath
Parse the 'frequency' field without an extra XPath.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
51e6ae319d virDomainTimerDef: Convert 'mode' field to proper enum type
Adjust the parser and switch statements to go with it.

Note that the XEN/libxl drivers had a 'default:' case for few of the
swtich statements so this patch blindly expands it to what it would be
in those cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
83e1368d95 virDomainTimerDef: Convert 'track' field to proper enum type
Adjust the parser and add missing switch cases to make the complier
happy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
7fb8adc7cd virDomainTimerDef: Convert 'tickpolicy' field to proper enum type
Convert the field, adjust the XML parser to use virXMLPropEnum and add
the VIR_DOMAIN_TIMER_TICKPOLICY_LAST enum case to all appropriate
'switch' statements.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
7fc2c87200 virDomainTimerDef: Convert 'name' field to proper enum type
Adjust the type and the corresponding parser to use virXMLPropEnum.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
a9a2ecec54 virDomainTimerDefParseXML: Refactor cleanup
Automatically free the 'def' variable and remove the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
a9294713d8 virDomainTimerCatchupDef: Change members to 'unsigned long long'
The struct used 'unsigned long' variables which we try to avoid due to
being different size on different architectures.

Convert the struct and use virXMLPropULongLong instead of virXPathULong
when parsing the XML.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:58 +01:00
Peter Krempa
1de6fd5edb virNetDevVlanParse: Use virXMLProp* helpers instead of XPath lookups
The loop inside virNetDevVlanParse fetches multiple attributes from the
element. Convert it to use the virXMLProp* helpers, which also
simplifies error reporting.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
b8e415b467 virInterfaceDefParseMtu: Use virXPathUInt instead of virXPathULong
Use the proper convertor function and refactor error reporting.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
367fdfbff8 virNetworkIPDefParseXML: Use virXMLPropUInt instead of virXPathULong
Parse the 'prefix' field directly and adjust the the error message
format strings.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
fa6ba9b8c7 virNetDevIPRouteParseXML: Refactor to use 'virXMLProp*' instead of XPath
The function extracts multiple attributes form a single element. Modify
the function to stop using multiple XPath lookups.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
a3c7426839 virQEMUCapsLoadCache: Use 'virXMLPropUInt' instead of 'virXPathULong'
The libvirt version is stored in an 'unsigned int' use the proper XPath
query function for the type and remove the temporary variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
5ff3e29d44 util: xml: Remove virXPathLong
The function is now unused and we no longer want to promote use of the
'long' type.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
a65dd31438 conf: domain: Convert from virXPathLong
Convert the two uses of virXPathLong to proper
virXMLPropInt/virXMLPropLongLong so that virXPathLong can be removed in
an upcoming patch.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
4899c55e99 testParseNodeInfo: Rewrite to virXPathU(Int|LongLong)
Use the function for appropriate types and simplify the error logic.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
3e3c52f10f util: xml: Disallow aliasing of negative numbers in virXPathUInt
Passing negative number as an alias for the max value is an anti-feature
we unfortunately allowed in virsh, but luckily never encouraged in the
XML.

Refuse numbers with negative sign when parsing unsigned int from
XPaths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
8989b3a54d virNodeDevCapsDefParseHexId: Use 'virXPathUIntBase'
Switch to the proper function for parsing integer variant of a hex
number via XPath and spell out properly that the argument is 'unsigned
int'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
7160805e76 util: xml: Introduce virXPathU(Int|LongLong)Base
In an effort to remove the 'Long' variants of XPath number fetching
functions we need a way to replace the hex number parsing capability.

The new helpers are created from the originals by adding a 'base'
argument and keeping the original function as a wrapper to pass 10.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
90cb594cf6 util: xml: Reimplement virXPath(U)Int via virXPathEvalString
Similarly to the refactor of virXPath(U)LongLong drop the ability to
convert from the internal double value forcing the use of the 'string()'
conversion.

In case of 32 bit integers there's no problem with overflows, but we can
implement the code identically to what we have in the other helpers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
fe4120ec26 conf: cpu: Extract and refactor parsing of cache from virCPUDefParseXML
Move the parser into a helper function named 'virCPUDefParseXMLCache'
and use the virXMLProp* helpers instead of multiple XPath lookups.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
5575187ece conf: numa: Don't fetch XML node count in virDomainNumatuneParseXML
The code only wants to refuse cases where more than one 'numatune'
element is present which can be achieved by using 'virXPathBoolean'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
136f351b0f conf: node_device: Use 'string()' in XPath expressions for virNodeDevCapsDefParseIntOptional
Upcoming patches will require that the XML XPath query returns a string
for conversion in virXPathInt. Convert all the XPaths used with
virNodeDevCapsDefParseIntOptional which uses virXPathInt internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
57b016bdd3 conf: node_device: Convert rest of virXPathUInt XPath expressions to number
Convert the rest of the XPath expressions used with virXPathUInt
directly to convert via string(). This will become mandatory in upcoming
patches.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:57 +01:00
Peter Krempa
090d18f7f7 conf: node_device: Use 'string()' in XPath expressions for virNodeDevCapsDefParseUInt
Upcoming patches will require that the XML XPath query returns a string
for conversion in virXPathUInt. Convert all the XPaths used with
virNodeDevCapsDefParseUInt which uses virXPathUInt internally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:56 +01:00
Peter Krempa
e8ea7ac579 util: xml: Disallow aliasing of negative numbers in virXPathULongLong
Passing negative number as an alias for the max value is an anti-feature
we unfortunately allowed in virsh, but luckily never encouraged in the
XML.

Refuse numbers with negative sign when parsing unsigned long long from
XPaths.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-02 09:20:56 +01:00
Peter Krempa
fd97c85b95 tests: qemucapabilities: Add data for the qemu-7.2 dev cycle
Add data based on the v7.1.0-1579-g5107fd3eff qemu commit.

Notable changes:

- New machine types and corresponding objects:
    - pc-i440fx-7.2, pc-i440fx-7.2-machine, pc-q35-7.2, pc-q35-7.2-machine
- new NETDEV_STREAM_CONNECTED/NETDEV_STREAM_DISCONNECTED events
- thread-context object and prealloc-property for memory devices added
- libblkio block driver backed support added:
    - new backend protocol drivers:
       - io_uring, nvme-io_uring, virtio-blk-vhost-user, virtio-blk-vhost-vdpa
- New CPU flags and some CPU features become migratable
  (corresponding 'cpu-host-model' test changed output)
- cpu features 'avx', 'avx2', 'f16c', 'fma', 'vaes' became available in
  TCG
- 'dumpdtb' command added
- New disk frontend properties:
    - account-failed, account-invalid
- New unstable commands for debugging virtio:
  x-query-virtio, x-query-virtio-status, x-query-virtio-queue-status,
  x-query-virtio-vhost-queue-status, x-query-virtio-queue-element

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 15:47:44 +01:00
Michal Privoznik
43ac2e703c qemu_namespace: Make qemuDomainGetPreservedMounts() more robust wrt running VMs
The aim of qemuDomainGetPreservedMounts() is to get a list of
filesystems mounted under /dev and optionally generate a path for
each one where they are moved temporarily when building the
namespace. And if given domain is also running it looks into its
mount table rather than at the host one. But if it did look at
the domain's private mount table, it find /dev mounted twice: the
first time by udev, the second time the tmpfs mounted by us.

Now, later in the function there's a "sorting" algorithm that
tries to reduce number of mount points needing preservation, by
identifying nested mount points. And if we keep the second
occurrence of /dev on the list, well, after the "sorting" we are
left with nothing but "/dev" because all other mount points are
nested.

Fixes: 46b03819ae
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 14:51:48 +01:00
Michal Privoznik
bca7a53333 qemu_namespace: Don't leak memory in qemuDomainGetPreservedMounts()
The aim of qemuDomainGetPreservedMounts() is to get a list of
filesystems mounted under /dev and optionally generate a path for
each one where they are moved temporarily when building the
namespace. And the function tries to be a bit clever about it.
For instance, if /dev/shm mount point exists, there's no need to
consider /dev/shm/a nor /dev/shm/b as preserving just 'top level'
/dev/shm gives the same result. To achieve this, the function
iterates over the list of filesystem as returned by
virFileGetMountSubtree() and removes the nested ones. However, it
does so in a bit clumsy way: plain VIR_DELETE_ELEMENT() is used
without freeing the string itself. Therefore, if all three
aforementioned example paths appeared on the list, /dev/shm/a and
/dev/shm/b strings would be leaked.

And when I think about it more, there's no real need to shrink
the array down (realloc()). It's going to be free()-d when
returning from the function. Switch to
VIR_DELETE_ELEMENT_INPLACE() then.

Fixes: cdd9205dff
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 14:51:48 +01:00
Peter Krempa
ecb8c93196 qemuAppendDomainMemoryMachineParams: Refactor formatting of 'dump-guest-core'
Use virTristateSwitchFromBool to fill in the default if user didn't
request it explicitly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
c7c5d65183 util: xml: Remove double->(u)ll conversion in virXPath(U)LongLong
The conversion from double is not precise enough at the extremes so it
must not be used.

Spell out that the callers are required to use a string() conversion in
the XPath expression and remove the code path handling the direct
conversion from numbers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
713ec72222 util: xml: Extract XPath evaluation for strings
Extract the internals of virXPathString which evaluate the XPath and
validate that the returned object is a string into a new helper named
'virXPathEvalString'.

The function will be later reused in the number XPath evaluation
functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
8525ac4b83 conf: Always use 'string()' conversion with virXPath(U)LongLong
When the 'string()' conversion is used the number is parsed inside
libvirt by our internal helpers which work on integers in contrast to
when 'number()' is used and libxml2 uses a 'double' variable internally.

On the upper extremes of the 64 bit variables the double precision
variable doesn't have enough precision to represent each distinct
integer and thus could cause problems.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
3ae376535a virNodeDeviceCapPCIDefFormat: Use %u for unsigned values
'bus', 'slot' and 'function' are unsigned int variables parsed as
unsigned int, but were formated as signed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
c0cbdd24d5 conf: node_device: Rename virNodeDevCapsDefParseULong to virNodeDevCapsDefParseUInt
The function parses an unsigned int so rename it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
f7281dd014 virNodeDevCapsDefParseULong: Use virXPathUInt instead of virXPathULong
Fix the function argument to properly spell out 'unsigned int' and use
virXPathUInt instead of virXPathULong and a temporary value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
a3f7165889 util: xml: Remove unused 'virXPathLongHex'
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
426a0b3779 util: xml: Use consistent naming for RNG validation error handling functions
Rename 'catchRNGError' to 'virXMLValidatorRNGErrorCatch' and
'ignoreRNGError' to 'virXMLValidatorRNGErrorIgnore'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
877654b879 util: xml: Ensure proper header style in virxml.c
Make the file use consistent header formatting and two line spacing
between functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00
Peter Krempa
5def8f7577 util: xml: Unexport virXMLXPathContextNew
The function is now referenced only within util/virxml.c other callers
should not use it directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-11-01 13:07:20 +01:00