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(a)redhat.com>
---
src/libvirt_private.syms | 2 +-
src/qemu/qemu_block.c | 6 +-----
src/qemu/qemu_snapshot.c | 13 +++----------
src/storage_file/storage_source.c | 22 +++++++++++++---------
src/storage_file/storage_source.h | 4 ++--
5 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fbaf16704b..c03b769c37 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1691,7 +1691,7 @@ virStorageSourceChainLookup;
virStorageSourceChown;
virStorageSourceCreate;
virStorageSourceDeinit;
-virStorageSourceGetBackingStoreStr;
+virStorageSourceFetchRelativeBackingPath;
virStorageSourceGetMetadata;
virStorageSourceGetMetadataFromBuf;
virStorageSourceGetMetadataFromFD;
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index d845a3312d..6456100170 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -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;
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index bfc5a1a46b..39445738a2 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -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)
{
diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_source.c
index 430e3214c4..23d36507ea 100644
--- a/src/storage_file/storage_source.c
+++ b/src/storage_file/storage_source.c
@@ -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;
}
diff --git a/src/storage_file/storage_source.h b/src/storage_file/storage_source.h
index 480333d37a..58f88a3c01 100644
--- a/src/storage_file/storage_source.h
+++ b/src/storage_file/storage_source.h
@@ -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
--
2.29.2