Commit Graph

2249 Commits

Author SHA1 Message Date
Michal Privoznik
03ba98b259 numa_conf: Expose virNumaCache formatter
Expose virNumaCache XML formatter so that it can be re-used by
other parts of the code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-06-15 10:41:22 +02:00
Michal Privoznik
b0b7554229 numa_conf: Rename virDomainCache* to virNumaCache*
There's nothing domain specific about NUMA memory caches. Rename the
virDomainCache* structures and enums to virNumaCache*.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-06-15 10:41:22 +02:00
Jonathon Jongsma
70f53b1c04 nodedev: Revert auto-start property for mdevs
We supported autostart of node devices via an xml element, but this
is not consistent with other libvirt objects which use an explicit API
for setting autostart status. So revert this and implement it as an
official API in a future commit.

The initial support was refactored after merging, so this commit reverts
both of those previous commits.

Revert "virNodeDevCapMdevParseXML: Use virXMLPropEnum() for ./start/@type"
This reverts commit 9d4cd1d1cd.

Revert "nodedev: support auto-start property for mdevs"
This reverts commit 42a5585499.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-05-27 15:38:28 +02:00
Laine Stump
a52b74e7a3 conf: new function virDomainNetRemoveByObj()
virDomainNetRemove() requires the index of the net device you want to
remove from the list, but in some cases you may not have the index
handy, only the object itself (or the object may not have been added
to the domain's list). virDomainNetRemoveByObj() first tries to find
the given object in the nets list, and deletes that if it is found.

As with virDomainNetRemove() it always unconditionally tries to remove
the device from the hostdevs list (in case it is the ridiculous
combined net+hostdev device created for <interface type='hostdev'>).

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-05-25 10:08:00 -04:00
Michal Privoznik
c380ae220e virxml: Introduce and use virXMLFormatMetadata()
So far, we have to places where we format <metadata/> into XMLs:
domain and network. Bot places share the same code. Move it into
a helper function and just call it from those places.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-05-25 13:17:22 +02:00
Peter Krempa
02f843e70a conf: remove virDomainDiskInsertPreAlloced
Replace the last use of the function by virDomainDiskInsert and remove
the unused helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-05-24 20:38:08 +02:00
Michal Privoznik
773118632e numa_conf: Expose virNumaDistance formatter
Expose virNumaDistance XML formatter so that it can be re-used by
other parts of the code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-24 14:49:28 +02:00
Kristina Hanicova
cff0444e51 conf: Parse/format XML input type 'evdev'
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-05-21 14:29:09 +02:00
Boris Fiuczynski
42a5585499 nodedev: support auto-start property for mdevs
This adds a new element to the mdev capabilities xml schema that
represents the start policy for a defined mediated device. The actual
auto-start functionality is handled behind the scenes by mdevctl, but it
wasn't yet hooked up in libvirt.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-05-20 11:10:08 +02:00
Michal Privoznik
9e63f35247 virnuma: Export virNumaGetMaxCPUs properly
This function will be used in virnumamock, shortly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-05-17 15:54:13 +02:00
Daniel P. Berrangé
11f077e286 src: add API to determine if current identity is a system identity
This is essentially a way to determine if the current identity
is that of another libvirt daemon.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-05-13 11:07:40 +01:00
Daniel P. Berrangé
10689c16d8 util: helper to temporary elevate privileges of the current identity
When talking to the secret driver, the callers inside libvirt daemons
need to be able to run with an elevated privileges that prove the API
calls are made by a libvirt daemon, not an end user application.

The virIdentityElevateCurrent method will take the current identity
and, if not already present, add the system token. The old current
identity is returned to the caller. With the VIR_IDENTITY_AUTORESTORE
annotation, the old current identity will be restored upon leaving
the codeblock scope.

    ... early work with regular privileges ...
    if (something needing elevated privs) {
        VIR_IDENTITY_AUTORESTORE virIdentity *oldident =
	    virIdentityElevateCurrent();
	if (!oldident)
	    return -1;

        ... do something with elevated privileges ...
    }
    ... later work with regular privileges ...

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-05-13 11:07:36 +01:00
Daniel P. Berrangé
695d713df2 util: add API for copying identity objects
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-05-13 11:07:35 +01:00
Daniel P. Berrangé
cbfebfc747 util: generate a persistent system token
When creating the system identity set the system token. The system
token is currently stored in a local path

   /var/run/libvirt/common/system.token

Obviously with only traditional UNIX DAC in effect, this is largely
security through obscurity, if the client is running at the same
privilege level as the daemon. It does, however, reliably distinguish
an unprivileged client from the system daemons.

With a MAC system like SELinux though, or possible use of containers,
access can be further restricted.

A possible future improvement for Linux would be to populate the
kernel keyring with a secret for libvirt daemons to share.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-05-13 11:07:16 +01:00
Daniel P. Berrangé
d5d011f767 util: introduce concept of a system token into identities
We want a way to distinguish between calls from a libvirt daemon, and a
regular client application when both are running as the same user
account. This is not possible with the current set of attributes
recorded against an identity, as there is nothing that is common to all
of the modular libvirt daemons, while distinct to all other processes.

We thus introduce the idea of a system token, which is simply a random
hex string that is only known by the libvirt daemons, to be recorded
against the system identity.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-05-13 11:07:15 +01:00
Daniel P. Berrangé
1ca3959712 util: add virRandomToken API
A random token is simply a string of random bytes formatted in
hexidecimal.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-05-13 11:07:13 +01:00
Peter Krempa
7054465212 util: xml: Introduce virXMLPropEnumDefault
The helper is almost identical to virXMLPropEnum but it allows to pass a
default value to initialize the result to.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-05-07 10:06:18 +02:00
Peter Krempa
1ac21ab7ea util: xml: Introduce virXMLFormatElementEmpty
Add a helper which will format an XML element with attributes and
children, but compared to virXMLFormatElement it also formats an empty
element if both buffers are empty.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
Tested-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-26 17:22:30 +02:00
Tim Wiederhake
3d69665959 virxml: Add virXMLPropULongLong
Convenience function to return the value of an unsigned long long XML
attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-22 11:24:53 +02:00
Cole Robinson
f4c97327fb conf: Introduce <sandbox mode='chroot'/> for <filesystem><binary>
This adds a new XML element

<filesystem>
  <binary>
    <sandbox mode='chroot|namespace'/>
  </binary>
</filesystem>

This will be used by qemu virtiofs

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
2021-04-21 11:51:31 -04:00
Pavel Hrdina
18882ea776 virnetdev: move virNetDevSetRootQDisc to virnetdevbandwidth
The function in question uses "tc" binary so virnetdevbandwidth feels
like better place for it.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-04-21 14:19:34 +02:00
Pavel Hrdina
6df8455aac virdnsmasq: drop unused dnsmasqCapsRefresh function
Instead of removing binaryPath let's drop the function completely as
it is not used anywhere.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-04-21 14:18:14 +02:00
Pavel Hrdina
033c21a8ee virdnsmasq: drop unused dnsmasqCapsNewFromFile function
Instead of removing binaryPath let's drop the function completely as
it is not used anywhere.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-04-21 14:17:54 +02:00
Peter Krempa
fb0238414e conf: domain: Introduce virDomainDiskDefParseSource
Add a helper function which will parse the source portion of a <disk>.

The idea is to replace *virDomainDiskDefParse with
VIR_DOMAIN_DEF_PARSE_DISK_SOURCE with the new helper in the future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-19 14:43:58 +02:00
Tim Wiederhake
ab5d2776c9 virxml: Add virXMLPropEnum
Convenience function to return the value of an enum XML attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-16 13:22:32 +02:00
Tim Wiederhake
68cda45b57 virxml: Add virXMLPropUInt
Convenience function to return the value of an unsigned integer XML attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-16 13:22:11 +02:00
Tim Wiederhake
de17e0d30d virxml: Add virXMLPropInt
Convenience function to return the value of an integer XML attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-16 13:21:55 +02:00
Tim Wiederhake
8861d96c88 virxml: Add virXMLPropTristateSwitch
Convenience function to return the value of an on / off XML attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-16 13:21:27 +02:00
Tim Wiederhake
c8726ede83 virxml: Add virXMLPropTristateBool
Convenience function to return the value of a yes / no XML attribute.

Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-16 13:21:07 +02:00
Pavel Hrdina
07497fc6da vircgroupv2devices: refactor virCgroupV2DevicesRemoveProg
When running on systemd host the cgroup itself is removed by machined
so when we reach this code the directory no longer exist. If libvirtd
was running the whole time between starting and destroying VM the
detection is skipped because we still have both FD in memory. But if
libvirtd was restarted and no operation requiring cgroup devices
executed the FDs would be 0 and libvirt would try to detect them using
the cgroup directory. This results in reporting following errors:

    libvirtd[955]: unable to open '/sys/fs/cgroup/machine.slice/machine-qemu\x2d1\x2dguest.scope/': No such file or directory
    libvirtd[955]: Failed to remove cgroup for guest

When running on non-systemd host where we handle cgroups manually this
would not happen.

When destroying VM it is not necessary to detect the BPF prog and map
because the following code only closes the FDs without doing anything
else. We could run code that would try to detach the BPF prog from the
cgroup but that is not necessary as well. If the cgroup is removed and
there is no other FD open to the prog kernel will cleanup the prog and
map eventually.

Reported-by: Eric Farman <farman@linux.ibm.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Tested-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-14 12:06:16 +02:00
Tim Wiederhake
f0e1e31bf7 Remove references to deleted Makefile.am
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-04-13 11:21:00 +02:00
Peter Krempa
0dffca8f95 virCommandSetDryRun: Rework resetting of the dry run data
While virCommandSetDryRun is used in tests only, there were some cases
when error paths would not call the function with NULL arguments to
reset the dry run infrastructure.

Introduce virCommandDryRunToken type which must be allocated via
virCommandDryRunTokenNew and passed to virCommandSetDryRun.

This way we can use automatic variable cleaning to trigger the cleanup
of virCommandSetDryRun parameters and also the use of the token variable
ensures that all callers of virCommandSetDryRun clean up after
themselves and also that the token isn't left unused in the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-04-12 15:55:10 +02:00
Peter Krempa
2116063791 virCommandToString: Allow stripping command path
In tests we don't want to use the full path to commands as it's
unpleasant to keep that working on all systems.

Add an integrated way to strip the prefix which will be used to replace
virTestClearCommandPath() as a more systemic solution.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-04-12 15:55:10 +02:00
Peter Krempa
0a6f02de70 util: virstring: Remove the virStringSplitCount wrapper funcion
Callers which need the count of elements now count it in place.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:10 +02:00
Peter Krempa
b2c2de01dc Remove virStorageFileCanonicalizePath
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Peter Krempa
218ddd60e7 Remove virStorageSourceGetUniqueIdentifier file backend API
The API isn't used any more.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Peter Krempa
51221af10e util: json: Remove virJSONValueNewArrayFromBitmap
The function is used only inside of the file. We can open-code it and
remove it as it's not very useful.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-04-12 14:59:29 +02:00
Peter Krempa
f55031535c util: json: Remove virJSONValueGetArrayAsBitmap
The function is not used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-04-12 14:59:29 +02:00
Jonathon Jongsma
00b649d0cf nodedev: add helper functions to remove node devices
When a mediated device is stopped or undefined by an application outside
of libvirt, we need to remove it from our list of node devices within
libvirt. This patch introduces virNodeDeviceObjListRemoveLocked() and
virNodeDeviceObjListForEachRemove() (which are analogous to other types
of object lists in libvirt) to facilitate that. They will be used in
coming commits.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-04-07 15:08:59 -05:00
Jonathon Jongsma
d4375403ff nodedev: add persistence to virNodeDeviceObj
Consistent with other objects (e.g. virDomainObj), add a field to
indicate whether the node device is persistent or transient.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-04-07 15:07:45 -05:00
Jonathon Jongsma
b7a823177b nodedev: introduce concept of 'active' node devices
we will be able to define mediated devices that can be started or
stopped, so we need to be able to indicate whether the device is active
or not, similar to other resources (storage pools, domains, etc.)

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-04-07 15:03:34 -05:00
Tim Wiederhake
a839fcbe62 cpu: Introduce virCPUCheckForbiddenFeatures
Signed-off-by: Tim Wiederhake <twiederh@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com
2021-03-26 11:40:52 +01:00
Laine Stump
43d8d16161 conf: new function virDomainDefHasVDPANet()
This function returns true if the domain has any interfaces that are
type='vdpa'.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-03-24 15:06:08 -04:00
Peter Krempa
4f33b817b2 qemu: command: Use JSON for QAPIfied -object directly
Skip the lossy conversion to legacy commandline arguments by using the
JSON props directly when -object is QAPIfied. This avoids issues with
conversion of bitmaps and also allows validation of the generated JSON
against the QMP schema in the tests.

Since the new approach is triggered by a qemu capability the code
from 'virQEMUBuildObjectCommandlineFromJSON' in util/virqemu.c was moved
to 'qemuBuildObjectCommandlineFromJSON' in qemu/qemu_command.c which has
the virQEMUCaps type.

Some functions needed to be modified to propagate qemuCaps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-03-23 14:06:31 +01:00
Daniel P. Berrangé
695bdb3841 src: ensure GSource background unref happens in correct event loop
The g_idle_add function adds a callback to the primary GMainContext.

To workaround the GSource unref bugs, we need to add our callbacks
to the GMainContext that is associated with the GSource being
unref'd. Thus code using the per-VM virEventThread must use its
private GMainContext.

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-03-17 09:16:05 +00:00
Peter Krempa
d380dd0efd util: virstring: Remove virStrncpy
The function is now unused and motivated users to write crazy parsers
which were hard to understand, had pointless error paths just to avoid
few memory allocations.

Remove the function as we're fine with g_strndup and virStrcpy.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-03-12 10:57:42 +01:00
Daniel P. Berrangé
46b77b3e6a conf: introduce support for common audio settings
This introduces support for the QEMU audio settings that are common to
all audio backends. These are expressed in the QAPI schema as settings
common to all backends, but in reality some backends ignore some of
them. For example, some backends are output only. The parser isn't
attempting to apply restrictions that QEMU itself doesn't apply.

    <audio id='1' type='pulseaudio'>
      <input mixingEngine='yes' fixedSettings='yes' voices='1' bufferLength='100'>
        <settings frequency='44100' channels='2' format='s16'/>
      </input>
      <output mixingEngine='yes' fixedSettings='yes' voices='2' bufferLength='100'>
        <settings frequency='22050' channels='4' format='f32'/>
      </output>
    </audio>

The <settings> child is only valid if fixedSettings='yes'

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-03-09 22:58:39 +00:00
Daniel P. Berrangé
6be99c99c5 qemu: support use of <audio> elements
Currently the QEMU driver secretly sets the QEMU_AUDIO_DRV env variable
depending on how <graphics> are configured.

This introduces support for configuring audio backends from the <audio>
elements in the XML config.

The existing default behaviour is now only used if no <audio> element is
present.

All except the 'jack' audio driver are supported via QEMU's old env
variable config.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-03-09 22:58:26 +00:00
Daniel P. Berrangé
efdab67f44 conf: rename and improve virDomainDefFindAudioForSound
The virDomainDefFindAudioForSound only takes a virDomainSoundDefPtr as
its arg, but we want to use the same functionality for VNC graphics.
In addition if audio ID is zero, then we want to return the first
available audio backend.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-03-09 22:58:23 +00:00
Daniel P. Berrangé
657999b04f conf: add helper to test for sound device codec support
The check for ICH6 || ICH9 is repeated in many places in the code. The
new virDomainSoundModelSupportsCodecs() method provides a helper to
standardize this check.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-03-09 22:58:04 +00:00