render / rpms / libvirt

Forked from rpms/libvirt 7 months ago
Clone
a41c76
From 12892e0376be4dc07dc317b807f2ec86c27a94b2 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <12892e0376be4dc07dc317b807f2ec86c27a94b2@dist-git>
a41c76
From: Laine Stump <laine@redhat.com>
a41c76
Date: Sun, 26 Apr 2020 13:04:07 -0400
a41c76
Subject: [PATCH] conf: new attribute "hotplug" for pci controllers
a41c76
a41c76
a <controller type='pci'...> element can now have a "hotplug"
a41c76
attribute in the <target> subelement. This is intended to control
a41c76
whether or not the slot(s) of the controller support
a41c76
hotplugging/unplugging a device:
a41c76
a41c76
   <controller type='pci' model='pcie-root-port'>
a41c76
     <target hotplug='off'/>
a41c76
   </controller>
a41c76
a41c76
The default value of hotplug is "on".
a41c76
a41c76
Since support for configuring such an option is hypervisor-dependent
a41c76
(and will vary among different types of PCI controllers even on a
a41c76
single hypervisor), no validation is done in this patch - that
a41c76
validation will be done in the patch that wires support for the
a41c76
setting into the hypervisor.
a41c76
a41c76
Signed-off-by: Laine Stump <laine@redhat.com>
a41c76
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
(cherry picked from commit 78f4d5e6f188a9f0f8d6da6b1fe78b9f4172d9ad)
a41c76
a41c76
https://bugzilla.redhat.com/1802592
a41c76
Signed-off-by: Laine Stump <laine@redhat.com>
a41c76
a41c76
Conflicts/Changes from upstread:
a41c76
a41c76
  tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml:
a41c76
a41c76
    had to be modified to remove reference to the qemu64 CPU type.
a41c76
a41c76
Signed-off-by: Laine Stump <laine@redhat.com>
a41c76
Message-Id: <20200426170415.18328-5-laine@redhat.com>
a41c76
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
---
a41c76
 docs/formatdomain.html.in                     | 11 +++
a41c76
 docs/schemas/domaincommon.rng                 |  5 ++
a41c76
 src/conf/domain_conf.c                        | 20 +++++-
a41c76
 src/conf/domain_conf.h                        |  1 +
a41c76
 .../pcie-root-port-nohotplug.xml              | 35 ++++++++++
a41c76
 ...pcie-root-port-nohotplug.x86_64-latest.xml | 67 +++++++++++++++++++
a41c76
 tests/qemuxml2xmltest.c                       |  2 +-
a41c76
 7 files changed, 139 insertions(+), 2 deletions(-)
a41c76
 create mode 100644 tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml
a41c76
 create mode 100644 tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml
a41c76
a41c76
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
a41c76
index 9c588185df..76799f5ffc 100644
a41c76
--- a/docs/formatdomain.html.in
a41c76
+++ b/docs/formatdomain.html.in
a41c76
@@ -4651,6 +4651,17 @@
a41c76
         which is visible to the virtual machine. If set, port must be
a41c76
         between 0 and 255.
a41c76
       
a41c76
+      
hotplug
a41c76
+      
a41c76
+        pcie-root-port and pcie-switch-downstream-port controllers can
a41c76
+        also have a hotplug attribute in
a41c76
+        the <target> subelement, which is used to
a41c76
+        disable hotplug/unplug of devices on a particular
a41c76
+        controller. The default setting of hotplug
a41c76
+        is on; it should be set to off to
a41c76
+        disable hotplug/unplug of devices on a particular controller.
a41c76
+        Since 6.3.0
a41c76
+      
a41c76
       
busNr
a41c76
       
a41c76
         pci-expander-bus and pcie-expander-bus controllers can have an
a41c76
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
a41c76
index dd8f27243a..9fda5f17e0 100644
a41c76
--- a/docs/schemas/domaincommon.rng
a41c76
+++ b/docs/schemas/domaincommon.rng
a41c76
@@ -2475,6 +2475,11 @@
a41c76
                     <ref name='uint8'/>
a41c76
                   </attribute>
a41c76
                 </optional>
a41c76
+                <optional>
a41c76
+                  <attribute name='hotplug'>
a41c76
+                    <ref name="virOnOff"/>
a41c76
+                  </attribute>
a41c76
+                </optional>
a41c76
                 <optional>
a41c76
                   <element name='node'>
a41c76
                     <ref name='unsignedInt'/>
a41c76
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
a41c76
index 28160a2967..ed9ca0e9d8 100644
a41c76
--- a/src/conf/domain_conf.c
a41c76
+++ b/src/conf/domain_conf.c
a41c76
@@ -10933,6 +10933,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
a41c76
     g_autofree char *port = NULL;
a41c76
     g_autofree char *busNr = NULL;
a41c76
     g_autofree char *targetIndex = NULL;
a41c76
+    g_autofree char *hotplug = NULL;
a41c76
     g_autofree char *ioeventfd = NULL;
a41c76
     g_autofree char *portsStr = NULL;
a41c76
     g_autofree char *iothread = NULL;
a41c76
@@ -11004,6 +11005,7 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
a41c76
                 chassis = virXMLPropString(cur, "chassis");
a41c76
                 port = virXMLPropString(cur, "port");
a41c76
                 busNr = virXMLPropString(cur, "busNr");
a41c76
+                hotplug = virXMLPropString(cur, "hotplug");
a41c76
                 targetIndex = virXMLPropString(cur, "index");
a41c76
                 processedTarget = true;
a41c76
             }
a41c76
@@ -11240,6 +11242,17 @@ virDomainControllerDefParseXML(virDomainXMLOptionPtr xmlopt,
a41c76
             }
a41c76
             def->opts.pciopts.numaNode = numaNode;
a41c76
         }
a41c76
+        if (hotplug) {
a41c76
+            int val = virTristateSwitchTypeFromString(hotplug);
a41c76
+
a41c76
+            if (val <= 0) {
a41c76
+                virReportError(VIR_ERR_XML_ERROR,
a41c76
+                               _("PCI controller unrecognized hotplug setting '%s'"),
a41c76
+                               hotplug);
a41c76
+                goto error;
a41c76
+            }
a41c76
+            def->opts.pciopts.hotplug = val;
a41c76
+        }
a41c76
         break;
a41c76
     case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: {
a41c76
         g_autofree char *gntframes = virXMLPropString(node, "maxGrantFrames");
a41c76
@@ -25112,7 +25125,8 @@ virDomainControllerDefFormat(virBufferPtr buf,
a41c76
             def->opts.pciopts.port != -1 ||
a41c76
             def->opts.pciopts.busNr != -1 ||
a41c76
             def->opts.pciopts.targetIndex != -1 ||
a41c76
-            def->opts.pciopts.numaNode != -1) {
a41c76
+            def->opts.pciopts.numaNode != -1 ||
a41c76
+            def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
a41c76
             virBufferAddLit(&childBuf, "
a41c76
             if (def->opts.pciopts.chassisNr != -1)
a41c76
                 virBufferAsprintf(&childBuf, " chassisNr='%d'",
a41c76
@@ -25129,6 +25143,10 @@ virDomainControllerDefFormat(virBufferPtr buf,
a41c76
             if (def->opts.pciopts.targetIndex != -1)
a41c76
                 virBufferAsprintf(&childBuf, " index='%d'",
a41c76
                                   def->opts.pciopts.targetIndex);
a41c76
+            if (def->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_ABSENT) {
a41c76
+                virBufferAsprintf(&childBuf, " hotplug='%s'",
a41c76
+                                  virTristateSwitchTypeToString(def->opts.pciopts.hotplug));
a41c76
+            }
a41c76
             if (def->opts.pciopts.numaNode == -1) {
a41c76
                 virBufferAddLit(&childBuf, "/>\n");
a41c76
             } else {
a41c76
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
a41c76
index 2a382ede72..118077edaa 100644
a41c76
--- a/src/conf/domain_conf.h
a41c76
+++ b/src/conf/domain_conf.h
a41c76
@@ -719,6 +719,7 @@ struct _virDomainPCIControllerOpts {
a41c76
      * item in memory target config) -1 == unspecified
a41c76
      */
a41c76
     int numaNode;
a41c76
+    virTristateSwitch hotplug; /* 'off' to prevent hotplug/unplug, default 'on' */
a41c76
 };
a41c76
 
a41c76
 struct _virDomainUSBControllerOpts {
a41c76
diff --git a/tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml b/tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml
a41c76
new file mode 100644
a41c76
index 0000000000..8a01494470
a41c76
--- /dev/null
a41c76
+++ b/tests/qemuxml2argvdata/pcie-root-port-nohotplug.xml
a41c76
@@ -0,0 +1,35 @@
a41c76
+<domain type='qemu'>
a41c76
+  <name>guest</name>
a41c76
+  <uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
a41c76
+  <memory unit='KiB'>2097152</memory>
a41c76
+  <currentMemory unit='KiB'>2097152</currentMemory>
a41c76
+  <vcpu placement='static'>2</vcpu>
a41c76
+  <os>
a41c76
+    <type arch='x86_64' machine='q35'>hvm</type>
a41c76
+  </os>
a41c76
+  <devices>
a41c76
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
a41c76
+    <controller type='pci' index='0' model='pcie-root'/>
a41c76
+    <controller type='pci' index='1' model='pcie-root-port'/>
a41c76
+    <controller type='pci' index='2' model='pcie-root-port'>
a41c76
+      <target hotplug='off'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='3' model='pcie-root-port'>
a41c76
+      <model name='ioh3420'/>
a41c76
+      <target hotplug='off'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='4' model='pcie-switch-upstream-port'/>
a41c76
+    <controller type='pci' index='5' model='pcie-switch-downstream-port'>
a41c76
+      <target hotplug='off'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='6' model='pcie-switch-downstream-port'>
a41c76
+      <target hotplug='on'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='7' model='pcie-switch-downstream-port'/>
a41c76
+    <controller type='pci' index='8' model='pcie-switch-downstream-port'>
a41c76
+      <model name='xio3130-downstream'/>
a41c76
+      <target chassis='30' port='0x27'/>
a41c76
+    </controller>
a41c76
+    <memballoon model='none'/>
a41c76
+  </devices>
a41c76
+</domain>
a41c76
diff --git a/tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml b/tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml
a41c76
new file mode 100644
a41c76
index 0000000000..f7dbaccae9
a41c76
--- /dev/null
a41c76
+++ b/tests/qemuxml2xmloutdata/pcie-root-port-nohotplug.x86_64-latest.xml
a41c76
@@ -0,0 +1,67 @@
a41c76
+<domain type='qemu'>
a41c76
+  <name>guest</name>
a41c76
+  <uuid>11dbdcdd-4c3b-482b-8903-9bdb8c0a2774</uuid>
a41c76
+  <memory unit='KiB'>2097152</memory>
a41c76
+  <currentMemory unit='KiB'>2097152</currentMemory>
a41c76
+  <vcpu placement='static'>2</vcpu>
a41c76
+  <os>
a41c76
+    <type arch='x86_64' machine='q35'>hvm</type>
a41c76
+    <boot dev='hd'/>
a41c76
+  </os>
a41c76
+  <clock offset='utc'/>
a41c76
+  <on_poweroff>destroy</on_poweroff>
a41c76
+  <on_reboot>restart</on_reboot>
a41c76
+  <on_crash>destroy</on_crash>
a41c76
+  <devices>
a41c76
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
a41c76
+    <controller type='pci' index='0' model='pcie-root'/>
a41c76
+    <controller type='pci' index='1' model='pcie-root-port'>
a41c76
+      <model name='pcie-root-port'/>
a41c76
+      <target chassis='1' port='0x8'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='2' model='pcie-root-port'>
a41c76
+      <model name='pcie-root-port'/>
a41c76
+      <target chassis='2' port='0x9' hotplug='off'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='3' model='pcie-root-port'>
a41c76
+      <model name='ioh3420'/>
a41c76
+      <target chassis='3' port='0xa' hotplug='off'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='4' model='pcie-switch-upstream-port'>
a41c76
+      <model name='x3130-upstream'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='5' model='pcie-switch-downstream-port'>
a41c76
+      <model name='xio3130-downstream'/>
a41c76
+      <target chassis='5' port='0x0' hotplug='off'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='6' model='pcie-switch-downstream-port'>
a41c76
+      <model name='xio3130-downstream'/>
a41c76
+      <target chassis='6' port='0x1' hotplug='on'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x01' function='0x0'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='7' model='pcie-switch-downstream-port'>
a41c76
+      <model name='xio3130-downstream'/>
a41c76
+      <target chassis='7' port='0x2'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
a41c76
+    </controller>
a41c76
+    <controller type='pci' index='8' model='pcie-switch-downstream-port'>
a41c76
+      <model name='xio3130-downstream'/>
a41c76
+      <target chassis='30' port='0x27'/>
a41c76
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x03' function='0x0'/>
a41c76
+    </controller>
a41c76
+    <controller type='usb' index='0' model='qemu-xhci'>
a41c76
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
a41c76
+    </controller>
a41c76
+    <controller type='sata' index='0'>
a41c76
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
a41c76
+    </controller>
a41c76
+    <input type='mouse' bus='ps2'/>
a41c76
+    <input type='keyboard' bus='ps2'/>
a41c76
+    <memballoon model='none'/>
a41c76
+  </devices>
a41c76
+</domain>
a41c76
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
a41c76
index 15110dd104..c8218e423e 100644
a41c76
--- a/tests/qemuxml2xmltest.c
a41c76
+++ b/tests/qemuxml2xmltest.c
a41c76
@@ -953,7 +953,7 @@ mymain(void)
a41c76
             QEMU_CAPS_DEVICE_IOH3420);
a41c76
     DO_TEST("pcie-root-port-model-ioh3420",
a41c76
             QEMU_CAPS_DEVICE_IOH3420);
a41c76
-
a41c76
+    DO_TEST_CAPS_LATEST("pcie-root-port-nohotplug");
a41c76
     DO_TEST("pcie-switch-upstream-port",
a41c76
             QEMU_CAPS_DEVICE_IOH3420,
a41c76
             QEMU_CAPS_DEVICE_X3130_UPSTREAM,
a41c76
-- 
a41c76
2.26.2
a41c76