mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-06 17:23:56 -06:00
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>
This commit is contained in:
parent
0c0e618d23
commit
dcfe480544
24 changed files with 169 additions and 242 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue