Commit Graph

31060 Commits

Author SHA1 Message Date
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
Kristina Hanicova
eabb73eba2 conf: virnwfilterbindingdef: add validation against schema in create
We need to validate the XML against schema if option '--validate'
was passed to the virsh command. This patch also includes
propagation of flags into the virNWFilterBindingDefParse().

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
Kristina Hanicova
e21448e830 api: add virNWFilterBindingCreateFlags
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
Kristina Hanicova
652147d0e1 bridge_driver: allow VIR_NETWORK_PORT_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
Kristina Hanicova
c2652059d6 conf: virnetworkportdef: add validation against schema in network port create
We need to validate the XML against schema if option '--validate'
was passed to the virsh command. This patch also includes
propagation of flags into the virNetworkPortDefParse().

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
Kristina Hanicova
c499b09e91 api: add VIR_NETWORK_PORT_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
Michal Privoznik
5599dc547e qemu_driver: Don't check for g_strdup_printf() retval
The g_strdup_printf() function can't fail really. There's no need
to check for its return value.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-09-06 16:20:38 +02:00
Michal Privoznik
1c2b96c206 qemu_driver.c: Fix file mode
In the previous commit I accidentally changed the mode of
qemu_driver.c file. Restore the original mode.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-06 13:45:22 +02:00
Lei Yang
d34640b0c0 qemu: fix iothread residual when qemuProcessSetupIOThread failed
In process of iothread hotplug, qemuDomainHotplugAddIOThread() calls
qemuProcessSetupIOThread(). When qemuProcessSetupIOThread() returned
a failure, only the cgroup directory 'iothread' was cleaned up within
the function. Right after that qemuDomainHotplugAddIOThread() would
return failure directly without rolling back the livedef and iothread
process that created previously.

Further, when 'virsh schedinfo domain --live' requires schedinfo of
such machine, the interface will always return a failure print as
follows: 'Failed to create v1 controller cpu for group: No such file
or directory'. The reason is qemuGetIOThreadsBWLive() using member
vm->def->iothreadids[0]->iothread_id to findout the corresponding
cgroup dircetory. In case mentioned previously, iothreadids[0] was not
been cleaned up while whose cgroup directroy has already been removed.

This patch rolls back the livedef and iothread process after
qemuProcessSetupIOThread() returned a failure. Of course we are not
limited to this function, we also perform the same rolling back after
any exception proecss in qemuDomainHotplugAddIOThread().

Signed-off-by: Lei Yang <yanglei209@huawei.com>
Signed-off-by: Wang Xin <wangxinxin.wang@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-06 13:42:01 +02:00
Masayoshi Mizuma
131fddd429 qemuValidateDomainDeviceDefDiskTransient: Validate that qemu doesn't terminate early
Setup of a disk with <transient shareBacking='yes'/> option issues a
reset of qemu. In cases when QEMU didn't yet support the 'set-action'
QMP libvirt would in certain cases setup the commandline without
'-no-shutdown' which caused qemu to exit during startup. Forbid this
specific scenario.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-09-06 11:13:06 +02:00
Masayoshi Mizuma
a2e6039cca qemu: process: Split out logic for setting the 'allowReboot' internal flag
Split out the logic which was used to determine whether qemu should
allow the guest OS to reboot for QEMU versions which don't support the
'set-action' QMP command.

Signed-off-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-09-06 11:13:06 +02:00
Daniel P. Berrangé
88c5b9f827 qemu, xen: add missing deps on virtlockd/virtlogd sockets
The QEMU driver uses both virtlogd and virtlockd, while the Xen driver
uses virtlockd. The libvirtd.service unit contains deps on the socket
units for these services, but these deps were missed in the modular
daemons. As a result the virtlockd/virtlogd sockets are not started
when the virtqemud/virtxend daemons are started.

Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-08-31 13:40:33 +01:00
Jim Fehlig
2e8ebfe3fa qemu: Set label on vhostuser net device when hotplugging
Attaching a newly created vhostuser port to a VM fails due to an
apparmor denial

internal error: unable to execute QEMU command 'chardev-add': Failed
to bind socket to /run/openvswitch/vhu838c4d29-c9: Permission denied

In the case of a net device type VIR_DOMAIN_NET_TYPE_VHOSTUSER, the
underlying chardev is not labeled in qemuDomainAttachNetDevice prior
to calling qemuMonitorAttachCharDev.

A simple fix would be to call qemuSecuritySetChardevLabel using the
embedded virDomainChrSourceDef in the virDomainNetDef vhostuser data,
but this incurs the risk of incorrectly restoring the label. E.g.
consider the DAC driver behavior with a vhostuser net device, which
uses a socket for the chardev backend. The DAC driver uses XATTRS to
store original labelling information, but XATTRS are not compatible
with sockets. Without the original labelling information, the socket
labels will be restored with root ownership, preventing other
less-privileged processes from connecting to the socket.

This patch avoids overloading chardev labelling with vhostuser net
devices by introducing virSecurityManager{Set,Restore}NetdevLabel,
which is currently only implemented for the apparmor driver. The
new APIs are then used to set and restore labels for the vhostuser
net devices.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-26 16:06:45 -06:00
Pavel Hrdina
3796e8e1ff src: fix generation of default resource partition
Now that resource structure can have appid as well we need to adapt code
that creates default resource partition if not provided by user.
Otherwise starting a VM with appid defined would fail with following
error:

    error: unsupported configuration: Resource partition '(null)' must start with '/'

Fixes: 38b5f4faab
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-26 18:25:29 +02:00
Michal Privoznik
cb50dc0ecb virscsi: Drop @tmp from virSCSIDeviceListDel
Clang on Rawhide started to complain that @tmp variable in
virSCSIDeviceListDel() is set but not used. This is obviously a
false positive because the variable is used to free device stolen
from the list. Anyway, we can do without the variable so in this
specific case let's fix our code to appease Clang.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-08-26 09:16:44 +02:00
Michal Privoznik
8340ce57b4 virpci: Clarify lifetime of temporary object
The virPCIDeviceIsBehindSwitchLackingACS() function checks
whether given PCI device is not behind a switch that lacks ACS.
It does so by starting at given device and traversing up, one
parent at time towards the root. The parent device is obtained
via virPCIDeviceGetParent() which allocates new virPCIDevice
structure. For freeing the structure we use g_autoptr() and a
temporary variable @tmp. However, Clang fails to understand our
clever algorithm and complains that the variable is set but never
used. This is obviously a false positive, but using a small trick
we can shut Clang up.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-08-26 09:16:44 +02:00
Peter Krempa
97e4fb3c10 qemu: snapshot: Translate 'volume' disks before attempting offline snapshot manipulation
When the VM is inactive the 'virStorageSource' struct doesn't have the
necessary data pointing to the actual storage. This is a problem for
inactive snapshot operations on VMs which use disk type='volume'.

Add the translation steps for reversion and deletion of snapshots.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1977155
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/202
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-08-25 15:48:25 +02:00
Peter Krempa
9eef395fcc qemu: process: Ignore 'RESET' event during startup
In cases when we are adding a <transient/> disk with sharing backend
(and thus hotplugging it) we need to re-initialize ACPI tables so that
the VM boots from the correct device.

This has a side-effect of emitting the RESET event and forwarding it to
the clients which is not correct.

Fix this by ignoring RESET events during startup of the VM.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-25 15:32:45 +02:00
Peter Krempa
526cff4f03 qemuDomainSetLifecycleAction: Properly update 'onReboot' action in qemu
When qemu supports 'set-action' command we can update what happens on
reboot. Additionally we can fully relax the checks as we now properly
update the lifecycle actions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-25 15:32:45 +02:00
Peter Krempa
3061f8f9cb qemu: process: Don't set 'allowReboot' when qemu supports 'set-action'
We don't use the value of the flag when the new handling is in place so
we don't have to initialize it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-25 15:32:45 +02:00
Peter Krempa
b67e450a5a qemu: command: Always use '-no-shutdown'
The '-no-shutdown' flag prevents qemu from terminating if a shutdown was
requested. Libvirt will handle the termination of the qemu process
anyways and using this consistently will allow greater flexibility for
the virDomainSetLifecycleAction API as well as will allow using
the 'system-reset' QMP command during startup to reinitiate devices
exported to the firmware.

This efectively partially reverts 0e034efaf9

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-25 15:32:45 +02:00