virStorageSourceGetBackingStoreStr: Return relative paths only

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>
This commit is contained in:
Peter Krempa 2021-01-22 15:08:23 +01:00
parent 489742e76d
commit db4d7a37ca
5 changed files with 20 additions and 27 deletions

View File

@ -1691,7 +1691,7 @@ virStorageSourceChainLookup;
virStorageSourceChown; virStorageSourceChown;
virStorageSourceCreate; virStorageSourceCreate;
virStorageSourceDeinit; virStorageSourceDeinit;
virStorageSourceGetBackingStoreStr; virStorageSourceFetchRelativeBackingPath;
virStorageSourceGetMetadata; virStorageSourceGetMetadata;
virStorageSourceGetMetadataFromBuf; virStorageSourceGetMetadataFromBuf;
virStorageSourceGetMetadataFromFD; virStorageSourceGetMetadataFromFD;

View File

@ -3420,7 +3420,6 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
virStorageSourcePtr n; virStorageSourcePtr n;
for (n = src; virStorageSourceHasBacking(n); n = n->backingStore) { for (n = src; virStorageSourceHasBacking(n); n = n->backingStore) {
g_autofree char *backingStoreStr = NULL;
int rc; int rc;
if (n->backingStore->relPath) if (n->backingStore->relPath)
@ -3432,15 +3431,12 @@ qemuBlockUpdateRelativeBacking(virDomainObjPtr vm,
if (qemuDomainStorageFileInit(driver, vm, n, topsrc) < 0) if (qemuDomainStorageFileInit(driver, vm, n, topsrc) < 0)
return -1; return -1;
rc = virStorageSourceGetBackingStoreStr(n, &backingStoreStr); rc = virStorageSourceFetchRelativeBackingPath(n, &n->backingStore->relPath);
virStorageSourceDeinit(n); virStorageSourceDeinit(n);
if (rc < 0) if (rc < 0)
return rc; return rc;
if (backingStoreStr && virStorageIsRelative(backingStoreStr))
n->backingStore->relPath = g_steal_pointer(&backingStoreStr);
} }
return 0; return 0;

View File

@ -1088,16 +1088,9 @@ qemuSnapshotDiskPrepareOne(virDomainObjPtr vm,
dd->initialized = true; dd->initialized = true;
if (reuse) { if (reuse) {
if (updateRelativeBacking) { if (updateRelativeBacking &&
g_autofree char *backingStoreStr = NULL; virStorageSourceFetchRelativeBackingPath(dd->src, &dd->relPath) < 0)
return -1;
if (virStorageSourceGetBackingStoreStr(dd->src, &backingStoreStr) < 0)
return -1;
if (backingStoreStr != NULL) {
if (virStorageIsRelative(backingStoreStr))
dd->relPath = g_steal_pointer(&backingStoreStr);
}
}
} else { } else {
/* pre-create the image file so that we can label it before handing it to qemu */ /* 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) { if (supportsCreate && dd->src->type != VIR_STORAGE_TYPE_BLOCK) {

View File

@ -1881,24 +1881,26 @@ virStorageSourceGetRelativeBackingPath(virStorageSourcePtr top,
/** /**
* virStorageSourceGetBackingStoreStr: * virStorageSourceFetchRelativeBackingPath:
* @src: storage object * @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 * Fetches the backing store definition of @src by updating the metadata from
* by @src and returns it to the user. Caller is responsible for freeing it. * disk and fills 'relPath' if the backing store string is relative. The data
* In case when the string can't be retrieved or does not exist NULL is * is used by virStorageSourceGetRelativeBackingPath to establish the relative
* returned. * path between two images.
*/ */
int int
virStorageSourceGetBackingStoreStr(virStorageSourcePtr src, virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src,
char **backing) char **relPath)
{ {
ssize_t headerLen; ssize_t headerLen;
int rv; int rv;
g_autofree char *buf = NULL; g_autofree char *buf = NULL;
g_autoptr(virStorageSource) tmp = 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 */ /* exit if we can't load information about the current image */
if (!virStorageSourceSupportsBackingChainTraversal(src)) if (!virStorageSourceSupportsBackingChainTraversal(src))
@ -1925,7 +1927,9 @@ virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0) if (virStorageFileProbeGetMetadata(tmp, buf, headerLen) < 0)
return -1; return -1;
*backing = g_steal_pointer(&tmp->backingStoreRaw); if (virStorageIsRelative(tmp->backingStoreRaw))
*relPath = g_steal_pointer(&tmp->backingStoreRaw);
return 0; return 0;
} }

View File

@ -138,8 +138,8 @@ virStorageSourceGetMetadata(virStorageSourcePtr src,
ATTRIBUTE_NONNULL(1); ATTRIBUTE_NONNULL(1);
int int
virStorageSourceGetBackingStoreStr(virStorageSourcePtr src, virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src,
char **backing) char **relPath)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void void