From nobody Wed Apr 24 04:42:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154712656035648.26333145663682; Thu, 10 Jan 2019 05:22:40 -0800 (PST) Received: from localhost ([127.0.0.1]:45638 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghaIB-0003T8-9I for importer@patchew.org; Thu, 10 Jan 2019 08:22:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:46231) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghaGX-0002Yw-EL for qemu-devel@nongnu.org; Thu, 10 Jan 2019 08:20:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghaGV-0001mb-QE for qemu-devel@nongnu.org; Thu, 10 Jan 2019 08:20:57 -0500 Received: from relay.sw.ru ([185.231.240.75]:47954) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ghaGV-0001jg-IW; Thu, 10 Jan 2019 08:20:55 -0500 Received: from [10.28.8.145] (helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1ghaGP-0004k4-3q; Thu, 10 Jan 2019 16:20:49 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 10 Jan 2019 16:20:48 +0300 Message-Id: <20190110132048.49451-1-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.18.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH] block: don't probe zeroes in bs->file by default on block_status 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: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" drv_co_block_status digs bs->file for additional, more accurate search for hole inside region, reported as DATA by bs since 5daa74a6ebc. This accuracy is not free: assume we have qcow2 disk. Actually, qcow2 knows, where are holes and where is data. But every block_status request calls lseek additionally. Assume a big disk, full of data, in any iterative copying block job (or img convert) we'll call lseek(HOLE) on every iteration, and each of these lseeks will have to iterate through all metadata up to the end of file. It's obviously ineffective behavior. And for many scenarios we don't need this lseek at all. So, let's "5daa74a6ebc" by default, leaving an option to return previous behavior, which is needed for scenarios with preallocated images. Add iotest illustrating new option semantics. Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! I don't call it v2, as it do completely another thing, but here is a link to my previous try with discussion: [PATCH] file-posix: add rough-block-status parameter (https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg01322.html) And the previous discussion on the topic is "do not lseek in qcow2 block_status" thread (https://lists.gnu.org/archive/html/qemu-devel/2018-12/msg05749.html) qapi/block-core.json | 5 +++- include/block/block.h | 1 + include/block/block_int.h | 1 + block.c | 9 ++++++ block/io.c | 2 +- qemu-options.hx | 4 +++ tests/qemu-iotests/237 | 61 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/237.out | 12 ++++++++ tests/qemu-iotests/group | 1 + 9 files changed, 94 insertions(+), 2 deletions(-) create mode 100755 tests/qemu-iotests/237 create mode 100644 tests/qemu-iotests/237.out diff --git a/qapi/block-core.json b/qapi/block-core.json index 762000f31f..9eed36f3f4 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3673,6 +3673,8 @@ # (default: off) # @force-share: force share all permission on added nodes. # Requires read-only=3Dtrue. (Since 2.10) +# @probe-zeroes: Probe zeroes on protocol layer if format reports data +# (default: false) (since 4.0) # # Remaining options are determined by the block driver. # @@ -3686,7 +3688,8 @@ '*read-only': 'bool', '*auto-read-only': 'bool', '*force-share': 'bool', - '*detect-zeroes': 'BlockdevDetectZeroesOptions' }, + '*detect-zeroes': 'BlockdevDetectZeroesOptions', + '*probe-zeroes': 'bool' }, 'discriminator': 'driver', 'data': { 'blkdebug': 'BlockdevOptionsBlkdebug', diff --git a/include/block/block.h b/include/block/block.h index f70a843b72..1d7f4a6296 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -129,6 +129,7 @@ typedef struct HDGeometry { #define BDRV_OPT_AUTO_READ_ONLY "auto-read-only" #define BDRV_OPT_DISCARD "discard" #define BDRV_OPT_FORCE_SHARE "force-share" +#define BDRV_OPT_PROBE_ZEROES "probe-zeroes" =20 =20 #define BDRV_SECTOR_BITS 9 diff --git a/include/block/block_int.h b/include/block/block_int.h index f605622216..68bddf06b8 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -753,6 +753,7 @@ struct BlockDriverState { QDict *options; QDict *explicit_options; BlockdevDetectZeroesOptions detect_zeroes; + bool probe_zeroes; =20 /* The error object in use for blocking operations on backing_hd */ Error *backing_blocker; diff --git a/block.c b/block.c index 4f5ff2cc12..23a17435c9 100644 --- a/block.c +++ b/block.c @@ -939,6 +939,7 @@ static void bdrv_inherited_options(int *child_flags, QD= ict *child_options, qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIREC= T); qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FL= USH); qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE= ); + qdict_copy_default(child_options, parent_options, BDRV_OPT_PROBE_ZEROE= S); =20 /* Inherit the read-only option from the parent if it's not set */ qdict_copy_default(child_options, parent_options, BDRV_OPT_READ_ONLY); @@ -1063,6 +1064,7 @@ static void bdrv_backing_options(int *child_flags, QD= ict *child_options, qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIREC= T); qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FL= USH); qdict_copy_default(child_options, parent_options, BDRV_OPT_FORCE_SHARE= ); + qdict_copy_default(child_options, parent_options, BDRV_OPT_PROBE_ZEROE= S); =20 /* backing files always opened read-only */ qdict_set_default_str(child_options, BDRV_OPT_READ_ONLY, "on"); @@ -1364,6 +1366,12 @@ QemuOptsList bdrv_runtime_opts =3D { .type =3D QEMU_OPT_BOOL, .help =3D "always accept other writers (default: off)", }, + { + .name =3D BDRV_OPT_PROBE_ZEROES, + .type =3D QEMU_OPT_BOOL, + .help =3D "probe zeroes on protocol layer if format reports da= ta " + "(default: false)", + }, { /* end of list */ } }, }; @@ -1403,6 +1411,7 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, assert(drv !=3D NULL); =20 bs->force_share =3D qemu_opt_get_bool(opts, BDRV_OPT_FORCE_SHARE, fals= e); + bs->probe_zeroes =3D qemu_opt_get_bool(opts, BDRV_OPT_PROBE_ZEROES, fa= lse); =20 if (bs->force_share && (bs->open_flags & BDRV_O_RDWR)) { error_setg(errp, diff --git a/block/io.c b/block/io.c index bd9d688f8b..0c0cb3a17f 100644 --- a/block/io.c +++ b/block/io.c @@ -2186,7 +2186,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, } } =20 - if (want_zero && local_file && local_file !=3D bs && + if (want_zero && bs->probe_zeroes && local_file && local_file !=3D bs = && (ret & BDRV_BLOCK_DATA) && !(ret & BDRV_BLOCK_ZERO) && (ret & BDRV_BLOCK_OFFSET_VALID)) { int64_t file_pnum; diff --git a/qemu-options.hx b/qemu-options.hx index d4f3564b78..7b8dfcfaf6 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -615,6 +615,7 @@ DEF("blockdev", HAS_ARG, QEMU_OPTION_blockdev, "-blockdev [driver=3D]driver[,node-name=3DN][,discard=3Dignore|unmap]\= n" " [,cache.direct=3Don|off][,cache.no-flush=3Don|off]\n" " [,read-only=3Don|off][,detect-zeroes=3Don|off|unmap]\n" + " [,probe-zeroes=3Don|off]\n" " [,driver specific parameters...]\n" " configure a block backend\n", QEMU_ARCH_ALL) STEXI @@ -670,6 +671,8 @@ discard requests. conversion of plain zero writes by the OS to driver specific optimized zero write commands. You may even choose "unmap" if @var{discard} is set to "unmap" to allow a zero write to be converted to an @code{unmap} operat= ion. +@item probe-zeroes=3D@var{probe-zeroes} +Probe zeroes on protocol layer if format reports data. Default is "off". @end table =20 @item Driver-specific options for @code{file} @@ -793,6 +796,7 @@ DEF("drive", HAS_ARG, QEMU_OPTION_drive, " [,werror=3Dignore|stop|report|enospc][,id=3Dname][,aio=3Dthrea= ds|native]\n" " [,readonly=3Don|off][,copy-on-read=3Don|off]\n" " [,discard=3Dignore|unmap][,detect-zeroes=3Don|off|unmap]\n" + " [,probe-zeroes=3Don|off]\n" " [[,bps=3Db]|[[,bps_rd=3Dr][,bps_wr=3Dw]]]\n" " [[,iops=3Di]|[[,iops_rd=3Dr][,iops_wr=3Dw]]]\n" " [[,bps_max=3Dbm]|[[,bps_rd_max=3Drm][,bps_wr_max=3Dwm]]]\n" diff --git a/tests/qemu-iotests/237 b/tests/qemu-iotests/237 new file mode 100755 index 0000000000..9e66230c13 --- /dev/null +++ b/tests/qemu-iotests/237 @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Test probe-zeroes drive option +# +# Copyright (c) 2019 Virtuozzo International GmbH. All rights reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=3Dvsementsov@virtuozzo.com + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +IMGOPTS=3D'preallocation=3Dmetadata' _make_test_img 1M + +echo "=3D=3D default map =3D=3D" +$QEMU_IMG map --output=3Djson "$TEST_IMG" + +echo +echo "=3D=3D map with probe-zeroes=3Doff =3D=3D" +$QEMU_IMG map --output=3Djson --image-opts \ + driver=3D"$IMGFMT",file.filename=3D"$TEST_IMG",probe-zeroes=3Doff + +echo +echo "=3D=3D map with probe-zeroes=3Don =3D=3D" +$QEMU_IMG map --output=3Djson --image-opts \ + driver=3D"$IMGFMT",file.filename=3D"$TEST_IMG",probe-zeroes=3Don + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/237.out b/tests/qemu-iotests/237.out new file mode 100644 index 0000000000..8747757da7 --- /dev/null +++ b/tests/qemu-iotests/237.out @@ -0,0 +1,12 @@ +QA output created by 237 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 preallocation= =3Dmetadata +=3D=3D default map =3D=3D +[{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true,= "offset": 327680}] + +=3D=3D map with probe-zeroes=3Doff =3D=3D +[{ "start": 0, "length": 1048576, "depth": 0, "zero": false, "data": true,= "offset": 327680}] + +=3D=3D map with probe-zeroes=3Don =3D=3D +[{ "start": 0, "length": 1044480, "depth": 0, "zero": true, "data": true, = "offset": 327680}, +{ "start": 1044480, "length": 4096, "depth": 0, "zero": false, "data": tru= e, "offset": 1372160}] +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 61a6d98ebd..3064a04911 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -233,3 +233,4 @@ 233 auto quick 234 auto quick migration 235 auto quick +237 auto quick --=20 2.18.0