dcavalca / rpms / qemu

Forked from rpms/qemu 11 months ago
Clone

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

Justin M. Forbes 252f3a
>From 7d8cbead9454da6dbfdc050c6828faae39621a1b Mon Sep 17 00:00:00 2001
Justin M. Forbes 252f3a
From: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes 252f3a
Date: Mon, 21 Mar 2011 22:02:47 +0100
Justin M. Forbes 252f3a
Subject: [PATCH 10/17] char: Equip the unix/tcp backend to handle nonblocking writes#
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
Now that the infrastructure is in place to return -EAGAIN to callers,
Justin M. Forbes 252f3a
individual char drivers can set their update_fd_handlers() function to
Justin M. Forbes 252f3a
set or remove an fd's write handler.  This handler checks if the driver
Justin M. Forbes 252f3a
became writable.
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
A generic callback routine is used for unblocking writes and letting
Justin M. Forbes 252f3a
users of chardevs know that a driver became writable again.
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
Signed-off-by: Amit Shah <amit.shah@redhat.com>
Justin M. Forbes 252f3a
---
Justin M. Forbes 252f3a
 qemu-char.c |   34 ++++++++++++++++++++++++++++++++++
Justin M. Forbes 252f3a
 1 files changed, 34 insertions(+), 0 deletions(-)
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
diff --git a/qemu-char.c b/qemu-char.c
Justin M. Forbes 252f3a
index eed61d6..7517f64 100644
Justin M. Forbes 252f3a
--- a/qemu-char.c
Justin M. Forbes 252f3a
+++ b/qemu-char.c
Justin M. Forbes 252f3a
@@ -107,6 +107,19 @@
Justin M. Forbes 252f3a
 static QTAILQ_HEAD(CharDriverStateHead, CharDriverState) chardevs =
Justin M. Forbes 252f3a
     QTAILQ_HEAD_INITIALIZER(chardevs);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+/*
Justin M. Forbes 252f3a
+ * Generic routine that gets called when chardev becomes writable.
Justin M. Forbes 252f3a
+ * Lets chardev user know it's OK to send more data.
Justin M. Forbes 252f3a
+ */
Justin M. Forbes 252f3a
+static void char_write_unblocked(void *opaque)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    CharDriverState *chr = opaque;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    chr->write_blocked = false;
Justin M. Forbes 252f3a
+    chr->chr_disable_write_fd_handler(chr);
Justin M. Forbes 252f3a
+    chr->chr_write_unblocked(chr->handler_opaque);
Justin M. Forbes 252f3a
+}
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static void qemu_chr_event(CharDriverState *s, int event)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     /* Keep track if the char device is open */
Justin M. Forbes 252f3a
@@ -2261,6 +2274,25 @@ static void tcp_chr_close(CharDriverState *chr)
Justin M. Forbes 252f3a
     qemu_chr_event(chr, CHR_EVENT_CLOSED);
Justin M. Forbes 252f3a
 }
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static void tcp_enable_write_fd_handler(CharDriverState *chr)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    TCPCharDriver *s = chr->opaque;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    /*
Justin M. Forbes 252f3a
+     * This function is called only after tcp_chr_connect() is called
Justin M. Forbes 252f3a
+     * (either in 'server' mode or client mode.  So we're sure of
Justin M. Forbes 252f3a
+     * s->fd being initialised.
Justin M. Forbes 252f3a
+     */
Justin M. Forbes 252f3a
+    enable_write_fd_handler(s->fd, char_write_unblocked);
Justin M. Forbes 252f3a
+}
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+static void tcp_disable_write_fd_handler(CharDriverState *chr)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    TCPCharDriver *s = chr->opaque;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    disable_write_fd_handler(s->fd);
Justin M. Forbes 252f3a
+}
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
Justin M. Forbes 252f3a
 {
Justin M. Forbes 252f3a
     CharDriverState *chr = NULL;
Justin M. Forbes 252f3a
@@ -2313,6 +2345,8 @@ static CharDriverState *qemu_chr_open_socket(QemuOpts *opts)
Justin M. Forbes 252f3a
     chr->chr_write = tcp_chr_write;
Justin M. Forbes 252f3a
     chr->chr_close = tcp_chr_close;
Justin M. Forbes 252f3a
     chr->get_msgfd = tcp_get_msgfd;
Justin M. Forbes 252f3a
+    chr->chr_enable_write_fd_handler = tcp_enable_write_fd_handler;
Justin M. Forbes 252f3a
+    chr->chr_disable_write_fd_handler = tcp_disable_write_fd_handler;
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
     if (is_listen) {
Justin M. Forbes 252f3a
         s->listen_fd = fd;
Justin M. Forbes 252f3a
-- 
Justin M. Forbes 252f3a
1.7.3.2
Justin M. Forbes 252f3a