[RFC PATCH 04/12] domain_conf: introduce cpu device hotplug helpers

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

 



virDomainCPUFind - to find a cpu within VM def
virDomainCPUInsert - wrapper for inserting a new cpu device into VM def
virDomainCPURemove - wrapper for removing cpu from VM def

Signed-off-by: Zhu Guihua <zhugh.fnst@xxxxxxxxxxxxxx>
---
 src/conf/domain_conf.c   | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   | 13 +++++++++++
 src/libvirt_private.syms |  3 +++
 3 files changed, 75 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1f05056..45f954f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12142,6 +12142,65 @@ virDomainChrRemove(virDomainDefPtr vmdef,
     return ret;
 }
 
+int
+virDomainCPUInsert(virDomainDefPtr vmdef,
+                   virDomainCPUDefPtr cpu)
+{
+    return VIR_APPEND_ELEMENT(vmdef->cpus, vmdef->ncpus, cpu);
+}
+
+bool
+virDomainCPUEquals(virDomainCPUDefPtr src,
+                   virDomainCPUDefPtr tgt)
+{
+    bool ret = false;
+
+    if (!src || !tgt)
+        return src == tgt;
+
+    if (src->apic_id == tgt->apic_id)
+        ret = true;
+
+    return ret;
+}
+
+virDomainCPUDefPtr
+virDomainCPUFind(virDomainDefPtr def,
+                 virDomainCPUDefPtr target)
+{
+    virDomainCPUDefPtr cpu;
+    size_t i;
+
+    for (i = 0; i < def->ncpus; i++) {
+        cpu = def->cpus[i];
+        if (virDomainCPUEquals(cpu, target))
+            return cpu;
+    }
+
+    return NULL;
+}
+
+virDomainCPUDefPtr
+virDomainCPURemove(virDomainDefPtr vmdef,
+                   virDomainCPUDefPtr cpu)
+{
+    virDomainCPUDefPtr ret;
+    size_t i;
+
+    for (i = 0; i < vmdef->ncpus; i++) {
+        ret = vmdef->cpus[i];
+
+        if (virDomainCPUEquals(ret, cpu))
+            break;
+    }
+
+    if (i == vmdef->ncpus)
+        return NULL;
+
+    VIR_DELETE_ELEMENT(vmdef->cpus, i, vmdef->ncpus);
+    return ret;
+}
+
 char *
 virDomainDefGetDefaultEmulator(virDomainDefPtr def,
                                virCapsPtr caps)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 618eef3..4b71052 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2674,6 +2674,19 @@ virDomainChrDefPtr
 virDomainChrRemove(virDomainDefPtr vmdef,
                    virDomainChrDefPtr chr);
 
+int
+virDomainCPUInsert(virDomainDefPtr vmdef,
+                       virDomainCPUDefPtr cpu);
+bool
+virDomainCPUEquals(virDomainCPUDefPtr src,
+                   virDomainCPUDefPtr tgt);
+virDomainCPUDefPtr
+virDomainCPUFind(virDomainDefPtr def,
+                 virDomainCPUDefPtr cpu);
+virDomainCPUDefPtr
+virDomainCPURemove(virDomainDefPtr vmdef,
+                   virDomainCPUDefPtr cpu);
+
 int virDomainSaveXML(const char *configDir,
                      virDomainDefPtr def,
                      const char *xml);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9ceff71..032e9a9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -167,6 +167,9 @@ virDomainChrTcpProtocolTypeToString;
 virDomainChrTypeFromString;
 virDomainChrTypeToString;
 virDomainCPUDefFree;
+virDomainCPUInsert;
+virDomainCPUFind;
+virDomainCPURemove;
 virDomainClockBasisTypeToString;
 virDomainClockOffsetTypeFromString;
 virDomainClockOffsetTypeToString;
-- 
1.9.3

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