summaryrefslogtreecommitdiffstats
path: root/qemu-img.c
diff options
context:
space:
mode:
authorMarkus Armbruster2020-07-07 18:05:42 +0200
committerMarkus Armbruster2020-07-10 15:17:35 +0200
commit235e59cf03ed75d0ce96c97343194ed11c146231 (patch)
treec2de9b6a66355d038fe4ccb4d79de13905101b52 /qemu-img.c
parentqemu-option: Make functions taking Error ** return bool, not void (diff)
downloadqemu-235e59cf03ed75d0ce96c97343194ed11c146231.tar.gz
qemu-235e59cf03ed75d0ce96c97343194ed11c146231.tar.xz
qemu-235e59cf03ed75d0ce96c97343194ed11c146231.zip
qemu-option: Use returned bool to check for failure
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 0b6786a9c1 "block/amend: refactor qcow2 amend options" resolved by rerunning Coccinelle on master's version]
Diffstat (limited to 'qemu-img.c')
-rw-r--r--qemu-img.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/qemu-img.c b/qemu-img.c
index 53bd32bf8f..41d2b91091 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -468,8 +468,8 @@ static int add_old_style_options(const char *fmt, QemuOpts *opts,
Error *err = NULL;
if (base_filename) {
- qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename, &err);
- if (err) {
+ if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FILE, base_filename,
+ &err)) {
error_report("Backing file not supported for file format '%s'",
fmt);
error_free(err);
@@ -477,8 +477,7 @@ static int add_old_style_options(const char *fmt, QemuOpts *opts,
}
}
if (base_fmt) {
- qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err);
- if (err) {
+ if (!qemu_opt_set(opts, BLOCK_OPT_BACKING_FMT, base_fmt, &err)) {
error_report("Backing file format not supported for file "
"format '%s'", fmt);
error_free(err);
@@ -2487,8 +2486,7 @@ static int img_convert(int argc, char **argv)
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
if (options) {
- qemu_opts_do_parse(opts, options, NULL, &local_err);
- if (local_err) {
+ if (!qemu_opts_do_parse(opts, options, NULL, &local_err)) {
error_report_err(local_err);
ret = -1;
goto out;
@@ -3963,8 +3961,7 @@ static int img_resize(int argc, char **argv)
/* Parse size */
param = qemu_opts_create(&resize_options, NULL, 0, &error_abort);
- qemu_opt_set(param, BLOCK_OPT_SIZE, size, &err);
- if (err) {
+ if (!qemu_opt_set(param, BLOCK_OPT_SIZE, size, &err)) {
error_report_err(err);
ret = -1;
qemu_opts_del(param);
@@ -4215,9 +4212,7 @@ static int img_amend(int argc, char **argv)
amend_opts = qemu_opts_append(amend_opts, bs->drv->amend_opts);
opts = qemu_opts_create(amend_opts, NULL, 0, &error_abort);
- qemu_opts_do_parse(opts, options, NULL, &err);
-
- if (err) {
+ if (!qemu_opts_do_parse(opts, options, NULL, &err)) {
/* Try to parse options using the create options */
Error *err1 = NULL;
amend_opts = qemu_opts_append(amend_opts, bs->drv->create_opts);
@@ -5363,8 +5358,7 @@ static int img_measure(int argc, char **argv)
create_opts = qemu_opts_append(create_opts, bdrv_file.create_opts);
opts = qemu_opts_create(create_opts, NULL, 0, &error_abort);
if (options) {
- qemu_opts_do_parse(opts, options, NULL, &local_err);
- if (local_err) {
+ if (!qemu_opts_do_parse(opts, options, NULL, &local_err)) {
error_report_err(local_err);
error_report("Invalid options for file format '%s'", out_fmt);
goto out;