virStorageSourceChown;
virStorageSourceCreate;
virStorageSourceDeinit;
-virStorageSourceGetBackingStoreStr;
+virStorageSourceFetchRelativeBackingPath;
virStorageSourceGetMetadata;
virStorageSourceGetMetadataFromBuf;
virStorageSourceGetMetadataFromFD;
virStorageSourcePtr n;
for (n = src; virStorageSourceHasBacking(n); n = n->backingStore) {
- g_autofree char *backingStoreStr = NULL;
int rc;
if (n->backingStore->relPath)
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;
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) {
/**
- * 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))
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;
}
ATTRIBUTE_NONNULL(1);
int
-virStorageSourceGetBackingStoreStr(virStorageSourcePtr src,
- char **backing)
+virStorageSourceFetchRelativeBackingPath(virStorageSourcePtr src,
+ char **relPath)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
void