qemu-option: remove now-dead code

-M was the sole user of qemu_opts_set and qemu_opts_set_defaults,
remove them and the arguments that they used.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2020-11-11 09:03:37 -05:00
parent fe68090e8f
commit 904806c69b
3 changed files with 10 additions and 79 deletions

View File

@ -119,7 +119,6 @@ QemuOpts *qemu_opts_create(QemuOptsList *list, const char *id,
int fail_if_exists, Error **errp); int fail_if_exists, Error **errp);
void qemu_opts_reset(QemuOptsList *list); void qemu_opts_reset(QemuOptsList *list);
void qemu_opts_loc_restore(QemuOpts *opts); void qemu_opts_loc_restore(QemuOpts *opts);
bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value, Error **errp);
const char *qemu_opts_id(QemuOpts *opts); const char *qemu_opts_id(QemuOpts *opts);
void qemu_opts_set_id(QemuOpts *opts, char *id); void qemu_opts_set_id(QemuOpts *opts, char *id);
void qemu_opts_del(QemuOpts *opts); void qemu_opts_del(QemuOpts *opts);
@ -130,8 +129,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,
bool permit_abbrev); bool permit_abbrev);
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
bool permit_abbrev, Error **errp); bool permit_abbrev, Error **errp);
void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
int permit_abbrev);
QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict, QemuOpts *qemu_opts_from_qdict(QemuOptsList *list, const QDict *qdict,
Error **errp); Error **errp);
QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict, QDict *qemu_opts_to_qdict_filtered(QemuOpts *opts, QDict *qdict,

View File

@ -410,40 +410,6 @@ static void test_qemu_opts_reset(void)
g_assert(opts == NULL); g_assert(opts == NULL);
} }
static void test_qemu_opts_set(void)
{
QemuOptsList *list;
QemuOpts *opts;
const char *opt;
list = qemu_find_opts("opts_list_04");
g_assert(list != NULL);
g_assert(QTAILQ_EMPTY(&list->head));
g_assert_cmpstr(list->name, ==, "opts_list_04");
/* should not find anything at this point */
opts = qemu_opts_find(list, NULL);
g_assert(opts == NULL);
/* implicitly create opts and set str3 value */
qemu_opts_set(list, "str3", "value", &error_abort);
g_assert(!QTAILQ_EMPTY(&list->head));
/* get the just created opts */
opts = qemu_opts_find(list, NULL);
g_assert(opts != NULL);
/* check the str3 value */
opt = qemu_opt_get(opts, "str3");
g_assert_cmpstr(opt, ==, "value");
qemu_opts_del(opts);
/* should not find anything at this point */
opts = qemu_opts_find(list, NULL);
g_assert(opts == NULL);
}
static int opts_count_iter(void *opaque, const char *name, const char *value, static int opts_count_iter(void *opaque, const char *name, const char *value,
Error **errp) Error **errp)
{ {
@ -1041,7 +1007,6 @@ int main(int argc, char *argv[])
g_test_add_func("/qemu-opts/opt_get_size", test_qemu_opt_get_size); g_test_add_func("/qemu-opts/opt_get_size", test_qemu_opt_get_size);
g_test_add_func("/qemu-opts/opt_unset", test_qemu_opt_unset); g_test_add_func("/qemu-opts/opt_unset", test_qemu_opt_unset);
g_test_add_func("/qemu-opts/opts_reset", test_qemu_opts_reset); g_test_add_func("/qemu-opts/opts_reset", test_qemu_opts_reset);
g_test_add_func("/qemu-opts/opts_set", test_qemu_opts_set);
g_test_add_func("/qemu-opts/opts_parse/general", test_opts_parse); g_test_add_func("/qemu-opts/opts_parse/general", test_opts_parse);
g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool); g_test_add_func("/qemu-opts/opts_parse/bool", test_opts_parse_bool);
g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number); g_test_add_func("/qemu-opts/opts_parse/number", test_opts_parse_number);

View File

@ -479,19 +479,14 @@ int qemu_opt_unset(QemuOpts *opts, const char *name)
} }
} }
static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value, static QemuOpt *opt_create(QemuOpts *opts, const char *name, char *value)
bool prepend)
{ {
QemuOpt *opt = g_malloc0(sizeof(*opt)); QemuOpt *opt = g_malloc0(sizeof(*opt));
opt->name = g_strdup(name); opt->name = g_strdup(name);
opt->str = value; opt->str = value;
opt->opts = opts; opt->opts = opts;
if (prepend) {
QTAILQ_INSERT_HEAD(&opts->head, opt, next);
} else {
QTAILQ_INSERT_TAIL(&opts->head, opt, next); QTAILQ_INSERT_TAIL(&opts->head, opt, next);
}
return opt; return opt;
} }
@ -518,7 +513,7 @@ static bool opt_validate(QemuOpt *opt, Error **errp)
bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value, bool qemu_opt_set(QemuOpts *opts, const char *name, const char *value,
Error **errp) Error **errp)
{ {
QemuOpt *opt = opt_create(opts, name, g_strdup(value), false); QemuOpt *opt = opt_create(opts, name, g_strdup(value));
if (!opt_validate(opt, errp)) { if (!opt_validate(opt, errp)) {
qemu_opt_del(opt); qemu_opt_del(opt);
@ -662,15 +657,6 @@ void qemu_opts_loc_restore(QemuOpts *opts)
loc_restore(&opts->loc); loc_restore(&opts->loc);
} }
bool qemu_opts_set(QemuOptsList *list, const char *name, const char *value, Error **errp)
{
QemuOpts *opts;
assert(list->merge_lists);
opts = qemu_opts_create(list, NULL, 0, &error_abort);
return qemu_opt_set(opts, name, value, errp);
}
const char *qemu_opts_id(QemuOpts *opts) const char *qemu_opts_id(QemuOpts *opts)
{ {
return opts->id; return opts->id;
@ -811,7 +797,7 @@ static const char *get_opt_name_value(const char *params,
} }
static bool opts_do_parse(QemuOpts *opts, const char *params, static bool opts_do_parse(QemuOpts *opts, const char *params,
const char *firstname, bool prepend, const char *firstname,
bool warn_on_flag, bool *help_wanted, Error **errp) bool warn_on_flag, bool *help_wanted, Error **errp)
{ {
char *option, *value; char *option, *value;
@ -833,7 +819,7 @@ static bool opts_do_parse(QemuOpts *opts, const char *params,
continue; continue;
} }
opt = opt_create(opts, option, value, prepend); opt = opt_create(opts, option, value);
g_free(option); g_free(option);
if (!opt_validate(opt, errp)) { if (!opt_validate(opt, errp)) {
qemu_opt_del(opt); qemu_opt_del(opt);
@ -889,11 +875,11 @@ bool has_help_option(const char *params)
bool qemu_opts_do_parse(QemuOpts *opts, const char *params, bool qemu_opts_do_parse(QemuOpts *opts, const char *params,
const char *firstname, Error **errp) const char *firstname, Error **errp)
{ {
return opts_do_parse(opts, params, firstname, false, false, NULL, errp); return opts_do_parse(opts, params, firstname, false, NULL, errp);
} }
static QemuOpts *opts_parse(QemuOptsList *list, const char *params, static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
bool permit_abbrev, bool defaults, bool permit_abbrev,
bool warn_on_flag, bool *help_wanted, Error **errp) bool warn_on_flag, bool *help_wanted, Error **errp)
{ {
const char *firstname; const char *firstname;
@ -903,21 +889,13 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
assert(!permit_abbrev || list->implied_opt_name); assert(!permit_abbrev || list->implied_opt_name);
firstname = permit_abbrev ? list->implied_opt_name : NULL; firstname = permit_abbrev ? list->implied_opt_name : NULL;
/*
* This code doesn't work for defaults && !list->merge_lists: when
* params has no id=, and list has an element with !opts->id, it
* appends a new element instead of returning the existing opts.
* However, we got no use for this case. Guard against possible
* (if unlikely) future misuse:
*/
assert(!defaults || list->merge_lists);
opts = qemu_opts_create(list, id, !list->merge_lists, errp); opts = qemu_opts_create(list, id, !list->merge_lists, errp);
g_free(id); g_free(id);
if (opts == NULL) { if (opts == NULL) {
return NULL; return NULL;
} }
if (!opts_do_parse(opts, params, firstname, defaults, if (!opts_do_parse(opts, params, firstname,
warn_on_flag, help_wanted, errp)) { warn_on_flag, help_wanted, errp)) {
qemu_opts_del(opts); qemu_opts_del(opts);
return NULL; return NULL;
@ -936,7 +914,7 @@ static QemuOpts *opts_parse(QemuOptsList *list, const char *params,
QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params, QemuOpts *qemu_opts_parse(QemuOptsList *list, const char *params,
bool permit_abbrev, Error **errp) bool permit_abbrev, Error **errp)
{ {
return opts_parse(list, params, permit_abbrev, false, false, NULL, errp); return opts_parse(list, params, permit_abbrev, false, NULL, errp);
} }
/** /**
@ -954,7 +932,7 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,
QemuOpts *opts; QemuOpts *opts;
bool help_wanted = false; bool help_wanted = false;
opts = opts_parse(list, params, permit_abbrev, false, true, opts = opts_parse(list, params, permit_abbrev, true,
opts_accepts_any(list) ? NULL : &help_wanted, opts_accepts_any(list) ? NULL : &help_wanted,
&err); &err);
if (!opts) { if (!opts) {
@ -968,15 +946,6 @@ QemuOpts *qemu_opts_parse_noisily(QemuOptsList *list, const char *params,
return opts; return opts;
} }
void qemu_opts_set_defaults(QemuOptsList *list, const char *params,
int permit_abbrev)
{
QemuOpts *opts;
opts = opts_parse(list, params, permit_abbrev, true, false, NULL, NULL);
assert(opts);
}
static bool qemu_opts_from_qdict_entry(QemuOpts *opts, static bool qemu_opts_from_qdict_entry(QemuOpts *opts,
const QDictEntry *entry, const QDictEntry *entry,
Error **errp) Error **errp)