All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 07/11] chardev: add tty chardev support to chardev-add (qmp)
Date: Thu, 10 Jan 2013 11:39:15 +0100	[thread overview]
Message-ID: <50EE9A53.3070000@redhat.com> (raw)
In-Reply-To: <1357566928-25361-8-git-send-email-kraxel@redhat.com>

Il 07/01/2013 14:55, Gerd Hoffmann ha scritto:
> Simliar to file, except that no separate in/out files are supported
> because it's pointless for direct device access.  Also the special
> tty ioctl hooks (pass through linespeed settings etc) are activated.
> Both file names and file descriptor passing is supported.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  qapi-schema.json |    6 ++++++
>  qemu-char.c      |   53 +++++++++++++++++++++++++++++++++++++++++++++++------
>  2 files changed, 53 insertions(+), 6 deletions(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 8904d36..7e5c8c2 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3036,9 +3036,15 @@
>  { 'type': 'ChardevFile', 'data': { '*in' : 'ChardevFileSource',
>                                     'out' : 'ChardevFileSource' } }
>  
> +{ 'enum': 'ChardevPortKind', 'data': [ 'tty' ] }
> +
> +{ 'type': 'ChardevPort', 'data': { 'device' : 'ChardevFileSource',
> +                                   'type'   : 'ChardevPortKind'} }
> +
>  { 'type': 'ChardevDummy', 'data': { } }
>  
>  { 'union': 'ChardevBackend', 'data': { 'file' : 'ChardevFile',
> +                                       'port' : 'ChardevPort',
>                                         'null' : 'ChardevDummy' } }
>  
>  { 'command': 'chardev-add', 'data': {'id'      : 'str',
> diff --git a/qemu-char.c b/qemu-char.c
> index 91b0a57..764321b 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -1230,21 +1230,27 @@ static void qemu_chr_close_tty(CharDriverState *chr)
>      }
>  }
>  
> +static CharDriverState *qemu_chr_open_tty_fd(int fd)
> +{
> +    CharDriverState *chr;
> +
> +    tty_serial_init(fd, 115200, 'N', 8, 1);
> +    chr = qemu_chr_open_fd(fd, fd);
> +    chr->chr_ioctl = tty_serial_ioctl;
> +    chr->chr_close = qemu_chr_close_tty;
> +    return chr;
> +}
> +
>  static CharDriverState *qemu_chr_open_tty(QemuOpts *opts)
>  {
>      const char *filename = qemu_opt_get(opts, "path");
> -    CharDriverState *chr;
>      int fd;
>  
>      TFR(fd = qemu_open(filename, O_RDWR | O_NONBLOCK));
>      if (fd < 0) {
>          return NULL;
>      }
> -    tty_serial_init(fd, 115200, 'N', 8, 1);
> -    chr = qemu_chr_open_fd(fd, fd);
> -    chr->chr_ioctl = tty_serial_ioctl;
> -    chr->chr_close = qemu_chr_close_tty;
> -    return chr;
> +    return qemu_chr_open_tty_fd(fd);
>  }
>  #endif /* __linux__ || __sun__ */
>  
> @@ -2962,6 +2968,15 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)
>      return qemu_chr_open_win_file(out);
>  }
>  
> +static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp)
> +{
> +    switch (port->type) {
> +    default:
> +        error_setg(errp, "unknown chardev port (%d)", port->type);
> +        return NULL;
> +    }
> +}
> +
>  #else /* WIN32 */
>  
>  static int qmp_chardev_open_file_source(ChardevFileSource *src, int flags,
> @@ -2978,6 +2993,9 @@ static int qmp_chardev_open_file_source(ChardevFileSource *src, int flags,
>          break;
>      case CHARDEV_FILE_SOURCE_KIND_FD:
>          fd = monitor_get_fd(cur_mon, src->fd, errp);
> +        if (flags & O_NONBLOCK) {
> +            socket_set_nonblock(fd);
> +        }
>          break;
>      default:
>          error_setg(errp, "unknown chardev file source (%d)", src->kind);
> @@ -3008,6 +3026,26 @@ static CharDriverState *qmp_chardev_open_file(ChardevFile *file, Error **errp)
>      return qemu_chr_open_fd(in, out);
>  }
>  
> +static CharDriverState *qmp_chardev_open_port(ChardevPort *port, Error **errp)
> +{
> +    int flags, fd;
> +
> +    switch (port->type) {
> +#ifdef HAVE_CHARDEV_TTY
> +    case CHARDEV_PORT_KIND_TTY:
> +        flags = O_RDWR | O_NONBLOCK;
> +        fd = qmp_chardev_open_file_source(port->device, flags, errp);
> +        if (error_is_set(errp)) {
> +            return NULL;
> +        }
> +        return qemu_chr_open_tty_fd(fd);
> +#endif
> +    default:
> +        error_setg(errp, "unknown chardev port (%d)", port->type);
> +        return NULL;
> +    }
> +}
> +
>  #endif /* WIN32 */
>  
>  void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp)
> @@ -3018,6 +3056,9 @@ void qmp_chardev_add(const char *id, ChardevBackend *backend, Error **errp)
>      case CHARDEV_BACKEND_KIND_FILE:
>          chr = qmp_chardev_open_file(backend->file, errp);
>          break;
> +    case CHARDEV_BACKEND_KIND_PORT:
> +        chr = qmp_chardev_open_port(backend->port, errp);
> +        break;
>      case CHARDEV_BACKEND_KIND_NULL:
>          chr = qemu_chr_open_null(NULL);
>          break;
> 

Apart from the naming question (see my review of 8/11),

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

  reply	other threads:[~2013-01-10 10:39 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-07 13:55 [Qemu-devel] [PATCH 00/11] chardev hotplug patch series Gerd Hoffmann
2013-01-07 13:55 ` [Qemu-devel] [PATCH 01/11] chardev: add error reporting for qemu_chr_new_from_opts Gerd Hoffmann
2013-01-10 10:26   ` Paolo Bonzini
2013-01-07 13:55 ` [Qemu-devel] [PATCH 02/11] chardev: fix QemuOpts lifecycle Gerd Hoffmann
2013-01-10 10:26   ` Paolo Bonzini
2013-01-07 13:55 ` [Qemu-devel] [PATCH 03/11] chardev: reduce chardev ifdef mess a bit Gerd Hoffmann
2013-01-10 10:27   ` Paolo Bonzini
2013-01-07 13:55 ` [Qemu-devel] [PATCH 04/11] chardev: add qmp hotplug commands, with null chardev support Gerd Hoffmann
2013-01-09 17:14   ` Eric Blake
2013-01-10  8:45     ` Gerd Hoffmann
2013-01-07 13:55 ` [Qemu-devel] [PATCH 05/11] chardev: add hmp hotplug commands Gerd Hoffmann
2013-01-10 10:33   ` Paolo Bonzini
2013-01-10 10:53     ` Gerd Hoffmann
2013-01-10 10:57       ` Paolo Bonzini
2013-01-10 12:35     ` Luiz Capitulino
2013-01-07 13:55 ` [Qemu-devel] [PATCH 06/11] chardev: add file chardev support to chardev-add (qmp) Gerd Hoffmann
2013-01-09 18:12   ` Eric Blake
2013-01-10  9:10     ` Gerd Hoffmann
2013-01-10 10:35       ` Paolo Bonzini
2013-01-07 13:55 ` [Qemu-devel] [PATCH 07/11] chardev: add tty " Gerd Hoffmann
2013-01-10 10:39   ` Paolo Bonzini [this message]
2013-01-07 13:55 ` [Qemu-devel] [PATCH 08/11] chardev: add serial " Gerd Hoffmann
2013-01-10 10:38   ` Paolo Bonzini
2013-01-10 11:05     ` Gerd Hoffmann
2013-01-10 12:37       ` Gerd Hoffmann
2013-01-10 12:46         ` Paolo Bonzini
2013-01-07 13:55 ` [Qemu-devel] [PATCH 09/11] chardev: add parport " Gerd Hoffmann
2013-01-10 10:40   ` Paolo Bonzini
2013-01-07 13:55 ` [Qemu-devel] [PATCH 10/11] chardev: add socket " Gerd Hoffmann
2013-01-09 20:03   ` Eric Blake
2013-01-10  9:12     ` Gerd Hoffmann
2013-01-07 13:55 ` [Qemu-devel] [PATCH 11/11] chardev: add pty " Gerd Hoffmann
2013-01-09 17:37   ` Eric Blake
2013-01-10  9:14     ` Gerd Hoffmann
2013-01-10 10:42     ` Paolo Bonzini

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=50EE9A53.3070000@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kraxel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.