peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0007-iohandlers-Add-enable-disable_write_fd_handler-funct.patch

Justin M. Forbes 252f3a
>From da7e6cd863ed0cffe885cd2d3639f92c82baf6e2 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 20:32:58 +0100
Justin M. Forbes 252f3a
Subject: [PATCH 07/17] iohandlers: Add enable/disable_write_fd_handler() functions
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
These will be used to provide a cleaner API for the nonblocking case.
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.h |    3 +++
Justin M. Forbes 252f3a
 vl.c        |   35 +++++++++++++++++++++++++++++++++++
Justin M. Forbes 252f3a
 2 files changed, 38 insertions(+), 0 deletions(-)
Justin M. Forbes 252f3a
Justin M. Forbes 252f3a
diff --git a/qemu-char.h b/qemu-char.h
Justin M. Forbes 252f3a
index 7a1924c..185377c 100644
Justin M. Forbes 252f3a
--- a/qemu-char.h
Justin M. Forbes 252f3a
+++ b/qemu-char.h
Justin M. Forbes 252f3a
@@ -116,6 +116,9 @@ size_t qemu_chr_mem_osize(const CharDriverState *chr);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
 /* async I/O support */
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+void enable_write_fd_handler(int fd, IOHandler *fd_write);
Justin M. Forbes 252f3a
+void disable_write_fd_handler(int fd);
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
 int qemu_set_fd_handler2(int fd,
Justin M. Forbes 252f3a
                          IOCanReadHandler *fd_read_poll,
Justin M. Forbes 252f3a
                          IOHandler *fd_read,
Justin M. Forbes 252f3a
diff --git a/vl.c b/vl.c
Justin M. Forbes 252f3a
index 85c36e3..95f51cb 100644
Justin M. Forbes 252f3a
--- a/vl.c
Justin M. Forbes 252f3a
+++ b/vl.c
Justin M. Forbes 252f3a
@@ -1044,6 +1044,41 @@ typedef struct IOHandlerRecord {
Justin M. Forbes 252f3a
 static QLIST_HEAD(, IOHandlerRecord) io_handlers =
Justin M. Forbes 252f3a
     QLIST_HEAD_INITIALIZER(io_handlers);
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
+static IOHandlerRecord *find_iohandler(int fd)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    IOHandlerRecord *ioh;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    QLIST_FOREACH(ioh, &io_handlers, next) {
Justin M. Forbes 252f3a
+        if (ioh->fd == fd) {
Justin M. Forbes 252f3a
+            return ioh;
Justin M. Forbes 252f3a
+        }
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
+    return NULL;
Justin M. Forbes 252f3a
+}
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+void enable_write_fd_handler(int fd, IOHandler *fd_write)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    IOHandlerRecord *ioh;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    ioh = find_iohandler(fd);
Justin M. Forbes 252f3a
+    if (!ioh) {
Justin M. Forbes 252f3a
+        return;
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    ioh->fd_write = fd_write;
Justin M. Forbes 252f3a
+}
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+void disable_write_fd_handler(int fd)
Justin M. Forbes 252f3a
+{
Justin M. Forbes 252f3a
+    IOHandlerRecord *ioh;
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    ioh = find_iohandler(fd);
Justin M. Forbes 252f3a
+    if (!ioh) {
Justin M. Forbes 252f3a
+        return;
Justin M. Forbes 252f3a
+    }
Justin M. Forbes 252f3a
+
Justin M. Forbes 252f3a
+    ioh->fd_write = NULL;
Justin M. Forbes 252f3a
+}
Justin M. Forbes 252f3a
 
Justin M. Forbes 252f3a
 /* XXX: fd_read_poll should be suppressed, but an API change is
Justin M. Forbes 252f3a
    necessary in the character devices to suppress fd_can_read(). */
Justin M. Forbes 252f3a
-- 
Justin M. Forbes 252f3a
1.7.3.2
Justin M. Forbes 252f3a