]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageSourceGetBackingStoreStr: Return relative paths only
authorPeter Krempa <pkrempa@redhat.com>
Fri, 22 Jan 2021 14:08:23 +0000 (15:08 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 27 Jan 2021 06:49:57 +0000 (07:49 +0100)
Rename the function to virStorageSourceFetchRelativeBackingPath and
return relative paths only. The function is only used to restore the
relative relationship between images so there's no need for it to be
universal.

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

index fbaf16704b77306ed35e50554c281b8bbd87ea99..c03b769c3729c01aa07430bce52dd1f62ebecc62 100644 (file)
@@ -1691,7 +1691,7 @@ virStorageSourceChainLookup;
 virStorageSourceChown;
 virStorageSourceCreate;
 virStorageSourceDeinit;
-virStorageSourceGetBackingStoreStr;
+virStorageSourceFetchRelativeBackingPath;
 virStorageSourceGetMetadata;
 virStorageSourceGetMetadataFromBuf;
 virStorageSourceGetMetadataFromFD;
index d845a3312d7fb892fb519aac89eaa42bb951ebdc..645610017031eedb7ea6e29b90f31c8263400368 100644 (file)
@@ -3420,7 +3420,6 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
     virStorageSourcePtr n;
 
     for (n = src; virStorageSourceHasBacking(n); n = n->backingStore) {
-        g_autofree char *backingStoreStr = NULL;
         int rc;
 
         if (n->backingStore->relPath)
@@ -3432,15 +3431,12 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
         if (qemuDomainStorageFileInit(driver, vm, n, topsrc) < 0)
             return -1;
 
-        rc = virStorageSourceGetBackingStoreStr(n, &backingStoreStr);
+        rc = virStorageSourceFetchRelativeBackingPath(n, &n->backingStore->relPath);
 
         virStorageSourceDeinit(n);
 
         if (rc < 0)
             return rc;
-
-        if (backingStoreStr && virStorageIsRelative(backingStoreStr))
-            n->backingStore->relPath = g_steal_pointer(&backingStoreStr);
     }
 
     return 0;
index bfc5a1a46bb685dae2f43bf5365c9f525795b8c0..39445738a21465ce4fdb2814910d6de2d6ffcd54 100644 (file)
@@ -1088,16 +1088,9 @@ qemuSnapshotDiskPrepareOne(virDomainObjPtr vm,
         dd->initialized = true;
 
         if (reuse) {
-            if (updateRelativeBacking) {
-                g_autofree char *backingStoreStr = NULL;
-
-                if (virStorageSourceGetBackingStoreStr(dd->src, &backingStoreStr) < 0)
-                    return -1;
-                if (backingStoreStr != NULL) {
-                    if (virStorageIsRelative(backingStoreStr))
-                        dd->relPath = g_steal_pointer(&backingStoreStr);
-                }
-            }
+            if (updateRelativeBacking &&
+                virStorageSourceFetchRelativeBackingPath(dd->src, &dd->relPath) < 0)
+                return -1;
         } else {
             /* pre-create the image file so that we can label it before handing it to qemu */
             if (supportsCreate && dd->src->type != VIR_STORAGE_TYPE_BLOCK) {
index 430e3214c48f982eac8350221407bb6851d040b2..23d36507ea985e3eb1130d3dda5b1a77117acb6a 100644 (file)
@@ -1881,24 +1881,26 @@ virStorageSourceGetRelativeBackingPath(virStorageSourcePtr top,
 
 
 /**
- * virStorageSourceGetBackingStoreStr:
+ * virStorageSourceFetchRelativeBackingPath:
  * @src: storage object
+ * @relPath: filled with the relative path to the backing image of @src if
+ *           the metadata of @src refer to it as relative.
  *
- * Extracts the backing store string as stored in the storage volume described
- * by @src and returns it to the user. Caller is responsible for freeing it.
- * In case when the string can't be retrieved or does not exist NULL is
- * returned.
+ * Fetches the backing store definition of @src by updating the metadata from
+ * disk and fills 'relPath' if the backing store string is relative. The data
+ * is used by virStorageSourceGetRelativeBackingPath to establish the relative
+ * path between two images.
  */
 int
-virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
-                                   char **backing)
+virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src,
+                                         char **relPath)
 {
     ssize_t headerLen;
     int rv;
     g_autofree char *buf = NULL;
     g_autoptr(virStorageSource) tmp = NULL;
 
-    *backing = NULL;
+    g_clear_pointer(relPath, g_free);
 
     /* exit if we can't load information about the current image */
     if (!virStorageSourceSupportsBackingChainTraversal(src))
@@ -1925,7 +1927,9 @@ virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
     if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0)
         return -1;
 
-    *backing = g_steal_pointer(&tmp->backingStoreRaw);
+    if (virStorageIsRelative(tmp->backingStoreRaw))
+        *relPath = g_steal_pointer(&tmp->backingStoreRaw);
+
     return 0;
 }
 
index 480333d37ac53be8148dcb3683eea396b1741b18..58f88a3c01ec563a64e15ba18ff413d3698d46a5 100644 (file)
@@ -138,8 +138,8 @@ virStorageSourceGetMetadata(virStorageSourcePtr src,
     ATTRIBUTE_NONNULL(1);
 
 int
-virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
-                                   char **backing)
+virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src,
+                                         char **relPath)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 void