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,32 +1404,34 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr src)
virJSONValuePtr
qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src)
{
bool backingSupported = src->format >= VIR_STORAGE_FILE_BACKING;
virStorageSourcePtr backingStore = src->backingStore;
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)))
return NULL;
if (virJSONValueObjectAppendString(props, "file", src->nodestorage) < 0)
return NULL;
if (src->backingStore && backingSupported) {
if (virStorageSourceHasBacking(src)) {
if (virJSONValueObjectAppendString(props, "backing",
src->backingStore->nodeformat) < 0)
return NULL;
if (backingStore) {
if (src->format >= VIR_STORAGE_FILE_BACKING) {
if (virStorageSourceIsBacking(backingStore)) {
if (virJSONValueObjectAppendString(props, "backing",
backingStore->nodeformat) < 0)
return NULL;
} else {
/* chain is terminated, indicate that no detection should happen
* in qemu */
if (virJSONValueObjectAppendNull(props, "backing") < 0)
return NULL;
}
} else {
/* chain is terminated, indicate that no detection should happen
* in qemu */
if (virJSONValueObjectAppendNull(props, "backing") < 0)
if (virStorageSourceIsBacking(backingStore)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("storage format '%s' does not support backing store"),
virStorageFileFormatTypeToString(src->format));
return NULL;
}
}
}