From: "Marc-André Lureau" <marcandre.lureau@redhat.com>
To: qemu-devel@nongnu.org
Cc: pbonzini@redhat.com, eblake@redhat.com,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH v2 08/20] char: fold single-user functions in caller
Date: Tue, 10 Jan 2017 18:47:58 +0100 [thread overview]
Message-ID: <20170110174810.17748-9-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20170110174810.17748-1-marcandre.lureau@redhat.com>
This shortens the code a bit.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
qemu-char.c | 95 +++++++++++++++++++------------------------------------------
1 file changed, 29 insertions(+), 66 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index 9ce0aadc9b..305f410c73 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -1891,22 +1891,6 @@ static void qemu_chr_free_tty(CharDriverState *chr)
{
fd_chr_free(chr);
}
-
-static CharDriverState *qemu_chr_open_tty_fd(const CharDriver *driver,
- int fd,
- ChardevCommon *backend,
- bool *be_opened,
- Error **errp)
-{
- CharDriverState *chr;
-
- tty_serial_init(fd, 115200, 'N', 8, 1);
- chr = qemu_chr_open_fd(driver, fd, fd, backend, errp);
- if (!chr) {
- return NULL;
- }
- return chr;
-}
#endif /* __linux__ || __sun__ */
#if defined(__linux__)
@@ -2327,29 +2311,6 @@ static int win_chr_poll(void *opaque)
return 0;
}
-static CharDriverState *qemu_chr_open_win_path(const CharDriver *driver,
- const char *filename,
- ChardevCommon *backend,
- Error **errp)
-{
- CharDriverState *chr;
- WinCharState *s;
-
- chr = qemu_chr_alloc(driver, backend, errp);
- if (!chr) {
- return NULL;
- }
- s = g_new0(WinCharState, 1);
- chr->opaque = s;
-
- if (win_chr_init(chr, filename, errp) < 0) {
- g_free(s);
- qemu_chr_free_common(chr);
- return NULL;
- }
- return chr;
-}
-
static int win_chr_pipe_poll(void *opaque)
{
CharDriverState *chr = opaque;
@@ -2806,30 +2767,6 @@ static void udp_chr_free(CharDriverState *chr)
qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
}
-static CharDriverState *qemu_chr_open_udp(const CharDriver *driver,
- QIOChannelSocket *sioc,
- ChardevCommon *backend,
- bool *be_opened,
- Error **errp)
-{
- CharDriverState *chr = NULL;
- NetCharDriver *s = NULL;
-
- chr = qemu_chr_alloc(driver, backend, errp);
- if (!chr) {
- return NULL;
- }
- s = g_new0(NetCharDriver, 1);
-
- s->ioc = QIO_CHANNEL(sioc);
- s->bufcnt = 0;
- s->bufptr = 0;
- chr->opaque = s;
- /* be isn't opened until we get a connection */
- *be_opened = false;
- return chr;
-}
-
/***********************************************************/
/* TCP Net console */
@@ -4612,8 +4549,23 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver,
{
ChardevHostdev *serial = backend->u.serial.data;
ChardevCommon *common = qapi_ChardevHostdev_base(serial);
+ CharDriverState *chr;
+ WinCharState *s;
+
+ chr = qemu_chr_alloc(driver, common, errp);
+ if (!chr) {
+ return NULL;
+ }
- return qemu_chr_open_win_path(driver, serial->device, common, errp);
+ s = g_new0(WinCharState, 1);
+ chr->opaque = s;
+ if (win_chr_init(chr, serial->device, errp) < 0) {
+ g_free(s);
+ qemu_chr_free_common(chr);
+ return NULL;
+ }
+
+ return chr;
}
#else /* WIN32 */
@@ -4682,8 +4634,9 @@ static CharDriverState *qmp_chardev_open_serial(const CharDriver *driver,
return NULL;
}
qemu_set_nonblock(fd);
+ tty_serial_init(fd, 115200, 'N', 8, 1);
- return qemu_chr_open_tty_fd(driver, fd, common, be_opened, errp);
+ return qemu_chr_open_fd(driver, fd, fd, common, errp);
}
#endif
@@ -4939,6 +4892,7 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,
QIOChannelSocket *sioc = qio_channel_socket_new();
char *name;
CharDriverState *chr;
+ NetCharDriver *s;
if (qio_channel_socket_dgram_sync(sioc,
udp->local, udp->remote,
@@ -4947,12 +4901,21 @@ static CharDriverState *qmp_chardev_open_udp(const CharDriver *driver,
return NULL;
}
- chr = qemu_chr_open_udp(driver, sioc, common, be_opened, errp);
+ chr = qemu_chr_alloc(driver, common, errp);
+ if (!chr) {
+ return NULL;
+ }
name = g_strdup_printf("chardev-udp-%s", chr->label);
qio_channel_set_name(QIO_CHANNEL(sioc), name);
g_free(name);
+ s = g_new0(NetCharDriver, 1);
+ s->ioc = QIO_CHANNEL(sioc);
+ chr->opaque = s;
+ /* be isn't opened until we get a connection */
+ *be_opened = false;
+
return chr;
}
--
2.11.0
next prev parent reply other threads:[~2017-01-10 17:48 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-10 17:47 [Qemu-devel] [PATCH v2 00/20] chardev: qom-ify Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 01/20] tests: fix linking test-char on win32 Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 02/20] qemu-options: stdio is available " Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 03/20] char: add qemu_chr_fe_add_watch() Returns description Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 04/20] doc: fix spelling Marc-André Lureau
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 05/20] char: use a const CharDriver Marc-André Lureau
2017-01-10 18:01 ` Eric Blake
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 06/20] char: use a static array for backends Marc-André Lureau
2017-01-10 18:03 ` Eric Blake
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 07/20] char: move callbacks in CharDriver Marc-André Lureau
2017-01-10 17:47 ` Marc-André Lureau [this message]
2017-01-10 17:47 ` [Qemu-devel] [PATCH v2 09/20] char: introduce generic qemu_chr_get_kind() Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 10/20] char: use a feature bit for replay Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 11/20] char: allocate CharDriverState as a single object Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 12/20] bt: use qemu_chr_alloc() Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 13/20] char: rename CharDriverState Chardev Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 14/20] char: rename TCPChardev and NetChardev Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 15/20] spice-char: improve error reporting Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 16/20] char: use error_report() Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 17/20] gtk: overwrite the console.c char driver Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 18/20] baum: use a common prefix for chr callbacks Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 19/20] vc: " Marc-André Lureau
2017-01-10 17:48 ` [Qemu-devel] [PATCH v2 20/20] chardev: qom-ify Marc-André Lureau
2017-01-11 21:27 ` Eric Blake
2017-01-12 15:19 ` Marc-André Lureau
2017-01-24 13:59 ` [Qemu-devel] [PATCH v2 00/20] " 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=20170110174810.17748-9-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=eblake@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).