From nobody Sun Feb 8 13:16:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1491873944470827.0454163576421; Mon, 10 Apr 2017 18:25:44 -0700 (PDT) Received: from localhost ([::1]:36727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxkYx-0003Q1-Cz for importer@patchew.org; Mon, 10 Apr 2017 21:25:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cxkR6-0005HD-65 for qemu-devel@nongnu.org; Mon, 10 Apr 2017 21:17:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cxkR4-0005pq-EP for qemu-devel@nongnu.org; Mon, 10 Apr 2017 21:17:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33100) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cxkQz-0005nf-NW; Mon, 10 Apr 2017 21:17:29 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C6374C059727; Tue, 11 Apr 2017 01:17:28 +0000 (UTC) Received: from red.redhat.com (ovpn-122-58.rdu2.redhat.com [10.10.122.58]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CBF178DF2; Tue, 11 Apr 2017 01:17:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C6374C059727 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eblake@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C6374C059727 From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 10 Apr 2017 20:17:08 -0500 Message-Id: <20170411011718.9152-4-eblake@redhat.com> In-Reply-To: <20170411011718.9152-1-eblake@redhat.com> References: <20170411011718.9152-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 11 Apr 2017 01:17:28 +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] [PATCH v9 03/13] qemu-io: Switch 'alloc' command to byte-based length 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, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For the 'alloc' command, accepting an offset in bytes but a length in sectors, and reporting output in sectors, is confusing. Do everything in bytes, and adjust the expected output accordingly. Signed-off-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- qemu-io-cmds.c | 30 ++++++++++++++++++------------ tests/qemu-iotests/019.out | 8 ++++---- tests/qemu-iotests/179 | 4 ++-- tests/qemu-iotests/179.out | 4 ++-- tests/qemu-iotests/common.pattern | 2 +- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 9e023a4..df7297f 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1760,7 +1760,7 @@ out: static int alloc_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); - int64_t offset, sector_num, nb_sectors, remaining; + int64_t offset, sector_num, nb_sectors, remaining, bytes; char s1[64]; int num, ret; int64_t sum_alloc; @@ -1776,18 +1776,24 @@ static int alloc_f(BlockBackend *blk, int argc, cha= r **argv) } if (argc =3D=3D 3) { - nb_sectors =3D cvtnum(argv[2]); - if (nb_sectors < 0) { - print_cvtnum_err(nb_sectors, argv[2]); + bytes =3D cvtnum(argv[2]); + if (bytes < 0) { + print_cvtnum_err(bytes, argv[2]); return 0; - } else if (nb_sectors > INT_MAX) { - printf("length argument cannot exceed %d, given %s\n", - INT_MAX, argv[2]); + } else if (bytes > INT_MAX * BDRV_SECTOR_SIZE) { + printf("length argument cannot exceed %llu, given %s\n", + INT_MAX * BDRV_SECTOR_SIZE, argv[2]); return 0; } } else { - nb_sectors =3D 1; + bytes =3D BDRV_SECTOR_SIZE; } + if (bytes & 0x1ff) { + printf("bytes %" PRId64 " is not sector aligned\n", + bytes); + return 0; + } + nb_sectors =3D bytes >> BDRV_SECTOR_BITS; remaining =3D nb_sectors; sum_alloc =3D 0; @@ -1811,8 +1817,8 @@ static int alloc_f(BlockBackend *blk, int argc, char = **argv) cvtstr(offset, s1, sizeof(s1)); - printf("%"PRId64"/%"PRId64" sectors allocated at offset %s\n", - sum_alloc, nb_sectors, s1); + printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n", + sum_alloc << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, = s1); return 0; } @@ -1822,8 +1828,8 @@ static const cmdinfo_t alloc_cmd =3D { .argmin =3D 1, .argmax =3D 2, .cfunc =3D alloc_f, - .args =3D "off [sectors]", - .oneline =3D "checks if a sector is present in the file", + .args =3D "offset [bytes]", + .oneline =3D "checks if offset is allocated in the file", }; diff --git a/tests/qemu-iotests/019.out b/tests/qemu-iotests/019.out index 0124264..17a7c03 100644 --- a/tests/qemu-iotests/019.out +++ b/tests/qemu-iotests/019.out @@ -542,8 +542,8 @@ Testing conversion with -B TEST_DIR/t.IMGFMT.base Checking if backing clusters are allocated when they shouldn't -0/128 sectors allocated at offset 1 MiB -0/128 sectors allocated at offset 4.001 GiB +0/65536 bytes allocated at offset 1 MiB +0/65536 bytes allocated at offset 4.001 GiB Reading =3D=3D=3D IO: pattern 42 @@ -1086,8 +1086,8 @@ Testing conversion with -o backing_file=3DTEST_DIR/t.= IMGFMT.base Checking if backing clusters are allocated when they shouldn't -0/128 sectors allocated at offset 1 MiB -0/128 sectors allocated at offset 4.001 GiB +0/65536 bytes allocated at offset 1 MiB +0/65536 bytes allocated at offset 4.001 GiB Reading =3D=3D=3D IO: pattern 42 diff --git a/tests/qemu-iotests/179 b/tests/qemu-iotests/179 index 338a45d..44541e1 100755 --- a/tests/qemu-iotests/179 +++ b/tests/qemu-iotests/179 @@ -62,12 +62,12 @@ $QEMU_IMG map --output=3Djson "$TEST_IMG" | _filter_qem= u_img_map # But not requesting unmap must result in allocation (whether a cluster # allocation in compat=3D0.10 or a flag allocation in compat=3D1.1). $QEMU_IO -c "write -z 5M 1M" "$TEST_IMG.base" | _filter_qemu_io -$QEMU_IO -c "alloc 5M $((1024*1024 / 512))" "$TEST_IMG.base" | _filter_qem= u_io +$QEMU_IO -c "alloc 5M 1M" "$TEST_IMG.base" | _filter_qemu_io # Presence of a backing file overrides permission to unmap. Again, # compat=3D0.10 images allocate, while compat=3D1.1 images set zero flag. $QEMU_IO -c "write -z -u 7M 1M" "$TEST_IMG" | _filter_qemu_io -$QEMU_IO -c "alloc 7M $((1024 * 1024 / 512))" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "alloc 7M 1M" "$TEST_IMG" | _filter_qemu_io # Final check that images are still sane. TEST_IMG=3D"$TEST_IMG.base" _check_test_img diff --git a/tests/qemu-iotests/179.out b/tests/qemu-iotests/179.out index fc97b19..18ecf0f 100644 --- a/tests/qemu-iotests/179.out +++ b/tests/qemu-iotests/179.out @@ -13,10 +13,10 @@ wrote 1048576/1048576 bytes at offset 3145728 [{ "start": 0, "length": 16777216, "depth": 1, "zero": true, "data": false= }] wrote 1048576/1048576 bytes at offset 5242880 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -2048/2048 sectors allocated at offset 5 MiB +1048576/1048576 bytes allocated at offset 5 MiB wrote 1048576/1048576 bytes at offset 7340032 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) -2048/2048 sectors allocated at offset 7 MiB +1048576/1048576 bytes allocated at offset 7 MiB No errors were found on the image. No errors were found on the image. *** done diff --git a/tests/qemu-iotests/common.pattern b/tests/qemu-iotests/common.= pattern index ddfbca1..34f4a8d 100644 --- a/tests/qemu-iotests/common.pattern +++ b/tests/qemu-iotests/common.pattern @@ -18,7 +18,7 @@ function do_is_allocated() { local start=3D$1 - local size=3D$(( $2 / 512)) + local size=3D$2 local step=3D$3 local count=3D$4 --=20 2.9.3