aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2020-07-07 18:06:01 +0200
committerMarkus Armbruster <armbru@redhat.com>2020-07-10 15:18:08 +0200
commitdcfe480544eef72d666cb1695624449e2c22da2d (patch)
treeaaa611acd223064dd8ebc278d0998c2e3d29c080 /block
parent0c0e618d233e3249f6b60678a1b013a2c8d83339 (diff)
error: Avoid unnecessary error_propagate() after error_setg()
Replace error_setg(&err, ...); error_propagate(errp, err); by error_setg(errp, ...); Related pattern: if (...) { error_setg(&err, ...); goto out; } ... out: error_propagate(errp, err); return; When all paths to label out are that way, replace by if (...) { error_setg(errp, ...); return; } and delete the label along with the error_propagate(). When we have at most one other path that actually needs to propagate, and maybe one at the end that where propagation is unnecessary, e.g. foo(..., &err); if (err) { goto out; } ... bar(..., &err); out: error_propagate(errp, err); return; move the error_propagate() to where it's needed, like if (...) { foo(..., &err); error_propagate(errp, err); return; } ... bar(..., errp); return; and transform the error_setg() as above. In some places, the transformation results in obviously unnecessary error_propagate(). The next few commits will eliminate them. Bonus: the elimination of gotos will make later patches in this series easier to review. Candidates for conversion tracked down with this Coccinelle script: @@ identifier err, errp; expression list args; @@ - error_setg(&err, args); + error_setg(errp, args); ... when != err error_propagate(errp, err); Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <20200707160613.848843-34-armbru@redhat.com>
Diffstat (limited to 'block')
-rw-r--r--block/quorum.c16
-rw-r--r--block/replication.c11
-rw-r--r--block/throttle-groups.c22
-rw-r--r--block/vxhs.c9
4 files changed, 25 insertions, 33 deletions
diff --git a/block/quorum.c b/block/quorum.c
index beb3b6dbcc..5d52e605db 100644
--- a/block/quorum.c
+++ b/block/quorum.c
@@ -910,13 +910,12 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
/* count how many different children are present */
s->num_children = qdict_array_entries(options, "children.");
if (s->num_children < 0) {
- error_setg(&local_err, "Option children is not a valid array");
+ error_setg(errp, "Option children is not a valid array");
ret = -EINVAL;
goto exit;
}
if (s->num_children < 1) {
- error_setg(&local_err,
- "Number of provided children must be 1 or more");
+ error_setg(errp, "Number of provided children must be 1 or more");
ret = -EINVAL;
goto exit;
}
@@ -929,7 +928,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
s->threshold = qemu_opt_get_number(opts, QUORUM_OPT_VOTE_THRESHOLD, 0);
/* and validate it against s->num_children */
- ret = quorum_valid_threshold(s->threshold, s->num_children, &local_err);
+ ret = quorum_valid_threshold(s->threshold, s->num_children, errp);
if (ret < 0) {
goto exit;
}
@@ -942,7 +941,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
-EINVAL, NULL);
}
if (ret < 0) {
- error_setg(&local_err, "Please set read-pattern as fifo or quorum");
+ error_setg(errp, "Please set read-pattern as fifo or quorum");
goto exit;
}
s->read_pattern = ret;
@@ -950,7 +949,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
if (s->read_pattern == QUORUM_READ_PATTERN_QUORUM) {
s->is_blkverify = qemu_opt_get_bool(opts, QUORUM_OPT_BLKVERIFY, false);
if (s->is_blkverify && (s->num_children != 2 || s->threshold != 2)) {
- error_setg(&local_err, "blkverify=on can only be set if there are "
+ error_setg(errp, "blkverify=on can only be set if there are "
"exactly two files and vote-threshold is 2");
ret = -EINVAL;
goto exit;
@@ -959,7 +958,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
s->rewrite_corrupted = qemu_opt_get_bool(opts, QUORUM_OPT_REWRITE,
false);
if (s->rewrite_corrupted && s->is_blkverify) {
- error_setg(&local_err,
+ error_setg(errp,
"rewrite-corrupted=on cannot be used with blkverify=on");
ret = -EINVAL;
goto exit;
@@ -979,6 +978,7 @@ static int quorum_open(BlockDriverState *bs, QDict *options, int flags,
&child_of_bds, BDRV_CHILD_DATA, false,
&local_err);
if (local_err) {
+ error_propagate(errp, local_err);
ret = -EINVAL;
goto close_exit;
}
@@ -1004,8 +1004,6 @@ close_exit:
g_free(opened);
exit:
qemu_opts_del(opts);
- /* propagate error */
- error_propagate(errp, local_err);
return ret;
}
diff --git a/block/replication.c b/block/replication.c
index 5701eeb9e8..b844a09eb1 100644
--- a/block/replication.c
+++ b/block/replication.c
@@ -105,7 +105,7 @@ static int replication_open(BlockDriverState *bs, QDict *options,
mode = qemu_opt_get(opts, REPLICATION_MODE);
if (!mode) {
- error_setg(&local_err, "Missing the option mode");
+ error_setg(errp, "Missing the option mode");
goto fail;
}
@@ -113,7 +113,8 @@ static int replication_open(BlockDriverState *bs, QDict *options,
s->mode = REPLICATION_MODE_PRIMARY;
top_id = qemu_opt_get(opts, REPLICATION_TOP_ID);
if (top_id) {
- error_setg(&local_err, "The primary side does not support option top-id");
+ error_setg(errp,
+ "The primary side does not support option top-id");
goto fail;
}
} else if (!strcmp(mode, "secondary")) {
@@ -121,11 +122,11 @@ static int replication_open(BlockDriverState *bs, QDict *options,
top_id = qemu_opt_get(opts, REPLICATION_TOP_ID);
s->top_id = g_strdup(top_id);
if (!s->top_id) {
- error_setg(&local_err, "Missing the option top-id");
+ error_setg(errp, "Missing the option top-id");
goto fail;
}
} else {
- error_setg(&local_err,
+ error_setg(errp,
"The option mode's value should be primary or secondary");
goto fail;
}
@@ -136,8 +137,6 @@ static int replication_open(BlockDriverState *bs, QDict *options,
fail:
qemu_opts_del(opts);
- error_propagate(errp, local_err);
-
return ret;
}
diff --git a/block/throttle-groups.c b/block/throttle-groups.c
index e411051160..3d7e7cf990 100644
--- a/block/throttle-groups.c
+++ b/block/throttle-groups.c
@@ -819,16 +819,17 @@ static void throttle_group_set(Object *obj, Visitor *v, const char * name,
* transaction, as certain combinations are invalid.
*/
if (tg->is_initialized) {
- error_setg(&local_err, "Property cannot be set after initialization");
- goto ret;
+ error_setg(errp, "Property cannot be set after initialization");
+ return;
}
if (!visit_type_int64(v, name, &value, &local_err)) {
- goto ret;
+ error_propagate(errp, local_err);
+ return;
}
if (value < 0) {
- error_setg(&local_err, "Property values cannot be negative");
- goto ret;
+ error_setg(errp, "Property values cannot be negative");
+ return;
}
cfg = &tg->ts.cfg;
@@ -841,9 +842,9 @@ static void throttle_group_set(Object *obj, Visitor *v, const char * name,
break;
case BURST_LENGTH:
if (value > UINT_MAX) {
- error_setg(&local_err, "%s value must be in the"
- "range [0, %u]", info->name, UINT_MAX);
- goto ret;
+ error_setg(errp, "%s value must be in the" "range [0, %u]",
+ info->name, UINT_MAX);
+ return;
}
cfg->buckets[info->type].burst_length = value;
break;
@@ -851,11 +852,6 @@ static void throttle_group_set(Object *obj, Visitor *v, const char * name,
cfg->op_size = value;
break;
}
-
-ret:
- error_propagate(errp, local_err);
- return;
-
}
static void throttle_group_get(Object *obj, Visitor *v, const char *name,
diff --git a/block/vxhs.c b/block/vxhs.c
index 237df4f185..fecaeb82c9 100644
--- a/block/vxhs.c
+++ b/block/vxhs.c
@@ -326,14 +326,14 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
/* vdisk-id is the disk UUID */
vdisk_id_opt = qemu_opt_get(opts, VXHS_OPT_VDISK_ID);
if (!vdisk_id_opt) {
- error_setg(&local_err, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID);
+ error_setg(errp, QERR_MISSING_PARAMETER, VXHS_OPT_VDISK_ID);
ret = -EINVAL;
goto out;
}
/* vdisk-id may contain a leading '/' */
if (strlen(vdisk_id_opt) > UUID_FMT_LEN + 1) {
- error_setg(&local_err, "vdisk-id cannot be more than %d characters",
+ error_setg(errp, "vdisk-id cannot be more than %d characters",
UUID_FMT_LEN);
ret = -EINVAL;
goto out;
@@ -352,14 +352,14 @@ static int vxhs_open(BlockDriverState *bs, QDict *options,
server_host_opt = qemu_opt_get(tcp_opts, VXHS_OPT_HOST);
if (!server_host_opt) {
- error_setg(&local_err, QERR_MISSING_PARAMETER,
+ error_setg(errp, QERR_MISSING_PARAMETER,
VXHS_OPT_SERVER"."VXHS_OPT_HOST);
ret = -EINVAL;
goto out;
}
if (strlen(server_host_opt) > MAXHOSTNAMELEN) {
- error_setg(&local_err, "server.host cannot be more than %d characters",
+ error_setg(errp, "server.host cannot be more than %d characters",
MAXHOSTNAMELEN);
ret = -EINVAL;
goto out;
@@ -412,7 +412,6 @@ out:
if (ret < 0) {
vxhs_unref();
- error_propagate(errp, local_err);
g_free(s->vdisk_hostinfo.host);
g_free(s->vdisk_guid);
g_free(s->tlscredsid);