dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

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

5544c1
From 625915146f56f77c275be1aee160f40183008b8d 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
5544c1
Subject: [PATCH] char: Equip the unix/tcp backend to handle nonblocking
5544c1
 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
5544c1
index b46cc97..9f8608a 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 */
5544c1
@@ -2503,6 +2516,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;
5544c1
@@ -2557,6 +2589,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
-- 
5544c1
1.7.12.1
Justin M. Forbes d4cdad