[PATCHv5 08/28] util: storage: Add function to transfer config parts to new chain element

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

 



We are going to modify storage source chains in place. Add a helper that
will copy relevant information such as security labels to the new
element if that doesn't contain it.
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/util/virstoragefile.h |  3 +++
 3 files changed, 44 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 918b6d2..9838dfa 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1923,6 +1923,7 @@ virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourceGetSecurityLabelDef;
+virStorageSourceInitChainElement;
 virStorageSourceIsLocalStorage;
 virStorageSourceNewFromBacking;
 virStorageSourcePoolDefFree;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 3037435..cdbe24b 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1902,6 +1902,46 @@ virStorageSourceCopy(const virStorageSource *src,
 }


+/**
+ * virStorageSourceInitChainElement:
+ * @newelem: New backing chain element disk source
+ * @old: Existing top level disk source
+ * @force: Force-copy the information
+ *
+ * Transfers relevant information from the existing disk source to the new
+ * backing chain element if they weren't supplied so that labelling info
+ * and possibly other stuff is correct.
+ *
+ * If @force is true, user-supplied information for the new backing store
+ * element is overwritten from @old instead of keeping it.
+ *
+ * Returns 0 on success, -1 on error.
+ */
+int
+virStorageSourceInitChainElement(virStorageSourcePtr newelem,
+                                 virStorageSourcePtr old,
+                                 bool force)
+{
+    int ret = -1;
+
+    if (force) {
+        virStorageSourceSeclabelsClear(newelem);
+    }
+
+    if (!newelem->seclabels &&
+        virStorageSourceSeclabelsCopy(newelem, old) < 0)
+        goto cleanup;
+
+    newelem->shared = old->shared;
+    newelem->readonly = old->readonly;
+
+    ret = 0;
+
+ cleanup:
+    return ret;
+}
+
+
 void
 virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def)
 {
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 5c0460b..7fd0bd7 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -342,6 +342,9 @@ void virStorageNetHostDefFree(size_t nhosts, virStorageNetHostDefPtr hosts);
 virStorageNetHostDefPtr virStorageNetHostDefCopy(size_t nhosts,
                                                  virStorageNetHostDefPtr hosts);

+int virStorageSourceInitChainElement(virStorageSourcePtr newelem,
+                                     virStorageSourcePtr old,
+                                     bool force);
 void virStorageSourcePoolDefFree(virStorageSourcePoolDefPtr def);
 void virStorageSourceClear(virStorageSourcePtr def);
 int virStorageSourceGetActualType(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]