peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

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

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