Blame SOURCES/libvirt-qemu-conf-set-HOTPLUGGABLE-connect-flag-during-PCI-address-set-init.patch

b971b8
From 351bb3a04c1eb6de11efad54f809a6f3e3a868c8 Mon Sep 17 00:00:00 2001
b971b8
Message-Id: <351bb3a04c1eb6de11efad54f809a6f3e3a868c8@dist-git>
b971b8
From: Laine Stump <laine@redhat.com>
b971b8
Date: Sun, 26 Apr 2020 13:17:01 -0400
b971b8
Subject: [PATCH] qemu/conf: set HOTPLUGGABLE connect flag during PCI address
b971b8
 set init
b971b8
b971b8
virDomainPCIAddressBusSetModel() is called for each PCI controller
b971b8
when building an address set prior to assiging PCI addresses to
b971b8
devices.
b971b8
b971b8
This patch adds a new argument, allowHotplug, to that function that
b971b8
can be set to false if we know for certain that a particular
b971b8
controller won't support hotplug
b971b8
b971b8
The most interesting case is in qemuDomainPCIAddressSetCreate(), where
b971b8
the config of each existing controller is available while building the
b971b8
address set, so we can appropriately set allowHotplug = false when the
b971b8
user has "hotplug='off'" in the config of a controller that normally
b971b8
would support hotplug. In all other cases, it is set to true or false
b971b8
in accordance with the capability of the controller model.
b971b8
b971b8
So far we aren't doing anything with this bus flag in the address set.
b971b8
b971b8
Signed-off-by: Laine Stump <laine@redhat.com>
b971b8
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
b971b8
(cherry picked from commit aa15e9259f1f246e69fb9742581ced720c88695d)
b971b8
b971b8
https://bugzilla.redhat.com/1802592
b971b8
Signed-off-by: Laine Stump <laine@redhat.com>
b971b8
Message-Id: <20200426171703.18808-1-laine@redhat.com>
b971b8
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
b971b8
---
b971b8
 src/conf/domain_addr.c         | 31 +++++++++++++++++++++----------
b971b8
 src/conf/domain_addr.h         |  3 ++-
b971b8
 src/qemu/qemu_domain_address.c | 10 +++++++---
b971b8
 3 files changed, 30 insertions(+), 14 deletions(-)
b971b8
b971b8
diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
b971b8
index 05f036e3e6..cc45a0bbf1 100644
b971b8
--- a/src/conf/domain_addr.c
b971b8
+++ b/src/conf/domain_addr.c
b971b8
@@ -495,31 +495,40 @@ virDomainPCIAddressValidate(virDomainPCIAddressSetPtr addrs,
b971b8
 
b971b8
 int
b971b8
 virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus,
b971b8
-                               virDomainControllerModelPCI model)
b971b8
+                               virDomainControllerModelPCI model,
b971b8
+                               bool allowHotplug)
b971b8
 {
b971b8
     /* set flags for what can be connected *downstream* from each
b971b8
      * bus.
b971b8
      */
b971b8
+    virDomainPCIConnectFlags hotplugFlag = 0;
b971b8
+
b971b8
+    if (allowHotplug)
b971b8
+        hotplugFlag = VIR_PCI_CONNECT_HOTPLUGGABLE;
b971b8
+
b971b8
     switch (model) {
b971b8
     case VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT:
b971b8
         bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCI_DEVICE |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCI_BRIDGE |
b971b8
-                      VIR_PCI_CONNECT_TYPE_PCI_EXPANDER_BUS);
b971b8
+                      VIR_PCI_CONNECT_TYPE_PCI_EXPANDER_BUS |
b971b8
+                      hotplugFlag);
b971b8
         bus->minSlot = 1;
b971b8
         bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST;
b971b8
         break;
b971b8
     case VIR_DOMAIN_CONTROLLER_MODEL_PCI_BRIDGE:
b971b8
         bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCI_DEVICE |
b971b8
-                      VIR_PCI_CONNECT_TYPE_PCI_BRIDGE);
b971b8
+                      VIR_PCI_CONNECT_TYPE_PCI_BRIDGE |
b971b8
+                      hotplugFlag);
b971b8
         bus->minSlot = 1;
b971b8
         bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST;
b971b8
         break;
b971b8
     case VIR_DOMAIN_CONTROLLER_MODEL_PCI_EXPANDER_BUS:
b971b8
         bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCI_DEVICE |
b971b8
-                      VIR_PCI_CONNECT_TYPE_PCI_BRIDGE);
b971b8
+                      VIR_PCI_CONNECT_TYPE_PCI_BRIDGE |
b971b8
+                      hotplugFlag);
b971b8
         bus->minSlot = 0;
b971b8
         bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST;
b971b8
         break;
b971b8
@@ -550,7 +559,8 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus,
b971b8
          * the first of which is not usable because of the SHPC */
b971b8
         bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCI_DEVICE |
b971b8
-                      VIR_PCI_CONNECT_TYPE_PCI_BRIDGE);
b971b8
+                      VIR_PCI_CONNECT_TYPE_PCI_BRIDGE |
b971b8
+                      hotplugFlag);
b971b8
         bus->minSlot = 1;
b971b8
         bus->maxSlot = VIR_PCI_ADDRESS_SLOT_LAST;
b971b8
         break;
b971b8
@@ -562,7 +572,8 @@ virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus,
b971b8
         bus->flags = (VIR_PCI_CONNECT_AUTOASSIGN |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCIE_DEVICE |
b971b8
                       VIR_PCI_CONNECT_TYPE_PCIE_SWITCH_UPSTREAM_PORT |
b971b8
-                      VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE);
b971b8
+                      VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE |
b971b8
+                      hotplugFlag);
b971b8
         bus->minSlot = 0;
b971b8
         bus->maxSlot = 0;
b971b8
         break;
b971b8
@@ -759,7 +770,7 @@ virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs,
b971b8
          * rest are of the requested type
b971b8
          */
b971b8
         if (virDomainPCIAddressBusSetModel(&addrs->buses[i++],
b971b8
-                                           VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE) < 0) {
b971b8
+                                           VIR_DOMAIN_CONTROLLER_MODEL_DMI_TO_PCI_BRIDGE, false) < 0) {
b971b8
             return -1;
b971b8
         }
b971b8
     }
b971b8
@@ -776,20 +787,20 @@ virDomainPCIAddressSetGrow(virDomainPCIAddressSetPtr addrs,
b971b8
          * will be allocated for the dummy PCIe device later on.
b971b8
          */
b971b8
         if (virDomainPCIAddressBusSetModel(&addrs->buses[i],
b971b8
-                                           VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT) < 0) {
b971b8
+                                           VIR_DOMAIN_CONTROLLER_MODEL_PCIE_ROOT_PORT, true) < 0) {
b971b8
             return -1;
b971b8
         }
b971b8
         addrs->buses[i].flags = VIR_PCI_CONNECT_TYPE_PCIE_TO_PCI_BRIDGE;
b971b8
         i++;
b971b8
 
b971b8
         if (virDomainPCIAddressBusSetModel(&addrs->buses[i++],
b971b8
-                                           VIR_DOMAIN_CONTROLLER_MODEL_PCIE_TO_PCI_BRIDGE) < 0) {
b971b8
+                                           VIR_DOMAIN_CONTROLLER_MODEL_PCIE_TO_PCI_BRIDGE, true) < 0) {
b971b8
             return -1;
b971b8
         }
b971b8
     }
b971b8
 
b971b8
     for (; i < addrs->nbuses; i++) {
b971b8
-        if (virDomainPCIAddressBusSetModel(&addrs->buses[i], model) < 0)
b971b8
+        if (virDomainPCIAddressBusSetModel(&addrs->buses[i], model, true) < 0)
b971b8
             return -1;
b971b8
     }
b971b8
 
b971b8
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
b971b8
index 40738ddb72..c1363c1490 100644
b971b8
--- a/src/conf/domain_addr.h
b971b8
+++ b/src/conf/domain_addr.h
b971b8
@@ -148,7 +148,8 @@ bool virDomainPCIAddressValidate(virDomainPCIAddressSetPtr addrs,
b971b8
 
b971b8
 
b971b8
 int virDomainPCIAddressBusSetModel(virDomainPCIAddressBusPtr bus,
b971b8
-                                   virDomainControllerModelPCI model)
b971b8
+                                   virDomainControllerModelPCI model,
b971b8
+                                   bool allowHotplug)
b971b8
     ATTRIBUTE_NONNULL(1);
b971b8
 
b971b8
 bool virDomainPCIAddressBusIsFullyReserved(virDomainPCIAddressBusPtr bus)
b971b8
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
b971b8
index e81585bc6c..2ae1724696 100644
b971b8
--- a/src/qemu/qemu_domain_address.c
b971b8
+++ b/src/qemu/qemu_domain_address.c
b971b8
@@ -1645,6 +1645,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
b971b8
     for (i = 0; i < def->ncontrollers; i++) {
b971b8
         virDomainControllerDefPtr cont = def->controllers[i];
b971b8
         size_t idx = cont->idx;
b971b8
+        bool allowHotplug = false;
b971b8
 
b971b8
         if (cont->type != VIR_DOMAIN_CONTROLLER_TYPE_PCI)
b971b8
             continue;
b971b8
@@ -1656,7 +1657,10 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
b971b8
             goto error;
b971b8
         }
b971b8
 
b971b8
-        if (virDomainPCIAddressBusSetModel(&addrs->buses[idx], cont->model) < 0)
b971b8
+        if (cont->opts.pciopts.hotplug != VIR_TRISTATE_SWITCH_OFF)
b971b8
+            allowHotplug = true;
b971b8
+
b971b8
+        if (virDomainPCIAddressBusSetModel(&addrs->buses[idx], cont->model, allowHotplug) < 0)
b971b8
             goto error;
b971b8
 
b971b8
         /* Forward the information about isolation groups */
b971b8
@@ -1674,7 +1678,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
b971b8
          * assigning addresses to devices.
b971b8
          */
b971b8
         if (virDomainPCIAddressBusSetModel(&addrs->buses[0],
b971b8
-                                           VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT) < 0)
b971b8
+                                           VIR_DOMAIN_CONTROLLER_MODEL_PCI_ROOT, true) < 0)
b971b8
             goto error;
b971b8
     }
b971b8
 
b971b8
@@ -1696,7 +1700,7 @@ qemuDomainPCIAddressSetCreate(virDomainDefPtr def,
b971b8
         if (addrs->buses[i].model)
b971b8
             continue;
b971b8
 
b971b8
-        if (virDomainPCIAddressBusSetModel(&addrs->buses[i], defaultModel) < 0)
b971b8
+        if (virDomainPCIAddressBusSetModel(&addrs->buses[i], defaultModel, true) < 0)
b971b8
             goto error;
b971b8
 
b971b8
         VIR_DEBUG("Auto-adding <controller type='pci' model='%s' index='%zu'/>",
b971b8
-- 
b971b8
2.26.2
b971b8