aboutsummaryrefslogtreecommitdiff
path: root/block/replication.c
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/replication.c
parent0c0e618d233e3249f6b60678a1b013a2c8d83339 (diff)
downloadqemu-dcfe480544eef72d666cb1695624449e2c22da2d.zip
qemu-dcfe480544eef72d666cb1695624449e2c22da2d.tar.gz
qemu-dcfe480544eef72d666cb1695624449e2c22da2d.tar.bz2
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/replication.c')
-rw-r--r--block/replication.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/block/replication.c b/block/replication.c
index 5701eeb..b844a09 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;
}