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

Hans de Goede 329b58
From bccdec085744256038f35b243853d7142b85cddb Mon Sep 17 00:00:00 2001
Justin M. Forbes d4cdad
From: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes d4cdad
Date: Mon, 21 Mar 2011 22:02:47 +0100
Hans de Goede 329b58
Subject: [PATCH 106/114] char: Equip the unix/tcp backend to handle
Justin M. Forbes d4cdad
 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>
Justin M. Forbes d4cdad
---
Justin M. Forbes d4cdad
 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
Hans de Goede 329b58
index d8059ff..ed306e5 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 */
Hans de Goede 329b58
@@ -2493,6 +2506,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;
Hans de Goede 329b58
@@ -2547,6 +2579,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
-- 
Hans de Goede 329b58
1.7.10.4
Justin M. Forbes d4cdad