From patchwork Fri Jun 8 06:04:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 10453817 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 ED7FC6037F for ; Fri, 8 Jun 2018 06:08:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CDABD2951D for ; Fri, 8 Jun 2018 06:08:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD44329520; Fri, 8 Jun 2018 06:08:35 +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=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, 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 297D82951D for ; Fri, 8 Jun 2018 06:08:35 +0000 (UTC) Received: from localhost ([::1]:33301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAZe-0002jC-7i for patchwork-qemu-devel@patchwork.kernel.org; Fri, 08 Jun 2018 02:08:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fRAW8-0008WV-SD for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:04:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fRAW7-0008IS-N3 for qemu-devel@nongnu.org; Fri, 08 Jun 2018 02:04:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37780 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fRAW4-0008Gx-Co; Fri, 08 Jun 2018 02:04:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F201A805A531; Fri, 8 Jun 2018 06:04:51 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-108.pek2.redhat.com [10.72.12.108]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AE6C1C5BA; Fri, 8 Jun 2018 06:04:46 +0000 (UTC) From: Fam Zheng To: qemu-devel@nongnu.org Date: Fri, 8 Jun 2018 14:04:13 +0800 Message-Id: <20180608060417.10170-3-famz@redhat.com> In-Reply-To: <20180608060417.10170-1-famz@redhat.com> References: <20180608060417.10170-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 08 Jun 2018 06:04:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 08 Jun 2018 06:04:52 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'famz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/6] block: Check if block drivers can do copy offloading 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: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Jeff Cody , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This avoids the wasteful cluster allocation in qcow2 before actually trying an unsupported copy range call, for example. Signed-off-by: Fam Zheng --- block.c | 12 ++++++++++++ block/file-posix.c | 9 +++++++++ block/io.c | 3 +++ block/iscsi.c | 8 ++++++++ block/qcow2.c | 11 +++++++++++ block/raw-format.c | 6 ++++++ include/block/block_int.h | 4 ++++ 7 files changed, 53 insertions(+) diff --git a/block.c b/block.c index 501b64c819..28aa8d8a65 100644 --- a/block.c +++ b/block.c @@ -5320,3 +5320,15 @@ bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp); } + +bool bdrv_can_copy_range(BdrvChild *src, BdrvChild *dst) +{ + BlockDriverState *bs; + + if (!src || !src->bs) { + return false; + } + bs = src->bs; + return bs && bs->drv && bs->drv->bdrv_can_copy_range && + bs->drv->bdrv_can_copy_range(bs, dst); +} diff --git a/block/file-posix.c b/block/file-posix.c index c6dae38f94..41c491c65b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2539,6 +2539,13 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, NULL, bytes, QEMU_AIO_COPY_RANGE); } +static bool raw_can_copy_range(BlockDriverState *bs, + BdrvChild *dst) +{ + return dst->bs && dst->bs->drv && + dst->bs->drv->bdrv_can_copy_range == raw_can_copy_range; +} + BlockDriver bdrv_file = { .format_name = "file", .protocol_name = "file", @@ -2564,6 +2571,7 @@ BlockDriver bdrv_file = { .bdrv_aio_pdiscard = raw_aio_pdiscard, .bdrv_co_copy_range_from = raw_co_copy_range_from, .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_can_copy_range = raw_can_copy_range, .bdrv_refresh_limits = raw_refresh_limits, .bdrv_io_plug = raw_aio_plug, .bdrv_io_unplug = raw_aio_unplug, @@ -3044,6 +3052,7 @@ static BlockDriver bdrv_host_device = { .bdrv_aio_pdiscard = hdev_aio_pdiscard, .bdrv_co_copy_range_from = raw_co_copy_range_from, .bdrv_co_copy_range_to = raw_co_copy_range_to, + .bdrv_can_copy_range = raw_can_copy_range, .bdrv_refresh_limits = raw_refresh_limits, .bdrv_io_plug = raw_aio_plug, .bdrv_io_unplug = raw_aio_unplug, diff --git a/block/io.c b/block/io.c index b7beaeeb9f..d8039793c2 100644 --- a/block/io.c +++ b/block/io.c @@ -2913,6 +2913,9 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, uint64_t src_offset, BlockDriverState *dst_bs = dst->bs; int ret; + if (!bdrv_can_copy_range(src, dst)) { + return -ENOTSUP; + } bdrv_inc_in_flight(src_bs); bdrv_inc_in_flight(dst_bs); tracked_request_begin(&src_req, src_bs, src_offset, diff --git a/block/iscsi.c b/block/iscsi.c index c2fbd8a8aa..6c465ebd46 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2420,6 +2420,12 @@ out_unlock: return r; } +static bool iscsi_can_copy_range(BlockDriverState *bs, BdrvChild *dst) +{ + return dst->bs && dst->bs->drv && + dst->bs->drv->bdrv_can_copy_range == iscsi_can_copy_range; +} + static QemuOptsList iscsi_create_opts = { .name = "iscsi-create-opts", .head = QTAILQ_HEAD_INITIALIZER(iscsi_create_opts.head), @@ -2456,6 +2462,7 @@ static BlockDriver bdrv_iscsi = { .bdrv_co_pdiscard = iscsi_co_pdiscard, .bdrv_co_copy_range_from = iscsi_co_copy_range_from, .bdrv_co_copy_range_to = iscsi_co_copy_range_to, + .bdrv_can_copy_range = iscsi_can_copy_range, .bdrv_co_pwrite_zeroes = iscsi_co_pwrite_zeroes, .bdrv_co_readv = iscsi_co_readv, .bdrv_co_writev = iscsi_co_writev, @@ -2493,6 +2500,7 @@ static BlockDriver bdrv_iser = { .bdrv_co_pdiscard = iscsi_co_pdiscard, .bdrv_co_copy_range_from = iscsi_co_copy_range_from, .bdrv_co_copy_range_to = iscsi_co_copy_range_to, + .bdrv_can_copy_range = iscsi_can_copy_range, .bdrv_co_pwrite_zeroes = iscsi_co_pwrite_zeroes, .bdrv_co_readv = iscsi_co_readv, .bdrv_co_writev = iscsi_co_writev, diff --git a/block/qcow2.c b/block/qcow2.c index 549fee9b69..1326410d1c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3440,6 +3440,16 @@ fail: return ret; } +static bool qcow2_can_copy_range(BlockDriverState *bs, BdrvChild *dst) +{ + bool r = bdrv_can_copy_range(bs->file, dst); + + if (bs->backing) { + r = r && bdrv_can_copy_range(bs->backing, dst); + } + return r; +} + static int qcow2_truncate(BlockDriverState *bs, int64_t offset, PreallocMode prealloc, Error **errp) { @@ -4690,6 +4700,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_co_pdiscard = qcow2_co_pdiscard, .bdrv_co_copy_range_from = qcow2_co_copy_range_from, .bdrv_co_copy_range_to = qcow2_co_copy_range_to, + .bdrv_can_copy_range = qcow2_can_copy_range, .bdrv_truncate = qcow2_truncate, .bdrv_co_pwritev_compressed = qcow2_co_pwritev_compressed, .bdrv_make_empty = qcow2_make_empty, diff --git a/block/raw-format.c b/block/raw-format.c index f2e468df6f..707b25fc77 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -527,6 +527,11 @@ static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, flags); } +static bool raw_can_copy_range(BlockDriverState *bs, BdrvChild *dst) +{ + return bdrv_can_copy_range(bs->file, dst); +} + BlockDriver bdrv_raw = { .format_name = "raw", .instance_size = sizeof(BDRVRawState), @@ -545,6 +550,7 @@ BlockDriver bdrv_raw = { .bdrv_co_block_status = &raw_co_block_status, .bdrv_co_copy_range_from = &raw_co_copy_range_from, .bdrv_co_copy_range_to = &raw_co_copy_range_to, + .bdrv_can_copy_range = &raw_can_copy_range, .bdrv_truncate = &raw_truncate, .bdrv_getlength = &raw_getlength, .has_variable_length = true, diff --git a/include/block/block_int.h b/include/block/block_int.h index 888b7f7bff..2c51cd420f 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -235,6 +235,9 @@ struct BlockDriver { uint64_t bytes, BdrvRequestFlags flags); + bool (*bdrv_can_copy_range)(BlockDriverState *bs, + BdrvChild *dst); + /* * Building block for bdrv_block_status[_above] and * bdrv_is_allocated[_above]. The driver should answer only @@ -1139,5 +1142,6 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, uint64_t src_offset, int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, uint64_t src_offset, BdrvChild *dst, uint64_t dst_offset, uint64_t bytes, BdrvRequestFlags flags); +bool bdrv_can_copy_range(BdrvChild *src, BdrvChild *dst); #endif /* BLOCK_INT_H */