From patchwork Wed Nov 3 14:29:44 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 70009 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 4DCE5B70E7 for ; Thu, 4 Nov 2010 01:31:18 +1100 (EST) Received: from localhost ([127.0.0.1]:55962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDeMt-00022r-Q3 for incoming@patchwork.ozlabs.org; Wed, 03 Nov 2010 10:31:15 -0400 Received: from [140.186.70.92] (port=47251 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDeLZ-0001Xz-48 for qemu-devel@nongnu.org; Wed, 03 Nov 2010 10:29:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDeLX-0006Jy-Uj for qemu-devel@nongnu.org; Wed, 03 Nov 2010 10:29:52 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:48041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDeLX-0006Jb-NV for qemu-devel@nongnu.org; Wed, 03 Nov 2010 10:29:51 -0400 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id oA3ETnMo004300 for ; Wed, 3 Nov 2010 14:29:49 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oA3ETp622891818 for ; Wed, 3 Nov 2010 14:29:51 GMT Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oA3ETmQB011257 for ; Wed, 3 Nov 2010 08:29:48 -0600 Received: from stefan-thinkpad.ibm.com (sig-9-146-160-131.uk.ibm.com [9.146.160.131]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id oA3ETkM1011234; Wed, 3 Nov 2010 08:29:47 -0600 From: Stefan Hajnoczi To: Date: Wed, 3 Nov 2010 14:29:44 +0000 Message-Id: <1288794584-6099-1-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.2.3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Stefan Hajnoczi , Juan Quintela Subject: [Qemu-devel] [PATCH] Delete IOHandlers after potentially running them 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 Since commit 4bed9837309e58d208183f81d8344996744292cf an .fd_read() handler that deletes its IOHandler is exposed to .fd_write() being called on the deleted IOHandler. This patch fixes deletion so that .fd_read() and .fd_write() are never called on an IOHandler that is marked for deletion. Signed-off-by: Stefan Hajnoczi --- vl.c | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/vl.c b/vl.c index 7038952..6f56123 100644 --- a/vl.c +++ b/vl.c @@ -1252,17 +1252,18 @@ void main_loop_wait(int nonblocking) IOHandlerRecord *pioh; QLIST_FOREACH_SAFE(ioh, &io_handlers, next, pioh) { - if (ioh->deleted) { - QLIST_REMOVE(ioh, next); - qemu_free(ioh); - continue; - } - if (ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { + if (!ioh->deleted && ioh->fd_read && FD_ISSET(ioh->fd, &rfds)) { ioh->fd_read(ioh->opaque); } - if (ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) { + if (!ioh->deleted && ioh->fd_write && FD_ISSET(ioh->fd, &wfds)) { ioh->fd_write(ioh->opaque); } + + /* Do this last in case read/write handlers marked it for deletion */ + if (ioh->deleted) { + QLIST_REMOVE(ioh, next); + qemu_free(ioh); + } } }