render / rpms / libvirt

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