Commit Graph

43454 Commits

Author SHA1 Message Date
Peter Krempa
927f189a36 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>
2021-10-12 10:26:02 +02:00
Peter Krempa
6cbbb83d32 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
a1dc15e677 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
65d014fbf6 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
085d9b40a6 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
bc130288a3 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
e1eae5c430 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
2fbda628c6 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
79f872a8d1 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
3d4f0aba0d 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
93cdb1cae2 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
5204578993 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
fbc088ab82 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
2154718c29 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
daaa28d774 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
605a1e9d2e 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>
2021-10-12 10:26:01 +02:00
Peter Krempa
fd2aed1ab5 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
bab8d47797 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
3209048f36 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
c7d26f4742 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
7c48fa2f58 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
1a97c8f50e 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
4b67fe3843 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
debc33ef84 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
803d3f2ca0 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
424dc5d2d2 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
2464e5523c 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
63a833038f 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
36253a48b4 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
c6a9285925 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
cacfd540f0 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>
2021-10-12 10:26:00 +02:00
Peter Krempa
2e2d871773 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>
2021-10-12 10:25:59 +02:00
Peter Krempa
6da02fecca 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>
2021-10-12 10:25:59 +02:00
Peter Krempa
f8f9c49302 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>
2021-10-12 10:25:59 +02:00
Peter Krempa
d8f3fb187d 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>
2021-10-12 10:25:59 +02:00
Peter Krempa
acf4159556 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>
2021-10-12 10:25:59 +02:00
Peter Krempa
eb5b7722ea 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>
2021-10-12 10:25:59 +02:00
Peter Krempa
618e8665db qemu: capabilities: Remove QEMU_CAPS_PIIX4_ACPI_HOTPLUG_BRIDGE
Commit 58ba0f6a3d 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>
2021-10-12 09:41:22 +02:00
Peter Krempa
da896d440c 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>
2021-10-12 09:41:22 +02:00
Peter Krempa
6414603105 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>
2021-10-12 09:41:22 +02:00
Peter Krempa
2d20f0bb05 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: bef0f0d8be
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-12 09:41:22 +02:00
Peter Krempa
2017b9f0c0 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: 133d7983d6
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-12 09:41:22 +02:00
Peter Krempa
bdc3e8f47b 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: 7300ccc9b3
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-12 09:41:22 +02:00
Peter Krempa
7d074c5683 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>
2021-10-12 09:41:22 +02:00
Christian Ehrhardt
e3c5a8ec73
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>
2021-10-11 08:01:27 +02:00
Ani Sinha
5ee4f3e1d4 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>
2021-10-10 13:21:46 -04:00
Ani Sinha
bef0f0d8be 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>
2021-10-10 13:21:04 -04:00
Ani Sinha
7300ccc9b3 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>
2021-10-10 13:13:45 -04:00
Ani Sinha
58ba0f6a3d 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>
2021-10-10 13:12:50 -04:00
Michal Privoznik
5de203f879 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>
2021-10-10 18:42:15 +02:00