From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, "Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [RFC 01/14] Add qemu_chr_open_socket()
Date: Sat, 4 Jun 2016 23:33:10 +0200 [thread overview]
Message-ID: <1465076003-26291-2-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Create a CharDriver from an existing socket fd. Is there a better way to
do that?
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/sysemu/char.h | 2 ++
qemu-char.c | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 307fd8f..bd97031 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -106,6 +106,8 @@ struct CharDriverState {
*/
CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp);
+CharDriverState *qemu_chr_open_socket(int fd, Error **errp);
+
/**
* @qemu_chr_new_from_opts:
*
diff --git a/qemu-char.c b/qemu-char.c
index b597ee1..caa737d 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -96,6 +96,10 @@
static char *SocketAddress_to_str(const char *prefix, SocketAddress *addr,
bool is_listen, bool is_telnet)
{
+ if (!addr) {
+ return g_strdup(prefix);
+ }
+
switch (addr->type) {
case SOCKET_ADDRESS_KIND_INET:
return g_strdup_printf("%s%s:%s:%s%s", prefix,
@@ -166,7 +170,7 @@ CharDriverState *qemu_chr_alloc(ChardevCommon *backend, Error **errp)
CharDriverState *chr = g_malloc0(sizeof(CharDriverState));
qemu_mutex_init(&chr->chr_write_lock);
- if (backend->has_logfile) {
+ if (backend && backend->has_logfile) {
int flags = O_WRONLY | O_CREAT;
if (backend->has_logappend &&
backend->logappend) {
@@ -4466,6 +4470,37 @@ static CharDriverState *qmp_chardev_open_socket(const char *id,
return NULL;
}
+CharDriverState *qemu_chr_open_socket(int fd, Error **errp)
+{
+ CharDriverState *chr;
+ TCPCharDriver *s;
+
+ chr = qemu_chr_alloc(NULL, errp);
+ if (!chr) {
+ return NULL;
+ }
+
+ qemu_set_nonblock(fd);
+
+ s = g_new0(TCPCharDriver, 1);
+ chr->opaque = s;
+ chr->chr_write = tcp_chr_write;
+ chr->chr_sync_read = tcp_chr_sync_read;
+ chr->chr_close = tcp_chr_close;
+ chr->get_msgfds = tcp_get_msgfds;
+ chr->set_msgfds = tcp_set_msgfds;
+ chr->chr_add_watch = tcp_chr_add_watch;
+ chr->chr_update_read_handler = tcp_chr_update_read_handler;
+
+ if (tcp_chr_add_client(chr, fd) < -1) {
+ free(s);
+ qemu_chr_free_common(chr);
+ return NULL;
+ }
+
+ return chr;
+}
+
static CharDriverState *qmp_chardev_open_udp(const char *id,
ChardevBackend *backend,
ChardevReturn *ret,
--
2.7.4
next prev parent reply other threads:[~2016-06-04 21:33 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-04 21:33 [Qemu-devel] [RFC 00/14] vhost-user backends for gpu & input virtio devices marcandre.lureau
2016-06-04 21:33 ` marcandre.lureau [this message]
2016-06-04 21:33 ` [Qemu-devel] [RFC 02/14] Add vhost-user-backend marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 03/14] vhost-user: split vhost_user_read() marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 04/14] vhost-user: add vhost_user_input_get_config() marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 05/14] Add vhost-user backend to virtio-input-host marcandre.lureau
2016-06-06 6:22 ` Gerd Hoffmann
2016-06-04 21:33 ` [Qemu-devel] [RFC 06/14] contrib: add vhost-user-input marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 07/14] misc: rename virtio-gpu.h header guard marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 08/14] vhost: make sure call fd has been received marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 09/14] qemu-char: use READ_RETRIES marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 10/14] qemu-char: block during sync read marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 11/14] console: add dpy_gl_scanout2() marcandre.lureau
2016-06-06 6:35 ` Gerd Hoffmann
2016-06-06 13:18 ` Marc-André Lureau
2016-06-06 14:04 ` Gerd Hoffmann
2016-06-04 21:33 ` [Qemu-devel] [RFC 12/14] contrib: add vhost-user-gpu marcandre.lureau
2016-06-04 21:33 ` [Qemu-devel] [RFC 13/14] vhost-user: add vhost_user_gpu_set_socket() marcandre.lureau
2016-06-06 6:36 ` Gerd Hoffmann
2016-06-04 21:33 ` [Qemu-devel] [RFC 14/14] Add virtio-gpu vhost-user backend marcandre.lureau
2016-06-06 6:54 ` Gerd Hoffmann
2016-06-06 13:54 ` [Qemu-devel] [RFC 00/14] vhost-user backends for gpu & input virtio devices Marc-André Lureau
2016-06-07 14:47 ` Gerd Hoffmann
2016-06-07 15:01 ` Marc-André Lureau
2016-06-08 6:11 ` Gerd Hoffmann
2016-06-08 12:53 ` Marc-André Lureau
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=1465076003-26291-2-git-send-email-marcandre.lureau@redhat.com \
--to=marcandre.lureau@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 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).