From: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
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(a)linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
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 0d289fbab5..fcd390ace4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -17315,6 +17315,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 e6d3e04109..634865842a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3315,6 +3315,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 e74174ffbd..323291367f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -323,6 +323,7 @@ virDomainDefHasOldStyleUEFI;
virDomainDefHasUSB;
virDomainDefHasVcpusOffline;
virDomainDefHasVFIOHostdev;
+virDomainDefHostdevGetPCIOnlineFunctionMap;
virDomainDefLifecycleActionAllowed;
virDomainDefMaybeAddController;
virDomainDefMaybeAddInput;
--
2.26.2