[PATCH 06/10] conf: Add helpers to insert/remove/find shmem devices in domain def

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

 



The helpers will be useful when implementing hotplug and coldplug of
shared memory devices.

Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx>
---
 src/conf/domain_conf.c   | 61 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  7 ++++++
 src/libvirt_private.syms |  3 +++
 3 files changed, 71 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 306b718..8a8e4f7 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -13343,6 +13343,67 @@ virDomainMemoryRemove(virDomainDefPtr def,
 }
 
 
+int
+virDomainShmemInsert(virDomainDefPtr def,
+                     virDomainShmemDefPtr shmem)
+{
+    return VIR_APPEND_ELEMENT(def->shmems, def->nshmems, shmem);
+}
+
+
+ssize_t
+virDomainShmemFind(virDomainDefPtr def,
+                   virDomainShmemDefPtr shmem)
+{
+    size_t i;
+
+    for (i = 0; i < def->nshmems; i++) {
+         virDomainShmemDefPtr tmpshmem = def->shmems[i];
+
+         if (STRNEQ_NULLABLE(shmem->name, tmpshmem->name))
+             continue;
+
+         if (shmem->size != tmpshmem->size)
+             continue;
+
+         if (shmem->server.enabled != tmpshmem->server.enabled ||
+             (shmem->server.enabled &&
+              STRNEQ_NULLABLE(shmem->server.chr.data.nix.path,
+                              tmpshmem->server.chr.data.nix.path)))
+             continue;
+
+         if (shmem->msi.enabled != tmpshmem->msi.enabled ||
+             (shmem->msi.enabled &&
+              (shmem->msi.vectors != tmpshmem->msi.vectors ||
+               shmem->msi.ioeventfd != tmpshmem->msi.ioeventfd)))
+             continue;
+
+        if (shmem->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
+            !virDomainDeviceInfoAddressIsEqual(&shmem->info, &tmpshmem->info))
+            continue;
+
+        break;
+    }
+
+    if (i < def->nshmems)
+        return i;
+
+    return -1;
+}
+
+
+virDomainShmemDefPtr
+virDomainShmemRemove(virDomainDefPtr def,
+                     size_t idx)
+{
+    virDomainShmemDefPtr ret = def->shmems[idx];
+
+    VIR_DELETE_ELEMENT(def->shmems, idx, def->nshmems);
+
+    return ret;
+}
+
+
 char *
 virDomainDefGetDefaultEmulator(virDomainDefPtr def,
                                virCapsPtr caps)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index a4b1bf3..39bc928 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2943,6 +2943,13 @@ int virDomainMemoryFindInactiveByDef(virDomainDefPtr def,
                                      virDomainMemoryDefPtr mem)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
 
+int virDomainShmemInsert(virDomainDefPtr def, virDomainShmemDefPtr shmem)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+ssize_t virDomainShmemFind(virDomainDefPtr def, virDomainShmemDefPtr shmem)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+virDomainShmemDefPtr virDomainShmemRemove(virDomainDefPtr def, size_t idx)
+    ATTRIBUTE_NONNULL(1);
+
 VIR_ENUM_DECL(virDomainTaint)
 VIR_ENUM_DECL(virDomainVirt)
 VIR_ENUM_DECL(virDomainBoot)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3ceb4e3..6127f51 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -439,6 +439,9 @@ virDomainSaveStatus;
 virDomainSaveXML;
 virDomainSeclabelTypeFromString;
 virDomainSeclabelTypeToString;
+virDomainShmemFind;
+virDomainShmemInsert;
+virDomainShmemRemove;
 virDomainShutdownReasonTypeFromString;
 virDomainShutdownReasonTypeToString;
 virDomainShutoffReasonTypeFromString;
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]