]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
util: storage: Add function to transfer config parts to new chain element
authorPeter Krempa <pkrempa@redhat.com>
Wed, 25 Jun 2014 16:48:27 +0000 (18:48 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 8 Jul 2014 12:34:04 +0000 (14:34 +0200)
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
src/util/virstoragefile.c
src/util/virstoragefile.h

index 3a0f3fb67047e1e34ab4ba42c70f6ba59662f37a..22dde5a603fae46c4ce1b6c9db4fcd206bc75c34 100644 (file)
@@ -1925,6 +1925,7 @@ virStorageSourceCopy;
 virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourceGetSecurityLabelDef;
+virStorageSourceInitChainElement;
 virStorageSourceIsLocalStorage;
 virStorageSourceNewFromBacking;
 virStorageSourcePoolDefFree;
index 1deb7df10b587a46c4db6678b8851a06019e80c2..b97fd56bc3d6e8e840a6d097fae4aafbda89368e 100644 (file)
@@ -1885,6 +1885,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)
 {
index 86dca3c6701a4fb359ae0987e3e8759f3aacaee4..744a6bacc346fc5e4a6e37ac45b0c1ee4823f866 100644 (file)
@@ -345,6 +345,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);