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

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