From patchwork Thu Jan 13 12:14:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arun Bharadwaj X-Patchwork-Id: 78731 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 D50E2B6EF1 for ; Thu, 13 Jan 2011 23:18:39 +1100 (EST) Received: from localhost ([127.0.0.1]:38621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdM8S-0000sk-V0 for incoming@patchwork.ozlabs.org; Thu, 13 Jan 2011 07:18:37 -0500 Received: from [140.186.70.92] (port=57644 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PdM4M-0007Y3-7d for qemu-devel@nongnu.org; Thu, 13 Jan 2011 07:14:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PdM4L-0001cy-13 for qemu-devel@nongnu.org; Thu, 13 Jan 2011 07:14:22 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:34041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PdM4K-0001cd-Cu for qemu-devel@nongnu.org; Thu, 13 Jan 2011 07:14:20 -0500 Received: from d23relay04.au.ibm.com (d23relay04.au.ibm.com [202.81.31.246]) by e23smtp07.au.ibm.com (8.14.4/8.13.1) with ESMTP id p0DCEJ8h018426 for ; Thu, 13 Jan 2011 23:14:19 +1100 Received: from d23av02.au.ibm.com (d23av02.au.ibm.com [9.190.235.138]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p0DCEIat2199634 for ; Thu, 13 Jan 2011 23:14:18 +1100 Received: from d23av02.au.ibm.com (loopback [127.0.0.1]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p0DCEIjQ019776 for ; Thu, 13 Jan 2011 23:14:18 +1100 Received: from localhost6.localdomain6 ([9.124.35.18]) by d23av02.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p0DCEHX9019753; Thu, 13 Jan 2011 23:14:17 +1100 To: qemu-devel@nongnu.org From: Arun R Bharadwaj Date: Thu, 13 Jan 2011 17:44:17 +0530 Message-ID: <20110113121416.4487.41177.stgit@localhost6.localdomain6> In-Reply-To: <20110113120837.4487.95784.stgit@localhost6.localdomain6> References: <20110113120837.4487.95784.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: kwolf@redhat.com, aliguori@linux.vnet.ibm.com, jvrao@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 01/12] Add aiocb_mutex and aiocb_completion. 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 This patch adds the aiocb_mutex to protect aiocb. This patch also removes the infinite loop present in paio_cancel. Since there can only be one cancellation at a time, we need to introduce a condition variable. For this, we need a global aiocb_completion condition variable. This patch also adds the Makefile entry to compile qemu-thread.c when CONFIG_POSIX is set, instead of the unused CONFIG_THREAD. Signed-off-by: Arun R Bharadwaj --- Makefile.objs | 2 +- posix-aio-compat.c | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index cd5a24b..3b7ec27 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -9,6 +9,7 @@ qobject-obj-y += qerror.o block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o block-obj-y += nbd.o block.o aio.o aes.o osdep.o qemu-config.o +block-obj-$(CONFIG_POSIX) += qemu-thread.o block-obj-$(CONFIG_POSIX) += posix-aio-compat.o block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o @@ -124,7 +125,6 @@ endif common-obj-y += $(addprefix ui/, $(ui-obj-y)) common-obj-y += iov.o acl.o -common-obj-$(CONFIG_THREAD) += qemu-thread.o common-obj-y += notify.o event_notifier.o common-obj-y += qemu-timer.o diff --git a/posix-aio-compat.c b/posix-aio-compat.c index 7b862b5..82862ec 100644 --- a/posix-aio-compat.c +++ b/posix-aio-compat.c @@ -27,9 +27,12 @@ #include "qemu-common.h" #include "trace.h" #include "block_int.h" +#include "qemu-thread.h" #include "block/raw-posix-aio.h" +static QemuMutex aiocb_mutex; +static QemuCond aiocb_completion; struct qemu_paiocb { BlockDriverAIOCB common; @@ -351,10 +354,14 @@ static void *aio_thread(void *unused) } mutex_lock(&lock); - aiocb->ret = ret; idle_threads++; mutex_unlock(&lock); + qemu_mutex_lock(&aiocb_mutex); + aiocb->ret = ret; + qemu_cond_broadcast(&aiocb_completion); + qemu_mutex_unlock(&aiocb_mutex); + if (kill(pid, aiocb->ev_signo)) die("kill failed"); } @@ -383,8 +390,11 @@ static void spawn_thread(void) static void qemu_paio_submit(struct qemu_paiocb *aiocb) { + qemu_mutex_lock(&aiocb_mutex); aiocb->ret = -EINPROGRESS; aiocb->active = 0; + qemu_mutex_unlock(&aiocb_mutex); + mutex_lock(&lock); if (idle_threads == 0 && cur_threads < max_threads) spawn_thread(); @@ -397,9 +407,9 @@ static ssize_t qemu_paio_return(struct qemu_paiocb *aiocb) { ssize_t ret; - mutex_lock(&lock); + qemu_mutex_lock(&aiocb_mutex); ret = aiocb->ret; - mutex_unlock(&lock); + qemu_mutex_unlock(&aiocb_mutex); return ret; } @@ -536,22 +546,26 @@ static void paio_cancel(BlockDriverAIOCB *blockacb) struct qemu_paiocb *acb = (struct qemu_paiocb *)blockacb; int active = 0; - mutex_lock(&lock); + qemu_mutex_lock(&aiocb_mutex); if (!acb->active) { QTAILQ_REMOVE(&request_list, acb, node); acb->ret = -ECANCELED; } else if (acb->ret == -EINPROGRESS) { active = 1; } - mutex_unlock(&lock); - if (active) { - /* fail safe: if the aio could not be canceled, we wait for - it */ - while (qemu_paio_error(acb) == EINPROGRESS) - ; + if (!active) { + acb->ret = -ECANCELED; + } else { + while (acb->ret == -EINPROGRESS) { + /* + * fail safe: if the aio could not be canceled, + * we wait for it + */ + qemu_cond_wait(&aiocb_completion, &aiocb_mutex); + } } - + qemu_mutex_unlock(&aiocb_mutex); paio_remove(acb); } @@ -623,6 +637,9 @@ int paio_init(void) if (posix_aio_state) return 0; + qemu_mutex_init(&aiocb_mutex); + qemu_cond_init(&aiocb_completion); + s = qemu_malloc(sizeof(PosixAioState)); sigfillset(&act.sa_mask);