With the removal of the support for short-form flags, the only other
source of "noise" in the qemu_parse_*noisily() functions aside from
errors is the printing of the help text.
Therefore, the only difference from the _noisily versions to the
normal ones is this block:
if (qemu_opt_has_help_opt(opts) && !opts_accepts_any(list)) {
qemu_opts_print_help(list, true);
return NULL;
}
Stop calling qemu_parse_*noisily() in any case where it's certain that
opts_accepts_any(list) returns true, i.e. when list->desc is empty.
This creates some instances of the pattern: error_report ->
exit(1). Use &error_fatal instead.
Signed-off-by: Fabiano Rosas <[email protected]>
---
block/monitor/block-hmp-cmds.c | 4 ++--
include/system/tpm.h | 3 ++-
monitor/hmp.c | 4 +++-
net/net.c | 4 +---
plugins/loader.c | 5 +---
qemu-img.c | 5 +++-
qemu-io-cmds.c | 2 +-
qemu-io.c | 7 ++----
system/tpm.c | 8 +++----
system/vl.c | 42 +++++++++++++++-------------------
tests/unit/test-replication.c | 17 +++++++++++---
util/qemu-option.c | 3 +++
12 files changed, 55 insertions(+), 49 deletions(-)
diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c
index d94a07314f..93b622227c 100644
--- a/block/monitor/block-hmp-cmds.c
+++ b/block/monitor/block-hmp-cmds.c
@@ -63,9 +63,9 @@ static void hmp_drive_add_node(MonitorHMP *hmp, const char
*optstr)
QDict *qdict;
Error *err = NULL;
- opts = qemu_opts_parse_list_noisily(&qemu_drive_opts, optstr, false);
+ opts = qemu_opts_parse_list(&qemu_drive_opts, optstr, false, &err);
if (!opts) {
- return;
+ goto out;
}
qdict = qemu_opts_to_qdict(opts, NULL);
diff --git a/include/system/tpm.h b/include/system/tpm.h
index 874068d19a..4132a3a641 100644
--- a/include/system/tpm.h
+++ b/include/system/tpm.h
@@ -17,7 +17,8 @@
#ifdef CONFIG_TPM
-int tpm_config_parse(QemuOptsList *opts_list, const char *optstr);
+bool tpm_config_parse(QemuOptsList *opts_list, const char *optstr,
+ Error **errp);
int tpm_init(void);
void tpm_cleanup(void);
diff --git a/monitor/hmp.c b/monitor/hmp.c
index fc32cfd1ff..6a6be8f12f 100644
--- a/monitor/hmp.c
+++ b/monitor/hmp.c
@@ -883,6 +883,7 @@ static QDict *monitor_parse_arguments(MonitorHMP *mon,
{
QemuOptsList *opts_list;
QemuOpts *opts;
+ Error *err = NULL;
opts_list = qemu_find_opts(key);
if (!opts_list || opts_list->desc->name) {
@@ -897,8 +898,9 @@ static QDict *monitor_parse_arguments(MonitorHMP *mon,
if (get_str(buf, sizeof(buf), &p) < 0) {
goto fail;
}
- opts = qemu_opts_parse_list_noisily(opts_list, buf, true);
+ opts = qemu_opts_parse_list(opts_list, buf, true, &err);
if (!opts) {
+ error_report_err(err);
goto fail;
}
qemu_opts_to_qdict(opts, qdict);
diff --git a/net/net.c b/net/net.c
index 37401ab2b4..09ed34557d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -2029,9 +2029,7 @@ void netdev_parse_modern(const char *optstr)
void net_client_parse(QemuOptsList *opts_list, const char *optstr)
{
- if (!qemu_opts_parse_list_noisily(opts_list, optstr, true)) {
- exit(1);
- }
+ qemu_opts_parse_list(opts_list, optstr, true, &error_fatal);
}
/* From FreeBSD */
diff --git a/plugins/loader.c b/plugins/loader.c
index 1808679c82..db6ae6d1f4 100644
--- a/plugins/loader.c
+++ b/plugins/loader.c
@@ -147,10 +147,7 @@ void qemu_plugin_opt_parse(const char *optstr,
QemuPluginList *head)
struct qemu_plugin_parse_arg arg;
QemuOpts *opts;
- opts = qemu_opts_parse_noisily("plugin", optstr, true);
- if (opts == NULL) {
- exit(1);
- }
+ opts = qemu_opts_parse("plugin", optstr, true, &error_fatal);
arg.head = head;
arg.curr = NULL;
qemu_opt_foreach(opts, plugin_add, &arg, &error_fatal);
diff --git a/qemu-img.c b/qemu-img.c
index 5e58ccc587..18501f7fb9 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -354,12 +354,15 @@ static BlockBackend *img_open(bool image_opts,
BlockBackend *blk;
if (image_opts) {
QemuOpts *opts;
+ Error *err = NULL;
+
if (fmt) {
error_report("--image-opts and --format are mutually exclusive");
return NULL;
}
- opts = qemu_opts_parse_noisily("source", filename, true);
+ opts = qemu_opts_parse("source", filename, true, &err);
if (!opts) {
+ error_report_err(err);
return NULL;
}
blk = img_open_opts(filename, opts, flags, writethrough, quiet,
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 6c8c4c9540..fa52fbb900 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -2540,7 +2540,7 @@ static int reopen_f(BlockBackend *blk, int argc, char
**argv, Error **errp)
has_cache_option = true;
break;
case 'o':
- if (!qemu_opts_parse_list_noisily(&reopen_opts, optarg, 0)) {
+ if (!qemu_opts_parse_list(&reopen_opts, optarg, 0, errp)) {
qemu_opts_reset(&reopen_opts);
return -EINVAL;
}
diff --git a/qemu-io.c b/qemu-io.c
index db0ee499e4..837e5048ba 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -659,11 +659,8 @@ int main(int argc, char **argv)
if ((argc - optind) == 1) {
if (imageOpts) {
QemuOpts *qopts = NULL;
- qopts = qemu_opts_parse_list_noisily(&file_opts, argv[optind],
- false);
- if (!qopts) {
- exit(1);
- }
+ qopts = qemu_opts_parse_list(&file_opts, argv[optind], false,
+ &error_fatal);
opts = qemu_opts_to_qdict(qopts, NULL);
if (openfile(NULL, flags, writethrough, force_share, opts)) {
exit(1);
diff --git a/system/tpm.c b/system/tpm.c
index f0f5a64d9a..31aeaa5cc6 100644
--- a/system/tpm.c
+++ b/system/tpm.c
@@ -176,7 +176,7 @@ int tpm_init(void)
* Parse the TPM configuration options.
* To display all available TPM backends the user may use '-tpmdev help'
*/
-int tpm_config_parse(QemuOptsList *opts_list, const char *optstr)
+bool tpm_config_parse(QemuOptsList *opts_list, const char *optstr, Error
**errp)
{
QemuOpts *opts;
@@ -184,11 +184,11 @@ int tpm_config_parse(QemuOptsList *opts_list, const char
*optstr)
tpm_display_backend_drivers();
exit(EXIT_SUCCESS);
}
- opts = qemu_opts_parse_list_noisily(opts_list, optstr, true);
+ opts = qemu_opts_parse_list(opts_list, optstr, true, errp);
if (!opts) {
- return -1;
+ return false;
}
- return 0;
+ return true;
}
/*
diff --git a/system/vl.c b/system/vl.c
index 4a3fa80c5c..8382bb902b 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -1871,11 +1871,7 @@ static void object_option_parse(const char *str)
v = qobject_input_visitor_new(obj);
qobject_unref(obj);
} else {
- opts = qemu_opts_parse_noisily("object", str, true);
- if (!opts) {
- exit(1);
- }
-
+ opts = qemu_opts_parse("object", str, true, &error_fatal);
type = qemu_opt_get(opts, "qom-type");
if (!type) {
error_report(QERR_MISSING_PARAMETER, "qom-type");
@@ -2483,12 +2479,15 @@ static void configure_accelerators(const char *progname)
accel_list = g_strsplit(accelerators, ":", 0);
for (tmp = accel_list; *tmp; tmp++) {
+ Error *err = NULL;
/*
* Filter invalid accelerators here, to prevent obscenities
* such as "-machine accel=tcg,,thread=single".
*/
if (accel_find(*tmp)) {
- qemu_opts_parse_noisily("accel", *tmp, true);
+ if (!qemu_opts_parse("accel", *tmp, true, &err)) {
+ error_report_err(err);
+ }
} else {
init_failed = true;
error_report("invalid accelerator %s", *tmp);
@@ -3013,9 +3012,7 @@ void qemu_init(int argc, char **argv)
replay_add_blocker("-snapshot");
break;
case QEMU_OPTION_numa:
- if (!qemu_opts_parse_noisily("numa", optarg, true)) {
- exit(1);
- }
+ qemu_opts_parse("numa", optarg, true, &error_fatal);
break;
case QEMU_OPTION_display:
parse_display(optarg);
@@ -3131,9 +3128,7 @@ void qemu_init(int argc, char **argv)
break;
#ifdef CONFIG_TPM
case QEMU_OPTION_tpmdev:
- if (tpm_config_parse(qemu_find_opts("tpmdev"), optarg) < 0) {
- exit(1);
- }
+ tpm_config_parse(qemu_find_opts("tpmdev"), optarg,
&error_fatal);
break;
#endif
case QEMU_OPTION_mempath:
@@ -3396,17 +3391,11 @@ void qemu_init(int argc, char **argv)
object_register_sugar_prop("ide-device", "win2k-install-hack",
"true", true);
break;
case QEMU_OPTION_acpitable:
- opts = qemu_opts_parse_noisily("acpi", optarg, true);
- if (!opts) {
- exit(1);
- }
+ opts = qemu_opts_parse("acpi", optarg, true, &error_fatal);
acpi_table_add(opts, &error_fatal);
break;
case QEMU_OPTION_smbios:
- opts = qemu_opts_parse_noisily("smbios", optarg, false);
- if (!opts) {
- exit(1);
- }
+ opts = qemu_opts_parse("smbios", optarg, false, &error_fatal);
smbios_entry_add(opts, &error_fatal);
break;
case QEMU_OPTION_fwcfg:
@@ -3433,7 +3422,13 @@ void qemu_init(int argc, char **argv)
break;
}
case QEMU_OPTION_accel:
- accel_opts = qemu_opts_parse_noisily("accel", optarg, true);
+ {
+ Error *err = NULL;
+
+ accel_opts = qemu_opts_parse("accel", optarg, true, &err);
+ if (!accel_opts) {
+ error_report_err(err);
+ }
optarg = qemu_opt_get(accel_opts, "accel");
if (!optarg || is_help_option(optarg)) {
printf("Accelerators supported in QEMU binary:\n");
@@ -3459,6 +3454,7 @@ void qemu_init(int argc, char **argv)
exit(0);
}
break;
+ }
case QEMU_OPTION_usb:
qdict_put_str(machine_opts_dict, "usb", "on");
break;
@@ -3475,9 +3471,7 @@ void qemu_init(int argc, char **argv)
assert(opt->opts != NULL);
QTAILQ_INSERT_TAIL(&device_opts, opt, next);
} else {
- if (!qemu_opts_parse_noisily("device", optarg, true)) {
- exit(1);
- }
+ qemu_opts_parse("device", optarg, true, &error_fatal);
}
break;
case QEMU_OPTION_smp:
diff --git a/tests/unit/test-replication.c b/tests/unit/test-replication.c
index 101f72acdc..dbed415f87 100644
--- a/tests/unit/test-replication.c
+++ b/tests/unit/test-replication.c
@@ -174,12 +174,16 @@ static BlockBackend *start_primary(void)
QemuOpts *opts;
QDict *qdict;
char *cmdline;
+ Error *err = NULL;
cmdline = g_strdup_printf("driver=replication,mode=primary,node-name=xxx,"
"file.driver=qcow2,file.file.filename=%s,"
"file.file.locking=off"
, p_local_disk);
- opts = qemu_opts_parse_list_noisily(&qemu_drive_opts, cmdline, false);
+ opts = qemu_opts_parse_list(&qemu_drive_opts, cmdline, false, &err);
+ if (!opts) {
+ error_report_err(err);
+ }
g_free(cmdline);
qdict = qemu_opts_to_qdict(opts, NULL);
@@ -290,12 +294,16 @@ static BlockBackend *start_secondary(void)
QDict *qdict;
BlockBackend *blk;
char *cmdline;
+ Error *err = NULL;
/* add s_local_disk and forge S_LOCAL_DISK_ID */
cmdline = g_strdup_printf("file.filename=%s,driver=qcow2,"
"file.locking=off",
s_local_disk);
- opts = qemu_opts_parse_list_noisily(&qemu_drive_opts, cmdline, false);
+ opts = qemu_opts_parse_list(&qemu_drive_opts, cmdline, false, &err);
+ if (!opts) {
+ error_report_err(err);
+ }
g_free(cmdline);
qdict = qemu_opts_to_qdict(opts, NULL);
@@ -321,7 +329,10 @@ static BlockBackend *start_secondary(void)
"file.backing.backing=%s"
, S_ID, s_active_disk, s_hidden_disk
, S_LOCAL_DISK_ID);
- opts = qemu_opts_parse_list_noisily(&qemu_drive_opts, cmdline, false);
+ opts = qemu_opts_parse_list(&qemu_drive_opts, cmdline, false, &err);
+ if (!opts) {
+ error_report_err(err);
+ }
g_free(cmdline);
qdict = qemu_opts_to_qdict(opts, NULL);
diff --git a/util/qemu-option.c b/util/qemu-option.c
index 83fa2399d3..833c69f6a5 100644
--- a/util/qemu-option.c
+++ b/util/qemu-option.c
@@ -995,6 +995,9 @@ QemuOpts *qemu_opts_parse_list_noisily(QemuOptsList *list,
const char *params,
Error *err = NULL;
QemuOpts *opts;
+ assert(g_str_equal("drive", list->name) ||
+ !opts_accepts_any(list));
+
opts = opts_parse(list, params, permit_abbrev, &err);
if (!opts) {
error_report_err(err);
--
2.53.0