From: Fam Zheng <famz@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, kraxel@redhat.com, qemu-devel@nongnu.org,
stefanha@redhat.com, lcapitulino@redhat.com
Subject: Re: [Qemu-devel] [PATCH 1/6] qemu-char: introduce qemu_chr_alloc
Date: Wed, 11 Jun 2014 14:28:15 +0800 [thread overview]
Message-ID: <20140611062815.GD5448@T430.nay.redhat.com> (raw)
In-Reply-To: <1401813551-6667-2-git-send-email-pbonzini@redhat.com>
On Tue, 06/03 18:39, Paolo Bonzini wrote:
> The next patch will modify this function to initialize state that is
> common to all backends.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
> ---
> backends/baum.c | 2 +-
> backends/msmouse.c | 2 +-
> include/sysemu/char.h | 9 +++++++++
> qemu-char.c | 32 +++++++++++++++++++-------------
> spice-qemu-char.c | 2 +-
> ui/console.c | 2 +-
> 6 files changed, 32 insertions(+), 17 deletions(-)
>
> diff --git a/backends/baum.c b/backends/baum.c
> index 759003f..796512d 100644
> --- a/backends/baum.c
> +++ b/backends/baum.c
> @@ -574,7 +574,7 @@ CharDriverState *chr_baum_init(void)
> int tty;
>
> baum = g_malloc0(sizeof(BaumDriverState));
> - baum->chr = chr = g_malloc0(sizeof(CharDriverState));
> + baum->chr = chr = qemu_chr_alloc();
>
> chr->opaque = baum;
> chr->chr_write = baum_write;
> diff --git a/backends/msmouse.c b/backends/msmouse.c
> index c0dbfcd..650a531 100644
> --- a/backends/msmouse.c
> +++ b/backends/msmouse.c
> @@ -67,7 +67,7 @@ CharDriverState *qemu_chr_open_msmouse(void)
> {
> CharDriverState *chr;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> chr->chr_write = msmouse_chr_write;
> chr->chr_close = msmouse_chr_close;
> chr->explicit_be_open = true;
> diff --git a/include/sysemu/char.h b/include/sysemu/char.h
> index b81a6ff..9bbfd06 100644
> --- a/include/sysemu/char.h
> +++ b/include/sysemu/char.h
> @@ -85,6 +85,15 @@ struct CharDriverState {
> };
>
> /**
> + * @qemu_chr_alloc:
> + *
> + * Allocate and initialize a new CharDriverState.
> + *
> + * Returns: a newly allocated CharDriverState.
> + */
> +CharDriverState *qemu_chr_alloc(void);
> +
> +/**
> * @qemu_chr_new_from_opts:
> *
> * Create a new character backend from a QemuOpts list.
> diff --git a/qemu-char.c b/qemu-char.c
> index 54ed244..3df5db7 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -91,6 +91,12 @@
> static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
> QTAILQ_HEAD_INITIALIZER(chardevs);
>
> +CharDriverState *qemu_chr_alloc(void)
> +{
> + CharDriverState *chr = g_malloc0(sizeof(CharDriverState));
> + return chr;
> +}
> +
> void qemu_chr_be_event(CharDriverState *s, int event)
> {
> /* Keep track if the char device is open */
> @@ -236,7 +242,7 @@ static CharDriverState *qemu_chr_open_null(void)
> {
> CharDriverState *chr;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> chr->chr_write = null_chr_write;
> chr->explicit_be_open = true;
> return chr;
> @@ -524,7 +530,7 @@ static CharDriverState *qemu_chr_open_mux(CharDriverState *drv)
> CharDriverState *chr;
> MuxDriver *d;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> d = g_malloc0(sizeof(MuxDriver));
>
> chr->opaque = d;
> @@ -899,7 +905,7 @@ static CharDriverState *qemu_chr_open_fd(int fd_in, int fd_out)
> CharDriverState *chr;
> FDCharDriver *s;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(FDCharDriver));
> s->fd_in = io_channel_from_fd(fd_in);
> s->fd_out = io_channel_from_fd(fd_out);
> @@ -1176,7 +1182,7 @@ static CharDriverState *qemu_chr_open_pty(const char *id,
>
> close(slave_fd);
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
>
> chr->filename = g_strdup_printf("pty:%s", pty_name);
> ret->pty = g_strdup(pty_name);
> @@ -1538,7 +1544,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd)
> drv->fd = fd;
> drv->mode = IEEE1284_MODE_COMPAT;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> chr->chr_write = null_chr_write;
> chr->chr_ioctl = pp_ioctl;
> chr->chr_close = pp_close;
> @@ -1593,7 +1599,7 @@ static CharDriverState *qemu_chr_open_pp_fd(int fd)
> {
> CharDriverState *chr;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> chr->opaque = (void *)(intptr_t)fd;
> chr->chr_write = null_chr_write;
> chr->chr_ioctl = pp_ioctl;
> @@ -1817,7 +1823,7 @@ static CharDriverState *qemu_chr_open_win_path(const char *filename)
> CharDriverState *chr;
> WinCharState *s;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(WinCharState));
> chr->opaque = s;
> chr->chr_write = win_chr_write;
> @@ -1916,7 +1922,7 @@ static CharDriverState *qemu_chr_open_pipe(ChardevHostdev *opts)
> CharDriverState *chr;
> WinCharState *s;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(WinCharState));
> chr->opaque = s;
> chr->chr_write = win_chr_write;
> @@ -1935,7 +1941,7 @@ static CharDriverState *qemu_chr_open_win_file(HANDLE fd_out)
> CharDriverState *chr;
> WinCharState *s;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(WinCharState));
> s->hcom = fd_out;
> chr->opaque = s;
> @@ -2091,7 +2097,7 @@ static CharDriverState *qemu_chr_open_stdio(ChardevStdio *opts)
> DWORD dwMode;
> int is_console = 0;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> stdio = g_malloc0(sizeof(WinStdioCharState));
>
> stdio->hStdIn = GetStdHandle(STD_INPUT_HANDLE);
> @@ -2253,7 +2259,7 @@ static CharDriverState *qemu_chr_open_udp_fd(int fd)
> CharDriverState *chr = NULL;
> NetCharDriver *s = NULL;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(NetCharDriver));
>
> s->fd = fd;
> @@ -2637,7 +2643,7 @@ static CharDriverState *qemu_chr_open_socket_fd(int fd, bool do_nodelay,
> return NULL;
> }
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(TCPCharDriver));
>
> s->connected = 0;
> @@ -2822,7 +2828,7 @@ static CharDriverState *qemu_chr_open_ringbuf(ChardevRingbuf *opts,
> CharDriverState *chr;
> RingBufCharDriver *d;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> d = g_malloc(sizeof(*d));
>
> d->size = opts->has_size ? opts->size : 65536;
> diff --git a/spice-qemu-char.c b/spice-qemu-char.c
> index 6624559..4518a4d 100644
> --- a/spice-qemu-char.c
> +++ b/spice-qemu-char.c
> @@ -268,7 +268,7 @@ static CharDriverState *chr_open(const char *subtype,
> CharDriverState *chr;
> SpiceCharDriver *s;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
> s = g_malloc0(sizeof(SpiceCharDriver));
> s->chr = chr;
> s->active = false;
> diff --git a/ui/console.c b/ui/console.c
> index e057755..c893b27 100644
> --- a/ui/console.c
> +++ b/ui/console.c
> @@ -1795,7 +1795,7 @@ static CharDriverState *text_console_init(ChardevVC *vc)
> unsigned width = 0;
> unsigned height = 0;
>
> - chr = g_malloc0(sizeof(CharDriverState));
> + chr = qemu_chr_alloc();
>
> if (vc->has_width) {
> width = vc->width;
> --
> 1.8.3.1
>
>
next prev parent reply other threads:[~2014-06-11 6:28 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-03 16:39 [Qemu-devel] [PATCH 0/5] qemu-char/monitor: make monitor_puts thread safe Paolo Bonzini
2014-06-03 16:39 ` [Qemu-devel] [PATCH 1/6] qemu-char: introduce qemu_chr_alloc Paolo Bonzini
2014-06-11 6:28 ` Fam Zheng [this message]
2014-06-03 16:39 ` [Qemu-devel] [PATCH 2/6] qemu-char: do not call chr_write directly Paolo Bonzini
2014-06-11 6:30 ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 3/6] qemu-char: move pty_chr_update_read_handler around Paolo Bonzini
2014-06-11 6:32 ` Fam Zheng
2014-06-03 16:39 ` [Qemu-devel] [PATCH 4/6] qemu-char: make writes thread-safe Paolo Bonzini
2014-06-11 6:59 ` Fam Zheng
2014-06-11 8:16 ` Paolo Bonzini
2014-06-03 16:39 ` [Qemu-devel] [PATCH 5/6] monitor: protect outbuf with mutex Paolo Bonzini
2014-06-10 14:10 ` Luiz Capitulino
2014-06-10 14:24 ` Paolo Bonzini
2014-06-10 14:28 ` Luiz Capitulino
2014-06-03 16:39 ` [Qemu-devel] [PATCH 6/6] monitor: protect event emission Paolo Bonzini
2014-06-10 13:33 ` Luiz Capitulino
2014-06-27 9:43 ` [Qemu-devel] [PATCH 0/5] qemu-char/monitor: make monitor_puts thread safe Stefan Hajnoczi
2014-06-27 12:33 ` Luiz Capitulino
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=20140611062815.GD5448@T430.nay.redhat.com \
--to=famz@redhat.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).