qapi: Smooth another visitor error checking pattern

Convert

    visit_type_FOO(v, ..., &ptr, &err);
    ...
    if (err) {
        ...
    }

to

    visit_type_FOO(v, ..., &ptr, errp);
    ...
    if (!ptr) {
        ...
    }

for functions that set @ptr to non-null / null on success / error.

Eliminate error_propagate() that are now unnecessary.  Delete @err
that are now unused.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200707160613.848843-40-armbru@redhat.com>
This commit is contained in:
Markus Armbruster 2020-07-07 18:06:07 +02:00
parent 4bc6d7ee0e
commit b11a093c60
15 changed files with 36 additions and 79 deletions

View File

@ -563,18 +563,15 @@ static BlockdevOptionsNfs *nfs_options_qdict_to_qapi(QDict *options,
BlockdevOptionsNfs *opts = NULL; BlockdevOptionsNfs *opts = NULL;
Visitor *v; Visitor *v;
const QDictEntry *e; const QDictEntry *e;
Error *local_err = NULL;
v = qobject_input_visitor_new_flat_confused(options, errp); v = qobject_input_visitor_new_flat_confused(options, errp);
if (!v) { if (!v) {
return NULL; return NULL;
} }
visit_type_BlockdevOptionsNfs(v, NULL, &opts, &local_err); visit_type_BlockdevOptionsNfs(v, NULL, &opts, errp);
visit_free(v); visit_free(v);
if (!opts) {
if (local_err) {
error_propagate(errp, local_err);
return NULL; return NULL;
} }

View File

@ -625,7 +625,6 @@ static int coroutine_fn parallels_co_create_opts(BlockDriver *drv,
Error **errp) Error **errp)
{ {
BlockdevCreateOptions *create_options = NULL; BlockdevCreateOptions *create_options = NULL;
Error *local_err = NULL;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
QDict *qdict; QDict *qdict;
Visitor *v; Visitor *v;
@ -668,11 +667,9 @@ static int coroutine_fn parallels_co_create_opts(BlockDriver *drv,
goto done; goto done;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto done; goto done;
} }

View File

@ -943,7 +943,6 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
QDict *qdict; QDict *qdict;
Visitor *v; Visitor *v;
const char *val; const char *val;
Error *local_err = NULL;
int ret; int ret;
static const QDictRenames opt_renames[] = { static const QDictRenames opt_renames[] = {
@ -995,11 +994,9 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver *drv,
goto fail; goto fail;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }

View File

@ -3685,7 +3685,6 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
Visitor *v; Visitor *v;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
BlockDriverState *data_bs = NULL; BlockDriverState *data_bs = NULL;
Error *local_err = NULL;
const char *val; const char *val;
int ret; int ret;
@ -3781,11 +3780,9 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,
goto finish; goto finish;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto finish; goto finish;
} }

View File

@ -729,7 +729,6 @@ static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv,
QDict *qdict; QDict *qdict;
Visitor *v; Visitor *v;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
Error *local_err = NULL;
int ret; int ret;
static const QDictRenames opt_renames[] = { static const QDictRenames opt_renames[] = {
@ -771,11 +770,9 @@ static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv,
goto fail; goto fail;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }

View File

@ -681,7 +681,6 @@ static int qemu_rbd_convert_options(QDict *options, BlockdevOptionsRbd **opts,
Error **errp) Error **errp)
{ {
Visitor *v; Visitor *v;
Error *local_err = NULL;
/* Convert the remaining options into a QAPI object */ /* Convert the remaining options into a QAPI object */
v = qobject_input_visitor_new_flat_confused(options, errp); v = qobject_input_visitor_new_flat_confused(options, errp);
@ -689,11 +688,9 @@ static int qemu_rbd_convert_options(QDict *options, BlockdevOptionsRbd **opts,
return -EINVAL; return -EINVAL;
} }
visit_type_BlockdevOptionsRbd(v, NULL, opts, &local_err); visit_type_BlockdevOptionsRbd(v, NULL, opts, errp);
visit_free(v); visit_free(v);
if (!opts) {
if (local_err) {
error_propagate(errp, local_err);
return -EINVAL; return -EINVAL;
} }

View File

@ -2193,11 +2193,9 @@ static int coroutine_fn sd_co_create_opts(BlockDriver *drv,
goto fail; goto fail;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }

View File

@ -616,7 +616,6 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
{ {
BlockdevOptionsSsh *result = NULL; BlockdevOptionsSsh *result = NULL;
QemuOpts *opts = NULL; QemuOpts *opts = NULL;
Error *local_err = NULL;
const QDictEntry *e; const QDictEntry *e;
Visitor *v; Visitor *v;
@ -636,11 +635,9 @@ static BlockdevOptionsSsh *ssh_parse_options(QDict *options, Error **errp)
goto fail; goto fail;
} }
visit_type_BlockdevOptionsSsh(v, NULL, &result, &local_err); visit_type_BlockdevOptionsSsh(v, NULL, &result, errp);
visit_free(v); visit_free(v);
if (!result) {
if (local_err) {
error_propagate(errp, local_err);
goto fail; goto fail;
} }

View File

@ -906,7 +906,6 @@ static int coroutine_fn vdi_co_create_opts(BlockDriver *drv,
uint64_t block_size = DEFAULT_CLUSTER_SIZE; uint64_t block_size = DEFAULT_CLUSTER_SIZE;
bool is_static = false; bool is_static = false;
Visitor *v; Visitor *v;
Error *local_err = NULL;
int ret; int ret;
/* Parse options and convert legacy syntax. /* Parse options and convert legacy syntax.
@ -957,11 +956,9 @@ static int coroutine_fn vdi_co_create_opts(BlockDriver *drv,
ret = -EINVAL; ret = -EINVAL;
goto done; goto done;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto done; goto done;
} }

View File

@ -2064,7 +2064,6 @@ static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv,
QDict *qdict; QDict *qdict;
Visitor *v; Visitor *v;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
Error *local_err = NULL;
int ret; int ret;
static const QDictRenames opt_renames[] = { static const QDictRenames opt_renames[] = {
@ -2105,11 +2104,9 @@ static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv,
goto fail; goto fail;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }

View File

@ -1095,7 +1095,6 @@ static int coroutine_fn vpc_co_create_opts(BlockDriver *drv,
QDict *qdict; QDict *qdict;
Visitor *v; Visitor *v;
BlockDriverState *bs = NULL; BlockDriverState *bs = NULL;
Error *local_err = NULL;
int ret; int ret;
static const QDictRenames opt_renames[] = { static const QDictRenames opt_renames[] = {
@ -1134,11 +1133,9 @@ static int coroutine_fn vpc_co_create_opts(BlockDriver *drv,
goto fail; goto fail;
} }
visit_type_BlockdevCreateOptions(v, NULL, &create_options, &local_err); visit_type_BlockdevCreateOptions(v, NULL, &create_options, errp);
visit_free(v); visit_free(v);
if (!create_options) {
if (local_err) {
error_propagate(errp, local_err);
ret = -EINVAL; ret = -EINVAL;
goto fail; goto fail;
} }

View File

@ -239,7 +239,6 @@ static void acpi_table_install(const char unsigned *blob, size_t bloblen,
void acpi_table_add(const QemuOpts *opts, Error **errp) void acpi_table_add(const QemuOpts *opts, Error **errp)
{ {
AcpiTableOptions *hdrs = NULL; AcpiTableOptions *hdrs = NULL;
Error *err = NULL;
char **pathnames = NULL; char **pathnames = NULL;
char **cur; char **cur;
size_t bloblen = 0; size_t bloblen = 0;
@ -249,11 +248,11 @@ void acpi_table_add(const QemuOpts *opts, Error **errp)
Visitor *v; Visitor *v;
v = opts_visitor_new(opts); v = opts_visitor_new(opts);
visit_type_AcpiTableOptions(v, NULL, &hdrs, &err); visit_type_AcpiTableOptions(v, NULL, &hdrs, errp);
visit_free(v); visit_free(v);
} }
if (err) { if (!hdrs) {
goto out; goto out;
} }
if (hdrs->has_file == hdrs->has_data) { if (hdrs->has_file == hdrs->has_data) {

View File

@ -682,11 +682,9 @@ static char *xen_block_blockdev_add(const char *id, QDict *qdict,
trace_xen_block_blockdev_add(node_name); trace_xen_block_blockdev_add(node_name);
v = qobject_input_visitor_new(QOBJECT(qdict)); v = qobject_input_visitor_new(QOBJECT(qdict));
visit_type_BlockdevOptions(v, NULL, &options, &local_err); visit_type_BlockdevOptions(v, NULL, &options, errp);
visit_free(v); visit_free(v);
if (!options) {
if (local_err) {
error_propagate(errp, local_err);
goto fail; goto fail;
} }

View File

@ -516,10 +516,10 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
Error *err = NULL; Error *err = NULL;
Visitor *v = opts_visitor_new(opts); Visitor *v = opts_visitor_new(opts);
visit_type_NumaOptions(v, NULL, &object, &err); visit_type_NumaOptions(v, NULL, &object, errp);
visit_free(v); visit_free(v);
if (err) { if (!object) {
goto end; return -1;
} }
/* Fix up legacy suffix-less format */ /* Fix up legacy suffix-less format */
@ -530,7 +530,6 @@ static int parse_numa(void *opaque, QemuOpts *opts, Error **errp)
set_numa_options(ms, object, &err); set_numa_options(ms, object, &err);
end:
qapi_free_NumaOptions(object); qapi_free_NumaOptions(object);
if (err) { if (err) {
error_propagate(errp, err); error_propagate(errp, err);

View File

@ -657,25 +657,18 @@ int monitor_init_opts(QemuOpts *opts, Error **errp)
{ {
Visitor *v; Visitor *v;
MonitorOptions *options; MonitorOptions *options;
Error *local_err = NULL; int ret;
v = opts_visitor_new(opts); v = opts_visitor_new(opts);
visit_type_MonitorOptions(v, NULL, &options, &local_err); visit_type_MonitorOptions(v, NULL, &options, errp);
visit_free(v); visit_free(v);
if (!options) {
if (local_err) {
goto out;
}
monitor_init(options, true, &local_err);
qapi_free_MonitorOptions(options);
out:
if (local_err) {
error_propagate(errp, local_err);
return -1; return -1;
} }
return 0;
ret = monitor_init(options, true, errp);
qapi_free_MonitorOptions(options);
return ret;
} }
QemuOptsList qemu_mon_opts = { QemuOptsList qemu_mon_opts = {