mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
qapi: Change data type of the FOO_lookup generated for enum FOO
Currently, a FOO_lookup is an array of strings terminated by a NULL sentinel. A future patch will generate enums with "holes". NULL-termination will cease to work then. To prepare for that, store the length in the FOO_lookup by wrapping it in a struct and adding a member for the length. The sentinel will be dropped next. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20170822132255.23945-13-marcandre.lureau@redhat.com> [Basically redone] Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <1503564371-26090-16-git-send-email-armbru@redhat.com> [Rebased]
This commit is contained in:
committed by
Markus Armbruster
parent
788b305c91
commit
f7abe0ecd4
+1
-1
@@ -395,7 +395,7 @@ host_memory_backend_class_init(ObjectClass *oc, void *data)
|
||||
host_memory_backend_set_host_nodes,
|
||||
NULL, NULL, &error_abort);
|
||||
object_class_property_add_enum(oc, "policy", "HostMemPolicy",
|
||||
HostMemPolicy_lookup,
|
||||
&HostMemPolicy_lookup,
|
||||
host_memory_backend_get_policy,
|
||||
host_memory_backend_set_policy, &error_abort);
|
||||
object_class_property_add_str(oc, "id", get_id, set_id, &error_abort);
|
||||
|
||||
@@ -1332,7 +1332,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
|
||||
detect_zeroes = qemu_opt_get(opts, "detect-zeroes");
|
||||
if (detect_zeroes) {
|
||||
BlockdevDetectZeroesOptions value =
|
||||
qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
|
||||
qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
|
||||
detect_zeroes,
|
||||
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
|
||||
&local_err);
|
||||
|
||||
+2
-2
@@ -169,7 +169,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp)
|
||||
error_setg(errp, "Missing event name for rule");
|
||||
return -1;
|
||||
}
|
||||
event = qapi_enum_parse(BlkdebugEvent_lookup, event_name, -1, errp);
|
||||
event = qapi_enum_parse(&BlkdebugEvent_lookup, event_name, -1, errp);
|
||||
if (event < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -732,7 +732,7 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event,
|
||||
struct BlkdebugRule *rule;
|
||||
int blkdebug_event;
|
||||
|
||||
blkdebug_event = qapi_enum_parse(BlkdebugEvent_lookup, event, -1, NULL);
|
||||
blkdebug_event = qapi_enum_parse(&BlkdebugEvent_lookup, event, -1, NULL);
|
||||
if (blkdebug_event < 0) {
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
+5
-3
@@ -437,7 +437,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
||||
aio_default = (bdrv_flags & BDRV_O_NATIVE_AIO)
|
||||
? BLOCKDEV_AIO_OPTIONS_NATIVE
|
||||
: BLOCKDEV_AIO_OPTIONS_THREADS;
|
||||
aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
|
||||
aio = qapi_enum_parse(&BlockdevAioOptions_lookup,
|
||||
qemu_opt_get(opts, "aio"),
|
||||
aio_default, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
@@ -446,7 +447,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
|
||||
}
|
||||
s->use_linux_aio = (aio == BLOCKDEV_AIO_OPTIONS_NATIVE);
|
||||
|
||||
locking = qapi_enum_parse(OnOffAuto_lookup, qemu_opt_get(opts, "locking"),
|
||||
locking = qapi_enum_parse(&OnOffAuto_lookup,
|
||||
qemu_opt_get(opts, "locking"),
|
||||
ON_OFF_AUTO_AUTO, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
@@ -1973,7 +1975,7 @@ static int raw_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
BDRV_SECTOR_SIZE);
|
||||
nocow = qemu_opt_get_bool(opts, BLOCK_OPT_NOCOW, false);
|
||||
buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
|
||||
prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
|
||||
prealloc = qapi_enum_parse(&PreallocMode_lookup, buf,
|
||||
PREALLOC_MODE_OFF, &local_err);
|
||||
g_free(buf);
|
||||
if (local_err) {
|
||||
|
||||
+1
-1
@@ -302,7 +302,7 @@ static bool get_aio_option(QemuOpts *opts, int flags, Error **errp)
|
||||
|
||||
aio_default = (flags & BDRV_O_NATIVE_AIO) ? BLOCKDEV_AIO_OPTIONS_NATIVE
|
||||
: BLOCKDEV_AIO_OPTIONS_THREADS;
|
||||
aio = qapi_enum_parse(BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
|
||||
aio = qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"),
|
||||
aio_default, errp);
|
||||
|
||||
switch (aio) {
|
||||
|
||||
+2
-2
@@ -543,7 +543,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
|
||||
if (!strcmp(ptr, "tcp")) {
|
||||
ptr = "inet"; /* accept legacy "tcp" */
|
||||
}
|
||||
type = qapi_enum_parse(SocketAddressType_lookup, ptr, -1, NULL);
|
||||
type = qapi_enum_parse(&SocketAddressType_lookup, ptr, -1, NULL);
|
||||
if (type != SOCKET_ADDRESS_TYPE_INET
|
||||
&& type != SOCKET_ADDRESS_TYPE_UNIX) {
|
||||
error_setg(&local_err,
|
||||
@@ -1000,7 +1000,7 @@ static int qemu_gluster_create(const char *filename,
|
||||
BDRV_SECTOR_SIZE);
|
||||
|
||||
tmp = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
|
||||
prealloc = qapi_enum_parse(PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
|
||||
prealloc = qapi_enum_parse(&PreallocMode_lookup, tmp, PREALLOC_MODE_OFF,
|
||||
&local_err);
|
||||
g_free(tmp);
|
||||
if (local_err) {
|
||||
|
||||
+8
-6
@@ -68,13 +68,15 @@ typedef enum ParallelsPreallocMode {
|
||||
PRL_PREALLOC_MODE__MAX = 2,
|
||||
} ParallelsPreallocMode;
|
||||
|
||||
static const char *prealloc_mode_lookup[] = {
|
||||
"falloc",
|
||||
"truncate",
|
||||
NULL,
|
||||
static QEnumLookup prealloc_mode_lookup = {
|
||||
.array = (const char *const[]) {
|
||||
"falloc",
|
||||
"truncate",
|
||||
NULL,
|
||||
},
|
||||
.size = PRL_PREALLOC_MODE__MAX
|
||||
};
|
||||
|
||||
|
||||
typedef struct BDRVParallelsState {
|
||||
/** Locking is conservative, the lock protects
|
||||
* - image file extending (truncate, fallocate)
|
||||
@@ -695,7 +697,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
qemu_opt_get_size_del(opts, PARALLELS_OPT_PREALLOC_SIZE, 0);
|
||||
s->prealloc_size = MAX(s->tracks, s->prealloc_size >> BDRV_SECTOR_BITS);
|
||||
buf = qemu_opt_get_del(opts, PARALLELS_OPT_PREALLOC_MODE);
|
||||
s->prealloc_mode = qapi_enum_parse(prealloc_mode_lookup, buf,
|
||||
s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf,
|
||||
PRL_PREALLOC_MODE_FALLOCATE,
|
||||
&local_err);
|
||||
g_free(buf);
|
||||
|
||||
+2
-2
@@ -2915,7 +2915,7 @@ static int qcow2_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
goto finish;
|
||||
}
|
||||
buf = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
|
||||
prealloc = qapi_enum_parse(PreallocMode_lookup, buf,
|
||||
prealloc = qapi_enum_parse(&PreallocMode_lookup, buf,
|
||||
PREALLOC_MODE_OFF, &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
@@ -3605,7 +3605,7 @@ static BlockMeasureInfo *qcow2_measure(QemuOpts *opts, BlockDriverState *in_bs,
|
||||
}
|
||||
|
||||
optstr = qemu_opt_get_del(opts, BLOCK_OPT_PREALLOC);
|
||||
prealloc = qapi_enum_parse(PreallocMode_lookup, optstr,
|
||||
prealloc = qapi_enum_parse(&PreallocMode_lookup, optstr,
|
||||
PREALLOC_MODE_OFF, &local_err);
|
||||
g_free(optstr);
|
||||
if (local_err) {
|
||||
|
||||
+1
-1
@@ -912,7 +912,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
if (!pattern_str) {
|
||||
ret = QUORUM_READ_PATTERN_QUORUM;
|
||||
} else {
|
||||
ret = qapi_enum_parse(QuorumReadPattern_lookup, pattern_str,
|
||||
ret = qapi_enum_parse(&QuorumReadPattern_lookup, pattern_str,
|
||||
-EINVAL, NULL);
|
||||
}
|
||||
if (ret < 0) {
|
||||
|
||||
+1
-1
@@ -437,7 +437,7 @@ static void extract_common_blockdev_options(QemuOpts *opts, int *bdrv_flags,
|
||||
|
||||
if (detect_zeroes) {
|
||||
*detect_zeroes =
|
||||
qapi_enum_parse(BlockdevDetectZeroesOptions_lookup,
|
||||
qapi_enum_parse(&BlockdevDetectZeroesOptions_lookup,
|
||||
qemu_opt_get(opts, "detect-zeroes"),
|
||||
BLOCKDEV_DETECT_ZEROES_OPTIONS_OFF,
|
||||
&local_error);
|
||||
|
||||
+4
-4
@@ -264,7 +264,7 @@ qcrypto_block_luks_cipher_alg_lookup(QCryptoCipherAlgorithm alg,
|
||||
/* XXX replace with qapi_enum_parse() in future, when we can
|
||||
* make that function emit a more friendly error message */
|
||||
static int qcrypto_block_luks_name_lookup(const char *name,
|
||||
const char *const *map,
|
||||
const QEnumLookup *map,
|
||||
const char *type,
|
||||
Error **errp)
|
||||
{
|
||||
@@ -279,19 +279,19 @@ static int qcrypto_block_luks_name_lookup(const char *name,
|
||||
|
||||
#define qcrypto_block_luks_cipher_mode_lookup(name, errp) \
|
||||
qcrypto_block_luks_name_lookup(name, \
|
||||
QCryptoCipherMode_lookup, \
|
||||
&QCryptoCipherMode_lookup, \
|
||||
"Cipher mode", \
|
||||
errp)
|
||||
|
||||
#define qcrypto_block_luks_hash_name_lookup(name, errp) \
|
||||
qcrypto_block_luks_name_lookup(name, \
|
||||
QCryptoHashAlgorithm_lookup, \
|
||||
&QCryptoHashAlgorithm_lookup, \
|
||||
"Hash algorithm", \
|
||||
errp)
|
||||
|
||||
#define qcrypto_block_luks_ivgen_name_lookup(name, errp) \
|
||||
qcrypto_block_luks_name_lookup(name, \
|
||||
QCryptoIVGenAlgorithm_lookup, \
|
||||
&QCryptoIVGenAlgorithm_lookup, \
|
||||
"IV generator", \
|
||||
errp)
|
||||
|
||||
|
||||
+1
-1
@@ -378,7 +378,7 @@ qcrypto_secret_class_init(ObjectClass *oc, void *data)
|
||||
NULL);
|
||||
object_class_property_add_enum(oc, "format",
|
||||
"QCryptoSecretFormat",
|
||||
QCryptoSecretFormat_lookup,
|
||||
&QCryptoSecretFormat_lookup,
|
||||
qcrypto_secret_prop_get_format,
|
||||
qcrypto_secret_prop_set_format,
|
||||
NULL);
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ qcrypto_tls_creds_class_init(ObjectClass *oc, void *data)
|
||||
NULL);
|
||||
object_class_property_add_enum(oc, "endpoint",
|
||||
"QCryptoTLSCredsEndpoint",
|
||||
QCryptoTLSCredsEndpoint_lookup,
|
||||
&QCryptoTLSCredsEndpoint_lookup,
|
||||
qcrypto_tls_creds_prop_get_endpoint,
|
||||
qcrypto_tls_creds_prop_set_endpoint,
|
||||
NULL);
|
||||
|
||||
@@ -1528,7 +1528,7 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
|
||||
MigrationCapabilityStatusList *caps = g_malloc0(sizeof(*caps));
|
||||
int val;
|
||||
|
||||
val = qapi_enum_parse(MigrationCapability_lookup, cap, -1, &err);
|
||||
val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
|
||||
if (val < 0) {
|
||||
goto end;
|
||||
}
|
||||
@@ -1557,7 +1557,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
|
||||
Error *err = NULL;
|
||||
int val, ret;
|
||||
|
||||
val = qapi_enum_parse(MigrationParameter_lookup, param, -1, &err);
|
||||
val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
|
||||
if (val < 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -1735,7 +1735,7 @@ void hmp_change(Monitor *mon, const QDict *qdict)
|
||||
} else {
|
||||
if (read_only) {
|
||||
read_only_mode =
|
||||
qapi_enum_parse(BlockdevChangeReadOnlyMode_lookup,
|
||||
qapi_enum_parse(&BlockdevChangeReadOnlyMode_lookup,
|
||||
read_only,
|
||||
BLOCKDEV_CHANGE_READ_ONLY_MODE_RETAIN, &err);
|
||||
if (err) {
|
||||
|
||||
@@ -587,7 +587,7 @@ const PropertyInfo qdev_prop_macaddr = {
|
||||
const PropertyInfo qdev_prop_on_off_auto = {
|
||||
.name = "OnOffAuto",
|
||||
.description = "on/off/auto",
|
||||
.enum_table = OnOffAuto_lookup,
|
||||
.enum_table = &OnOffAuto_lookup,
|
||||
.get = get_enum,
|
||||
.set = set_enum,
|
||||
.set_default_value = set_default_value_enum,
|
||||
@@ -599,7 +599,7 @@ QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy) != sizeof(int));
|
||||
|
||||
const PropertyInfo qdev_prop_losttickpolicy = {
|
||||
.name = "LostTickPolicy",
|
||||
.enum_table = LostTickPolicy_lookup,
|
||||
.enum_table = &LostTickPolicy_lookup,
|
||||
.get = get_enum,
|
||||
.set = set_enum,
|
||||
.set_default_value = set_default_value_enum,
|
||||
@@ -613,7 +613,7 @@ const PropertyInfo qdev_prop_blockdev_on_error = {
|
||||
.name = "BlockdevOnError",
|
||||
.description = "Error handling policy, "
|
||||
"report/ignore/enospc/stop/auto",
|
||||
.enum_table = BlockdevOnError_lookup,
|
||||
.enum_table = &BlockdevOnError_lookup,
|
||||
.get = get_enum,
|
||||
.set = set_enum,
|
||||
.set_default_value = set_default_value_enum,
|
||||
@@ -627,7 +627,7 @@ const PropertyInfo qdev_prop_bios_chs_trans = {
|
||||
.name = "BiosAtaTranslation",
|
||||
.description = "Logical CHS translation algorithm, "
|
||||
"auto/none/lba/large/rechs",
|
||||
.enum_table = BiosAtaTranslation_lookup,
|
||||
.enum_table = &BiosAtaTranslation_lookup,
|
||||
.get = get_enum,
|
||||
.set = set_enum,
|
||||
.set_default_value = set_default_value_enum,
|
||||
@@ -639,7 +639,7 @@ const PropertyInfo qdev_prop_fdc_drive_type = {
|
||||
.name = "FdcDriveType",
|
||||
.description = "FDC drive type, "
|
||||
"144/288/120/none/auto",
|
||||
.enum_table = FloppyDriveType_lookup,
|
||||
.enum_table = &FloppyDriveType_lookup,
|
||||
.get = get_enum,
|
||||
.set = set_enum,
|
||||
.set_default_value = set_default_value_enum,
|
||||
|
||||
@@ -249,7 +249,7 @@ struct Property {
|
||||
struct PropertyInfo {
|
||||
const char *name;
|
||||
const char *description;
|
||||
const char * const *enum_table;
|
||||
const QEnumLookup *enum_table;
|
||||
int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
|
||||
void (*set_default_value)(Object *obj, const Property *prop);
|
||||
void (*create)(Object *obj, Property *prop, Error **errp);
|
||||
|
||||
+7
-2
@@ -11,8 +11,13 @@
|
||||
#ifndef QAPI_UTIL_H
|
||||
#define QAPI_UTIL_H
|
||||
|
||||
const char *qapi_enum_lookup(const char *const lookup[], int val);
|
||||
int qapi_enum_parse(const char * const lookup[], const char *buf,
|
||||
typedef struct QEnumLookup {
|
||||
const char *const *array;
|
||||
int size;
|
||||
} QEnumLookup;
|
||||
|
||||
const char *qapi_enum_lookup(const QEnumLookup *lookup, int val);
|
||||
int qapi_enum_parse(const QEnumLookup *lookup, const char *buf,
|
||||
int def, Error **errp);
|
||||
|
||||
int parse_qapi_name(const char *name, bool complete);
|
||||
|
||||
@@ -469,7 +469,7 @@ bool visit_optional(Visitor *v, const char *name, bool *present);
|
||||
* that visit_type_str() must have no unwelcome side effects.
|
||||
*/
|
||||
void visit_type_enum(Visitor *v, const char *name, int *obj,
|
||||
const char *const strings[], Error **errp);
|
||||
const QEnumLookup *lookup, Error **errp);
|
||||
|
||||
/*
|
||||
* Check if visitor is an input visitor.
|
||||
|
||||
@@ -1415,14 +1415,14 @@ void object_class_property_add_bool(ObjectClass *klass, const char *name,
|
||||
*/
|
||||
void object_property_add_enum(Object *obj, const char *name,
|
||||
const char *typename,
|
||||
const char * const *strings,
|
||||
const QEnumLookup *lookup,
|
||||
int (*get)(Object *, Error **),
|
||||
void (*set)(Object *, int, Error **),
|
||||
Error **errp);
|
||||
|
||||
void object_class_property_add_enum(ObjectClass *klass, const char *name,
|
||||
const char *typename,
|
||||
const char * const *strings,
|
||||
const QEnumLookup *lookup,
|
||||
int (*get)(Object *, Error **),
|
||||
void (*set)(Object *, int, Error **),
|
||||
Error **errp);
|
||||
|
||||
@@ -88,7 +88,7 @@ static int global_state_post_load(void *opaque, int version_id)
|
||||
s->received = true;
|
||||
trace_migrate_global_state_post_load(runstate);
|
||||
|
||||
r = qapi_enum_parse(RunState_lookup, runstate, -1, &local_err);
|
||||
r = qapi_enum_parse(&RunState_lookup, runstate, -1, &local_err);
|
||||
|
||||
if (r == -1) {
|
||||
if (local_err) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user