From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447479286950.7253231887468; Fri, 7 Jul 2017 10:11:19 -0700 (PDT) Received: from localhost ([::1]:57694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmj-0006OQ-MT for importer@patchew.org; Fri, 07 Jul 2017 13:11:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41196) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWko-0004X8-Dz for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkm-0007Wm-My for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkg-0007Ro-H1; Fri, 07 Jul 2017 13:09:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4E10F5BECD; Fri, 7 Jul 2017 17:09:09 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6697762924; Fri, 7 Jul 2017 17:09:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4E10F5BECD Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4E10F5BECD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:16 +0200 Message-Id: <1499447335-6125-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 07 Jul 2017 17:09:09 +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] [PULL 001/100] qemu-io: Don't die on second open 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-devel@nongnu.org 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" From: Eric Blake Most callback commands in qemu-io return 0 to keep the interpreter loop running, or 1 to quit immediately. However, open_f() just passed through the return value of openfile(), which has different semantics of returning 0 if a file was opened, or 1 on any failure. As a result of mixing the return semantics, we are forcing the qemu-io interpreter to exit early on any failures, which is rather annoying when some of the failures are obviously trying to give the user a hint of how to proceed (if we didn't then kill qemu-io out from under the user's feet): $ qemu-io qemu-io> open foo qemu-io> open foo file open already, try 'help close' $ echo $? 0 In general, we WANT openfile() to report failures, since it is the function used in the form 'qemu-io -c "$something" no_such_file' for performing one or more -c options on a single file, and it is not worth attempting $something if the file itself cannot be opened. So the solution is to fix open_f() to always return 0 (when we are in interactive mode, even failure to open should not end the session), and save the return value of openfile() for command line use in main(). Note, however, that we do have some qemu-iotests that do 'qemu-io -c "open file" -c "$something"'; such tests will now proceed to attempt $something whether or not the open succeeded, the same way as if the two commands had been attempted in interactive mode. As such, the expected output for those tests has to be modified. But it also means that it is now possible to use -c close and have a single qemu-io command line operate on more than one file even without using interactive mode. Although the '-c open' action is a subtle change in behavior, remember that qemu-io is for debugging purposes, so as long as it serves the needs of qemu-iotests while still being reasonable for interactive use, it should not be a problem that we are changing tests to the new behavior. This has been awkward since at least as far back as commit e3aff4f, in 2009. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- qemu-io.c | 7 ++++--- tests/qemu-iotests/060.out | 1 + tests/qemu-iotests/114.out | 5 +++-- tests/qemu-iotests/153.out | 6 ++++++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index 8e38b28..8074656 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -230,13 +230,14 @@ static int open_f(BlockBackend *blk, int argc, char *= *argv) qemu_opts_reset(&empty_opts); =20 if (optind =3D=3D argc - 1) { - return openfile(argv[optind], flags, writethrough, force_share, op= ts); + openfile(argv[optind], flags, writethrough, force_share, opts); } else if (optind =3D=3D argc) { - return openfile(NULL, flags, writethrough, force_share, opts); + openfile(NULL, flags, writethrough, force_share, opts); } else { QDECREF(opts); - return qemuio_command_usage(&open_cmd); + qemuio_command_usage(&open_cmd); } + return 0; } =20 static int quit_f(BlockBackend *blk, int argc, char **argv) diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 3bc1461..5ca3af4 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -21,6 +21,7 @@ Format specific information: refcount bits: 16 corrupt: true can't open device TEST_DIR/t.IMGFMT: IMGFMT: Image is corrupt; cannot be o= pened read/write +no file open, try 'help open' read 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 diff --git a/tests/qemu-iotests/114.out b/tests/qemu-iotests/114.out index b6d10e4..1a47a52 100644 --- a/tests/qemu-iotests/114.out +++ b/tests/qemu-iotests/114.out @@ -1,6 +1,6 @@ QA output created by 114 -Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D67108864=20 -Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base=20 +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D67108864 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_file= =3DTEST_DIR/t.IMGFMT.base image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 64M (67108864 bytes) @@ -8,6 +8,7 @@ cluster_size: 65536 backing file: TEST_DIR/t.IMGFMT.base backing file format: foo can't open device TEST_DIR/t.qcow2: Could not open backing file: Unknown d= river 'foo' +no file open, try 'help open' read 4096/4096 bytes at offset 0 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index 5ba0b63..5b917b1 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -33,10 +33,12 @@ Is another process using the image? _qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512 can't open device TEST_DIR/t.qcow2: Failed to get "write" lock Is another process using the image? +no file open, try 'help open' =20 _qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512 can't open device TEST_DIR/t.qcow2: Failed to get shared "write" lock Is another process using the image? +no file open, try 'help open' =20 _qemu_img_wrapper info TEST_DIR/t.qcow2 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get shared "write" = lock @@ -99,6 +101,7 @@ _qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2 =20 _qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512 can't open device TEST_DIR/t.qcow2: force-share=3Don can only be used with= read-only images +no file open, try 'help open' =20 _qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512 =20 @@ -166,6 +169,7 @@ _qemu_io_wrapper -r -c read 0 512 TEST_DIR/t.qcow2 _qemu_io_wrapper -c open TEST_DIR/t.qcow2 -c read 0 512 can't open device TEST_DIR/t.qcow2: Failed to get "write" lock Is another process using the image? +no file open, try 'help open' =20 _qemu_io_wrapper -c open -r TEST_DIR/t.qcow2 -c read 0 512 =20 @@ -214,6 +218,7 @@ _qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2 =20 _qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512 can't open device TEST_DIR/t.qcow2: force-share=3Don can only be used with= read-only images +no file open, try 'help open' =20 _qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512 =20 @@ -313,6 +318,7 @@ _qemu_io_wrapper -U -r -c read 0 512 TEST_DIR/t.qcow2 =20 _qemu_io_wrapper -c open -U TEST_DIR/t.qcow2 -c read 0 512 can't open device TEST_DIR/t.qcow2: force-share=3Don can only be used with= read-only images +no file open, try 'help open' =20 _qemu_io_wrapper -c open -r -U TEST_DIR/t.qcow2 -c read 0 512 =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447639963368.29384848165785; Fri, 7 Jul 2017 10:13:59 -0700 (PDT) Received: from localhost ([::1]:57710 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWpK-0000Po-Kh for importer@patchew.org; Fri, 07 Jul 2017 13:13:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkn-0004WM-Gg for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkm-0007Vj-7O for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56052) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWki-0007T1-Ee; Fri, 07 Jul 2017 13:09:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2F81C0587C4; Fri, 7 Jul 2017 17:09:10 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A83561F52; Fri, 7 Jul 2017 17:09:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C2F81C0587C4 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C2F81C0587C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:17 +0200 Message-Id: <1499447335-6125-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:09:10 +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] [PULL 002/100] block: Guarantee that *file is set on bdrv_get_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: kwolf@redhat.com, qemu-devel@nongnu.org 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" From: Eric Blake We document that *file is valid if the return is not an error and includes BDRV_BLOCK_OFFSET_VALID, but forgot to obey this contract when a driver (such as blkdebug) lacks a callback. Messed up in commit 67a0fd2 (v2.6), when we added the file parameter. Enhance qemu-iotest 177 to cover this, using a sequence that would print garbage or even SEGV, because it was dererefencing through uninitialized memory. [The resulting test output shows that we have less-than-ideal block status from the blkdebug driver, but that's a separate fix coming up soon.] Setting *file on all paths that return BDRV_BLOCK_OFFSET_VALID is enough to fix the crash, but we can go one step further: always setting *file, even on error, means that a broken caller that blindly dereferences file without checking for error is now more likely to get a reliable SEGV instead of randomly acting on garbage, making it easier to diagnose such buggy callers. Adding an assertion that file is set where expected doesn't hurt either. CC: qemu-stable@nongnu.org Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Max Reitz Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/io.c | 5 +++-- tests/qemu-iotests/177 | 3 +++ tests/qemu-iotests/177.out | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/block/io.c b/block/io.c index 2de7c77..5c146b5 100644 --- a/block/io.c +++ b/block/io.c @@ -1734,6 +1734,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, int64_t n; int64_t ret, ret2; =20 + *file =3D NULL; total_sectors =3D bdrv_nb_sectors(bs); if (total_sectors < 0) { return total_sectors; @@ -1757,11 +1758,11 @@ static int64_t coroutine_fn bdrv_co_get_block_statu= s(BlockDriverState *bs, } if (bs->drv->protocol_name) { ret |=3D BDRV_BLOCK_OFFSET_VALID | (sector_num * BDRV_SECTOR_S= IZE); + *file =3D bs; } return ret; } =20 - *file =3D NULL; bdrv_inc_in_flight(bs); ret =3D bs->drv->bdrv_co_get_block_status(bs, sector_num, nb_sectors, = pnum, file); @@ -1771,7 +1772,7 @@ static int64_t coroutine_fn bdrv_co_get_block_status(= BlockDriverState *bs, } =20 if (ret & BDRV_BLOCK_RAW) { - assert(ret & BDRV_BLOCK_OFFSET_VALID); + assert(ret & BDRV_BLOCK_OFFSET_VALID && *file); ret =3D bdrv_co_get_block_status(*file, ret >> BDRV_SECTOR_BITS, *pnum, pnum, file); goto out; diff --git a/tests/qemu-iotests/177 b/tests/qemu-iotests/177 index 2005c17..f8ed8fb 100755 --- a/tests/qemu-iotests/177 +++ b/tests/qemu-iotests/177 @@ -43,6 +43,7 @@ _supported_proto file CLUSTER_SIZE=3D1M size=3D128M options=3Ddriver=3Dblkdebug,image.driver=3Dqcow2 +nested_opts=3Dimage.file.driver=3Dfile,image.file.filename=3D$TEST_IMG =20 echo echo "=3D=3D setting up files =3D=3D" @@ -106,6 +107,8 @@ function verify_io() } =20 verify_io | $QEMU_IO -r "$TEST_IMG" | _filter_qemu_io +$QEMU_IMG map --image-opts "$options,$nested_opts,align=3D4k" \ + | _filter_qemu_img_map =20 _check_test_img =20 diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out index e887542..fcfbfa3 100644 --- a/tests/qemu-iotests/177.out +++ b/tests/qemu-iotests/177.out @@ -45,5 +45,7 @@ read 30408704/30408704 bytes at offset 80740352 29 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) read 23068672/23068672 bytes at offset 111149056 22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length File +0 0x8000000 json:{"image": {"driver": "IMGFMT", "file"= : {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}}, "driver": "blkdebug= ", "align": "4k"} No errors were found on the image. *** done --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447489605276.98143587876996; Fri, 7 Jul 2017 10:11:29 -0700 (PDT) Received: from localhost ([::1]:57695 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmt-0006Zy-3l for importer@patchew.org; Fri, 07 Jul 2017 13:11:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkn-0004W4-9q for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkm-0007Vc-58 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkj-0007TN-94; Fri, 07 Jul 2017 13:09:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EF6A61B91; Fri, 7 Jul 2017 17:09:12 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19C1317140; Fri, 7 Jul 2017 17:09:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0EF6A61B91 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0EF6A61B91 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:18 +0200 Message-Id: <1499447335-6125-4-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:12 +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] [PULL 003/100] block: Simplify use of BDRV_BLOCK_RAW 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-devel@nongnu.org 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" From: Eric Blake The lone caller that cares about a return of BDRV_BLOCK_RAW (namely, io.c:bdrv_co_get_block_status) completely replaces the return value, so there is no point in passing BDRV_BLOCK_DATA. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/commit.c | 2 +- block/mirror.c | 2 +- block/raw-format.c | 2 +- block/vpc.c | 2 +- include/block/block.h | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/commit.c b/block/commit.c index 8c09c3d..524bd54 100644 --- a/block/commit.c +++ b/block/commit.c @@ -253,7 +253,7 @@ static int64_t coroutine_fn bdrv_commit_top_get_block_s= tatus( { *pnum =3D nb_sectors; *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } =20 diff --git a/block/mirror.c b/block/mirror.c index 68744a1..61a862d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1058,7 +1058,7 @@ static int64_t coroutine_fn bdrv_mirror_top_get_block= _status( { *pnum =3D nb_sectors; *file =3D bs->backing->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } =20 diff --git a/block/raw-format.c b/block/raw-format.c index 0d185fe..1ea8c2d 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -259,7 +259,7 @@ static int64_t coroutine_fn raw_co_get_block_status(Blo= ckDriverState *bs, *pnum =3D nb_sectors; *file =3D bs->file->bs; sector_num +=3D s->offset / BDRV_SECTOR_SIZE; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } =20 diff --git a/block/vpc.c b/block/vpc.c index 4240ba9..b313c68 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -701,7 +701,7 @@ static int64_t coroutine_fn vpc_co_get_block_status(Blo= ckDriverState *bs, if (be32_to_cpu(footer->type) =3D=3D VHD_FIXED) { *pnum =3D nb_sectors; *file =3D bs->file->bs; - return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | BDRV_BLOCK_DATA | + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | (sector_num << BDRV_SECTOR_BITS); } =20 diff --git a/include/block/block.h b/include/block/block.h index 4c149ad..afe1b61 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -132,9 +132,9 @@ typedef struct HDGeometry { * BDRV_BLOCK_EOF: the returned pnum covers through end of file for this l= ayer * * Internal flag: - * BDRV_BLOCK_RAW: used internally to indicate that the request was - * answered by a passthrough driver such as raw and that t= he - * block layer should recompute the answer from bs->file. + * BDRV_BLOCK_RAW: for use by passthrough drivers, such as raw, to request + * that the block layer recompute the answer from the retu= rned + * BDS; must be accompanied by just BDRV_BLOCK_OFFSET_VALI= D. * * If BDRV_BLOCK_OFFSET_VALID is set, bits 9-62 (BDRV_BLOCK_OFFSET_MASK) * represent the offset in the returned BDS that is allocated for the --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447789393636.2255092564303; Fri, 7 Jul 2017 10:16:29 -0700 (PDT) Received: from localhost ([::1]:57727 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWrj-0002oT-4U for importer@patchew.org; Fri, 07 Jul 2017 13:16:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41184) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWko-0004Wl-0j for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkm-0007XN-S3 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:17 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39418) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkk-0007U8-Fe; Fri, 07 Jul 2017 13:09:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4A3C6624A8; Fri, 7 Jul 2017 17:09:13 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 59951627DB; Fri, 7 Jul 2017 17:09:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4A3C6624A8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4A3C6624A8 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:19 +0200 Message-Id: <1499447335-6125-5-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:13 +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] [PULL 004/100] blkdebug: Support .bdrv_co_get_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: kwolf@redhat.com, qemu-devel@nongnu.org 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" From: Eric Blake Without a passthrough status of BDRV_BLOCK_RAW, anything wrapped by blkdebug appears 100% allocated as data. Better is treating it the same as the underlying file being wrapped. Update iotest 177 for the new expected output. Signed-off-by: Eric Blake Reviewed-by: Fam Zheng Reviewed-by: Max Reitz Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/blkdebug.c | 11 +++++++++++ tests/qemu-iotests/177.out | 5 ++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index a1b24b9..b25856c 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -641,6 +641,16 @@ static int coroutine_fn blkdebug_co_pdiscard(BlockDriv= erState *bs, return bdrv_co_pdiscard(bs->file->bs, offset, bytes); } =20 +static int64_t coroutine_fn blkdebug_co_get_block_status( + BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum, + BlockDriverState **file) +{ + *pnum =3D nb_sectors; + *file =3D bs->file->bs; + return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID | + (sector_num << BDRV_SECTOR_BITS); +} + static void blkdebug_close(BlockDriverState *bs) { BDRVBlkdebugState *s =3D bs->opaque; @@ -915,6 +925,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_co_flush_to_disk =3D blkdebug_co_flush, .bdrv_co_pwrite_zeroes =3D blkdebug_co_pwrite_zeroes, .bdrv_co_pdiscard =3D blkdebug_co_pdiscard, + .bdrv_co_get_block_status =3D blkdebug_co_get_block_status, =20 .bdrv_debug_event =3D blkdebug_debug_event, .bdrv_debug_breakpoint =3D blkdebug_debug_breakpoint, diff --git a/tests/qemu-iotests/177.out b/tests/qemu-iotests/177.out index fcfbfa3..43a7778 100644 --- a/tests/qemu-iotests/177.out +++ b/tests/qemu-iotests/177.out @@ -46,6 +46,9 @@ read 30408704/30408704 bytes at offset 80740352 read 23068672/23068672 bytes at offset 111149056 22 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) Offset Length File -0 0x8000000 json:{"image": {"driver": "IMGFMT", "file"= : {"driver": "file", "filename": "TEST_DIR/t.IMGFMT"}}, "driver": "blkdebug= ", "align": "4k"} +0 0x800000 TEST_DIR/t.IMGFMT +0x900000 0x2400000 TEST_DIR/t.IMGFMT +0x3c00000 0x1100000 TEST_DIR/t.IMGFMT +0x6a00000 0x1600000 TEST_DIR/t.IMGFMT No errors were found on the image. *** done --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447955005155.62990582276302; Fri, 7 Jul 2017 10:19:15 -0700 (PDT) Received: from localhost ([::1]:57736 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWuO-0004xV-GA for importer@patchew.org; Fri, 07 Jul 2017 13:19:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41221) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkp-0004Ys-GK for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWko-0007Zv-HT for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36582) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkl-0007Ui-GM; Fri, 07 Jul 2017 13:09:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8D9AC4F2; Fri, 7 Jul 2017 17:09:14 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F41061F52; Fri, 7 Jul 2017 17:09:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8D9AC4F2 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8D9AC4F2 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:20 +0200 Message-Id: <1499447335-6125-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:09:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 005/100] vvfat: fix qemu-img map and qemu-img convert 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau - bs->total_sectors is the number of sectors of the whole disk - s->sector_count is the number of sectors of the FAT partition This fixes the following assert in qemu-img map: qemu-img.c:2641: get_block_status: Assertion `nb_sectors' failed. This also fixes an infinite loop in qemu-img convert. Fixes: 4480e0f924a42e1db8b8cfcac4d0634dd1bb27a0 Fixes: https://bugs.launchpad.net/qemu/+bug/1599539 Cc: qemu-stable@nongnu.org Signed-off-by: Herv=C3=A9 Poussineau Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- block/vvfat.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 8ab647c..040fb71 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -2968,8 +2968,7 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offse= t, uint64_t bytes, static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *n, BlockDriverState **file) { - BDRVVVFATState* s =3D bs->opaque; - *n =3D s->sector_count - sector_num; + *n =3D bs->total_sectors - sector_num; if (*n > nb_sectors) { *n =3D nb_sectors; } else if (*n < 0) { --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448701225122.22239508656821; Fri, 7 Jul 2017 10:31:41 -0700 (PDT) Received: from localhost ([::1]:57815 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX6R-00080s-JZ for importer@patchew.org; Fri, 07 Jul 2017 13:31:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlE-000536-2R for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl5-0007pB-If for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55908) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkn-0007WM-3M; Fri, 07 Jul 2017 13:09:17 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2072174864; Fri, 7 Jul 2017 17:09:16 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id D57E617140; Fri, 7 Jul 2017 17:09:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2072174864 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2072174864 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:21 +0200 Message-Id: <1499447335-6125-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:16 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 006/100] vvfat: replace tabs by 8 spaces 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau This was a complete mess. On 2299 indented lines: - 1329 were with spaces only - 617 with tabulations only - 353 with spaces and tabulations Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 2054 ++++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 1027 insertions(+), 1027 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 040fb71..e83b8ba 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -100,12 +100,12 @@ static inline void* array_get(array_t* array,unsigned= int index) { static inline int array_ensure_allocated(array_t* array, int index) { if((index + 1) * array->item_size > array->size) { - int new_size =3D (index + 32) * array->item_size; - array->pointer =3D g_realloc(array->pointer, new_size); - if (!array->pointer) - return -1; - array->size =3D new_size; - array->next =3D index + 1; + int new_size =3D (index + 32) * array->item_size; + array->pointer =3D g_realloc(array->pointer, new_size); + if (!array->pointer) + return -1; + array->size =3D new_size; + array->next =3D index + 1; } =20 return 0; @@ -115,7 +115,7 @@ static inline void* array_get_next(array_t* array) { unsigned int next =3D array->next; =20 if (array_ensure_allocated(array, next) < 0) - return NULL; + return NULL; =20 array->next =3D next + 1; return array_get(array, next); @@ -123,15 +123,15 @@ static inline void* array_get_next(array_t* array) { =20 static inline void* array_insert(array_t* array,unsigned int index,unsigne= d int count) { if((array->next+count)*array->item_size>array->size) { - int increment=3Dcount*array->item_size; - array->pointer=3Dg_realloc(array->pointer,array->size+increment); - if(!array->pointer) + int increment=3Dcount*array->item_size; + array->pointer=3Dg_realloc(array->pointer,array->size+increment); + if(!array->pointer) return NULL; - array->size+=3Dincrement; + array->size+=3Dincrement; } memmove(array->pointer+(index+count)*array->item_size, - array->pointer+index*array->item_size, - (array->next-index)*array->item_size); + array->pointer+index*array->item_size, + (array->next-index)*array->item_size); array->next+=3Dcount; return array->pointer+index*array->item_size; } @@ -146,12 +146,12 @@ static inline int array_roll(array_t* array,int index= _to,int index_from,int coun int is; =20 if(!array || - index_to<0 || index_to>=3Darray->next || - index_from<0 || index_from>=3Darray->next) - return -1; + index_to<0 || index_to>=3Darray->next || + index_from<0 || index_from>=3Darray->next) + return -1; =20 if(index_to=3D=3Dindex_from) - return 0; + return 0; =20 is=3Darray->item_size; from=3Darray->pointer+index_from*is; @@ -160,9 +160,9 @@ static inline int array_roll(array_t* array,int index_t= o,int index_from,int coun memcpy(buf,from,is*count); =20 if(index_to 0); assert(index + count <=3D array->next); if(array_roll(array,array->next-1,index,count)) - return -1; + return -1; array->next -=3D count; return 0; } @@ -216,21 +216,21 @@ typedef struct bootsector_t { uint32_t total_sectors; union { struct { - uint8_t drive_number; - uint8_t current_head; - uint8_t signature; - uint32_t id; - uint8_t volume_label[11]; - } QEMU_PACKED fat16; - struct { - uint32_t sectors_per_fat; - uint16_t flags; - uint8_t major,minor; - uint32_t first_cluster_of_root_directory; - uint16_t info_sector; - uint16_t backup_boot_sector; - uint16_t ignored; - } QEMU_PACKED fat32; + uint8_t drive_number; + uint8_t current_head; + uint8_t signature; + uint32_t id; + uint8_t volume_label[11]; + } QEMU_PACKED fat16; + struct { + uint32_t sectors_per_fat; + uint16_t flags; + uint8_t major,minor; + uint32_t first_cluster_of_root_directory; + uint16_t info_sector; + uint16_t backup_boot_sector; + uint16_t ignored; + } QEMU_PACKED fat32; } u; uint8_t fat_type[8]; uint8_t ignored[0x1c0]; @@ -284,25 +284,25 @@ typedef struct mapping_t { /* the clusters of a file may be in any order; this points to the firs= t */ int first_mapping_index; union { - /* offset is - * - the offset in the file (in clusters) for a file, or - * - the next cluster of the directory for a directory, and - * - the address of the buffer for a faked entry - */ - struct { - uint32_t offset; - } file; - struct { - int parent_mapping_index; - int first_dir_index; - } dir; + /* offset is + * - the offset in the file (in clusters) for a file, or + * - the next cluster of the directory for a directory, and + * - the address of the buffer for a faked entry + */ + struct { + uint32_t offset; + } file; + struct { + int parent_mapping_index; + int first_dir_index; + } dir; } info; /* path contains the full path, i.e. it always starts with s->path */ char* path; =20 enum { MODE_UNDEFINED =3D 0, MODE_NORMAL =3D 1, MODE_MODIFIED =3D 2, - MODE_DIRECTORY =3D 4, MODE_FAKED =3D 8, - MODE_DELETED =3D 16, MODE_RENAMED =3D 32 } mode; + MODE_DIRECTORY =3D 4, MODE_FAKED =3D 8, + MODE_DELETED =3D 16, MODE_RENAMED =3D 32 } mode; int read_only; } mapping_t; =20 @@ -419,12 +419,12 @@ static inline int short2long_name(char* dest,const ch= ar* src) int len; for(i=3D0;i<129 && src[i];i++) { dest[2*i]=3Dsrc[i]; - dest[2*i+1]=3D0; + dest[2*i+1]=3D0; } len=3D2*i; dest[2*i]=3Ddest[2*i+1]=3D0; for(i=3D2*i+2;(i%26);i++) - dest[i]=3D0xff; + dest[i]=3D0xff; return len; } =20 @@ -436,19 +436,19 @@ static inline direntry_t* create_long_filename(BDRVVV= FATState* s,const char* fil direntry_t* entry; =20 for(i=3D0;idirectory)); - entry->attributes=3D0xf; - entry->reserved[0]=3D0; - entry->begin=3D0; - entry->name[0]=3D(number_of_entries-i)|(i=3D=3D0?0x40:0); + entry=3Darray_get_next(&(s->directory)); + entry->attributes=3D0xf; + entry->reserved[0]=3D0; + entry->begin=3D0; + entry->name[0]=3D(number_of_entries-i)|(i=3D=3D0?0x40:0); } for(i=3D0;i<26*number_of_entries;i++) { - int offset=3D(i%26); - if(offset<10) offset=3D1+offset; - else if(offset<22) offset=3D14+offset-10; - else offset=3D28+offset-22; - entry=3Darray_get(&(s->directory),s->directory.next-1-(i/26)); - entry->name[offset]=3Dbuffer[i]; + int offset=3D(i%26); + if(offset<10) offset=3D1+offset; + else if(offset<22) offset=3D14+offset-10; + else offset=3D28+offset-22; + entry=3Darray_get(&(s->directory),s->directory.next-1-(i/26)); + entry->name[offset]=3Dbuffer[i]; } return array_get(&(s->directory),s->directory.next-number_of_entries); } @@ -471,7 +471,7 @@ static char is_long_name(const direntry_t* direntry) static char is_short_name(const direntry_t* direntry) { return !is_volume_label(direntry) && !is_long_name(direntry) - && !is_free(direntry); + && !is_free(direntry); } =20 static char is_directory(const direntry_t* direntry) @@ -527,73 +527,73 @@ static uint16_t fat_datetime(time_t time,int return_t= ime) { t =3D &t1; localtime_r(&time,t); if(return_time) - return cpu_to_le16((t->tm_sec/2)|(t->tm_min<<5)|(t->tm_hour<<11)); + return cpu_to_le16((t->tm_sec/2)|(t->tm_min<<5)|(t->tm_hour<<11)); return cpu_to_le16((t->tm_mday)|((t->tm_mon+1)<<5)|((t->tm_year-80)<<9= )); } =20 static inline void fat_set(BDRVVVFATState* s,unsigned int cluster,uint32_t= value) { if(s->fat_type=3D=3D32) { - uint32_t* entry=3Darray_get(&(s->fat),cluster); - *entry=3Dcpu_to_le32(value); + uint32_t* entry=3Darray_get(&(s->fat),cluster); + *entry=3Dcpu_to_le32(value); } else if(s->fat_type=3D=3D16) { - uint16_t* entry=3Darray_get(&(s->fat),cluster); - *entry=3Dcpu_to_le16(value&0xffff); + uint16_t* entry=3Darray_get(&(s->fat),cluster); + *entry=3Dcpu_to_le16(value&0xffff); } else { - int offset =3D (cluster*3/2); - unsigned char* p =3D array_get(&(s->fat), offset); + int offset =3D (cluster*3/2); + unsigned char* p =3D array_get(&(s->fat), offset); switch (cluster&1) { - case 0: - p[0] =3D value&0xff; - p[1] =3D (p[1]&0xf0) | ((value>>8)&0xf); - break; - case 1: - p[0] =3D (p[0]&0xf) | ((value&0xf)<<4); - p[1] =3D (value>>4); - break; - } + case 0: + p[0] =3D value&0xff; + p[1] =3D (p[1]&0xf0) | ((value>>8)&0xf); + break; + case 1: + p[0] =3D (p[0]&0xf) | ((value&0xf)<<4); + p[1] =3D (value>>4); + break; + } } } =20 static inline uint32_t fat_get(BDRVVVFATState* s,unsigned int cluster) { if(s->fat_type=3D=3D32) { - uint32_t* entry=3Darray_get(&(s->fat),cluster); - return le32_to_cpu(*entry); + uint32_t* entry=3Darray_get(&(s->fat),cluster); + return le32_to_cpu(*entry); } else if(s->fat_type=3D=3D16) { - uint16_t* entry=3Darray_get(&(s->fat),cluster); - return le16_to_cpu(*entry); + uint16_t* entry=3Darray_get(&(s->fat),cluster); + return le16_to_cpu(*entry); } else { - const uint8_t* x=3D(uint8_t*)(s->fat.pointer)+cluster*3/2; - return ((x[0]|(x[1]<<8))>>(cluster&1?4:0))&0x0fff; + const uint8_t* x=3D(uint8_t*)(s->fat.pointer)+cluster*3/2; + return ((x[0]|(x[1]<<8))>>(cluster&1?4:0))&0x0fff; } } =20 static inline int fat_eof(BDRVVVFATState* s,uint32_t fat_entry) { if(fat_entry>s->max_fat_value-8) - return -1; + return -1; return 0; } =20 static inline void init_fat(BDRVVVFATState* s) { if (s->fat_type =3D=3D 12) { - array_init(&(s->fat),1); - array_ensure_allocated(&(s->fat), - s->sectors_per_fat * 0x200 * 3 / 2 - 1); + array_init(&(s->fat),1); + array_ensure_allocated(&(s->fat), + s->sectors_per_fat * 0x200 * 3 / 2 - 1); } else { - array_init(&(s->fat),(s->fat_type=3D=3D32?4:2)); - array_ensure_allocated(&(s->fat), - s->sectors_per_fat * 0x200 / s->fat.item_size - 1); + array_init(&(s->fat),(s->fat_type=3D=3D32?4:2)); + array_ensure_allocated(&(s->fat), + s->sectors_per_fat * 0x200 / s->fat.item_size - 1); } memset(s->fat.pointer,0,s->fat.size); =20 switch(s->fat_type) { - case 12: s->max_fat_value=3D0xfff; break; - case 16: s->max_fat_value=3D0xffff; break; - case 32: s->max_fat_value=3D0x0fffffff; break; - default: s->max_fat_value=3D0; /* error... */ + case 12: s->max_fat_value=3D0xfff; break; + case 16: s->max_fat_value=3D0xffff; break; + case 32: s->max_fat_value=3D0x0fffffff; break; + default: s->max_fat_value=3D0; /* error... */ } =20 } @@ -601,17 +601,17 @@ static inline void init_fat(BDRVVVFATState* s) /* TODO: in create_short_filename, 0xe5->0x05 is not yet handled! */ /* TODO: in parse_short_filename, 0x05->0xe5 is not yet handled! */ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s, - unsigned int directory_start, const char* filename, int is_dot) + unsigned int directory_start, const char* filename, int is_dot) { int i,j,long_index=3Ds->directory.next; direntry_t* entry =3D NULL; direntry_t* entry_long =3D NULL; =20 if(is_dot) { - entry=3Darray_get_next(&(s->directory)); + entry=3Darray_get_next(&(s->directory)); memset(entry->name, 0x20, sizeof(entry->name)); - memcpy(entry->name,filename,strlen(filename)); - return entry; + memcpy(entry->name,filename,strlen(filename)); + return entry; } =20 entry_long=3Dcreate_long_filename(s,filename); @@ -619,9 +619,9 @@ static inline direntry_t* create_short_and_long_name(BD= RVVVFATState* s, i =3D strlen(filename); for(j =3D i - 1; j>0 && filename[j]!=3D'.';j--); if (j > 0) - i =3D (j > 8 ? 8 : j); + i =3D (j > 8 ? 8 : j); else if (i > 8) - i =3D 8; + i =3D 8; =20 entry=3Darray_get_next(&(s->directory)); memset(entry->name, 0x20, sizeof(entry->name)); @@ -635,53 +635,53 @@ static inline direntry_t* create_short_and_long_name(= BDRVVVFATState* s, =20 /* upcase & remove unwanted characters */ for(i=3D10;i>=3D0;i--) { - if(i=3D=3D10 || i=3D=3D7) for(;i>0 && entry->name[i]=3D=3D' ';i--); - if(entry->name[i]<=3D' ' || entry->name[i]>0x7f - || strchr(".*?<>|\":/\\[];,+=3D'",entry->name[i])) - entry->name[i]=3D'_'; + if(i=3D=3D10 || i=3D=3D7) for(;i>0 && entry->name[i]=3D=3D' ';i--); + if(entry->name[i]<=3D' ' || entry->name[i]>0x7f + || strchr(".*?<>|\":/\\[];,+=3D'",entry->name[i])) + entry->name[i]=3D'_'; else if(entry->name[i]>=3D'a' && entry->name[i]<=3D'z') entry->name[i]+=3D'A'-'a'; } =20 /* mangle duplicates */ while(1) { - direntry_t* entry1=3Darray_get(&(s->directory),directory_start); - int j; - - for(;entry1name,entry->name,11)) - break; /* found dupe */ - if(entry1=3D=3Dentry) /* no dupe found */ - break; - - /* use all 8 characters of name */ - if(entry->name[7]=3D=3D' ') { - int j; - for(j=3D6;j>0 && entry->name[j]=3D=3D' ';j--) - entry->name[j]=3D'~'; - } - - /* increment number */ - for(j=3D7;j>0 && entry->name[j]=3D=3D'9';j--) - entry->name[j]=3D'0'; - if(j>0) { - if(entry->name[j]<'0' || entry->name[j]>'9') - entry->name[j]=3D'0'; - else - entry->name[j]++; - } + direntry_t* entry1=3Darray_get(&(s->directory),directory_start); + int j; + + for(;entry1name,entry->name,1= 1)) + break; /* found dupe */ + if(entry1=3D=3Dentry) /* no dupe found */ + break; + + /* use all 8 characters of name */ + if(entry->name[7]=3D=3D' ') { + int j; + for(j=3D6;j>0 && entry->name[j]=3D=3D' ';j--) + entry->name[j]=3D'~'; + } + + /* increment number */ + for(j=3D7;j>0 && entry->name[j]=3D=3D'9';j--) + entry->name[j]=3D'0'; + if(j>0) { + if(entry->name[j]<'0' || entry->name[j]>'9') + entry->name[j]=3D'0'; + else + entry->name[j]++; + } } =20 /* calculate checksum; propagate to long name */ if(entry_long) { uint8_t chksum=3Dfat_chksum(entry); =20 - /* calculate anew, because realloc could have taken place */ - entry_long=3Darray_get(&(s->directory),long_index); - while(entry_longreserved[1]=3Dchksum; - entry_long++; - } + /* calculate anew, because realloc could have taken place */ + entry_long=3Darray_get(&(s->directory),long_index); + while(entry_longreserved[1]=3Dchksum; + entry_long++; + } } =20 return entry; @@ -708,80 +708,80 @@ static int read_directory(BDRVVVFATState* s, int mapp= ing_index) assert(mapping->mode & MODE_DIRECTORY); =20 if(!dir) { - mapping->end =3D mapping->begin; - return -1; + mapping->end =3D mapping->begin; + return -1; } =20 i =3D mapping->info.dir.first_dir_index =3D - first_cluster =3D=3D 0 ? 0 : s->directory.next; + first_cluster =3D=3D 0 ? 0 : s->directory.next; =20 /* actually read the directory, and allocate the mappings */ while((entry=3Dreaddir(dir))) { - unsigned int length=3Dstrlen(dirname)+2+strlen(entry->d_name); + unsigned int length=3Dstrlen(dirname)+2+strlen(entry->d_name); char* buffer; - direntry_t* direntry; + direntry_t* direntry; struct stat st; - int is_dot=3D!strcmp(entry->d_name,"."); - int is_dotdot=3D!strcmp(entry->d_name,".."); + int is_dot=3D!strcmp(entry->d_name,"."); + int is_dotdot=3D!strcmp(entry->d_name,".."); =20 - if(first_cluster =3D=3D 0 && (is_dotdot || is_dot)) - continue; + if(first_cluster =3D=3D 0 && (is_dotdot || is_dot)) + continue; =20 - buffer =3D g_malloc(length); - snprintf(buffer,length,"%s/%s",dirname,entry->d_name); + buffer =3D g_malloc(length); + snprintf(buffer,length,"%s/%s",dirname,entry->d_name); =20 - if(stat(buffer,&st)<0) { + if(stat(buffer,&st)<0) { g_free(buffer); continue; - } - - /* create directory entry for this file */ - direntry=3Dcreate_short_and_long_name(s, i, entry->d_name, - is_dot || is_dotdot); - direntry->attributes=3D(S_ISDIR(st.st_mode)?0x10:0x20); - direntry->reserved[0]=3Ddirentry->reserved[1]=3D0; - direntry->ctime=3Dfat_datetime(st.st_ctime,1); - direntry->cdate=3Dfat_datetime(st.st_ctime,0); - direntry->adate=3Dfat_datetime(st.st_atime,0); - direntry->begin_hi=3D0; - direntry->mtime=3Dfat_datetime(st.st_mtime,1); - direntry->mdate=3Dfat_datetime(st.st_mtime,0); - if(is_dotdot) - set_begin_of_direntry(direntry, first_cluster_of_parent); - else if(is_dot) - set_begin_of_direntry(direntry, first_cluster); - else - direntry->begin=3D0; /* do that later */ + } + + /* create directory entry for this file */ + direntry=3Dcreate_short_and_long_name(s, i, entry->d_name, + is_dot || is_dotdot); + direntry->attributes=3D(S_ISDIR(st.st_mode)?0x10:0x20); + direntry->reserved[0]=3Ddirentry->reserved[1]=3D0; + direntry->ctime=3Dfat_datetime(st.st_ctime,1); + direntry->cdate=3Dfat_datetime(st.st_ctime,0); + direntry->adate=3Dfat_datetime(st.st_atime,0); + direntry->begin_hi=3D0; + direntry->mtime=3Dfat_datetime(st.st_mtime,1); + direntry->mdate=3Dfat_datetime(st.st_mtime,0); + if(is_dotdot) + set_begin_of_direntry(direntry, first_cluster_of_parent); + else if(is_dot) + set_begin_of_direntry(direntry, first_cluster); + else + direntry->begin=3D0; /* do that later */ if (st.st_size > 0x7fffffff) { - fprintf(stderr, "File %s is larger than 2GB\n", buffer); + fprintf(stderr, "File %s is larger than 2GB\n", buffer); g_free(buffer); closedir(dir); - return -2; + return -2; } - direntry->size=3Dcpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size); - - /* create mapping for this file */ - if(!is_dot && !is_dotdot && (S_ISDIR(st.st_mode) || st.st_size)) { - s->current_mapping =3D array_get_next(&(s->mapping)); - s->current_mapping->begin=3D0; - s->current_mapping->end=3Dst.st_size; - /* - * we get the direntry of the most recent direntry, which - * contains the short name and all the relevant information. - */ - s->current_mapping->dir_index=3Ds->directory.next-1; - s->current_mapping->first_mapping_index =3D -1; - if (S_ISDIR(st.st_mode)) { - s->current_mapping->mode =3D MODE_DIRECTORY; - s->current_mapping->info.dir.parent_mapping_index =3D - mapping_index; - } else { - s->current_mapping->mode =3D MODE_UNDEFINED; - s->current_mapping->info.file.offset =3D 0; - } - s->current_mapping->path=3Dbuffer; - s->current_mapping->read_only =3D - (st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) =3D=3D 0; + direntry->size=3Dcpu_to_le32(S_ISDIR(st.st_mode)?0:st.st_size); + + /* create mapping for this file */ + if(!is_dot && !is_dotdot && (S_ISDIR(st.st_mode) || st.st_size)) { + s->current_mapping =3D array_get_next(&(s->mapping)); + s->current_mapping->begin=3D0; + s->current_mapping->end=3Dst.st_size; + /* + * we get the direntry of the most recent direntry, which + * contains the short name and all the relevant information. + */ + s->current_mapping->dir_index=3Ds->directory.next-1; + s->current_mapping->first_mapping_index =3D -1; + if (S_ISDIR(st.st_mode)) { + s->current_mapping->mode =3D MODE_DIRECTORY; + s->current_mapping->info.dir.parent_mapping_index =3D + mapping_index; + } else { + s->current_mapping->mode =3D MODE_UNDEFINED; + s->current_mapping->info.file.offset =3D 0; + } + s->current_mapping->path=3Dbuffer; + s->current_mapping->read_only =3D + (st.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) =3D=3D 0; } else { g_free(buffer); } @@ -790,25 +790,25 @@ static int read_directory(BDRVVVFATState* s, int mapp= ing_index) =20 /* fill with zeroes up to the end of the cluster */ while(s->directory.next%(0x10*s->sectors_per_cluster)) { - direntry_t* direntry=3Darray_get_next(&(s->directory)); - memset(direntry,0,sizeof(direntry_t)); + direntry_t* direntry=3Darray_get_next(&(s->directory)); + memset(direntry,0,sizeof(direntry_t)); } =20 /* TODO: if there are more entries, bootsector has to be adjusted! */ #define ROOT_ENTRIES (0x02 * 0x10 * s->sectors_per_cluster) if (mapping_index =3D=3D 0 && s->directory.next < ROOT_ENTRIES) { - /* root directory */ - int cur =3D s->directory.next; - array_ensure_allocated(&(s->directory), ROOT_ENTRIES - 1); - s->directory.next =3D ROOT_ENTRIES; - memset(array_get(&(s->directory), cur), 0, - (ROOT_ENTRIES - cur) * sizeof(direntry_t)); + /* root directory */ + int cur =3D s->directory.next; + array_ensure_allocated(&(s->directory), ROOT_ENTRIES - 1); + s->directory.next =3D ROOT_ENTRIES; + memset(array_get(&(s->directory), cur), 0, + (ROOT_ENTRIES - cur) * sizeof(direntry_t)); } =20 /* reget the mapping, since s->mapping was possibly realloc()ed */ mapping =3D array_get(&(s->mapping), mapping_index); first_cluster +=3D (s->directory.next - mapping->info.dir.first_dir_in= dex) - * 0x20 / s->cluster_size; + * 0x20 / s->cluster_size; mapping->end =3D first_cluster; =20 direntry =3D array_get(&(s->directory), mapping->dir_index); @@ -856,8 +856,8 @@ static int init_directories(BDRVVVFATState* s, =20 /* add volume label */ { - direntry_t* entry=3Darray_get_next(&(s->directory)); - entry->attributes=3D0x28; /* archive | volume label */ + direntry_t* entry=3Darray_get_next(&(s->directory)); + entry->attributes=3D0x28; /* archive | volume label */ memcpy(entry->name, s->volume_label, sizeof(entry->name)); } =20 @@ -875,61 +875,61 @@ static int init_directories(BDRVVVFATState* s, mapping->path =3D g_strdup(dirname); i =3D strlen(mapping->path); if (i > 0 && mapping->path[i - 1] =3D=3D '/') - mapping->path[i - 1] =3D '\0'; + mapping->path[i - 1] =3D '\0'; mapping->mode =3D MODE_DIRECTORY; mapping->read_only =3D 0; s->path =3D mapping->path; =20 for (i =3D 0, cluster =3D 0; i < s->mapping.next; i++) { - /* MS-DOS expects the FAT to be 0 for the root directory - * (except for the media byte). */ - /* LATER TODO: still true for FAT32? */ - int fix_fat =3D (i !=3D 0); - mapping =3D array_get(&(s->mapping), i); + /* MS-DOS expects the FAT to be 0 for the root directory + * (except for the media byte). */ + /* LATER TODO: still true for FAT32? */ + int fix_fat =3D (i !=3D 0); + mapping =3D array_get(&(s->mapping), i); =20 if (mapping->mode & MODE_DIRECTORY) { - mapping->begin =3D cluster; - if(read_directory(s, i)) { + mapping->begin =3D cluster; + if(read_directory(s, i)) { error_setg(errp, "Could not read directory %s", mapping->path); - return -1; - } - mapping =3D array_get(&(s->mapping), i); - } else { - assert(mapping->mode =3D=3D MODE_UNDEFINED); - mapping->mode=3DMODE_NORMAL; - mapping->begin =3D cluster; - if (mapping->end > 0) { - direntry_t* direntry =3D array_get(&(s->directory), - mapping->dir_index); - - mapping->end =3D cluster + 1 + (mapping->end-1)/s->cluster_size; - set_begin_of_direntry(direntry, mapping->begin); - } else { - mapping->end =3D cluster + 1; - fix_fat =3D 0; - } - } - - assert(mapping->begin < mapping->end); - - /* next free cluster */ - cluster =3D mapping->end; - - if(cluster > s->cluster_count) { + return -1; + } + mapping =3D array_get(&(s->mapping), i); + } else { + assert(mapping->mode =3D=3D MODE_UNDEFINED); + mapping->mode=3DMODE_NORMAL; + mapping->begin =3D cluster; + if (mapping->end > 0) { + direntry_t* direntry =3D array_get(&(s->directory), + mapping->dir_index); + + mapping->end =3D cluster + 1 + (mapping->end-1)/s->cluster= _size; + set_begin_of_direntry(direntry, mapping->begin); + } else { + mapping->end =3D cluster + 1; + fix_fat =3D 0; + } + } + + assert(mapping->begin < mapping->end); + + /* next free cluster */ + cluster =3D mapping->end; + + if(cluster > s->cluster_count) { error_setg(errp, "Directory does not fit in FAT%d (capacity %.2f MB)= ", s->fat_type, s->sector_count / 2000.0); return -1; - } + } =20 - /* fix fat for entry */ - if (fix_fat) { - int j; - for(j =3D mapping->begin; j < mapping->end - 1; j++) - fat_set(s, j, j+1); - fat_set(s, mapping->end - 1, s->max_fat_value); - } + /* fix fat for entry */ + if (fix_fat) { + int j; + for(j =3D mapping->begin; j < mapping->end - 1; j++) + fat_set(s, j, j+1); + fat_set(s, mapping->end - 1, s->max_fat_value); + } } =20 mapping =3D array_get(&(s->mapping), 0); @@ -1135,7 +1135,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, =20 switch (s->fat_type) { case 32: - fprintf(stderr, "Big fat greek warning: FAT32 has not been tested. " + fprintf(stderr, "Big fat greek warning: FAT32 has not been tes= ted. " "You are welcome to do so!\n"); break; case 16: @@ -1229,11 +1229,11 @@ static void vvfat_refresh_limits(BlockDriverState *= bs, Error **errp) static inline void vvfat_close_current_file(BDRVVVFATState *s) { if(s->current_mapping) { - s->current_mapping =3D NULL; - if (s->current_fd) { - qemu_close(s->current_fd); - s->current_fd =3D 0; - } + s->current_mapping =3D NULL; + if (s->current_fd) { + qemu_close(s->current_fd); + s->current_fd =3D 0; + } } s->current_cluster =3D -1; } @@ -1245,26 +1245,26 @@ static inline int find_mapping_for_cluster_aux(BDRV= VVFATState* s,int cluster_num { while(1) { int index3; - mapping_t* mapping; - index3=3D(index1+index2)/2; - mapping=3Darray_get(&(s->mapping),index3); - assert(mapping->begin < mapping->end); - if(mapping->begin>=3Dcluster_num) { - assert(index2!=3Dindex3 || index2=3D=3D0); - if(index2=3D=3Dindex3) - return index1; - index2=3Dindex3; - } else { - if(index1=3D=3Dindex3) - return mapping->end<=3Dcluster_num ? index2 : index1; - index1=3Dindex3; - } - assert(index1<=3Dindex2); - DLOG(mapping=3Darray_get(&(s->mapping),index1); - assert(mapping->begin<=3Dcluster_num); - assert(index2 >=3D s->mapping.next || - ((mapping =3D array_get(&(s->mapping),index2)) && - mapping->end>cluster_num))); + mapping_t* mapping; + index3=3D(index1+index2)/2; + mapping=3Darray_get(&(s->mapping),index3); + assert(mapping->begin < mapping->end); + if(mapping->begin>=3Dcluster_num) { + assert(index2!=3Dindex3 || index2=3D=3D0); + if(index2=3D=3Dindex3) + return index1; + index2=3Dindex3; + } else { + if(index1=3D=3Dindex3) + return mapping->end<=3Dcluster_num ? index2 : index1; + index1=3Dindex3; + } + assert(index1<=3Dindex2); + DLOG(mapping=3Darray_get(&(s->mapping),index1); + assert(mapping->begin<=3Dcluster_num); + assert(index2 >=3D s->mapping.next || + ((mapping =3D array_get(&(s->mapping),index2)) && + mapping->end>cluster_num))); } } =20 @@ -1284,16 +1284,16 @@ static inline mapping_t* find_mapping_for_cluster(B= DRVVVFATState* s,int cluster_ static int open_file(BDRVVVFATState* s,mapping_t* mapping) { if(!mapping) - return -1; + return -1; if(!s->current_mapping || - strcmp(s->current_mapping->path,mapping->path)) { - /* open file */ - int fd =3D qemu_open(mapping->path, O_RDONLY | O_BINARY | O_LARGEFILE); - if(fd<0) - return -1; - vvfat_close_current_file(s); - s->current_fd =3D fd; - s->current_mapping =3D mapping; + strcmp(s->current_mapping->path,mapping->path)) { + /* open file */ + int fd =3D qemu_open(mapping->path, O_RDONLY | O_BINARY | O_LARGEF= ILE); + if(fd<0) + return -1; + vvfat_close_current_file(s); + s->current_fd =3D fd; + s->current_mapping =3D mapping; } return 0; } @@ -1301,47 +1301,47 @@ static int open_file(BDRVVVFATState* s,mapping_t* m= apping) static inline int read_cluster(BDRVVVFATState *s,int cluster_num) { if(s->current_cluster !=3D cluster_num) { - int result=3D0; - off_t offset; - assert(!s->current_mapping || s->current_fd || (s->current_mapping->mode = & MODE_DIRECTORY)); - if(!s->current_mapping - || s->current_mapping->begin>cluster_num - || s->current_mapping->end<=3Dcluster_num) { - /* binary search of mappings for file */ - mapping_t* mapping=3Dfind_mapping_for_cluster(s,cluster_num); - - assert(!mapping || (cluster_num>=3Dmapping->begin && cluster_numend)); - - if (mapping && mapping->mode & MODE_DIRECTORY) { - vvfat_close_current_file(s); - s->current_mapping =3D mapping; + int result=3D0; + off_t offset; + assert(!s->current_mapping || s->current_fd || (s->current_mapping= ->mode & MODE_DIRECTORY)); + if(!s->current_mapping + || s->current_mapping->begin>cluster_num + || s->current_mapping->end<=3Dcluster_num) { + /* binary search of mappings for file */ + mapping_t* mapping=3Dfind_mapping_for_cluster(s,cluster_num); + + assert(!mapping || (cluster_num>=3Dmapping->begin && cluster_n= umend)); + + if (mapping && mapping->mode & MODE_DIRECTORY) { + vvfat_close_current_file(s); + s->current_mapping =3D mapping; read_cluster_directory: - offset =3D s->cluster_size*(cluster_num-s->current_mapping->begin); - s->cluster =3D (unsigned char*)s->directory.pointer+offset - + 0x20*s->current_mapping->info.dir.first_dir_index; - assert(((s->cluster-(unsigned char*)s->directory.pointer)%s->cluster_siz= e)=3D=3D0); - assert((char*)s->cluster+s->cluster_size <=3D s->directory.pointer+s->di= rectory.next*s->directory.item_size); - s->current_cluster =3D cluster_num; - return 0; - } - - if(open_file(s,mapping)) - return -2; - } else if (s->current_mapping->mode & MODE_DIRECTORY) - goto read_cluster_directory; - - assert(s->current_fd); - - offset=3Ds->cluster_size*(cluster_num-s->current_mapping->begin)+s->curre= nt_mapping->info.file.offset; - if(lseek(s->current_fd, offset, SEEK_SET)!=3Doffset) - return -3; - s->cluster=3Ds->cluster_buffer; - result=3Dread(s->current_fd,s->cluster,s->cluster_size); - if(result<0) { - s->current_cluster =3D -1; - return -1; - } - s->current_cluster =3D cluster_num; + offset =3D s->cluster_size*(cluster_num-s->current_mapping= ->begin); + s->cluster =3D (unsigned char*)s->directory.pointer+offset + + 0x20*s->current_mapping->info.dir.first_dir_inde= x; + assert(((s->cluster-(unsigned char*)s->directory.pointer)%= s->cluster_size)=3D=3D0); + assert((char*)s->cluster+s->cluster_size <=3D s->directory= .pointer+s->directory.next*s->directory.item_size); + s->current_cluster =3D cluster_num; + return 0; + } + + if(open_file(s,mapping)) + return -2; + } else if (s->current_mapping->mode & MODE_DIRECTORY) + goto read_cluster_directory; + + assert(s->current_fd); + + offset=3Ds->cluster_size*(cluster_num-s->current_mapping->begin)+s= ->current_mapping->info.file.offset; + if(lseek(s->current_fd, offset, SEEK_SET)!=3Doffset) + return -3; + s->cluster=3Ds->cluster_buffer; + result=3Dread(s->current_fd,s->cluster,s->cluster_size); + if(result<0) { + s->current_cluster =3D -1; + return -1; + } + s->current_cluster =3D cluster_num; } return 0; } @@ -1354,28 +1354,28 @@ static void print_direntry(const direntry_t* dirent= ry) =20 fprintf(stderr, "direntry %p: ", direntry); if(!direntry) - return; + return; if(is_long_name(direntry)) { - unsigned char* c=3D(unsigned char*)direntry; - int i; - for(i=3D1;i<11 && c[i] && c[i]!=3D0xff;i+=3D2) + unsigned char* c=3D(unsigned char*)direntry; + int i; + for(i=3D1;i<11 && c[i] && c[i]!=3D0xff;i+=3D2) #define ADD_CHAR(c) {buffer[j] =3D (c); if (buffer[j] < ' ') buffer[j] =3D= 0xb0; j++;} - ADD_CHAR(c[i]); - for(i=3D14;i<26 && c[i] && c[i]!=3D0xff;i+=3D2) - ADD_CHAR(c[i]); - for(i=3D28;i<32 && c[i] && c[i]!=3D0xff;i+=3D2) - ADD_CHAR(c[i]); - buffer[j] =3D 0; - fprintf(stderr, "%s\n", buffer); + ADD_CHAR(c[i]); + for(i=3D14;i<26 && c[i] && c[i]!=3D0xff;i+=3D2) + ADD_CHAR(c[i]); + for(i=3D28;i<32 && c[i] && c[i]!=3D0xff;i+=3D2) + ADD_CHAR(c[i]); + buffer[j] =3D 0; + fprintf(stderr, "%s\n", buffer); } else { - int i; - for(i=3D0;i<11;i++) - ADD_CHAR(direntry->name[i]); - buffer[j] =3D 0; - fprintf(stderr,"%s attributes=3D0x%02x begin=3D%d size=3D%d\n", - buffer, - direntry->attributes, - begin_of_direntry(direntry),le32_to_cpu(direntry->size)); + int i; + for(i=3D0;i<11;i++) + ADD_CHAR(direntry->name[i]); + buffer[j] =3D 0; + fprintf(stderr,"%s attributes=3D0x%02x begin=3D%d size=3D%d\n", + buffer, + direntry->attributes, + begin_of_direntry(direntry),le32_to_cpu(direntry->size)); } } =20 @@ -1387,9 +1387,9 @@ static void print_mapping(const mapping_t* mapping) mapping->first_mapping_index, mapping->path, mapping->mode); =20 if (mapping->mode & MODE_DIRECTORY) - fprintf(stderr, "parent_mapping_index =3D %d, first_dir_index =3D %d\n", = mapping->info.dir.parent_mapping_index, mapping->info.dir.first_dir_index); + fprintf(stderr, "parent_mapping_index =3D %d, first_dir_index =3D = %d\n", mapping->info.dir.parent_mapping_index, mapping->info.dir.first_dir_= index); else - fprintf(stderr, "offset =3D %d\n", mapping->info.file.offset); + fprintf(stderr, "offset =3D %d\n", mapping->info.file.offset); } #endif =20 @@ -1400,10 +1400,10 @@ static int vvfat_read(BlockDriverState *bs, int64_t= sector_num, int i; =20 for(i=3D0;i=3D bs->total_sectors) - return -1; - if (s->qcow) { - int n; + if (sector_num >=3D bs->total_sectors) + return -1; + if (s->qcow) { + int n; int ret; ret =3D bdrv_is_allocated(s->qcow->bs, sector_num, nb_sectors - i, &n); @@ -1421,25 +1421,25 @@ static int vvfat_read(BlockDriverState *bs, int64_t= sector_num, continue; } DLOG(fprintf(stderr, "sector %d not allocated\n", (int)sector_num)); - } - if(sector_numfaked_sectors) { - if(sector_numfirst_sectors_number) - memcpy(buf+i*0x200,&(s->first_sectors[sector_num*0x200]),0x200); - else if(sector_num-s->first_sectors_numbersectors_per_fat) - memcpy(buf+i*0x200,&(s->fat.pointer[(sector_num-s->first_sectors_number)= *0x200]),0x200); - else if(sector_num-s->first_sectors_number-s->sectors_per_fatsect= ors_per_fat) - memcpy(buf+i*0x200,&(s->fat.pointer[(sector_num-s->first_sectors_number-= s->sectors_per_fat)*0x200]),0x200); - } else { - uint32_t sector=3Dsector_num-s->faked_sectors, - sector_offset_in_cluster=3D(sector%s->sectors_per_cluster), - cluster_num=3Dsector/s->sectors_per_cluster; - if(cluster_num > s->cluster_count || read_cluster(s, cluster_num) != =3D 0) { - /* LATER TODO: strict: return -1; */ - memset(buf+i*0x200,0,0x200); - continue; - } - memcpy(buf+i*0x200,s->cluster+sector_offset_in_cluster*0x200,0x200); - } + } + if(sector_numfaked_sectors) { + if(sector_numfirst_sectors_number) + memcpy(buf+i*0x200,&(s->first_sectors[sector_num*0x200]),0= x200); + else if(sector_num-s->first_sectors_numbersectors_per_fat) + memcpy(buf+i*0x200,&(s->fat.pointer[(sector_num-s->first_s= ectors_number)*0x200]),0x200); + else if(sector_num-s->first_sectors_number-s->sectors_per_fat<= s->sectors_per_fat) + memcpy(buf+i*0x200,&(s->fat.pointer[(sector_num-s->first_s= ectors_number-s->sectors_per_fat)*0x200]),0x200); + } else { + uint32_t sector=3Dsector_num-s->faked_sectors, + sector_offset_in_cluster=3D(sector%s->sectors_per_cluster), + cluster_num=3Dsector/s->sectors_per_cluster; + if(cluster_num > s->cluster_count || read_cluster(s, cluster_n= um) !=3D 0) { + /* LATER TODO: strict: return -1; */ + memset(buf+i*0x200,0,0x200); + continue; + } + memcpy(buf+i*0x200,s->cluster+sector_offset_in_cluster*0x200,0= x200); + } } return 0; } @@ -1497,14 +1497,14 @@ vvfat_co_preadv(BlockDriverState *bs, uint64_t offs= et, uint64_t bytes, typedef struct commit_t { char* path; union { - struct { uint32_t cluster; } rename; - struct { int dir_index; uint32_t modified_offset; } writeout; - struct { uint32_t first_cluster; } new_file; - struct { uint32_t cluster; } mkdir; + struct { uint32_t cluster; } rename; + struct { int dir_index; uint32_t modified_offset; } writeout; + struct { uint32_t first_cluster; } new_file; + struct { uint32_t cluster; } mkdir; } param; /* DELETEs and RMDIRs are handled differently: see handle_deletes() */ enum { - ACTION_RENAME, ACTION_WRITEOUT, ACTION_NEW_FILE, ACTION_MKDIR + ACTION_RENAME, ACTION_WRITEOUT, ACTION_NEW_FILE, ACTION_MKDIR } action; } commit_t; =20 @@ -1513,19 +1513,19 @@ static void clear_commits(BDRVVVFATState* s) int i; DLOG(fprintf(stderr, "clear_commits (%d commits)\n", s->commits.next)); for (i =3D 0; i < s->commits.next; i++) { - commit_t* commit =3D array_get(&(s->commits), i); - assert(commit->path || commit->action =3D=3D ACTION_WRITEOUT); - if (commit->action !=3D ACTION_WRITEOUT) { - assert(commit->path); + commit_t* commit =3D array_get(&(s->commits), i); + assert(commit->path || commit->action =3D=3D ACTION_WRITEOUT); + if (commit->action !=3D ACTION_WRITEOUT) { + assert(commit->path); g_free(commit->path); - } else - assert(commit->path =3D=3D NULL); + } else + assert(commit->path =3D=3D NULL); } s->commits.next =3D 0; } =20 static void schedule_rename(BDRVVVFATState* s, - uint32_t cluster, char* new_path) + uint32_t cluster, char* new_path) { commit_t* commit =3D array_get_next(&(s->commits)); commit->path =3D new_path; @@ -1534,7 +1534,7 @@ static void schedule_rename(BDRVVVFATState* s, } =20 static void schedule_writeout(BDRVVVFATState* s, - int dir_index, uint32_t modified_offset) + int dir_index, uint32_t modified_offset) { commit_t* commit =3D array_get_next(&(s->commits)); commit->path =3D NULL; @@ -1544,7 +1544,7 @@ static void schedule_writeout(BDRVVVFATState* s, } =20 static void schedule_new_file(BDRVVVFATState* s, - char* path, uint32_t first_cluster) + char* path, uint32_t first_cluster) { commit_t* commit =3D array_get_next(&(s->commits)); commit->path =3D path; @@ -1579,72 +1579,72 @@ static void lfn_init(long_file_name* lfn) =20 /* return 0 if parsed successfully, > 0 if no long name, < 0 if error */ static int parse_long_name(long_file_name* lfn, - const direntry_t* direntry) + const direntry_t* direntry) { int i, j, offset; const unsigned char* pointer =3D (const unsigned char*)direntry; =20 if (!is_long_name(direntry)) - return 1; + return 1; =20 if (pointer[0] & 0x40) { - lfn->sequence_number =3D pointer[0] & 0x3f; - lfn->checksum =3D pointer[13]; - lfn->name[0] =3D 0; - lfn->name[lfn->sequence_number * 13] =3D 0; + lfn->sequence_number =3D pointer[0] & 0x3f; + lfn->checksum =3D pointer[13]; + lfn->name[0] =3D 0; + lfn->name[lfn->sequence_number * 13] =3D 0; } else if ((pointer[0] & 0x3f) !=3D --lfn->sequence_number) - return -1; + return -1; else if (pointer[13] !=3D lfn->checksum) - return -2; + return -2; else if (pointer[12] || pointer[26] || pointer[27]) - return -3; + return -3; =20 offset =3D 13 * (lfn->sequence_number - 1); for (i =3D 0, j =3D 1; i < 13; i++, j+=3D2) { - if (j =3D=3D 11) - j =3D 14; - else if (j =3D=3D 26) - j =3D 28; + if (j =3D=3D 11) + j =3D 14; + else if (j =3D=3D 26) + j =3D 28; =20 - if (pointer[j+1] =3D=3D 0) - lfn->name[offset + i] =3D pointer[j]; - else if (pointer[j+1] !=3D 0xff || (pointer[0] & 0x40) =3D=3D 0) - return -4; - else - lfn->name[offset + i] =3D 0; + if (pointer[j+1] =3D=3D 0) + lfn->name[offset + i] =3D pointer[j]; + else if (pointer[j+1] !=3D 0xff || (pointer[0] & 0x40) =3D=3D 0) + return -4; + else + lfn->name[offset + i] =3D 0; } =20 if (pointer[0] & 0x40) - lfn->len =3D offset + strlen((char*)lfn->name + offset); + lfn->len =3D offset + strlen((char*)lfn->name + offset); =20 return 0; } =20 /* returns 0 if successful, >0 if no short_name, and <0 on error */ static int parse_short_name(BDRVVVFATState* s, - long_file_name* lfn, direntry_t* direntry) + long_file_name* lfn, direntry_t* direntry) { int i, j; =20 if (!is_short_name(direntry)) - return 1; + return 1; =20 for (j =3D 7; j >=3D 0 && direntry->name[j] =3D=3D ' '; j--); for (i =3D 0; i <=3D j; i++) { - if (direntry->name[i] <=3D ' ' || direntry->name[i] > 0x7f) - return -1; - else if (s->downcase_short_names) - lfn->name[i] =3D qemu_tolower(direntry->name[i]); - else - lfn->name[i] =3D direntry->name[i]; + if (direntry->name[i] <=3D ' ' || direntry->name[i] > 0x7f) + return -1; + else if (s->downcase_short_names) + lfn->name[i] =3D qemu_tolower(direntry->name[i]); + else + lfn->name[i] =3D direntry->name[i]; } =20 for (j =3D 2; j >=3D 0 && direntry->name[8 + j] =3D=3D ' '; j--) { } if (j >=3D 0) { - lfn->name[i++] =3D '.'; - lfn->name[i + j + 1] =3D '\0'; - for (;j >=3D 0; j--) { + lfn->name[i++] =3D '.'; + lfn->name[i + j + 1] =3D '\0'; + for (;j >=3D 0; j--) { uint8_t c =3D direntry->name[8 + j]; if (c <=3D ' ' || c > 0x7f) { return -2; @@ -1653,9 +1653,9 @@ static int parse_short_name(BDRVVVFATState* s, } else { lfn->name[i + j] =3D c; } - } + } } else - lfn->name[i + j + 1] =3D '\0'; + lfn->name[i + j + 1] =3D '\0'; =20 lfn->len =3D strlen((char*)lfn->name); =20 @@ -1663,13 +1663,13 @@ static int parse_short_name(BDRVVVFATState* s, } =20 static inline uint32_t modified_fat_get(BDRVVVFATState* s, - unsigned int cluster) + unsigned int cluster) { if (cluster < s->last_cluster_of_root_directory) { - if (cluster + 1 =3D=3D s->last_cluster_of_root_directory) - return s->max_fat_value; - else - return cluster + 1; + if (cluster + 1 =3D=3D s->last_cluster_of_root_directory) + return s->max_fat_value; + else + return cluster + 1; } =20 if (s->fat_type=3D=3D32) { @@ -1713,9 +1713,9 @@ static const char* get_basename(const char* path) { char* basename =3D strrchr(path, '/'); if (basename =3D=3D NULL) - return path; + return path; else - return basename + 1; /* strip '/' */ + return basename + 1; /* strip '/' */ } =20 /* @@ -1740,7 +1740,7 @@ typedef enum { * assumed to be *not* deleted (and *only* those). */ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, - direntry_t* direntry, const char* path) + direntry_t* direntry, const char* path) { /* * This is a little bit tricky: @@ -1773,85 +1773,85 @@ static uint32_t get_cluster_count_for_direntry(BDRV= VVFATState* s, =20 /* the root directory */ if (cluster_num =3D=3D 0) - return 0; + return 0; =20 /* write support */ if (s->qcow) { - basename2 =3D get_basename(path); + basename2 =3D get_basename(path); =20 - mapping =3D find_mapping_for_cluster(s, cluster_num); + mapping =3D find_mapping_for_cluster(s, cluster_num); =20 - if (mapping) { - const char* basename; + if (mapping) { + const char* basename; =20 - assert(mapping->mode & MODE_DELETED); - mapping->mode &=3D ~MODE_DELETED; + assert(mapping->mode & MODE_DELETED); + mapping->mode &=3D ~MODE_DELETED; =20 - basename =3D get_basename(mapping->path); + basename =3D get_basename(mapping->path); =20 - assert(mapping->mode & MODE_NORMAL); + assert(mapping->mode & MODE_NORMAL); =20 - /* rename */ - if (strcmp(basename, basename2)) - schedule_rename(s, cluster_num, g_strdup(path)); - } else if (is_file(direntry)) - /* new file */ - schedule_new_file(s, g_strdup(path), cluster_num); - else { + /* rename */ + if (strcmp(basename, basename2)) + schedule_rename(s, cluster_num, g_strdup(path)); + } else if (is_file(direntry)) + /* new file */ + schedule_new_file(s, g_strdup(path), cluster_num); + else { abort(); - return 0; - } + return 0; + } } =20 while(1) { - if (s->qcow) { - if (!copy_it && cluster_was_modified(s, cluster_num)) { - if (mapping =3D=3D NULL || - mapping->begin > cluster_num || - mapping->end <=3D cluster_num) - mapping =3D find_mapping_for_cluster(s, cluster_num); + if (s->qcow) { + if (!copy_it && cluster_was_modified(s, cluster_num)) { + if (mapping =3D=3D NULL || + mapping->begin > cluster_num || + mapping->end <=3D cluster_num) + mapping =3D find_mapping_for_cluster(s, cluster_num); =20 =20 - if (mapping && - (mapping->mode & MODE_DIRECTORY) =3D=3D 0) { + if (mapping && + (mapping->mode & MODE_DIRECTORY) =3D=3D 0) { =20 - /* was modified in qcow */ - if (offset !=3D mapping->info.file.offset + s->cluster_size - * (cluster_num - mapping->begin)) { - /* offset of this cluster in file chain has changed */ + /* was modified in qcow */ + if (offset !=3D mapping->info.file.offset + s->cluster= _size + * (cluster_num - mapping->begin)) { + /* offset of this cluster in file chain has change= d */ abort(); - copy_it =3D 1; - } else if (offset =3D=3D 0) { - const char* basename =3D get_basename(mapping->path); + copy_it =3D 1; + } else if (offset =3D=3D 0) { + const char* basename =3D get_basename(mapping->pat= h); =20 - if (strcmp(basename, basename2)) - copy_it =3D 1; - first_mapping_index =3D array_index(&(s->mapping), mapping); - } + if (strcmp(basename, basename2)) + copy_it =3D 1; + first_mapping_index =3D array_index(&(s->mapping),= mapping); + } =20 - if (mapping->first_mapping_index !=3D first_mapping_index - && mapping->info.file.offset > 0) { + if (mapping->first_mapping_index !=3D first_mapping_in= dex + && mapping->info.file.offset > 0) { abort(); - copy_it =3D 1; - } - - /* need to write out? */ - if (!was_modified && is_file(direntry)) { - was_modified =3D 1; - schedule_writeout(s, mapping->dir_index, offset); - } - } - } - - if (copy_it) { - int i, dummy; - /* - * This is horribly inefficient, but that is okay, since - * it is rarely executed, if at all. - */ - int64_t offset =3D cluster2sector(s, cluster_num); - - vvfat_close_current_file(s); + copy_it =3D 1; + } + + /* need to write out? */ + if (!was_modified && is_file(direntry)) { + was_modified =3D 1; + schedule_writeout(s, mapping->dir_index, offset); + } + } + } + + if (copy_it) { + int i, dummy; + /* + * This is horribly inefficient, but that is okay, since + * it is rarely executed, if at all. + */ + int64_t offset =3D cluster2sector(s, cluster_num); + + vvfat_close_current_file(s); for (i =3D 0; i < s->sectors_per_cluster; i++) { int res; =20 @@ -1870,22 +1870,22 @@ static uint32_t get_cluster_count_for_direntry(BDRV= VVFATState* s, } } } - } - } + } + } =20 - ret++; - if (s->used_clusters[cluster_num] & USED_ANY) - return 0; - s->used_clusters[cluster_num] =3D USED_FILE; + ret++; + if (s->used_clusters[cluster_num] & USED_ANY) + return 0; + s->used_clusters[cluster_num] =3D USED_FILE; =20 - cluster_num =3D modified_fat_get(s, cluster_num); + cluster_num =3D modified_fat_get(s, cluster_num); =20 - if (fat_eof(s, cluster_num)) - return ret; - else if (cluster_num < 2 || cluster_num > s->max_fat_value - 16) - return -1; + if (fat_eof(s, cluster_num)) + return ret; + else if (cluster_num < 2 || cluster_num > s->max_fat_value - 16) + return -1; =20 - offset +=3D s->cluster_size; + offset +=3D s->cluster_size; } } =20 @@ -1895,7 +1895,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVV= FATState* s, * used by the directory, its subdirectories and their files. */ static int check_directory_consistency(BDRVVVFATState *s, - int cluster_num, const char* path) + int cluster_num, const char* path) { int ret =3D 0; unsigned char* cluster =3D g_malloc(s->cluster_size); @@ -1912,104 +1912,104 @@ static int check_directory_consistency(BDRVVVFATS= tate *s, path2[path_len + 1] =3D '\0'; =20 if (mapping) { - const char* basename =3D get_basename(mapping->path); - const char* basename2 =3D get_basename(path); + const char* basename =3D get_basename(mapping->path); + const char* basename2 =3D get_basename(path); =20 - assert(mapping->mode & MODE_DIRECTORY); + assert(mapping->mode & MODE_DIRECTORY); =20 - assert(mapping->mode & MODE_DELETED); - mapping->mode &=3D ~MODE_DELETED; + assert(mapping->mode & MODE_DELETED); + mapping->mode &=3D ~MODE_DELETED; =20 - if (strcmp(basename, basename2)) - schedule_rename(s, cluster_num, g_strdup(path)); + if (strcmp(basename, basename2)) + schedule_rename(s, cluster_num, g_strdup(path)); } else - /* new directory */ - schedule_mkdir(s, cluster_num, g_strdup(path)); + /* new directory */ + schedule_mkdir(s, cluster_num, g_strdup(path)); =20 lfn_init(&lfn); do { - int i; - int subret =3D 0; + int i; + int subret =3D 0; =20 - ret++; + ret++; =20 - if (s->used_clusters[cluster_num] & USED_ANY) { - fprintf(stderr, "cluster %d used more than once\n", (int)cluster_num); + if (s->used_clusters[cluster_num] & USED_ANY) { + fprintf(stderr, "cluster %d used more than once\n", (int)clust= er_num); goto fail; - } - s->used_clusters[cluster_num] =3D USED_DIRECTORY; + } + s->used_clusters[cluster_num] =3D USED_DIRECTORY; =20 DLOG(fprintf(stderr, "read cluster %d (sector %d)\n", (int)cluster_num, (i= nt)cluster2sector(s, cluster_num))); - subret =3D vvfat_read(s->bs, cluster2sector(s, cluster_num), cluster, - s->sectors_per_cluster); - if (subret) { - fprintf(stderr, "Error fetching direntries\n"); - fail: + subret =3D vvfat_read(s->bs, cluster2sector(s, cluster_num), clust= er, + s->sectors_per_cluster); + if (subret) { + fprintf(stderr, "Error fetching direntries\n"); + fail: g_free(cluster); - return 0; - } + return 0; + } =20 - for (i =3D 0; i < 0x10 * s->sectors_per_cluster; i++) { - int cluster_count =3D 0; + for (i =3D 0; i < 0x10 * s->sectors_per_cluster; i++) { + int cluster_count =3D 0; =20 DLOG(fprintf(stderr, "check direntry %d:\n", i); print_direntry(direntries= + i)); - if (is_volume_label(direntries + i) || is_dot(direntries + i) || - is_free(direntries + i)) - continue; - - subret =3D parse_long_name(&lfn, direntries + i); - if (subret < 0) { - fprintf(stderr, "Error in long name\n"); - goto fail; - } - if (subret =3D=3D 0 || is_free(direntries + i)) - continue; - - if (fat_chksum(direntries+i) !=3D lfn.checksum) { - subret =3D parse_short_name(s, &lfn, direntries + i); - if (subret < 0) { - fprintf(stderr, "Error in short name (%d)\n", subret); - goto fail; - } - if (subret > 0 || !strcmp((char*)lfn.name, ".") - || !strcmp((char*)lfn.name, "..")) - continue; - } - lfn.checksum =3D 0x100; /* cannot use long name twice */ - - if (path_len + 1 + lfn.len >=3D PATH_MAX) { - fprintf(stderr, "Name too long: %s/%s\n", path, lfn.name); - goto fail; - } + if (is_volume_label(direntries + i) || is_dot(direntries + i) = || + is_free(direntries + i)) + continue; + + subret =3D parse_long_name(&lfn, direntries + i); + if (subret < 0) { + fprintf(stderr, "Error in long name\n"); + goto fail; + } + if (subret =3D=3D 0 || is_free(direntries + i)) + continue; + + if (fat_chksum(direntries+i) !=3D lfn.checksum) { + subret =3D parse_short_name(s, &lfn, direntries + i); + if (subret < 0) { + fprintf(stderr, "Error in short name (%d)\n", subret); + goto fail; + } + if (subret > 0 || !strcmp((char*)lfn.name, ".") + || !strcmp((char*)lfn.name, "..")) + continue; + } + lfn.checksum =3D 0x100; /* cannot use long name twice */ + + if (path_len + 1 + lfn.len >=3D PATH_MAX) { + fprintf(stderr, "Name too long: %s/%s\n", path, lfn.name); + goto fail; + } pstrcpy(path2 + path_len + 1, sizeof(path2) - path_len - 1, (char*)lfn.name); =20 - if (is_directory(direntries + i)) { - if (begin_of_direntry(direntries + i) =3D=3D 0) { - DLOG(fprintf(stderr, "invalid begin for directory: %s\n", path2); pr= int_direntry(direntries + i)); - goto fail; - } - cluster_count =3D check_directory_consistency(s, - begin_of_direntry(direntries + i), path2); - if (cluster_count =3D=3D 0) { - DLOG(fprintf(stderr, "problem in directory %s:\n", path2); print_dir= entry(direntries + i)); - goto fail; - } - } else if (is_file(direntries + i)) { - /* check file size with FAT */ - cluster_count =3D get_cluster_count_for_direntry(s, direntries + i, path= 2); - if (cluster_count !=3D + if (is_directory(direntries + i)) { + if (begin_of_direntry(direntries + i) =3D=3D 0) { + DLOG(fprintf(stderr, "invalid begin for directory: %s\= n", path2); print_direntry(direntries + i)); + goto fail; + } + cluster_count =3D check_directory_consistency(s, + begin_of_direntry(direntries + i), path2); + if (cluster_count =3D=3D 0) { + DLOG(fprintf(stderr, "problem in directory %s:\n", pat= h2); print_direntry(direntries + i)); + goto fail; + } + } else if (is_file(direntries + i)) { + /* check file size with FAT */ + cluster_count =3D get_cluster_count_for_direntry(s, dirent= ries + i, path2); + if (cluster_count !=3D DIV_ROUND_UP(le32_to_cpu(direntries[i].size), s->cluster_size)= ) { - DLOG(fprintf(stderr, "Cluster count mismatch\n")); - goto fail; - } - } else + DLOG(fprintf(stderr, "Cluster count mismatch\n")); + goto fail; + } + } else abort(); /* cluster_count =3D 0; */ =20 - ret +=3D cluster_count; - } + ret +=3D cluster_count; + } =20 - cluster_num =3D modified_fat_get(s, cluster_num); + cluster_num =3D modified_fat_get(s, cluster_num); } while(!fat_eof(s, cluster_num)); =20 g_free(cluster); @@ -2037,81 +2037,81 @@ DLOG(checkpoint()); * - if all is fine, return number of used clusters */ if (s->fat2 =3D=3D NULL) { - int size =3D 0x200 * s->sectors_per_fat; - s->fat2 =3D g_malloc(size); - memcpy(s->fat2, s->fat.pointer, size); + int size =3D 0x200 * s->sectors_per_fat; + s->fat2 =3D g_malloc(size); + memcpy(s->fat2, s->fat.pointer, size); } check =3D vvfat_read(s->bs, - s->first_sectors_number, s->fat2, s->sectors_per_fat); + s->first_sectors_number, s->fat2, s->sectors_per_fat); if (check) { - fprintf(stderr, "Could not copy fat\n"); - return 0; + fprintf(stderr, "Could not copy fat\n"); + return 0; } assert (s->used_clusters); for (i =3D 0; i < sector2cluster(s, s->sector_count); i++) - s->used_clusters[i] &=3D ~USED_ANY; + s->used_clusters[i] &=3D ~USED_ANY; =20 clear_commits(s); =20 /* mark every mapped file/directory as deleted. * (check_directory_consistency() will unmark those still present). */ if (s->qcow) - for (i =3D 0; i < s->mapping.next; i++) { - mapping_t* mapping =3D array_get(&(s->mapping), i); - if (mapping->first_mapping_index < 0) - mapping->mode |=3D MODE_DELETED; - } + for (i =3D 0; i < s->mapping.next; i++) { + mapping_t* mapping =3D array_get(&(s->mapping), i); + if (mapping->first_mapping_index < 0) + mapping->mode |=3D MODE_DELETED; + } =20 used_clusters_count =3D check_directory_consistency(s, 0, s->path); if (used_clusters_count <=3D 0) { - DLOG(fprintf(stderr, "problem in directory\n")); - return 0; + DLOG(fprintf(stderr, "problem in directory\n")); + return 0; } =20 check =3D s->last_cluster_of_root_directory; for (i =3D check; i < sector2cluster(s, s->sector_count); i++) { - if (modified_fat_get(s, i)) { - if(!s->used_clusters[i]) { - DLOG(fprintf(stderr, "FAT was modified (%d), but cluster is not used?\n"= , i)); - return 0; - } - check++; - } + if (modified_fat_get(s, i)) { + if(!s->used_clusters[i]) { + DLOG(fprintf(stderr, "FAT was modified (%d), but cluster i= s not used?\n", i)); + return 0; + } + check++; + } =20 - if (s->used_clusters[i] =3D=3D USED_ALLOCATED) { - /* allocated, but not used... */ - DLOG(fprintf(stderr, "unused, modified cluster: %d\n", i)); - return 0; - } + if (s->used_clusters[i] =3D=3D USED_ALLOCATED) { + /* allocated, but not used... */ + DLOG(fprintf(stderr, "unused, modified cluster: %d\n", i)); + return 0; + } } =20 if (check !=3D used_clusters_count) - return 0; + return 0; =20 return used_clusters_count; } =20 static inline void adjust_mapping_indices(BDRVVVFATState* s, - int offset, int adjust) + int offset, int adjust) { int i; =20 for (i =3D 0; i < s->mapping.next; i++) { - mapping_t* mapping =3D array_get(&(s->mapping), i); + mapping_t* mapping =3D array_get(&(s->mapping), i); =20 #define ADJUST_MAPPING_INDEX(name) \ - if (mapping->name >=3D offset) \ - mapping->name +=3D adjust + if (mapping->name >=3D offset) \ + mapping->name +=3D adjust =20 - ADJUST_MAPPING_INDEX(first_mapping_index); - if (mapping->mode & MODE_DIRECTORY) - ADJUST_MAPPING_INDEX(info.dir.parent_mapping_index); + ADJUST_MAPPING_INDEX(first_mapping_index); + if (mapping->mode & MODE_DIRECTORY) + ADJUST_MAPPING_INDEX(info.dir.parent_mapping_index); } } =20 /* insert or update mapping */ static mapping_t* insert_mapping(BDRVVVFATState* s, - uint32_t begin, uint32_t end) + uint32_t begin, uint32_t end) { /* * - find mapping where mapping->begin >=3D begin, @@ -2125,15 +2125,15 @@ static mapping_t* insert_mapping(BDRVVVFATState* s, mapping_t* first_mapping =3D array_get(&(s->mapping), 0); =20 if (index < s->mapping.next && (mapping =3D array_get(&(s->mapping), i= ndex)) - && mapping->begin < begin) { - mapping->end =3D begin; - index++; - mapping =3D array_get(&(s->mapping), index); + && mapping->begin < begin) { + mapping->end =3D begin; + index++; + mapping =3D array_get(&(s->mapping), index); } if (index >=3D s->mapping.next || mapping->begin > begin) { - mapping =3D array_insert(&(s->mapping), index, 1); - mapping->path =3D NULL; - adjust_mapping_indices(s, index, +1); + mapping =3D array_insert(&(s->mapping), index, 1); + mapping->path =3D NULL; + adjust_mapping_indices(s, index, +1); } =20 mapping->begin =3D begin; @@ -2145,8 +2145,8 @@ assert(index + 1 >=3D s->mapping.next || next_mapping->begin >=3D end))); =20 if (s->current_mapping && first_mapping !=3D (mapping_t*)s->mapping.po= inter) - s->current_mapping =3D array_get(&(s->mapping), - s->current_mapping - first_mapping); + s->current_mapping =3D array_get(&(s->mapping), + s->current_mapping - first_mapping); =20 return mapping; } @@ -2168,8 +2168,8 @@ static int remove_mapping(BDRVVVFATState* s, int mapp= ing_index) adjust_mapping_indices(s, mapping_index, -1); =20 if (s->current_mapping && first_mapping !=3D (mapping_t*)s->mapping.po= inter) - s->current_mapping =3D array_get(&(s->mapping), - s->current_mapping - first_mapping); + s->current_mapping =3D array_get(&(s->mapping), + s->current_mapping - first_mapping); =20 return 0; } @@ -2178,17 +2178,17 @@ static void adjust_dirindices(BDRVVVFATState* s, in= t offset, int adjust) { int i; for (i =3D 0; i < s->mapping.next; i++) { - mapping_t* mapping =3D array_get(&(s->mapping), i); - if (mapping->dir_index >=3D offset) - mapping->dir_index +=3D adjust; - if ((mapping->mode & MODE_DIRECTORY) && - mapping->info.dir.first_dir_index >=3D offset) - mapping->info.dir.first_dir_index +=3D adjust; + mapping_t* mapping =3D array_get(&(s->mapping), i); + if (mapping->dir_index >=3D offset) + mapping->dir_index +=3D adjust; + if ((mapping->mode & MODE_DIRECTORY) && + mapping->info.dir.first_dir_index >=3D offset) + mapping->info.dir.first_dir_index +=3D adjust; } } =20 static direntry_t* insert_direntries(BDRVVVFATState* s, - int dir_index, int count) + int dir_index, int count) { /* * make room in s->directory, @@ -2196,7 +2196,7 @@ static direntry_t* insert_direntries(BDRVVVFATState* = s, */ direntry_t* result =3D array_insert(&(s->directory), dir_index, count); if (result =3D=3D NULL) - return NULL; + return NULL; adjust_dirindices(s, dir_index, count); return result; } @@ -2205,7 +2205,7 @@ static int remove_direntries(BDRVVVFATState* s, int d= ir_index, int count) { int ret =3D array_remove_slice(&(s->directory), dir_index, count); if (ret) - return ret; + return ret; adjust_dirindices(s, dir_index, -count); return 0; } @@ -2217,7 +2217,7 @@ static int remove_direntries(BDRVVVFATState* s, int d= ir_index, int count) * adjusted) */ static int commit_mappings(BDRVVVFATState* s, - uint32_t first_cluster, int dir_index) + uint32_t first_cluster, int dir_index) { mapping_t* mapping =3D find_mapping_for_cluster(s, first_cluster); direntry_t* direntry =3D array_get(&(s->directory), dir_index); @@ -2230,71 +2230,71 @@ static int commit_mappings(BDRVVVFATState* s, mapping->first_mapping_index =3D -1; mapping->dir_index =3D dir_index; mapping->mode =3D (dir_index <=3D 0 || is_directory(direntry)) ? - MODE_DIRECTORY : MODE_NORMAL; + MODE_DIRECTORY : MODE_NORMAL; =20 while (!fat_eof(s, cluster)) { - uint32_t c, c1; - - for (c =3D cluster, c1 =3D modified_fat_get(s, c); c + 1 =3D=3D c1; - c =3D c1, c1 =3D modified_fat_get(s, c1)); - - c++; - if (c > mapping->end) { - int index =3D array_index(&(s->mapping), mapping); - int i, max_i =3D s->mapping.next - index; - for (i =3D 1; i < max_i && mapping[i].begin < c; i++); - while (--i > 0) - remove_mapping(s, index + 1); - } - assert(mapping =3D=3D array_get(&(s->mapping), s->mapping.next - 1) - || mapping[1].begin >=3D c); - mapping->end =3D c; - - if (!fat_eof(s, c1)) { - int i =3D find_mapping_for_cluster_aux(s, c1, 0, s->mapping.next); - mapping_t* next_mapping =3D i >=3D s->mapping.next ? NULL : - array_get(&(s->mapping), i); - - if (next_mapping =3D=3D NULL || next_mapping->begin > c1) { - int i1 =3D array_index(&(s->mapping), mapping); - - next_mapping =3D insert_mapping(s, c1, c1+1); - - if (c1 < c) - i1++; - mapping =3D array_get(&(s->mapping), i1); - } - - next_mapping->dir_index =3D mapping->dir_index; - next_mapping->first_mapping_index =3D - mapping->first_mapping_index < 0 ? - array_index(&(s->mapping), mapping) : - mapping->first_mapping_index; - next_mapping->path =3D mapping->path; - next_mapping->mode =3D mapping->mode; - next_mapping->read_only =3D mapping->read_only; - if (mapping->mode & MODE_DIRECTORY) { - next_mapping->info.dir.parent_mapping_index =3D - mapping->info.dir.parent_mapping_index; - next_mapping->info.dir.first_dir_index =3D - mapping->info.dir.first_dir_index + - 0x10 * s->sectors_per_cluster * - (mapping->end - mapping->begin); - } else - next_mapping->info.file.offset =3D mapping->info.file.offset + - mapping->end - mapping->begin; - - mapping =3D next_mapping; - } - - cluster =3D c1; + uint32_t c, c1; + + for (c =3D cluster, c1 =3D modified_fat_get(s, c); c + 1 =3D=3D c1; + c =3D c1, c1 =3D modified_fat_get(s, c1)); + + c++; + if (c > mapping->end) { + int index =3D array_index(&(s->mapping), mapping); + int i, max_i =3D s->mapping.next - index; + for (i =3D 1; i < max_i && mapping[i].begin < c; i++); + while (--i > 0) + remove_mapping(s, index + 1); + } + assert(mapping =3D=3D array_get(&(s->mapping), s->mapping.next - 1) + || mapping[1].begin >=3D c); + mapping->end =3D c; + + if (!fat_eof(s, c1)) { + int i =3D find_mapping_for_cluster_aux(s, c1, 0, s->mapping.ne= xt); + mapping_t* next_mapping =3D i >=3D s->mapping.next ? NULL : + array_get(&(s->mapping), i); + + if (next_mapping =3D=3D NULL || next_mapping->begin > c1) { + int i1 =3D array_index(&(s->mapping), mapping); + + next_mapping =3D insert_mapping(s, c1, c1+1); + + if (c1 < c) + i1++; + mapping =3D array_get(&(s->mapping), i1); + } + + next_mapping->dir_index =3D mapping->dir_index; + next_mapping->first_mapping_index =3D + mapping->first_mapping_index < 0 ? + array_index(&(s->mapping), mapping) : + mapping->first_mapping_index; + next_mapping->path =3D mapping->path; + next_mapping->mode =3D mapping->mode; + next_mapping->read_only =3D mapping->read_only; + if (mapping->mode & MODE_DIRECTORY) { + next_mapping->info.dir.parent_mapping_index =3D + mapping->info.dir.parent_mapping_index; + next_mapping->info.dir.first_dir_index =3D + mapping->info.dir.first_dir_index + + 0x10 * s->sectors_per_cluster * + (mapping->end - mapping->begin); + } else + next_mapping->info.file.offset =3D mapping->info.file.offs= et + + mapping->end - mapping->begin; + + mapping =3D next_mapping; + } + + cluster =3D c1; } =20 return 0; } =20 static int commit_direntries(BDRVVVFATState* s, - int dir_index, int parent_mapping_index) + int dir_index, int parent_mapping_index) { direntry_t* direntry =3D array_get(&(s->directory), dir_index); uint32_t first_cluster =3D dir_index =3D=3D 0 ? 0 : begin_of_direntry(= direntry); @@ -2319,58 +2319,58 @@ DLOG(fprintf(stderr, "commit_direntries for %s, par= ent_mapping_index %d\n", mapp mapping->info.dir.parent_mapping_index =3D parent_mapping_index; =20 if (first_cluster =3D=3D 0) { - old_cluster_count =3D new_cluster_count =3D - s->last_cluster_of_root_directory; + old_cluster_count =3D new_cluster_count =3D + s->last_cluster_of_root_directory; } else { - for (old_cluster_count =3D 0, c =3D first_cluster; !fat_eof(s, c); - c =3D fat_get(s, c)) - old_cluster_count++; + for (old_cluster_count =3D 0, c =3D first_cluster; !fat_eof(s, c); + c =3D fat_get(s, c)) + old_cluster_count++; =20 - for (new_cluster_count =3D 0, c =3D first_cluster; !fat_eof(s, c); - c =3D modified_fat_get(s, c)) - new_cluster_count++; + for (new_cluster_count =3D 0, c =3D first_cluster; !fat_eof(s, c); + c =3D modified_fat_get(s, c)) + new_cluster_count++; } =20 if (new_cluster_count > old_cluster_count) { - if (insert_direntries(s, - current_dir_index + factor * old_cluster_count, - factor * (new_cluster_count - old_cluster_count)) =3D=3D NULL) - return -1; + if (insert_direntries(s, + current_dir_index + factor * old_cluster_count, + factor * (new_cluster_count - old_cluster_count)) =3D=3D N= ULL) + return -1; } else if (new_cluster_count < old_cluster_count) - remove_direntries(s, - current_dir_index + factor * new_cluster_count, - factor * (old_cluster_count - new_cluster_count)); + remove_direntries(s, + current_dir_index + factor * new_cluster_count, + factor * (old_cluster_count - new_cluster_count)); =20 for (c =3D first_cluster; !fat_eof(s, c); c =3D modified_fat_get(s, c)= ) { direntry_t *first_direntry; - void* direntry =3D array_get(&(s->directory), current_dir_index); - int ret =3D vvfat_read(s->bs, cluster2sector(s, c), direntry, - s->sectors_per_cluster); - if (ret) - return ret; + void* direntry =3D array_get(&(s->directory), current_dir_index); + int ret =3D vvfat_read(s->bs, cluster2sector(s, c), direntry, + s->sectors_per_cluster); + if (ret) + return ret; =20 /* The first directory entry on the filesystem is the volume name = */ first_direntry =3D (direntry_t*) s->directory.pointer; assert(!memcmp(first_direntry->name, s->volume_label, 11)); =20 - current_dir_index +=3D factor; + current_dir_index +=3D factor; } =20 ret =3D commit_mappings(s, first_cluster, dir_index); if (ret) - return ret; + return ret; =20 /* recurse */ for (i =3D 0; i < factor * new_cluster_count; i++) { - direntry =3D array_get(&(s->directory), first_dir_index + i); - if (is_directory(direntry) && !is_dot(direntry)) { - mapping =3D find_mapping_for_cluster(s, first_cluster); - assert(mapping->mode & MODE_DIRECTORY); - ret =3D commit_direntries(s, first_dir_index + i, - array_index(&(s->mapping), mapping)); - if (ret) - return ret; - } + direntry =3D array_get(&(s->directory), first_dir_index + i); + if (is_directory(direntry) && !is_dot(direntry)) { + mapping =3D find_mapping_for_cluster(s, first_cluster); + assert(mapping->mode & MODE_DIRECTORY); + ret =3D commit_direntries(s, first_dir_index + i, + array_index(&(s->mapping), mapping)); + if (ret) + return ret; + } } =20 return 0; @@ -2379,7 +2379,7 @@ DLOG(fprintf(stderr, "commit_direntries for %s, paren= t_mapping_index %d\n", mapp /* commit one file (adjust contents, adjust mapping), return first_mapping_index */ static int commit_one_file(BDRVVVFATState* s, - int dir_index, uint32_t offset) + int dir_index, uint32_t offset) { direntry_t* direntry =3D array_get(&(s->directory), dir_index); uint32_t c =3D begin_of_direntry(direntry); @@ -2394,14 +2394,14 @@ static int commit_one_file(BDRVVVFATState* s, assert((offset % s->cluster_size) =3D=3D 0); =20 for (i =3D s->cluster_size; i < offset; i +=3D s->cluster_size) - c =3D modified_fat_get(s, c); + c =3D modified_fat_get(s, c); =20 fd =3D qemu_open(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666); if (fd < 0) { - fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path, - strerror(errno), errno); + fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path, + strerror(errno), errno); g_free(cluster); - return fd; + return fd; } if (offset > 0) { if (lseek(fd, offset, SEEK_SET) !=3D offset) { @@ -2412,18 +2412,18 @@ static int commit_one_file(BDRVVVFATState* s, } =20 while (offset < size) { - uint32_t c1; - int rest_size =3D (size - offset > s->cluster_size ? - s->cluster_size : size - offset); - int ret; + uint32_t c1; + int rest_size =3D (size - offset > s->cluster_size ? + s->cluster_size : size - offset); + int ret; =20 - c1 =3D modified_fat_get(s, c); + c1 =3D modified_fat_get(s, c); =20 - assert((size - offset =3D=3D 0 && fat_eof(s, c)) || - (size > offset && c >=3D2 && !fat_eof(s, c))); + assert((size - offset =3D=3D 0 && fat_eof(s, c)) || + (size > offset && c >=3D2 && !fat_eof(s, c))); =20 - ret =3D vvfat_read(s->bs, cluster2sector(s, c), - (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200); + ret =3D vvfat_read(s->bs, cluster2sector(s, c), + (uint8_t*)cluster, (rest_size + 0x1ff) / 0x200); =20 if (ret < 0) { qemu_close(fd); @@ -2437,8 +2437,8 @@ static int commit_one_file(BDRVVVFATState* s, return -2; } =20 - offset +=3D rest_size; - c =3D c1; + offset +=3D rest_size; + c =3D c1; } =20 if (ftruncate(fd, size)) { @@ -2459,18 +2459,18 @@ static void check1(BDRVVVFATState* s) { int i; for (i =3D 0; i < s->mapping.next; i++) { - mapping_t* mapping =3D array_get(&(s->mapping), i); - if (mapping->mode & MODE_DELETED) { - fprintf(stderr, "deleted\n"); - continue; - } - assert(mapping->dir_index < s->directory.next); - direntry_t* direntry =3D array_get(&(s->directory), mapping->dir_index); - assert(mapping->begin =3D=3D begin_of_direntry(direntry) || mapping->firs= t_mapping_index >=3D 0); - if (mapping->mode & MODE_DIRECTORY) { - assert(mapping->info.dir.first_dir_index + 0x10 * s->sectors_per_clus= ter * (mapping->end - mapping->begin) <=3D s->directory.next); - assert((mapping->info.dir.first_dir_index % (0x10 * s->sectors_per_cl= uster)) =3D=3D 0); - } + mapping_t* mapping =3D array_get(&(s->mapping), i); + if (mapping->mode & MODE_DELETED) { + fprintf(stderr, "deleted\n"); + continue; + } + assert(mapping->dir_index < s->directory.next); + direntry_t* direntry =3D array_get(&(s->directory), mapping->dir_i= ndex); + assert(mapping->begin =3D=3D begin_of_direntry(direntry) || mappin= g->first_mapping_index >=3D 0); + if (mapping->mode & MODE_DIRECTORY) { + assert(mapping->info.dir.first_dir_index + 0x10 * s->sectors_p= er_cluster * (mapping->end - mapping->begin) <=3D s->directory.next); + assert((mapping->info.dir.first_dir_index % (0x10 * s->sectors= _per_cluster)) =3D=3D 0); + } } } =20 @@ -2481,43 +2481,43 @@ static void check2(BDRVVVFATState* s) int first_mapping =3D -1; =20 for (i =3D 0; i < s->directory.next; i++) { - direntry_t* direntry =3D array_get(&(s->directory), i); - - if (is_short_name(direntry) && begin_of_direntry(direntry)) { - mapping_t* mapping =3D find_mapping_for_cluster(s, begin_of_direntry(= direntry)); - assert(mapping); - assert(mapping->dir_index =3D=3D i || is_dot(direntry)); - assert(mapping->begin =3D=3D begin_of_direntry(direntry) || is_dot(di= rentry)); - } - - if ((i % (0x10 * s->sectors_per_cluster)) =3D=3D 0) { - /* cluster start */ - int j, count =3D 0; - - for (j =3D 0; j < s->mapping.next; j++) { - mapping_t* mapping =3D array_get(&(s->mapping), j); - if (mapping->mode & MODE_DELETED) - continue; - if (mapping->mode & MODE_DIRECTORY) { - if (mapping->info.dir.first_dir_index <=3D i && mapping->info.dir.fi= rst_dir_index + 0x10 * s->sectors_per_cluster > i) { - assert(++count =3D=3D 1); - if (mapping->first_mapping_index =3D=3D -1) - first_mapping =3D array_index(&(s->mapping), mapping); - else - assert(first_mapping =3D=3D mapping->first_mapping_index); - if (mapping->info.dir.parent_mapping_index < 0) - assert(j =3D=3D 0); - else { - mapping_t* parent =3D array_get(&(s->mapping), mapping->info.dir.pa= rent_mapping_index); - assert(parent->mode & MODE_DIRECTORY); - assert(parent->info.dir.first_dir_index < mapping->info.dir.first_d= ir_index); - } - } - } - } - if (count =3D=3D 0) - first_mapping =3D -1; - } + direntry_t* direntry =3D array_get(&(s->directory), i); + + if (is_short_name(direntry) && begin_of_direntry(direntry)) { + mapping_t* mapping =3D find_mapping_for_cluster(s, begin_of_di= rentry(direntry)); + assert(mapping); + assert(mapping->dir_index =3D=3D i || is_dot(direntry)); + assert(mapping->begin =3D=3D begin_of_direntry(direntry) || is= _dot(direntry)); + } + + if ((i % (0x10 * s->sectors_per_cluster)) =3D=3D 0) { + /* cluster start */ + int j, count =3D 0; + + for (j =3D 0; j < s->mapping.next; j++) { + mapping_t* mapping =3D array_get(&(s->mapping), j); + if (mapping->mode & MODE_DELETED) + continue; + if (mapping->mode & MODE_DIRECTORY) { + if (mapping->info.dir.first_dir_index <=3D i && mappin= g->info.dir.first_dir_index + 0x10 * s->sectors_per_cluster > i) { + assert(++count =3D=3D 1); + if (mapping->first_mapping_index =3D=3D -1) + first_mapping =3D array_index(&(s->mapping), m= apping); + else + assert(first_mapping =3D=3D mapping->first_map= ping_index); + if (mapping->info.dir.parent_mapping_index < 0) + assert(j =3D=3D 0); + else { + mapping_t* parent =3D array_get(&(s->mapping),= mapping->info.dir.parent_mapping_index); + assert(parent->mode & MODE_DIRECTORY); + assert(parent->info.dir.first_dir_index < mapp= ing->info.dir.first_dir_index); + } + } + } + } + if (count =3D=3D 0) + first_mapping =3D -1; + } } } #endif @@ -2529,63 +2529,63 @@ static int handle_renames_and_mkdirs(BDRVVVFATState= * s) #ifdef DEBUG fprintf(stderr, "handle_renames\n"); for (i =3D 0; i < s->commits.next; i++) { - commit_t* commit =3D array_get(&(s->commits), i); - fprintf(stderr, "%d, %s (%d, %d)\n", i, commit->path ? commit->path : "(n= ull)", commit->param.rename.cluster, commit->action); + commit_t* commit =3D array_get(&(s->commits), i); + fprintf(stderr, "%d, %s (%d, %d)\n", i, commit->path ? commit->pat= h : "(null)", commit->param.rename.cluster, commit->action); } #endif =20 for (i =3D 0; i < s->commits.next;) { - commit_t* commit =3D array_get(&(s->commits), i); - if (commit->action =3D=3D ACTION_RENAME) { - mapping_t* mapping =3D find_mapping_for_cluster(s, - commit->param.rename.cluster); - char* old_path =3D mapping->path; - - assert(commit->path); - mapping->path =3D commit->path; - if (rename(old_path, mapping->path)) - return -2; - - if (mapping->mode & MODE_DIRECTORY) { - int l1 =3D strlen(mapping->path); - int l2 =3D strlen(old_path); - int diff =3D l1 - l2; - direntry_t* direntry =3D array_get(&(s->directory), - mapping->info.dir.first_dir_index); - uint32_t c =3D mapping->begin; - int i =3D 0; - - /* recurse */ - while (!fat_eof(s, c)) { - do { - direntry_t* d =3D direntry + i; - - if (is_file(d) || (is_directory(d) && !is_dot(d))) { - mapping_t* m =3D find_mapping_for_cluster(s, - begin_of_direntry(d)); - int l =3D strlen(m->path); - char* new_path =3D g_malloc(l + diff + 1); - - assert(!strncmp(m->path, mapping->path, l2)); + commit_t* commit =3D array_get(&(s->commits), i); + if (commit->action =3D=3D ACTION_RENAME) { + mapping_t* mapping =3D find_mapping_for_cluster(s, + commit->param.rename.cluster); + char* old_path =3D mapping->path; + + assert(commit->path); + mapping->path =3D commit->path; + if (rename(old_path, mapping->path)) + return -2; + + if (mapping->mode & MODE_DIRECTORY) { + int l1 =3D strlen(mapping->path); + int l2 =3D strlen(old_path); + int diff =3D l1 - l2; + direntry_t* direntry =3D array_get(&(s->directory), + mapping->info.dir.first_dir_index); + uint32_t c =3D mapping->begin; + int i =3D 0; + + /* recurse */ + while (!fat_eof(s, c)) { + do { + direntry_t* d =3D direntry + i; + + if (is_file(d) || (is_directory(d) && !is_dot(d)))= { + mapping_t* m =3D find_mapping_for_cluster(s, + begin_of_direntry(d)); + int l =3D strlen(m->path); + char* new_path =3D g_malloc(l + diff + 1); + + assert(!strncmp(m->path, mapping->path, l2)); =20 pstrcpy(new_path, l + diff + 1, mapping->path); pstrcpy(new_path + l1, l + diff + 1 - l1, m->path + l2); =20 - schedule_rename(s, m->begin, new_path); - } - i++; - } while((i % (0x10 * s->sectors_per_cluster)) !=3D 0); - c =3D fat_get(s, c); - } - } + schedule_rename(s, m->begin, new_path); + } + i++; + } while((i % (0x10 * s->sectors_per_cluster)) !=3D 0); + c =3D fat_get(s, c); + } + } =20 g_free(old_path); - array_remove(&(s->commits), i); - continue; - } else if (commit->action =3D=3D ACTION_MKDIR) { - mapping_t* mapping; - int j, parent_path_len; + array_remove(&(s->commits), i); + continue; + } else if (commit->action =3D=3D ACTION_MKDIR) { + mapping_t* mapping; + int j, parent_path_len; =20 #ifdef __MINGW32__ if (mkdir(commit->path)) @@ -2595,37 +2595,37 @@ static int handle_renames_and_mkdirs(BDRVVVFATState= * s) return -5; #endif =20 - mapping =3D insert_mapping(s, commit->param.mkdir.cluster, - commit->param.mkdir.cluster + 1); - if (mapping =3D=3D NULL) - return -6; - - mapping->mode =3D MODE_DIRECTORY; - mapping->read_only =3D 0; - mapping->path =3D commit->path; - j =3D s->directory.next; - assert(j); - insert_direntries(s, s->directory.next, - 0x10 * s->sectors_per_cluster); - mapping->info.dir.first_dir_index =3D j; - - parent_path_len =3D strlen(commit->path) - - strlen(get_basename(commit->path)) - 1; - for (j =3D 0; j < s->mapping.next; j++) { - mapping_t* m =3D array_get(&(s->mapping), j); - if (m->first_mapping_index < 0 && m !=3D mapping && - !strncmp(m->path, mapping->path, parent_path_len) && - strlen(m->path) =3D=3D parent_path_len) - break; - } - assert(j < s->mapping.next); - mapping->info.dir.parent_mapping_index =3D j; - - array_remove(&(s->commits), i); - continue; - } - - i++; + mapping =3D insert_mapping(s, commit->param.mkdir.cluster, + commit->param.mkdir.cluster + 1); + if (mapping =3D=3D NULL) + return -6; + + mapping->mode =3D MODE_DIRECTORY; + mapping->read_only =3D 0; + mapping->path =3D commit->path; + j =3D s->directory.next; + assert(j); + insert_direntries(s, s->directory.next, + 0x10 * s->sectors_per_cluster); + mapping->info.dir.first_dir_index =3D j; + + parent_path_len =3D strlen(commit->path) + - strlen(get_basename(commit->path)) - 1; + for (j =3D 0; j < s->mapping.next; j++) { + mapping_t* m =3D array_get(&(s->mapping), j); + if (m->first_mapping_index < 0 && m !=3D mapping && + !strncmp(m->path, mapping->path, parent_path_len) = && + strlen(m->path) =3D=3D parent_path_len) + break; + } + assert(j < s->mapping.next); + mapping->info.dir.parent_mapping_index =3D j; + + array_remove(&(s->commits), i); + continue; + } + + i++; } return 0; } @@ -2640,75 +2640,75 @@ static int handle_commits(BDRVVVFATState* s) vvfat_close_current_file(s); =20 for (i =3D 0; !fail && i < s->commits.next; i++) { - commit_t* commit =3D array_get(&(s->commits), i); - switch(commit->action) { - case ACTION_RENAME: case ACTION_MKDIR: + commit_t* commit =3D array_get(&(s->commits), i); + switch(commit->action) { + case ACTION_RENAME: case ACTION_MKDIR: abort(); - fail =3D -2; - break; - case ACTION_WRITEOUT: { + fail =3D -2; + break; + case ACTION_WRITEOUT: { #ifndef NDEBUG /* these variables are only used by assert() below */ - direntry_t* entry =3D array_get(&(s->directory), - commit->param.writeout.dir_index); - uint32_t begin =3D begin_of_direntry(entry); - mapping_t* mapping =3D find_mapping_for_cluster(s, begin); + direntry_t* entry =3D array_get(&(s->directory), + commit->param.writeout.dir_index); + uint32_t begin =3D begin_of_direntry(entry); + mapping_t* mapping =3D find_mapping_for_cluster(s, begin); #endif =20 - assert(mapping); - assert(mapping->begin =3D=3D begin); - assert(commit->path =3D=3D NULL); - - if (commit_one_file(s, commit->param.writeout.dir_index, - commit->param.writeout.modified_offset)) - fail =3D -3; - - break; - } - case ACTION_NEW_FILE: { - int begin =3D commit->param.new_file.first_cluster; - mapping_t* mapping =3D find_mapping_for_cluster(s, begin); - direntry_t* entry; - int i; - - /* find direntry */ - for (i =3D 0; i < s->directory.next; i++) { - entry =3D array_get(&(s->directory), i); - if (is_file(entry) && begin_of_direntry(entry) =3D=3D begin) - break; - } - - if (i >=3D s->directory.next) { - fail =3D -6; - continue; - } - - /* make sure there exists an initial mapping */ - if (mapping && mapping->begin !=3D begin) { - mapping->end =3D begin; - mapping =3D NULL; - } - if (mapping =3D=3D NULL) { - mapping =3D insert_mapping(s, begin, begin+1); - } - /* most members will be fixed in commit_mappings() */ - assert(commit->path); - mapping->path =3D commit->path; - mapping->read_only =3D 0; - mapping->mode =3D MODE_NORMAL; - mapping->info.file.offset =3D 0; - - if (commit_one_file(s, i, 0)) - fail =3D -7; - - break; - } - default: + assert(mapping); + assert(mapping->begin =3D=3D begin); + assert(commit->path =3D=3D NULL); + + if (commit_one_file(s, commit->param.writeout.dir_index, + commit->param.writeout.modified_offset)) + fail =3D -3; + + break; + } + case ACTION_NEW_FILE: { + int begin =3D commit->param.new_file.first_cluster; + mapping_t* mapping =3D find_mapping_for_cluster(s, begin); + direntry_t* entry; + int i; + + /* find direntry */ + for (i =3D 0; i < s->directory.next; i++) { + entry =3D array_get(&(s->directory), i); + if (is_file(entry) && begin_of_direntry(entry) =3D=3D begi= n) + break; + } + + if (i >=3D s->directory.next) { + fail =3D -6; + continue; + } + + /* make sure there exists an initial mapping */ + if (mapping && mapping->begin !=3D begin) { + mapping->end =3D begin; + mapping =3D NULL; + } + if (mapping =3D=3D NULL) { + mapping =3D insert_mapping(s, begin, begin+1); + } + /* most members will be fixed in commit_mappings() */ + assert(commit->path); + mapping->path =3D commit->path; + mapping->read_only =3D 0; + mapping->mode =3D MODE_NORMAL; + mapping->info.file.offset =3D 0; + + if (commit_one_file(s, i, 0)) + fail =3D -7; + + break; + } + default: abort(); - } + } } if (i > 0 && array_remove_slice(&(s->commits), 0, i)) - return -1; + return -1; return fail; } =20 @@ -2719,53 +2719,53 @@ static int handle_deletes(BDRVVVFATState* s) /* delete files corresponding to mappings marked as deleted */ /* handle DELETEs and unused mappings (modified_fat_get(s, mapping->be= gin) =3D=3D 0) */ while (deferred && deleted) { - deferred =3D 0; - deleted =3D 0; - - for (i =3D 1; i < s->mapping.next; i++) { - mapping_t* mapping =3D array_get(&(s->mapping), i); - if (mapping->mode & MODE_DELETED) { - direntry_t* entry =3D array_get(&(s->directory), - mapping->dir_index); - - if (is_free(entry)) { - /* remove file/directory */ - if (mapping->mode & MODE_DIRECTORY) { - int j, next_dir_index =3D s->directory.next, - first_dir_index =3D mapping->info.dir.first_dir_index; - - if (rmdir(mapping->path) < 0) { - if (errno =3D=3D ENOTEMPTY) { - deferred++; - continue; - } else - return -5; - } - - for (j =3D 1; j < s->mapping.next; j++) { - mapping_t* m =3D array_get(&(s->mapping), j); - if (m->mode & MODE_DIRECTORY && - m->info.dir.first_dir_index > - first_dir_index && - m->info.dir.first_dir_index < - next_dir_index) - next_dir_index =3D - m->info.dir.first_dir_index; - } - remove_direntries(s, first_dir_index, - next_dir_index - first_dir_index); - - deleted++; - } - } else { - if (unlink(mapping->path)) - return -4; - deleted++; - } - DLOG(fprintf(stderr, "DELETE (%d)\n", i); print_mapping(mapping); print_= direntry(entry)); - remove_mapping(s, i); - } - } + deferred =3D 0; + deleted =3D 0; + + for (i =3D 1; i < s->mapping.next; i++) { + mapping_t* mapping =3D array_get(&(s->mapping), i); + if (mapping->mode & MODE_DELETED) { + direntry_t* entry =3D array_get(&(s->directory), + mapping->dir_index); + + if (is_free(entry)) { + /* remove file/directory */ + if (mapping->mode & MODE_DIRECTORY) { + int j, next_dir_index =3D s->directory.next, + first_dir_index =3D mapping->info.dir.first_dir_in= dex; + + if (rmdir(mapping->path) < 0) { + if (errno =3D=3D ENOTEMPTY) { + deferred++; + continue; + } else + return -5; + } + + for (j =3D 1; j < s->mapping.next; j++) { + mapping_t* m =3D array_get(&(s->mapping), j); + if (m->mode & MODE_DIRECTORY && + m->info.dir.first_dir_index > + first_dir_index && + m->info.dir.first_dir_index < + next_dir_index) + next_dir_index =3D + m->info.dir.first_dir_index; + } + remove_direntries(s, first_dir_index, + next_dir_index - first_dir_index); + + deleted++; + } + } else { + if (unlink(mapping->path)) + return -4; + deleted++; + } + DLOG(fprintf(stderr, "DELETE (%d)\n", i); print_mapping(ma= pping); print_direntry(entry)); + remove_mapping(s, i); + } + } } =20 return 0; @@ -2785,15 +2785,15 @@ static int do_commit(BDRVVVFATState* s) =20 /* the real meat are the commits. Nothing to do? Move along! */ if (s->commits.next =3D=3D 0) - return 0; + return 0; =20 vvfat_close_current_file(s); =20 ret =3D handle_renames_and_mkdirs(s); if (ret) { - fprintf(stderr, "Error handling renames (%d)\n", ret); + fprintf(stderr, "Error handling renames (%d)\n", ret); abort(); - return ret; + return ret; } =20 /* copy FAT (with bdrv_read) */ @@ -2802,23 +2802,23 @@ static int do_commit(BDRVVVFATState* s) /* recurse direntries from root (using bs->bdrv_read) */ ret =3D commit_direntries(s, 0, -1); if (ret) { - fprintf(stderr, "Fatal: error while committing (%d)\n", ret); + fprintf(stderr, "Fatal: error while committing (%d)\n", ret); abort(); - return ret; + return ret; } =20 ret =3D handle_commits(s); if (ret) { - fprintf(stderr, "Error handling commits (%d)\n", ret); + fprintf(stderr, "Error handling commits (%d)\n", ret); abort(); - return ret; + return ret; } =20 ret =3D handle_deletes(s); if (ret) { - fprintf(stderr, "Error deleting\n"); + fprintf(stderr, "Error deleting\n"); abort(); - return ret; + return ret; } =20 if (s->qcow->bs->drv->bdrv_make_empty) { @@ -2836,7 +2836,7 @@ static int try_commit(BDRVVVFATState* s) vvfat_close_current_file(s); DLOG(checkpoint()); if(!is_consistent(s)) - return -1; + return -1; return do_commit(s); } =20 @@ -2862,56 +2862,56 @@ DLOG(checkpoint()); */ =20 if (sector_num < s->first_sectors_number) - return -1; + return -1; =20 for (i =3D sector2cluster(s, sector_num); - i <=3D sector2cluster(s, sector_num + nb_sectors - 1);) { - mapping_t* mapping =3D find_mapping_for_cluster(s, i); - if (mapping) { - if (mapping->read_only) { - fprintf(stderr, "Tried to write to write-protected file %s\n", - mapping->path); - return -1; - } - - if (mapping->mode & MODE_DIRECTORY) { - int begin =3D cluster2sector(s, i); - int end =3D begin + s->sectors_per_cluster, k; - int dir_index; - const direntry_t* direntries; - long_file_name lfn; - - lfn_init(&lfn); - - if (begin < sector_num) - begin =3D sector_num; - if (end > sector_num + nb_sectors) - end =3D sector_num + nb_sectors; - dir_index =3D mapping->dir_index + - 0x10 * (begin - mapping->begin * s->sectors_per_cluster); - direntries =3D (direntry_t*)(buf + 0x200 * (begin - sector_num)); - - for (k =3D 0; k < (end - begin) * 0x10; k++) { - /* do not allow non-ASCII filenames */ - if (parse_long_name(&lfn, direntries + k) < 0) { - fprintf(stderr, "Warning: non-ASCII filename\n"); - return -1; - } - /* no access to the direntry of a read-only file */ - else if (is_short_name(direntries+k) && - (direntries[k].attributes & 1)) { - if (memcmp(direntries + k, - array_get(&(s->directory), dir_index + k), - sizeof(direntry_t))) { - fprintf(stderr, "Warning: tried to write to write-protected file\n"= ); - return -1; - } - } - } - } - i =3D mapping->end; - } else - i++; + i <=3D sector2cluster(s, sector_num + nb_sectors - 1);) { + mapping_t* mapping =3D find_mapping_for_cluster(s, i); + if (mapping) { + if (mapping->read_only) { + fprintf(stderr, "Tried to write to write-protected file %s= \n", + mapping->path); + return -1; + } + + if (mapping->mode & MODE_DIRECTORY) { + int begin =3D cluster2sector(s, i); + int end =3D begin + s->sectors_per_cluster, k; + int dir_index; + const direntry_t* direntries; + long_file_name lfn; + + lfn_init(&lfn); + + if (begin < sector_num) + begin =3D sector_num; + if (end > sector_num + nb_sectors) + end =3D sector_num + nb_sectors; + dir_index =3D mapping->dir_index + + 0x10 * (begin - mapping->begin * s->sectors_per_cluste= r); + direntries =3D (direntry_t*)(buf + 0x200 * (begin - sector= _num)); + + for (k =3D 0; k < (end - begin) * 0x10; k++) { + /* do not allow non-ASCII filenames */ + if (parse_long_name(&lfn, direntries + k) < 0) { + fprintf(stderr, "Warning: non-ASCII filename\n"); + return -1; + } + /* no access to the direntry of a read-only file */ + else if (is_short_name(direntries+k) && + (direntries[k].attributes & 1)) { + if (memcmp(direntries + k, + array_get(&(s->directory), dir_index += k), + sizeof(direntry_t))) { + fprintf(stderr, "Warning: tried to write to wr= ite-protected file\n"); + return -1; + } + } + } + } + i =3D mapping->end; + } else + i++; } =20 /* @@ -2920,14 +2920,14 @@ DLOG(checkpoint()); DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, = nb_sectors)); ret =3D bdrv_write(s->qcow, sector_num, buf, nb_sectors); if (ret < 0) { - fprintf(stderr, "Error writing to qcow backend\n"); - return ret; + fprintf(stderr, "Error writing to qcow backend\n"); + return ret; } =20 for (i =3D sector2cluster(s, sector_num); - i <=3D sector2cluster(s, sector_num + nb_sectors - 1); i++) - if (i >=3D 0) - s->used_clusters[i] |=3D USED_ALLOCATED; + i <=3D sector2cluster(s, sector_num + nb_sectors - 1); i++) + if (i >=3D 0) + s->used_clusters[i] |=3D USED_ALLOCATED; =20 DLOG(checkpoint()); /* TODO: add timeout */ @@ -2966,7 +2966,7 @@ vvfat_co_pwritev(BlockDriverState *bs, uint64_t offse= t, uint64_t bytes, } =20 static int64_t coroutine_fn vvfat_co_get_block_status(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, int *n, BlockDriverState **file) + int64_t sector_num, int nb_sectors, int *n, BlockDriverState **fil= e) { *n =3D bs->total_sectors - sector_num; if (*n > nb_sectors) { @@ -3145,13 +3145,13 @@ static void checkpoint(void) { assert(!vvv->current_mapping || vvv->current_fd || (vvv->current_mappi= ng->mode & MODE_DIRECTORY)); #if 0 if (((direntry_t*)vvv->directory.pointer)[1].attributes !=3D 0xf) - fprintf(stderr, "Nonono!\n"); + fprintf(stderr, "Nonono!\n"); mapping_t* mapping; direntry_t* direntry; assert(vvv->mapping.size >=3D vvv->mapping.item_size * vvv->mapping.ne= xt); assert(vvv->directory.size >=3D vvv->directory.item_size * vvv->direct= ory.next); if (vvv->mapping.next<47) - return; + return; assert((mapping =3D array_get(&(vvv->mapping), 47))); assert(mapping->dir_index < vvv->directory.next); direntry =3D array_get(&(vvv->directory), mapping->dir_index); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447549406394.3354202882657; Fri, 7 Jul 2017 10:12:29 -0700 (PDT) Received: from localhost ([::1]:57697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWnr-0007am-U8 for importer@patchew.org; Fri, 07 Jul 2017 13:12:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41290) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkv-0004gx-GD for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkq-0007cI-Oz for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47482) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWko-0007Yx-DI; Fri, 07 Jul 2017 13:09:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5285E155E4; Fri, 7 Jul 2017 17:09:17 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C2F761F52; Fri, 7 Jul 2017 17:09:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5285E155E4 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5285E155E4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:22 +0200 Message-Id: <1499447335-6125-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:09:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 007/100] vvfat: fix typos 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index e83b8ba..07a111f 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -403,9 +403,9 @@ static void init_mbr(BDRVVVFATState *s, int cyls, int h= eads, int secs) /* FAT12/FAT16/FAT32 */ /* DOS uses different types when partition is LBA, probably to prevent older versions from using CHS on them */ - partition->fs_type=3D s->fat_type=3D=3D12 ? 0x1: - s->fat_type=3D=3D16 ? (lba?0xe:0x06): - /*fat_tyoe=3D=3D32*/ (lba?0xc:0x0b); + partition->fs_type =3D s->fat_type =3D=3D 12 ? 0x1 : + s->fat_type =3D=3D 16 ? (lba ? 0xe : 0x06) : + /*s->fat_type =3D=3D 32*/ (lba ? 0xc : 0x0b); =20 real_mbr->magic[0]=3D0x55; real_mbr->magic[1]=3D0xaa; } @@ -805,7 +805,7 @@ static int read_directory(BDRVVVFATState* s, int mappin= g_index) (ROOT_ENTRIES - cur) * sizeof(direntry_t)); } =20 - /* reget the mapping, since s->mapping was possibly realloc()ed */ + /* re-get the mapping, since s->mapping was possibly realloc()ed */ mapping =3D array_get(&(s->mapping), mapping_index); first_cluster +=3D (s->directory.next - mapping->info.dir.first_dir_in= dex) * 0x20 / s->cluster_size; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 149944765390038.67597231859372; Fri, 7 Jul 2017 10:14:13 -0700 (PDT) Received: from localhost ([::1]:57711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWpW-0000Zk-LD for importer@patchew.org; Fri, 07 Jul 2017 13:14:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkw-0004hx-E9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkv-0007ek-JF for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36674) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkp-0007aD-GS; Fri, 07 Jul 2017 13:09:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8624E91FCC; Fri, 7 Jul 2017 17:09:18 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DB3D62924; Fri, 7 Jul 2017 17:09:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8624E91FCC Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8624E91FCC From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:23 +0200 Message-Id: <1499447335-6125-9-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:09:18 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 008/100] vvfat: rename useless enumeration values 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau MODE_FAKED and MODE_RENAMED are not and were never used. Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 07a111f..18d9559 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -286,8 +286,7 @@ typedef struct mapping_t { union { /* offset is * - the offset in the file (in clusters) for a file, or - * - the next cluster of the directory for a directory, and - * - the address of the buffer for a faked entry + * - the next cluster of the directory for a directory */ struct { uint32_t offset; @@ -300,9 +299,13 @@ typedef struct mapping_t { /* path contains the full path, i.e. it always starts with s->path */ char* path; =20 - enum { MODE_UNDEFINED =3D 0, MODE_NORMAL =3D 1, MODE_MODIFIED =3D 2, - MODE_DIRECTORY =3D 4, MODE_FAKED =3D 8, - MODE_DELETED =3D 16, MODE_RENAMED =3D 32 } mode; + enum { + MODE_UNDEFINED =3D 0, + MODE_NORMAL =3D 1, + MODE_MODIFIED =3D 2, + MODE_DIRECTORY =3D 4, + MODE_DELETED =3D 8, + } mode; int read_only; } mapping_t; =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 149944766169513.804590558192217; Fri, 7 Jul 2017 10:14:21 -0700 (PDT) Received: from localhost ([::1]:57712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWpf-0000sw-7D for importer@patchew.org; Fri, 07 Jul 2017 13:14:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkz-0004lG-3O for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkx-0007gY-Ad for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53550) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkq-0007bu-Sb; Fri, 07 Jul 2017 13:09:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DE50C285B6; Fri, 7 Jul 2017 17:09:19 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id D316161F52; Fri, 7 Jul 2017 17:09:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DE50C285B6 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DE50C285B6 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:24 +0200 Message-Id: <1499447335-6125-10-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:09:20 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 009/100] vvfat: introduce offset_to_bootsector, offset_to_fat and offset_to_root_dir 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau - offset_to_bootsector is the number of sectors up to FAT bootsector - offset_to_fat is the number of sectors up to first File Allocation Table - offset_to_root_dir is the number of sectors up to root directory sector Replace first_sectors_number - 1 by offset_to_bootsector. Replace first_sectors_number by offset_to_fat. Replace faked_sectors by offset_to_rootdir. Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 70 ++++++++++++++++++++++++++++++++++++-------------------= ---- 1 file changed, 43 insertions(+), 27 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 18d9559..88d1879 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -319,22 +319,24 @@ static void print_mapping(const struct mapping_t* map= ping); typedef struct BDRVVVFATState { CoMutex lock; BlockDriverState* bs; /* pointer to parent */ - unsigned int first_sectors_number; /* 1 for a single partition, 0x40 f= or a disk with partition table */ unsigned char first_sectors[0x40*0x200]; =20 int fat_type; /* 16 or 32 */ array_t fat,directory,mapping; char volume_label[11]; =20 + uint32_t offset_to_bootsector; /* 0 for floppy, 0x3f for disk */ + unsigned int cluster_size; unsigned int sectors_per_cluster; unsigned int sectors_per_fat; unsigned int sectors_of_root_directory; uint32_t last_cluster_of_root_directory; - unsigned int faked_sectors; /* how many sectors are faked before file = data */ uint32_t sector_count; /* total number of sectors of the partition */ uint32_t cluster_count; /* total number of clusters of this partition = */ uint32_t max_fat_value; + uint32_t offset_to_fat; + uint32_t offset_to_root_dir; =20 int current_fd; mapping_t* current_mapping; @@ -393,15 +395,15 @@ static void init_mbr(BDRVVVFATState *s, int cyls, int= heads, int secs) partition->attributes=3D0x80; /* bootable */ =20 /* LBA is used when partition is outside the CHS geometry */ - lba =3D sector2CHS(&partition->start_CHS, s->first_sectors_number - 1, + lba =3D sector2CHS(&partition->start_CHS, s->offset_to_bootsector, cyls, heads, secs); lba |=3D sector2CHS(&partition->end_CHS, s->bs->total_sectors - 1, cyls, heads, secs); =20 /*LBA partitions are identified only by start/length_sector_long not b= y CHS*/ - partition->start_sector_long =3D cpu_to_le32(s->first_sectors_number = - 1); + partition->start_sector_long =3D cpu_to_le32(s->offset_to_bootsector); partition->length_sector_long =3D cpu_to_le32(s->bs->total_sectors - - s->first_sectors_number = + 1); + - s->offset_to_bootsector); =20 /* FAT12/FAT16/FAT32 */ /* DOS uses different types when partition is LBA, @@ -822,12 +824,12 @@ static int read_directory(BDRVVVFATState* s, int mapp= ing_index) =20 static inline uint32_t sector2cluster(BDRVVVFATState* s,off_t sector_num) { - return (sector_num-s->faked_sectors)/s->sectors_per_cluster; + return (sector_num - s->offset_to_root_dir) / s->sectors_per_cluster; } =20 static inline off_t cluster2sector(BDRVVVFATState* s, uint32_t cluster_num) { - return s->faked_sectors + s->sectors_per_cluster * cluster_num; + return s->offset_to_root_dir + s->sectors_per_cluster * cluster_num; } =20 static int init_directories(BDRVVVFATState* s, @@ -854,6 +856,9 @@ static int init_directories(BDRVVVFATState* s, i =3D 1+s->sectors_per_cluster*0x200*8/s->fat_type; s->sectors_per_fat=3D(s->sector_count+i)/i; /* round up */ =20 + s->offset_to_fat =3D s->offset_to_bootsector + 1; + s->offset_to_root_dir =3D s->offset_to_fat + s->sectors_per_fat * 2; + array_init(&(s->mapping),sizeof(mapping_t)); array_init(&(s->directory),sizeof(direntry_t)); =20 @@ -867,7 +872,6 @@ static int init_directories(BDRVVVFATState* s, /* Now build FAT, and write back information into directory */ init_fat(s); =20 - s->faked_sectors=3Ds->first_sectors_number+s->sectors_per_fat*2; s->cluster_count=3Dsector2cluster(s, s->sector_count); =20 mapping =3D array_get_next(&(s->mapping)); @@ -945,7 +949,8 @@ static int init_directories(BDRVVVFATState* s, =20 s->current_mapping =3D NULL; =20 - bootsector=3D(bootsector_t*)(s->first_sectors+(s->first_sectors_number= -1)*0x200); + bootsector =3D (bootsector_t *)(s->first_sectors + + s->offset_to_bootsector * 0x200); bootsector->jump[0]=3D0xeb; bootsector->jump[1]=3D0x3e; bootsector->jump[2]=3D0x90; @@ -956,16 +961,18 @@ static int init_directories(BDRVVVFATState* s, bootsector->number_of_fats=3D0x2; /* number of FATs */ bootsector->root_entries=3Dcpu_to_le16(s->sectors_of_root_directory*0x= 10); bootsector->total_sectors16=3Ds->sector_count>0xffff?0:cpu_to_le16(s->= sector_count); - bootsector->media_type=3D(s->first_sectors_number>1?0xf8:0xf0); /* med= ia descriptor (f8=3Dhd, f0=3D3.5 fd)*/ + /* media descriptor: hard disk=3D0xf8, floppy=3D0xf0 */ + bootsector->media_type =3D (s->offset_to_bootsector > 0 ? 0xf8 : 0xf0); s->fat.pointer[0] =3D bootsector->media_type; bootsector->sectors_per_fat=3Dcpu_to_le16(s->sectors_per_fat); bootsector->sectors_per_track =3D cpu_to_le16(secs); bootsector->number_of_heads =3D cpu_to_le16(heads); - bootsector->hidden_sectors=3Dcpu_to_le32(s->first_sectors_number=3D=3D= 1?0:0x3f); + bootsector->hidden_sectors =3D cpu_to_le32(s->offset_to_bootsector); bootsector->total_sectors=3Dcpu_to_le32(s->sector_count>0xffff?s->sect= or_count:0); =20 /* LATER TODO: if FAT32, this is wrong */ - bootsector->u.fat16.drive_number=3Ds->first_sectors_number=3D=3D1?0:0x= 80; /* fda=3D0, hda=3D0x80 */ + /* drive_number: fda=3D0, hda=3D0x80 */ + bootsector->u.fat16.drive_number =3D s->offset_to_bootsector =3D=3D 0 = ? 0 : 0x80; bootsector->u.fat16.current_head=3D0; bootsector->u.fat16.signature=3D0x29; bootsector->u.fat16.id=3Dcpu_to_le32(0xfabe1afd); @@ -1122,7 +1129,6 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, secs =3D s->fat_type =3D=3D 12 ? 18 : 36; s->sectors_per_cluster =3D 1; } - s->first_sectors_number =3D 1; cyls =3D 80; heads =3D 2; } else { @@ -1130,7 +1136,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, if (!s->fat_type) { s->fat_type =3D 16; } - s->first_sectors_number =3D 0x40; + s->offset_to_bootsector =3D 0x3f; cyls =3D s->fat_type =3D=3D 12 ? 64 : 1024; heads =3D 16; secs =3D 63; @@ -1166,7 +1172,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, fprintf(stderr, "vvfat %s chs %d,%d,%d\n", dirname, cyls, heads, secs); =20 - s->sector_count =3D cyls * heads * secs - (s->first_sectors_number - 1= ); + s->sector_count =3D cyls * heads * secs - s->offset_to_bootsector; =20 if (qemu_opt_get_bool(opts, "rw", false)) { if (!bdrv_is_read_only(bs)) { @@ -1196,7 +1202,8 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, goto fail; } =20 - s->sector_count =3D s->faked_sectors + s->sectors_per_cluster*s->clust= er_count; + s->sector_count =3D s->offset_to_root_dir + + s->sectors_per_cluster * s->cluster_count; =20 /* Disable migration when vvfat is used rw */ if (s->qcow) { @@ -1212,7 +1219,7 @@ static int vvfat_open(BlockDriverState *bs, QDict *op= tions, int flags, } } =20 - if (s->first_sectors_number =3D=3D 0x40) { + if (s->offset_to_bootsector > 0) { init_mbr(s, cyls, heads, secs); } =20 @@ -1425,15 +1432,24 @@ static int vvfat_read(BlockDriverState *bs, int64_t= sector_num, } DLOG(fprintf(stderr, "sector %d not allocated\n", (int)sector_num)); } - if(sector_numfaked_sectors) { - if(sector_numfirst_sectors_number) - memcpy(buf+i*0x200,&(s->first_sectors[sector_num*0x200]),0= x200); - else if(sector_num-s->first_sectors_numbersectors_per_fat) - memcpy(buf+i*0x200,&(s->fat.pointer[(sector_num-s->first_s= ectors_number)*0x200]),0x200); - else if(sector_num-s->first_sectors_number-s->sectors_per_fat<= s->sectors_per_fat) - memcpy(buf+i*0x200,&(s->fat.pointer[(sector_num-s->first_s= ectors_number-s->sectors_per_fat)*0x200]),0x200); + if (sector_num < s->offset_to_root_dir) { + if (sector_num < s->offset_to_fat) { + memcpy(buf + i * 0x200, + &(s->first_sectors[sector_num * 0x200]), + 0x200); + } else if (sector_num < s->offset_to_fat + s->sectors_per_fat)= { + memcpy(buf + i * 0x200, + &(s->fat.pointer[(sector_num + - s->offset_to_fat) * 0x200]), + 0x200); + } else if (sector_num < s->offset_to_root_dir) { + memcpy(buf + i * 0x200, + &(s->fat.pointer[(sector_num - s->offset_to_fat + - s->sectors_per_fat) * 0x200]), + 0x200); + } } else { - uint32_t sector=3Dsector_num-s->faked_sectors, + uint32_t sector =3D sector_num - s->offset_to_root_dir, sector_offset_in_cluster=3D(sector%s->sectors_per_cluster), cluster_num=3Dsector/s->sectors_per_cluster; if(cluster_num > s->cluster_count || read_cluster(s, cluster_n= um) !=3D 0) { @@ -2045,7 +2061,7 @@ DLOG(checkpoint()); memcpy(s->fat2, s->fat.pointer, size); } check =3D vvfat_read(s->bs, - s->first_sectors_number, s->fat2, s->sectors_per_fat); + s->offset_to_fat, s->fat2, s->sectors_per_fat); if (check) { fprintf(stderr, "Could not copy fat\n"); return 0; @@ -2864,7 +2880,7 @@ DLOG(checkpoint()); * - do not allow to write non-ASCII filenames */ =20 - if (sector_num < s->first_sectors_number) + if (sector_num < s->offset_to_fat) return -1; =20 for (i =3D sector2cluster(s, sector_num); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447716619316.532691248423; Fri, 7 Jul 2017 10:15:16 -0700 (PDT) Received: from localhost ([::1]:57715 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWqX-0001j8-B8 for importer@patchew.org; Fri, 07 Jul 2017 13:15:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkx-0004jV-Of for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkw-0007fw-Pa for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53578) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWks-0007cf-1u; Fri, 07 Jul 2017 13:09:22 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D407267CC; Fri, 7 Jul 2017 17:09:21 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 342FE62924; Fri, 7 Jul 2017 17:09:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1D407267CC Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1D407267CC From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:25 +0200 Message-Id: <1499447335-6125-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:09:21 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 010/100] vvfat: fix field names in FAT12/FAT16 and FAT32 boot sectors 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Specification: "FAT: General overview of on-disk format" v1.03, pages 11-13 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 88d1879..676cacb 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -217,23 +217,30 @@ typedef struct bootsector_t { union { struct { uint8_t drive_number; - uint8_t current_head; + uint8_t reserved1; uint8_t signature; uint32_t id; uint8_t volume_label[11]; + uint8_t fat_type[8]; + uint8_t ignored[0x1c0]; } QEMU_PACKED fat16; struct { uint32_t sectors_per_fat; uint16_t flags; uint8_t major,minor; - uint32_t first_cluster_of_root_directory; + uint32_t first_cluster_of_root_dir; uint16_t info_sector; uint16_t backup_boot_sector; - uint16_t ignored; + uint8_t reserved[12]; + uint8_t drive_number; + uint8_t reserved1; + uint8_t signature; + uint32_t id; + uint8_t volume_label[11]; + uint8_t fat_type[8]; + uint8_t ignored[0x1a4]; } QEMU_PACKED fat32; } u; - uint8_t fat_type[8]; - uint8_t ignored[0x1c0]; uint8_t magic[2]; } QEMU_PACKED bootsector_t; =20 @@ -973,13 +980,13 @@ static int init_directories(BDRVVVFATState* s, /* LATER TODO: if FAT32, this is wrong */ /* drive_number: fda=3D0, hda=3D0x80 */ bootsector->u.fat16.drive_number =3D s->offset_to_bootsector =3D=3D 0 = ? 0 : 0x80; - bootsector->u.fat16.current_head=3D0; bootsector->u.fat16.signature=3D0x29; bootsector->u.fat16.id=3Dcpu_to_le32(0xfabe1afd); =20 memcpy(bootsector->u.fat16.volume_label, s->volume_label, sizeof(bootsector->u.fat16.volume_label)); - memcpy(bootsector->fat_type,(s->fat_type=3D=3D12?"FAT12 ":s->fat_typ= e=3D=3D16?"FAT16 ":"FAT32 "),8); + memcpy(bootsector->u.fat16.fat_type, + s->fat_type =3D=3D 12 ? "FAT12 " : "FAT16 ", 8); bootsector->magic[0]=3D0x55; bootsector->magic[1]=3D0xaa; =20 return 0; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447801489342.7630365767618; Fri, 7 Jul 2017 10:16:41 -0700 (PDT) Received: from localhost ([::1]:57728 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWrv-0002yH-4S for importer@patchew.org; Fri, 07 Jul 2017 13:16:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41387) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWky-0004kC-9j for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkw-0007g6-T9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53602) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkt-0007dB-7Z; Fri, 07 Jul 2017 13:09:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4FA3E267CC; Fri, 7 Jul 2017 17:09:22 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67B3D62924; Fri, 7 Jul 2017 17:09:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4FA3E267CC Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4FA3E267CC From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:26 +0200 Message-Id: <1499447335-6125-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:09:22 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 011/100] vvfat: always create . and .. entries at first and in that order 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau readdir() doesn't always return . and .. entries at first and in that order. This leads to not creating them at first in the directory, which raises some errors on file system checking utilities like MS-DOS Scandisk. Specification: "FAT: General overview of on-disk format" v1.03, page 25 Fixes: https://bugs.launchpad.net/qemu/+bug/1599539 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 676cacb..0c6d0f4 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -727,6 +727,12 @@ static int read_directory(BDRVVVFATState* s, int mappi= ng_index) i =3D mapping->info.dir.first_dir_index =3D first_cluster =3D=3D 0 ? 0 : s->directory.next; =20 + if (first_cluster !=3D 0) { + /* create the top entries of a subdirectory */ + (void)create_short_and_long_name(s, i, ".", 1); + (void)create_short_and_long_name(s, i, "..", 1); + } + /* actually read the directory, and allocate the mappings */ while((entry=3Dreaddir(dir))) { unsigned int length=3Dstrlen(dirname)+2+strlen(entry->d_name); @@ -748,8 +754,11 @@ static int read_directory(BDRVVVFATState* s, int mappi= ng_index) } =20 /* create directory entry for this file */ - direntry=3Dcreate_short_and_long_name(s, i, entry->d_name, - is_dot || is_dotdot); + if (!is_dot && !is_dotdot) { + direntry =3D create_short_and_long_name(s, i, entry->d_name, 0= ); + } else { + direntry =3D array_get(&(s->directory), is_dot ? i : i + 1); + } direntry->attributes=3D(S_ISDIR(st.st_mode)?0x10:0x20); direntry->reserved[0]=3Ddirentry->reserved[1]=3D0; direntry->ctime=3Dfat_datetime(st.st_ctime,1); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447510050784.5579158694048; Fri, 7 Jul 2017 10:11:50 -0700 (PDT) Received: from localhost ([::1]:57696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWnB-0006x9-JK for importer@patchew.org; Fri, 07 Jul 2017 13:11:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41380) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWky-0004ju-44 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkx-0007gE-2v for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56150) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWku-0007dd-FS; Fri, 07 Jul 2017 13:09:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 841B17D0DC; Fri, 7 Jul 2017 17:09:23 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A38561F23; Fri, 7 Jul 2017 17:09:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 841B17D0DC Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 841B17D0DC From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:27 +0200 Message-Id: <1499447335-6125-13-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:23 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 012/100] vvfat: correctly create long names for non-ASCII filenames 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Assume that input filename is encoded as UTF-8, so correctly create UTF-16 = encoding. Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 0c6d0f4..c52c9ba 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -424,28 +424,19 @@ static void init_mbr(BDRVVVFATState *s, int cyls, int= heads, int secs) =20 /* direntry functions */ =20 -/* dest is assumed to hold 258 bytes, and pads with 0xffff up to next mult= iple of 26 */ -static inline int short2long_name(char* dest,const char* src) +static direntry_t *create_long_filename(BDRVVVFATState *s, const char *fil= ename) { - int i; - int len; - for(i=3D0;i<129 && src[i];i++) { - dest[2*i]=3Dsrc[i]; - dest[2*i+1]=3D0; + int number_of_entries, i; + glong length; + direntry_t *entry; + + gunichar2 *longname =3D g_utf8_to_utf16(filename, -1, NULL, &length, N= ULL); + if (!longname) { + fprintf(stderr, "vvfat: invalid UTF-8 name: %s\n", filename); + return NULL; } - len=3D2*i; - dest[2*i]=3Ddest[2*i+1]=3D0; - for(i=3D2*i+2;(i%26);i++) - dest[i]=3D0xff; - return len; -} =20 -static inline direntry_t* create_long_filename(BDRVVVFATState* s,const cha= r* filename) -{ - char buffer[258]; - int length=3Dshort2long_name(buffer,filename), - number_of_entries=3D(length+25)/26,i; - direntry_t* entry; + number_of_entries =3D (length * 2 + 25) / 26; =20 for(i=3D0;idirectory)); @@ -460,8 +451,15 @@ static inline direntry_t* create_long_filename(BDRVVVF= ATState* s,const char* fil else if(offset<22) offset=3D14+offset-10; else offset=3D28+offset-22; entry=3Darray_get(&(s->directory),s->directory.next-1-(i/26)); - entry->name[offset]=3Dbuffer[i]; + if (i >=3D 2 * length + 2) { + entry->name[offset] =3D 0xff; + } else if (i % 2 =3D=3D 0) { + entry->name[offset] =3D longname[i / 2] & 0xff; + } else { + entry->name[offset] =3D longname[i / 2] >> 8; + } } + g_free(longname); return array_get(&(s->directory),s->directory.next-number_of_entries); } =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447874916682.9588942894594; Fri, 7 Jul 2017 10:17:54 -0700 (PDT) Received: from localhost ([::1]:57731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWt4-0003sj-CD for importer@patchew.org; Fri, 07 Jul 2017 13:17:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41429) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWkz-0004mH-Ph for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWky-0007hV-MB for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52296) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkv-0007eN-Nj; Fri, 07 Jul 2017 13:09:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C75C67F3F1; Fri, 7 Jul 2017 17:09:24 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFA21627DB; Fri, 7 Jul 2017 17:09:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C75C67F3F1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C75C67F3F1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:28 +0200 Message-Id: <1499447335-6125-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:09:24 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 013/100] vvfat: correctly create base short names for non-ASCII filenames 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau More specifically, create short name from filename and change blacklist of invalid chars to whitelist of valid chars. Windows 9x also now correctly see long file names of filenames containing a= space, but Scandisk still complains about mismatch between SFN and LFN. [kwolf: Build fix for this intermediate patch (it included declarations for variables that are only used in the next patch) ] Specification: "FAT: General overview of on-disk format" v1.03, pages 30-31 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 104 ++++++++++++++++++++++++++++++++++++++++++------------= ---- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index c52c9ba..2125ddb 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -515,6 +515,80 @@ static void set_begin_of_direntry(direntry_t* direntry= , uint32_t begin) direntry->begin_hi =3D cpu_to_le16((begin >> 16) & 0xffff); } =20 +static uint8_t to_valid_short_char(gunichar c) +{ + c =3D g_unichar_toupper(c); + if ((c >=3D '0' && c <=3D '9') || + (c >=3D 'A' && c <=3D 'Z') || + strchr("$%'-_@~`!(){}^#&", c) !=3D 0) { + return c; + } else { + return 0; + } +} + +static direntry_t *create_short_filename(BDRVVVFATState *s, + const char *filename) +{ + int j =3D 0; + direntry_t *entry =3D array_get_next(&(s->directory)); + const gchar *p, *last_dot =3D NULL; + gunichar c; + bool lossy_conversion =3D false; + + if (!entry) { + return NULL; + } + memset(entry->name, 0x20, sizeof(entry->name)); + + /* copy filename and search last dot */ + for (p =3D filename; ; p =3D g_utf8_next_char(p)) { + c =3D g_utf8_get_char(p); + if (c =3D=3D '\0') { + break; + } else if (c =3D=3D '.') { + if (j =3D=3D 0) { + /* '.' at start of filename */ + lossy_conversion =3D true; + } else { + if (last_dot) { + lossy_conversion =3D true; + } + last_dot =3D p; + } + } else if (!last_dot) { + /* first part of the name; copy it */ + uint8_t v =3D to_valid_short_char(c); + if (j < 8 && v) { + entry->name[j++] =3D v; + } else { + lossy_conversion =3D true; + } + } + } + + /* copy extension (if any) */ + if (last_dot) { + j =3D 0; + for (p =3D g_utf8_next_char(last_dot); ; p =3D g_utf8_next_char(p)= ) { + c =3D g_utf8_get_char(p); + if (c =3D=3D '\0') { + break; + } else { + /* extension; copy it */ + uint8_t v =3D to_valid_short_char(c); + if (j < 3 && v) { + entry->name[8 + (j++)] =3D v; + } else { + lossy_conversion =3D true; + } + } + } + } + (void)lossy_conversion; + return entry; +} + /* fat functions */ =20 static inline uint8_t fat_chksum(const direntry_t* entry) @@ -613,7 +687,7 @@ static inline void init_fat(BDRVVVFATState* s) static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s, unsigned int directory_start, const char* filename, int is_dot) { - int i,j,long_index=3Ds->directory.next; + int long_index =3D s->directory.next; direntry_t* entry =3D NULL; direntry_t* entry_long =3D NULL; =20 @@ -625,33 +699,7 @@ static inline direntry_t* create_short_and_long_name(B= DRVVVFATState* s, } =20 entry_long=3Dcreate_long_filename(s,filename); - - i =3D strlen(filename); - for(j =3D i - 1; j>0 && filename[j]!=3D'.';j--); - if (j > 0) - i =3D (j > 8 ? 8 : j); - else if (i > 8) - i =3D 8; - - entry=3Darray_get_next(&(s->directory)); - memset(entry->name, 0x20, sizeof(entry->name)); - memcpy(entry->name, filename, i); - - if (j > 0) { - for (i =3D 0; i < 3 && filename[j + 1 + i]; i++) { - entry->name[8 + i] =3D filename[j + 1 + i]; - } - } - - /* upcase & remove unwanted characters */ - for(i=3D10;i>=3D0;i--) { - if(i=3D=3D10 || i=3D=3D7) for(;i>0 && entry->name[i]=3D=3D' ';i--); - if(entry->name[i]<=3D' ' || entry->name[i]>0x7f - || strchr(".*?<>|\":/\\[];,+=3D'",entry->name[i])) - entry->name[i]=3D'_'; - else if(entry->name[i]>=3D'a' && entry->name[i]<=3D'z') - entry->name[i]+=3D'A'-'a'; - } + entry =3D create_short_filename(s, filename); =20 /* mangle duplicates */ while(1) { --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447977498657.2585004198739; Fri, 7 Jul 2017 10:19:37 -0700 (PDT) Received: from localhost ([::1]:57739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWul-0005Hr-50 for importer@patchew.org; Fri, 07 Jul 2017 13:19:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl0-0004nJ-TU for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWkz-0007iH-OB for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36906) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkw-0007fV-W0; Fri, 07 Jul 2017 13:09:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF7694DB15; Fri, 7 Jul 2017 17:09:25 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1119B61F23; Fri, 7 Jul 2017 17:09:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EF7694DB15 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EF7694DB15 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:29 +0200 Message-Id: <1499447335-6125-15-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:09:26 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 014/100] vvfat: correctly generate numeric-tail of short file names 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau More specifically: - try without numeric-tail only if LFN didn't have invalid short chars - start at ~1 (instead of ~0) - handle case if numeric tail is more than one char (ie > 10) Windows 9x Scandisk doesn't see anymore mismatches between short file names= and long file names for non-ASCII filenames. Specification: "FAT: General overview of on-disk format" v1.03, page 31 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 65 ++++++++++++++++++++++++++++---------------------------= ---- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 2125ddb..62f411b 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -528,13 +528,15 @@ static uint8_t to_valid_short_char(gunichar c) } =20 static direntry_t *create_short_filename(BDRVVVFATState *s, - const char *filename) + const char *filename, + unsigned int directory_start) { - int j =3D 0; + int i, j =3D 0; direntry_t *entry =3D array_get_next(&(s->directory)); const gchar *p, *last_dot =3D NULL; gunichar c; bool lossy_conversion =3D false; + char tail[11]; =20 if (!entry) { return NULL; @@ -585,8 +587,32 @@ static direntry_t *create_short_filename(BDRVVVFATStat= e *s, } } } - (void)lossy_conversion; - return entry; + + /* numeric-tail generation */ + for (j =3D 0; j < 8; j++) { + if (entry->name[j] =3D=3D ' ') { + break; + } + } + for (i =3D lossy_conversion ? 1 : 0; i < 999999; i++) { + direntry_t *entry1; + if (i > 0) { + int len =3D sprintf(tail, "~%d", i); + memcpy(entry->name + MIN(j, 8 - len), tail, len); + } + for (entry1 =3D array_get(&(s->directory), directory_start); + entry1 < entry; entry1++) { + if (!is_long_name(entry1) && + !memcmp(entry1->name, entry->name, 11)) { + break; /* found dupe */ + } + } + if (entry1 =3D=3D entry) { + /* no dupe found */ + return entry; + } + } + return NULL; } =20 /* fat functions */ @@ -699,36 +725,7 @@ static inline direntry_t* create_short_and_long_name(B= DRVVVFATState* s, } =20 entry_long=3Dcreate_long_filename(s,filename); - entry =3D create_short_filename(s, filename); - - /* mangle duplicates */ - while(1) { - direntry_t* entry1=3Darray_get(&(s->directory),directory_start); - int j; - - for(;entry1name,entry->name,1= 1)) - break; /* found dupe */ - if(entry1=3D=3Dentry) /* no dupe found */ - break; - - /* use all 8 characters of name */ - if(entry->name[7]=3D=3D' ') { - int j; - for(j=3D6;j>0 && entry->name[j]=3D=3D' ';j--) - entry->name[j]=3D'~'; - } - - /* increment number */ - for(j=3D7;j>0 && entry->name[j]=3D=3D'9';j--) - entry->name[j]=3D'0'; - if(j>0) { - if(entry->name[j]<'0' || entry->name[j]>'9') - entry->name[j]=3D'0'; - else - entry->name[j]++; - } - } + entry =3D create_short_filename(s, filename, directory_start); =20 /* calculate checksum; propagate to long name */ if(entry_long) { --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448050181529.1654770796379; Fri, 7 Jul 2017 10:20:50 -0700 (PDT) Received: from localhost ([::1]:57749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWvw-0006ag-TA for importer@patchew.org; Fri, 07 Jul 2017 13:20:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl5-0004sX-A5 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl0-0007j3-Ty for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWky-0007gg-6z; Fri, 07 Jul 2017 13:09:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3BCD7C0587CD; Fri, 7 Jul 2017 17:09:27 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47EE9627DB; Fri, 7 Jul 2017 17:09:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3BCD7C0587CD 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3BCD7C0587CD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:30 +0200 Message-Id: <1499447335-6125-16-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:09:27 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 015/100] vvfat: limit number of entries in root directory in FAT12/FAT16 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau FAT12/FAT16 root directory is two sectors in size, which allows only 512 di= rectory entries. Prevent QEMU startup if too much files exist, instead of overflowing root d= irectory. Also introduce variable root_entries, which will be required for FAT32. Fixes: https://bugs.launchpad.net/qemu/+bug/1599539/comments/4 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index 62f411b..dc9af01 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -337,8 +337,9 @@ typedef struct BDRVVVFATState { unsigned int cluster_size; unsigned int sectors_per_cluster; unsigned int sectors_per_fat; - unsigned int sectors_of_root_directory; uint32_t last_cluster_of_root_directory; + /* how many entries are available in root directory (0 for FAT32) */ + uint16_t root_entries; uint32_t sector_count; /* total number of sectors of the partition */ uint32_t cluster_count; /* total number of clusters of this partition = */ uint32_t max_fat_value; @@ -785,6 +786,12 @@ static int read_directory(BDRVVVFATState* s, int mappi= ng_index) int is_dot=3D!strcmp(entry->d_name,"."); int is_dotdot=3D!strcmp(entry->d_name,".."); =20 + if (first_cluster =3D=3D 0 && s->directory.next >=3D s->root_entri= es - 1) { + fprintf(stderr, "Too many entries in root directory\n"); + closedir(dir); + return -2; + } + if(first_cluster =3D=3D 0 && (is_dotdot || is_dot)) continue; =20 @@ -858,15 +865,15 @@ static int read_directory(BDRVVVFATState* s, int mapp= ing_index) memset(direntry,0,sizeof(direntry_t)); } =20 -/* TODO: if there are more entries, bootsector has to be adjusted! */ -#define ROOT_ENTRIES (0x02 * 0x10 * s->sectors_per_cluster) - if (mapping_index =3D=3D 0 && s->directory.next < ROOT_ENTRIES) { + if (s->fat_type !=3D 32 && + mapping_index =3D=3D 0 && + s->directory.next < s->root_entries) { /* root directory */ int cur =3D s->directory.next; - array_ensure_allocated(&(s->directory), ROOT_ENTRIES - 1); - s->directory.next =3D ROOT_ENTRIES; + array_ensure_allocated(&(s->directory), s->root_entries - 1); + s->directory.next =3D s->root_entries; memset(array_get(&(s->directory), cur), 0, - (ROOT_ENTRIES - cur) * sizeof(direntry_t)); + (s->root_entries - cur) * sizeof(direntry_t)); } =20 /* re-get the mapping, since s->mapping was possibly realloc()ed */ @@ -931,6 +938,8 @@ static int init_directories(BDRVVVFATState* s, /* Now build FAT, and write back information into directory */ init_fat(s); =20 + /* TODO: if there are more entries, bootsector has to be adjusted! */ + s->root_entries =3D 0x02 * 0x10 * s->sectors_per_cluster; s->cluster_count=3Dsector2cluster(s, s->sector_count); =20 mapping =3D array_get_next(&(s->mapping)); @@ -999,7 +1008,6 @@ static int init_directories(BDRVVVFATState* s, } =20 mapping =3D array_get(&(s->mapping), 0); - s->sectors_of_root_directory =3D mapping->end * s->sectors_per_cluster; s->last_cluster_of_root_directory =3D mapping->end; =20 /* the FAT signature */ @@ -1018,7 +1026,7 @@ static int init_directories(BDRVVVFATState* s, bootsector->sectors_per_cluster=3Ds->sectors_per_cluster; bootsector->reserved_sectors=3Dcpu_to_le16(1); bootsector->number_of_fats=3D0x2; /* number of FATs */ - bootsector->root_entries=3Dcpu_to_le16(s->sectors_of_root_directory*0x= 10); + bootsector->root_entries =3D cpu_to_le16(s->root_entries); bootsector->total_sectors16=3Ds->sector_count>0xffff?0:cpu_to_le16(s->= sector_count); /* media descriptor: hard disk=3D0xf8, floppy=3D0xf0 */ bootsector->media_type =3D (s->offset_to_bootsector > 0 ? 0xf8 : 0xf0); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448133992144.97697752937938; Fri, 7 Jul 2017 10:22:13 -0700 (PDT) Received: from localhost ([::1]:57756 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWxI-0007iD-MV for importer@patchew.org; Fri, 07 Jul 2017 13:22:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl5-0004t6-VB for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl1-0007jJ-C4 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56574) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWkz-0007hZ-C3; Fri, 07 Jul 2017 13:09:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63DF7C058ED5; Fri, 7 Jul 2017 17:09:28 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B500173C1; Fri, 7 Jul 2017 17:09:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 63DF7C058ED5 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 63DF7C058ED5 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:31 +0200 Message-Id: <1499447335-6125-17-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:09:28 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 016/100] vvfat: handle KANJI lead byte 0xe5 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau Specification: "FAT: General overview of on-disk format" v1.03, page 23 Signed-off-by: Herv=C3=A9 Poussineau Signed-off-by: Kevin Wolf --- block/vvfat.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index dc9af01..9cb48ef 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -589,6 +589,10 @@ static direntry_t *create_short_filename(BDRVVVFATStat= e *s, } } =20 + if (entry->name[0] =3D=3D 0xe5) { + entry->name[0] =3D 0x05; + } + /* numeric-tail generation */ for (j =3D 0; j < 8; j++) { if (entry->name[j] =3D=3D ' ') { @@ -709,8 +713,6 @@ static inline void init_fat(BDRVVVFATState* s) =20 } =20 -/* TODO: in create_short_filename, 0xe5->0x05 is not yet handled! */ -/* TODO: in parse_short_filename, 0x05->0xe5 is not yet handled! */ static inline direntry_t* create_short_and_long_name(BDRVVVFATState* s, unsigned int directory_start, const char* filename, int is_dot) { @@ -1743,6 +1745,9 @@ static int parse_short_name(BDRVVVFATState* s, } else lfn->name[i + j + 1] =3D '\0'; =20 + if (lfn->name[0] =3D=3D 0x05) { + lfn->name[0] =3D 0xe5; + } lfn->len =3D strlen((char*)lfn->name); =20 return 0; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448294302731.9342817220382; Fri, 7 Jul 2017 10:24:54 -0700 (PDT) Received: from localhost ([::1]:57771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWzt-0001pv-04 for importer@patchew.org; Fri, 07 Jul 2017 13:24:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl7-0004uS-0J for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl6-0007pk-1D for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49534) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl0-0007iR-J5; Fri, 07 Jul 2017 13:09:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A528B8008D; Fri, 7 Jul 2017 17:09:29 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFE5F61F23; Fri, 7 Jul 2017 17:09:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A528B8008D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A528B8008D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:32 +0200 Message-Id: <1499447335-6125-18-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:09:29 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 017/100] vvfat: change OEM name to 'MSWIN4.1' 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-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Herv=C3=A9 Poussineau According to specification: "'MSWIN4.1' is the recommanded setting, because it is the setting least lik= ely to cause compatibility problems. If you want to put something else in here, that is your option, but the result may be that some FAT drivers might not recognize the volume." Specification: "FAT: General overview of on-disk format" v1.03, page 9 Signed-off-by: Herv=C3=A9 Poussineau Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Kevin Wolf --- block/vvfat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/vvfat.c b/block/vvfat.c index 9cb48ef..f55104c 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1023,7 +1023,7 @@ static int init_directories(BDRVVVFATState* s, bootsector->jump[0]=3D0xeb; bootsector->jump[1]=3D0x3e; bootsector->jump[2]=3D0x90; - memcpy(bootsector->name,"QEMU ",8); + memcpy(bootsector->name, "MSWIN4.1", 8); bootsector->sector_size=3Dcpu_to_le16(0x200); bootsector->sectors_per_cluster=3Ds->sectors_per_cluster; bootsector->reserved_sectors=3Dcpu_to_le16(1); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448234450316.3618440608625; Fri, 7 Jul 2017 10:23:54 -0700 (PDT) Received: from localhost ([::1]:57768 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWys-0000bj-Sw for importer@patchew.org; Fri, 07 Jul 2017 13:23:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41589) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl8-0004vs-8E for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl7-0007qP-4g for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56652) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl1-0007jE-R1; Fri, 07 Jul 2017 13:09:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DD6F5C0587D2; Fri, 7 Jul 2017 17:09:30 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0C1261F23; Fri, 7 Jul 2017 17:09:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DD6F5C0587D2 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DD6F5C0587D2 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:33 +0200 Message-Id: <1499447335-6125-19-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:09:31 +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] [PULL 018/100] qemu-img: drop -e and -6 options from the 'create' & 'convert' commands 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-devel@nongnu.org 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" From: "Daniel P. Berrange" The '-e' and '-6' options to the 'create' & 'convert' commands were "deprecated" in favour of the more generic '-o' option many years ago: commit eec77d9e712bd4157a4e1c0b5a9249d168add738 Author: Jes Sorensen Date: Tue Dec 7 17:44:34 2010 +0100 qemu-img: Deprecate obsolete -6 and -e options Except this was never actually a deprecation, which would imply giving the user a warning while the functionality continues to work for a number of releases before eventual removal. Instead the options were immediately turned into an error + exit. Given that the functionality is already broken, there's no point in keeping these psuedo-deprecation messages around any longer. Signed-off-by: Daniel P. Berrange Signed-off-by: Kevin Wolf --- qemu-img.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 91ad6be..c5f00db 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -464,7 +464,7 @@ static int img_create(int argc, char **argv) {"object", required_argument, 0, OPTION_OBJECT}, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":F:b:f:he6o:q", + c =3D getopt_long(argc, argv, ":F:b:f:ho:q", long_options, NULL); if (c =3D=3D -1) { break; @@ -488,14 +488,6 @@ static int img_create(int argc, char **argv) case 'f': fmt =3D optarg; break; - case 'e': - error_report("option -e is deprecated, please use \'-o " - "encryption\' instead!"); - goto fail; - case '6': - error_report("option -6 is deprecated, please use \'-o " - "compat6\' instead!"); - goto fail; case 'o': if (!is_valid_option_list(optarg)) { error_report("Invalid option list: %s", optarg); @@ -1985,7 +1977,7 @@ static int img_convert(int argc, char **argv) {"target-image-opts", no_argument, 0, OPTION_TARGET_IMAGE_OPTS= }, {0, 0, 0, 0} }; - c =3D getopt_long(argc, argv, ":hf:O:B:ce6o:s:l:S:pt:T:qnm:WU", + c =3D getopt_long(argc, argv, ":hf:O:B:co:s:l:S:pt:T:qnm:WU", long_options, NULL); if (c =3D=3D -1) { break; @@ -2012,14 +2004,6 @@ static int img_convert(int argc, char **argv) case 'c': s.compressed =3D true; break; - case 'e': - error_report("option -e is deprecated, please use \'-o " - "encryption\' instead!"); - goto fail_getopt; - case '6': - error_report("option -6 is deprecated, please use \'-o " - "compat6\' instead!"); - goto fail_getopt; case 'o': if (!is_valid_option_list(optarg)) { error_report("Invalid option list: %s", optarg); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448285242471.63749963646296; Fri, 7 Jul 2017 10:24:45 -0700 (PDT) Received: from localhost ([::1]:57770 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWzi-0001hG-N2 for importer@patchew.org; Fri, 07 Jul 2017 13:24:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41594) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl8-0004wF-Fq for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl7-0007qb-DC for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39934) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl3-0007l1-39; Fri, 07 Jul 2017 13:09:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 256B461D2D; Fri, 7 Jul 2017 17:09:32 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3107E61F23; Fri, 7 Jul 2017 17:09:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 256B461D2D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 256B461D2D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:34 +0200 Message-Id: <1499447335-6125-20-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:32 +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] [PULL 019/100] blockdev: Print a warning for legacy drive options that belong to -device 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-devel@nongnu.org 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" From: Thomas Huth We likely do not want to carry these legacy -drive options along forever. Let's emit a deprecation warning for the -drive options that have a replacement with the -device option, so that the (hopefully few) remaining users are aware of this and can adapt their scripts / behaviour accordingly. Signed-off-by: Thomas Huth Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- blockdev.c | 14 ++++++++++++++ qemu-options.hx | 9 +++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index f92dcf2..e2016b6 100644 --- a/blockdev.c +++ b/blockdev.c @@ -50,6 +50,7 @@ #include "qmp-commands.h" #include "block/trace.h" #include "sysemu/arch_init.h" +#include "sysemu/qtest.h" #include "qemu/cutils.h" #include "qemu/help_option.h" #include "qemu/throttle-options.h" @@ -798,6 +799,9 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterface= Type block_default_type) const char *filename; Error *local_err =3D NULL; int i; + const char *deprecated[] =3D { + "serial", "trans", "secs", "heads", "cyls", "addr" + }; =20 /* Change legacy command line options into QMP ones */ static const struct { @@ -881,6 +885,16 @@ DriveInfo *drive_new(QemuOpts *all_opts, BlockInterfac= eType block_default_type) "update your scripts.\n"); } =20 + /* Other deprecated options */ + if (!qtest_enabled()) { + for (i =3D 0; i < ARRAY_SIZE(deprecated); i++) { + if (qemu_opt_get(legacy_opts, deprecated[i]) !=3D NULL) { + error_report("'%s' is deprecated, please use the correspon= ding " + "option of '-device' instead", deprecated[i]); + } + } + } + /* Media type */ value =3D qemu_opt_get(legacy_opts, "media"); if (value) { diff --git a/qemu-options.hx b/qemu-options.hx index 297bd8a..ddab656 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -818,6 +818,8 @@ of available connectors of a given interface type. This option defines the type of the media: disk or cdrom. @item cyls=3D@var{c},heads=3D@var{h},secs=3D@var{s}[,trans=3D@var{t}] These options have the same definition as they have in @option{-hdachs}. +These parameters are deprecated, use the corresponding parameters +of @code{-device} instead. @item snapshot=3D@var{snapshot} @var{snapshot} is "on" or "off" and controls snapshot mode for the given d= rive (see @option{-snapshot}). @@ -852,9 +854,12 @@ Specify which disk @var{format} will be used rather th= an detecting the format. Can be used to specify format=3Draw to avoid interpreting an untrusted format header. @item serial=3D@var{serial} -This option specifies the serial number to assign to the device. +This option specifies the serial number to assign to the device. This +parameter is deprecated, use the corresponding parameter of @code{-device} +instead. @item addr=3D@var{addr} -Specify the controller's PCI address (if=3Dvirtio only). +Specify the controller's PCI address (if=3Dvirtio only). This parameter is +deprecated, use the corresponding parameter of @code{-device} instead. @item werror=3D@var{action},rerror=3D@var{action} Specify which @var{action} to take on write and read errors. Valid actions= are: "ignore" (ignore the error and try to continue), "stop" (pause QEMU), --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448433587240.9513675567042; Fri, 7 Jul 2017 10:27:13 -0700 (PDT) Received: from localhost ([::1]:57787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX28-0003rL-73 for importer@patchew.org; Fri, 07 Jul 2017 13:27:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWl9-0004ws-0n for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl7-0007qk-Kr for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46022) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl4-0007nl-9U; Fri, 07 Jul 2017 13:09:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57F89C0467C5; Fri, 7 Jul 2017 17:09:33 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7015361F23; Fri, 7 Jul 2017 17:09:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57F89C0467C5 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 57F89C0467C5 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:35 +0200 Message-Id: <1499447335-6125-21-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:09:33 +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] [PULL 020/100] blockjob: Track job ratelimits via bytes, not sectors 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-devel@nongnu.org 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" From: Eric Blake The user interface specifies job rate limits in bytes/second. It's pointless to have our internal representation track things in sectors/second, particularly since we want to move away from sector-based interfaces. Fix up a doc typo found while verifying that the ratelimit code handles the scaling difference. Repetition of expressions like 'n * BDRV_SECTOR_SIZE' will be cleaned up later when functions are converted to iterate over images by bytes rather than by sectors. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 5 +++-- block/commit.c | 5 +++-- block/mirror.c | 13 +++++++------ block/stream.c | 5 +++-- include/qemu/ratelimit.h | 3 ++- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/block/backup.c b/block/backup.c index 5387fbd..9ca1d8e 100644 --- a/block/backup.c +++ b/block/backup.c @@ -208,7 +208,7 @@ static void backup_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static void backup_cleanup_sync_bitmap(BackupBlockJob *job, int ret) @@ -359,7 +359,8 @@ static bool coroutine_fn yield_and_check(BackupBlockJob= *job) */ if (job->common.speed) { uint64_t delay_ns =3D ratelimit_calculate_delay(&job->limit, - job->sectors_read); + job->sectors_read * + BDRV_SECTOR_SIZE); job->sectors_read =3D 0; block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, delay_ns); } else { diff --git a/block/commit.c b/block/commit.c index 524bd54..6993994 100644 --- a/block/commit.c +++ b/block/commit.c @@ -209,7 +209,8 @@ static void coroutine_fn commit_run(void *opaque) s->common.offset +=3D n * BDRV_SECTOR_SIZE; =20 if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, n); + delay_ns =3D ratelimit_calculate_delay(&s->limit, + n * BDRV_SECTOR_SIZE); } } =20 @@ -231,7 +232,7 @@ static void commit_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static const BlockJobDriver commit_job_driver =3D { diff --git a/block/mirror.c b/block/mirror.c index 61a862d..eb27efc 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -396,7 +396,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) bitmap_set(s->in_flight_bitmap, sector_num / sectors_per_chunk, nb_chu= nks); while (nb_chunks > 0 && sector_num < end) { int64_t ret; - int io_sectors, io_sectors_acct; + int io_sectors; + int64_t io_bytes_acct; BlockDriverState *file; enum MirrorMethod { MIRROR_METHOD_COPY, @@ -444,16 +445,16 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) switch (mirror_method) { case MIRROR_METHOD_COPY: io_sectors =3D mirror_do_read(s, sector_num, io_sectors); - io_sectors_acct =3D io_sectors; + io_bytes_acct =3D io_sectors * BDRV_SECTOR_SIZE; break; case MIRROR_METHOD_ZERO: case MIRROR_METHOD_DISCARD: mirror_do_zero_or_discard(s, sector_num, io_sectors, mirror_method =3D=3D MIRROR_METHOD_D= ISCARD); if (write_zeroes_ok) { - io_sectors_acct =3D 0; + io_bytes_acct =3D 0; } else { - io_sectors_acct =3D io_sectors; + io_bytes_acct =3D io_sectors * BDRV_SECTOR_SIZE; } break; default: @@ -463,7 +464,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) sector_num +=3D io_sectors; nb_chunks -=3D DIV_ROUND_UP(io_sectors, sectors_per_chunk); if (s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, io_sectors_a= cct); + delay_ns =3D ratelimit_calculate_delay(&s->limit, io_bytes_acc= t); } } return delay_ns; @@ -929,7 +930,7 @@ static void mirror_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static void mirror_complete(BlockJob *job, Error **errp) diff --git a/block/stream.c b/block/stream.c index 52d329f..29273a5 100644 --- a/block/stream.c +++ b/block/stream.c @@ -191,7 +191,8 @@ static void coroutine_fn stream_run(void *opaque) /* Publish progress */ s->common.offset +=3D n * BDRV_SECTOR_SIZE; if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, n); + delay_ns =3D ratelimit_calculate_delay(&s->limit, + n * BDRV_SECTOR_SIZE); } } =20 @@ -220,7 +221,7 @@ static void stream_set_speed(BlockJob *job, int64_t spe= ed, Error **errp) error_setg(errp, QERR_INVALID_PARAMETER, "speed"); return; } - ratelimit_set_speed(&s->limit, speed / BDRV_SECTOR_SIZE, SLICE_TIME); + ratelimit_set_speed(&s->limit, speed, SLICE_TIME); } =20 static const BlockJobDriver stream_job_driver =3D { diff --git a/include/qemu/ratelimit.h b/include/qemu/ratelimit.h index 8da1232..8dece48 100644 --- a/include/qemu/ratelimit.h +++ b/include/qemu/ratelimit.h @@ -24,7 +24,8 @@ typedef struct { =20 /** Calculate and return delay for next request in ns * - * Record that we sent @p n data units. If we may send more data units + * Record that we sent @n data units (where @n matches the scale chosen + * during ratelimit_set_speed). If we may send more data units * in the current time slice, return 0 (i.e. no delay). Otherwise * return the amount of time (in ns) until the start of the next time * slice that will permit sending the next chunk of data. --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448450065477.6295986817894; Fri, 7 Jul 2017 10:27:30 -0700 (PDT) Received: from localhost ([::1]:57788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX2O-00046b-LP for importer@patchew.org; Fri, 07 Jul 2017 13:27:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlB-0004zf-CM for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl9-0007sB-Gx for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49604) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl5-0007ov-NA; Fri, 07 Jul 2017 13:09:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 928467CE0A; Fri, 7 Jul 2017 17:09:34 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id A549C61F23; Fri, 7 Jul 2017 17:09:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 928467CE0A Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 928467CE0A From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:36 +0200 Message-Id: <1499447335-6125-22-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:09:34 +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] [PULL 021/100] trace: Show blockjob actions via bytes, not sectors 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-devel@nongnu.org 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" From: Eric Blake Upcoming patches are going to switch to byte-based interfaces instead of sector-based. Even worse, trace_backup_do_cow_enter() had a weird mix of cluster and sector indices. The trace interface is low enough that there are no stability guarantees, and therefore nothing wrong with changing our units, even in cases like trace_backup_do_cow_skip() where we are not changing the trace output. So make the tracing uniformly use bytes. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 16 ++++++++++------ block/commit.c | 3 ++- block/mirror.c | 26 +++++++++++++++++--------- block/stream.c | 3 ++- block/trace-events | 14 +++++++------- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/block/backup.c b/block/backup.c index 9ca1d8e..06431ac 100644 --- a/block/backup.c +++ b/block/backup.c @@ -102,6 +102,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, void *bounce_buffer =3D NULL; int ret =3D 0; int64_t sectors_per_cluster =3D cluster_size_sectors(job); + int64_t bytes_per_cluster =3D sectors_per_cluster * BDRV_SECTOR_SIZE; int64_t start, end; int n; =20 @@ -110,18 +111,20 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, start =3D sector_num / sectors_per_cluster; end =3D DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); =20 - trace_backup_do_cow_enter(job, start, sector_num, nb_sectors); + trace_backup_do_cow_enter(job, start * bytes_per_cluster, + sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); =20 wait_for_overlapping_requests(job, start, end); cow_request_begin(&cow_request, job, start, end); =20 for (; start < end; start++) { if (test_bit(start, job->done_bitmap)) { - trace_backup_do_cow_skip(job, start); + trace_backup_do_cow_skip(job, start * bytes_per_cluster); continue; /* already copied */ } =20 - trace_backup_do_cow_process(job, start); + trace_backup_do_cow_process(job, start * bytes_per_cluster); =20 n =3D MIN(sectors_per_cluster, job->common.len / BDRV_SECTOR_SIZE - @@ -138,7 +141,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, bounce_qiov.size, &bounce_qiov, is_write_notifier ? BDRV_REQ_NO_SERIALISING : = 0); if (ret < 0) { - trace_backup_do_cow_read_fail(job, start, ret); + trace_backup_do_cow_read_fail(job, start * bytes_per_cluster, = ret); if (error_is_read) { *error_is_read =3D true; } @@ -154,7 +157,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, job->compress ? BDRV_REQ_WRITE_COMPRESSED= : 0); } if (ret < 0) { - trace_backup_do_cow_write_fail(job, start, ret); + trace_backup_do_cow_write_fail(job, start * bytes_per_cluster,= ret); if (error_is_read) { *error_is_read =3D false; } @@ -177,7 +180,8 @@ out: =20 cow_request_end(&cow_request); =20 - trace_backup_do_cow_return(job, sector_num, nb_sectors, ret); + trace_backup_do_cow_return(job, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, ret); =20 qemu_co_rwlock_unlock(&job->flush_rwlock); =20 diff --git a/block/commit.c b/block/commit.c index 6993994..4cda7f2 100644 --- a/block/commit.c +++ b/block/commit.c @@ -190,7 +190,8 @@ static void coroutine_fn commit_run(void *opaque) COMMIT_BUFFER_SIZE / BDRV_SECTOR_SIZ= E, &n); copy =3D (ret =3D=3D 1); - trace_commit_one_iteration(s, sector_num, n, ret); + trace_commit_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, ret); if (copy) { ret =3D commit_populate(s->top, s->base, sector_num, n, buf); bytes_written +=3D n * BDRV_SECTOR_SIZE; diff --git a/block/mirror.c b/block/mirror.c index eb27efc..b4dfe95 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -103,7 +103,8 @@ static void mirror_iteration_done(MirrorOp *op, int ret) int64_t chunk_num; int i, nb_chunks, sectors_per_chunk; =20 - trace_mirror_iteration_done(s, op->sector_num, op->nb_sectors, ret); + trace_mirror_iteration_done(s, op->sector_num * BDRV_SECTOR_SIZE, + op->nb_sectors * BDRV_SECTOR_SIZE, ret); =20 s->in_flight--; s->sectors_in_flight -=3D op->nb_sectors; @@ -268,7 +269,8 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t se= ctor_num, nb_chunks =3D DIV_ROUND_UP(nb_sectors, sectors_per_chunk); =20 while (s->buf_free_count < nb_chunks) { - trace_mirror_yield_in_flight(s, sector_num, s->in_flight); + trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE, + s->in_flight); mirror_wait_for_io(s); } =20 @@ -294,7 +296,8 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t se= ctor_num, /* Copy the dirty cluster. */ s->in_flight++; s->sectors_in_flight +=3D nb_sectors; - trace_mirror_one_iteration(s, sector_num, nb_sectors); + trace_mirror_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE); =20 blk_aio_preadv(source, sector_num * BDRV_SECTOR_SIZE, &op->qiov, 0, mirror_read_complete, op); @@ -347,14 +350,16 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) if (sector_num < 0) { bdrv_set_dirty_iter(s->dbi, 0); sector_num =3D bdrv_dirty_iter_next(s->dbi); - trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap)= ); + trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap)= * + BDRV_SECTOR_SIZE); assert(sector_num >=3D 0); } bdrv_dirty_bitmap_unlock(s->dirty_bitmap); =20 first_chunk =3D sector_num / sectors_per_chunk; while (test_bit(first_chunk, s->in_flight_bitmap)) { - trace_mirror_yield_in_flight(s, sector_num, s->in_flight); + trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE, + s->in_flight); mirror_wait_for_io(s); } =20 @@ -433,7 +438,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) } =20 while (s->in_flight >=3D MAX_IN_FLIGHT) { - trace_mirror_yield_in_flight(s, sector_num, s->in_flight); + trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE, + s->in_flight); mirror_wait_for_io(s); } =20 @@ -823,7 +829,8 @@ static void coroutine_fn mirror_run(void *opaque) s->common.iostatus =3D=3D BLOCK_DEVICE_IO_STATUS_OK) { if (s->in_flight >=3D MAX_IN_FLIGHT || s->buf_free_count =3D= =3D 0 || (cnt =3D=3D 0 && s->in_flight > 0)) { - trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight= ); + trace_mirror_yield(s, cnt * BDRV_SECTOR_SIZE, + s->buf_free_count, s->in_flight); mirror_wait_for_io(s); continue; } else if (cnt !=3D 0) { @@ -864,7 +871,7 @@ static void coroutine_fn mirror_run(void *opaque) * whether to switch to target check one last time if I/O has * come in the meanwhile, and if not flush the data to disk. */ - trace_mirror_before_drain(s, cnt); + trace_mirror_before_drain(s, cnt * BDRV_SECTOR_SIZE); =20 bdrv_drained_begin(bs); cnt =3D bdrv_get_dirty_count(s->dirty_bitmap); @@ -883,7 +890,8 @@ static void coroutine_fn mirror_run(void *opaque) } =20 ret =3D 0; - trace_mirror_before_sleep(s, cnt, s->synced, delay_ns); + trace_mirror_before_sleep(s, cnt * BDRV_SECTOR_SIZE, + s->synced, delay_ns); if (!s->synced) { block_job_sleep_ns(&s->common, QEMU_CLOCK_REALTIME, delay_ns); if (block_job_is_cancelled(&s->common)) { diff --git a/block/stream.c b/block/stream.c index 29273a5..6cb3939 100644 --- a/block/stream.c +++ b/block/stream.c @@ -168,7 +168,8 @@ static void coroutine_fn stream_run(void *opaque) =20 copy =3D (ret =3D=3D 1); } - trace_stream_one_iteration(s, sector_num, n, ret); + trace_stream_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, ret); if (copy) { ret =3D stream_populate(blk, sector_num, n, buf); } diff --git a/block/trace-events b/block/trace-events index 752de6a..4a4df25 100644 --- a/block/trace-events +++ b/block/trace-events @@ -15,11 +15,11 @@ bdrv_co_pwrite_zeroes(void *bs, int64_t offset, int cou= nt, int flags) "bs %p off bdrv_co_do_copy_on_readv(void *bs, int64_t offset, unsigned int bytes, int= 64_t cluster_offset, unsigned int cluster_bytes) "bs %p offset %"PRId64" by= tes %u cluster_offset %"PRId64" cluster_bytes %u" =20 # block/stream.c -stream_one_iteration(void *s, int64_t sector_num, int nb_sectors, int is_a= llocated) "s %p sector_num %"PRId64" nb_sectors %d is_allocated %d" +stream_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_alloc= ated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d" stream_start(void *bs, void *base, void *s) "bs %p base %p s %p" =20 # block/commit.c -commit_one_iteration(void *s, int64_t sector_num, int nb_sectors, int is_a= llocated) "s %p sector_num %"PRId64" nb_sectors %d is_allocated %d" +commit_one_iteration(void *s, int64_t offset, uint64_t bytes, int is_alloc= ated) "s %p offset %" PRId64 " bytes %" PRIu64 " is_allocated %d" commit_start(void *bs, void *base, void *top, void *s) "bs %p base %p top = %p s %p" =20 # block/mirror.c @@ -28,14 +28,14 @@ mirror_restart_iter(void *s, int64_t cnt) "s %p dirty c= ount %"PRId64 mirror_before_flush(void *s) "s %p" mirror_before_drain(void *s, int64_t cnt) "s %p dirty count %"PRId64 mirror_before_sleep(void *s, int64_t cnt, int synced, uint64_t delay_ns) "= s %p dirty count %"PRId64" synced %d delay %"PRIu64"ns" -mirror_one_iteration(void *s, int64_t sector_num, int nb_sectors) "s %p se= ctor_num %"PRId64" nb_sectors %d" -mirror_iteration_done(void *s, int64_t sector_num, int nb_sectors, int ret= ) "s %p sector_num %"PRId64" nb_sectors %d ret %d" +mirror_one_iteration(void *s, int64_t offset, uint64_t bytes) "s %p offset= %" PRId64 " bytes %" PRIu64 +mirror_iteration_done(void *s, int64_t offset, uint64_t bytes, int ret) "s= %p offset %" PRId64 " bytes %" PRIu64 " ret %d" mirror_yield(void *s, int64_t cnt, int buf_free_count, int in_flight) "s %= p dirty count %"PRId64" free buffers %d in_flight %d" -mirror_yield_in_flight(void *s, int64_t sector_num, int in_flight) "s %p s= ector_num %"PRId64" in_flight %d" +mirror_yield_in_flight(void *s, int64_t offset, int in_flight) "s %p offse= t %" PRId64 " in_flight %d" =20 # block/backup.c -backup_do_cow_enter(void *job, int64_t start, int64_t sector_num, int nb_s= ectors) "job %p start %"PRId64" sector_num %"PRId64" nb_sectors %d" -backup_do_cow_return(void *job, int64_t sector_num, int nb_sectors, int re= t) "job %p sector_num %"PRId64" nb_sectors %d ret %d" +backup_do_cow_enter(void *job, int64_t start, int64_t offset, uint64_t byt= es) "job %p start %" PRId64 " offset %" PRId64 " bytes %" PRIu64 +backup_do_cow_return(void *job, int64_t offset, uint64_t bytes, int ret) "= job %p offset %" PRId64 " bytes %" PRIu64 " ret %d" backup_do_cow_skip(void *job, int64_t start) "job %p start %"PRId64 backup_do_cow_process(void *job, int64_t start) "job %p start %"PRId64 backup_do_cow_read_fail(void *job, int64_t start, int ret) "job %p start %= "PRId64" ret %d" --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448578314508.0311824537929; Fri, 7 Jul 2017 10:29:38 -0700 (PDT) Received: from localhost ([::1]:57802 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX4T-00060z-4u for importer@patchew.org; Fri, 07 Jul 2017 13:29:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41641) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlA-0004yU-8I for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWl9-0007rt-7C for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49642) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl6-0007pt-QN; Fri, 07 Jul 2017 13:09:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFF9A7CE06; Fri, 7 Jul 2017 17:09:35 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB2F0627DB; Fri, 7 Jul 2017 17:09:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CFF9A7CE06 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CFF9A7CE06 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:37 +0200 Message-Id: <1499447335-6125-23-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:09:36 +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] [PULL 022/100] stream: Switch stream_populate() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Start by converting an internal function (no semantic change). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/stream.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/block/stream.c b/block/stream.c index 6cb3939..746d525 100644 --- a/block/stream.c +++ b/block/stream.c @@ -41,20 +41,20 @@ typedef struct StreamBlockJob { } StreamBlockJob; =20 static int coroutine_fn stream_populate(BlockBackend *blk, - int64_t sector_num, int nb_sectors, + int64_t offset, uint64_t bytes, void *buf) { struct iovec iov =3D { .iov_base =3D buf, - .iov_len =3D nb_sectors * BDRV_SECTOR_SIZE, + .iov_len =3D bytes, }; QEMUIOVector qiov; =20 + assert(bytes < SIZE_MAX); qemu_iovec_init_external(&qiov, &iov, 1); =20 /* Copy-on-read the unallocated clusters */ - return blk_co_preadv(blk, sector_num * BDRV_SECTOR_SIZE, qiov.size, &q= iov, - BDRV_REQ_COPY_ON_READ); + return blk_co_preadv(blk, offset, qiov.size, &qiov, BDRV_REQ_COPY_ON_R= EAD); } =20 typedef struct { @@ -171,7 +171,8 @@ static void coroutine_fn stream_run(void *opaque) trace_stream_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, n * BDRV_SECTOR_SIZE, ret); if (copy) { - ret =3D stream_populate(blk, sector_num, n, buf); + ret =3D stream_populate(blk, sector_num * BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, buf); } if (ret < 0) { BlockErrorAction action =3D --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448387764766.2685790752411; Fri, 7 Jul 2017 10:26:27 -0700 (PDT) Received: from localhost ([::1]:57785 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX1O-0003Dp-F0 for importer@patchew.org; Fri, 07 Jul 2017 13:26:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41671) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlB-0004zi-De for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlA-0007si-BZ for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40026) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl7-0007qW-Ub; Fri, 07 Jul 2017 13:09:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 016D2624A8; Fri, 7 Jul 2017 17:09:37 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A0DF61F23; Fri, 7 Jul 2017 17:09:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 016D2624A8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 016D2624A8 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:38 +0200 Message-Id: <1499447335-6125-24-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:37 +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] [PULL 023/100] stream: Drop reached_end for stream_complete() 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-devel@nongnu.org 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" From: Eric Blake stream_complete() skips the work of rewriting the backing file if the job was cancelled, if data->reached_end is false, or if there was an error detected (non-zero data->ret) during the streaming. But note that in stream_run(), data->reached_end is only set if the loop ran to completion, and data->ret is only 0 in two cases: either the loop ran to completion (possibly by cancellation, but stream_complete checks for that), or we took an early goto out because there is no bs->backing. Thus, we can preserve the same semantics without the use of reached_end, by merely checking for bs->backing (and logically, if there was no backing file, streaming is a no-op, so there is no backing file to rewrite). Suggested-by: Kevin Wolf Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/stream.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/block/stream.c b/block/stream.c index 746d525..12f1659 100644 --- a/block/stream.c +++ b/block/stream.c @@ -59,7 +59,6 @@ static int coroutine_fn stream_populate(BlockBackend *blk, =20 typedef struct { int ret; - bool reached_end; } StreamCompleteData; =20 static void stream_complete(BlockJob *job, void *opaque) @@ -70,7 +69,7 @@ static void stream_complete(BlockJob *job, void *opaque) BlockDriverState *base =3D s->base; Error *local_err =3D NULL; =20 - if (!block_job_is_cancelled(&s->common) && data->reached_end && + if (!block_job_is_cancelled(&s->common) && bs->backing && data->ret =3D=3D 0) { const char *base_id =3D NULL, *base_fmt =3D NULL; if (base) { @@ -211,7 +210,6 @@ out: /* Modify backing chain and close BDSes in main loop */ data =3D g_malloc(sizeof(*data)); data->ret =3D ret; - data->reached_end =3D sector_num =3D=3D end; block_job_defer_to_main_loop(&s->common, stream_complete, data); } =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448620900852.0303044384934; Fri, 7 Jul 2017 10:30:20 -0700 (PDT) Received: from localhost ([::1]:57805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX58-0006ct-BK for importer@patchew.org; Fri, 07 Jul 2017 13:30:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41730) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlG-00055v-I5 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlB-0007ti-LH for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWl9-0007rP-43; Fri, 07 Jul 2017 13:09:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 35214A4FB7; Fri, 7 Jul 2017 17:09:38 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DAB961F23; Fri, 7 Jul 2017 17:09:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 35214A4FB7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 35214A4FB7 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:39 +0200 Message-Id: <1499447335-6125-25-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:38 +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] [PULL 024/100] stream: Switch stream_run() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of streaming to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are sector-aligned). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/stream.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/block/stream.c b/block/stream.c index 12f1659..e3dd2ac 100644 --- a/block/stream.c +++ b/block/stream.c @@ -107,12 +107,11 @@ static void coroutine_fn stream_run(void *opaque) BlockBackend *blk =3D s->common.blk; BlockDriverState *bs =3D blk_bs(blk); BlockDriverState *base =3D s->base; - int64_t sector_num =3D 0; - int64_t end =3D -1; + int64_t offset =3D 0; uint64_t delay_ns =3D 0; int error =3D 0; int ret =3D 0; - int n =3D 0; + int n =3D 0; /* sectors */ void *buf; =20 if (!bs->backing) { @@ -125,7 +124,6 @@ static void coroutine_fn stream_run(void *opaque) goto out; } =20 - end =3D s->common.len >> BDRV_SECTOR_BITS; buf =3D qemu_blockalign(bs, STREAM_BUFFER_SIZE); =20 /* Turn on copy-on-read for the whole block device so that guest read @@ -137,7 +135,7 @@ static void coroutine_fn stream_run(void *opaque) bdrv_enable_copy_on_read(bs); } =20 - for (sector_num =3D 0; sector_num < end; sector_num +=3D n) { + for ( ; offset < s->common.len; offset +=3D n * BDRV_SECTOR_SIZE) { bool copy; =20 /* Note that even when no rate limit is applied we need to yield @@ -150,28 +148,26 @@ static void coroutine_fn stream_run(void *opaque) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, sector_num, + ret =3D bdrv_is_allocated(bs, offset / BDRV_SECTOR_SIZE, STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { /* Copy if allocated in the intermediate images. Limit to the - * known-unallocated area [sector_num, sector_num+n). */ + * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ ret =3D bdrv_is_allocated_above(backing_bs(bs), base, - sector_num, n, &n); + offset / BDRV_SECTOR_SIZE, n, &n= ); =20 /* Finish early if end of backing file has been reached */ if (ret =3D=3D 0 && n =3D=3D 0) { - n =3D end - sector_num; + n =3D (s->common.len - offset) / BDRV_SECTOR_SIZE; } =20 copy =3D (ret =3D=3D 1); } - trace_stream_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, - n * BDRV_SECTOR_SIZE, ret); + trace_stream_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret); if (copy) { - ret =3D stream_populate(blk, sector_num * BDRV_SECTOR_SIZE, - n * BDRV_SECTOR_SIZE, buf); + ret =3D stream_populate(blk, offset, n * BDRV_SECTOR_SIZE, buf= ); } if (ret < 0) { BlockErrorAction action =3D --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448541935665.1277496586018; Fri, 7 Jul 2017 10:29:01 -0700 (PDT) Received: from localhost ([::1]:57799 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX3s-0005Sj-90 for importer@patchew.org; Fri, 07 Jul 2017 13:29:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41767) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlH-00057E-QT for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlG-00080S-LV for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46212) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlA-0007sK-BB; Fri, 07 Jul 2017 13:09:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 659EAC0467C4; Fri, 7 Jul 2017 17:09:39 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 800CE627DB; Fri, 7 Jul 2017 17:09:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 659EAC0467C4 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 659EAC0467C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:40 +0200 Message-Id: <1499447335-6125-26-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:09:39 +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] [PULL 025/100] commit: Switch commit_populate() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Start by converting an internal function (no semantic change). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/commit.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/block/commit.c b/block/commit.c index 4cda7f2..6f67d78 100644 --- a/block/commit.c +++ b/block/commit.c @@ -47,26 +47,25 @@ typedef struct CommitBlockJob { } CommitBlockJob; =20 static int coroutine_fn commit_populate(BlockBackend *bs, BlockBackend *ba= se, - int64_t sector_num, int nb_sectors, + int64_t offset, uint64_t bytes, void *buf) { int ret =3D 0; QEMUIOVector qiov; struct iovec iov =3D { .iov_base =3D buf, - .iov_len =3D nb_sectors * BDRV_SECTOR_SIZE, + .iov_len =3D bytes, }; =20 + assert(bytes < SIZE_MAX); qemu_iovec_init_external(&qiov, &iov, 1); =20 - ret =3D blk_co_preadv(bs, sector_num * BDRV_SECTOR_SIZE, - qiov.size, &qiov, 0); + ret =3D blk_co_preadv(bs, offset, qiov.size, &qiov, 0); if (ret < 0) { return ret; } =20 - ret =3D blk_co_pwritev(base, sector_num * BDRV_SECTOR_SIZE, - qiov.size, &qiov, 0); + ret =3D blk_co_pwritev(base, offset, qiov.size, &qiov, 0); if (ret < 0) { return ret; } @@ -193,7 +192,9 @@ static void coroutine_fn commit_run(void *opaque) trace_commit_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, n * BDRV_SECTOR_SIZE, ret); if (copy) { - ret =3D commit_populate(s->top, s->base, sector_num, n, buf); + ret =3D commit_populate(s->top, s->base, + sector_num * BDRV_SECTOR_SIZE, + n * BDRV_SECTOR_SIZE, buf); bytes_written +=3D n * BDRV_SECTOR_SIZE; } if (ret < 0) { --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448734556676.9102219701233; Fri, 7 Jul 2017 10:32:14 -0700 (PDT) Received: from localhost ([::1]:57817 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX6z-0008W1-5I for importer@patchew.org; Fri, 07 Jul 2017 13:32:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlJ-00058Z-4E for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlH-00082A-Tj for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40154) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlB-0007t6-Hv; Fri, 07 Jul 2017 13:09:41 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9E20F61E50; Fri, 7 Jul 2017 17:09:40 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id B45CD61F23; Fri, 7 Jul 2017 17:09:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9E20F61E50 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9E20F61E50 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:41 +0200 Message-Id: <1499447335-6125-27-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:40 +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] [PULL 026/100] commit: Switch commit_run() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of committing to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are sector-aligned). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/commit.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/block/commit.c b/block/commit.c index 6f67d78..c3a7bca 100644 --- a/block/commit.c +++ b/block/commit.c @@ -143,17 +143,16 @@ static void coroutine_fn commit_run(void *opaque) { CommitBlockJob *s =3D opaque; CommitCompleteData *data; - int64_t sector_num, end; + int64_t offset; uint64_t delay_ns =3D 0; int ret =3D 0; - int n =3D 0; + int n =3D 0; /* sectors */ void *buf =3D NULL; int bytes_written =3D 0; int64_t base_len; =20 ret =3D s->common.len =3D blk_getlength(s->top); =20 - if (s->common.len < 0) { goto out; } @@ -170,10 +169,9 @@ static void coroutine_fn commit_run(void *opaque) } } =20 - end =3D s->common.len >> BDRV_SECTOR_BITS; buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); =20 - for (sector_num =3D 0; sector_num < end; sector_num +=3D n) { + for (offset =3D 0; offset < s->common.len; offset +=3D n * BDRV_SECTOR= _SIZE) { bool copy; =20 /* Note that even when no rate limit is applied we need to yield @@ -185,15 +183,13 @@ static void coroutine_fn commit_run(void *opaque) } /* Copy if allocated above the base */ ret =3D bdrv_is_allocated_above(blk_bs(s->top), blk_bs(s->base), - sector_num, + offset / BDRV_SECTOR_SIZE, COMMIT_BUFFER_SIZE / BDRV_SECTOR_SIZ= E, &n); copy =3D (ret =3D=3D 1); - trace_commit_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, - n * BDRV_SECTOR_SIZE, ret); + trace_commit_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret); if (copy) { - ret =3D commit_populate(s->top, s->base, - sector_num * BDRV_SECTOR_SIZE, + ret =3D commit_populate(s->top, s->base, offset, n * BDRV_SECTOR_SIZE, buf); bytes_written +=3D n * BDRV_SECTOR_SIZE; } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499447901221720.3865189233248; Fri, 7 Jul 2017 10:18:21 -0700 (PDT) Received: from localhost ([::1]:57734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWtV-0004D8-NK for importer@patchew.org; Fri, 07 Jul 2017 13:18:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41856) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlK-00059l-Ie for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlI-00083U-IP for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37378) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlC-0007u5-R8; Fri, 07 Jul 2017 13:09:43 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D427D15561; Fri, 7 Jul 2017 17:09:41 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E7B7161F23; Fri, 7 Jul 2017 17:09:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D427D15561 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D427D15561 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:42 +0200 Message-Id: <1499447335-6125-28-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:09:42 +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] [PULL 027/100] mirror: Switch MirrorBlockJob to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Continue by converting an internal structure (no semantic change), and all references to the buffer size. Add an assertion that our use of s->granularity >> BDRV_SECTOR_BITS (necessary for interaction with sector-based dirty bitmaps, until a later patch converts those to be byte-based) does not suffer from truncation problems. [checkpatch has a false positive on use of MIN() in this patch] Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 84 +++++++++++++++++++++++++++++-------------------------= ---- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index b4dfe95..10f4e9b 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -24,9 +24,8 @@ =20 #define SLICE_TIME 100000000ULL /* ns */ #define MAX_IN_FLIGHT 16 -#define MAX_IO_SECTORS ((1 << 20) >> BDRV_SECTOR_BITS) /* 1 Mb */ -#define DEFAULT_MIRROR_BUF_SIZE \ - (MAX_IN_FLIGHT * MAX_IO_SECTORS * BDRV_SECTOR_SIZE) +#define MAX_IO_BYTES (1 << 20) /* 1 Mb */ +#define DEFAULT_MIRROR_BUF_SIZE (MAX_IN_FLIGHT * MAX_IO_BYTES) =20 /* The mirroring buffer is a list of granularity-sized chunks. * Free chunks are organized in a list. @@ -67,11 +66,11 @@ typedef struct MirrorBlockJob { uint64_t last_pause_ns; unsigned long *in_flight_bitmap; int in_flight; - int64_t sectors_in_flight; + int64_t bytes_in_flight; int ret; bool unmap; bool waiting_for_io; - int target_cluster_sectors; + int target_cluster_size; int max_iov; bool initial_zeroing_ongoing; } MirrorBlockJob; @@ -79,8 +78,8 @@ typedef struct MirrorBlockJob { typedef struct MirrorOp { MirrorBlockJob *s; QEMUIOVector qiov; - int64_t sector_num; - int nb_sectors; + int64_t offset; + uint64_t bytes; } MirrorOp; =20 static BlockErrorAction mirror_error_action(MirrorBlockJob *s, bool read, @@ -101,13 +100,12 @@ static void mirror_iteration_done(MirrorOp *op, int r= et) MirrorBlockJob *s =3D op->s; struct iovec *iov; int64_t chunk_num; - int i, nb_chunks, sectors_per_chunk; + int i, nb_chunks; =20 - trace_mirror_iteration_done(s, op->sector_num * BDRV_SECTOR_SIZE, - op->nb_sectors * BDRV_SECTOR_SIZE, ret); + trace_mirror_iteration_done(s, op->offset, op->bytes, ret); =20 s->in_flight--; - s->sectors_in_flight -=3D op->nb_sectors; + s->bytes_in_flight -=3D op->bytes; iov =3D op->qiov.iov; for (i =3D 0; i < op->qiov.niov; i++) { MirrorBuffer *buf =3D (MirrorBuffer *) iov[i].iov_base; @@ -115,16 +113,15 @@ static void mirror_iteration_done(MirrorOp *op, int r= et) s->buf_free_count++; } =20 - sectors_per_chunk =3D s->granularity >> BDRV_SECTOR_BITS; - chunk_num =3D op->sector_num / sectors_per_chunk; - nb_chunks =3D DIV_ROUND_UP(op->nb_sectors, sectors_per_chunk); + chunk_num =3D op->offset / s->granularity; + nb_chunks =3D DIV_ROUND_UP(op->bytes, s->granularity); bitmap_clear(s->in_flight_bitmap, chunk_num, nb_chunks); if (ret >=3D 0) { if (s->cow_bitmap) { bitmap_set(s->cow_bitmap, chunk_num, nb_chunks); } if (!s->initial_zeroing_ongoing) { - s->common.offset +=3D (uint64_t)op->nb_sectors * BDRV_SECTOR_S= IZE; + s->common.offset +=3D op->bytes; } } qemu_iovec_destroy(&op->qiov); @@ -144,7 +141,8 @@ static void mirror_write_complete(void *opaque, int ret) if (ret < 0) { BlockErrorAction action; =20 - bdrv_set_dirty_bitmap(s->dirty_bitmap, op->sector_num, op->nb_sect= ors); + bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset >> BDRV_SECTOR_B= ITS, + op->bytes >> BDRV_SECTOR_BITS); action =3D mirror_error_action(s, false, -ret); if (action =3D=3D BLOCK_ERROR_ACTION_REPORT && s->ret >=3D 0) { s->ret =3D ret; @@ -163,7 +161,8 @@ static void mirror_read_complete(void *opaque, int ret) if (ret < 0) { BlockErrorAction action; =20 - bdrv_set_dirty_bitmap(s->dirty_bitmap, op->sector_num, op->nb_sect= ors); + bdrv_set_dirty_bitmap(s->dirty_bitmap, op->offset >> BDRV_SECTOR_B= ITS, + op->bytes >> BDRV_SECTOR_BITS); action =3D mirror_error_action(s, true, -ret); if (action =3D=3D BLOCK_ERROR_ACTION_REPORT && s->ret >=3D 0) { s->ret =3D ret; @@ -171,7 +170,7 @@ static void mirror_read_complete(void *opaque, int ret) =20 mirror_iteration_done(op, ret); } else { - blk_aio_pwritev(s->target, op->sector_num * BDRV_SECTOR_SIZE, &op-= >qiov, + blk_aio_pwritev(s->target, op->offset, &op->qiov, 0, mirror_write_complete, op); } aio_context_release(blk_get_aio_context(s->common.blk)); @@ -211,7 +210,8 @@ static int mirror_cow_align(MirrorBlockJob *s, align_nb_sectors =3D max_sectors; if (need_cow) { align_nb_sectors =3D QEMU_ALIGN_DOWN(align_nb_sectors, - s->target_cluster_sectors); + s->target_cluster_size >> + BDRV_SECTOR_BITS); } } /* Clipping may result in align_nb_sectors unaligned to chunk boundary= , but @@ -277,8 +277,8 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t se= ctor_num, /* Allocate a MirrorOp that is used as an AIO callback. */ op =3D g_new(MirrorOp, 1); op->s =3D s; - op->sector_num =3D sector_num; - op->nb_sectors =3D nb_sectors; + op->offset =3D sector_num * BDRV_SECTOR_SIZE; + op->bytes =3D nb_sectors * BDRV_SECTOR_SIZE; =20 /* Now make a QEMUIOVector taking enough granularity-sized chunks * from s->buf_free. @@ -295,7 +295,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t se= ctor_num, =20 /* Copy the dirty cluster. */ s->in_flight++; - s->sectors_in_flight +=3D nb_sectors; + s->bytes_in_flight +=3D nb_sectors * BDRV_SECTOR_SIZE; trace_mirror_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); =20 @@ -315,19 +315,17 @@ static void mirror_do_zero_or_discard(MirrorBlockJob = *s, * so the freeing in mirror_iteration_done is nop. */ op =3D g_new0(MirrorOp, 1); op->s =3D s; - op->sector_num =3D sector_num; - op->nb_sectors =3D nb_sectors; + op->offset =3D sector_num * BDRV_SECTOR_SIZE; + op->bytes =3D nb_sectors * BDRV_SECTOR_SIZE; =20 s->in_flight++; - s->sectors_in_flight +=3D nb_sectors; + s->bytes_in_flight +=3D nb_sectors * BDRV_SECTOR_SIZE; if (is_discard) { blk_aio_pdiscard(s->target, sector_num << BDRV_SECTOR_BITS, - op->nb_sectors << BDRV_SECTOR_BITS, - mirror_write_complete, op); + op->bytes, mirror_write_complete, op); } else { blk_aio_pwrite_zeroes(s->target, sector_num * BDRV_SECTOR_SIZE, - op->nb_sectors * BDRV_SECTOR_SIZE, - s->unmap ? BDRV_REQ_MAY_UNMAP : 0, + op->bytes, s->unmap ? BDRV_REQ_MAY_UNMAP : 0, mirror_write_complete, op); } } @@ -342,8 +340,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) int64_t end =3D s->bdev_length / BDRV_SECTOR_SIZE; int sectors_per_chunk =3D s->granularity >> BDRV_SECTOR_BITS; bool write_zeroes_ok =3D bdrv_can_write_zeroes_with_unmap(blk_bs(s->ta= rget)); - int max_io_sectors =3D MAX((s->buf_size >> BDRV_SECTOR_BITS) / MAX_IN_= FLIGHT, - MAX_IO_SECTORS); + int max_io_bytes =3D MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); =20 bdrv_dirty_bitmap_lock(s->dirty_bitmap); sector_num =3D bdrv_dirty_iter_next(s->dbi); @@ -415,9 +412,10 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) nb_chunks * sectors_per_chunk, &io_sectors, &file); if (ret < 0) { - io_sectors =3D MIN(nb_chunks * sectors_per_chunk, max_io_secto= rs); + io_sectors =3D MIN(nb_chunks * sectors_per_chunk, + max_io_bytes >> BDRV_SECTOR_BITS); } else if (ret & BDRV_BLOCK_DATA) { - io_sectors =3D MIN(io_sectors, max_io_sectors); + io_sectors =3D MIN(io_sectors, max_io_bytes >> BDRV_SECTOR_BIT= S); } =20 io_sectors -=3D io_sectors % sectors_per_chunk; @@ -719,7 +717,6 @@ static void coroutine_fn mirror_run(void *opaque) char backing_filename[2]; /* we only need 2 characters because we are = only checking for a NULL string */ int ret =3D 0; - int target_cluster_size =3D BDRV_SECTOR_SIZE; =20 if (block_job_is_cancelled(&s->common)) { goto immediate_exit; @@ -771,14 +768,15 @@ static void coroutine_fn mirror_run(void *opaque) bdrv_get_backing_filename(target_bs, backing_filename, sizeof(backing_filename)); if (!bdrv_get_info(target_bs, &bdi) && bdi.cluster_size) { - target_cluster_size =3D bdi.cluster_size; + s->target_cluster_size =3D bdi.cluster_size; + } else { + s->target_cluster_size =3D BDRV_SECTOR_SIZE; } - if (backing_filename[0] && !target_bs->backing - && s->granularity < target_cluster_size) { - s->buf_size =3D MAX(s->buf_size, target_cluster_size); + if (backing_filename[0] && !target_bs->backing && + s->granularity < s->target_cluster_size) { + s->buf_size =3D MAX(s->buf_size, s->target_cluster_size); s->cow_bitmap =3D bitmap_new(length); } - s->target_cluster_sectors =3D target_cluster_size >> BDRV_SECTOR_BITS; s->max_iov =3D MIN(bs->bl.max_iov, target_bs->bl.max_iov); =20 s->buf =3D qemu_try_blockalign(bs, s->buf_size); @@ -814,10 +812,10 @@ static void coroutine_fn mirror_run(void *opaque) cnt =3D bdrv_get_dirty_count(s->dirty_bitmap); /* s->common.offset contains the number of bytes already processed= so * far, cnt is the number of dirty sectors remaining and - * s->sectors_in_flight is the number of sectors currently being + * s->bytes_in_flight is the number of bytes currently being * processed; together those are the current total operation lengt= h */ - s->common.len =3D s->common.offset + - (cnt + s->sectors_in_flight) * BDRV_SECTOR_SIZE; + s->common.len =3D s->common.offset + s->bytes_in_flight + + cnt * BDRV_SECTOR_SIZE; =20 /* Note that even when no rate limit is applied we need to yield * periodically with no pending I/O so that bdrv_drain_all() retur= ns. @@ -1150,6 +1148,8 @@ static void mirror_start_job(const char *job_id, Bloc= kDriverState *bs, } =20 assert ((granularity & (granularity - 1)) =3D=3D 0); + /* Granularity must be large enough for sector-based dirty bitmap */ + assert(granularity >=3D BDRV_SECTOR_SIZE); =20 if (buf_size < 0) { error_setg(errp, "Invalid parameter 'buf-size'"); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448896450631.1298352602149; Fri, 7 Jul 2017 10:34:56 -0700 (PDT) Received: from localhost ([::1]:57829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX9a-0002Wi-56 for importer@patchew.org; Fri, 07 Jul 2017 13:34:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlJ-00058M-4B for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlH-00081r-QR for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49790) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlE-0007vF-1c; Fri, 07 Jul 2017 13:09:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1AC838008D; Fri, 7 Jul 2017 17:09:43 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28306627DB; Fri, 7 Jul 2017 17:09:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1AC838008D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1AC838008D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:43 +0200 Message-Id: <1499447335-6125-29-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:09:43 +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] [PULL 028/100] mirror: Switch mirror_do_zero_or_discard() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 10f4e9b..60eefbd 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -305,8 +305,8 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t se= ctor_num, } =20 static void mirror_do_zero_or_discard(MirrorBlockJob *s, - int64_t sector_num, - int nb_sectors, + int64_t offset, + uint64_t bytes, bool is_discard) { MirrorOp *op; @@ -315,16 +315,16 @@ static void mirror_do_zero_or_discard(MirrorBlockJob = *s, * so the freeing in mirror_iteration_done is nop. */ op =3D g_new0(MirrorOp, 1); op->s =3D s; - op->offset =3D sector_num * BDRV_SECTOR_SIZE; - op->bytes =3D nb_sectors * BDRV_SECTOR_SIZE; + op->offset =3D offset; + op->bytes =3D bytes; =20 s->in_flight++; - s->bytes_in_flight +=3D nb_sectors * BDRV_SECTOR_SIZE; + s->bytes_in_flight +=3D bytes; if (is_discard) { - blk_aio_pdiscard(s->target, sector_num << BDRV_SECTOR_BITS, + blk_aio_pdiscard(s->target, offset, op->bytes, mirror_write_complete, op); } else { - blk_aio_pwrite_zeroes(s->target, sector_num * BDRV_SECTOR_SIZE, + blk_aio_pwrite_zeroes(s->target, offset, op->bytes, s->unmap ? BDRV_REQ_MAY_UNMAP : 0, mirror_write_complete, op); } @@ -453,7 +453,8 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) break; case MIRROR_METHOD_ZERO: case MIRROR_METHOD_DISCARD: - mirror_do_zero_or_discard(s, sector_num, io_sectors, + mirror_do_zero_or_discard(s, sector_num * BDRV_SECTOR_SIZE, + io_sectors * BDRV_SECTOR_SIZE, mirror_method =3D=3D MIRROR_METHOD_D= ISCARD); if (write_zeroes_ok) { io_bytes_acct =3D 0; @@ -657,7 +658,8 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) continue; } =20 - mirror_do_zero_or_discard(s, sector_num, nb_sectors, false); + mirror_do_zero_or_discard(s, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, false= ); sector_num +=3D nb_sectors; } =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448784572740.3570034118773; Fri, 7 Jul 2017 10:33:04 -0700 (PDT) Received: from localhost ([::1]:57821 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX7l-0000gc-KC for importer@patchew.org; Fri, 07 Jul 2017 13:33:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41817) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlJ-00058l-Ej for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlI-00082c-2V for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlF-0007xz-95; Fri, 07 Jul 2017 13:09:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4F7123680C; Fri, 7 Jul 2017 17:09:44 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 663F261F52; Fri, 7 Jul 2017 17:09:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4F7123680C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4F7123680C From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:44 +0200 Message-Id: <1499447335-6125-30-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:09:44 +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] [PULL 029/100] mirror: Update signature of mirror_clip_sectors() 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-devel@nongnu.org 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" From: Eric Blake Rather than having a void function that modifies its input in-place as the output, change the signature to reduce a layer of indirection and return the result. Suggested-by: John Snow Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 60eefbd..a41ef25 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -176,12 +176,12 @@ static void mirror_read_complete(void *opaque, int re= t) aio_context_release(blk_get_aio_context(s->common.blk)); } =20 -static inline void mirror_clip_sectors(MirrorBlockJob *s, - int64_t sector_num, - int *nb_sectors) +static inline int mirror_clip_sectors(MirrorBlockJob *s, + int64_t sector_num, + int nb_sectors) { - *nb_sectors =3D MIN(*nb_sectors, - s->bdev_length / BDRV_SECTOR_SIZE - sector_num); + return MIN(nb_sectors, + s->bdev_length / BDRV_SECTOR_SIZE - sector_num); } =20 /* Round sector_num and/or nb_sectors to target cluster if COW is needed, = and @@ -216,7 +216,8 @@ static int mirror_cow_align(MirrorBlockJob *s, } /* Clipping may result in align_nb_sectors unaligned to chunk boundary= , but * that doesn't matter because it's already the end of source image. */ - mirror_clip_sectors(s, align_sector_num, &align_nb_sectors); + align_nb_sectors =3D mirror_clip_sectors(s, align_sector_num, + align_nb_sectors); =20 ret =3D align_sector_num + align_nb_sectors - (*sector_num + *nb_secto= rs); *sector_num =3D align_sector_num; @@ -445,7 +446,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) return 0; } =20 - mirror_clip_sectors(s, sector_num, &io_sectors); + io_sectors =3D mirror_clip_sectors(s, sector_num, io_sectors); switch (mirror_method) { case MIRROR_METHOD_COPY: io_sectors =3D mirror_do_read(s, sector_num, io_sectors); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499448954902169.92973409188187; Fri, 7 Jul 2017 10:35:54 -0700 (PDT) Received: from localhost ([::1]:57838 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXAX-0003N4-G7 for importer@patchew.org; Fri, 07 Jul 2017 13:35:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41875) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlL-0005AC-1F for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlJ-000854-L9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52814) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlG-0007zZ-Fg; Fri, 07 Jul 2017 13:09:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8135D8123F; Fri, 7 Jul 2017 17:09:45 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AD3161F23; Fri, 7 Jul 2017 17:09:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8135D8123F Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8135D8123F From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:45 +0200 Message-Id: <1499447335-6125-31-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:09:45 +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] [PULL 030/100] mirror: Switch mirror_cow_align() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change), and add mirror_clip_bytes() as a counterpart to mirror_clip_sectors(). Some of the conversion is a bit tricky, requiring temporaries to convert between units; it will be cleared up in a following patch. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 63 ++++++++++++++++++++++++++++++++++--------------------= ---- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index a41ef25..0378bd2 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -176,6 +176,15 @@ static void mirror_read_complete(void *opaque, int ret) aio_context_release(blk_get_aio_context(s->common.blk)); } =20 +/* Clip bytes relative to offset to not exceed end-of-file */ +static inline int64_t mirror_clip_bytes(MirrorBlockJob *s, + int64_t offset, + int64_t bytes) +{ + return MIN(bytes, s->bdev_length - offset); +} + +/* Clip nb_sectors relative to sector_num to not exceed end-of-file */ static inline int mirror_clip_sectors(MirrorBlockJob *s, int64_t sector_num, int nb_sectors) @@ -184,44 +193,38 @@ static inline int mirror_clip_sectors(MirrorBlockJob = *s, s->bdev_length / BDRV_SECTOR_SIZE - sector_num); } =20 -/* Round sector_num and/or nb_sectors to target cluster if COW is needed, = and - * return the offset of the adjusted tail sector against original. */ -static int mirror_cow_align(MirrorBlockJob *s, - int64_t *sector_num, - int *nb_sectors) +/* Round offset and/or bytes to target cluster if COW is needed, and + * return the offset of the adjusted tail against original. */ +static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset, + unsigned int *bytes) { bool need_cow; int ret =3D 0; - int chunk_sectors =3D s->granularity >> BDRV_SECTOR_BITS; - int64_t align_sector_num =3D *sector_num; - int align_nb_sectors =3D *nb_sectors; - int max_sectors =3D chunk_sectors * s->max_iov; + int64_t align_offset =3D *offset; + unsigned int align_bytes =3D *bytes; + int max_bytes =3D s->granularity * s->max_iov; =20 - need_cow =3D !test_bit(*sector_num / chunk_sectors, s->cow_bitmap); - need_cow |=3D !test_bit((*sector_num + *nb_sectors - 1) / chunk_sector= s, + need_cow =3D !test_bit(*offset / s->granularity, s->cow_bitmap); + need_cow |=3D !test_bit((*offset + *bytes - 1) / s->granularity, s->cow_bitmap); if (need_cow) { - bdrv_round_sectors_to_clusters(blk_bs(s->target), *sector_num, - *nb_sectors, &align_sector_num, - &align_nb_sectors); + bdrv_round_to_clusters(blk_bs(s->target), *offset, *bytes, + &align_offset, &align_bytes); } =20 - if (align_nb_sectors > max_sectors) { - align_nb_sectors =3D max_sectors; + if (align_bytes > max_bytes) { + align_bytes =3D max_bytes; if (need_cow) { - align_nb_sectors =3D QEMU_ALIGN_DOWN(align_nb_sectors, - s->target_cluster_size >> - BDRV_SECTOR_BITS); + align_bytes =3D QEMU_ALIGN_DOWN(align_bytes, s->target_cluster= _size); } } - /* Clipping may result in align_nb_sectors unaligned to chunk boundary= , but + /* Clipping may result in align_bytes unaligned to chunk boundary, but * that doesn't matter because it's already the end of source image. */ - align_nb_sectors =3D mirror_clip_sectors(s, align_sector_num, - align_nb_sectors); + align_bytes =3D mirror_clip_bytes(s, align_offset, align_bytes); =20 - ret =3D align_sector_num + align_nb_sectors - (*sector_num + *nb_secto= rs); - *sector_num =3D align_sector_num; - *nb_sectors =3D align_nb_sectors; + ret =3D align_offset + align_bytes - (*offset + *bytes); + *offset =3D align_offset; + *bytes =3D align_bytes; assert(ret >=3D 0); return ret; } @@ -257,10 +260,18 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t = sector_num, nb_sectors =3D MIN(s->buf_size >> BDRV_SECTOR_BITS, nb_sectors); nb_sectors =3D MIN(max_sectors, nb_sectors); assert(nb_sectors); + assert(nb_sectors < BDRV_REQUEST_MAX_SECTORS); ret =3D nb_sectors; =20 if (s->cow_bitmap) { - ret +=3D mirror_cow_align(s, §or_num, &nb_sectors); + int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; + unsigned int bytes =3D nb_sectors * BDRV_SECTOR_SIZE; + int gap; + + gap =3D mirror_cow_align(s, &offset, &bytes); + sector_num =3D offset / BDRV_SECTOR_SIZE; + nb_sectors =3D bytes / BDRV_SECTOR_SIZE; + ret +=3D gap / BDRV_SECTOR_SIZE; } assert(nb_sectors << BDRV_SECTOR_BITS <=3D s->buf_size); /* The sector range must meet granularity because: --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499449118034794.2148657109894; Fri, 7 Jul 2017 10:38:38 -0700 (PDT) Received: from localhost ([::1]:57851 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXD9-0005Wl-GF for importer@patchew.org; Fri, 07 Jul 2017 13:38:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlM-0005Cj-P7 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlL-000875-8W for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlH-00080w-Mm; Fri, 07 Jul 2017 13:09:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B531161E50; Fri, 7 Jul 2017 17:09:46 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD04C61F23; Fri, 7 Jul 2017 17:09:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B531161E50 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B531161E50 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:46 +0200 Message-Id: <1499447335-6125-32-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:46 +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] [PULL 031/100] mirror: Switch mirror_do_read() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function, preserving all existing semantics, and adding one more assertion that things are still sector-aligned (so that conversions to sectors in mirror_read_complete don't need to round). Signed-off-by: Eric Blake Signed-off-by: Kevin Wolf --- block/mirror.c | 74 ++++++++++++++++++++++++++----------------------------= ---- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 0378bd2..262fddf 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -196,7 +196,7 @@ static inline int mirror_clip_sectors(MirrorBlockJob *s, /* Round offset and/or bytes to target cluster if COW is needed, and * return the offset of the adjusted tail against original. */ static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset, - unsigned int *bytes) + uint64_t *bytes) { bool need_cow; int ret =3D 0; @@ -204,6 +204,7 @@ static int mirror_cow_align(MirrorBlockJob *s, int64_t = *offset, unsigned int align_bytes =3D *bytes; int max_bytes =3D s->granularity * s->max_iov; =20 + assert(*bytes < INT_MAX); need_cow =3D !test_bit(*offset / s->granularity, s->cow_bitmap); need_cow |=3D !test_bit((*offset + *bytes - 1) / s->granularity, s->cow_bitmap); @@ -238,59 +239,51 @@ static inline void mirror_wait_for_io(MirrorBlockJob = *s) } =20 /* Submit async read while handling COW. - * Returns: The number of sectors copied after and including sector_num, - * excluding any sectors copied prior to sector_num due to alignm= ent. - * This will be nb_sectors if no alignment is necessary, or - * (new_end - sector_num) if tail is rounded up or down due to + * Returns: The number of bytes copied after and including offset, + * excluding any bytes copied prior to offset due to alignment. + * This will be @bytes if no alignment is necessary, or + * (new_end - offset) if tail is rounded up or down due to * alignment or buffer limit. */ -static int mirror_do_read(MirrorBlockJob *s, int64_t sector_num, - int nb_sectors) +static uint64_t mirror_do_read(MirrorBlockJob *s, int64_t offset, + uint64_t bytes) { BlockBackend *source =3D s->common.blk; - int sectors_per_chunk, nb_chunks; - int ret; + int nb_chunks; + uint64_t ret; MirrorOp *op; - int max_sectors; + uint64_t max_bytes; =20 - sectors_per_chunk =3D s->granularity >> BDRV_SECTOR_BITS; - max_sectors =3D sectors_per_chunk * s->max_iov; + max_bytes =3D s->granularity * s->max_iov; =20 /* We can only handle as much as buf_size at a time. */ - nb_sectors =3D MIN(s->buf_size >> BDRV_SECTOR_BITS, nb_sectors); - nb_sectors =3D MIN(max_sectors, nb_sectors); - assert(nb_sectors); - assert(nb_sectors < BDRV_REQUEST_MAX_SECTORS); - ret =3D nb_sectors; + bytes =3D MIN(s->buf_size, MIN(max_bytes, bytes)); + assert(bytes); + assert(bytes < BDRV_REQUEST_MAX_BYTES); + ret =3D bytes; =20 if (s->cow_bitmap) { - int64_t offset =3D sector_num * BDRV_SECTOR_SIZE; - unsigned int bytes =3D nb_sectors * BDRV_SECTOR_SIZE; - int gap; - - gap =3D mirror_cow_align(s, &offset, &bytes); - sector_num =3D offset / BDRV_SECTOR_SIZE; - nb_sectors =3D bytes / BDRV_SECTOR_SIZE; - ret +=3D gap / BDRV_SECTOR_SIZE; + ret +=3D mirror_cow_align(s, &offset, &bytes); } - assert(nb_sectors << BDRV_SECTOR_BITS <=3D s->buf_size); - /* The sector range must meet granularity because: + assert(bytes <=3D s->buf_size); + /* The offset is granularity-aligned because: * 1) Caller passes in aligned values; * 2) mirror_cow_align is used only when target cluster is larger. */ - assert(!(sector_num % sectors_per_chunk)); - nb_chunks =3D DIV_ROUND_UP(nb_sectors, sectors_per_chunk); + assert(QEMU_IS_ALIGNED(offset, s->granularity)); + /* The range is sector-aligned, since bdrv_getlength() rounds up. */ + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE)); + nb_chunks =3D DIV_ROUND_UP(bytes, s->granularity); =20 while (s->buf_free_count < nb_chunks) { - trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE, - s->in_flight); + trace_mirror_yield_in_flight(s, offset, s->in_flight); mirror_wait_for_io(s); } =20 /* Allocate a MirrorOp that is used as an AIO callback. */ op =3D g_new(MirrorOp, 1); op->s =3D s; - op->offset =3D sector_num * BDRV_SECTOR_SIZE; - op->bytes =3D nb_sectors * BDRV_SECTOR_SIZE; + op->offset =3D offset; + op->bytes =3D bytes; =20 /* Now make a QEMUIOVector taking enough granularity-sized chunks * from s->buf_free. @@ -298,7 +291,7 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t se= ctor_num, qemu_iovec_init(&op->qiov, nb_chunks); while (nb_chunks-- > 0) { MirrorBuffer *buf =3D QSIMPLEQ_FIRST(&s->buf_free); - size_t remaining =3D nb_sectors * BDRV_SECTOR_SIZE - op->qiov.size; + size_t remaining =3D bytes - op->qiov.size; =20 QSIMPLEQ_REMOVE_HEAD(&s->buf_free, next); s->buf_free_count--; @@ -307,12 +300,10 @@ static int mirror_do_read(MirrorBlockJob *s, int64_t = sector_num, =20 /* Copy the dirty cluster. */ s->in_flight++; - s->bytes_in_flight +=3D nb_sectors * BDRV_SECTOR_SIZE; - trace_mirror_one_iteration(s, sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE); + s->bytes_in_flight +=3D bytes; + trace_mirror_one_iteration(s, offset, bytes); =20 - blk_aio_preadv(source, sector_num * BDRV_SECTOR_SIZE, &op->qiov, 0, - mirror_read_complete, op); + blk_aio_preadv(source, offset, &op->qiov, 0, mirror_read_complete, op); return ret; } =20 @@ -460,8 +451,9 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) io_sectors =3D mirror_clip_sectors(s, sector_num, io_sectors); switch (mirror_method) { case MIRROR_METHOD_COPY: - io_sectors =3D mirror_do_read(s, sector_num, io_sectors); - io_bytes_acct =3D io_sectors * BDRV_SECTOR_SIZE; + io_bytes_acct =3D mirror_do_read(s, sector_num * BDRV_SECTOR_S= IZE, + io_sectors * BDRV_SECTOR_SIZE); + io_sectors =3D io_bytes_acct / BDRV_SECTOR_SIZE; break; case MIRROR_METHOD_ZERO: case MIRROR_METHOD_DISCARD: --=20 1.8.3.1 From nobody Wed Apr 16 07:35:55 2025 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.zohomail.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 1499449122143360.5330944223997; Fri, 7 Jul 2017 10:38:42 -0700 (PDT) Received: from localhost ([::1]:57853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXDD-0005am-Q2 for importer@patchew.org; Fri, 07 Jul 2017 13:38:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlR-0005IJ-H9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlM-00088V-Kw for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlI-000830-Ui; Fri, 07 Jul 2017 13:09:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0F978B11B; Fri, 7 Jul 2017 17:09:47 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0DAF961F52; Fri, 7 Jul 2017 17:09:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F0F978B11B Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F0F978B11B From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:47 +0200 Message-Id: <1499447335-6125-33-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:09:48 +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] [PULL 032/100] mirror: Switch mirror_iteration() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of mirroring to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are both sector-aligned and multiples of the granularity). Drop the now-unused mirror_clip_sectors(). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 105 +++++++++++++++++++++++++----------------------------= ---- 1 file changed, 46 insertions(+), 59 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 262fddf..b33f4bb 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -184,15 +184,6 @@ static inline int64_t mirror_clip_bytes(MirrorBlockJob= *s, return MIN(bytes, s->bdev_length - offset); } =20 -/* Clip nb_sectors relative to sector_num to not exceed end-of-file */ -static inline int mirror_clip_sectors(MirrorBlockJob *s, - int64_t sector_num, - int nb_sectors) -{ - return MIN(nb_sectors, - s->bdev_length / BDRV_SECTOR_SIZE - sector_num); -} - /* Round offset and/or bytes to target cluster if COW is needed, and * return the offset of the adjusted tail against original. */ static int mirror_cow_align(MirrorBlockJob *s, int64_t *offset, @@ -336,30 +327,28 @@ static void mirror_do_zero_or_discard(MirrorBlockJob = *s, static uint64_t coroutine_fn mirror_iteration(MirrorBlockJob *s) { BlockDriverState *source =3D s->source; - int64_t sector_num, first_chunk; + int64_t offset, first_chunk; uint64_t delay_ns =3D 0; /* At least the first dirty chunk is mirrored in one iteration. */ int nb_chunks =3D 1; - int64_t end =3D s->bdev_length / BDRV_SECTOR_SIZE; int sectors_per_chunk =3D s->granularity >> BDRV_SECTOR_BITS; bool write_zeroes_ok =3D bdrv_can_write_zeroes_with_unmap(blk_bs(s->ta= rget)); int max_io_bytes =3D MAX(s->buf_size / MAX_IN_FLIGHT, MAX_IO_BYTES); =20 bdrv_dirty_bitmap_lock(s->dirty_bitmap); - sector_num =3D bdrv_dirty_iter_next(s->dbi); - if (sector_num < 0) { + offset =3D bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; + if (offset < 0) { bdrv_set_dirty_iter(s->dbi, 0); - sector_num =3D bdrv_dirty_iter_next(s->dbi); + offset =3D bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; trace_mirror_restart_iter(s, bdrv_get_dirty_count(s->dirty_bitmap)= * BDRV_SECTOR_SIZE); - assert(sector_num >=3D 0); + assert(offset >=3D 0); } bdrv_dirty_bitmap_unlock(s->dirty_bitmap); =20 - first_chunk =3D sector_num / sectors_per_chunk; + first_chunk =3D offset / s->granularity; while (test_bit(first_chunk, s->in_flight_bitmap)) { - trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE, - s->in_flight); + trace_mirror_yield_in_flight(s, offset, s->in_flight); mirror_wait_for_io(s); } =20 @@ -368,25 +357,26 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) /* Find the number of consective dirty chunks following the first dirty * one, and wait for in flight requests in them. */ bdrv_dirty_bitmap_lock(s->dirty_bitmap); - while (nb_chunks * sectors_per_chunk < (s->buf_size >> BDRV_SECTOR_BIT= S)) { + while (nb_chunks * s->granularity < s->buf_size) { int64_t next_dirty; - int64_t next_sector =3D sector_num + nb_chunks * sectors_per_chunk; - int64_t next_chunk =3D next_sector / sectors_per_chunk; - if (next_sector >=3D end || - !bdrv_get_dirty_locked(source, s->dirty_bitmap, next_sector)) { + int64_t next_offset =3D offset + nb_chunks * s->granularity; + int64_t next_chunk =3D next_offset / s->granularity; + if (next_offset >=3D s->bdev_length || + !bdrv_get_dirty_locked(source, s->dirty_bitmap, + next_offset >> BDRV_SECTOR_BITS)) { break; } if (test_bit(next_chunk, s->in_flight_bitmap)) { break; } =20 - next_dirty =3D bdrv_dirty_iter_next(s->dbi); - if (next_dirty > next_sector || next_dirty < 0) { + next_dirty =3D bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; + if (next_dirty > next_offset || next_dirty < 0) { /* The bitmap iterator's cache is stale, refresh it */ - bdrv_set_dirty_iter(s->dbi, next_sector); - next_dirty =3D bdrv_dirty_iter_next(s->dbi); + bdrv_set_dirty_iter(s->dbi, next_offset >> BDRV_SECTOR_BITS); + next_dirty =3D bdrv_dirty_iter_next(s->dbi) * BDRV_SECTOR_SIZE; } - assert(next_dirty =3D=3D next_sector); + assert(next_dirty =3D=3D next_offset); nb_chunks++; } =20 @@ -394,14 +384,15 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) * calling bdrv_get_block_status_above could yield - if some blocks are * marked dirty in this window, we need to know. */ - bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, sector_num, - nb_chunks * sectors_per_chunk); + bdrv_reset_dirty_bitmap_locked(s->dirty_bitmap, offset >> BDRV_SECTOR_= BITS, + nb_chunks * sectors_per_chunk); bdrv_dirty_bitmap_unlock(s->dirty_bitmap); =20 - bitmap_set(s->in_flight_bitmap, sector_num / sectors_per_chunk, nb_chu= nks); - while (nb_chunks > 0 && sector_num < end) { + bitmap_set(s->in_flight_bitmap, offset / s->granularity, nb_chunks); + while (nb_chunks > 0 && offset < s->bdev_length) { int64_t ret; int io_sectors; + unsigned int io_bytes; int64_t io_bytes_acct; BlockDriverState *file; enum MirrorMethod { @@ -410,28 +401,28 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) MIRROR_METHOD_DISCARD } mirror_method =3D MIRROR_METHOD_COPY; =20 - assert(!(sector_num % sectors_per_chunk)); - ret =3D bdrv_get_block_status_above(source, NULL, sector_num, + assert(!(offset % s->granularity)); + ret =3D bdrv_get_block_status_above(source, NULL, + offset >> BDRV_SECTOR_BITS, nb_chunks * sectors_per_chunk, &io_sectors, &file); + io_bytes =3D io_sectors * BDRV_SECTOR_SIZE; if (ret < 0) { - io_sectors =3D MIN(nb_chunks * sectors_per_chunk, - max_io_bytes >> BDRV_SECTOR_BITS); + io_bytes =3D MIN(nb_chunks * s->granularity, max_io_bytes); } else if (ret & BDRV_BLOCK_DATA) { - io_sectors =3D MIN(io_sectors, max_io_bytes >> BDRV_SECTOR_BIT= S); + io_bytes =3D MIN(io_bytes, max_io_bytes); } =20 - io_sectors -=3D io_sectors % sectors_per_chunk; - if (io_sectors < sectors_per_chunk) { - io_sectors =3D sectors_per_chunk; + io_bytes -=3D io_bytes % s->granularity; + if (io_bytes < s->granularity) { + io_bytes =3D s->granularity; } else if (ret >=3D 0 && !(ret & BDRV_BLOCK_DATA)) { - int64_t target_sector_num; - int target_nb_sectors; - bdrv_round_sectors_to_clusters(blk_bs(s->target), sector_num, - io_sectors, &target_sector_num, - &target_nb_sectors); - if (target_sector_num =3D=3D sector_num && - target_nb_sectors =3D=3D io_sectors) { + int64_t target_offset; + unsigned int target_bytes; + bdrv_round_to_clusters(blk_bs(s->target), offset, io_bytes, + &target_offset, &target_bytes); + if (target_offset =3D=3D offset && + target_bytes =3D=3D io_bytes) { mirror_method =3D ret & BDRV_BLOCK_ZERO ? MIRROR_METHOD_ZERO : MIRROR_METHOD_DISCARD; @@ -439,8 +430,7 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBlo= ckJob *s) } =20 while (s->in_flight >=3D MAX_IN_FLIGHT) { - trace_mirror_yield_in_flight(s, sector_num * BDRV_SECTOR_SIZE, - s->in_flight); + trace_mirror_yield_in_flight(s, offset, s->in_flight); mirror_wait_for_io(s); } =20 @@ -448,30 +438,27 @@ static uint64_t coroutine_fn mirror_iteration(MirrorB= lockJob *s) return 0; } =20 - io_sectors =3D mirror_clip_sectors(s, sector_num, io_sectors); + io_bytes =3D mirror_clip_bytes(s, offset, io_bytes); switch (mirror_method) { case MIRROR_METHOD_COPY: - io_bytes_acct =3D mirror_do_read(s, sector_num * BDRV_SECTOR_S= IZE, - io_sectors * BDRV_SECTOR_SIZE); - io_sectors =3D io_bytes_acct / BDRV_SECTOR_SIZE; + io_bytes =3D io_bytes_acct =3D mirror_do_read(s, offset, io_by= tes); break; case MIRROR_METHOD_ZERO: case MIRROR_METHOD_DISCARD: - mirror_do_zero_or_discard(s, sector_num * BDRV_SECTOR_SIZE, - io_sectors * BDRV_SECTOR_SIZE, + mirror_do_zero_or_discard(s, offset, io_bytes, mirror_method =3D=3D MIRROR_METHOD_D= ISCARD); if (write_zeroes_ok) { io_bytes_acct =3D 0; } else { - io_bytes_acct =3D io_sectors * BDRV_SECTOR_SIZE; + io_bytes_acct =3D io_bytes; } break; default: abort(); } - assert(io_sectors); - sector_num +=3D io_sectors; - nb_chunks -=3D DIV_ROUND_UP(io_sectors, sectors_per_chunk); + assert(io_bytes); + offset +=3D io_bytes; + nb_chunks -=3D DIV_ROUND_UP(io_bytes, s->granularity); if (s->common.speed) { delay_ns =3D ratelimit_calculate_delay(&s->limit, io_bytes_acc= t); } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449268599963.6140175605066; Fri, 7 Jul 2017 10:41:08 -0700 (PDT) Received: from localhost ([::1]:57867 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXFb-00087a-7M for importer@patchew.org; Fri, 07 Jul 2017 13:41:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41988) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlR-0005IK-HC for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlM-00088K-Gj for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52872) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlK-00084r-5J; Fri, 07 Jul 2017 13:09:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2ABB181236; Fri, 7 Jul 2017 17:09:49 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42AC461F23; Fri, 7 Jul 2017 17:09:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2ABB181236 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2ABB181236 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:48 +0200 Message-Id: <1499447335-6125-34-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:09:49 +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] [PULL 033/100] block: Drop unused bdrv_round_sectors_to_clusters() 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-devel@nongnu.org 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" From: Eric Blake Now that the last user [mirror_iteration()] has converted to using bytes, we no longer need a function to round sectors to clusters. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/io.c | 21 --------------------- include/block/block.h | 4 ---- 2 files changed, 25 deletions(-) diff --git a/block/io.c b/block/io.c index 5c146b5..a0a36df 100644 --- a/block/io.c +++ b/block/io.c @@ -419,27 +419,6 @@ static void mark_request_serialising(BdrvTrackedReques= t *req, uint64_t align) } =20 /** - * Round a region to cluster boundaries (sector-based) - */ -void bdrv_round_sectors_to_clusters(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - int64_t *cluster_sector_num, - int *cluster_nb_sectors) -{ - BlockDriverInfo bdi; - - if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size =3D=3D 0) { - *cluster_sector_num =3D sector_num; - *cluster_nb_sectors =3D nb_sectors; - } else { - int64_t c =3D bdi.cluster_size / BDRV_SECTOR_SIZE; - *cluster_sector_num =3D QEMU_ALIGN_DOWN(sector_num, c); - *cluster_nb_sectors =3D QEMU_ALIGN_UP(sector_num - *cluster_sector= _num + - nb_sectors, c); - } -} - -/** * Round a region to cluster boundaries */ void bdrv_round_to_clusters(BlockDriverState *bs, diff --git a/include/block/block.h b/include/block/block.h index afe1b61..121f42b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -475,10 +475,6 @@ const char *bdrv_get_device_or_node_name(const BlockDr= iverState *bs); int bdrv_get_flags(BlockDriverState *bs); int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs); -void bdrv_round_sectors_to_clusters(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - int64_t *cluster_sector_num, - int *cluster_nb_sectors); void bdrv_round_to_clusters(BlockDriverState *bs, int64_t offset, unsigned int bytes, int64_t *cluster_offset, --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499448868427423.86762025522467; Fri, 7 Jul 2017 10:34:28 -0700 (PDT) Received: from localhost ([::1]:57827 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX97-00029D-V2 for importer@patchew.org; Fri, 07 Jul 2017 13:34:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42034) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlT-0005K7-Dx for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlS-0008CO-2l for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54194) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlL-00086F-At; Fri, 07 Jul 2017 13:09:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5DE663680F; Fri, 7 Jul 2017 17:09:50 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74E2B61F23; Fri, 7 Jul 2017 17:09:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5DE663680F Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5DE663680F From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:49 +0200 Message-Id: <1499447335-6125-35-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:09:50 +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] [PULL 034/100] backup: Switch BackupBlockJob to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Continue by converting an internal structure (no semantic change), and all references to tracking progress. Drop a redundant local variable bytes_per_cluster. Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/block/backup.c b/block/backup.c index 06431ac..4e64710 100644 --- a/block/backup.c +++ b/block/backup.c @@ -39,7 +39,7 @@ typedef struct BackupBlockJob { BlockdevOnError on_source_error; BlockdevOnError on_target_error; CoRwlock flush_rwlock; - uint64_t sectors_read; + uint64_t bytes_read; unsigned long *done_bitmap; int64_t cluster_size; bool compress; @@ -102,16 +102,15 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, void *bounce_buffer =3D NULL; int ret =3D 0; int64_t sectors_per_cluster =3D cluster_size_sectors(job); - int64_t bytes_per_cluster =3D sectors_per_cluster * BDRV_SECTOR_SIZE; - int64_t start, end; - int n; + int64_t start, end; /* clusters */ + int n; /* bytes */ =20 qemu_co_rwlock_rdlock(&job->flush_rwlock); =20 start =3D sector_num / sectors_per_cluster; end =3D DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); =20 - trace_backup_do_cow_enter(job, start * bytes_per_cluster, + trace_backup_do_cow_enter(job, start * job->cluster_size, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); =20 @@ -120,28 +119,27 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, =20 for (; start < end; start++) { if (test_bit(start, job->done_bitmap)) { - trace_backup_do_cow_skip(job, start * bytes_per_cluster); + trace_backup_do_cow_skip(job, start * job->cluster_size); continue; /* already copied */ } =20 - trace_backup_do_cow_process(job, start * bytes_per_cluster); + trace_backup_do_cow_process(job, start * job->cluster_size); =20 - n =3D MIN(sectors_per_cluster, - job->common.len / BDRV_SECTOR_SIZE - - start * sectors_per_cluster); + n =3D MIN(job->cluster_size, + job->common.len - start * job->cluster_size); =20 if (!bounce_buffer) { bounce_buffer =3D blk_blockalign(blk, job->cluster_size); } iov.iov_base =3D bounce_buffer; - iov.iov_len =3D n * BDRV_SECTOR_SIZE; + iov.iov_len =3D n; qemu_iovec_init_external(&bounce_qiov, &iov, 1); =20 ret =3D blk_co_preadv(blk, start * job->cluster_size, bounce_qiov.size, &bounce_qiov, is_write_notifier ? BDRV_REQ_NO_SERIALISING : = 0); if (ret < 0) { - trace_backup_do_cow_read_fail(job, start * bytes_per_cluster, = ret); + trace_backup_do_cow_read_fail(job, start * job->cluster_size, = ret); if (error_is_read) { *error_is_read =3D true; } @@ -157,7 +155,7 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, job->compress ? BDRV_REQ_WRITE_COMPRESSED= : 0); } if (ret < 0) { - trace_backup_do_cow_write_fail(job, start * bytes_per_cluster,= ret); + trace_backup_do_cow_write_fail(job, start * job->cluster_size,= ret); if (error_is_read) { *error_is_read =3D false; } @@ -169,8 +167,8 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *j= ob, /* Publish progress, guest I/O counts as progress too. Note that = the * offset field is an opaque progress value, it is not a disk offs= et. */ - job->sectors_read +=3D n; - job->common.offset +=3D n * BDRV_SECTOR_SIZE; + job->bytes_read +=3D n; + job->common.offset +=3D n; } =20 out: @@ -363,9 +361,8 @@ static bool coroutine_fn yield_and_check(BackupBlockJob= *job) */ if (job->common.speed) { uint64_t delay_ns =3D ratelimit_calculate_delay(&job->limit, - job->sectors_read * - BDRV_SECTOR_SIZE); - job->sectors_read =3D 0; + job->bytes_read); + job->bytes_read =3D 0; block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, delay_ns); } else { block_job_sleep_ns(&job->common, QEMU_CLOCK_REALTIME, 0); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449025015446.53225722949514; Fri, 7 Jul 2017 10:37:05 -0700 (PDT) Received: from localhost ([::1]:57842 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXBf-0004JM-Ol for importer@patchew.org; Fri, 07 Jul 2017 13:37:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlU-0005LN-H9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlT-0008De-6l for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57360) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlN-00088D-3G; Fri, 07 Jul 2017 13:09:53 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 293D0C00108D; Fri, 7 Jul 2017 17:09:52 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8EE161F52; Fri, 7 Jul 2017 17:09:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 293D0C00108D 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 293D0C00108D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:50 +0200 Message-Id: <1499447335-6125-36-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:09:52 +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] [PULL 035/100] backup: Switch block_backup.h to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Continue by converting the public interface to backup jobs (no semantic change), including a change to CowRequest to track by bytes instead of cluster indices. Note that this does not change the difference between the public interface (starting point, and size of the subsequent range) and the internal interface (starting and end points). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Xie Changlong Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 31 +++++++++++++++---------------- block/replication.c | 12 ++++++++---- include/block/block_backup.h | 11 +++++------ 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/block/backup.c b/block/backup.c index 4e64710..503fbec 100644 --- a/block/backup.c +++ b/block/backup.c @@ -64,7 +64,7 @@ static void coroutine_fn wait_for_overlapping_requests(Ba= ckupBlockJob *job, do { retry =3D false; QLIST_FOREACH(req, &job->inflight_reqs, list) { - if (end > req->start && start < req->end) { + if (end > req->start_byte && start < req->end_byte) { qemu_co_queue_wait(&req->wait_queue, NULL); retry =3D true; break; @@ -75,10 +75,10 @@ static void coroutine_fn wait_for_overlapping_requests(= BackupBlockJob *job, =20 /* Keep track of an in-flight request */ static void cow_request_begin(CowRequest *req, BackupBlockJob *job, - int64_t start, int64_t end) + int64_t start, int64_t end) { - req->start =3D start; - req->end =3D end; + req->start_byte =3D start; + req->end_byte =3D end; qemu_co_queue_init(&req->wait_queue); QLIST_INSERT_HEAD(&job->inflight_reqs, req, list); } @@ -114,8 +114,10 @@ static int coroutine_fn backup_do_cow(BackupBlockJob *= job, sector_num * BDRV_SECTOR_SIZE, nb_sectors * BDRV_SECTOR_SIZE); =20 - wait_for_overlapping_requests(job, start, end); - cow_request_begin(&cow_request, job, start, end); + wait_for_overlapping_requests(job, start * job->cluster_size, + end * job->cluster_size); + cow_request_begin(&cow_request, job, start * job->cluster_size, + end * job->cluster_size); =20 for (; start < end; start++) { if (test_bit(start, job->done_bitmap)) { @@ -277,32 +279,29 @@ void backup_do_checkpoint(BlockJob *job, Error **errp) bitmap_zero(backup_job->done_bitmap, len); } =20 -void backup_wait_for_overlapping_requests(BlockJob *job, int64_t sector_nu= m, - int nb_sectors) +void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset, + uint64_t bytes) { BackupBlockJob *backup_job =3D container_of(job, BackupBlockJob, commo= n); - int64_t sectors_per_cluster =3D cluster_size_sectors(backup_job); int64_t start, end; =20 assert(job->driver->job_type =3D=3D BLOCK_JOB_TYPE_BACKUP); =20 - start =3D sector_num / sectors_per_cluster; - end =3D DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); + start =3D QEMU_ALIGN_DOWN(offset, backup_job->cluster_size); + end =3D QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size); wait_for_overlapping_requests(backup_job, start, end); } =20 void backup_cow_request_begin(CowRequest *req, BlockJob *job, - int64_t sector_num, - int nb_sectors) + int64_t offset, uint64_t bytes) { BackupBlockJob *backup_job =3D container_of(job, BackupBlockJob, commo= n); - int64_t sectors_per_cluster =3D cluster_size_sectors(backup_job); int64_t start, end; =20 assert(job->driver->job_type =3D=3D BLOCK_JOB_TYPE_BACKUP); =20 - start =3D sector_num / sectors_per_cluster; - end =3D DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); + start =3D QEMU_ALIGN_DOWN(offset, backup_job->cluster_size); + end =3D QEMU_ALIGN_UP(offset + bytes, backup_job->cluster_size); cow_request_begin(req, backup_job, start, end); } =20 diff --git a/block/replication.c b/block/replication.c index 3885f04..8f3aba7 100644 --- a/block/replication.c +++ b/block/replication.c @@ -234,10 +234,14 @@ static coroutine_fn int replication_co_readv(BlockDri= verState *bs, } =20 if (job) { - backup_wait_for_overlapping_requests(child->bs->job, sector_num, - remaining_sectors); - backup_cow_request_begin(&req, child->bs->job, sector_num, - remaining_sectors); + uint64_t remaining_bytes =3D remaining_sectors * BDRV_SECTOR_SIZE; + + backup_wait_for_overlapping_requests(child->bs->job, + sector_num * BDRV_SECTOR_SIZE, + remaining_bytes); + backup_cow_request_begin(&req, child->bs->job, + sector_num * BDRV_SECTOR_SIZE, + remaining_bytes); ret =3D bdrv_co_readv(bs->file, sector_num, remaining_sectors, qiov); backup_cow_request_end(&req); diff --git a/include/block/block_backup.h b/include/block/block_backup.h index 8a75947..994a3bd 100644 --- a/include/block/block_backup.h +++ b/include/block/block_backup.h @@ -21,17 +21,16 @@ #include "block/block_int.h" =20 typedef struct CowRequest { - int64_t start; - int64_t end; + int64_t start_byte; + int64_t end_byte; QLIST_ENTRY(CowRequest) list; CoQueue wait_queue; /* coroutines blocked on this request */ } CowRequest; =20 -void backup_wait_for_overlapping_requests(BlockJob *job, int64_t sector_nu= m, - int nb_sectors); +void backup_wait_for_overlapping_requests(BlockJob *job, int64_t offset, + uint64_t bytes); void backup_cow_request_begin(CowRequest *req, BlockJob *job, - int64_t sector_num, - int nb_sectors); + int64_t offset, uint64_t bytes); void backup_cow_request_end(CowRequest *req); =20 void backup_do_checkpoint(BlockJob *job, Error **errp); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449434324348.32395012375866; Fri, 7 Jul 2017 10:43:54 -0700 (PDT) Received: from localhost ([::1]:57886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXIG-00020f-R2 for importer@patchew.org; Fri, 07 Jul 2017 13:43:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlU-0005Lf-PE for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlT-0008Dy-9l for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlO-00089f-At; Fri, 07 Jul 2017 13:09:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5E87861E50; Fri, 7 Jul 2017 17:09:53 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7550061F23; Fri, 7 Jul 2017 17:09:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5E87861E50 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5E87861E50 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:51 +0200 Message-Id: <1499447335-6125-37-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:53 +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] [PULL 036/100] backup: Switch backup_do_cow() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Convert another internal function (no semantic change). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 62 ++++++++++++++++++++++++------------------------------= ---- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/block/backup.c b/block/backup.c index 503fbec..f7e14db 100644 --- a/block/backup.c +++ b/block/backup.c @@ -91,7 +91,7 @@ static void cow_request_end(CowRequest *req) } =20 static int coroutine_fn backup_do_cow(BackupBlockJob *job, - int64_t sector_num, int nb_sectors, + int64_t offset, uint64_t bytes, bool *error_is_read, bool is_write_notifier) { @@ -101,34 +101,28 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, QEMUIOVector bounce_qiov; void *bounce_buffer =3D NULL; int ret =3D 0; - int64_t sectors_per_cluster =3D cluster_size_sectors(job); - int64_t start, end; /* clusters */ + int64_t start, end; /* bytes */ int n; /* bytes */ =20 qemu_co_rwlock_rdlock(&job->flush_rwlock); =20 - start =3D sector_num / sectors_per_cluster; - end =3D DIV_ROUND_UP(sector_num + nb_sectors, sectors_per_cluster); + start =3D QEMU_ALIGN_DOWN(offset, job->cluster_size); + end =3D QEMU_ALIGN_UP(bytes + offset, job->cluster_size); =20 - trace_backup_do_cow_enter(job, start * job->cluster_size, - sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE); + trace_backup_do_cow_enter(job, start, offset, bytes); =20 - wait_for_overlapping_requests(job, start * job->cluster_size, - end * job->cluster_size); - cow_request_begin(&cow_request, job, start * job->cluster_size, - end * job->cluster_size); + wait_for_overlapping_requests(job, start, end); + cow_request_begin(&cow_request, job, start, end); =20 - for (; start < end; start++) { - if (test_bit(start, job->done_bitmap)) { - trace_backup_do_cow_skip(job, start * job->cluster_size); + for (; start < end; start +=3D job->cluster_size) { + if (test_bit(start / job->cluster_size, job->done_bitmap)) { + trace_backup_do_cow_skip(job, start); continue; /* already copied */ } =20 - trace_backup_do_cow_process(job, start * job->cluster_size); + trace_backup_do_cow_process(job, start); =20 - n =3D MIN(job->cluster_size, - job->common.len - start * job->cluster_size); + n =3D MIN(job->cluster_size, job->common.len - start); =20 if (!bounce_buffer) { bounce_buffer =3D blk_blockalign(blk, job->cluster_size); @@ -137,11 +131,10 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, iov.iov_len =3D n; qemu_iovec_init_external(&bounce_qiov, &iov, 1); =20 - ret =3D blk_co_preadv(blk, start * job->cluster_size, - bounce_qiov.size, &bounce_qiov, + ret =3D blk_co_preadv(blk, start, bounce_qiov.size, &bounce_qiov, is_write_notifier ? BDRV_REQ_NO_SERIALISING : = 0); if (ret < 0) { - trace_backup_do_cow_read_fail(job, start * job->cluster_size, = ret); + trace_backup_do_cow_read_fail(job, start, ret); if (error_is_read) { *error_is_read =3D true; } @@ -149,22 +142,22 @@ static int coroutine_fn backup_do_cow(BackupBlockJob = *job, } =20 if (buffer_is_zero(iov.iov_base, iov.iov_len)) { - ret =3D blk_co_pwrite_zeroes(job->target, start * job->cluster= _size, + ret =3D blk_co_pwrite_zeroes(job->target, start, bounce_qiov.size, BDRV_REQ_MAY_UNMA= P); } else { - ret =3D blk_co_pwritev(job->target, start * job->cluster_size, + ret =3D blk_co_pwritev(job->target, start, bounce_qiov.size, &bounce_qiov, job->compress ? BDRV_REQ_WRITE_COMPRESSED= : 0); } if (ret < 0) { - trace_backup_do_cow_write_fail(job, start * job->cluster_size,= ret); + trace_backup_do_cow_write_fail(job, start, ret); if (error_is_read) { *error_is_read =3D false; } goto out; } =20 - set_bit(start, job->done_bitmap); + set_bit(start / job->cluster_size, job->done_bitmap); =20 /* Publish progress, guest I/O counts as progress too. Note that = the * offset field is an opaque progress value, it is not a disk offs= et. @@ -180,8 +173,7 @@ out: =20 cow_request_end(&cow_request); =20 - trace_backup_do_cow_return(job, sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, ret); + trace_backup_do_cow_return(job, offset, bytes, ret); =20 qemu_co_rwlock_unlock(&job->flush_rwlock); =20 @@ -194,14 +186,12 @@ static int coroutine_fn backup_before_write_notify( { BackupBlockJob *job =3D container_of(notifier, BackupBlockJob, before_= write); BdrvTrackedRequest *req =3D opaque; - int64_t sector_num =3D req->offset >> BDRV_SECTOR_BITS; - int nb_sectors =3D req->bytes >> BDRV_SECTOR_BITS; =20 assert(req->bs =3D=3D blk_bs(job->common.blk)); - assert((req->offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); - assert((req->bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); + assert(QEMU_IS_ALIGNED(req->offset, BDRV_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(req->bytes, BDRV_SECTOR_SIZE)); =20 - return backup_do_cow(job, sector_num, nb_sectors, NULL, true); + return backup_do_cow(job, req->offset, req->bytes, NULL, true); } =20 static void backup_set_speed(BlockJob *job, int64_t speed, Error **errp) @@ -406,8 +396,8 @@ static int coroutine_fn backup_run_incremental(BackupBl= ockJob *job) if (yield_and_check(job)) { goto out; } - ret =3D backup_do_cow(job, cluster * sectors_per_cluster, - sectors_per_cluster, &error_is_read, + ret =3D backup_do_cow(job, cluster * job->cluster_size, + job->cluster_size, &error_is_read, false); if ((ret < 0) && backup_error_action(job, error_is_read, -ret) =3D=3D @@ -509,8 +499,8 @@ static void coroutine_fn backup_run(void *opaque) if (alloced < 0) { ret =3D alloced; } else { - ret =3D backup_do_cow(job, start * sectors_per_cluster, - sectors_per_cluster, &error_is_read, + ret =3D backup_do_cow(job, start * job->cluster_size, + job->cluster_size, &error_is_read, false); } if (ret < 0) { --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 14994492758861001.5760449290206; Fri, 7 Jul 2017 10:41:15 -0700 (PDT) Received: from localhost ([::1]:57869 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXFi-0008Dw-Js for importer@patchew.org; Fri, 07 Jul 2017 13:41:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlU-0005Ky-1h for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlS-0008DK-Rn for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:09:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56802) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlP-0008AS-Ju; Fri, 07 Jul 2017 13:09:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9AA728EB35; Fri, 7 Jul 2017 17:09:54 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9B6961F23; Fri, 7 Jul 2017 17:09:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9AA728EB35 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9AA728EB35 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:52 +0200 Message-Id: <1499447335-6125-38-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:54 +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] [PULL 037/100] backup: Switch backup_run() to byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually converting to byte-based interfaces, as they are easier to reason about than sector-based. Change the internal loop iteration of backups to track by bytes instead of sectors (although we are still guaranteed that we iterate by steps that are cluster-aligned). Signed-off-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Jeff Cody Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/backup.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/block/backup.c b/block/backup.c index f7e14db..2bd1d94 100644 --- a/block/backup.c +++ b/block/backup.c @@ -370,11 +370,10 @@ static int coroutine_fn backup_run_incremental(Backup= BlockJob *job) int ret =3D 0; int clusters_per_iter; uint32_t granularity; - int64_t sector; + int64_t offset; int64_t cluster; int64_t end; int64_t last_cluster =3D -1; - int64_t sectors_per_cluster =3D cluster_size_sectors(job); BdrvDirtyBitmapIter *dbi; =20 granularity =3D bdrv_dirty_bitmap_granularity(job->sync_bitmap); @@ -382,8 +381,8 @@ static int coroutine_fn backup_run_incremental(BackupBl= ockJob *job) dbi =3D bdrv_dirty_iter_new(job->sync_bitmap, 0); =20 /* Find the next dirty sector(s) */ - while ((sector =3D bdrv_dirty_iter_next(dbi)) !=3D -1) { - cluster =3D sector / sectors_per_cluster; + while ((offset =3D bdrv_dirty_iter_next(dbi) * BDRV_SECTOR_SIZE) >=3D = 0) { + cluster =3D offset / job->cluster_size; =20 /* Fake progress updates for any clusters we skipped */ if (cluster !=3D last_cluster + 1) { @@ -410,7 +409,8 @@ static int coroutine_fn backup_run_incremental(BackupBl= ockJob *job) /* If the bitmap granularity is smaller than the backup granularit= y, * we need to advance the iterator pointer to the next cluster. */ if (granularity < job->cluster_size) { - bdrv_set_dirty_iter(dbi, cluster * sectors_per_cluster); + bdrv_set_dirty_iter(dbi, + cluster * job->cluster_size / BDRV_SECTOR_= SIZE); } =20 last_cluster =3D cluster - 1; @@ -432,17 +432,15 @@ static void coroutine_fn backup_run(void *opaque) BackupBlockJob *job =3D opaque; BackupCompleteData *data; BlockDriverState *bs =3D blk_bs(job->common.blk); - int64_t start, end; + int64_t offset; int64_t sectors_per_cluster =3D cluster_size_sectors(job); int ret =3D 0; =20 QLIST_INIT(&job->inflight_reqs); qemu_co_rwlock_init(&job->flush_rwlock); =20 - start =3D 0; - end =3D DIV_ROUND_UP(job->common.len, job->cluster_size); - - job->done_bitmap =3D bitmap_new(end); + job->done_bitmap =3D bitmap_new(DIV_ROUND_UP(job->common.len, + job->cluster_size)); =20 job->before_write.notify =3D backup_before_write_notify; bdrv_add_before_write_notifier(bs, &job->before_write); @@ -457,7 +455,8 @@ static void coroutine_fn backup_run(void *opaque) ret =3D backup_run_incremental(job); } else { /* Both FULL and TOP SYNC_MODE's require copying.. */ - for (; start < end; start++) { + for (offset =3D 0; offset < job->common.len; + offset +=3D job->cluster_size) { bool error_is_read; int alloced =3D 0; =20 @@ -480,8 +479,8 @@ static void coroutine_fn backup_run(void *opaque) * needed but at some point that is always the case. */ alloced =3D bdrv_is_allocated(bs, - start * sectors_per_cluster + i, - sectors_per_cluster - i, &n); + (offset >> BDRV_SECTOR_BITS) + i, + sectors_per_cluster - i, &n); i +=3D n; =20 if (alloced || n =3D=3D 0) { @@ -499,9 +498,8 @@ static void coroutine_fn backup_run(void *opaque) if (alloced < 0) { ret =3D alloced; } else { - ret =3D backup_do_cow(job, start * job->cluster_size, - job->cluster_size, &error_is_read, - false); + ret =3D backup_do_cow(job, offset, job->cluster_size, + &error_is_read, false); } if (ret < 0) { /* Depending on error action, fail now or retry cluster */ @@ -510,7 +508,7 @@ static void coroutine_fn backup_run(void *opaque) if (action =3D=3D BLOCK_ERROR_ACTION_REPORT) { break; } else { - start--; + offset -=3D job->cluster_size; continue; } } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499448239887365.02952113362426; Fri, 7 Jul 2017 10:23:59 -0700 (PDT) Received: from localhost ([::1]:57769 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWz0-0000m1-FC for importer@patchew.org; Fri, 07 Jul 2017 13:23:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlc-0005U5-1o for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlW-0008KE-UE for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53016) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlQ-0008B1-Po; Fri, 07 Jul 2017 13:09:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2DC87F6B9; Fri, 7 Jul 2017 17:09:55 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E671561F23; Fri, 7 Jul 2017 17:09:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D2DC87F6B9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D2DC87F6B9 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:53 +0200 Message-Id: <1499447335-6125-39-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:09:56 +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] [PULL 038/100] block: Make bdrv_is_allocated() byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the signature of the function to use int64_t *pnum ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned on input and that *pnum is sector-aligned on return to the caller, but that can be relaxed when a later patch implements byte-based block status. Therefore, this code adds usages like DIV_ROUND_UP(,BDRV_SECTOR_SIZE) to callers that still want aligned values, where the call might reasonbly give non-aligned results in the future; on the other hand, no rounding is needed for callers that should just continue to work with byte alignment. For the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_is_allocated(). But some code, particularly bdrv_commit(), gets a lot simpler because it no longer has to mess with sectors; also, it is now possible to pass NULL if the caller does not care how much of the image is allocated beyond the initial offset. Leave comments where we can further simplify once a later patch eliminates the need for sector-aligned requests through bdrv_is_allocated(). For ease of review, bdrv_is_allocated_above() will be tackled separately. Signed-off-by: Eric Blake Signed-off-by: Kevin Wolf --- block/backup.c | 17 ++++--------- block/commit.c | 21 +++++++--------- block/io.c | 54 ++++++++++++++++++++++++++------------- block/stream.c | 7 ++++-- block/vvfat.c | 34 ++++++++++++++----------- include/block/block.h | 4 +-- migration/block.c | 16 +++++++----- qemu-img.c | 8 +++++- qemu-io-cmds.c | 70 +++++++++++++++++++++++------------------------= ---- 9 files changed, 126 insertions(+), 105 deletions(-) diff --git a/block/backup.c b/block/backup.c index 2bd1d94..b69184e 100644 --- a/block/backup.c +++ b/block/backup.c @@ -47,12 +47,6 @@ typedef struct BackupBlockJob { QLIST_HEAD(, CowRequest) inflight_reqs; } BackupBlockJob; =20 -/* Size of a cluster in sectors, instead of bytes. */ -static inline int64_t cluster_size_sectors(BackupBlockJob *job) -{ - return job->cluster_size / BDRV_SECTOR_SIZE; -} - /* See if in-flight requests overlap and wait for them to complete */ static void coroutine_fn wait_for_overlapping_requests(BackupBlockJob *job, int64_t start, @@ -433,7 +427,6 @@ static void coroutine_fn backup_run(void *opaque) BackupCompleteData *data; BlockDriverState *bs =3D blk_bs(job->common.blk); int64_t offset; - int64_t sectors_per_cluster =3D cluster_size_sectors(job); int ret =3D 0; =20 QLIST_INIT(&job->inflight_reqs); @@ -465,12 +458,13 @@ static void coroutine_fn backup_run(void *opaque) } =20 if (job->sync_mode =3D=3D MIRROR_SYNC_MODE_TOP) { - int i, n; + int i; + int64_t n; =20 /* Check to see if these blocks are already in the * backing file. */ =20 - for (i =3D 0; i < sectors_per_cluster;) { + for (i =3D 0; i < job->cluster_size;) { /* bdrv_is_allocated() only returns true/false based * on the first set of sectors it comes across that * are are all in the same state. @@ -478,9 +472,8 @@ static void coroutine_fn backup_run(void *opaque) * backup cluster length. We end up copying more than * needed but at some point that is always the case. */ alloced =3D - bdrv_is_allocated(bs, - (offset >> BDRV_SECTOR_BITS) + i, - sectors_per_cluster - i, &n); + bdrv_is_allocated(bs, offset + i, + job->cluster_size - i, &n); i +=3D n; =20 if (alloced || n =3D=3D 0) { diff --git a/block/commit.c b/block/commit.c index c3a7bca..241aa95 100644 --- a/block/commit.c +++ b/block/commit.c @@ -443,7 +443,7 @@ fail: } =20 =20 -#define COMMIT_BUF_SECTORS 2048 +#define COMMIT_BUF_SIZE (2048 * BDRV_SECTOR_SIZE) =20 /* commit COW file into the raw image */ int bdrv_commit(BlockDriverState *bs) @@ -452,8 +452,9 @@ int bdrv_commit(BlockDriverState *bs) BlockDriverState *backing_file_bs =3D NULL; BlockDriverState *commit_top_bs =3D NULL; BlockDriver *drv =3D bs->drv; - int64_t sector, total_sectors, length, backing_length; - int n, ro, open_flags; + int64_t offset, length, backing_length; + int ro, open_flags; + int64_t n; int ret =3D 0; uint8_t *buf =3D NULL; Error *local_err =3D NULL; @@ -531,30 +532,26 @@ int bdrv_commit(BlockDriverState *bs) } } =20 - total_sectors =3D length >> BDRV_SECTOR_BITS; - /* blk_try_blockalign() for src will choose an alignment that works for * backing as well, so no need to compare the alignment manually. */ - buf =3D blk_try_blockalign(src, COMMIT_BUF_SECTORS * BDRV_SECTOR_SIZE); + buf =3D blk_try_blockalign(src, COMMIT_BUF_SIZE); if (buf =3D=3D NULL) { ret =3D -ENOMEM; goto ro_cleanup; } =20 - for (sector =3D 0; sector < total_sectors; sector +=3D n) { - ret =3D bdrv_is_allocated(bs, sector, COMMIT_BUF_SECTORS, &n); + for (offset =3D 0; offset < length; offset +=3D n) { + ret =3D bdrv_is_allocated(bs, offset, COMMIT_BUF_SIZE, &n); if (ret < 0) { goto ro_cleanup; } if (ret) { - ret =3D blk_pread(src, sector * BDRV_SECTOR_SIZE, buf, - n * BDRV_SECTOR_SIZE); + ret =3D blk_pread(src, offset, buf, n); if (ret < 0) { goto ro_cleanup; } =20 - ret =3D blk_pwrite(backing, sector * BDRV_SECTOR_SIZE, buf, - n * BDRV_SECTOR_SIZE, 0); + ret =3D blk_pwrite(backing, offset, buf, n, 0); if (ret < 0) { goto ro_cleanup; } diff --git a/block/io.c b/block/io.c index a0a36df..6656d7f 100644 --- a/block/io.c +++ b/block/io.c @@ -1033,17 +1033,18 @@ static int coroutine_fn bdrv_aligned_preadv(BdrvChi= ld *child, } =20 if (flags & BDRV_REQ_COPY_ON_READ) { - int64_t start_sector =3D offset >> BDRV_SECTOR_BITS; - int64_t end_sector =3D DIV_ROUND_UP(offset + bytes, BDRV_SECTOR_SI= ZE); - unsigned int nb_sectors =3D end_sector - start_sector; - int pnum; + /* TODO: Simplify further once bdrv_is_allocated no longer + * requires sector alignment */ + int64_t start =3D QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE); + int64_t end =3D QEMU_ALIGN_UP(offset + bytes, BDRV_SECTOR_SIZE); + int64_t pnum; =20 - ret =3D bdrv_is_allocated(bs, start_sector, nb_sectors, &pnum); + ret =3D bdrv_is_allocated(bs, start, end - start, &pnum); if (ret < 0) { goto out; } =20 - if (!ret || pnum !=3D nb_sectors) { + if (!ret || pnum !=3D end - start) { ret =3D bdrv_co_do_copy_on_readv(child, offset, bytes, qiov); goto out; } @@ -1900,15 +1901,25 @@ int64_t bdrv_get_block_status(BlockDriverState *bs, sector_num, nb_sectors, pnum, file); } =20 -int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t sector_nu= m, - int nb_sectors, int *pnum) +int coroutine_fn bdrv_is_allocated(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum) { BlockDriverState *file; - int64_t ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, pnum, - &file); + int64_t sector_num =3D offset >> BDRV_SECTOR_BITS; + int nb_sectors =3D bytes >> BDRV_SECTOR_BITS; + int64_t ret; + int psectors; + + assert(QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)); + assert(QEMU_IS_ALIGNED(bytes, BDRV_SECTOR_SIZE) && bytes < INT_MAX); + ret =3D bdrv_get_block_status(bs, sector_num, nb_sectors, &psectors, + &file); if (ret < 0) { return ret; } + if (pnum) { + *pnum =3D psectors * BDRV_SECTOR_SIZE; + } return !!(ret & BDRV_BLOCK_ALLOCATED); } =20 @@ -1917,7 +1928,8 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState *= bs, int64_t sector_num, * * Return true if the given sector is allocated in any image between * BASE and TOP (inclusive). BASE can be NULL to check if the given - * sector is allocated in any image of the chain. Return false otherwise. + * sector is allocated in any image of the chain. Return false otherwise, + * or negative errno on failure. * * 'pnum' is set to the number of sectors (including and immediately follo= wing * the specified sector) that are known to be in the same @@ -1934,13 +1946,19 @@ int bdrv_is_allocated_above(BlockDriverState *top, =20 intermediate =3D top; while (intermediate && intermediate !=3D base) { - int pnum_inter; - ret =3D bdrv_is_allocated(intermediate, sector_num, nb_sectors, + int64_t pnum_inter; + int psectors_inter; + + ret =3D bdrv_is_allocated(intermediate, sector_num * BDRV_SECTOR_S= IZE, + nb_sectors * BDRV_SECTOR_SIZE, &pnum_inter); if (ret < 0) { return ret; - } else if (ret) { - *pnum =3D pnum_inter; + } + assert(pnum_inter < INT_MAX * BDRV_SECTOR_SIZE); + psectors_inter =3D pnum_inter >> BDRV_SECTOR_BITS; + if (ret) { + *pnum =3D psectors_inter; return 1; } =20 @@ -1950,10 +1968,10 @@ int bdrv_is_allocated_above(BlockDriverState *top, * * [sector_num+x, nr_sectors] allocated. */ - if (n > pnum_inter && + if (n > psectors_inter && (intermediate =3D=3D top || - sector_num + pnum_inter < intermediate->total_sectors)) { - n =3D pnum_inter; + sector_num + psectors_inter < intermediate->total_sectors)) { + n =3D psectors_inter; } =20 intermediate =3D backing_bs(intermediate); diff --git a/block/stream.c b/block/stream.c index e3dd2ac..df9679c 100644 --- a/block/stream.c +++ b/block/stream.c @@ -137,6 +137,7 @@ static void coroutine_fn stream_run(void *opaque) =20 for ( ; offset < s->common.len; offset +=3D n * BDRV_SECTOR_SIZE) { bool copy; + int64_t count =3D 0; =20 /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. @@ -148,8 +149,10 @@ static void coroutine_fn stream_run(void *opaque) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, offset / BDRV_SECTOR_SIZE, - STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); + ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &count); + /* TODO relax this once bdrv_is_allocated does not enforce sectors= */ + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { diff --git a/block/vvfat.c b/block/vvfat.c index f55104c..4fd28e1 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1482,24 +1482,27 @@ static int vvfat_read(BlockDriverState *bs, int64_t= sector_num, if (sector_num >=3D bs->total_sectors) return -1; if (s->qcow) { - int n; + int64_t n; int ret; - ret =3D bdrv_is_allocated(s->qcow->bs, sector_num, - nb_sectors - i, &n); + ret =3D bdrv_is_allocated(s->qcow->bs, sector_num * BDRV_SECTO= R_SIZE, + (nb_sectors - i) * BDRV_SECTOR_SIZE, &= n); if (ret < 0) { return ret; } if (ret) { - DLOG(fprintf(stderr, "sectors %d+%d allocated\n", - (int)sector_num, n)); - if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, n)) { + DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64 + " allocated\n", sector_num, + n >> BDRV_SECTOR_BITS)); + if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, + n >> BDRV_SECTOR_BITS)) { return -1; } - i +=3D n - 1; - sector_num +=3D n - 1; + i +=3D (n >> BDRV_SECTOR_BITS) - 1; + sector_num +=3D (n >> BDRV_SECTOR_BITS) - 1; continue; } -DLOG(fprintf(stderr, "sector %d not allocated\n", (int)sector_num)); + DLOG(fprintf(stderr, "sector %" PRId64 " not allocated\n", + sector_num)); } if (sector_num < s->offset_to_root_dir) { if (sector_num < s->offset_to_fat) { @@ -1779,7 +1782,7 @@ static inline bool cluster_was_modified(BDRVVVFATStat= e *s, uint32_t cluster_num) { int was_modified =3D 0; - int i, dummy; + int i; =20 if (s->qcow =3D=3D NULL) { return 0; @@ -1787,8 +1790,9 @@ static inline bool cluster_was_modified(BDRVVVFATStat= e *s, =20 for (i =3D 0; !was_modified && i < s->sectors_per_cluster; i++) { was_modified =3D bdrv_is_allocated(s->qcow->bs, - cluster2sector(s, cluster_num) + = i, - 1, &dummy); + (cluster2sector(s, cluster_num) + + i) * BDRV_SECTOR_SIZE, + BDRV_SECTOR_SIZE, NULL); } =20 /* @@ -1935,7 +1939,7 @@ static uint32_t get_cluster_count_for_direntry(BDRVVV= FATState* s, } =20 if (copy_it) { - int i, dummy; + int i; /* * This is horribly inefficient, but that is okay, since * it is rarely executed, if at all. @@ -1946,7 +1950,9 @@ static uint32_t get_cluster_count_for_direntry(BDRVVV= FATState* s, for (i =3D 0; i < s->sectors_per_cluster; i++) { int res; =20 - res =3D bdrv_is_allocated(s->qcow->bs, offset + i, 1, = &dummy); + res =3D bdrv_is_allocated(s->qcow->bs, + (offset + i) * BDRV_SECTOR_SIZ= E, + BDRV_SECTOR_SIZE, NULL); if (res < 0) { return -1; } diff --git a/include/block/block.h b/include/block/block.h index 121f42b..8d16cc1 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -427,8 +427,8 @@ int64_t bdrv_get_block_status_above(BlockDriverState *b= s, int64_t sector_num, int nb_sectors, int *pnum, BlockDriverState **file); -int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sec= tors, - int *pnum); +int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, + int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int64_t sector_num, int nb_sectors, int *pnum); =20 diff --git a/migration/block.c b/migration/block.c index 7674ae1..86c0b96 100644 --- a/migration/block.c +++ b/migration/block.c @@ -34,7 +34,7 @@ #define BLK_MIG_FLAG_PROGRESS 0x04 #define BLK_MIG_FLAG_ZERO_BLOCK 0x08 =20 -#define MAX_IS_ALLOCATED_SEARCH 65536 +#define MAX_IS_ALLOCATED_SEARCH (65536 * BDRV_SECTOR_SIZE) =20 #define MAX_INFLIGHT_IO 512 =20 @@ -267,16 +267,20 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDe= vState *bmds) BlockBackend *bb =3D bmds->blk; BlkMigBlock *blk; int nr_sectors; + int64_t count; =20 if (bmds->shared_base) { qemu_mutex_lock_iothread(); aio_context_acquire(blk_get_aio_context(bb)); - /* Skip unallocated sectors; intentionally treats failure as - * an allocated sector */ + /* Skip unallocated sectors; intentionally treats failure or + * partial sector as an allocated sector */ while (cur_sector < total_sectors && - !bdrv_is_allocated(blk_bs(bb), cur_sector, - MAX_IS_ALLOCATED_SEARCH, &nr_sectors)) { - cur_sector +=3D nr_sectors; + !bdrv_is_allocated(blk_bs(bb), cur_sector * BDRV_SECTOR_SIZ= E, + MAX_IS_ALLOCATED_SEARCH, &count)) { + if (count < BDRV_SECTOR_SIZE) { + break; + } + cur_sector +=3D count >> BDRV_SECTOR_BITS; } aio_context_release(blk_get_aio_context(bb)); qemu_mutex_unlock_iothread(); diff --git a/qemu-img.c b/qemu-img.c index c5f00db..86e2433 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3258,6 +3258,7 @@ static int img_rebase(int argc, char **argv) int64_t new_backing_num_sectors =3D 0; uint64_t sector; int n; + int64_t count; float local_progress =3D 0; =20 buf_old =3D blk_blockalign(blk, IO_BUF_SIZE); @@ -3305,12 +3306,17 @@ static int img_rebase(int argc, char **argv) } =20 /* If the cluster is allocated, we don't need to take action */ - ret =3D bdrv_is_allocated(bs, sector, n, &n); + ret =3D bdrv_is_allocated(bs, sector << BDRV_SECTOR_BITS, + n << BDRV_SECTOR_BITS, &count); if (ret < 0) { error_report("error while reading image metadata: %s", strerror(-ret)); goto out; } + /* TODO relax this once bdrv_is_allocated does not enforce + * sector alignment */ + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; if (ret) { continue; } diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index b0ea327..f4fdf2d 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -1760,12 +1760,12 @@ 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, count; + int64_t offset, start, remaining, count; char s1[64]; - int num, ret; - int64_t sum_alloc; + int ret; + int64_t num, sum_alloc; =20 - offset =3D cvtnum(argv[1]); + start =3D offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); return 0; @@ -1793,32 +1793,30 @@ static int alloc_f(BlockBackend *blk, int argc, cha= r **argv) count); return 0; } - nb_sectors =3D count >> BDRV_SECTOR_BITS; =20 - remaining =3D nb_sectors; + remaining =3D count; sum_alloc =3D 0; - sector_num =3D offset >> 9; while (remaining) { - ret =3D bdrv_is_allocated(bs, sector_num, remaining, &num); + ret =3D bdrv_is_allocated(bs, offset, remaining, &num); if (ret < 0) { printf("is_allocated failed: %s\n", strerror(-ret)); return 0; } - sector_num +=3D num; + offset +=3D num; remaining -=3D num; if (ret) { sum_alloc +=3D num; } if (num =3D=3D 0) { - nb_sectors -=3D remaining; + count -=3D remaining; remaining =3D 0; } } =20 - cvtstr(offset, s1, sizeof(s1)); + cvtstr(start, s1, sizeof(s1)); =20 printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n", - sum_alloc << BDRV_SECTOR_BITS, nb_sectors << BDRV_SECTOR_BITS, = s1); + sum_alloc, count, s1); return 0; } =20 @@ -1833,14 +1831,15 @@ static const cmdinfo_t alloc_cmd =3D { }; =20 =20 -static int map_is_allocated(BlockDriverState *bs, int64_t sector_num, - int64_t nb_sectors, int64_t *pnum) +static int map_is_allocated(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum) { - int num, num_checked; + int64_t num; + int num_checked; int ret, firstret; =20 - num_checked =3D MIN(nb_sectors, INT_MAX); - ret =3D bdrv_is_allocated(bs, sector_num, num_checked, &num); + num_checked =3D MIN(bytes, BDRV_REQUEST_MAX_BYTES); + ret =3D bdrv_is_allocated(bs, offset, num_checked, &num); if (ret < 0) { return ret; } @@ -1848,12 +1847,12 @@ static int map_is_allocated(BlockDriverState *bs, i= nt64_t sector_num, firstret =3D ret; *pnum =3D num; =20 - while (nb_sectors > 0 && ret =3D=3D firstret) { - sector_num +=3D num; - nb_sectors -=3D num; + while (bytes > 0 && ret =3D=3D firstret) { + offset +=3D num; + bytes -=3D num; =20 - num_checked =3D MIN(nb_sectors, INT_MAX); - ret =3D bdrv_is_allocated(bs, sector_num, num_checked, &num); + num_checked =3D MIN(bytes, BDRV_REQUEST_MAX_BYTES); + ret =3D bdrv_is_allocated(bs, offset, num_checked, &num); if (ret =3D=3D firstret && num) { *pnum +=3D num; } else { @@ -1866,25 +1865,21 @@ static int map_is_allocated(BlockDriverState *bs, i= nt64_t sector_num, =20 static int map_f(BlockBackend *blk, int argc, char **argv) { - int64_t offset; - int64_t nb_sectors, total_sectors; + int64_t offset, bytes; char s1[64], s2[64]; int64_t num; int ret; const char *retstr; =20 offset =3D 0; - total_sectors =3D blk_nb_sectors(blk); - if (total_sectors < 0) { - error_report("Failed to query image length: %s", - strerror(-total_sectors)); + bytes =3D blk_getlength(blk); + if (bytes < 0) { + error_report("Failed to query image length: %s", strerror(-bytes)); return 0; } =20 - nb_sectors =3D total_sectors; - - do { - ret =3D map_is_allocated(blk_bs(blk), offset, nb_sectors, &num); + while (bytes) { + ret =3D map_is_allocated(blk_bs(blk), offset, bytes, &num); if (ret < 0) { error_report("Failed to get allocation status: %s", strerror(-= ret)); return 0; @@ -1894,15 +1889,14 @@ static int map_f(BlockBackend *blk, int argc, char = **argv) } =20 retstr =3D ret ? " allocated" : "not allocated"; - cvtstr(num << BDRV_SECTOR_BITS, s1, sizeof(s1)); - cvtstr(offset << BDRV_SECTOR_BITS, s2, sizeof(s2)); + cvtstr(num, s1, sizeof(s1)); + cvtstr(offset, s2, sizeof(s2)); printf("%s (0x%" PRIx64 ") bytes %s at offset %s (0x%" PRIx64 ")\n= ", - s1, num << BDRV_SECTOR_BITS, retstr, - s2, offset << BDRV_SECTOR_BITS); + s1, num, retstr, s2, offset); =20 offset +=3D num; - nb_sectors -=3D num; - } while (offset < total_sectors); + bytes -=3D num; + } =20 return 0; } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499448083154418.4130538268862; Fri, 7 Jul 2017 10:21:23 -0700 (PDT) Received: from localhost ([::1]:57751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWwT-00070O-Sc for importer@patchew.org; Fri, 07 Jul 2017 13:21:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlW-0005NV-1L for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlV-0008GI-2Y for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56848) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlS-0008Bo-4N; Fri, 07 Jul 2017 13:09:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 28C57A4FB7; Fri, 7 Jul 2017 17:09:57 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2AA8461F23; Fri, 7 Jul 2017 17:09:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 28C57A4FB7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 28C57A4FB7 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:54 +0200 Message-Id: <1499447335-6125-40-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:57 +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] [PULL 039/100] block: Minimize raw use of bds->total_sectors 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-devel@nongnu.org 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" From: Eric Blake bdrv_is_allocated_above() was relying on intermediate->total_sectors, which is a field that can have stale contents depending on the value of intermediate->has_variable_length. An audit shows that we are safe (we were first calling through bdrv_co_get_block_status() which in turn calls bdrv_nb_sectors() and therefore just refreshed the current length), but it's nicer to favor our accessor functions to avoid having to repeat such an audit, even if it means refresh_total_sectors() is called more frequently. Suggested-by: John Snow Signed-off-by: Eric Blake Reviewed-by: Manos Pitsidianakis Reviewed-by: Jeff Cody Reviewed-by: John Snow Signed-off-by: Kevin Wolf --- block/io.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/block/io.c b/block/io.c index 6656d7f..aad7fd3 100644 --- a/block/io.c +++ b/block/io.c @@ -1947,6 +1947,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, intermediate =3D top; while (intermediate && intermediate !=3D base) { int64_t pnum_inter; + int64_t size_inter; int psectors_inter; =20 ret =3D bdrv_is_allocated(intermediate, sector_num * BDRV_SECTOR_S= IZE, @@ -1962,15 +1963,12 @@ int bdrv_is_allocated_above(BlockDriverState *top, return 1; } =20 - /* - * [sector_num, nb_sectors] is unallocated on top but intermediate - * might have - * - * [sector_num+x, nr_sectors] allocated. - */ + size_inter =3D bdrv_nb_sectors(intermediate); + if (size_inter < 0) { + return size_inter; + } if (n > psectors_inter && - (intermediate =3D=3D top || - sector_num + psectors_inter < intermediate->total_sectors)) { + (intermediate =3D=3D top || sector_num + psectors_inter < size= _inter)) { n =3D psectors_inter; } =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449606788954.2115394193879; Fri, 7 Jul 2017 10:46:46 -0700 (PDT) Received: from localhost ([::1]:57905 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXL3-0004jI-GL for importer@patchew.org; Fri, 07 Jul 2017 13:46:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42203) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlc-0005U0-0m for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlX-0008Kz-Uu for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlT-0008DC-9g; Fri, 07 Jul 2017 13:09:59 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5EA8D74864; Fri, 7 Jul 2017 17:09:58 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 73F8561F23; Fri, 7 Jul 2017 17:09:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5EA8D74864 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5EA8D74864 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:55 +0200 Message-Id: <1499447335-6125-41-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:09:58 +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] [PULL 040/100] block: Make bdrv_is_allocated_above() byte-based 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-devel@nongnu.org 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" From: Eric Blake We are gradually moving away from sector-based interfaces, towards byte-based. In the common case, allocation is unlikely to ever use values that are not naturally sector-aligned, but it is possible that byte-based values will let us be more precise about allocation at the end of an unaligned file that can do byte-based access. Changing the signature of the function to use int64_t *pnum ensures that the compiler enforces that all callers are updated. For now, the io.c layer still assert()s that all callers are sector-aligned, but that can be relaxed when a later patch implements byte-based block status. Therefore, for the most part this patch is just the addition of scaling at the callers followed by inverse scaling at bdrv_is_allocated(). But some code, particularly stream_run(), gets a lot simpler because it no longer has to mess with sectors. Leave comments where we can further simplify by switching to byte-based iterations, once later patches eliminate the need for sector-aligned operations. For ease of review, bdrv_is_allocated() was tackled separately. Signed-off-by: Eric Blake Signed-off-by: Kevin Wolf --- block/commit.c | 20 ++++++++------------ block/io.c | 38 ++++++++++++++++++-------------------- block/mirror.c | 8 +++++++- block/replication.c | 17 ++++++++++++----- block/stream.c | 23 +++++++++-------------- include/block/block.h | 2 +- qemu-img.c | 13 ++++++++++--- 7 files changed, 65 insertions(+), 56 deletions(-) diff --git a/block/commit.c b/block/commit.c index 241aa95..774a8a5 100644 --- a/block/commit.c +++ b/block/commit.c @@ -146,7 +146,7 @@ static void coroutine_fn commit_run(void *opaque) int64_t offset; uint64_t delay_ns =3D 0; int ret =3D 0; - int n =3D 0; /* sectors */ + int64_t n =3D 0; /* bytes */ void *buf =3D NULL; int bytes_written =3D 0; int64_t base_len; @@ -171,7 +171,7 @@ static void coroutine_fn commit_run(void *opaque) =20 buf =3D blk_blockalign(s->top, COMMIT_BUFFER_SIZE); =20 - for (offset =3D 0; offset < s->common.len; offset +=3D n * BDRV_SECTOR= _SIZE) { + for (offset =3D 0; offset < s->common.len; offset +=3D n) { bool copy; =20 /* Note that even when no rate limit is applied we need to yield @@ -183,15 +183,12 @@ static void coroutine_fn commit_run(void *opaque) } /* Copy if allocated above the base */ ret =3D bdrv_is_allocated_above(blk_bs(s->top), blk_bs(s->base), - offset / BDRV_SECTOR_SIZE, - COMMIT_BUFFER_SIZE / BDRV_SECTOR_SIZ= E, - &n); + offset, COMMIT_BUFFER_SIZE, &n); copy =3D (ret =3D=3D 1); - trace_commit_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret); + trace_commit_one_iteration(s, offset, n, ret); if (copy) { - ret =3D commit_populate(s->top, s->base, offset, - n * BDRV_SECTOR_SIZE, buf); - bytes_written +=3D n * BDRV_SECTOR_SIZE; + ret =3D commit_populate(s->top, s->base, offset, n, buf); + bytes_written +=3D n; } if (ret < 0) { BlockErrorAction action =3D @@ -204,11 +201,10 @@ static void coroutine_fn commit_run(void *opaque) } } /* Publish progress */ - s->common.offset +=3D n * BDRV_SECTOR_SIZE; + s->common.offset +=3D n; =20 if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, - n * BDRV_SECTOR_SIZE); + delay_ns =3D ratelimit_calculate_delay(&s->limit, n); } } =20 diff --git a/block/io.c b/block/io.c index aad7fd3..23170a5 100644 --- a/block/io.c +++ b/block/io.c @@ -1926,50 +1926,48 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState= *bs, int64_t offset, /* * Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP] * - * Return true if the given sector is allocated in any image between - * BASE and TOP (inclusive). BASE can be NULL to check if the given - * sector is allocated in any image of the chain. Return false otherwise, + * Return true if (a prefix of) the given range is allocated in any image + * between BASE and TOP (inclusive). BASE can be NULL to check if the giv= en + * offset is allocated in any image of the chain. Return false otherwise, * or negative errno on failure. * - * 'pnum' is set to the number of sectors (including and immediately follo= wing - * the specified sector) that are known to be in the same - * allocated/unallocated state. + * 'pnum' is set to the number of bytes (including and immediately + * following the specified offset) that are known to be in the same + * allocated/unallocated state. Note that a subsequent call starting + * at 'offset + *pnum' may return the same allocation status (in other + * words, the result is not necessarily the maximum possible range); + * but 'pnum' will only be 0 when end of file is reached. * */ int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, - int64_t sector_num, - int nb_sectors, int *pnum) + int64_t offset, int64_t bytes, int64_t *pnum) { BlockDriverState *intermediate; - int ret, n =3D nb_sectors; + int ret; + int64_t n =3D bytes; =20 intermediate =3D top; while (intermediate && intermediate !=3D base) { int64_t pnum_inter; int64_t size_inter; - int psectors_inter; =20 - ret =3D bdrv_is_allocated(intermediate, sector_num * BDRV_SECTOR_S= IZE, - nb_sectors * BDRV_SECTOR_SIZE, - &pnum_inter); + ret =3D bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter= ); if (ret < 0) { return ret; } - assert(pnum_inter < INT_MAX * BDRV_SECTOR_SIZE); - psectors_inter =3D pnum_inter >> BDRV_SECTOR_BITS; if (ret) { - *pnum =3D psectors_inter; + *pnum =3D pnum_inter; return 1; } =20 - size_inter =3D bdrv_nb_sectors(intermediate); + size_inter =3D bdrv_getlength(intermediate); if (size_inter < 0) { return size_inter; } - if (n > psectors_inter && - (intermediate =3D=3D top || sector_num + psectors_inter < size= _inter)) { - n =3D psectors_inter; + if (n > pnum_inter && + (intermediate =3D=3D top || offset + pnum_inter < size_inter))= { + n =3D pnum_inter; } =20 intermediate =3D backing_bs(intermediate); diff --git a/block/mirror.c b/block/mirror.c index b33f4bb..eaf0fe7 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -621,6 +621,7 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) BlockDriverState *bs =3D s->source; BlockDriverState *target_bs =3D blk_bs(s->target); int ret, n; + int64_t count; =20 end =3D s->bdev_length / BDRV_SECTOR_SIZE; =20 @@ -670,11 +671,16 @@ static int coroutine_fn mirror_dirty_init(MirrorBlock= Job *s) return 0; } =20 - ret =3D bdrv_is_allocated_above(bs, base, sector_num, nb_sectors, = &n); + ret =3D bdrv_is_allocated_above(bs, base, sector_num * BDRV_SECTOR= _SIZE, + nb_sectors * BDRV_SECTOR_SIZE, &coun= t); if (ret < 0) { return ret; } =20 + /* TODO: Relax this once bdrv_is_allocated_above and dirty + * bitmaps no longer require sector alignment. */ + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; assert(n > 0); if (ret =3D=3D 1) { bdrv_set_dirty_bitmap(s->dirty_bitmap, sector_num, n); diff --git a/block/replication.c b/block/replication.c index 8f3aba7..bf4462c 100644 --- a/block/replication.c +++ b/block/replication.c @@ -264,7 +264,8 @@ static coroutine_fn int replication_co_writev(BlockDriv= erState *bs, BdrvChild *top =3D bs->file; BdrvChild *base =3D s->secondary_disk; BdrvChild *target; - int ret, n; + int ret; + int64_t n; =20 ret =3D replication_get_io_status(s); if (ret < 0) { @@ -283,14 +284,20 @@ static coroutine_fn int replication_co_writev(BlockDr= iverState *bs, */ qemu_iovec_init(&hd_qiov, qiov->niov); while (remaining_sectors > 0) { - ret =3D bdrv_is_allocated_above(top->bs, base->bs, sector_num, - remaining_sectors, &n); + int64_t count; + + ret =3D bdrv_is_allocated_above(top->bs, base->bs, + sector_num * BDRV_SECTOR_SIZE, + remaining_sectors * BDRV_SECTOR_SIZE, + &count); if (ret < 0) { goto out1; } =20 + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + n =3D count >> BDRV_SECTOR_BITS; qemu_iovec_reset(&hd_qiov); - qemu_iovec_concat(&hd_qiov, qiov, bytes_done, n * BDRV_SECTOR_SIZE= ); + qemu_iovec_concat(&hd_qiov, qiov, bytes_done, count); =20 target =3D ret ? top : base; ret =3D bdrv_co_writev(target, sector_num, n, &hd_qiov); @@ -300,7 +307,7 @@ static coroutine_fn int replication_co_writev(BlockDriv= erState *bs, =20 remaining_sectors -=3D n; sector_num +=3D n; - bytes_done +=3D n * BDRV_SECTOR_SIZE; + bytes_done +=3D count; } =20 out1: diff --git a/block/stream.c b/block/stream.c index df9679c..e6f7234 100644 --- a/block/stream.c +++ b/block/stream.c @@ -111,7 +111,7 @@ static void coroutine_fn stream_run(void *opaque) uint64_t delay_ns =3D 0; int error =3D 0; int ret =3D 0; - int n =3D 0; /* sectors */ + int64_t n =3D 0; /* bytes */ void *buf; =20 if (!bs->backing) { @@ -135,9 +135,8 @@ static void coroutine_fn stream_run(void *opaque) bdrv_enable_copy_on_read(bs); } =20 - for ( ; offset < s->common.len; offset +=3D n * BDRV_SECTOR_SIZE) { + for ( ; offset < s->common.len; offset +=3D n) { bool copy; - int64_t count =3D 0; =20 /* Note that even when no rate limit is applied we need to yield * with no pending I/O here so that bdrv_drain_all() returns. @@ -149,28 +148,25 @@ static void coroutine_fn stream_run(void *opaque) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &count); - /* TODO relax this once bdrv_is_allocated does not enforce sectors= */ - assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); - n =3D count >> BDRV_SECTOR_BITS; + ret =3D bdrv_is_allocated(bs, offset, STREAM_BUFFER_SIZE, &n); if (ret =3D=3D 1) { /* Allocated in the top, no need to copy. */ } else if (ret >=3D 0) { /* Copy if allocated in the intermediate images. Limit to the * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ ret =3D bdrv_is_allocated_above(backing_bs(bs), base, - offset / BDRV_SECTOR_SIZE, n, &n= ); + offset, n, &n); =20 /* Finish early if end of backing file has been reached */ if (ret =3D=3D 0 && n =3D=3D 0) { - n =3D (s->common.len - offset) / BDRV_SECTOR_SIZE; + n =3D s->common.len - offset; } =20 copy =3D (ret =3D=3D 1); } - trace_stream_one_iteration(s, offset, n * BDRV_SECTOR_SIZE, ret); + trace_stream_one_iteration(s, offset, n, ret); if (copy) { - ret =3D stream_populate(blk, offset, n * BDRV_SECTOR_SIZE, buf= ); + ret =3D stream_populate(blk, offset, n, buf); } if (ret < 0) { BlockErrorAction action =3D @@ -189,10 +185,9 @@ static void coroutine_fn stream_run(void *opaque) ret =3D 0; =20 /* Publish progress */ - s->common.offset +=3D n * BDRV_SECTOR_SIZE; + s->common.offset +=3D n; if (copy && s->common.speed) { - delay_ns =3D ratelimit_calculate_delay(&s->limit, - n * BDRV_SECTOR_SIZE); + delay_ns =3D ratelimit_calculate_delay(&s->limit, n); } } =20 diff --git a/include/block/block.h b/include/block/block.h index 8d16cc1..4a27252 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -430,7 +430,7 @@ int64_t bdrv_get_block_status_above(BlockDriverState *b= s, int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, - int64_t sector_num, int nb_sectors, int *pnum); + int64_t offset, int64_t bytes, int64_t *pnum); =20 bool bdrv_is_read_only(BlockDriverState *bs); bool bdrv_is_writable(BlockDriverState *bs); diff --git a/qemu-img.c b/qemu-img.c index 86e2433..f7ffb79 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1508,12 +1508,16 @@ static int img_compare(int argc, char **argv) } =20 for (;;) { + int64_t count; + nb_sectors =3D sectors_to_process(total_sectors_over, sector_n= um); if (nb_sectors <=3D 0) { break; } - ret =3D bdrv_is_allocated_above(blk_bs(blk_over), NULL, sector= _num, - nb_sectors, &pnum); + ret =3D bdrv_is_allocated_above(blk_bs(blk_over), NULL, + sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, + &count); if (ret < 0) { ret =3D 3; error_report("Sector allocation test failed for %s", @@ -1521,7 +1525,10 @@ static int img_compare(int argc, char **argv) goto out; =20 } - nb_sectors =3D pnum; + /* TODO relax this once bdrv_is_allocated_above does not enfor= ce + * sector alignment */ + assert(QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)); + nb_sectors =3D count >> BDRV_SECTOR_BITS; if (ret) { ret =3D check_empty_sectors(blk_over, sector_num, nb_secto= rs, filename_over, buf1, quiet); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 149944984178266.51625069164481; Fri, 7 Jul 2017 10:50:41 -0700 (PDT) Received: from localhost ([::1]:57927 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXOq-0008Ap-5u for importer@patchew.org; Fri, 07 Jul 2017 13:50:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42321) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlg-0005ay-2e for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWld-0008SP-Q1 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40684) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlU-0008Eq-Js; Fri, 07 Jul 2017 13:10:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 952EC635E8; Fri, 7 Jul 2017 17:09:59 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA77B61F23; Fri, 7 Jul 2017 17:09:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 952EC635E8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 952EC635E8 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:56 +0200 Message-Id: <1499447335-6125-42-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:09:59 +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] [PULL 041/100] block: expose crypto option names / defs to other drivers 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-devel@nongnu.org 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" From: "Daniel P. Berrange" The block/crypto.c defines a set of QemuOpts that provide parameters for encryption. This will also be needed by the qcow/qcow2 integration, so expose the relevant pieces in a new block/crypto.h header. Some helper methods taking QemuOpts are changed to take QDict to simplify usage in other places. Reviewed-by: Max Reitz Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-2-berrange@redhat.com Signed-off-by: Max Reitz --- block/crypto.c | 82 +++++++++++++++++----------------------------------- block/crypto.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 117 insertions(+), 56 deletions(-) create mode 100644 block/crypto.h diff --git a/block/crypto.c b/block/crypto.c index 10e5ddc..ea40ba4 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -24,16 +24,10 @@ #include "sysemu/block-backend.h" #include "crypto/block.h" #include "qapi/opts-visitor.h" +#include "qapi/qobject-input-visitor.h" #include "qapi-visit.h" #include "qapi/error.h" - -#define BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET "key-secret" -#define BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG "cipher-alg" -#define BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE "cipher-mode" -#define BLOCK_CRYPTO_OPT_LUKS_IVGEN_ALG "ivgen-alg" -#define BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG "ivgen-hash-alg" -#define BLOCK_CRYPTO_OPT_LUKS_HASH_ALG "hash-alg" -#define BLOCK_CRYPTO_OPT_LUKS_ITER_TIME "iter-time" +#include "block/crypto.h" =20 typedef struct BlockCrypto BlockCrypto; =20 @@ -135,11 +129,7 @@ static QemuOptsList block_crypto_runtime_opts_luks =3D= { .name =3D "crypto", .head =3D QTAILQ_HEAD_INITIALIZER(block_crypto_runtime_opts_luks.head), .desc =3D { - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, - .type =3D QEMU_OPT_STRING, - .help =3D "ID of the secret that provides the encryption key", - }, + BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET, { /* end of list */ } }, }; @@ -154,49 +144,21 @@ static QemuOptsList block_crypto_create_opts_luks =3D= { .type =3D QEMU_OPT_SIZE, .help =3D "Virtual disk size" }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, - .type =3D QEMU_OPT_STRING, - .help =3D "ID of the secret that provides the encryption key", - }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG, - .type =3D QEMU_OPT_STRING, - .help =3D "Name of encryption cipher algorithm", - }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE, - .type =3D QEMU_OPT_STRING, - .help =3D "Name of encryption cipher mode", - }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_IVGEN_ALG, - .type =3D QEMU_OPT_STRING, - .help =3D "Name of IV generator algorithm", - }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG, - .type =3D QEMU_OPT_STRING, - .help =3D "Name of IV generator hash algorithm", - }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_HASH_ALG, - .type =3D QEMU_OPT_STRING, - .help =3D "Name of encryption hash algorithm", - }, - { - .name =3D BLOCK_CRYPTO_OPT_LUKS_ITER_TIME, - .type =3D QEMU_OPT_NUMBER, - .help =3D "Time to spend in PBKDF in milliseconds", - }, + BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET, + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG, + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE, + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG, + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG, + BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG, + BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME, { /* end of list */ } }, }; =20 =20 -static QCryptoBlockOpenOptions * +QCryptoBlockOpenOptions * block_crypto_open_opts_init(QCryptoBlockFormat format, - QemuOpts *opts, + QDict *opts, Error **errp) { Visitor *v; @@ -206,7 +168,7 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, ret =3D g_new0(QCryptoBlockOpenOptions, 1); ret->format =3D format; =20 - v =3D opts_visitor_new(opts); + v =3D qobject_input_visitor_new_keyval(QOBJECT(opts)); =20 visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { @@ -240,9 +202,9 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, } =20 =20 -static QCryptoBlockCreateOptions * +QCryptoBlockCreateOptions * block_crypto_create_opts_init(QCryptoBlockFormat format, - QemuOpts *opts, + QDict *opts, Error **errp) { Visitor *v; @@ -252,7 +214,7 @@ block_crypto_create_opts_init(QCryptoBlockFormat format, ret =3D g_new0(QCryptoBlockCreateOptions, 1); ret->format =3D format; =20 - v =3D opts_visitor_new(opts); + v =3D qobject_input_visitor_new_keyval(QOBJECT(opts)); =20 visit_start_struct(v, NULL, NULL, 0, &local_err); if (local_err) { @@ -299,6 +261,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, int ret =3D -EINVAL; QCryptoBlockOpenOptions *open_opts =3D NULL; unsigned int cflags =3D 0; + QDict *cryptoopts =3D NULL; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -313,7 +276,9 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, goto cleanup; } =20 - open_opts =3D block_crypto_open_opts_init(format, opts, errp); + cryptoopts =3D qemu_opts_to_qdict(opts, NULL); + + open_opts =3D block_crypto_open_opts_init(format, cryptoopts, errp); if (!open_opts) { goto cleanup; } @@ -337,6 +302,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, =20 ret =3D 0; cleanup: + QDECREF(cryptoopts); qapi_free_QCryptoBlockOpenOptions(open_opts); return ret; } @@ -356,8 +322,11 @@ static int block_crypto_create_generic(QCryptoBlockFor= mat format, .opts =3D opts, .filename =3D filename, }; + QDict *cryptoopts; + + cryptoopts =3D qemu_opts_to_qdict(opts, NULL); =20 - create_opts =3D block_crypto_create_opts_init(format, opts, errp); + create_opts =3D block_crypto_create_opts_init(format, cryptoopts, errp= ); if (!create_opts) { return -1; } @@ -375,6 +344,7 @@ static int block_crypto_create_generic(QCryptoBlockForm= at format, =20 ret =3D 0; cleanup: + QDECREF(cryptoopts); qcrypto_block_free(crypto); blk_unref(data.blk); qapi_free_QCryptoBlockCreateOptions(create_opts); diff --git a/block/crypto.h b/block/crypto.h new file mode 100644 index 0000000..c0e9b54 --- /dev/null +++ b/block/crypto.h @@ -0,0 +1,91 @@ +/* + * QEMU block full disk encryption + * + * Copyright (c) 2015-2017 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see . + * + */ + +#ifndef BLOCK_CRYPTO_H__ +#define BLOCK_CRYPTO_H__ + +#define BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET "key-secret" +#define BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG "cipher-alg" +#define BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE "cipher-mode" +#define BLOCK_CRYPTO_OPT_LUKS_IVGEN_ALG "ivgen-alg" +#define BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG "ivgen-hash-alg" +#define BLOCK_CRYPTO_OPT_LUKS_HASH_ALG "hash-alg" +#define BLOCK_CRYPTO_OPT_LUKS_ITER_TIME "iter-time" + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "ID of the secret that provides the keyslot passphrase",= \ + } + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of encryption cipher algorithm", \ + } + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of encryption cipher mode", \ + } + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_IVGEN_ALG, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of IV generator algorithm", \ + } + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of IV generator hash algorithm", \ + } + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_HASH_ALG, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of encryption hash algorithm", \ + } + +#define BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME \ + { \ + .name =3D BLOCK_CRYPTO_OPT_LUKS_ITER_TIME, \ + .type =3D QEMU_OPT_NUMBER, \ + .help =3D "Time to spend in PBKDF in milliseconds", \ + } + +QCryptoBlockCreateOptions * +block_crypto_create_opts_init(QCryptoBlockFormat format, + QDict *opts, + Error **errp); + +QCryptoBlockOpenOptions * +block_crypto_open_opts_init(QCryptoBlockFormat format, + QDict *opts, + Error **errp); + +#endif /* BLOCK_CRYPTO_H__ */ --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 149944839249451.951208055942516; Fri, 7 Jul 2017 10:26:32 -0700 (PDT) Received: from localhost ([::1]:57786 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX1S-0003GW-4t for importer@patchew.org; Fri, 07 Jul 2017 13:26:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42303) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlf-0005Zn-5O for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWld-0008S2-L2 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlV-0008GU-Sb; Fri, 07 Jul 2017 13:10:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC0F8285B1; Fri, 7 Jul 2017 17:10:00 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E038E61F23; Fri, 7 Jul 2017 17:09:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CC0F8285B1 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CC0F8285B1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:57 +0200 Message-Id: <1499447335-6125-43-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:10:01 +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] [PULL 042/100] block: add ability to set a prefix for opt names 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-devel@nongnu.org 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" From: "Daniel P. Berrange" When integrating the crypto support with qcow/qcow2, we don't want to use the bare LUKS option names "hash-alg", "key-secret", etc. We need to namespace them to match the nested QAPI schema. e.g. "encrypt.hash-alg", "encrypt.key-secret" so that they don't clash with any general qcow options at a later date. Reviewed-by: Eric Blake Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-3-berrange@redhat.com Signed-off-by: Max Reitz --- block/crypto.c | 16 ++++++++-------- block/crypto.h | 40 ++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index ea40ba4..9df1e5d 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -129,7 +129,7 @@ static QemuOptsList block_crypto_runtime_opts_luks =3D { .name =3D "crypto", .head =3D QTAILQ_HEAD_INITIALIZER(block_crypto_runtime_opts_luks.head), .desc =3D { - BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET, + BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""), { /* end of list */ } }, }; @@ -144,13 +144,13 @@ static QemuOptsList block_crypto_create_opts_luks =3D= { .type =3D QEMU_OPT_SIZE, .help =3D "Virtual disk size" }, - BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET, - BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG, - BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE, - BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG, - BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG, - BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG, - BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME, + BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG(""), + BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME(""), { /* end of list */ } }, }; diff --git a/block/crypto.h b/block/crypto.h index c0e9b54..3430dcd 100644 --- a/block/crypto.h +++ b/block/crypto.h @@ -29,51 +29,51 @@ #define BLOCK_CRYPTO_OPT_LUKS_HASH_ALG "hash-alg" #define BLOCK_CRYPTO_OPT_LUKS_ITER_TIME "iter-time" =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(prefix) \ { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, \ .type =3D QEMU_OPT_STRING, \ .help =3D "ID of the secret that provides the keyslot passphrase",= \ } =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG(prefix) \ { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG, \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG, \ .type =3D QEMU_OPT_STRING, \ .help =3D "Name of encryption cipher algorithm", \ } =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE \ - { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE, \ - .type =3D QEMU_OPT_STRING, \ - .help =3D "Name of encryption cipher mode", \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE(prefix) \ + { \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of encryption cipher mode", \ } =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG \ - { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_IVGEN_ALG, \ - .type =3D QEMU_OPT_STRING, \ - .help =3D "Name of IV generator algorithm", \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG(prefix) \ + { \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_IVGEN_ALG, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D "Name of IV generator algorithm", \ } =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG(prefix) \ { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG, \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_IVGEN_HASH_ALG, \ .type =3D QEMU_OPT_STRING, \ .help =3D "Name of IV generator hash algorithm", \ } =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG(prefix) \ { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_HASH_ALG, \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_HASH_ALG, \ .type =3D QEMU_OPT_STRING, \ .help =3D "Name of encryption hash algorithm", \ } =20 -#define BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME \ +#define BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME(prefix) \ { \ - .name =3D BLOCK_CRYPTO_OPT_LUKS_ITER_TIME, \ + .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_ITER_TIME, \ .type =3D QEMU_OPT_NUMBER, \ .help =3D "Time to spend in PBKDF in milliseconds", \ } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449592025840.1792158410202; Fri, 7 Jul 2017 10:46:32 -0700 (PDT) Received: from localhost ([::1]:57904 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXKo-0004Y8-Jk for importer@patchew.org; Fri, 07 Jul 2017 13:46:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42300) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlf-0005ZS-2R for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWld-0008SB-MK for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56448) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlX-0008K6-CD; Fri, 07 Jul 2017 13:10:03 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5320083F3E; Fri, 7 Jul 2017 17:10:02 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 201C662925; Fri, 7 Jul 2017 17:10:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5320083F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5320083F3E From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:58 +0200 Message-Id: <1499447335-6125-44-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:02 +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] [PULL 043/100] qcow: document another weakness of qcow AES encryption 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Document that use of guest virtual sector numbers as the basis for the initialization vectors is a potential weakness, when combined with internal snapshots or multiple images using the same passphrase. This fixes the formatting of the itemized list too. Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-4-berrange@redhat.com Signed-off-by: Max Reitz --- qemu-img.texi | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/qemu-img.texi b/qemu-img.texi index 5b925ec..f335139 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -567,16 +567,29 @@ The use of encryption in qcow and qcow2 images is con= sidered to be flawed by modern cryptography standards, suffering from a number of design problems: =20 @itemize @minus -@item The AES-CBC cipher is used with predictable initialization vectors b= ased +@item +The AES-CBC cipher is used with predictable initialization vectors based on the sector number. This makes it vulnerable to chosen plaintext attacks which can reveal the existence of encrypted data. -@item The user passphrase is directly used as the encryption key. A poorly +@item +The user passphrase is directly used as the encryption key. A poorly chosen or short passphrase will compromise the security of the encryption. -@item In the event of the passphrase being compromised there is no way to +@item +In the event of the passphrase being compromised there is no way to change the passphrase to protect data in any qcow images. The files must be cloned, using a different encryption passphrase in the new file. The original file must then be securely erased using a program like shred, though even this is ineffective with many modern storage technologies. +@item +Initialization vectors used to encrypt sectors are based on the +guest virtual sector number, instead of the host physical sector. When +a disk image has multiple internal snapshots this means that data in +multiple physical sectors is encrypted with the same initialization +vector. With the CBC mode, this opens the possibility of watermarking +attacks if the attack can collect multiple sectors encrypted with the +same IV and some predictable data. Having multiple qcow2 images with +the same passphrase also exposes this weakness since the passphrase +is directly used as the key. @end itemize =20 Use of qcow / qcow2 encryption is thus strongly discouraged. Users are --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449439899447.0193135939818; Fri, 7 Jul 2017 10:43:59 -0700 (PDT) Received: from localhost ([::1]:57887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXIM-0002K6-FZ for importer@patchew.org; Fri, 07 Jul 2017 13:43:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42278) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWle-0005YT-Hf for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWld-0008Re-BR for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40832) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlY-0008L4-L3; Fri, 07 Jul 2017 13:10:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A0966624A8; Fri, 7 Jul 2017 17:10:03 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8054961F52; Fri, 7 Jul 2017 17:10:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A0966624A8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A0966624A8 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:07:59 +0200 Message-Id: <1499447335-6125-45-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:10:03 +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] [PULL 044/100] qcow: require image size to be > 1 for new images 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-devel@nongnu.org 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" From: "Daniel P. Berrange" The qcow driver refuses to open images which are less than 2 bytes in size, but will happily create such images. Add a check in the create path to avoid this discrepancy. Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-5-berrange@redhat.com Signed-off-by: Max Reitz --- block/qcow.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/qcow.c b/block/qcow.c index 7bd94dc..49871fb 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -811,6 +811,12 @@ static int qcow_create(const char *filename, QemuOpts = *opts, Error **errp) /* Read out options */ total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), BDRV_SECTOR_SIZE); + if (total_size =3D=3D 0) { + error_setg(errp, "Image size is too small, cannot be zero length"); + ret =3D -EINVAL; + goto cleanup; + } + backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { flags |=3D BLOCK_FLAG_ENCRYPT; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449201504514.2470208179462; Fri, 7 Jul 2017 10:40:01 -0700 (PDT) Received: from localhost ([::1]:57860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXEW-00075x-8t for importer@patchew.org; Fri, 07 Jul 2017 13:40:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlf-0005ZR-1o for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWld-0008Sf-V1 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46900) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlb-0008N8-GU; Fri, 07 Jul 2017 13:10:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7E628C04B326; Fri, 7 Jul 2017 17:10:06 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E451C61F52; Fri, 7 Jul 2017 17:10:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7E628C04B326 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7E628C04B326 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:00 +0200 Message-Id: <1499447335-6125-46-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:10:06 +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] [PULL 045/100] iotests: skip 042 with qcow which dosn't support zero sized images 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Test 042 is designed to verify operation with zero sized images. Such images are not supported with qcow (v1), so this test has always failed. Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-6-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/042 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/042 b/tests/qemu-iotests/042 index 351b283..a53e7cb 100755 --- a/tests/qemu-iotests/042 +++ b/tests/qemu-iotests/042 @@ -37,7 +37,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.rc . ./common.filter =20 -_supported_fmt qcow2 qcow qed +_supported_fmt qcow2 qed _supported_proto file _supported_os Linux =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449346156162.47923727138868; Fri, 7 Jul 2017 10:42:26 -0700 (PDT) Received: from localhost ([::1]:57874 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXGp-0000l4-Qp for importer@patchew.org; Fri, 07 Jul 2017 13:42:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlg-0005cD-Qu for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlf-0008U7-H3 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56596) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlc-0008PK-QU; Fri, 07 Jul 2017 13:10:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BBBF7804F0; Fri, 7 Jul 2017 17:10:07 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id CBB0552FCD; Fri, 7 Jul 2017 17:10:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BBBF7804F0 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BBBF7804F0 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:01 +0200 Message-Id: <1499447335-6125-47-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:07 +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] [PULL 046/100] iotests: skip 048 with qcow which doesn't support resize 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Test 048 is designed to verify data preservation during an image resize. The qcow (v1) format impl has never supported resize so always fails. Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-7-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/048 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/048 b/tests/qemu-iotests/048 index 203c04f..9ed04a0 100755 --- a/tests/qemu-iotests/048 +++ b/tests/qemu-iotests/048 @@ -46,7 +46,7 @@ _compare() . ./common.filter . ./common.pattern =20 -_supported_fmt raw qcow qcow2 qed luks +_supported_fmt raw qcow2 qed luks _supported_proto file _supported_os Linux =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450273413161.8603373347388; Fri, 7 Jul 2017 10:57:53 -0700 (PDT) Received: from localhost ([::1]:57975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXVm-000672-Mq for importer@patchew.org; Fri, 07 Jul 2017 13:57:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlw-0005vE-2O for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlq-00008A-5f for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40942) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWle-0008Rr-8Y; Fri, 07 Jul 2017 13:10:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BAC4624A8; Fri, 7 Jul 2017 17:10:09 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1398661F23; Fri, 7 Jul 2017 17:10:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2BAC4624A8 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2BAC4624A8 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:02 +0200 Message-Id: <1499447335-6125-48-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:10:09 +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] [PULL 047/100] block: deprecate "encryption=on" in favor of "encrypt.format=aes" 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Historically the qcow & qcow2 image formats supported a property "encryption=3Don" to enable their built-in AES encryption. We'll soon be supporting LUKS for qcow2, so need a more general purpose way to enable encryption, with a choice of formats. This introduces an "encrypt.format" option, which will later be joined by a number of other "encrypt.XXX" options. The use of a "encrypt." prefix instead of "encrypt-" is done to facilitate mapping to a nested QAPI schema at later date. e.g. the preferred syntax is now qemu-img create -f qcow2 -o encrypt.format=3Daes demo.qcow2 Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-8-berrange@redhat.com Reviewed-by: Alberto Garcia Signed-off-by: Max Reitz --- block/qcow.c | 31 ++++++++++++--- block/qcow2.c | 34 ++++++++++++---- include/block/block_int.h | 2 +- qemu-img.c | 4 +- tests/qemu-iotests/049.out | 98 +++++++++++++++++++++++-------------------= ---- tests/qemu-iotests/082.out | 95 ++++++++++++++++++++++++++++--------------= -- tests/qemu-iotests/085.out | 38 +++++++++--------- tests/qemu-iotests/144.out | 4 +- tests/qemu-iotests/185.out | 8 ++-- 9 files changed, 191 insertions(+), 123 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index 49871fb..a442ed7 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -803,10 +803,10 @@ static int qcow_create(const char *filename, QemuOpts= *opts, Error **errp) uint8_t *tmp; int64_t total_size =3D 0; char *backing_file =3D NULL; - int flags =3D 0; Error *local_err =3D NULL; int ret; BlockBackend *qcow_blk; + const char *encryptfmt =3D NULL; =20 /* Read out options */ total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), @@ -818,8 +818,16 @@ static int qcow_create(const char *filename, QemuOpts = *opts, Error **errp) } =20 backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); - if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { - flags |=3D BLOCK_FLAG_ENCRYPT; + encryptfmt =3D qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT_FORMAT); + if (encryptfmt) { + if (qemu_opt_get(opts, BLOCK_OPT_ENCRYPT)) { + error_setg(errp, "Options " BLOCK_OPT_ENCRYPT " and " + BLOCK_OPT_ENCRYPT_FORMAT " are mutually exclusive"); + ret =3D -EINVAL; + goto cleanup; + } + } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { + encryptfmt =3D "aes"; } =20 ret =3D bdrv_create_file(filename, opts, &local_err); @@ -873,7 +881,13 @@ static int qcow_create(const char *filename, QemuOpts = *opts, Error **errp) l1_size =3D (total_size + (1LL << shift) - 1) >> shift; =20 header.l1_table_offset =3D cpu_to_be64(header_size); - if (flags & BLOCK_FLAG_ENCRYPT) { + if (encryptfmt) { + if (!g_str_equal(encryptfmt, "aes")) { + error_setg(errp, "Unknown encryption format '%s', expected 'ae= s'", + encryptfmt); + ret =3D -EINVAL; + goto exit; + } header.crypt_method =3D cpu_to_be32(QCOW_CRYPT_AES); } else { header.crypt_method =3D cpu_to_be32(QCOW_CRYPT_NONE); @@ -1047,8 +1061,13 @@ static QemuOptsList qcow_create_opts =3D { { .name =3D BLOCK_OPT_ENCRYPT, .type =3D QEMU_OPT_BOOL, - .help =3D "Encrypt the image", - .def_value_str =3D "off" + .help =3D "Encrypt the image with format 'aes'. (Deprecated " + "in favor of " BLOCK_OPT_ENCRYPT_FORMAT "=3Daes)", + }, + { + .name =3D BLOCK_OPT_ENCRYPT_FORMAT, + .type =3D QEMU_OPT_STRING, + .help =3D "Encrypt the image, format choices: 'aes'", }, { /* end of list */ } } diff --git a/block/qcow2.c b/block/qcow2.c index 2f94f03..8f1822c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2144,7 +2144,7 @@ static int qcow2_create2(const char *filename, int64_= t total_size, const char *backing_file, const char *backing_for= mat, int flags, size_t cluster_size, PreallocMode prea= lloc, QemuOpts *opts, int version, int refcount_order, - Error **errp) + const char *encryptfmt, Error **errp) { int cluster_bits; QDict *options; @@ -2273,7 +2273,13 @@ static int qcow2_create2(const char *filename, int64= _t total_size, .header_length =3D cpu_to_be32(sizeof(*header)), }; =20 - if (flags & BLOCK_FLAG_ENCRYPT) { + if (encryptfmt) { + if (!g_str_equal(encryptfmt, "aes")) { + error_setg(errp, "Unknown encryption format '%s', expected 'ae= s'", + encryptfmt); + ret =3D -EINVAL; + goto out; + } header->crypt_method =3D cpu_to_be32(QCOW_CRYPT_AES); } else { header->crypt_method =3D cpu_to_be32(QCOW_CRYPT_NONE); @@ -2402,6 +2408,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) int version =3D 3; uint64_t refcount_bits =3D 16; int refcount_order; + const char *encryptfmt =3D NULL; Error *local_err =3D NULL; int ret; =20 @@ -2410,8 +2417,16 @@ static int qcow2_create(const char *filename, QemuOp= ts *opts, Error **errp) BDRV_SECTOR_SIZE); backing_file =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FILE); backing_fmt =3D qemu_opt_get_del(opts, BLOCK_OPT_BACKING_FMT); - if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { - flags |=3D BLOCK_FLAG_ENCRYPT; + encryptfmt =3D qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT_FORMAT); + if (encryptfmt) { + if (qemu_opt_get_del(opts, BLOCK_OPT_ENCRYPT)) { + error_setg(errp, "Options " BLOCK_OPT_ENCRYPT " and " + BLOCK_OPT_ENCRYPT_FORMAT " are mutually exclusive"); + ret =3D -EINVAL; + goto finish; + } + } else if (qemu_opt_get_bool_del(opts, BLOCK_OPT_ENCRYPT, false)) { + encryptfmt =3D "aes"; } cluster_size =3D qemu_opt_get_size_del(opts, BLOCK_OPT_CLUSTER_SIZE, DEFAULT_CLUSTER_SIZE); @@ -2477,7 +2492,7 @@ static int qcow2_create(const char *filename, QemuOpt= s *opts, Error **errp) =20 ret =3D qcow2_create2(filename, size, backing_file, backing_fmt, flags, cluster_size, prealloc, opts, version, refcount_or= der, - &local_err); + encryptfmt, &local_err); error_propagate(errp, local_err); =20 finish: @@ -3431,8 +3446,13 @@ static QemuOptsList qcow2_create_opts =3D { { .name =3D BLOCK_OPT_ENCRYPT, .type =3D QEMU_OPT_BOOL, - .help =3D "Encrypt the image", - .def_value_str =3D "off" + .help =3D "Encrypt the image with format 'aes'. (Deprecated " + "in favor of " BLOCK_OPT_ENCRYPT_FORMAT "=3Daes)", + }, + { + .name =3D BLOCK_OPT_ENCRYPT_FORMAT, + .type =3D QEMU_OPT_STRING, + .help =3D "Encrypt the image, format choices: 'aes'", }, { .name =3D BLOCK_OPT_CLUSTER_SIZE, diff --git a/include/block/block_int.h b/include/block/block_int.h index 15fa602..701508d 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -37,11 +37,11 @@ #include "qemu/main-loop.h" #include "qemu/throttle.h" =20 -#define BLOCK_FLAG_ENCRYPT 1 #define BLOCK_FLAG_LAZY_REFCOUNTS 8 =20 #define BLOCK_OPT_SIZE "size" #define BLOCK_OPT_ENCRYPT "encryption" +#define BLOCK_OPT_ENCRYPT_FORMAT "encrypt.format" #define BLOCK_OPT_COMPAT6 "compat6" #define BLOCK_OPT_HWVERSION "hwversion" #define BLOCK_OPT_BACKING_FILE "backing_file" diff --git a/qemu-img.c b/qemu-img.c index f7ffb79..ae4fe6d 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2264,6 +2264,8 @@ static int img_convert(int argc, char **argv) if (s.compressed) { bool encryption =3D qemu_opt_get_bool(opts, BLOCK_OPT_ENCRYPT, false); + const char *encryptfmt =3D + qemu_opt_get(opts, BLOCK_OPT_ENCRYPT_FORMAT); const char *preallocation =3D qemu_opt_get(opts, BLOCK_OPT_PREALLOC); =20 @@ -2273,7 +2275,7 @@ static int img_convert(int argc, char **argv) goto out; } =20 - if (encryption) { + if (encryption || encryptfmt) { error_report("Compression and encryption not supported at " "the same time"); ret =3D -1; diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index 34e66db..50e91c8 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -4,90 +4,90 @@ QA output created by 049 =3D=3D 1. Traditional size parameter =3D=3D =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024b -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1k -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1K -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 encryption=3Doff= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1G -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1T -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1024.0b -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5k -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5K -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 encryption=3Doff= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5G -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 TEST_DIR/t.qcow2 1.5T -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 =3D=3D 2. Specifying size via -o =3D=3D =20 qemu-img create -f qcow2 -o size=3D1024 TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024b TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1k TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1K TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1M TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 encryption=3Doff= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1048576 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1G TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1073741824 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1T TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1099511627776 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024.0 TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1024.0b TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1024 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5k TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5K TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 encryption=3Doff cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1536 cluster_size=3D6553= 6 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5M TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 encryption=3Doff= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1572864 cluster_size=3D6= 5536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5G TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1610612736 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o size=3D1.5T TEST_DIR/t.qcow2 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D1649267441664 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 =3D=3D 3. Invalid sizes =3D=3D =20 @@ -128,62 +128,62 @@ qemu-img: TEST_DIR/t.qcow2: Invalid options for file = format 'qcow2' =3D=3D Check correct interpretation of suffixes for cluster size =3D=3D =20 qemu-img create -f qcow2 -o cluster_size=3D1024 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024b TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1k TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1K TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1M TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1048576 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1048576 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024.0 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D1024.0b TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D1024 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 1024 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5k TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D512 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5K TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D512 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 512 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o cluster_size=3D0.5M TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D524288 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 524288 lazy_refcounts=3Doff refcount_bits=3D16 =20 =3D=3D Check compat level option =3D=3D =20 qemu-img create -f qcow2 -o compat=3D0.10 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 e= ncryption=3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D1.1 TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 en= cryption=3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.42 TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid compatibility level: '0.42' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.42 e= ncryption=3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.42 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3Dfoobar TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: Invalid compatibility level: 'foobar' -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3Dfoobar= encryption=3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits= =3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3Dfoobar= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 =3D=3D Check preallocation option =3D=3D =20 qemu-img create -f qcow2 -o preallocation=3Doff TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 preallocation=3Doff lazy_refcounts=3Doff refcount_bi= ts=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Doff lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o preallocation=3Dmetadata TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 preallocation=3Dmetadata lazy_refcounts=3Doff refcou= nt_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3Dmetadata lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o preallocation=3D1234 TEST_DIR/t.qcow2 64M qemu-img: TEST_DIR/t.qcow2: invalid parameter value: 1234 -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 preallocation=3D1234 lazy_refcounts=3Doff refcount_b= its=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 cluster_size=3D= 65536 preallocation=3D1234 lazy_refcounts=3Doff refcount_bits=3D16 =20 =3D=3D Check encryption option =3D=3D =20 @@ -196,16 +196,16 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D671= 08864 encryption=3Don cluster_siz =3D=3D Check lazy_refcounts option (only with v3) =3D=3D =20 qemu-img create -f qcow2 -o compat=3D1.1,lazy_refcounts=3Doff TEST_DIR/t.q= cow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 en= cryption=3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D1.1,lazy_refcounts=3Don TEST_DIR/t.qc= ow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 en= cryption=3Doff cluster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D1.1 cl= uster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.10,lazy_refcounts=3Doff TEST_DIR/t.= qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 e= ncryption=3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 qemu-img create -f qcow2 -o compat=3D0.10,lazy_refcounts=3Don TEST_DIR/t.q= cow2 64M qemu-img: TEST_DIR/t.qcow2: Lazy refcounts only supported with compatibili= ty level 1.1 and above (use compat=3D1.1 or greater) -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 e= ncryption=3Doff cluster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 compat=3D0.10 c= luster_size=3D65536 lazy_refcounts=3Don refcount_bits=3D16 =20 *** done diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index a952330..621386b 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -3,14 +3,14 @@ QA output created by 082 =3D=3D=3D create: Options specified more than once =3D=3D=3D =20 Testing: create -f foo -f qcow2 TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 encryption=3Do= ff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128M (134217728 bytes) cluster_size: 65536 =20 Testing: create -f qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don TEST_= DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 encryption=3Do= ff cluster_size=3D4096 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D4096 lazy_refcounts=3Don refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128M (134217728 bytes) @@ -22,7 +22,7 @@ Format specific information: corrupt: false =20 Testing: create -f qcow2 -o cluster_size=3D4k -o lazy_refcounts=3Don -o cl= uster_size=3D8k TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 encryption=3Do= ff cluster_size=3D8192 lazy_refcounts=3Don refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Don refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128M (134217728 bytes) @@ -34,7 +34,7 @@ Format specific information: corrupt: false =20 Testing: create -f qcow2 -o cluster_size=3D4k,cluster_size=3D8k TEST_DIR/t= .qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 encryption=3Do= ff cluster_size=3D8192 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D8192 lazy_refcounts=3Doff refcount_bits=3D16 image: TEST_DIR/t.IMGFMT file format: IMGFMT virtual size: 128M (134217728 bytes) @@ -48,7 +48,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -61,7 +62,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -74,7 +76,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -87,7 +90,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -100,7 +104,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -113,7 +118,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -126,7 +132,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -139,7 +146,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -147,10 +155,10 @@ refcount_bits Width of a reference count entry in = bits nocow Turn off copy-on-write (valid only on btrfs) =20 Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_DIR= /t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help encryption=3Doff cluster_size=3D65536 lazy_refcou= nts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,help cluster_size=3D65536 lazy_refcounts=3Doff refcoun= t_bits=3D16 =20 Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,? TEST_DIR/t.= qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? encryption=3Doff cluster_size=3D65536 lazy_refcounts= =3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 backing_file= =3DTEST_DIR/t.qcow2,,? cluster_size=3D65536 lazy_refcounts=3Doff refcount_b= its=3D16 =20 Testing: create -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2, -o help TEST_= DIR/t.qcow2 128M qemu-img: Invalid option list: backing_file=3DTEST_DIR/t.qcow2, @@ -167,7 +175,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -180,7 +189,7 @@ size Virtual disk size =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 Testing: create -f qcow2 TEST_DIR/t.qcow2 128M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 encryption=3Do= ff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D134217728 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 Testing: convert -f foo -f qcow2 TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base image: TEST_DIR/t.IMGFMT.base @@ -229,7 +238,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -242,7 +252,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -255,7 +266,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -268,7 +280,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -281,7 +294,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -294,7 +308,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -307,7 +322,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -320,7 +336,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -348,7 +365,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -407,7 +425,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -420,7 +439,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -433,7 +453,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -446,7 +467,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -459,7 +481,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -472,7 +495,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -485,7 +509,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -498,7 +523,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -528,7 +554,8 @@ size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image -encryption Encrypt the image +encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) +encrypt.format Encrypt the image, format choices: 'aes' cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates diff --git a/tests/qemu-iotests/085.out b/tests/qemu-iotests/085.out index a5d4cc3..6edf107 100644 --- a/tests/qemu-iotests/085.out +++ b/tests/qemu-iotests/085.out @@ -11,7 +11,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D13421= 7728 =20 =3D=3D=3D Create a single snapshot on virtio0 =3D=3D=3D =20 -Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.1 backing_fmt=3Dqcow2 encryption=3Doff cluste= r_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.1 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Invalid command - missing device and nodename =3D=3D=3D @@ -25,32 +25,32 @@ Formatting 'TEST_DIR/1-snapshot-v0.qcow2', fmt=3Dqcow2 = size=3D134217728 backing_file =20 =3D=3D=3D Create several transactional group snapshots =3D=3D=3D =20 -Formatting 'TEST_DIR/2-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/1-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/2-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.2 backing_fmt=3Dqcow2 encryption=3Doff cluste= r_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/2-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/1-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/2-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/t.qcow2.2 backing_fmt=3Dqcow2 cluster_size=3D65536 la= zy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/3-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/3-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/3-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/3-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/2-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/4-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/4-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/4-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/4-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/3-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/5-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/5-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/5-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/5-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/4-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/6-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/6-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/6-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/6-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/5-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/7-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/7-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/7-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/7-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/6-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/8-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/8-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/8-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/8-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/7-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/9-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/9-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption=3D= off cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/9-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/9-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 ba= cking_file=3DTEST_DIR/8-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} -Formatting 'TEST_DIR/10-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v0.qcow2 backing_fmt=3Dqcow2 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 -Formatting 'TEST_DIR/10-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v1.qcow2 backing_fmt=3Dqcow2 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/10-snapshot-v0.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v0.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/10-snapshot-v1.qcow2', fmt=3Dqcow2 size=3D134217728 b= acking_file=3DTEST_DIR/9-snapshot-v1.qcow2 backing_fmt=3Dqcow2 cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Create a couple of snapshots using blockdev-snapshot =3D=3D=3D diff --git a/tests/qemu-iotests/144.out b/tests/qemu-iotests/144.out index 387855c..014b281 100644 --- a/tests/qemu-iotests/144.out +++ b/tests/qemu-iotests/144.out @@ -7,7 +7,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D5368709= 12 =3D=3D=3D Performing Live Snapshot 1 =3D=3D=3D =20 {"return": {}} -Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D536870912 backing_file= =3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 encryption=3Doff cluster_size=3D655= 36 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D536870912 backing_file= =3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcounts= =3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Performing block-commit on active layer =3D=3D=3D @@ -19,6 +19,6 @@ Formatting 'TEST_DIR/tmp.qcow2', fmt=3Dqcow2 size=3D53687= 0912 backing_file=3DTEST_DIR/ =20 =3D=3D=3D Performing Live Snapshot 2 =3D=3D=3D =20 -Formatting 'TEST_DIR/tmp2.qcow2', fmt=3Dqcow2 size=3D536870912 backing_fil= e=3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 encryption=3Doff cluster_size=3D65= 536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/tmp2.qcow2', fmt=3Dqcow2 size=3D536870912 backing_fil= e=3DTEST_DIR/t.qcow2 backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff refcount_bits=3D16 {"return": {}} *** done diff --git a/tests/qemu-iotests/185.out b/tests/qemu-iotests/185.out index 45bc7cb..57eaf8d 100644 --- a/tests/qemu-iotests/185.out +++ b/tests/qemu-iotests/185.out @@ -7,12 +7,12 @@ Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D= 67108864 =20 =3D=3D=3D Creating backing chain =3D=3D=3D =20 -Formatting 'TEST_DIR/t.qcow2.mid', fmt=3Dqcow2 size=3D67108864 backing_fil= e=3DTEST_DIR/t.qcow2.base backing_fmt=3Dqcow2 encryption=3Doff cluster_size= =3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.mid', fmt=3Dqcow2 size=3D67108864 backing_fil= e=3DTEST_DIR/t.qcow2.base backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_ref= counts=3Doff refcount_bits=3D16 {"return": {}} wrote 4194304/4194304 bytes at offset 0 4 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) {"return": ""} -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 backing_file=3D= TEST_DIR/t.qcow2.mid backing_fmt=3Dqcow2 encryption=3Doff cluster_size=3D65= 536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 backing_file=3D= TEST_DIR/t.qcow2.mid backing_fmt=3Dqcow2 cluster_size=3D65536 lazy_refcount= s=3Doff refcount_bits=3D16 {"return": {}} =20 =3D=3D=3D Start commit job and exit qemu =3D=3D=3D @@ -33,7 +33,7 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D6710886= 4 backing_file=3DTEST_DIR/t.q =3D=3D=3D Start mirror job and exit qemu =3D=3D=3D =20 {"return": {}} -Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false}} @@ -42,7 +42,7 @@ Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67= 108864 encryption=3Doff clust =3D=3D=3D Start backup job and exit qemu =3D=3D=3D =20 {"return": {}} -Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 encryption= =3Doff cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +Formatting 'TEST_DIR/t.qcow2.copy', fmt=3Dqcow2 size=3D67108864 cluster_si= ze=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 {"return": {}} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false}} --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449795942478.81702200033124; Fri, 7 Jul 2017 10:49:55 -0700 (PDT) Received: from localhost ([::1]:57920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXO5-0007Rj-JM for importer@patchew.org; Fri, 07 Jul 2017 13:49:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42605) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWly-0005xG-5z for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlt-0000A1-E5 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlh-0008V8-QV; Fri, 07 Jul 2017 13:10:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 967F18EB35; Fri, 7 Jul 2017 17:10:12 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75D9F61F23; Fri, 7 Jul 2017 17:10:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 967F18EB35 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 967F18EB35 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:03 +0200 Message-Id: <1499447335-6125-49-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:12 +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] [PULL 048/100] qcow: make encrypt_sectors encrypt in place 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Instead of requiring separate input/output buffers for encrypting data, change encrypt_sectors() to assume use of a single buffer, encrypting in place. One current caller uses the same buffer for input/output already and the other two callers are easily converted to do so. Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Reviewed-by: Max Reitz Reviewed-by: Kevin Wolf Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-9-berrange@redhat.com Signed-off-by: Max Reitz --- block/qcow.c | 45 +++++++++++++++------------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index a442ed7..3a3dbf9 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -322,11 +322,10 @@ static int qcow_set_key(BlockDriverState *bs, const c= har *key) } =20 /* The crypt function is compatible with the linux cryptoloop - algorithm for < 4 GB images. NOTE: out_buf =3D=3D in_buf is - supported */ + algorithm for < 4 GB images. */ static int encrypt_sectors(BDRVQcowState *s, int64_t sector_num, - uint8_t *out_buf, const uint8_t *in_buf, - int nb_sectors, bool enc, Error **errp) + uint8_t *buf, int nb_sectors, bool enc, + Error **errp) { union { uint64_t ll[2]; @@ -345,14 +344,12 @@ static int encrypt_sectors(BDRVQcowState *s, int64_t = sector_num, } if (enc) { ret =3D qcrypto_cipher_encrypt(s->cipher, - in_buf, - out_buf, + buf, buf, 512, errp); } else { ret =3D qcrypto_cipher_decrypt(s->cipher, - in_buf, - out_buf, + buf, buf, 512, errp); } @@ -360,8 +357,7 @@ static int encrypt_sectors(BDRVQcowState *s, int64_t se= ctor_num, return -1; } sector_num++; - in_buf +=3D 512; - out_buf +=3D 512; + buf +=3D 512; } return 0; } @@ -481,13 +477,12 @@ static uint64_t get_cluster_offset(BlockDriverState *= bs, uint64_t start_sect; assert(s->cipher); start_sect =3D (offset & ~(s->cluster_size - 1)) >> 9; - memset(s->cluster_data + 512, 0x00, 512); for(i =3D 0; i < s->cluster_sectors; i++) { if (i < n_start || i >=3D n_end) { Error *err =3D NULL; + memset(s->cluster_data, 0x00, 512); if (encrypt_sectors(s, start_sect + i, - s->cluster_data, - s->cluster_data + 512, 1, + s->cluster_data, 1, true, &err) < 0) { error_free(err); errno =3D EIO; @@ -665,7 +660,7 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, } if (bs->encrypted) { assert(s->cipher); - if (encrypt_sectors(s, sector_num, buf, buf, + if (encrypt_sectors(s, sector_num, buf, n, false, &err) < 0) { goto fail; } @@ -700,9 +695,7 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, BDRVQcowState *s =3D bs->opaque; int index_in_cluster; uint64_t cluster_offset; - const uint8_t *src_buf; int ret =3D 0, n; - uint8_t *cluster_data =3D NULL; struct iovec hd_iov; QEMUIOVector hd_qiov; uint8_t *buf; @@ -710,7 +703,9 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, =20 s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 - if (qiov->niov > 1) { + /* We must always copy the iov when encrypting, so we + * don't modify the original data buffer during encryption */ + if (bs->encrypted || qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { return -ENOMEM; @@ -740,21 +735,14 @@ static coroutine_fn int qcow_co_writev(BlockDriverSta= te *bs, int64_t sector_num, if (bs->encrypted) { Error *err =3D NULL; assert(s->cipher); - if (!cluster_data) { - cluster_data =3D g_malloc0(s->cluster_size); - } - if (encrypt_sectors(s, sector_num, cluster_data, buf, - n, true, &err) < 0) { + if (encrypt_sectors(s, sector_num, buf, n, true, &err) < 0) { error_free(err); ret =3D -EIO; break; } - src_buf =3D cluster_data; - } else { - src_buf =3D buf; } =20 - hd_iov.iov_base =3D (void *)src_buf; + hd_iov.iov_base =3D (void *)buf; hd_iov.iov_len =3D n * 512; qemu_iovec_init_external(&hd_qiov, &hd_iov, 1); qemu_co_mutex_unlock(&s->lock); @@ -773,10 +761,7 @@ static coroutine_fn int qcow_co_writev(BlockDriverStat= e *bs, int64_t sector_num, } qemu_co_mutex_unlock(&s->lock); =20 - if (qiov->niov > 1) { - qemu_vfree(orig_buf); - } - g_free(cluster_data); + qemu_vfree(orig_buf); =20 return ret; } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449675340353.1319599877345; Fri, 7 Jul 2017 10:47:55 -0700 (PDT) Received: from localhost ([::1]:57907 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXM9-0005cS-TQ for importer@patchew.org; Fri, 07 Jul 2017 13:47:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWls-0005r4-Cf for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlp-00007s-Ob for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlj-0008Vs-G6; Fri, 07 Jul 2017 13:10:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8409961B91; Fri, 7 Jul 2017 17:10:14 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE87A62924; Fri, 7 Jul 2017 17:10:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8409961B91 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8409961B91 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:04 +0200 Message-Id: <1499447335-6125-50-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:10:14 +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] [PULL 049/100] qcow: convert QCow to use QCryptoBlock for encryption 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-devel@nongnu.org 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" From: "Daniel P. Berrange" This converts the qcow driver to make use of the QCryptoBlock APIs for encrypting image content. This is only wired up to permit use of the legacy QCow encryption format. Users who wish to have the strong LUKS format should switch to qcow2 instead. With this change it is now required to use the QCryptoSecret object for providing passwords, instead of the current block password APIs / interactive prompting. $QEMU \ -object secret,id=3Dsec0,file=3D/home/berrange/encrypted.pw \ -drive file=3D/home/berrange/encrypted.qcow,encrypt.format=3Daes,\ encrypt.key-secret=3Dsec0 Though note that running QEMU system emulators with the AES encryption is no longer supported, so while the above syntax is valid, QEMU will refuse to actually run the VM in this particular example. Likewise when creating images with the legacy AES-CBC format qemu-img create -f qcow \ --object secret,id=3Dsec0,file=3D/home/berrange/encrypted.pw \ -o encrypt.format=3Daes,encrypt.key-secret=3Dsec0 \ /home/berrange/encrypted.qcow 64M Reviewed-by: Max Reitz Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-10-berrange@redhat.com Signed-off-by: Max Reitz --- block/crypto.c | 10 +++ block/crypto.h | 20 ++++-- block/qcow.c | 198 +++++++++++++++++++++++++----------------------= ---- qapi/block-core.json | 38 +++++++++- 4 files changed, 158 insertions(+), 108 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 9df1e5d..da4be74 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -181,6 +181,11 @@ block_crypto_open_opts_init(QCryptoBlockFormat format, v, &ret->u.luks, &local_err); break; =20 + case Q_CRYPTO_BLOCK_FORMAT_QCOW: + visit_type_QCryptoBlockOptionsQCow_members( + v, &ret->u.qcow, &local_err); + break; + default: error_setg(&local_err, "Unsupported block format %d", format); break; @@ -227,6 +232,11 @@ block_crypto_create_opts_init(QCryptoBlockFormat forma= t, v, &ret->u.luks, &local_err); break; =20 + case Q_CRYPTO_BLOCK_FORMAT_QCOW: + visit_type_QCryptoBlockOptionsQCow_members( + v, &ret->u.qcow, &local_err); + break; + default: error_setg(&local_err, "Unsupported block format %d", format); break; diff --git a/block/crypto.h b/block/crypto.h index 3430dcd..0f985ea 100644 --- a/block/crypto.h +++ b/block/crypto.h @@ -21,6 +21,19 @@ #ifndef BLOCK_CRYPTO_H__ #define BLOCK_CRYPTO_H__ =20 +#define BLOCK_CRYPTO_OPT_DEF_KEY_SECRET(prefix, helpstr) \ + { \ + .name =3D prefix BLOCK_CRYPTO_OPT_QCOW_KEY_SECRET, \ + .type =3D QEMU_OPT_STRING, \ + .help =3D helpstr, \ + } + +#define BLOCK_CRYPTO_OPT_QCOW_KEY_SECRET "key-secret" + +#define BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET(prefix) \ + BLOCK_CRYPTO_OPT_DEF_KEY_SECRET(prefix, \ + "ID of the secret that provides the AES encryption key") + #define BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET "key-secret" #define BLOCK_CRYPTO_OPT_LUKS_CIPHER_ALG "cipher-alg" #define BLOCK_CRYPTO_OPT_LUKS_CIPHER_MODE "cipher-mode" @@ -30,11 +43,8 @@ #define BLOCK_CRYPTO_OPT_LUKS_ITER_TIME "iter-time" =20 #define BLOCK_CRYPTO_OPT_DEF_LUKS_KEY_SECRET(prefix) \ - { \ - .name =3D prefix BLOCK_CRYPTO_OPT_LUKS_KEY_SECRET, \ - .type =3D QEMU_OPT_STRING, \ - .help =3D "ID of the secret that provides the keyslot passphrase",= \ - } + BLOCK_CRYPTO_OPT_DEF_KEY_SECRET(prefix, \ + "ID of the secret that provides the keyslot passphrase") =20 #define BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG(prefix) \ { \ diff --git a/block/qcow.c b/block/qcow.c index 3a3dbf9..db0c5a9 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -31,8 +31,10 @@ #include "qemu/bswap.h" #include #include "qapi/qmp/qerror.h" -#include "crypto/cipher.h" +#include "qapi/qmp/qstring.h" +#include "crypto/block.h" #include "migration/blocker.h" +#include "block/crypto.h" =20 /**************************************************************/ /* QEMU COW block driver with compression and encryption support */ @@ -77,7 +79,7 @@ typedef struct BDRVQcowState { uint8_t *cluster_cache; uint8_t *cluster_data; uint64_t cluster_cache_offset; - QCryptoCipher *cipher; /* NULL if no key yet */ + QCryptoBlock *crypto; /* Disk encryption format driver */ uint32_t crypt_method_header; CoMutex lock; Error *migration_blocker; @@ -97,6 +99,15 @@ static int qcow_probe(const uint8_t *buf, int buf_size, = const char *filename) return 0; } =20 +static QemuOptsList qcow_runtime_opts =3D { + .name =3D "qcow", + .head =3D QTAILQ_HEAD_INITIALIZER(qcow_runtime_opts.head), + .desc =3D { + BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET("encrypt."), + { /* end of list */ } + }, +}; + static int qcow_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) { @@ -105,11 +116,19 @@ static int qcow_open(BlockDriverState *bs, QDict *opt= ions, int flags, int ret; QCowHeader header; Error *local_err =3D NULL; + QCryptoBlockOpenOptions *crypto_opts =3D NULL; + unsigned int cflags =3D 0; + QDict *encryptopts =3D NULL; + const char *encryptfmt; + + qdict_extract_subqdict(options, &encryptopts, "encrypt."); + encryptfmt =3D qdict_get_try_str(encryptopts, "format"); =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); if (!bs->file) { - return -EINVAL; + ret =3D -EINVAL; + goto fail; } =20 ret =3D bdrv_pread(bs->file, 0, &header, sizeof(header)); @@ -155,17 +174,6 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, int flags, goto fail; } =20 - if (header.crypt_method > QCOW_CRYPT_AES) { - error_setg(errp, "invalid encryption method in qcow header"); - ret =3D -EINVAL; - goto fail; - } - if (!qcrypto_cipher_supports(QCRYPTO_CIPHER_ALG_AES_128, - QCRYPTO_CIPHER_MODE_CBC)) { - error_setg(errp, "AES cipher not available"); - ret =3D -EINVAL; - goto fail; - } s->crypt_method_header =3D header.crypt_method; if (s->crypt_method_header) { if (bdrv_uses_whitelist() && @@ -181,8 +189,38 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, int flags, ret =3D -ENOSYS; goto fail; } + if (s->crypt_method_header =3D=3D QCOW_CRYPT_AES) { + if (encryptfmt && !g_str_equal(encryptfmt, "aes")) { + error_setg(errp, + "Header reported 'aes' encryption format but " + "options specify '%s'", encryptfmt); + ret =3D -EINVAL; + goto fail; + } + qdict_del(encryptopts, "format"); + crypto_opts =3D block_crypto_open_opts_init( + Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + if (!crypto_opts) { + ret =3D -EINVAL; + goto fail; + } =20 + if (flags & BDRV_O_NO_IO) { + cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; + } + s->crypto =3D qcrypto_block_open(crypto_opts, NULL, NULL, + cflags, errp); + if (!s->crypto) { + ret =3D -EINVAL; + goto fail; + } + } else { + error_setg(errp, "invalid encryption method in qcow header"); + ret =3D -EINVAL; + goto fail; + } bs->encrypted =3D true; + bs->valid_key =3D true; } s->cluster_bits =3D header.cluster_bits; s->cluster_size =3D 1 << s->cluster_bits; @@ -266,6 +304,8 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, goto fail; } =20 + QDECREF(encryptopts); + qapi_free_QCryptoBlockOpenOptions(crypto_opts); qemu_co_mutex_init(&s->lock); return 0; =20 @@ -274,6 +314,9 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, qemu_vfree(s->l2_cache); g_free(s->cluster_cache); g_free(s->cluster_data); + qcrypto_block_free(s->crypto); + QDECREF(encryptopts); + qapi_free_QCryptoBlockOpenOptions(crypto_opts); return ret; } =20 @@ -286,81 +329,6 @@ static int qcow_reopen_prepare(BDRVReopenState *state, return 0; } =20 -static int qcow_set_key(BlockDriverState *bs, const char *key) -{ - BDRVQcowState *s =3D bs->opaque; - uint8_t keybuf[16]; - int len, i; - Error *err; - - memset(keybuf, 0, 16); - len =3D strlen(key); - if (len > 16) - len =3D 16; - /* XXX: we could compress the chars to 7 bits to increase - entropy */ - for(i =3D 0;i < len;i++) { - keybuf[i] =3D key[i]; - } - assert(bs->encrypted); - - qcrypto_cipher_free(s->cipher); - s->cipher =3D qcrypto_cipher_new( - QCRYPTO_CIPHER_ALG_AES_128, - QCRYPTO_CIPHER_MODE_CBC, - keybuf, G_N_ELEMENTS(keybuf), - &err); - - if (!s->cipher) { - /* XXX would be nice if errors in this method could - * be properly propagate to the caller. Would need - * the bdrv_set_key() API signature to be fixed. */ - error_free(err); - return -1; - } - return 0; -} - -/* The crypt function is compatible with the linux cryptoloop - algorithm for < 4 GB images. */ -static int encrypt_sectors(BDRVQcowState *s, int64_t sector_num, - uint8_t *buf, int nb_sectors, bool enc, - Error **errp) -{ - union { - uint64_t ll[2]; - uint8_t b[16]; - } ivec; - int i; - int ret; - - for(i =3D 0; i < nb_sectors; i++) { - ivec.ll[0] =3D cpu_to_le64(sector_num); - ivec.ll[1] =3D 0; - if (qcrypto_cipher_setiv(s->cipher, - ivec.b, G_N_ELEMENTS(ivec.b), - errp) < 0) { - return -1; - } - if (enc) { - ret =3D qcrypto_cipher_encrypt(s->cipher, - buf, buf, - 512, - errp); - } else { - ret =3D qcrypto_cipher_decrypt(s->cipher, - buf, buf, - 512, - errp); - } - if (ret < 0) { - return -1; - } - sector_num++; - buf +=3D 512; - } - return 0; -} =20 /* 'allocate' is: * @@ -475,15 +443,16 @@ static uint64_t get_cluster_offset(BlockDriverState *= bs, if (bs->encrypted && (n_end - n_start) < s->cluster_sectors) { uint64_t start_sect; - assert(s->cipher); + assert(s->crypto); start_sect =3D (offset & ~(s->cluster_size - 1)) >> 9; for(i =3D 0; i < s->cluster_sectors; i++) { if (i < n_start || i >=3D n_end) { Error *err =3D NULL; memset(s->cluster_data, 0x00, 512); - if (encrypt_sectors(s, start_sect + i, - s->cluster_data, 1, - true, &err) < 0) { + if (qcrypto_block_encrypt(s->crypto, start_sec= t + i, + s->cluster_data, + BDRV_SECTOR_SIZE, + &err) < 0) { error_free(err); errno =3D EIO; return -1; @@ -528,7 +497,7 @@ static int64_t coroutine_fn qcow_co_get_block_status(Bl= ockDriverState *bs, if (!cluster_offset) { return 0; } - if ((cluster_offset & QCOW_OFLAG_COMPRESSED) || s->cipher) { + if ((cluster_offset & QCOW_OFLAG_COMPRESSED) || s->crypto) { return BDRV_BLOCK_DATA; } cluster_offset |=3D (index_in_cluster << BDRV_SECTOR_BITS); @@ -659,9 +628,9 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, break; } if (bs->encrypted) { - assert(s->cipher); - if (encrypt_sectors(s, sector_num, buf, - n, false, &err) < 0) { + assert(s->crypto); + if (qcrypto_block_decrypt(s->crypto, sector_num, buf, + n * BDRV_SECTOR_SIZE, &err) < 0)= { goto fail; } } @@ -734,8 +703,9 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, } if (bs->encrypted) { Error *err =3D NULL; - assert(s->cipher); - if (encrypt_sectors(s, sector_num, buf, n, true, &err) < 0) { + assert(s->crypto); + if (qcrypto_block_encrypt(s->crypto, sector_num, buf, + n * BDRV_SECTOR_SIZE, &err) < 0) { error_free(err); ret =3D -EIO; break; @@ -770,8 +740,8 @@ static void qcow_close(BlockDriverState *bs) { BDRVQcowState *s =3D bs->opaque; =20 - qcrypto_cipher_free(s->cipher); - s->cipher =3D NULL; + qcrypto_block_free(s->crypto); + s->crypto =3D NULL; g_free(s->l1_table); qemu_vfree(s->l2_cache); g_free(s->cluster_cache); @@ -792,6 +762,10 @@ static int qcow_create(const char *filename, QemuOpts = *opts, Error **errp) int ret; BlockBackend *qcow_blk; const char *encryptfmt =3D NULL; + QDict *options; + QDict *encryptopts =3D NULL; + QCryptoBlockCreateOptions *crypto_opts =3D NULL; + QCryptoBlock *crypto =3D NULL; =20 /* Read out options */ total_size =3D ROUND_UP(qemu_opt_get_size_del(opts, BLOCK_OPT_SIZE, 0), @@ -866,6 +840,10 @@ static int qcow_create(const char *filename, QemuOpts = *opts, Error **errp) l1_size =3D (total_size + (1LL << shift) - 1) >> shift; =20 header.l1_table_offset =3D cpu_to_be64(header_size); + + options =3D qemu_opts_to_qdict(opts, NULL); + qdict_extract_subqdict(options, &encryptopts, "encrypt."); + QDECREF(options); if (encryptfmt) { if (!g_str_equal(encryptfmt, "aes")) { error_setg(errp, "Unknown encryption format '%s', expected 'ae= s'", @@ -874,6 +852,19 @@ static int qcow_create(const char *filename, QemuOpts = *opts, Error **errp) goto exit; } header.crypt_method =3D cpu_to_be32(QCOW_CRYPT_AES); + + crypto_opts =3D block_crypto_create_opts_init( + Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + if (!crypto_opts) { + ret =3D -EINVAL; + goto exit; + } + + crypto =3D qcrypto_block_create(crypto_opts, NULL, NULL, NULL, err= p); + if (!crypto) { + ret =3D -EINVAL; + goto exit; + } } else { header.crypt_method =3D cpu_to_be32(QCOW_CRYPT_NONE); } @@ -908,6 +899,9 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) exit: blk_unref(qcow_blk); cleanup: + QDECREF(encryptopts); + qcrypto_block_free(crypto); + qapi_free_QCryptoBlockCreateOptions(crypto_opts); g_free(backing_file); return ret; } @@ -1054,6 +1048,7 @@ static QemuOptsList qcow_create_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "Encrypt the image, format choices: 'aes'", }, + BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET("encrypt."), { /* end of list */ } } }; @@ -1074,7 +1069,6 @@ static BlockDriver bdrv_qcow =3D { .bdrv_co_writev =3D qcow_co_writev, .bdrv_co_get_block_status =3D qcow_co_get_block_status, =20 - .bdrv_set_key =3D qcow_set_key, .bdrv_make_empty =3D qcow_make_empty, .bdrv_co_pwritev_compressed =3D qcow_co_pwritev_compressed, .bdrv_get_info =3D qcow_get_info, diff --git a/qapi/block-core.json b/qapi/block-core.json index f85c223..c4b7e6e 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2282,6 +2282,42 @@ 'mode': 'Qcow2OverlapCheckMode' } } =20 ## +# @BlockdevQcowEncryptionFormat: +# +# @aes: AES-CBC with plain64 initialization vectors +# +# Since: 2.10 +## +{ 'enum': 'BlockdevQcowEncryptionFormat', + 'data': [ 'aes' ] } + +## +# @BlockdevQcowEncryption: +# +# Since: 2.10 +## +{ 'union': 'BlockdevQcowEncryption', + 'base': { 'format': 'BlockdevQcowEncryptionFormat' }, + 'discriminator': 'format', + 'data': { 'aes': 'QCryptoBlockOptionsQCow' } } + +## +# @BlockdevOptionsQcow: +# +# Driver specific block device options for qcow. +# +# @encrypt: Image decryption options. Mandatory for +# encrypted images, except when doing a metadata-o= nly +# probe of the image. +# +# Since: 2.10 +## +{ 'struct': 'BlockdevOptionsQcow', + 'base': 'BlockdevOptionsGenericCOWFormat', + 'data': { '*encrypt': 'BlockdevQcowEncryption' } } + + +## # @BlockdevOptionsQcow2: # # Driver specific block device options for qcow2. @@ -2976,7 +3012,7 @@ 'null-co': 'BlockdevOptionsNull', 'parallels': 'BlockdevOptionsGenericFormat', 'qcow2': 'BlockdevOptionsQcow2', - 'qcow': 'BlockdevOptionsGenericCOWFormat', + 'qcow': 'BlockdevOptionsQcow', 'qed': 'BlockdevOptionsGenericCOWFormat', 'quorum': 'BlockdevOptionsQuorum', 'raw': 'BlockdevOptionsRaw', --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499448549767536.0202908503221; Fri, 7 Jul 2017 10:29:09 -0700 (PDT) Received: from localhost ([::1]:57801 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX40-0005aL-Gc for importer@patchew.org; Fri, 07 Jul 2017 13:29:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42497) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWls-0005rc-Vc for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlr-00008p-DX for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50472) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlk-0008WV-M3; Fri, 07 Jul 2017 13:10:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B6FDD7CE06; Fri, 7 Jul 2017 17:10:15 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFBF317140; Fri, 7 Jul 2017 17:10:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B6FDD7CE06 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B6FDD7CE06 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:05 +0200 Message-Id: <1499447335-6125-51-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:10:15 +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] [PULL 050/100] qcow2: make qcow2_encrypt_sectors encrypt in place 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Instead of requiring separate input/output buffers for encrypting data, change qcow2_encrypt_sectors() to assume use of a single buffer, encrypting in place. The current callers all used the same buffer for input/output already. Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-11-berrange@redhat.com Reviewed-by: Alberto Garcia Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 17 ++++++----------- block/qcow2.c | 4 ++-- block/qcow2.h | 3 +-- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 3d341fd..a570929 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -358,11 +358,9 @@ static int count_contiguous_clusters_unallocated(int n= b_clusters, } =20 /* The crypt function is compatible with the linux cryptoloop - algorithm for < 4 GB images. NOTE: out_buf =3D=3D in_buf is - supported */ + algorithm for < 4 GB images. */ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, - uint8_t *out_buf, const uint8_t *in_buf, - int nb_sectors, bool enc, + uint8_t *buf, int nb_sectors, bool enc, Error **errp) { union { @@ -382,14 +380,12 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t = sector_num, } if (enc) { ret =3D qcrypto_cipher_encrypt(s->cipher, - in_buf, - out_buf, + buf, buf, 512, errp); } else { ret =3D qcrypto_cipher_decrypt(s->cipher, - in_buf, - out_buf, + buf, buf, 512, errp); } @@ -397,8 +393,7 @@ int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t se= ctor_num, return -1; } sector_num++; - in_buf +=3D 512; - out_buf +=3D 512; + buf +=3D 512; } return 0; } @@ -446,7 +441,7 @@ static bool coroutine_fn do_perform_cow_encrypt(BlockDr= iverState *bs, assert(s->cipher); assert((offset_in_cluster & ~BDRV_SECTOR_MASK) =3D=3D 0); assert((bytes & ~BDRV_SECTOR_MASK) =3D=3D 0); - if (qcow2_encrypt_sectors(s, sector, buffer, buffer, + if (qcow2_encrypt_sectors(s, sector, buffer, bytes >> BDRV_SECTOR_BITS, true, NULL) <= 0) { return false; } diff --git a/block/qcow2.c b/block/qcow2.c index 8f1822c..df9caa8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1543,7 +1543,7 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); Error *err =3D NULL; if (qcow2_encrypt_sectors(s, offset >> BDRV_SECTOR_BITS, - cluster_data, cluster_data, + cluster_data, cur_bytes >> BDRV_SECTOR_BITS, false, &err) < 0) { error_free(err); @@ -1677,7 +1677,7 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverS= tate *bs, uint64_t offset, qemu_iovec_to_buf(&hd_qiov, 0, cluster_data, hd_qiov.size); =20 if (qcow2_encrypt_sectors(s, offset >> BDRV_SECTOR_BITS, - cluster_data, cluster_data, + cluster_data, cur_bytes >>BDRV_SECTOR_BITS, true, &err) < 0) { error_free(err); diff --git a/block/qcow2.h b/block/qcow2.h index 87b15eb..5a3f07e 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -545,8 +545,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t = min_size, int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index); int qcow2_decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset= ); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, - uint8_t *out_buf, const uint8_t *in_buf, - int nb_sectors, bool enc, Error **errp); + uint8_t *buf, int nb_sectors, bool enc, Error **= errp); =20 int qcow2_get_cluster_offset(BlockDriverState *bs, uint64_t offset, unsigned int *bytes, uint64_t *cluster_offset= ); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449188024240.0295726197545; Fri, 7 Jul 2017 10:39:48 -0700 (PDT) Received: from localhost ([::1]:57855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXEH-0006qb-7b for importer@patchew.org; Fri, 07 Jul 2017 13:39:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm5-000651-Gl for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlx-0000C5-2p for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56936) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWll-00005X-Uk; Fri, 07 Jul 2017 13:10:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EF639804F0; Fri, 7 Jul 2017 17:10:16 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EF4161F23; Fri, 7 Jul 2017 17:10:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EF639804F0 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EF639804F0 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:06 +0200 Message-Id: <1499447335-6125-52-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:17 +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] [PULL 051/100] qcow2: convert QCow2 to use QCryptoBlock for encryption 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-devel@nongnu.org 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" From: "Daniel P. Berrange" This converts the qcow2 driver to make use of the QCryptoBlock APIs for encrypting image content, using the legacy QCow2 AES scheme. With this change it is now required to use the QCryptoSecret object for providing passwords, instead of the current block password APIs / interactive prompting. $QEMU \ -object secret,id=3Dsec0,file=3D/home/berrange/encrypted.pw \ -drive file=3D/home/berrange/encrypted.qcow2,encrypt.key-secret=3Dsec0 The test 087 could be simplified since there is no longer a difference in behaviour when using blockdev_add with encrypted images for the running vs stopped CPU state. Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-12-berrange@redhat.com Reviewed-by: Alberto Garcia Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 47 +--------- block/qcow2.c | 226 ++++++++++++++++++++++++++++++-----------= ---- block/qcow2.h | 5 +- qapi/block-core.json | 27 +++++- tests/qemu-iotests/049 | 2 +- tests/qemu-iotests/049.out | 4 +- tests/qemu-iotests/082.out | 27 ++++++ tests/qemu-iotests/087 | 28 +++--- tests/qemu-iotests/087.out | 12 +-- tests/qemu-iotests/134 | 18 +++- tests/qemu-iotests/134.out | 10 +- tests/qemu-iotests/158 | 19 ++-- tests/qemu-iotests/158.out | 14 +-- tests/qemu-iotests/common | 10 +- 14 files changed, 263 insertions(+), 186 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a570929..71a5e0d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -357,47 +357,6 @@ static int count_contiguous_clusters_unallocated(int n= b_clusters, return i; } =20 -/* The crypt function is compatible with the linux cryptoloop - algorithm for < 4 GB images. */ -int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, - uint8_t *buf, int nb_sectors, bool enc, - Error **errp) -{ - union { - uint64_t ll[2]; - uint8_t b[16]; - } ivec; - int i; - int ret; - - for(i =3D 0; i < nb_sectors; i++) { - ivec.ll[0] =3D cpu_to_le64(sector_num); - ivec.ll[1] =3D 0; - if (qcrypto_cipher_setiv(s->cipher, - ivec.b, G_N_ELEMENTS(ivec.b), - errp) < 0) { - return -1; - } - if (enc) { - ret =3D qcrypto_cipher_encrypt(s->cipher, - buf, buf, - 512, - errp); - } else { - ret =3D qcrypto_cipher_decrypt(s->cipher, - buf, buf, - 512, - errp); - } - if (ret < 0) { - return -1; - } - sector_num++; - buf +=3D 512; - } - return 0; -} - static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, uint64_t src_cluster_offset, unsigned offset_in_cluster, @@ -438,11 +397,11 @@ static bool coroutine_fn do_perform_cow_encrypt(Block= DriverState *bs, BDRVQcow2State *s =3D bs->opaque; int64_t sector =3D (src_cluster_offset + offset_in_cluster) >> BDRV_SECTOR_BITS; - assert(s->cipher); assert((offset_in_cluster & ~BDRV_SECTOR_MASK) =3D=3D 0); assert((bytes & ~BDRV_SECTOR_MASK) =3D=3D 0); - if (qcow2_encrypt_sectors(s, sector, buffer, - bytes >> BDRV_SECTOR_BITS, true, NULL) <= 0) { + assert(s->crypto); + if (qcrypto_block_encrypt(s->crypto, sector, buffer, + bytes, NULL) < 0) { return false; } } diff --git a/block/qcow2.c b/block/qcow2.c index df9caa8..1c66ec1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -37,6 +37,9 @@ #include "qemu/option_int.h" #include "qemu/cutils.h" #include "qemu/bswap.h" +#include "qapi/opts-visitor.h" +#include "qapi-visit.h" +#include "block/crypto.h" =20 /* Differences with QCOW: @@ -461,6 +464,7 @@ static QemuOptsList qcow2_runtime_opts =3D { .type =3D QEMU_OPT_NUMBER, .help =3D "Clean unused cache entries after this time (in seco= nds)", }, + BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET("encrypt."), { /* end of list */ } }, }; @@ -585,6 +589,7 @@ typedef struct Qcow2ReopenState { int overlap_check; bool discard_passthrough[QCOW2_DISCARD_MAX]; uint64_t cache_clean_interval; + QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime optio= ns */ } Qcow2ReopenState; =20 static int qcow2_update_options_prepare(BlockDriverState *bs, @@ -598,9 +603,14 @@ static int qcow2_update_options_prepare(BlockDriverSta= te *bs, int overlap_check_template =3D 0; uint64_t l2_cache_size, refcount_cache_size; int i; + const char *encryptfmt; + QDict *encryptopts =3D NULL; Error *local_err =3D NULL; int ret; =20 + qdict_extract_subqdict(options, &encryptopts, "encrypt."); + encryptfmt =3D qdict_get_try_str(encryptopts, "format"); + opts =3D qemu_opts_create(&qcow2_runtime_opts, NULL, 0, &error_abort); qemu_opts_absorb_qdict(opts, options, &local_err); if (local_err) { @@ -751,8 +761,42 @@ static int qcow2_update_options_prepare(BlockDriverSta= te *bs, r->discard_passthrough[QCOW2_DISCARD_OTHER] =3D qemu_opt_get_bool(opts, QCOW2_OPT_DISCARD_OTHER, false); =20 + switch (s->crypt_method_header) { + case QCOW_CRYPT_NONE: + if (encryptfmt) { + error_setg(errp, "No encryption in image header, but options " + "specified format '%s'", encryptfmt); + ret =3D -EINVAL; + goto fail; + } + break; + + case QCOW_CRYPT_AES: + if (encryptfmt && !g_str_equal(encryptfmt, "aes")) { + error_setg(errp, + "Header reported 'aes' encryption format but " + "options specify '%s'", encryptfmt); + ret =3D -EINVAL; + goto fail; + } + qdict_del(encryptopts, "format"); + r->crypto_opts =3D block_crypto_open_opts_init( + Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + break; + + default: + error_setg(errp, "Unsupported encryption method %d", + s->crypt_method_header); + break; + } + if (s->crypt_method_header !=3D QCOW_CRYPT_NONE && !r->crypto_opts) { + ret =3D -EINVAL; + goto fail; + } + ret =3D 0; fail: + QDECREF(encryptopts); qemu_opts_del(opts); opts =3D NULL; return ret; @@ -785,6 +829,9 @@ static void qcow2_update_options_commit(BlockDriverStat= e *bs, s->cache_clean_interval =3D r->cache_clean_interval; cache_clean_timer_init(bs, bdrv_get_aio_context(bs)); } + + qapi_free_QCryptoBlockOpenOptions(s->crypto_opts); + s->crypto_opts =3D r->crypto_opts; } =20 static void qcow2_update_options_abort(BlockDriverState *bs, @@ -796,6 +843,7 @@ static void qcow2_update_options_abort(BlockDriverState= *bs, if (r->refcount_block_cache) { qcow2_cache_destroy(bs, r->refcount_block_cache); } + qapi_free_QCryptoBlockOpenOptions(r->crypto_opts); } =20 static int qcow2_update_options(BlockDriverState *bs, QDict *options, @@ -967,12 +1015,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, ret =3D -EINVAL; goto fail; } - if (!qcrypto_cipher_supports(QCRYPTO_CIPHER_ALG_AES_128, - QCRYPTO_CIPHER_MODE_CBC)) { - error_setg(errp, "AES cipher not available"); - ret =3D -EINVAL; - goto fail; - } s->crypt_method_header =3D header.crypt_method; if (s->crypt_method_header) { if (bdrv_uses_whitelist() && @@ -990,6 +1032,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *= options, int flags, } =20 bs->encrypted =3D true; + bs->valid_key =3D true; } =20 s->l2_bits =3D s->cluster_bits - 3; /* L2 is always one cluster */ @@ -1122,6 +1165,19 @@ static int qcow2_do_open(BlockDriverState *bs, QDict= *options, int flags, goto fail; } =20 + if (s->crypt_method_header =3D=3D QCOW_CRYPT_AES) { + unsigned int cflags =3D 0; + if (flags & BDRV_O_NO_IO) { + cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; + } + s->crypto =3D qcrypto_block_open(s->crypto_opts, NULL, NULL, + cflags, errp); + if (!s->crypto) { + ret =3D -EINVAL; + goto fail; + } + } + /* read the backing file name */ if (header.backing_file_offset !=3D 0) { len =3D header.backing_file_size; @@ -1202,6 +1258,8 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, } g_free(s->cluster_cache); qemu_vfree(s->cluster_data); + qcrypto_block_free(s->crypto); + qapi_free_QCryptoBlockOpenOptions(s->crypto_opts); return ret; } =20 @@ -1229,41 +1287,6 @@ static void qcow2_refresh_limits(BlockDriverState *b= s, Error **errp) bs->bl.pdiscard_alignment =3D s->cluster_size; } =20 -static int qcow2_set_key(BlockDriverState *bs, const char *key) -{ - BDRVQcow2State *s =3D bs->opaque; - uint8_t keybuf[16]; - int len, i; - Error *err =3D NULL; - - memset(keybuf, 0, 16); - len =3D strlen(key); - if (len > 16) - len =3D 16; - /* XXX: we could compress the chars to 7 bits to increase - entropy */ - for(i =3D 0;i < len;i++) { - keybuf[i] =3D key[i]; - } - assert(bs->encrypted); - - qcrypto_cipher_free(s->cipher); - s->cipher =3D qcrypto_cipher_new( - QCRYPTO_CIPHER_ALG_AES_128, - QCRYPTO_CIPHER_MODE_CBC, - keybuf, G_N_ELEMENTS(keybuf), - &err); - - if (!s->cipher) { - /* XXX would be nice if errors in this method could - * be properly propagate to the caller. Would need - * the bdrv_set_key() API signature to be fixed. */ - error_free(err); - return -1; - } - return 0; -} - static int qcow2_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) { @@ -1379,7 +1402,7 @@ static int64_t coroutine_fn qcow2_co_get_block_status= (BlockDriverState *bs, *pnum =3D bytes >> BDRV_SECTOR_BITS; =20 if (cluster_offset !=3D 0 && ret !=3D QCOW2_CLUSTER_COMPRESSED && - !s->cipher) { + !s->crypto) { index_in_cluster =3D sector_num & (s->cluster_sectors - 1); cluster_offset |=3D (index_in_cluster << BDRV_SECTOR_BITS); *file =3D bs->file->bs; @@ -1436,7 +1459,7 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, =20 /* prepare next request */ cur_bytes =3D MIN(bytes, INT_MAX); - if (s->cipher) { + if (s->crypto) { cur_bytes =3D MIN(cur_bytes, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); } @@ -1506,7 +1529,7 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, } =20 if (bs->encrypted) { - assert(s->cipher); + assert(s->crypto); =20 /* * For encrypted images, read everything into a temporary @@ -1538,14 +1561,15 @@ static coroutine_fn int qcow2_co_preadv(BlockDriver= State *bs, uint64_t offset, goto fail; } if (bs->encrypted) { - assert(s->cipher); + assert(s->crypto); assert((offset & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); Error *err =3D NULL; - if (qcow2_encrypt_sectors(s, offset >> BDRV_SECTOR_BITS, + if (qcrypto_block_decrypt(s->crypto, + offset >> BDRV_SECTOR_BITS, cluster_data, - cur_bytes >> BDRV_SECTOR_BITS, - false, &err) < 0) { + cur_bytes, + &err) < 0) { error_free(err); ret =3D -EIO; goto fail; @@ -1661,7 +1685,7 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriverS= tate *bs, uint64_t offset, =20 if (bs->encrypted) { Error *err =3D NULL; - assert(s->cipher); + assert(s->crypto); if (!cluster_data) { cluster_data =3D qemu_try_blockalign(bs->file->bs, QCOW_MAX_CRYPT_CLUSTERS @@ -1676,10 +1700,9 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriver= State *bs, uint64_t offset, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); qemu_iovec_to_buf(&hd_qiov, 0, cluster_data, hd_qiov.size); =20 - if (qcow2_encrypt_sectors(s, offset >> BDRV_SECTOR_BITS, + if (qcrypto_block_encrypt(s->crypto, offset >> BDRV_SECTOR_BIT= S, cluster_data, - cur_bytes >>BDRV_SECTOR_BITS, - true, &err) < 0) { + cur_bytes, &err) < 0) { error_free(err); ret =3D -EIO; goto fail; @@ -1804,8 +1827,8 @@ static void qcow2_close(BlockDriverState *bs) qcow2_cache_destroy(bs, s->l2_table_cache); qcow2_cache_destroy(bs, s->refcount_block_cache); =20 - qcrypto_cipher_free(s->cipher); - s->cipher =3D NULL; + qcrypto_block_free(s->crypto); + s->crypto =3D NULL; =20 g_free(s->unknown_header_fields); cleanup_unknown_header_ext(bs); @@ -1823,7 +1846,7 @@ static void qcow2_invalidate_cache(BlockDriverState *= bs, Error **errp) { BDRVQcow2State *s =3D bs->opaque; int flags =3D s->flags; - QCryptoCipher *cipher =3D NULL; + QCryptoBlock *crypto =3D NULL; QDict *options; Error *local_err =3D NULL; int ret; @@ -1833,8 +1856,8 @@ static void qcow2_invalidate_cache(BlockDriverState *= bs, Error **errp) * that means we don't have to worry about reopening them here. */ =20 - cipher =3D s->cipher; - s->cipher =3D NULL; + crypto =3D s->crypto; + s->crypto =3D NULL; =20 qcow2_close(bs); =20 @@ -1855,7 +1878,7 @@ static void qcow2_invalidate_cache(BlockDriverState *= bs, Error **errp) return; } =20 - s->cipher =3D cipher; + s->crypto =3D crypto; } =20 static size_t header_ext_add(char *buf, uint32_t magic, const void *s, @@ -2079,6 +2102,56 @@ static int qcow2_change_backing_file(BlockDriverStat= e *bs, return qcow2_update_header(bs); } =20 + +static int qcow2_set_up_encryption(BlockDriverState *bs, const char *encry= ptfmt, + QemuOpts *opts, Error **errp) +{ + BDRVQcow2State *s =3D bs->opaque; + QCryptoBlockCreateOptions *cryptoopts =3D NULL; + QCryptoBlock *crypto =3D NULL; + int ret =3D -EINVAL; + QDict *options, *encryptopts; + + options =3D qemu_opts_to_qdict(opts, NULL); + qdict_extract_subqdict(options, &encryptopts, "encrypt."); + QDECREF(options); + + if (!g_str_equal(encryptfmt, "aes")) { + error_setg(errp, "Unknown encryption format '%s', expected 'aes'", + encryptfmt); + ret =3D -EINVAL; + goto out; + } + cryptoopts =3D block_crypto_create_opts_init( + Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + if (!cryptoopts) { + ret =3D -EINVAL; + goto out; + } + s->crypt_method_header =3D QCOW_CRYPT_AES; + + crypto =3D qcrypto_block_create(cryptoopts, + NULL, NULL, + bs, errp); + if (!crypto) { + ret =3D -EINVAL; + goto out; + } + + ret =3D qcow2_update_header(bs); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not write encryption header"); + goto out; + } + + out: + QDECREF(encryptopts); + qcrypto_block_free(crypto); + qapi_free_QCryptoBlockCreateOptions(cryptoopts); + return ret; +} + + static int preallocate(BlockDriverState *bs) { uint64_t bytes; @@ -2273,17 +2346,8 @@ static int qcow2_create2(const char *filename, int64= _t total_size, .header_length =3D cpu_to_be32(sizeof(*header)), }; =20 - if (encryptfmt) { - if (!g_str_equal(encryptfmt, "aes")) { - error_setg(errp, "Unknown encryption format '%s', expected 'ae= s'", - encryptfmt); - ret =3D -EINVAL; - goto out; - } - header->crypt_method =3D cpu_to_be32(QCOW_CRYPT_AES); - } else { - header->crypt_method =3D cpu_to_be32(QCOW_CRYPT_NONE); - } + /* We'll update this to correct value later */ + header->crypt_method =3D cpu_to_be32(QCOW_CRYPT_NONE); =20 if (flags & BLOCK_FLAG_LAZY_REFCOUNTS) { header->compatible_features |=3D @@ -2362,6 +2426,14 @@ static int qcow2_create2(const char *filename, int64= _t total_size, } } =20 + /* Want encryption? There you go. */ + if (encryptfmt) { + ret =3D qcow2_set_up_encryption(blk_bs(blk), encryptfmt, opts, err= p); + if (ret < 0) { + goto out; + } + } + /* And if we're supposed to preallocate metadata, do that now */ if (prealloc !=3D PREALLOC_MODE_OFF) { BDRVQcow2State *s =3D blk_bs(blk)->opaque; @@ -2377,11 +2449,17 @@ static int qcow2_create2(const char *filename, int6= 4_t total_size, blk_unref(blk); blk =3D NULL; =20 - /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returni= ng */ + /* Reopen the image without BDRV_O_NO_FLUSH to flush it before returni= ng. + * Using BDRV_O_NO_IO, since encryption is now setup we don't want to + * have to setup decryption context. We're not doing any I/O on the top + * level BlockDriverState, only lower layers, where BDRV_O_NO_IO does + * not have effect. + */ options =3D qdict_new(); qdict_put_str(options, "driver", "qcow2"); blk =3D blk_new_open(filename, NULL, options, - BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err); + BDRV_O_RDWR | BDRV_O_NO_BACKING | BDRV_O_NO_IO, + &local_err); if (blk =3D=3D NULL) { error_propagate(errp, local_err); ret =3D -EIO; @@ -3226,9 +3304,9 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, backing_format =3D qemu_opt_get(opts, BLOCK_OPT_BACKING_FMT); } else if (!strcmp(desc->name, BLOCK_OPT_ENCRYPT)) { encrypt =3D qemu_opt_get_bool(opts, BLOCK_OPT_ENCRYPT, - !!s->cipher); + !!s->crypto); =20 - if (encrypt !=3D !!s->cipher) { + if (encrypt !=3D !!s->crypto) { error_report("Changing the encryption flag is not supporte= d"); return -ENOTSUP; } @@ -3454,6 +3532,7 @@ static QemuOptsList qcow2_create_opts =3D { .type =3D QEMU_OPT_STRING, .help =3D "Encrypt the image, format choices: 'aes'", }, + BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET("encrypt."), { .name =3D BLOCK_OPT_CLUSTER_SIZE, .type =3D QEMU_OPT_SIZE, @@ -3496,7 +3575,6 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_create =3D qcow2_create, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, .bdrv_co_get_block_status =3D qcow2_co_get_block_status, - .bdrv_set_key =3D qcow2_set_key, =20 .bdrv_co_preadv =3D qcow2_co_preadv, .bdrv_co_pwritev =3D qcow2_co_pwritev, diff --git a/block/qcow2.h b/block/qcow2.h index 5a3f07e..4b89610 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -25,7 +25,7 @@ #ifndef BLOCK_QCOW2_H #define BLOCK_QCOW2_H =20 -#include "crypto/cipher.h" +#include "crypto/block.h" #include "qemu/coroutine.h" =20 //#define DEBUG_ALLOC @@ -257,7 +257,8 @@ typedef struct BDRVQcow2State { =20 CoMutex lock; =20 - QCryptoCipher *cipher; /* current cipher, NULL if no key yet */ + QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime optio= ns */ + QCryptoBlock *crypto; /* Disk encryption format driver */ uint32_t crypt_method_header; uint64_t snapshots_offset; int snapshots_size; diff --git a/qapi/block-core.json b/qapi/block-core.json index c4b7e6e..1f268ee 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2317,6 +2317,26 @@ 'data': { '*encrypt': 'BlockdevQcowEncryption' } } =20 =20 + +## +# @BlockdevQcow2EncryptionFormat: +# @aes: AES-CBC with plain64 initialization venctors +# +# Since: 2.10 +## +{ 'enum': 'BlockdevQcow2EncryptionFormat', + 'data': [ 'aes' ] } + +## +# @BlockdevQcow2Encryption: +# +# Since: 2.10 +## +{ 'union': 'BlockdevQcow2Encryption', + 'base': { 'format': 'BlockdevQcow2EncryptionFormat' }, + 'discriminator': 'format', + 'data': { 'aes': 'QCryptoBlockOptionsQCow' } } + ## # @BlockdevOptionsQcow2: # @@ -2351,6 +2371,9 @@ # @cache-clean-interval: clean unused entries in the L2 and refcount # caches. The interval is in seconds. The default = value # is 0 and it disables this feature (since 2.5) +# @encrypt: Image decryption options. Mandatory for +# encrypted images, except when doing a metadata-o= nly +# probe of the image. (since 2.10) # # Since: 2.9 ## @@ -2364,8 +2387,8 @@ '*cache-size': 'int', '*l2-cache-size': 'int', '*refcount-cache-size': 'int', - '*cache-clean-interval': 'int' } } - + '*cache-clean-interval': 'int', + '*encrypt': 'BlockdevQcow2Encryption' } } =20 ## # @BlockdevOptionsSsh: diff --git a/tests/qemu-iotests/049 b/tests/qemu-iotests/049 index fff0760..df35b6d 100755 --- a/tests/qemu-iotests/049 +++ b/tests/qemu-iotests/049 @@ -106,7 +106,7 @@ test_qemu_img create -f $IMGFMT -o preallocation=3D1234= "$TEST_IMG" 64M echo "=3D=3D Check encryption option =3D=3D" echo test_qemu_img create -f $IMGFMT -o encryption=3Doff "$TEST_IMG" 64M -test_qemu_img create -f $IMGFMT -o encryption=3Don "$TEST_IMG" 64M +test_qemu_img create -f $IMGFMT --object secret,id=3Dsec0,data=3D123456 -o= encryption=3Don,encrypt.key-secret=3Dsec0 "$TEST_IMG" 64M =20 echo "=3D=3D Check lazy_refcounts option (only with v3) =3D=3D" echo diff --git a/tests/qemu-iotests/049.out b/tests/qemu-iotests/049.out index 50e91c8..0032470 100644 --- a/tests/qemu-iotests/049.out +++ b/tests/qemu-iotests/049.out @@ -190,8 +190,8 @@ Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108= 864 cluster_size=3D65536 preall qemu-img create -f qcow2 -o encryption=3Doff TEST_DIR/t.qcow2 64M Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Dof= f cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 =20 -qemu-img create -f qcow2 -o encryption=3Don TEST_DIR/t.qcow2 64M -Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Don= cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 +qemu-img create -f qcow2 --object secret,id=3Dsec0,data=3D123456 -o encryp= tion=3Don,encrypt.key-secret=3Dsec0 TEST_DIR/t.qcow2 64M +Formatting 'TEST_DIR/t.qcow2', fmt=3Dqcow2 size=3D67108864 encryption=3Don= encrypt.key-secret=3Dsec0 cluster_size=3D65536 lazy_refcounts=3Doff refcou= nt_bits=3D16 =20 =3D=3D Check lazy_refcounts option (only with v3) =3D=3D =20 diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 621386b..3978db5 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -50,6 +50,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -64,6 +65,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -78,6 +80,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -92,6 +95,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -106,6 +110,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -120,6 +125,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -134,6 +140,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -148,6 +155,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -177,6 +185,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -240,6 +249,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -254,6 +264,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -268,6 +279,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -282,6 +294,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -296,6 +309,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -310,6 +324,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -324,6 +339,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -338,6 +354,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -367,6 +384,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -427,6 +445,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -441,6 +460,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -455,6 +475,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -469,6 +490,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -483,6 +505,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -497,6 +520,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -511,6 +535,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -525,6 +550,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -556,6 +582,7 @@ backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) encrypt.format Encrypt the image, format choices: 'aes' +encrypt.key-secret ID of the secret that provides the AES encryption key cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087 index 6d52f7d..1d595b2 100755 --- a/tests/qemu-iotests/087 +++ b/tests/qemu-iotests/087 @@ -122,24 +122,18 @@ echo echo =3D=3D=3D Encrypted image =3D=3D=3D echo =20 -_make_test_img -o encryption=3Don $size -run_qemu -S < Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1499449511789456.34252845513686; Fri, 7 Jul 2017 10:45:11 -0700 (PDT) Received: from localhost ([::1]:57891 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXJV-0003PV-FW for importer@patchew.org; Fri, 07 Jul 2017 13:45:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42471) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWlr-0005qL-PL for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlq-00008R-Bt for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41166) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWln-000062-3S; Fri, 07 Jul 2017 13:10:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2D12C61D2D; Fri, 7 Jul 2017 17:10:18 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4716062925; Fri, 7 Jul 2017 17:10:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2D12C61D2D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2D12C61D2D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:07 +0200 Message-Id: <1499447335-6125-53-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:10:18 +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] [PULL 052/100] qcow2: extend specification to cover LUKS encryption 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Update the qcow2 specification to describe how the LUKS header is placed inside a qcow2 file, when using LUKS encryption for the qcow2 payload instead of the legacy AES-CBC encryption Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-13-berrange@redhat.com Signed-off-by: Max Reitz --- docs/interop/qcow2.txt | 103 +++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 103 insertions(+) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index 80cdfd0..886a546 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -45,6 +45,7 @@ The first cluster of a qcow2 image contains the file head= er: 32 - 35: crypt_method 0 for no encryption 1 for AES encryption + 2 for LUKS encryption =20 36 - 39: l1_size Number of entries in the active L1 table @@ -135,6 +136,7 @@ be stored. Each extension has a structure like the foll= owing: 0xE2792ACA - Backing file format name 0x6803f857 - Feature name table 0x23852875 - Bitmaps extension + 0x0537be77 - Full disk encryption header pointer other - Unknown header extension, can be safe= ly ignored =20 @@ -207,6 +209,107 @@ The fields of the bitmaps extension are: Offset into the image file at which the bitmap directory starts. Must be aligned to a cluster boundary. =20 +=3D=3D Full disk encryption header pointer =3D=3D + +The full disk encryption header must be present if, and only if, the +'crypt_method' header requires metadata. Currently this is only true +of the 'LUKS' crypt method. The header extension must be absent for +other methods. + +This header provides the offset at which the crypt method can store +its additional data, as well as the length of such data. + + Byte 0 - 7: Offset into the image file at which the encryption + header starts in bytes. Must be aligned to a cluster + boundary. + Byte 8 - 15: Length of the written encryption header in bytes. + Note actual space allocated in the qcow2 file may + be larger than this value, since it will be rounded + to the nearest multiple of the cluster size. Any + unused bytes in the allocated space will be initialized + to 0. + +For the LUKS crypt method, the encryption header works as follows. + +The first 592 bytes of the header clusters will contain the LUKS +partition header. This is then followed by the key material data areas. +The size of the key material data areas is determined by the number of +stripes in the key slot and key size. Refer to the LUKS format +specification ('docs/on-disk-format.pdf' in the cryptsetup source +package) for details of the LUKS partition header format. + +In the LUKS partition header, the "payload-offset" field will be +calculated as normal for the LUKS spec. ie the size of the LUKS +header, plus key material regions, plus padding, relative to the +start of the LUKS header. This offset value is not required to be +qcow2 cluster aligned. Its value is currently never used in the +context of qcow2, since the qcow2 file format itself defines where +the real payload offset is, but none the less a valid payload offset +should always be present. + +In the LUKS key slots header, the "key-material-offset" is relative +to the start of the LUKS header clusters in the qcow2 container, +not the start of the qcow2 file. + +Logically the layout looks like + + +-----------------------------+ + | QCow2 header | + | QCow2 header extension X | + | QCow2 header extension FDE | + | QCow2 header extension ... | + | QCow2 header extension Z | + +-----------------------------+ + | ....other QCow2 tables.... | + . . + . . + +-----------------------------+ + | +-------------------------+ | + | | LUKS partition header | | + | +-------------------------+ | + | | LUKS key material 1 | | + | +-------------------------+ | + | | LUKS key material 2 | | + | +-------------------------+ | + | | LUKS key material ... | | + | +-------------------------+ | + | | LUKS key material 8 | | + | +-------------------------+ | + +-----------------------------+ + | QCow2 cluster payload | + . . + . . + . . + | | + +-----------------------------+ + +=3D=3D Data encryption =3D=3D + +When an encryption method is requested in the header, the image payload +data must be encrypted/decrypted on every write/read. The image headers +and metadata are never encrypted. + +The algorithms used for encryption vary depending on the method + + - AES: + + The AES cipher, in CBC mode, with 256 bit keys. + + Initialization vectors generated using plain64 method, with + the virtual disk sector as the input tweak. + + This format is no longer supported in QEMU system emulators, due + to a number of design flaws affecting its security. It is only + supported in the command line tools for the sake of back compatibility + and data liberation. + + - LUKS: + + The algorithms are specified in the LUKS header. + + Initialization vectors generated using the method specified + in the LUKS header, with the physical disk sector as the + input tweak. =20 =3D=3D Host cluster management =3D=3D =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449348899592.1710049804254; Fri, 7 Jul 2017 10:42:28 -0700 (PDT) Received: from localhost ([::1]:57873 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXGt-0000kt-88 for importer@patchew.org; Fri, 07 Jul 2017 13:42:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42884) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm9-00069U-4q for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm1-0000HT-7P for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54978) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlo-00006z-FF; Fri, 07 Jul 2017 13:10:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 740533680A; Fri, 7 Jul 2017 17:10:19 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 78F0A61F23; Fri, 7 Jul 2017 17:10:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 740533680A Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 740533680A From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:08 +0200 Message-Id: <1499447335-6125-54-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:10:19 +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] [PULL 053/100] qcow2: add support for LUKS encryption format 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-devel@nongnu.org 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" From: "Daniel P. Berrange" This adds support for using LUKS as an encryption format with the qcow2 file, using the new encrypt.format parameter to request "luks" format. e.g. # qemu-img create --object secret,data=3D123456,id=3Dsec0 \ -f qcow2 -o encrypt.format=3Dluks,encrypt.key-secret=3Dsec0 \ test.qcow2 10G The legacy "encryption=3Don" parameter still results in creation of the old qcow2 AES format (and is equivalent to the new 'encryption-format=3Daes'). e.g. the following are equivalent: # qemu-img create --object secret,data=3D123456,id=3Dsec0 \ -f qcow2 -o encryption=3Don,encrypt.key-secret=3Dsec0 \ test.qcow2 10G # qemu-img create --object secret,data=3D123456,id=3Dsec0 \ -f qcow2 -o encryption-format=3Daes,encrypt.key-secret=3Dsec0 \ test.qcow2 10G With the LUKS format it is necessary to store the LUKS partition header and key material in the QCow2 file. This data can be many MB in size, so cannot go into the QCow2 header region directly. Thus the spec defines a FDE (Full Disk Encryption) header extension that specifies the offset of a set of clusters to hold the FDE headers, as well as the length of that region. The LUKS header is thus stored in these extra allocated clusters before the main image payload. Aside from all the cryptographic differences implied by use of the LUKS format, there is one further key difference between the use of legacy AES and LUKS encryption in qcow2. For LUKS, the initialiazation vectors are generated using the host physical sector as the input, rather than the guest virtual sector. This guarantees unique initialization vectors for all sectors when qcow2 internal snapshots are used, thus giving stronger protection against watermarking attacks. Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-14-berrange@redhat.com Reviewed-by: Alberto Garcia Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 14 ++- block/qcow2-refcount.c | 10 ++ block/qcow2.c | 268 ++++++++++++++++++++++++++++++++++++++---= --- block/qcow2.h | 9 ++ qapi/block-core.json | 5 +- tests/qemu-iotests/082.out | 270 ++++++++++++++++++++++++++++++++++++-----= ---- 6 files changed, 484 insertions(+), 92 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 71a5e0d..f06c08f 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -389,13 +389,16 @@ static int coroutine_fn do_perform_cow_read(BlockDriv= erState *bs, =20 static bool coroutine_fn do_perform_cow_encrypt(BlockDriverState *bs, uint64_t src_cluster_offse= t, + uint64_t cluster_offset, unsigned offset_in_cluster, uint8_t *buffer, unsigned bytes) { if (bytes && bs->encrypted) { BDRVQcow2State *s =3D bs->opaque; - int64_t sector =3D (src_cluster_offset + offset_in_cluster) + int64_t sector =3D (s->crypt_physical_offset ? + (cluster_offset + offset_in_cluster) : + (src_cluster_offset + offset_in_cluster)) >> BDRV_SECTOR_BITS; assert((offset_in_cluster & ~BDRV_SECTOR_MASK) =3D=3D 0); assert((bytes & ~BDRV_SECTOR_MASK) =3D=3D 0); @@ -788,10 +791,11 @@ static int perform_cow(BlockDriverState *bs, QCowL2Me= ta *m) =20 /* Encrypt the data if necessary before writing it */ if (bs->encrypted) { - if (!do_perform_cow_encrypt(bs, m->offset, start->offset, - start_buffer, start->nb_bytes) || - !do_perform_cow_encrypt(bs, m->offset, end->offset, - end_buffer, end->nb_bytes)) { + if (!do_perform_cow_encrypt(bs, m->offset, m->alloc_offset, + start->offset, start_buffer, + start->nb_bytes) || + !do_perform_cow_encrypt(bs, m->offset, m->alloc_offset, + end->offset, end_buffer, end->nb_bytes= )) { ret =3D -EIO; goto fail; } diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 7c06061..81c22e6 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1856,6 +1856,16 @@ static int calculate_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, return ret; } =20 + /* encryption */ + if (s->crypto_header.length) { + ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, + s->crypto_header.offset, + s->crypto_header.length); + if (ret < 0) { + return ret; + } + } + return check_refblocks(bs, res, fix, rebuild, refcount_table, nb_clust= ers); } =20 diff --git a/block/qcow2.c b/block/qcow2.c index 1c66ec1..7d1c5a3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -66,6 +66,7 @@ typedef struct { #define QCOW2_EXT_MAGIC_END 0 #define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA #define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857 +#define QCOW2_EXT_MAGIC_CRYPTO_HEADER 0x0537be77 =20 static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filen= ame) { @@ -80,6 +81,86 @@ static int qcow2_probe(const uint8_t *buf, int buf_size,= const char *filename) } =20 =20 +static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offs= et, + uint8_t *buf, size_t buflen, + void *opaque, Error **errp) +{ + BlockDriverState *bs =3D opaque; + BDRVQcow2State *s =3D bs->opaque; + ssize_t ret; + + if ((offset + buflen) > s->crypto_header.length) { + error_setg(errp, "Request for data outside of extension header"); + return -1; + } + + ret =3D bdrv_pread(bs->file, + s->crypto_header.offset + offset, buf, buflen); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not read encryption header"); + return -1; + } + return ret; +} + + +static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t head= erlen, + void *opaque, Error **errp) +{ + BlockDriverState *bs =3D opaque; + BDRVQcow2State *s =3D bs->opaque; + int64_t ret; + int64_t clusterlen; + + ret =3D qcow2_alloc_clusters(bs, headerlen); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Cannot allocate cluster for LUKS header size %zu= ", + headerlen); + return -1; + } + + s->crypto_header.length =3D headerlen; + s->crypto_header.offset =3D ret; + + /* Zero fill remaining space in cluster so it has predictable + * content in case of future spec changes */ + clusterlen =3D size_to_clusters(s, headerlen) * s->cluster_size; + ret =3D bdrv_pwrite_zeroes(bs->file, + ret + headerlen, + clusterlen - headerlen, 0); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not zero fill encryption heade= r"); + return -1; + } + + return ret; +} + + +static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t off= set, + const uint8_t *buf, size_t bufl= en, + void *opaque, Error **errp) +{ + BlockDriverState *bs =3D opaque; + BDRVQcow2State *s =3D bs->opaque; + ssize_t ret; + + if ((offset + buflen) > s->crypto_header.length) { + error_setg(errp, "Request for data outside of extension header"); + return -1; + } + + ret =3D bdrv_pwrite(bs->file, + s->crypto_header.offset + offset, buf, buflen); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not read encryption header"); + return -1; + } + return ret; +} + + /*=20 * read qcow2 extension and fill bs * start reading from start_offset @@ -89,7 +170,7 @@ static int qcow2_probe(const uint8_t *buf, int buf_size,= const char *filename) */ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offs= et, uint64_t end_offset, void **p_feature_tab= le, - Error **errp) + int flags, Error **errp) { BDRVQcow2State *s =3D bs->opaque; QCowExtension ext; @@ -165,6 +246,47 @@ static int qcow2_read_extensions(BlockDriverState *bs,= uint64_t start_offset, } break; =20 + case QCOW2_EXT_MAGIC_CRYPTO_HEADER: { + unsigned int cflags =3D 0; + if (s->crypt_method_header !=3D QCOW_CRYPT_LUKS) { + error_setg(errp, "CRYPTO header extension only " + "expected with LUKS encryption method"); + return -EINVAL; + } + if (ext.len !=3D sizeof(Qcow2CryptoHeaderExtension)) { + error_setg(errp, "CRYPTO header extension size %u, " + "but expected size %zu", ext.len, + sizeof(Qcow2CryptoHeaderExtension)); + return -EINVAL; + } + + ret =3D bdrv_pread(bs->file, offset, &s->crypto_header, ext.le= n); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Unable to read CRYPTO header extension"); + return ret; + } + be64_to_cpus(&s->crypto_header.offset); + be64_to_cpus(&s->crypto_header.length); + + if ((s->crypto_header.offset % s->cluster_size) !=3D 0) { + error_setg(errp, "Encryption header offset '%" PRIu64 "' i= s " + "not a multiple of cluster size '%u'", + s->crypto_header.offset, s->cluster_size); + return -EINVAL; + } + + if (flags & BDRV_O_NO_IO) { + cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; + } + s->crypto =3D qcrypto_block_open(s->crypto_opts, + qcow2_crypto_hdr_read_func, + bs, cflags, errp); + if (!s->crypto) { + return -EINVAL; + } + } break; + default: /* unknown magic - save it in case we need to rewrite the head= er */ { @@ -464,7 +586,8 @@ static QemuOptsList qcow2_runtime_opts =3D { .type =3D QEMU_OPT_NUMBER, .help =3D "Clean unused cache entries after this time (in seco= nds)", }, - BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET("encrypt."), + BLOCK_CRYPTO_OPT_DEF_KEY_SECRET("encrypt.", + "ID of secret providing qcow2 AES key or LUKS passphrase"), { /* end of list */ } }, }; @@ -784,6 +907,19 @@ static int qcow2_update_options_prepare(BlockDriverSta= te *bs, Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); break; =20 + case QCOW_CRYPT_LUKS: + if (encryptfmt && !g_str_equal(encryptfmt, "luks")) { + error_setg(errp, + "Header reported 'luks' encryption format but " + "options specify '%s'", encryptfmt); + ret =3D -EINVAL; + goto fail; + } + qdict_del(encryptopts, "format"); + r->crypto_opts =3D block_crypto_open_opts_init( + Q_CRYPTO_BLOCK_FORMAT_LUKS, encryptopts, errp); + break; + default: error_setg(errp, "Unsupported encryption method %d", s->crypt_method_header); @@ -977,7 +1113,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *= options, int flags, if (s->incompatible_features & ~QCOW2_INCOMPAT_MASK) { void *feature_table =3D NULL; qcow2_read_extensions(bs, header.header_length, ext_end, - &feature_table, NULL); + &feature_table, flags, NULL); report_unsupported_feature(errp, feature_table, s->incompatible_features & ~QCOW2_INCOMPAT_MASK); @@ -1009,12 +1145,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict= *options, int flags, s->refcount_max =3D UINT64_C(1) << (s->refcount_bits - 1); s->refcount_max +=3D s->refcount_max - 1; =20 - if (header.crypt_method > QCOW_CRYPT_AES) { - error_setg(errp, "Unsupported encryption method: %" PRIu32, - header.crypt_method); - ret =3D -EINVAL; - goto fail; - } s->crypt_method_header =3D header.crypt_method; if (s->crypt_method_header) { if (bdrv_uses_whitelist() && @@ -1031,6 +1161,15 @@ static int qcow2_do_open(BlockDriverState *bs, QDict= *options, int flags, goto fail; } =20 + if (s->crypt_method_header =3D=3D QCOW_CRYPT_AES) { + s->crypt_physical_offset =3D false; + } else { + /* Assuming LUKS and any future crypt methods we + * add will all use physical offsets, due to the + * fact that the alternative is insecure... */ + s->crypt_physical_offset =3D true; + } + bs->encrypted =3D true; bs->valid_key =3D true; } @@ -1159,20 +1298,31 @@ static int qcow2_do_open(BlockDriverState *bs, QDic= t *options, int flags, =20 /* read qcow2 extensions */ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL, - &local_err)) { + flags, &local_err)) { error_propagate(errp, local_err); ret =3D -EINVAL; goto fail; } =20 - if (s->crypt_method_header =3D=3D QCOW_CRYPT_AES) { - unsigned int cflags =3D 0; - if (flags & BDRV_O_NO_IO) { - cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; - } - s->crypto =3D qcrypto_block_open(s->crypto_opts, NULL, NULL, - cflags, errp); - if (!s->crypto) { + /* qcow2_read_extension may have set up the crypto context + * if the crypt method needs a header region, some methods + * don't need header extensions, so must check here + */ + if (s->crypt_method_header && !s->crypto) { + if (s->crypt_method_header =3D=3D QCOW_CRYPT_AES) { + unsigned int cflags =3D 0; + if (flags & BDRV_O_NO_IO) { + cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; + } + s->crypto =3D qcrypto_block_open(s->crypto_opts, NULL, NULL, + cflags, errp); + if (!s->crypto) { + ret =3D -EINVAL; + goto fail; + } + } else if (!(flags & BDRV_O_NO_IO)) { + error_setg(errp, "Missing CRYPTO header for crypt method %d", + s->crypt_method_header); ret =3D -EINVAL; goto fail; } @@ -1566,7 +1716,9 @@ static coroutine_fn int qcow2_co_preadv(BlockDriverSt= ate *bs, uint64_t offset, assert((cur_bytes & (BDRV_SECTOR_SIZE - 1)) =3D=3D 0); Error *err =3D NULL; if (qcrypto_block_decrypt(s->crypto, - offset >> BDRV_SECTOR_BITS, + (s->crypt_physical_offset ? + cluster_offset + offset_in_clus= ter : + offset) >> BDRV_SECTOR_BITS, cluster_data, cur_bytes, &err) < 0) { @@ -1700,7 +1852,10 @@ static coroutine_fn int qcow2_co_pwritev(BlockDriver= State *bs, uint64_t offset, QCOW_MAX_CRYPT_CLUSTERS * s->cluster_size); qemu_iovec_to_buf(&hd_qiov, 0, cluster_data, hd_qiov.size); =20 - if (qcrypto_block_encrypt(s->crypto, offset >> BDRV_SECTOR_BIT= S, + if (qcrypto_block_encrypt(s->crypto, + (s->crypt_physical_offset ? + cluster_offset + offset_in_cluster : + offset) >> BDRV_SECTOR_BITS, cluster_data, cur_bytes, &err) < 0) { error_free(err); @@ -2004,6 +2159,22 @@ int qcow2_update_header(BlockDriverState *bs) buflen -=3D ret; } =20 + /* Full disk encryption header pointer extension */ + if (s->crypto_header.offset !=3D 0) { + cpu_to_be64s(&s->crypto_header.offset); + cpu_to_be64s(&s->crypto_header.length); + ret =3D header_ext_add(buf, QCOW2_EXT_MAGIC_CRYPTO_HEADER, + &s->crypto_header, sizeof(s->crypto_header), + buflen); + be64_to_cpus(&s->crypto_header.offset); + be64_to_cpus(&s->crypto_header.length); + if (ret < 0) { + goto fail; + } + buf +=3D ret; + buflen -=3D ret; + } + /* Feature table */ if (s->qcow_version >=3D 3) { Qcow2Feature features[] =3D { @@ -2102,6 +2273,16 @@ static int qcow2_change_backing_file(BlockDriverStat= e *bs, return qcow2_update_header(bs); } =20 +static int qcow2_crypt_method_from_format(const char *encryptfmt) +{ + if (g_str_equal(encryptfmt, "luks")) { + return QCOW_CRYPT_LUKS; + } else if (g_str_equal(encryptfmt, "aes")) { + return QCOW_CRYPT_AES; + } else { + return -EINVAL; + } +} =20 static int qcow2_set_up_encryption(BlockDriverState *bs, const char *encry= ptfmt, QemuOpts *opts, Error **errp) @@ -2111,27 +2292,36 @@ static int qcow2_set_up_encryption(BlockDriverState= *bs, const char *encryptfmt, QCryptoBlock *crypto =3D NULL; int ret =3D -EINVAL; QDict *options, *encryptopts; + int fmt; =20 options =3D qemu_opts_to_qdict(opts, NULL); qdict_extract_subqdict(options, &encryptopts, "encrypt."); QDECREF(options); =20 - if (!g_str_equal(encryptfmt, "aes")) { - error_setg(errp, "Unknown encryption format '%s', expected 'aes'", - encryptfmt); - ret =3D -EINVAL; - goto out; + fmt =3D qcow2_crypt_method_from_format(encryptfmt); + + switch (fmt) { + case QCOW_CRYPT_LUKS: + cryptoopts =3D block_crypto_create_opts_init( + Q_CRYPTO_BLOCK_FORMAT_LUKS, encryptopts, errp); + break; + case QCOW_CRYPT_AES: + cryptoopts =3D block_crypto_create_opts_init( + Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); + break; + default: + error_setg(errp, "Unknown encryption format '%s'", encryptfmt); + break; } - cryptoopts =3D block_crypto_create_opts_init( - Q_CRYPTO_BLOCK_FORMAT_QCOW, encryptopts, errp); if (!cryptoopts) { ret =3D -EINVAL; goto out; } - s->crypt_method_header =3D QCOW_CRYPT_AES; + s->crypt_method_header =3D fmt; =20 crypto =3D qcrypto_block_create(cryptoopts, - NULL, NULL, + qcow2_crypto_hdr_init_func, + qcow2_crypto_hdr_write_func, bs, errp); if (!crypto) { ret =3D -EINVAL; @@ -3268,6 +3458,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, const char *compat =3D NULL; uint64_t cluster_size =3D s->cluster_size; bool encrypt; + int encformat; int refcount_bits =3D s->refcount_bits; Error *local_err =3D NULL; int ret; @@ -3310,6 +3501,14 @@ static int qcow2_amend_options(BlockDriverState *bs,= QemuOpts *opts, error_report("Changing the encryption flag is not supporte= d"); return -ENOTSUP; } + } else if (!strcmp(desc->name, BLOCK_OPT_ENCRYPT_FORMAT)) { + encformat =3D qcow2_crypt_method_from_format( + qemu_opt_get(opts, BLOCK_OPT_ENCRYPT_FORMAT)); + + if (encformat !=3D s->crypt_method_header) { + error_report("Changing the encryption format is not suppor= ted"); + return -ENOTSUP; + } } else if (!strcmp(desc->name, BLOCK_OPT_CLUSTER_SIZE)) { cluster_size =3D qemu_opt_get_size(opts, BLOCK_OPT_CLUSTER_SIZ= E, cluster_size); @@ -3530,9 +3729,16 @@ static QemuOptsList qcow2_create_opts =3D { { .name =3D BLOCK_OPT_ENCRYPT_FORMAT, .type =3D QEMU_OPT_STRING, - .help =3D "Encrypt the image, format choices: 'aes'", + .help =3D "Encrypt the image, format choices: 'aes', 'luks'", }, - BLOCK_CRYPTO_OPT_DEF_QCOW_KEY_SECRET("encrypt."), + BLOCK_CRYPTO_OPT_DEF_KEY_SECRET("encrypt.", + "ID of secret providing qcow AES key or LUKS passphrase"), + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_ALG("encrypt."), + BLOCK_CRYPTO_OPT_DEF_LUKS_CIPHER_MODE("encrypt."), + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_ALG("encrypt."), + BLOCK_CRYPTO_OPT_DEF_LUKS_IVGEN_HASH_ALG("encrypt."), + BLOCK_CRYPTO_OPT_DEF_LUKS_HASH_ALG("encrypt."), + BLOCK_CRYPTO_OPT_DEF_LUKS_ITER_TIME("encrypt."), { .name =3D BLOCK_OPT_CLUSTER_SIZE, .type =3D QEMU_OPT_SIZE, diff --git a/block/qcow2.h b/block/qcow2.h index 4b89610..84c9853 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -36,6 +36,7 @@ =20 #define QCOW_CRYPT_NONE 0 #define QCOW_CRYPT_AES 1 +#define QCOW_CRYPT_LUKS 2 =20 #define QCOW_MAX_CRYPT_CLUSTERS 32 #define QCOW_MAX_SNAPSHOTS 65536 @@ -163,6 +164,11 @@ typedef struct QCowSnapshot { struct Qcow2Cache; typedef struct Qcow2Cache Qcow2Cache; =20 +typedef struct Qcow2CryptoHeaderExtension { + uint64_t offset; + uint64_t length; +} QEMU_PACKED Qcow2CryptoHeaderExtension; + typedef struct Qcow2UnknownHeaderExtension { uint32_t magic; uint32_t len; @@ -257,8 +263,11 @@ typedef struct BDRVQcow2State { =20 CoMutex lock; =20 + Qcow2CryptoHeaderExtension crypto_header; /* QCow2 header extension */ QCryptoBlockOpenOptions *crypto_opts; /* Disk encryption runtime optio= ns */ QCryptoBlock *crypto; /* Disk encryption format driver */ + bool crypt_physical_offset; /* Whether to use virtual or physical offs= et + for encryption initialization vector tw= eak */ uint32_t crypt_method_header; uint64_t snapshots_offset; int snapshots_size; diff --git a/qapi/block-core.json b/qapi/block-core.json index 1f268ee..bb075c0 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -2325,7 +2325,7 @@ # Since: 2.10 ## { 'enum': 'BlockdevQcow2EncryptionFormat', - 'data': [ 'aes' ] } + 'data': [ 'aes', 'luks' ] } =20 ## # @BlockdevQcow2Encryption: @@ -2335,7 +2335,8 @@ { 'union': 'BlockdevQcow2Encryption', 'base': { 'format': 'BlockdevQcow2EncryptionFormat' }, 'discriminator': 'format', - 'data': { 'aes': 'QCryptoBlockOptionsQCow' } } + 'data': { 'aes': 'QCryptoBlockOptionsQCow', + 'luks': 'QCryptoBlockOptionsLUKS'} } =20 ## # @BlockdevOptionsQcow2: diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 3978db5..dbed67f 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -49,8 +49,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -64,8 +70,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -79,8 +91,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -94,8 +112,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -109,8 +133,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -124,8 +154,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -139,8 +175,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -154,8 +196,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -184,8 +232,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -248,8 +302,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -263,8 +323,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -278,8 +344,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -293,8 +365,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -308,8 +386,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -323,8 +407,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -338,8 +428,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -353,8 +449,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -383,8 +485,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -444,8 +552,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -459,8 +573,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -474,8 +594,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -489,8 +615,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -504,8 +636,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -519,8 +657,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -534,8 +678,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -549,8 +699,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates @@ -581,8 +737,14 @@ compat Compatibility level (0.10 or 1.1) backing_file File name of a base image backing_fmt Image format of the base image encryption Encrypt the image with format 'aes'. (Deprecated in favor= of encrypt.format=3Daes) -encrypt.format Encrypt the image, format choices: 'aes' -encrypt.key-secret ID of the secret that provides the AES encryption key +encrypt.format Encrypt the image, format choices: 'aes', 'luks' +encrypt.key-secret ID of secret providing qcow AES key or LUKS passphrase +encrypt.cipher-alg Name of encryption cipher algorithm +encrypt.cipher-mode Name of encryption cipher mode +encrypt.ivgen-alg Name of IV generator algorithm +encrypt.ivgen-hash-alg Name of IV generator hash algorithm +encrypt.hash-alg Name of encryption hash algorithm +encrypt.iter-time Time to spend in PBKDF in milliseconds cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449858693708.413492837036; Fri, 7 Jul 2017 10:50:58 -0700 (PDT) Received: from localhost ([::1]:57928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXP7-0008NL-A1 for importer@patchew.org; Fri, 07 Jul 2017 13:50:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWly-0005xO-7s for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlu-0000AT-Em for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38316) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlp-00007Z-Kh; Fri, 07 Jul 2017 13:10:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A9AF34DB15; Fri, 7 Jul 2017 17:10:20 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA9DD61F23; Fri, 7 Jul 2017 17:10:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com A9AF34DB15 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com A9AF34DB15 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:09 +0200 Message-Id: <1499447335-6125-55-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:10:20 +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] [PULL 054/100] qcow2: add iotests to cover LUKS encryption support 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-devel@nongnu.org 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" From: "Daniel P. Berrange" This extends the 087 iotest to cover LUKS encryption when doing blockdev-add. Two further tests are added to validate read/write of LUKS encrypted images with a single file and with a backing file. Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-15-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/087 | 35 ++++++++++++++++++- tests/qemu-iotests/087.out | 14 +++++++- tests/qemu-iotests/188 | 76 ++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/188.out | 18 ++++++++++ tests/qemu-iotests/189 | 86 ++++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/189.out | 26 ++++++++++++++ tests/qemu-iotests/group | 2 ++ 7 files changed, 255 insertions(+), 2 deletions(-) create mode 100755 tests/qemu-iotests/188 create mode 100644 tests/qemu-iotests/188.out create mode 100755 tests/qemu-iotests/189 create mode 100644 tests/qemu-iotests/189.out diff --git a/tests/qemu-iotests/087 b/tests/qemu-iotests/087 index 1d595b2..f8e4903 100755 --- a/tests/qemu-iotests/087 +++ b/tests/qemu-iotests/087 @@ -119,7 +119,7 @@ run_qemu <. +# + +# creator +owner=3Dberrange@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +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 generic +_supported_os Linux + + +size=3D16M + +SECRET=3D"secret,id=3Dsec0,data=3Dastrochicken" +SECRETALT=3D"secret,id=3Dsec0,data=3Dplatypus" + +_make_test_img --object $SECRET -o "encrypt.format=3Dluks,encrypt.key-secr= et=3Dsec0,encrypt.iter-time=3D10" $size + +IMGSPEC=3D"driver=3D$IMGFMT,file.filename=3D$TEST_IMG,encrypt.key-secret= =3Dsec0" + +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT + +echo +echo "=3D=3D reading whole image =3D=3D" +$QEMU_IO --object $SECRET -c "read -P 0 0 $size" --image-opts $IMGSPEC | _= filter_qemu_io | _filter_testdir + +echo +echo "=3D=3D rewriting whole image =3D=3D" +$QEMU_IO --object $SECRET -c "write -P 0xa 0 $size" --image-opts $IMGSPEC = | _filter_qemu_io | _filter_testdir + +echo +echo "=3D=3D verify pattern =3D=3D" +$QEMU_IO --object $SECRET -c "read -P 0xa 0 $size" --image-opts $IMGSPEC = | _filter_qemu_io | _filter_testdir + +echo +echo "=3D=3D verify open failure with wrong password =3D=3D" +$QEMU_IO --object $SECRETALT -c "read -P 0xa 0 $size" --image-opts $IMGSPE= C | _filter_qemu_io | _filter_testdir + + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/188.out b/tests/qemu-iotests/188.out new file mode 100644 index 0000000..8af24e5 --- /dev/null +++ b/tests/qemu-iotests/188.out @@ -0,0 +1,18 @@ +QA output created by 188 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D16777216 encrypt.forma= t=3Dluks encrypt.key-secret=3Dsec0 encrypt.iter-time=3D10 + +=3D=3D reading whole image =3D=3D +read 16777216/16777216 bytes at offset 0 +16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D rewriting whole image =3D=3D +wrote 16777216/16777216 bytes at offset 0 +16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D verify pattern =3D=3D +read 16777216/16777216 bytes at offset 0 +16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D verify open failure with wrong password =3D=3D +can't open: Invalid password, cannot unlock any keyslot +*** done diff --git a/tests/qemu-iotests/189 b/tests/qemu-iotests/189 new file mode 100755 index 0000000..54ad980 --- /dev/null +++ b/tests/qemu-iotests/189 @@ -0,0 +1,86 @@ +#!/bin/bash +# +# Test encrypted read/write using backing files +# +# Copyright (C) 2017 Red Hat, Inc. +# +# 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=3Dberrange@redhat.com + +seq=3D`basename $0` +echo "QA output created by $seq" + +here=3D`pwd` +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 generic +_supported_os Linux + + +size=3D16M +TEST_IMG_BASE=3D$TEST_IMG.base +SECRET0=3D"secret,id=3Dsec0,data=3Dastrochicken" +SECRET1=3D"secret,id=3Dsec1,data=3Dfurby" + +TEST_IMG_SAVE=3D$TEST_IMG +TEST_IMG=3D$TEST_IMG_BASE +echo "=3D=3D create base =3D=3D" +_make_test_img --object $SECRET0 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec0,encrypt.iter-time=3D10" $size +TEST_IMG=3D$TEST_IMG_SAVE + +IMGSPECBASE=3D"driver=3D$IMGFMT,file.filename=3D$TEST_IMG_BASE,encrypt.key= -secret=3Dsec0" +IMGSPEC=3D"driver=3D$IMGFMT,file.filename=3D$TEST_IMG,backing.driver=3D$IM= GFMT,backing.file.filename=3D$TEST_IMG_BASE,backing.encrypt.key-secret=3Dse= c0,encrypt.key-secret=3Dsec1" +QEMU_IO_OPTIONS=3D$QEMU_IO_OPTIONS_NO_FMT + +echo +echo "=3D=3D writing whole image =3D=3D" +$QEMU_IO --object $SECRET0 -c "write -P 0xa 0 $size" --image-opts $IMGSPEC= BASE | _filter_qemu_io | _filter_testdir + +echo +echo "=3D=3D verify pattern =3D=3D" +$QEMU_IO --object $SECRET0 -c "read -P 0xa 0 $size" --image-opts $IMGSPECB= ASE | _filter_qemu_io | _filter_testdir + +echo "=3D=3D create overlay =3D=3D" +_make_test_img --object $SECRET1 -o "encrypt.format=3Dluks,encrypt.key-sec= ret=3Dsec1,encrypt.iter-time=3D10" -b "$TEST_IMG_BASE" $size + +echo +echo "=3D=3D writing part of a cluster =3D=3D" +$QEMU_IO --object $SECRET0 --object $SECRET1 -c "write -P 0xe 0 1024" --im= age-opts $IMGSPEC | _filter_qemu_io | _filter_testdir + +echo +echo "=3D=3D verify pattern =3D=3D" +$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0xe 0 1024" --ima= ge-opts $IMGSPEC | _filter_qemu_io | _filter_testdir +echo +echo "=3D=3D verify pattern =3D=3D" +$QEMU_IO --object $SECRET0 --object $SECRET1 -c "read -P 0xa 1024 64512" -= -image-opts $IMGSPEC | _filter_qemu_io | _filter_testdir + + +# success, all done +echo "*** done" +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/189.out b/tests/qemu-iotests/189.out new file mode 100644 index 0000000..a0b7c9c --- /dev/null +++ b/tests/qemu-iotests/189.out @@ -0,0 +1,26 @@ +QA output created by 189 +=3D=3D create base =3D=3D +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D16777216 encrypt.= format=3Dluks encrypt.key-secret=3Dsec0 encrypt.iter-time=3D10 + +=3D=3D writing whole image =3D=3D +wrote 16777216/16777216 bytes at offset 0 +16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D verify pattern =3D=3D +read 16777216/16777216 bytes at offset 0 +16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +=3D=3D create overlay =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D16777216 backing_file= =3DTEST_DIR/t.IMGFMT.base encrypt.format=3Dluks encrypt.key-secret=3Dsec1 e= ncrypt.iter-time=3D10 + +=3D=3D writing part of a cluster =3D=3D +wrote 1024/1024 bytes at offset 0 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D verify pattern =3D=3D +read 1024/1024 bytes at offset 0 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D verify pattern =3D=3D +read 64512/64512 bytes at offset 1024 +63 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 318ae74..613d596 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -176,3 +176,5 @@ 182 rw auto quick 183 rw auto migration 185 rw auto +188 rw auto quick +189 rw auto quick --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499448696246581.4210954106981; Fri, 7 Jul 2017 10:31:36 -0700 (PDT) Received: from localhost ([::1]:57814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX6M-0007zP-0f for importer@patchew.org; Fri, 07 Jul 2017 13:31:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWly-0005xP-7G for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWlt-0000A7-Q4 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57000) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlr-00008W-0O; Fri, 07 Jul 2017 13:10:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1CD3383F3E; Fri, 7 Jul 2017 17:10:22 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00A1B61F23; Fri, 7 Jul 2017 17:10:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1CD3383F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1CD3383F3E From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:10 +0200 Message-Id: <1499447335-6125-56-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:22 +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] [PULL 055/100] iotests: enable tests 134 and 158 to work with qcow (v1) 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-devel@nongnu.org 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" From: "Daniel P. Berrange" The 138 and 158 iotests exercise the legacy qcow2 aes encryption code path and they work fine with qcow v1 too. Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-16-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/134 | 2 +- tests/qemu-iotests/158 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/134 b/tests/qemu-iotests/134 index f851d92..9914415 100755 --- a/tests/qemu-iotests/134 +++ b/tests/qemu-iotests/134 @@ -37,7 +37,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.rc . ./common.filter =20 -_supported_fmt qcow2 +_supported_fmt qcow qcow2 _supported_proto generic _unsupported_proto vxhs _supported_os Linux diff --git a/tests/qemu-iotests/158 b/tests/qemu-iotests/158 index e280b79..823c120 100755 --- a/tests/qemu-iotests/158 +++ b/tests/qemu-iotests/158 @@ -37,7 +37,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.rc . ./common.filter =20 -_supported_fmt qcow2 +_supported_fmt qcow qcow2 _supported_proto generic _unsupported_proto vxhs _supported_os Linux --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450422051319.04906707143687; Fri, 7 Jul 2017 11:00:22 -0700 (PDT) Received: from localhost ([::1]:57987 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXYC-0000Bn-KZ for importer@patchew.org; Fri, 07 Jul 2017 14:00:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42693) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm1-00060Z-IC for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWly-0000Cp-AJ for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWls-000092-BG; Fri, 07 Jul 2017 13:10:24 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 53897C04B326; Fri, 7 Jul 2017 17:10:23 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 675D061F23; Fri, 7 Jul 2017 17:10:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 53897C04B326 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 53897C04B326 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:11 +0200 Message-Id: <1499447335-6125-57-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:10:23 +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] [PULL 056/100] block: rip out all traces of password prompting 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Now that qcow & qcow2 are wired up to get encryption keys via the QCryptoSecret object, nothing is relying on the interactive prompting for passwords. All the code related to password prompting can thus be ripped out. Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-17-berrange@redhat.com Signed-off-by: Max Reitz --- hmp.c | 31 --------------------- include/monitor/monitor.h | 7 ----- include/qemu/osdep.h | 2 -- monitor.c | 68 -------------------------------------------= ---- qapi-schema.json | 10 +------ qemu-img.c | 31 --------------------- qemu-io.c | 20 -------------- qmp.c | 12 +-------- util/oslib-posix.c | 66 -------------------------------------------= -- util/oslib-win32.c | 24 ----------------- 10 files changed, 2 insertions(+), 269 deletions(-) diff --git a/hmp.c b/hmp.c index dee4028..6d32c40 100644 --- a/hmp.c +++ b/hmp.c @@ -1088,37 +1088,12 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qd= ict) g_free(data); } =20 -static void hmp_cont_cb(void *opaque, int err) -{ - if (!err) { - qmp_cont(NULL); - } -} - -static bool key_is_missing(const BlockInfo *bdev) -{ - return (bdev->inserted && bdev->inserted->encryption_key_missing); -} - void hmp_cont(Monitor *mon, const QDict *qdict) { - BlockInfoList *bdev_list, *bdev; Error *err =3D NULL; =20 - bdev_list =3D qmp_query_block(NULL); - for (bdev =3D bdev_list; bdev; bdev =3D bdev->next) { - if (key_is_missing(bdev->value)) { - monitor_read_block_device_key(mon, bdev->value->device, - hmp_cont_cb, NULL); - goto out; - } - } - qmp_cont(&err); hmp_handle_error(mon, &err); - -out: - qapi_free_BlockInfoList(bdev_list); } =20 void hmp_system_wakeup(Monitor *mon, const QDict *qdict) @@ -1741,12 +1716,6 @@ void hmp_change(Monitor *mon, const QDict *qdict) qmp_blockdev_change_medium(true, device, false, NULL, target, !!arg, arg, !!read_only, read_only_mode, &err); - if (err && - error_get_class(err) =3D=3D ERROR_CLASS_DEVICE_ENCRYPTED) { - error_free(err); - monitor_read_block_device_key(mon, device, NULL, NULL); - return; - } } =20 hmp_handle_error(mon, &err); diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index d2b3aaf..83ea4a1 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -23,13 +23,6 @@ void monitor_cleanup(void); int monitor_suspend(Monitor *mon); void monitor_resume(Monitor *mon); =20 -int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, - BlockCompletionFunc *completion_cb, - void *opaque); -int monitor_read_block_device_key(Monitor *mon, const char *device, - BlockCompletionFunc *completion_cb, - void *opaque); - int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp); int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp); =20 diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 8559634..3b74f6f 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -457,8 +457,6 @@ void qemu_set_tty_echo(int fd, bool echo); void os_mem_prealloc(int fd, char *area, size_t sz, int smp_cpus, Error **errp); =20 -int qemu_read_password(char *buf, int buf_size); - /** * qemu_get_pid_name: * @pid: pid of a process diff --git a/monitor.c b/monitor.c index d8ac20f..fa3e3ac 100644 --- a/monitor.c +++ b/monitor.c @@ -4136,74 +4136,6 @@ void monitor_cleanup(void) qemu_mutex_unlock(&monitor_lock); } =20 -static void bdrv_password_cb(void *opaque, const char *password, - void *readline_opaque) -{ - Monitor *mon =3D opaque; - BlockDriverState *bs =3D readline_opaque; - int ret =3D 0; - Error *local_err =3D NULL; - - bdrv_add_key(bs, password, &local_err); - if (local_err) { - error_report_err(local_err); - ret =3D -EPERM; - } - if (mon->password_completion_cb) - mon->password_completion_cb(mon->password_opaque, ret); - - monitor_read_command(mon, 1); -} - -int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, - BlockCompletionFunc *completion_cb, - void *opaque) -{ - int err; - - monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs= ), - bdrv_get_encrypted_filename(bs)); - - mon->password_completion_cb =3D completion_cb; - mon->password_opaque =3D opaque; - - err =3D monitor_read_password(mon, bdrv_password_cb, bs); - - if (err && completion_cb) - completion_cb(opaque, err); - - return err; -} - -int monitor_read_block_device_key(Monitor *mon, const char *device, - BlockCompletionFunc *completion_cb, - void *opaque) -{ - Error *err =3D NULL; - BlockBackend *blk; - - blk =3D blk_by_name(device); - if (!blk) { - monitor_printf(mon, "Device not found %s\n", device); - return -1; - } - if (!blk_bs(blk)) { - monitor_printf(mon, "Device '%s' has no medium\n", device); - return -1; - } - - bdrv_add_key(blk_bs(blk), NULL, &err); - if (err) { - error_free(err); - return monitor_read_bdrv_key_start(mon, blk_bs(blk), completion_cb= , opaque); - } - - if (completion_cb) { - completion_cb(opaque, 0); - } - return 0; -} - QemuOptsList qemu_mon_opts =3D { .name =3D "mon", .implied_opt_name =3D "chardev", diff --git a/qapi-schema.json b/qapi-schema.json index 37c4b95..485767f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2431,8 +2431,6 @@ # Since: 0.14.0 # # Returns: If successful, nothing -# If QEMU was started with an encrypted block device and a key h= as -# not yet been set, DeviceEncrypted. # # Notes: This command will succeed if the guest is currently running. It # will also succeed if the guest is in the "inmigrate" state; in @@ -2713,8 +2711,7 @@ # * This command is stateless, this means that commands that depend # on state information (such as getfd) might not work # -# * Commands that prompt the user for data (eg. 'cont' when the blo= ck -# device is encrypted) don't currently work +# * Commands that prompt the user for data don't currently work # # Example: # @@ -3019,11 +3016,6 @@ # # Returns: Nothing on success. # If @device is not a valid block device, DeviceNotFound -# If the new block device is encrypted, DeviceEncrypted. Note th= at -# if this error is returned, the device has been opened successfu= lly -# and an additional call to @block_passwd is required to set the -# device's password. The behavior of reads and writes to the blo= ck -# device between when these calls are executed is undefined. # # Notes: This interface is deprecated, and it is strongly recommended tha= t you # avoid using it. For changing block devices, use diff --git a/qemu-img.c b/qemu-img.c index ae4fe6d..7f1de74 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -260,29 +260,6 @@ static int print_block_option_help(const char *filenam= e, const char *fmt) } =20 =20 -static int img_open_password(BlockBackend *blk, const char *filename, - int flags, bool quiet) -{ - BlockDriverState *bs; - char password[256]; - - bs =3D blk_bs(blk); - if (bdrv_is_encrypted(bs) && bdrv_key_required(bs) && - !(flags & BDRV_O_NO_IO)) { - qprintf(quiet, "Disk image '%s' is encrypted.\n", filename); - if (qemu_read_password(password, sizeof(password)) < 0) { - error_report("No password given"); - return -1; - } - if (bdrv_set_key(bs, password) < 0) { - error_report("invalid password"); - return -1; - } - } - return 0; -} - - static BlockBackend *img_open_opts(const char *optstr, QemuOpts *opts, int flags, bool writeth= rough, bool quiet, bool force_share) @@ -307,10 +284,6 @@ static BlockBackend *img_open_opts(const char *optstr, } blk_set_enable_write_cache(blk, !writethrough); =20 - if (img_open_password(blk, optstr, flags, quiet) < 0) { - blk_unref(blk); - return NULL; - } return blk; } =20 @@ -340,10 +313,6 @@ static BlockBackend *img_open_file(const char *filenam= e, } blk_set_enable_write_cache(blk, !writethrough); =20 - if (img_open_password(blk, filename, flags, quiet) < 0) { - blk_unref(blk); - return NULL; - } return blk; } =20 diff --git a/qemu-io.c b/qemu-io.c index 8074656..4cfa41c 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -58,7 +58,6 @@ static int openfile(char *name, int flags, bool writethro= ugh, bool force_share, QDict *opts) { Error *local_err =3D NULL; - BlockDriverState *bs; =20 if (qemuio_blk) { error_report("file open already, try 'help close'"); @@ -85,28 +84,9 @@ static int openfile(char *name, int flags, bool writethr= ough, bool force_share, return 1; } =20 - bs =3D blk_bs(qemuio_blk); - if (bdrv_is_encrypted(bs) && bdrv_key_required(bs)) { - char password[256]; - printf("Disk image '%s' is encrypted.\n", name); - if (qemu_read_password(password, sizeof(password)) < 0) { - error_report("No password given"); - goto error; - } - if (bdrv_set_key(bs, password) < 0) { - error_report("invalid password"); - goto error; - } - } - blk_set_enable_write_cache(qemuio_blk, !writethrough); =20 return 0; - - error: - blk_unref(qemuio_blk); - qemuio_blk =3D NULL; - return 1; } =20 static void open_help(void) diff --git a/qmp.c b/qmp.c index 7ee9bcf..84a4f29 100644 --- a/qmp.c +++ b/qmp.c @@ -164,10 +164,8 @@ SpiceInfo *qmp_query_spice(Error **errp) =20 void qmp_cont(Error **errp) { - Error *local_err =3D NULL; BlockBackend *blk; - BlockDriverState *bs; - BdrvNextIterator it; + Error *local_err =3D NULL; =20 /* if there is a dump in background, we should wait until the dump * finished */ @@ -187,14 +185,6 @@ void qmp_cont(Error **errp) blk_iostatus_reset(blk); } =20 - for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { - bdrv_add_key(bs, NULL, &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - } - /* Continuing after completed migration. Images have been inactivated = to * allow the destination to take control. Need to get control back now. * diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 5e8b4b3..b2dea48 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -414,72 +414,6 @@ void os_mem_prealloc(int fd, char *area, size_t memory= , int smp_cpus, } =20 =20 -static struct termios oldtty; - -static void term_exit(void) -{ - tcsetattr(0, TCSANOW, &oldtty); -} - -static void term_init(void) -{ - struct termios tty; - - tcgetattr(0, &tty); - oldtty =3D tty; - - tty.c_iflag &=3D ~(IGNBRK|BRKINT|PARMRK|ISTRIP - |INLCR|IGNCR|ICRNL|IXON); - tty.c_oflag |=3D OPOST; - tty.c_lflag &=3D ~(ECHO|ECHONL|ICANON|IEXTEN); - tty.c_cflag &=3D ~(CSIZE|PARENB); - tty.c_cflag |=3D CS8; - tty.c_cc[VMIN] =3D 1; - tty.c_cc[VTIME] =3D 0; - - tcsetattr(0, TCSANOW, &tty); - - atexit(term_exit); -} - -int qemu_read_password(char *buf, int buf_size) -{ - uint8_t ch; - int i, ret; - - printf("password: "); - fflush(stdout); - term_init(); - i =3D 0; - for (;;) { - ret =3D read(0, &ch, 1); - if (ret =3D=3D -1) { - if (errno =3D=3D EAGAIN || errno =3D=3D EINTR) { - continue; - } else { - break; - } - } else if (ret =3D=3D 0) { - ret =3D -1; - break; - } else { - if (ch =3D=3D '\r' || - ch =3D=3D '\n') { - ret =3D 0; - break; - } - if (i < (buf_size - 1)) { - buf[i++] =3D ch; - } - } - } - term_exit(); - buf[i] =3D '\0'; - printf("\n"); - return ret; -} - - char *qemu_get_pid_name(pid_t pid) { char *name =3D NULL; diff --git a/util/oslib-win32.c b/util/oslib-win32.c index 3de9e77..69a6286 100644 --- a/util/oslib-win32.c +++ b/util/oslib-win32.c @@ -552,30 +552,6 @@ void os_mem_prealloc(int fd, char *area, size_t memory= , int smp_cpus, } =20 =20 -/* XXX: put correct support for win32 */ -int qemu_read_password(char *buf, int buf_size) -{ - int c, i; - - printf("Password: "); - fflush(stdout); - i =3D 0; - for (;;) { - c =3D getchar(); - if (c < 0) { - buf[i] =3D '\0'; - return -1; - } else if (c =3D=3D '\n') { - break; - } else if (i < (buf_size - 1)) { - buf[i++] =3D c; - } - } - buf[i] =3D '\0'; - return 0; -} - - char *qemu_get_pid_name(pid_t pid) { /* XXX Implement me */ --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449023345589.6986428630066; Fri, 7 Jul 2017 10:37:03 -0700 (PDT) Received: from localhost ([::1]:57841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXBc-0004HC-UU for importer@patchew.org; Fri, 07 Jul 2017 13:37:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm5-00064p-BB for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm1-0000HF-4W for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlt-00009m-I9; Fri, 07 Jul 2017 13:10:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89C4A7CE18; Fri, 7 Jul 2017 17:10:24 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F81061F23; Fri, 7 Jul 2017 17:10:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 89C4A7CE18 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 89C4A7CE18 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:12 +0200 Message-Id: <1499447335-6125-58-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:10:24 +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] [PULL 057/100] block: remove all encryption handling APIs 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Now that all encryption keys must be provided upfront via the QCryptoSecret API and associated block driver properties there is no need for any explicit encryption handling APIs in the block layer. Encryption can be handled transparently within the block driver. We only retain an API for querying whether an image is encrypted or not, since that is a potentially useful piece of metadata to report to the user. Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-18-berrange@redhat.com Signed-off-by: Max Reitz --- block.c | 77 +------------------------------------------= ---- block/crypto.c | 1 - block/qapi.c | 2 +- block/qcow.c | 8 ++++- block/qcow2.c | 1 - blockdev.c | 37 ++--------------------- hmp-commands.hx | 2 ++ include/block/block.h | 3 -- include/block/block_int.h | 1 - include/qapi/error.h | 1 - qapi/block-core.json | 37 ++--------------------- qapi/common.json | 5 +-- 12 files changed, 16 insertions(+), 159 deletions(-) diff --git a/block.c b/block.c index 6943962..edfa6b7 100644 --- a/block.c +++ b/block.c @@ -2573,15 +2573,7 @@ static BlockDriverState *bdrv_open_inherit(const cha= r *filename, goto close_and_fail; } =20 - if (!bdrv_key_required(bs)) { - bdrv_parent_cb_change_media(bs, true); - } else if (!runstate_check(RUN_STATE_PRELAUNCH) - && !runstate_check(RUN_STATE_INMIGRATE) - && !runstate_check(RUN_STATE_PAUSED)) { /* HACK */ - error_setg(errp, - "Guest must be stopped for opening of encrypted image"); - goto close_and_fail; - } + bdrv_parent_cb_change_media(bs, true); =20 QDECREF(options); =20 @@ -3072,7 +3064,6 @@ static void bdrv_close(BlockDriverState *bs) bs->backing_format[0] =3D '\0'; bs->total_sectors =3D 0; bs->encrypted =3D false; - bs->valid_key =3D false; bs->sg =3D false; QDECREF(bs->options); QDECREF(bs->explicit_options); @@ -3502,72 +3493,6 @@ bool bdrv_is_encrypted(BlockDriverState *bs) return bs->encrypted; } =20 -bool bdrv_key_required(BlockDriverState *bs) -{ - BdrvChild *backing =3D bs->backing; - - if (backing && backing->bs->encrypted && !backing->bs->valid_key) { - return true; - } - return (bs->encrypted && !bs->valid_key); -} - -int bdrv_set_key(BlockDriverState *bs, const char *key) -{ - int ret; - if (bs->backing && bs->backing->bs->encrypted) { - ret =3D bdrv_set_key(bs->backing->bs, key); - if (ret < 0) - return ret; - if (!bs->encrypted) - return 0; - } - if (!bs->encrypted) { - return -EINVAL; - } else if (!bs->drv || !bs->drv->bdrv_set_key) { - return -ENOMEDIUM; - } - ret =3D bs->drv->bdrv_set_key(bs, key); - if (ret < 0) { - bs->valid_key =3D false; - } else if (!bs->valid_key) { - /* call the change callback now, we skipped it on open */ - bs->valid_key =3D true; - bdrv_parent_cb_change_media(bs, true); - } - return ret; -} - -/* - * Provide an encryption key for @bs. - * If @key is non-null: - * If @bs is not encrypted, fail. - * Else if the key is invalid, fail. - * Else set @bs's key to @key, replacing the existing key, if any. - * If @key is null: - * If @bs is encrypted and still lacks a key, fail. - * Else do nothing. - * On failure, store an error object through @errp if non-null. - */ -void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp) -{ - if (key) { - if (!bdrv_is_encrypted(bs)) { - error_setg(errp, "Node '%s' is not encrypted", - bdrv_get_device_or_node_name(bs)); - } else if (bdrv_set_key(bs, key) < 0) { - error_setg(errp, QERR_INVALID_PASSWORD); - } - } else { - if (bdrv_key_required(bs)) { - error_set(errp, ERROR_CLASS_DEVICE_ENCRYPTED, - "'%s' (%s) is encrypted", - bdrv_get_device_or_node_name(bs), - bdrv_get_encrypted_filename(bs)); - } - } -} - const char *bdrv_get_format_name(BlockDriverState *bs) { return bs->drv ? bs->drv->format_name : NULL; diff --git a/block/crypto.c b/block/crypto.c index da4be74..3ad4b20 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -308,7 +308,6 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, } =20 bs->encrypted =3D true; - bs->valid_key =3D true; =20 ret =3D 0; cleanup: diff --git a/block/qapi.c b/block/qapi.c index 0a41d59..080eb8f 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -45,7 +45,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk, info->ro =3D bs->read_only; info->drv =3D g_strdup(bs->drv->format_name); info->encrypted =3D bs->encrypted; - info->encryption_key_missing =3D bdrv_key_required(bs); + info->encryption_key_missing =3D false; =20 info->cache =3D g_new(BlockdevCacheInfo, 1); *info->cache =3D (BlockdevCacheInfo) { diff --git a/block/qcow.c b/block/qcow.c index db0c5a9..8a24930 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -220,7 +220,13 @@ static int qcow_open(BlockDriverState *bs, QDict *opti= ons, int flags, goto fail; } bs->encrypted =3D true; - bs->valid_key =3D true; + } else { + if (encryptfmt) { + error_setg(errp, "No encryption in image header, but options " + "specified format '%s'", encryptfmt); + ret =3D -EINVAL; + goto fail; + } } s->cluster_bits =3D header.cluster_bits; s->cluster_size =3D 1 << s->cluster_bits; diff --git a/block/qcow2.c b/block/qcow2.c index 7d1c5a3..2dd5d51 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1171,7 +1171,6 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, } =20 bs->encrypted =3D true; - bs->valid_key =3D true; } =20 s->l2_bits =3D s->cluster_bits - 3; /* L2 is always one cluster */ diff --git a/blockdev.c b/blockdev.c index e2016b6..92c5991 100644 --- a/blockdev.c +++ b/blockdev.c @@ -593,10 +593,6 @@ static BlockBackend *blockdev_init(const char *file, Q= Dict *bs_opts, =20 bs->detect_zeroes =3D detect_zeroes; =20 - if (bdrv_key_required(bs)) { - autostart =3D 0; - } - block_acct_setup(blk_get_stats(blk), account_invalid, account_fail= ed); =20 if (!parse_stats_intervals(blk_get_stats(blk), interval_list, errp= )) { @@ -2265,24 +2261,8 @@ void qmp_block_passwd(bool has_device, const char *d= evice, bool has_node_name, const char *node_name, const char *password, Error **errp) { - Error *local_err =3D NULL; - BlockDriverState *bs; - AioContext *aio_context; - - bs =3D bdrv_lookup_bs(has_device ? device : NULL, - has_node_name ? node_name : NULL, - &local_err); - if (local_err) { - error_propagate(errp, local_err); - return; - } - - aio_context =3D bdrv_get_aio_context(bs); - aio_context_acquire(aio_context); - - bdrv_add_key(bs, password, errp); - - aio_context_release(aio_context); + error_setg(errp, + "Setting block passwords directly is no longer supported"); } =20 /* @@ -2591,12 +2571,6 @@ void qmp_blockdev_change_medium(bool has_device, con= st char *device, goto fail; } =20 - bdrv_add_key(medium_bs, NULL, &err); - if (err) { - error_propagate(errp, err); - goto fail; - } - rc =3D do_open_tray(has_device ? device : NULL, has_id ? id : NULL, false, &err); @@ -3866,13 +3840,6 @@ void qmp_blockdev_add(BlockdevOptions *options, Erro= r **errp) =20 QTAILQ_INSERT_TAIL(&monitor_bdrv_states, bs, monitor_list); =20 - if (bs && bdrv_key_required(bs)) { - QTAILQ_REMOVE(&monitor_bdrv_states, bs, monitor_list); - bdrv_unref(bs); - error_setg(errp, "blockdev-add doesn't support encrypted devices"); - goto fail; - } - fail: visit_free(v); } diff --git a/hmp-commands.hx b/hmp-commands.hx index 275ccdf..75f8bac 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1646,6 +1646,8 @@ STEXI @item block_passwd @var{device} @var{password} @findex block_passwd Set the encrypted device @var{device} password to @var{password} + +This command is now obsolete and will always return an error since 2.10 ETEXI =20 { diff --git a/include/block/block.h b/include/block/block.h index 4a27252..2d637d1 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -464,9 +464,6 @@ BlockDriverState *bdrv_next(BdrvNextIterator *it); =20 BlockDriverState *bdrv_next_monitor_owned(BlockDriverState *bs); bool bdrv_is_encrypted(BlockDriverState *bs); -bool bdrv_key_required(BlockDriverState *bs); -int bdrv_set_key(BlockDriverState *bs, const char *key); -void bdrv_add_key(BlockDriverState *bs, const char *key, Error **errp); void bdrv_iterate_format(void (*it)(void *opaque, const char *name), void *opaque); const char *bdrv_get_node_name(const BlockDriverState *bs); diff --git a/include/block/block_int.h b/include/block/block_int.h index 701508d..b9069c5 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -529,7 +529,6 @@ struct BlockDriverState { int open_flags; /* flags used to open the file, re-used for re-open */ bool read_only; /* if true, the media is read only */ bool encrypted; /* if true, the media is encrypted */ - bool valid_key; /* if true, a valid encryption key has been set */ bool sg; /* if true, the device is a /dev/sg* */ bool probed; /* if true, format was probed rather than specified */ bool force_share; /* if true, always allow all shared permissions */ diff --git a/include/qapi/error.h b/include/qapi/error.h index 7e532d0..5d5e737 100644 --- a/include/qapi/error.h +++ b/include/qapi/error.h @@ -125,7 +125,6 @@ typedef enum ErrorClass { ERROR_CLASS_GENERIC_ERROR =3D QAPI_ERROR_CLASS_GENERICERROR, ERROR_CLASS_COMMAND_NOT_FOUND =3D QAPI_ERROR_CLASS_COMMANDNOTFOUND, - ERROR_CLASS_DEVICE_ENCRYPTED =3D QAPI_ERROR_CLASS_DEVICEENCRYPTED, ERROR_CLASS_DEVICE_NOT_ACTIVE =3D QAPI_ERROR_CLASS_DEVICENOTACTIVE, ERROR_CLASS_DEVICE_NOT_FOUND =3D QAPI_ERROR_CLASS_DEVICENOTFOUND, ERROR_CLASS_KVM_MISSING_CAP =3D QAPI_ERROR_CLASS_KVMMISSINGCAP, diff --git a/qapi/block-core.json b/qapi/block-core.json index bb075c0..d04d277 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -259,8 +259,7 @@ # # @encrypted: true if the backing device is encrypted # -# @encryption_key_missing: true if the backing device is encrypted but an -# valid encryption key is missing +# @encryption_key_missing: Deprecated; always false # # @detect_zeroes: detect and optimize zero writes (Since 2.1) # @@ -946,39 +945,7 @@ # This command sets the password of a block device that has not been open # with a password and requires one. # -# The two cases where this can happen are a block device is created through -# QEMU's initial command line or a block device is changed through the leg= acy -# @change interface. -# -# In the event that the block device is created through the initial command -# line, the VM will start in the stopped state regardless of whether '-S' = is -# used. The intention is for a management tool to query the block devices= to -# determine which ones are encrypted, set the passwords with this command,= and -# then start the guest with the @cont command. -# -# Either @device or @node-name must be set but not both. -# -# @device: the name of the block backend device to set the password on -# -# @node-name: graph node name to set the password on (Since 2.0) -# -# @password: the password to use for the device -# -# Returns: nothing on success -# If @device is not a valid block device, DeviceNotFound -# If @device is not encrypted, DeviceNotEncrypted -# -# Notes: Not all block formats support encryption and some that do are not -# able to validate that a password is correct. Disk corruption may -# occur if an invalid password is specified. -# -# Since: 0.14.0 -# -# Example: -# -# -> { "execute": "block_passwd", "arguments": { "device": "ide0-hd0", -# "password": "12345" } } -# <- { "return": {} } +# This command is now obsolete and will always return an error since 2.10 # ## { 'command': 'block_passwd', 'data': {'*device': 'str', diff --git a/qapi/common.json b/qapi/common.json index b626647..8355d5a 100644 --- a/qapi/common.json +++ b/qapi/common.json @@ -14,9 +14,6 @@ # # @CommandNotFound: the requested command has not been found # -# @DeviceEncrypted: the requested operation can't be fulfilled because the -# selected device is encrypted -# # @DeviceNotActive: a device has failed to be become active # # @DeviceNotFound: the requested device has not been found @@ -28,7 +25,7 @@ ## { 'enum': 'QapiErrorClass', # Keep this in sync with ErrorClass in error.h - 'data': [ 'GenericError', 'CommandNotFound', 'DeviceEncrypted', + 'data': [ 'GenericError', 'CommandNotFound', 'DeviceNotActive', 'DeviceNotFound', 'KVMMissingCap' ] } =20 ## --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450050085169.68517214000713; Fri, 7 Jul 2017 10:54:10 -0700 (PDT) Received: from localhost ([::1]:57954 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXSB-0002ZU-Ne for importer@patchew.org; Fri, 07 Jul 2017 13:54:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42830) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm5-00065U-OE for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm1-0000ID-Mj for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58174) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlu-0000AM-NW; Fri, 07 Jul 2017 13:10:26 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C16F8C0587C4; Fri, 7 Jul 2017 17:10:25 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id D478361F23; Fri, 7 Jul 2017 17:10:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C16F8C0587C4 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C16F8C0587C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:13 +0200 Message-Id: <1499447335-6125-59-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:10:25 +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] [PULL 058/100] block: pass option prefix down to crypto layer 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-devel@nongnu.org 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" From: "Daniel P. Berrange" While the crypto layer uses a fixed option name "key-secret", the upper block layer may have a prefix on the options. e.g. "encrypt.key-secret", in order to avoid clashes between crypto option names & other block option names. To ensure the crypto layer can report accurate error messages, we must tell it what option name prefix was used. Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-19-berrange@redhat.com Signed-off-by: Max Reitz --- block/crypto.c | 4 ++-- block/qcow.c | 7 ++++--- block/qcow2.c | 8 ++++---- crypto/block-luks.c | 8 ++++++-- crypto/block-qcow.c | 8 ++++++-- crypto/block.c | 6 ++++-- crypto/blockpriv.h | 2 ++ include/crypto/block.h | 6 +++++- tests/test-crypto-block.c | 8 ++++---- 9 files changed, 37 insertions(+), 20 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 3ad4b20..c561cba 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -296,7 +296,7 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, if (flags & BDRV_O_NO_IO) { cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; } - crypto->block =3D qcrypto_block_open(open_opts, + crypto->block =3D qcrypto_block_open(open_opts, NULL, block_crypto_read_func, bs, cflags, @@ -340,7 +340,7 @@ static int block_crypto_create_generic(QCryptoBlockForm= at format, return -1; } =20 - crypto =3D qcrypto_block_create(create_opts, + crypto =3D qcrypto_block_create(create_opts, NULL, block_crypto_init_func, block_crypto_write_func, &data, diff --git a/block/qcow.c b/block/qcow.c index 8a24930..2002c16 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -208,8 +208,8 @@ static int qcow_open(BlockDriverState *bs, QDict *optio= ns, int flags, if (flags & BDRV_O_NO_IO) { cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; } - s->crypto =3D qcrypto_block_open(crypto_opts, NULL, NULL, - cflags, errp); + s->crypto =3D qcrypto_block_open(crypto_opts, "encrypt.", + NULL, NULL, cflags, errp); if (!s->crypto) { ret =3D -EINVAL; goto fail; @@ -866,7 +866,8 @@ static int qcow_create(const char *filename, QemuOpts *= opts, Error **errp) goto exit; } =20 - crypto =3D qcrypto_block_create(crypto_opts, NULL, NULL, NULL, err= p); + crypto =3D qcrypto_block_create(crypto_opts, "encrypt.", + NULL, NULL, NULL, errp); if (!crypto) { ret =3D -EINVAL; goto exit; diff --git a/block/qcow2.c b/block/qcow2.c index 2dd5d51..f597fd0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -279,7 +279,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, if (flags & BDRV_O_NO_IO) { cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; } - s->crypto =3D qcrypto_block_open(s->crypto_opts, + s->crypto =3D qcrypto_block_open(s->crypto_opts, "encrypt.", qcow2_crypto_hdr_read_func, bs, cflags, errp); if (!s->crypto) { @@ -1313,8 +1313,8 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, if (flags & BDRV_O_NO_IO) { cflags |=3D QCRYPTO_BLOCK_OPEN_NO_IO; } - s->crypto =3D qcrypto_block_open(s->crypto_opts, NULL, NULL, - cflags, errp); + s->crypto =3D qcrypto_block_open(s->crypto_opts, "encrypt.", + NULL, NULL, cflags, errp); if (!s->crypto) { ret =3D -EINVAL; goto fail; @@ -2318,7 +2318,7 @@ static int qcow2_set_up_encryption(BlockDriverState *= bs, const char *encryptfmt, } s->crypt_method_header =3D fmt; =20 - crypto =3D qcrypto_block_create(cryptoopts, + crypto =3D qcrypto_block_create(cryptoopts, "encrypt.", qcow2_crypto_hdr_init_func, qcow2_crypto_hdr_write_func, bs, errp); diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 2b97d89..afb8543 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -638,6 +638,7 @@ qcrypto_block_luks_find_key(QCryptoBlock *block, static int qcrypto_block_luks_open(QCryptoBlock *block, QCryptoBlockOpenOptions *options, + const char *optprefix, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, @@ -661,7 +662,8 @@ qcrypto_block_luks_open(QCryptoBlock *block, =20 if (!(flags & QCRYPTO_BLOCK_OPEN_NO_IO)) { if (!options->u.luks.key_secret) { - error_setg(errp, "Parameter 'key-secret' is required for ciphe= r"); + error_setg(errp, "Parameter '%skey-secret' is required for cip= her", + optprefix ? optprefix : ""); return -1; } password =3D qcrypto_secret_lookup_as_utf8( @@ -885,6 +887,7 @@ qcrypto_block_luks_uuid_gen(uint8_t *uuidstr) static int qcrypto_block_luks_create(QCryptoBlock *block, QCryptoBlockCreateOptions *options, + const char *optprefix, QCryptoBlockInitFunc initfunc, QCryptoBlockWriteFunc writefunc, void *opaque, @@ -937,7 +940,8 @@ qcrypto_block_luks_create(QCryptoBlock *block, * be silently ignored, for compatibility with dm-crypt */ =20 if (!options->u.luks.key_secret) { - error_setg(errp, "Parameter 'key-secret' is required for cipher"); + error_setg(errp, "Parameter '%skey-secret' is required for cipher", + optprefix ? optprefix : ""); return -1; } password =3D qcrypto_secret_lookup_as_utf8(luks_opts.key_secret, errp); diff --git a/crypto/block-qcow.c b/crypto/block-qcow.c index be88c6f..a456fe3 100644 --- a/crypto/block-qcow.c +++ b/crypto/block-qcow.c @@ -94,6 +94,7 @@ qcrypto_block_qcow_init(QCryptoBlock *block, static int qcrypto_block_qcow_open(QCryptoBlock *block, QCryptoBlockOpenOptions *options, + const char *optprefix, QCryptoBlockReadFunc readfunc G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, unsigned int flags, @@ -104,7 +105,8 @@ qcrypto_block_qcow_open(QCryptoBlock *block, } else { if (!options->u.qcow.key_secret) { error_setg(errp, - "Parameter 'key-secret' is required for cipher"); + "Parameter '%skey-secret' is required for cipher", + optprefix ? optprefix : ""); return -1; } return qcrypto_block_qcow_init(block, @@ -116,13 +118,15 @@ qcrypto_block_qcow_open(QCryptoBlock *block, static int qcrypto_block_qcow_create(QCryptoBlock *block, QCryptoBlockCreateOptions *options, + const char *optprefix, QCryptoBlockInitFunc initfunc G_GNUC_UNUSED, QCryptoBlockWriteFunc writefunc G_GNUC_UNUSED, void *opaque G_GNUC_UNUSED, Error **errp) { if (!options->u.qcow.key_secret) { - error_setg(errp, "Parameter 'key-secret' is required for cipher"); + error_setg(errp, "Parameter '%skey-secret' is required for cipher", + optprefix ? optprefix : ""); return -1; } /* QCow2 has no special header, since everything is hardwired */ diff --git a/crypto/block.c b/crypto/block.c index 64c8420..b097d45 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -48,6 +48,7 @@ bool qcrypto_block_has_format(QCryptoBlockFormat format, =20 =20 QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions *options, + const char *optprefix, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, @@ -67,7 +68,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, =20 block->driver =3D qcrypto_block_drivers[options->format]; =20 - if (block->driver->open(block, options, + if (block->driver->open(block, options, optprefix, readfunc, opaque, flags, errp) < 0) { g_free(block); return NULL; @@ -78,6 +79,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions = *options, =20 =20 QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options, + const char *optprefix, QCryptoBlockInitFunc initfunc, QCryptoBlockWriteFunc writefunc, void *opaque, @@ -97,7 +99,7 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOpti= ons *options, =20 block->driver =3D qcrypto_block_drivers[options->format]; =20 - if (block->driver->create(block, options, initfunc, + if (block->driver->create(block, options, optprefix, initfunc, writefunc, opaque, errp) < 0) { g_free(block); return NULL; diff --git a/crypto/blockpriv.h b/crypto/blockpriv.h index 68f0f06..0edb810 100644 --- a/crypto/blockpriv.h +++ b/crypto/blockpriv.h @@ -41,6 +41,7 @@ struct QCryptoBlock { struct QCryptoBlockDriver { int (*open)(QCryptoBlock *block, QCryptoBlockOpenOptions *options, + const char *optprefix, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, @@ -48,6 +49,7 @@ struct QCryptoBlockDriver { =20 int (*create)(QCryptoBlock *block, QCryptoBlockCreateOptions *options, + const char *optprefix, QCryptoBlockInitFunc initfunc, QCryptoBlockWriteFunc writefunc, void *opaque, diff --git a/include/crypto/block.h b/include/crypto/block.h index 013a435..f0e543b 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -71,6 +71,7 @@ typedef enum { /** * qcrypto_block_open: * @options: the encryption options + * @optprefix: name prefix for options * @readfunc: callback for reading data from the volume * @opaque: data to pass to @readfunc * @flags: bitmask of QCryptoBlockOpenFlags values @@ -102,6 +103,7 @@ typedef enum { * Returns: a block encryption format, or NULL on error */ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOptions *options, + const char *optprefix, QCryptoBlockReadFunc readfunc, void *opaque, unsigned int flags, @@ -109,7 +111,8 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOption= s *options, =20 /** * qcrypto_block_create: - * @format: the encryption format + * @options: the encryption options + * @optprefix: name prefix for options * @initfunc: callback for initializing volume header * @writefunc: callback for writing data to the volume header * @opaque: data to pass to @initfunc and @writefunc @@ -133,6 +136,7 @@ QCryptoBlock *qcrypto_block_open(QCryptoBlockOpenOption= s *options, * Returns: a block encryption format, or NULL on error */ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options, + const char *optprefix, QCryptoBlockInitFunc initfunc, QCryptoBlockWriteFunc writefunc, void *opaque, diff --git a/tests/test-crypto-block.c b/tests/test-crypto-block.c index 95c4bd5..bd7fe59 100644 --- a/tests/test-crypto-block.c +++ b/tests/test-crypto-block.c @@ -281,7 +281,7 @@ static void test_block(gconstpointer opaque) memset(&header, 0, sizeof(header)); buffer_init(&header, "header"); =20 - blk =3D qcrypto_block_create(data->create_opts, + blk =3D qcrypto_block_create(data->create_opts, NULL, test_block_init_func, test_block_write_func, &header, @@ -300,7 +300,7 @@ static void test_block(gconstpointer opaque) object_unparent(sec); =20 /* Ensure we can't open without the secret */ - blk =3D qcrypto_block_open(data->open_opts, + blk =3D qcrypto_block_open(data->open_opts, NULL, test_block_read_func, &header, 0, @@ -308,7 +308,7 @@ static void test_block(gconstpointer opaque) g_assert(blk =3D=3D NULL); =20 /* Ensure we can't open without the secret, unless NO_IO */ - blk =3D qcrypto_block_open(data->open_opts, + blk =3D qcrypto_block_open(data->open_opts, NULL, test_block_read_func, &header, QCRYPTO_BLOCK_OPEN_NO_IO, @@ -322,7 +322,7 @@ static void test_block(gconstpointer opaque) =20 /* Now open for real with secret */ sec =3D test_block_secret(); - blk =3D qcrypto_block_open(data->open_opts, + blk =3D qcrypto_block_open(data->open_opts, NULL, test_block_read_func, &header, 0, --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450112274852.1382350468984; Fri, 7 Jul 2017 10:55:12 -0700 (PDT) Received: from localhost ([::1]:57957 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXTD-0003bE-0n for importer@patchew.org; Fri, 07 Jul 2017 13:55:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm3-000634-Oc for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm1-0000H6-2Q for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlv-0000B9-VJ; Fri, 07 Jul 2017 13:10:28 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BBF77CE06; Fri, 7 Jul 2017 17:10:27 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1940161F23; Fri, 7 Jul 2017 17:10:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0BBF77CE06 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0BBF77CE06 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:14 +0200 Message-Id: <1499447335-6125-60-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:10:27 +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] [PULL 059/100] qcow2: report encryption specific image information 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Currently 'qemu-img info' reports a simple "encrypted: yes" field. This is not very useful now that qcow2 can support multiple encryption formats. Users want to know which format is in use and some data related to it. Wire up usage of the qcrypto_block_get_info() method so that 'qemu-img info' can report about the encryption format and parameters in use $ qemu-img create \ --object secret,id=3Dsec0,data=3D123456 \ -o encrypt.format=3Dluks,encrypt.key-secret=3Dsec0 \ -f qcow2 demo.qcow2 1G Formatting 'demo.qcow2', fmt=3Dqcow2 size=3D1073741824 \ encryption=3Doff encrypt.format=3Dluks encrypt.key-secret=3Dsec0 \ cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 $ qemu-img info demo.qcow2 image: demo.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 480K encrypted: yes cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false refcount bits: 16 encrypt: ivgen alg: plain64 hash alg: sha256 cipher alg: aes-256 uuid: 3fa930c4-58c8-4ef7-b3c5-314bb5af21f3 format: luks cipher mode: xts slots: [0]: active: true iters: 1839058 key offset: 4096 stripes: 4000 [1]: active: false key offset: 262144 [2]: active: false key offset: 520192 [3]: active: false key offset: 778240 [4]: active: false key offset: 1036288 [5]: active: false key offset: 1294336 [6]: active: false key offset: 1552384 [7]: active: false key offset: 1810432 payload offset: 2068480 master key iters: 438487 corrupt: false With the legacy "AES" encryption we just report the format name $ qemu-img create \ --object secret,id=3Dsec0,data=3D123456 \ -o encrypt.format=3Daes,encrypt.key-secret=3Dsec0 \ -f qcow2 demo.qcow2 1G Formatting 'demo.qcow2', fmt=3Dqcow2 size=3D1073741824 \ encryption=3Doff encrypt.format=3Daes encrypt.key-secret=3Dsec0 \ cluster_size=3D65536 lazy_refcounts=3Doff refcount_bits=3D16 $ ./qemu-img info demo.qcow2 image: demo.qcow2 file format: qcow2 virtual size: 1.0G (1073741824 bytes) disk size: 196K encrypted: yes cluster_size: 65536 Format specific information: compat: 1.1 lazy refcounts: false refcount bits: 16 encrypt: format: aes corrupt: false Reviewed-by: Alberto Garcia Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-20-berrange@redhat.com Signed-off-by: Max Reitz --- block/qcow2.c | 32 +++++++++++++++++++++++++++++++- qapi/block-core.json | 27 ++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index f597fd0..5339aa0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3241,8 +3241,14 @@ static int qcow2_get_info(BlockDriverState *bs, Bloc= kDriverInfo *bdi) static ImageInfoSpecific *qcow2_get_specific_info(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; - ImageInfoSpecific *spec_info =3D g_new(ImageInfoSpecific, 1); + ImageInfoSpecific *spec_info; + QCryptoBlockInfo *encrypt_info =3D NULL; =20 + if (s->crypto !=3D NULL) { + encrypt_info =3D qcrypto_block_get_info(s->crypto, &error_abort); + } + + spec_info =3D g_new(ImageInfoSpecific, 1); *spec_info =3D (ImageInfoSpecific){ .type =3D IMAGE_INFO_SPECIFIC_KIND_QCOW2, .u.qcow2.data =3D g_new(ImageInfoSpecificQCow2, 1), @@ -3269,6 +3275,30 @@ static ImageInfoSpecific *qcow2_get_specific_info(Bl= ockDriverState *bs) assert(false); } =20 + if (encrypt_info) { + ImageInfoSpecificQCow2Encryption *qencrypt =3D + g_new(ImageInfoSpecificQCow2Encryption, 1); + switch (encrypt_info->format) { + case Q_CRYPTO_BLOCK_FORMAT_QCOW: + qencrypt->format =3D BLOCKDEV_QCOW2_ENCRYPTION_FORMAT_AES; + qencrypt->u.aes =3D encrypt_info->u.qcow; + break; + case Q_CRYPTO_BLOCK_FORMAT_LUKS: + qencrypt->format =3D BLOCKDEV_QCOW2_ENCRYPTION_FORMAT_LUKS; + qencrypt->u.luks =3D encrypt_info->u.luks; + break; + default: + abort(); + } + /* Since we did shallow copy above, erase any pointers + * in the original info */ + memset(&encrypt_info->u, 0, sizeof(encrypt_info->u)); + qapi_free_QCryptoBlockInfo(encrypt_info); + + spec_info->u.qcow2.data->has_encrypt =3D true; + spec_info->u.qcow2.data->encrypt =3D qencrypt; + } + return spec_info; } =20 diff --git a/qapi/block-core.json b/qapi/block-core.json index d04d277..9570963 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -33,6 +33,27 @@ 'vm-clock-sec': 'int', 'vm-clock-nsec': 'int' } } =20 ## +# @ImageInfoSpecificQCow2EncryptionBase: +# +# @format: The encryption format +# +# Since: 2.10 +## +{ 'struct': 'ImageInfoSpecificQCow2EncryptionBase', + 'data': { 'format': 'BlockdevQcow2EncryptionFormat'}} + +## +# @ImageInfoSpecificQCow2Encryption: +# +# Since: 2.10 +## +{ 'union': 'ImageInfoSpecificQCow2Encryption', + 'base': 'ImageInfoSpecificQCow2EncryptionBase', + 'discriminator': 'format', + 'data': { 'aes': 'QCryptoBlockInfoQCow', + 'luks': 'QCryptoBlockInfoLUKS' } } + +## # @ImageInfoSpecificQCow2: # # @compat: compatibility level @@ -44,6 +65,9 @@ # # @refcount-bits: width of a refcount entry in bits (since 2.3) # +# @encrypt: details about encryption parameters; only set if image +# is encrypted (since 2.10) +# # Since: 1.7 ## { 'struct': 'ImageInfoSpecificQCow2', @@ -51,7 +75,8 @@ 'compat': 'str', '*lazy-refcounts': 'bool', '*corrupt': 'bool', - 'refcount-bits': 'int' + 'refcount-bits': 'int', + '*encrypt': 'ImageInfoSpecificQCow2Encryption' } } =20 ## --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450578448298.1718715173513; Fri, 7 Jul 2017 11:02:58 -0700 (PDT) Received: from localhost ([::1]:58005 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXag-0002Oo-5F for importer@patchew.org; Fri, 07 Jul 2017 14:02:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm5-00064S-5A for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm1-0000Ht-H9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlx-0000Ba-4J; Fri, 07 Jul 2017 13:10:29 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 356C83680C; Fri, 7 Jul 2017 17:10:28 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CCC062924; Fri, 7 Jul 2017 17:10:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 356C83680C Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 356C83680C From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:15 +0200 Message-Id: <1499447335-6125-61-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:10: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] [PULL 060/100] docs: document encryption options for qcow, qcow2 and luks 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Expand the image format docs to cover the new options for the qcow, qcow2 and luks disk image formats Reviewed-by: Alberto Garcia Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170623162419.26068-21-berrange@redhat.com Signed-off-by: Max Reitz --- qemu-doc.texi | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++= ---- 1 file changed, 115 insertions(+), 8 deletions(-) diff --git a/qemu-doc.texi b/qemu-doc.texi index d2986cb..48af515 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -540,10 +540,20 @@ File name of a base image (see @option{create} subcom= mand) @item backing_fmt Image format of the base image @item encryption -If this option is set to @code{on}, the image is encrypted with 128-bit AE= S-CBC. +This option is deprecated and equivalent to @code{encrypt.format=3Daes} =20 -The use of encryption in qcow and qcow2 images is considered to be flawed = by -modern cryptography standards, suffering from a number of design problems: +@item encrypt.format + +If this is set to @code{luks}, it requests that the qcow2 payload (not +qcow2 header) be encrypted using the LUKS format. The passphrase to +use to unlock the LUKS key slot is given by the @code{encrypt.key-secret} +parameter. LUKS encryption parameters can be tuned with the other +@code{encrypt.*} parameters. + +If this is set to @code{aes}, the image is encrypted with 128-bit AES-CBC. +The encryption key is given by the @code{encrypt.key-secret} parameter. +This encryption format is considered to be flawed by modern cryptography +standards, suffering from a number of design problems: =20 @itemize @minus @item The AES-CBC cipher is used with predictable initialization vectors b= ased @@ -558,10 +568,45 @@ original file must then be securely erased using a pr= ogram like shred, though even this is ineffective with many modern storage technologies. @end itemize =20 -Use of qcow / qcow2 encryption with QEMU is deprecated, and support for -it will go away in a future release. Users are recommended to use an -alternative encryption technology such as the Linux dm-crypt / LUKS -system. +The use of this is no longer supported in system emulators. Support only +remains in the command line utilities, for the purposes of data liberation +and interoperability with old versions of QEMU. The @code{luks} format +should be used instead. + +@item encrypt.key-secret + +Provides the ID of a @code{secret} object that contains the passphrase +(@code{encrypt.format=3Dluks}) or encryption key (@code{encrypt.format=3Da= es}). + +@item encrypt.cipher-alg + +Name of the cipher algorithm and key length. Currently defaults +to @code{aes-256}. Only used when @code{encrypt.format=3Dluks}. + +@item encrypt.cipher-mode + +Name of the encryption mode to use. Currently defaults to @code{xts}. +Only used when @code{encrypt.format=3Dluks}. + +@item encrypt.ivgen-alg + +Name of the initialization vector generator algorithm. Currently defaults +to @code{plain64}. Only used when @code{encrypt.format=3Dluks}. + +@item encrypt.ivgen-hash-alg + +Name of the hash algorithm to use with the initialization vector generator +(if required). Defaults to @code{sha256}. Only used when @code{encrypt.for= mat=3Dluks}. + +@item encrypt.hash-alg + +Name of the hash algorithm to use for PBKDF algorithm +Defaults to @code{sha256}. Only used when @code{encrypt.format=3Dluks}. + +@item encrypt.iter-time + +Amount of time, in milliseconds, to use for PBKDF algorithm per key slot. +Defaults to @code{2000}. Only used when @code{encrypt.format=3Dluks}. =20 @item cluster_size Changes the qcow2 cluster size (must be between 512 and 2M). Smaller clust= er @@ -636,7 +681,69 @@ Supported options: @item backing_file File name of a base image (see @option{create} subcommand) @item encryption -If this option is set to @code{on}, the image is encrypted. +This option is deprecated and equivalent to @code{encrypt.format=3Daes} + +@item encrypt.format +If this is set to @code{aes}, the image is encrypted with 128-bit AES-CBC. +The encryption key is given by the @code{encrypt.key-secret} parameter. +This encryption format is considered to be flawed by modern cryptography +standards, suffering from a number of design problems enumerated previously +against the @code{qcow2} image format. + +The use of this is no longer supported in system emulators. Support only +remains in the command line utilities, for the purposes of data liberation +and interoperability with old versions of QEMU. + +Users requiring native encryption should use the @code{qcow2} format +instead with @code{encrypt.format=3Dluks}. + +@item encrypt.key-secret + +Provides the ID of a @code{secret} object that contains the encryption +key (@code{encrypt.format=3Daes}). + +@end table + +@item luks + +LUKS v1 encryption format, compatible with Linux dm-crypt/cryptsetup + +Supported options: +@table @code + +@item key-secret + +Provides the ID of a @code{secret} object that contains the passphrase. + +@item cipher-alg + +Name of the cipher algorithm and key length. Currently defaults +to @code{aes-256}. + +@item cipher-mode + +Name of the encryption mode to use. Currently defaults to @code{xts}. + +@item ivgen-alg + +Name of the initialization vector generator algorithm. Currently defaults +to @code{plain64}. + +@item ivgen-hash-alg + +Name of the hash algorithm to use with the initialization vector generator +(if required). Defaults to @code{sha256}. + +@item hash-alg + +Name of the hash algorithm to use for PBKDF algorithm +Defaults to @code{sha256}. + +@item iter-time + +Amount of time, in milliseconds, to use for PBKDF algorithm per key slot. +Defaults to @code{2000}. + @end table =20 @item vdi --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449967819600.5279385138238; Fri, 7 Jul 2017 10:52:47 -0700 (PDT) Received: from localhost ([::1]:57946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXQq-0001Qo-KT for importer@patchew.org; Fri, 07 Jul 2017 13:52:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42733) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm3-00062D-0q for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm1-0000Hk-FY for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41480) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWly-0000CK-DI; Fri, 07 Jul 2017 13:10:30 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6661861E50; Fri, 7 Jul 2017 17:10:29 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 807D561F23; Fri, 7 Jul 2017 17:10:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6661861E50 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6661861E50 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:16 +0200 Message-Id: <1499447335-6125-62-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:10:29 +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] [PULL 061/100] iotests: 181 does not work for all formats 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-devel@nongnu.org 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" From: Max Reitz Test 181 only works for formats which support live migration (naturally, as it is a live migration test). Disable it for all formats which do not. Signed-off-by: Max Reitz Message-id: 20170621131157.16584-1-mreitz@redhat.com Reviewed-by: John Snow Signed-off-by: Max Reitz --- tests/qemu-iotests/181 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/qemu-iotests/181 b/tests/qemu-iotests/181 index e969a2a..f73ad5a 100755 --- a/tests/qemu-iotests/181 +++ b/tests/qemu-iotests/181 @@ -43,6 +43,8 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.qemu =20 _supported_fmt generic +# Formats that do not support live migration +_unsupported_fmt qcow vdi vhdx vmdk vpc vvfat _supported_proto generic _supported_os Linux =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499448864844949.7012367743262; Fri, 7 Jul 2017 10:34:24 -0700 (PDT) Received: from localhost ([::1]:57826 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTX95-00026k-Av for importer@patchew.org; Fri, 07 Jul 2017 13:34:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42809) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWm5-00064a-8c for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm3-0000KY-G8 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53852) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWlz-0000Dh-Nf; Fri, 07 Jul 2017 13:10:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9CB117F410; Fri, 7 Jul 2017 17:10:30 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3F5861F23; Fri, 7 Jul 2017 17:10:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9CB117F410 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9CB117F410 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:17 +0200 Message-Id: <1499447335-6125-63-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:10:30 +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] [PULL 062/100] mirror: Fix inconsistent backing AioContext for after mirroring 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-devel@nongnu.org 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" From: "sochin.jiang" mirror_complete opens the backing chain, which should have the same AioContext as the top when using iothreads. Make the code guarantee this, which fixes a failed assertion in bdrv_attach_child. Signed-off-by: sochin.jiang Message-id: 1498475064-39816-1-git-send-email-sochin.jiang@huawei.com [mreitz: Reworded commit message] Signed-off-by: Max Reitz --- block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block.c b/block.c index edfa6b7..b9e5114 100644 --- a/block.c +++ b/block.c @@ -2185,6 +2185,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDic= t *parent_options, ret =3D -EINVAL; goto free_exit; } + bdrv_set_aio_context(backing_hd, bdrv_get_aio_context(bs)); =20 /* Hook up the backing file link; drop our reference, bs owns the * backing_hd reference now */ --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450195359315.7885749443707; Fri, 7 Jul 2017 10:56:35 -0700 (PDT) Received: from localhost ([::1]:57971 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXUW-00053n-Ue for importer@patchew.org; Fri, 07 Jul 2017 13:56:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmA-0006AZ-1b for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm5-0000MP-2O for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57770) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm0-0000FI-R5; Fri, 07 Jul 2017 13:10:32 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D05B345CB7; Fri, 7 Jul 2017 17:10:31 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E6F4561F23; Fri, 7 Jul 2017 17:10:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com D05B345CB7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com D05B345CB7 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:18 +0200 Message-Id: <1499447335-6125-64-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:32 +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] [PULL 063/100] specs/qcow2: fix bitmap granularity qemu-specific note 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Message-id: 20170628120530.31251-2-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- docs/interop/qcow2.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index 886a546..aee3553 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -575,8 +575,7 @@ Structure of a bitmap directory entry: 17: granularity_bits Granularity bits. Valid values: 0 - 63. =20 - Note: Qemu currently doesn't support granularity_bits - greater than 31. + Note: Qemu currently supports only values 9 - 31. =20 Granularity is calculated as granularity =3D 1 << granularity_bits --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450742906787.3106219942558; Fri, 7 Jul 2017 11:05:42 -0700 (PDT) Received: from localhost ([::1]:58024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXdN-00052i-Lm for importer@patchew.org; Fri, 07 Jul 2017 14:05:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42956) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmB-0006CW-IU for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWm9-0000TO-Ul for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53912) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm2-0000Ho-6x; Fri, 07 Jul 2017 13:10:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1A0807F40E; Fri, 7 Jul 2017 17:10:33 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2743E61F52; Fri, 7 Jul 2017 17:10:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1A0807F40E Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1A0807F40E From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:19 +0200 Message-Id: <1499447335-6125-65-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:10:33 +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] [PULL 064/100] specs/qcow2: do not use wording 'bitmap header' 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy A bitmap directory entry is sometimes called a 'bitmap header'. This patch leaves only one name - 'bitmap directory entry'. The name 'bitmap header' creates misunderstandings with 'qcow2 header' and 'qcow2 bitmap header extension' (which is extension of qcow2 header) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: John Snow Message-id: 20170628120530.31251-3-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- docs/interop/qcow2.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/interop/qcow2.txt b/docs/interop/qcow2.txt index aee3553..d7fdb1f 100644 --- a/docs/interop/qcow2.txt +++ b/docs/interop/qcow2.txt @@ -203,7 +203,7 @@ The fields of the bitmaps extension are: =20 8 - 15: bitmap_directory_size Size of the bitmap directory in bytes. It is the cumula= tive - size of all (nb_bitmaps) bitmap headers. + size of all (nb_bitmaps) bitmap directory entries. =20 16 - 23: bitmap_directory_offset Offset into the image file at which the bitmap directory @@ -529,8 +529,7 @@ Each bitmap saved in the image is described in a bitmap= directory entry. The bitmap directory is a contiguous area in the image file, whose starting of= fset and length are given by the header extension fields bitmap_directory_offse= t and bitmap_directory_size. The entries of the bitmap directory have variable -length, depending on the lengths of the bitmap name and extra data. These -entries are also called bitmap headers. +length, depending on the lengths of the bitmap name and extra data. =20 Structure of a bitmap directory entry: =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450520581583.9768720680959; Fri, 7 Jul 2017 11:02:00 -0700 (PDT) Received: from localhost ([::1]:58002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXZm-0001g4-Ru for importer@patchew.org; Fri, 07 Jul 2017 14:01:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmG-0006JP-8J for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmB-0000WO-JR for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38686) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm3-0000Jm-J1; Fri, 07 Jul 2017 13:10:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7D1F013A60; Fri, 7 Jul 2017 17:10:34 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58BBE62924; Fri, 7 Jul 2017 17:10:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7D1F013A60 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7D1F013A60 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:20 +0200 Message-Id: <1499447335-6125-66-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:10:34 +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] [PULL 065/100] hbitmap: improve dirty iter 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Make dirty iter resistant to resetting bits in corresponding HBitmap. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-4-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- include/qemu/hbitmap.h | 26 ++++---------------------- util/hbitmap.c | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 9239fe5..6b04391 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -256,10 +256,9 @@ void hbitmap_free(HBitmap *hb); * the lowest-numbered bit that is set in @hb, starting at @first. * * Concurrent setting of bits is acceptable, and will at worst cause the - * iteration to miss some of those bits. Resetting bits before the current - * position of the iterator is also okay. However, concurrent resetting of - * bits can lead to unexpected behavior if the iterator has not yet reached - * those bits. + * iteration to miss some of those bits. + * + * The concurrent resetting of bits is OK. */ void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first= ); =20 @@ -298,24 +297,7 @@ void hbitmap_free_meta(HBitmap *hb); * Return the next bit that is set in @hbi's associated HBitmap, * or -1 if all remaining bits are zero. */ -static inline int64_t hbitmap_iter_next(HBitmapIter *hbi) -{ - unsigned long cur =3D hbi->cur[HBITMAP_LEVELS - 1]; - int64_t item; - - if (cur =3D=3D 0) { - cur =3D hbitmap_iter_skip_words(hbi); - if (cur =3D=3D 0) { - return -1; - } - } - - /* The next call will resume work from the next bit. */ - hbi->cur[HBITMAP_LEVELS - 1] =3D cur & (cur - 1); - item =3D ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur); - - return item << hbi->granularity; -} +int64_t hbitmap_iter_next(HBitmapIter *hbi); =20 /** * hbitmap_iter_next_word: diff --git a/util/hbitmap.c b/util/hbitmap.c index 35088e1..0b38817 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -106,8 +106,9 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi) =20 unsigned long cur; do { - cur =3D hbi->cur[--i]; + i--; pos >>=3D BITS_PER_LEVEL; + cur =3D hbi->cur[i] & hb->levels[i][pos]; } while (cur =3D=3D 0); =20 /* Check for end of iteration. We always use fewer than BITS_PER_LONG @@ -139,6 +140,26 @@ unsigned long hbitmap_iter_skip_words(HBitmapIter *hbi) return cur; } =20 +int64_t hbitmap_iter_next(HBitmapIter *hbi) +{ + unsigned long cur =3D hbi->cur[HBITMAP_LEVELS - 1] & + hbi->hb->levels[HBITMAP_LEVELS - 1][hbi->pos]; + int64_t item; + + if (cur =3D=3D 0) { + cur =3D hbitmap_iter_skip_words(hbi); + if (cur =3D=3D 0) { + return -1; + } + } + + /* The next call will resume work from the next bit. */ + hbi->cur[HBITMAP_LEVELS - 1] =3D cur & (cur - 1); + item =3D ((uint64_t)hbi->pos << BITS_PER_LEVEL) + ctzl(cur); + + return item << hbi->granularity; +} + void hbitmap_iter_init(HBitmapIter *hbi, const HBitmap *hb, uint64_t first) { unsigned i, bit; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450902241162.35346998281773; Fri, 7 Jul 2017 11:08:22 -0700 (PDT) Received: from localhost ([::1]:58041 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXft-000791-W0 for importer@patchew.org; Fri, 07 Jul 2017 14:08:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmC-0006Eb-Vd for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmB-0000WE-Hm for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm4-0000LK-Up; Fri, 07 Jul 2017 13:10:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AACB674864; Fri, 7 Jul 2017 17:10:35 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id C591761F23; Fri, 7 Jul 2017 17:10:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com AACB674864 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com AACB674864 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:21 +0200 Message-Id: <1499447335-6125-67-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:35 +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] [PULL 066/100] tests: add hbitmap iter test 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Test that hbitmap iter is resistant to bitmap resetting. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-5-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- tests/test-hbitmap.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test-hbitmap.c b/tests/test-hbitmap.c index 23773d2..1acb353 100644 --- a/tests/test-hbitmap.c +++ b/tests/test-hbitmap.c @@ -909,6 +909,22 @@ static void hbitmap_test_add(const char *testpath, hbitmap_test_teardown); } =20 +static void test_hbitmap_iter_and_reset(TestHBitmapData *data, + const void *unused) +{ + HBitmapIter hbi; + + hbitmap_test_init(data, L1 * 2, 0); + hbitmap_set(data->hb, 0, data->size); + + hbitmap_iter_init(&hbi, data->hb, BITS_PER_LONG - 1); + + hbitmap_iter_next(&hbi); + + hbitmap_reset_all(data->hb); + hbitmap_iter_next(&hbi); +} + int main(int argc, char **argv) { g_test_init(&argc, &argv, NULL); @@ -966,6 +982,9 @@ int main(int argc, char **argv) test_hbitmap_serialize_part); hbitmap_test_add("/hbitmap/serialize/zeroes", test_hbitmap_serialize_zeroes); + + hbitmap_test_add("/hbitmap/iter/iter_and_reset", + test_hbitmap_iter_and_reset); g_test_run(); =20 return 0; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450365744315.86361365403206; Fri, 7 Jul 2017 10:59:25 -0700 (PDT) Received: from localhost ([::1]:57984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXXI-0007hh-BL for importer@patchew.org; Fri, 07 Jul 2017 13:59:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42999) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmC-0006Ec-Vu for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmB-0000Vx-E3 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57420) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm6-0000N5-1d; Fri, 07 Jul 2017 13:10:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0E4F83F3E; Fri, 7 Jul 2017 17:10:36 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03552627DB; Fri, 7 Jul 2017 17:10:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E0E4F83F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E0E4F83F3E From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:22 +0200 Message-Id: <1499447335-6125-68-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:37 +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] [PULL 067/100] block: fix bdrv_dirty_bitmap_granularity signature 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Make getter signature const-correct. This allows other functions with const dirty bitmap parameter use bdrv_dirty_bitmap_granularity(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: John Snow Reviewed-by: Kevin Wolf Message-id: 20170628120530.31251-6-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 2 +- include/block/dirty-bitmap.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index a04c6e4..df0110c 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -455,7 +455,7 @@ uint32_t bdrv_get_default_bitmap_granularity(BlockDrive= rState *bs) return granularity; } =20 -uint32_t bdrv_dirty_bitmap_granularity(BdrvDirtyBitmap *bitmap) +uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap) { return BDRV_SECTOR_SIZE << hbitmap_granularity(bitmap->bitmap); } diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index ad6558a..ab89f08 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -29,7 +29,7 @@ void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); uint32_t bdrv_get_default_bitmap_granularity(BlockDriverState *bs); -uint32_t bdrv_dirty_bitmap_granularity(BdrvDirtyBitmap *bitmap); +uint32_t bdrv_dirty_bitmap_granularity(const BdrvDirtyBitmap *bitmap); uint32_t bdrv_dirty_bitmap_meta_granularity(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_enabled(BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_frozen(BdrvDirtyBitmap *bitmap); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450090379530.128287554614; Fri, 7 Jul 2017 10:54:50 -0700 (PDT) Received: from localhost ([::1]:57956 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXSq-0003G1-3o for importer@patchew.org; Fri, 07 Jul 2017 13:54:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43004) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmD-0006Eh-2x for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmB-0000W3-Dw for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54016) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm7-0000P4-34; Fri, 07 Jul 2017 13:10:39 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20E507F411; Fri, 7 Jul 2017 17:10:38 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3704D61F23; Fri, 7 Jul 2017 17:10:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 20E507F411 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 20E507F411 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:23 +0200 Message-Id: <1499447335-6125-69-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:10:38 +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] [PULL 068/100] block/dirty-bitmap: add deserialize_ones func 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Add bdrv_dirty_bitmap_deserialize_ones() function, which is needed for qcow2 bitmap loading, to handle unallocated bitmap parts, marked as all-ones. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Kevin Wolf Reviewed-by: John Snow Message-id: 20170628120530.31251-7-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 7 +++++++ include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 15 +++++++++++++++ util/hbitmap.c | 17 +++++++++++++++++ 4 files changed, 42 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index df0110c..f502c45 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -586,6 +586,13 @@ void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBit= map *bitmap, hbitmap_deserialize_zeroes(bitmap->bitmap, start, count, finish); } =20 +void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, + uint64_t start, uint64_t count, + bool finish) +{ + hbitmap_deserialize_ones(bitmap->bitmap, start, count, finish); +} + void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap) { hbitmap_deserialize_finish(bitmap->bitmap); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index ab89f08..05451c7 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -66,6 +66,9 @@ void bdrv_dirty_bitmap_deserialize_part(BdrvDirtyBitmap *= bitmap, void bdrv_dirty_bitmap_deserialize_zeroes(BdrvDirtyBitmap *bitmap, uint64_t start, uint64_t count, bool finish); +void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *bitmap, + uint64_t start, uint64_t count, + bool finish); void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); =20 /* Functions that require manual locking. */ diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 6b04391..b52304a 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -229,6 +229,21 @@ void hbitmap_deserialize_zeroes(HBitmap *hb, uint64_t = start, uint64_t count, bool finish); =20 /** + * hbitmap_deserialize_ones + * @hb: HBitmap to operate on. + * @start: First bit to restore. + * @count: Number of bits to restore. + * @finish: Whether to call hbitmap_deserialize_finish automatically. + * + * Fills the bitmap with ones. + * + * If @finish is false, caller must call hbitmap_serialize_finish before u= sing + * the bitmap. + */ +void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count, + bool finish); + +/** * hbitmap_deserialize_finish * @hb: HBitmap to operate on. * diff --git a/util/hbitmap.c b/util/hbitmap.c index 0b38817..0c1591a 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -551,6 +551,23 @@ void hbitmap_deserialize_zeroes(HBitmap *hb, uint64_t = start, uint64_t count, } } =20 +void hbitmap_deserialize_ones(HBitmap *hb, uint64_t start, uint64_t count, + bool finish) +{ + uint64_t el_count; + unsigned long *first; + + if (!count) { + return; + } + serialization_chunk(hb, start, count, &first, &el_count); + + memset(first, 0xff, el_count * sizeof(unsigned long)); + if (finish) { + hbitmap_deserialize_finish(hb); + } +} + void hbitmap_deserialize_finish(HBitmap *bitmap) { int64_t i, size, prev_size; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449508443669.6983825564168; Fri, 7 Jul 2017 10:45:08 -0700 (PDT) Received: from localhost ([::1]:57890 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXJS-0003Nm-Lz for importer@patchew.org; Fri, 07 Jul 2017 13:45:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmD-0006Fm-Rf for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmC-0000XI-75 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57966) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm8-0000Py-8S; Fri, 07 Jul 2017 13:10:40 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 538A5A0221; Fri, 7 Jul 2017 17:10:39 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 69EFB627DB; Fri, 7 Jul 2017 17:10:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 538A5A0221 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 538A5A0221 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:24 +0200 Message-Id: <1499447335-6125-70-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:39 +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] [PULL 069/100] qcow2-refcount: rename inc_refcounts() and make it public 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy This is needed for the following patch, which will introduce refcounts checking for qcow2 bitmaps. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-8-vsementsov@virtuozzo.com [mreitz: s/inc_refcounts/qcow2_inc_refcounts_imrt/ in one more (new) place] Signed-off-by: Max Reitz --- block/qcow2-refcount.c | 59 ++++++++++++++++++++++++++--------------------= ---- block/qcow2.h | 4 ++++ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 81c22e6..8add3d5 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1323,11 +1323,10 @@ static int realloc_refcount_array(BDRVQcow2State *s= , void **array, * * Modifies the number of errors in res. */ -static int inc_refcounts(BlockDriverState *bs, - BdrvCheckResult *res, - void **refcount_table, - int64_t *refcount_table_size, - int64_t offset, int64_t size) +int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res, + void **refcount_table, + int64_t *refcount_table_size, + int64_t offset, int64_t size) { BDRVQcow2State *s =3D bs->opaque; uint64_t start, last, cluster_offset, k, refcount; @@ -1420,8 +1419,9 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, nb_csectors =3D ((l2_entry >> s->csize_shift) & s->csize_mask) + 1; l2_entry &=3D s->cluster_offset_mask; - ret =3D inc_refcounts(bs, res, refcount_table, refcount_table_= size, - l2_entry & ~511, nb_csectors * 512); + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, refcount_table_= size, + l2_entry & ~511, nb_csectors * = 512); if (ret < 0) { goto fail; } @@ -1454,8 +1454,9 @@ static int check_refcounts_l2(BlockDriverState *bs, B= drvCheckResult *res, } =20 /* Mark cluster as used */ - ret =3D inc_refcounts(bs, res, refcount_table, refcount_table_= size, - offset, s->cluster_size); + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, refcount_table_= size, + offset, s->cluster_size); if (ret < 0) { goto fail; } @@ -1508,8 +1509,8 @@ static int check_refcounts_l1(BlockDriverState *bs, l1_size2 =3D l1_size * sizeof(uint64_t); =20 /* Mark L1 table as used */ - ret =3D inc_refcounts(bs, res, refcount_table, refcount_table_size, - l1_table_offset, l1_size2); + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_tab= le_size, + l1_table_offset, l1_size2); if (ret < 0) { goto fail; } @@ -1538,8 +1539,9 @@ static int check_refcounts_l1(BlockDriverState *bs, if (l2_offset) { /* Mark L2 table as used */ l2_offset &=3D L1E_OFFSET_MASK; - ret =3D inc_refcounts(bs, res, refcount_table, refcount_table_= size, - l2_offset, s->cluster_size); + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, refcount_table_= size, + l2_offset, s->cluster_size); if (ret < 0) { goto fail; } @@ -1757,14 +1759,15 @@ static int check_refblocks(BlockDriverState *bs, Bd= rvCheckResult *res, } =20 res->corruptions_fixed++; - ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, - offset, s->cluster_size); + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, nb_clusters, + offset, s->cluster_size); if (ret < 0) { return ret; } /* No need to check whether the refcount is now greater th= an 1: * This area was just allocated and zeroed, so it can only= be - * exactly 1 after inc_refcounts() */ + * exactly 1 after qcow2_inc_refcounts_imrt() */ continue; =20 resize_fail: @@ -1779,8 +1782,8 @@ resize_fail: } =20 if (offset !=3D 0) { - ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, - offset, s->cluster_size); + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_c= lusters, + offset, s->cluster_size); if (ret < 0) { return ret; } @@ -1820,8 +1823,8 @@ static int calculate_refcounts(BlockDriverState *bs, = BdrvCheckResult *res, } =20 /* header */ - ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, - 0, s->cluster_size); + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, + 0, s->cluster_size); if (ret < 0) { return ret; } @@ -1842,25 +1845,25 @@ static int calculate_refcounts(BlockDriverState *bs= , BdrvCheckResult *res, return ret; } } - ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, - s->snapshots_offset, s->snapshots_size); + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, + s->snapshots_offset, s->snapshots_size); if (ret < 0) { return ret; } =20 /* refcount data */ - ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, - s->refcount_table_offset, - s->refcount_table_size * sizeof(uint64_t)); + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clusters, + s->refcount_table_offset, + s->refcount_table_size * sizeof(uint64_= t)); if (ret < 0) { return ret; } =20 /* encryption */ if (s->crypto_header.length) { - ret =3D inc_refcounts(bs, res, refcount_table, nb_clusters, - s->crypto_header.offset, - s->crypto_header.length); + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, nb_clust= ers, + s->crypto_header.offset, + s->crypto_header.length); if (ret < 0) { return ret; } diff --git a/block/qcow2.h b/block/qcow2.h index 84c9853..a272a39 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -544,6 +544,10 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs,= int ign, int64_t offset, int64_t size); int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t o= ffset, int64_t size); +int qcow2_inc_refcounts_imrt(BlockDriverState *bs, BdrvCheckResult *res, + void **refcount_table, + int64_t *refcount_table_size, + int64_t offset, int64_t size); =20 int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, BlockDriverAmendStatusCB *status_cb, --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451354988728.0946269092725; Fri, 7 Jul 2017 11:15:54 -0700 (PDT) Received: from localhost ([::1]:58083 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXnD-0005tz-Iy for importer@patchew.org; Fri, 07 Jul 2017 14:15:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmK-0006OK-B7 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmH-0000ex-3X for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38866) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWm9-0000RP-GU; Fri, 07 Jul 2017 13:10:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 86D3019D05F; Fri, 7 Jul 2017 17:10:40 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DFA961F23; Fri, 7 Jul 2017 17:10:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 86D3019D05F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 86D3019D05F From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:25 +0200 Message-Id: <1499447335-6125-71-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:10:40 +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] [PULL 070/100] qcow2: add bitmaps extension 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Add bitmap extension as specified in docs/specs/qcow2.txt. For now, just mirror extension header into Qcow2 state and check constraints. Also, calculate refcounts for qcow2 bitmaps, to not break qemu-img check. For now, disable image resize if it has bitmaps. It will be fixed later. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-9-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/Makefile.objs | 2 +- block/qcow2-bitmap.c | 439 +++++++++++++++++++++++++++++++++++++++++++++= ++++ block/qcow2-refcount.c | 6 + block/qcow2.c | 125 +++++++++++++- block/qcow2.h | 27 +++ 5 files changed, 593 insertions(+), 6 deletions(-) create mode 100644 block/qcow2-bitmap.c diff --git a/block/Makefile.objs b/block/Makefile.objs index f9368b5..2aaede4 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -1,5 +1,5 @@ block-obj-y +=3D raw-format.o qcow.o vdi.o vmdk.o cloop.o bochs.o vpc.o vv= fat.o dmg.o -block-obj-y +=3D qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o= qcow2-cache.o +block-obj-y +=3D qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o= qcow2-cache.o qcow2-bitmap.o block-obj-y +=3D qed.o qed-l2-cache.o qed-table.o qed-cluster.o block-obj-y +=3D qed-check.o block-obj-y +=3D vhdx.o vhdx-endian.o vhdx-log.o diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c new file mode 100644 index 0000000..b8e472b --- /dev/null +++ b/block/qcow2-bitmap.c @@ -0,0 +1,439 @@ +/* + * Bitmaps for the QCOW version 2 format + * + * Copyright (c) 2014-2017 Vladimir Sementsov-Ogievskiy + * + * This file is derived from qcow2-snapshot.c, original copyright: + * Copyright (c) 2004-2006 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" + +#include "block/block_int.h" +#include "block/qcow2.h" + +/* NOTICE: BME here means Bitmaps Extension and used as a namespace for + * _internal_ constants. Please do not use this _internal_ abbreviation for + * other needs and/or outside of this file. */ + +/* Bitmap directory entry constraints */ +#define BME_MAX_TABLE_SIZE 0x8000000 +#define BME_MAX_PHYS_SIZE 0x20000000 /* restrict BdrvDirtyBitmap size in R= AM */ +#define BME_MAX_GRANULARITY_BITS 31 +#define BME_MIN_GRANULARITY_BITS 9 +#define BME_MAX_NAME_SIZE 1023 + +/* Bitmap directory entry flags */ +#define BME_RESERVED_FLAGS 0xfffffffcU + +/* bits [1, 8] U [56, 63] are reserved */ +#define BME_TABLE_ENTRY_RESERVED_MASK 0xff000000000001feULL +#define BME_TABLE_ENTRY_OFFSET_MASK 0x00fffffffffffe00ULL +#define BME_TABLE_ENTRY_FLAG_ALL_ONES (1ULL << 0) + +typedef struct QEMU_PACKED Qcow2BitmapDirEntry { + /* header is 8 byte aligned */ + uint64_t bitmap_table_offset; + + uint32_t bitmap_table_size; + uint32_t flags; + + uint8_t type; + uint8_t granularity_bits; + uint16_t name_size; + uint32_t extra_data_size; + /* extra data follows */ + /* name follows */ +} Qcow2BitmapDirEntry; + +typedef struct Qcow2BitmapTable { + uint64_t offset; + uint32_t size; /* number of 64bit entries */ + QSIMPLEQ_ENTRY(Qcow2BitmapTable) entry; +} Qcow2BitmapTable; + +typedef struct Qcow2Bitmap { + Qcow2BitmapTable table; + uint32_t flags; + uint8_t granularity_bits; + char *name; + + QSIMPLEQ_ENTRY(Qcow2Bitmap) entry; +} Qcow2Bitmap; +typedef QSIMPLEQ_HEAD(Qcow2BitmapList, Qcow2Bitmap) Qcow2BitmapList; + +typedef enum BitmapType { + BT_DIRTY_TRACKING_BITMAP =3D 1 +} BitmapType; + +static int check_table_entry(uint64_t entry, int cluster_size) +{ + uint64_t offset; + + if (entry & BME_TABLE_ENTRY_RESERVED_MASK) { + return -EINVAL; + } + + offset =3D entry & BME_TABLE_ENTRY_OFFSET_MASK; + if (offset !=3D 0) { + /* if offset specified, bit 0 is reserved */ + if (entry & BME_TABLE_ENTRY_FLAG_ALL_ONES) { + return -EINVAL; + } + + if (offset % cluster_size !=3D 0) { + return -EINVAL; + } + } + + return 0; +} + +static int bitmap_table_load(BlockDriverState *bs, Qcow2BitmapTable *tb, + uint64_t **bitmap_table) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + uint32_t i; + uint64_t *table; + + assert(tb->size !=3D 0); + table =3D g_try_new(uint64_t, tb->size); + if (table =3D=3D NULL) { + return -ENOMEM; + } + + assert(tb->size <=3D BME_MAX_TABLE_SIZE); + ret =3D bdrv_pread(bs->file, tb->offset, + table, tb->size * sizeof(uint64_t)); + if (ret < 0) { + goto fail; + } + + for (i =3D 0; i < tb->size; ++i) { + be64_to_cpus(&table[i]); + ret =3D check_table_entry(table[i], s->cluster_size); + if (ret < 0) { + goto fail; + } + } + + *bitmap_table =3D table; + return 0; + +fail: + g_free(table); + + return ret; +} + +/* + * Bitmap List + */ + +/* + * Bitmap List private functions + * Only Bitmap List knows about bitmap directory structure in Qcow2. + */ + +static inline void bitmap_dir_entry_to_cpu(Qcow2BitmapDirEntry *entry) +{ + be64_to_cpus(&entry->bitmap_table_offset); + be32_to_cpus(&entry->bitmap_table_size); + be32_to_cpus(&entry->flags); + be16_to_cpus(&entry->name_size); + be32_to_cpus(&entry->extra_data_size); +} + +static inline int calc_dir_entry_size(size_t name_size, size_t extra_data_= size) +{ + return align_offset(sizeof(Qcow2BitmapDirEntry) + + name_size + extra_data_size, 8); +} + +static inline int dir_entry_size(Qcow2BitmapDirEntry *entry) +{ + return calc_dir_entry_size(entry->name_size, entry->extra_data_size); +} + +static inline const char *dir_entry_name_field(Qcow2BitmapDirEntry *entry) +{ + return (const char *)(entry + 1) + entry->extra_data_size; +} + +static inline char *dir_entry_copy_name(Qcow2BitmapDirEntry *entry) +{ + const char *name_field =3D dir_entry_name_field(entry); + return g_strndup(name_field, entry->name_size); +} + +static inline Qcow2BitmapDirEntry *next_dir_entry(Qcow2BitmapDirEntry *ent= ry) +{ + return (Qcow2BitmapDirEntry *)((uint8_t *)entry + dir_entry_size(entry= )); +} + +static int check_dir_entry(BlockDriverState *bs, Qcow2BitmapDirEntry *entr= y) +{ + BDRVQcow2State *s =3D bs->opaque; + uint64_t phys_bitmap_bytes; + int64_t len; + + bool fail =3D (entry->bitmap_table_size =3D=3D 0) || + (entry->bitmap_table_offset =3D=3D 0) || + (entry->bitmap_table_offset % s->cluster_size) || + (entry->bitmap_table_size > BME_MAX_TABLE_SIZE) || + (entry->granularity_bits > BME_MAX_GRANULARITY_BITS) || + (entry->granularity_bits < BME_MIN_GRANULARITY_BITS) || + (entry->flags & BME_RESERVED_FLAGS) || + (entry->name_size > BME_MAX_NAME_SIZE) || + (entry->type !=3D BT_DIRTY_TRACKING_BITMAP); + + if (fail) { + return -EINVAL; + } + + phys_bitmap_bytes =3D (uint64_t)entry->bitmap_table_size * s->cluster_= size; + len =3D bdrv_getlength(bs); + + if (len < 0) { + return len; + } + + fail =3D (phys_bitmap_bytes > BME_MAX_PHYS_SIZE) || + (len > ((phys_bitmap_bytes * 8) << entry->granularity_bits)); + + return fail ? -EINVAL : 0; +} + +/* + * Bitmap List public functions + */ + +static void bitmap_free(Qcow2Bitmap *bm) +{ + g_free(bm->name); + g_free(bm); +} + +static void bitmap_list_free(Qcow2BitmapList *bm_list) +{ + Qcow2Bitmap *bm; + + if (bm_list =3D=3D NULL) { + return; + } + + while ((bm =3D QSIMPLEQ_FIRST(bm_list)) !=3D NULL) { + QSIMPLEQ_REMOVE_HEAD(bm_list, entry); + bitmap_free(bm); + } + + g_free(bm_list); +} + +static Qcow2BitmapList *bitmap_list_new(void) +{ + Qcow2BitmapList *bm_list =3D g_new(Qcow2BitmapList, 1); + QSIMPLEQ_INIT(bm_list); + + return bm_list; +} + +/* bitmap_list_load + * Get bitmap list from qcow2 image. Actually reads bitmap directory, + * checks it and convert to bitmap list. + */ +static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t of= fset, + uint64_t size, Error **errp) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + uint8_t *dir, *dir_end; + Qcow2BitmapDirEntry *e; + uint32_t nb_dir_entries =3D 0; + Qcow2BitmapList *bm_list =3D NULL; + + if (size =3D=3D 0) { + error_setg(errp, "Requested bitmap directory size is zero"); + return NULL; + } + + if (size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { + error_setg(errp, "Requested bitmap directory size is too big"); + return NULL; + } + + dir =3D g_try_malloc(size); + if (dir =3D=3D NULL) { + error_setg(errp, "Failed to allocate space for bitmap directory"); + return NULL; + } + dir_end =3D dir + size; + + ret =3D bdrv_pread(bs->file, offset, dir, size); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to read bitmap directory"); + goto fail; + } + + bm_list =3D bitmap_list_new(); + for (e =3D (Qcow2BitmapDirEntry *)dir; + e < (Qcow2BitmapDirEntry *)dir_end; + e =3D next_dir_entry(e)) + { + Qcow2Bitmap *bm; + + if ((uint8_t *)(e + 1) > dir_end) { + goto broken_dir; + } + + if (++nb_dir_entries > s->nb_bitmaps) { + error_setg(errp, "More bitmaps found than specified in header" + " extension"); + goto fail; + } + bitmap_dir_entry_to_cpu(e); + + if ((uint8_t *)next_dir_entry(e) > dir_end) { + goto broken_dir; + } + + if (e->extra_data_size !=3D 0) { + error_setg(errp, "Bitmap extra data is not supported"); + goto fail; + } + + ret =3D check_dir_entry(bs, e); + if (ret < 0) { + error_setg(errp, "Bitmap '%.*s' doesn't satisfy the constraint= s", + e->name_size, dir_entry_name_field(e)); + goto fail; + } + + bm =3D g_new(Qcow2Bitmap, 1); + bm->table.offset =3D e->bitmap_table_offset; + bm->table.size =3D e->bitmap_table_size; + bm->flags =3D e->flags; + bm->granularity_bits =3D e->granularity_bits; + bm->name =3D dir_entry_copy_name(e); + QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry); + } + + if (nb_dir_entries !=3D s->nb_bitmaps) { + error_setg(errp, "Less bitmaps found than specified in header" + " extension"); + goto fail; + } + + if ((uint8_t *)e !=3D dir_end) { + goto broken_dir; + } + + g_free(dir); + return bm_list; + +broken_dir: + ret =3D -EINVAL; + error_setg(errp, "Broken bitmap directory"); + +fail: + g_free(dir); + bitmap_list_free(bm_list); + + return NULL; +} + +int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, + void **refcount_table, + int64_t *refcount_table_size) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + Qcow2BitmapList *bm_list; + Qcow2Bitmap *bm; + + if (s->nb_bitmaps =3D=3D 0) { + return 0; + } + + ret =3D qcow2_inc_refcounts_imrt(bs, res, refcount_table, refcount_tab= le_size, + s->bitmap_directory_offset, + s->bitmap_directory_size); + if (ret < 0) { + return ret; + } + + bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, + s->bitmap_directory_size, NULL); + if (bm_list =3D=3D NULL) { + res->corruptions++; + return -EINVAL; + } + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + uint64_t *bitmap_table =3D NULL; + int i; + + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, refcount_table_size, + bm->table.offset, + bm->table.size * sizeof(uint64_t)); + if (ret < 0) { + goto out; + } + + ret =3D bitmap_table_load(bs, &bm->table, &bitmap_table); + if (ret < 0) { + res->corruptions++; + goto out; + } + + for (i =3D 0; i < bm->table.size; ++i) { + uint64_t entry =3D bitmap_table[i]; + uint64_t offset =3D entry & BME_TABLE_ENTRY_OFFSET_MASK; + + if (check_table_entry(entry, s->cluster_size) < 0) { + res->corruptions++; + continue; + } + + if (offset =3D=3D 0) { + continue; + } + + ret =3D qcow2_inc_refcounts_imrt(bs, res, + refcount_table, refcount_table_= size, + offset, s->cluster_size); + if (ret < 0) { + g_free(bitmap_table); + goto out; + } + } + + g_free(bitmap_table); + } + +out: + bitmap_list_free(bm_list); + + return ret; +} diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 8add3d5..ceb08bc 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1869,6 +1869,12 @@ static int calculate_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, } } =20 + /* bitmaps */ + ret =3D qcow2_check_bitmaps_refcounts(bs, res, refcount_table, nb_clus= ters); + if (ret < 0) { + return ret; + } + return check_refblocks(bs, res, fix, rebuild, refcount_table, nb_clust= ers); } =20 diff --git a/block/qcow2.c b/block/qcow2.c index 5339aa0..8688fdd 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -67,6 +67,7 @@ typedef struct { #define QCOW2_EXT_MAGIC_BACKING_FORMAT 0xE2792ACA #define QCOW2_EXT_MAGIC_FEATURE_TABLE 0x6803f857 #define QCOW2_EXT_MAGIC_CRYPTO_HEADER 0x0537be77 +#define QCOW2_EXT_MAGIC_BITMAPS 0x23852875 =20 static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filen= ame) { @@ -170,12 +171,18 @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlo= ck *block, size_t offset, */ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offs= et, uint64_t end_offset, void **p_feature_tab= le, - int flags, Error **errp) + int flags, bool *need_update_header, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; QCowExtension ext; uint64_t offset; int ret; + Qcow2BitmapHeaderExt bitmaps_ext; + + if (need_update_header !=3D NULL) { + *need_update_header =3D false; + } =20 #ifdef DEBUG_EXT printf("qcow2_read_extensions: start=3D%ld end=3D%ld\n", start_offset,= end_offset); @@ -287,6 +294,85 @@ static int qcow2_read_extensions(BlockDriverState *bs,= uint64_t start_offset, } } break; =20 + case QCOW2_EXT_MAGIC_BITMAPS: + if (ext.len !=3D sizeof(bitmaps_ext)) { + error_setg_errno(errp, -ret, "bitmaps_ext: " + "Invalid extension length"); + return -EINVAL; + } + + if (!(s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS)) { + error_report("WARNING: a program lacking bitmap support " + "modified this file, so all bitmaps are now " + "considered inconsistent. Some clusters may b= e " + "leaked, run 'qemu-img check -r' on the image= " + "file to fix."); + if (need_update_header !=3D NULL) { + /* Updating is needed to drop invalid bitmap extension= . */ + *need_update_header =3D true; + } + break; + } + + ret =3D bdrv_pread(bs->file, offset, &bitmaps_ext, ext.len); + if (ret < 0) { + error_setg_errno(errp, -ret, "bitmaps_ext: " + "Could not read ext header"); + return ret; + } + + if (bitmaps_ext.reserved32 !=3D 0) { + error_setg_errno(errp, -ret, "bitmaps_ext: " + "Reserved field is not zero"); + return -EINVAL; + } + + be32_to_cpus(&bitmaps_ext.nb_bitmaps); + be64_to_cpus(&bitmaps_ext.bitmap_directory_size); + be64_to_cpus(&bitmaps_ext.bitmap_directory_offset); + + if (bitmaps_ext.nb_bitmaps > QCOW2_MAX_BITMAPS) { + error_setg(errp, + "bitmaps_ext: Image has %" PRIu32 " bitmaps, " + "exceeding the QEMU supported maximum of %d", + bitmaps_ext.nb_bitmaps, QCOW2_MAX_BITMAPS); + return -EINVAL; + } + + if (bitmaps_ext.nb_bitmaps =3D=3D 0) { + error_setg(errp, "found bitmaps extension with zero bitmap= s"); + return -EINVAL; + } + + if (bitmaps_ext.bitmap_directory_offset & (s->cluster_size - 1= )) { + error_setg(errp, "bitmaps_ext: " + "invalid bitmap directory offset"); + return -EINVAL; + } + + if (bitmaps_ext.bitmap_directory_size > + QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { + error_setg(errp, "bitmaps_ext: " + "bitmap directory size (%" PRIu64 ") exce= eds " + "the maximum supported size (%d)", + bitmaps_ext.bitmap_directory_size, + QCOW2_MAX_BITMAP_DIRECTORY_SIZE); + return -EINVAL; + } + + s->nb_bitmaps =3D bitmaps_ext.nb_bitmaps; + s->bitmap_directory_offset =3D + bitmaps_ext.bitmap_directory_offset; + s->bitmap_directory_size =3D + bitmaps_ext.bitmap_directory_size; + +#ifdef DEBUG_EXT + printf("Qcow2: Got bitmaps extension: " + "offset=3D%" PRIu64 " nb_bitmaps=3D%" PRIu32 "\n", + s->bitmap_directory_offset, s->nb_bitmaps); +#endif + break; + default: /* unknown magic - save it in case we need to rewrite the head= er */ { @@ -1008,6 +1094,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, Error *local_err =3D NULL; uint64_t ext_end; uint64_t l1_vm_state_index; + bool update_header =3D false; =20 ret =3D bdrv_pread(bs->file, 0, &header, sizeof(header)); if (ret < 0) { @@ -1113,7 +1200,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, if (s->incompatible_features & ~QCOW2_INCOMPAT_MASK) { void *feature_table =3D NULL; qcow2_read_extensions(bs, header.header_length, ext_end, - &feature_table, flags, NULL); + &feature_table, flags, NULL, NULL); report_unsupported_feature(errp, feature_table, s->incompatible_features & ~QCOW2_INCOMPAT_MASK); @@ -1297,7 +1384,7 @@ static int qcow2_do_open(BlockDriverState *bs, QDict = *options, int flags, =20 /* read qcow2 extensions */ if (qcow2_read_extensions(bs, header.header_length, ext_end, NULL, - flags, &local_err)) { + flags, &update_header, &local_err)) { error_propagate(errp, local_err); ret =3D -EINVAL; goto fail; @@ -1357,8 +1444,10 @@ static int qcow2_do_open(BlockDriverState *bs, QDict= *options, int flags, } =20 /* Clear unknown autoclear feature bits */ - if (!bs->read_only && !(flags & BDRV_O_INACTIVE) && s->autoclear_featu= res) { - s->autoclear_features =3D 0; + update_header |=3D s->autoclear_features & ~QCOW2_AUTOCLEAR_MASK; + + if (update_header && !bs->read_only && !(flags & BDRV_O_INACTIVE)) { + s->autoclear_features &=3D QCOW2_AUTOCLEAR_MASK; ret =3D qcow2_update_header(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Could not update qcow2 header"); @@ -2203,6 +2292,25 @@ int qcow2_update_header(BlockDriverState *bs) buflen -=3D ret; } =20 + /* Bitmap extension */ + if (s->nb_bitmaps > 0) { + Qcow2BitmapHeaderExt bitmaps_header =3D { + .nb_bitmaps =3D cpu_to_be32(s->nb_bitmaps), + .bitmap_directory_size =3D + cpu_to_be64(s->bitmap_directory_size), + .bitmap_directory_offset =3D + cpu_to_be64(s->bitmap_directory_offset) + }; + ret =3D header_ext_add(buf, QCOW2_EXT_MAGIC_BITMAPS, + &bitmaps_header, sizeof(bitmaps_header), + buflen); + if (ret < 0) { + goto fail; + } + buf +=3D ret; + buflen -=3D ret; + } + /* Keep unknown header extensions */ QLIST_FOREACH(uext, &s->unknown_header_ext, next) { ret =3D header_ext_add(buf, uext->magic, uext->data, uext->len, bu= flen); @@ -2884,6 +2992,13 @@ static int qcow2_truncate(BlockDriverState *bs, int6= 4_t offset, Error **errp) return -ENOTSUP; } =20 + /* cannot proceed if image has bitmaps */ + if (s->nb_bitmaps) { + /* TODO: resize bitmaps in the image */ + error_setg(errp, "Can't resize an image which has bitmaps"); + return -ENOTSUP; + } + /* shrinking is currently not supported */ if (offset < bs->total_sectors * 512) { error_setg(errp, "qcow2 doesn't support shrinking images yet"); diff --git a/block/qcow2.h b/block/qcow2.h index a272a39..3488648 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -53,6 +53,10 @@ * space for snapshot names and IDs */ #define QCOW_MAX_SNAPSHOTS_SIZE (1024 * QCOW_MAX_SNAPSHOTS) =20 +/* Bitmap header extension constraints */ +#define QCOW2_MAX_BITMAPS 65535 +#define QCOW2_MAX_BITMAP_DIRECTORY_SIZE (1024 * QCOW2_MAX_BITMAPS) + /* indicate that the refcount of the referenced cluster is exactly one. */ #define QCOW_OFLAG_COPIED (1ULL << 63) /* indicate that the cluster is compressed (they never have the copied fla= g) */ @@ -201,6 +205,14 @@ enum { QCOW2_COMPAT_FEAT_MASK =3D QCOW2_COMPAT_LAZY_REFCOUNTS, }; =20 +/* Autoclear feature bits */ +enum { + QCOW2_AUTOCLEAR_BITMAPS_BITNR =3D 0, + QCOW2_AUTOCLEAR_BITMAPS =3D 1 << QCOW2_AUTOCLEAR_BITMAPS_BITNR, + + QCOW2_AUTOCLEAR_MASK =3D QCOW2_AUTOCLEAR_BITMAPS, +}; + enum qcow2_discard_type { QCOW2_DISCARD_NEVER =3D 0, QCOW2_DISCARD_ALWAYS, @@ -228,6 +240,13 @@ typedef uint64_t Qcow2GetRefcountFunc(const void *refc= ount_array, typedef void Qcow2SetRefcountFunc(void *refcount_array, uint64_t index, uint64_t value); =20 +typedef struct Qcow2BitmapHeaderExt { + uint32_t nb_bitmaps; + uint32_t reserved32; + uint64_t bitmap_directory_size; + uint64_t bitmap_directory_offset; +} QEMU_PACKED Qcow2BitmapHeaderExt; + typedef struct BDRVQcow2State { int cluster_bits; int cluster_size; @@ -274,6 +293,10 @@ typedef struct BDRVQcow2State { unsigned int nb_snapshots; QCowSnapshot *snapshots; =20 + uint32_t nb_bitmaps; + uint64_t bitmap_directory_size; + uint64_t bitmap_directory_offset; + int flags; int qcow_version; bool use_lazy_refcounts; @@ -618,4 +641,8 @@ int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Ca= che *c, uint64_t offset, void **table); void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); =20 +/* qcow2-bitmap.c functions */ +int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, + void **refcount_table, + int64_t *refcount_table_size); #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451049326962.2695064500339; Fri, 7 Jul 2017 11:10:49 -0700 (PDT) Received: from localhost ([::1]:58055 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXiK-00012d-4K for importer@patchew.org; Fri, 07 Jul 2017 14:10:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43072) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmF-0006Ho-8v for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmE-0000aB-AL for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmA-0000To-OI; Fri, 07 Jul 2017 13:10:42 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BB3817F6B9; Fri, 7 Jul 2017 17:10:41 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id D13A861F23; Fri, 7 Jul 2017 17:10:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BB3817F6B9 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BB3817F6B9 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:26 +0200 Message-Id: <1499447335-6125-72-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:10:41 +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] [PULL 071/100] block/dirty-bitmap: fix comment for BlockDirtyBitmap.disabled field 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Reviewed-by: Max Reitz Message-id: 20170628120530.31251-10-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index f502c45..a8fe149 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -43,7 +43,8 @@ struct BdrvDirtyBitmap { BdrvDirtyBitmap *successor; /* Anonymous child; implies frozen status = */ char *name; /* Optional non-empty unique ID */ int64_t size; /* Size of the bitmap (Number of sectors) = */ - bool disabled; /* Bitmap is read-only */ + bool disabled; /* Bitmap is disabled. It ignores all writ= es to + the device */ int active_iterators; /* How many iterators are active */ QLIST_ENTRY(BdrvDirtyBitmap) list; }; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499449911883102.65373012489624; Fri, 7 Jul 2017 10:51:51 -0700 (PDT) Received: from localhost ([::1]:57934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXPx-0000df-ET for importer@patchew.org; Fri, 07 Jul 2017 13:51:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43174) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmK-0006Ob-Cm for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmF-0000dF-Ro for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58070) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmB-0000Vq-T6; Fri, 07 Jul 2017 13:10:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EDA2FA4F81; Fri, 7 Jul 2017 17:10:42 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1019961F23; Fri, 7 Jul 2017 17:10:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EDA2FA4F81 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EDA2FA4F81 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:27 +0200 Message-Id: <1499447335-6125-73-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:43 +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] [PULL 072/100] block/dirty-bitmap: add readonly field to BdrvDirtyBitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy It will be needed in following commits for persistent bitmaps. If bitmap is loaded from read-only storage (and we can't mark it "in use" in this storage) corresponding BdrvDirtyBitmap should be read-only. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20170628120530.31251-11-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 36 ++++++++++++++++++++++++++++++++++++ block/io.c | 8 ++++++++ blockdev.c | 6 ++++++ include/block/dirty-bitmap.h | 4 ++++ 4 files changed, 54 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index a8fe149..17d3068 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -46,6 +46,12 @@ struct BdrvDirtyBitmap { bool disabled; /* Bitmap is disabled. It ignores all writ= es to the device */ int active_iterators; /* How many iterators are active */ + bool readonly; /* Bitmap is read-only. This field also + prevents the respective image from being + modified (i.e. blocks writes and discar= ds). + Such operations must fail and both the = image + and this bitmap must remain unchanged w= hile + this flag is set. */ QLIST_ENTRY(BdrvDirtyBitmap) list; }; =20 @@ -505,6 +511,7 @@ void bdrv_set_dirty_bitmap_locked(BdrvDirtyBitmap *bitm= ap, int64_t cur_sector, int64_t nr_sectors) { assert(bdrv_dirty_bitmap_enabled(bitmap)); + assert(!bdrv_dirty_bitmap_readonly(bitmap)); hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); } =20 @@ -521,6 +528,7 @@ void bdrv_reset_dirty_bitmap_locked(BdrvDirtyBitmap *bi= tmap, int64_t cur_sector, int64_t nr_sectors) { assert(bdrv_dirty_bitmap_enabled(bitmap)); + assert(!bdrv_dirty_bitmap_readonly(bitmap)); hbitmap_reset(bitmap->bitmap, cur_sector, nr_sectors); } =20 @@ -535,6 +543,7 @@ void bdrv_reset_dirty_bitmap(BdrvDirtyBitmap *bitmap, void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out) { assert(bdrv_dirty_bitmap_enabled(bitmap)); + assert(!bdrv_dirty_bitmap_readonly(bitmap)); bdrv_dirty_bitmap_lock(bitmap); if (!out) { hbitmap_reset_all(bitmap->bitmap); @@ -551,6 +560,7 @@ void bdrv_undo_clear_dirty_bitmap(BdrvDirtyBitmap *bitm= ap, HBitmap *in) { HBitmap *tmp =3D bitmap->bitmap; assert(bdrv_dirty_bitmap_enabled(bitmap)); + assert(!bdrv_dirty_bitmap_readonly(bitmap)); bitmap->bitmap =3D in; hbitmap_free(tmp); } @@ -613,6 +623,7 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t cur_s= ector, if (!bdrv_dirty_bitmap_enabled(bitmap)) { continue; } + assert(!bdrv_dirty_bitmap_readonly(bitmap)); hbitmap_set(bitmap->bitmap, cur_sector, nr_sectors); } bdrv_dirty_bitmaps_unlock(bs); @@ -635,3 +646,28 @@ int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bit= map) { return hbitmap_count(bitmap->meta); } + +bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap) +{ + return bitmap->readonly; +} + +/* Called with BQL taken. */ +void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value) +{ + qemu_mutex_lock(bitmap->mutex); + bitmap->readonly =3D value; + qemu_mutex_unlock(bitmap->mutex); +} + +bool bdrv_has_readonly_bitmaps(BlockDriverState *bs) +{ + BdrvDirtyBitmap *bm; + QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { + if (bm->readonly) { + return true; + } + } + + return false; +} diff --git a/block/io.c b/block/io.c index 23170a5..b413727 100644 --- a/block/io.c +++ b/block/io.c @@ -1315,6 +1315,10 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChi= ld *child, uint64_t bytes_remaining =3D bytes; int max_transfer; =20 + if (bdrv_has_readonly_bitmaps(bs)) { + return -EPERM; + } + assert(is_power_of_2(align)); assert((offset & (align - 1)) =3D=3D 0); assert((bytes & (align - 1)) =3D=3D 0); @@ -2287,6 +2291,10 @@ int coroutine_fn bdrv_co_pdiscard(BlockDriverState *= bs, int64_t offset, return -ENOMEDIUM; } =20 + if (bdrv_has_readonly_bitmaps(bs)) { + return -EPERM; + } + ret =3D bdrv_check_byte_request(bs, offset, bytes); if (ret < 0) { return ret; diff --git a/blockdev.c b/blockdev.c index 92c5991..edeb36b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2033,6 +2033,9 @@ static void block_dirty_bitmap_clear_prepare(BlkActio= nState *common, } else if (!bdrv_dirty_bitmap_enabled(state->bitmap)) { error_setg(errp, "Cannot clear a disabled bitmap"); return; + } else if (bdrv_dirty_bitmap_readonly(state->bitmap)) { + error_setg(errp, "Cannot clear a readonly bitmap"); + return; } =20 bdrv_clear_dirty_bitmap(state->bitmap, &state->backup); @@ -2779,6 +2782,9 @@ void qmp_block_dirty_bitmap_clear(const char *node, c= onst char *name, "Bitmap '%s' is currently disabled and cannot be cleare= d", name); return; + } else if (bdrv_dirty_bitmap_readonly(bitmap)) { + error_setg(errp, "Bitmap '%s' is readonly and cannot be cleared", = name); + return; } =20 bdrv_clear_dirty_bitmap(bitmap, NULL); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 05451c7..cb43fa3 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -71,6 +71,8 @@ void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *= bitmap, bool finish); void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); =20 +void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); + /* Functions that require manual locking. */ void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); void bdrv_dirty_bitmap_unlock(BdrvDirtyBitmap *bitmap); @@ -85,5 +87,7 @@ void bdrv_set_dirty_iter(BdrvDirtyBitmapIter *hbi, int64_= t sector_num); int64_t bdrv_get_dirty_count(BdrvDirtyBitmap *bitmap); int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap); void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); +bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); +bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451675064654.4973931518958; Fri, 7 Jul 2017 11:21:15 -0700 (PDT) Received: from localhost ([::1]:58120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXsO-00024C-PK for importer@patchew.org; Fri, 07 Jul 2017 14:21:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmM-0006RS-TK for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmK-0000iW-CU for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57598) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmD-0000Y0-4W; Fri, 07 Jul 2017 13:10:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 31A0883F3E; Fri, 7 Jul 2017 17:10:44 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 465D661F52; Fri, 7 Jul 2017 17:10:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 31A0883F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 31A0883F3E From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:28 +0200 Message-Id: <1499447335-6125-74-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:44 +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] [PULL 073/100] qcow2: autoloading dirty bitmaps 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Auto loading bitmaps are bitmaps in Qcow2, with the AUTO flag set. They are loaded when the image is opened and become BdrvDirtyBitmaps for the corresponding drive. Extra data in bitmaps is not supported for now. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-12-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 389 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ block/qcow2.c | 17 ++- block/qcow2.h | 2 + 3 files changed, 406 insertions(+), 2 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index b8e472b..2c7b057 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -44,6 +44,8 @@ =20 /* Bitmap directory entry flags */ #define BME_RESERVED_FLAGS 0xfffffffcU +#define BME_FLAG_IN_USE (1U << 0) +#define BME_FLAG_AUTO (1U << 1) =20 /* bits [1, 8] U [56, 63] are reserved */ #define BME_TABLE_ENTRY_RESERVED_MASK 0xff000000000001feULL @@ -85,6 +87,23 @@ typedef enum BitmapType { BT_DIRTY_TRACKING_BITMAP =3D 1 } BitmapType; =20 +static inline bool can_write(BlockDriverState *bs) +{ + return !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIV= E); +} + +static int update_header_sync(BlockDriverState *bs) +{ + int ret; + + ret =3D qcow2_update_header(bs); + if (ret < 0) { + return ret; + } + + return bdrv_flush(bs); +} + static int check_table_entry(uint64_t entry, int cluster_size) { uint64_t offset; @@ -146,6 +165,120 @@ fail: return ret; } =20 +/* This function returns the number of disk sectors covered by a single qc= ow2 + * cluster of bitmap data. */ +static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s, + const BdrvDirtyBitmap *b= itmap) +{ + uint32_t sector_granularity =3D + bdrv_dirty_bitmap_granularity(bitmap) >> BDRV_SECTOR_BITS; + + return (uint64_t)sector_granularity * (s->cluster_size << 3); +} + +/* load_bitmap_data + * @bitmap_table entries must satisfy specification constraints. + * @bitmap must be cleared */ +static int load_bitmap_data(BlockDriverState *bs, + const uint64_t *bitmap_table, + uint32_t bitmap_table_size, + BdrvDirtyBitmap *bitmap) +{ + int ret =3D 0; + BDRVQcow2State *s =3D bs->opaque; + uint64_t sector, sbc; + uint64_t bm_size =3D bdrv_dirty_bitmap_size(bitmap); + uint8_t *buf =3D NULL; + uint64_t i, tab_size =3D + size_to_clusters(s, + bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size)); + + if (tab_size !=3D bitmap_table_size || tab_size > BME_MAX_TABLE_SIZE) { + return -EINVAL; + } + + buf =3D g_malloc(s->cluster_size); + sbc =3D sectors_covered_by_bitmap_cluster(s, bitmap); + for (i =3D 0, sector =3D 0; i < tab_size; ++i, sector +=3D sbc) { + uint64_t count =3D MIN(bm_size - sector, sbc); + uint64_t entry =3D bitmap_table[i]; + uint64_t offset =3D entry & BME_TABLE_ENTRY_OFFSET_MASK; + + assert(check_table_entry(entry, s->cluster_size) =3D=3D 0); + + if (offset =3D=3D 0) { + if (entry & BME_TABLE_ENTRY_FLAG_ALL_ONES) { + bdrv_dirty_bitmap_deserialize_ones(bitmap, sector, count, + false); + } else { + /* No need to deserialize zeros because the dirty bitmap is + * already cleared */ + } + } else { + ret =3D bdrv_pread(bs->file, offset, buf, s->cluster_size); + if (ret < 0) { + goto finish; + } + bdrv_dirty_bitmap_deserialize_part(bitmap, buf, sector, count, + false); + } + } + ret =3D 0; + + bdrv_dirty_bitmap_deserialize_finish(bitmap); + +finish: + g_free(buf); + + return ret; +} + +static BdrvDirtyBitmap *load_bitmap(BlockDriverState *bs, + Qcow2Bitmap *bm, Error **errp) +{ + int ret; + uint64_t *bitmap_table =3D NULL; + uint32_t granularity; + BdrvDirtyBitmap *bitmap =3D NULL; + + if (bm->flags & BME_FLAG_IN_USE) { + error_setg(errp, "Bitmap '%s' is in use", bm->name); + goto fail; + } + + ret =3D bitmap_table_load(bs, &bm->table, &bitmap_table); + if (ret < 0) { + error_setg_errno(errp, -ret, + "Could not read bitmap_table table from image for= " + "bitmap '%s'", bm->name); + goto fail; + } + + granularity =3D 1U << bm->granularity_bits; + bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, bm->name, errp); + if (bitmap =3D=3D NULL) { + goto fail; + } + + ret =3D load_bitmap_data(bs, bitmap_table, bm->table.size, bitmap); + if (ret < 0) { + error_setg_errno(errp, -ret, "Could not read bitmap '%s' from imag= e", + bm->name); + goto fail; + } + + g_free(bitmap_table); + return bitmap; + +fail: + g_free(bitmap_table); + if (bitmap !=3D NULL) { + bdrv_release_dirty_bitmap(bs, bitmap); + } + + return NULL; +} + /* * Bitmap List */ @@ -164,6 +297,15 @@ static inline void bitmap_dir_entry_to_cpu(Qcow2Bitmap= DirEntry *entry) be32_to_cpus(&entry->extra_data_size); } =20 +static inline void bitmap_dir_entry_to_be(Qcow2BitmapDirEntry *entry) +{ + cpu_to_be64s(&entry->bitmap_table_offset); + cpu_to_be32s(&entry->bitmap_table_size); + cpu_to_be32s(&entry->flags); + cpu_to_be16s(&entry->name_size); + cpu_to_be32s(&entry->extra_data_size); +} + static inline int calc_dir_entry_size(size_t name_size, size_t extra_data_= size) { return align_offset(sizeof(Qcow2BitmapDirEntry) + @@ -224,6 +366,17 @@ static int check_dir_entry(BlockDriverState *bs, Qcow2= BitmapDirEntry *entry) return fail ? -EINVAL : 0; } =20 +static inline void bitmap_directory_to_be(uint8_t *dir, size_t size) +{ + uint8_t *end =3D dir + size; + while (dir < end) { + Qcow2BitmapDirEntry *e =3D (Qcow2BitmapDirEntry *)dir; + dir +=3D dir_entry_size(e); + + bitmap_dir_entry_to_be(e); + } +} + /* * Bitmap List public functions */ @@ -258,6 +411,18 @@ static Qcow2BitmapList *bitmap_list_new(void) return bm_list; } =20 +static uint32_t bitmap_list_count(Qcow2BitmapList *bm_list) +{ + Qcow2Bitmap *bm; + uint32_t nb_bitmaps =3D 0; + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + nb_bitmaps++; + } + + return nb_bitmaps; +} + /* bitmap_list_load * Get bitmap list from qcow2 image. Actually reads bitmap directory, * checks it and convert to bitmap list. @@ -437,3 +602,227 @@ out: =20 return ret; } + +/* bitmap_list_store + * Store bitmap list to qcow2 image as a bitmap directory. + * Everything is checked. + */ +static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_lis= t, + uint64_t *offset, uint64_t *size, bool in_pla= ce) +{ + int ret; + uint8_t *dir; + int64_t dir_offset =3D 0; + uint64_t dir_size =3D 0; + Qcow2Bitmap *bm; + Qcow2BitmapDirEntry *e; + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + dir_size +=3D calc_dir_entry_size(strlen(bm->name), 0); + } + + if (dir_size =3D=3D 0 || dir_size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { + return -EINVAL; + } + + if (in_place) { + if (*size !=3D dir_size || *offset =3D=3D 0) { + return -EINVAL; + } + + dir_offset =3D *offset; + } + + dir =3D g_try_malloc(dir_size); + if (dir =3D=3D NULL) { + return -ENOMEM; + } + + e =3D (Qcow2BitmapDirEntry *)dir; + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + e->bitmap_table_offset =3D bm->table.offset; + e->bitmap_table_size =3D bm->table.size; + e->flags =3D bm->flags; + e->type =3D BT_DIRTY_TRACKING_BITMAP; + e->granularity_bits =3D bm->granularity_bits; + e->name_size =3D strlen(bm->name); + e->extra_data_size =3D 0; + memcpy(e + 1, bm->name, e->name_size); + + if (check_dir_entry(bs, e) < 0) { + ret =3D -EINVAL; + goto fail; + } + + e =3D next_dir_entry(e); + } + + bitmap_directory_to_be(dir, dir_size); + + if (!in_place) { + dir_offset =3D qcow2_alloc_clusters(bs, dir_size); + if (dir_offset < 0) { + ret =3D dir_offset; + goto fail; + } + } + + ret =3D qcow2_pre_write_overlap_check(bs, 0, dir_offset, dir_size); + if (ret < 0) { + goto fail; + } + + ret =3D bdrv_pwrite(bs->file, dir_offset, dir, dir_size); + if (ret < 0) { + goto fail; + } + + g_free(dir); + + if (!in_place) { + *size =3D dir_size; + *offset =3D dir_offset; + } + + return 0; + +fail: + g_free(dir); + + if (!in_place && dir_offset > 0) { + qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_OTHER); + } + + return ret; +} + +/* + * Bitmap List end + */ + +static int update_ext_header_and_dir_in_place(BlockDriverState *bs, + Qcow2BitmapList *bm_list) +{ + BDRVQcow2State *s =3D bs->opaque; + int ret; + + if (!(s->autoclear_features & QCOW2_AUTOCLEAR_BITMAPS) || + bm_list =3D=3D NULL || QSIMPLEQ_EMPTY(bm_list) || + bitmap_list_count(bm_list) !=3D s->nb_bitmaps) + { + return -EINVAL; + } + + s->autoclear_features &=3D ~(uint64_t)QCOW2_AUTOCLEAR_BITMAPS; + ret =3D update_header_sync(bs); + if (ret < 0) { + /* Two variants are possible here: + * 1. Autoclear flag is dropped, all bitmaps will be lost. + * 2. Autoclear flag is not dropped, old state is left. + */ + return ret; + } + + /* autoclear bit is not set, so we can safely update bitmap directory = */ + + ret =3D bitmap_list_store(bs, bm_list, &s->bitmap_directory_offset, + &s->bitmap_directory_size, true); + if (ret < 0) { + /* autoclear bit is cleared, so all leaked clusters would be remov= ed on + * qemu-img check */ + return ret; + } + + ret =3D update_header_sync(bs); + if (ret < 0) { + /* autoclear bit is cleared, so all leaked clusters would be remov= ed on + * qemu-img check */ + return ret; + } + + s->autoclear_features |=3D QCOW2_AUTOCLEAR_BITMAPS; + return update_header_sync(bs); + /* If final update_header_sync() fails, two variants are possible: + * 1. Autoclear flag is not set, all bitmaps will be lost. + * 2. Autoclear flag is set, header and directory are successfully upd= ated. + */ +} + +/* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */ +static void release_dirty_bitmap_helper(gpointer bitmap, + gpointer bs) +{ + bdrv_release_dirty_bitmap(bs, bitmap); +} + +/* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */ +static void set_readonly_helper(gpointer bitmap, gpointer value) +{ + bdrv_dirty_bitmap_set_readonly(bitmap, (bool)value); +} + +/* qcow2_load_autoloading_dirty_bitmaps() + * Return value is a hint for caller: true means that the Qcow2 header was + * updated. (false doesn't mean that the header should be updated by the + * caller, it just means that updating was not needed or the image cannot = be + * written to). + * On failure the function returns false. + */ +bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) +{ + BDRVQcow2State *s =3D bs->opaque; + Qcow2BitmapList *bm_list; + Qcow2Bitmap *bm; + GSList *created_dirty_bitmaps =3D NULL; + bool header_updated =3D false; + + if (s->nb_bitmaps =3D=3D 0) { + /* No bitmaps - nothing to do */ + return false; + } + + bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, + s->bitmap_directory_size, errp); + if (bm_list =3D=3D NULL) { + return false; + } + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if ((bm->flags & BME_FLAG_AUTO) && !(bm->flags & BME_FLAG_IN_USE))= { + BdrvDirtyBitmap *bitmap =3D load_bitmap(bs, bm, errp); + if (bitmap =3D=3D NULL) { + goto fail; + } + bm->flags |=3D BME_FLAG_IN_USE; + created_dirty_bitmaps =3D + g_slist_append(created_dirty_bitmaps, bitmap); + } + } + + if (created_dirty_bitmaps !=3D NULL) { + if (can_write(bs)) { + /* in_use flags must be updated */ + int ret =3D update_ext_header_and_dir_in_place(bs, bm_list); + if (ret < 0) { + error_setg_errno(errp, -ret, "Can't update bitmap director= y"); + goto fail; + } + header_updated =3D true; + } else { + g_slist_foreach(created_dirty_bitmaps, set_readonly_helper, + (gpointer)true); + } + } + + g_slist_free(created_dirty_bitmaps); + bitmap_list_free(bm_list); + + return header_updated; + +fail: + g_slist_foreach(created_dirty_bitmaps, release_dirty_bitmap_helper, bs= ); + g_slist_free(created_dirty_bitmaps); + bitmap_list_free(bm_list); + + return false; +} diff --git a/block/qcow2.c b/block/qcow2.c index 8688fdd..8645b08 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1445,9 +1445,22 @@ static int qcow2_do_open(BlockDriverState *bs, QDict= *options, int flags, =20 /* Clear unknown autoclear feature bits */ update_header |=3D s->autoclear_features & ~QCOW2_AUTOCLEAR_MASK; - - if (update_header && !bs->read_only && !(flags & BDRV_O_INACTIVE)) { + update_header =3D + update_header && !bs->read_only && !(flags & BDRV_O_INACTIVE); + if (update_header) { s->autoclear_features &=3D QCOW2_AUTOCLEAR_MASK; + } + + if (qcow2_load_autoloading_dirty_bitmaps(bs, &local_err)) { + update_header =3D false; + } + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + ret =3D -EINVAL; + goto fail; + } + + if (update_header) { ret =3D qcow2_update_header(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Could not update qcow2 header"); diff --git a/block/qcow2.h b/block/qcow2.h index 3488648..886480b 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -645,4 +645,6 @@ void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *= c, void **table); int qcow2_check_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *r= es, void **refcount_table, int64_t *refcount_table_size); +bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); + #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450059881508.0168488832576; Fri, 7 Jul 2017 10:54:19 -0700 (PDT) Received: from localhost ([::1]:57955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXSK-0002kt-IO for importer@patchew.org; Fri, 07 Jul 2017 13:54:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43214) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmL-0006Pn-J4 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmK-0000ig-Du for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57696) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmE-0000ZO-DW; Fri, 07 Jul 2017 13:10:46 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 635CB7C847; Fri, 7 Jul 2017 17:10:45 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D1AC627DB; Fri, 7 Jul 2017 17:10:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 635CB7C847 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 635CB7C847 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:29 +0200 Message-Id: <1499447335-6125-75-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:10:45 +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] [PULL 074/100] block: refactor bdrv_reopen_commit 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Add bs local variable to simplify code. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Message-id: 20170628120530.31251-13-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index b9e5114..15a4e75 100644 --- a/block.c +++ b/block.c @@ -2982,9 +2982,11 @@ error: void bdrv_reopen_commit(BDRVReopenState *reopen_state) { BlockDriver *drv; + BlockDriverState *bs; =20 assert(reopen_state !=3D NULL); - drv =3D reopen_state->bs->drv; + bs =3D reopen_state->bs; + drv =3D bs->drv; assert(drv !=3D NULL); =20 /* If there are any driver level actions to take */ @@ -2993,13 +2995,13 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_sta= te) } =20 /* set BDS specific flags now */ - QDECREF(reopen_state->bs->explicit_options); + QDECREF(bs->explicit_options); =20 - reopen_state->bs->explicit_options =3D reopen_state->explicit_option= s; - reopen_state->bs->open_flags =3D reopen_state->flags; - reopen_state->bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); + bs->explicit_options =3D reopen_state->explicit_options; + bs->open_flags =3D reopen_state->flags; + bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); =20 - bdrv_refresh_limits(reopen_state->bs, NULL); + bdrv_refresh_limits(bs, NULL); } =20 /* --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451205753150.24944126929336; Fri, 7 Jul 2017 11:13:25 -0700 (PDT) Received: from localhost ([::1]:58064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXkp-0003Oi-Te for importer@patchew.org; Fri, 07 Jul 2017 14:13:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43256) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmM-0006RR-Sw for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmL-0000lP-OZ for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58844) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmF-0000bU-Hz; Fri, 07 Jul 2017 13:10:47 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 977AEC003580; Fri, 7 Jul 2017 17:10:46 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF73C61F23; Fri, 7 Jul 2017 17:10:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 977AEC003580 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 977AEC003580 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:30 +0200 Message-Id: <1499447335-6125-76-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:10:46 +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] [PULL 075/100] block: new bdrv_reopen_bitmaps_rw interface 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Add format driver handler, which should mark loaded read-only bitmaps as 'IN_USE' in the image and unset read_only field in corresponding BdrvDirtyBitmap's. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Reviewed-by: Max Reitz Message-id: 20170628120530.31251-14-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block.c | 19 +++++++++++++++++++ include/block/block_int.h | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/block.c b/block.c index 15a4e75..3ec6624 100644 --- a/block.c +++ b/block.c @@ -2983,12 +2983,16 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_sta= te) { BlockDriver *drv; BlockDriverState *bs; + bool old_can_write, new_can_write; =20 assert(reopen_state !=3D NULL); bs =3D reopen_state->bs; drv =3D bs->drv; assert(drv !=3D NULL); =20 + old_can_write =3D + !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE); + /* If there are any driver level actions to take */ if (drv->bdrv_reopen_commit) { drv->bdrv_reopen_commit(reopen_state); @@ -3002,6 +3006,21 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_stat= e) bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); =20 bdrv_refresh_limits(bs, NULL); + + new_can_write =3D + !bdrv_is_read_only(bs) && !(bdrv_get_flags(bs) & BDRV_O_INACTIVE); + if (!old_can_write && new_can_write && drv->bdrv_reopen_bitmaps_rw) { + Error *local_err =3D NULL; + if (drv->bdrv_reopen_bitmaps_rw(bs, &local_err) < 0) { + /* This is not fatal, bitmaps just left read-only, so all foll= owing + * writes will fail. User can remove read-only bitmaps to unbl= ock + * writes. + */ + error_reportf_err(local_err, + "%s: Failed to make dirty bitmaps writable: = ", + bdrv_get_node_name(bs)); + } + } } =20 /* diff --git a/include/block/block_int.h b/include/block/block_int.h index b9069c5..254f860 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -381,6 +381,13 @@ struct BlockDriver { uint64_t parent_perm, uint64_t parent_shared, uint64_t *nperm, uint64_t *nshared); =20 + /** + * Bitmaps should be marked as 'IN_USE' in the image on reopening image + * as rw. This handler should realize it. It also should unset readonly + * field of BlockDirtyBitmap's in case of success. + */ + int (*bdrv_reopen_bitmaps_rw)(BlockDriverState *bs, Error **errp); + QLIST_ENTRY(BlockDriver) list; }; =20 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 149945025146988.93306115825669; Fri, 7 Jul 2017 10:57:31 -0700 (PDT) Received: from localhost ([::1]:57973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXVR-0005p7-4g for importer@patchew.org; Fri, 07 Jul 2017 13:57:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmN-0006Rh-61 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmM-0000ly-10 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33256) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmG-0000dS-St; Fri, 07 Jul 2017 13:10:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E31EA80C07; Fri, 7 Jul 2017 17:10:47 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E300D61F23; Fri, 7 Jul 2017 17:10:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E31EA80C07 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E31EA80C07 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:31 +0200 Message-Id: <1499447335-6125-77-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:48 +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] [PULL 076/100] qcow2: support .bdrv_reopen_bitmaps_rw 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Realize bdrv_reopen_bitmaps_rw interface. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Reviewed-by: Max Reitz Message-id: 20170628120530.31251-15-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ block/qcow2.c | 2 ++ block/qcow2.h | 1 + 3 files changed, 64 insertions(+) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 2c7b057..a21fab8 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -826,3 +826,64 @@ fail: =20 return false; } + +int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp) +{ + BDRVQcow2State *s =3D bs->opaque; + Qcow2BitmapList *bm_list; + Qcow2Bitmap *bm; + GSList *ro_dirty_bitmaps =3D NULL; + int ret =3D 0; + + if (s->nb_bitmaps =3D=3D 0) { + /* No bitmaps - nothing to do */ + return 0; + } + + if (!can_write(bs)) { + error_setg(errp, "Can't write to the image on reopening bitmaps rw= "); + return -EINVAL; + } + + bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, + s->bitmap_directory_size, errp); + if (bm_list =3D=3D NULL) { + return -EINVAL; + } + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if (!(bm->flags & BME_FLAG_IN_USE)) { + BdrvDirtyBitmap *bitmap =3D bdrv_find_dirty_bitmap(bs, bm->nam= e); + if (bitmap =3D=3D NULL) { + continue; + } + + if (!bdrv_dirty_bitmap_readonly(bitmap)) { + error_setg(errp, "Bitmap %s is not readonly but not marked" + "'IN_USE' in the image. Something went wr= ong," + "all the bitmaps may be corrupted", bm->n= ame); + ret =3D -EINVAL; + goto out; + } + + bm->flags |=3D BME_FLAG_IN_USE; + ro_dirty_bitmaps =3D g_slist_append(ro_dirty_bitmaps, bitmap); + } + } + + if (ro_dirty_bitmaps !=3D NULL) { + /* in_use flags must be updated */ + ret =3D update_ext_header_and_dir_in_place(bs, bm_list); + if (ret < 0) { + error_setg_errno(errp, -ret, "Can't update bitmap directory"); + goto out; + } + g_slist_foreach(ro_dirty_bitmaps, set_readonly_helper, false); + } + +out: + g_slist_free(ro_dirty_bitmaps); + bitmap_list_free(bm_list); + + return ret; +} diff --git a/block/qcow2.c b/block/qcow2.c index 8645b08..19cc49a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3973,6 +3973,8 @@ BlockDriver bdrv_qcow2 =3D { =20 .bdrv_detach_aio_context =3D qcow2_detach_aio_context, .bdrv_attach_aio_context =3D qcow2_attach_aio_context, + + .bdrv_reopen_bitmaps_rw =3D qcow2_reopen_bitmaps_rw, }; =20 static void bdrv_qcow2_init(void) diff --git a/block/qcow2.h b/block/qcow2.h index 886480b..633bd43 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -646,5 +646,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, void **refcount_table, int64_t *refcount_table_size); bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); +int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 149945151284956.10586445526587; Fri, 7 Jul 2017 11:18:32 -0700 (PDT) Received: from localhost ([::1]:58104 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXpm-0007xA-3r for importer@patchew.org; Fri, 07 Jul 2017 14:18:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmN-0006Re-4U for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmL-0000lZ-QQ for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39134) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmI-0000fN-4Y; Fri, 07 Jul 2017 13:10:50 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2372A18DF47; Fri, 7 Jul 2017 17:10:49 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A1EF61F23; Fri, 7 Jul 2017 17:10:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2372A18DF47 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2372A18DF47 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:32 +0200 Message-Id: <1499447335-6125-78-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:10:49 +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] [PULL 077/100] block/dirty-bitmap: add autoload field to BdrvDirtyBitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Mirror AUTO flag from Qcow2 bitmap in BdrvDirtyBitmap. This will be needed in future, to save this flag back to Qcow2 for persistent bitmaps. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20170628120530.31251-16-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 18 ++++++++++++++++++ block/qcow2-bitmap.c | 2 ++ include/block/dirty-bitmap.h | 2 ++ 3 files changed, 22 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 17d3068..06dc7a3 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -52,6 +52,8 @@ struct BdrvDirtyBitmap { Such operations must fail and both the = image and this bitmap must remain unchanged w= hile this flag is set. */ + bool autoload; /* For persistent bitmaps: bitmap must be + autoloaded on image opening */ QLIST_ENTRY(BdrvDirtyBitmap) list; }; =20 @@ -100,6 +102,7 @@ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitma= p) assert(!bdrv_dirty_bitmap_frozen(bitmap)); g_free(bitmap->name); bitmap->name =3D NULL; + bitmap->autoload =3D false; } =20 /* Called with BQL taken. */ @@ -296,6 +299,8 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriver= State *bs, bitmap->name =3D NULL; successor->name =3D name; bitmap->successor =3D NULL; + successor->autoload =3D bitmap->autoload; + bitmap->autoload =3D false; bdrv_release_dirty_bitmap(bs, bitmap); =20 return successor; @@ -671,3 +676,16 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs) =20 return false; } + +/* Called with BQL taken. */ +void bdrv_dirty_bitmap_set_autoload(BdrvDirtyBitmap *bitmap, bool autoload) +{ + qemu_mutex_lock(bitmap->mutex); + bitmap->autoload =3D autoload; + qemu_mutex_unlock(bitmap->mutex); +} + +bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap) +{ + return bitmap->autoload; +} diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index a21fab8..ee6d8f7 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -793,6 +793,8 @@ bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverSt= ate *bs, Error **errp) if (bitmap =3D=3D NULL) { goto fail; } + + bdrv_dirty_bitmap_set_autoload(bitmap, true); bm->flags |=3D BME_FLAG_IN_USE; created_dirty_bitmaps =3D g_slist_append(created_dirty_bitmaps, bitmap); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index cb43fa3..e2fea12 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -72,6 +72,7 @@ void bdrv_dirty_bitmap_deserialize_ones(BdrvDirtyBitmap *= bitmap, void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap *bitmap); =20 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); +void bdrv_dirty_bitmap_set_autoload(BdrvDirtyBitmap *bitmap, bool autoload= ); =20 /* Functions that require manual locking. */ void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); @@ -89,5 +90,6 @@ int64_t bdrv_get_meta_dirty_count(BdrvDirtyBitmap *bitmap= ); void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); +bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450203037769.1827835151006; Fri, 7 Jul 2017 10:56:43 -0700 (PDT) Received: from localhost ([::1]:57972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXUf-0005Dg-P4 for importer@patchew.org; Fri, 07 Jul 2017 13:56:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmM-0006Qy-Dv for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmL-0000kw-HL for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58998) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmJ-0000gM-8l; Fri, 07 Jul 2017 13:10:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5606EC0587C4; Fri, 7 Jul 2017 17:10:50 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D5FC61F23; Fri, 7 Jul 2017 17:10:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5606EC0587C4 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5606EC0587C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:33 +0200 Message-Id: <1499447335-6125-79-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:10:50 +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] [PULL 078/100] block: bdrv_close: release bitmaps after drv->bdrv_close 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Release bitmaps after 'if (bs->drv) { ... }' block. This will allow format driver to save persistent bitmaps, which will appear in following commits. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-id: 20170628120530.31251-17-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 3ec6624..700431d 100644 --- a/block.c +++ b/block.c @@ -3054,9 +3054,6 @@ static void bdrv_close(BlockDriverState *bs) bdrv_flush(bs); bdrv_drain(bs); /* in case flush left pending I/O */ =20 - bdrv_release_named_dirty_bitmaps(bs); - assert(QLIST_EMPTY(&bs->dirty_bitmaps)); - if (bs->drv) { BdrvChild *child, *next; =20 @@ -3094,6 +3091,9 @@ static void bdrv_close(BlockDriverState *bs) bs->full_open_options =3D NULL; } =20 + bdrv_release_named_dirty_bitmaps(bs); + assert(QLIST_EMPTY(&bs->dirty_bitmaps)); + QLIST_FOREACH_SAFE(ban, &bs->aio_notifiers, list, ban_next) { g_free(ban); } --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450720529668.6412438517985; Fri, 7 Jul 2017 11:05:20 -0700 (PDT) Received: from localhost ([::1]:58018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXcy-0004d3-W8 for importer@patchew.org; Fri, 07 Jul 2017 14:05:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43311) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmO-0006Tv-QO for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmN-0000oj-Iy for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48158) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmK-0000hl-Gb; Fri, 07 Jul 2017 13:10:52 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8A9235BECD; Fri, 7 Jul 2017 17:10:51 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id A119162925; Fri, 7 Jul 2017 17:10:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8A9235BECD Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8A9235BECD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:34 +0200 Message-Id: <1499447335-6125-80-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 07 Jul 2017 17:10:51 +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] [PULL 079/100] block: introduce persistent dirty bitmaps 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy New field BdrvDirtyBitmap.persistent means, that bitmap should be saved by format driver in .bdrv_close and .bdrv_inactivate. No format driver supports it for now. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20170628120530.31251-18-vsementsov@virtuozzo.com [mreitz: Fixed indentation] Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 29 +++++++++++++++++++++++++++++ block/qcow2-bitmap.c | 1 + include/block/dirty-bitmap.h | 4 ++++ 3 files changed, 34 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 06dc7a3..3c17c45 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -54,6 +54,7 @@ struct BdrvDirtyBitmap { this flag is set. */ bool autoload; /* For persistent bitmaps: bitmap must be autoloaded on image opening */ + bool persistent; /* bitmap must be saved to owner disk imag= e */ QLIST_ENTRY(BdrvDirtyBitmap) list; }; =20 @@ -102,6 +103,7 @@ void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitma= p) assert(!bdrv_dirty_bitmap_frozen(bitmap)); g_free(bitmap->name); bitmap->name =3D NULL; + bitmap->persistent =3D false; bitmap->autoload =3D false; } =20 @@ -299,6 +301,8 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriver= State *bs, bitmap->name =3D NULL; successor->name =3D name; bitmap->successor =3D NULL; + successor->persistent =3D bitmap->persistent; + bitmap->persistent =3D false; successor->autoload =3D bitmap->autoload; bitmap->autoload =3D false; bdrv_release_dirty_bitmap(bs, bitmap); @@ -689,3 +693,28 @@ bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBit= map *bitmap) { return bitmap->autoload; } + +/* Called with BQL taken. */ +void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, bool persi= stent) +{ + qemu_mutex_lock(bitmap->mutex); + bitmap->persistent =3D persistent; + qemu_mutex_unlock(bitmap->mutex); +} + +bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap) +{ + return bitmap->persistent; +} + +bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs) +{ + BdrvDirtyBitmap *bm; + QLIST_FOREACH(bm, &bs->dirty_bitmaps, list) { + if (bm->persistent && !bm->readonly) { + return true; + } + } + + return false; +} diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index ee6d8f7..52e4616 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -794,6 +794,7 @@ bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverSt= ate *bs, Error **errp) goto fail; } =20 + bdrv_dirty_bitmap_set_persistance(bitmap, true); bdrv_dirty_bitmap_set_autoload(bitmap, true); bm->flags |=3D BME_FLAG_IN_USE; created_dirty_bitmaps =3D diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index e2fea12..bdf43df 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -73,6 +73,8 @@ void bdrv_dirty_bitmap_deserialize_finish(BdrvDirtyBitmap= *bitmap); =20 void bdrv_dirty_bitmap_set_readonly(BdrvDirtyBitmap *bitmap, bool value); void bdrv_dirty_bitmap_set_autoload(BdrvDirtyBitmap *bitmap, bool autoload= ); +void bdrv_dirty_bitmap_set_persistance(BdrvDirtyBitmap *bitmap, + bool persistent); =20 /* Functions that require manual locking. */ void bdrv_dirty_bitmap_lock(BdrvDirtyBitmap *bitmap); @@ -91,5 +93,7 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs); bool bdrv_dirty_bitmap_readonly(const BdrvDirtyBitmap *bitmap); bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); +bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap); +bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450348538557.9306941623386; Fri, 7 Jul 2017 10:59:08 -0700 (PDT) Received: from localhost ([::1]:57983 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXX1-0007FS-Au for importer@patchew.org; Fri, 07 Jul 2017 13:59:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmP-0006Uu-HV for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmO-0000qk-J2 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:10:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39254) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmL-0000kW-W4; Fri, 07 Jul 2017 13:10:54 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DB7F34DB15; Fri, 7 Jul 2017 17:10:52 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3F8B61F23; Fri, 7 Jul 2017 17:10:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com DB7F34DB15 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com DB7F34DB15 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:35 +0200 Message-Id: <1499447335-6125-81-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:10:53 +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] [PULL 080/100] block/dirty-bitmap: add bdrv_dirty_bitmap_next() 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-19-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 7 +++++++ include/block/dirty-bitmap.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 3c17c45..d146941 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -718,3 +718,10 @@ bool bdrv_has_changed_persistent_bitmaps(BlockDriverSt= ate *bs) =20 return false; } + +BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap) +{ + return bitmap =3D=3D NULL ? QLIST_FIRST(&bs->dirty_bitmaps) : + QLIST_NEXT(bitmap, list); +} diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index bdf43df..c8b3110 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -95,5 +95,7 @@ bool bdrv_has_readonly_bitmaps(BlockDriverState *bs); bool bdrv_dirty_bitmap_get_autoload(const BdrvDirtyBitmap *bitmap); bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *bitmap); bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); +BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450398476494.6880088347692; Fri, 7 Jul 2017 10:59:58 -0700 (PDT) Received: from localhost ([::1]:57985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXXp-0008IG-1R for importer@patchew.org; Fri, 07 Jul 2017 13:59:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43480) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmX-0006dq-5a for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmV-00010f-1V for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59118) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmN-0000me-1M; Fri, 07 Jul 2017 13:10:55 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 13F89C0587CD; Fri, 7 Jul 2017 17:10:54 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27A8361F52; Fri, 7 Jul 2017 17:10:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 13F89C0587CD 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 13F89C0587CD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:36 +0200 Message-Id: <1499447335-6125-82-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:10:54 +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] [PULL 081/100] qcow2: add persistent dirty bitmaps support 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Store persistent dirty bitmaps in qcow2 image. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-id: 20170628120530.31251-20-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 475 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ block/qcow2.c | 9 + block/qcow2.h | 1 + 3 files changed, 485 insertions(+) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 52e4616..5f53486 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -27,6 +27,7 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" +#include "qemu/cutils.h" =20 #include "block/block_int.h" #include "block/qcow2.h" @@ -42,6 +43,10 @@ #define BME_MIN_GRANULARITY_BITS 9 #define BME_MAX_NAME_SIZE 1023 =20 +#if BME_MAX_TABLE_SIZE * 8ULL > INT_MAX +#error In the code bitmap table physical size assumed to fit into int +#endif + /* Bitmap directory entry flags */ #define BME_RESERVED_FLAGS 0xfffffffcU #define BME_FLAG_IN_USE (1U << 0) @@ -72,6 +77,8 @@ typedef struct Qcow2BitmapTable { uint32_t size; /* number of 64bit entries */ QSIMPLEQ_ENTRY(Qcow2BitmapTable) entry; } Qcow2BitmapTable; +typedef QSIMPLEQ_HEAD(Qcow2BitmapTableList, Qcow2BitmapTable) + Qcow2BitmapTableList; =20 typedef struct Qcow2Bitmap { Qcow2BitmapTable table; @@ -79,6 +86,8 @@ typedef struct Qcow2Bitmap { uint8_t granularity_bits; char *name; =20 + BdrvDirtyBitmap *dirty_bitmap; + QSIMPLEQ_ENTRY(Qcow2Bitmap) entry; } Qcow2Bitmap; typedef QSIMPLEQ_HEAD(Qcow2BitmapList, Qcow2Bitmap) Qcow2BitmapList; @@ -104,6 +113,15 @@ static int update_header_sync(BlockDriverState *bs) return bdrv_flush(bs); } =20 +static inline void bitmap_table_to_be(uint64_t *bitmap_table, size_t size) +{ + size_t i; + + for (i =3D 0; i < size; ++i) { + cpu_to_be64s(&bitmap_table[i]); + } +} + static int check_table_entry(uint64_t entry, int cluster_size) { uint64_t offset; @@ -127,6 +145,70 @@ static int check_table_entry(uint64_t entry, int clust= er_size) return 0; } =20 +static int check_constraints_on_bitmap(BlockDriverState *bs, + const char *name, + uint32_t granularity, + Error **errp) +{ + BDRVQcow2State *s =3D bs->opaque; + int granularity_bits =3D ctz32(granularity); + int64_t len =3D bdrv_getlength(bs); + + assert(granularity > 0); + assert((granularity & (granularity - 1)) =3D=3D 0); + + if (len < 0) { + error_setg_errno(errp, -len, "Failed to get size of '%s'", + bdrv_get_device_or_node_name(bs)); + return len; + } + + if (granularity_bits > BME_MAX_GRANULARITY_BITS) { + error_setg(errp, "Granularity exceeds maximum (%llu bytes)", + 1ULL << BME_MAX_GRANULARITY_BITS); + return -EINVAL; + } + if (granularity_bits < BME_MIN_GRANULARITY_BITS) { + error_setg(errp, "Granularity is under minimum (%llu bytes)", + 1ULL << BME_MIN_GRANULARITY_BITS); + return -EINVAL; + } + + if ((len > (uint64_t)BME_MAX_PHYS_SIZE << granularity_bits) || + (len > (uint64_t)BME_MAX_TABLE_SIZE * s->cluster_size << + granularity_bits)) + { + error_setg(errp, "Too much space will be occupied by the bitmap. " + "Use larger granularity"); + return -EINVAL; + } + + if (strlen(name) > BME_MAX_NAME_SIZE) { + error_setg(errp, "Name length exceeds maximum (%u characters)", + BME_MAX_NAME_SIZE); + return -EINVAL; + } + + return 0; +} + +static void clear_bitmap_table(BlockDriverState *bs, uint64_t *bitmap_tabl= e, + uint32_t bitmap_table_size) +{ + BDRVQcow2State *s =3D bs->opaque; + int i; + + for (i =3D 0; i < bitmap_table_size; ++i) { + uint64_t addr =3D bitmap_table[i] & BME_TABLE_ENTRY_OFFSET_MASK; + if (!addr) { + continue; + } + + qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_OTHER= ); + bitmap_table[i] =3D 0; + } +} + static int bitmap_table_load(BlockDriverState *bs, Qcow2BitmapTable *tb, uint64_t **bitmap_table) { @@ -165,6 +247,28 @@ fail: return ret; } =20 +static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb) +{ + int ret; + uint64_t *bitmap_table; + + ret =3D bitmap_table_load(bs, tb, &bitmap_table); + if (ret < 0) { + assert(bitmap_table =3D=3D NULL); + return ret; + } + + clear_bitmap_table(bs, bitmap_table, tb->size); + qcow2_free_clusters(bs, tb->offset, tb->size * sizeof(uint64_t), + QCOW2_DISCARD_OTHER); + g_free(bitmap_table); + + tb->offset =3D 0; + tb->size =3D 0; + + return 0; +} + /* This function returns the number of disk sectors covered by a single qc= ow2 * cluster of bitmap data. */ static uint64_t sectors_covered_by_bitmap_cluster(const BDRVQcow2State *s, @@ -748,6 +852,69 @@ static int update_ext_header_and_dir_in_place(BlockDri= verState *bs, */ } =20 +static int update_ext_header_and_dir(BlockDriverState *bs, + Qcow2BitmapList *bm_list) +{ + BDRVQcow2State *s =3D bs->opaque; + int ret; + uint64_t new_offset =3D 0; + uint64_t new_size =3D 0; + uint32_t new_nb_bitmaps =3D 0; + uint64_t old_offset =3D s->bitmap_directory_offset; + uint64_t old_size =3D s->bitmap_directory_size; + uint32_t old_nb_bitmaps =3D s->nb_bitmaps; + uint64_t old_autocl =3D s->autoclear_features; + + if (bm_list !=3D NULL && !QSIMPLEQ_EMPTY(bm_list)) { + new_nb_bitmaps =3D bitmap_list_count(bm_list); + + if (new_nb_bitmaps > QCOW2_MAX_BITMAPS) { + return -EINVAL; + } + + ret =3D bitmap_list_store(bs, bm_list, &new_offset, &new_size, fal= se); + if (ret < 0) { + return ret; + } + + ret =3D bdrv_flush(bs->file->bs); + if (ret < 0) { + goto fail; + } + + s->autoclear_features |=3D QCOW2_AUTOCLEAR_BITMAPS; + } else { + s->autoclear_features &=3D ~(uint64_t)QCOW2_AUTOCLEAR_BITMAPS; + } + + s->bitmap_directory_offset =3D new_offset; + s->bitmap_directory_size =3D new_size; + s->nb_bitmaps =3D new_nb_bitmaps; + + ret =3D update_header_sync(bs); + if (ret < 0) { + goto fail; + } + + if (old_size > 0) { + qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_OTHER); + } + + return 0; + +fail: + if (new_offset > 0) { + qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_OTHER); + } + + s->bitmap_directory_offset =3D old_offset; + s->bitmap_directory_size =3D old_size; + s->nb_bitmaps =3D old_nb_bitmaps; + s->autoclear_features =3D old_autocl; + + return ret; +} + /* for g_slist_foreach for GSList of BdrvDirtyBitmap* elements */ static void release_dirty_bitmap_helper(gpointer bitmap, gpointer bs) @@ -890,3 +1057,311 @@ out: =20 return ret; } + +/* store_bitmap_data() + * Store bitmap to image, filling bitmap table accordingly. + */ +static uint64_t *store_bitmap_data(BlockDriverState *bs, + BdrvDirtyBitmap *bitmap, + uint32_t *bitmap_table_size, Error **er= rp) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + int64_t sector; + uint64_t sbc; + uint64_t bm_size =3D bdrv_dirty_bitmap_size(bitmap); + const char *bm_name =3D bdrv_dirty_bitmap_name(bitmap); + uint8_t *buf =3D NULL; + BdrvDirtyBitmapIter *dbi; + uint64_t *tb; + uint64_t tb_size =3D + size_to_clusters(s, + bdrv_dirty_bitmap_serialization_size(bitmap, 0, bm_size)); + + if (tb_size > BME_MAX_TABLE_SIZE || + tb_size * s->cluster_size > BME_MAX_PHYS_SIZE) + { + error_setg(errp, "Bitmap '%s' is too big", bm_name); + return NULL; + } + + tb =3D g_try_new0(uint64_t, tb_size); + if (tb =3D=3D NULL) { + error_setg(errp, "No memory"); + return NULL; + } + + dbi =3D bdrv_dirty_iter_new(bitmap, 0); + buf =3D g_malloc(s->cluster_size); + sbc =3D sectors_covered_by_bitmap_cluster(s, bitmap); + assert(DIV_ROUND_UP(bm_size, sbc) =3D=3D tb_size); + + while ((sector =3D bdrv_dirty_iter_next(dbi)) !=3D -1) { + uint64_t cluster =3D sector / sbc; + uint64_t end, write_size; + int64_t off; + + sector =3D cluster * sbc; + end =3D MIN(bm_size, sector + sbc); + write_size =3D + bdrv_dirty_bitmap_serialization_size(bitmap, sector, end - sec= tor); + assert(write_size <=3D s->cluster_size); + + off =3D qcow2_alloc_clusters(bs, s->cluster_size); + if (off < 0) { + error_setg_errno(errp, -off, + "Failed to allocate clusters for bitmap '%s'", + bm_name); + goto fail; + } + tb[cluster] =3D off; + + bdrv_dirty_bitmap_serialize_part(bitmap, buf, sector, end - sector= ); + if (write_size < s->cluster_size) { + memset(buf + write_size, 0, s->cluster_size - write_size); + } + + ret =3D qcow2_pre_write_overlap_check(bs, 0, off, s->cluster_size); + if (ret < 0) { + error_setg_errno(errp, -ret, "Qcow2 overlap check failed"); + goto fail; + } + + ret =3D bdrv_pwrite(bs->file, off, buf, s->cluster_size); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to f= ile", + bm_name); + goto fail; + } + + if (end >=3D bm_size) { + break; + } + + bdrv_set_dirty_iter(dbi, end); + } + + *bitmap_table_size =3D tb_size; + g_free(buf); + bdrv_dirty_iter_free(dbi); + + return tb; + +fail: + clear_bitmap_table(bs, tb, tb_size); + g_free(buf); + bdrv_dirty_iter_free(dbi); + g_free(tb); + + return NULL; +} + +/* store_bitmap() + * Store bm->dirty_bitmap to qcow2. + * Set bm->table_offset and bm->table_size accordingly. + */ +static int store_bitmap(BlockDriverState *bs, Qcow2Bitmap *bm, Error **err= p) +{ + int ret; + uint64_t *tb; + int64_t tb_offset; + uint32_t tb_size; + BdrvDirtyBitmap *bitmap =3D bm->dirty_bitmap; + const char *bm_name; + + assert(bitmap !=3D NULL); + + bm_name =3D bdrv_dirty_bitmap_name(bitmap); + + tb =3D store_bitmap_data(bs, bitmap, &tb_size, errp); + if (tb =3D=3D NULL) { + return -EINVAL; + } + + assert(tb_size <=3D BME_MAX_TABLE_SIZE); + tb_offset =3D qcow2_alloc_clusters(bs, tb_size * sizeof(tb[0])); + if (tb_offset < 0) { + error_setg_errno(errp, -tb_offset, + "Failed to allocate clusters for bitmap '%s'", + bm_name); + goto fail; + } + + ret =3D qcow2_pre_write_overlap_check(bs, 0, tb_offset, + tb_size * sizeof(tb[0])); + if (ret < 0) { + error_setg_errno(errp, -ret, "Qcow2 overlap check failed"); + goto fail; + } + + bitmap_table_to_be(tb, tb_size); + ret =3D bdrv_pwrite(bs->file, tb_offset, tb, tb_size * sizeof(tb[0])); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file", + bm_name); + goto fail; + } + + g_free(tb); + + bm->table.offset =3D tb_offset; + bm->table.size =3D tb_size; + + return 0; + +fail: + clear_bitmap_table(bs, tb, tb_size); + + if (tb_offset > 0) { + qcow2_free_clusters(bs, tb_offset, tb_size * sizeof(tb[0]), + QCOW2_DISCARD_OTHER); + } + + g_free(tb); + + return ret; +} + +static Qcow2Bitmap *find_bitmap_by_name(Qcow2BitmapList *bm_list, + const char *name) +{ + Qcow2Bitmap *bm; + + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if (strcmp(name, bm->name) =3D=3D 0) { + return bm; + } + } + + return NULL; +} + +void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) +{ + BdrvDirtyBitmap *bitmap; + BDRVQcow2State *s =3D bs->opaque; + uint32_t new_nb_bitmaps =3D s->nb_bitmaps; + uint64_t new_dir_size =3D s->bitmap_directory_size; + int ret; + Qcow2BitmapList *bm_list; + Qcow2Bitmap *bm; + Qcow2BitmapTableList drop_tables; + Qcow2BitmapTable *tb, *tb_next; + + if (!bdrv_has_changed_persistent_bitmaps(bs)) { + /* nothing to do */ + return; + } + + if (!can_write(bs)) { + error_setg(errp, "No write access"); + return; + } + + QSIMPLEQ_INIT(&drop_tables); + + if (s->nb_bitmaps =3D=3D 0) { + bm_list =3D bitmap_list_new(); + } else { + bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, + s->bitmap_directory_size, errp); + if (bm_list =3D=3D NULL) { + return; + } + } + + /* check constraints and names */ + for (bitmap =3D bdrv_dirty_bitmap_next(bs, NULL); bitmap !=3D NULL; + bitmap =3D bdrv_dirty_bitmap_next(bs, bitmap)) + { + const char *name =3D bdrv_dirty_bitmap_name(bitmap); + uint32_t granularity =3D bdrv_dirty_bitmap_granularity(bitmap); + Qcow2Bitmap *bm; + + if (!bdrv_dirty_bitmap_get_persistance(bitmap) || + bdrv_dirty_bitmap_readonly(bitmap)) + { + continue; + } + + if (check_constraints_on_bitmap(bs, name, granularity, errp) < 0) { + error_prepend(errp, "Bitmap '%s' doesn't satisfy the constrain= ts: ", + name); + goto fail; + } + + bm =3D find_bitmap_by_name(bm_list, name); + if (bm =3D=3D NULL) { + if (++new_nb_bitmaps > QCOW2_MAX_BITMAPS) { + error_setg(errp, "Too many persistent bitmaps"); + goto fail; + } + + new_dir_size +=3D calc_dir_entry_size(strlen(name), 0); + if (new_dir_size > QCOW2_MAX_BITMAP_DIRECTORY_SIZE) { + error_setg(errp, "Bitmap directory is too large"); + goto fail; + } + + bm =3D g_new0(Qcow2Bitmap, 1); + bm->name =3D g_strdup(name); + QSIMPLEQ_INSERT_TAIL(bm_list, bm, entry); + } else { + if (!(bm->flags & BME_FLAG_IN_USE)) { + error_setg(errp, "Bitmap '%s' already exists in the image", + name); + goto fail; + } + tb =3D g_memdup(&bm->table, sizeof(bm->table)); + bm->table.offset =3D 0; + bm->table.size =3D 0; + QSIMPLEQ_INSERT_TAIL(&drop_tables, tb, entry); + } + bm->flags =3D bdrv_dirty_bitmap_get_autoload(bitmap) ? BME_FLAG_AU= TO : 0; + bm->granularity_bits =3D ctz32(bdrv_dirty_bitmap_granularity(bitma= p)); + bm->dirty_bitmap =3D bitmap; + } + + /* allocate clusters and store bitmaps */ + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if (bm->dirty_bitmap =3D=3D NULL) { + continue; + } + + ret =3D store_bitmap(bs, bm, errp); + if (ret < 0) { + goto fail; + } + } + + ret =3D update_ext_header_and_dir(bs, bm_list); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to update bitmap extension"); + goto fail; + } + + /* Bitmap directory was successfully updated, so, old data can be drop= ped. + * TODO it is better to reuse these clusters */ + QSIMPLEQ_FOREACH_SAFE(tb, &drop_tables, entry, tb_next) { + free_bitmap_clusters(bs, tb); + g_free(tb); + } + + bitmap_list_free(bm_list); + return; + +fail: + QSIMPLEQ_FOREACH(bm, bm_list, entry) { + if (bm->dirty_bitmap =3D=3D NULL || bm->table.offset =3D=3D 0) { + continue; + } + + free_bitmap_clusters(bs, &bm->table); + } + + QSIMPLEQ_FOREACH_SAFE(tb, &drop_tables, entry, tb_next) { + g_free(tb); + } + + bitmap_list_free(bm_list); +} diff --git a/block/qcow2.c b/block/qcow2.c index 19cc49a..790b5b1 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2046,6 +2046,7 @@ static int qcow2_inactivate(BlockDriverState *bs) { BDRVQcow2State *s =3D bs->opaque; int ret, result =3D 0; + Error *local_err =3D NULL; =20 ret =3D qcow2_cache_flush(bs, s->l2_table_cache); if (ret) { @@ -2061,6 +2062,14 @@ static int qcow2_inactivate(BlockDriverState *bs) strerror(-ret)); } =20 + qcow2_store_persistent_dirty_bitmaps(bs, &local_err); + if (local_err !=3D NULL) { + result =3D -EINVAL; + error_report_err(local_err); + error_report("Persistent bitmaps are lost for node '%s'", + bdrv_get_device_or_node_name(bs)); + } + if (result =3D=3D 0) { qcow2_mark_clean(bs); } diff --git a/block/qcow2.h b/block/qcow2.h index 633bd43..308cefd 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -647,5 +647,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, int64_t *refcount_table_size); bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); +void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451857056483.72865236269683; Fri, 7 Jul 2017 11:24:17 -0700 (PDT) Received: from localhost ([::1]:58153 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXvJ-0004pT-IN for importer@patchew.org; Fri, 07 Jul 2017 14:24:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmU-0006bm-VS for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmQ-0000v1-CP for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmO-0000on-6g; Fri, 07 Jul 2017 13:10:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 469E24A544; Fri, 7 Jul 2017 17:10:55 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5F3F561F23; Fri, 7 Jul 2017 17:10:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 469E24A544 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 469E24A544 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:37 +0200 Message-Id: <1499447335-6125-83-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 07 Jul 2017 17:10:55 +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] [PULL 082/100] qcow2: store bitmaps on reopening image as read-only 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Store bitmaps and mark them read-only on reopening image as read-only. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-id: 20170628120530.31251-21-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 22 ++++++++++++++++++++++ block/qcow2.c | 5 +++++ block/qcow2.h | 1 + 3 files changed, 28 insertions(+) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 5f53486..7912a82 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1365,3 +1365,25 @@ fail: =20 bitmap_list_free(bm_list); } + +int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp) +{ + BdrvDirtyBitmap *bitmap; + Error *local_err =3D NULL; + + qcow2_store_persistent_dirty_bitmaps(bs, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return -EINVAL; + } + + for (bitmap =3D bdrv_dirty_bitmap_next(bs, NULL); bitmap !=3D NULL; + bitmap =3D bdrv_dirty_bitmap_next(bs, bitmap)) + { + if (bdrv_dirty_bitmap_get_persistance(bitmap)) { + bdrv_dirty_bitmap_set_readonly(bitmap, true); + } + } + + return 0; +} diff --git a/block/qcow2.c b/block/qcow2.c index 790b5b1..1a31f1d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1555,6 +1555,11 @@ static int qcow2_reopen_prepare(BDRVReopenState *sta= te, =20 /* We need to write out any unwritten data if we reopen read-only. */ if ((state->flags & BDRV_O_RDWR) =3D=3D 0) { + ret =3D qcow2_reopen_bitmaps_ro(state->bs, errp); + if (ret < 0) { + goto fail; + } + ret =3D bdrv_flush(state->bs); if (ret < 0) { goto fail; diff --git a/block/qcow2.h b/block/qcow2.h index 308cefd..1f80b5d 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -648,5 +648,6 @@ int qcow2_check_bitmaps_refcounts(BlockDriverState *bs,= BdrvCheckResult *res, bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); +int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450553353538.0382246300368; Fri, 7 Jul 2017 11:02:33 -0700 (PDT) Received: from localhost ([::1]:58003 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXaI-000245-Vc for importer@patchew.org; Fri, 07 Jul 2017 14:02:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmW-0006d5-5s for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmV-000110-2u for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59188) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmP-0000rT-Eq; Fri, 07 Jul 2017 13:10:57 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7EC23C0587C4; Fri, 7 Jul 2017 17:10:56 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 941AE61F23; Fri, 7 Jul 2017 17:10:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7EC23C0587C4 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 7EC23C0587C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:38 +0200 Message-Id: <1499447335-6125-84-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:10:56 +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] [PULL 083/100] block: add bdrv_can_store_new_dirty_bitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy This will be needed to check some restrictions before making bitmap persistent in qmp-block-dirty-bitmap-add (this functionality will be added by future patch) Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-22-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block.c | 22 ++++++++++++++++++++++ include/block/block.h | 3 +++ include/block/block_int.h | 4 ++++ 3 files changed, 29 insertions(+) diff --git a/block.c b/block.c index 700431d..1d44165 100644 --- a/block.c +++ b/block.c @@ -4880,3 +4880,25 @@ void bdrv_del_child(BlockDriverState *parent_bs, Bdr= vChild *child, Error **errp) =20 parent_bs->drv->bdrv_del_child(parent_bs, child, errp); } + +bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, + uint32_t granularity, Error **errp) +{ + BlockDriver *drv =3D bs->drv; + + if (!drv) { + error_setg_errno(errp, ENOMEDIUM, + "Can't store persistent bitmaps to %s", + bdrv_get_device_or_node_name(bs)); + return false; + } + + if (!drv->bdrv_can_store_new_dirty_bitmap) { + error_setg_errno(errp, ENOTSUP, + "Can't store persistent bitmaps to %s", + bdrv_get_device_or_node_name(bs)); + return false; + } + + return drv->bdrv_can_store_new_dirty_bitmap(bs, name, granularity, err= p); +} diff --git a/include/block/block.h b/include/block/block.h index 2d637d1..f0fdbe8 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -617,4 +617,7 @@ void bdrv_add_child(BlockDriverState *parent, BlockDriv= erState *child, Error **errp); void bdrv_del_child(BlockDriverState *parent, BdrvChild *child, Error **er= rp); =20 +bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, + uint32_t granularity, Error **errp); + #endif diff --git a/include/block/block_int.h b/include/block/block_int.h index 254f860..c9e29bf 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -387,6 +387,10 @@ struct BlockDriver { * field of BlockDirtyBitmap's in case of success. */ int (*bdrv_reopen_bitmaps_rw)(BlockDriverState *bs, Error **errp); + bool (*bdrv_can_store_new_dirty_bitmap)(BlockDriverState *bs, + const char *name, + uint32_t granularity, + Error **errp); =20 QLIST_ENTRY(BlockDriver) list; }; --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450725898743.5754849218001; Fri, 7 Jul 2017 11:05:25 -0700 (PDT) Received: from localhost ([::1]:58019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXd5-0004ja-Hk for importer@patchew.org; Fri, 07 Jul 2017 14:05:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmX-0006eE-Ix for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmW-00013R-Cq for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmQ-0000uX-Lx; Fri, 07 Jul 2017 13:10:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADD7EC058ED5; Fri, 7 Jul 2017 17:10:57 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6FBA61F23; Fri, 7 Jul 2017 17:10:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com ADD7EC058ED5 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com ADD7EC058ED5 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:39 +0200 Message-Id: <1499447335-6125-85-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:10:57 +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] [PULL 084/100] qcow2: add .bdrv_can_store_new_dirty_bitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Realize .bdrv_can_store_new_dirty_bitmap interface. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: John Snow Reviewed-by: Max Reitz Message-id: 20170628120530.31251-23-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++= +++ block/qcow2.c | 1 + block/qcow2.h | 4 ++++ 3 files changed, 56 insertions(+) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 7912a82..f45324e 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1387,3 +1387,54 @@ int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Er= ror **errp) =20 return 0; } + +bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs, + const char *name, + uint32_t granularity, + Error **errp) +{ + BDRVQcow2State *s =3D bs->opaque; + bool found; + Qcow2BitmapList *bm_list; + + if (check_constraints_on_bitmap(bs, name, granularity, errp) !=3D 0) { + goto fail; + } + + if (s->nb_bitmaps =3D=3D 0) { + return true; + } + + if (s->nb_bitmaps >=3D QCOW2_MAX_BITMAPS) { + error_setg(errp, + "Maximum number of persistent bitmaps is already reache= d"); + goto fail; + } + + if (s->bitmap_directory_size + calc_dir_entry_size(strlen(name), 0) > + QCOW2_MAX_BITMAP_DIRECTORY_SIZE) + { + error_setg(errp, "Not enough space in the bitmap directory"); + goto fail; + } + + bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, + s->bitmap_directory_size, errp); + if (bm_list =3D=3D NULL) { + goto fail; + } + + found =3D find_bitmap_by_name(bm_list, name); + bitmap_list_free(bm_list); + if (found) { + error_setg(errp, "Bitmap with the same name is already stored"); + goto fail; + } + + return true; + +fail: + error_prepend(errp, "Can't make bitmap '%s' persistent in '%s': ", + name, bdrv_get_device_or_node_name(bs)); + return false; +} diff --git a/block/qcow2.c b/block/qcow2.c index 1a31f1d..d7046a3 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3989,6 +3989,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_attach_aio_context =3D qcow2_attach_aio_context, =20 .bdrv_reopen_bitmaps_rw =3D qcow2_reopen_bitmaps_rw, + .bdrv_can_store_new_dirty_bitmap =3D qcow2_can_store_new_dirty_bitmap, }; =20 static void bdrv_qcow2_init(void) diff --git a/block/qcow2.h b/block/qcow2.h index 1f80b5d..084a298 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -649,5 +649,9 @@ bool qcow2_load_autoloading_dirty_bitmaps(BlockDriverSt= ate *bs, Error **errp); int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp); int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); +bool qcow2_can_store_new_dirty_bitmap(BlockDriverState *bs, + const char *name, + uint32_t granularity, + Error **errp); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450569139887.4349131022068; Fri, 7 Jul 2017 11:02:49 -0700 (PDT) Received: from localhost ([::1]:58004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXaY-0002IX-QF for importer@patchew.org; Fri, 07 Jul 2017 14:02:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43485) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmX-0006dv-8o for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmW-00013G-BT for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39422) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmR-0000wP-US; Fri, 07 Jul 2017 13:11:00 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F113D15561; Fri, 7 Jul 2017 17:10:58 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06146627DB; Fri, 7 Jul 2017 17:10:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F113D15561 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com F113D15561 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:40 +0200 Message-Id: <1499447335-6125-86-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:10:59 +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] [PULL 085/100] qmp: add persistent flag to block-dirty-bitmap-add 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Add optional 'persistent' flag to qmp command block-dirty-bitmap-add. Default is false. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-24-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- blockdev.c | 18 +++++++++++++++++- qapi/block-core.json | 8 +++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index edeb36b..2ef731b 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1983,6 +1983,7 @@ static void block_dirty_bitmap_add_prepare(BlkActionS= tate *common, /* AIO context taken and released within qmp_block_dirty_bitmap_add */ qmp_block_dirty_bitmap_add(action->node, action->name, action->has_granularity, action->granularit= y, + action->has_persistent, action->persistent, &local_err); =20 if (!local_err) { @@ -2708,9 +2709,11 @@ out: =20 void qmp_block_dirty_bitmap_add(const char *node, const char *name, bool has_granularity, uint32_t granularity, + bool has_persistent, bool persistent, Error **errp) { BlockDriverState *bs; + BdrvDirtyBitmap *bitmap; =20 if (!name || name[0] =3D=3D '\0') { error_setg(errp, "Bitmap name cannot be empty"); @@ -2733,7 +2736,20 @@ void qmp_block_dirty_bitmap_add(const char *node, co= nst char *name, granularity =3D bdrv_get_default_bitmap_granularity(bs); } =20 - bdrv_create_dirty_bitmap(bs, granularity, name, errp); + if (!has_persistent) { + persistent =3D false; + } + + if (persistent && + !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) + { + return; + } + + bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); + if (bitmap !=3D NULL) { + bdrv_dirty_bitmap_set_persistance(bitmap, persistent); + } } =20 void qmp_block_dirty_bitmap_remove(const char *node, const char *name, diff --git a/qapi/block-core.json b/qapi/block-core.json index 9570963..907ac9d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1553,10 +1553,16 @@ # @granularity: the bitmap granularity, default is 64k for # block-dirty-bitmap-add # +# @persistent: the bitmap is persistent, i.e. it will be saved to the +# corresponding block device image file on its close. For now= only +# Qcow2 disks support persistent bitmaps. Default is false for +# block-dirty-bitmap-add. (Since: 2.10) +# # Since: 2.4 ## { 'struct': 'BlockDirtyBitmapAdd', - 'data': { 'node': 'str', 'name': 'str', '*granularity': 'uint32' } } + 'data': { 'node': 'str', 'name': 'str', '*granularity': 'uint32', + '*persistent': 'bool' } } =20 ## # @block-dirty-bitmap-add: --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450884151665.6181214614342; Fri, 7 Jul 2017 11:08:04 -0700 (PDT) Received: from localhost ([::1]:58039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXfd-0006tX-62 for importer@patchew.org; Fri, 07 Jul 2017 14:08:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43495) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmX-0006eF-JN for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmW-00013W-E9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39442) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmT-0000x7-7S; Fri, 07 Jul 2017 13:11:01 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33BCD91FCC; Fri, 7 Jul 2017 17:11:00 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 422E261F23; Fri, 7 Jul 2017 17:10:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 33BCD91FCC Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 33BCD91FCC From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:41 +0200 Message-Id: <1499447335-6125-87-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 07 Jul 2017 17:11:00 +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] [PULL 086/100] qmp: add autoload parameter to block-dirty-bitmap-add 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Optional. Default is false. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-25-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- blockdev.c | 18 ++++++++++++++++-- qapi/block-core.json | 6 +++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/blockdev.c b/blockdev.c index 2ef731b..b7c1449 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1984,6 +1984,7 @@ static void block_dirty_bitmap_add_prepare(BlkActionS= tate *common, qmp_block_dirty_bitmap_add(action->node, action->name, action->has_granularity, action->granularit= y, action->has_persistent, action->persistent, + action->has_autoload, action->autoload, &local_err); =20 if (!local_err) { @@ -2710,6 +2711,7 @@ out: void qmp_block_dirty_bitmap_add(const char *node, const char *name, bool has_granularity, uint32_t granularity, bool has_persistent, bool persistent, + bool has_autoload, bool autoload, Error **errp) { BlockDriverState *bs; @@ -2739,6 +2741,15 @@ void qmp_block_dirty_bitmap_add(const char *node, co= nst char *name, if (!has_persistent) { persistent =3D false; } + if (!has_autoload) { + autoload =3D false; + } + + if (has_autoload && !persistent) { + error_setg(errp, "Autoload flag must be used only for persistent " + "bitmaps"); + return; + } =20 if (persistent && !bdrv_can_store_new_dirty_bitmap(bs, name, granularity, errp)) @@ -2747,9 +2758,12 @@ void qmp_block_dirty_bitmap_add(const char *node, co= nst char *name, } =20 bitmap =3D bdrv_create_dirty_bitmap(bs, granularity, name, errp); - if (bitmap !=3D NULL) { - bdrv_dirty_bitmap_set_persistance(bitmap, persistent); + if (bitmap =3D=3D NULL) { + return; } + + bdrv_dirty_bitmap_set_persistance(bitmap, persistent); + bdrv_dirty_bitmap_set_autoload(bitmap, autoload); } =20 void qmp_block_dirty_bitmap_remove(const char *node, const char *name, diff --git a/qapi/block-core.json b/qapi/block-core.json index 907ac9d..fb69efe 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1558,11 +1558,15 @@ # Qcow2 disks support persistent bitmaps. Default is false for # block-dirty-bitmap-add. (Since: 2.10) # +# @autoload: the bitmap will be automatically loaded when the image it is = stored +# in is opened. This flag may only be specified for persistent +# bitmaps. Default is false for block-dirty-bitmap-add. (Since:= 2.10) +# # Since: 2.4 ## { 'struct': 'BlockDirtyBitmapAdd', 'data': { 'node': 'str', 'name': 'str', '*granularity': 'uint32', - '*persistent': 'bool' } } + '*persistent': 'bool', '*autoload': 'bool' } } =20 ## # @block-dirty-bitmap-add: --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451032613887.391502235566; Fri, 7 Jul 2017 11:10:32 -0700 (PDT) Received: from localhost ([::1]:58054 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXi3-0000kB-6W for importer@patchew.org; Fri, 07 Jul 2017 14:10:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43536) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmZ-0006g0-AD for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmY-000164-2W for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48344) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmU-0000yr-Mi; Fri, 07 Jul 2017 13:11:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3C56C04B326; Fri, 7 Jul 2017 17:11:01 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB35D173D2; Fri, 7 Jul 2017 17:11:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B3C56C04B326 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B3C56C04B326 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:42 +0200 Message-Id: <1499447335-6125-88-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:11:01 +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] [PULL 087/100] qmp: add x-debug-block-dirty-bitmap-sha256 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20170628120530.31251-26-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 5 +++++ blockdev.c | 25 +++++++++++++++++++++++++ include/block/dirty-bitmap.h | 1 + include/qemu/hbitmap.h | 8 ++++++++ qapi/block-core.json | 27 +++++++++++++++++++++++++++ tests/Makefile.include | 2 +- util/hbitmap.c | 11 +++++++++++ 7 files changed, 78 insertions(+), 1 deletion(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index d146941..5fcf917 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -725,3 +725,8 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverStat= e *bs, return bitmap =3D=3D NULL ? QLIST_FIRST(&bs->dirty_bitmaps) : QLIST_NEXT(bitmap, list); } + +char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp) +{ + return hbitmap_sha256(bitmap->bitmap, errp); +} diff --git a/blockdev.c b/blockdev.c index b7c1449..988a60d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2820,6 +2820,31 @@ void qmp_block_dirty_bitmap_clear(const char *node, = const char *name, bdrv_clear_dirty_bitmap(bitmap, NULL); } =20 +BlockDirtyBitmapSha256 *qmp_x_debug_block_dirty_bitmap_sha256(const char *= node, + const char *= name, + Error **errp) +{ + BdrvDirtyBitmap *bitmap; + BlockDriverState *bs; + BlockDirtyBitmapSha256 *ret =3D NULL; + char *sha256; + + bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); + if (!bitmap || !bs) { + return NULL; + } + + sha256 =3D bdrv_dirty_bitmap_sha256(bitmap, errp); + if (sha256 =3D=3D NULL) { + return NULL; + } + + ret =3D g_new(BlockDirtyBitmapSha256, 1); + ret->sha256 =3D sha256; + + return ret; +} + void hmp_drive_del(Monitor *mon, const QDict *qdict) { const char *id =3D qdict_get_str(qdict, "id"); diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index c8b3110..8e98aef 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -97,5 +97,6 @@ bool bdrv_dirty_bitmap_get_persistance(BdrvDirtyBitmap *b= itmap); bool bdrv_has_changed_persistent_bitmaps(BlockDriverState *bs); BdrvDirtyBitmap *bdrv_dirty_bitmap_next(BlockDriverState *bs, BdrvDirtyBitmap *bitmap); +char *bdrv_dirty_bitmap_sha256(const BdrvDirtyBitmap *bitmap, Error **errp= ); =20 #endif diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index b52304a..d3a74a2 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -253,6 +253,14 @@ void hbitmap_deserialize_ones(HBitmap *hb, uint64_t st= art, uint64_t count, void hbitmap_deserialize_finish(HBitmap *hb); =20 /** + * hbitmap_sha256: + * @bitmap: HBitmap to operate on. + * + * Returns SHA256 hash of the last level. + */ +char *hbitmap_sha256(const HBitmap *bitmap, Error **errp); + +/** * hbitmap_free: * @hb: HBitmap to operate on. * diff --git a/qapi/block-core.json b/qapi/block-core.json index fb69efe..9b5047d 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1636,6 +1636,33 @@ 'data': 'BlockDirtyBitmap' } =20 ## +# @BlockDirtyBitmapSha256: +# +# SHA256 hash of dirty bitmap data +# +# @sha256: ASCII representation of SHA256 bitmap hash +# +# Since: 2.10 +## + { 'struct': 'BlockDirtyBitmapSha256', + 'data': {'sha256': 'str'} } + +## +# @x-debug-block-dirty-bitmap-sha256: +# +# Get bitmap SHA256 +# +# Returns: BlockDirtyBitmapSha256 on success +# If @node is not a valid block device, DeviceNotFound +# If @name is not found or if hashing has failed, GenericError wi= th an +# explanation +# +# Since: 2.10 +## + { 'command': 'x-debug-block-dirty-bitmap-sha256', + 'data': 'BlockDirtyBitmap', 'returns': 'BlockDirtyBitmapSha256' } + +## # @blockdev-mirror: # # Start mirroring a block device's writes to a new destination. diff --git a/tests/Makefile.include b/tests/Makefile.include index 18cd06a..42e17e2 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -554,7 +554,7 @@ tests/test-blockjob$(EXESUF): tests/test-blockjob.o $(t= est-block-obj-y) $(test-u tests/test-blockjob-txn$(EXESUF): tests/test-blockjob-txn.o $(test-block-o= bj-y) $(test-util-obj-y) tests/test-thread-pool$(EXESUF): tests/test-thread-pool.o $(test-block-obj= -y) tests/test-iov$(EXESUF): tests/test-iov.o $(test-util-obj-y) -tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) +tests/test-hbitmap$(EXESUF): tests/test-hbitmap.o $(test-util-obj-y) $(tes= t-crypto-obj-y) tests/test-x86-cpuid$(EXESUF): tests/test-x86-cpuid.o tests/test-xbzrle$(EXESUF): tests/test-xbzrle.o migration/xbzrle.o migrati= on/page_cache.o $(test-util-obj-y) tests/test-cutils$(EXESUF): tests/test-cutils.o util/cutils.o diff --git a/util/hbitmap.c b/util/hbitmap.c index 0c1591a..21535cc 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -13,6 +13,7 @@ #include "qemu/hbitmap.h" #include "qemu/host-utils.h" #include "trace.h" +#include "crypto/hash.h" =20 /* HBitmaps provides an array of bits. The bits are stored as usual in an * array of unsigned longs, but HBitmap is also optimized to provide fast @@ -727,3 +728,13 @@ void hbitmap_free_meta(HBitmap *hb) hbitmap_free(hb->meta); hb->meta =3D NULL; } + +char *hbitmap_sha256(const HBitmap *bitmap, Error **errp) +{ + size_t size =3D bitmap->sizes[HBITMAP_LEVELS - 1] * sizeof(unsigned lo= ng); + char *data =3D (char *)bitmap->levels[HBITMAP_LEVELS - 1]; + char *hash =3D NULL; + qcrypto_hash_digest(QCRYPTO_HASH_ALG_SHA256, data, size, &hash, errp); + + return hash; +} --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451177150436.3063098232591; Fri, 7 Jul 2017 11:12:57 -0700 (PDT) Received: from localhost ([::1]:58063 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXkN-00032N-UD for importer@patchew.org; Fri, 07 Jul 2017 14:12:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43561) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWma-0006iM-Q9 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmZ-00017e-ED for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55982) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmW-00011b-3t; Fri, 07 Jul 2017 13:11:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 081A5267CE; Fri, 7 Jul 2017 17:11:03 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BC3E61F23; Fri, 7 Jul 2017 17:11:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 081A5267CE Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 081A5267CE From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:43 +0200 Message-Id: <1499447335-6125-89-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 07 Jul 2017 17:11:03 +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] [PULL 088/100] iotests: test qcow2 persistent dirty bitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-id: 20170628120530.31251-27-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- tests/qemu-iotests/165 | 105 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/165.out | 5 +++ tests/qemu-iotests/group | 1 + 3 files changed, 111 insertions(+) create mode 100755 tests/qemu-iotests/165 create mode 100644 tests/qemu-iotests/165.out diff --git a/tests/qemu-iotests/165 b/tests/qemu-iotests/165 new file mode 100755 index 0000000..74d7b79 --- /dev/null +++ b/tests/qemu-iotests/165 @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# +# Tests for persistent dirty bitmaps. +# +# Copyright: Vladimir Sementsov-Ogievskiy 2015-2017 +# +# 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 . +# + +import os +import re +import iotests +from iotests import qemu_img + +disk =3D os.path.join(iotests.test_dir, 'disk') +disk_size =3D 0x40000000 # 1G + +# regions for qemu_io: (start, count) in bytes +regions1 =3D ((0, 0x100000), + (0x200000, 0x100000)) + +regions2 =3D ((0x10000000, 0x20000), + (0x3fff0000, 0x10000)) + +class TestPersistentDirtyBitmap(iotests.QMPTestCase): + + def setUp(self): + qemu_img('create', '-f', iotests.imgfmt, disk, str(disk_size)) + + def tearDown(self): + os.remove(disk) + + def mkVm(self): + return iotests.VM().add_drive(disk) + + def mkVmRo(self): + return iotests.VM().add_drive(disk, opts=3D'readonly=3Don') + + def getSha256(self): + result =3D self.vm.qmp('x-debug-block-dirty-bitmap-sha256', + node=3D'drive0', name=3D'bitmap0') + return result['return']['sha256'] + + def checkBitmap(self, sha256): + result =3D self.vm.qmp('x-debug-block-dirty-bitmap-sha256', + node=3D'drive0', name=3D'bitmap0') + self.assert_qmp(result, 'return/sha256', sha256); + + def writeRegions(self, regions): + for r in regions: + self.vm.hmp_qemu_io('drive0', + 'write %d %d' % r) + + def qmpAddBitmap(self): + self.vm.qmp('block-dirty-bitmap-add', node=3D'drive0', + name=3D'bitmap0', persistent=3DTrue, autoload=3DTrue) + + def test_persistent(self): + self.vm =3D self.mkVm() + self.vm.launch() + self.qmpAddBitmap() + + self.writeRegions(regions1) + sha256 =3D self.getSha256() + + self.vm.shutdown() + + self.vm =3D self.mkVmRo() + self.vm.launch() + self.vm.shutdown() + + #catch 'Persistent bitmaps are lost' possible error + log =3D self.vm.get_log() + log =3D re.sub(r'^\[I \d+\.\d+\] OPENED\n', '', log) + log =3D re.sub(r'\[I \+\d+\.\d+\] CLOSED\n?$', '', log) + if log: + print log + + self.vm =3D self.mkVm() + self.vm.launch() + + self.checkBitmap(sha256) + self.writeRegions(regions2) + sha256 =3D self.getSha256() + + self.vm.shutdown() + self.vm.launch() + + self.checkBitmap(sha256) + + self.vm.shutdown() + +if __name__ =3D=3D '__main__': + iotests.main(supported_fmts=3D['qcow2']) diff --git a/tests/qemu-iotests/165.out b/tests/qemu-iotests/165.out new file mode 100644 index 0000000..ae1213e --- /dev/null +++ b/tests/qemu-iotests/165.out @@ -0,0 +1,5 @@ +. +---------------------------------------------------------------------- +Ran 1 tests + +OK diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 613d596..7d86715 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -163,6 +163,7 @@ 159 rw auto quick 160 rw auto quick 162 auto quick +165 rw auto quick 170 rw auto quick 171 rw auto quick 172 auto --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 14994520118117.62679356182241; Fri, 7 Jul 2017 11:26:51 -0700 (PDT) Received: from localhost ([::1]:58173 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXxq-0007AQ-7v for importer@patchew.org; Fri, 07 Jul 2017 14:26:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43645) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmg-0006oz-Rg for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmf-0001FG-On for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59478) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmZ-00017K-9S; Fri, 07 Jul 2017 13:11:07 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 56D5BC0587CD; Fri, 7 Jul 2017 17:11:06 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F3EF61F52; Fri, 7 Jul 2017 17:11:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 56D5BC0587CD 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 56D5BC0587CD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:44 +0200 Message-Id: <1499447335-6125-90-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:11:06 +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] [PULL 089/100] block/dirty-bitmap: add bdrv_remove_persistent_dirty_bitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Interface for removing persistent bitmap from its storage. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-28-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/dirty-bitmap.c | 18 ++++++++++++++++++ include/block/block_int.h | 3 +++ include/block/dirty-bitmap.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 5fcf917..b2ca78b 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -395,6 +395,7 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, Bd= rvDirtyBitmap *bitmap) /** * Release all named dirty bitmaps attached to a BDS (for use in bdrv_clos= e()). * There must not be any frozen bitmaps attached. + * This function does not remove persistent bitmaps from the storage. * Called with BQL taken. */ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs) @@ -402,6 +403,23 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState= *bs) bdrv_do_release_matching_dirty_bitmap(bs, NULL, true); } =20 +/** + * Remove persistent dirty bitmap from the storage if it exists. + * Absence of bitmap is not an error, because we have the following scenar= io: + * BdrvDirtyBitmap can have .persistent =3D true but not yet saved and hav= e no + * stored version. For such bitmap bdrv_remove_persistent_dirty_bitmap() s= hould + * not fail. + * This function doesn't release corresponding BdrvDirtyBitmap. + */ +void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, + const char *name, + Error **errp) +{ + if (bs->drv && bs->drv->bdrv_remove_persistent_dirty_bitmap) { + bs->drv->bdrv_remove_persistent_dirty_bitmap(bs, name, errp); + } +} + /* Called with BQL taken. */ void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap) { diff --git a/include/block/block_int.h b/include/block/block_int.h index c9e29bf..58d4ffd 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -391,6 +391,9 @@ struct BlockDriver { const char *name, uint32_t granularity, Error **errp); + void (*bdrv_remove_persistent_dirty_bitmap)(BlockDriverState *bs, + const char *name, + Error **errp); =20 QLIST_ENTRY(BlockDriver) list; }; diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 8e98aef..93d97f0 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -25,6 +25,9 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState = *bs, void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap); void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); +void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, + const char *name, + Error **errp); void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); BlockDirtyInfoList *bdrv_query_dirty_bitmaps(BlockDriverState *bs); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451342139796.7084475231572; Fri, 7 Jul 2017 11:15:42 -0700 (PDT) Received: from localhost ([::1]:58082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXn2-0005kO-O7 for importer@patchew.org; Fri, 07 Jul 2017 14:15:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43680) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmi-0006qB-1Z for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmh-0001GL-2M for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59510) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWma-00017u-He; Fri, 07 Jul 2017 13:11:08 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 954DCC0587CD; Fri, 7 Jul 2017 17:11:07 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id A248A61F23; Fri, 7 Jul 2017 17:11:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 954DCC0587CD 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 954DCC0587CD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:45 +0200 Message-Id: <1499447335-6125-91-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:11:07 +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] [PULL 090/100] qcow2: add .bdrv_remove_persistent_dirty_bitmap 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Realize .bdrv_remove_persistent_dirty_bitmap interface. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-29-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 41 +++++++++++++++++++++++++++++++++++++++++ block/qcow2.c | 1 + block/qcow2.h | 3 +++ 3 files changed, 45 insertions(+) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index f45324e..8448bec 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1236,6 +1236,47 @@ static Qcow2Bitmap *find_bitmap_by_name(Qcow2BitmapL= ist *bm_list, return NULL; } =20 +void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, + const char *name, + Error **errp) +{ + int ret; + BDRVQcow2State *s =3D bs->opaque; + Qcow2Bitmap *bm; + Qcow2BitmapList *bm_list; + + if (s->nb_bitmaps =3D=3D 0) { + /* Absence of the bitmap is not an error: see explanation above + * bdrv_remove_persistent_dirty_bitmap() definition. */ + return; + } + + bm_list =3D bitmap_list_load(bs, s->bitmap_directory_offset, + s->bitmap_directory_size, errp); + if (bm_list =3D=3D NULL) { + return; + } + + bm =3D find_bitmap_by_name(bm_list, name); + if (bm =3D=3D NULL) { + goto fail; + } + + QSIMPLEQ_REMOVE(bm_list, bm, Qcow2Bitmap, entry); + + ret =3D update_ext_header_and_dir(bs, bm_list); + if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to update bitmap extension"); + goto fail; + } + + free_bitmap_clusters(bs, &bm->table); + +fail: + bitmap_free(bm); + bitmap_list_free(bm_list); +} + void qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, Error **er= rp) { BdrvDirtyBitmap *bitmap; diff --git a/block/qcow2.c b/block/qcow2.c index d7046a3..9d3c70e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3990,6 +3990,7 @@ BlockDriver bdrv_qcow2 =3D { =20 .bdrv_reopen_bitmaps_rw =3D qcow2_reopen_bitmaps_rw, .bdrv_can_store_new_dirty_bitmap =3D qcow2_can_store_new_dirty_bitmap, + .bdrv_remove_persistent_dirty_bitmap =3D qcow2_remove_persistent_dirty= _bitmap, }; =20 static void bdrv_qcow2_init(void) diff --git a/block/qcow2.h b/block/qcow2.h index 084a298..2df05ac 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -653,5 +653,8 @@ bool qcow2_can_store_new_dirty_bitmap(BlockDriverState = *bs, const char *name, uint32_t granularity, Error **errp); +void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, + const char *name, + Error **errp); =20 #endif --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499450727462442.9007110984818; Fri, 7 Jul 2017 11:05:27 -0700 (PDT) Received: from localhost ([::1]:58020 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXd8-0004lP-5N for importer@patchew.org; Fri, 07 Jul 2017 14:05:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmh-0006px-M4 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmg-0001Fx-QQ for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmb-00019f-QD; Fri, 07 Jul 2017 13:11:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB0BE7F7A9; Fri, 7 Jul 2017 17:11:08 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id E131061F23; Fri, 7 Jul 2017 17:11:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CB0BE7F7A9 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CB0BE7F7A9 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:46 +0200 Message-Id: <1499447335-6125-92-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:11:08 +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] [PULL 091/100] qmp: block-dirty-bitmap-remove: remove persistent 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy Remove persistent bitmap from the storage on block-dirty-bitmap-remove. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Reviewed-by: John Snow Message-id: 20170628120530.31251-30-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- blockdev.c | 10 ++++++++++ qapi/block-core.json | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/blockdev.c b/blockdev.c index 988a60d..124c230 100644 --- a/blockdev.c +++ b/blockdev.c @@ -2771,6 +2771,7 @@ void qmp_block_dirty_bitmap_remove(const char *node, = const char *name, { BlockDriverState *bs; BdrvDirtyBitmap *bitmap; + Error *local_err =3D NULL; =20 bitmap =3D block_dirty_bitmap_lookup(node, name, &bs, errp); if (!bitmap || !bs) { @@ -2783,6 +2784,15 @@ void qmp_block_dirty_bitmap_remove(const char *node,= const char *name, name); return; } + + if (bdrv_dirty_bitmap_get_persistance(bitmap)) { + bdrv_remove_persistent_dirty_bitmap(bs, name, &local_err); + if (local_err !=3D NULL) { + error_propagate(errp, local_err); + return; + } + } + bdrv_dirty_bitmap_make_anon(bitmap); bdrv_release_dirty_bitmap(bs, bitmap); } diff --git a/qapi/block-core.json b/qapi/block-core.json index 9b5047d..4bf11e8 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -1593,7 +1593,8 @@ # @block-dirty-bitmap-remove: # # Stop write tracking and remove the dirty bitmap that was created -# with block-dirty-bitmap-add. +# with block-dirty-bitmap-add. If the bitmap is persistent, remove it from= its +# storage too. # # Returns: nothing on success # If @node is not a valid block device or node, DeviceNotFound --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499452310775181.3777477854212; Fri, 7 Jul 2017 11:31:50 -0700 (PDT) Received: from localhost ([::1]:58227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTY2f-00039q-Jr for importer@patchew.org; Fri, 07 Jul 2017 14:31:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmi-0006qM-46 for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmg-0001G9-SY for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59602) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmc-0001BX-V8; Fri, 07 Jul 2017 13:11:11 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 06553C056828; Fri, 7 Jul 2017 17:11:10 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F31361F23; Fri, 7 Jul 2017 17:11:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 06553C056828 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 06553C056828 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:47 +0200 Message-Id: <1499447335-6125-93-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:11:10 +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] [PULL 092/100] block: release persistent bitmaps on inactivate 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-devel@nongnu.org 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" From: Vladimir Sementsov-Ogievskiy We should release them here to reload on invalidate cache. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Max Reitz Message-id: 20170628120530.31251-31-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block.c | 4 ++++ block/dirty-bitmap.c | 29 +++++++++++++++++++++++------ include/block/dirty-bitmap.h | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 1d44165..913bb43 100644 --- a/block.c +++ b/block.c @@ -4082,6 +4082,10 @@ static int bdrv_inactivate_recurse(BlockDriverState = *bs, } } =20 + /* At this point persistent bitmaps should be already stored by the fo= rmat + * driver */ + bdrv_release_persistent_dirty_bitmaps(bs); + return 0; } =20 diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index b2ca78b..543bddb 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -356,15 +356,20 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs) bdrv_dirty_bitmaps_unlock(bs); } =20 +static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap *bitmap) +{ + return !!bdrv_dirty_bitmap_name(bitmap); +} + /* Called with BQL taken. */ -static void bdrv_do_release_matching_dirty_bitmap(BlockDriverState *bs, - BdrvDirtyBitmap *bitmap, - bool only_named) +static void bdrv_do_release_matching_dirty_bitmap( + BlockDriverState *bs, BdrvDirtyBitmap *bitmap, + bool (*cond)(BdrvDirtyBitmap *bitmap)) { BdrvDirtyBitmap *bm, *next; bdrv_dirty_bitmaps_lock(bs); QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) { - if ((!bitmap || bm =3D=3D bitmap) && (!only_named || bm->name)) { + if ((!bitmap || bm =3D=3D bitmap) && (!cond || cond(bm))) { assert(!bm->active_iterators); assert(!bdrv_dirty_bitmap_frozen(bm)); assert(!bm->meta); @@ -389,7 +394,7 @@ out: /* Called with BQL taken. */ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap) { - bdrv_do_release_matching_dirty_bitmap(bs, bitmap, false); + bdrv_do_release_matching_dirty_bitmap(bs, bitmap, NULL); } =20 /** @@ -400,7 +405,19 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, B= drvDirtyBitmap *bitmap) */ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs) { - bdrv_do_release_matching_dirty_bitmap(bs, NULL, true); + bdrv_do_release_matching_dirty_bitmap(bs, NULL, bdrv_dirty_bitmap_has_= name); +} + +/** + * Release all persistent dirty bitmaps attached to a BDS (for use in + * bdrv_inactivate_recurse()). + * There must not be any frozen bitmaps attached. + * This function does not remove persistent bitmaps from the storage. + */ +void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs) +{ + bdrv_do_release_matching_dirty_bitmap(bs, NULL, + bdrv_dirty_bitmap_get_persistanc= e); } =20 /** diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 93d97f0..a79a58d 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -25,6 +25,7 @@ BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState = *bs, void bdrv_dirty_bitmap_make_anon(BdrvDirtyBitmap *bitmap); void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); +void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs); void bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, Error **errp); --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499452161140237.10519161288585; Fri, 7 Jul 2017 11:29:21 -0700 (PDT) Received: from localhost ([::1]:58197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTY0E-0000op-SX for importer@patchew.org; Fri, 07 Jul 2017 14:29:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmh-0006py-MR for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmg-0001G2-Ra for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWme-0001Db-5P; Fri, 07 Jul 2017 13:11:12 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 39827C0467C4; Fri, 7 Jul 2017 17:11:11 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 51B9461F23; Fri, 7 Jul 2017 17:11:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 39827C0467C4 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 39827C0467C4 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:48 +0200 Message-Id: <1499447335-6125-94-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:11:11 +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] [PULL 093/100] iotests: skip 159 & 170 with luks format 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-devel@nongnu.org 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" From: "Daniel P. Berrange" While the qemu-img dd command does accept --image-opts this is not sufficient to make it work with the LUKS image yet. This is because bdrv_create() still always requires the non-image-opts syntax. Thus we must skip 159/170 with luks for now Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170626123510.20134-2-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/159 | 1 + tests/qemu-iotests/170 | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/qemu-iotests/159 b/tests/qemu-iotests/159 index 825f05f..9b0e1ec 100755 --- a/tests/qemu-iotests/159 +++ b/tests/qemu-iotests/159 @@ -40,6 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 _supported_fmt generic _supported_proto file _supported_os Linux +_unsupported_fmt luks =20 TEST_SIZES=3D"5 512 1024 1999 1K 64K 1M" =20 diff --git a/tests/qemu-iotests/170 b/tests/qemu-iotests/170 index 5b335db..b79359f 100755 --- a/tests/qemu-iotests/170 +++ b/tests/qemu-iotests/170 @@ -40,6 +40,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 _supported_fmt generic _supported_proto file _supported_os Linux +_unsupported_fmt luks =20 echo echo "=3D=3D Creating image =3D=3D" --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 149945088697395.58049140904177; Fri, 7 Jul 2017 11:08:06 -0700 (PDT) Received: from localhost ([::1]:58040 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXfe-0006uc-Co for importer@patchew.org; Fri, 07 Jul 2017 14:08:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43715) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmk-0006tZ-Lt for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmj-0001Hj-4C for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:18 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59672) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmf-0001En-DM; Fri, 07 Jul 2017 13:11:13 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75A06C056828; Fri, 7 Jul 2017 17:11:12 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8427F61F23; Fri, 7 Jul 2017 17:11:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 75A06C056828 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=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 75A06C056828 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:49 +0200 Message-Id: <1499447335-6125-95-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 07 Jul 2017 17:11:12 +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] [PULL 094/100] iotests: fix remainining tests to work with LUKS 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-devel@nongnu.org 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" From: "Daniel P. Berrange" The tests 033, 140, 145 and 157 were all broken when run with LUKS, since they did not correctly use the required image opts args syntax to specify the decryption secret. Further, the 120 test simply does not make sense to run with luks, as the scenario exercised is not relevant. The test 181 was broken when run with LUKS because it didn't take account of fact that $TEST_IMG was already in image opts syntax. The launch_qemu helper also didn't register the secret object providing the LUKS password. Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170626123510.20134-3-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/033 | 12 ++++++++++-- tests/qemu-iotests/120 | 1 + tests/qemu-iotests/140 | 9 ++++++++- tests/qemu-iotests/145 | 19 +++++++++++++++++-- tests/qemu-iotests/157 | 17 ++++++++++++++--- tests/qemu-iotests/157.out | 16 ++++++++-------- tests/qemu-iotests/174 | 2 +- tests/qemu-iotests/181 | 21 ++++++++++++++++----- tests/qemu-iotests/common.qemu | 9 +++++++-- 9 files changed, 82 insertions(+), 24 deletions(-) diff --git a/tests/qemu-iotests/033 b/tests/qemu-iotests/033 index 16edcf2..2cdfd13 100755 --- a/tests/qemu-iotests/033 +++ b/tests/qemu-iotests/033 @@ -50,10 +50,18 @@ do_test() local align=3D$1 local iocmd=3D$2 local img=3D$3 + if [ "$IMGOPTSSYNTAX" =3D "true" ] + then + IO_OPEN_ARG=3D"$img" + IO_EXTRA_ARGS=3D"--image-opts" + else + IO_OPEN_ARG=3D"-o driver=3D$IMGFMT,file.align=3D$align blkdebug::$img" + IO_EXTRA_ARGS=3D"" + fi { - echo "open -o driver=3D$IMGFMT,file.align=3D$align blkdebug::$img" + echo "open $IO_OPEN_ARG" echo $iocmd - } | $QEMU_IO + } | $QEMU_IO $IO_EXTRA_ARGS } =20 for write_zero_cmd in "write -z" "aio_write -z"; do diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120 index 4f88a67..f40b97d 100755 --- a/tests/qemu-iotests/120 +++ b/tests/qemu-iotests/120 @@ -41,6 +41,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 _supported_fmt generic _supported_proto file _supported_os Linux +_unsupported_fmt luks =20 _make_test_img 64M =20 diff --git a/tests/qemu-iotests/140 b/tests/qemu-iotests/140 index 8c80a5a..f89d0d6 100755 --- a/tests/qemu-iotests/140 +++ b/tests/qemu-iotests/140 @@ -52,8 +52,15 @@ _make_test_img 64k =20 $QEMU_IO -c 'write -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io =20 +if test "$IMGOPTSSYNTAX" =3D "true" +then + SYSEMU_DRIVE_ARG=3Dif=3Dnone,media=3Dcdrom,id=3Ddrv,"$TEST_IMG" +else + SYSEMU_DRIVE_ARG=3Dif=3Dnone,media=3Dcdrom,id=3Ddrv,file=3D"$TEST_IMG"= ,driver=3D$IMGFMT +fi + keep_stderr=3Dy \ -_launch_qemu -drive if=3Dnone,media=3Dcdrom,id=3Ddrv,file=3D"$TEST_IMG",fo= rmat=3D$IMGFMT \ +_launch_qemu -drive $SYSEMU_DRIVE_ARG \ 2> >(_filter_nbd) =20 _send_qemu_cmd $QEMU_HANDLE \ diff --git a/tests/qemu-iotests/145 b/tests/qemu-iotests/145 index e6c6bc4..c371b3c 100755 --- a/tests/qemu-iotests/145 +++ b/tests/qemu-iotests/145 @@ -43,8 +43,23 @@ _supported_proto generic _supported_os Linux =20 _make_test_img 1M -echo quit | $QEMU -nographic -hda "$TEST_IMG" -incoming 'exec:true' -snaps= hot -serial none -monitor stdio | - _filter_qemu | _filter_hmp + +if test "$IMGOPTSSYNTAX" =3D "true" +then + SYSEMU_DRIVE_ARG=3Dif=3Dnone,$TEST_IMG + SYSEMU_EXTRA_ARGS=3D"" + if [ -n "$IMGKEYSECRET" ]; then + SECRET_ARG=3D"secret,id=3Dkeysec0,data=3D$IMGKEYSECRET" + SYSEMU_EXTRA_ARGS=3D"-object $SECRET_ARG" + fi +else + SYSEMU_DRIVE_ARG=3Dif=3Dnone,file=3D"$TEST_IMG",driver=3D$IMGFMT + SYSEMU_EXTRA_ARGS=3D"" +fi + +echo quit | $QEMU -nographic $SYSEMU_EXTRA_ARGS -drive $SYSEMU_DRIVE_ARG \ + -incoming 'exec:true' -snapshot -serial none -monitor st= dio \ + | _filter_qemu | _filter_hmp =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/157 b/tests/qemu-iotests/157 index 8d939cb..2bf02be 100755 --- a/tests/qemu-iotests/157 +++ b/tests/qemu-iotests/157 @@ -43,7 +43,6 @@ _supported_os Linux =20 function do_run_qemu() { - echo Testing: "$@" ( if ! test -t 0; then while read cmd; do @@ -63,7 +62,18 @@ function run_qemu() =20 =20 size=3D128M -drive=3D"if=3Dnone,file=3D$TEST_IMG,driver=3D$IMGFMT" +if test "$IMGOPTSSYNTAX" =3D "true" +then + SYSEMU_DRIVE_ARG=3Dif=3Dnone,$TEST_IMG + SYSEMU_EXTRA_ARGS=3D"" + if [ -n "$IMGKEYSECRET" ]; then + SECRET_ARG=3D"secret,id=3Dkeysec0,data=3D$IMGKEYSECRET" + SYSEMU_EXTRA_ARGS=3D"-object $SECRET_ARG" + fi +else + SYSEMU_DRIVE_ARG=3Dif=3Dnone,file=3D"$TEST_IMG",driver=3D$IMGFMT + SYSEMU_EXTRA_ARGS=3D"" +fi =20 _make_test_img $size =20 @@ -76,8 +86,9 @@ echo =20 for cache in "writeback" "writethrough"; do for wce in "" ",write-cache=3Dauto" ",write-cache=3Don" ",write-cache= =3Doff"; do + echo "Testing: cache=3D'$cache' wce=3D'$wce'" echo "info block" \ - | run_qemu -drive "$drive,cache=3D$cache" \ + | run_qemu $SYSEMU_EXTRA_ARGS -drive "$SYSEMU_DRIVE_ARG,cache= =3D$cache" \ -device "virtio-blk,drive=3Dnone0$wce" \ | grep -e "Testing" -e "Cache mode" done diff --git a/tests/qemu-iotests/157.out b/tests/qemu-iotests/157.out index 77a9c03..fdc807f 100644 --- a/tests/qemu-iotests/157.out +++ b/tests/qemu-iotests/157.out @@ -3,20 +3,20 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D13421= 7728 =20 =3D=3D=3D Setting WCE with qdev and with manually created BB =3D=3D=3D =20 -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwriteback -device virtio-blk,drive=3Dnone0 +Testing: cache=3D'writeback' wce=3D'' Cache mode: writeback -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwriteback -device virtio-blk,drive=3Dnone0,write-cache=3Dauto +Testing: cache=3D'writeback' wce=3D',write-cache=3Dauto' Cache mode: writeback -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwriteback -device virtio-blk,drive=3Dnone0,write-cache=3Don +Testing: cache=3D'writeback' wce=3D',write-cache=3Don' Cache mode: writeback -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwriteback -device virtio-blk,drive=3Dnone0,write-cache=3Doff +Testing: cache=3D'writeback' wce=3D',write-cache=3Doff' Cache mode: writethrough -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwritethrough -device virtio-blk,drive=3Dnone0 +Testing: cache=3D'writethrough' wce=3D'' Cache mode: writethrough -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwritethrough -device virtio-blk,drive=3Dnone0,write-cache=3Dauto +Testing: cache=3D'writethrough' wce=3D',write-cache=3Dauto' Cache mode: writethrough -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwritethrough -device virtio-blk,drive=3Dnone0,write-cache=3Don +Testing: cache=3D'writethrough' wce=3D',write-cache=3Don' Cache mode: writeback -Testing: -drive if=3Dnone,file=3DTEST_DIR/t.IMGFMT,driver=3DIMGFMT,cache= =3Dwritethrough -device virtio-blk,drive=3Dnone0,write-cache=3Doff +Testing: cache=3D'writethrough' wce=3D',write-cache=3Doff' Cache mode: writethrough *** done diff --git a/tests/qemu-iotests/174 b/tests/qemu-iotests/174 index c1c20a1a..552879d 100755 --- a/tests/qemu-iotests/174 +++ b/tests/qemu-iotests/174 @@ -41,7 +41,7 @@ _unsupported_fmt raw =20 =20 size=3D256K -IMGFMT=3Draw IMGOPTS=3D _make_test_img $size | _filter_imgfmt +IMGFMT=3Draw IMGKEYSECRET=3D IMGOPTS=3D _make_test_img $size | _filter_img= fmt =20 echo echo "=3D=3D reading wrong format should fail =3D=3D" diff --git a/tests/qemu-iotests/181 b/tests/qemu-iotests/181 index f73ad5a..0333dda 100755 --- a/tests/qemu-iotests/181 +++ b/tests/qemu-iotests/181 @@ -57,13 +57,24 @@ echo =20 qemu_comm_method=3D"monitor" =20 -_launch_qemu \ - -drive file=3D"${TEST_IMG}",cache=3D${CACHEMODE},driver=3D$IMGFMT,id= =3Ddisk +if [ "$IMGOPTSSYNTAX" =3D "true" ]; then + _launch_qemu \ + -drive "${TEST_IMG}",cache=3D${CACHEMODE},id=3Ddisk +else + _launch_qemu \ + -drive file=3D"${TEST_IMG}",cache=3D${CACHEMODE},driver=3D$IMGFMT,= id=3Ddisk +fi src=3D$QEMU_HANDLE =20 -_launch_qemu \ - -drive file=3D"${TEST_IMG}",cache=3D${CACHEMODE},driver=3D$IMGFMT,id= =3Ddisk \ - -incoming "unix:${MIG_SOCKET}" +if [ "$IMGOPTSSYNTAX" =3D "true" ]; then + _launch_qemu \ + -drive "${TEST_IMG}",cache=3D${CACHEMODE},id=3Ddisk \ + -incoming "unix:${MIG_SOCKET}" +else + _launch_qemu \ + -drive file=3D"${TEST_IMG}",cache=3D${CACHEMODE},driver=3D$IMGFMT,= id=3Ddisk \ + -incoming "unix:${MIG_SOCKET}" +fi dest=3D$QEMU_HANDLE =20 echo diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu index 76ef298..7645f1d 100644 --- a/tests/qemu-iotests/common.qemu +++ b/tests/qemu-iotests/common.qemu @@ -153,14 +153,19 @@ function _launch_qemu() mkfifo "${fifo_out}" mkfifo "${fifo_in}" =20 + object_options=3D + if [ -n "$IMGKEYSECRET" ]; then + object_options=3D"--object secret,id=3Dkeysec0,data=3D$IMGKEYSECRE= T" + fi + if [ -z "$keep_stderr" ]; then QEMU_NEED_PID=3D'y'\ - ${QEMU} -nographic -serial none ${comm} "${@}" >"${fifo_out}" \ + ${QEMU} ${object_options} -nographic -serial none ${comm} "${@}" >= "${fifo_out}" \ 2>&1 \ <"${fifo_in}" & elif [ "$keep_stderr" =3D "y" ]; then QEMU_NEED_PID=3D'y'\ - ${QEMU} -nographic -serial none ${comm} "${@}" >"${fifo_out}" \ + ${QEMU} ${object_options} -nographic -serial none ${comm} "${@}" >= "${fifo_out}" \ <"${fifo_in}" & else exit 1 --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451294765109.6890100081697; Fri, 7 Jul 2017 11:14:54 -0700 (PDT) Received: from localhost ([::1]:58076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXmH-00051X-6k for importer@patchew.org; Fri, 07 Jul 2017 14:14:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmu-00076D-VF for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmq-0001KV-Fs for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14566) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmg-0001Fj-P7; Fri, 07 Jul 2017 13:11:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CACB57EBDB; Fri, 7 Jul 2017 17:11:13 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEE9D61F23; Fri, 7 Jul 2017 17:11:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CACB57EBDB Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CACB57EBDB From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:50 +0200 Message-Id: <1499447335-6125-96-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 07 Jul 2017 17:11:14 +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] [PULL 095/100] iotests: reduce PBKDF iterations when testing LUKS 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-devel@nongnu.org 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" From: "Daniel P. Berrange" By default the PBKDF algorithm used with LUKS is tuned based on the number of iterations to produce 1 second of running time. This makes running the I/O test with the LUKS format orders of magnitude slower than with qcow2/raw formats. When creating LUKS images, set the iteration time to a 10ms to reduce the time overhead for LUKS, since security does not matter in I/O tests. Previously a full 'check -luks' would take $ time ./check -luks Passed all 22 tests real 23m9.988s user 21m46.223s sys 0m22.841s Now it takes $ time ./check -luks Passed all 22 tests real 4m39.235s user 3m29.590s sys 0m24.234s Still slow compared to qcow2/raw, but much improved none the less. Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170626123510.20134-4-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/149 | 3 + tests/qemu-iotests/149.out | 118 +++++++++++++++++++----------------= ---- tests/qemu-iotests/common.filter | 3 +- tests/qemu-iotests/common.rc | 3 + 4 files changed, 67 insertions(+), 60 deletions(-) diff --git a/tests/qemu-iotests/149 b/tests/qemu-iotests/149 index 8407251..f62e618 100755 --- a/tests/qemu-iotests/149 +++ b/tests/qemu-iotests/149 @@ -136,6 +136,7 @@ def cryptsetup_add_password(config, slot): args =3D ["luksAddKey", config.image_path(), "--key-slot", slot, "--key-file", "-", + "--iter-time", "10", pwfile] =20 cryptsetup(args, password) @@ -164,6 +165,7 @@ def cryptsetup_format(config): args.extend(["--hash", config.hash]) args.extend(["--key-slot", slot]) args.extend(["--key-file", "-"]) + args.extend(["--iter-time", "10"]) args.append(config.image_path()) =20 cryptsetup(args, password) @@ -230,6 +232,7 @@ def qemu_img_create(config, size_mb): =20 opts =3D [ "key-secret=3Dsec0", + "iter-time=3D10", "cipher-alg=3D%s-%d" % (config.cipher, config.keylen), "cipher-mode=3D%s" % config.mode, "ivgen-alg=3D%s" % config.ivgen, diff --git a/tests/qemu-iotests/149.out b/tests/qemu-iotests/149.out index 90b5b55..b18c4e4 100644 --- a/tests/qemu-iotests/149.out +++ b/tests/qemu-iotests/149.out @@ -2,7 +2,7 @@ # Create image truncate TEST_DIR/luks-aes-256-xts-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-xts-plain64-sha1= .img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-x= ts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha1.img = qiotest-145-aes-256-xts-plain64-sha1 # Set dev owner @@ -60,8 +60,8 @@ unlink TEST_DIR/luks-aes-256-xts-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dxts,ivgen= -alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-xts-plain64-sha1.img 4= 194304M -Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha1.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-xts-pla= in64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha1.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha1.img = qiotest-145-aes-256-xts-plain64-sha1 @@ -122,7 +122,7 @@ unlink TEST_DIR/luks-aes-256-xts-plain64-sha1.img # Create image truncate TEST_DIR/luks-twofish-256-xts-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher twofish-xts-plain64 --key-size 5= 12 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-twofish-256-xts-plai= n64-sha1.img +sudo cryptsetup -q -v luksFormat --cipher twofish-xts-plain64 --key-size 5= 12 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-twofi= sh-256-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-256-xts-plain64-sha1.= img qiotest-145-twofish-256-xts-plain64-sha1 # Set dev owner @@ -180,8 +180,8 @@ unlink TEST_DIR/luks-twofish-256-xts-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img twofish-256= -xts-plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Dtwofish-256,cipher-mode=3Dxts,i= vgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-twofish-256-xts-plain64-sh= a1.img 4194304M -Formatting 'TEST_DIR/luks-twofish-256-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dtwofish-256 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Dtwofish-256,ciph= er-mode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-twofish-256= -xts-plain64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-twofish-256-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dtwofish-256 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-256-xts-plain64-sha1.= img qiotest-145-twofish-256-xts-plain64-sha1 @@ -242,7 +242,7 @@ unlink TEST_DIR/luks-twofish-256-xts-plain64-sha1.img # Create image truncate TEST_DIR/luks-serpent-256-xts-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 5= 12 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-serpent-256-xts-plai= n64-sha1.img +sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 5= 12 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-serpe= nt-256-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-256-xts-plain64-sha1.= img qiotest-145-serpent-256-xts-plain64-sha1 # Set dev owner @@ -300,8 +300,8 @@ unlink TEST_DIR/luks-serpent-256-xts-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img serpent-256= -xts-plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Dserpent-256,cipher-mode=3Dxts,i= vgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-serpent-256-xts-plain64-sh= a1.img 4194304M -Formatting 'TEST_DIR/luks-serpent-256-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dserpent-256 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Dserpent-256,ciph= er-mode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-serpent-256= -xts-plain64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-serpent-256-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dserpent-256 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-256-xts-plain64-sha1.= img qiotest-145-serpent-256-xts-plain64-sha1 @@ -362,7 +362,7 @@ unlink TEST_DIR/luks-serpent-256-xts-plain64-sha1.img # Create image truncate TEST_DIR/luks-cast5-128-cbc-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher cast5-cbc-plain64 --key-size 128= --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-cast5-128-cbc-plain64-= sha1.img +sudo cryptsetup -q -v luksFormat --cipher cast5-cbc-plain64 --key-size 128= --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-cast5-1= 28-cbc-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-cast5-128-cbc-plain64-sha1.im= g qiotest-145-cast5-128-cbc-plain64-sha1 # Set dev owner @@ -420,8 +420,8 @@ unlink TEST_DIR/luks-cast5-128-cbc-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img cast5-128-c= bc-plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Dcast5-128,cipher-mode=3Dcbc,ivg= en-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-cast5-128-cbc-plain64-sha1.i= mg 4194304M -Formatting 'TEST_DIR/luks-cast5-128-cbc-plain64-sha1.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dcast5-128 cipher-mode=3Dcbc= ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Dcast5-128,cipher= -mode=3Dcbc,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-cast5-128-cbc= -plain64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-cast5-128-cbc-plain64-sha1.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dcast5-128 cipher-mode=3Dcbc= ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-cast5-128-cbc-plain64-sha1.im= g qiotest-145-cast5-128-cbc-plain64-sha1 @@ -483,7 +483,7 @@ Skipping cast6-256-xts-plain64-sha1 in blacklist # Create image truncate TEST_DIR/luks-aes-256-cbc-plain-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain --key-size 256 --h= ash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-cbc-plain-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain --key-size 256 --h= ash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-cbc= -plain-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain-sha1.img qi= otest-145-aes-256-cbc-plain-sha1 # Set dev owner @@ -541,8 +541,8 @@ unlink TEST_DIR/luks-aes-256-cbc-plain-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-cbc= -plain-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dcbc,ivgen= -alg=3Dplain,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-cbc-plain-sha1.img 41943= 04M -Formatting 'TEST_DIR/luks-aes-256-cbc-plain-sha1.img', fmt=3Dluks size=3D4= 398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcbc ivgen= -alg=3Dplain hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dcbc,ivgen-alg=3Dplain,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-cbc-plain= -sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-cbc-plain-sha1.img', fmt=3Dluks size=3D4= 398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcbc ivgen= -alg=3Dplain hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain-sha1.img qi= otest-145-aes-256-cbc-plain-sha1 @@ -603,7 +603,7 @@ unlink TEST_DIR/luks-aes-256-cbc-plain-sha1.img # Create image truncate TEST_DIR/luks-aes-256-cbc-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain64 --key-size 256 -= -hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-cbc-plain64-sha1= .img +sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain64 --key-size 256 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-c= bc-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha1.img = qiotest-145-aes-256-cbc-plain64-sha1 # Set dev owner @@ -661,8 +661,8 @@ unlink TEST_DIR/luks-aes-256-cbc-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-cbc= -plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dcbc,ivgen= -alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-cbc-plain64-sha1.img 4= 194304M -Formatting 'TEST_DIR/luks-aes-256-cbc-plain64-sha1.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcbc i= vgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dcbc,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-cbc-pla= in64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-cbc-plain64-sha1.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcbc i= vgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha1.img = qiotest-145-aes-256-cbc-plain64-sha1 @@ -723,7 +723,7 @@ unlink TEST_DIR/luks-aes-256-cbc-plain64-sha1.img # Create image truncate TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-cbc-essiv:sha256 --key-size = 256 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-cbc-essiv-s= ha256-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-cbc-essiv:sha256 --key-size = 256 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-cbc-essiv-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1= .img qiotest-145-aes-256-cbc-essiv-sha256-sha1 # Set dev owner @@ -781,8 +781,8 @@ unlink TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-cbc= -essiv-sha256-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dcbc,ivgen= -alg=3Dessiv,hash-alg=3Dsha1,ivgen-hash-alg=3Dsha256 TEST_DIR/luks-aes-256-= cbc-essiv-sha256-sha1.img 4194304M -Formatting 'TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1.img', fmt=3Dluks s= ize=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcb= c ivgen-alg=3Dessiv ivgen-hash-alg=3Dsha256 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dcbc,ivgen-alg=3Dessiv,hash-alg=3Dsha1,ivgen-hash-alg=3Dsha256 TEST_DI= R/luks-aes-256-cbc-essiv-sha256-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1.img', fmt=3Dluks s= ize=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcb= c ivgen-alg=3Dessiv ivgen-hash-alg=3Dsha256 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1= .img qiotest-145-aes-256-cbc-essiv-sha256-sha1 @@ -843,7 +843,7 @@ unlink TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1.img # Create image truncate TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-essiv:sha256 --key-size = 512 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-xts-essiv-s= ha256-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-essiv:sha256 --key-size = 512 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-xts-essiv-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1= .img qiotest-145-aes-256-xts-essiv-sha256-sha1 # Set dev owner @@ -901,8 +901,8 @@ unlink TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -essiv-sha256-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dxts,ivgen= -alg=3Dessiv,hash-alg=3Dsha1,ivgen-hash-alg=3Dsha256 TEST_DIR/luks-aes-256-= xts-essiv-sha256-sha1.img 4194304M -Formatting 'TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1.img', fmt=3Dluks s= ize=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxt= s ivgen-alg=3Dessiv ivgen-hash-alg=3Dsha256 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dessiv,hash-alg=3Dsha1,ivgen-hash-alg=3Dsha256 TEST_DI= R/luks-aes-256-xts-essiv-sha256-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1.img', fmt=3Dluks s= ize=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxt= s ivgen-alg=3Dessiv ivgen-hash-alg=3Dsha256 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1= .img qiotest-145-aes-256-xts-essiv-sha256-sha1 @@ -963,7 +963,7 @@ unlink TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1.img # Create image truncate TEST_DIR/luks-aes-128-xts-plain64-sha256-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 256 -= -hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-128-xts-plain64-sha2= 56-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 256 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-128-x= ts-plain64-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-128-xts-plain64-sha256-sh= a1.img qiotest-145-aes-128-xts-plain64-sha256-sha1 # Set dev owner @@ -1021,8 +1021,8 @@ unlink TEST_DIR/luks-aes-128-xts-plain64-sha256-sha1.= img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-128-xts= -plain64-sha256-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-128,cipher-mode=3Dxts,ivgen= -alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-128-xts-plain64-sha256-sha= 1.img 4194304M -Formatting 'TEST_DIR/luks-aes-128-xts-plain64-sha256-sha1.img', fmt=3Dluks= size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-128 cipher-mode=3D= xts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-128,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-128-xts-pla= in64-sha256-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-128-xts-plain64-sha256-sha1.img', fmt=3Dluks= size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-128 cipher-mode=3D= xts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-128-xts-plain64-sha256-sh= a1.img qiotest-145-aes-128-xts-plain64-sha256-sha1 @@ -1083,7 +1083,7 @@ unlink TEST_DIR/luks-aes-128-xts-plain64-sha256-sha1.= img # Create image truncate TEST_DIR/luks-aes-192-xts-plain64-sha256-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 384 -= -hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-192-xts-plain64-sha2= 56-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 384 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-192-x= ts-plain64-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-192-xts-plain64-sha256-sh= a1.img qiotest-145-aes-192-xts-plain64-sha256-sha1 # Set dev owner @@ -1141,8 +1141,8 @@ unlink TEST_DIR/luks-aes-192-xts-plain64-sha256-sha1.= img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-192-xts= -plain64-sha256-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-192,cipher-mode=3Dxts,ivgen= -alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-192-xts-plain64-sha256-sha= 1.img 4194304M -Formatting 'TEST_DIR/luks-aes-192-xts-plain64-sha256-sha1.img', fmt=3Dluks= size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-192 cipher-mode=3D= xts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-192,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-aes-192-xts-pla= in64-sha256-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-192-xts-plain64-sha256-sha1.img', fmt=3Dluks= size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-192 cipher-mode=3D= xts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-192-xts-plain64-sha256-sh= a1.img qiotest-145-aes-192-xts-plain64-sha256-sha1 @@ -1203,7 +1203,7 @@ unlink TEST_DIR/luks-aes-192-xts-plain64-sha256-sha1.= img # Create image truncate TEST_DIR/luks-twofish-128-xts-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher twofish-xts-plain64 --key-size 2= 56 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-twofish-128-xts-plai= n64-sha1.img +sudo cryptsetup -q -v luksFormat --cipher twofish-xts-plain64 --key-size 2= 56 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-twofi= sh-128-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-128-xts-plain64-sha1.= img qiotest-145-twofish-128-xts-plain64-sha1 # Set dev owner @@ -1261,8 +1261,8 @@ unlink TEST_DIR/luks-twofish-128-xts-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img twofish-128= -xts-plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Dtwofish-128,cipher-mode=3Dxts,i= vgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-twofish-128-xts-plain64-sh= a1.img 4194304M -Formatting 'TEST_DIR/luks-twofish-128-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dtwofish-128 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Dtwofish-128,ciph= er-mode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-twofish-128= -xts-plain64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-twofish-128-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dtwofish-128 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-128-xts-plain64-sha1.= img qiotest-145-twofish-128-xts-plain64-sha1 @@ -1324,7 +1324,7 @@ Skipping twofish-192-xts-plain64-sha1 in blacklist # Create image truncate TEST_DIR/luks-serpent-128-xts-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 2= 56 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-serpent-128-xts-plai= n64-sha1.img +sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 2= 56 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-serpe= nt-128-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-128-xts-plain64-sha1.= img qiotest-145-serpent-128-xts-plain64-sha1 # Set dev owner @@ -1382,8 +1382,8 @@ unlink TEST_DIR/luks-serpent-128-xts-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img serpent-128= -xts-plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Dserpent-128,cipher-mode=3Dxts,i= vgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-serpent-128-xts-plain64-sh= a1.img 4194304M -Formatting 'TEST_DIR/luks-serpent-128-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dserpent-128 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Dserpent-128,ciph= er-mode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-serpent-128= -xts-plain64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-serpent-128-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dserpent-128 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-128-xts-plain64-sha1.= img qiotest-145-serpent-128-xts-plain64-sha1 @@ -1444,7 +1444,7 @@ unlink TEST_DIR/luks-serpent-128-xts-plain64-sha1.img # Create image truncate TEST_DIR/luks-serpent-192-xts-plain64-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 3= 84 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-serpent-192-xts-plai= n64-sha1.img +sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 3= 84 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-serpe= nt-192-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-192-xts-plain64-sha1.= img qiotest-145-serpent-192-xts-plain64-sha1 # Set dev owner @@ -1502,8 +1502,8 @@ unlink TEST_DIR/luks-serpent-192-xts-plain64-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img serpent-192= -xts-plain64-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Dserpent-192,cipher-mode=3Dxts,i= vgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-serpent-192-xts-plain64-sh= a1.img 4194304M -Formatting 'TEST_DIR/luks-serpent-192-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dserpent-192 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Dserpent-192,ciph= er-mode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha1 TEST_DIR/luks-serpent-192= -xts-plain64-sha1.img 4194304M +Formatting 'TEST_DIR/luks-serpent-192-xts-plain64-sha1.img', fmt=3Dluks si= ze=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Dserpent-192 cipher-mode= =3Dxts ivgen-alg=3Dplain64 hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-192-xts-plain64-sha1.= img qiotest-145-serpent-192-xts-plain64-sha1 @@ -1566,7 +1566,7 @@ Skipping cast6-192-xts-plain64-sha1 in blacklist # Create image truncate TEST_DIR/luks-aes-256-xts-plain64-sha256.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha256 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-xts-plain64-sh= a256.img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha256 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha256.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha256.im= g qiotest-145-aes-256-xts-plain64-sha256 # Set dev owner @@ -1624,8 +1624,8 @@ unlink TEST_DIR/luks-aes-256-xts-plain64-sha256.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain64-sha256 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dxts,ivgen= -alg=3Dplain64,hash-alg=3Dsha256 TEST_DIR/luks-aes-256-xts-plain64-sha256.i= mg 4194304M -Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha256.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha256 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha256 TEST_DIR/luks-aes-256-xts-p= lain64-sha256.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha256.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha256 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha256.im= g qiotest-145-aes-256-xts-plain64-sha256 @@ -1688,7 +1688,7 @@ Skipping aes-256-xts-plain64-ripemd160 in blacklist # Create image truncate TEST_DIR/luks-aes-256-xts-plain-sha1-pwslot3.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain --key-size 512 --h= ash sha1 --key-slot 3 --key-file - TEST_DIR/luks-aes-256-xts-plain-sha1-pws= lot3.img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain --key-size 512 --h= ash sha1 --key-slot 3 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-xts= -plain-sha1-pwslot3.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwslot= 3.img qiotest-145-aes-256-xts-plain-sha1-pwslot3 # Set dev owner @@ -1748,21 +1748,21 @@ unlink TEST_DIR/luks-aes-256-xts-plain-sha1-pwslot3= .img # Create image truncate TEST_DIR/luks-aes-256-xts-plain-sha1-pwallslots.img --size 419430= 4MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain --key-size 512 --h= ash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-xts-plain-sha1-pwa= llslots.img +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain --key-size 512 --h= ash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-xts= -plain-sha1-pwallslots.img # Add password slot 1 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 1 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 1 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Add password slot 2 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 2 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 2 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Add password slot 3 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 3 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 3 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Add password slot 4 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 4 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 4 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Add password slot 5 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 5 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 5 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Add password slot 6 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 6 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 6 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Add password slot 7 -sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 7 --key-file - TEST_DIR/passwd.txt +sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 7 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwalls= lots.img qiotest-145-aes-256-xts-plain-sha1-pwallslots # Set dev owner @@ -1820,8 +1820,8 @@ unlink TEST_DIR/luks-aes-256-xts-plain-sha1-pwallslot= s.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain-sha1-pwallslots =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3Dc2xvdDE=3D,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dxts,ivgen= -alg=3Dplain,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-xts-plain-sha1-pwallslot= s.img 4194304M -Formatting 'TEST_DIR/luks-aes-256-xts-plain-sha1-pwallslots.img', fmt=3Dlu= ks size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode= =3Dxts ivgen-alg=3Dplain hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3Dc2xvdDE=3D,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-xts-plain= -sha1-pwallslots.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain-sha1-pwallslots.img', fmt=3Dlu= ks size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode= =3Dxts ivgen-alg=3Dplain hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwalls= lots.img qiotest-145-aes-256-xts-plain-sha1-pwallslots @@ -1882,7 +1882,7 @@ unlink TEST_DIR/luks-aes-256-xts-plain-sha1-pwallslot= s.img # Create image truncate TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-cbc-essiv:sha256 --key-size = 256 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-cbc-essiv-a= uto-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-cbc-essiv:sha256 --key-size = 256 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-cbc-essiv-auto-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.i= mg qiotest-145-aes-256-cbc-essiv-auto-sha1 # Set dev owner @@ -1940,8 +1940,8 @@ unlink TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-cbc= -essiv-auto-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dcbc,ivgen= -alg=3Dessiv,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.img = 4194304M -Formatting 'TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.img', fmt=3Dluks siz= e=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcbc = ivgen-alg=3Dessiv hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dcbc,ivgen-alg=3Dessiv,hash-alg=3Dsha1 TEST_DIR/luks-aes-256-cbc-essiv= -auto-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.img', fmt=3Dluks siz= e=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dcbc = ivgen-alg=3Dessiv hash-alg=3Dsha1 iter-time=3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.i= mg qiotest-145-aes-256-cbc-essiv-auto-sha1 @@ -2002,7 +2002,7 @@ unlink TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.img # Create image truncate TEST_DIR/luks-aes-256-cbc-plain64-sha256-sha1.img --size 4194304MB # Format image -sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain64:sha256 --key-siz= e 256 --hash sha1 --key-slot 0 --key-file - TEST_DIR/luks-aes-256-cbc-plain= 64-sha256-sha1.img +sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain64:sha256 --key-siz= e 256 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-ae= s-256-cbc-plain64-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha256-sh= a1.img qiotest-145-aes-256-cbc-plain64-sha256-sha1 # Set dev owner @@ -2060,8 +2060,8 @@ unlink TEST_DIR/luks-aes-256-cbc-plain64-sha256-sha1.= img =20 # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-cbc= -plain64-sha256-sha1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image -qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,cipher-alg=3Daes-256,cipher-mode=3Dcbc,ivgen= -alg=3Dplain64,hash-alg=3Dsha1,ivgen-hash-alg=3Dsha256 TEST_DIR/luks-aes-25= 6-cbc-plain64-sha256-sha1.img 4194304M -Formatting 'TEST_DIR/luks-aes-256-cbc-plain64-sha256-sha1.img', fmt=3Dluks= size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3D= cbc ivgen-alg=3Dplain64 ivgen-hash-alg=3Dsha256 hash-alg=3Dsha1 +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dcbc,ivgen-alg=3Dplain64,hash-alg=3Dsha1,ivgen-hash-alg=3Dsha256 TEST_= DIR/luks-aes-256-cbc-plain64-sha256-sha1.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-cbc-plain64-sha256-sha1.img', fmt=3Dluks= size=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3D= cbc ivgen-alg=3Dplain64 ivgen-hash-alg=3Dsha256 hash-alg=3Dsha1 iter-time= =3D10 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha256-sh= a1.img qiotest-145-aes-256-cbc-plain64-sha256-sha1 diff --git a/tests/qemu-iotests/common.filter b/tests/qemu-iotests/common.f= ilter index 2f595b2..7a58e57 100644 --- a/tests/qemu-iotests/common.filter +++ b/tests/qemu-iotests/common.filter @@ -126,7 +126,8 @@ _filter_img_create() -e "s# block_state_zero=3D\\(on\\|off\\)##g" \ -e "s# log_size=3D[0-9]\\+##g" \ -e "s# refcount_bits=3D[0-9]\\+##g" \ - -e "s# key-secret=3D[a-zA-Z0-9]\\+##g" + -e "s# key-secret=3D[a-zA-Z0-9]\\+##g" \ + -e "s# iter-time=3D[0-9]\\+##g" } =20 _filter_img_info() diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 9fd3130..2548e58 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -107,6 +107,9 @@ _set_default_imgopts() if [ "$IMGFMT" =3D=3D "qcow2" ] && ! (echo "$IMGOPTS" | grep "compat= =3D" > /dev/null); then IMGOPTS=3D$(_optstr_add "$IMGOPTS" "compat=3D1.1") fi + if [ "$IMGFMT" =3D=3D "luks" ] && ! (echo "$IMGOPTS" | grep "iter-time= =3D" > /dev/null); then + IMGOPTS=3D$(_optstr_add "$IMGOPTS" "iter-time=3D10") + fi } =20 _use_sample_img() --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 149945121186783.98134217757683; Fri, 7 Jul 2017 11:13:31 -0700 (PDT) Received: from localhost ([::1]:58065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXkv-0003SD-9d for importer@patchew.org; Fri, 07 Jul 2017 14:13:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmu-00075Z-8u for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmq-0001KQ-FI for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51726) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmi-0001Gq-9K; Fri, 07 Jul 2017 13:11:16 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FFC68008D; Fri, 7 Jul 2017 17:11:15 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39A2762924; Fri, 7 Jul 2017 17:11:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3FFC68008D Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3FFC68008D From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:51 +0200 Message-Id: <1499447335-6125-97-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 07 Jul 2017 17:11:15 +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] [PULL 096/100] iotests: add more LUKS hash combination tests 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-devel@nongnu.org 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" From: "Daniel P. Berrange" Add tests for sha224, sha512, sha384 and ripemd160 hash algorithms. Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170626123510.20134-5-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/149 | 10 +- tests/qemu-iotests/149.out | 482 +++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 484 insertions(+), 8 deletions(-) diff --git a/tests/qemu-iotests/149 b/tests/qemu-iotests/149 index f62e618..5faf585 100755 --- a/tests/qemu-iotests/149 +++ b/tests/qemu-iotests/149 @@ -457,8 +457,12 @@ configs =3D [ =20 =20 # LUKS default but diff hash + LUKSConfig("aes-256-xts-plain64-sha224", + "aes", 256, "xts", "plain64", None, "sha224"), LUKSConfig("aes-256-xts-plain64-sha256", "aes", 256, "xts", "plain64", None, "sha256"), + LUKSConfig("aes-256-xts-plain64-sha384", + "aes", 256, "xts", "plain64", None, "sha384"), LUKSConfig("aes-256-xts-plain64-sha512", "aes", 256, "xts", "plain64", None, "sha512"), LUKSConfig("aes-256-xts-plain64-ripemd160", @@ -504,12 +508,6 @@ blacklist =3D [ =20 # GCrypt doesn't support Twofish with 192 bit key "twofish-192-xts-plain64-sha1", - - # We don't have sha512 hash wired up yet - "aes-256-xts-plain64-sha512", - - # We don't have ripemd160 hash wired up yet - "aes-256-xts-plain64-ripemd160", ] =20 whitelist =3D [] diff --git a/tests/qemu-iotests/149.out b/tests/qemu-iotests/149.out index b18c4e4..2f0454f 100644 --- a/tests/qemu-iotests/149.out +++ b/tests/qemu-iotests/149.out @@ -1562,6 +1562,126 @@ unlink TEST_DIR/luks-serpent-192-xts-plain64-sha1.i= mg =20 Skipping cast6-128-xts-plain64-sha1 in blacklist Skipping cast6-192-xts-plain64-sha1 in blacklist +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D dm-crypt aes-256-xts= -plain64-sha224 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +truncate TEST_DIR/luks-aes-256-xts-plain64-sha224.img --size 4194304MB +# Format image +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha224 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha224.img +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha224 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha224 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha224 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-sha224.img + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain64-sha224 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha224 TEST_DIR/luks-aes-256-xts-p= lain64-sha224.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha224.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha224 iter-time=3D10 + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha224 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-sha224.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha224 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha224 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-sha224.img + # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D dm-crypt aes-256-xts= -plain64-sha256 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image truncate TEST_DIR/luks-aes-256-xts-plain64-sha256.img --size 4194304MB @@ -1682,8 +1802,366 @@ sudo cryptsetup -q -v luksClose qiotest-145-aes-256= -xts-plain64-sha256 # Delete image unlink TEST_DIR/luks-aes-256-xts-plain64-sha256.img =20 -Skipping aes-256-xts-plain64-sha512 in blacklist -Skipping aes-256-xts-plain64-ripemd160 in blacklist +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D dm-crypt aes-256-xts= -plain64-sha384 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +truncate TEST_DIR/luks-aes-256-xts-plain64-sha384.img --size 4194304MB +# Format image +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha384 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha384.img +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha384 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha384 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha384 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-sha384.img + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain64-sha384 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha384 TEST_DIR/luks-aes-256-xts-p= lain64-sha384.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha384.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha384 iter-time=3D10 + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha384 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-sha384.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha384 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha384 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-sha384.img + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D dm-crypt aes-256-xts= -plain64-sha512 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +truncate TEST_DIR/luks-aes-256-xts-plain64-sha512.img --size 4194304MB +# Format image +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha512 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha512.img +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha512 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha512 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha512 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-sha512.img + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain64-sha512 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dsha512 TEST_DIR/luks-aes-256-xts-p= lain64-sha512.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha512.img', fmt=3Dluks size= =3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxts i= vgen-alg=3Dplain64 hash-alg=3Dsha512 iter-time=3D10 + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha512 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-sha512.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha512 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-sha512 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-sha512.img + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D dm-crypt aes-256-xts= -plain64-ripemd160 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +truncate TEST_DIR/luks-aes-256-xts-plain64-ripemd160.img --size 4194304MB +# Format image +sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash ripemd160 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-xts-plain64-ripemd160.img +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-ripemd160 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-ripemd160 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-ripemd160.img + +# =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D qemu-img aes-256-xts= -plain64-ripemd160 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +# Create image +qemu-img create -f luks --object secret,id=3Dsec0,data=3DMTIzNDU2,format= =3Dbase64 -o key-secret=3Dsec0,iter-time=3D10,cipher-alg=3Daes-256,cipher-m= ode=3Dxts,ivgen-alg=3Dplain64,hash-alg=3Dripemd160 TEST_DIR/luks-aes-256-xt= s-plain64-ripemd160.img 4194304M +Formatting 'TEST_DIR/luks-aes-256-xts-plain64-ripemd160.img', fmt=3Dluks s= ize=3D4398046511104 key-secret=3Dsec0 cipher-alg=3Daes-256 cipher-mode=3Dxt= s ivgen-alg=3Dplain64 hash-alg=3Dripemd160 iter-time=3D10 + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +# Write test pattern 0xa7 +qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x13 +qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-ripemd160 +# Read test pattern 0xa7 +qemu-io -c read -P 0xa7 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU2= ,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filename= =3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x13 +qemu-io -c read -P 0x13 3145728M 10M --object secret,id=3Dsec0,data=3DMTIz= NDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.file= name=3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x91 +qemu-io -c write -P 0x91 100M 10M --object secret,id=3Dsec0,data=3DMTIzNDU= 2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.filenam= e=3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +wrote 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Write test pattern 0x5e +qemu-io -c write -P 0x5e 3145728M 10M --object secret,id=3Dsec0,data=3DMTI= zNDU2,format=3Dbase64 --image-opts driver=3Dluks,key-secret=3Dsec0,file.fil= ename=3DTEST_DIR/luks-aes-256-xts-plain64-ripemd160.img +wrote 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Open dev +sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 +# Set dev owner +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +# Read test pattern 0x91 +qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +read 10485760/10485760 bytes at offset 104857600 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Read test pattern 0x5e +qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 +read 10485760/10485760 bytes at offset 3298534883328 +10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +# Close dev +sudo cryptsetup -q -v luksClose qiotest-145-aes-256-xts-plain64-ripemd160 +# Delete image +unlink TEST_DIR/luks-aes-256-xts-plain64-ripemd160.img + # =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D dm-crypt aes-256-xts= -plain-sha1-pwslot3 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D # Create image truncate TEST_DIR/luks-aes-256-xts-plain-sha1-pwslot3.img --size 4194304MB --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451376521553.9573204477471; Fri, 7 Jul 2017 11:16:16 -0700 (PDT) Received: from localhost ([::1]:58086 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXnb-0006DZ-15 for importer@patchew.org; Fri, 07 Jul 2017 14:16:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWnC-0007LU-5X for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWn3-0001OX-9k for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48878) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmj-0001He-Gw; Fri, 07 Jul 2017 13:11:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C7885BECD; Fri, 7 Jul 2017 17:11:16 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B38D61F23; Fri, 7 Jul 2017 17:11:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8C7885BECD Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8C7885BECD From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:52 +0200 Message-Id: <1499447335-6125-98-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 07 Jul 2017 17:11:16 +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] [PULL 097/100] iotests: chown LUKS device before qemu-io launches 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-devel@nongnu.org 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" From: "Daniel P. Berrange" On some distros, whenever you close a block device file descriptor there is a udev rule that resets the file permissions. This can race with the test script when we run qemu-io multiple times against the same block device. Occasionally the second qemu-io invocation will find udev has reset the permissions causing failure. Reviewed-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange Message-id: 20170626123510.20134-6-berrange@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/149 | 12 +- tests/qemu-iotests/149.out | 344 ++++++++++++++++++++++-------------------= ---- 2 files changed, 177 insertions(+), 179 deletions(-) diff --git a/tests/qemu-iotests/149 b/tests/qemu-iotests/149 index 5faf585..223cd68 100755 --- a/tests/qemu-iotests/149 +++ b/tests/qemu-iotests/149 @@ -186,7 +186,7 @@ def chown(config): msg =3D proc.communicate()[0] =20 if proc.returncode !=3D 0: - raise Exception("Cannot change owner on %s" % path) + raise Exception(msg) =20 =20 def cryptsetup_open(config): @@ -271,6 +271,8 @@ def qemu_io_image_args(config, dev=3DFalse): def qemu_io_write_pattern(config, pattern, offset_mb, size_mb, dev=3DFalse= ): """Write a pattern of data to a LUKS image or device""" =20 + if dev: + chown(config) args =3D ["-c", "write -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb= )] args.extend(qemu_io_image_args(config, dev)) iotests.log("qemu-io " + " ".join(args), filters=3D[iotests.filter_tes= t_dir]) @@ -281,6 +283,8 @@ def qemu_io_write_pattern(config, pattern, offset_mb, s= ize_mb, dev=3DFalse): def qemu_io_read_pattern(config, pattern, offset_mb, size_mb, dev=3DFalse): """Read a pattern of data to a LUKS image or device""" =20 + if dev: + chown(config) args =3D ["-c", "read -P 0x%x %dM %dM" % (pattern, offset_mb, size_mb)] args.extend(qemu_io_image_args(config, dev)) iotests.log("qemu-io " + " ".join(args), filters=3D[iotests.filter_tes= t_dir]) @@ -331,9 +335,6 @@ def test_once(config, qemu_img=3DFalse): cryptsetup_open(config) =20 try: - iotests.log("# Set dev owner") - chown(config) - iotests.log("# Write test pattern 0xa7") qemu_io_write_pattern(config, 0xa7, lowOffsetMB, 10, dev=3DTru= e) iotests.log("# Write test pattern 0x13") @@ -365,9 +366,6 @@ def test_once(config, qemu_img=3DFalse): cryptsetup_open(config) =20 try: - iotests.log("# Set dev owner") - chown(config) - iotests.log("# Read test pattern 0x91") qemu_io_read_pattern(config, 0x91, lowOffsetMB, 10, dev=3DTrue) iotests.log("# Read test pattern 0x5e") diff --git a/tests/qemu-iotests/149.out b/tests/qemu-iotests/149.out index 2f0454f..5dea00b 100644 --- a/tests/qemu-iotests/149.out +++ b/tests/qemu-iotests/149.out @@ -5,14 +5,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain64-sha1.img --siz= e 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-x= ts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha1.img = qiotest-145-aes-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -41,14 +41,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha1.img = qiotest-145-aes-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -65,14 +65,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha1.img'= , fmt=3Dluks size=3D439804651 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha1.img = qiotest-145-aes-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -101,14 +101,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha1.img = qiotest-145-aes-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -125,14 +125,14 @@ truncate TEST_DIR/luks-twofish-256-xts-plain64-sha1.i= mg --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher twofish-xts-plain64 --key-size 5= 12 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-twofi= sh-256-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-256-xts-plain64-sha1.= img qiotest-145-twofish-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -161,14 +161,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-256-xts-plain64-sha1.= img qiotest-145-twofish-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-twofish-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -185,14 +185,14 @@ Formatting 'TEST_DIR/luks-twofish-256-xts-plain64-sha= 1.img', fmt=3Dluks size=3D43980 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-256-xts-plain64-sha1.= img qiotest-145-twofish-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -221,14 +221,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-256-xts-plain64-sha1.= img qiotest-145-twofish-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-twofish-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -245,14 +245,14 @@ truncate TEST_DIR/luks-serpent-256-xts-plain64-sha1.i= mg --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 5= 12 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-serpe= nt-256-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-256-xts-plain64-sha1.= img qiotest-145-serpent-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -281,14 +281,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-256-xts-plain64-sha1.= img qiotest-145-serpent-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-serpent-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -305,14 +305,14 @@ Formatting 'TEST_DIR/luks-serpent-256-xts-plain64-sha= 1.img', fmt=3Dluks size=3D43980 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-256-xts-plain64-sha1.= img qiotest-145-serpent-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -341,14 +341,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-256-xts-plain64-sha1.= img qiotest-145-serpent-256-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-serpent-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-256-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -365,14 +365,14 @@ truncate TEST_DIR/luks-cast5-128-cbc-plain64-sha1.img= --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher cast5-cbc-plain64 --key-size 128= --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-cast5-1= 28-cbc-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-cast5-128-cbc-plain64-sha1.im= g qiotest-145-cast5-128-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -401,14 +401,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-cast5-128-cbc-plain64-sha1.im= g qiotest-145-cast5-128-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -425,14 +425,14 @@ Formatting 'TEST_DIR/luks-cast5-128-cbc-plain64-sha1.= img', fmt=3Dluks size=3D4398046 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-cast5-128-cbc-plain64-sha1.im= g qiotest-145-cast5-128-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -461,14 +461,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-cast5-128-cbc-plain64-sha1.im= g qiotest-145-cast5-128-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-cast5-128-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -486,14 +486,14 @@ truncate TEST_DIR/luks-aes-256-cbc-plain-sha1.img --s= ize 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain --key-size 256 --h= ash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-cbc= -plain-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain-sha1.img qi= otest-145-aes-256-cbc-plain-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-plain-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -522,14 +522,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain-sha1.img qi= otest-145-aes-256-cbc-plain-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-plain-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -546,14 +546,14 @@ Formatting 'TEST_DIR/luks-aes-256-cbc-plain-sha1.img'= , fmt=3Dluks size=3D43980465111 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain-sha1.img qi= otest-145-aes-256-cbc-plain-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-plain-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -582,14 +582,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain-sha1.img qi= otest-145-aes-256-cbc-plain-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-plain-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -606,14 +606,14 @@ truncate TEST_DIR/luks-aes-256-cbc-plain64-sha1.img -= -size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain64 --key-size 256 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-c= bc-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha1.img = qiotest-145-aes-256-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -642,14 +642,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha1.img = qiotest-145-aes-256-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -666,14 +666,14 @@ Formatting 'TEST_DIR/luks-aes-256-cbc-plain64-sha1.im= g', fmt=3Dluks size=3D439804651 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha1.img = qiotest-145-aes-256-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -702,14 +702,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha1.img = qiotest-145-aes-256-cbc-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -726,14 +726,14 @@ truncate TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1.= img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-cbc-essiv:sha256 --key-size = 256 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-cbc-essiv-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1= .img qiotest-145-aes-256-cbc-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -762,14 +762,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1= .img qiotest-145-aes-256-cbc-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -786,14 +786,14 @@ Formatting 'TEST_DIR/luks-aes-256-cbc-essiv-sha256-sh= a1.img', fmt=3Dluks size=3D4398 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1= .img qiotest-145-aes-256-cbc-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -822,14 +822,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-sha256-sha1= .img qiotest-145-aes-256-cbc-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -846,14 +846,14 @@ truncate TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1.= img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-essiv:sha256 --key-size = 512 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-xts-essiv-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1= .img qiotest-145-aes-256-xts-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -882,14 +882,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1= .img qiotest-145-aes-256-xts-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -906,14 +906,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-essiv-sha256-sh= a1.img', fmt=3Dluks size=3D4398 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1= .img qiotest-145-aes-256-xts-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -942,14 +942,14 @@ wrote 10485760/10485760 bytes at offset 3298534883328 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-essiv-sha256-sha1= .img qiotest-145-aes-256-xts-essiv-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-essiv-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -966,14 +966,14 @@ truncate TEST_DIR/luks-aes-128-xts-plain64-sha256-sha= 1.img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 256 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-128-x= ts-plain64-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-128-xts-plain64-sha256-sh= a1.img qiotest-145-aes-128-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1002,14 +1002,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-128-xts-plain64-sha256-sh= a1.img qiotest-145-aes-128-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1026,14 +1026,14 @@ Formatting 'TEST_DIR/luks-aes-128-xts-plain64-sha25= 6-sha1.img', fmt=3Dluks size=3D43 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-128-xts-plain64-sha256-sh= a1.img qiotest-145-aes-128-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1062,14 +1062,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-128-xts-plain64-sha256-sh= a1.img qiotest-145-aes-128-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-128-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1086,14 +1086,14 @@ truncate TEST_DIR/luks-aes-192-xts-plain64-sha256-s= ha1.img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 384 -= -hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-192-x= ts-plain64-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-192-xts-plain64-sha256-sh= a1.img qiotest-145-aes-192-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1122,14 +1122,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-192-xts-plain64-sha256-sh= a1.img qiotest-145-aes-192-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1146,14 +1146,14 @@ Formatting 'TEST_DIR/luks-aes-192-xts-plain64-sha25= 6-sha1.img', fmt=3Dluks size=3D43 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-192-xts-plain64-sha256-sh= a1.img qiotest-145-aes-192-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1182,14 +1182,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-192-xts-plain64-sha256-sh= a1.img qiotest-145-aes-192-xts-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-192-xts-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1206,14 +1206,14 @@ truncate TEST_DIR/luks-twofish-128-xts-plain64-sha1= .img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher twofish-xts-plain64 --key-size 2= 56 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-twofi= sh-128-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-128-xts-plain64-sha1.= img qiotest-145-twofish-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1242,14 +1242,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-128-xts-plain64-sha1.= img qiotest-145-twofish-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-twofish-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1266,14 +1266,14 @@ Formatting 'TEST_DIR/luks-twofish-128-xts-plain64-s= ha1.img', fmt=3Dluks size=3D43980 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-128-xts-plain64-sha1.= img qiotest-145-twofish-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1302,14 +1302,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-twofish-128-xts-plain64-sha1.= img qiotest-145-twofish-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-twofish-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-twofish-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1327,14 +1327,14 @@ truncate TEST_DIR/luks-serpent-128-xts-plain64-sha1= .img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 2= 56 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-serpe= nt-128-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-128-xts-plain64-sha1.= img qiotest-145-serpent-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1363,14 +1363,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-128-xts-plain64-sha1.= img qiotest-145-serpent-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-serpent-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1387,14 +1387,14 @@ Formatting 'TEST_DIR/luks-serpent-128-xts-plain64-s= ha1.img', fmt=3Dluks size=3D43980 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-128-xts-plain64-sha1.= img qiotest-145-serpent-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1423,14 +1423,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-128-xts-plain64-sha1.= img qiotest-145-serpent-128-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-serpent-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-128-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1447,14 +1447,14 @@ truncate TEST_DIR/luks-serpent-192-xts-plain64-sha1= .img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher serpent-xts-plain64 --key-size 3= 84 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-serpe= nt-192-xts-plain64-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-192-xts-plain64-sha1.= img qiotest-145-serpent-192-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1483,14 +1483,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-192-xts-plain64-sha1.= img qiotest-145-serpent-192-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-serpent-192-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1507,14 +1507,14 @@ Formatting 'TEST_DIR/luks-serpent-192-xts-plain64-s= ha1.img', fmt=3Dluks size=3D43980 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-192-xts-plain64-sha1.= img qiotest-145-serpent-192-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1543,14 +1543,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-serpent-192-xts-plain64-sha1.= img qiotest-145-serpent-192-xts-plain64-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-serpent-192-xts-plain64-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-serpent-192-xts-plain64-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1569,14 +1569,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain64-sha224.i= mg --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha224 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha224.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha224 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1605,14 +1605,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha224 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1629,14 +1629,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha22= 4.img', fmt=3Dluks size=3D4398046 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha224 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1665,14 +1665,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha224.im= g qiotest-145-aes-256-xts-plain64-sha224 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha224 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha224 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1689,14 +1689,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain64-sha256.i= mg --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha256 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha256.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha256.im= g qiotest-145-aes-256-xts-plain64-sha256 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha256 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1725,14 +1725,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha256.im= g qiotest-145-aes-256-xts-plain64-sha256 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha256 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1749,14 +1749,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha25= 6.img', fmt=3Dluks size=3D4398046 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha256.im= g qiotest-145-aes-256-xts-plain64-sha256 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha256 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1785,14 +1785,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha256.im= g qiotest-145-aes-256-xts-plain64-sha256 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha256 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha256 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1809,14 +1809,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain64-sha384.i= mg --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha384 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha384.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha384 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1845,14 +1845,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha384 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1869,14 +1869,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha38= 4.img', fmt=3Dluks size=3D4398046 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha384 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1905,14 +1905,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha384.im= g qiotest-145-aes-256-xts-plain64-sha384 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha384 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha384 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1929,14 +1929,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain64-sha512.i= mg --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash sha512 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-256= -xts-plain64-sha512.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha512 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1965,14 +1965,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha512 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -1989,14 +1989,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain64-sha51= 2.img', fmt=3Dluks size=3D4398046 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-sha512 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2025,14 +2025,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-sha512.im= g qiotest-145-aes-256-xts-plain64-sha512 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-sha512 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-sha512 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2049,14 +2049,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain64-ripemd16= 0.img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain64 --key-size 512 -= -hash ripemd160 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-xts-plain64-ripemd160.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2085,14 +2085,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2109,14 +2109,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain64-ripem= d160.img', fmt=3Dluks size=3D4398 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2145,14 +2145,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain64-ripemd160= .img qiotest-145-aes-256-xts-plain64-ripemd160 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain64-ripemd160 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2169,14 +2169,14 @@ truncate TEST_DIR/luks-aes-256-xts-plain-sha1-pwslo= t3.img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-xts-plain --key-size 512 --h= ash sha1 --key-slot 3 --key-file - --iter-time 10 TEST_DIR/luks-aes-256-xts= -plain-sha1-pwslot3.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwslot= 3.img qiotest-145-aes-256-xts-plain-sha1-pwslot3 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2205,14 +2205,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwslot= 3.img qiotest-145-aes-256-xts-plain-sha1-pwslot3 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwslot3 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2243,14 +2243,14 @@ sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-= 256-xts-plain-sha1-pwallslots sudo cryptsetup -q -v luksAddKey TEST_DIR/luks-aes-256-xts-plain-sha1-pwal= lslots.img --key-slot 7 --key-file - --iter-time 10 TEST_DIR/passwd.txt # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwalls= lots.img qiotest-145-aes-256-xts-plain-sha1-pwallslots -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2279,14 +2279,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwalls= lots.img qiotest-145-aes-256-xts-plain-sha1-pwallslots -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2303,14 +2303,14 @@ Formatting 'TEST_DIR/luks-aes-256-xts-plain-sha1-pw= allslots.img', fmt=3Dluks size=3D =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwalls= lots.img qiotest-145-aes-256-xts-plain-sha1-pwallslots -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2339,14 +2339,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-xts-plain-sha1-pwalls= lots.img qiotest-145-aes-256-xts-plain-sha1-pwallslots -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslo= ts qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-xts-plain-sha1-pwallslots read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2363,14 +2363,14 @@ truncate TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.= img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-cbc-essiv:sha256 --key-size = 256 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-aes-= 256-cbc-essiv-auto-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.i= mg qiotest-145-aes-256-cbc-essiv-auto-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2399,14 +2399,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.i= mg qiotest-145-aes-256-cbc-essiv-auto-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2423,14 +2423,14 @@ Formatting 'TEST_DIR/luks-aes-256-cbc-essiv-auto-sh= a1.img', fmt=3Dluks size=3D439804 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.i= mg qiotest-145-aes-256-cbc-essiv-auto-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2459,14 +2459,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-essiv-auto-sha1.i= mg qiotest-145-aes-256-cbc-essiv-auto-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-essiv-auto-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2483,14 +2483,14 @@ truncate TEST_DIR/luks-aes-256-cbc-plain64-sha256-s= ha1.img --size 4194304MB sudo cryptsetup -q -v luksFormat --cipher aes-cbc-plain64:sha256 --key-siz= e 256 --hash sha1 --key-slot 0 --key-file - --iter-time 10 TEST_DIR/luks-ae= s-256-cbc-plain64-sha256-sha1.img # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha256-sh= a1.img qiotest-145-aes-256-cbc-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2519,14 +2519,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha256-sh= a1.img qiotest-145-aes-256-cbc-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2543,14 +2543,14 @@ Formatting 'TEST_DIR/luks-aes-256-cbc-plain64-sha25= 6-sha1.img', fmt=3Dluks size=3D43 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha256-sh= a1.img qiotest-145-aes-256-cbc-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 # Write test pattern 0xa7 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c write -P 0xa7 100M 10M --image-opts driver=3Dfile,filename=3D/d= ev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Write test pattern 0x13 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c write -P 0x13 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 wrote 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) @@ -2579,14 +2579,14 @@ wrote 10485760/10485760 bytes at offset 32985348833= 28 =20 # Open dev sudo cryptsetup -q -v luksOpen TEST_DIR/luks-aes-256-cbc-plain64-sha256-sh= a1.img qiotest-145-aes-256-cbc-plain64-sha256-sha1 -# Set dev owner -sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 # Read test pattern 0x91 +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c read -P 0x91 100M 10M --image-opts driver=3Dfile,filename=3D/de= v/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 104857600 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 # Read test pattern 0x5e +sudo chown UID:GID /dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 qemu-io -c read -P 0x5e 3145728M 10M --image-opts driver=3Dfile,filename= =3D/dev/mapper/qiotest-145-aes-256-cbc-plain64-sha256-sha1 read 10485760/10485760 bytes at offset 3298534883328 10 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 14994509375351007.8251370881145; Fri, 7 Jul 2017 11:08:57 -0700 (PDT) Received: from localhost ([::1]:58042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXgU-0007ds-8H for importer@patchew.org; Fri, 07 Jul 2017 14:08:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43795) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmr-000725-BG for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWmq-0001KJ-Ec for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmk-0001Hy-NC; Fri, 07 Jul 2017 13:11:18 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0E5C5D689; Fri, 7 Jul 2017 17:11:17 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id D953761F23; Fri, 7 Jul 2017 17:11:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C0E5C5D689 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C0E5C5D689 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:53 +0200 Message-Id: <1499447335-6125-99-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 07 Jul 2017 17:11:17 +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] [PULL 098/100] iotests: Use absolute paths for executables 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-devel@nongnu.org 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" From: Max Reitz A user may specify a relative path for accessing qemu, qemu-img, etc. through environment variables ($QEMU_PROG and friends) or a symlink. If a test decides to change its working directory, relative paths will cease to work, however. Work around this by making all of the paths to programs that should undergo testing absolute. Besides "realpath", we also have to use "type -p" to support programs in $PATH. As a side effect, this fixes specifying these programs as symlinks for out-of-tree builds: Before, you would have to create two symlinks, one in the build and one in the source tree (the first one for common.config to find, the second one for the iotest to use). Now it is sufficient to create one in the build tree because common.config will resolve it. Reported-by: Kevin Wolf Signed-off-by: Max Reitz Message-id: 20170702150510.23276-2-mreitz@redhat.com Reviewed-by: Eric Blake Tested-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/common.config | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/qemu-iotests/common.config b/tests/qemu-iotests/common.c= onfig index d1b45f5..e0883a0 100644 --- a/tests/qemu-iotests/common.config +++ b/tests/qemu-iotests/common.config @@ -103,6 +103,17 @@ if [ -z "$QEMU_VXHS_PROG" ]; then export QEMU_VXHS_PROG=3D"`set_prog_path qnio_server`" fi =20 +export QEMU_PROG=3D$(realpath -- "$(type -p "$QEMU_PROG")") +export QEMU_IMG_PROG=3D$(realpath -- "$(type -p "$QEMU_IMG_PROG")") +export QEMU_IO_PROG=3D$(realpath -- "$(type -p "$QEMU_IO_PROG")") +export QEMU_NBD_PROG=3D$(realpath -- "$(type -p "$QEMU_NBD_PROG")") + +# This program is not built as part of qemu but (possibly) provided by the +# system, so it may not be present at all +if [ -n "$QEMU_VXHS_PROG" ]; then + export QEMU_VXHS_PROG=3D$(realpath -- "$(type -p "$QEMU_VXHS_PROG")") +fi + _qemu_wrapper() { ( --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451145639853.9941481382631; Fri, 7 Jul 2017 11:12:25 -0700 (PDT) Received: from localhost ([::1]:58062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXjo-0002W5-9z for importer@patchew.org; Fri, 07 Jul 2017 14:12:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmt-00074s-Ne for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWms-0001L9-4M for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54962) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmm-0001Ib-5K; Fri, 07 Jul 2017 13:11:20 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2C3EC7F3F1; Fri, 7 Jul 2017 17:11:19 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17A2562924; Fri, 7 Jul 2017 17:11:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2C3EC7F3F1 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2C3EC7F3F1 From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:54 +0200 Message-Id: <1499447335-6125-100-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 07 Jul 2017 17:11:19 +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] [PULL 099/100] iotests: Add test for colon handling 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-devel@nongnu.org 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" From: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Max Reitz Message-id: 20170702150510.23276-3-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/126 | 105 +++++++++++++++++++++++++++++++++++++++++= ++++ tests/qemu-iotests/126.out | 23 ++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 129 insertions(+) create mode 100755 tests/qemu-iotests/126 create mode 100644 tests/qemu-iotests/126.out diff --git a/tests/qemu-iotests/126 b/tests/qemu-iotests/126 new file mode 100755 index 0000000..a2d4d6c --- /dev/null +++ b/tests/qemu-iotests/126 @@ -0,0 +1,105 @@ +#!/bin/bash +# +# Tests handling of colons in filenames (which may be confused with protoc= ol +# prefixes) +# +# Copyright (C) 2017 Red Hat, Inc. +# +# 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=3Dmreitz@redhat.com + +seq=3D"$(basename $0)" +echo "QA output created by $seq" + +here=3D"$PWD" +status=3D1 # failure is the default! + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +# Needs backing file support +_supported_fmt qcow qcow2 qed vmdk +# This is the default protocol (and we want to test the difference between +# colons which separate a protocol prefix from the rest and colons which a= re +# just part of the filename, so we cannot test protocols which require a p= refix) +_supported_proto file +_supported_os Linux + +echo +echo '=3D=3D=3D Testing plain files =3D=3D=3D' +echo + +# A colon after a slash is not a protocol prefix separator +TEST_IMG=3D"$TEST_DIR/a:b.$IMGFMT" _make_test_img 64M +_rm_test_img "$TEST_DIR/a:b.$IMGFMT" + +# But if you want to be really sure, you can do this +TEST_IMG=3D"file:$TEST_DIR/a:b.$IMGFMT" _make_test_img 64M +_rm_test_img "$TEST_DIR/a:b.$IMGFMT" + + +echo +echo '=3D=3D=3D Testing relative backing filename resolution =3D=3D=3D' +echo + +BASE_IMG=3D"$TEST_DIR/image:base.$IMGFMT" +TOP_IMG=3D"$TEST_DIR/image:top.$IMGFMT" + +TEST_IMG=3D$BASE_IMG _make_test_img 64M +TEST_IMG=3D$TOP_IMG _make_test_img -b ./image:base.$IMGFMT + +# The default cluster size depends on the image format +TEST_IMG=3D$TOP_IMG _img_info | grep -v 'cluster_size' + +_rm_test_img "$BASE_IMG" +_rm_test_img "$TOP_IMG" + + +# Do another test where we access both top and base without any slash in t= hem +echo +pushd "$TEST_DIR" >/dev/null + +BASE_IMG=3D"base.$IMGFMT" +TOP_IMG=3D"file:image:top.$IMGFMT" + +TEST_IMG=3D$BASE_IMG _make_test_img 64M +TEST_IMG=3D$TOP_IMG _make_test_img -b "$BASE_IMG" + +TEST_IMG=3D$TOP_IMG _img_info | grep -v 'cluster_size' + +_rm_test_img "$BASE_IMG" +_rm_test_img "image:top.$IMGFMT" + +popd >/dev/null + +# Note that we could also do the same test with BASE_IMG=3Dfile:image:base= .$IMGFMT +# -- but behavior for that case is a bit strange. Protocol-prefixed paths = are +# in a sense always absolute paths, so such paths will never be combined w= ith +# the path of the overlay. But since "image:base.$IMGFMT" is actually a +# relative path, it will always be evaluated relative to qemu's CWD (but n= ot +# relative to the overlay!). While this is more or less intended, it is st= ill +# pretty strange and thus not something that is tested here. +# (The root of the issue is the use of a relative path with a protocol pre= fix. +# This may always give you weird results because in one sense, qemu consi= ders +# such paths absolute, whereas in another, they are still relative.) + + +# success, all done +echo '*** done' +rm -f $seq.full +status=3D0 diff --git a/tests/qemu-iotests/126.out b/tests/qemu-iotests/126.out new file mode 100644 index 0000000..50d7308 --- /dev/null +++ b/tests/qemu-iotests/126.out @@ -0,0 +1,23 @@ +QA output created by 126 + +=3D=3D=3D Testing plain files =3D=3D=3D + +Formatting 'TEST_DIR/a:b.IMGFMT', fmt=3DIMGFMT size=3D67108864 +Formatting 'TEST_DIR/a:b.IMGFMT', fmt=3DIMGFMT size=3D67108864 + +=3D=3D=3D Testing relative backing filename resolution =3D=3D=3D + +Formatting 'TEST_DIR/image:base.IMGFMT', fmt=3DIMGFMT size=3D67108864 +Formatting 'TEST_DIR/image:top.IMGFMT', fmt=3DIMGFMT size=3D67108864 backi= ng_file=3D./image:base.IMGFMT +image: TEST_DIR/image:top.IMGFMT +file format: IMGFMT +virtual size: 64M (67108864 bytes) +backing file: ./image:base.IMGFMT (actual path: TEST_DIR/./image:base.IMGF= MT) + +Formatting 'base.IMGFMT', fmt=3DIMGFMT size=3D67108864 +Formatting 'file:image:top.IMGFMT', fmt=3DIMGFMT size=3D67108864 backing_f= ile=3Dbase.IMGFMT +image: ./image:top.IMGFMT +file format: IMGFMT +virtual size: 64M (67108864 bytes) +backing file: base.IMGFMT (actual path: ./base.IMGFMT) +*** done diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group index 7d86715..40bef99 100644 --- a/tests/qemu-iotests/group +++ b/tests/qemu-iotests/group @@ -130,6 +130,7 @@ 122 rw auto 123 rw auto quick 124 rw auto backing +126 rw auto backing 128 rw auto quick 129 rw auto quick 130 rw auto quick --=20 1.8.3.1 From nobody Wed Apr 16 07:35:56 2025 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.zohomail.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 1499451055867751.5144773824497; Fri, 7 Jul 2017 11:10:55 -0700 (PDT) Received: from localhost ([::1]:58056 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTXiQ-00017B-CZ for importer@patchew.org; Fri, 07 Jul 2017 14:10:54 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43851) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dTWmv-00076R-5B for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dTWms-0001LR-Mo for qemu-devel@nongnu.org; Fri, 07 Jul 2017 13:11:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48714) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dTWmn-0001J7-AA; Fri, 07 Jul 2017 13:11:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 67003C04D29A; Fri, 7 Jul 2017 17:11:20 +0000 (UTC) Received: from noname.redhat.com (ovpn-117-34.ams2.redhat.com [10.36.117.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75FD861F23; Fri, 7 Jul 2017 17:11:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 67003C04D29A Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=kwolf@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 67003C04D29A From: Kevin Wolf To: qemu-block@nongnu.org Date: Fri, 7 Jul 2017 19:08:55 +0200 Message-Id: <1499447335-6125-101-git-send-email-kwolf@redhat.com> In-Reply-To: <1499447335-6125-1-git-send-email-kwolf@redhat.com> References: <1499447335-6125-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 07 Jul 2017 17:11:20 +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] [PULL 100/100] tests: Avoid non-portable 'echo -ARG' 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-devel@nongnu.org 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" From: Eric Blake POSIX says that backslashes in the arguments to 'echo', as well as any use of 'echo -n' and 'echo -e', are non-portable; it recommends people should favor 'printf' instead. This is definitely true where we do not control which shell is running (such as in makefile snippets or in documentation examples). But even for scripts where we require bash (and therefore, where echo does what we want by default), it is still possible to use 'shopt -s xpg_echo' to change bash's behavior of echo. And setting a good example never hurts when we are not sure if a snippet will be copied from a bash-only script to a general shell script (although I don't change the use of non-portable \e for ESC when we know the running shell is bash). Replace 'echo -n "..."' with 'printf %s "..."', and 'echo -e "..."' with 'printf %b "...\n"', with the optimization that the %s/%b argument can be omitted if the string being printed is a strict literal with no '%', '$', or '`' (we could technically also make this optimization when there are $ or `` substitutions but where we can prove their results will not be problematic, but proving that such substitutions are safe makes the patch less trivial compared to just being consistent). In the qemu-iotests check script, fix unusual shell quoting that would result in word-splitting if 'date' outputs a space. In test 051, take an opportunity to shorten the line. In test 068, get rid of a pointless second invocation of bash. CC: qemu-trivial@nongnu.org Signed-off-by: Eric Blake Message-id: 20170703180950.9895-1-eblake@redhat.com Signed-off-by: Max Reitz --- qemu-options.hx | 4 ++-- tests/multiboot/run_test.sh | 10 +++++----- tests/qemu-iotests/051 | 7 ++++--- tests/qemu-iotests/068 | 2 +- tests/qemu-iotests/142 | 48 ++++++++++++++++++++++-------------------= ---- tests/qemu-iotests/171 | 14 ++++++------- tests/qemu-iotests/check | 18 ++++++++--------- tests/rocker/all | 10 +++++----- tests/tcg/cris/Makefile | 8 ++++---- 9 files changed, 61 insertions(+), 60 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index ddab656..b465fea 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4368,7 +4368,7 @@ The simplest (insecure) usage is to provide the secre= t inline =20 The simplest secure usage is to provide the secret via a file =20 - # echo -n "letmein" > mypasswd.txt + # printf "letmein" > mypasswd.txt # $QEMU -object secret,id=3Dsec0,file=3Dmypasswd.txt,format=3Draw =20 For greater security, AES-256-CBC should be used. To illustrate usage, @@ -4396,7 +4396,7 @@ telling openssl to base64 encode the result, but it c= ould be left as raw bytes if desired. =20 @example - # SECRET=3D$(echo -n "letmein" | + # SECRET=3D$(printf "letmein" | openssl enc -aes-256-cbc -a -K $KEY -iv $IV) @end example =20 diff --git a/tests/multiboot/run_test.sh b/tests/multiboot/run_test.sh index 78d7edf..c8f3da8 100755 --- a/tests/multiboot/run_test.sh +++ b/tests/multiboot/run_test.sh @@ -26,7 +26,7 @@ run_qemu() { local kernel=3D$1 shift =20 - echo -e "\n\n=3D=3D=3D Running test case: $kernel $@ =3D=3D=3D\n" >> t= est.log + printf %b "\n\n=3D=3D=3D Running test case: $kernel $@ =3D=3D=3D\n\n" = >> test.log =20 $QEMU \ -kernel $kernel \ @@ -68,21 +68,21 @@ for t in mmap modules; do pass=3D1 =20 if [ $debugexit !=3D 1 ]; then - echo -e "\e[31m ?? \e[0m $t (no debugexit used, exit code $ret)" + printf %b "\e[31m ?? \e[0m $t (no debugexit used, exit code $ret)\= n" pass=3D0 elif [ $ret !=3D 0 ]; then - echo -e "\e[31mFAIL\e[0m $t (exit code $ret)" + printf %b "\e[31mFAIL\e[0m $t (exit code $ret)\n" pass=3D0 fi =20 if ! diff $t.out test.log > /dev/null 2>&1; then - echo -e "\e[31mFAIL\e[0m $t (output difference)" + printf %b "\e[31mFAIL\e[0m $t (output difference)\n" diff -u $t.out test.log pass=3D0 fi =20 if [ $pass =3D=3D 1 ]; then - echo -e "\e[32mPASS\e[0m $t" + printf %b "\e[32mPASS\e[0m $t\n" fi =20 done diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051 index 26c29de..c8cfc76 100755 --- a/tests/qemu-iotests/051 +++ b/tests/qemu-iotests/051 @@ -217,7 +217,7 @@ run_qemu -drive driver=3Dnull-co,cache=3Dinvalid_value # Test 142 checks the direct=3Don cases =20 for cache in writeback writethrough unsafe invalid_value; do - echo -e "info block\ninfo block file\ninfo block backing\ninfo block b= acking-file" | \ + printf "info block %s\n" '' file backing backing-file | \ run_qemu -drive file=3D"$TEST_IMG",cache=3D$cache,backing.file.filenam= e=3D"$TEST_IMG.base",backing.cache.no-flush=3Don,backing.node-name=3Dbackin= g,backing.file.node-name=3Dbacking-file,file.node-name=3Dfile,if=3Dnone,id= =3D$device_id -nodefaults done =20 @@ -325,8 +325,9 @@ echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_= qemu -drive file=3D"$TEST_I =20 $QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io =20 -echo -e "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id" | r= un_qemu -drive file=3D"$TEST_IMG",snapshot=3Don,if=3Dnone,id=3D$device_id\ - | _= filter_qemu_io +printf %b "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id\n"= | + run_qemu -drive file=3D"$TEST_IMG",snapshot=3Don,if=3Dnone,id=3D$devic= e_id | + _filter_qemu_io =20 $QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io =20 diff --git a/tests/qemu-iotests/068 b/tests/qemu-iotests/068 index 3801b65..cfa0f2a 100755 --- a/tests/qemu-iotests/068 +++ b/tests/qemu-iotests/068 @@ -76,7 +76,7 @@ for extra_args in \ _make_test_img $IMG_SIZE =20 # Give qemu some time to boot before saving the VM state - bash -c 'sleep 1; echo -e "savevm 0\nquit"' | _qemu $extra_args + { sleep 1; printf "savevm 0\nquit\n"; } | _qemu $extra_args # Now try to continue from that VM state (this should just work) echo quit | _qemu $extra_args -loadvm 0 done diff --git a/tests/qemu-iotests/142 b/tests/qemu-iotests/142 index 9a5b713..1639c83 100755 --- a/tests/qemu-iotests/142 +++ b/tests/qemu-iotests/142 @@ -94,36 +94,36 @@ function check_cache_all() # cache.direct is supposed to be inherited by both bs->file and # bs->backing =20 - echo -e "cache.direct=3Don on none0" + printf "cache.direct=3Don on none0\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.direct=3Don |= grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" - echo -e "\ncache.direct=3Don on file" + printf "\ncache.direct=3Don on file\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.direct= =3Don | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" - echo -e "\ncache.direct=3Don on backing" + printf "\ncache.direct=3Don on backing\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.direc= t=3Don | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" - echo -e "\ncache.direct=3Don on backing-file" + printf "\ncache.direct=3Don on backing-file\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.= direct=3Don | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" =20 # cache.writeback is supposed to be inherited by bs->backing; bs->file # always gets cache.writeback=3Don =20 - echo -e "\n\ncache.writeback=3Doff on none0" + printf "\n\ncache.writeback=3Doff on none0\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=3Do= ff | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.writeback=3Doff on file" + printf "\ncache.writeback=3Doff on file\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writebac= k=3Doff | grep -e "doesn't" -e "does not" - echo -e "\ncache.writeback=3Doff on backing" + printf "\ncache.writeback=3Doff on backing\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.write= back=3Doff | grep -e "doesn't" -e "does not" - echo -e "\ncache.writeback=3Doff on backing-file" + printf "\ncache.writeback=3Doff on backing-file\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.= writeback=3Doff | grep -e "doesn't" -e "does not" =20 # cache.no-flush is supposed to be inherited by both bs->file and bs->= backing =20 - echo -e "\n\ncache.no-flush=3Don on none0" + printf "\n\ncache.no-flush=3Don on none0\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.no-flush=3Don= | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.no-flush=3Don on file" + printf "\ncache.no-flush=3Don on file\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.no-flush= =3Don | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.no-flush=3Don on backing" + printf "\ncache.no-flush=3Don on backing\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.no-fl= ush=3Don | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.no-flush=3Don on backing-file" + printf "\ncache.no-flush=3Don on backing-file\n" echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.= no-flush=3Don | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" } =20 @@ -236,35 +236,35 @@ function check_cache_all_separate() { # Check cache.direct =20 - echo -e "cache.direct=3Don on blk" + printf "cache.direct=3Don on blk\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -dri= ve "$drv_file" -drive "$drv_img",cache.direct=3Don | grep -e "Cache" -e "[C= c]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.direct=3Don on file" + printf "\ncache.direct=3Don on file\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -dri= ve "$drv_file",cache.direct=3Don -drive "$drv_img" | grep -e "Cache" -e "[C= c]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.direct=3Don on backing" + printf "\ncache.direct=3Don on backing\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cach= e.direct=3Don -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[C= c]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.direct=3Don on backing-file" + printf "\ncache.direct=3Don on backing-file\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.direct=3Don -dr= ive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[C= c]annot\|[Cc]ould not\|[Cc]an't" =20 # Check cache.writeback =20 - echo -e "\n\ncache.writeback=3Doff on blk" + printf "\n\ncache.writeback=3Doff on blk\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -dri= ve "$drv_file" -drive "$drv_img",cache.writeback=3Doff | grep -e "Cache" -e= "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.writeback=3Doff on file" + printf "\ncache.writeback=3Doff on file\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -dri= ve "$drv_file",cache.writeback=3Doff -drive "$drv_img" | grep -e "Cache" -e= "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.writeback=3Doff on backing" + printf "\ncache.writeback=3Doff on backing\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cach= e.writeback=3Doff -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e= "[Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.writeback=3Doff on backing-file" + printf "\ncache.writeback=3Doff on backing-file\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.writeback=3Doff= -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e= "[Cc]annot\|[Cc]ould not\|[Cc]an't" =20 # Check cache.no-flush =20 - echo -e "\n\ncache.no-flush=3Don on blk" + printf "\n\ncache.no-flush=3Don on blk\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -dri= ve "$drv_file" -drive "$drv_img",cache.no-flush=3Don | grep -e "Cache" -e "= [Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.no-flush=3Don on file" + printf "\ncache.no-flush=3Don on file\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -dri= ve "$drv_file",cache.no-flush=3Don -drive "$drv_img" | grep -e "Cache" -e "= [Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.no-flush=3Don on backing" + printf "\ncache.no-flush=3Don on backing\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cach= e.no-flush=3Don -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "= [Cc]annot\|[Cc]ould not\|[Cc]an't" - echo -e "\ncache.no-flush=3Don on backing-file" + printf "\ncache.no-flush=3Don on backing-file\n" echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.no-flush=3Don -= drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "= [Cc]annot\|[Cc]ould not\|[Cc]an't" } =20 diff --git a/tests/qemu-iotests/171 b/tests/qemu-iotests/171 index 257be10..bcfaaf1 100755 --- a/tests/qemu-iotests/171 +++ b/tests/qemu-iotests/171 @@ -45,15 +45,15 @@ _supported_os Linux =20 # Create JSON with options img_json() { - echo -n 'json:{"driver":"raw", ' - echo -n "\"offset\":\"$img_offset\", " + printf %s 'json:{"driver":"raw", ' + printf %s "\"offset\":\"$img_offset\", " if [ "$img_size" -ne -1 ] ; then - echo -n "\"size\":\"$img_size\", " + printf %s "\"size\":\"$img_size\", " fi - echo -n '"file": {' - echo -n '"driver":"file", ' - echo -n "\"filename\":\"$TEST_IMG\" " - echo -n "} }" + printf %s '"file": {' + printf %s '"driver":"file", ' + printf %s "\"filename\":\"$TEST_IMG\" " + printf %s "} }" } =20 do_general_test() { diff --git a/tests/qemu-iotests/check b/tests/qemu-iotests/check index 4b1c674..9ded37c 100755 --- a/tests/qemu-iotests/check +++ b/tests/qemu-iotests/check @@ -141,7 +141,7 @@ _wallclock() _timestamp() { now=3D`date "+%T"` - echo -n " [$now]" + printf %s " [$now]" } =20 _wrapup() @@ -255,7 +255,7 @@ seq=3D"check" for seq in $list do err=3Dfalse - echo -n "$seq" + printf %s "$seq" if [ -n "$TESTS_REMAINING_LOG" ] ; then sed -e "s/$seq//" -e 's/ / /' -e 's/^ *//' $TESTS_REMAINING_LOG >= $TESTS_REMAINING_LOG.tmp mv $TESTS_REMAINING_LOG.tmp $TESTS_REMAINING_LOG @@ -281,9 +281,9 @@ do rm -f $seq.out.bad lasttime=3D`sed -n -e "/^$seq /s/.* //p" <$TIMESTAMP_FILE` if [ "X$lasttime" !=3D X ]; then - echo -n " ${lasttime}s ..." + printf %s " ${lasttime}s ..." else - echo -n " " # prettier output with timestamp= s. + printf " " # prettier output with timestamps. fi rm -f core $seq.notrun =20 @@ -291,7 +291,7 @@ do echo "$seq" > "${TEST_DIR}"/check.sts =20 start=3D`_wallclock` - $timestamp && echo -n " ["`date "+%T"`"]" + $timestamp && printf %s " [$(date "+%T")]" =20 if [ "$(head -n 1 "$source_iotests/$seq")" =3D=3D "#!/usr/bin/env = python" ]; then run_command=3D"$PYTHON $seq" @@ -314,21 +314,21 @@ do =20 if [ -f core ] then - echo -n " [dumped core]" + printf " [dumped core]" mv core $seq.core err=3Dtrue fi =20 if [ -f $seq.notrun ] then - $timestamp || echo -n " [not run] " - $timestamp && echo " [not run]" && echo -n " $seq -- " + $timestamp || printf " [not run] " + $timestamp && echo " [not run]" && printf %s " $seq -- " cat $seq.notrun notrun=3D"$notrun $seq" else if [ $sts -ne 0 ] then - echo -n " [failed, exit status $sts]" + printf %s " [failed, exit status $sts]" err=3Dtrue fi =20 diff --git a/tests/rocker/all b/tests/rocker/all index d5ae963..3f9b786 100755 --- a/tests/rocker/all +++ b/tests/rocker/all @@ -1,19 +1,19 @@ -echo -n "Running port test... " +printf "Running port test... " ./port if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi =20 -echo -n "Running bridge test... " +printf "Running bridge test... " ./bridge if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi =20 -echo -n "Running bridge STP test... " +printf "Running bridge STP test... " ./bridge-stp if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi =20 -echo -n "Running bridge VLAN test... " +printf "Running bridge VLAN test... " ./bridge-vlan if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi =20 -echo -n "Running bridge VLAN STP test... " +printf "Running bridge VLAN STP test... " ./bridge-vlan-stp if [ $? -eq 0 ]; then echo "pass"; else echo "FAILED"; exit 1; fi diff --git a/tests/tcg/cris/Makefile b/tests/tcg/cris/Makefile index 6b3dba4..664b30c 100644 --- a/tests/tcg/cris/Makefile +++ b/tests/tcg/cris/Makefile @@ -150,17 +150,17 @@ check_addcv17.tst: crtv10.o sysv10.o build: $(CRT) $(SYS) $(TESTCASES) =20 check: $(CRT) $(SYS) $(TESTCASES) - @echo -e "\nQEMU simulator." + @printf "\nQEMU simulator.\n" for case in $(TESTCASES); do \ - echo -n "$$case "; \ + printf %s "$$case "; \ SIMARGS=3D; \ case $$case in *v17*) SIMARGS=3D"-cpu crisv17";; esac; \ $(SIM) $$SIMARGS ./$$case; \ done check-g: $(CRT) $(SYS) $(TESTCASES) - @echo -e "\nGDB simulator." + @printf "\nGDB simulator.\n" @for case in $(TESTCASES); do \ - echo -n "$$case "; \ + printf %s "$$case "; \ $(SIMG) $$case; \ done =20 --=20 1.8.3.1