From patchwork Wed May 4 09:39:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9011821 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 B9CAE9FC33 for ; Wed, 4 May 2016 09:41:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DFC7E20382 for ; Wed, 4 May 2016 09:41:00 +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 CA3F920394 for ; Wed, 4 May 2016 09:40:59 +0000 (UTC) Received: from localhost ([::1]:46627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axtId-0005wX-Un for patchwork-qemu-devel@patchwork.kernel.org; Wed, 04 May 2016 05:40:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axtIG-0005df-Qd for qemu-devel@nongnu.org; Wed, 04 May 2016 05:40:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1axtI4-0005qa-9W for qemu-devel@nongnu.org; Wed, 04 May 2016 05:40:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1axtHk-0005YI-LP; Wed, 04 May 2016 05:40:00 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (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 278C23E3; Wed, 4 May 2016 09:39:44 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u449dYe3000875; Wed, 4 May 2016 05:39:42 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Wed, 4 May 2016 11:39:16 +0200 Message-Id: <1462354765-14037-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1462354765-14037-1-git-send-email-kwolf@redhat.com> References: <1462354765-14037-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 05/14] stream: Use BlockBackend for I/O 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: kwolf@redhat.com, berto@igalia.com, jcody@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 This changes the streaming block job to use the job's BlockBackend for performing the COR reads. job->bs isn't used by the streaming code any more afterwards. Signed-off-by: Kevin Wolf Reviewed-by: Max Reitz --- block/block-backend.c | 15 +++++++++++++++ block/io.c | 9 --------- block/stream.c | 14 ++++++++------ include/block/block.h | 2 -- include/sysemu/block-backend.h | 2 ++ trace-events | 4 +++- 6 files changed, 28 insertions(+), 18 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 2932a58..25bb5ca 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -19,6 +19,7 @@ #include "sysemu/sysemu.h" #include "qapi-event.h" #include "qemu/id.h" +#include "trace.h" /* Number of coroutines to reserve per attached device model */ #define COROUTINE_POOL_RESERVATION 64 @@ -793,6 +794,20 @@ static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, return bdrv_co_pwritev(blk_bs(blk), offset, bytes, qiov, flags); } +int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) +{ + trace_blk_co_copy_on_readv(blk, blk_bs(blk), sector_num, nb_sectors); + + if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { + return -EINVAL; + } + + return blk_co_preadv(blk, sector_num << BDRV_SECTOR_BITS, + nb_sectors << BDRV_SECTOR_BITS, qiov, + BDRV_REQ_COPY_ON_READ); +} + typedef struct BlkRwCo { BlockBackend *blk; int64_t offset; diff --git a/block/io.c b/block/io.c index 9aae030..8280e14 100644 --- a/block/io.c +++ b/block/io.c @@ -1102,15 +1102,6 @@ int coroutine_fn bdrv_co_readv_no_serialising(BlockDriverState *bs, BDRV_REQ_NO_SERIALISING); } -int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) -{ - trace_bdrv_co_copy_on_readv(bs, sector_num, nb_sectors); - - return bdrv_co_do_readv(bs, sector_num, nb_sectors, qiov, - BDRV_REQ_COPY_ON_READ); -} - #define MAX_WRITE_ZEROES_BOUNCE_BUFFER 32768 static int coroutine_fn bdrv_co_do_write_zeroes(BlockDriverState *bs, diff --git a/block/stream.c b/block/stream.c index 40aa322..70ed9be 100644 --- a/block/stream.c +++ b/block/stream.c @@ -39,7 +39,7 @@ typedef struct StreamBlockJob { char *backing_file_str; } StreamBlockJob; -static int coroutine_fn stream_populate(BlockDriverState *bs, +static int coroutine_fn stream_populate(BlockBackend *blk, int64_t sector_num, int nb_sectors, void *buf) { @@ -52,7 +52,7 @@ static int coroutine_fn stream_populate(BlockDriverState *bs, qemu_iovec_init_external(&qiov, &iov, 1); /* Copy-on-read the unallocated clusters */ - return bdrv_co_copy_on_readv(bs, sector_num, nb_sectors, &qiov); + return blk_co_copy_on_readv(blk, sector_num, nb_sectors, &qiov); } typedef struct { @@ -64,6 +64,7 @@ static void stream_complete(BlockJob *job, void *opaque) { StreamBlockJob *s = container_of(job, StreamBlockJob, common); StreamCompleteData *data = opaque; + BlockDriverState *bs = blk_bs(job->blk); BlockDriverState *base = s->base; if (!block_job_is_cancelled(&s->common) && data->reached_end && @@ -75,8 +76,8 @@ static void stream_complete(BlockJob *job, void *opaque) base_fmt = base->drv->format_name; } } - data->ret = bdrv_change_backing_file(job->bs, base_id, base_fmt); - bdrv_set_backing_hd(job->bs, base); + data->ret = bdrv_change_backing_file(bs, base_id, base_fmt); + bdrv_set_backing_hd(bs, base); } g_free(s->backing_file_str); @@ -88,7 +89,8 @@ static void coroutine_fn stream_run(void *opaque) { StreamBlockJob *s = opaque; StreamCompleteData *data; - BlockDriverState *bs = s->common.bs; + BlockBackend *blk = s->common.blk; + BlockDriverState *bs = blk_bs(blk); BlockDriverState *base = s->base; int64_t sector_num = 0; int64_t end = -1; @@ -159,7 +161,7 @@ wait: goto wait; } } - ret = stream_populate(bs, sector_num, n, buf); + ret = stream_populate(blk, sector_num, n, buf); } if (ret < 0) { BlockErrorAction action = diff --git a/include/block/block.h b/include/block/block.h index a4eb5be..39b5812 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -243,8 +243,6 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, const void *buf, int count); int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); -int coroutine_fn bdrv_co_copy_on_readv(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_readv_no_serialising(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h index 12e4585..eac4d88 100644 --- a/include/sysemu/block-backend.h +++ b/include/sysemu/block-backend.h @@ -116,6 +116,8 @@ int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int nb_sectors); int blk_read_unthrottled(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int nb_sectors); +int coroutine_fn blk_co_copy_on_readv(BlockBackend *blk, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); int blk_write(BlockBackend *blk, int64_t sector_num, const uint8_t *buf, int nb_sectors); int blk_write_zeroes(BlockBackend *blk, int64_t sector_num, diff --git a/trace-events b/trace-events index 2f0ec6d..9beb588 100644 --- a/trace-events +++ b/trace-events @@ -61,6 +61,9 @@ virtio_console_chr_event(unsigned int port, int event) "port %u, event %d" bdrv_open_common(void *bs, const char *filename, int flags, const char *format_name) "bs %p filename \"%s\" flags %#x format_name \"%s\"" bdrv_lock_medium(void *bs, bool locked) "bs %p locked %d" +# block/block-backend.c +blk_co_copy_on_readv(void *blk, void *bs, int64_t sector_num, int nb_sector) "blk %p bs %p sector_num %"PRId64" nb_sectors %d" + # block/io.c bdrv_aio_discard(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" bdrv_aio_flush(void *bs, void *opaque) "bs %p opaque %p" @@ -68,7 +71,6 @@ bdrv_aio_readv(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs % bdrv_aio_writev(void *bs, int64_t sector_num, int nb_sectors, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d opaque %p" bdrv_aio_write_zeroes(void *bs, int64_t sector_num, int nb_sectors, int flags, void *opaque) "bs %p sector_num %"PRId64" nb_sectors %d flags %#x opaque %p" bdrv_co_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" -bdrv_co_copy_on_readv(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_readv_no_serialising(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_writev(void *bs, int64_t sector_num, int nb_sector) "bs %p sector_num %"PRId64" nb_sectors %d" bdrv_co_write_zeroes(void *bs, int64_t sector_num, int nb_sector, int flags) "bs %p sector_num %"PRId64" nb_sectors %d flags %#x"