[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 04/13] Introduce virDomainPCIMultifunctionDeviceAddressAssign



This patch assigns multifunction pci addresses to devices in the devlist.
The pciaddrs passed in the argument is not altered so that the actual call to
reserve the address using virDomainPCIAddressEnsureAddr() passes. The function
focuses on user given address validation and also the auto-assign of addresses.
The address auto-assignment works well for PPC64 and x86-i440fx machines.

The q35 machines needs some level of logic here to get the correct next valid
slot so that the hotplug go through fine.

Signed-off-by: Shivaprasad G Bhat <sbhat linux vnet ibm com>
---
 src/conf/domain_addr.c   |  113 ++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_addr.h   |    4 ++
 src/libvirt_private.syms |    1 
 3 files changed, 118 insertions(+)

diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c
index 7ea9e4d..c171067 100644
--- a/src/conf/domain_addr.c
+++ b/src/conf/domain_addr.c
@@ -455,6 +455,119 @@ virDomainPCIAddressReserveSlot(virDomainPCIAddressSetPtr addrs,
 }
 
 int
+virDomainPCIMultifunctionDeviceAddressValidateAssign(virDomainPCIAddressSetPtr addrs, virDomainDeviceDefListPtr devlist)
+{
+    size_t i;
+    char *addrStr = NULL;
+    virPCIDeviceAddress addr;
+    virDomainPCIAddressBusPtr bus;
+    uint8_t slot;
+    virDomainDeviceInfoPtr info = NULL, privinfo = NULL;
+    virDomainPCIConnectFlags flags = VIR_PCI_CONNECT_TYPES_MASK;
+
+    if (virDomainPCIAddressGetNextSlot(addrs, &addr, flags) < 0)
+        return -1;
+
+    bus = &addrs->buses[addr.bus];
+    slot = bus->slots[addr.slot];
+
+    for (i = 0; i < devlist->count; i++) {
+        virDomainDeviceDefPtr dev = devlist->devs[i];
+        switch ((virDomainDeviceType) dev->type) {
+        case VIR_DOMAIN_DEVICE_DISK:
+            info = &dev->data.disk->info;
+            break;
+        case VIR_DOMAIN_DEVICE_NET:
+            info = &dev->data.net->info;
+            break;
+        case VIR_DOMAIN_DEVICE_RNG:
+            info = &dev->data.rng->info;
+            break;
+        case VIR_DOMAIN_DEVICE_HOSTDEV:
+            info = dev->data.hostdev->info;
+            break;
+        case VIR_DOMAIN_DEVICE_CONTROLLER:
+            info = &dev->data.controller->info;
+            break;
+        case VIR_DOMAIN_DEVICE_CHR:
+        case VIR_DOMAIN_DEVICE_FS:
+        case VIR_DOMAIN_DEVICE_INPUT:
+        case VIR_DOMAIN_DEVICE_SOUND:
+        case VIR_DOMAIN_DEVICE_VIDEO:
+        case VIR_DOMAIN_DEVICE_WATCHDOG:
+        case VIR_DOMAIN_DEVICE_HUB:
+        case VIR_DOMAIN_DEVICE_SMARTCARD:
+        case VIR_DOMAIN_DEVICE_MEMBALLOON:
+        case VIR_DOMAIN_DEVICE_NVRAM:
+        case VIR_DOMAIN_DEVICE_SHMEM:
+        case VIR_DOMAIN_DEVICE_LEASE:
+        case VIR_DOMAIN_DEVICE_REDIRDEV:
+        case VIR_DOMAIN_DEVICE_MEMORY:
+        case VIR_DOMAIN_DEVICE_NONE:
+        case VIR_DOMAIN_DEVICE_TPM:
+        case VIR_DOMAIN_DEVICE_PANIC:
+        case VIR_DOMAIN_DEVICE_GRAPHICS:
+        case VIR_DOMAIN_DEVICE_LAST:
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Only PCI devices are allowed"));
+            break;
+        }
+
+        if (i == 0 && info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+           /* User has given an address in xml use that slot
+            * and bus instead */
+            bus = &addrs->buses[info->addr.pci.bus];
+            slot = bus->slots[info->addr.pci.slot];
+            if (slot & 0xFF) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Slot not free"));
+                goto error;
+            }
+        }
+
+        if (privinfo) {
+            if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+                if (privinfo->addr.pci.bus != info->addr.pci.bus ||
+                    privinfo->addr.pci.slot != info->addr.pci.slot) {
+                    virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Multifunction PCI device "
+                                 "cant be split across different guest PCI slots"));
+                    return -1;
+                }
+            }
+        }
+
+        if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE) {
+            info->addr.pci = addr;
+            info->addr.pci.function = devlist->count - i - 1;
+            info->type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
+            if (info->addr.pci.function == 0)
+                info->addr.pci.multi = VIR_TRISTATE_SWITCH_ON;
+        } else if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI) {
+            if (info->addr.pci.function != devlist->count - i - 1) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("PCI function numbers to be in decreasing order"));
+                goto error;
+            }
+        }
+
+        if (!(addrStr = virDomainPCIAddressAsString(&info->addr.pci)))
+            goto error;
+
+        if (!virDomainPCIAddressValidate(addrs, &info->addr.pci,
+                                         addrStr, flags, true))
+            goto error;
+
+        privinfo = info;
+    }
+
+    return 0;
+ error:
+    return -1;
+}
+
+
+int
 virDomainPCIAddressEnsureAddr(virDomainPCIAddressSetPtr addrs,
                               virDomainDeviceInfoPtr dev)
 {
diff --git a/src/conf/domain_addr.h b/src/conf/domain_addr.h
index f3eda89..1e810b0 100644
--- a/src/conf/domain_addr.h
+++ b/src/conf/domain_addr.h
@@ -157,6 +157,10 @@ int virDomainPCIAddressReserveNextSlot(virDomainPCIAddressSetPtr addrs,
                                        virDomainPCIConnectFlags flags)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+int
+virDomainPCIMultifunctionDeviceAddressValidateAssign(virDomainPCIAddressSetPtr addrs,
+                                             virDomainDeviceDefListPtr devlist);
+
 struct _virDomainCCWAddressSet {
     virHashTablePtr defined;
     virDomainDeviceCCWAddress next;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0e8a887..9262859 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -109,6 +109,7 @@ virDomainPCIAddressSetGrow;
 virDomainPCIAddressSlotInUse;
 virDomainPCIAddressValidate;
 virDomainPCIControllerModelToConnectType;
+virDomainPCIMultifunctionDeviceAddressValidateAssign;
 virDomainVirtioSerialAddrAssign;
 virDomainVirtioSerialAddrAutoAssign;
 virDomainVirtioSerialAddrIsComplete;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]