]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage_source: introduce virStorageSourceChainLookupBySource
authorPavel Hrdina <phrdina@redhat.com>
Thu, 5 Jan 2023 10:46:41 +0000 (11:46 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Mon, 9 Jan 2023 12:32:49 +0000 (13:32 +0100)
Looks up disk storage source within storage source chain using storage
source object instead of path to make it work with all disk types.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/libvirt_private.syms
src/storage_file/storage_source.c
src/storage_file/storage_source.h

index b81c2cc7dad547dfc17fbbcfa03c249eaf8428cb..0aef539dc83bfe6c36a372bd666f3380195a502e 100644 (file)
@@ -1780,6 +1780,7 @@ virStorageFileProbeGetMetadata;
 # storage_file/storage_source.h
 virStorageSourceAccess;
 virStorageSourceChainLookup;
+virStorageSourceChainLookupBySource;
 virStorageSourceChown;
 virStorageSourceCreate;
 virStorageSourceDeinit;
index ab0cdf2b1242a083c0b98cd69dae1c5673666318..0db6e695915323a04878d4819b78b6bd78dc9ba7 100644 (file)
@@ -322,6 +322,46 @@ virStorageSourceChainLookup(virStorageSource *chain,
 }
 
 
+/**
+ * virStorageSourceChainLookupBySource:
+ * @chain: chain top to look in
+ * @base: storage source to look for in @chain
+ * @parent: Filled with parent virStorageSource of the returned value if non-NULL.
+ *
+ * Looks up a storage source definition corresponding to @base in @chain.
+ *
+ * Returns virStorageSource withing chain or NULL if not found.
+ */
+virStorageSource *
+virStorageSourceChainLookupBySource(virStorageSource *chain,
+                                    virStorageSource *base,
+                                    virStorageSource **parent)
+{
+    virStorageSource *prev = NULL;
+
+    if (parent)
+        *parent = NULL;
+
+    while (virStorageSourceIsBacking(chain)) {
+        if (virStorageSourceIsSameLocation(chain, base))
+            break;
+
+        prev = chain;
+        chain = chain->backingStore;
+    }
+
+    if (!virStorageSourceIsBacking(chain)) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("could not find base disk source in disk source chain"));
+        return NULL;
+    }
+
+    if (parent)
+        *parent = prev;
+    return chain;
+}
+
+
 static virStorageSource *
 virStorageSourceNewFromBackingRelative(virStorageSource *parent,
                                        const char *rel)
index 0ae06f4e7d1cd3a8d388e2751867c7075b9a5b56..63fefb691913e0ee1085a48384ee625e0c8b4731 100644 (file)
@@ -47,6 +47,12 @@ virStorageSourceChainLookup(virStorageSource *chain,
                             virStorageSource **parent)
     ATTRIBUTE_NONNULL(1);
 
+virStorageSource *
+virStorageSourceChainLookupBySource(virStorageSource *chain,
+                                    virStorageSource *base,
+                                    virStorageSource **parent)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 int
 virStorageSourceUpdatePhysicalSize(virStorageSource *src,
                                    int fd,