mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 22:15:21 +00:00
qemu: block: Refactor logic in qemuBlockStorageSourceGetBlockdevProps
Restructure the conditions so that we can use virJSONValueObjectAdd with a clearer logic for backing store control. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8bc0d3fb7a
commit
d354750521
@ -1309,38 +1309,40 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSource *src,
|
|||||||
virStorageSource *backingStore)
|
virStorageSource *backingStore)
|
||||||
{
|
{
|
||||||
g_autoptr(virJSONValue) props = NULL;
|
g_autoptr(virJSONValue) props = NULL;
|
||||||
|
const char *backingFormatterStr = NULL;
|
||||||
|
const char *backingNodename = NULL;
|
||||||
const char *storagenode = src->nodestorage;
|
const char *storagenode = src->nodestorage;
|
||||||
|
|
||||||
if (qemuBlockStorageSourceNeedsStorageSliceLayer(src))
|
if (qemuBlockStorageSourceNeedsStorageSliceLayer(src))
|
||||||
storagenode = src->sliceStorage->nodename;
|
storagenode = src->sliceStorage->nodename;
|
||||||
|
|
||||||
|
if (virStorageSourceIsBacking(backingStore) &&
|
||||||
|
src->format < VIR_STORAGE_FILE_BACKING) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("storage format '%1$s' does not support backing store"),
|
||||||
|
virStorageFileFormatTypeToString(src->format));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backingStore &&
|
||||||
|
src->format >= VIR_STORAGE_FILE_BACKING) {
|
||||||
|
if (virStorageSourceIsBacking(backingStore)) {
|
||||||
|
backingFormatterStr = "s:backing";
|
||||||
|
backingNodename = backingStore->nodeformat;
|
||||||
|
} else {
|
||||||
|
/* chain is terminated, indicate that no detection should happen in qemu */
|
||||||
|
backingFormatterStr = "n:backing";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src)))
|
if (!(props = qemuBlockStorageSourceGetBlockdevFormatProps(src)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virJSONValueObjectAppendString(props, "file", storagenode) < 0)
|
if (virJSONValueObjectAdd(&props,
|
||||||
return NULL;
|
"s:file", storagenode,
|
||||||
|
backingFormatterStr, backingNodename,
|
||||||
if (backingStore) {
|
NULL) < 0)
|
||||||
if (src->format >= VIR_STORAGE_FILE_BACKING) {
|
return 0;
|
||||||
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 {
|
|
||||||
if (virStorageSourceIsBacking(backingStore)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
||||||
_("storage format '%1$s' does not support backing store"),
|
|
||||||
virStorageFileFormatTypeToString(src->format));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return g_steal_pointer(&props);
|
return g_steal_pointer(&props);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user