From cccb7967bdf19f9d31e65d2d07d4d311e07545c4 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 16:37:44 +0100 Subject: QemuOpts: Convert qemu_opt_set_bool() to Error, fix its use Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/qemu/option.h b/include/qemu/option.h index 58c0157ed5..320687494a 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -97,7 +97,8 @@ int qemu_opt_unset(QemuOpts *opts, const char *name); int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, Error **errp); -int qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val); +void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, + Error **errp); int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val); typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, -- cgit v1.2.3 From 39101f2511f6adf1ae4380f8d729dba1213b9d7a Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 16:46:36 +0100 Subject: QemuOpts: Convert qemu_opt_set_number() to Error, fix its use Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/qemu/option.h b/include/qemu/option.h index 320687494a..7422cc2aaa 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -99,7 +99,8 @@ void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, Error **errp); void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, Error **errp); -int qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val); +void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, + Error **errp); typedef int (*qemu_opt_loopfunc)(const char *name, const char *value, void *opaque); int qemu_opt_foreach(QemuOpts *opts, qemu_opt_loopfunc func, void *opaque, int abort_on_failure); -- cgit v1.2.3 From 79087c782e1549a6f9c8303aafc0b74f4e637756 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 17:07:34 +0100 Subject: QemuOpts: Convert qemu_opts_set() to Error, fix its use Return the Error object instead of reporting it with qerror_report_err(). Change callers that assume the function can't fail to pass &error_abort, so that should the assumption ever break, it'll break noisily. Turns out all callers outside its unit test assume that. We could drop the Error ** argument, but that would make the interface less regular, so don't. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/qemu/option.h b/include/qemu/option.h index 7422cc2aaa..7d6addc174 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -110,8 +110,8 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id, int fail_if_exists, Error **errp); void qemu_opts_reset(QemuOptsList *list); void qemu_opts_loc_restore(QemuOpts *opts); -int qemu_opts_set(QemuOptsList *list, const char *id, - const char *name, const char *value); +void qemu_opts_set(QemuOptsList *list, const char *id, + const char *name, const char *value, Error **errp); const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); -- cgit v1.2.3 From f43e47dbf6de24db20ec9b588bb6cc762093dd69 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 17:52:20 +0100 Subject: QemuOpts: Drop qemu_opt_set(), rename qemu_opt_set_err(), fix use qemu_opt_set() is a wrapper around qemu_opt_set() that reports the error with qerror_report_err(). Most of its users assume the function can't fail. Make them use qemu_opt_set_err() with &error_abort, so that should the assumption ever break, it'll break noisily. Just two users remain, in util/qemu-config.c. Switch them to qemu_opt_set_err() as well, then rename qemu_opt_set_err() to qemu_opt_set(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/qemu/option.h b/include/qemu/option.h index 7d6addc174..a41ee92508 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -94,9 +94,8 @@ uint64_t qemu_opt_get_number_del(QemuOpts *opts, const char *name, uint64_t qemu_opt_get_size_del(QemuOpts *opts, const char *name, uint64_t defval); int qemu_opt_unset(QemuOpts *opts, const char *name); -int qemu_opt_set(QemuOpts *opts, const char *name, const char *value); -void qemu_opt_set_err(QemuOpts *opts, const char *name, const char *value, - Error **errp); +void qemu_opt_set(QemuOpts *opts, const char *name, const char *value, + Error **errp); void qemu_opt_set_bool(QemuOpts *opts, const char *name, bool val, Error **errp); void qemu_opt_set_number(QemuOpts *opts, const char *name, int64_t val, -- cgit v1.2.3 From dc523cd348c47372faa7271c9aab2030f94c290d Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Feb 2015 18:37:11 +0100 Subject: qemu-img: Suppress unhelpful extra errors in convert, amend img_convert() and img_amend() use qemu_opts_do_parse(), which reports errors with qerror_report_err(). Its error messages aren't helpful here, the caller reports one that actually makes sense. Reproducer: $ qemu-img convert -o backing_format=raw in.img out.img qemu-img: Invalid parameter 'backing_format' qemu-img: Invalid options for file format 'raw' To fix, propagate errors through qemu_opts_do_parse(). This lifts the error reporting into callers. Drop it from img_convert() and img_amend(), keep it in qemu_chr_parse_compat(), bdrv_img_create(). Since I'm touching qemu_opts_do_parse() anyway, write a function comment for it. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- include/qemu/option.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/qemu/option.h b/include/qemu/option.h index a41ee92508..f88b545dfc 100644 --- a/include/qemu/option.h +++ b/include/qemu/option.h @@ -115,7 +115,8 @@ const char *qemu_opts_id(QemuOpts *opts); void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_del(QemuOpts *opts); void qemu_opts_validate(QemuOpts *opts, const QemuOptDesc *desc, Error **errp); -int qemu_opts_do_parse(QemuOpts *opts, const char *params, const char *firstname); +void qemu_opts_do_parse(QemuOpts *opts, const char *params, + const char *firstname, Error **errp); QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, int permit_abbrev); void qemu_opts_set_defaults(QemuOptsList *list, const char *params, int permit_abbrev); -- cgit v1.2.3