Skip to content

Commit

Permalink
qemu-option: Use returned bool to check for failure
Browse files Browse the repository at this point in the history
The previous commit enables conversion of

    foo(..., &err);
    if (err) {
        ...
    }

to

    if (!foo(..., &err)) {
        ...
    }

for QemuOpts functions that now return true / false on success /
error.  Coccinelle script:

    @@
    identifier fun = {
        opts_do_parse, parse_option_bool, parse_option_number,
        parse_option_size, qemu_opt_parse, qemu_opt_rename, qemu_opt_set,
        qemu_opt_set_bool, qemu_opt_set_number, qemu_opts_absorb_qdict,
        qemu_opts_do_parse, qemu_opts_from_qdict_entry, qemu_opts_set,
        qemu_opts_validate
    };
    expression list args, args2;
    typedef Error;
    Error *err;
    @@
    -    fun(args, &err, args2);
    -    if (err)
    +    if (!fun(args, &err, args2))
         {
             ...
         }

A few line breaks tidied up manually.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20200707160613.848843-15-armbru@redhat.com>
[Conflict with commit 0b6786a "block/amend: refactor qcow2 amend
options" resolved by rerunning Coccinelle on master's version]
  • Loading branch information
Markus Armbruster committed Jul 10, 2020
1 parent c75d7f7 commit 235e59c
Show file tree
Hide file tree
Showing 32 changed files with 71 additions and 133 deletions.
16 changes: 6 additions & 10 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,8 +1629,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
assert(options != NULL && bs->options != options);

opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail_opts;
Expand Down Expand Up @@ -4091,8 +4090,7 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,

/* Process generic block layer options */
opts = qemu_opts_create(&bdrv_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, reopen_state->options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, reopen_state->options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto error;
Expand Down Expand Up @@ -6063,8 +6061,7 @@ void bdrv_img_create(const char *filename, const char *fmt,

/* Parse -o options */
if (options) {
qemu_opts_do_parse(opts, options, NULL, &local_err);
if (local_err) {
if (!qemu_opts_do_parse(opts, options, NULL, &local_err)) {
goto out;
}
}
Expand All @@ -6077,17 +6074,16 @@ void bdrv_img_create(const char *filename, const char *fmt,
}

if (base_filename) {
qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename, &local_err);
if (local_err) {
if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename,
&local_err)) {
error_setg(errp, "Backing file not supported for file format '%s'",
fmt);
goto out;
}
}

if (base_fmt) {
qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &local_err);
if (local_err) {
if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &local_err)) {
error_setg(errp, "Backing file format not supported for file "
"format '%s'", fmt);
goto out;
Expand Down
3 changes: 1 addition & 2 deletions block/blkdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,7 @@ static int blkdebug_open(BlockDriverState *bs, QDict *options, int flags,
uint64_t align;

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto out;
Expand Down
3 changes: 1 addition & 2 deletions block/blklogwrites.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
bool log_append;

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
ret = -EINVAL;
error_propagate(errp, local_err);
goto fail;
Expand Down
3 changes: 1 addition & 2 deletions block/blkverify.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ static int blkverify_open(BlockDriverState *bs, QDict *options, int flags,
int ret;

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
Expand Down
3 changes: 1 addition & 2 deletions block/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat format,
bs->file->bs->supported_write_flags;

opts = qemu_opts_create(opts_spec, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
goto cleanup;
}
Expand Down
3 changes: 1 addition & 2 deletions block/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,

qemu_mutex_init(&s->mutex);
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
goto out_noclean;
}
Expand Down
6 changes: 2 additions & 4 deletions block/file-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,7 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
OnOffAuto locking;

opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
Expand Down Expand Up @@ -1000,8 +999,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,

/* Handle options changes */
opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, state->options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, state->options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto out;
Expand Down
6 changes: 2 additions & 4 deletions block/file-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
s->type = FTYPE_FILE;

opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
Expand Down Expand Up @@ -739,8 +738,7 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,

QemuOpts *opts = qemu_opts_create(&raw_runtime_opts, NULL, 0,
&error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto done;
Expand Down
15 changes: 5 additions & 10 deletions block/gluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,8 +523,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,

/* create opts info from runtime_json_opts list */
opts = qemu_opts_create(&runtime_json_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
goto out;
}

Expand Down Expand Up @@ -555,8 +554,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,

/* create opts info from runtime_type_opts list */
opts = qemu_opts_create(&runtime_type_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, backing_options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, backing_options, &local_err)) {
goto out;
}

Expand Down Expand Up @@ -586,8 +584,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
if (gsconf->type == SOCKET_ADDRESS_TYPE_INET) {
/* create opts info from runtime_inet_opts list */
opts = qemu_opts_create(&runtime_inet_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, backing_options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, backing_options, &local_err)) {
goto out;
}

Expand Down Expand Up @@ -635,8 +632,7 @@ static int qemu_gluster_parse_json(BlockdevOptionsGluster *gconf,
} else {
/* create opts info from runtime_unix_opts list */
opts = qemu_opts_create(&runtime_unix_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, backing_options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, backing_options, &local_err)) {
goto out;
}

Expand Down Expand Up @@ -819,8 +815,7 @@ static int qemu_gluster_open(BlockDriverState *bs, QDict *options,
const char *filename, *logfile;

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto out;
Expand Down
3 changes: 1 addition & 2 deletions block/iscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1792,8 +1792,7 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags,
int i, ret = 0, timeout = 0, lun;

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto out;
Expand Down
3 changes: 1 addition & 2 deletions block/nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1840,8 +1840,7 @@ static int nbd_process_options(BlockDriverState *bs, QDict *options,
int ret = -EINVAL;

opts = qemu_opts_create(&nbd_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
goto error;
}
Expand Down
3 changes: 1 addition & 2 deletions block/parallels.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,8 +829,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
goto fail_options;
}

qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err != NULL) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
goto fail_options;
}

Expand Down
3 changes: 1 addition & 2 deletions block/qcow2.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,8 +990,7 @@ static int qcow2_update_options_prepare(BlockDriverState *bs,
encryptfmt = qdict_get_try_str(encryptopts, "format");

opts = qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
Expand Down
3 changes: 1 addition & 2 deletions block/quorum.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,8 +922,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
}

opts = qemu_opts_create(&quorum_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
ret = -EINVAL;
goto exit;
}
Expand Down
3 changes: 1 addition & 2 deletions block/raw-format.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ static int raw_read_options(QDict *options, uint64_t *offset, bool *has_size,
int ret;

opts = qemu_opts_create(&raw_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto end;
Expand Down
3 changes: 1 addition & 2 deletions block/replication.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ static int replication_open(BlockDriverState *bs, QDict *options,

ret = -EINVAL;
opts = qemu_opts_create(&replication_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
goto fail;
}

Expand Down
3 changes: 1 addition & 2 deletions block/sheepdog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1556,8 +1556,7 @@ static int sd_open(BlockDriverState *bs, QDict *options, int flags,
s->aio_context = bdrv_get_aio_context(bs);

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto err_no_fd;
Expand Down
3 changes: 1 addition & 2 deletions block/ssh.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,7 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)

/* Translate legacy options */
opts = qemu_opts_create(&ssh_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
goto fail;
}
Expand Down
3 changes: 1 addition & 2 deletions block/throttle.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ static int throttle_parse_options(QDict *options, char **group, Error **errp)
Error *local_err = NULL;
QemuOpts *opts = qemu_opts_create(&throttle_opts, NULL, 0, &error_abort);

qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fin;
Expand Down
3 changes: 1 addition & 2 deletions block/vpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
}

opts = qemu_opts_create(&vpc_runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
Expand Down
3 changes: 1 addition & 2 deletions block/vvfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *options, int flags,
#endif

opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
error_propagate(errp, local_err);
ret = -EINVAL;
goto fail;
Expand Down
6 changes: 2 additions & 4 deletions block/vxhs.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
opts = qemu_opts_create(&runtime_opts, NULL, 0, &error_abort);
tcp_opts = qemu_opts_create(&runtime_tcp_opts, NULL, 0, &error_abort);

qemu_opts_absorb_qdict(opts, options, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(opts, options, &local_err)) {
ret = -EINVAL;
goto out;
}
Expand All @@ -346,8 +345,7 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
/* get the 'server.' arguments */
qdict_extract_subqdict(options, &backing_options, VXHS_OPT_SERVER".");

qemu_opts_absorb_qdict(tcp_opts, backing_options, &local_err);
if (local_err != NULL) {
if (!qemu_opts_absorb_qdict(tcp_opts, backing_options, &local_err)) {
ret = -EINVAL;
goto out;
}
Expand Down
11 changes: 4 additions & 7 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -509,8 +509,7 @@ static BlockBackend *blockdev_init(const char *file, QDict *bs_opts,
goto err_no_opts;
}

qemu_opts_absorb_qdict(opts, bs_opts, &error);
if (error) {
if (!qemu_opts_absorb_qdict(opts, bs_opts, &error)) {
error_propagate(errp, error);
goto early_err;
}
Expand Down Expand Up @@ -827,9 +826,8 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type,
};

for (i = 0; i < ARRAY_SIZE(opt_renames); i++) {
qemu_opt_rename(all_opts, opt_renames[i].from, opt_renames[i].to,
&local_err);
if (local_err) {
if (!qemu_opt_rename(all_opts, opt_renames[i].from,
opt_renames[i].to, &local_err)) {
error_propagate(errp, local_err);
return NULL;
}
Expand Down Expand Up @@ -867,8 +865,7 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfaceType block_default_type,

legacy_opts = qemu_opts_create(&qemu_legacy_drive_opts, NULL, 0,
&error_abort);
qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err);
if (local_err) {
if (!qemu_opts_absorb_qdict(legacy_opts, bs_opts, &local_err)) {
error_propagate(errp, local_err);
goto fail;
}
Expand Down
6 changes: 2 additions & 4 deletions chardev/char.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
qemu_opt_set(opts, "host", host, &error_abort);
qemu_opt_set(opts, "port", port, &error_abort);
if (p[pos] == ',') {
qemu_opts_do_parse(opts, p+pos+1, NULL, &local_err);
if (local_err) {
if (!qemu_opts_do_parse(opts, p + pos + 1, NULL, &local_err)) {
error_report_err(local_err);
goto fail;
}
Expand Down Expand Up @@ -484,8 +483,7 @@ QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename,
}
if (strstart(filename, "unix:", &p)) {
qemu_opt_set(opts, "backend", "socket", &error_abort);
qemu_opts_do_parse(opts, p, "path", &local_err);
if (local_err) {
if (!qemu_opts_do_parse(opts, p, "path", &local_err)) {
error_report_err(local_err);
goto fail;
}
Expand Down
4 changes: 2 additions & 2 deletions contrib/ivshmem-server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ ivshmem_server_parse_args(IvshmemServerArgs *args, int argc, char *argv[])
break;

case 'l': /* shm size */
parse_option_size("shm_size", optarg, &args->shm_size, &err);
if (err) {
if (!parse_option_size("shm_size", optarg, &args->shm_size,
&err)) {
error_report_err(err);
ivshmem_server_help(argv[0]);
exit(1);
Expand Down
Loading

0 comments on commit 235e59c

Please sign in to comment.