From patchwork Thu Mar 17 15:56:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8612721 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BBF279F6E1 for ; Thu, 17 Mar 2016 16:06:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3280820361 for ; Thu, 17 Mar 2016 16:06:03 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 5FA2420351 for ; Thu, 17 Mar 2016 16:06:02 +0000 (UTC) Received: from localhost ([::1]:36224 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agaQz-0004Fq-Oo for patchwork-qemu-devel@patchwork.kernel.org; Thu, 17 Mar 2016 12:06:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38097) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agaId-0002iZ-Vh for qemu-devel@nongnu.org; Thu, 17 Mar 2016 11:57:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1agaIc-0001rb-Rm for qemu-devel@nongnu.org; Thu, 17 Mar 2016 11:57:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51315) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1agaIW-0001oT-3W; Thu, 17 Mar 2016 11:57:16 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id A893281F03; Thu, 17 Mar 2016 15:57:15 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-71.ams2.redhat.com [10.36.116.71]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2HFuj1S010106; Thu, 17 Mar 2016 11:57:14 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 17 Mar 2016 16:56:35 +0100 Message-Id: <1458230202-29136-23-git-send-email-kwolf@redhat.com> In-Reply-To: <1458230202-29136-1-git-send-email-kwolf@redhat.com> References: <1458230202-29136-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PULL 22/29] block: Use blk_co_pwritev() for blk_write() 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Kevin Wolf --- block/block-backend.c | 39 ++++++++++++++++++++++++++++++--------- block/io.c | 5 +---- include/block/block_int.h | 3 +++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index c058785..5b15475 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -707,6 +707,18 @@ static int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, return bdrv_co_do_preadv(blk_bs(blk), offset, bytes, qiov, flags); } +static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, + unsigned int bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags) +{ + int ret = blk_check_byte_request(blk, offset, bytes); + if (ret < 0) { + return ret; + } + + return bdrv_co_do_pwritev(blk_bs(blk), offset, bytes, qiov, flags); +} + typedef struct BlkRwCo { BlockBackend *blk; int64_t offset; @@ -723,8 +735,16 @@ static void blk_read_entry(void *opaque) rwco->qiov, rwco->flags); } -int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf, - int nb_sectors) +static void blk_write_entry(void *opaque) +{ + BlkRwCo *rwco = opaque; + + rwco->ret = blk_co_pwritev(rwco->blk, rwco->offset, rwco->qiov->size, + rwco->qiov, rwco->flags); +} + +static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf, + int nb_sectors, CoroutineEntry co_entry) { AioContext *aio_context; QEMUIOVector qiov; @@ -749,7 +769,7 @@ int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf, .ret = NOT_DONE, }; - co = qemu_coroutine_create(blk_read_entry); + co = qemu_coroutine_create(co_entry); qemu_coroutine_enter(co, &rwco); aio_context = blk_get_aio_context(blk); @@ -760,6 +780,12 @@ int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf, return rwco.ret; } +int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf, + int nb_sectors) +{ + return blk_rw(blk, sector_num, buf, nb_sectors, blk_read_entry); +} + int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int nb_sectors) { @@ -774,12 +800,7 @@ int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf, int nb_sectors) { - int ret = blk_check_request(blk, sector_num, nb_sectors); - if (ret < 0) { - return ret; - } - - return bdrv_write(blk_bs(blk), sector_num, buf, nb_sectors); + return blk_rw(blk, sector_num, (uint8_t*) buf, nb_sectors, blk_write_entry); } int blk_write_zeroes(BlockBackend *blk, int64_t sector_num, diff --git a/block/io.c b/block/io.c index c7084e4..aa8537c 100644 --- a/block/io.c +++ b/block/io.c @@ -44,9 +44,6 @@ static int coroutine_fn bdrv_co_readv_em(BlockDriverState *bs, static int coroutine_fn bdrv_co_writev_em(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *iov); -static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, - int64_t offset, unsigned int bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); static BlockAIOCB *bdrv_co_aio_rw_vector(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, @@ -1281,7 +1278,7 @@ fail: /* * Handle a write request in coroutine context */ -static int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, +int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/include/block/block_int.h b/include/block/block_int.h index b78be8d..ba6e9ac 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -511,6 +511,9 @@ void bdrv_setup_io_funcs(BlockDriver *bdrv); int coroutine_fn bdrv_co_do_preadv(BlockDriverState *bs, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); +int coroutine_fn bdrv_co_do_pwritev(BlockDriverState *bs, + int64_t offset, unsigned int bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); int get_tmp_filename(char *filename, int size); BlockDriver *bdrv_probe_all(const uint8_t *buf, int buf_size,