char: error out if given unhandled size options

This is a small help, because in fact all combined chardev
options are accepted by qemu_chardev_opts[]. But given that a user may
legitimately want to use the size options with a VC backend, we can
report an error when we know the backend doesn't support it.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau
2026-04-23 15:20:53 +04:00
parent f031490790
commit 4cb2250c58
5 changed files with 28 additions and 0 deletions

View File

@@ -639,6 +639,18 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)
return NULL;
}
if (!cc->supports_size_opts) {
const char * const invalid_opts[] = {
"width", "height", "cols", "rows", NULL
};
if (qemu_opt_has_any(opts, invalid_opts)) {
error_setg(errp, "chardev '%s' does not support size options",
qemu_opts_id(opts));
return NULL;
}
}
backend = g_new0(ChardevBackend, 1);
backend->type = CHARDEV_BACKEND_KIND_NULL;

View File

@@ -254,6 +254,7 @@ struct ChardevClass {
bool internal; /* TODO: eventually use TYPE_USER_CREATABLE */
bool supports_yank;
bool supports_size_opts;
/* parse command line options and populate QAPI @backend */
void (*chr_parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);

View File

@@ -73,6 +73,7 @@ struct QemuOptsList {
const char *qemu_opt_get(QemuOpts *opts, const char *name);
char *qemu_opt_get_del(QemuOpts *opts, const char *name);
bool qemu_opt_has_any(QemuOpts *opts, const char * const *names);
/**
* qemu_opt_has_help_opt:
* @opts: options to search for a help request

View File

@@ -1251,6 +1251,7 @@ static void char_vc_class_init(ObjectClass *oc, const void *data)
cc->chr_write = vc_chr_write;
cc->chr_accept_input = vc_chr_accept_input;
cc->chr_set_echo = vc_chr_set_echo;
cc->supports_size_opts = true;
}
static const TypeInfo char_vc_type_info = {

View File

@@ -271,6 +271,19 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
return opt->str;
}
bool qemu_opt_has_any(QemuOpts *opts, const char * const *names)
{
int it;
for (it = 0; names[it]; it++) {
if (qemu_opt_get(opts, names[it])) {
return true;
}
}
return false;
}
void qemu_opt_iter_init(QemuOptsIter *iter, QemuOpts *opts, const char *name)
{
iter->opts = opts;