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>
Marc-André Lureau committed
Apr 23, 2026 at 15:20 UTC
4cb2250c583ad8a020a3ff40f5bda3a5c44381d4
5 files changed
+28
chardev/char.c
+12
@@ -639,6 +639,18 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)
639
return NULL;
640
}
641
642
+ if (!cc->supports_size_opts) {
643
+ const char * const invalid_opts[] = {
644
+ "width", "height", "cols", "rows", NULL
645
+ };
646
+
647
+ if (qemu_opt_has_any(opts, invalid_opts)) {
648
+ error_setg(errp, "chardev '%s' does not support size options",
649
+ qemu_opts_id(opts));
650
+ return NULL;
651
+ }
652
+ }
653
+
654
backend = g_new0(ChardevBackend, 1);
655
backend->type = CHARDEV_BACKEND_KIND_NULL;
656
include/chardev/char.h
+1
@@ -254,6 +254,7 @@ struct ChardevClass {
254
255
bool internal; /* TODO: eventually use TYPE_USER_CREATABLE */
256
bool supports_yank;
257
+ bool supports_size_opts;
258
259
/* parse command line options and populate QAPI @backend */
260
void (*chr_parse)(QemuOpts *opts, ChardevBackend *backend, Error **errp);
include/qemu/option.h
+1
@@ -73,6 +73,7 @@ struct QemuOptsList {
73
74
const char *qemu_opt_get(QemuOpts *opts, const char *name);
75
char *qemu_opt_get_del(QemuOpts *opts, const char *name);
76
+bool qemu_opt_has_any(QemuOpts *opts, const char * const *names);
77
/**
78
* qemu_opt_has_help_opt:
79
* @opts: options to search for a help request
ui/console-vc.c
+1
@@ -1251,6 +1251,7 @@ static void char_vc_class_init(ObjectClass *oc, const void *data)
1251
cc->chr_write = vc_chr_write;
1252
cc->chr_accept_input = vc_chr_accept_input;
1253
cc->chr_set_echo = vc_chr_set_echo;
1254
+ cc->supports_size_opts = true;
1255
}
1256
1257
static const TypeInfo char_vc_type_info = {
util/qemu-option.c
+13
@@ -271,6 +271,19 @@ const char *qemu_opt_get(QemuOpts *opts, const char *name)
271
return opt->str;
272
}
273
274
+bool qemu_opt_has_any(QemuOpts *opts, const char * const *names)
275
+{
276
+ int it;
277
+
278
+ for (it = 0; names[it]; it++) {
279
+ if (qemu_opt_get(opts, names[it])) {
280
+ return true;
281
+ }
282
+ }
283
+ return false;
284
+}
285
+
286
+
287
void qemu_opt_iter_init(QemuOptsIter *iter, QemuOpts *opts, const char *name)
288
{
289
iter->opts = opts;