[PATCH 04/10] util: storagesource: Add helper to copy and free storage source seclabels

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

 



They will be reused to transfer disk labels from snapshotted disks to
the new disk definitions.
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 43 ++++++++++++++++++++++++++++++++++++-------
 src/util/virstoragefile.h |  3 +++
 3 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 46c0f02..acb2ea3 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1898,6 +1898,7 @@ virStorageNetProtocolTypeToString;
 virStorageSourceAuthClear;
 virStorageSourceClear;
 virStorageSourceClearBackingStore;
+virStorageSourceCopySeclabels;
 virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourceNewFromBacking;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index a23ac6a..d835917 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1496,6 +1496,29 @@ virStorageNetHostDefCopy(size_t nhosts,
 }


+int
+virStorageSourceCopySeclabels(virStorageSourcePtr to,
+                              const virStorageSource *from)
+{
+    size_t i;
+
+    if (VIR_ALLOC_N(to->seclabels, from->nseclabels) < 0)
+        return -1;
+    to->nseclabels = from->nseclabels;
+
+    for (i = 0; i < to->nseclabels; i++) {
+        if (!(to->seclabels[i] = virSecurityDeviceLabelDefCopy(from->seclabels[i])))
+            goto error;
+    }
+
+    return 0;
+
+ error:
+    virStorageSourceClearSeclabels(to);
+    return -1;
+}
+
+
 void
 virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def)
 {
@@ -1555,10 +1578,21 @@ virStorageSourceClearBackingStore(virStorageSourcePtr def)


 void
-virStorageSourceClear(virStorageSourcePtr def)
+virStorageSourceClearSeclabels(virStorageSourcePtr def)
 {
     size_t i;

+    if (def->seclabels) {
+        for (i = 0; i < def->nseclabels; i++)
+            virSecurityDeviceLabelDefFree(def->seclabels[i]);
+        VIR_FREE(def->seclabels);
+    }
+}
+
+
+void
+virStorageSourceClear(virStorageSourcePtr def)
+{
     if (!def)
         return;

@@ -1569,12 +1603,7 @@ virStorageSourceClear(virStorageSourcePtr def)
     virBitmapFree(def->features);
     VIR_FREE(def->compat);
     virStorageEncryptionFree(def->encryption);
-
-    if (def->seclabels) {
-        for (i = 0; i < def->nseclabels; i++)
-            virSecurityDeviceLabelDefFree(def->seclabels[i]);
-        VIR_FREE(def->seclabels);
-    }
+    virStorageSourceClearSeclabels(def);
     virStoragePermsFree(def->perms);
     VIR_FREE(def->timestamps);

diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 34b3625..e686cef 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -317,6 +317,9 @@ void virStorageNetHostDefFree(size_t nhosts, virStorageNetHostDefPtr hosts);
 virStorageNetHostDefPtr virStorageNetHostDefCopy(size_t nhosts,
                                                  virStorageNetHostDefPtr hosts);

+void virStorageSourceClearSeclabels(virStorageSourcePtr def);
+int virStorageSourceCopySeclabels(virStorageSourcePtr to,
+                                  const virStorageSource *from);
 void virStorageSourceAuthClear(virStorageSourcePtr def);
 void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
 void virStorageSourceClear(virStorageSourcePtr def);
-- 
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]