]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Helper function for making a copy of virCPUDefPtr
authorJiri Denemark <jdenemar@redhat.com>
Tue, 23 Mar 2010 08:34:04 +0000 (09:34 +0100)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 26 Mar 2010 22:03:17 +0000 (23:03 +0100)
src/conf/cpu_conf.c
src/conf/cpu_conf.h
src/libvirt_private.syms

index 612e376393c43ceb4bfa7cd3e6af6ad281ae8738..cf91930365885901a61a3c26752b657a8f2945c5 100644 (file)
@@ -67,6 +67,43 @@ virCPUDefFree(virCPUDefPtr def)
 }
 
 
+virCPUDefPtr
+virCPUDefCopy(const virCPUDefPtr cpu)
+{
+    virCPUDefPtr copy;
+    unsigned int i;
+
+    if (!cpu)
+        return NULL;
+
+    if (VIR_ALLOC(copy) < 0
+        || (cpu->arch && !(copy->arch = strdup(cpu->arch)))
+        || (cpu->model && !(copy->model = strdup(cpu->model)))
+        || VIR_ALLOC_N(copy->features, cpu->nfeatures) < 0)
+        goto no_memory;
+
+    copy->type = cpu->type;
+    copy->match = cpu->match;
+    copy->sockets = cpu->sockets;
+    copy->cores = cpu->cores;
+    copy->threads = cpu->threads;
+    copy->nfeatures = cpu->nfeatures;
+
+    for (i = 0; i < copy->nfeatures; i++) {
+        copy->features[i].policy = cpu->features[i].policy;
+        if (!(copy->features[i].name = strdup(cpu->features[i].name)))
+            goto no_memory;
+    }
+
+    return copy;
+
+no_memory:
+    virReportOOMError();
+    virCPUDefFree(copy);
+    return NULL;
+}
+
+
 #ifndef PROXY
 virCPUDefPtr
 virCPUDefParseXML(const xmlNodePtr node,
index bb8a8442b82f0f3da38174fa855763a65ecb217f..a30991d234bd6c2a8f4e709b7cb373337f245de7 100644 (file)
@@ -83,6 +83,9 @@ struct _virCPUDef {
 void
 virCPUDefFree(virCPUDefPtr def);
 
+virCPUDefPtr
+virCPUDefCopy(const virCPUDefPtr cpu);
+
 # ifndef PROXY
 virCPUDefPtr
 virCPUDefParseXML(const xmlNodePtr node,
index b389723ab4b623de6ea8e3f6d891b98eb9054824..4111010b199d3933fb3fc32e2af584ed7a02be38 100644 (file)
@@ -90,6 +90,7 @@ virCPUDefParseXML;
 virCPUDefFormat;
 virCPUDefFormatBuf;
 virCPUDefAddFeature;
+virCPUDefCopy;
 
 
 # datatypes.h