mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 03:12:22 +00:00
qemuBlockStorageSourceGetBackendProps: Convert boolean arguments to flags
Upcoming commit will need to add another flag for the function so convert it to a bitwise-or'd array of flags to prevent having 4 booleans. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
8b0cb0e666
commit
d73c5eda63
@ -1052,26 +1052,32 @@ qemuBlockStorageSourceGetBlockdevGetCacheProps(virStorageSourcePtr src,
|
|||||||
/**
|
/**
|
||||||
* qemuBlockStorageSourceGetBackendProps:
|
* qemuBlockStorageSourceGetBackendProps:
|
||||||
* @src: disk source
|
* @src: disk source
|
||||||
* @legacy: use legacy formatting of attributes (for -drive / old qemus)
|
* @flags: bitwise-or of qemuBlockStorageSourceBackendPropsFlags
|
||||||
* @onlytarget: omit any data which does not identify the image itself
|
*
|
||||||
* @autoreadonly: use the auto-read-only feature of qemu
|
* Flags:
|
||||||
|
* QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_LEGACY:
|
||||||
|
* use legacy formatting of attributes (for -drive / old qemus)
|
||||||
|
* QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY:
|
||||||
|
* omit any data which does not identify the image itself
|
||||||
|
* QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY:
|
||||||
|
* use the auto-read-only feature of qemu
|
||||||
*
|
*
|
||||||
* Creates a JSON object describing the underlying storage or protocol of a
|
* Creates a JSON object describing the underlying storage or protocol of a
|
||||||
* storage source. Returns NULL on error and reports an appropriate error message.
|
* storage source. Returns NULL on error and reports an appropriate error message.
|
||||||
*/
|
*/
|
||||||
virJSONValuePtr
|
virJSONValuePtr
|
||||||
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
|
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
|
||||||
bool legacy,
|
unsigned int flags)
|
||||||
bool onlytarget,
|
|
||||||
bool autoreadonly)
|
|
||||||
{
|
{
|
||||||
int actualType = virStorageSourceGetActualType(src);
|
int actualType = virStorageSourceGetActualType(src);
|
||||||
g_autoptr(virJSONValue) fileprops = NULL;
|
g_autoptr(virJSONValue) fileprops = NULL;
|
||||||
const char *driver = NULL;
|
const char *driver = NULL;
|
||||||
virTristateBool aro = VIR_TRISTATE_BOOL_ABSENT;
|
virTristateBool aro = VIR_TRISTATE_BOOL_ABSENT;
|
||||||
virTristateBool ro = VIR_TRISTATE_BOOL_ABSENT;
|
virTristateBool ro = VIR_TRISTATE_BOOL_ABSENT;
|
||||||
|
bool onlytarget = flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY;
|
||||||
|
bool legacy = flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_LEGACY;
|
||||||
|
|
||||||
if (autoreadonly) {
|
if (flags & QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY) {
|
||||||
aro = VIR_TRISTATE_BOOL_YES;
|
aro = VIR_TRISTATE_BOOL_YES;
|
||||||
} else {
|
} else {
|
||||||
if (src->readonly)
|
if (src->readonly)
|
||||||
@ -1576,15 +1582,18 @@ qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src,
|
|||||||
bool autoreadonly)
|
bool autoreadonly)
|
||||||
{
|
{
|
||||||
g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
|
g_autoptr(qemuBlockStorageSourceAttachData) data = NULL;
|
||||||
|
unsigned int backendpropsflags = 0;
|
||||||
|
|
||||||
|
if (autoreadonly)
|
||||||
|
backendpropsflags |= QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY;
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
if (VIR_ALLOC(data) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(data->formatProps = qemuBlockStorageSourceGetBlockdevProps(src,
|
if (!(data->formatProps = qemuBlockStorageSourceGetBlockdevProps(src,
|
||||||
backingStore)) ||
|
backingStore)) ||
|
||||||
!(data->storageProps = qemuBlockStorageSourceGetBackendProps(src, false,
|
!(data->storageProps = qemuBlockStorageSourceGetBackendProps(src,
|
||||||
false,
|
backendpropsflags)))
|
||||||
autoreadonly)))
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
data->storageNodeName = src->nodestorage;
|
data->storageNodeName = src->nodestorage;
|
||||||
@ -2108,7 +2117,8 @@ qemuBlockGetBackingStoreString(virStorageSourcePtr src,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* use json: pseudo protocol otherwise */
|
/* use json: pseudo protocol otherwise */
|
||||||
if (!(backingProps = qemuBlockStorageSourceGetBackendProps(src, false, true, false)))
|
if (!(backingProps = qemuBlockStorageSourceGetBackendProps(src,
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
props = backingProps;
|
props = backingProps;
|
||||||
|
@ -56,11 +56,15 @@ qemuBlockGetNodeData(virJSONValuePtr data);
|
|||||||
bool
|
bool
|
||||||
qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSourcePtr src);
|
qemuBlockStorageSourceSupportsConcurrentAccess(virStorageSourcePtr src);
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_LEGACY = 1 << 0,
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY = 1 << 1,
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY = 1 << 2,
|
||||||
|
} qemuBlockStorageSourceBackendPropsFlags;
|
||||||
|
|
||||||
virJSONValuePtr
|
virJSONValuePtr
|
||||||
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
|
qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
|
||||||
bool legacy,
|
unsigned int flags);
|
||||||
bool onlytarget,
|
|
||||||
bool autoreadonly);
|
|
||||||
|
|
||||||
virURIPtr
|
virURIPtr
|
||||||
qemuBlockStorageSourceGetURI(virStorageSourcePtr src);
|
qemuBlockStorageSourceGetURI(virStorageSourcePtr src);
|
||||||
|
@ -1193,7 +1193,8 @@ qemuDiskSourceGetProps(virStorageSourcePtr src)
|
|||||||
g_autoptr(virJSONValue) props = NULL;
|
g_autoptr(virJSONValue) props = NULL;
|
||||||
virJSONValuePtr ret;
|
virJSONValuePtr ret;
|
||||||
|
|
||||||
if (!(props = qemuBlockStorageSourceGetBackendProps(src, true, false, false)))
|
if (!(props = qemuBlockStorageSourceGetBackendProps(src,
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_LEGACY)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virJSONValueObjectCreate(&ret, "a:file", &props, NULL) < 0)
|
if (virJSONValueObjectCreate(&ret, "a:file", &props, NULL) < 0)
|
||||||
|
@ -62,6 +62,10 @@ testBackingXMLjsonXML(const void *args)
|
|||||||
g_autoptr(virStorageSource) xmlsrc = NULL;
|
g_autoptr(virStorageSource) xmlsrc = NULL;
|
||||||
g_autoptr(virStorageSource) jsonsrc = NULL;
|
g_autoptr(virStorageSource) jsonsrc = NULL;
|
||||||
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) debug = VIR_BUFFER_INITIALIZER;
|
||||||
|
unsigned int backendpropsflags = 0;
|
||||||
|
|
||||||
|
if (data->legacy)
|
||||||
|
backendpropsflags |= QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_LEGACY;
|
||||||
|
|
||||||
if (!(xmlsrc = virStorageSourceNew()))
|
if (!(xmlsrc = virStorageSourceNew()))
|
||||||
return -1;
|
return -1;
|
||||||
@ -77,9 +81,7 @@ testBackingXMLjsonXML(const void *args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc,
|
if (!(backendprops = qemuBlockStorageSourceGetBackendProps(xmlsrc,
|
||||||
data->legacy,
|
backendpropsflags))) {
|
||||||
false,
|
|
||||||
false))) {
|
|
||||||
fprintf(stderr, "failed to format disk source json\n");
|
fprintf(stderr, "failed to format disk source json\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -159,7 +161,8 @@ testJSONtoJSON(const void *args)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(jsonsrcout = qemuBlockStorageSourceGetBackendProps(src, false, false, true))) {
|
if (!(jsonsrcout = qemuBlockStorageSourceGetBackendProps(src,
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY))) {
|
||||||
fprintf(stderr, "failed to format disk source json\n");
|
fprintf(stderr, "failed to format disk source json\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -290,6 +293,9 @@ testQemuDiskXMLToProps(const void *opaque)
|
|||||||
|
|
||||||
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
||||||
g_autofree char *backingstore = NULL;
|
g_autofree char *backingstore = NULL;
|
||||||
|
unsigned int backendpropsflagsnormal = QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY;
|
||||||
|
unsigned int backendpropsflagstarget = QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_AUTO_READONLY |
|
||||||
|
QEMU_BLOCK_STORAGE_SOURCE_BACKEND_PROPS_TARGET_ONLY;
|
||||||
|
|
||||||
if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
|
if (testQemuDiskXMLToJSONFakeSecrets(n) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -300,8 +306,8 @@ testQemuDiskXMLToProps(const void *opaque)
|
|||||||
qemuDomainPrepareDiskSourceData(disk, n);
|
qemuDomainPrepareDiskSourceData(disk, n);
|
||||||
|
|
||||||
if (!(formatProps = qemuBlockStorageSourceGetBlockdevProps(n, n->backingStore)) ||
|
if (!(formatProps = qemuBlockStorageSourceGetBlockdevProps(n, n->backingStore)) ||
|
||||||
!(storageSrcOnlyProps = qemuBlockStorageSourceGetBackendProps(n, false, true, true)) ||
|
!(storageSrcOnlyProps = qemuBlockStorageSourceGetBackendProps(n, backendpropsflagstarget)) ||
|
||||||
!(storageProps = qemuBlockStorageSourceGetBackendProps(n, false, false, true)) ||
|
!(storageProps = qemuBlockStorageSourceGetBackendProps(n, backendpropsflagsnormal)) ||
|
||||||
!(backingstore = qemuBlockGetBackingStoreString(n, true))) {
|
!(backingstore = qemuBlockGetBackingStoreString(n, true))) {
|
||||||
if (!data->fail) {
|
if (!data->fail) {
|
||||||
VIR_TEST_VERBOSE("failed to generate qemu blockdev props");
|
VIR_TEST_VERBOSE("failed to generate qemu blockdev props");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user