Blame 0106-char-Equip-the-unix-tcp-backend-to-handle-nonblockin.patch

bd56df
From 2fa4be9d3b84d214f4ea9da8513ef664f412ad09 Mon Sep 17 00:00:00 2001
bd56df
Message-Id: <2fa4be9d3b84d214f4ea9da8513ef664f412ad09.1346162949.git.crobinso@redhat.com>
bd56df
In-Reply-To: <90a59d545ad6759c105b0bfcfca70f574482584f.1346162949.git.crobinso@redhat.com>
bd56df
References: <90a59d545ad6759c105b0bfcfca70f574482584f.1346162949.git.crobinso@redhat.com>
Justin M. Forbes d4cdad
From: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes d4cdad
Date: Mon, 21 Mar 2011 22:02:47 +0100
bd56df
Subject: [PATCH 106/114] char: Equip the unix/tcp backend to handle
bd56df
 nonblocking writes#
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
Now that the infrastructure is in place to return -EAGAIN to callers,
Justin M. Forbes d4cdad
individual char drivers can set their update_fd_handlers() function to
Justin M. Forbes d4cdad
set or remove an fd's write handler.  This handler checks if the driver
Justin M. Forbes d4cdad
became writable.
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
A generic callback routine is used for unblocking writes and letting
Justin M. Forbes d4cdad
users of chardevs know that a driver became writable again.
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
Signed-off-by: Amit Shah <amit.shah@redhat.com>
bd56df
Signed-off-by: Cole Robinson <crobinso@redhat.com>
Justin M. Forbes d4cdad
---
b6dd5a
 qemu-char.c | 34 ++++++++++++++++++++++++++++++++++
Hans de Goede 329b58
 1 file changed, 34 insertions(+)
Justin M. Forbes d4cdad
Justin M. Forbes d4cdad
diff --git a/qemu-char.c b/qemu-char.c
bd56df
index c2a3138..5e136fd 100644
Justin M. Forbes d4cdad
--- a/qemu-char.c
Justin M. Forbes d4cdad
+++ b/qemu-char.c
Justin M. Forbes d4cdad
@@ -106,6 +106,19 @@
Justin M. Forbes d4cdad
 static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
Justin M. Forbes d4cdad
     QTAILQ_HEAD_INITIALIZER(chardevs);
Hans de Goede 329b58
 
Justin M. Forbes d4cdad
+/*
Justin M. Forbes d4cdad
+ * Generic routine that gets called when chardev becomes writable.
Justin M. Forbes d4cdad
+ * Lets chardev user know it's OK to send more data.
Justin M. Forbes d4cdad
+ */
Justin M. Forbes d4cdad
+static void char_write_unblocked(void *opaque)
Justin M. Forbes d4cdad
+{
Justin M. Forbes d4cdad
+    CharDriverState *chr = opaque;
Justin M. Forbes d4cdad
+
Justin M. Forbes d4cdad
+    chr->write_blocked = false;
Justin M. Forbes d4cdad
+    chr->chr_disable_write_fd_handler(chr);
Justin M. Forbes d4cdad
+    chr->chr_write_unblocked(chr->handler_opaque);
Justin M. Forbes d4cdad
+}
Justin M. Forbes d4cdad
+
Justin M. Forbes d4cdad
 void qemu_chr_be_event(CharDriverState *s, int event)
Justin M. Forbes d4cdad
 {
Justin M. Forbes d4cdad
     /* Keep track if the char device is open */
bd56df
@@ -2504,6 +2517,25 @@ static void tcp_chr_close(CharDriverState *chr)
Justin M. Forbes d4cdad
     qemu_chr_be_event(chr, CHR_EVENT_CLOSED);
Justin M. Forbes d4cdad
 }
Hans de Goede 329b58
 
Justin M. Forbes d4cdad
+static void tcp_enable_write_fd_handler(CharDriverState *chr)
Justin M. Forbes d4cdad
+{
Justin M. Forbes d4cdad
+    TCPCharDriver *s = chr->opaque;
Justin M. Forbes d4cdad
+
Justin M. Forbes d4cdad
+    /*
Justin M. Forbes d4cdad
+     * This function is called only after tcp_chr_connect() is called
Justin M. Forbes d4cdad
+     * (either in 'server' mode or client mode.  So we're sure of
Justin M. Forbes d4cdad
+     * s->fd being initialised.
Justin M. Forbes d4cdad
+     */
Justin M. Forbes d4cdad
+    enable_write_fd_handler(s->fd, char_write_unblocked);
Justin M. Forbes d4cdad
+}
Justin M. Forbes d4cdad
+
Justin M. Forbes d4cdad
+static void tcp_disable_write_fd_handler(CharDriverState *chr)
Justin M. Forbes d4cdad
+{
Justin M. Forbes d4cdad
+    TCPCharDriver *s = chr->opaque;
Justin M. Forbes d4cdad
+
Justin M. Forbes d4cdad
+    disable_write_fd_handler(s->fd);
Justin M. Forbes d4cdad
+}
Justin M. Forbes d4cdad
+
Hans de Goede 329b58
 static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
Justin M. Forbes d4cdad
 {
Justin M. Forbes d4cdad
     CharDriverState *chr = NULL;
bd56df
@@ -2558,6 +2590,8 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
Justin M. Forbes d4cdad
     chr->chr_close = tcp_chr_close;
Justin M. Forbes d4cdad
     chr->get_msgfd = tcp_get_msgfd;
Justin M. Forbes d4cdad
     chr->chr_add_client = tcp_chr_add_client;
Justin M. Forbes d4cdad
+    chr->chr_enable_write_fd_handler = tcp_enable_write_fd_handler;
Justin M. Forbes d4cdad
+    chr->chr_disable_write_fd_handler = tcp_disable_write_fd_handler;
Hans de Goede 329b58
 
Justin M. Forbes d4cdad
     if (is_listen) {
Justin M. Forbes d4cdad
         s->listen_fd = fd;
Justin M. Forbes d4cdad
-- 
b6dd5a
1.7.11.2
Justin M. Forbes d4cdad