qemuBlockStorageSourceGetBackendProps: Introduce QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE

Introduce a mode where the protocol layer -blockdev will be formatted
so that it can be used as the effective node (used to access data from
the device). For this new mode we'll use
qemuBlockStorageSourceAddBlockdevCommonProps.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-10-19 16:12:38 +02:00
parent 80494dfb74
commit ec936526c2
2 changed files with 25 additions and 16 deletions

View File

@ -1031,6 +1031,8 @@ qemuBlockStorageSourceAddBlockdevCommonProps(virJSONValue **props,
* QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP:
* don't enable 'discard:unmap' option for passing through discards
* (note that this is disabled also for _LEGACY and _TARGET_ONLY options)
* QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE:
* the 'protocol' node is used as the effective/top node of a virStorageSource
*
* Creates a JSON object describing the underlying storage or protocol of a
* storage source. Returns NULL on error and reports an appropriate error message.
@ -1183,27 +1185,33 @@ qemuBlockStorageSourceGetBackendProps(virStorageSource *src,
return NULL;
if (!onlytarget && !legacy) {
g_autoptr(virJSONValue) cache = NULL;
const char *discardstr = "unmap";
const char *nodename = qemuBlockStorageSourceGetStorageNodename(src);
if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP)
discardstr = NULL;
if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE) {
if (qemuBlockStorageSourceAddBlockdevCommonProps(&fileprops, src, nodename, true) < 0)
return NULL;
} else {
g_autoptr(virJSONValue) cache = NULL;
const char *discardstr = "unmap";
if (qemuBlockNodeNameValidate(nodename) < 0)
return NULL;
if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP)
discardstr = NULL;
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
return NULL;
if (qemuBlockNodeNameValidate(nodename) < 0)
return NULL;
if (virJSONValueObjectAdd(&fileprops,
"s:node-name", nodename,
"T:read-only", ro,
"T:auto-read-only", aro,
"S:discard", discardstr,
"A:cache", &cache,
NULL) < 0)
return NULL;
if (qemuBlockStorageSourceGetBlockdevGetCacheProps(src, &cache) < 0)
return NULL;
if (virJSONValueObjectAdd(&fileprops,
"s:node-name", nodename,
"T:read-only", ro,
"T:auto-read-only", aro,
"S:discard", discardstr,
"A:cache", &cache,
NULL) < 0)
return NULL;
}
}
return g_steal_pointer(&fileprops);

View File

@ -68,6 +68,7 @@ typedef enum {
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY = 1 << 1,
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY = 1 << 2,
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_SKIP_UNMAP = 1 << 3,
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_EFFECTIVE_NODE = 1 << 4,
} qemuBlockStorageSourceBackendPropsFlags;
virJSONValue *