render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c401cc
From 0d7d69ef2dc65cc9bbfe63b9f6304aa9232636d8 Mon Sep 17 00:00:00 2001
c401cc
Message-Id: <0d7d69ef2dc65cc9bbfe63b9f6304aa9232636d8@dist-git>
c401cc
From: Peter Krempa <pkrempa@redhat.com>
c401cc
Date: Wed, 26 Feb 2014 14:54:49 +0100
c401cc
Subject: [PATCH] conf: Add functions to copy and free network disk source
c401cc
 definitions
c401cc
c401cc
https://bugzilla.redhat.com/show_bug.cgi?id=1032370
c401cc
c401cc
To simplify operations on virDomainDiskHostDef arrays we will need deep
c401cc
copy and freeing functions. Add and properly export them.
c401cc
c401cc
(cherry picked from commit ae361674aca64b97288b81874b8e565e12f685e0)
c401cc
c401cc
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c401cc
---
c401cc
 src/conf/domain_conf.c   | 55 +++++++++++++++++++++++++++++++++++++++++++++---
c401cc
 src/conf/domain_conf.h   |  3 +++
c401cc
 src/libvirt_private.syms |  2 ++
c401cc
 3 files changed, 57 insertions(+), 3 deletions(-)
c401cc
c401cc
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
c401cc
index cec0236..4e182f1 100644
c401cc
--- a/src/conf/domain_conf.c
c401cc
+++ b/src/conf/domain_conf.c
c401cc
@@ -1211,9 +1211,7 @@ void virDomainDiskDefFree(virDomainDiskDefPtr def)
c401cc
         VIR_FREE(def->seclabels);
c401cc
     }
c401cc
 
c401cc
-    for (i = 0; i < def->nhosts; i++)
c401cc
-        virDomainDiskHostDefClear(&def->hosts[i]);
c401cc
-    VIR_FREE(def->hosts);
c401cc
+    virDomainDiskHostDefFree(def->nhosts, def->hosts);
c401cc
 
c401cc
     VIR_FREE(def);
c401cc
 }
c401cc
@@ -1228,6 +1226,57 @@ void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def)
c401cc
     VIR_FREE(def->socket);
c401cc
 }
c401cc
 
c401cc
+
c401cc
+void
c401cc
+virDomainDiskHostDefFree(size_t nhosts,
c401cc
+                         virDomainDiskHostDefPtr hosts)
c401cc
+{
c401cc
+    size_t i;
c401cc
+
c401cc
+    if (!hosts)
c401cc
+        return;
c401cc
+
c401cc
+    for (i = 0; i < nhosts; i++)
c401cc
+        virDomainDiskHostDefClear(&hosts[i]);
c401cc
+
c401cc
+    VIR_FREE(hosts);
c401cc
+}
c401cc
+
c401cc
+
c401cc
+virDomainDiskHostDefPtr
c401cc
+virDomainDiskHostDefCopy(size_t nhosts,
c401cc
+                         virDomainDiskHostDefPtr hosts)
c401cc
+{
c401cc
+    virDomainDiskHostDefPtr ret = NULL;
c401cc
+    size_t i;
c401cc
+
c401cc
+    if (VIR_ALLOC_N(ret, nhosts) < 0)
c401cc
+        goto error;
c401cc
+
c401cc
+    for (i = 0; i < nhosts; i++) {
c401cc
+        virDomainDiskHostDefPtr src = &hosts[i];
c401cc
+        virDomainDiskHostDefPtr dst = &ret[i];
c401cc
+
c401cc
+        dst->transport = src->transport;
c401cc
+
c401cc
+        if (VIR_STRDUP(dst->name, src->name) < 0)
c401cc
+            goto error;
c401cc
+
c401cc
+        if (VIR_STRDUP(dst->port, src->port) < 0)
c401cc
+            goto error;
c401cc
+
c401cc
+        if (VIR_STRDUP(dst->socket, src->socket) < 0)
c401cc
+            goto error;
c401cc
+    }
c401cc
+
c401cc
+    return ret;
c401cc
+
c401cc
+error:
c401cc
+    virDomainDiskHostDefFree(nhosts, ret);
c401cc
+    return NULL;
c401cc
+}
c401cc
+
c401cc
+
c401cc
 void virDomainControllerDefFree(virDomainControllerDefPtr def)
c401cc
 {
c401cc
     if (!def)
c401cc
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
c401cc
index fa81fa1..3d8666a 100644
c401cc
--- a/src/conf/domain_conf.h
c401cc
+++ b/src/conf/domain_conf.h
c401cc
@@ -2210,6 +2210,9 @@ void virDomainInputDefFree(virDomainInputDefPtr def);
c401cc
 void virDomainDiskDefFree(virDomainDiskDefPtr def);
c401cc
 void virDomainLeaseDefFree(virDomainLeaseDefPtr def);
c401cc
 void virDomainDiskHostDefClear(virDomainDiskHostDefPtr def);
c401cc
+void virDomainDiskHostDefFree(size_t nhosts, virDomainDiskHostDefPtr hosts);
c401cc
+virDomainDiskHostDefPtr virDomainDiskHostDefCopy(size_t nhosts,
c401cc
+                                                 virDomainDiskHostDefPtr hosts);
c401cc
 int virDomainDeviceFindControllerModel(virDomainDefPtr def,
c401cc
                                        virDomainDeviceInfoPtr info,
c401cc
                                        int controllerType);
c401cc
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
c401cc
index 4d80130..827b1ec 100644
c401cc
--- a/src/libvirt_private.syms
c401cc
+++ b/src/libvirt_private.syms
c401cc
@@ -196,6 +196,8 @@ virDomainDiskFindByBusAndDst;
c401cc
 virDomainDiskGeometryTransTypeFromString;
c401cc
 virDomainDiskGeometryTransTypeToString;
c401cc
 virDomainDiskHostDefClear;
c401cc
+virDomainDiskHostDefCopy;
c401cc
+virDomainDiskHostDefFree;
c401cc
 virDomainDiskIndexByName;
c401cc
 virDomainDiskInsert;
c401cc
 virDomainDiskInsertPreAlloced;
c401cc
-- 
c401cc
1.9.0
c401cc