From: Amit Shah <amit.shah@redhat.com>
To: qemu list <qemu-devel@nongnu.org>
Cc: Amit Shah <amit.shah@redhat.com>,
Gerd Hoffmann <kraxel@redhat.com>,
Paul Brook <paul@codesourcery.com>
Subject: [Qemu-devel] [PATCH v2 3/5] iohandlers: Allow each iohandler to be enabled/disabled individually
Date: Thu, 13 Jan 2011 20:30:40 +0530 [thread overview]
Message-ID: <c3913ebb3dbb863ac1e7add91887f4fa6e676004.1294930723.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1294930723.git.amit.shah@redhat.com>
In-Reply-To: <cover.1294930723.git.amit.shah@redhat.com>
Each iohandler for an fd can now be individually enabled or disabled.
Signed-off-by: Amit Shah <amit.shah@redhat.com>
---
qemu-char.h | 4 +++
vl.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 79 insertions(+), 3 deletions(-)
diff --git a/qemu-char.h b/qemu-char.h
index 0ef83f4..e88a108 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -115,6 +115,10 @@ int assign_fd_handlers(int fd,
IOHandler *fd_write,
void *opaque);
void remove_fd_handlers(int fd);
+int set_read_poll_fd_action(int fd, bool enable);
+int set_read_fd_action(int fd, bool enable);
+int set_write_fd_action(int fd, bool enable);
+
int qemu_set_fd_handler2(int fd,
IOCanReadHandler *fd_read_poll,
IOHandler *fd_read,
diff --git a/vl.c b/vl.c
index 30256e1..b9c902a 100644
--- a/vl.c
+++ b/vl.c
@@ -1014,6 +1014,9 @@ typedef struct IOHandlerRecord {
IOHandler *fd_write;
int deleted;
void *opaque;
+ bool read_poll_enabled;
+ bool read_enabled;
+ bool write_enabled;
/* temporary data */
struct pollfd *ufd;
QLIST_ENTRY(IOHandlerRecord) next;
@@ -1035,6 +1038,57 @@ static IOHandlerRecord *get_iohandler(int fd)
}
/*
+ * Enable the fd_read_poll handler for fd if the fd_read_poll handler exists.
+ */
+int set_read_poll_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->read_poll_enabled = enable;
+
+ return 0;
+}
+
+/*
+ * Enable the fd_read handler for fd if the fd_read handler exists.
+ */
+int set_read_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->read_enabled = enable;
+
+ return 0;
+}
+
+/*
+ * Enable the fd_write handler for fd if the fd_write handler exists.
+ */
+int set_write_fd_action(int fd, bool enable)
+{
+ IOHandlerRecord *ioh;
+
+ ioh = get_iohandler(fd);
+
+ if (!ioh) {
+ return -1;
+ }
+ ioh->write_enabled = enable;
+
+ return 0;
+}
+
+/*
* Specify function pointers for the various IOHandlers for an fd here.
*
* XXX: fd_read_poll should be suppressed, but an API change is
@@ -1067,6 +1121,20 @@ int assign_fd_handlers(int fd,
ioh->opaque = opaque;
ioh->deleted = 0;
+ /*
+ * To maintain compatibility with the callers that expect all
+ * handlers to be enabled. Callers that wish for some handlers
+ * not to be enabled right away should ensure they call
+ * set_xx_fd_action(fd, false) after this call.
+ *
+ * Note: if gets threading and one day is capable of running
+ * main_loop_wait() in parallel to this function, ensure this call
+ * and any later set_xx_fd_action() calls can execute atomically.
+ */
+ set_read_poll_fd_action(fd, true);
+ set_read_fd_action(fd, true);
+ set_write_fd_action(fd, true);
+
return 0;
}
@@ -1079,6 +1147,10 @@ void remove_fd_handlers(int fd)
assign_fd_handlers(fd, NULL, NULL, NULL, NULL);
}
+/*
+ * TODO: Deprecate these two function calls in favour of
+ * assign_fd_handlers().
+ */
int qemu_set_fd_handler2(int fd,
IOCanReadHandler *fd_read_poll,
IOHandler *fd_read,
@@ -1349,14 +1421,14 @@ void main_loop_wait(int nonblocking)
QLIST_FOREACH(ioh, &io_handlers, next) {
if (ioh->deleted)
continue;
- if (ioh->fd_read &&
+ if (ioh->fd_read && ioh->read_enabled &&
(!ioh->fd_read_poll ||
- ioh->fd_read_poll(ioh->opaque) != 0)) {
+ (!ioh->read_poll_enabled || ioh->fd_read_poll(ioh->opaque) != 0))) {
FD_SET(ioh->fd, &rfds);
if (ioh->fd > nfds)
nfds = ioh->fd;
}
- if (ioh->fd_write) {
+ if (ioh->fd_write && ioh->write_enabled) {
FD_SET(ioh->fd, &wfds);
if (ioh->fd > nfds)
nfds = ioh->fd;
--
1.7.3.4
next prev parent reply other threads:[~2011-01-13 15:01 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-13 15:00 [Qemu-devel] [PATCH v2 0/5] iohandlers: Add support for enabling/disabling individual handlers Amit Shah
2011-01-13 15:00 ` [Qemu-devel] [PATCH v2 1/5] iohandlers: Avoid code duplication Amit Shah
2011-01-13 15:00 ` [Qemu-devel] [PATCH v2 2/5] iohandlers: Introduce assign_fd_handlers() and remove_fd_handlers Amit Shah
2011-01-13 15:00 ` Amit Shah [this message]
2011-01-13 15:00 ` [Qemu-devel] [PATCH v2 4/5] iohandlers: Enable an iohandler only if the associated handler exists Amit Shah
2011-01-13 15:00 ` [Qemu-devel] [PATCH v2 5/5] iohandlers: Add IOHandlerOps struct Amit Shah
2011-01-13 15:09 ` [Qemu-devel] Re: [PATCH v2 0/5] iohandlers: Add support for enabling/disabling individual handlers Gerd Hoffmann
2011-01-13 19:17 ` Anthony Liguori
2011-01-17 10:18 ` Amit Shah
2011-01-17 14:57 ` Anthony Liguori
2011-01-17 18:30 ` Michael Roth
2011-01-18 11:56 ` Amit Shah
2011-01-18 14:19 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c3913ebb3dbb863ac1e7add91887f4fa6e676004.1294930723.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=kraxel@redhat.com \
--cc=paul@codesourcery.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).