From: "Marc-André Lureau" <mlureau@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
qemu-devel@nongnu.org, pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH 06/20] char: use a static array for backends
Date: Fri, 6 Jan 2017 18:22:34 -0500 (EST) [thread overview]
Message-ID: <1003433157.3653645.1483744954232.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <7367a62e-09b4-3c48-1812-5c2586e0f4ac@redhat.com>
Hi
----- Original Message -----
> On 01/05/2017 10:53 AM, Marc-André Lureau wrote:
> > Number and kinds of backends is known at compile-time, use a fixed-sized
> > static array to simplify iterations & lookups. Add an alias field to the
> > CharDriver structure to cover the cases where we previously registered a
> > driver twice under two names.
>
> Except that 5/20 didn't register twice under two names, so my option 2
> on that patch was floating that portion of this patch earlier.
>
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > include/sysemu/char.h | 1 +
> > qemu-char.c | 98
> > ++++++++++++++++++++++++++++++---------------------
> > 2 files changed, 59 insertions(+), 40 deletions(-)
> >
> > @@ -4134,17 +4139,20 @@ CharDriverState *qemu_chr_new_from_opts(QemuOpts
> > *opts,
> > goto err;
> > }
> >
> > - for (i = backends; i; i = i->next) {
> > - cd = i->data;
> > + cd = NULL;
>
> Dead assignment, since backends is a non-empty array so it will always
> be overwritten by the first iteration of the following loop.
ok, it feels more correct. I'll move it at declaration instead if you don't mind.
>
> > + for (i = 0; i < ARRAY_SIZE(backends); i++) {
> > + cd = backends[i];
> >
> > - if (strcmp(ChardevBackendKind_lookup[cd->kind],
> > - qemu_opt_get(opts, "backend")) == 0) {
> > + if (!cd) {
> > + continue;
> > + }
> > + if (g_str_equal(ChardevBackendKind_lookup[cd->kind], name) ||
> > + (g_strcmp0(cd->alias, name) == 0)) {
> > break;
> > }
> > }
> > - if (i == NULL) {
> > - error_setg(errp, "chardev: backend \"%s\" not found",
> > - qemu_opt_get(opts, "backend"));
> > + if (cd == NULL || i >= ARRAY_SIZE(backends)) {
>
> Simplify: 'if (i == ARRAY_SIZE(backends))' (whether cd is NULL at the
> end of the loop is irrelevant, you know it is non-NULL if you broke
> early on a match, but it is ALSO non-null if the last element of the
> array was non-NULL; and right now, our last element of the array is the
> 'memory' alias which is unconditionally present and thus non-NULL; also,
> i cannot grow greater than ARRAY_SIZE(), so == suffices rather than >=).
ok
>
> > ChardevBackendInfoList *qmp_query_chardev_backends(Error **errp)
> > {
> > ChardevBackendInfoList *backend_list = NULL;
> > - CharDriver *c = NULL;
> > - GSList *i = NULL;
> > + const CharDriver *c;
> > + int i;
> >
> > - for (i = backends; i; i = i->next) {
> > - ChardevBackendInfoList *info = g_malloc0(sizeof(*info));
> > - c = i->data;
> > - info->value = g_malloc0(sizeof(*info->value));
> > - info->value->name = g_strdup(ChardevBackendKind_lookup[c->kind]);
> > + for (i = 0; i < ARRAY_SIZE(backends); i++) {
> > + c = backends[i];
> > + if (!c) {
> > + continue;
> > + }
> >
> > - info->next = backend_list;
> > - backend_list = info;
> > + backend_list = qmp_prepend_backend(backend_list, c,
> > +
> > ChardevBackendKind_lookup[c->kind]);
> > + if (c->alias) {
> > + backend_list = qmp_prepend_backend(backend_list, c, c->alias);
> > + }
>
> Hmm, I didn't account for this in the changes I suggested for option 2
> of 5/20 (which means unless you further tweak it, I temporarily
> regressed the command to omit the aliases - but then again, taking your
> 5/20 as-is without either of my options omits the aliases and lists the
> canonical name twice).
fixed in patch 5
>
> > @@ -4827,22 +4849,16 @@ ChardevReturn *qmp_chardev_add(const char *id,
> > ChardevBackend *backend,
> > goto out_error;
> > }
> >
> > - for (i = backends; i; i = i->next) {
> > - cd = i->data;
> > -
> > - if (cd->kind == backend->type) {
> > - chr = cd->create(id, backend, ret, &be_opened, &local_err);
> > - if (local_err) {
> > - error_propagate(errp, local_err);
> > - goto out_error;
> > - }
> > - break;
> > - }
> > + cd = (int)backend->type >= 0 && backend->type < ARRAY_SIZE(backends) ?
> > + backends[backend->type] : NULL;
> > + if (cd == NULL) {
> > + error_setg(errp, "chardev backend not available");
>
> Worth including %s and the user-provided name that failed lookup?
It's improved with qom-ify patch
>
> > @@ -4927,6 +4943,7 @@ static void register_types(void)
> > #if defined HAVE_CHARDEV_SERIAL
> > {
> > .kind = CHARDEV_BACKEND_KIND_SERIAL,
> > + .alias = "tty",
> > .parse = qemu_chr_parse_serial,
> > .create = qmp_chardev_open_serial,
> > },
>
> Unless you get rid of the duplicates (both my option 1 and option 2 of
> 5/20 did so), then you are registering 'serial/tty' once, and
> 'serial/NULL' a second time, where the second registration overwrites
> the first, and so the alias doesn't work.
bad patch split :)
>
> > @@ -4939,6 +4956,7 @@ static void register_types(void)
> > #ifdef HAVE_CHARDEV_PARPORT
> > {
> > .kind = CHARDEV_BACKEND_KIND_PARALLEL,
> > + .alias = "parport",
> > .parse = qemu_chr_parse_parallel,
> > .create = qmp_chardev_open_parallel,
> > },
>
> And again.
thanks
next prev parent reply other threads:[~2017-01-06 23:22 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-05 16:53 [Qemu-devel] [PATCH 00/20] chardev: qom-ify Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 01/20] tests: fix linking test-char on win32 Marc-André Lureau
2017-01-06 16:45 ` Eric Blake
2017-01-06 19:50 ` Marc-André Lureau
2017-01-06 20:26 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 02/20] qemu-options: stdio is available " Marc-André Lureau
2017-01-06 16:51 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 03/20] char: add qemu_chr_fe_add_watch() Returns description Marc-André Lureau
2017-01-06 16:54 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 04/20] doc: fix spelling Marc-André Lureau
2017-01-06 16:55 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 05/20] char: use a const CharDriver Marc-André Lureau
2017-01-06 18:01 ` Eric Blake
2017-01-06 22:43 ` Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 06/20] char: use a static array for backends Marc-André Lureau
2017-01-06 19:24 ` Eric Blake
2017-01-06 23:22 ` Marc-André Lureau [this message]
2017-01-05 16:53 ` [Qemu-devel] [PATCH 07/20] char: move callbacks in CharDriver Marc-André Lureau
2017-01-06 21:36 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 08/20] char: fold single-user functions in caller Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 09/20] char: introduce generic qemu_chr_get_kind() Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 10/20] char: use a feature bit for replay Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 11/20] char: allocate CharDriverState as a single object Marc-André Lureau
2017-01-06 21:43 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 12/20] bt: use qemu_chr_alloc() Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 13/20] char: rename CharDriverState Chardev Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 14/20] char: rename TCPChardev and NetChardev Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 15/20] spice-char: improve error reporting Marc-André Lureau
2017-01-06 22:22 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 16/20] char: use error_report() Marc-André Lureau
2017-01-05 16:53 ` [Qemu-devel] [PATCH 17/20] gtk: overwrite the console.c char driver Marc-André Lureau
2017-01-06 22:24 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 18/20] baum: use a common prefix for chr callbacks Marc-André Lureau
2017-01-06 22:25 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 19/20] vc: " Marc-André Lureau
2017-01-06 22:26 ` Eric Blake
2017-01-05 16:53 ` [Qemu-devel] [PATCH 20/20] chardev: qom-ify Marc-André Lureau
2017-01-09 18:02 ` Eric Blake
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=1003433157.3653645.1483744954232.JavaMail.zimbra@redhat.com \
--to=mlureau@redhat.com \
--cc=eblake@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--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).