]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: storage: Add variables for node names into virStorageSource
authorPeter Krempa <pkrempa@redhat.com>
Wed, 22 Feb 2017 15:20:00 +0000 (16:20 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 27 Mar 2017 07:29:57 +0000 (09:29 +0200)
'nodeformat' should be used for strings which describe the storage
format object, and 'nodebacking' for the actual storage object itself.

src/libvirt_private.syms
src/util/virstoragefile.c
src/util/virstoragefile.h

index 3091791f4acb493c006fc3d8d54414645feceb1f..010942529afb54ec2562a35375948b228971709b 100644 (file)
@@ -2509,6 +2509,7 @@ virStorageNetProtocolTypeToString;
 virStorageSourceBackingStoreClear;
 virStorageSourceClear;
 virStorageSourceCopy;
+virStorageSourceFindByNodeName;
 virStorageSourceFree;
 virStorageSourceGetActualType;
 virStorageSourceGetSecurityLabelDef;
index c8eb26aa74e4562a36a041c9915ac9fd773fcd40..3bcb69bf62066acec529d3f97b2140315861175f 100644 (file)
@@ -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;
+}
index 5f6e419117d36ea1618050a796eb8e561ac8656b..9ebfc1108141437d918f93a271795e97a9bad2c8 100644 (file)
@@ -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__ */