mirror of https://gitee.com/openkylin/libvirt.git
qemuBlockStorageSourceGetBlockdevGetCacheProps: Return the cache object rather than appending it
Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
4cf223962a
commit
e60c3057cc
|
@ -913,24 +913,20 @@ qemuBlockStorageSourceGetVhostVdpaProps(virStorageSource *src)
|
|||
|
||||
static int
|
||||
qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSource *src,
|
||||
virJSONValue *props)
|
||||
virJSONValue **cache)
|
||||
{
|
||||
g_autoptr(virJSONValue) cacheobj = NULL;
|
||||
bool direct = false;
|
||||
bool noflush = false;
|
||||
|
||||
if (!qemuDomainDiskCachemodeFlags(src->cachemode, NULL, &direct, &noflush))
|
||||
return 0;
|
||||
|
||||
if (virJSONValueObjectAdd(&cacheobj,
|
||||
if (virJSONValueObjectAdd(cache,
|
||||
"b:direct", direct,
|
||||
"b:no-flush", noflush,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
if (virJSONValueObjectAppend(props, "cache", &cacheobj) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1109,10 +1105,13 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
|
|||
return NULL;
|
||||
|
||||
if (!legacy) {
|
||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, fileprops) < 0)
|
||||
g_autoptr(virJSONValue) cache = NULL;
|
||||
|
||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virJSONValueObjectAdd(&fileprops,
|
||||
"A:cache", &cache,
|
||||
"T:read-only", ro,
|
||||
"T:auto-read-only", aro,
|
||||
NULL) < 0)
|
||||
|
@ -1278,10 +1277,14 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSource *src)
|
|||
int detectZeroesMode = virDomainDiskGetDetectZeroesMode(src->discard,
|
||||
src->detect_zeroes);
|
||||
g_autoptr(virJSONValue) props = NULL;
|
||||
g_autoptr(virJSONValue) cache = NULL;
|
||||
|
||||
if (qemuBlockNodeNameValidate(qemuBlockStorageSourceGetFormatNodename(src)) < 0)
|
||||
return NULL;
|
||||
|
||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
|
||||
return NULL;
|
||||
|
||||
if (src->discard)
|
||||
discard = virDomainDiskDiscardTypeToString(src->discard);
|
||||
|
||||
|
@ -1297,12 +1300,10 @@ qemuBlockStorageSourceGetBlockdevFormatCommonProps(virStorageSource *src)
|
|||
"b:read-only", src->readonly,
|
||||
"S:discard", discard,
|
||||
"S:detect-zeroes", detectZeroes,
|
||||
"A:cache", &cache,
|
||||
NULL) < 0)
|
||||
return NULL;
|
||||
|
||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&props);
|
||||
}
|
||||
|
||||
|
@ -1439,10 +1440,14 @@ static virJSONValue *
|
|||
qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src)
|
||||
{
|
||||
g_autoptr(virJSONValue) props = NULL;
|
||||
g_autoptr(virJSONValue) cache = NULL;
|
||||
|
||||
if (qemuBlockNodeNameValidate(src->sliceStorage->nodename) < 0)
|
||||
return NULL;
|
||||
|
||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
|
||||
return NULL;
|
||||
|
||||
if (virJSONValueObjectAdd(&props,
|
||||
"s:driver", "raw",
|
||||
"s:node-name", src->sliceStorage->nodename,
|
||||
|
@ -1451,12 +1456,10 @@ qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src)
|
|||
"s:file", qemuBlockStorageSourceGetStorageNodename(src),
|
||||
"b:auto-read-only", true,
|
||||
"s:discard", "unmap",
|
||||
"A:cache", &cache,
|
||||
NULL) < 0)
|
||||
return NULL;
|
||||
|
||||
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, props) < 0)
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&props);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue