[PATCH v2 06/21] conf: Add helper to get active functions of a slot of domain

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

 



From: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>

In some cases it may be better to have a bitmap representing the
state of individual functions rather than iterating the definition.
The new helper creates a bitmap representing the state from the
domain definition.

Signed-off-by: Shivaprasad G Bhat <sbhat@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/conf/domain_conf.c   | 27 +++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  3 +++
 src/libvirt_private.syms |  1 +
 3 files changed, 31 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9b60db7ecd..5b918cc737 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16947,6 +16947,33 @@ virDomainHostdevFind(virDomainDefPtr def,
     return *found ? i : -1;
 }
 
+#define PCI_MAX_SLOT_FUNCTIONS 8
+/**
+ * virDomainDefHostdevGetPCIOnlineFunctionMap:
+ * @def: domain definition
+ * @aggrSlotIdx: slot aggregation index
+ * Returns a bitmap representing state of individual functions of a slot.
+ */
+virBitmapPtr
+virDomainDefHostdevGetPCIOnlineFunctionMap(virDomainDefPtr def,
+                                           int aggrSlotIdx)
+{
+    size_t i;
+    virBitmapPtr ret = NULL;
+
+    if (!(ret = virBitmapNew(PCI_MAX_SLOT_FUNCTIONS)))
+        return NULL;
+
+    for (i = 0; i < def->nhostdevs; i++) {
+        size_t function = def->hostdevs[i]->source.subsys.u.pci.addr.function;
+
+        if (def->hostdevs[i]->info->aggregateSlotIdx == aggrSlotIdx)
+            ignore_value(virBitmapSetBit(ret, function));
+    }
+
+    return ret;
+}
+
 static bool
 virDomainDiskControllerMatch(int controller_type, int disk_bus)
 {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e144f3aad3..77a01fbec0 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3212,6 +3212,9 @@ virDomainHostdevDefPtr
 virDomainHostdevRemove(virDomainDefPtr def, size_t i);
 int virDomainHostdevFind(virDomainDefPtr def, virDomainHostdevDefPtr match,
                          virDomainHostdevDefPtr *found);
+virBitmapPtr virDomainDefHostdevGetPCIOnlineFunctionMap(virDomainDefPtr def,
+                                                        int aggrSlotIdx);
+
 
 virDomainGraphicsListenDefPtr
 virDomainGraphicsGetListen(virDomainGraphicsDefPtr def, size_t i);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 702cd958b1..5b247ded4b 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -321,6 +321,7 @@ virDomainDefHasOldStyleUEFI;
 virDomainDefHasUSB;
 virDomainDefHasVcpusOffline;
 virDomainDefHasVFIOHostdev;
+virDomainDefHostdevGetPCIOnlineFunctionMap;
 virDomainDefLifecycleActionAllowed;
 virDomainDefMaybeAddController;
 virDomainDefMaybeAddInput;
-- 
2.24.1






[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux