Received: from eggs.gnu.org ([2001:4830:134:3::10]:49730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZV0ts-0005qw-PY for qemu-devel@nongnu.org; Thu, 27 Aug 2015 13:23:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZV0tp-00056m-IO for qemu-devel@nongnu.org; Thu, 27 Aug 2015 13:23:44 -0400 Date: Thu, 27 Aug 2015 18:23:38 +0100 From: Stefan Hajnoczi Message-ID: <20150827172338.GG4917@stefanha-thinkpad.redhat.com> References: <1438144934-23619-1-git-send-email-famz@redhat.com> <1438144934-23619-8-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438144934-23619-8-git-send-email-famz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v2 07/11] aio-posix: introduce aio_{disable, enable}_clients List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, pbonzini@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, stefanha@redhat.com On Wed, Jul 29, 2015 at 12:42:10PM +0800, Fam Zheng wrote: > +void aio_disable_enable_clients(AioContext *ctx, int clients_mask, > + bool is_disable) > +{ > + AioHandler *node; > + aio_context_acquire(ctx); > + > + QLIST_FOREACH(node, &ctx->aio_handlers, node) { > + if (!node->deleted && node->type & clients_mask) { > + node->disable_cnt += is_disable ? 1 : -1; > + } > + } > + aio_context_release(ctx); > +} If someone adds an fd of a disabled type *after* the call to aio_disable_clients() then it won't be disabled. Another approach is to keep an array of counters per AioContext and check the counters during aio_poll() when deciding which fds to monitor. Also, this function acquires/releases AioContext so it's worth mentioning in the doc comments that this function is thread-safe.