From patchwork Tue Aug 23 13:21:08 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frediano Ziglio X-Patchwork-Id: 111100 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1F10BB6F94 for ; Tue, 23 Aug 2011 23:21:32 +1000 (EST) Received: from localhost ([::1]:34847 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvqv3-0008Rc-Ah for incoming@patchwork.ozlabs.org; Tue, 23 Aug 2011 09:21:29 -0400 Received: from eggs.gnu.org ([140.186.70.92]:58303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvquu-0008F9-Q0 for qemu-devel@nongnu.org; Tue, 23 Aug 2011 09:21:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qvqut-0006lP-Ft for qemu-devel@nongnu.org; Tue, 23 Aug 2011 09:21:20 -0400 Received: from mail-gy0-f173.google.com ([209.85.160.173]:59783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvqut-0006lL-6n for qemu-devel@nongnu.org; Tue, 23 Aug 2011 09:21:19 -0400 Received: by gyd12 with SMTP id 12so86989gyd.4 for ; Tue, 23 Aug 2011 06:21:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=KdGYwTMux98rUz39/W7mFFLJOoYmS8zvHxp8GLV9gVM=; b=Z6RmdLY2jbOu6UH5/DyaCF19fmocBAN8UukqAeTiFEzZN1Cbv1pRl5uZxUbebo3ArQ olcK3aSwKc0QqtTiFksY1lAtuCkUGhbSqsTQtykSQr+78dZ8EEqnwOUdkolrbGEgO3eP k8gWA68u0r3J1FiebnTc7AtVz8MNw1BprBR3c= Received: by 10.150.72.29 with SMTP id u29mr4000873yba.235.1314105678084; Tue, 23 Aug 2011 06:21:18 -0700 (PDT) Received: from obol602.omnitel.it (tor-exit-router37-readme.formlessnetworking.net [199.48.147.37]) by mx.google.com with ESMTPS id a29sm227805yhj.3.2011.08.23.06.21.10 (version=SSLv3 cipher=OTHER); Tue, 23 Aug 2011 06:21:16 -0700 (PDT) From: Frediano Ziglio To: kwolf@redhat.com Date: Tue, 23 Aug 2011 15:21:08 +0200 Message-Id: <1314105682-28396-2-git-send-email-freddy77@gmail.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1314105682-28396-1-git-send-email-freddy77@gmail.com> References: <1314105682-28396-1-git-send-email-freddy77@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.160.173 Cc: qemu-devel@nongnu.org, Frediano Ziglio Subject: [Qemu-devel] [PATCH v3 01/15] qcow: allocate QCowAIOCB structure using stack 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 instead of calling qemi_aio_get use stack Signed-off-by: Frediano Ziglio --- block/qcow.c | 52 ++++++++++++++++------------------------------------ block/qcow2.c | 38 +++++++++++--------------------------- 2 files changed, 27 insertions(+), 63 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index e155d3c..b4506b4 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -503,28 +503,12 @@ typedef struct QCowAIOCB { BlockDriverAIOCB *hd_aiocb; } QCowAIOCB; -static void qcow_aio_cancel(BlockDriverAIOCB *blockacb) -{ - QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common); - if (acb->hd_aiocb) - bdrv_aio_cancel(acb->hd_aiocb); - qemu_aio_release(acb); -} - -static AIOPool qcow_aio_pool = { - .aiocb_size = sizeof(QCowAIOCB), - .cancel = qcow_aio_cancel, -}; - static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, - int is_write) + int is_write, QCowAIOCB *acb) { - QCowAIOCB *acb; - - acb = qemu_aio_get(&qcow_aio_pool, bs, NULL, NULL); - if (!acb) - return NULL; + memset(acb, 0, sizeof(*acb)); + acb->common.bs = bs; acb->hd_aiocb = NULL; acb->sector_num = sector_num; acb->qiov = qiov; @@ -543,9 +527,8 @@ static QCowAIOCB *qcow_aio_setup(BlockDriverState *bs, return acb; } -static int qcow_aio_read_cb(void *opaque) +static int qcow_aio_read_cb(QCowAIOCB *acb) { - QCowAIOCB *acb = opaque; BlockDriverState *bs = acb->common.bs; BDRVQcowState *s = bs->opaque; int index_in_cluster; @@ -634,29 +617,27 @@ static int qcow_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; - QCowAIOCB *acb; + QCowAIOCB acb; int ret; - acb = qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 0); + qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 0, &acb); qemu_co_mutex_lock(&s->lock); do { - ret = qcow_aio_read_cb(acb); + ret = qcow_aio_read_cb(&acb); } while (ret > 0); qemu_co_mutex_unlock(&s->lock); - if (acb->qiov->niov > 1) { - qemu_iovec_from_buffer(acb->qiov, acb->orig_buf, acb->qiov->size); - qemu_vfree(acb->orig_buf); + if (acb.qiov->niov > 1) { + qemu_iovec_from_buffer(acb.qiov, acb.orig_buf, acb.qiov->size); + qemu_vfree(acb.orig_buf); } - qemu_aio_release(acb); return ret; } -static int qcow_aio_write_cb(void *opaque) +static int qcow_aio_write_cb(QCowAIOCB *acb) { - QCowAIOCB *acb = opaque; BlockDriverState *bs = acb->common.bs; BDRVQcowState *s = bs->opaque; int index_in_cluster; @@ -714,23 +695,22 @@ static int qcow_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; - QCowAIOCB *acb; + QCowAIOCB acb; int ret; s->cluster_cache_offset = -1; /* disable compressed cache */ - acb = qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 1); + qcow_aio_setup(bs, sector_num, qiov, nb_sectors, 1, &acb); qemu_co_mutex_lock(&s->lock); do { - ret = qcow_aio_write_cb(acb); + ret = qcow_aio_write_cb(&acb); } while (ret > 0); qemu_co_mutex_unlock(&s->lock); - if (acb->qiov->niov > 1) { - qemu_vfree(acb->orig_buf); + if (acb.qiov->niov > 1) { + qemu_vfree(acb.orig_buf); } - qemu_aio_release(acb); return ret; } diff --git a/block/qcow2.c b/block/qcow2.c index bfff6cd..bb6c75e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -388,17 +388,6 @@ typedef struct QCowAIOCB { QLIST_ENTRY(QCowAIOCB) next_depend; } QCowAIOCB; -static void qcow2_aio_cancel(BlockDriverAIOCB *blockacb) -{ - QCowAIOCB *acb = container_of(blockacb, QCowAIOCB, common); - qemu_aio_release(acb); -} - -static AIOPool qcow2_aio_pool = { - .aiocb_size = sizeof(QCowAIOCB), - .cancel = qcow2_aio_cancel, -}; - /* * Returns 0 when the request is completed successfully, 1 when there is still * a part left to do and -errno in error cases. @@ -528,13 +517,10 @@ static int qcow2_aio_read_cb(QCowAIOCB *acb) static QCowAIOCB *qcow2_aio_setup(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, - void *opaque, int is_write) + void *opaque, int is_write, QCowAIOCB *acb) { - QCowAIOCB *acb; - - acb = qemu_aio_get(&qcow2_aio_pool, bs, cb, opaque); - if (!acb) - return NULL; + memset(acb, 0, sizeof(*acb)); + acb->common.bs = bs; acb->sector_num = sector_num; acb->qiov = qiov; acb->is_write = is_write; @@ -554,19 +540,18 @@ static int qcow2_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; - QCowAIOCB *acb; + QCowAIOCB acb; int ret; - acb = qcow2_aio_setup(bs, sector_num, qiov, nb_sectors, NULL, NULL, 0); + qcow2_aio_setup(bs, sector_num, qiov, nb_sectors, NULL, NULL, 0, &acb); qemu_co_mutex_lock(&s->lock); do { - ret = qcow2_aio_read_cb(acb); + ret = qcow2_aio_read_cb(&acb); } while (ret > 0); qemu_co_mutex_unlock(&s->lock); - qemu_iovec_destroy(&acb->hd_qiov); - qemu_aio_release(acb); + qemu_iovec_destroy(&acb.hd_qiov); return ret; } @@ -670,20 +655,19 @@ static int qcow2_co_writev(BlockDriverState *bs, QEMUIOVector *qiov) { BDRVQcowState *s = bs->opaque; - QCowAIOCB *acb; + QCowAIOCB acb; int ret; - acb = qcow2_aio_setup(bs, sector_num, qiov, nb_sectors, NULL, NULL, 1); + qcow2_aio_setup(bs, sector_num, qiov, nb_sectors, NULL, NULL, 1, &acb); s->cluster_cache_offset = -1; /* disable compressed cache */ qemu_co_mutex_lock(&s->lock); do { - ret = qcow2_aio_write_cb(acb); + ret = qcow2_aio_write_cb(&acb); } while (ret > 0); qemu_co_mutex_unlock(&s->lock); - qemu_iovec_destroy(&acb->hd_qiov); - qemu_aio_release(acb); + qemu_iovec_destroy(&acb.hd_qiov); return ret; }