[PATCH v3 5/9] virstoragefile: change backingStore to backingStores.

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

 



The backingStore field was a virStorageSourcePtr.
because a quorum can contain more that one backingStore at the same level
it's now a 'virStorageSourcePtr *'.

This patch rename  src->backingStore to src->backingStores,
add a static function virStorageSourceExpandBackingStore
(virStorageSourcePushBackingStore in the V2) and made the necessary modification to
virStorageSourceSetBackingStore and virStorageSourceGetBackingStore.
virStorageSourceSetBackingStore can now expand size of src->backingStores
by calling virStorageSourceExpandBackingStore if necessary.

Signed-off-by: Matthias Gatto <matthias.gatto@xxxxxxxxxxxx>
---
 src/util/virstoragefile.c | 69 +++++++++++++++++++++++++++++++++++++++++------
 src/util/virstoragefile.h |  3 ++-
 2 files changed, 63 insertions(+), 9 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index d573aba..2a5321c 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1798,21 +1798,66 @@ virStorageSourcePoolDefCopy(const virStorageSourcePoolDef *src)
 }
 
 
+/**
+ * virStorageSourceGetBackingStore:
+ * @src: virStorageSourcePtr containing the backing stores
+ * @pos: position of the backing store to get
+ *
+ * return the backingStore at the position of @pos
+ */
 virStorageSourcePtr
-virStorageSourceGetBackingStore(const virStorageSource *src,
-                                size_t pos ATTRIBUTE_UNUSED)
+virStorageSourceGetBackingStore(const virStorageSource *src, size_t pos)
+{
+    if (!src || !src->backingStores || pos >= src->nBackingStores)
+        return NULL;
+    return src->backingStores[pos];
+}
+
+
+/**
+ * virStorageSourcePushBackingStore:
+ *
+ * Expand src->backingStores and update src->nBackingStores
+ */
+static bool
+virStorageSourceExpandBackingStore(virStorageSourcePtr src, size_t nbr)
 {
-    return src->backingStore;
+    if (!src)
+        return false;
+    if (src->nBackingStores > 0) {
+        if (VIR_EXPAND_N(src->backingStores, src->nBackingStores, nbr) < 0)
+            return false;
+    } else {
+        if (VIR_ALLOC_N(src->backingStores, nbr) < 0)
+            return false;
+        src->nBackingStores += nbr;
+    }
+    return true;
 }
 
 
+/**
+ * virStorageSourceSetBackingStore:
+ * @src: virStorageSourcePtr to hold @backingStore
+ * @backingStore: backingStore to store
+ * @pos: position of the backing store to store
+ *
+ * Set @backingStore at @pos in src->backingStores.
+ * If src->backingStores don't have the space to contain
+ * @backingStore, we expand src->backingStores
+ */
 bool
 virStorageSourceSetBackingStore(virStorageSourcePtr src,
                                 virStorageSourcePtr backingStore,
-                                size_t pos ATTRIBUTE_UNUSED)
+                                size_t pos)
 {
-    src->backingStore = backingStore;
-    return src->backingStore;
+    if (!src)
+        return false;
+    if (pos >= src->nBackingStores &&
+        !virStorageSourceExpandBackingStore(src, pos - src->nBackingStores + 1))
+        return false;
+    src->backingStores[pos] = backingStore;
+    return true;
 }
 
 
@@ -2023,6 +2068,8 @@ virStorageSourceIsEmpty(virStorageSourcePtr src)
 void
 virStorageSourceBackingStoreClear(virStorageSourcePtr def)
 {
+    size_t i;
+
     if (!def)
         return;
 
@@ -2030,8 +2077,14 @@ virStorageSourceBackingStoreClear(virStorageSourcePtr def)
     VIR_FREE(def->backingStoreRaw);
 
     /* recursively free backing chain */
-    virStorageSourceFree(virStorageSourceGetBackingStore(def, 0));
-    virStorageSourceSetBackingStore(def, NULL, 0);
+    for (i = 0; i < def->nBackingStores; ++i)
+        virStorageSourceFree(virStorageSourceGetBackingStore(def, i));
+    if (def->nBackingStores > 0) {
+        /* in this case def->backingStores is treat as an array so we have to free it*/
+        VIR_FREE(def->backingStores);
+    }
+    def->nBackingStores = 0;
+    def->backingStores = NULL;
 }
 
 
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 85b8d6e..b94f9d9 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -270,7 +270,8 @@ struct _virStorageSource {
     bool shared;
 
     /* backing chain of the storage source */
-    virStorageSourcePtr backingStore;
+    virStorageSourcePtr *backingStores;
+    size_t      nBackingStores;
 
     /* metadata for storage driver access to remote and local volumes */
     virStorageDriverDataPtr drv;
-- 
1.8.3.1

--
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]