diff options
Diffstat (limited to 'block')
-rw-r--r-- | block/backup.c | 2 | ||||
-rw-r--r-- | block/blkdebug.c | 27 | ||||
-rw-r--r-- | block/file-posix.c | 20 | ||||
-rw-r--r-- | block/file-win32.c | 7 | ||||
-rw-r--r-- | block/gluster.c | 11 | ||||
-rw-r--r-- | block/iscsi.c | 2 | ||||
-rw-r--r-- | block/nfs.c | 2 | ||||
-rw-r--r-- | block/parallels.c | 17 | ||||
-rw-r--r-- | block/qcow2.c | 15 | ||||
-rw-r--r-- | block/qed.c | 2 | ||||
-rw-r--r-- | block/quorum.c | 27 | ||||
-rw-r--r-- | block/rbd.c | 2 | ||||
-rw-r--r-- | block/sheepdog.c | 2 |
13 files changed, 53 insertions, 83 deletions
diff --git a/block/backup.c b/block/backup.c index 504a089150..517c300a49 100644 --- a/block/backup.c +++ b/block/backup.c @@ -596,7 +596,7 @@ BlockJob *backup_job_create(const char *job_id, BlockDriverState *bs, error_setg(errp, "a sync_bitmap was provided to backup_run, " "but received an incompatible sync_mode (%s)", - MirrorSyncMode_lookup[sync_mode]); + MirrorSyncMode_str(sync_mode)); return NULL; } diff --git a/block/blkdebug.c b/block/blkdebug.c index c19ab28f07..8e385acf54 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -149,20 +149,6 @@ static QemuOptsList *config_groups[] = { NULL }; -static int get_event_by_name(const char *name, BlkdebugEvent *event) -{ - int i; - - for (i = 0; i < BLKDBG__MAX; i++) { - if (!strcmp(BlkdebugEvent_lookup[i], name)) { - *event = i; - return 0; - } - } - - return -1; -} - struct add_rule_data { BDRVBlkdebugState *s; int action; @@ -173,7 +159,7 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp) struct add_rule_data *d = opaque; BDRVBlkdebugState *s = d->s; const char* event_name; - BlkdebugEvent event; + int event; struct BlkdebugRule *rule; int64_t sector; @@ -182,8 +168,9 @@ static int add_rule(void *opaque, QemuOpts *opts, Error **errp) if (!event_name) { error_setg(errp, "Missing event name for rule"); return -1; - } else if (get_event_by_name(event_name, &event) < 0) { - error_setg(errp, "Invalid event name \"%s\"", event_name); + } + event = qapi_enum_parse(&BlkdebugEvent_lookup, event_name, -1, errp); + if (event < 0) { return -1; } @@ -743,13 +730,13 @@ static int blkdebug_debug_breakpoint(BlockDriverState *bs, const char *event, { BDRVBlkdebugState *s = bs->opaque; struct BlkdebugRule *rule; - BlkdebugEvent blkdebug_event; + int blkdebug_event; - if (get_event_by_name(event, &blkdebug_event) < 0) { + blkdebug_event = qapi_enum_parse(&BlkdebugEvent_lookup, event, -1, NULL); + if (blkdebug_event < 0) { return -ENOENT; } - rule = g_malloc(sizeof(*rule)); *rule = (struct BlkdebugRule) { .event = blkdebug_event, diff --git a/block/file-posix.c b/block/file-posix.c index cb3bfce147..6acbd56238 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -31,7 +31,6 @@ #include "block/thread-pool.h" #include "qemu/iov.h" #include "block/raw-aio.h" -#include "qapi/util.h" #include "qapi/qmp/qstring.h" #if defined(__APPLE__) && (__MACH__) @@ -438,8 +437,9 @@ 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"), - BLOCKDEV_AIO_OPTIONS__MAX, aio_default, &local_err); + aio = qapi_enum_parse(&BlockdevAioOptions_lookup, + qemu_opt_get(opts, "aio"), + aio_default, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; @@ -447,8 +447,9 @@ 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"), - ON_OFF_AUTO__MAX, ON_OFF_AUTO_AUTO, &local_err); + 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); ret = -EINVAL; @@ -1725,7 +1726,7 @@ static int raw_regular_truncate(int fd, int64_t offset, PreallocMode prealloc, default: result = -ENOTSUP; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return result; } @@ -1760,7 +1761,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Preallocation mode '%s' unsupported for this " - "non-regular file", PreallocMode_lookup[prealloc]); + "non-regular file", PreallocMode_str(prealloc)); return -ENOTSUP; } @@ -1974,9 +1975,8 @@ 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_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc = qapi_enum_parse(&PreallocMode_lookup, buf, + PREALLOC_MODE_OFF, &local_err); g_free(buf); if (local_err) { error_propagate(errp, local_err); diff --git a/block/file-win32.c b/block/file-win32.c index 4706335cff..9e02214a69 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -31,7 +31,6 @@ #include "block/thread-pool.h" #include "qemu/iov.h" #include "qapi/qmp/qstring.h" -#include "qapi/util.h" #include <windows.h> #include <winioctl.h> @@ -303,8 +302,8 @@ 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"), - BLOCKDEV_AIO_OPTIONS__MAX, aio_default, errp); + aio = qapi_enum_parse(&BlockdevAioOptions_lookup, qemu_opt_get(opts, "aio"), + aio_default, errp); switch (aio) { case BLOCKDEV_AIO_OPTIONS_NATIVE: @@ -470,7 +469,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } diff --git a/block/gluster.c b/block/gluster.c index 3064a45047..0f4265a3a4 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -12,7 +12,6 @@ #include "block/block_int.h" #include "qapi/error.h" #include "qapi/qmp/qerror.h" -#include "qapi/util.h" #include "qemu/uri.h" #include "qemu/error-report.h" #include "qemu/cutils.h" @@ -544,8 +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, - SOCKET_ADDRESS_TYPE__MAX, -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, @@ -1002,8 +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__MAX, PREALLOC_MODE_OFF, + prealloc = qapi_enum_parse(&PreallocMode_lookup, tmp, PREALLOC_MODE_OFF, &local_err); g_free(tmp); if (local_err) { @@ -1050,7 +1047,7 @@ static int qemu_gluster_create(const char *filename, default: ret = -EINVAL; error_setg(errp, "Unsupported preallocation mode: %s", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); break; } @@ -1102,7 +1099,7 @@ static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } diff --git a/block/iscsi.c b/block/iscsi.c index d557c99668..8b47d30dcc 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2087,7 +2087,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } diff --git a/block/nfs.c b/block/nfs.c index bec16b72a6..337fcd9c84 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -772,7 +772,7 @@ static int nfs_file_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } diff --git a/block/parallels.c b/block/parallels.c index e1e06d23cc..2b6c6e5709 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -35,7 +35,6 @@ #include "qemu/module.h" #include "qemu/bswap.h" #include "qemu/bitmap.h" -#include "qapi/util.h" /**************************************************************/ @@ -69,13 +68,14 @@ 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", + }, + .size = PRL_PREALLOC_MODE__MAX }; - typedef struct BDRVParallelsState { /** Locking is conservative, the lock protects * - image file extending (truncate, fallocate) @@ -696,8 +696,9 @@ 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, - PRL_PREALLOC_MODE__MAX, PRL_PREALLOC_MODE_FALLOCATE, &local_err); + s->prealloc_mode = qapi_enum_parse(&prealloc_mode_lookup, buf, + PRL_PREALLOC_MODE_FALLOCATE, + &local_err); g_free(buf); if (local_err != NULL) { goto fail_options; diff --git a/block/qcow2.c b/block/qcow2.c index a3679c69e8..2ec399663e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -30,7 +30,6 @@ #include "qemu/error-report.h" #include "qapi/qmp/qerror.h" #include "qapi/qmp/qbool.h" -#include "qapi/util.h" #include "qapi/qmp/types.h" #include "qapi-event.h" #include "trace.h" @@ -2716,7 +2715,7 @@ static int qcow2_create2(const char *filename, int64_t total_size, int64_t prealloc_size = qcow2_calc_prealloc_size(total_size, cluster_size, refcount_order); qemu_opt_set_number(opts, BLOCK_OPT_SIZE, prealloc_size, &error_abort); - qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_lookup[prealloc], + qemu_opt_set(opts, BLOCK_OPT_PREALLOC, PreallocMode_str(prealloc), &error_abort); } @@ -2916,9 +2915,8 @@ 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_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc = qapi_enum_parse(&PreallocMode_lookup, buf, + PREALLOC_MODE_OFF, &local_err); if (local_err) { error_propagate(errp, local_err); ret = -EINVAL; @@ -3082,7 +3080,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset, prealloc != PREALLOC_MODE_FALLOC && prealloc != PREALLOC_MODE_FULL) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } @@ -3607,9 +3605,8 @@ 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_MODE__MAX, PREALLOC_MODE_OFF, - &local_err); + prealloc = qapi_enum_parse(&PreallocMode_lookup, optstr, + PREALLOC_MODE_OFF, &local_err); g_free(optstr); if (local_err) { goto err; diff --git a/block/qed.c b/block/qed.c index dc54bf4a93..28e2ec89e8 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1399,7 +1399,7 @@ static int bdrv_qed_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } diff --git a/block/quorum.c b/block/quorum.c index d04da4f430..272f9a5b77 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -867,30 +867,13 @@ static QemuOptsList quorum_runtime_opts = { }, }; -static int parse_read_pattern(const char *opt) -{ - int i; - - if (!opt) { - /* Set quorum as default */ - return QUORUM_READ_PATTERN_QUORUM; - } - - for (i = 0; i < QUORUM_READ_PATTERN__MAX; i++) { - if (!strcmp(opt, QuorumReadPattern_lookup[i])) { - return i; - } - } - - return -EINVAL; -} - static int quorum_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { BDRVQuorumState *s = bs->opaque; Error *local_err = NULL; QemuOpts *opts = NULL; + const char *pattern_str; bool *opened; int i; int ret = 0; @@ -925,7 +908,13 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags, goto exit; } - ret = parse_read_pattern(qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN)); + pattern_str = qemu_opt_get(opts, QUORUM_OPT_READ_PATTERN); + if (!pattern_str) { + ret = QUORUM_READ_PATTERN_QUORUM; + } else { + ret = qapi_enum_parse(&QuorumReadPattern_lookup, pattern_str, + -EINVAL, NULL); + } if (ret < 0) { error_setg(&local_err, "Please set read-pattern as fifo or quorum"); goto exit; diff --git a/block/rbd.c b/block/rbd.c index 9c3aa638e7..144f350e1f 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -944,7 +944,7 @@ static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } diff --git a/block/sheepdog.c b/block/sheepdog.c index 64ab07f3b7..696a71442a 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2176,7 +2176,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset, if (prealloc != PREALLOC_MODE_OFF) { error_setg(errp, "Unsupported preallocation mode '%s'", - PreallocMode_lookup[prealloc]); + PreallocMode_str(prealloc)); return -ENOTSUP; } |