Commit Graph

31080 Commits

Author SHA1 Message Date
Kristina Hanicova
d0c80da88a api: add virNetworkCreateFlags
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-16 16:26:18 +02:00
Kristina Hanicova
00182251d0 src: add driver support for networkCreateXMLFlags()
I added new driver functions to handle creating network with
given flags. I also replaced definitions of the functions without
flags with function calls to the new ones.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-16 16:26:18 +02:00
Kristina Hanicova
6a0a2840cf api: add public virNetworkCreateXMLFlags() and remote protocol
This new API creates network with given flags.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-16 16:26:18 +02:00
Laine Stump
ddba9f1dc9 conf: log error on attempts to modify ACPI index of active device
The ACPI index of a device in a running guest can't be modified, and
libvirt doesn't actually attempt to modify it, but it was possible for
a user to request such a modification, and libvirt wouldn't complain,
thus misleading the user into thinking that it had actually been changed.

Resolves: https://bugzilla.redhat.com/1998920

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-16 09:29:24 -04:00
Laine Stump
cf916af4a1 conf: reformat virDomainDefCompatibleDevice for upcoming additional check
The next patch will add another check similar to the existing check
for a change in alias name. This patch reformats the code in
preparation so that the next patch's purpose will be clear.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-16 09:29:24 -04:00
Michal Privoznik
306a1ee685 qemu: Fix typo in qemuBuilNumaCellCache
The function should be named qemuBuildNumaCellCache (note the
missing 'd' in Build).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-16 08:45:48 +02:00
Peter Krempa
3a90cb03ee qemu: validate: Allow 'preserve' action for on_crash lifecycle action
In fact keeping the VM around for debugging is a desirable configuration
and actually the implementation has no code as we keep the VM around.

Remove the validation and add a note that it's actually used.

Fixes: b1b85a475f
Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Acked-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
2021-09-15 14:40:51 +02:00
Nick Chevsky
dbc605d8d9 qemu_tpm: Start swtpm(8) daemon with --terminate switch
Launch swtpm(8) with the --terminate switch, which guarantees that
the daemon will shut itself down when QEMU dies (current behavior).
We had so far been getting this "for free" (i.e. without --terminate)
due to a defect in upstream's connection handling logic [1], on which
libvirt should not rely since it will eventually be fixed. Adding
--terminate preserves and guarantees the current behavior.

[1] https://github.com/stefanberger/swtpm/pull/509

Signed-off-by: Nick Chevsky <nchevsky@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-15 09:54:06 +02:00
Michal Privoznik
757ed5b09c node_device_conf: Don't prealloc @vfs in virNodeDeviceGetPCISRIOVCaps()
The array of virtual functions @vfs in
virNodeDeviceGetPCISRIOVCaps() is allocated twice: the first time
during its declaration and the second time inside
virPCIGetVirtualFunctions() which leads to a memleak:

==16691== 1,128 bytes in 47 blocks are definitely lost in loss record 1,771 of 1,803
==16691==    at 0x4844CC1: calloc (vg_replace_malloc.c:1117)
==16691==    by 0x4E50070: g_malloc0 (in /usr/lib64/libglib-2.0.so.0.6800.3)
==16691==    by 0x4A7B034: virNodeDeviceGetPCISRIOVCaps (node_device_conf.c:2649)
==16691==    by 0x4A7B5E2: virNodeDeviceGetPCIDynamicCaps (node_device_conf.c:2762)
==16691==    by 0xA7F6E18: udevProcessPCI (node_device_udev.c:418)

Fixes: c97518d9b8
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-15 08:41:06 +02:00
Jonathon Jongsma
24ffeef09c nodedev: Implement virNodeDeviceIsPersistent()/IsActive()
Implement these new API functions in the nodedev driver.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-14 14:25:55 -05:00
Jonathon Jongsma
6d0b85d792 api: add virNodeDeviceIsPersistent()/IsActive()
These two public APIs are implemented for almost all other objects that
have a concept of persistent definition and activatability. Now that we
have node devices (mdevs) that can be defined and inactive, it will be
useful to query the persistent/active state of node devices as well.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-14 14:25:10 -05:00
Jonathon Jongsma
dc60f91530 nodedev: implement virNodeDevice(Get|Set)Autostart()
Implement autostart functionality for mediated devices.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-14 14:24:00 -05:00
Jonathon Jongsma
c6607a25b9 api: add virNodeDevice(Get|Set)Autostart()
This will allow persistent mediated devices to be configured to be
restarted automatically when the host reboots.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-14 14:22:51 -05:00
Jim Fehlig
51eb680b26 libxl: Don't autostart domains on driver reload
When libxlAutostartDomain was introduced with commit fb92307f0d, one hunk
mistakenly added a call site in libxlStateReload. Domains should not be
autostarted when reloading the driver, so remove the offending hunk.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-14 11:37:35 -06:00
Jim Fehlig
65fab900c5 libxl: Fix driver reload
On reload, the libxl driver calls virDomainObjListLoadAllConfigs to load
all configs from /etc/libvirt/libxl/ but incorrectly passes 'true' for
the liveStatus parameter, resulting in error messages such as

libvirtd[21053]: XML error: unexpected root element <domain>, expecting <domstatus>
libvirtd[21053]: Failed to load config for domain 'sles15sp3'

Fix by not requesting live status when re-reading the persistent VM config
files.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-14 11:04:46 -06:00
Jim Fehlig
b75a16ae5e libxl: Improve reporting of die_id in capabilities
On Xen, libvirt runs in a VM (typically dom0) and does not have an accurate
picture of numa and cpu topology of the underlying physical machine using
the "usual" mechanisms. numa info and cpu toplogy are retrieved from libxl
and used to populate the libvirt conterparts. Commit 7b79ee2f78 introduced
support for reporting die_id in capabilities, but did not account for
special handling of numa and cpu topology in libxl.

Currently, Xen does not report die_id in the libxl_cputopology structure.
In the meantime, set die_id to 0, which was suggested by the Xen developers
and is slightly better than random garbage such as

<cpu id='1' socket_id='0' die_id='-1073069552' core_id='0' siblings='0-1'/>

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-14 11:02:26 -06:00
Kristina Hanicova
3e4f4c2eec src: network_conf: propagate only bool to virNetworkDefParseString()
We don't need to propagate all public flags, only the information
about the presence of the validation one, which can differ from
function to function. This patch makes it easier and more
readable in case of a future additions of validation flags.
This change was suggested by Daniel.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-10 17:38:06 +02:00
Peter Krempa
7e23272e35 qemuDomainChangeDiskLive: Modify 'startupPolicy' before changing source
We don't support all startup policies with all source types so to
correctly allow switching from a 'file' based cdrom with 'optional'
startup policy to a 'block' based one which doesn't support optional we
must update the startup policy field first. Obviously we need to have
fallback if the update fails.

Reported-by: Vojtech Juranek <vjuranek@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-10 16:55:33 +02:00
Peter Krempa
526f2900bc qemuProcessQMPInit: Use long options for '-qmp' when probing qemu.
'-qmp' in this case behaves the same as '-chardev' so it should have
been converted the same way as others were in 43c9c0859f since
short options are deprecated.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-10 15:18:48 +02:00
Michal Privoznik
4c910519c5 libvirt-domain.c: Fix typo in virDomainAttachDevice doc
In the documentation to virDomainAttachDevice() we refer to a
non-existent virDomainUpdateDeviceFlag() function. The correct
name is virDomainUpdateDeviceFlags().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-10 11:09:27 +02:00
Ján Tomko
a26df27662 conf: add cleanup func for virMacMap
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2021-09-09 18:06:13 +02:00
Ján Tomko
a9ce03636c conf: add cleanup func for virNetworkXMLOption
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2021-09-09 18:06:13 +02:00
Daniel P. Berrangé
69254cafa0 qemu: stop probing for '-device sga' support
Since we no longer use '-device sga' we can stop probing for this device
in our capabilities code.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-09 16:17:30 +01:00
Daniel P. Berrangé
40dfef297a qemu: switch to use -M graphics=off instead of -device sga
SeaBIOS >= 1.11 has built-in support for outputting to the serial
console when QEMU sets -M graphics=off. Our minimum QEMU version
is 2.11.0, which bundled SeaBIOS 1.11. Thus we have no need to
use '-device sga' anymore.

This change results in a slight layout difference for option ROMs
in memory, however, it does not affect the migration data stream
format on the wire and once migration is complete the target QEMU
memory layout for ROMs matches the source QEMU once again.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-09 16:17:30 +01:00
Daniel P. Berrangé
58dfbca51d qemu: tweak error message to be more general purpose
The BIOS serial console output is currently implemented using the QEMU
'sga' device, but this is going to change in future patches, so the
error message ought to be more generically phrased.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-09 16:17:30 +01:00
Daniel P. Berrangé
c82726a460 qemu: prevent use of <bios useserial='yes'> on non-x86 arches
The <bios useserial='yes'> config results in use of the '-device sga'
QEMU options. This in turn causes QEMU go load the sgabios.bin option
ROM, which contains x86 machine code. This cannot work on non-x86
arches, thus we should block the bad config.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-09-09 16:17:30 +01:00
William Douglas
c88b26a656 ch_driver: Handle validation failure correctly
When validation like deviceValidateCallback fails, the vm will not be
set and so the call to virDomainObjListRemove will be passed a NULL
pointer causing a segfault. To prevent this add a check that the vm is
defined before calling out to virDomainObjListRemove.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
d4f047dbd1 ch_driver: Add handler for console API
Enable the handler function to find and open the console character
device that will be used by the console API.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
6a77dd2b67 ch_domain: Allow controller and chr devices
With the console and serial device handling fully functional, allow
the required device types to be specified in the domain
configuration.

The configuration only supports a single serial or console device.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
d79b9a5a17 ch_process: Handle enabled console devices
Add functionality to allow libvirt console to connect to the
cloud-hypervisor created PTY associated with a VM by updating the
domain with console path information. This has to be run after the VM
is created by cloud-hypervisor.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
93accefd9e ch_monitor: Add pty json builder function
Add function to build the the json structure to configure a PTY in
cloud-hypervisor.

The devices themselves still aren't allowed in configurations yet
though.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
3b164e6897 ch_monitor: Make virCHMonitorGet function static
The virCHMonitorGet function isn't going to be used outside of the
monitor, so remove the initial declaration and define the function
to be static.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
14da5cb95a ch_monitor: Use virCHMonitorGet to access cloud-hypervisor API
Now that virCHMonitorGet is capable of handling data returned by the
cloud-hypervisor API, make use of this via virCHMonitorGetInfo to call
into the vm.info endpoint.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
e727cc8041 ch_monitor: Update virCHMonitorGet to handle accept a response
The virCHMonitorGet function needed to be able to return data from the
hypervisor. This functionality is needed in order for the driver to
support PTY enablement and getting details about the VM state.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
William Douglas
f84286c0b3 ch_domain: Add virChrdevs for console support
Add and initialize a virChrdevs to the _virCHDomainObjPrivate
structure in order to eventually track the consoles in use by a domain.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: William Douglas <william.douglas@intel.com>
2021-09-09 14:51:02 +01:00
Peter Krempa
0404d4fc38 virDomainDiskDefValidate: Move validation of disk target
The disk target is mandatory and used as a designator in error messages
of other validation steps, so we must validate it first.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-09 10:17:28 +02:00
Peter Krempa
cf6b34c683 conf: Don't call 'virDomainDiskDefAssignAddress' when disk->dst is NULL
The code rejecting a XML when the disk target is missing was moved to
the validation code which goes after post parse. One of the cases in the
disk post parse code didn't check whether 'disk->dst' is set which at
that point isn't guaranteed.

Fixes: 61fd7174c2
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2001627
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-09 10:17:28 +02:00
Peter Krempa
002de683c6 conf: validate: Run global device definition validation before callbacks
The validation infrastructure doesn't modify the definition and
additionally it makes sense to run the global code first as it's
validating certain corner cases.

The changed error messages from qemuxml2argvtest show that this is
indeed the proper ordering as all changed messages are actually better
describing the error.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-09 10:17:28 +02:00
Peter Krempa
7dee442677 conf: validate: Move qemu-specific LUN disk validation to global validation
LUN disks are supported only by VMX and QEMU drivers and the VMX
implementation is a subset of qemu's implementation, thus we can move
the qemu-specific validator to the global validation code providing that
we allow the format to be 'none' (qemu driver always sets 'raw' if it's
not set) and allow disk type 'volume' as a source (qemu always
translates the source, and VMX doesn't implement 'volume' at all).

Moving the code to the global validation allows us to stop calling it
from the qemu specific validation and also deduplicates the checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-09 10:17:28 +02:00
Peter Krempa
5ccb39616f qemuDomainDefValidateDiskLunSource: Unbreak error messages
Simplify looking for the error messages.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-09 10:17:28 +02:00
Ján Tomko
fa8ce012a3 libxl: use g_auto in libxlDomainGetEmulatorType
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
d6cd7a478f libxl: use g_auto in libxlCapsNodeData
Also remove pointless labels.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
3e4c5e20b8 libxl: refactor libxlCapsInitCPU
Use g_auto, g_steal_pointer and remove unnecessary labels.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
5f5d698053 libxl: capsInitCPU: fail if we can't initialize host features
Introduced by:
  commit 17322e5518
      libxl: describe host cpu features based on hwcaps
with the justification that libxl_hwcaps does not have a stable
format across all version.

Even though the code would return '0' in the case of such failure,
it frees the 'cpu' pointer, while keeping it in caps->host.
Based on that, assume it does not happen in current usage.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
6b08d4b37d libxl: remove enum libxlHwcapVersion
As well as the code probing for the version in libxlCapsInitHost.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
a8328f5222 libxl: capabilities: assume Xen version >= 4.7
Remove the code handling old Xen's hwcap words,
as well as the comment describing it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
eec09bcae6 rpc: mark source returned by virEventGLibAddSocketWatch as unused
Two users of virEventGLibAddSocketWatch care about the GSource
it returns.

The other three free it by assigning it to an autofreed variable.

Mark them with G_GNUC_UNUSED to make this obvious to the reader
and the compiler.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
a082c46229 util: virIdentitySetCurrent: only unref the old identity on success
In the unlikely case that we were unable to set the new
identity, we would unref the old one even though it still
could be in the thread-local storage.

Fixes: c6825d8813
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-08 16:19:55 +02:00
Ján Tomko
09b08e9a80 qemu: remove unused 'cfg' variables
Unused as of:
  commit effeee5c2f
      qemu: driver: Use 'qemuDomainSaveStatus' for saving status XML

This function extracts the config from the vm object, so the caller
no longer needs to do it.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-08 16:19:55 +02:00
Kristina Hanicova
39f835621a nwfilter_driver: allow VIR_NWFILTER_BINDING_CREATE_VALIDATE flag
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>
2021-09-06 17:08:59 +02:00