From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, Hanna Reitz <hreitz@redhat.com>
Subject: [PULL 07/14] qemu-config: Make config_parse_qdict() return bool
Date: Wed, 14 Dec 2022 17:46:22 +0100 [thread overview]
Message-ID: <20221214164629.919880-8-armbru@redhat.com> (raw)
In-Reply-To: <20221214164629.919880-1-armbru@redhat.com>
This simplifies error checking.
Cc: Hanna Reitz <hreitz@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20221121085054.683122-7-armbru@redhat.com>
---
include/qemu/config-file.h | 2 +-
block/blkdebug.c | 4 +---
util/qemu-config.c | 39 ++++++++++++++++++--------------------
3 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/include/qemu/config-file.h b/include/qemu/config-file.h
index 321e7c7c03..b82a778123 100644
--- a/include/qemu/config-file.h
+++ b/include/qemu/config-file.h
@@ -22,7 +22,7 @@ int qemu_read_config_file(const char *filename, QEMUConfigCB *f, Error **errp);
/* Parse QDict options as a replacement for a config file (allowing multiple
enumerated (0..(n-1)) configuration "sections") */
-void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+bool qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
Error **errp);
#endif /* QEMU_CONFIG_FILE_H */
diff --git a/block/blkdebug.c b/block/blkdebug.c
index 4265ca125e..ca65b043f0 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -297,9 +297,7 @@ static int read_config(BDRVBlkdebugState *s, const char *filename,
}
}
- qemu_config_parse_qdict(options, config_groups, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
+ if (!qemu_config_parse_qdict(options, config_groups, errp)) {
ret = -EINVAL;
goto fail;
}
diff --git a/util/qemu-config.c b/util/qemu-config.c
index 433488aa56..e983607b46 100644
--- a/util/qemu-config.c
+++ b/util/qemu-config.c
@@ -423,12 +423,12 @@ int qemu_read_config_file(const char *filename, QEMUConfigCB *cb, Error **errp)
return ret;
}
-static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
+static bool config_parse_qdict_section(QDict *options, QemuOptsList *opts,
Error **errp)
{
QemuOpts *subopts;
- QDict *subqdict;
- QList *list = NULL;
+ g_autoptr(QDict) subqdict = NULL;
+ g_autoptr(QList) list = NULL;
size_t orig_size, enum_size;
char *prefix;
@@ -437,23 +437,23 @@ static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
g_free(prefix);
orig_size = qdict_size(subqdict);
if (!orig_size) {
- goto out;
+ return true;
}
subopts = qemu_opts_create(opts, NULL, 0, errp);
if (!subopts) {
- goto out;
+ return false;
}
if (!qemu_opts_absorb_qdict(subopts, subqdict, errp)) {
- goto out;
+ return false;
}
enum_size = qdict_size(subqdict);
if (enum_size < orig_size && enum_size) {
error_setg(errp, "Unknown option '%s' for [%s]",
qdict_first(subqdict)->key, opts->name);
- goto out;
+ return false;
}
if (enum_size) {
@@ -468,7 +468,7 @@ static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
if (qdict_size(subqdict)) {
error_setg(errp, "Unused option '%s' for [%s]",
qdict_first(subqdict)->key, opts->name);
- goto out;
+ return false;
}
QLIST_FOREACH_ENTRY(list, list_entry) {
@@ -478,46 +478,43 @@ static void config_parse_qdict_section(QDict *options, QemuOptsList *opts,
if (!section) {
error_setg(errp, "[%s] section (index %u) does not consist of "
"keys", opts->name, i);
- goto out;
+ return false;
}
opt_name = g_strdup_printf("%s.%u", opts->name, i++);
subopts = qemu_opts_create(opts, opt_name, 1, errp);
g_free(opt_name);
if (!subopts) {
- goto out;
+ return false;
}
if (!qemu_opts_absorb_qdict(subopts, section, errp)) {
qemu_opts_del(subopts);
- goto out;
+ return false;
}
if (qdict_size(section)) {
error_setg(errp, "[%s] section doesn't support the option '%s'",
opts->name, qdict_first(section)->key);
qemu_opts_del(subopts);
- goto out;
+ return false;
}
}
}
-out:
- qobject_unref(subqdict);
- qobject_unref(list);
+ return true;
}
-void qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
+bool qemu_config_parse_qdict(QDict *options, QemuOptsList **lists,
Error **errp)
{
int i;
- Error *local_err = NULL;
for (i = 0; lists[i]; i++) {
- config_parse_qdict_section(options, lists[i], &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
+ if (!config_parse_qdict_section(options, lists[i], errp)) {
+ return false;
}
}
+
+ return true;
}
--
2.37.3
next prev parent reply other threads:[~2022-12-14 16:47 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 16:46 [PULL 00/14] Miscellaneous patches for 2022-12-14 Markus Armbruster
2022-12-14 16:46 ` [PULL 01/14] Drop more useless casts from void * to pointer Markus Armbruster
2022-12-14 16:46 ` [PULL 02/14] error: Drop some obviously superfluous error_propagate() Markus Armbruster
2022-12-14 16:46 ` [PULL 03/14] error: Drop a few superfluous ERRP_GUARD() Markus Armbruster
2022-12-14 16:46 ` [PULL 04/14] error: Move ERRP_GUARD() to the beginning of the function Markus Armbruster
2022-12-14 16:46 ` [PULL 05/14] monitor: Simplify monitor_fd_param()'s error handling Markus Armbruster
2022-12-14 16:46 ` [PULL 06/14] monitor: Use ERRP_GUARD() in monitor_init() Markus Armbruster
2022-12-14 16:46 ` Markus Armbruster [this message]
2022-12-14 16:46 ` [PULL 08/14] qemu-config: Use ERRP_GUARD() where obviously appropriate Markus Armbruster
2022-12-14 16:46 ` [PULL 09/14] sockets: " Markus Armbruster
2022-12-14 16:46 ` [PULL 10/14] qapi: Use returned bool to check for failure (again) Markus Armbruster
2022-12-14 16:46 ` [PULL 11/14] io: Tidy up fat-fingered parameter name Markus Armbruster
2022-12-14 16:46 ` [PULL 12/14] cleanup: Tweak and re-run return_directly.cocci Markus Armbruster
2022-12-14 16:46 ` [PULL 13/14] block/vmdk: Simplify vmdk_co_create() to return directly Markus Armbruster
2022-12-14 16:46 ` [PULL 14/14] ppc4xx_sdram: Simplify sdram_ddr_size() to return Markus Armbruster
2022-12-15 13:06 ` [PULL 00/14] Miscellaneous patches for 2022-12-14 Peter Maydell
2022-12-15 13:10 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221214164629.919880-8-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=hreitz@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).