qemu: block: Unify conditions to format backing store of format node definition

Move all bits of the formatting of the 'backing' attribute to a single
condition and make it use a single extracted copy of the backing store.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-09-03 13:16:39 +02:00
parent 510d154a0b
commit d6f1116091

View File

@ -1404,26 +1404,20 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr src)
virJSONValuePtr virJSONValuePtr
qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src) qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src)
{ {
bool backingSupported = src->format >= VIR_STORAGE_FILE_BACKING; virStorageSourcePtr backingStore = src->backingStore;
VIR_AUTOPTR(virJSONValue) props = NULL; VIR_AUTOPTR(virJSONValue) props = NULL;
if (virStorageSourceHasBacking(src) && !backingSupported) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("storage format '%s' does not support backing store"),
virStorageFileFormatTypeToString(src->format));
return NULL;
}
if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src))) if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src)))
return NULL; return NULL;
if (virJSONValueObjectAppendString(props, "file", src->nodestorage) < 0) if (virJSONValueObjectAppendString(props, "file", src->nodestorage) < 0)
return NULL; return NULL;
if (src->backingStore && backingSupported) { if (backingStore) {
if (virStorageSourceHasBacking(src)) { if (src->format >= VIR_STORAGE_FILE_BACKING) {
if (virStorageSourceIsBacking(backingStore)) {
if (virJSONValueObjectAppendString(props, "backing", if (virJSONValueObjectAppendString(props, "backing",
src->backingStore->nodeformat) < 0) backingStore->nodeformat) < 0)
return NULL; return NULL;
} else { } else {
/* chain is terminated, indicate that no detection should happen /* chain is terminated, indicate that no detection should happen
@ -1431,6 +1425,14 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src)
if (virJSONValueObjectAppendNull(props, "backing") < 0) if (virJSONValueObjectAppendNull(props, "backing") < 0)
return NULL; return NULL;
} }
} else {
if (virStorageSourceIsBacking(backingStore)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("storage format '%s' does not support backing store"),
virStorageFileFormatTypeToString(src->format));
return NULL;
}
}
} }
VIR_RETURN_PTR(props); VIR_RETURN_PTR(props);