1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

qemu: block: Properly format storage slice into backing store strings

When creating overlay images e.g. for snapshots or when merging
snapshots we often specify the backing store string to use. Make the
formatter aware of backing chain entries which have a <slice>
configured so that we record it properly. Otherwise such images
would not work without the XML (when detecting the backing chain).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-02-12 17:25:12 +01:00
parent f36d751fa6
commit 73ca201467

View File

@ -1930,10 +1930,13 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
{
int actualType = virStorageSourceGetActualType(src);
g_autoptr(virJSONValue) backingProps = NULL;
g_autoptr(virJSONValue) sliceProps = NULL;
virJSONValuePtr props = NULL;
g_autoptr(virURI) uri = NULL;
g_autofree char *backingJSON = NULL;
char *ret = NULL;
if (!src->sliceStorage) {
if (virStorageSourceIsLocalStorage(src)) {
ret = g_strdup(src->path);
return ret;
@ -1970,12 +1973,27 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src)
break;
}
}
}
/* use json: pseudo protocol otherwise */
if (!(backingProps = qemuBlockStorageSourceGetBackendProps(src, false, true, false)))
return NULL;
if (!(backingJSON = virJSONValueToString(backingProps, false)))
props = backingProps;
if (src->sliceStorage) {
if (virJSONValueObjectCreate(&sliceProps,
"s:driver", "raw",
"U:offset", src->sliceStorage->offset,
"U:size", src->sliceStorage->size,
"a:file", &backingProps,
NULL) < 0)
return NULL;
props = sliceProps;
}
if (!(backingJSON = virJSONValueToString(props, false)))
return NULL;
ret = g_strdup_printf("json:%s", backingJSON);