From patchwork Tue Sep 18 18:53:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 184799 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8121E2C0091 for ; Wed, 19 Sep 2012 04:53:59 +1000 (EST) Received: from localhost ([::1]:50523 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE2vl-0001pk-4b for incoming@patchwork.ozlabs.org; Tue, 18 Sep 2012 14:53:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE2vV-0001gT-03 for qemu-devel@nongnu.org; Tue, 18 Sep 2012 14:53:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TE2vT-0004P6-U0 for qemu-devel@nongnu.org; Tue, 18 Sep 2012 14:53:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TE2vT-0004P2-KS for qemu-devel@nongnu.org; Tue, 18 Sep 2012 14:53:39 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8IIradR006768 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 18 Sep 2012 14:53:36 -0400 Received: from localhost (ovpn-112-22.phx2.redhat.com [10.3.112.22]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8IIrY5X024332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Tue, 18 Sep 2012 14:53:35 -0400 From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 18 Sep 2012 14:53:09 -0400 Message-Id: <1c38c5ca7393821314d988235d7476141bdf3882.1347993885.git.jcody@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@gmail.com, eblake@redhat.com, supriyak@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v3 04/19] block: move aio initialization into a helper function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move AIO initialization for raw-posix block driver into a helper function. In addition to just code motion, the aio_ctx pointer is checked for NULL, prior to calling laio_init(), to make sure laio_init() is only run once. Signed-off-by: Jeff Cody --- block/raw-posix.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 6be20b1..ee55f79 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -185,6 +185,40 @@ static int raw_normalize_devicepath(const char **filename) } #endif +static int raw_set_aio(void **aio_ctx, int *use_aio, int bdrv_flags) +{ +#ifdef CONFIG_LINUX_AIO + int ret = -1; + assert(aio_ctx != NULL); + assert(use_aio != NULL); + /* + * Currently Linux do AIO only for files opened with O_DIRECT + * specified so check NOCACHE flag too + */ + if ((bdrv_flags & (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) == + (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) { + + /* if non-NULL, laio_init() has already been run */ + if (*aio_ctx == NULL) { + *aio_ctx = laio_init(); + if (!*aio_ctx) { + goto error; + } + } + *use_aio = 1; + } else { + *use_aio = 0; + } + + ret = 0; + +error: + return ret; +#else + return 0; +#endif +} + static int raw_open_common(BlockDriverState *bs, const char *filename, int bdrv_flags, int open_flags) { @@ -239,26 +273,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, goto out_free_buf; } -#ifdef CONFIG_LINUX_AIO - /* - * Currently Linux do AIO only for files opened with O_DIRECT - * specified so check NOCACHE flag too - */ - if ((bdrv_flags & (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) == - (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) { - - s->aio_ctx = laio_init(); - if (!s->aio_ctx) { - goto out_free_buf; - } - s->use_aio = 1; - } else -#endif - { -#ifdef CONFIG_LINUX_AIO - s->use_aio = 0; -#endif - } + raw_set_aio(&s->aio_ctx, &s->use_aio, bdrv_flags); #ifdef CONFIG_XFS if (platform_test_xfs_fd(s->fd)) {