Commit Graph

2471 Commits

Author SHA1 Message Date
Peter Krempa
cd3599c876 conf: virdomainobjlist: Introduce 'virDomainObjListCollectAll'
Introduce a helper which will return a list of all domain objects inside
of the list without filtering and thus without the need to lock
individual members.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2023-01-06 15:27:52 +01:00
Peter Krempa
b62aaceff9 conf: domain: Remove virDomainDeviceDefCopy
The function is now unused. Remove it to dissuade anybody from trying to
use it in the future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-12-05 12:03:11 +01:00
Peter Krempa
1a136152e6 util: xml: Introduce virXMLNodeGetSubelement
Introduce a simple helper fetching a sub-element node by name. This is
meant as a simple replacement for either open-coded versions of this or
use of XPath for this trivial lookup.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-12-02 16:49:25 +01:00
Peter Krempa
83a8f249c2 util: json: Remove unused virJSONValueObjectGetStringArray wrapper
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-12-02 16:18:37 +01:00
Peter Krempa
6765bdeaf7 util: json: Split out array->strinlist conversion from virJSONValueObjectGetStringArray
Introduce virJSONValueArrayToStringList which does only the conversion
from an array to a stringlist.

This will allow refactoring the callers to be more careful in case when
they want to handle the existance of the member in the parent object
differently.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-12-02 16:18:37 +01:00
Haibin Huang
fa0da364e7 domain_capabilities: Define SGX capabilities structs
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Haibin Huang <haibin.huang@intel.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-11-11 14:06:21 +01:00
Eric Garver
d0e4d2fde7 util: add virFirewallDPolicyExists()
Signed-off-by: Eric Garver <eric@garver.life>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-11-05 14:34:42 -04:00
Eric Garver
ab56f84976 util: add virFirewallDGetPolicies()
Signed-off-by: Eric Garver <eric@garver.life>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-11-05 14:34:37 -04: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
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
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
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
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
Peter Krempa
ed03de9e46 util: xml: Remove unused virXPathNumber
'virXPathNumber' is not used currently, remove 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
Michal Privoznik
bd481a79d8 virCommand: Introduce APIs for core scheduling
There are two modes of core scheduling that are handy wrt
virCommand:

1) create new trusted group when executing a virCommand

2) place freshly executed virCommand into the trusted group of
   another process.

Therefore, implement these two new operations as new APIs:
virCommandSetRunAlone() and virCommandSetRunAmong(),
respectively.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-10-20 08:51:50 +02:00
Michal Privoznik
c935cead2d virprocess: Core Scheduling support
Since its 5.14 release the Linux kernel allows userspace to
define trusted groups of processes/threads that can run on
sibling Hyper Threads (HT) at the same time. This is to mitigate
side channel attacks like L1TF or MDS. If there are no tasks to
fully utilize all HTs, then a HT will idle instead of running a
task from another (un-)trusted group.

On low level, this is implemented by cookies (effectively an UL
value): processes in the same trusted group share the same cookie
and cookie is unique to the group. There are four basic
operations:

1) PR_SCHED_CORE_GET -- get cookie of given PID,
2) PR_SCHED_CORE_CREATE -- create a new unique cookie for PID,
3) PR_SCHED_CORE_SHARE_TO -- push cookie of the caller onto
   another PID,
4) PR_SCHED_CORE_SHARE_FROM -- pull cookie of another PID into
   the caller.

Since a system where the code is built can be different to the
one where the code is ran let's provide declaration of some
values. It's not unusual for distros to ship older linux-headers
than the actual kernel.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-10-20 08:51:50 +02:00
Jiri Denemark
bbd2d9cb40 Introduce virCPUGetVendorForModel and use it in QEMU driver
So far QEMU driver does not get CPU model vendor from QEMU directly and
it has to ask the CPU driver for the info stored in CPU map.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-10 14:31:43 +02:00
Peter Krempa
d4b6496f24 conf: domain: Remove virDomainObjParseNode
virDomainObjParseFile is the only caller of virDomainObjParseNode.
The code can be merged into it, simplified by using virXMLParse and
the function removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
1eb67d24de conf: network: Provide only virNetworkDefParse
Replace virNetworkDefParseString/File by direct calls to
virNetworkDefParse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
e56e82a654 conf: network: Remove virNetworkDefParseNode
Both callers can be easily converted to call virNetworkDefParseXML
directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
be43d74b63 conf: interface: Remove virInterfaceDefParseFile
The function was not used. Remove it and merge virInterfaceDefParse
into virInterfaceDefParseString.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
05ffd59436 conf: interface: Remove virInterfaceDefParseNode
Both callers be easily made to call virInterfaceDefParseXML directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
37de09a2f9 conf: nodedev: Provide only virNodeDeviceDefParse
Replace the thin wrappers virNodeDeviceDefParseString/File by directly
calling the main parser.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
23f301bd2d conf: node_device: Remove virNodeDeviceDefParseNode
Both callers be easily made to call virNodeDeviceDefParseXML directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
5ea1d04322 conf: nwfilter: Provide only virNWFilterDefParse
Replace virNWFilterDefParseString/File with the common function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
573f764ee4 conf: backup: Remove virDomainBackupDefParseNode
Rename virDomainBackupDefParse to virDomainBackupDefParseXML and use
it in place of virDomainBackupDefParseNode. This is possible as
virXMLParse can be used to replace XPath context allocation and root
node checking.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:25 +02:00
Peter Krempa
7c32578531 conf: secret: Provide only virSecretDefParse
Replace the virSecretDefParseFile/String shims by calls to
virSecretDefParse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
2a166e6c12 conf: storage: Provide only virStorageVolDefParse
Remove the virStorageVolDefParseFile/String shim functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
3c56186031 conf: storage: Remove virStorageVolDefParseNode
Proper use of virXMLParse replaces everything the function provides.
Callers can use virStorageVolDefParseXML instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
97df89d7f5 conf: storage: Provide only virStoragePoolDefParse
Replace the virStoragePoolDefParseString/File thin wrappers by
virStoragePoolDefParse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
b3e33a0ef7 conf: storage: Remove virStoragePoolDefParseNode
Replace it by proper use of virXMLParse to validate the root node and
allocate the context. The use in the test driver can be directly
replaced by virStoragePoolDefParseXML as both are validated.

The change to the storage driver isn't trivial though as it requires
careful xpath context juggling to parse the nested volumes properly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
ed080445a6 conf: networkportdef: Provide only virNetworkPortDefParse
Replace the two helpers virNetworkPortDefParseString/File with the
common helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
0589afb96b conf: networkport: Remove virNetworkPortDefParseNode
The function is exported but used only intenally, additionally
everything it did for the only caller can be replaced by properly using
virXMLParse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
0dceac9b8e conf: nwfilterbinding: Provide only virNWFilterBindingDefParse
Remove the virNWFilterBindingDefParseString/File thin wrappers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
3eb151ddfd virNWFilterBindingDefParse: Properly use virXMLParse
Fetch the XPath context and validate the node by using virXMLParse's
features.

This allows to completely remove virNWFilterBindingDefParseNode as
all callers now properly validate the root element name and have a XPath
context handy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
2597e16e29 virNWFilterBindingObjParse: Refactor XML parsing code
Remove the redundant root node checking and XPath context creation by
using virXMLParse properly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-06 10:54:24 +02:00
Peter Krempa
3387eae871 util: xml: Introduce virXMLPropLongLong
Add a helper for parsing long long values from XML properties with
semantics like virXMLPropInt.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-03 14:43:17 +02:00
Peter Krempa
65eaf58335 util: xml: Introduce virXMLPropStringRequired
Similarly to virXMLPropString it extracts a string but reports an error
similar to the newer virXMLProp helpers if the attribute is not present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-03 14:43:17 +02:00
Peter Krempa
fe54d2a94f util: xml: Introduce virXMLPropUUID
The helper function extracts a UUID with semantics similar to other
helpers we have.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-10-03 14:43:17 +02:00
Kristina Hanicova
ecc742126a qemu & conf: move BeginNestedJob & BeginJobNowait into src/conf
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:15:28 +02:00
Kristina Hanicova
4435c026b7 qemu & conf: move BeginAsyncJob & EndAsyncJob into src/conf
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:15:06 +02:00
Kristina Hanicova
421f1e749f qemu & conf: move BeginAgentJob & EndAgentJob into src/conf/virdomainjob
Although these and functions in the following two patches are for
now just being used by the qemu driver, it makes sense to have all
begin job functions in the same file.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:14:43 +02:00
Kristina Hanicova
9085ccbfb4 qemu: use virDomainObjEndJob()
This patch moves qemuDomainObjEndJob() into
src/conf/virdomainjob as universal virDomainObjEndJob().

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:14:07 +02:00
Kristina Hanicova
0d22febfc6 qemu: use virDomainObjBeginJob()
This patch moves qemuDomainObjBeginJob() into
src/conf/virdomainjob as universal virDomainObjBeginJob().

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:13:30 +02:00
Kristina Hanicova
84e9fd068c conf: extend xmlopt with job config & add job object into domain object
This patch adds the generalized job object into the domain object
so that it can be used by all drivers without the need to extract
it from the private data.

Because of this, the job object needs to be created and set
during the creation of the domain object. This patch also extends
xmlopt with possible job config containing virDomainJobObj
callbacks, its private data callbacks and one variable
(maxQueuedJobs).

This patch includes:
* addition of virDomainJobObj into virDomainObj (used in the
  following patches)
* extending xmlopt with job config structure
* new function for freeing the virDomainJobObj

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:06:18 +02:00
Kristina Hanicova
2378f9d86e move files: hypervisor/domain_job -> conf/virdomainjob
The following patches move job object as a member into the domain
object.  Because of this, domain_conf (where the domain object is
defined) needs to import the file with the job object.

It makes sense to move jobs to the same level as the domain_conf:
into src/conf/

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:06:17 +02:00
Kristina Hanicova
3b1ad4cb17 qemu & hypervisor: move qemuDomainObjBeginJobInternal() into hypervisor
This patch moves qemuDomainObjBeginJobInternal() as
virDomainObjBeginJobInternal() into hypervisor in order to be
used by other hypervisors in the following patches.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2022-09-07 12:06:17 +02:00
Laine Stump
4dce6eee5c util: make virFirewallRuleToString() global
Although the next commit will eliminate the one current use of
virFirewallRuleToString(), a future commit will once again have a use
for it, but in a different source file so it will need to be a global
function rather than static. Make that change now so that we don't get
a compile error from having an unused static function in the next
commit.

(The arg list is also changed to include the name of the command as a
separate argument rather than just assuming that it can be derived
from the rule's layer (which is correct for iptables, but won't be
correct for nftables)).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-08-24 12:22:47 -04:00
Jonathon Jongsma
ab29ddfdf8 nodedev: support 'mtty' device for testing
It would be nice to be able to test the mediated device capabilities
without having physical hardware which supports it. The 'mtty' kernel
module presents a virtual parent device which is capable of creating
'fake' mediated devices, and as such it would be useful for testing.

However, the 'mtty' device is not part of an existing device subsystem
(e.g. PCI, etc), so libvirt ignores it and it does not get added to the
node device list. And because it does not get added to the node device
list, it cannot be used to create child mdevs using `virsh
nodedev-create`.

There is already a node device type capability
VIR_NODE_DEV_CAP_MDEV_TYPES that indicates whether a device supports
creating child mediated devices, but libvirt assumes that this is a
nested capability (in other words, it assumes that the primary
capability of a device is something like PCI). If we allow this
MDEV_TYPES capability to be a primary device capability, then we can
support virtual devices like 'mtty' as a parent for mediated devices.

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-10 11:19:03 -05:00
Kristina Hanicova
54f48e033e qemu: move virDomainObjCanSetJob() into hypervisor
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:50 +02:00
Kristina Hanicova
7537c4d0a5 qemu: move virDomainNestedJobAllowed into hypervisor
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:47 +02:00
Kristina Hanicova
6260204c7f qemu & hypervisor: move qemuDomainTrackJob() into hypervisor
This patch moves qemuDomainTrackJob() as virDomainTrackJob() into
hypervisor because it is called in begin job and end job
functions that will be generalized in the following series.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:45 +02:00
Kristina Hanicova
d5b677792c qemu & hypervisor: move qemuDomainObjClearJob() into hypervisor
This patch moves qemuDomainObjClearJob() as
virDomainObjClearJob() into hypervisor in order to be used by
other hypervisors as well.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:34 +02:00
Kristina Hanicova
635bb08025 qemu & hypervisor: move qemuDomainObjPreserveJob() into hypervisor
This patch moves qemuDomainObjPreserveJob() as
virDomainObjPreserveJob() into hypervisor in order to be used by
other hypervisors as well.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:31 +02:00
Kristina Hanicova
36435967f6 qemu & hypervisor: move qemuDomainObjResetAsyncJob() into hypervisor
This patch moves qemuDomainObjResetAsyncJob() as
virDomainObjResetAsyncJob() into hypervisor.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:27 +02:00
Kristina Hanicova
7bbc465b45 qemu & hypervisor: move qemuDomainObjResetAgentJob() into hypervisor
This patch moves qemuDomainObjResetAgentJob() as
virDomainObjResetAgentJob() into hypervisor.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-08 12:19:24 +02:00
Jim Fehlig
c647bf29af capabilities: Report number of host CPU physical address bits
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-04 09:04:12 +02:00
Dario Faggioli
e6c29f09e5 conf: Add support for specifying CPU max physical address size
This patch introduces the

    <maxphysaddr mode='passthrough'/>
    <maxphysaddr mode='emulate' bits='42'/>

sub element of /domain/cpu, which allows specifying the guest virtual CPU
address size. This can be useful if the guest needs to have a large amount
of memory.

If mode='passthrough', the virtual CPU will have the same number of address
bits as the host. If mode='emulate', the mandatory bits attribute specifies
the number of address bits.

Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-08-04 09:04:07 +02:00
Michal Privoznik
a6c1d061a5 src: Export virDomainTPMVersion enum conversion helpers
The virDomainTPMVersion enum is declared in domain_conf.h among
with its TypeFromString() and TypeToString() helpers (which are
then implemented in domain_conf.c). However, neither of these
helpers is exposed in libvirt_private.syms which makes it
impossible for other modules to use.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Kristina Hanicova <khanicov@redhat.com>
2022-08-04 08:09:03 +02:00
Kristina Hanicova
cee50d1187 qemu & hypervisor: move qemuDomainObjResetJob() into hypervisor
This patch moves qemuDomainObjResetJob() as
virDomainObjResetJob() into hypervisor in order to be used by
other hypervisors as well.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2022-08-02 10:38:51 -05:00
Peter Krempa
1122b16276 virclosecallbacks: Remove unused virCloseCallbacksGetConn
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
2022-07-22 11:11:42 +02:00
Kristina Hanicova
260a091982 qemu & hypervisor: move qemuDomainObjInitJob() into hypervisor
This patch moves qemuDomainObjInitJob() as virDomainObjInitJob()
into hypervisor in order to be used by other drivers as well.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-07-21 15:02:44 +02:00
Jonathon Jongsma
62ca300530 util: remove virObjectUnref() adapters
These wrapper functions were used to adapt the virObjectUnref() function
signature for different callbacks. But in commit 0d184072, the
virObjectUnref() function was changed to return a void instead of a
bool, so these adapters are no longer necessary.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2022-07-15 16:44:39 -05:00
Michal Privoznik
d9916c3519 conf: Separate domain post parse code into domain_postparse.c
The domain post parse functions currently live in domain_conf.c
which thus grows always larger. Mimic what we've done for the
validation code and move the post parse code into a separate
file: domain_postparse.c.

I've started by moving every function with PostParse in its name
into the new file and then compile hunting for helper functions
only to move them as well.

In the end, I've moved virDomainDefPostParse symbol in
libvirt_private.syms into a new section. And while
virDomainDeviceDefPostParseOne() is made 'public' in
domain_postparse.h too, I'm not exporting it because it has no
caller outside src/conf/ and it's unlikely it ever will.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-07-07 14:32:21 +02:00
Peter Krempa
3603a18bce domain_validate: Split out validation of disk startup policy
Move the code into 'virDomainDiskDefValidateStartupPolicy' which will be
later reused in the qemu driver.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-06-14 16:38:11 +02:00
Jiri Denemark
83ccd3a3d1 conf: Introduce virDomainObjIsPostcopy helper
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2022-06-07 17:40:20 +02:00
Jiri Denemark
efe95fb878 conf: Introduce virDomainObjIsFailedPostcopy helper
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2022-06-07 17:40:20 +02:00
Boris Fiuczynski
9453eb458a util: add virCCWDeviceAddressFromString to virccw
Add a method to parse a ccw device address from a string.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:59 +02:00
Boris Fiuczynski
8d52f99f0b util: add ccw device address parsing into virccw
Add virCCWDeviceAddressParseFromString and use it in nodedev udev.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:57 +02:00
Boris Fiuczynski
2d9fd19bf5 conf: adjust method name virDomainDeviceCCWAddressParseXML
Adjust method name virDomainDeviceCCWAddressParseXML to
virCCWDeviceAddressParseXML.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:55 +02:00
Boris Fiuczynski
784b876035 util: refactor virDomainDeviceCCWAddressEqual into virccw
Refactor virDomainDeviceCCWAddressEqual into virccw and rename method as
virCCWDeviceAddressEqual.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:53 +02:00
Boris Fiuczynski
38756ce5ba util: refactor virDomainDeviceCCWAddressIsValid into virccw
Refactor virDomainDeviceCCWAddressIsValid into virccw and rename method
as virCCWDeviceAddressIsValid.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:52 +02:00
Boris Fiuczynski
be1e16ed11 util: refactor virDomainCCWAddressIncrement into virccw
Refactor virDomainCCWAddressIncrement into virccw and rename method as
virCCWDeviceAddressIncrement.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:49 +02:00
Boris Fiuczynski
1df0a19869 util: refactor virDomainCCWAddressAsString into virccw
Move virDomainCCWAddressAsString into virccw and rename method as
virCCWDeviceAddressAsString.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-23 16:31:42 +02:00
Peter Krempa
45064119c1 util: typedparam: Introduce virTypedParamListFromParams
The helper constructs a virTypedParamList from loose params.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2022-05-18 13:46:30 +02:00
Jonathon Jongsma
43aa510c19 util: Remove virCommandPassFDIndex()
The last use of this function was removed in commit 6d161bcc, so the
function is no longer used except as an internal implementation for
virCommandPassFD().

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2022-05-16 09:29:47 -05:00
Jonathon Jongsma
2e89805894 util: remove virCommandPassFDGetFDIndex()
commit f9236200 removed the last use of this function, so it can be
dropped.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2022-05-16 09:29:47 -05:00
Martin Kletzander
45c0ff3eea conf: Add virDomainDefHasSpiceGraphics
It will be used in future patch in multiple places.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-05-12 10:20:37 +02:00
Jonathon Jongsma
f135fdabab Rename virDomainGraphicsSpiceMouseMode to virDomainMouseMode
This enumeration will be useful for vnc with the upcoming qemu-vdagent
device so make the name more generic.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2022-05-10 11:00:15 -05:00
Peter Krempa
68d1056392 virXMLFormatElement: Introduce virXMLFormatElementInternal
The new function aggregates the internal working of virXMLFormatElement
and virXMLFormatElementEmpty and also allows skipping the newline
after the opening tag to allow using this helper also in cases where we
don't format any child elements but directly a value.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-04-08 09:32:47 +02:00
Andrea Bolognani
fd3ca84c3e util: Introduce virXMLPropTristateBoolAllowDefault()
We need it for a single scenario in which prop='default' has to
be treated as valid input.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-04-05 13:40:24 +02:00
Kristina Hanicova
a193f4bef6 move jobs enums QEMU_X into hypervisor as VIR_X
These enums are essentially the same and always sorted in the
same order in every hypervisor with jobs. They can be generalized
by using the qemu enums as the main ones as they are the most
extensive.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-03-25 13:40:56 +01:00
Daniel P. Berrangé
731456ca13 nwfilter: merge updateMutex and updateLock
The updateLock is a R/W lock held by anything which needs to read or
modify the rules associated with an NWFilter.

APIs for defining/undefining NW filters rules hold a write lock on
updateLock.

APIs for creating/deleting NW filter bindings hold a read lock on
updateLock, which prevents define/undefine taking place concurrently.

The problems arise when we attempt to creating two NW filter bindings in
parallel.

Thread 1 can acquire the mutex for filter A

Thread 2 can acquire the mutex for filter B

Consider if filters A and B both reference filters C and D, but in
different orders:

  Filter A
     -> filter C
     -> filter D

  Filter B
     -> filter D
     -> filter C

Thread 1 will try to acquire locks in order A, C, D while thread 1 will
try to acquire in order A, D, C. Deadlock can still occur.

Think we can sort the list of filters before acquiring locks on all of
them ? Nope, we allow arbitrary recursion:

  Filter A
     -> filter C
          -> filter E
             -> filter F
                -> filter H
                -> filter K
     -> filter D
         -> filter G
         -> filter I

So we can't tell from looking at 'A' which filters we're going to
need to lock. We can only see the first level of filters references
and we need to lock those before we can see the second level of
filters, etc.

We could probably come up with some cleverness to address this but
it isn't worth the time investment. It is simpler to just keep the
process of creating NW filter bindings totally serialized.

Using two separate locks for this serialization though is pointless.

Every code path which gets a read(updateLock) will go on to hold
updateMutex. It is simpler to just hold write(updateLock) and
get rid of updateMutex. At that point we don't need updateLock
to be a R/W lock, it can be a plain mutex.

Thus this patch gets rid of the current updateLock and updateMutex
and introduces a new top level updateMutex.

This has a secondary benefit of introducing fairness into the
locking.  With a POSIX R/W lock, you get writer starvation if
you have lots of readers. IOW, if we call virNWFilterBIndingCreate
and virNWFilterBindingDelete in a tight loop from a couple of
threads, we can prevent virNWFilterDefine from ever acquiring
a write lock.

Getting rid of the R/W lock gives us FIFO lock acquisition
preventing starvation of any API call servicing.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-03-22 10:19:31 +00:00
Boris Fiuczynski
ccb3dc72b8 virnodedeviceobj: export virNodeDeviceObjHasCap
The function will be reused in the nodedev drivers udev handling.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2022-03-17 10:57:17 +01:00
Peter Krempa
f17da1c24b conf: Move definition of 'virDomainSnapshotLocation'
The snapshot location enum is also needed for the disk definition so if
we house it inside domain_conf we can use the proper type for it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-11 13:55:49 +01:00
Peter Krempa
f24a22315b driver: Introduce global driver feature flag handling function
The 'virDrvFeature' has a combination of features which are asserted by
the specific driver and features which are actually global.

In many cases the implementation was cargo-culted into newer drivers
without re-assesing whether it makes sense.

This patch introduces a global function which will specifically handle
these global flags and defer the rest to the driver.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-02-17 13:15:46 +01:00
Kristina Hanicova
f304de0df6 qemu: use generalized virDomainJobData instead of qemuDomainJobInfo
This patch includes:
* introducing new files: src/hypervisor/domain_job.c and src/hypervisor/domain_job.h
* new struct virDomainJobData, which is almost the same as
  qemuDomainJobInfo - the only differences are moving qemu specific
  job stats into the qemuDomainJobDataPrivate and adding jobType
  (possibly more attributes in the future if needed).
* moving qemuDomainJobStatus to the domain_job.h and renaming it
  as virDomainJobStatus
* moving and renaming qemuDomainJobStatusToType
* adding callback struct virDomainJobDataPrivateDataCallbacks
  taking care of allocation, copying and freeing of private data
  of virDomainJobData
* adding functions for virDomainJobDataPrivateDataCallbacks for
  qemu hypervisor
* adding 'public' (public between the different hypervisors) functions
  taking care of init, copy, free of virDomainJobData
* renaming every occurrence of qemuDomainJobInfo *info to
  virDomainJobData *data

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
2022-02-15 12:20:45 +01:00
Vasiliy Ulyanov
013ab22f79 virpidfile: Add virPidFileReadPathIfLocked func
The function will attempt to read a pid from @path, and store it in
@pid. The @pid will only be set, however, if @path is locked by
virFileLock() at byte 0 and the pid in @path is running.

Signed-off-by: Vasiliy Ulyanov <vulyanov@suse.de>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-04 10:27:30 +01:00
Dmitrii Shcherbakov
86fc0c2576 Set VF MAC and VLAN ID in two different operations
This has a benefit of being able to handle error codes for those
operations separately which is useful when drivers allow setting a MAC
address but do not allow setting a VLAN (which is the case with some
SmartNIC DPUs).

Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherbakov@canonical.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-03 16:52:05 +01:00
Ján Tomko
8eb7d869ed virParseVersionString: rename to virStringParseVersion
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-02-03 14:10:03 +01:00
Ján Tomko
f40179b9fb util: virParseVersionString: move to virstring.c
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2022-02-03 14:10:03 +01:00
Tim Wiederhake
8935c8397c virobject: Introduce virObjectLockGuard
Typical usage:
    void foobar(virObjectLockable *obj)
    {
        VIR_LOCK_GUARD lock = virObjectLockGuard(obj);
        /* `obj` is locked, and released automatically on scope exit */

        ...
    }

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-01 17:19:38 +01:00
Tim Wiederhake
d00d078968 virthread: Introduce virLockGuard
Locks a virMutex on creation and unlocks it in its destructor.

The VIR_LOCK_GUARD macro is used instead of "g_auto(virLockGuard)" to
work around a clang issue (see https://bugs.llvm.org/show_bug.cgi?id=3888
and https://bugs.llvm.org/show_bug.cgi?id=43482).

Typical usage:

    void function(virMutex *m)
    {
        VIR_LOCK_GUARD lock = virLockGuardLock(m);
        /* `m` is locked, and released automatically on scope exit */

        ...
        while (expression) {
            VIR_LOCK_GUARD lock2 = virLockGuardLock(...);
            /* similar */
        }
    }

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-01 17:19:23 +01:00
Praveen K Paladugu
788e2b58cb qemu, hypervisor: refactor some cgroup mgmt methods
Refactor some cgroup management methods from qemu into hypervisor.
These methods will be shared with ch driver for cgroup management.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-01-28 17:04:50 +01:00
Ján Tomko
44aaa02992 util: remove virGetDeviceID
It was only used to construct the hash key for the (now removed)
shared devices in the qemu driver.

Remove it and its mocking.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-19 13:57:59 +01:00
Ján Tomko
dbd2f26cf0 qemu: remove all use of SGIO
Now that the 'unfiltered' attribute is rejected by the validator,
remove all the code that deals with the feature.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-19 13:57:59 +01:00
Ján Tomko
f322018c23 util: remove virGetUnprivSGIOSysfsPath
unpriv_sgio was a downstream-only feature in RHEL 6-8.
The libvirt support was merged upstream by mistake.

Remove the function that constructs the sysfs path and assume it
does not exist in all the callers.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-19 13:57:59 +01:00
Ján Tomko
186aa292a0 util: openvswitch: unexport InterfaceClear{Rx,Tx}Qos
This also removes the indentation error.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-01-18 17:48:32 +01:00
Michal Privoznik
d730392293 virdnsmasq: Drop dnsmasqCapsNewFromBuffer()
The function is no longer used. Remove it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2022-01-18 16:18:57 +01:00
Peter Krempa
717f1cc4d1 virDomainSnapshotRedefinePrep: Don't do partial redefine
'virDomainSnapshotRedefinePrep' does everything needed for a redefine
when the snapshot exists but not when we are defining metadata for a new
snapshot. This gives us weird semantics.

Extract the code for replacing the definition of an existing snapshot
into a new helper 'virDomainSnapshotReplaceDef' and refactor all
callers.

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