From patchwork Wed Feb 1 05:34:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 9548919 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2E26D60425 for ; Wed, 1 Feb 2017 05:39:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 211E72711E for ; Wed, 1 Feb 2017 05:39:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15C4D2838D; Wed, 1 Feb 2017 05:39:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6DB9F2711E for ; Wed, 1 Feb 2017 05:39:29 +0000 (UTC) Received: from localhost ([::1]:42827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYndg-0007rb-BN for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Feb 2017 00:39:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cYnZC-00044K-J8 for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cYnZB-0006W2-AK for qemu-devel@nongnu.org; Wed, 01 Feb 2017 00:34:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52380) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cYnZ7-0006UI-DY; Wed, 01 Feb 2017 00:34:45 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8624C3B722; Wed, 1 Feb 2017 05:34:45 +0000 (UTC) Received: from localhost (ovpn-116-86.phx2.redhat.com [10.3.116.86]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v115Yi8H007938 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 1 Feb 2017 00:34:45 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Wed, 1 Feb 2017 00:34:38 -0500 Message-Id: <20170201053440.26002-4-jcody@redhat.com> In-Reply-To: <20170201053440.26002-1-jcody@redhat.com> References: <20170201053440.26002-1-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 01 Feb 2017 05:34:45 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 3/5] sheepdog: do not use BlockAIOCB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Paolo Bonzini Sheepdog's AIOCB are completely internal entities for a group of requests and do not need dynamic allocation. Signed-off-by: Paolo Bonzini Message-id: 20161129113245.32724-4-pbonzini@redhat.com Signed-off-by: Jeff Cody --- block/sheepdog.c | 99 ++++++++++++++++++++++---------------------------------- 1 file changed, 39 insertions(+), 60 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index e0985df..33ded57 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -306,6 +306,7 @@ static inline size_t count_data_objs(const struct SheepdogInode *inode) } while (0) typedef struct SheepdogAIOCB SheepdogAIOCB; +typedef struct BDRVSheepdogState BDRVSheepdogState; typedef struct AIOReq { SheepdogAIOCB *aiocb; @@ -334,7 +335,7 @@ enum AIOCBState { || y->max_affect_data_idx < x->min_affect_data_idx)) struct SheepdogAIOCB { - BlockAIOCB common; + BDRVSheepdogState *s; QEMUIOVector *qiov; @@ -362,7 +363,7 @@ struct SheepdogAIOCB { QLIST_ENTRY(SheepdogAIOCB) aiocb_siblings; }; -typedef struct BDRVSheepdogState { +struct BDRVSheepdogState { BlockDriverState *bs; AioContext *aio_context; @@ -389,7 +390,7 @@ typedef struct BDRVSheepdogState { CoQueue overlapping_queue; QLIST_HEAD(inflight_aiocb_head, SheepdogAIOCB) inflight_aiocb_head; -} BDRVSheepdogState; +}; typedef struct BDRVSheepdogReopenState { int fd; @@ -488,20 +489,15 @@ static inline void free_aio_req(BDRVSheepdogState *s, AIOReq *aio_req) acb->nr_pending--; } -static const AIOCBInfo sd_aiocb_info = { - .aiocb_size = sizeof(SheepdogAIOCB), -}; - -static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, - int64_t sector_num, int nb_sectors) +static void sd_aio_setup(SheepdogAIOCB *acb, BDRVSheepdogState *s, + QEMUIOVector *qiov, int64_t sector_num, int nb_sectors, + int type) { - SheepdogAIOCB *acb; uint32_t object_size; - BDRVSheepdogState *s = bs->opaque; object_size = (UINT32_C(1) << s->inode.block_size_shift); - acb = qemu_aio_get(&sd_aiocb_info, bs, NULL, NULL); + acb->s = s; acb->qiov = qiov; @@ -518,8 +514,7 @@ static SheepdogAIOCB *sd_aio_setup(BlockDriverState *bs, QEMUIOVector *qiov, acb->min_dirty_data_idx = UINT32_MAX; acb->max_dirty_data_idx = 0; - - return acb; + acb->aiocb_type = type; } /* Return -EIO in case of error, file descriptor on success */ @@ -1967,7 +1962,7 @@ static int sd_truncate(BlockDriverState *bs, int64_t offset) */ static void coroutine_fn sd_write_done(SheepdogAIOCB *acb) { - BDRVSheepdogState *s = acb->common.bs->opaque; + BDRVSheepdogState *s = acb->s; struct iovec iov; AIOReq *aio_req; uint32_t offset, data_len, mn, mx; @@ -2105,16 +2100,15 @@ out: * Returns 1 when we need to wait a response, 0 when there is no sent * request and -errno in error cases. */ -static void coroutine_fn sd_co_rw_vector(void *p) +static void coroutine_fn sd_co_rw_vector(SheepdogAIOCB *acb) { - SheepdogAIOCB *acb = p; int ret = 0; unsigned long len, done = 0, total = acb->nb_sectors * BDRV_SECTOR_SIZE; unsigned long idx; uint32_t object_size; uint64_t oid; uint64_t offset; - BDRVSheepdogState *s = acb->common.bs->opaque; + BDRVSheepdogState *s = acb->s; SheepdogInode *inode = &s->inode; AIOReq *aio_req; @@ -2222,7 +2216,7 @@ static bool check_overlapping_aiocb(BDRVSheepdogState *s, SheepdogAIOCB *aiocb) static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { - SheepdogAIOCB *acb; + SheepdogAIOCB acb; int ret; int64_t offset = (sector_num + nb_sectors) * BDRV_SECTOR_SIZE; BDRVSheepdogState *s = bs->opaque; @@ -2234,76 +2228,65 @@ static coroutine_fn int sd_co_writev(BlockDriverState *bs, int64_t sector_num, } } - acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); - acb->aiocb_type = AIOCB_WRITE_UDATA; + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_WRITE_UDATA); retry: - if (check_overlapping_aiocb(s, acb)) { + if (check_overlapping_aiocb(s, &acb)) { qemu_co_queue_wait(&s->overlapping_queue); goto retry; } - sd_co_rw_vector(acb); - sd_write_done(acb); + sd_co_rw_vector(&acb); + sd_write_done(&acb); - QLIST_REMOVE(acb, aiocb_siblings); + QLIST_REMOVE(&acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - ret = acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } static coroutine_fn int sd_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { - SheepdogAIOCB *acb; - int ret; + SheepdogAIOCB acb; BDRVSheepdogState *s = bs->opaque; - acb = sd_aio_setup(bs, qiov, sector_num, nb_sectors); - acb->aiocb_type = AIOCB_READ_UDATA; + sd_aio_setup(&acb, s, qiov, sector_num, nb_sectors, AIOCB_READ_UDATA); retry: - if (check_overlapping_aiocb(s, acb)) { + if (check_overlapping_aiocb(s, &acb)) { qemu_co_queue_wait(&s->overlapping_queue); goto retry; } - sd_co_rw_vector(acb); + sd_co_rw_vector(&acb); - QLIST_REMOVE(acb, aiocb_siblings); + QLIST_REMOVE(&acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - ret = acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } static int coroutine_fn sd_co_flush_to_disk(BlockDriverState *bs) { BDRVSheepdogState *s = bs->opaque; - SheepdogAIOCB *acb; - int ret; + SheepdogAIOCB acb; AIOReq *aio_req; if (s->cache_flags != SD_FLAG_CMD_CACHE) { return 0; } - acb = sd_aio_setup(bs, NULL, 0, 0); - acb->aiocb_type = AIOCB_FLUSH_CACHE; + sd_aio_setup(&acb, s, NULL, 0, 0, AIOCB_FLUSH_CACHE); - acb->nr_pending++; - aio_req = alloc_aio_req(s, acb, vid_to_vdi_oid(s->inode.vdi_id), + acb.nr_pending++; + aio_req = alloc_aio_req(s, &acb, vid_to_vdi_oid(s->inode.vdi_id), 0, 0, 0, false, 0, 0); QLIST_INSERT_HEAD(&s->inflight_aio_head, aio_req, aio_siblings); - add_aio_request(s, aio_req, NULL, 0, acb->aiocb_type); + add_aio_request(s, aio_req, NULL, 0, acb.aiocb_type); - if (--acb->nr_pending) { + if (--acb.nr_pending) { qemu_coroutine_yield(); } - ret = acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } static int sd_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) @@ -2737,9 +2720,8 @@ static int sd_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, int count) { - SheepdogAIOCB *acb; + SheepdogAIOCB acb; BDRVSheepdogState *s = bs->opaque; - int ret; QEMUIOVector discard_iov; struct iovec iov; uint32_t zero = 0; @@ -2757,23 +2739,20 @@ static coroutine_fn int sd_co_pdiscard(BlockDriverState *bs, int64_t offset, if (!QEMU_IS_ALIGNED(offset | count, BDRV_SECTOR_SIZE)) { return -ENOTSUP; } - acb = sd_aio_setup(bs, &discard_iov, offset >> BDRV_SECTOR_BITS, - count >> BDRV_SECTOR_BITS); - acb->aiocb_type = AIOCB_DISCARD_OBJ; + sd_aio_setup(&acb, s, &discard_iov, offset >> BDRV_SECTOR_BITS, + count >> BDRV_SECTOR_BITS, AIOCB_DISCARD_OBJ); retry: - if (check_overlapping_aiocb(s, acb)) { + if (check_overlapping_aiocb(s, &acb)) { qemu_co_queue_wait(&s->overlapping_queue); goto retry; } - sd_co_rw_vector(acb); + sd_co_rw_vector(&acb); - QLIST_REMOVE(acb, aiocb_siblings); + QLIST_REMOVE(&acb, aiocb_siblings); qemu_co_queue_restart_all(&s->overlapping_queue); - ret = acb->ret; - qemu_aio_unref(acb); - return ret; + return acb.ret; } static coroutine_fn int64_t