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 04/54] char: move callbacks in CharDriver
Date: Mon, 2 Jan 2017 10:33:39 -0500 (EST) [thread overview]
Message-ID: <305153287.20363.1483371219240.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <aeb7472e-69f4-b73e-7db2-bf88559b3116@redhat.com>
hi
----- Original Message -----
> On 12/12/2016 04:42 PM, Marc-André Lureau wrote:
> > This makes the code more declarative, and avoids to duplicate the
>
> s/to duplicate/duplicating/
ok
>
> > information on all instances.
> >
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> > backends/baum.c | 13 +-
> > backends/msmouse.c | 13 +-
> > backends/testdev.c | 10 +-
> > gdbstub.c | 7 +-
> > hw/bt/hci-csr.c | 8 +-
> > qemu-char.c | 427
> > +++++++++++++++++++++++++++++++-------------------
> > spice-qemu-char.c | 36 +++--
> > ui/console.c | 26 +--
> > ui/gtk.c | 11 +-
> > include/sysemu/char.h | 46 +++---
>
> Again, seeing the .h changes first makes a huge difference on code
> review. I'm manually reformatting:
>
> > 10 files changed, 370 insertions(+), 227 deletions(-)
>
> > diff --git a/include/sysemu/char.h b/include/sysemu/char.h
> > index c8750ede21..09e40ef9b8 100644
> > --- a/include/sysemu/char.h
> > +++ b/include/sysemu/char.h
> > @@ -85,24 +85,11 @@ typedef struct CharBackend {
> > int fe_open;
> > } CharBackend;
> >
> > +typedef struct CharDriver CharDriver;
> > +
> > struct CharDriverState {
> > + const CharDriver *driver;
> > QemuMutex chr_write_lock;
> > - int (*chr_write)(struct CharDriverState *s, const uint8_t *buf,
> int len);
>
> So all the callbacks are moved into the CharDriver struct...
>
> > @@ -125,7 +112,8 @@ struct CharDriverState {
> > *
> > * Returns: a newly allocated CharDriverState, or NULL on error.
> > */
> > -CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp);
> > +CharDriverState *qemu_chr_alloc(const CharDriver *driver,
> > + ChardevCommon *backend, Error **errp);
>
> ...and all the entry points are now passed that struct as a new parameter.
>
> >
> > /**
> > * @qemu_chr_new_from_opts:
> > @@ -473,15 +461,33 @@ void qemu_chr_set_feature(CharDriverState *chr,
> > CharDriverFeature feature);
> > QemuOpts *qemu_chr_parse_compat(const char *label, const char *filename);
> >
> > -typedef struct CharDriver {
> > +struct CharDriver {
>
> ...the struct already existed, but is now more useful.
>
> Looks worthwhile. I suspect the rest of the patch is mechanical.
>
> > @@ -688,7 +686,10 @@ static void register_types(void)
> > {
> > static const CharDriver driver = {
> > .kind = CHARDEV_BACKEND_KIND_BRAILLE,
> > - .parse = NULL, .create = chr_baum_init
> > + .parse = NULL, .create = chr_baum_init,
>
> And now you see why I asked for trailing commas in 2/54 :)
>
> > + .chr_write = baum_write,
> > + .chr_accept_input = baum_accept_input,
> > + .chr_free = baum_free,
> > };
> >
>
> > +++ b/gdbstub.c
> > @@ -1730,6 +1730,10 @@ int gdbserver_start(const char *device)
> > CharDriverState *chr = NULL;
> > CharDriverState *mon_chr;
> > ChardevCommon common = { 0 };
> > + static const CharDriver driver = {
> > + .kind = -1,
> > + .chr_write = gdb_monitor_write
>
> Trailing comma.
>
> Interesting that this is a new use of CharDriver with an out-of-range
> .kind. But I think your code in 3/54 was careful to explicitly handle a
> .kind that does not map to one of the public types, so that you are able
> to use this as an internal-only driver.
and kind is removed is later patches "char: remove class kind field"
>
>
> >
> > +static const CharDriver null_driver = {
> > + .kind = CHARDEV_BACKEND_KIND_NULL, .create = qemu_chr_open_null,
>
> One initializer per line is fine.
>
> > + .chr_write = null_chr_write
> > +};
> > +
>
> >
> > @@ -864,14 +880,6 @@ static CharDriverState *qemu_chr_open_mux(const char
> > *id,
> >
> > chr->opaque = d;
> > d->focus = -1;
> > - chr->chr_free = mux_chr_free;
> > - chr->chr_write = mux_chr_write;
> > - chr->chr_accept_input = mux_chr_accept_input;
> > - /* Frontend guest-open / -close notification is not support with muxes
> > */
> > - chr->chr_set_fe_open = NULL;
> > - if (drv->chr_add_watch) {
> > - chr->chr_add_watch = mux_chr_add_watch;
> > - }
>
> Here, the callback was only conditionally registered...
>
> > +static const CharDriver mux_driver = {
> > + .kind = CHARDEV_BACKEND_KIND_MUX,
> > + .parse = qemu_chr_parse_mux, .create = qemu_chr_open_mux,
> > + .chr_free = mux_chr_free,
> > + .chr_write = mux_chr_write,
> > + .chr_accept_input = mux_chr_accept_input,
> > + .chr_add_watch = mux_chr_add_watch,
> > +};
>
> ...but here, it is always registered. Is that an unintentional semantic
> change?
>
mux_chr_add_watch() also checks if the underlying driver has chr_add_watch(). qemu_chr_fe_add_watch() returns 0 in both cases then.
>
> > +#ifdef HAVE_CHARDEV_SERIAL
> > +static const CharDriver serial_driver = {
> > + .alias = "tty", .kind = CHARDEV_BACKEND_KIND_SERIAL,
> > + .parse = qemu_chr_parse_serial, .create = qmp_chardev_open_serial,
> > +#ifdef _WIN32
> > + .chr_write = win_chr_write,
> > + .chr_free = win_chr_free,
> > +#else
> > + .chr_add_watch = fd_chr_add_watch,
> > + .chr_write = fd_chr_write,
> > + .chr_update_read_handler = fd_chr_update_read_handler,
> > + .chr_ioctl = tty_serial_ioctl,
> > + .chr_free = qemu_chr_free_tty,
> > +#endif
> > +};
> > +#endif
>
>
> > @@ -4910,49 +5037,33 @@ void qemu_chr_cleanup(void)
> >
> > static void register_types(void)
> > {
> > - int i;
> > - static const CharDriver drivers[] = {
> > - { .kind = CHARDEV_BACKEND_KIND_NULL, .parse = NULL,
> > - .create = qemu_chr_open_null },
> > - { .kind = CHARDEV_BACKEND_KIND_SOCKET,
> > - .parse = qemu_chr_parse_socket, .create =
> > qmp_chardev_open_socket },
> > - { .kind = CHARDEV_BACKEND_KIND_UDP, .parse = qemu_chr_parse_udp,
> > - .create = qmp_chardev_open_udp },
> > - { .kind = CHARDEV_BACKEND_KIND_RINGBUF,
> > - .parse = qemu_chr_parse_ringbuf, .create = qemu_chr_open_ringbuf
> > },
> > - { .kind = CHARDEV_BACKEND_KIND_FILE,
> > - .parse = qemu_chr_parse_file_out, .create =
> > qmp_chardev_open_file },
> > - { .kind = CHARDEV_BACKEND_KIND_STDIO,
> > - .parse = qemu_chr_parse_stdio, .create = qemu_chr_open_stdio },
> > -#if defined HAVE_CHARDEV_SERIAL
> > - { .kind = CHARDEV_BACKEND_KIND_SERIAL, .alias = "tty",
> > - .parse = qemu_chr_parse_serial, .create =
> > qmp_chardev_open_serial },
>
> It feels like some code motion between 3/54 and 4/54 (you are moving
> where the CharDriver is declared); is it worth tweaking the series to
> avoid the code motion by declaring the structs in the right place to
> begin with? Not necessarily a show-stopper to the series, though.
I did place it where it felt right at the time I did the change. I don't think we need to care much because all this is going away in the series. No strong feeling though
>
> > + static const CharDriver *drivers[] = {
> > + &null_driver,
> > + &socket_driver,
> > + &udp_driver,
> > + &ringbuf_driver,
> > + &file_driver,
> > + &stdio_driver,
> > +#ifdef HAVE_CHARDEV_SERIAL
> > + &serial_driver,
> > #endif
>
> Overall impression is that I still like where this is headed.
thanks
next prev parent reply other threads:[~2017-01-02 15:33 UTC|newest]
Thread overview: 85+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-12 22:42 [Qemu-devel] [PATCH 00/54] WIP: chardev: qom-ify Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 01/54] gtk: avoid oob array access Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 02/54] char: use a const CharDriver Marc-André Lureau
2016-12-13 23:11 ` Eric Blake
2017-01-02 15:33 ` Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 03/54] char: use a static array for backends Marc-André Lureau
2016-12-14 14:52 ` Eric Blake
2017-01-02 15:33 ` Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 04/54] char: move callbacks in CharDriver Marc-André Lureau
2016-12-14 16:02 ` Eric Blake
2017-01-02 15:33 ` Marc-André Lureau [this message]
2016-12-12 22:42 ` [Qemu-devel] [PATCH 05/54] char: fold single-user functions in caller Marc-André Lureau
2016-12-14 16:05 ` Eric Blake
2017-01-02 15:33 ` Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 06/54] char: introduce generic qemu_chr_get_kind() Marc-André Lureau
2016-12-19 21:16 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 07/54] char: use a feature bit for replay Marc-André Lureau
2016-12-19 21:58 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 08/54] char: allocate CharDriverState as a single object Marc-André Lureau
2017-01-04 20:24 ` Eric Blake
2017-01-04 21:09 ` Marc-André Lureau
2017-01-04 21:15 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 09/54] bt: use qemu_chr_alloc() Marc-André Lureau
2017-01-04 21:18 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 10/54] char: rename CharDriverState Chardev Marc-André Lureau
2017-01-04 21:30 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 11/54] char: rename TCPChardev and NetChardev Marc-André Lureau
2017-01-04 21:55 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 12/54] spice-char: improve error reporting Marc-André Lureau
2017-01-04 22:00 ` Eric Blake
2017-01-05 14:03 ` Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 13/54] char: use error_report() Marc-André Lureau
2017-01-04 22:04 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 14/54] gtk: overwrite the console.c char driver Marc-André Lureau
2017-01-04 22:26 ` Eric Blake
2016-12-12 22:42 ` [Qemu-devel] [PATCH 15/54] chardev: qom-ify Marc-André Lureau
2017-01-05 2:30 ` Eric Blake
2017-01-05 15:54 ` Eric Blake
2017-01-05 16:20 ` Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 16/54] spice-qemu-char: convert to finalize Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 17/54] baum: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 18/54] msmouse: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 19/54] mux: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 20/54] char-udp: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 21/54] char-socket: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 22/54] char-pty: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 23/54] char-ringbuf: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 24/54] char-parallel: convert parallel " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 25/54] char-stdio: convert " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 26/54] char-win-stdio: " Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 27/54] char-win: do not override chr_free Marc-André Lureau
2016-12-12 22:42 ` [Qemu-devel] [PATCH 28/54] char-win: convert to finalize Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 29/54] char-fd: " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 30/54] char: remove chr_free Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 31/54] char: get rid of CharDriver Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 32/54] char: remove class kind field Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 33/54] char: move to chardev/ Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 34/54] char: create chardev-obj-y Marc-André Lureau
2016-12-13 11:10 ` Paolo Bonzini
2016-12-13 12:40 ` Marc-André Lureau
2016-12-13 12:52 ` Paolo Bonzini
2016-12-12 22:43 ` [Qemu-devel] [PATCH 35/54] char: make null_chr_write() the default method Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 36/54] char: move null chardev to its own file Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 37/54] char: move mux " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 38/54] char: move ringbuf/memory " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 39/54] char: rename and move to header CHR_READ_BUF_LEN Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 40/54] char: remove unused READ_RETRIES Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 41/54] char: move QIOChannel-related in char-io.h Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 42/54] char: move fd chardev in its own file Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 43/54] char: move win chardev base class " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 44/54] char: move win-stdio into " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 45/54] char: move socket chardev to itw " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 46/54] char: move udp chardev in its " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 47/54] char: move file " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 48/54] char: move stdio " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 49/54] char: move console " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 50/54] char: move pipe chardev " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 51/54] char: move pty " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 52/54] char: move serial chardev to itw " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 53/54] char: move parallel chardev in its " Marc-André Lureau
2016-12-12 22:43 ` [Qemu-devel] [PATCH 54/54] char: headers clean-up Marc-André Lureau
2016-12-13 0:33 ` [Qemu-devel] [PATCH 00/54] WIP: chardev: qom-ify no-reply
2017-01-02 10:26 ` Paolo Bonzini
2017-01-04 21:20 ` Marc-André Lureau
2017-01-04 21:50 ` 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=305153287.20363.1483371219240.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).