From patchwork Thu Jan 13 13:00:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Shah X-Patchwork-Id: 78747 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E3CD4B70DA for ; Fri, 14 Jan 2011 00:02:57 +1100 (EST) Received: from localhost ([127.0.0.1]:38157 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdMoz-0006sm-5h for incoming@patchwork.ozlabs.org; Thu, 13 Jan 2011 08:02:33 -0500 Received: from [140.186.70.92] (port=42226 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdMn6-0005q4-Q6 for qemu-devel@nongnu.org; Thu, 13 Jan 2011 08:00:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdMn4-0004Xx-Fl for qemu-devel@nongnu.org; Thu, 13 Jan 2011 08:00:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:29559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdMn4-0004Xb-4w for qemu-devel@nongnu.org; Thu, 13 Jan 2011 08:00:34 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id p0DD0N2r010133 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 13 Jan 2011 08:00:23 -0500 Received: from localhost (dhcp193-64.pnq.redhat.com [10.65.193.64]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p0DD0Lgm022794; Thu, 13 Jan 2011 08:00:22 -0500 From: Amit Shah To: qemu list Date: Thu, 13 Jan 2011 18:30:08 +0530 Message-Id: <1bdf0a5a5de06cfb332ac17c439ef79cabb835db.1294923288.git.amit.shah@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Amit Shah , Gerd Hoffmann , Paul Brook Subject: [Qemu-devel] [PATCH 3/5] iohandlers: Allow each iohandler to be enabled/disabled individually X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Each iohandler for an fd can now be individually enabled or disabled. Signed-off-by: Amit Shah --- qemu-char.h | 4 ++++ vl.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 4 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 38e0a3c..a0b14b5 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; @@ -1062,6 +1065,7 @@ int assign_fd_handlers(int fd, ioh->fd_write = fd_write; ioh->opaque = opaque; ioh->deleted = 0; + ioh->read_poll_enabled = ioh->read_enabled = ioh->write_enabled = false; return 0; } @@ -1071,13 +1075,59 @@ void remove_fd_handlers(int fd) assign_fd_handlers(fd, NULL, NULL, NULL, NULL); } +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; +} + +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; +} + +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; +} + int qemu_set_fd_handler2(int fd, IOCanReadHandler *fd_read_poll, IOHandler *fd_read, IOHandler *fd_write, void *opaque) { - return assign_fd_handlers(fd, fd_read_poll, fd_read, fd_write, opaque); + assign_fd_handlers(fd, fd_read_poll, fd_read, fd_write, opaque); + set_read_poll_fd_action(fd, true); + set_read_fd_action(fd, true); + set_write_fd_action(fd, true); + return 0; } int qemu_set_fd_handler(int fd, @@ -1341,14 +1391,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;