]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: command: add support to enable/disable hotplug on pci-root controller
authorAni Sinha <ani@anisinha.ca>
Fri, 1 Oct 2021 09:29:47 +0000 (14:59 +0530)
committerLaine Stump <laine@redhat.com>
Fri, 1 Oct 2021 18:42:18 +0000 (14:42 -0400)
This change adds qemu backend command line support for enabling or disabling
hotplug on the pci-root controller using the 'target' sub-element of the
pci-root controller as shown below:

<controller type='pci' model='pci-root'>
  <target hotplug='off'/>
</controller>

'<target hotplug='off/on'/>' is only valid for pc (i440fx-based x86)
machinetypes and turns on the following command line option that is passed
to qemu for x86 guests:

-global PIIX4_PM.acpi-root-pci-hotplug=<off/on>

Before introduction of this attribute, hotplug was always enabled for
pci-root of an i440fx-based machinetype, and since its introduction
the default setting has always been "on" for those machinetypes.

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.

Signed-off-by: Ani Sinha <ani@anisinha.ca>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-disable.args [new file with mode: 0644]
tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-disable.err [new file with mode: 0644]
tests/qemuxml2argvtest.c

index eaa1e0deb99de1ccd62d810fd5188d7a4d8f7484..08f6d735f88e6d81a2a72b18174c5245dffc8dba 100644 (file)
@@ -2645,6 +2645,20 @@ qemuBuildSkipController(const virDomainControllerDef *controller,
     return false;
 }
 
+static int
+qemuBuildPMPCIRootHotplugCommandLine(virCommand *cmd,
+                              const virDomainControllerDef *controller)
+{
+    if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
+        controller->model == VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT &&
+        controller->idx == 0 &&
+        controller->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
+            virCommandAddArg(cmd, "-global");
+            virCommandAddArgFormat(cmd, "PIIX4_PM.acpi-root-pci-hotplug=%s",
+                                   virTristateSwitchTypeToString(controller->opts.pciopts.hotplug));
+    }
+    return 0;
+}
 
 static int
 qemuBuildControllersByTypeCommandLine(virCommand *cmd,
@@ -2661,6 +2675,9 @@ qemuBuildControllersByTypeCommandLine(virCommand *cmd,
         if (cont->type != type)
             continue;
 
+        if (qemuBuildPMPCIRootHotplugCommandLine(cmd, cont))
+            continue;
+
         if (qemuBuildSkipController(cont, def))
             continue;
 
diff --git a/tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-disable.args b/tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-disable.args
new file mode 100644 (file)
index 0000000..dd8ea50
--- /dev/null
@@ -0,0 +1,31 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-i440fx \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-i440fx/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-i440fx/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-i440fx/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=i440fx,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,file=/tmp/lib/domain--1-i440fx/master-key.aes \
+-machine pc-i440fx-2.5,accel=tcg,usb=off,dump-guest-core=off \
+-m 1024 \
+-realtime mlock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid 56f5055c-1b8d-490c-844a-ad646a1caaaa \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,path=/tmp/lib/domain--1-i440fx/monitor.sock,server=on,wait=off \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-global PIIX4_PM.acpi-root-pci-hotplug=off \
+-usb \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-disable.err b/tests/qemuxml2argvdata/pc-i440fx-acpi-root-hotplug-disable.err
new file mode 100644 (file)
index 0000000..b507f1f
--- /dev/null
@@ -0,0 +1 @@
+unsupported configuration: setting the hotplug property on a 'pci-root' device is not supported by this QEMU binary
index bf05c9c6c33e0f55d0b6820fd2bd35b1cd3cc5ab..e0ff216b3a2197aada889ffe57f59bdc138c04ce 100644 (file)
@@ -2571,6 +2571,9 @@ mymain(void)
             QEMU_CAPS_DEVICE_IOH3420,
             QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_ICH9_AHCI,
             QEMU_CAPS_PIIX_DISABLE_S3, QEMU_CAPS_PIIX_DISABLE_S4);
+    DO_TEST("pc-i440fx-acpi-root-hotplug-disable",
+            QEMU_CAPS_PIIX_ACPI_ROOT_PCI_HOTPLUG);
+    DO_TEST_PARSE_ERROR_NOCAPS("pc-i440fx-acpi-root-hotplug-disable");
     DO_TEST("q35-usb2",
             QEMU_CAPS_DEVICE_PCI_BRIDGE,
             QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,