[PATCH 04/23] util: storage: Add variables for node names into virStorageSource

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

 



'nodeformat' should be used for strings which describe the storage
format object, and 'nodebacking' for the actual storage object itself.
---
 src/libvirt_private.syms  |  1 +
 src/util/virstoragefile.c | 40 ++++++++++++++++++++++++++++++++++++++++
 src/util/virstoragefile.h | 10 ++++++++++
 3 files changed, 51 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 31d6085cb..bf2039a75 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2490,6 +2490,7 @@ virStorageNetProtocolTypeToString;
 virStorageSourceBackingStoreClear;
 virStorageSourceClear;
 virStorageSourceCopy;
+virStorageSourceFindByNodeName;
 virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourceGetSecurityLabelDef;
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index c8eb26aa7..3bcb69bf6 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2012,6 +2012,8 @@ virStorageSourceCopy(const virStorageSource *src,
         VIR_STRDUP(ret->backingStoreRaw, src->backingStoreRaw) < 0 ||
         VIR_STRDUP(ret->snapshot, src->snapshot) < 0 ||
         VIR_STRDUP(ret->configFile, src->configFile) < 0 ||
+        VIR_STRDUP(ret->nodeformat, src->nodeformat) < 0 ||
+        VIR_STRDUP(ret->nodebacking, src->nodebacking) < 0 ||
         VIR_STRDUP(ret->compat, src->compat) < 0)
         goto error;

@@ -2232,6 +2234,9 @@ virStorageSourceClear(virStorageSourcePtr def)
     virStorageNetHostDefFree(def->nhosts, def->hosts);
     virStorageAuthDefFree(def->auth);

+    VIR_FREE(def->nodebacking);
+    VIR_FREE(def->nodeformat);
+
     virStorageSourceBackingStoreClear(def);
 }

@@ -3781,3 +3786,38 @@ virStorageSourceIsRelative(virStorageSourcePtr src)

     return false;
 }
+
+
+/**
+ * virStorageSourceFindByNodeName:
+ * @top: backing chain top
+ * @nodeName: node name to find in backing chain
+ * @index: if provided the index in the backing chain
+ *
+ * Looks up the given storage source in the backing chain and returns the
+ * pointer to it. If @index is passed then it's filled by the index in the
+ * backing chain. On failure NULL is returned and no error is reported.
+ */
+virStorageSourcePtr
+virStorageSourceFindByNodeName(virStorageSourcePtr top,
+                               const char *nodeName,
+                               unsigned int *index)
+{
+    virStorageSourcePtr tmp;
+
+    if (index)
+        *index = 0;
+
+    for (tmp = top; tmp; tmp = tmp->backingStore) {
+        if (STREQ_NULLABLE(tmp->nodeformat, nodeName) ||
+            STREQ_NULLABLE(tmp->nodebacking, nodeName))
+            return tmp;
+
+        if (index)
+            (*index)++;
+    }
+
+    if (index)
+        *index = 0;
+    return NULL;
+}
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 5f6e41911..9ebfc1108 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -276,6 +276,10 @@ struct _virStorageSource {
     /* Name of the child backing store recorded in metadata of the
      * current file.  */
     char *backingStoreRaw;
+
+    /* metadata that allows identifying given storage source */
+    char *nodeformat;  /* name of the format handler object */
+    char *nodebacking; /* name of the backing storage object */
 };


@@ -395,4 +399,10 @@ virStorageSourcePtr virStorageSourceNewFromBackingAbsolute(const char *path);

 bool virStorageSourceIsRelative(virStorageSourcePtr src);

+virStorageSourcePtr
+virStorageSourceFindByNodeName(virStorageSourcePtr top,
+                               const char *nodeName,
+                               unsigned int *index)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 #endif /* __VIR_STORAGE_FILE_H__ */
-- 
2.12.0

--
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]
  Powered by Linux