]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
3 years agoqemu: validate: Move disk address validation code
Peter Krempa [Mon, 4 Oct 2021 12:44:09 +0000 (14:44 +0200)]
qemu: validate: Move disk address validation code

Move the code from 'qemuValidateDomainDeviceDefDiskFrontend' into
'qemuValidateDomainDeviceDefAddressDrive' which is called from
'qemuValidateDomainDeviceDefAddress' so that we have all address
validation code together.

This also allows us to remove the inline validation inside
'qemuBuildSCSIHostdevDevStr'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildDeviceAddressProps: Format also 'drive' addresses
Peter Krempa [Mon, 4 Oct 2021 08:59:58 +0000 (10:59 +0200)]
qemuBuildDeviceAddressProps: Format also 'drive' addresses

Introduce infrastructure to format 'drive' addresses via the standard
helper rather than hand-rolled generators used inline.

The code needs to know the disk bus to format the correct address which
is passed in via an internal field in virDomainDeviceDriveAddress.

The field types according to QEMU are as following:

'ide-hd' for VIR_DOMAIN_DISK_BUS_IDE and VIR_DOMAIN_DISK_BUS_SATA
  unit=<uint32>          -  (default: 4294967295)

'floppy' for VIR_DOMAIN_DISK_BUS_FDC
  unit=<uint32>          -  (default: 4294967295)

'scsi-hd' for VIR_DOMAIN_DISK_BUS_SCSI
  channel=<uint32>       -  (default: 0)
  scsi-id=<uint32>       -  (default: 4294967295)
  lun=<uint32>           -  (default: 4294967295)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildPCIHostdevDevProps: Move 'failover_pair_id' property before address
Peter Krempa [Wed, 6 Oct 2021 15:04:48 +0000 (17:04 +0200)]
qemuBuildPCIHostdevDevProps: Move 'failover_pair_id' property before address

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildHostdevCommandLine: Format PCI host devices via JSON
Peter Krempa [Fri, 1 Oct 2021 20:28:59 +0000 (22:28 +0200)]
qemuBuildHostdevCommandLine: Format PCI host devices via JSON

For properties we use these are the QEMU types:
  host=<str>             - Address (bus/device/function) of the host device, example: 04:10.0
  bootindex=<int32>
  failover_pair_id=<str>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuCommandAddExtDevice: Generate via JSON
Peter Krempa [Fri, 1 Oct 2021 12:07:37 +0000 (14:07 +0200)]
qemuCommandAddExtDevice: Generate via JSON

Generate the 'zpci' device via JSON.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildInputCommandLine: Generate via JSON
Peter Krempa [Fri, 1 Oct 2021 11:16:15 +0000 (13:16 +0200)]
qemuBuildInputCommandLine: Generate via JSON

For 'usb-mouse'/'usb-tablet'/'usb-kbd' we don't use any special
property.

For 'virtio-input-pci' we only use the 'evdev' argument which is a
string so this conversion doesn't impact anything.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildRedirdevCommandLine: Generate via JSON
Peter Krempa [Fri, 1 Oct 2021 10:58:40 +0000 (12:58 +0200)]
qemuBuildRedirdevCommandLine: Generate via JSON

The 'usb-redir' device has the following types according to QEMU for
properties we control:

  chardev=<str>          - ID of a chardev to use as a backend
  filter=<str>
  bootindex=<int32>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildHostdevMediatedDevProps: Format USB host devices via JSON
Peter Krempa [Fri, 1 Oct 2021 09:24:04 +0000 (11:24 +0200)]
qemuBuildHostdevMediatedDevProps: Format USB host devices via JSON

The 'usb-host' device has the following types according to QEMU for
properties we control:

  hostdevice=<str>
  hostbus=<uint32>       -  (default: 0)
  hostaddr=<uint32>      -  (default: 0)
  bootindex=<int32>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildHostdevMediatedDevProps: Move 'ramfb' and 'bootindex' before the address
Peter Krempa [Wed, 6 Oct 2021 14:36:41 +0000 (16:36 +0200)]
qemuBuildHostdevMediatedDevProps: Move 'ramfb' and 'bootindex' before the address

Simplify the generator by moving few properties earlier.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildHostdevCommandLine: Build mediated device commandline via JSON
Peter Krempa [Fri, 1 Oct 2021 08:17:01 +0000 (10:17 +0200)]
qemuBuildHostdevCommandLine: Build mediated device commandline via JSON

The 'vfio-pci-nohotplug' device has the following property types
according to QEMU:

  display=<OnOffAuto>    - on/off/auto (default: "off")
  sysfsdev=<str>
  ramfb=<bool>
  bootindex=<int32>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildRNGCommandLine: Generate via JSON
Peter Krempa [Thu, 30 Sep 2021 16:07:29 +0000 (18:07 +0200)]
qemuBuildRNGCommandLine: Generate via JSON

The 'virtio-rng' has the following property types according to QEMU:
  rng=<link<rng-backend>>
  max-bytes=<uint64>     -  (default: 9223372036854775807)
  period=<uint32>        -  (default: 65536)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildMemballoonCommandLine: Reorder properties
Peter Krempa [Wed, 6 Oct 2021 14:18:37 +0000 (16:18 +0200)]
qemuBuildMemballoonCommandLine: Reorder properties

Move the 'deflate-on-oom' and 'free-page-reporting' before the address
to simplify the genrator code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildMemballoonCommandLine: Generate via JSON
Peter Krempa [Thu, 30 Sep 2021 15:55:49 +0000 (17:55 +0200)]
qemuBuildMemballoonCommandLine: Generate via JSON

The generated properties have the following types according to QEMU:
  deflate-on-oom=<bool>  - on/off (default: false)
  free-page-reporting=<bool> - on/off (default: false)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildShmemCommandLine: Generate via JSON
Peter Krempa [Mon, 27 Sep 2021 17:26:32 +0000 (19:26 +0200)]
qemuBuildShmemCommandLine: Generate via JSON

Note that the legacy 'ivshmem' device was already removed upstream, but
it's converted so that the code is identical.

For the two modern devices QEMU considers the properties being of
following types:

'ivshmem-doorbell'
  chardev=<str>          - ID of a chardev to use as a backend
  ioeventfd=<bool>       - on/off (default: true)
  master=<OnOffAuto>     - on/off/auto (default: "off")
  vectors=<uint32>       -  (default: 1)

'ivshmem-plain'
  master=<OnOffAuto>     - on/off/auto (default: "off")
  memdev=<link<memory-backend>>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildMemoryDeviceCommandLine: Generate via JSON
Peter Krempa [Mon, 27 Sep 2021 16:44:28 +0000 (18:44 +0200)]
qemuBuildMemoryDeviceCommandLine: Generate via JSON

This includes the 'pc-dimm', 'nvdimm', 'virtio-pmem-pci' and
'virtio-mem-pci' devices.

The value types according to QEMU are:

'pc-dimm'
  node=<uint32>          -  (default: 0)
  memdev=<link<memory-backend>>

'nvdimm'
  label-size=<int>
  memdev=<link<memory-backend>>
  node=<uint32>          -  (default: 0)
  unarmed=<bool>         -  (default: false)
  uuid=<QemuUUID>

'virtio-pmem-pci'
  memdev=<link<memory-backend>>

'virtio-mem-pci'
  block-size=<size>
  memdev=<link<memory-backend>>
  node=<uint32>          -  (default: 0)
  requested-size=<size>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildWatchdogCommandLine: Generate via JSON
Peter Krempa [Mon, 27 Sep 2021 12:37:48 +0000 (14:37 +0200)]
qemuBuildWatchdogCommandLine: Generate via JSON

The watchdog doesn't have any special properties.

Convert the command line generator and hotplug code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildPanicCommandLine: Generate via JSON
Peter Krempa [Fri, 26 Mar 2021 09:09:45 +0000 (10:09 +0100)]
qemuBuildPanicCommandLine: Generate via JSON

Format a JSON object with the device properties and then use
qemuBuildDeviceCommandlineFromJSON to convert it to the standard
commandline for now.

The 'ioport' property of 'pvpanic' is a number in QEMU:
  ioport=<uint16>        -  (default: 1285)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: command: Introduce JSON variant of qemuBuildRomProps
Peter Krempa [Fri, 1 Oct 2021 20:18:39 +0000 (22:18 +0200)]
qemu: command: Introduce JSON variant of qemuBuildRomProps

Add a JSON variant of the generator 'rom' properties. For convenience
both the old and new are for now marked as unused, which will be removed
once the conversion is complete.

The formatted properties have following types according to QEMU.
'virtio-blk-pci' was used as an example:
  rombar=<uint32>        -  (default: 1)
  romfile=<str>

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: command: Introduce helper for building JSON props of -device into commandline
Peter Krempa [Sat, 25 Sep 2021 07:08:05 +0000 (09:08 +0200)]
qemu: command: Introduce helper for building JSON props of -device into commandline

The helper converts the JSON object to a string and adds it to the
current command as arguments of '-device'. The helper also prepares for
'-device' taking JSON directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: command: Introduce JSON variant of qemuBuildVirtioDevStr
Peter Krempa [Thu, 30 Sep 2021 15:55:45 +0000 (17:55 +0200)]
qemu: command: Introduce JSON variant of qemuBuildVirtioDevStr

Add a JSON variant of the generator of properties for virtio devices.
For convenience both the old and new are for now marked as unused, which
will be removed once the conversion is complete.

The formatted properties have following types according to QEMU.
'virtio-blk-pci' was used as an example:

  disable-legacy=<OnOffAuto> - on/off/auto (default: "auto")
  disable-modern=<bool>  -  (default: false)
  iommu_platform=<bool>  - on/off (default: false)
  ats=<bool>             - on/off (default: false)
  packed=<bool>          - on/off (default: false)

Note that <OnOffAuto> is an enum type without alternates in QMP so it
must be represented as a string in JSON.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: validate: Move validation of device rom
Peter Krempa [Fri, 1 Oct 2021 14:47:12 +0000 (16:47 +0200)]
qemu: validate: Move validation of device rom

Move the validation from 'qemuBuildRomStr' into the function which
validates device info. It was originally named
'qemuValidateDomainDeviceDefAddress' but this commit renames it to
'qemuValidateDomainDeviceDefInfo'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainDeviceDef: Avoid unneded variable and 'break' statements
Peter Krempa [Fri, 1 Oct 2021 15:11:25 +0000 (17:11 +0200)]
qemuValidateDomainDeviceDef: Avoid unneded variable and 'break' statements

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainDeviceDef: Optimize virDomainDeviceInfo validation
Peter Krempa [Fri, 1 Oct 2021 15:06:27 +0000 (17:06 +0200)]
qemuValidateDomainDeviceDef: Optimize virDomainDeviceInfo validation

Commit ffda44030a2 added validation of the 'acpiIndex' field in
virDomainDeviceInfo by calling 'virDomainDeviceInfoIterate' from
'qemuValidateDomainDef'. This is overly complicated we have
'qemuValidateDomainDeviceDef' which is already called for every single
device so we can avoid the extra loop.

Restructure the code by calling 'qemuValidateDomainDeviceInfo' directly
from 'qemuValidateDomainDeviceDef' and avoid unnecessary calls to
'virDomainDeviceGetInfo' by calling 'qemuValidateDomainDeviceDefAddress'
from 'qemuValidateDomainDeviceInfo'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirDomainDeviceGetInfo: Make argument const
Peter Krempa [Fri, 1 Oct 2021 14:57:31 +0000 (16:57 +0200)]
virDomainDeviceGetInfo: Make argument const

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Clean up after old-style passing of 'bootIndex' to network devices
Peter Krempa [Fri, 1 Oct 2021 14:24:08 +0000 (16:24 +0200)]
qemu: Clean up after old-style passing of 'bootIndex' to network devices

Remove the now unused boot-index related attributes and the code which
is assigning it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Use 'effectiveBootIndex' to handle <os><boot dev='network'>
Peter Krempa [Fri, 1 Oct 2021 14:18:13 +0000 (16:18 +0200)]
qemu: Use 'effectiveBootIndex' to handle <os><boot dev='network'>

Fill in the effective boot index for network devices (or hostdev-backed
network devices via 'qemuProcessPrepareDeviceBootorder'. This patch
doesn't clean up the cruft to make it more obvious what's happening.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: process: Make qemuProcessPrepareDomainDiskBootorder more universal
Peter Krempa [Fri, 1 Oct 2021 13:22:17 +0000 (15:22 +0200)]
qemu: process: Make qemuProcessPrepareDomainDiskBootorder more universal

Rename it to 'qemuProcessPrepareDeviceBootorder' and call it from
'qemuProcessPrepareDomain' rather than
'qemuProcessPrepareDomainStorage'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoconf: Introduce 'effectiveBootIndex' into 'virDomainDeviceInfo'
Peter Krempa [Fri, 1 Oct 2021 13:16:57 +0000 (15:16 +0200)]
conf: Introduce 'effectiveBootIndex' into 'virDomainDeviceInfo'

'effectiveBootIndex' is a copy of 'bootIndex' if '<boot order=' was
present and left unassigned if not. This allows hypervisor drivers to
reinterpret <os><boot> without being visible in the XML.

QEMU driver had a internal implementation for disks, which is now
replaced. Additionally this will simplify a refactor of network boot
assignment.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildDeviceVideoStr: Properly format virtio options for 'virtio-vga'
Peter Krempa [Thu, 30 Sep 2021 15:36:35 +0000 (17:36 +0200)]
qemuBuildDeviceVideoStr: Properly format virtio options for 'virtio-vga'

'virtio-vga' is a virtio device but we didn't use the virtio formatter
for it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioOptionsStr: Remove empty function
Peter Krempa [Thu, 30 Sep 2021 15:35:43 +0000 (17:35 +0200)]
qemuBuildVirtioOptionsStr: Remove empty function

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevStr: Format also virtioOptions
Peter Krempa [Thu, 30 Sep 2021 15:31:27 +0000 (17:31 +0200)]
qemuBuildVirtioDevStr: Format also virtioOptions

Merge the code from qemuBuildVirtioOptionsStr so that we don't have to
call two separate functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevStr: Remove 'baseName' argument
Peter Krempa [Thu, 30 Sep 2021 15:27:35 +0000 (17:27 +0200)]
qemuBuildVirtioDevStr: Remove 'baseName' argument

The code doesn't need the name as it determines it internally. Remove
the argument and fix all callers. In certain cases it led to
simplification of the logic.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevGetConfigDev: Provide more information
Peter Krempa [Thu, 30 Sep 2021 11:27:13 +0000 (13:27 +0200)]
qemuBuildVirtioDevGetConfigDev: Provide more information

Since we already have code for per-device behaviour we can also populate
the device name and extract virtioOptions in the switch statement so
that callers don't have to pass it in.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevGetConfig: Split up formatting of bus suffix
Peter Krempa [Thu, 30 Sep 2021 15:06:02 +0000 (17:06 +0200)]
qemuBuildVirtioDevGetConfig: Split up formatting of bus suffix

Add the bus suffix in a separate call. This will make it more obvious
what's happening in the next commit.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDeviceVideoGetModel: Move to the beginning
Peter Krempa [Thu, 30 Sep 2021 14:44:23 +0000 (16:44 +0200)]
qemuDeviceVideoGetModel: Move to the beginning

The function is static and will be needed in the virtio device config
helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDeviceVideoGetModel: Clarify 'virtio' argument
Peter Krempa [Thu, 30 Sep 2021 14:39:59 +0000 (16:39 +0200)]
qemuDeviceVideoGetModel: Clarify 'virtio' argument

The 'virtio' argument was misleadingly implying that it's true for all
virtio devices, but that's not the case. 'virtio-vga(-gl)' is a virtio
device but doesn't accept the usual bus-dependant suffix.

Add a comment for 'qemuDeviceVideoGetModel' and another boolean
'virtioBusSuffix' which carries the above meaning so that the 'virtio'
argument can be fixed (it will be used later).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevGetConfig: Split out per device type code
Peter Krempa [Thu, 30 Sep 2021 08:59:03 +0000 (10:59 +0200)]
qemuBuildVirtioDevGetConfig: Split out per device type code

Split out the function a bit more to separate the per-device code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevStr: Extract code for determining device model
Peter Krempa [Thu, 30 Sep 2021 08:29:35 +0000 (10:29 +0200)]
qemuBuildVirtioDevStr: Extract code for determining device model

Extract the code into 'qemuBuildVirtioDevGetConfig' so that we can
later reuse it when converting individual device code into the more
modern JSON approach as the extracted code will be necessary either way.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildVirtioDevStr: Don't return early
Peter Krempa [Thu, 30 Sep 2021 08:18:23 +0000 (10:18 +0200)]
qemuBuildVirtioDevStr: Don't return early

To simplify upcoming refactors change the logic such that we don't
return early for device types which can't be transitional.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: command: Introduce JSON equivalent of qemuBuildDeviceAddressStr
Peter Krempa [Fri, 26 Mar 2021 14:43:14 +0000 (15:43 +0100)]
qemu: command: Introduce JSON equivalent of qemuBuildDeviceAddressStr

Upcoming patches will start converting the formatting of arguments for
-device from a string to JSON so that we can keep proper types around
when using it via QMP.

This means we will need an equivalet for the device address builder
function. 'qemuBuildDeviceAddressProps' provides equal functionality,
but the output differs for fields where a number is expected, where
we've previously formatted a hex value but now end up with a decimal
value per JSON standard.

For given address types I've selected an example device and used
'-device $DEV,help' to obtain the current types recognized by qemu:

Note that 'bus' is not shown below, but it's already a string so we can
keep using it as a string.

VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI (virtio-balloon-pci)
  acpi-index=<uint32>    -  (default: 0)
  addr=<int32>           - Slot and optional function number, example: 06.0 or 06 (default: -1)
  multifunction=<bool>   - on/off (default: false)

Note that 'addr' is here defined as 'int32' but in fact internally in
qemu is an alternate type between a number and a string so we can keep
using strings here.

VIR_DOMAIN_DEVICE_ADDRESS_TYPE_USB (usb-tablet)
  port=<str>

VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO (spapr-vty)
  reg=<uint32>           -  (default: 4294967295)

VIR_DOMAIN_DEVICE_ADDRESS_TYPE_CCW (virtio-blk-cww)
  devno=<str>            - Identifier of an I/O device in the channel subsystem, example: fe.1.23ab

VIR_DOMAIN_DEVICE_ADDRESS_TYPE_ISA (isa-serial)
  iobase=<uint32>        -  (default: 4294967295)
  irq=<uint32>           -  (default: 4294967295)

VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DIMM (pc-dimm)
  slot=<int32>           -  (default: -1)
  addr=<uint64>          -  (default: 0)

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildDeviceAddressPCIStr: Extract PCI bus name lookup
Peter Krempa [Fri, 26 Mar 2021 13:31:26 +0000 (14:31 +0100)]
qemuBuildDeviceAddressPCIStr: Extract PCI bus name lookup

Split up the bus lookup into a function called
'qemuBuildDeviceAddressPCIGetBus'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildDeviceAddressPCIStr: Make error messages easier to find
Peter Krempa [Sat, 25 Sep 2021 07:38:35 +0000 (09:38 +0200)]
qemuBuildDeviceAddressPCIStr: Make error messages easier to find

Per coding guidelines error messages [1] should not be broken into
lines and variables should be separated by apostrophes.

[1] https://libvirt.org/coding-style.html#error-message-format

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildDeviceAddressStr: Split out formatting of PCI address
Peter Krempa [Tue, 16 Mar 2021 13:47:43 +0000 (14:47 +0100)]
qemuBuildDeviceAddressStr: Split out formatting of PCI address

The PCI address case grew massive over time. Split it out into a new
function qemuBuildDeviceAddressPCIStr.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBlockStorageSourceAttachRollback: Sanitize warning messages
Peter Krempa [Fri, 1 Oct 2021 11:46:53 +0000 (13:46 +0200)]
qemuBlockStorageSourceAttachRollback: Sanitize warning messages

Mention the QMP command 'device_add' rather than 'qemuMonitorAddDevice'
and remove the weird formatting.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirQEMUBuildCommandLineJSONRecurse: Error out when array conversion function is not...
Peter Krempa [Sat, 25 Sep 2021 07:04:55 +0000 (09:04 +0200)]
virQEMUBuildCommandLineJSONRecurse: Error out when array conversion function is not provided

For conversion of '-device' we'll try to avoid usage of arrays if
possible, so for now if the array coversion function is not provided the
convertor will error out.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirQEMUBuildCommandLineJSONIterate: Simplify logic
Peter Krempa [Sat, 25 Sep 2021 07:01:52 +0000 (09:01 +0200)]
virQEMUBuildCommandLineJSONIterate: Simplify logic

With automatic memory freeing we can simplify the function to avoid two
almost-identical calls to virQEMUBuildCommandLineJSONRecurse.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuMonitorJSONAddDeviceProps: Refactor cleanup
Peter Krempa [Sat, 25 Sep 2021 06:34:48 +0000 (08:34 +0200)]
qemuMonitorJSONAddDeviceProps: Refactor cleanup

Use automatic memory freeing and remove 'ret' variable and 'cleanup'
label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Rename 'qemuMonitorAddDeviceArgs' to 'qemuMonitorAddDeviceProps'
Peter Krempa [Wed, 24 Mar 2021 10:07:56 +0000 (11:07 +0100)]
qemu: Rename 'qemuMonitorAddDeviceArgs' to 'qemuMonitorAddDeviceProps'

We commonly use 'props' for the JSON object describing something. Rename
the monitor device addition code.

Additionally the common approach is to clear the pointer if it was
consumed so the arguments are adjusted to do so.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuDomainHotplugAddVcpu: Refactor cleanup
Peter Krempa [Wed, 24 Mar 2021 09:58:13 +0000 (10:58 +0100)]
qemuDomainHotplugAddVcpu: Refactor cleanup

Use g_autoptr for 'vcpuprops' and remove the 'cleanup' label and 'ret'
varlaible which is no longer needed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Move watchdog model validation into the validation code
Peter Krempa [Tue, 16 Mar 2021 16:12:40 +0000 (17:12 +0100)]
qemu: Move watchdog model validation into the validation code

Report the error from 'qemuValidateDomainWatchdogDef' rather than
'qemuBuildWatchdogDevStr'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2xmltest: Remove 'panic-isa' case
Peter Krempa [Fri, 26 Mar 2021 15:23:34 +0000 (16:23 +0100)]
qemuxml2xmltest: Remove 'panic-isa' case

The same test in regards to the 'panic' device is the 'panic-double'
case, thus panic-isa can be removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Convert 'panic' test cases to DO_TEST_CAPS_LATEST
Peter Krempa [Fri, 26 Mar 2021 15:21:19 +0000 (16:21 +0100)]
qemuxml2argvtest: Convert 'panic' test cases to DO_TEST_CAPS_LATEST

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotests: qemuxml2argv: Test also the i6300esb watchdog
Peter Krempa [Thu, 25 Mar 2021 17:07:07 +0000 (18:07 +0100)]
tests: qemuxml2argv: Test also the i6300esb watchdog

Convert one of the tests to a different device.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotests: qemuxml2argv: Convert watchdog tests on x86_64 to DO_TEST_CAPS_LATEST
Peter Krempa [Thu, 25 Mar 2021 17:23:19 +0000 (18:23 +0100)]
tests: qemuxml2argv: Convert watchdog tests on x86_64 to DO_TEST_CAPS_LATEST

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Introduce QEMU_CAPS_DEVICE_JSON
Peter Krempa [Fri, 24 Sep 2021 17:02:28 +0000 (19:02 +0200)]
qemu: capabilities: Introduce QEMU_CAPS_DEVICE_JSON

The flag will be used to switch use of JSON arguments for -device once
qemu will support it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Introduce QEMU_CAPS_CHARDEV_JSON
Peter Krempa [Fri, 24 Sep 2021 17:08:12 +0000 (19:08 +0200)]
qemu: capabilities: Introduce QEMU_CAPS_CHARDEV_JSON

The flag will be used to switch use of JSON arguments for -chardev once
qemu will support it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirCommandGetArgList: Remove 'nargs' argument
Peter Krempa [Fri, 24 Sep 2021 11:32:16 +0000 (13:32 +0200)]
virCommandGetArgList: Remove 'nargs' argument

The returned argument list is a NULL-terminated string list and the only
caller doesn't use the count. Remove the argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Refactor QAPI schema validation code
Peter Krempa [Fri, 24 Sep 2021 11:28:57 +0000 (13:28 +0200)]
qemuxml2argvtest: Refactor QAPI schema validation code

Prevent duplication of code when extending the validator for new
commands. Add a struct describing a command to validate and make the
validation loop a bit more robust to corner cases.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirQEMUBuildDriveCommandlineFromJSON: Open-code in callers
Peter Krempa [Wed, 24 Mar 2021 13:00:07 +0000 (14:00 +0100)]
virQEMUBuildDriveCommandlineFromJSON: Open-code in callers

Optimize the number of string copies by using the virBuffers in the
callers directly. Simplest way to achieve this is to just open code the
one function call 'virQEMUBuildDriveCommandlineFromJSON' was wrapping
in the two callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: Remove 'qemuBuildCommandLineFlags' and associated code
Peter Krempa [Fri, 24 Sep 2021 17:15:22 +0000 (19:15 +0200)]
qemu: Remove 'qemuBuildCommandLineFlags' and associated code

The -netdev formatter code switched to a real virQEMUCaps flag so we can
remove the old flags which used to enable JSON for -netdev for
validation purposes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirQEMUBuildNetdevCommandlineFromJSON: Remove unused formatter
Peter Krempa [Fri, 24 Sep 2021 17:00:22 +0000 (19:00 +0200)]
virQEMUBuildNetdevCommandlineFromJSON: Remove unused formatter

Now that everything was replaced by the new code we can remove this
function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: command: Format netdev as JSON when QEMU_CAPS_NETDEV_JSON is present
Peter Krempa [Fri, 24 Sep 2021 16:47:59 +0000 (18:47 +0200)]
qemu: command: Format netdev as JSON when QEMU_CAPS_NETDEV_JSON is present

Base the JSON output on a regular capability flag rather than purely
internal flag. This will prepare for the time when QEMU will accept JSON
argumets for -netdev.

For now the capability is not set (thus we for now don't have QMP
schema validation) but that will be addressed later.

To achieve this 'qemuBuildNetdevCommandlineFromJSON' is introduced
and all callers of 'virQEMUBuildNetdevCommandlineFromJSON' are
refactored to use the new helper.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agotestCompareXMLToArgvValidateSchema: Base -netdev validation on JSON
Peter Krempa [Fri, 24 Sep 2021 16:58:33 +0000 (18:58 +0200)]
testCompareXMLToArgvValidateSchema: Base -netdev validation on JSON

Base the validation on presence of JSON as we do with other validated
commands. This will prepare the code for a refactor so that it's the
same for all validated commands.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildObjectCommandlineFromJSON: Remove checks for 'type' and 'alias'
Peter Krempa [Fri, 24 Sep 2021 16:43:35 +0000 (18:43 +0200)]
qemuBuildObjectCommandlineFromJSON: Remove checks for 'type' and 'alias'

We validate the generated props against the QMP schema which makes sure
that the objects are generated properly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Introduce QEMU_CAPS_NETDEV_JSON
Peter Krempa [Fri, 24 Sep 2021 14:27:32 +0000 (16:27 +0200)]
qemu: capabilities: Introduce QEMU_CAPS_NETDEV_JSON

Introduce a capability that will be asserted once '-netdev' will accept
JSON. For now it will be dormant (only used by tests).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Rename QEMU_CAPS_OBJECT_QAPIFIED to QEMU_CAPS_OBJECT_JSON
Peter Krempa [Fri, 24 Sep 2021 14:24:53 +0000 (16:24 +0200)]
qemu: capabilities: Rename QEMU_CAPS_OBJECT_QAPIFIED to QEMU_CAPS_OBJECT_JSON

Unify it with the upcoming capabilities for -netdev and -device.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildObjectCommandlineFromJSON: Format directly into the virCommand
Peter Krempa [Fri, 24 Sep 2021 14:15:38 +0000 (16:15 +0200)]
qemuBuildObjectCommandlineFromJSON: Format directly into the virCommand

All callers basically end up dumping the buffer into a string and then
adding '-object' 'props' arguments to virCommand. Simplify all callers
by doing this in the function itself.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildInputDevStr: Don't mix generators for -object and -device
Peter Krempa [Fri, 24 Sep 2021 13:52:03 +0000 (15:52 +0200)]
qemuBuildInputDevStr: Don't mix generators for -object and -device

Input devices of VIR_DOMAIN_INPUT_TYPE_EVDEV type are instantiated via
an '-object' rather than a '-device'. Mixing them in one function is a
bad idea as the caller then needs to use the string correctly which is
not the case in 'qemuDomainAttachInputDevice'.

Generate a JSON object for '-object' explicitly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuBuildMemoryCellBackendStr: Return JSON props instead of a buffer
Peter Krempa [Fri, 24 Sep 2021 13:37:17 +0000 (15:37 +0200)]
qemuBuildMemoryCellBackendStr: Return JSON props instead of a buffer

Rename the function to 'qemuBuildMemoryCellBackendProps' and return the
properties before conversion to commandline arguments. This requires
changes in the caller.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirJSONValueObjectAddVArgs: Add check for presence of the ':' separator
Peter Krempa [Wed, 6 Oct 2021 11:11:10 +0000 (13:11 +0200)]
virJSONValueObjectAddVArgs: Add check for presence of the ':' separator

Enforce that the ':' separator between the key and value is always
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agovirJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers
Peter Krempa [Tue, 5 Oct 2021 12:07:31 +0000 (14:07 +0200)]
virJSONValueObjectAddVArgs: Add 'k' convertor for formatting non-negative integers

In many cases we use a signed value, but use the sign to note that it
was not assigned. For converting to JSON objects it will be handy to
have possibility to do this automatically.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemu: capabilities: Remove QEMU_CAPS_PIIX4_ACPI_HOTPLUG_BRIDGE
Peter Krempa [Mon, 11 Oct 2021 07:17:54 +0000 (09:17 +0200)]
qemu: capabilities: Remove QEMU_CAPS_PIIX4_ACPI_HOTPLUG_BRIDGE

Commit 58ba0f6a3d7342fba29edbbf2bb9cb5497c870e5 added a capability which
is supported by all qemu versions we support. Remove it and the
associated dead code. Since the capability isn't present in any upstream
release we can delete it completely.

Specifically the commit itself states that it was introduced "around
(qemu) 2.1". The rest of the code handles properly that the feature is
used only on x86 with the i440fx machine so the capability is pointless.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2xmltest: Convert all acpi-hotplug control related tests to DO_TEST_CAPS_LATEST
Peter Krempa [Mon, 11 Oct 2021 12:46:46 +0000 (14:46 +0200)]
qemuxml2xmltest: Convert all acpi-hotplug control related tests to DO_TEST_CAPS_LATEST

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Add '-enable' variants for ACPI-hotplug related cases
Peter Krempa [Mon, 11 Oct 2021 12:55:42 +0000 (14:55 +0200)]
qemuxml2argvtest: Add '-enable' variants for ACPI-hotplug related cases

We have input files for those, provide also xml2argv testing since we
have them.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Use real-caps testing for 'acpi-hotplug-bridge-disable'
Peter Krempa [Mon, 11 Oct 2021 12:30:58 +0000 (14:30 +0200)]
qemuxml2argvtest: Use real-caps testing for 'acpi-hotplug-bridge-disable'

We can use real example configs to prove the support without the
need for using fake capabilities. Fix the recently added test cases.

The negative case for 'pc-i440fx-acpi-hotplug-bridge-disable' is removed
completely as there is no real qemu libvirt supports which wouldn't
have the capability.

The input file for the negative test on aarch64 is modified so that it's
actually a reasonably valid VM config.

Fixes: bef0f0d8be6
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuxml2argvtest: Use real-caps testing for 'pc-i440fx-acpi-root-hotplug-disable'
Peter Krempa [Mon, 11 Oct 2021 12:30:58 +0000 (14:30 +0200)]
qemuxml2argvtest: Use real-caps testing for 'pc-i440fx-acpi-root-hotplug-disable'

We can use two real example configs to prove the support without the
need for using fake capabilities. Fix the recently added test cases.

Fixes: 133d7983d6c
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainDefPCIFeature: Fix validation logic
Peter Krempa [Mon, 11 Oct 2021 12:15:14 +0000 (14:15 +0200)]
qemuValidateDomainDefPCIFeature: Fix validation logic

The error that "acpi-bridge-hotplug" is not supported would be triggered
only if both the ICH9 and PIIX don't support the capability and the
machine is q35. This makes no sense.

We want to check that the appropriate platform supports the appropriate
feature.

Fixes: 7300ccc9b3e
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoqemuValidateDomainDefPCIFeature: un-break error messages
Peter Krempa [Mon, 11 Oct 2021 12:11:06 +0000 (14:11 +0200)]
qemuValidateDomainDefPCIFeature: un-break error messages

https://www.libvirt.org/coding-style.html#error-message-format

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
3 years agoapparmor: ceph config file names
Christian Ehrhardt [Thu, 7 Oct 2021 11:27:35 +0000 (13:27 +0200)]
apparmor: ceph config file names

If running multiple [1] clusters (uncommon) the ceph config file will be
derived from the cluster name. Therefore the rule to allow to read ceph
config files need to be opened up slightly to allow for that condition.

[1]: https://docs.ceph.com/en/mimic/rados/configuration/common/#running-multiple-clusters

Fixes: https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1588576
Signed-off-by: Christian Ehrhardt <christian.ehrhardt@canonical.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
3 years agoNEWS: document new acpi pci hotplug config option
Ani Sinha [Fri, 8 Oct 2021 06:42:15 +0000 (12:12 +0530)]
NEWS: document new acpi pci hotplug config option

Added the following new libvirt conf option to the release note to
indicate their availability with the next release:

<feature>
  <pci>
    <acpi-bridge-hotplug state='off|on'/>
  </pci>
</feature>

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Laine Stump <laine@redhat.com>
3 years agoqemu: command: add support for acpi-bridge-hotplug feature
Ani Sinha [Fri, 8 Oct 2021 06:42:14 +0000 (12:12 +0530)]
qemu: command: add support for acpi-bridge-hotplug feature

This change adds backend qemu command line support for new libvirt
global feature 'acpi-bridge-hotplug'. This option can be used as
following:

<feature>
  <pci>
    <acpi-bridge-hotplug state='off|on'/>
  </pci>
</feature>

The '<pci>' sub-element under '<feature>' is also newly introduced.

'acpi-bridge-hotplug' turns on the following command line option to
qemu for x86 guests:

(pc): -global PIIX4_PM.acpi-pci-hotplug-with-bridge-support=<off|on>

(q35): -global ICH9-LPC.acpi-pci-hotplug-with-bridge-support=<off|on>

This change also adds the required qemuxml2argv unit tests in order to
test correct qemu arguments. Unit tests have also been added to test
qemu capability validation checks as well as checks for using this
option with the right architecture.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Laine Stump <laine@redhat.com>
3 years agoconf: introduce support for acpi-bridge-hotplug feature
Ani Sinha [Fri, 8 Oct 2021 06:42:13 +0000 (12:12 +0530)]
conf: introduce support for acpi-bridge-hotplug feature

This change introduces a new libvirt sub-element <pci> under
<features> that can be used to configure all pci related features.
Currently the only sub-sub element supported by this sub-element is
'acpi-bridge-hotplug' as shown below:

<features>
  <pci>
    <acpi-bridge-hotplug state='on|off'/>
  </pci>
</features>

The above option is only available for the QEMU driver, for x86 guests
only. It is a global option, affecting all PCI bridge controllers on
the guest.

The 'acpi-bridge-hotplug' option enables or disables ACPI hotplug
support for cold-plugged pci bridges. Examples of bridges include the
PCI-PCI bridge (pci-bridge controller) for pc (i440fx) machinetypes,
or PCIe-PCI bridges and pcie-root-port controllers for q35
machinetypes.

For pc machinetypes in x86, this option has been available in QEMU
since version 2.1. Please see the following changes in qemu repo:

9e047b982452c6 ("piix4: add acpi pci hotplug support")
133a2da488062e ("pc: acpi: generate AML only for PCI0 devices if PCI
               bridge hotplug is disabled")

For q35 machinetypes, this was introduced in QEMU 6.1 with the
following changes in qemu repo:

(a) c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
(b) 17858a16950860 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on
                   Q35")

The reasons for enabling ACPI based hotplug for PCIe (q35) based
machines (as opposed to native hotplug) are outlined in (b). There are
use cases where users would still want to use native
hotplug. Therefore, this config option enables users to choose either
ACPI based hotplug or native hotplug for bridges (for example for pcie
root port controller in q35 machines).

Qemu capability validation checks have also been added along with
related unit tests to exercise the new conf option.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Laine Stump <laine@redhat.com>
3 years agoqemu: capablities: detect acpi-pci-hotplug-with-bridge-support
Ani Sinha [Fri, 8 Oct 2021 06:42:12 +0000 (12:12 +0530)]
qemu: capablities: detect acpi-pci-hotplug-with-bridge-support

qemu added support for i440fx specific global boolean flag

PIIX4_PM.acpi-pci-hotplug-with-bridge-support

around version 2.1. This flag is enabled by default. When disabled, it
turns off acpi pci hotplug for cold plugged pci bridges in i440fx
machine types.

Very recently, in qemu version 6.1, the same global option was also
added for q35 machine types as well.

ICH9-LPC.acpi-pci-hotplug-with-bridge-support

This option turns on or off acpi based hotplug for cold plugged pcie
bridges like pcie root ports. This flag is also enabled by
default. Please refer to the following qemu changes:

c0e427d6eb5fef ("hw/acpi/ich9: Enable ACPI PCI hot-plug")
17858a16950860 ("hw/acpi/ich9: Set ACPI PCI hot-plug as default on Q35")

This patch adds the corresponding qemu capabilities in libvirt. For
i440fx, the capability is detected as
QEMU_CAPS_PIIX_ACPI_HOTPLUG_BRIDGE. For q35, the capability is
detected as QEMU_CAPS_ICH9_ACPI_HOTPLUG_BRIDGE.

Please note that the test specific qemu capabilities .replies files
has already been updated as a part of regular refreshing them when a
new qemu version is released. Hence, no updates to those files are
required.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Laine Stump <laine@redhat.com>
3 years agovireventglib: Remove handles with the highest priority
Michal Privoznik [Thu, 7 Oct 2021 11:46:43 +0000 (13:46 +0200)]
vireventglib: Remove handles with the highest priority

When a server decides to close a client, the
virNetServerClientCloseLocked() is called. In here various
cleanup steps are taken, but the most important part (from this
commit's POV at least) is the way that the socket is closed.
Firstly, removal of the socket associated with the client from
the event loop is signalized and then the socket is unrefed. The
socket is not closed just yet though, because the event loop
holds a reference to it. This reference will be freed as soon as
the event loop wakes up and starts issuing callbacks (in this
case virNetSocketEventFree()).

So far, this is how things usually work. But if the daemon
reaches the number of opened files limit, things start to work
differently.

If the RLIMIT_NOFILE limit is reached and there's a client that
wants to connect then the event loop wakes up, sees POLLIN on the
socket and calls virNetServerServiceAccept() which in turn calls
virNetSocketAccept(). But because of the limit, accept() fails
with EMFILE leaving the POLLIN event unhandled. The dispatch then
continues to next FDs with events on them. BUT, it will NOT call
the socket removal callback (virNetSocketEventFree()) because it
has low priority (G_PRIORITY_DEFAULT_IDLE). Per glib's
documentation:

 * Each event source is assigned a priority. The default priority,
 * %G_PRIORITY_DEFAULT, is 0. Values less than 0 denote higher priorities.
 * Values greater than 0 denote lower priorities. Events from high priority
 * sources are always processed before events from lower priority sources.

and per g_idle_add() documentation:

 * Adds a function to be called whenever there are no higher priority
 * events pending to the default main loop. The function is given the
 * default idle priority, %G_PRIORITY_DEFAULT_IDLE.

Now, because we did not accept() the client we are constantly
seeing POLLIN on the main socket and thus the removal of the
client socket won't ever happen.

The fix is to set at least the same priority as other sources,
but since we want to just close an FD, let's give it the highest
priority and call it before handling other events.

This issue can be easily reproduced, for instance:

 # ulimit -S -n 40 (tweak this number if needed)
 # ./src/libvirtd

from another terminal:

 # for ((i=0; i<100; i++)); do virsh list & done; virsh list

The last `virsh list` must not get stuck.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2007168
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
3 years agolxc: controller: Fix container launch on cgroup v1
Cole Robinson [Tue, 5 Oct 2021 13:42:12 +0000 (09:42 -0400)]
lxc: controller: Fix container launch on cgroup v1

With cgroup v1 I'm seeing LXC container startup failures:

$ sudo virt-install --connect lxc:/// --name test-container --memory 128
--boot init=/bin/sh

Starting install...
ERROR    error from service:
GDBus.Error:org.freedesktop.machine1.NoMachineForPID: PID 2145047 does
not belong to any known machine

libvirt 7.0.0 works but 7.1.0+ does not. The root error seems to predate
that, showing up in syslog, but commit 9c1693eff made it fatal:

commit 9c1693eff427661616ce1bd2795688f87288a412
Author: Pavel Hrdina <phrdina@redhat.com>
Date:   Fri Feb 5 16:17:35 2021 +0100

     vircgroup: use DBus call to systemd for some APIs

The error comes from virSystemdGetMachineByPID. The PID that shows up in
the above error message does not match the leader PID as reported by
machinectl.

This change fixes the error. Things seem to continue to work with
cgroupsv2 after this change.

https://gitlab.com/libvirt/libvirt/-/issues/182

Tested-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
3 years agotools: Fix virt-host-validate SEV detection
Jim Fehlig [Wed, 6 Oct 2021 04:34:57 +0000 (22:34 -0600)]
tools: Fix virt-host-validate SEV detection

virt-host-validate checks if AMD SEV is enabled by verifying
/sys/module/kvm_amd/parameters/sev is set to '1'. On a system
running kernel 5.13, the parameter is reported as 'Y'. To be
extra paranoid, add a check for 'y' along with 'Y' to complement
the existing check for '1'.

Fixes: https://bugzilla.opensuse.org/show_bug.cgi?id=1188715
Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
3 years agoqemu: export vhost-user-fs-related functions
Ján Tomko [Tue, 5 Oct 2021 14:20:36 +0000 (16:20 +0200)]
qemu: export vhost-user-fs-related functions

Prepare for hotplug support.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: vhost-user-fs: build extdevice for zpci
Ján Tomko [Tue, 17 Aug 2021 15:34:51 +0000 (17:34 +0200)]
qemu: vhost-user-fs: build extdevice for zpci

Other devices (includes 9p-based fsdev) call this wrapper
before formatting the device.

Add it here too.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: alias: prepare qemuAssignDeviceFSAlias for disjunct ranges
Ján Tomko [Tue, 17 Aug 2021 15:24:08 +0000 (17:24 +0200)]
qemu: alias: prepare qemuAssignDeviceFSAlias for disjunct ranges

Iterate through the array to find the first free index.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: remove private data from virDomainFSDef
Ján Tomko [Wed, 18 Aug 2021 12:10:57 +0000 (14:10 +0200)]
qemu: remove private data from virDomainFSDef

This reverts commit 801e6da29c0202946d44b42136cc4ee229932a29

They are not needed anymore.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: do not put virtiofs socket in private data
Ján Tomko [Wed, 18 Aug 2021 12:05:46 +0000 (14:05 +0200)]
qemu: do not put virtiofs socket in private data

Reconstruct the socket path from priv->libDir in every user.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: vhost-user-fs: separate building of device string
Ján Tomko [Tue, 17 Aug 2021 14:29:28 +0000 (16:29 +0200)]
qemu: vhost-user-fs: separate building of device string

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: vhost-user-fs: separate building of chardev string
Ján Tomko [Tue, 17 Aug 2021 14:12:50 +0000 (16:12 +0200)]
qemu: vhost-user-fs: separate building of chardev string

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agotests: qemuxml2argvtest: fix path to virtiofs socket
Ján Tomko [Wed, 18 Aug 2021 10:34:06 +0000 (12:34 +0200)]
tests: qemuxml2argvtest: fix path to virtiofs socket

The mocked path in the test suite is not in sync with what libvirtd
generates.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: domain: introduce qemuDomainGetVHostUserFSSocketPath
Ján Tomko [Wed, 18 Aug 2021 08:24:36 +0000 (10:24 +0200)]
qemu: domain: introduce qemuDomainGetVHostUserFSSocketPath

Intended as a replacement for qemuVirtioFSCreateSocketFilename,
to be used outside of qemu_virtiofs.c

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoconf: define cleanup func for virDomainChrSourceDef
Ján Tomko [Wed, 18 Aug 2021 08:46:13 +0000 (10:46 +0200)]
conf: define cleanup func for virDomainChrSourceDef

It's defined also for 'virDomainChrDef'

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agoqemu: vhost-user-fs: format alias on the command line
Ján Tomko [Tue, 5 Oct 2021 11:18:52 +0000 (13:18 +0200)]
qemu: vhost-user-fs: format alias on the command line

The commit adding the vhost-user-fs device forgot to format
the device's alias on the command line.

Thankfully it was not needed yet because virtiofs migration
is not yet supported, but it will be needed in the future
to allow hot(un)plug.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
3 years agotools: Fix typo firemare -> firmware
Andrea Bolognani [Wed, 6 Oct 2021 09:14:07 +0000 (11:14 +0200)]
tools: Fix typo firemare -> firmware

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
3 years agovirsh: Use VIR_AUTOCLOSE more
Michal Privoznik [Sun, 26 Sep 2021 10:54:10 +0000 (12:54 +0200)]
virsh: Use VIR_AUTOCLOSE more

There are few places where we can replace explicit
VIR_FORCE_CLOSE() with VIR_AUTOCLOSE annotation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
3 years agovirsh: Add wrapper for virStreamFree
Michal Privoznik [Sun, 26 Sep 2021 11:27:26 +0000 (13:27 +0200)]
virsh: Add wrapper for virStreamFree

Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>