From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727324288670.9440451004546; Mon, 11 Jun 2018 07:28:44 -0700 (PDT) Received: from localhost ([::1]:49152 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNoJ-0005qb-Dt for importer@patchew.org; Mon, 11 Jun 2018 10:28:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNm0-0004AC-8u for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNlz-0001XM-3v for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:20 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54472 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNlv-0001WB-S4; Mon, 11 Jun 2018 10:26:15 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7124B4022905; Mon, 11 Jun 2018 14:26:15 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 19FF42028672; Mon, 11 Jun 2018 14:26:14 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:43 +0200 Message-Id: <20180611142611.6609-2-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:15 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:15 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 01/29] block/file-posix: Pass FD to locking helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" raw_apply_lock_bytes() and raw_check_lock_bytes() currently take a BDRVRawState *, but they only use the lock_fd field. During image creation, we do not have a BDRVRawState, but we do have an FD; so if we want to reuse the functions there, we should modify them to receive only the FD. Signed-off-by: Max Reitz Reviewed-by: Fam Zheng Message-id: 20180509215336.31304-2-mreitz@redhat.com Signed-off-by: Max Reitz --- block/file-posix.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 513d371bb1..7583bbfbb3 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -643,7 +643,7 @@ typedef enum { * file; if @unlock =3D=3D true, also unlock the unneeded bytes. * @shared_perm_lock_bits is the mask of all permissions that are NOT shar= ed. */ -static int raw_apply_lock_bytes(BDRVRawState *s, +static int raw_apply_lock_bytes(int fd, uint64_t perm_lock_bits, uint64_t shared_perm_lock_bits, bool unlock, Error **errp) @@ -654,13 +654,13 @@ static int raw_apply_lock_bytes(BDRVRawState *s, PERM_FOREACH(i) { int off =3D RAW_LOCK_PERM_BASE + i; if (perm_lock_bits & (1ULL << i)) { - ret =3D qemu_lock_fd(s->lock_fd, off, 1, false); + ret =3D qemu_lock_fd(fd, off, 1, false); if (ret) { error_setg(errp, "Failed to lock byte %d", off); return ret; } } else if (unlock) { - ret =3D qemu_unlock_fd(s->lock_fd, off, 1); + ret =3D qemu_unlock_fd(fd, off, 1); if (ret) { error_setg(errp, "Failed to unlock byte %d", off); return ret; @@ -670,13 +670,13 @@ static int raw_apply_lock_bytes(BDRVRawState *s, PERM_FOREACH(i) { int off =3D RAW_LOCK_SHARED_BASE + i; if (shared_perm_lock_bits & (1ULL << i)) { - ret =3D qemu_lock_fd(s->lock_fd, off, 1, false); + ret =3D qemu_lock_fd(fd, off, 1, false); if (ret) { error_setg(errp, "Failed to lock byte %d", off); return ret; } } else if (unlock) { - ret =3D qemu_unlock_fd(s->lock_fd, off, 1); + ret =3D qemu_unlock_fd(fd, off, 1); if (ret) { error_setg(errp, "Failed to unlock byte %d", off); return ret; @@ -687,8 +687,7 @@ static int raw_apply_lock_bytes(BDRVRawState *s, } =20 /* Check "unshared" bytes implied by @perm and ~@shared_perm in the file. = */ -static int raw_check_lock_bytes(BDRVRawState *s, - uint64_t perm, uint64_t shared_perm, +static int raw_check_lock_bytes(int fd, uint64_t perm, uint64_t shared_per= m, Error **errp) { int ret; @@ -698,7 +697,7 @@ static int raw_check_lock_bytes(BDRVRawState *s, int off =3D RAW_LOCK_SHARED_BASE + i; uint64_t p =3D 1ULL << i; if (perm & p) { - ret =3D qemu_lock_fd_test(s->lock_fd, off, 1, true); + ret =3D qemu_lock_fd_test(fd, off, 1, true); if (ret) { char *perm_name =3D bdrv_perm_names(p); error_setg(errp, @@ -715,7 +714,7 @@ static int raw_check_lock_bytes(BDRVRawState *s, int off =3D RAW_LOCK_PERM_BASE + i; uint64_t p =3D 1ULL << i; if (!(shared_perm & p)) { - ret =3D qemu_lock_fd_test(s->lock_fd, off, 1, true); + ret =3D qemu_lock_fd_test(fd, off, 1, true); if (ret) { char *perm_name =3D bdrv_perm_names(p); error_setg(errp, @@ -752,11 +751,11 @@ static int raw_handle_perm_lock(BlockDriverState *bs, =20 switch (op) { case RAW_PL_PREPARE: - ret =3D raw_apply_lock_bytes(s, s->perm | new_perm, + ret =3D raw_apply_lock_bytes(s->lock_fd, s->perm | new_perm, ~s->shared_perm | ~new_shared, false, errp); if (!ret) { - ret =3D raw_check_lock_bytes(s, new_perm, new_shared, errp); + ret =3D raw_check_lock_bytes(s->lock_fd, new_perm, new_shared,= errp); if (!ret) { return 0; } @@ -764,7 +763,8 @@ static int raw_handle_perm_lock(BlockDriverState *bs, op =3D RAW_PL_ABORT; /* fall through to unlock bytes. */ case RAW_PL_ABORT: - raw_apply_lock_bytes(s, s->perm, ~s->shared_perm, true, &local_err= ); + raw_apply_lock_bytes(s->lock_fd, s->perm, ~s->shared_perm, + true, &local_err); if (local_err) { /* Theoretically the above call only unlocks bytes and it cann= ot * fail. Something weird happened, report it. @@ -773,7 +773,8 @@ static int raw_handle_perm_lock(BlockDriverState *bs, } break; case RAW_PL_COMMIT: - raw_apply_lock_bytes(s, new_perm, ~new_shared, true, &local_err); + raw_apply_lock_bytes(s->lock_fd, new_perm, ~new_shared, + true, &local_err); if (local_err) { /* Theoretically the above call only unlocks bytes and it cann= ot * fail. Something weird happened, report it. --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727310630661.0857375009158; Mon, 11 Jun 2018 07:28:30 -0700 (PDT) Received: from localhost ([::1]:49150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNo3-0005cJ-QY for importer@patchew.org; Mon, 11 Jun 2018 10:28:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52719) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNm1-0004Az-ET for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNm0-0001Xk-5u for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:21 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54476 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNlx-0001Wi-O2; Mon, 11 Jun 2018 10:26:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5870D4022905; Mon, 11 Jun 2018 14:26:17 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 01787202698A; Mon, 11 Jun 2018 14:26:16 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:44 +0200 Message-Id: <20180611142611.6609-3-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:17 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 02/29] block/file-posix: File locking during creation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" When creating a file, we should take the WRITE and RESIZE permissions. We do not need either for the creation itself, but we do need them for clearing and resizing it. So we can take the proper permissions by replacing O_TRUNC with an explicit truncation to 0, and by taking the appropriate file locks between those two steps. Signed-off-by: Max Reitz Message-id: 20180509215336.31304-3-mreitz@redhat.com Reviewed-by: Fam Zheng Signed-off-by: Max Reitz --- block/file-posix.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 7583bbfbb3..07bb061fe4 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2076,6 +2076,7 @@ static int raw_co_create(BlockdevCreateOptions *optio= ns, Error **errp) { BlockdevCreateOptionsFile *file_opts; int fd; + int perm, shared; int result =3D 0; =20 /* Validate options and set default values */ @@ -2090,14 +2091,44 @@ static int raw_co_create(BlockdevCreateOptions *opt= ions, Error **errp) } =20 /* Create file */ - fd =3D qemu_open(file_opts->filename, O_RDWR | O_CREAT | O_TRUNC | O_B= INARY, - 0644); + fd =3D qemu_open(file_opts->filename, O_RDWR | O_CREAT | O_BINARY, 064= 4); if (fd < 0) { result =3D -errno; error_setg_errno(errp, -result, "Could not create file"); goto out; } =20 + /* Take permissions: We want to discard everything, so we need + * BLK_PERM_WRITE; and truncation to the desired size requires + * BLK_PERM_RESIZE. + * On the other hand, we cannot share the RESIZE permission + * because we promise that after this function, the file has the + * size given in the options. If someone else were to resize it + * concurrently, we could not guarantee that. + * Note that after this function, we can no longer guarantee that + * the file is not touched by a third party, so it may be resized + * then. */ + perm =3D BLK_PERM_WRITE | BLK_PERM_RESIZE; + shared =3D BLK_PERM_ALL & ~BLK_PERM_RESIZE; + + /* Step one: Take locks */ + result =3D raw_apply_lock_bytes(fd, perm, shared, false, errp); + if (result < 0) { + goto out_close; + } + + /* Step two: Check that nobody else has taken conflicting locks */ + result =3D raw_check_lock_bytes(fd, perm, shared, errp); + if (result < 0) { + goto out_close; + } + + /* Clear the file by truncating it to 0 */ + result =3D raw_regular_truncate(fd, 0, PREALLOC_MODE_OFF, errp); + if (result < 0) { + goto out_close; + } + if (file_opts->nocow) { #ifdef __linux__ /* Set NOCOW flag to solve performance issue on fs like btrfs. @@ -2113,6 +2144,8 @@ static int raw_co_create(BlockdevCreateOptions *optio= ns, Error **errp) #endif } =20 + /* Resize and potentially preallocate the file to the desired + * final size */ result =3D raw_regular_truncate(fd, file_opts->size, file_opts->preall= ocation, errp); if (result < 0) { --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727708098724.5784654619214; Mon, 11 Jun 2018 07:35:08 -0700 (PDT) Received: from localhost ([::1]:49185 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNuV-0002P2-BS for importer@patchew.org; Mon, 11 Jun 2018 10:35:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmB-0004KT-0g for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNm9-0001cm-S9 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:31 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33500 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNlz-0001XS-Ll; Mon, 11 Jun 2018 10:26:19 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FEA8859A6; Mon, 11 Jun 2018 14:26:19 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DF123202698A; Mon, 11 Jun 2018 14:26:18 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:45 +0200 Message-Id: <20180611142611.6609-4-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:19 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 03/29] iotests: Add creation test to 153 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This patch adds a test case to 153 which tries to overwrite an image (using qemu-img create) while it is in use. Without the original user explicitly sharing the necessary permissions (writing and truncation), this should not be allowed. Signed-off-by: Max Reitz Reviewed-by: Fam Zheng Message-id: 20180509215336.31304-4-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/153 | 18 ++++++++++++++++++ tests/qemu-iotests/153.out | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153 index ec508c758f..673813cd39 100755 --- a/tests/qemu-iotests/153 +++ b/tests/qemu-iotests/153 @@ -137,6 +137,24 @@ for opts1 in "" "read-only=3Don" "read-only=3Don,force= -share=3Don"; do _run_cmd $QEMU_IMG dd $L if=3D"${TEST_IMG}" of=3D"${TEST_= IMG}.convert" bs=3D512 count=3D1 _run_cmd $QEMU_IMG bench $L -c 1 "${TEST_IMG}" _run_cmd $QEMU_IMG bench $L -w -c 1 "${TEST_IMG}" + + # qemu-img create does not support -U + if [ -z "$L" ]; then + _run_cmd $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" \ + -b ${TEST_IMG}.base + # Read the file format. It used to be the case that + # file-posix simply truncated the file, but the qcow2 + # driver then failed to format it because it was unable + # to acquire the necessary WRITE permission. However, the + # truncation was already wrong, and the whole process + # resulted in the file being completely empty and thus its + # format would be detected to be raw. + # So we read it here to see that creation either completed + # successfully (thus the format is qcow2) or it aborted + # before the file was changed at all (thus the format stays + # qcow2). + _img_info -U | grep 'file format' + fi done _send_qemu_cmd $h "{ 'execute': 'quit', }" "" echo diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out index 2510762ba1..3492ba7a29 100644 --- a/tests/qemu-iotests/153.out +++ b/tests/qemu-iotests/153.out @@ -92,6 +92,11 @@ _qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock Is another process using the image? =20 +_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base +qemu-img: TEST_DIR/t.qcow2: Failed to get "write" lock +Is another process using the image? +file format: IMGFMT + =3D=3D Running utility commands -U =3D=3D =20 _qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2 @@ -209,6 +214,11 @@ _qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock Is another process using the image? =20 +_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base +qemu-img: TEST_DIR/t.qcow2: Failed to get "write" lock +Is another process using the image? +file format: IMGFMT + =3D=3D Running utility commands -U =3D=3D =20 _qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2 @@ -309,6 +319,9 @@ _qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2 =20 _qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2 =20 +_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base +file format: IMGFMT + =3D=3D Running utility commands -U =3D=3D =20 _qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152872750566770.73400696123815; Mon, 11 Jun 2018 07:31:45 -0700 (PDT) Received: from localhost ([::1]:49171 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNrE-0008Kr-VM for importer@patchew.org; Mon, 11 Jun 2018 10:31:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNm6-0004Fw-3a for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNm3-0001ZO-QZ for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:26 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33508 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNm1-0001YJ-I8; Mon, 11 Jun 2018 10:26:21 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 25294859A6; Mon, 11 Jun 2018 14:26:21 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C206E83B9C; Mon, 11 Jun 2018 14:26:20 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:46 +0200 Message-Id: <20180611142611.6609-5-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:21 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 04/29] qemu-img: Amendment support implies create_opts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Instead of checking whether a driver has a non-NULL create_opts we should check whether it supports image amendment in the first place. If it does, it must have create_opts. On the other hand, if it does not have create_opts (so it does not support amendment either), the error message "does not support any options" is a bit useless. Stating clearly that the driver has no amendment support whatsoever is probably better. Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake Message-id: 20180509210023.20283-2-mreitz@redhat.com Signed-off-by: Max Reitz --- qemu-img.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 75f1610aa0..0be11b3852 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3789,13 +3789,16 @@ static int img_amend(int argc, char **argv) goto out; } =20 - if (!bs->drv->create_opts) { - error_report("Format driver '%s' does not support any options to a= mend", + if (!bs->drv->bdrv_amend_options) { + error_report("Format driver '%s' does not support option amendment= ", fmt); ret =3D -1; goto out; } =20 + /* Every driver supporting amendment must have create_opts */ + assert(bs->drv->create_opts); + create_opts =3D qemu_opts_append(create_opts, bs->drv->create_opts); opts =3D qemu_opts_create(create_opts, NULL, 0, &error_abort); qemu_opts_do_parse(opts, options, NULL, &err); --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727533871657.219851115534; Mon, 11 Jun 2018 07:32:13 -0700 (PDT) Received: from localhost ([::1]:49175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNrh-00009P-3e for importer@patchew.org; Mon, 11 Jun 2018 10:32:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52902) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmF-0004OM-JY for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmC-0001eI-Cw for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54482 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNm3-0001ZI-TH; Mon, 11 Jun 2018 10:26:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B9BC4022905; Mon, 11 Jun 2018 14:26:23 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9E61202698A; Mon, 11 Jun 2018 14:26:22 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:47 +0200 Message-Id: <20180611142611.6609-6-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:23 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:23 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 05/29] block: Add Error parameter to bdrv_amend_options X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Looking at the qcow2 code that is riddled with error_report() calls, this is really how it should have been from the start. Along the way, turn the target_version/current_version comparisons at the beginning of qcow2_downgrade() into assertions (the caller has to make sure these conditions are met), and rephrase the error message on using compat=3D1.1 to get refcount widths other than 16 bits. Signed-off-by: Max Reitz Message-id: 20180509210023.20283-3-mreitz@redhat.com Reviewed-by: Eric Blake Reviewed-by: John Snow Signed-off-by: Max Reitz --- include/block/block.h | 3 +- include/block/block_int.h | 3 +- block.c | 8 +++-- block/qcow2.c | 72 ++++++++++++++++++++++---------------- qemu-img.c | 4 +-- tests/qemu-iotests/060.out | 4 +-- tests/qemu-iotests/061.out | 7 ---- tests/qemu-iotests/080.out | 4 +-- tests/qemu-iotests/112.out | 5 +-- 9 files changed, 58 insertions(+), 52 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 6cc6c7e699..4dd4f1eab2 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -343,7 +343,8 @@ int bdrv_check(BlockDriverState *bs, BdrvCheckResult *r= es, BdrvCheckMode fix); typedef void BlockDriverAmendStatusCB(BlockDriverState *bs, int64_t offset, int64_t total_work_size, void *opaqu= e); int bdrv_amend_options(BlockDriverState *bs_new, QemuOpts *opts, - BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e); + BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e, + Error **errp); =20 /* external snapshots */ bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, diff --git a/include/block/block_int.h b/include/block/block_int.h index 888b7f7bff..327e478a73 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -353,7 +353,8 @@ struct BlockDriver { =20 int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts, BlockDriverAmendStatusCB *status_cb, - void *cb_opaque); + void *cb_opaque, + Error **errp); =20 void (*bdrv_debug_event)(BlockDriverState *bs, BlkdebugEvent event); =20 diff --git a/block.c b/block.c index 501b64c819..9d577f65bb 100644 --- a/block.c +++ b/block.c @@ -4996,15 +4996,19 @@ void bdrv_remove_aio_context_notifier(BlockDriverSt= ate *bs, } =20 int bdrv_amend_options(BlockDriverState *bs, QemuOpts *opts, - BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e) + BlockDriverAmendStatusCB *status_cb, void *cb_opaqu= e, + Error **errp) { if (!bs->drv) { + error_setg(errp, "Node is ejected"); return -ENOMEDIUM; } if (!bs->drv->bdrv_amend_options) { + error_setg(errp, "Block driver '%s' does not support option amendm= ent", + bs->drv->format_name); return -ENOTSUP; } - return bs->drv->bdrv_amend_options(bs, opts, status_cb, cb_opaque); + return bs->drv->bdrv_amend_options(bs, opts, status_cb, cb_opaque, err= p); } =20 /* This function will be called by the bdrv_recurse_is_first_non_filter me= thod diff --git a/block/qcow2.c b/block/qcow2.c index 549fee9b69..6b2d88759d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4215,22 +4215,21 @@ static int qcow2_load_vmstate(BlockDriverState *bs,= QEMUIOVector *qiov, * have to be removed. */ static int qcow2_downgrade(BlockDriverState *bs, int target_version, - BlockDriverAmendStatusCB *status_cb, void *cb_o= paque) + BlockDriverAmendStatusCB *status_cb, void *cb_o= paque, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; int current_version =3D s->qcow_version; int ret; =20 - if (target_version =3D=3D current_version) { - return 0; - } else if (target_version > current_version) { - return -EINVAL; - } else if (target_version !=3D 2) { - return -EINVAL; - } + /* This is qcow2_downgrade(), not qcow2_upgrade() */ + assert(target_version < current_version); + + /* There are no other versions (now) that you can downgrade to */ + assert(target_version =3D=3D 2); =20 if (s->refcount_order !=3D 4) { - error_report("compat=3D0.10 requires refcount_bits=3D16"); + error_setg(errp, "compat=3D0.10 requires refcount_bits=3D16"); return -ENOTSUP; } =20 @@ -4238,6 +4237,7 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, if (s->incompatible_features & QCOW2_INCOMPAT_DIRTY) { ret =3D qcow2_mark_clean(bs); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to make the image clean"); return ret; } } @@ -4247,6 +4247,8 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, * best thing to do anyway */ =20 if (s->incompatible_features) { + error_setg(errp, "Cannot downgrade an image with incompatible feat= ures " + "%#" PRIx64 " set", s->incompatible_features); return -ENOTSUP; } =20 @@ -4260,6 +4262,7 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, =20 ret =3D qcow2_expand_zero_clusters(bs, status_cb, cb_opaque); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to turn zero into data cluste= rs"); return ret; } =20 @@ -4267,6 +4270,7 @@ static int qcow2_downgrade(BlockDriverState *bs, int = target_version, ret =3D qcow2_update_header(bs); if (ret < 0) { s->qcow_version =3D current_version; + error_setg_errno(errp, -ret, "Failed to update the image header"); return ret; } return 0; @@ -4344,7 +4348,8 @@ static void qcow2_amend_helper_cb(BlockDriverState *b= s, =20 static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts, BlockDriverAmendStatusCB *status_cb, - void *cb_opaque) + void *cb_opaque, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; int old_version =3D s->qcow_version, new_version =3D old_version; @@ -4356,7 +4361,6 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, bool encrypt; int encformat; int refcount_bits =3D s->refcount_bits; - Error *local_err =3D NULL; int ret; QemuOptDesc *desc =3D opts->list->desc; Qcow2AmendHelperCBInfo helper_cb_info; @@ -4377,11 +4381,11 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, } else if (!strcmp(compat, "1.1")) { new_version =3D 3; } else { - error_report("Unknown compatibility level %s", compat); + error_setg(errp, "Unknown compatibility level %s", compat); return -EINVAL; } } else if (!strcmp(desc->name, BLOCK_OPT_PREALLOC)) { - error_report("Cannot change preallocation mode"); + error_setg(errp, "Cannot change preallocation mode"); return -ENOTSUP; } else if (!strcmp(desc->name, BLOCK_OPT_SIZE)) { new_size =3D qemu_opt_get_size(opts, BLOCK_OPT_SIZE, 0); @@ -4394,7 +4398,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, !!s->crypto); =20 if (encrypt !=3D !!s->crypto) { - error_report("Changing the encryption flag is not supporte= d"); + error_setg(errp, + "Changing the encryption flag is not supported"= ); return -ENOTSUP; } } else if (!strcmp(desc->name, BLOCK_OPT_ENCRYPT_FORMAT)) { @@ -4402,17 +4407,19 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, qemu_opt_get(opts, BLOCK_OPT_ENCRYPT_FORMAT)); =20 if (encformat !=3D s->crypt_method_header) { - error_report("Changing the encryption format is not suppor= ted"); + error_setg(errp, + "Changing the encryption format is not supporte= d"); return -ENOTSUP; } } else if (g_str_has_prefix(desc->name, "encrypt.")) { - error_report("Changing the encryption parameters is not suppor= ted"); + error_setg(errp, + "Changing the encryption parameters is not supporte= d"); 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); if (cluster_size !=3D s->cluster_size) { - error_report("Changing the cluster size is not supported"); + error_setg(errp, "Changing the cluster size is not support= ed"); return -ENOTSUP; } } else if (!strcmp(desc->name, BLOCK_OPT_LAZY_REFCOUNTS)) { @@ -4425,8 +4432,8 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, if (refcount_bits <=3D 0 || refcount_bits > 64 || !is_power_of_2(refcount_bits)) { - error_report("Refcount width must be a power of two and ma= y " - "not exceed 64 bits"); + error_setg(errp, "Refcount width must be a power of two an= d " + "may not exceed 64 bits"); return -EINVAL; } } else { @@ -4451,6 +4458,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, ret =3D qcow2_update_header(bs); if (ret < 0) { s->qcow_version =3D old_version; + error_setg_errno(errp, -ret, "Failed to update the image heade= r"); return ret; } } @@ -4459,18 +4467,17 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, int refcount_order =3D ctz32(refcount_bits); =20 if (new_version < 3 && refcount_bits !=3D 16) { - error_report("Different refcount widths than 16 bits require " - "compatibility level 1.1 or above (use compat=3D1= .1 or " - "greater)"); + error_setg(errp, "Refcount widths other than 16 bits require " + "compatibility level 1.1 or above (use compat=3D1.1= or " + "greater)"); return -EINVAL; } =20 helper_cb_info.current_operation =3D QCOW2_CHANGING_REFCOUNT_ORDER; ret =3D qcow2_change_refcount_order(bs, refcount_order, &qcow2_amend_helper_cb, - &helper_cb_info, &local_err); + &helper_cb_info, errp); if (ret < 0) { - error_report_err(local_err); return ret; } } @@ -4480,6 +4487,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, backing_file ?: s->image_backing_file, backing_format ?: s->image_backing_format); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to change the backing fil= e"); return ret; } } @@ -4487,14 +4495,16 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, if (s->use_lazy_refcounts !=3D lazy_refcounts) { if (lazy_refcounts) { if (new_version < 3) { - error_report("Lazy refcounts only supported with compatibi= lity " - "level 1.1 and above (use compat=3D1.1 or gre= ater)"); + error_setg(errp, "Lazy refcounts only supported with " + "compatibility level 1.1 and above (use compat= =3D1.1 " + "or greater)"); return -EINVAL; } s->compatible_features |=3D QCOW2_COMPAT_LAZY_REFCOUNTS; ret =3D qcow2_update_header(bs); if (ret < 0) { s->compatible_features &=3D ~QCOW2_COMPAT_LAZY_REFCOUNTS; + error_setg_errno(errp, -ret, "Failed to update the image h= eader"); return ret; } s->use_lazy_refcounts =3D true; @@ -4502,6 +4512,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, /* make image clean first */ ret =3D qcow2_mark_clean(bs); if (ret < 0) { + error_setg_errno(errp, -ret, "Failed to make the image cle= an"); return ret; } /* now disallow lazy refcounts */ @@ -4509,6 +4520,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, ret =3D qcow2_update_header(bs); if (ret < 0) { s->compatible_features |=3D QCOW2_COMPAT_LAZY_REFCOUNTS; + error_setg_errno(errp, -ret, "Failed to update the image h= eader"); return ret; } s->use_lazy_refcounts =3D false; @@ -4517,17 +4529,15 @@ static int qcow2_amend_options(BlockDriverState *bs= , QemuOpts *opts, =20 if (new_size) { BlockBackend *blk =3D blk_new(BLK_PERM_RESIZE, BLK_PERM_ALL); - ret =3D blk_insert_bs(blk, bs, &local_err); + ret =3D blk_insert_bs(blk, bs, errp); if (ret < 0) { - error_report_err(local_err); blk_unref(blk); return ret; } =20 - ret =3D blk_truncate(blk, new_size, PREALLOC_MODE_OFF, &local_err); + ret =3D blk_truncate(blk, new_size, PREALLOC_MODE_OFF, errp); blk_unref(blk); if (ret < 0) { - error_report_err(local_err); return ret; } } @@ -4536,7 +4546,7 @@ static int qcow2_amend_options(BlockDriverState *bs, = QemuOpts *opts, if (new_version < old_version) { helper_cb_info.current_operation =3D QCOW2_DOWNGRADING; ret =3D qcow2_downgrade(bs, new_version, &qcow2_amend_helper_cb, - &helper_cb_info); + &helper_cb_info, errp); if (ret < 0) { return ret; } diff --git a/qemu-img.c b/qemu-img.c index 0be11b3852..df3ec5b7fe 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3810,10 +3810,10 @@ static int img_amend(int argc, char **argv) =20 /* In case the driver does not call amend_status_cb() */ qemu_progress_print(0.f, 0); - ret =3D bdrv_amend_options(bs, opts, &amend_status_cb, NULL); + ret =3D bdrv_amend_options(bs, opts, &amend_status_cb, NULL, &err); qemu_progress_print(100.f, 0); if (ret < 0) { - error_report("Error while amending options: %s", strerror(-ret)); + error_report_err(err); goto out; } =20 diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 25d5c3938b..5f4264cff6 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -129,7 +129,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: L2 table offset 0x42a00 unaligned (L1 ind= ex: 0); further corruption events will be suppressed -qemu-img: Error while amending options: Input/output error +qemu-img: Failed to turn zero into data clusters: Input/output error =20 =3D=3D=3D Testing unaligned L2 entry =3D=3D=3D =20 @@ -145,7 +145,7 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 wrote 65536/65536 bytes at offset 0 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qcow2: Marking image as corrupt: Cluster allocation offset 0x52a00 unalign= ed (L2 offset: 0x40000, L2 index: 0); further corruption events will be sup= pressed -qemu-img: Error while amending options: Input/output error +qemu-img: Failed to turn zero into data clusters: Input/output error =20 =3D=3D=3D Testing unaligned reftable entry =3D=3D=3D =20 diff --git a/tests/qemu-iotests/061.out b/tests/qemu-iotests/061.out index e857ef9a7d..183f7dd690 100644 --- a/tests/qemu-iotests/061.out +++ b/tests/qemu-iotests/061.out @@ -358,18 +358,12 @@ No errors were found on the image. =20 Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 qemu-img: Lazy refcounts only supported with compatibility level 1.1 and a= bove (use compat=3D1.1 or greater) -qemu-img: Error while amending options: Invalid argument qemu-img: Lazy refcounts only supported with compatibility level 1.1 and a= bove (use compat=3D1.1 or greater) -qemu-img: Error while amending options: Invalid argument qemu-img: Unknown compatibility level 0.42 -qemu-img: Error while amending options: Invalid argument qemu-img: Invalid parameter 'foo' qemu-img: Changing the cluster size is not supported -qemu-img: Error while amending options: Operation not supported qemu-img: Changing the encryption flag is not supported -qemu-img: Error while amending options: Operation not supported qemu-img: Cannot change preallocation mode -qemu-img: Error while amending options: Operation not supported =20 =3D=3D=3D Testing correct handling of unset value =3D=3D=3D =20 @@ -377,7 +371,6 @@ Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D671= 08864 Should work: Should not work: qemu-img: Changing the cluster size is not supported -qemu-img: Error while amending options: Operation not supported =20 =3D=3D=3D Testing zero expansion on inactive clusters =3D=3D=3D =20 diff --git a/tests/qemu-iotests/080.out b/tests/qemu-iotests/080.out index 4e0f7f7b92..281c7e0d1d 100644 --- a/tests/qemu-iotests/080.out +++ b/tests/qemu-iotests/080.out @@ -65,7 +65,7 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Failed to load snapshot: Snapshot L1 table offset invalid qemu-img: Snapshot L1 table offset invalid -qemu-img: Error while amending options: Invalid argument +qemu-img: Failed to turn zero into data clusters: Invalid argument Failed to flush the refcount block cache: Invalid argument write failed: Invalid argument qemu-img: Snapshot L1 table offset invalid @@ -88,7 +88,7 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Failed to load snapshot: Snapshot L1 table too large qemu-img: Snapshot L1 table too large -qemu-img: Error while amending options: File too large +qemu-img: Failed to turn zero into data clusters: File too large Failed to flush the refcount block cache: File too large write failed: File too large qemu-img: Snapshot L1 table too large diff --git a/tests/qemu-iotests/112.out b/tests/qemu-iotests/112.out index 86f041075d..ae0318cabe 100644 --- a/tests/qemu-iotests/112.out +++ b/tests/qemu-iotests/112.out @@ -99,13 +99,11 @@ refcount bits: 64 =3D=3D=3D Amend to compat=3D0.10 =3D=3D=3D =20 qemu-img: compat=3D0.10 requires refcount_bits=3D16 -qemu-img: Error while amending options: Operation not supported refcount bits: 64 No errors were found on the image. refcount bits: 16 refcount bits: 16 -qemu-img: Different refcount widths than 16 bits require compatibility lev= el 1.1 or above (use compat=3D1.1 or greater) -qemu-img: Error while amending options: Invalid argument +qemu-img: Refcount widths other than 16 bits require compatibility level 1= .1 or above (use compat=3D1.1 or greater) refcount bits: 16 =20 =3D=3D=3D Amend with snapshot =3D=3D=3D @@ -113,7 +111,6 @@ refcount bits: 16 wrote 16777216/16777216 bytes at offset 0 16 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) qemu-img: Cannot decrease refcount entry width to 1 bits: Cluster at offse= t 0x50000 has a refcount of 2 -qemu-img: Error while amending options: Invalid argument No errors were found on the image. refcount bits: 16 No errors were found on the image. --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727508502827.7643945816625; Mon, 11 Jun 2018 07:31:48 -0700 (PDT) Received: from localhost ([::1]:49172 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNrH-0008Of-NF for importer@patchew.org; Mon, 11 Jun 2018 10:31:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52903) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmF-0004ON-KJ for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmC-0001ec-PO for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33538 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNm5-0001aC-Pw; Mon, 11 Jun 2018 10:26:25 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5CB10859A6; Mon, 11 Jun 2018 14:26:25 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 08AC88442D; Mon, 11 Jun 2018 14:26:24 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:48 +0200 Message-Id: <20180611142611.6609-7-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:25 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:25 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 06/29] qemu-option: Pull out "Supported options" print X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" It really is up to the caller to decide what this list of options means. Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake Message-id: 20180509210023.20283-4-mreitz@redhat.com Signed-off-by: Max Reitz --- qemu-img.c | 1 + util/qemu-option.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index df3ec5b7fe..52008c5647 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -260,6 +260,7 @@ static int print_block_option_help(const char *filename= , const char *fmt) create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); } =20 + printf("Supported options:\n"); qemu_opts_print_help(create_opts); qemu_opts_free(create_opts); return 0; diff --git a/util/qemu-option.c b/util/qemu-option.c index 58d1c23893..ba44a0895c 100644 --- a/util/qemu-option.c +++ b/util/qemu-option.c @@ -220,7 +220,6 @@ void qemu_opts_print_help(QemuOptsList *list) =20 assert(list); desc =3D list->desc; - printf("Supported options:\n"); while (desc && desc->name) { printf("%-16s %s\n", desc->name, desc->help ? desc->help : "No description available"); --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727713188485.01682983786486; Mon, 11 Jun 2018 07:35:13 -0700 (PDT) Received: from localhost ([::1]:49186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNua-0002Sj-D0 for importer@patchew.org; Mon, 11 Jun 2018 10:35:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmF-0004OP-KY for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmC-0001eA-B8 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:35 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55638 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNm7-0001be-Pf; Mon, 11 Jun 2018 10:26:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62B6340BC04D; Mon, 11 Jun 2018 14:26:27 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB67E2028672; Mon, 11 Jun 2018 14:26:26 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:49 +0200 Message-Id: <20180611142611.6609-8-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:27 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:27 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 07/29] qemu-img: Add print_amend_option_help() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" The more generic print_block_option_help() function is not really suitable for qemu-img amend, for a couple of reasons: (1) We do not need to append the protocol-level options, as amendment happens only on one node and does not descend downwards to its children. (2) print_block_option_help() says those options are "supported". For option amendment, we do not really know that. So this new function explicitly says that those options are the creation options, and not all of them may be supported. (3) If the driver does not support option amendment, we should not print anything (except for an error message that amendment is not supported). Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1537956 Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake Message-id: 20180509210023.20283-5-mreitz@redhat.com Signed-off-by: Max Reitz --- qemu-img.c | 30 ++++++++++++++++++++++++-- tests/qemu-iotests/082.out | 44 +++++++++++++++++++++++--------------- 2 files changed, 55 insertions(+), 19 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 52008c5647..07935cb232 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3658,6 +3658,32 @@ static void amend_status_cb(BlockDriverState *bs, qemu_progress_print(100.f * offset / total_work_size, 0); } =20 +static int print_amend_option_help(const char *format) +{ + BlockDriver *drv; + + /* Find driver and parse its options */ + drv =3D bdrv_find_format(format); + if (!drv) { + error_report("Unknown file format '%s'", format); + return 1; + } + + if (!drv->bdrv_amend_options) { + error_report("Format driver '%s' does not support option amendment= ", + format); + return 1; + } + + /* Every driver supporting amendment must have create_opts */ + assert(drv->create_opts); + + printf("Creation options for '%s':\n", format); + qemu_opts_print_help(drv->create_opts); + printf("\nNote that not all of these options may be amendable.\n"); + return 0; +} + static int img_amend(int argc, char **argv) { Error *err =3D NULL; @@ -3757,7 +3783,7 @@ static int img_amend(int argc, char **argv) if (fmt && has_help_option(options)) { /* If a format is explicitly specified (and possibly no filename is * given), print option help here */ - ret =3D print_block_option_help(filename, fmt); + ret =3D print_amend_option_help(fmt); goto out; } =20 @@ -3786,7 +3812,7 @@ static int img_amend(int argc, char **argv) =20 if (has_help_option(options)) { /* If the format was auto-detected, print option help here */ - ret =3D print_block_option_help(filename, fmt); + ret =3D print_amend_option_help(fmt); goto out; } =20 diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 1527fbe1b7..4e52dce8d6 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -546,7 +546,7 @@ cluster_size: 65536 =3D=3D=3D amend: help for -o =3D=3D=3D =20 Testing: amend -f qcow2 -o help TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -564,10 +564,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o ? TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -585,10 +586,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k,help TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -606,10 +608,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k,? TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -627,10 +630,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o help,cluster_size=3D4k TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -648,10 +652,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o ?,cluster_size=3D4k TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -669,10 +674,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k -o help TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -690,10 +696,11 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o cluster_size=3D4k -o ? TEST_DIR/t.qcow2 -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -711,7 +718,8 @@ cluster_size qcow2 cluster size preallocation Preallocation mode (allowed values: off, metadata, falloc= , full) lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits -nocow Turn off copy-on-write (valid only on btrfs) + +Note that not all of these options may be amendable. =20 Testing: amend -f qcow2 -o backing_file=3DTEST_DIR/t.qcow2,,help TEST_DIR/= t.qcow2 =20 @@ -731,7 +739,7 @@ Testing: amend -f qcow2 -o backing_file=3DTEST_DIR/t.qc= ow2 -o ,, -o help TEST_DIR/ qemu-img: Invalid option list: ,, =20 Testing: amend -f qcow2 -o help -Supported options: +Creation options for 'qcow2': size Virtual disk size compat Compatibility level (0.10 or 1.1) backing_file File name of a base image @@ -750,6 +758,8 @@ preallocation Preallocation mode (allowed values: of= f, metadata, falloc, full lazy_refcounts Postpone refcount updates refcount_bits Width of a reference count entry in bits =20 +Note that not all of these options may be amendable. + Testing: convert -o help Supported options: size Virtual disk size --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727631440920.3309271995253; Mon, 11 Jun 2018 07:33:51 -0700 (PDT) Received: from localhost ([::1]:49181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNtA-0001Ky-S8 for importer@patchew.org; Mon, 11 Jun 2018 10:33:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53111) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmS-0004dK-4v for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmM-0001ku-EJ for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:48 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54486 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNm9-0001cP-La; Mon, 11 Jun 2018 10:26:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4452D4022905; Mon, 11 Jun 2018 14:26:29 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E3741202698A; Mon, 11 Jun 2018 14:26:28 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:50 +0200 Message-Id: <20180611142611.6609-9-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:29 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 08/29] qemu-img: Recognize no creation support in -o help X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" The only users of print_block_option_help() are qemu-img create and qemu-img convert for the output image, so this function is always used for image creation (it used to be used for amendment also, but that is no longer the case). So if image creation is not supported by either the format or the protocol, there is no need to print any option description, because the user cannot create an image like this anyway. This also fixes an assertion failure: $ qemu-img create -f bochs -o help Supported options: qemu-img: util/qemu-option.c:219: qemu_opts_print_help: Assertion `list' failed. [1] 24831 abort (core dumped) qemu-img create -f bochs -o help Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake Message-id: 20180509210023.20283-6-mreitz@redhat.com Signed-off-by: Max Reitz --- qemu-img.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qemu-img.c b/qemu-img.c index 07935cb232..b1c1e484d2 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -249,6 +249,11 @@ static int print_block_option_help(const char *filenam= e, const char *fmt) return 1; } =20 + if (!drv->create_opts) { + error_report("Format driver '%s' does not support image creation",= fmt); + return 1; + } + create_opts =3D qemu_opts_append(create_opts, drv->create_opts); if (filename) { proto_drv =3D bdrv_find_protocol(filename, true, &local_err); @@ -257,6 +262,11 @@ static int print_block_option_help(const char *filenam= e, const char *fmt) qemu_opts_free(create_opts); return 1; } + if (!proto_drv->create_opts) { + error_report("Protocal driver '%s' does not support image crea= tion", + proto_drv->format_name); + return 1; + } create_opts =3D qemu_opts_append(create_opts, proto_drv->create_op= ts); } =20 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727425478128.98998522343015; Mon, 11 Jun 2018 07:30:25 -0700 (PDT) Received: from localhost ([::1]:49164 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNpr-0007Bt-Ly for importer@patchew.org; Mon, 11 Jun 2018 10:30:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmI-0004Ra-MV for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmH-0001ij-NG for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:38 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55642 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmB-0001dX-HT; Mon, 11 Jun 2018 10:26:31 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1FC0540BC04D; Mon, 11 Jun 2018 14:26:31 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C04DF202698A; Mon, 11 Jun 2018 14:26:30 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:51 +0200 Message-Id: <20180611142611.6609-10-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:31 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:31 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 09/29] iotests: Test help option for unsupporting 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This adds test cases to 082 for qemu-img create/convert/amend "-o help" on formats that do not support creation or amendment, respectively. Signed-off-by: Max Reitz Reviewed-by: John Snow Reviewed-by: Eric Blake Message-id: 20180509210023.20283-7-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/082 | 9 +++++++++ tests/qemu-iotests/082.out | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/tests/qemu-iotests/082 b/tests/qemu-iotests/082 index d5c83d45ed..a872f771a6 100755 --- a/tests/qemu-iotests/082 +++ b/tests/qemu-iotests/082 @@ -97,6 +97,9 @@ run_qemu_img create -f $IMGFMT -o backing_file=3D"$TEST_I= MG" -o ,, -o help "$TEST_ run_qemu_img create -f $IMGFMT -o help run_qemu_img create -o help =20 +# Try help option for a format that does not support creation +run_qemu_img create -f bochs -o help + echo echo =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 @@ -151,6 +154,9 @@ run_qemu_img convert -O $IMGFMT -o backing_file=3D"$TES= T_IMG" -o ,, -o help "$TEST run_qemu_img convert -O $IMGFMT -o help run_qemu_img convert -o help =20 +# Try help option for a format that does not support creation +run_qemu_img convert -O bochs -o help + echo echo =3D=3D=3D amend: Options specified more than once =3D=3D=3D =20 @@ -201,6 +207,9 @@ run_qemu_img amend -f $IMGFMT -o backing_file=3D"$TEST_= IMG" -o ,, -o help "$TEST_I run_qemu_img amend -f $IMGFMT -o help run_qemu_img convert -o help =20 +# Try help option for a format that does not support amendment +run_qemu_img amend -f bochs -o help + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out index 4e52dce8d6..60ef87c276 100644 --- a/tests/qemu-iotests/082.out +++ b/tests/qemu-iotests/082.out @@ -249,6 +249,9 @@ Testing: create -o help Supported options: size Virtual disk size =20 +Testing: create -f bochs -o help +qemu-img: Format driver 'bochs' does not support image creation + =3D=3D=3D convert: Options specified more than once =3D=3D=3D =20 Testing: create -f qcow2 TEST_DIR/t.qcow2 128M @@ -502,6 +505,9 @@ Testing: convert -o help Supported options: size Virtual disk size =20 +Testing: convert -O bochs -o help +qemu-img: Format driver 'bochs' does not support image creation + =3D=3D=3D amend: Options specified more than once =3D=3D=3D =20 Testing: amend -f foo -f qcow2 -o lazy_refcounts=3Don TEST_DIR/t.qcow2 @@ -763,4 +769,7 @@ Note that not all of these options may be amendable. Testing: convert -o help Supported options: size Virtual disk size + +Testing: amend -f bochs -o help +qemu-img: Format driver 'bochs' does not support option amendment *** done --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727926377562.8236308088464; Mon, 11 Jun 2018 07:38:46 -0700 (PDT) Received: from localhost ([::1]:49212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNy1-0005K1-M3 for importer@patchew.org; Mon, 11 Jun 2018 10:38:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmJ-0004S3-BJ for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmI-0001j4-Ax for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33544 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmD-0001eo-EX; Mon, 11 Jun 2018 10:26:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0026E859A6; Mon, 11 Jun 2018 14:26:33 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A0CDD83B9C; Mon, 11 Jun 2018 14:26:32 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:52 +0200 Message-Id: <20180611142611.6609-11-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:33 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:26:33 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 10/29] iotests: Rework 113 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This test case has been broken since 398e6ad014df261d (roughly half a year). qemu-img amend requires its output image to be R/W, so it opens it as such; the node is then turned into an read-only node automatically which is now accompanied by a warning, however. This warning has not been part of the reference output. For one thing, this warning shows that we cannot keep the test case as it is. We would need a format that has no create_opts but that does have write support -- we do not have such a format, though. Another thing is that qemu now actually checks whether an image format supports amendment instead of whether it has create_opts (since the former always implies the latter). So we can now use any format that does not support amendment (even if it supports creation) and thus test the same code path. The reason nobody has noticed the breakage until now of course is the fact that nobody runs the iotests for nbd+bochs. There actually was never any reason to set the protocol to "nbd" but because that was technically correct; functionally it made no difference. So that is the first thing we are going to change: Make the protocol "file" instead so that people might actually notice breakage here. Secondly, now that bochs no longer works for the amend test case, we have to change the format there anyway. Set let us just bend the truth a bit, declare this test a raw test. In fact, that does not even concern the bochs test cases, other than the output now reading 'bochs' instead of 'IMGFMT'. So with this test now being a raw test, we can rework the amend test case to use raw instead. Signed-off-by: Max Reitz Reviewed-by: John Snow Message-id: 20180509210023.20283-8-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/113 | 19 +++++++++---------- tests/qemu-iotests/113.out | 7 ++++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/qemu-iotests/113 b/tests/qemu-iotests/113 index 19b68b2727..4e09810905 100755 --- a/tests/qemu-iotests/113 +++ b/tests/qemu-iotests/113 @@ -38,16 +38,17 @@ trap "_cleanup; exit \$status" 0 1 2 3 15 . ./common.rc . ./common.filter =20 -# We can only test one format here because we need its sample file -_supported_fmt bochs -_supported_proto nbd +# Some of these test cases use bochs, but others do use raw, so this +# is only half a lie. +_supported_fmt raw +_supported_proto file _supported_os Linux =20 echo echo '=3D=3D=3D Unsupported image creation in qemu-img create =3D=3D=3D' echo =20 -$QEMU_IMG create -f $IMGFMT nbd://example.com 2>&1 64M | _filter_imgfmt +$QEMU_IMG create -f bochs nbd://example.com 2>&1 64M =20 echo echo '=3D=3D=3D Unsupported image creation in qemu-img convert =3D=3D=3D' @@ -56,17 +57,15 @@ echo # We could use any input image format here, but this is a bochs test, so j= ust # use the bochs image _use_sample_img empty.bochs.bz2 -$QEMU_IMG convert -f $IMGFMT -O $IMGFMT "$TEST_IMG" nbd://example.com 2>&1= \ - | _filter_imgfmt +$QEMU_IMG convert -f bochs -O bochs "$TEST_IMG" nbd://example.com =20 echo echo '=3D=3D=3D Unsupported format in qemu-img amend =3D=3D=3D' echo =20 -# The protocol does not matter here -_use_sample_img empty.bochs.bz2 -$QEMU_IMG amend -f $IMGFMT -o foo=3Dbar "$TEST_IMG" 2>&1 | _filter_imgfmt - +TEST_IMG=3D"$TEST_DIR/t.$IMGFMT" +_make_test_img 1M +$QEMU_IMG amend -f $IMGFMT -o size=3D2M "$TEST_IMG" 2>&1 | _filter_imgfmt =20 # success, all done echo diff --git a/tests/qemu-iotests/113.out b/tests/qemu-iotests/113.out index 00bdfd6887..3557e2bbf0 100644 --- a/tests/qemu-iotests/113.out +++ b/tests/qemu-iotests/113.out @@ -2,14 +2,15 @@ QA output created by 113 =20 =3D=3D=3D Unsupported image creation in qemu-img create =3D=3D=3D =20 -qemu-img: nbd://example.com: Format driver 'IMGFMT' does not support image= creation +qemu-img: nbd://example.com: Format driver 'bochs' does not support image = creation =20 =3D=3D=3D Unsupported image creation in qemu-img convert =3D=3D=3D =20 -qemu-img: Format driver 'IMGFMT' does not support image creation +qemu-img: Format driver 'bochs' does not support image creation =20 =3D=3D=3D Unsupported format in qemu-img amend =3D=3D=3D =20 -qemu-img: Format driver 'IMGFMT' does not support any options to amend +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 +qemu-img: Format driver 'IMGFMT' does not support option amendment =20 *** done --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727736999923.9908712689476; Mon, 11 Jun 2018 07:35:36 -0700 (PDT) Received: from localhost ([::1]:49189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNuu-0002oB-6g for importer@patchew.org; Mon, 11 Jun 2018 10:35:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmJ-0004Sr-Vc for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmI-0001jH-NQ for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:39 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35522 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmF-0001fg-KQ; Mon, 11 Jun 2018 10:26:35 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DA3ABB409; Mon, 11 Jun 2018 14:26:35 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 82C0F100294B; Mon, 11 Jun 2018 14:26:34 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:53 +0200 Message-Id: <20180611142611.6609-12-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:35 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 11/29] qcow2: Repair OFLAG_COPIED when fixing leaks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Repairing OFLAG_COPIED is usually safe because it is done after the refcounts have been repaired. Therefore, it we did not find anyone else referencing a data or L2 cluster, it makes no sense to not set OFLAG_COPIED -- and the other direction (clearing OFLAG_COPIED) is always safe, anyway, it may just induce leaks. Furthermore, if OFLAG_COPIED is actually consistent with a wrong (leaky) refcount, we will decrement the refcount with -r leaks, but OFLAG_COPIED will then be wrong. qemu-img check should not produce images that are more corrupted afterwards then they were before. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1527085 Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509200059.31125-2-mreitz@redhat.com Signed-off-by: Max Reitz --- block/qcow2-refcount.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 403236256b..18c729aa27 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1799,6 +1799,19 @@ static int check_oflag_copied(BlockDriverState *bs, = BdrvCheckResult *res, int ret; uint64_t refcount; int i, j; + bool repair; + + if (fix & BDRV_FIX_ERRORS) { + /* Always repair */ + repair =3D true; + } else if (fix & BDRV_FIX_LEAKS) { + /* Repair only if that seems safe: This function is always + * called after the refcounts have been fixed, so the refcount + * is accurate if that repair was successful */ + repair =3D !res->check_errors && !res->corruptions && !res->leaks; + } else { + repair =3D false; + } =20 for (i =3D 0; i < s->l1_size; i++) { uint64_t l1_entry =3D s->l1_table[i]; @@ -1818,10 +1831,8 @@ static int check_oflag_copied(BlockDriverState *bs, = BdrvCheckResult *res, if ((refcount =3D=3D 1) !=3D ((l1_entry & QCOW_OFLAG_COPIED) !=3D = 0)) { fprintf(stderr, "%s OFLAG_COPIED L2 cluster: l1_index=3D%d " "l1_entry=3D%" PRIx64 " refcount=3D%" PRIu64 "\n", - fix & BDRV_FIX_ERRORS ? "Repairing" : - "ERROR", - i, l1_entry, refcount); - if (fix & BDRV_FIX_ERRORS) { + repair ? "Repairing" : "ERROR", i, l1_entry, refcount); + if (repair) { s->l1_table[i] =3D refcount =3D=3D 1 ? l1_entry | QCOW_OFLAG_COPIED : l1_entry & ~QCOW_OFLAG_COPIED; @@ -1862,10 +1873,8 @@ static int check_oflag_copied(BlockDriverState *bs, = BdrvCheckResult *res, if ((refcount =3D=3D 1) !=3D ((l2_entry & QCOW_OFLAG_COPIE= D) !=3D 0)) { fprintf(stderr, "%s OFLAG_COPIED data cluster: " "l2_entry=3D%" PRIx64 " refcount=3D%" PRIu64 "= \n", - fix & BDRV_FIX_ERRORS ? "Repairing" : - "ERROR", - l2_entry, refcount); - if (fix & BDRV_FIX_ERRORS) { + repair ? "Repairing" : "ERROR", l2_entry, refc= ount); + if (repair) { l2_table[j] =3D cpu_to_be64(refcount =3D=3D 1 ? l2_entry | QCOW_OFLAG_COPIED : l2_entry & ~QCOW_OFLAG_COPIED); --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727923549338.0977445428879; Mon, 11 Jun 2018 07:38:43 -0700 (PDT) Received: from localhost ([::1]:49211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNxy-0005G4-N7 for importer@patchew.org; Mon, 11 Jun 2018 10:38:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53061) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmP-0004ac-In for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmN-0001lf-P5 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54492 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmH-0001iC-Aw; Mon, 11 Jun 2018 10:26:37 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E2B864022905; Mon, 11 Jun 2018 14:26:36 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8E7E083B9C; Mon, 11 Jun 2018 14:26:36 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:54 +0200 Message-Id: <20180611142611.6609-13-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:36 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:36 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 12/29] iotests: Repairing error during snapshot deletion X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This adds a test for an I/O error during snapshot deletion, and maybe more importantly, for how to repair the resulting image. If the snapshot has been deleted before the error occurs, the only negative result will be leaked clusters -- and those should be repairable with qemu-img check -r leaks. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509200059.31125-3-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/217 | 90 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/217.out | 42 ++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 133 insertions(+) create mode 100755 tests/qemu-iotests/217 create mode 100644 tests/qemu-iotests/217.out diff --git a/tests/qemu-iotests/217 b/tests/qemu-iotests/217 new file mode 100755 index 0000000000..d3ab5d72be --- /dev/null +++ b/tests/qemu-iotests/217 @@ -0,0 +1,90 @@ +#!/bin/bash +# +# I/O errors when working with internal qcow2 snapshots, and repairing +# the result +# +# Copyright (C) 2018 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 . + +seq=3D$(basename $0) +echo "QA output created by $seq" + +status=3D1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img + rm -f "$TEST_DIR/blkdebug.conf" +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +# This test is specific to qcow2 +_supported_fmt qcow2 +_supported_proto file +_supported_os Linux + +# This test needs clusters with at least a refcount of 2 so that +# OFLAG_COPIED is not set. refcount_bits=3D1 is therefore unsupported. +_unsupported_imgopts 'refcount_bits=3D1[^0-9]' + +echo +echo '=3D=3D=3D Simulating an I/O error during snapshot deletion =3D=3D=3D' +echo + +_make_test_img 64M +$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io + +# Create the snapshot +$QEMU_IMG snapshot -c foo "$TEST_IMG" + +# Verify the snapshot is there +echo +_img_info | grep 'Snapshot list' +echo '(Snapshot filtered)' +echo + +# Try to delete the snapshot (with an error happening when freeing the +# then leaked clusters) +cat > "$TEST_DIR/blkdebug.conf" < Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728639657564.8622416612958; Mon, 11 Jun 2018 07:50:39 -0700 (PDT) Received: from localhost ([::1]:49295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO9W-0006bQ-Qe for importer@patchew.org; Mon, 11 Jun 2018 10:50:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmf-0004rA-V7 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmW-0001qM-Uu for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:01 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35526 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmJ-0001jl-Lg; Mon, 11 Jun 2018 10:26:39 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 41432BB409; Mon, 11 Jun 2018 14:26:39 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E0992028672; Mon, 11 Jun 2018 14:26:38 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:55 +0200 Message-Id: <20180611142611.6609-14-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:39 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:39 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 13/29] qemu-io: Drop command functions' return 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" For qemu-io, a function returns an integer with two possible values: 0 for "qemu-io may continue execution", or 1 for "qemu-io should exit". However, there is only a single command that returns 1, and that is "quit". So let's turn this case into a global variable instead so we can make better use of the return value in a later patch. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509194302.21585-2-mreitz@redhat.com Signed-off-by: Max Reitz --- include/qemu-io.h | 6 +- qemu-io-cmds.c | 294 +++++++++++++++++++++------------------------- qemu-io.c | 36 +++--- 3 files changed, 157 insertions(+), 179 deletions(-) diff --git a/include/qemu-io.h b/include/qemu-io.h index 196fde0f3a..06cdfbf660 100644 --- a/include/qemu-io.h +++ b/include/qemu-io.h @@ -22,7 +22,7 @@ =20 #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */ =20 -typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv); +typedef void (*cfunc_t)(BlockBackend *blk, int argc, char **argv); typedef void (*helpfunc_t)(void); =20 typedef struct cmdinfo { @@ -41,10 +41,10 @@ typedef struct cmdinfo { =20 extern bool qemuio_misalign; =20 -bool qemuio_command(BlockBackend *blk, const char *cmd); +void qemuio_command(BlockBackend *blk, const char *cmd); =20 void qemuio_add_command(const cmdinfo_t *ci); -int qemuio_command_usage(const cmdinfo_t *ci); +void qemuio_command_usage(const cmdinfo_t *ci); void qemuio_complete_command(const char *input, void (*fn)(const char *cmd, void *opaque), void *opaque); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index 9b3cd00af6..c2fbaae0fd 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -48,10 +48,9 @@ void qemuio_add_command(const cmdinfo_t *ci) qsort(cmdtab, ncmds, sizeof(*cmdtab), compare_cmdname); } =20 -int qemuio_command_usage(const cmdinfo_t *ci) +void qemuio_command_usage(const cmdinfo_t *ci) { printf("%s %s -- %s\n", ci->name, ci->args, ci->oneline); - return 0; } =20 static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct) @@ -66,13 +65,13 @@ static int init_check_command(BlockBackend *blk, const = cmdinfo_t *ct) return 1; } =20 -static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, - char **argv) +static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc, + char **argv) { char *cmd =3D argv[0]; =20 if (!init_check_command(blk, ct)) { - return 0; + return; } =20 if (argc - 1 < ct->argmin || (ct->argmax !=3D -1 && argc - 1 > ct->arg= max)) { @@ -89,7 +88,7 @@ static int command(BlockBackend *blk, const cmdinfo_t *ct= , int argc, "bad argument count %d to %s, expected between %d and = %d arguments\n", argc-1, cmd, ct->argmin, ct->argmax); } - return 0; + return; } =20 /* Request additional permissions if necessary for this command. The c= aller @@ -109,13 +108,13 @@ static int command(BlockBackend *blk, const cmdinfo_t= *ct, int argc, ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, &local_e= rr); if (ret < 0) { error_report_err(local_err); - return 0; + return; } } } =20 optind =3D 0; - return ct->cfunc(blk, argc, argv); + ct->cfunc(blk, argc, argv); } =20 static const cmdinfo_t *find_command(const char *cmd) @@ -634,7 +633,7 @@ static void read_help(void) "\n"); } =20 -static int read_f(BlockBackend *blk, int argc, char **argv); +static void read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t read_cmd =3D { .name =3D "read", @@ -647,7 +646,7 @@ static const cmdinfo_t read_cmd =3D { .help =3D read_help, }; =20 -static int read_f(BlockBackend *blk, int argc, char **argv) +static void read_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; @@ -674,7 +673,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) pattern_count =3D cvtnum(optarg); if (pattern_count < 0) { print_cvtnum_err(pattern_count, optarg); - return 0; + return; } break; case 'p': @@ -684,7 +683,7 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; case 'q': @@ -695,40 +694,43 @@ static int read_f(BlockBackend *blk, int argc, char *= *argv) pattern_offset =3D cvtnum(optarg); if (pattern_offset < 0) { print_cvtnum_err(pattern_offset, optarg); - return 0; + return; } break; case 'v': vflag =3D true; break; default: - return qemuio_command_usage(&read_cmd); + qemuio_command_usage(&read_cmd); + return; } } =20 if (optind !=3D argc - 2) { - return qemuio_command_usage(&read_cmd); + qemuio_command_usage(&read_cmd); + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return 0; + return; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return 0; + return; } =20 if (!Pflag && (lflag || sflag)) { - return qemuio_command_usage(&read_cmd); + qemuio_command_usage(&read_cmd); + return; } =20 if (!lflag) { @@ -737,19 +739,19 @@ static int read_f(BlockBackend *blk, int argc, char *= *argv) =20 if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { printf("pattern verification range exceeds end of read data\n"); - return 0; + return; } =20 if (bflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return 0; + return; } if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return 0; + return; } } =20 @@ -793,8 +795,6 @@ static int read_f(BlockBackend *blk, int argc, char **a= rgv) =20 out: qemu_io_free(buf); - - return 0; } =20 static void readv_help(void) @@ -816,7 +816,7 @@ static void readv_help(void) "\n"); } =20 -static int readv_f(BlockBackend *blk, int argc, char **argv); +static void readv_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t readv_cmd =3D { .name =3D "readv", @@ -828,7 +828,7 @@ static const cmdinfo_t readv_cmd =3D { .help =3D readv_help, }; =20 -static int readv_f(BlockBackend *blk, int argc, char **argv) +static void readv_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; @@ -851,7 +851,7 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; case 'q': @@ -861,26 +861,28 @@ static int readv_f(BlockBackend *blk, int argc, char = **argv) vflag =3D true; break; default: - return qemuio_command_usage(&readv_cmd); + qemuio_command_usage(&readv_cmd); + return; } } =20 if (optind > argc - 2) { - return qemuio_command_usage(&readv_cmd); + qemuio_command_usage(&readv_cmd); + return; } =20 =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab); if (buf =3D=3D NULL) { - return 0; + return; } =20 gettimeofday(&t1, NULL); @@ -917,7 +919,6 @@ static int readv_f(BlockBackend *blk, int argc, char **= argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); - return 0; } =20 static void write_help(void) @@ -943,7 +944,7 @@ static void write_help(void) "\n"); } =20 -static int write_f(BlockBackend *blk, int argc, char **argv); +static void write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t write_cmd =3D { .name =3D "write", @@ -957,7 +958,7 @@ static const cmdinfo_t write_cmd =3D { .help =3D write_help, }; =20 -static int write_f(BlockBackend *blk, int argc, char **argv) +static void write_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, bflag =3D false; @@ -992,7 +993,7 @@ static int write_f(BlockBackend *blk, int argc, char **= argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; case 'q': @@ -1005,62 +1006,64 @@ static int write_f(BlockBackend *blk, int argc, cha= r **argv) zflag =3D true; break; default: - return qemuio_command_usage(&write_cmd); + qemuio_command_usage(&write_cmd); + return; } } =20 if (optind !=3D argc - 2) { - return qemuio_command_usage(&write_cmd); + qemuio_command_usage(&write_cmd); + return; } =20 if (bflag && zflag) { printf("-b and -z cannot be specified at the same time\n"); - return 0; + return; } =20 if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) { printf("-f and -b or -c cannot be specified at the same time\n"); - return 0; + return; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) { printf("-u requires -z to be specified\n"); - return 0; + return; } =20 if (zflag && Pflag) { printf("-z and -P cannot be specified at the same time\n"); - return 0; + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return 0; + return; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return 0; + return; } =20 if (bflag || cflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return 0; + return; } =20 if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return 0; + return; } } =20 @@ -1097,8 +1100,6 @@ out: if (!zflag) { qemu_io_free(buf); } - - return 0; } =20 static void @@ -1120,7 +1121,7 @@ writev_help(void) "\n"); } =20 -static int writev_f(BlockBackend *blk, int argc, char **argv); +static void writev_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t writev_cmd =3D { .name =3D "writev", @@ -1133,7 +1134,7 @@ static const cmdinfo_t writev_cmd =3D { .help =3D writev_help, }; =20 -static int writev_f(BlockBackend *blk, int argc, char **argv) +static void writev_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1161,29 +1162,31 @@ static int writev_f(BlockBackend *blk, int argc, ch= ar **argv) case 'P': pattern =3D parse_pattern(optarg); if (pattern < 0) { - return 0; + return; } break; default: - return qemuio_command_usage(&writev_cmd); + qemuio_command_usage(&writev_cmd); + return; } } =20 if (optind > argc - 2) { - return qemuio_command_usage(&writev_cmd); + qemuio_command_usage(&writev_cmd); + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern); if (buf =3D=3D NULL) { - return 0; + return; } =20 gettimeofday(&t1, NULL); @@ -1205,7 +1208,6 @@ static int writev_f(BlockBackend *blk, int argc, char= **argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); - return 0; } =20 struct aio_ctx { @@ -1320,7 +1322,7 @@ static void aio_read_help(void) "\n"); } =20 -static int aio_read_f(BlockBackend *blk, int argc, char **argv); +static void aio_read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_read_cmd =3D { .name =3D "aio_read", @@ -1332,7 +1334,7 @@ static const cmdinfo_t aio_read_cmd =3D { .help =3D aio_read_help, }; =20 -static int aio_read_f(BlockBackend *blk, int argc, char **argv) +static void aio_read_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); @@ -1348,14 +1350,14 @@ static int aio_read_f(BlockBackend *blk, int argc, = char **argv) ctx->pattern =3D parse_pattern(optarg); if (ctx->pattern < 0) { g_free(ctx); - return 0; + return; } break; case 'i': printf("injecting invalid read request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return 0; + return; case 'q': ctx->qflag =3D true; break; @@ -1364,20 +1366,22 @@ static int aio_read_f(BlockBackend *blk, int argc, = char **argv) break; default: g_free(ctx); - return qemuio_command_usage(&aio_read_cmd); + qemuio_command_usage(&aio_read_cmd); + return; } } =20 if (optind > argc - 2) { g_free(ctx); - return qemuio_command_usage(&aio_read_cmd); + qemuio_command_usage(&aio_read_cmd); + return; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { print_cvtnum_err(ctx->offset, argv[optind]); g_free(ctx); - return 0; + return; } optind++; =20 @@ -1386,14 +1390,13 @@ static int aio_read_f(BlockBackend *blk, int argc, = char **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return 0; + return; } =20 gettimeofday(&ctx->t1, NULL); block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_READ); blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx); - return 0; } =20 static void aio_write_help(void) @@ -1420,7 +1423,7 @@ static void aio_write_help(void) "\n"); } =20 -static int aio_write_f(BlockBackend *blk, int argc, char **argv); +static void aio_write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_write_cmd =3D { .name =3D "aio_write", @@ -1433,7 +1436,7 @@ static const cmdinfo_t aio_write_cmd =3D { .help =3D aio_write_help, }; =20 -static int aio_write_f(BlockBackend *blk, int argc, char **argv) +static void aio_write_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; int pattern =3D 0xcd; @@ -1459,51 +1462,53 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) pattern =3D parse_pattern(optarg); if (pattern < 0) { g_free(ctx); - return 0; + return; } break; case 'i': printf("injecting invalid write request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return 0; + return; case 'z': ctx->zflag =3D true; break; default: g_free(ctx); - return qemuio_command_usage(&aio_write_cmd); + qemuio_command_usage(&aio_write_cmd); + return; } } =20 if (optind > argc - 2) { g_free(ctx); - return qemuio_command_usage(&aio_write_cmd); + qemuio_command_usage(&aio_write_cmd); + return; } =20 if (ctx->zflag && optind !=3D argc - 2) { printf("-z supports only a single length parameter\n"); g_free(ctx); - return 0; + return; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { printf("-u requires -z to be specified\n"); g_free(ctx); - return 0; + return; } =20 if (ctx->zflag && ctx->Pflag) { printf("-z and -P cannot be specified at the same time\n"); g_free(ctx); - return 0; + return; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { print_cvtnum_err(ctx->offset, argv[optind]); g_free(ctx); - return 0; + return; } optind++; =20 @@ -1512,7 +1517,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) if (count < 0) { print_cvtnum_err(count, argv[optind]); g_free(ctx); - return 0; + return; } =20 ctx->qiov.size =3D count; @@ -1525,7 +1530,7 @@ static int aio_write_f(BlockBackend *blk, int argc, c= har **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return 0; + return; } =20 gettimeofday(&ctx->t1, NULL); @@ -1535,16 +1540,14 @@ static int aio_write_f(BlockBackend *blk, int argc,= char **argv) blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_don= e, ctx); } - return 0; } =20 -static int aio_flush_f(BlockBackend *blk, int argc, char **argv) +static void aio_flush_f(BlockBackend *blk, int argc, char **argv) { BlockAcctCookie cookie; block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH); blk_drain_all(); block_acct_done(blk_get_stats(blk), &cookie); - return 0; } =20 static const cmdinfo_t aio_flush_cmd =3D { @@ -1553,10 +1556,9 @@ static const cmdinfo_t aio_flush_cmd =3D { .oneline =3D "completes all outstanding aio requests" }; =20 -static int flush_f(BlockBackend *blk, int argc, char **argv) +static void flush_f(BlockBackend *blk, int argc, char **argv) { blk_flush(blk); - return 0; } =20 static const cmdinfo_t flush_cmd =3D { @@ -1566,7 +1568,7 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 -static int truncate_f(BlockBackend *blk, int argc, char **argv) +static void truncate_f(BlockBackend *blk, int argc, char **argv) { Error *local_err =3D NULL; int64_t offset; @@ -1575,16 +1577,14 @@ static int truncate_f(BlockBackend *blk, int argc, = char **argv) offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return 0; + return; } =20 ret =3D blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); - return 0; + return; } - - return 0; } =20 static const cmdinfo_t truncate_cmd =3D { @@ -1598,7 +1598,7 @@ static const cmdinfo_t truncate_cmd =3D { .oneline =3D "truncates the current file at the given offset", }; =20 -static int length_f(BlockBackend *blk, int argc, char **argv) +static void length_f(BlockBackend *blk, int argc, char **argv) { int64_t size; char s1[64]; @@ -1606,12 +1606,11 @@ static int length_f(BlockBackend *blk, int argc, ch= ar **argv) size =3D blk_getlength(blk); if (size < 0) { printf("getlength: %s\n", strerror(-size)); - return 0; + return; } =20 cvtstr(size, s1, sizeof(s1)); printf("%s\n", s1); - return 0; } =20 =20 @@ -1623,7 +1622,7 @@ static const cmdinfo_t length_cmd =3D { }; =20 =20 -static int info_f(BlockBackend *blk, int argc, char **argv) +static void info_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); BlockDriverInfo bdi; @@ -1640,7 +1639,7 @@ static int info_f(BlockBackend *blk, int argc, char *= *argv) =20 ret =3D bdrv_get_info(bs, &bdi); if (ret) { - return 0; + return; } =20 cvtstr(bdi.cluster_size, s1, sizeof(s1)); @@ -1655,8 +1654,6 @@ static int info_f(BlockBackend *blk, int argc, char *= *argv) bdrv_image_info_specific_dump(fprintf, stdout, spec_info); qapi_free_ImageInfoSpecific(spec_info); } - - return 0; } =20 =20 @@ -1683,7 +1680,7 @@ static void discard_help(void) "\n"); } =20 -static int discard_f(BlockBackend *blk, int argc, char **argv); +static void discard_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t discard_cmd =3D { .name =3D "discard", @@ -1697,7 +1694,7 @@ static const cmdinfo_t discard_cmd =3D { .help =3D discard_help, }; =20 -static int discard_f(BlockBackend *blk, int argc, char **argv) +static void discard_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1713,30 +1710,32 @@ static int discard_f(BlockBackend *blk, int argc, c= har **argv) qflag =3D true; break; default: - return qemuio_command_usage(&discard_cmd); + qemuio_command_usage(&discard_cmd); + return; } } =20 if (optind !=3D argc - 2) { - return qemuio_command_usage(&discard_cmd); + qemuio_command_usage(&discard_cmd); + return; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return 0; + return; } =20 optind++; bytes =3D cvtnum(argv[optind]); if (bytes < 0) { print_cvtnum_err(bytes, argv[optind]); - return 0; + return; } else if (bytes >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) { printf("length cannot exceed %"PRIu64", given %s\n", (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS, argv[optind]); - return 0; + return; } =20 gettimeofday(&t1, NULL); @@ -1745,7 +1744,7 @@ static int discard_f(BlockBackend *blk, int argc, cha= r **argv) =20 if (ret < 0) { printf("discard failed: %s\n", strerror(-ret)); - goto out; + return; } =20 /* Finally, report back -- -C gives a parsable format */ @@ -1753,12 +1752,9 @@ static int discard_f(BlockBackend *blk, int argc, ch= ar **argv) t2 =3D tsub(t2, t1); print_report("discard", &t2, offset, bytes, bytes, 1, Cflag); } - -out: - return 0; } =20 -static int alloc_f(BlockBackend *blk, int argc, char **argv) +static void alloc_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); int64_t offset, start, remaining, count; @@ -1769,14 +1765,14 @@ static int alloc_f(BlockBackend *blk, int argc, cha= r **argv) start =3D offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return 0; + return; } =20 if (argc =3D=3D 3) { count =3D cvtnum(argv[2]); if (count < 0) { print_cvtnum_err(count, argv[2]); - return 0; + return; } } else { count =3D BDRV_SECTOR_SIZE; @@ -1788,7 +1784,7 @@ static int alloc_f(BlockBackend *blk, int argc, char = **argv) ret =3D bdrv_is_allocated(bs, offset, remaining, &num); if (ret < 0) { printf("is_allocated failed: %s\n", strerror(-ret)); - return 0; + return; } offset +=3D num; remaining -=3D num; @@ -1805,7 +1801,6 @@ static int alloc_f(BlockBackend *blk, int argc, char = **argv) =20 printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n", sum_alloc, count, s1); - return 0; } =20 static const cmdinfo_t alloc_cmd =3D { @@ -1851,7 +1846,7 @@ static int map_is_allocated(BlockDriverState *bs, int= 64_t offset, return firstret; } =20 -static int map_f(BlockBackend *blk, int argc, char **argv) +static void map_f(BlockBackend *blk, int argc, char **argv) { int64_t offset, bytes; char s1[64], s2[64]; @@ -1863,17 +1858,17 @@ static int map_f(BlockBackend *blk, int argc, char = **argv) bytes =3D blk_getlength(blk); if (bytes < 0) { error_report("Failed to query image length: %s", strerror(-bytes)); - return 0; + return; } =20 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; + return; } else if (!num) { error_report("Unexpected end of image"); - return 0; + return; } =20 retstr =3D ret ? " allocated" : "not allocated"; @@ -1885,8 +1880,6 @@ static int map_f(BlockBackend *blk, int argc, char **= argv) offset +=3D num; bytes -=3D num; } - - return 0; } =20 static const cmdinfo_t map_cmd =3D { @@ -1914,7 +1907,7 @@ static void reopen_help(void) "\n"); } =20 -static int reopen_f(BlockBackend *blk, int argc, char **argv); +static void reopen_f(BlockBackend *blk, int argc, char **argv); =20 static QemuOptsList reopen_opts =3D { .name =3D "reopen", @@ -1936,7 +1929,7 @@ static const cmdinfo_t reopen_cmd =3D { .help =3D reopen_help, }; =20 -static int reopen_f(BlockBackend *blk, int argc, char **argv) +static void reopen_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); QemuOpts *qopts; @@ -1954,19 +1947,19 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) case 'c': if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); - return 0; + return; } break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { qemu_opts_reset(&reopen_opts); - return 0; + return; } break; case 'r': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return 0; + return; } flags &=3D ~BDRV_O_RDWR; has_rw_option =3D true; @@ -1974,20 +1967,22 @@ static int reopen_f(BlockBackend *blk, int argc, ch= ar **argv) case 'w': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return 0; + return; } flags |=3D BDRV_O_RDWR; has_rw_option =3D true; break; default: qemu_opts_reset(&reopen_opts); - return qemuio_command_usage(&reopen_cmd); + qemuio_command_usage(&reopen_cmd); + return; } } =20 if (optind !=3D argc) { qemu_opts_reset(&reopen_opts); - return qemuio_command_usage(&reopen_cmd); + qemuio_command_usage(&reopen_cmd); + return; } =20 if (writethrough !=3D blk_enable_write_cache(blk) && @@ -1995,7 +1990,7 @@ static int reopen_f(BlockBackend *blk, int argc, char= **argv) { error_report("Cannot change cache.writeback: Device attached"); qemu_opts_reset(&reopen_opts); - return 0; + return; } =20 if (!(flags & BDRV_O_RDWR)) { @@ -2024,11 +2019,9 @@ static int reopen_f(BlockBackend *blk, int argc, cha= r **argv) } else { blk_set_enable_write_cache(blk, !writethrough); } - - return 0; } =20 -static int break_f(BlockBackend *blk, int argc, char **argv) +static void break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 @@ -2036,11 +2029,9 @@ static int break_f(BlockBackend *blk, int argc, char= **argv) if (ret < 0) { printf("Could not set breakpoint: %s\n", strerror(-ret)); } - - return 0; } =20 -static int remove_break_f(BlockBackend *blk, int argc, char **argv) +static void remove_break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 @@ -2048,8 +2039,6 @@ static int remove_break_f(BlockBackend *blk, int argc= , char **argv) if (ret < 0) { printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-= ret)); } - - return 0; } =20 static const cmdinfo_t break_cmd =3D { @@ -2071,7 +2060,7 @@ static const cmdinfo_t remove_break_cmd =3D { .oneline =3D "remove a breakpoint by tag", }; =20 -static int resume_f(BlockBackend *blk, int argc, char **argv) +static void resume_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 @@ -2079,8 +2068,6 @@ static int resume_f(BlockBackend *blk, int argc, char= **argv) if (ret < 0) { printf("Could not resume request: %s\n", strerror(-ret)); } - - return 0; } =20 static const cmdinfo_t resume_cmd =3D { @@ -2092,13 +2079,11 @@ static const cmdinfo_t resume_cmd =3D { .oneline =3D "resumes the request tagged as tag", }; =20 -static int wait_break_f(BlockBackend *blk, int argc, char **argv) +static void wait_break_f(BlockBackend *blk, int argc, char **argv) { while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) { aio_poll(blk_get_aio_context(blk), true); } - - return 0; } =20 static const cmdinfo_t wait_break_cmd =3D { @@ -2110,7 +2095,7 @@ static const cmdinfo_t wait_break_cmd =3D { .oneline =3D "waits for the suspension of a request", }; =20 -static int abort_f(BlockBackend *blk, int argc, char **argv) +static void abort_f(BlockBackend *blk, int argc, char **argv) { abort(); } @@ -2136,7 +2121,7 @@ static void sigraise_help(void) "\n", SIGTERM); } =20 -static int sigraise_f(BlockBackend *blk, int argc, char **argv); +static void sigraise_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t sigraise_cmd =3D { .name =3D "sigraise", @@ -2149,16 +2134,16 @@ static const cmdinfo_t sigraise_cmd =3D { .help =3D sigraise_help, }; =20 -static int sigraise_f(BlockBackend *blk, int argc, char **argv) +static void sigraise_f(BlockBackend *blk, int argc, char **argv) { int64_t sig =3D cvtnum(argv[1]); if (sig < 0) { print_cvtnum_err(sig, argv[1]); - return 0; + return; } else if (sig > NSIG) { printf("signal argument '%s' is too large to be a valid signal\n", argv[1]); - return 0; + return; } =20 /* Using raise() to kill this process does not necessarily flush all o= pen @@ -2168,7 +2153,6 @@ static int sigraise_f(BlockBackend *blk, int argc, ch= ar **argv) fflush(stderr); =20 raise(sig); - return 0; } =20 static void sleep_cb(void *opaque) @@ -2177,7 +2161,7 @@ static void sleep_cb(void *opaque) *expired =3D true; } =20 -static int sleep_f(BlockBackend *blk, int argc, char **argv) +static void sleep_f(BlockBackend *blk, int argc, char **argv) { char *endptr; long ms; @@ -2187,7 +2171,7 @@ static int sleep_f(BlockBackend *blk, int argc, char = **argv) ms =3D strtol(argv[1], &endptr, 0); if (ms < 0 || *endptr !=3D '\0') { printf("%s is not a valid number\n", argv[1]); - return 0; + return; } =20 timer =3D timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired); @@ -2198,8 +2182,6 @@ static int sleep_f(BlockBackend *blk, int argc, char = **argv) } =20 timer_free(timer); - - return 0; } =20 static const cmdinfo_t sleep_cmd =3D { @@ -2246,23 +2228,22 @@ static void help_all(void) printf("\nUse 'help commandname' for extended help.\n"); } =20 -static int help_f(BlockBackend *blk, int argc, char **argv) +static void help_f(BlockBackend *blk, int argc, char **argv) { const cmdinfo_t *ct; =20 if (argc =3D=3D 1) { help_all(); - return 0; + return; } =20 ct =3D find_command(argv[1]); if (ct =3D=3D NULL) { printf("command %s not found\n", argv[1]); - return 0; + return; } =20 help_onecmd(argv[1], ct); - return 0; } =20 static const cmdinfo_t help_cmd =3D { @@ -2276,14 +2257,13 @@ static const cmdinfo_t help_cmd =3D { .oneline =3D "help for one or all commands", }; =20 -bool qemuio_command(BlockBackend *blk, const char *cmd) +void qemuio_command(BlockBackend *blk, const char *cmd) { AioContext *ctx; char *input; const cmdinfo_t *ct; char **v; int c; - bool done =3D false; =20 input =3D g_strdup(cmd); v =3D breakline(input, &c); @@ -2292,7 +2272,7 @@ bool qemuio_command(BlockBackend *blk, const char *cm= d) if (ct) { ctx =3D blk ? blk_get_aio_context(blk) : qemu_get_aio_context(= ); aio_context_acquire(ctx); - done =3D command(blk, ct, c, v); + command(blk, ct, c, v); aio_context_release(ctx); } else { fprintf(stderr, "command \"%s\" not found\n", v[0]); @@ -2300,8 +2280,6 @@ bool qemuio_command(BlockBackend *blk, const char *cm= d) } g_free(input); g_free(v); - - return done; } =20 static void __attribute((constructor)) init_qemuio_commands(void) diff --git a/qemu-io.c b/qemu-io.c index 73c638ff8b..02a67c929a 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -37,6 +37,7 @@ static char *progname; =20 static BlockBackend *qemuio_blk; +static bool quit_qemu_io; =20 /* qemu-io commands passed using -c */ static int ncmdline; @@ -65,11 +66,10 @@ static int get_eof_char(void) #endif } =20 -static int close_f(BlockBackend *blk, int argc, char **argv) +static void close_f(BlockBackend *blk, int argc, char **argv) { blk_unref(qemuio_blk); qemuio_blk =3D NULL; - return 0; } =20 static const cmdinfo_t close_cmd =3D { @@ -136,7 +136,7 @@ static void open_help(void) "\n"); } =20 -static int open_f(BlockBackend *blk, int argc, char **argv); +static void open_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t open_cmd =3D { .name =3D "open", @@ -160,7 +160,7 @@ static QemuOptsList empty_opts =3D { }, }; =20 -static int open_f(BlockBackend *blk, int argc, char **argv) +static void open_f(BlockBackend *blk, int argc, char **argv) { int flags =3D BDRV_O_UNMAP; int readonly =3D 0; @@ -192,25 +192,25 @@ static int open_f(BlockBackend *blk, int argc, char *= *argv) if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); qemu_opts_reset(&empty_opts); - return 0; + return; } break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { error_report("Invalid discard option: %s", optarg); qemu_opts_reset(&empty_opts); - return 0; + return; } break; case 'o': if (imageOpts) { printf("--image-opts and 'open -o' are mutually exclusive\= n"); qemu_opts_reset(&empty_opts); - return 0; + return; } if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) { qemu_opts_reset(&empty_opts); - return 0; + return; } break; case 'U': @@ -218,7 +218,8 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) break; default: qemu_opts_reset(&empty_opts); - return qemuio_command_usage(&open_cmd); + qemuio_command_usage(&open_cmd); + return; } } =20 @@ -229,7 +230,7 @@ static int open_f(BlockBackend *blk, int argc, char **a= rgv) if (imageOpts && (optind =3D=3D argc - 1)) { if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) { qemu_opts_reset(&empty_opts); - return 0; + return; } optind++; } @@ -246,12 +247,11 @@ static int open_f(BlockBackend *blk, int argc, char *= *argv) qobject_unref(opts); qemuio_command_usage(&open_cmd); } - return 0; } =20 -static int quit_f(BlockBackend *blk, int argc, char **argv) +static void quit_f(BlockBackend *blk, int argc, char **argv) { - return 1; + quit_qemu_io =3D true; } =20 static const cmdinfo_t quit_cmd =3D { @@ -392,18 +392,18 @@ static void prep_fetchline(void *opaque) =20 static void command_loop(void) { - int i, done =3D 0, fetchable =3D 0, prompted =3D 0; + int i, fetchable =3D 0, prompted =3D 0; char *input; =20 - for (i =3D 0; !done && i < ncmdline; i++) { - done =3D qemuio_command(qemuio_blk, cmdline[i]); + for (i =3D 0; !quit_qemu_io && i < ncmdline; i++) { + qemuio_command(qemuio_blk, cmdline[i]); } if (cmdline) { g_free(cmdline); return; } =20 - while (!done) { + while (!quit_qemu_io) { if (!prompted) { printf("%s", get_prompt()); fflush(stdout); @@ -421,7 +421,7 @@ static void command_loop(void) if (input =3D=3D NULL) { break; } - done =3D qemuio_command(qemuio_blk, input); + qemuio_command(qemuio_blk, input); g_free(input); =20 prompted =3D 0; --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152872787650130.084555976803586; Mon, 11 Jun 2018 07:37:56 -0700 (PDT) Received: from localhost ([::1]:49210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNxD-0004dK-KO for importer@patchew.org; Mon, 11 Jun 2018 10:37:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53238) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmZ-0004ju-Rh for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmV-0001pV-D9 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54498 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmM-0001kc-4i; Mon, 11 Jun 2018 10:26:42 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 933A94022905; Mon, 11 Jun 2018 14:26:41 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFCB2202698A; Mon, 11 Jun 2018 14:26:40 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:56 +0200 Message-Id: <20180611142611.6609-15-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:41 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 14/29] qemu-io: Let command functions return error code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This is basically what everything else in the qemu code base does, so we can do it here, too. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509194302.21585-3-mreitz@redhat.com Signed-off-by: Max Reitz --- include/qemu-io.h | 9 +- qemu-io-cmds.c | 346 +++++++++++++++++++++++++++------------------- qemu-io.c | 34 +++-- 3 files changed, 232 insertions(+), 157 deletions(-) diff --git a/include/qemu-io.h b/include/qemu-io.h index 06cdfbf660..7433239372 100644 --- a/include/qemu-io.h +++ b/include/qemu-io.h @@ -22,7 +22,12 @@ =20 #define CMD_FLAG_GLOBAL ((int)0x80000000) /* don't iterate "args" */ =20 -typedef void (*cfunc_t)(BlockBackend *blk, int argc, char **argv); +/* Implement a qemu-io command. + * Operate on @blk using @argc/@argv as the command's arguments, and + * return 0 on success or negative errno on failure. + */ +typedef int (*cfunc_t)(BlockBackend *blk, int argc, char **argv); + typedef void (*helpfunc_t)(void); =20 typedef struct cmdinfo { @@ -41,7 +46,7 @@ typedef struct cmdinfo { =20 extern bool qemuio_misalign; =20 -void qemuio_command(BlockBackend *blk, const char *cmd); +int qemuio_command(BlockBackend *blk, const char *cmd); =20 void qemuio_add_command(const cmdinfo_t *ci); void qemuio_command_usage(const cmdinfo_t *ci); diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c index c2fbaae0fd..5bf5f28178 100644 --- a/qemu-io-cmds.c +++ b/qemu-io-cmds.c @@ -65,13 +65,13 @@ static int init_check_command(BlockBackend *blk, const = cmdinfo_t *ct) return 1; } =20 -static void command(BlockBackend *blk, const cmdinfo_t *ct, int argc, - char **argv) +static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc, + char **argv) { char *cmd =3D argv[0]; =20 if (!init_check_command(blk, ct)) { - return; + return -EINVAL; } =20 if (argc - 1 < ct->argmin || (ct->argmax !=3D -1 && argc - 1 > ct->arg= max)) { @@ -88,7 +88,7 @@ static void command(BlockBackend *blk, const cmdinfo_t *c= t, int argc, "bad argument count %d to %s, expected between %d and = %d arguments\n", argc-1, cmd, ct->argmin, ct->argmax); } - return; + return -EINVAL; } =20 /* Request additional permissions if necessary for this command. The c= aller @@ -108,13 +108,13 @@ static void command(BlockBackend *blk, const cmdinfo_= t *ct, int argc, ret =3D blk_set_perm(blk, new_perm, orig_shared_perm, &local_e= rr); if (ret < 0) { error_report_err(local_err); - return; + return ret; } } } =20 optind =3D 0; - ct->cfunc(blk, argc, argv); + return ct->cfunc(blk, argc, argv); } =20 static const cmdinfo_t *find_command(const char *cmd) @@ -633,7 +633,7 @@ static void read_help(void) "\n"); } =20 -static void read_f(BlockBackend *blk, int argc, char **argv); +static int read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t read_cmd =3D { .name =3D "read", @@ -646,12 +646,12 @@ static const cmdinfo_t read_cmd =3D { .help =3D read_help, }; =20 -static void read_f(BlockBackend *blk, int argc, char **argv) +static int read_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; bool Pflag =3D false, sflag =3D false, lflag =3D false, bflag =3D fals= e; - int c, cnt; + int c, cnt, ret; char *buf; int64_t offset; int64_t count; @@ -673,7 +673,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) pattern_count =3D cvtnum(optarg); if (pattern_count < 0) { print_cvtnum_err(pattern_count, optarg); - return; + return pattern_count; } break; case 'p': @@ -683,7 +683,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; case 'q': @@ -694,7 +694,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) pattern_offset =3D cvtnum(optarg); if (pattern_offset < 0) { print_cvtnum_err(pattern_offset, optarg); - return; + return pattern_offset; } break; case 'v': @@ -702,35 +702,35 @@ static void read_f(BlockBackend *blk, int argc, char = **argv) break; default: qemuio_command_usage(&read_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc - 2) { qemuio_command_usage(&read_cmd); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return; + return count; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return; + return -EINVAL; } =20 if (!Pflag && (lflag || sflag)) { qemuio_command_usage(&read_cmd); - return; + return -EINVAL; } =20 if (!lflag) { @@ -739,19 +739,19 @@ static void read_f(BlockBackend *blk, int argc, char = **argv) =20 if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) { printf("pattern verification range exceeds end of read data\n"); - return; + return -EINVAL; } =20 if (bflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return; + return -EINVAL; } if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return; + return -EINVAL; } } =20 @@ -759,16 +759,19 @@ static void read_f(BlockBackend *blk, int argc, char = **argv) =20 gettimeofday(&t1, NULL); if (bflag) { - cnt =3D do_load_vmstate(blk, buf, offset, count, &total); + ret =3D do_load_vmstate(blk, buf, offset, count, &total); } else { - cnt =3D do_pread(blk, buf, offset, count, &total); + ret =3D do_pread(blk, buf, offset, count, &total); } gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("read failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("read failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (Pflag) { void *cmp_buf =3D g_malloc(pattern_count); @@ -777,6 +780,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) printf("Pattern verification failed at offset %" PRId64 ", %"PRId64" bytes\n", offset + pattern_offset, pattern_count); + ret =3D -EINVAL; } g_free(cmp_buf); } @@ -795,6 +799,7 @@ static void read_f(BlockBackend *blk, int argc, char **= argv) =20 out: qemu_io_free(buf); + return ret; } =20 static void readv_help(void) @@ -816,7 +821,7 @@ static void readv_help(void) "\n"); } =20 -static void readv_f(BlockBackend *blk, int argc, char **argv); +static int readv_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t readv_cmd =3D { .name =3D "readv", @@ -828,11 +833,11 @@ static const cmdinfo_t readv_cmd =3D { .help =3D readv_help, }; =20 -static void readv_f(BlockBackend *blk, int argc, char **argv) +static int readv_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, vflag =3D false; - int c, cnt; + int c, cnt, ret; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ @@ -851,7 +856,7 @@ static void readv_f(BlockBackend *blk, int argc, char *= *argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; case 'q': @@ -862,37 +867,40 @@ static void readv_f(BlockBackend *blk, int argc, char= **argv) break; default: qemuio_command_usage(&readv_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { qemuio_command_usage(&readv_cmd); - return; + return -EINVAL; } =20 =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab); if (buf =3D=3D NULL) { - return; + return -EINVAL; } =20 gettimeofday(&t1, NULL); - cnt =3D do_aio_readv(blk, &qiov, offset, &total); + ret =3D do_aio_readv(blk, &qiov, offset, &total); gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("readv failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("readv failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (Pflag) { void *cmp_buf =3D g_malloc(qiov.size); @@ -900,6 +908,7 @@ static void readv_f(BlockBackend *blk, int argc, char *= *argv) if (memcmp(buf, cmp_buf, qiov.size)) { printf("Pattern verification failed at offset %" PRId64 ", %zd bytes\n", offset, qiov.size); + ret =3D -EINVAL; } g_free(cmp_buf); } @@ -919,6 +928,7 @@ static void readv_f(BlockBackend *blk, int argc, char *= *argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); + return ret; } =20 static void write_help(void) @@ -944,7 +954,7 @@ static void write_help(void) "\n"); } =20 -static void write_f(BlockBackend *blk, int argc, char **argv); +static int write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t write_cmd =3D { .name =3D "write", @@ -958,13 +968,13 @@ static const cmdinfo_t write_cmd =3D { .help =3D write_help, }; =20 -static void write_f(BlockBackend *blk, int argc, char **argv) +static int write_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false, bflag =3D false; bool Pflag =3D false, zflag =3D false, cflag =3D false; int flags =3D 0; - int c, cnt; + int c, cnt, ret; char *buf =3D NULL; int64_t offset; int64_t count; @@ -993,7 +1003,7 @@ static void write_f(BlockBackend *blk, int argc, char = **argv) Pflag =3D true; pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; case 'q': @@ -1007,63 +1017,63 @@ static void write_f(BlockBackend *blk, int argc, ch= ar **argv) break; default: qemuio_command_usage(&write_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc - 2) { qemuio_command_usage(&write_cmd); - return; + return -EINVAL; } =20 if (bflag && zflag) { printf("-b and -z cannot be specified at the same time\n"); - return; + return -EINVAL; } =20 if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) { printf("-f and -b or -c cannot be specified at the same time\n"); - return; + return -EINVAL; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) { printf("-u requires -z to be specified\n"); - return; + return -EINVAL; } =20 if (zflag && Pflag) { printf("-z and -P cannot be specified at the same time\n"); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } =20 optind++; count =3D cvtnum(argv[optind]); if (count < 0) { print_cvtnum_err(count, argv[optind]); - return; + return count; } else if (count > BDRV_REQUEST_MAX_BYTES) { printf("length cannot exceed %" PRIu64 ", given %s\n", (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]); - return; + return -EINVAL; } =20 if (bflag || cflag) { if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) { printf("%" PRId64 " is not a sector-aligned value for 'offset'= \n", offset); - return; + return -EINVAL; } =20 if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) { printf("%"PRId64" is not a sector-aligned value for 'count'\n", count); - return; + return -EINVAL; } } =20 @@ -1073,20 +1083,23 @@ static void write_f(BlockBackend *blk, int argc, ch= ar **argv) =20 gettimeofday(&t1, NULL); if (bflag) { - cnt =3D do_save_vmstate(blk, buf, offset, count, &total); + ret =3D do_save_vmstate(blk, buf, offset, count, &total); } else if (zflag) { - cnt =3D do_co_pwrite_zeroes(blk, offset, count, flags, &total); + ret =3D do_co_pwrite_zeroes(blk, offset, count, flags, &total); } else if (cflag) { - cnt =3D do_write_compressed(blk, buf, offset, count, &total); + ret =3D do_write_compressed(blk, buf, offset, count, &total); } else { - cnt =3D do_pwrite(blk, buf, offset, count, flags, &total); + ret =3D do_pwrite(blk, buf, offset, count, flags, &total); } gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("write failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("write failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (qflag) { goto out; @@ -1100,6 +1113,7 @@ out: if (!zflag) { qemu_io_free(buf); } + return ret; } =20 static void @@ -1121,7 +1135,7 @@ writev_help(void) "\n"); } =20 -static void writev_f(BlockBackend *blk, int argc, char **argv); +static int writev_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t writev_cmd =3D { .name =3D "writev", @@ -1134,12 +1148,12 @@ static const cmdinfo_t writev_cmd =3D { .help =3D writev_help, }; =20 -static void writev_f(BlockBackend *blk, int argc, char **argv) +static int writev_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; int flags =3D 0; - int c, cnt; + int c, cnt, ret; char *buf; int64_t offset; /* Some compilers get confused and warn if this is not initialized. */ @@ -1162,41 +1176,44 @@ static void writev_f(BlockBackend *blk, int argc, c= har **argv) case 'P': pattern =3D parse_pattern(optarg); if (pattern < 0) { - return; + return -EINVAL; } break; default: qemuio_command_usage(&writev_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { qemuio_command_usage(&writev_cmd); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } optind++; =20 nr_iov =3D argc - optind; buf =3D create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern); if (buf =3D=3D NULL) { - return; + return -EINVAL; } =20 gettimeofday(&t1, NULL); - cnt =3D do_aio_writev(blk, &qiov, offset, flags, &total); + ret =3D do_aio_writev(blk, &qiov, offset, flags, &total); gettimeofday(&t2, NULL); =20 - if (cnt < 0) { - printf("writev failed: %s\n", strerror(-cnt)); + if (ret < 0) { + printf("writev failed: %s\n", strerror(-ret)); goto out; } + cnt =3D ret; + + ret =3D 0; =20 if (qflag) { goto out; @@ -1208,6 +1225,7 @@ static void writev_f(BlockBackend *blk, int argc, cha= r **argv) out: qemu_iovec_destroy(&qiov); qemu_io_free(buf); + return ret; } =20 struct aio_ctx { @@ -1314,6 +1332,9 @@ static void aio_read_help(void) " standard output stream (with -v option) for subsequent inspection.\n" " The read is performed asynchronously and the aio_flush command must be\n" " used to ensure all outstanding aio requests have been completed.\n" +" Note that due to its asynchronous nature, this command will be\n" +" considered successful once the request is submitted, independently\n" +" of potential I/O errors or pattern mismatches.\n" " -C, -- report statistics in a machine parsable format\n" " -P, -- use a pattern to verify read data\n" " -i, -- treat request as invalid, for exercising stats\n" @@ -1322,7 +1343,7 @@ static void aio_read_help(void) "\n"); } =20 -static void aio_read_f(BlockBackend *blk, int argc, char **argv); +static int aio_read_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_read_cmd =3D { .name =3D "aio_read", @@ -1334,7 +1355,7 @@ static const cmdinfo_t aio_read_cmd =3D { .help =3D aio_read_help, }; =20 -static void aio_read_f(BlockBackend *blk, int argc, char **argv) +static int aio_read_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; struct aio_ctx *ctx =3D g_new0(struct aio_ctx, 1); @@ -1350,14 +1371,14 @@ static void aio_read_f(BlockBackend *blk, int argc,= char **argv) ctx->pattern =3D parse_pattern(optarg); if (ctx->pattern < 0) { g_free(ctx); - return; + return -EINVAL; } break; case 'i': printf("injecting invalid read request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return; + return 0; case 'q': ctx->qflag =3D true; break; @@ -1367,21 +1388,22 @@ static void aio_read_f(BlockBackend *blk, int argc,= char **argv) default: g_free(ctx); qemuio_command_usage(&aio_read_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { g_free(ctx); qemuio_command_usage(&aio_read_cmd); - return; + return -EINVAL; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { - print_cvtnum_err(ctx->offset, argv[optind]); + int ret =3D ctx->offset; + print_cvtnum_err(ret, argv[optind]); g_free(ctx); - return; + return ret; } optind++; =20 @@ -1390,13 +1412,14 @@ static void aio_read_f(BlockBackend *blk, int argc,= char **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ); g_free(ctx); - return; + return -EINVAL; } =20 gettimeofday(&ctx->t1, NULL); block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size, BLOCK_ACCT_READ); blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx); + return 0; } =20 static void aio_write_help(void) @@ -1413,6 +1436,9 @@ static void aio_write_help(void) " filled with a set pattern (0xcdcdcdcd).\n" " The write is performed asynchronously and the aio_flush command must be\= n" " used to ensure all outstanding aio requests have been completed.\n" +" Note that due to its asynchronous nature, this command will be\n" +" considered successful once the request is submitted, independently\n" +" of potential I/O errors or pattern mismatches.\n" " -P, -- use different pattern to fill file\n" " -C, -- report statistics in a machine parsable format\n" " -f, -- use Force Unit Access semantics\n" @@ -1423,7 +1449,7 @@ static void aio_write_help(void) "\n"); } =20 -static void aio_write_f(BlockBackend *blk, int argc, char **argv); +static int aio_write_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t aio_write_cmd =3D { .name =3D "aio_write", @@ -1436,7 +1462,7 @@ static const cmdinfo_t aio_write_cmd =3D { .help =3D aio_write_help, }; =20 -static void aio_write_f(BlockBackend *blk, int argc, char **argv) +static int aio_write_f(BlockBackend *blk, int argc, char **argv) { int nr_iov, c; int pattern =3D 0xcd; @@ -1462,53 +1488,54 @@ static void aio_write_f(BlockBackend *blk, int argc= , char **argv) pattern =3D parse_pattern(optarg); if (pattern < 0) { g_free(ctx); - return; + return -EINVAL; } break; case 'i': printf("injecting invalid write request\n"); block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return; + return 0; case 'z': ctx->zflag =3D true; break; default: g_free(ctx); qemuio_command_usage(&aio_write_cmd); - return; + return -EINVAL; } } =20 if (optind > argc - 2) { g_free(ctx); qemuio_command_usage(&aio_write_cmd); - return; + return -EINVAL; } =20 if (ctx->zflag && optind !=3D argc - 2) { printf("-z supports only a single length parameter\n"); g_free(ctx); - return; + return -EINVAL; } =20 if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) { printf("-u requires -z to be specified\n"); g_free(ctx); - return; + return -EINVAL; } =20 if (ctx->zflag && ctx->Pflag) { printf("-z and -P cannot be specified at the same time\n"); g_free(ctx); - return; + return -EINVAL; } =20 ctx->offset =3D cvtnum(argv[optind]); if (ctx->offset < 0) { - print_cvtnum_err(ctx->offset, argv[optind]); + int ret =3D ctx->offset; + print_cvtnum_err(ret, argv[optind]); g_free(ctx); - return; + return ret; } optind++; =20 @@ -1517,7 +1544,7 @@ static void aio_write_f(BlockBackend *blk, int argc, = char **argv) if (count < 0) { print_cvtnum_err(count, argv[optind]); g_free(ctx); - return; + return count; } =20 ctx->qiov.size =3D count; @@ -1530,7 +1557,7 @@ static void aio_write_f(BlockBackend *blk, int argc, = char **argv) if (ctx->buf =3D=3D NULL) { block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE); g_free(ctx); - return; + return -EINVAL; } =20 gettimeofday(&ctx->t1, NULL); @@ -1540,14 +1567,17 @@ static void aio_write_f(BlockBackend *blk, int argc= , char **argv) blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_don= e, ctx); } + + return 0; } =20 -static void aio_flush_f(BlockBackend *blk, int argc, char **argv) +static int aio_flush_f(BlockBackend *blk, int argc, char **argv) { BlockAcctCookie cookie; block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH); blk_drain_all(); block_acct_done(blk_get_stats(blk), &cookie); + return 0; } =20 static const cmdinfo_t aio_flush_cmd =3D { @@ -1556,9 +1586,9 @@ static const cmdinfo_t aio_flush_cmd =3D { .oneline =3D "completes all outstanding aio requests" }; =20 -static void flush_f(BlockBackend *blk, int argc, char **argv) +static int flush_f(BlockBackend *blk, int argc, char **argv) { - blk_flush(blk); + return blk_flush(blk); } =20 static const cmdinfo_t flush_cmd =3D { @@ -1568,7 +1598,7 @@ static const cmdinfo_t flush_cmd =3D { .oneline =3D "flush all in-core file state to disk", }; =20 -static void truncate_f(BlockBackend *blk, int argc, char **argv) +static int truncate_f(BlockBackend *blk, int argc, char **argv) { Error *local_err =3D NULL; int64_t offset; @@ -1577,14 +1607,16 @@ static void truncate_f(BlockBackend *blk, int argc,= char **argv) offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return; + return offset; } =20 ret =3D blk_truncate(blk, offset, PREALLOC_MODE_OFF, &local_err); if (ret < 0) { error_report_err(local_err); - return; + return ret; } + + return 0; } =20 static const cmdinfo_t truncate_cmd =3D { @@ -1598,7 +1630,7 @@ static const cmdinfo_t truncate_cmd =3D { .oneline =3D "truncates the current file at the given offset", }; =20 -static void length_f(BlockBackend *blk, int argc, char **argv) +static int length_f(BlockBackend *blk, int argc, char **argv) { int64_t size; char s1[64]; @@ -1606,11 +1638,12 @@ static void length_f(BlockBackend *blk, int argc, c= har **argv) size =3D blk_getlength(blk); if (size < 0) { printf("getlength: %s\n", strerror(-size)); - return; + return size; } =20 cvtstr(size, s1, sizeof(s1)); printf("%s\n", s1); + return 0; } =20 =20 @@ -1622,7 +1655,7 @@ static const cmdinfo_t length_cmd =3D { }; =20 =20 -static void info_f(BlockBackend *blk, int argc, char **argv) +static int info_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); BlockDriverInfo bdi; @@ -1639,7 +1672,7 @@ static void info_f(BlockBackend *blk, int argc, char = **argv) =20 ret =3D bdrv_get_info(bs, &bdi); if (ret) { - return; + return ret; } =20 cvtstr(bdi.cluster_size, s1, sizeof(s1)); @@ -1654,6 +1687,8 @@ static void info_f(BlockBackend *blk, int argc, char = **argv) bdrv_image_info_specific_dump(fprintf, stdout, spec_info); qapi_free_ImageInfoSpecific(spec_info); } + + return 0; } =20 =20 @@ -1680,7 +1715,7 @@ static void discard_help(void) "\n"); } =20 -static void discard_f(BlockBackend *blk, int argc, char **argv); +static int discard_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t discard_cmd =3D { .name =3D "discard", @@ -1694,7 +1729,7 @@ static const cmdinfo_t discard_cmd =3D { .help =3D discard_help, }; =20 -static void discard_f(BlockBackend *blk, int argc, char **argv) +static int discard_f(BlockBackend *blk, int argc, char **argv) { struct timeval t1, t2; bool Cflag =3D false, qflag =3D false; @@ -1711,31 +1746,31 @@ static void discard_f(BlockBackend *blk, int argc, = char **argv) break; default: qemuio_command_usage(&discard_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc - 2) { qemuio_command_usage(&discard_cmd); - return; + return -EINVAL; } =20 offset =3D cvtnum(argv[optind]); if (offset < 0) { print_cvtnum_err(offset, argv[optind]); - return; + return offset; } =20 optind++; bytes =3D cvtnum(argv[optind]); if (bytes < 0) { print_cvtnum_err(bytes, argv[optind]); - return; + return bytes; } else if (bytes >> BDRV_SECTOR_BITS > BDRV_REQUEST_MAX_SECTORS) { printf("length cannot exceed %"PRIu64", given %s\n", (uint64_t)BDRV_REQUEST_MAX_SECTORS << BDRV_SECTOR_BITS, argv[optind]); - return; + return -EINVAL; } =20 gettimeofday(&t1, NULL); @@ -1744,7 +1779,7 @@ static void discard_f(BlockBackend *blk, int argc, ch= ar **argv) =20 if (ret < 0) { printf("discard failed: %s\n", strerror(-ret)); - return; + return ret; } =20 /* Finally, report back -- -C gives a parsable format */ @@ -1752,9 +1787,11 @@ static void discard_f(BlockBackend *blk, int argc, c= har **argv) t2 =3D tsub(t2, t1); print_report("discard", &t2, offset, bytes, bytes, 1, Cflag); } + + return 0; } =20 -static void alloc_f(BlockBackend *blk, int argc, char **argv) +static int alloc_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); int64_t offset, start, remaining, count; @@ -1765,14 +1802,14 @@ static void alloc_f(BlockBackend *blk, int argc, ch= ar **argv) start =3D offset =3D cvtnum(argv[1]); if (offset < 0) { print_cvtnum_err(offset, argv[1]); - return; + return offset; } =20 if (argc =3D=3D 3) { count =3D cvtnum(argv[2]); if (count < 0) { print_cvtnum_err(count, argv[2]); - return; + return count; } } else { count =3D BDRV_SECTOR_SIZE; @@ -1784,7 +1821,7 @@ static void alloc_f(BlockBackend *blk, int argc, char= **argv) ret =3D bdrv_is_allocated(bs, offset, remaining, &num); if (ret < 0) { printf("is_allocated failed: %s\n", strerror(-ret)); - return; + return ret; } offset +=3D num; remaining -=3D num; @@ -1801,6 +1838,7 @@ static void alloc_f(BlockBackend *blk, int argc, char= **argv) =20 printf("%"PRId64"/%"PRId64" bytes allocated at offset %s\n", sum_alloc, count, s1); + return 0; } =20 static const cmdinfo_t alloc_cmd =3D { @@ -1846,7 +1884,7 @@ static int map_is_allocated(BlockDriverState *bs, int= 64_t offset, return firstret; } =20 -static void map_f(BlockBackend *blk, int argc, char **argv) +static int map_f(BlockBackend *blk, int argc, char **argv) { int64_t offset, bytes; char s1[64], s2[64]; @@ -1858,17 +1896,17 @@ static void map_f(BlockBackend *blk, int argc, char= **argv) bytes =3D blk_getlength(blk); if (bytes < 0) { error_report("Failed to query image length: %s", strerror(-bytes)); - return; + return bytes; } =20 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; + return ret; } else if (!num) { error_report("Unexpected end of image"); - return; + return -EIO; } =20 retstr =3D ret ? " allocated" : "not allocated"; @@ -1880,6 +1918,8 @@ static void map_f(BlockBackend *blk, int argc, char *= *argv) offset +=3D num; bytes -=3D num; } + + return 0; } =20 static const cmdinfo_t map_cmd =3D { @@ -1907,7 +1947,7 @@ static void reopen_help(void) "\n"); } =20 -static void reopen_f(BlockBackend *blk, int argc, char **argv); +static int reopen_f(BlockBackend *blk, int argc, char **argv); =20 static QemuOptsList reopen_opts =3D { .name =3D "reopen", @@ -1929,7 +1969,7 @@ static const cmdinfo_t reopen_cmd =3D { .help =3D reopen_help, }; =20 -static void reopen_f(BlockBackend *blk, int argc, char **argv) +static int reopen_f(BlockBackend *blk, int argc, char **argv) { BlockDriverState *bs =3D blk_bs(blk); QemuOpts *qopts; @@ -1947,19 +1987,19 @@ static void reopen_f(BlockBackend *blk, int argc, c= har **argv) case 'c': if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); - return; + return -EINVAL; } break; case 'o': if (!qemu_opts_parse_noisily(&reopen_opts, optarg, 0)) { qemu_opts_reset(&reopen_opts); - return; + return -EINVAL; } break; case 'r': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return; + return -EINVAL; } flags &=3D ~BDRV_O_RDWR; has_rw_option =3D true; @@ -1967,7 +2007,7 @@ static void reopen_f(BlockBackend *blk, int argc, cha= r **argv) case 'w': if (has_rw_option) { error_report("Only one -r/-w option may be given"); - return; + return -EINVAL; } flags |=3D BDRV_O_RDWR; has_rw_option =3D true; @@ -1975,14 +2015,14 @@ static void reopen_f(BlockBackend *blk, int argc, c= har **argv) default: qemu_opts_reset(&reopen_opts); qemuio_command_usage(&reopen_cmd); - return; + return -EINVAL; } } =20 if (optind !=3D argc) { qemu_opts_reset(&reopen_opts); qemuio_command_usage(&reopen_cmd); - return; + return -EINVAL; } =20 if (writethrough !=3D blk_enable_write_cache(blk) && @@ -1990,7 +2030,7 @@ static void reopen_f(BlockBackend *blk, int argc, cha= r **argv) { error_report("Cannot change cache.writeback: Device attached"); qemu_opts_reset(&reopen_opts); - return; + return -EBUSY; } =20 if (!(flags & BDRV_O_RDWR)) { @@ -2016,29 +2056,37 @@ static void reopen_f(BlockBackend *blk, int argc, c= har **argv) =20 if (local_err) { error_report_err(local_err); - } else { - blk_set_enable_write_cache(blk, !writethrough); + return -EINVAL; } + + blk_set_enable_write_cache(blk, !writethrough); + return 0; } =20 -static void break_f(BlockBackend *blk, int argc, char **argv) +static int break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 ret =3D bdrv_debug_breakpoint(blk_bs(blk), argv[1], argv[2]); if (ret < 0) { printf("Could not set breakpoint: %s\n", strerror(-ret)); + return ret; } + + return 0; } =20 -static void remove_break_f(BlockBackend *blk, int argc, char **argv) +static int remove_break_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 ret =3D bdrv_debug_remove_breakpoint(blk_bs(blk), argv[1]); if (ret < 0) { printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-= ret)); + return ret; } + + return 0; } =20 static const cmdinfo_t break_cmd =3D { @@ -2060,14 +2108,17 @@ static const cmdinfo_t remove_break_cmd =3D { .oneline =3D "remove a breakpoint by tag", }; =20 -static void resume_f(BlockBackend *blk, int argc, char **argv) +static int resume_f(BlockBackend *blk, int argc, char **argv) { int ret; =20 ret =3D bdrv_debug_resume(blk_bs(blk), argv[1]); if (ret < 0) { printf("Could not resume request: %s\n", strerror(-ret)); + return ret; } + + return 0; } =20 static const cmdinfo_t resume_cmd =3D { @@ -2079,11 +2130,12 @@ static const cmdinfo_t resume_cmd =3D { .oneline =3D "resumes the request tagged as tag", }; =20 -static void wait_break_f(BlockBackend *blk, int argc, char **argv) +static int wait_break_f(BlockBackend *blk, int argc, char **argv) { while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) { aio_poll(blk_get_aio_context(blk), true); } + return 0; } =20 static const cmdinfo_t wait_break_cmd =3D { @@ -2095,7 +2147,7 @@ static const cmdinfo_t wait_break_cmd =3D { .oneline =3D "waits for the suspension of a request", }; =20 -static void abort_f(BlockBackend *blk, int argc, char **argv) +static int abort_f(BlockBackend *blk, int argc, char **argv) { abort(); } @@ -2121,7 +2173,7 @@ static void sigraise_help(void) "\n", SIGTERM); } =20 -static void sigraise_f(BlockBackend *blk, int argc, char **argv); +static int sigraise_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t sigraise_cmd =3D { .name =3D "sigraise", @@ -2134,16 +2186,16 @@ static const cmdinfo_t sigraise_cmd =3D { .help =3D sigraise_help, }; =20 -static void sigraise_f(BlockBackend *blk, int argc, char **argv) +static int sigraise_f(BlockBackend *blk, int argc, char **argv) { int64_t sig =3D cvtnum(argv[1]); if (sig < 0) { print_cvtnum_err(sig, argv[1]); - return; + return sig; } else if (sig > NSIG) { printf("signal argument '%s' is too large to be a valid signal\n", argv[1]); - return; + return -EINVAL; } =20 /* Using raise() to kill this process does not necessarily flush all o= pen @@ -2153,6 +2205,8 @@ static void sigraise_f(BlockBackend *blk, int argc, c= har **argv) fflush(stderr); =20 raise(sig); + + return 0; } =20 static void sleep_cb(void *opaque) @@ -2161,7 +2215,7 @@ static void sleep_cb(void *opaque) *expired =3D true; } =20 -static void sleep_f(BlockBackend *blk, int argc, char **argv) +static int sleep_f(BlockBackend *blk, int argc, char **argv) { char *endptr; long ms; @@ -2171,7 +2225,7 @@ static void sleep_f(BlockBackend *blk, int argc, char= **argv) ms =3D strtol(argv[1], &endptr, 0); if (ms < 0 || *endptr !=3D '\0') { printf("%s is not a valid number\n", argv[1]); - return; + return -EINVAL; } =20 timer =3D timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired); @@ -2182,6 +2236,7 @@ static void sleep_f(BlockBackend *blk, int argc, char= **argv) } =20 timer_free(timer); + return 0; } =20 static const cmdinfo_t sleep_cmd =3D { @@ -2228,22 +2283,23 @@ static void help_all(void) printf("\nUse 'help commandname' for extended help.\n"); } =20 -static void help_f(BlockBackend *blk, int argc, char **argv) +static int help_f(BlockBackend *blk, int argc, char **argv) { const cmdinfo_t *ct; =20 if (argc =3D=3D 1) { help_all(); - return; + return 0; } =20 ct =3D find_command(argv[1]); if (ct =3D=3D NULL) { printf("command %s not found\n", argv[1]); - return; + return -EINVAL; } =20 help_onecmd(argv[1], ct); + return 0; } =20 static const cmdinfo_t help_cmd =3D { @@ -2257,13 +2313,14 @@ static const cmdinfo_t help_cmd =3D { .oneline =3D "help for one or all commands", }; =20 -void qemuio_command(BlockBackend *blk, const char *cmd) +int qemuio_command(BlockBackend *blk, const char *cmd) { AioContext *ctx; char *input; const cmdinfo_t *ct; char **v; int c; + int ret =3D 0; =20 input =3D g_strdup(cmd); v =3D breakline(input, &c); @@ -2272,14 +2329,17 @@ void qemuio_command(BlockBackend *blk, const char *= cmd) if (ct) { ctx =3D blk ? blk_get_aio_context(blk) : qemu_get_aio_context(= ); aio_context_acquire(ctx); - command(blk, ct, c, v); + ret =3D command(blk, ct, c, v); aio_context_release(ctx); } else { fprintf(stderr, "command \"%s\" not found\n", v[0]); + ret =3D -EINVAL; } } g_free(input); g_free(v); + + return ret; } =20 static void __attribute((constructor)) init_qemuio_commands(void) diff --git a/qemu-io.c b/qemu-io.c index 02a67c929a..ec6683803f 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -66,10 +66,11 @@ static int get_eof_char(void) #endif } =20 -static void close_f(BlockBackend *blk, int argc, char **argv) +static int close_f(BlockBackend *blk, int argc, char **argv) { blk_unref(qemuio_blk); qemuio_blk =3D NULL; + return 0; } =20 static const cmdinfo_t close_cmd =3D { @@ -136,7 +137,7 @@ static void open_help(void) "\n"); } =20 -static void open_f(BlockBackend *blk, int argc, char **argv); +static int open_f(BlockBackend *blk, int argc, char **argv); =20 static const cmdinfo_t open_cmd =3D { .name =3D "open", @@ -160,12 +161,13 @@ static QemuOptsList empty_opts =3D { }, }; =20 -static void open_f(BlockBackend *blk, int argc, char **argv) +static int open_f(BlockBackend *blk, int argc, char **argv) { int flags =3D BDRV_O_UNMAP; int readonly =3D 0; bool writethrough =3D true; int c; + int ret; QemuOpts *qopts; QDict *opts; bool force_share =3D false; @@ -192,25 +194,25 @@ static void open_f(BlockBackend *blk, int argc, char = **argv) if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) { error_report("Invalid cache option: %s", optarg); qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } break; case 'd': if (bdrv_parse_discard_flags(optarg, &flags) < 0) { error_report("Invalid discard option: %s", optarg); qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } break; case 'o': if (imageOpts) { printf("--image-opts and 'open -o' are mutually exclusive\= n"); qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } if (!qemu_opts_parse_noisily(&empty_opts, optarg, false)) { qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } break; case 'U': @@ -219,7 +221,7 @@ static void open_f(BlockBackend *blk, int argc, char **= argv) default: qemu_opts_reset(&empty_opts); qemuio_command_usage(&open_cmd); - return; + return -EINVAL; } } =20 @@ -230,7 +232,7 @@ static void open_f(BlockBackend *blk, int argc, char **= argv) if (imageOpts && (optind =3D=3D argc - 1)) { if (!qemu_opts_parse_noisily(&empty_opts, argv[optind], false)) { qemu_opts_reset(&empty_opts); - return; + return -EINVAL; } optind++; } @@ -240,18 +242,26 @@ static void open_f(BlockBackend *blk, int argc, char = **argv) qemu_opts_reset(&empty_opts); =20 if (optind =3D=3D argc - 1) { - openfile(argv[optind], flags, writethrough, force_share, opts); + ret =3D openfile(argv[optind], flags, writethrough, force_share, o= pts); } else if (optind =3D=3D argc) { - openfile(NULL, flags, writethrough, force_share, opts); + ret =3D openfile(NULL, flags, writethrough, force_share, opts); } else { qobject_unref(opts); qemuio_command_usage(&open_cmd); + return -EINVAL; + } + + if (ret) { + return -EINVAL; } + + return 0; } =20 -static void quit_f(BlockBackend *blk, int argc, char **argv) +static int quit_f(BlockBackend *blk, int argc, char **argv) { quit_qemu_io =3D true; + return 0; } =20 static const cmdinfo_t quit_cmd =3D { --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528727951476272.7964075669971; Mon, 11 Jun 2018 07:39:11 -0700 (PDT) Received: from localhost ([::1]:49213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNyQ-0005d2-KV for importer@patchew.org; Mon, 11 Jun 2018 10:39:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53109) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmR-0004d2-Qk for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmQ-0001n0-Qf for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:47 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35294 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmN-0001lW-Re; Mon, 11 Jun 2018 10:26:43 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73F8A8011059; Mon, 11 Jun 2018 14:26:43 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1F0772028672; Mon, 11 Jun 2018 14:26:42 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:57 +0200 Message-Id: <20180611142611.6609-16-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 11 Jun 2018 14:26:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 11 Jun 2018 14:26:43 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 15/29] qemu-io: Exit with error when a command failed X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Currently, qemu-io basically always returns success when it gets to interactive mode (so once the whole command line has been parsed; even before the commands on the command line are interpreted). That is not very useful. This patch makes qemu-io return failure when any of the executed commands failed. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1519617 Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509194302.21585-4-mreitz@redhat.com Signed-off-by: Max Reitz --- qemu-io.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/qemu-io.c b/qemu-io.c index ec6683803f..13829f5e21 100644 --- a/qemu-io.c +++ b/qemu-io.c @@ -400,17 +400,21 @@ static void prep_fetchline(void *opaque) *fetchable=3D 1; } =20 -static void command_loop(void) +static int command_loop(void) { int i, fetchable =3D 0, prompted =3D 0; + int ret, last_error =3D 0; char *input; =20 for (i =3D 0; !quit_qemu_io && i < ncmdline; i++) { - qemuio_command(qemuio_blk, cmdline[i]); + ret =3D qemuio_command(qemuio_blk, cmdline[i]); + if (ret < 0) { + last_error =3D ret; + } } if (cmdline) { g_free(cmdline); - return; + return last_error; } =20 while (!quit_qemu_io) { @@ -431,13 +435,19 @@ static void command_loop(void) if (input =3D=3D NULL) { break; } - qemuio_command(qemuio_blk, input); + ret =3D qemuio_command(qemuio_blk, input); g_free(input); =20 + if (ret < 0) { + last_error =3D ret; + } + prompted =3D 0; fetchable =3D 0; } qemu_set_fd_handler(STDIN_FILENO, NULL, NULL, NULL); + + return last_error; } =20 static void add_user_command(char *optarg) @@ -502,6 +512,7 @@ int main(int argc, char **argv) int c; int opt_index =3D 0; int flags =3D BDRV_O_UNMAP; + int ret; bool writethrough =3D true; Error *local_error =3D NULL; QDict *opts =3D NULL; @@ -663,7 +674,7 @@ int main(int argc, char **argv) } } } - command_loop(); + ret =3D command_loop(); =20 /* * Make sure all outstanding requests complete before the program exit= s. @@ -672,5 +683,10 @@ int main(int argc, char **argv) =20 blk_unref(qemuio_blk); g_free(readline_state); - return 0; + + if (ret < 0) { + return 1; + } else { + return 0; + } } --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728135703950.0958650872597; Mon, 11 Jun 2018 07:42:15 -0700 (PDT) Received: from localhost ([::1]:49241 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO1O-0008Id-VK for importer@patchew.org; Mon, 11 Jun 2018 10:42:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmW-0004h9-Jr for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmU-0001or-RN for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:51 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:55656 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmP-0001mF-Op; Mon, 11 Jun 2018 10:26:45 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BB664002248; Mon, 11 Jun 2018 14:26:45 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0670B8442A; Mon, 11 Jun 2018 14:26:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:58 +0200 Message-Id: <20180611142611.6609-17-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 11 Jun 2018 14:26:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 16/29] iotests.py: Add qemu_io_silent X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" With qemu-io now returning a useful exit code, some tests may find it sufficient to just query that instead of logging (and filtering) the whole output. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509194302.21585-5-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index fdbdd8b300..0b204dc220 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -133,6 +133,15 @@ def qemu_io(*args): sys.stderr.write('qemu-io received signal %i: %s\n' % (-exitcode, = ' '.join(args))) return subp.communicate()[0] =20 +def qemu_io_silent(*args): + '''Run qemu-io and return the exit code, suppressing stdout''' + args =3D qemu_io_args + list(args) + exitcode =3D subprocess.call(args, stdout=3Dopen('/dev/null', 'w')) + if exitcode < 0: + sys.stderr.write('qemu-io received signal %i: %s\n' % + (-exitcode, ' '.join(args))) + return exitcode + =20 class QemuIoInteractive: def __init__(self, *args): --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728281628472.4200407219105; Mon, 11 Jun 2018 07:44:41 -0700 (PDT) Received: from localhost ([::1]:49266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO3k-00023y-Uv for importer@patchew.org; Mon, 11 Jun 2018 10:44:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmV-0004gT-3U for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmU-0001oV-03 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:51 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54508 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmR-0001nF-LW; Mon, 11 Jun 2018 10:26:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4090A4022931; Mon, 11 Jun 2018 14:26:47 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFDBD2028672; Mon, 11 Jun 2018 14:26:46 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:25:59 +0200 Message-Id: <20180611142611.6609-18-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:47 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 17/29] iotests: Let 216 make use of qemu-io's exit code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" As a showcase of how you can use qemu-io's exit code to determine success or failure (same for qemu-img), this test is changed to use qemu_io_silent() instead of qemu_io(), and to assert the exit code instead of logging the filtered result. One real advantage of this is that in case of an error, you get a backtrace that helps you locate the issue in the test file quickly. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509194302.21585-6-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/216 | 23 ++++++++++++----------- tests/qemu-iotests/216.out | 17 ++--------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/tests/qemu-iotests/216 b/tests/qemu-iotests/216 index ca9b47a7fd..3c0ae54b44 100755 --- a/tests/qemu-iotests/216 +++ b/tests/qemu-iotests/216 @@ -20,7 +20,7 @@ # Creator/Owner: Max Reitz =20 import iotests -from iotests import log, qemu_img_pipe, qemu_io, filter_qemu_io +from iotests import log, qemu_img, qemu_io_silent =20 # Need backing file support iotests.verify_image_format(supported_fmts=3D['qcow2', 'qcow', 'qed', 'vmd= k']) @@ -50,14 +50,13 @@ with iotests.FilePath('base.img') as base_img_path, \ log('--- Setting up images ---') log('') =20 - qemu_img_pipe('create', '-f', iotests.imgfmt, base_img_path, '64M') + assert qemu_img('create', '-f', iotests.imgfmt, base_img_path, '64M') = =3D=3D 0 + assert qemu_io_silent(base_img_path, '-c', 'write -P 1 0M 1M') =3D=3D 0 + assert qemu_img('create', '-f', iotests.imgfmt, '-b', base_img_path, + top_img_path) =3D=3D 0 + assert qemu_io_silent(top_img_path, '-c', 'write -P 2 1M 1M') =3D=3D 0 =20 - log(filter_qemu_io(qemu_io(base_img_path, '-c', 'write -P 1 0M 1M'))) - - qemu_img_pipe('create', '-f', iotests.imgfmt, '-b', base_img_path, - top_img_path) - - log(filter_qemu_io(qemu_io(top_img_path, '-c', 'write -P 2 1M 1M'))) + log('Done') =20 log('') log('--- Doing COR ---') @@ -110,6 +109,8 @@ with iotests.FilePath('base.img') as base_img_path, \ log('--- Checking COR result ---') log('') =20 - log(filter_qemu_io(qemu_io(base_img_path, '-c', 'discard 0 64M'))) - log(filter_qemu_io(qemu_io(top_img_path, '-c', 'read -P 1 0M 1M'))) - log(filter_qemu_io(qemu_io(top_img_path, '-c', 'read -P 2 1M 1M'))) + assert qemu_io_silent(base_img_path, '-c', 'discard 0 64M') =3D=3D 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 1 0M 1M') =3D=3D 0 + assert qemu_io_silent(top_img_path, '-c', 'read -P 2 1M 1M') =3D=3D 0 + + log('Done') diff --git a/tests/qemu-iotests/216.out b/tests/qemu-iotests/216.out index d3fc590d29..45ea857ee1 100644 --- a/tests/qemu-iotests/216.out +++ b/tests/qemu-iotests/216.out @@ -3,12 +3,7 @@ =20 --- Setting up images --- =20 -wrote 1048576/1048576 bytes at offset 0 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -wrote 1048576/1048576 bytes at offset 1048576 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - +Done =20 --- Doing COR --- =20 @@ -17,12 +12,4 @@ wrote 1048576/1048576 bytes at offset 1048576 =20 --- Checking COR result --- =20 -discard 67108864/67108864 bytes at offset 0 -64 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -read 1048576/1048576 bytes at offset 0 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - -read 1048576/1048576 bytes at offset 1048576 -1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) - +Done --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728126560835.9260385423097; Mon, 11 Jun 2018 07:42:06 -0700 (PDT) Received: from localhost ([::1]:49239 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO1F-0008AP-NH for importer@patchew.org; Mon, 11 Jun 2018 10:42:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53205) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmY-0004iu-Bh for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmW-0001qH-TN for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35298 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmT-0001o9-Hw; Mon, 11 Jun 2018 10:26:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 21B568011059; Mon, 11 Jun 2018 14:26:49 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BFE44100294B; Mon, 11 Jun 2018 14:26:48 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:00 +0200 Message-Id: <20180611142611.6609-19-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 11 Jun 2018 14:26:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 11 Jun 2018 14:26:49 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 18/29] qemu-img: Resolve relative backing paths in rebase X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Currently, rebase interprets a relative path for the new backing image as follows: (1) Open the new backing image with the given relative path (thus relative = to qemu-img's working directory). (2) Write it directly into the overlay's backing path field (thus relative to the overlay). If the overlay is not in qemu-img's working directory, both will be different interpretations, which may either lead to an error somewhere (either rebase fails because it cannot open the new backing image, or your overlay becomes unusable because its backing path does not point to a file), or, even worse, it may result in your rebase being performed for a different backing file than what your overlay will point to after the rebase. Fix this by interpreting the target backing path as relative to the overlay, like qemu-img does everywhere else. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1569835 Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20180509182002.8044-2-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- qemu-img.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index b1c1e484d2..ebe1b866da 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -3251,6 +3251,9 @@ static int img_rebase(int argc, char **argv) } =20 if (out_baseimg[0]) { + const char *overlay_filename; + char *out_real_path; + options =3D qdict_new(); if (out_basefmt) { qdict_put_str(options, "driver", out_basefmt); @@ -3259,8 +3262,26 @@ static int img_rebase(int argc, char **argv) qdict_put_bool(options, BDRV_OPT_FORCE_SHARE, true); } =20 - blk_new_backing =3D blk_new_open(out_baseimg, NULL, + overlay_filename =3D bs->exact_filename[0] ? bs->exact_filename + : bs->filename; + out_real_path =3D g_malloc(PATH_MAX); + + bdrv_get_full_backing_filename_from_filename(overlay_filename, + out_baseimg, + out_real_path, + PATH_MAX, + &local_err); + if (local_err) { + error_reportf_err(local_err, + "Could not resolve backing filename: "); + ret =3D -1; + g_free(out_real_path); + goto out; + } + + blk_new_backing =3D blk_new_open(out_real_path, NULL, options, src_flags, &local_err); + g_free(out_real_path); if (!blk_new_backing) { error_reportf_err(local_err, "Could not open new backing file '%s': ", --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728272893823.2116105845921; Mon, 11 Jun 2018 07:44:32 -0700 (PDT) Received: from localhost ([::1]:49265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO3c-0001xH-58 for importer@patchew.org; Mon, 11 Jun 2018 10:44:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmb-0004ll-JX for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNma-0001ua-9o for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54512 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmV-0001pA-Dy; Mon, 11 Jun 2018 10:26:51 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07AE54022905; Mon, 11 Jun 2018 14:26:51 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A62C283B9C; Mon, 11 Jun 2018 14:26:50 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:01 +0200 Message-Id: <20180611142611.6609-20-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:51 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 19/29] iotests: Add test for rebasing with relative paths X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Signed-off-by: Max Reitz Reviewed-by: Eric Blake Message-id: 20180509182002.8044-3-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/024 | 82 ++++++++++++++++++++++++++++++++++++-- tests/qemu-iotests/024.out | 30 ++++++++++++++ 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/tests/qemu-iotests/024 b/tests/qemu-iotests/024 index e0d77ce2f5..4071ed6093 100755 --- a/tests/qemu-iotests/024 +++ b/tests/qemu-iotests/024 @@ -29,9 +29,14 @@ status=3D1 # failure is the default! =20 _cleanup() { - _cleanup_test_img - rm -f "$TEST_DIR/t.$IMGFMT.base_old" - rm -f "$TEST_DIR/t.$IMGFMT.base_new" + _cleanup_test_img + rm -f "$TEST_DIR/t.$IMGFMT.base_old" + rm -f "$TEST_DIR/t.$IMGFMT.base_new" + + rm -f "$TEST_DIR/subdir/t.$IMGFMT" + rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_old" + rm -f "$TEST_DIR/subdir/t.$IMGFMT.base_new" + rmdir "$TEST_DIR/subdir" 2> /dev/null } trap "_cleanup; exit \$status" 0 1 2 3 15 =20 @@ -123,6 +128,77 @@ io_pattern readv $((13 * CLUSTER_SIZE)) $CLUSTER_SIZE = 0 1 0x00 io_pattern readv $((14 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x11 io_pattern readv $((15 * CLUSTER_SIZE)) $CLUSTER_SIZE 0 1 0x00 =20 +echo +echo "=3D=3D=3D Test rebase in a subdirectory of the working directory =3D= =3D=3D" +echo + +# Clean up the old images beforehand so they do not interfere with +# this test +_cleanup + +mkdir "$TEST_DIR/subdir" + +# Relative to the overlay +BASE_OLD_OREL=3D"t.$IMGFMT.base_old" +BASE_NEW_OREL=3D"t.$IMGFMT.base_new" + +# Relative to $TEST_DIR (which is going to be our working directory) +OVERLAY_WREL=3D"subdir/t.$IMGFMT" + +BASE_OLD=3D"$TEST_DIR/subdir/$BASE_OLD_OREL" +BASE_NEW=3D"$TEST_DIR/subdir/$BASE_NEW_OREL" +OVERLAY=3D"$TEST_DIR/$OVERLAY_WREL" + +# Test done here: +# +# Backing (old): 11 11 -- 11 +# Backing (new): -- 22 22 11 +# Overlay: -- -- -- -- +# +# Rebasing works, we have verified that above. Here, we just want to +# see that rebasing is done for the correct target backing file. + +TEST_IMG=3D$BASE_OLD _make_test_img 1M +TEST_IMG=3D$BASE_NEW _make_test_img 1M +TEST_IMG=3D$OVERLAY _make_test_img -b "$BASE_OLD_OREL" 1M + +echo + +$QEMU_IO "$BASE_OLD" \ + -c "write -P 0x11 $((0 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \ + | _filter_qemu_io + +$QEMU_IO "$BASE_NEW" \ + -c "write -P 0x22 $((1 * CLUSTER_SIZE)) $((2 * CLUSTER_SIZE))" \ + -c "write -P 0x11 $((3 * CLUSTER_SIZE)) $((1 * CLUSTER_SIZE))" \ + | _filter_qemu_io + +echo + +pushd "$TEST_DIR" >/dev/null +$QEMU_IMG rebase -f "$IMGFMT" -b "$BASE_NEW_OREL" "$OVERLAY_WREL" +popd >/dev/null + +# Verify the backing path is correct +TEST_IMG=3D$OVERLAY _img_info | grep '^backing file' + +echo + +# Verify the data is correct +$QEMU_IO "$OVERLAY" \ + -c "read -P 0x11 $((0 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + -c "read -P 0x11 $((1 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + -c "read -P 0x00 $((2 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + -c "read -P 0x11 $((3 * CLUSTER_SIZE)) $CLUSTER_SIZE" \ + | _filter_qemu_io + +echo + +# Verify that cluster #3 is not allocated (because it is the same in +# $BASE_OLD and $BASE_NEW) +$QEMU_IMG map "$OVERLAY" | _filter_qemu_img_map + =20 # success, all done echo "*** done" diff --git a/tests/qemu-iotests/024.out b/tests/qemu-iotests/024.out index 33cfaf5cfc..024dc786b3 100644 --- a/tests/qemu-iotests/024.out +++ b/tests/qemu-iotests/024.out @@ -141,4 +141,34 @@ read 65536/65536 bytes at offset 917504 =3D=3D=3D IO: pattern 0x00 read 65536/65536 bytes at offset 983040 64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=3D=3D=3D Test rebase in a subdirectory of the working directory =3D=3D=3D + +Formatting 'TEST_DIR/subdir/t.IMGFMT.base_old', fmt=3DIMGFMT size=3D1048576 +Formatting 'TEST_DIR/subdir/t.IMGFMT.base_new', fmt=3DIMGFMT size=3D1048576 +Formatting 'TEST_DIR/subdir/t.IMGFMT', fmt=3DIMGFMT size=3D1048576 backing= _file=3Dt.IMGFMT.base_old + +wrote 131072/131072 bytes at offset 0 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 196608 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 131072/131072 bytes at offset 65536 +128 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 65536/65536 bytes at offset 196608 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +backing file: t.IMGFMT.base_new (actual path: TEST_DIR/subdir/t.IMGFMT.bas= e_new) + +read 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 65536 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 131072 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 65536/65536 bytes at offset 196608 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +Offset Length File +0 0x30000 TEST_DIR/subdir/t.IMGFMT +0x30000 0x10000 TEST_DIR/subdir/t.IMGFMT.base_new *** done --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728458178571.9500788973164; Mon, 11 Jun 2018 07:47:38 -0700 (PDT) Received: from localhost ([::1]:49284 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO6Z-0004NI-Em for importer@patchew.org; Mon, 11 Jun 2018 10:47:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmb-0004lp-Lw for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNma-0001ui-C6 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:26:57 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35538 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmX-0001qa-9V; Mon, 11 Jun 2018 10:26:53 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DFAD9BB409; Mon, 11 Jun 2018 14:26:52 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8C081202698A; Mon, 11 Jun 2018 14:26:52 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:02 +0200 Message-Id: <20180611142611.6609-21-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:52 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 20/29] qemu-img: Special post-backing convert 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Currently, qemu-img convert writes zeroes when it reads zeroes. Sometimes it does not because the target is initialized to zeroes anyway, so we do not need to overwrite (and thus potentially allocate) it. This is never the case for targets with backing files, though. But even they may have an area that is initialized to zeroes, and that is the area past the end of the backing file (if that is shorter than the overlay). So if the target format's unallocated blocks are zero and there is a gap between the target's backing file's end and the target's end, we do not have to explicitly write zeroes there. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1527898 Signed-off-by: Max Reitz Message-id: 20180501165750.19242-2-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- qemu-img.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/qemu-img.c b/qemu-img.c index ebe1b866da..ae4acb655b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1556,7 +1556,9 @@ typedef struct ImgConvertState { BlockBackend *target; bool has_zero_init; bool compressed; + bool unallocated_blocks_are_zero; bool target_has_backing; + int64_t target_backing_sectors; /* negative if unknown */ bool wr_in_order; bool copy_range; int min_sparse; @@ -1586,12 +1588,23 @@ static int convert_iteration_sectors(ImgConvertStat= e *s, int64_t sector_num) { int64_t src_cur_offset; int ret, n, src_cur; + bool post_backing_zero =3D false; =20 convert_select_part(s, sector_num, &src_cur, &src_cur_offset); =20 assert(s->total_sectors > sector_num); n =3D MIN(s->total_sectors - sector_num, BDRV_REQUEST_MAX_SECTORS); =20 + if (s->target_backing_sectors >=3D 0) { + if (sector_num >=3D s->target_backing_sectors) { + post_backing_zero =3D s->unallocated_blocks_are_zero; + } else if (sector_num + n > s->target_backing_sectors) { + /* Split requests around target_backing_sectors (because + * starting from there, zeros are handled differently) */ + n =3D s->target_backing_sectors - sector_num; + } + } + if (s->sector_next_status <=3D sector_num) { int64_t count =3D n * BDRV_SECTOR_SIZE; =20 @@ -1613,7 +1626,7 @@ static int convert_iteration_sectors(ImgConvertState = *s, int64_t sector_num) n =3D DIV_ROUND_UP(count, BDRV_SECTOR_SIZE); =20 if (ret & BDRV_BLOCK_ZERO) { - s->status =3D BLK_ZERO; + s->status =3D post_backing_zero ? BLK_BACKING_FILE : BLK_ZERO; } else if (ret & BDRV_BLOCK_DATA) { s->status =3D BLK_DATA; } else { @@ -2379,6 +2392,16 @@ static int img_convert(int argc, char **argv) } } =20 + if (s.target_has_backing) { + /* Errors are treated as "backing length unknown" (which means + * s.target_backing_sectors has to be negative, which it will + * be automatically). The backing file length is used only + * for optimizations, so such a case is not fatal. */ + s.target_backing_sectors =3D bdrv_nb_sectors(out_bs->backing->bs); + } else { + s.target_backing_sectors =3D -1; + } + ret =3D bdrv_get_info(out_bs, &bdi); if (ret < 0) { if (s.compressed) { @@ -2388,6 +2411,7 @@ static int img_convert(int argc, char **argv) } else { s.compressed =3D s.compressed || bdi.needs_compressed_writes; s.cluster_sectors =3D bdi.cluster_size / BDRV_SECTOR_SIZE; + s.unallocated_blocks_are_zero =3D bdi.unallocated_blocks_are_zero; } =20 ret =3D convert_do_copy(&s); --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152872845058176.73065511383197; Mon, 11 Jun 2018 07:47:30 -0700 (PDT) Received: from localhost ([::1]:49283 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO6R-0004JC-Q2 for importer@patchew.org; Mon, 11 Jun 2018 10:47:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53340) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmg-0004rV-64 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmc-0001vc-2p for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:02 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35542 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmZ-0001tp-6M; Mon, 11 Jun 2018 10:26:55 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8743BB409; Mon, 11 Jun 2018 14:26:54 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7008D112D176; Mon, 11 Jun 2018 14:26:54 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:03 +0200 Message-Id: <20180611142611.6609-22-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:54 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:26:54 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 21/29] iotests: Test post-backing convert target behavior X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This adds a test case to 122 for what happens when you convert to a target with a backing file that is shorter than the target, and the image format does not support efficient zero writes (as is the case with qcow2 v2). Signed-off-by: Max Reitz Message-id: 20180501165750.19242-3-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/122 | 42 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/122.out | 18 ++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/tests/qemu-iotests/122 b/tests/qemu-iotests/122 index 45b359c2ba..d8c8ad722d 100755 --- a/tests/qemu-iotests/122 +++ b/tests/qemu-iotests/122 @@ -76,6 +76,48 @@ $QEMU_IMG convert -O $IMGFMT -c -B "$TEST_IMG".base "$TE= ST_IMG" "$TEST_IMG".orig $QEMU_IO -c "read -P 0 0 3M" "$TEST_IMG".orig 2>&1 | _filter_qemu_io | _fi= lter_testdir =20 =20 +echo +echo "=3D=3D=3D Converting to an overlay larger than its backing file =3D= =3D=3D" +echo + +TEST_IMG=3D"$TEST_IMG".base _make_test_img 256M +# Needs to be at least how much an L2 table covers +# (64 kB/entry * 64 kB / 8 B/entry =3D 512 MB) +# That way, qcow2 will yield at least two status request responses. +# With just a single response, it would always say "Allocated in the +# backing file", so the optimization qemu-img convert tries to do is +# done automatically. Once it has to be queried twice, however (and +# one of the queries is completely after the end of the backing file), +# the block layer will automatically add a ZERO flag that qemu-img +# convert used to follow up with a zero write to the target. +# We do not want such a zero write, however, because we are past the +# end of the backing file on the target as well, so we do not need to +# write anything there. +_make_test_img -b "$TEST_IMG".base 768M + +# Use compat=3D0.10 as the output so there is no zero cluster support +$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=3D0.10 \ + "$TEST_IMG" "$TEST_IMG".orig +# See that nothing has been allocated past 64M +$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map + +echo + +# Just before the end of the backing file +$QEMU_IO -c 'write -P 0x11 255M 1M' "$TEST_IMG".base 2>&1 | _filter_qemu_io +# Somewhere in the second L2 table +$QEMU_IO -c 'write -P 0x22 600M 1M' "$TEST_IMG" 2>&1 | _filter_qemu_io + +$QEMU_IMG convert -O $IMGFMT -B "$TEST_IMG".base -o compat=3D0.10 \ + "$TEST_IMG" "$TEST_IMG".orig + +$QEMU_IMG map "$TEST_IMG".orig | _filter_qemu_img_map +$QEMU_IO -c 'read -P 0x11 255M 1M' \ + -c 'read -P 0x22 600M 1M' \ + "$TEST_IMG".orig \ + | _filter_qemu_io + + echo echo "=3D=3D=3D Concatenate multiple source images =3D=3D=3D" echo diff --git a/tests/qemu-iotests/122.out b/tests/qemu-iotests/122.out index 47d8656db8..6c7ee1da6c 100644 --- a/tests/qemu-iotests/122.out +++ b/tests/qemu-iotests/122.out @@ -28,6 +28,24 @@ read 3145728/3145728 bytes at offset 0 read 3145728/3145728 bytes at offset 0 3 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) =20 +=3D=3D=3D Converting to an overlay larger than its backing file =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT.base', fmt=3DIMGFMT size=3D268435456 +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D805306368 backing_file= =3DTEST_DIR/t.IMGFMT.base +Offset Length File + +wrote 1048576/1048576 bytes at offset 267386880 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +wrote 1048576/1048576 bytes at offset 629145600 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +Offset Length File +0xff00000 0x100000 TEST_DIR/t.IMGFMT.base +0x25800000 0x100000 TEST_DIR/t.IMGFMT.orig +read 1048576/1048576 bytes at offset 267386880 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 1048576/1048576 bytes at offset 629145600 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + =3D=3D=3D Concatenate multiple source images =3D=3D=3D =20 Formatting 'TEST_DIR/t.IMGFMT.1', fmt=3DIMGFMT size=3D4194304 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152872806330137.00455930630221; Mon, 11 Jun 2018 07:41:03 -0700 (PDT) Received: from localhost ([::1]:49235 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO0E-0007JM-Ge for importer@patchew.org; Mon, 11 Jun 2018 10:41:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53319) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNme-0004ow-2Y for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmd-0001wH-9l for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:00 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54516 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmb-0001uz-2a; Mon, 11 Jun 2018 10:26:57 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC80E4022905; Mon, 11 Jun 2018 14:26:56 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56A652028672; Mon, 11 Jun 2018 14:26:56 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:04 +0200 Message-Id: <20180611142611.6609-23-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:56 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 22/29] iotests: improve pause_job X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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's possible, that job was finished during waiting. In this case we will see error message "Timeout waiting for job to pause" which is not very informative. So, let's check during waiting iteration that the job exists. Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20180601115923.17159-1-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- tests/qemu-iotests/iotests.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py index 0b204dc220..2f22fab2a7 100644 --- a/tests/qemu-iotests/iotests.py +++ b/tests/qemu-iotests/iotests.py @@ -590,9 +590,14 @@ class QMPTestCase(unittest.TestCase): with Timeout(1, "Timeout waiting for job to pause"): while True: result =3D self.vm.qmp('query-block-jobs') + found =3D False for job in result['return']: - if job['device'] =3D=3D job_id and job['paused'] =3D= =3D True and job['busy'] =3D=3D False: - return job + if job['device'] =3D=3D job_id: + found =3D True + if job['paused'] =3D=3D True and job['busy'] =3D= =3D False: + return job + break + assert found =20 def pause_job(self, job_id=3D'job0', wait=3DTrue): result =3D self.vm.qmp('block-job-pause', device=3Djob_id) --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728790562877.5115781551235; Mon, 11 Jun 2018 07:53:10 -0700 (PDT) Received: from localhost ([::1]:49311 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSOBx-0000Dx-Q5 for importer@patchew.org; Mon, 11 Jun 2018 10:53:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmm-00050S-NM for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNml-00020T-5w for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54520 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmc-0001vr-Vi; Mon, 11 Jun 2018 10:26:59 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 941DB4022905; Mon, 11 Jun 2018 14:26:58 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E702202698A; Mon, 11 Jun 2018 14:26:58 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:05 +0200 Message-Id: <20180611142611.6609-24-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:26:58 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 23/29] iotests: Fix 219's timing X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" 219 has two issues that may lead to sporadic failure, both of which are the result of issuing query-jobs too early after a job has been modified. This can then lead to different results based on whether the modification has taken effect already or not. First, query-jobs is issued right after the job has been created. Besides its current progress possibly being in any random state (which has already been taken care of), its total progress too is basically arbitrary, because the job may not yet have been able to determine it. This patch addresses this by just filtering the total progress, like what has been done for the current progress already. However, for more clarity, the filtering is changed to replace the values by a string 'FILTERED' instead of deleting them. Secondly, query-jobs is issued right after a job has been resumed. The job may or may not yet have had the time to actually perform any I/O, and thus its current progress may or may not have advanced. To make sure it has indeed advanced (which is what the reference output already assumes), keep querying it until it has. Signed-off-by: Max Reitz Message-id: 20180606190628.8170-1-mreitz@redhat.com Reviewed-by: Eric Blake Signed-off-by: Max Reitz --- tests/qemu-iotests/219 | 26 ++++++++++++++++++++------ tests/qemu-iotests/219.out | 10 +++++----- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tests/qemu-iotests/219 b/tests/qemu-iotests/219 index 898a26eef0..c03bbdb294 100755 --- a/tests/qemu-iotests/219 +++ b/tests/qemu-iotests/219 @@ -42,11 +42,24 @@ def test_pause_resume(vm): iotests.log(vm.qmp(pause_cmd, **{pause_arg: 'job0'})) pause_wait(vm, 'job0') iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS= _CHANGE'))) - iotests.log(vm.qmp('query-jobs')) + result =3D vm.qmp('query-jobs') + iotests.log(result) + + old_progress =3D result['return'][0]['current-progress'] + total_progress =3D result['return'][0]['total-progress'] =20 iotests.log(vm.qmp(resume_cmd, **{resume_arg: 'job0'})) iotests.log(iotests.filter_qmp_event(vm.event_wait('JOB_STATUS= _CHANGE'))) - iotests.log(vm.qmp('query-jobs')) + if old_progress < total_progress: + # Wait for the job to advance + while result['return'][0]['current-progress'] =3D=3D old_p= rogress: + result =3D vm.qmp('query-jobs') + iotests.log(result) + else: + # Already reached the end, so the job cannot advance + # any further; therefore, the query-jobs result can be + # logged immediately + iotests.log(vm.qmp('query-jobs')) =20 def test_job_lifecycle(vm, job, job_args, has_ready=3DFalse): iotests.log('') @@ -58,12 +71,13 @@ def test_job_lifecycle(vm, job, job_args, has_ready=3DF= alse): iotests.log(vm.qmp(job, job_id=3D'job0', **job_args)) =20 # Depending on the storage, the first request may or may not have comp= leted - # yet, so filter out the progress. Later query-job calls don't need the - # filtering because the progress is made deterministic by the block job - # speed + # yet (and the total progress may not have been fully determined yet),= so + # filter out the progress. Later query-job calls don't need the filter= ing + # because the progress is made deterministic by the block job speed result =3D vm.qmp('query-jobs') for j in result['return']: - del j['current-progress'] + j['current-progress'] =3D 'FILTERED' + j['total-progress'] =3D 'FILTERED' iotests.log(result) =20 # undefined -> created -> running diff --git a/tests/qemu-iotests/219.out b/tests/qemu-iotests/219.out index 346801b655..6dc07bc41e 100644 --- a/tests/qemu-iotests/219.out +++ b/tests/qemu-iotests/219.out @@ -3,7 +3,7 @@ Launching VM... =20 Starting block job: drive-mirror (auto-finalize: True; auto-dismiss: True) {u'return': {}} -{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'= job0', u'type': u'mirror'}]} +{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'to= tal-progress': 'FILTERED', u'id': u'job0', u'type': u'mirror'}]} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} =20 @@ -93,7 +93,7 @@ Waiting for PENDING state... =20 Starting block job: drive-backup (auto-finalize: True; auto-dismiss: True) {u'return': {}} -{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'= job0', u'type': u'backup'}]} +{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'to= tal-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} =20 @@ -144,7 +144,7 @@ Waiting for PENDING state... =20 Starting block job: drive-backup (auto-finalize: True; auto-dismiss: False) {u'return': {}} -{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'= job0', u'type': u'backup'}]} +{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'to= tal-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} =20 @@ -203,7 +203,7 @@ Waiting for PENDING state... =20 Starting block job: drive-backup (auto-finalize: False; auto-dismiss: True) {u'return': {}} -{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'= job0', u'type': u'backup'}]} +{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'to= tal-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} =20 @@ -262,7 +262,7 @@ Waiting for PENDING state... =20 Starting block job: drive-backup (auto-finalize: False; auto-dismiss: Fals= e) {u'return': {}} -{u'return': [{u'status': u'running', u'total-progress': 4194304, u'id': u'= job0', u'type': u'backup'}]} +{u'return': [{u'status': u'running', u'current-progress': 'FILTERED', u'to= tal-progress': 'FILTERED', u'id': u'job0', u'type': u'backup'}]} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'created', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} {u'timestamp': {u'seconds': 'SECS', u'microseconds': 'USECS'}, u'data': {u= 'status': u'running', u'id': u'job0'}, u'event': u'JOB_STATUS_CHANGE'} =20 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728885219811.9586363666384; Mon, 11 Jun 2018 07:54:45 -0700 (PDT) Received: from localhost ([::1]:49337 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSODU-0001Qa-Ip for importer@patchew.org; Mon, 11 Jun 2018 10:54:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNms-00054h-ER for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmq-00027s-Rm for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33552 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmf-0001wq-0B; Mon, 11 Jun 2018 10:27:01 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9817D7D859; Mon, 11 Jun 2018 14:27:00 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E9D4202698A; Mon, 11 Jun 2018 14:26:59 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:06 +0200 Message-Id: <20180611142611.6609-25-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:27:00 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:27:00 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 24/29] qemu-img: Remove deprecated -s snapshot_id_or_name option X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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 It has been marked as deprecated since QEMU v2.0 already, so it is time now to finally remove it. Signed-off-by: Thomas Huth Message-id: 1528288551-31641-1-git-send-email-thuth@redhat.com Reviewed-by: Jeff Cody Signed-off-by: Max Reitz --- qemu-img.c | 7 +------ qemu-doc.texi | 7 ------- qemu-img-cmds.hx | 4 ++-- qemu-img.texi | 7 ++----- tests/qemu-iotests/029 | 2 +- tests/qemu-iotests/080 | 4 ++-- 6 files changed, 8 insertions(+), 23 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index ae4acb655b..1dcdd47254 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -148,8 +148,6 @@ static void QEMU_NORETURN help(void) " 'snapshot_param' is param used for internal snapshot, format= \n" " is 'snapshot.id=3D[ID],snapshot.name=3D[NAME]', or\n" " '[ID_OR_NAME]'\n" - " 'snapshot_id_or_name' is deprecated, use 'snapshot_param'\n" - " instead\n" " '-c' indicates that target image must be compressed (qcow fo= rmat only)\n" " '-u' allows unsafe backing chains. For rebasing, it is assum= ed that old and\n" " new backing file match exactly. The image doesn't need = a working\n" @@ -2018,7 +2016,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:co:s:l:S:pt:T:qnm:WU", + c =3D getopt_long(argc, argv, ":hf:O:B:co:l:S:pt:T:qnm:WU", long_options, NULL); if (c =3D=3D -1) { break; @@ -2059,9 +2057,6 @@ static int img_convert(int argc, char **argv) g_free(old_options); } break; - case 's': - snapshot_name =3D optarg; - break; case 'l': if (strstart(optarg, SNAPSHOT_OPT_BASE, NULL)) { sn_opts =3D qemu_opts_parse_noisily(&internal_snapshot_opt= s, diff --git a/qemu-doc.texi b/qemu-doc.texi index 2effe66d6b..9aff6b4ea9 100644 --- a/qemu-doc.texi +++ b/qemu-doc.texi @@ -2927,13 +2927,6 @@ Option @option{-virtioconsole} has been replaced by The @code{-clock} option is ignored since QEMU version 1.7.0. There is no replacement since it is not needed anymore. =20 -@section qemu-img command line arguments - -@subsection convert -s (since 2.0.0) - -The ``convert -s snapshot_id_or_name'' argument is obsoleted -by the ``convert -l snapshot_param'' argument instead. - @section QEMU Machine Protocol (QMP) commands =20 @subsection block-dirty-bitmap-add "autoload" parameter (since 2.12.0) diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx index 3d2f7b26eb..69758fb6e8 100644 --- a/qemu-img-cmds.hx +++ b/qemu-img-cmds.hx @@ -44,9 +44,9 @@ STEXI ETEXI =20 DEF("convert", img_convert, - "convert [--object objectdef] [--image-opts] [--target-image-opts] [-U= ] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-= B backing_file] [-o options] [-s snapshot_id_or_name] [-l snapshot_param] [= -S sparse_size] [-m num_coroutines] [-W] filename [filename2 [...]] output_= filename") + "convert [--object objectdef] [--image-opts] [--target-image-opts] [-U= ] [-c] [-p] [-q] [-n] [-f fmt] [-t cache] [-T src_cache] [-O output_fmt] [-= B backing_file] [-o options] [-l snapshot_param] [-S sparse_size] [-m num_c= oroutines] [-W] filename [filename2 [...]] output_filename") STEXI -@item convert [--object @var{objectdef}] [--image-opts] [--target-image-op= ts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_c= ache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s= @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}= ] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @va= r{output_filename} +@item convert [--object @var{objectdef}] [--image-opts] [--target-image-op= ts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_c= ache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-l= @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W= ] @var{filename} [@var{filename2} [...]] @var{output_filename} ETEXI =20 DEF("create", img_create, diff --git a/qemu-img.texi b/qemu-img.texi index 2be8206a05..aeb1b9e66c 100644 --- a/qemu-img.texi +++ b/qemu-img.texi @@ -61,9 +61,6 @@ by the used format or see the format descriptions below f= or details. is param used for internal snapshot, format is 'snapshot.id=3D[ID],snapshot.name=3D[NAME]' or '[ID_OR_NAME]' =20 -@item snapshot_id_or_name -is deprecated, use snapshot_param instead - @end table =20 @table @option @@ -322,9 +319,9 @@ Error on reading data =20 @end table =20 -@item convert [--object @var{objectdef}] [--image-opts] [--target-image-op= ts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_c= ache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-s= @var{snapshot_id_or_name}] [-l @var{snapshot_param}] [-S @var{sparse_size}= ] [-m @var{num_coroutines}] [-W] @var{filename} [@var{filename2} [...]] @va= r{output_filename} +@item convert [--object @var{objectdef}] [--image-opts] [--target-image-op= ts] [-U] [-c] [-p] [-q] [-n] [-f @var{fmt}] [-t @var{cache}] [-T @var{src_c= ache}] [-O @var{output_fmt}] [-B @var{backing_file}] [-o @var{options}] [-l= @var{snapshot_param}] [-S @var{sparse_size}] [-m @var{num_coroutines}] [-W= ] @var{filename} [@var{filename2} [...]] @var{output_filename} =20 -Convert the disk image @var{filename} or a snapshot @var{snapshot_param}(@= var{snapshot_id_or_name} is deprecated) +Convert the disk image @var{filename} or a snapshot @var{snapshot_param} to disk image @var{output_filename} using format @var{output_fmt}. It can = be optionally compressed (@code{-c} option) or use any format specific options like encryption (@code{-o} opti= on). =20 diff --git a/tests/qemu-iotests/029 b/tests/qemu-iotests/029 index 30bab24dc0..5cff6875bf 100755 --- a/tests/qemu-iotests/029 +++ b/tests/qemu-iotests/029 @@ -92,7 +92,7 @@ _make_test_img 64M { $QEMU_IMG snapshot -c foo $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_= testdir poke_file "$TEST_IMG" "$offset_size" "\x00\x00\x00\x00\x00\x00\x02\x00" poke_file "$TEST_IMG" "$offset_l1_size" "\x00\x00\x00\x01" -{ $QEMU_IMG convert -s foo $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_qemu= _io | _filter_testdir +{ $QEMU_IMG convert -l foo $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_qemu= _io | _filter_testdir =20 =20 # success, all done diff --git a/tests/qemu-iotests/080 b/tests/qemu-iotests/080 index 4dbe68e950..f0eb42f390 100755 --- a/tests/qemu-iotests/080 +++ b/tests/qemu-iotests/080 @@ -176,7 +176,7 @@ _make_test_img 64M { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_= testdir { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir poke_file "$TEST_IMG" "$offset_snap1_l1_offset" "\x00\x00\x00\x00\x00\x40\= x02\x00" -{ $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_tes= tdir +{ $QEMU_IMG convert -l test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_tes= tdir { $QEMU_IMG amend -o compat=3D0.10 $TEST_IMG; } 2>&1 | _filter_testdir { $QEMU_IO -c "open -o overlap-check.inactive-l2=3Don $TEST_IMG" \ -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir @@ -190,7 +190,7 @@ _make_test_img 64M { $QEMU_IO -c "write 0 512" $TEST_IMG; } 2>&1 | _filter_qemu_io | _filter_= testdir { $QEMU_IMG snapshot -c test $TEST_IMG; } 2>&1 | _filter_testdir poke_file "$TEST_IMG" "$offset_snap1_l1_size" "\x10\x00\x00\x00" -{ $QEMU_IMG convert -s test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_tes= tdir +{ $QEMU_IMG convert -l test $TEST_IMG $TEST_IMG.snap; } 2>&1 | _filter_tes= tdir { $QEMU_IMG amend -o compat=3D0.10 $TEST_IMG; } 2>&1 | _filter_testdir { $QEMU_IO -c "open -o overlap-check.inactive-l2=3Don $TEST_IMG" \ -c 'write 0 4k'; } 2>&1 | _filter_qemu_io | _filter_testdir --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152872877793675.83096208722213; Mon, 11 Jun 2018 07:52:57 -0700 (PDT) Received: from localhost ([::1]:49310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSOBh-0008UK-Hx for importer@patchew.org; Mon, 11 Jun 2018 10:52:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53468) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmq-00052v-Rf for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmn-00023p-TX for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35548 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmg-0001yC-T4; Mon, 11 Jun 2018 10:27:03 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F505BB409; Mon, 11 Jun 2018 14:27:02 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2916C112D176; Mon, 11 Jun 2018 14:27:02 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:07 +0200 Message-Id: <20180611142611.6609-26-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:27:02 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:27:02 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 25/29] block/qcow2-bitmap: fix free_bitmap_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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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 assert may fail, because bitmap_table is not initialized. Just drop it, as it's obvious, that bitmap_table_load sets bitmap_table parameter only when returning zero. Reported-by: Pavel Butsykin Signed-off-by: Vladimir Sementsov-Ogievskiy Message-id: 20180608101225.2575-1-vsementsov@virtuozzo.com Signed-off-by: Max Reitz --- block/qcow2-bitmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 60d5290f10..69485aa1de 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -254,7 +254,6 @@ static int free_bitmap_clusters(BlockDriverState *bs, Q= cow2BitmapTable *tb) =20 ret =3D bitmap_table_load(bs, tb, &bitmap_table); if (ret < 0) { - assert(bitmap_table =3D=3D NULL); return ret; } =20 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728626765815.5836855925927; Mon, 11 Jun 2018 07:50:26 -0700 (PDT) Received: from localhost ([::1]:49293 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO9I-0006Uw-0i for importer@patchew.org; Mon, 11 Jun 2018 10:50:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmm-00050Y-QL for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNml-00020k-LD for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:08 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:33556 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmi-0001zJ-Oc; Mon, 11 Jun 2018 10:27:04 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BFA57D859; Mon, 11 Jun 2018 14:27:04 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 080098442A; Mon, 11 Jun 2018 14:27:03 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:08 +0200 Message-Id: <20180611142611.6609-27-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:27:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 11 Jun 2018 14:27:04 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 26/29] throttle: Fix crash on reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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: Alberto Garcia The throttle block filter can be reopened, and with this it is possible to change the throttle group that the filter belongs to. The way the code does that is the following: - On throttle_reopen_prepare(): create a new ThrottleGroupMember and attach it to the new throttle group. - On throttle_reopen_commit(): detach the old ThrottleGroupMember, delete it and replace it with the new one. The problem with this is that by replacing the ThrottleGroupMember the previous value of io_limits_disabled is lost, causing an assertion failure in throttle_co_drain_end(). This problem can be reproduced by reopening a throttle node: $QEMU -monitor stdio -object throttle-group,id=3Dtg0,x-iops-total=3D1000 \ -blockdev node-name=3Dhd0,driver=3Dqcow2,file.driver=3Dfile,file.filenam= e=3Dhd.qcow2 \ -blockdev node-name=3Droot,driver=3Dthrottle,throttle-group=3Dtg0,file= =3Dhd0,read-only=3Don (qemu) block_stream root block/throttle.c:214: throttle_co_drain_end: Assertion `tgm->io_limits_d= isabled' failed. Since we only want to change the throttle group on reopen there's no need to create a ThrottleGroupMember and discard the old one. It's easier if we simply detach it from its current group and attach it to the new one. Signed-off-by: Alberto Garcia Message-id: 20180608151536.7378-1-berto@igalia.com Signed-off-by: Max Reitz --- block/throttle.c | 54 +++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/block/throttle.c b/block/throttle.c index e298827f95..f617f23a12 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -36,9 +36,12 @@ static QemuOptsList throttle_opts =3D { }, }; =20 -static int throttle_configure_tgm(BlockDriverState *bs, - ThrottleGroupMember *tgm, - QDict *options, Error **errp) +/* + * If this function succeeds then the throttle group name is stored in + * @group and must be freed by the caller. + * If there's an error then @group remains unmodified. + */ +static int throttle_parse_options(QDict *options, char **group, Error **er= rp) { int ret; const char *group_name; @@ -63,8 +66,7 @@ static int throttle_configure_tgm(BlockDriverState *bs, goto fin; } =20 - /* Register membership to group with name group_name */ - throttle_group_register_tgm(tgm, group_name, bdrv_get_aio_context(bs)); + *group =3D g_strdup(group_name); ret =3D 0; fin: qemu_opts_del(opts); @@ -75,6 +77,8 @@ static int throttle_open(BlockDriverState *bs, QDict *opt= ions, int flags, Error **errp) { ThrottleGroupMember *tgm =3D bs->opaque; + char *group; + int ret; =20 bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -86,7 +90,14 @@ static int throttle_open(BlockDriverState *bs, QDict *op= tions, bs->supported_zero_flags =3D bs->file->bs->supported_zero_flags | BDRV_REQ_WRITE_UNCHANGED; =20 - return throttle_configure_tgm(bs, tgm, options, errp); + ret =3D throttle_parse_options(options, &group, errp); + if (ret =3D=3D 0) { + /* Register membership to group with name group_name */ + throttle_group_register_tgm(tgm, group, bdrv_get_aio_context(bs)); + g_free(group); + } + + return ret; } =20 static void throttle_close(BlockDriverState *bs) @@ -162,35 +173,36 @@ static void throttle_attach_aio_context(BlockDriverSt= ate *bs, static int throttle_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp) { - ThrottleGroupMember *tgm; + int ret; + char *group =3D NULL; =20 assert(reopen_state !=3D NULL); assert(reopen_state->bs !=3D NULL); =20 - reopen_state->opaque =3D g_new0(ThrottleGroupMember, 1); - tgm =3D reopen_state->opaque; - - return throttle_configure_tgm(reopen_state->bs, tgm, reopen_state->opt= ions, - errp); + ret =3D throttle_parse_options(reopen_state->options, &group, errp); + reopen_state->opaque =3D group; + return ret; } =20 static void throttle_reopen_commit(BDRVReopenState *reopen_state) { - ThrottleGroupMember *old_tgm =3D reopen_state->bs->opaque; - ThrottleGroupMember *new_tgm =3D reopen_state->opaque; + BlockDriverState *bs =3D reopen_state->bs; + ThrottleGroupMember *tgm =3D bs->opaque; + char *group =3D reopen_state->opaque; + + assert(group); =20 - throttle_group_unregister_tgm(old_tgm); - g_free(old_tgm); - reopen_state->bs->opaque =3D new_tgm; + if (strcmp(group, throttle_group_get_name(tgm))) { + throttle_group_unregister_tgm(tgm); + throttle_group_register_tgm(tgm, group, bdrv_get_aio_context(bs)); + } + g_free(reopen_state->opaque); reopen_state->opaque =3D NULL; } =20 static void throttle_reopen_abort(BDRVReopenState *reopen_state) { - ThrottleGroupMember *tgm =3D reopen_state->opaque; - - throttle_group_unregister_tgm(tgm); - g_free(tgm); + g_free(reopen_state->opaque); reopen_state->opaque =3D NULL; } =20 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728240911521.3255144069768; Mon, 11 Jun 2018 07:44:00 -0700 (PDT) Received: from localhost ([::1]:49264 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO35-0001WD-SM for importer@patchew.org; Mon, 11 Jun 2018 10:43:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53509) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNms-00054P-51 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmr-000287-0E for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:14 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:54528 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmk-000201-LU; Mon, 11 Jun 2018 10:27:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3FE2A4022905; Mon, 11 Jun 2018 14:27:06 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E0607202698A; Mon, 11 Jun 2018 14:27:05 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:09 +0200 Message-Id: <20180611142611.6609-28-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:27:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 11 Jun 2018 14:27:06 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 27/29] block: Make bdrv_is_writable() 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: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" This is a useful function for the whole block layer, so make it public. At the same time, users outside of block.c probably do not need to make use of the reopen functionality, so rename the current function to bdrv_is_writable_after_reopen() create a new bdrv_is_writable() function that just passes NULL to it for the reopen queue. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20180606193702.7113-2-mreitz@redhat.com Reviewed-by: John Snow Reviewed-by: Jeff Cody Signed-off-by: Max Reitz --- include/block/block.h | 1 + block.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 4dd4f1eab2..e677080c4e 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -408,6 +408,7 @@ bool bdrv_is_read_only(BlockDriverState *bs); int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, bool ignore_allow_rdw, Error **errp); int bdrv_set_read_only(BlockDriverState *bs, bool read_only, Error **errp); +bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); bool bdrv_is_inserted(BlockDriverState *bs); void bdrv_lock_medium(BlockDriverState *bs, bool locked); diff --git a/block.c b/block.c index 9d577f65bb..50887087f3 100644 --- a/block.c +++ b/block.c @@ -1620,13 +1620,24 @@ static int bdrv_reopen_get_flags(BlockReopenQueue *= q, BlockDriverState *bs) =20 /* Returns whether the image file can be written to after the reopen queue= @q * has been successfully applied, or right now if @q is NULL. */ -static bool bdrv_is_writable(BlockDriverState *bs, BlockReopenQueue *q) +static bool bdrv_is_writable_after_reopen(BlockDriverState *bs, + BlockReopenQueue *q) { int flags =3D bdrv_reopen_get_flags(q, bs); =20 return (flags & (BDRV_O_RDWR | BDRV_O_INACTIVE)) =3D=3D BDRV_O_RDWR; } =20 +/* + * Return whether the BDS can be written to. This is not necessarily + * the same as !bdrv_is_read_only(bs), as inactivated images may not + * be written to but do not count as read-only images. + */ +bool bdrv_is_writable(BlockDriverState *bs) +{ + return bdrv_is_writable_after_reopen(bs, NULL); +} + static void bdrv_child_perm(BlockDriverState *bs, BlockDriverState *child_= bs, BdrvChild *c, const BdrvChildRole *role, BlockReopenQueue *reopen_queue, @@ -1664,7 +1675,7 @@ static int bdrv_check_perm(BlockDriverState *bs, Bloc= kReopenQueue *q, =20 /* Write permissions never work with read-only images */ if ((cumulative_perms & (BLK_PERM_WRITE | BLK_PERM_WRITE_UNCHANGED)) && - !bdrv_is_writable(bs, q)) + !bdrv_is_writable_after_reopen(bs, q)) { error_setg(errp, "Block node is read-only"); return -EPERM; @@ -1956,7 +1967,7 @@ void bdrv_format_default_perms(BlockDriverState *bs, = BdrvChild *c, &perm, &shared); =20 /* Format drivers may touch metadata even if the guest doesn't wri= te */ - if (bdrv_is_writable(bs, reopen_queue)) { + if (bdrv_is_writable_after_reopen(bs, reopen_queue)) { perm |=3D BLK_PERM_WRITE | BLK_PERM_RESIZE; } =20 --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728390528633.0378495787562; Mon, 11 Jun 2018 07:46:30 -0700 (PDT) Received: from localhost ([::1]:49282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSO5R-0003ah-5T for importer@patchew.org; Mon, 11 Jun 2018 10:46:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53502) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmr-00054D-Vu for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNmr-00028C-0D for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:13 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:37644 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmm-00021k-Hu; Mon, 11 Jun 2018 10:27:08 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 267C4401EF04; Mon, 11 Jun 2018 14:27:08 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C38A42028672; Mon, 11 Jun 2018 14:27:07 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:10 +0200 Message-Id: <20180611142611.6609-29-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 11 Jun 2018 14:27:08 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Mon, 11 Jun 2018 14:27:08 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 28/29] qcow2: Do not mark inactive images corrupt X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" When signaling a corruption on a read-only image, qcow2 already makes fatal events non-fatal (i.e., they will not result in the image being closed, and the image header's corrupt flag will not be set). This is necessary because we cannot set the corrupt flag on read-only images, and it is possible because further corruption of read-only images is impossible. Inactive images are effectively read-only, too, so we should do the same for them. bdrv_is_writable() can tell us whether an image can actually be written to, so use its result instead of !bs->read_only. (Otherwise, the assert(!(bs->open_flags & BDRV_O_INACTIVE)) in bdrv_co_pwritev() will fail, crashing qemu.) Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20180606193702.7113-3-mreitz@redhat.com Reviewed-by: John Snow Reviewed-by: Jeff Cody Signed-off-by: Max Reitz --- block/qcow2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 6b2d88759d..6fa5e1d71a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4569,7 +4569,7 @@ void qcow2_signal_corruption(BlockDriverState *bs, bo= ol fatal, int64_t offset, char *message; va_list ap; =20 - fatal =3D fatal && !bs->read_only; + fatal =3D fatal && bdrv_is_writable(bs); =20 if (s->signaled_corruption && (!fatal || (s->incompatible_features & QCOW2_INCOMPAT_CORRUPT))) --=20 2.17.1 From nobody Wed May 8 00:40:52 2024 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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528728961683515.8309524689429; Mon, 11 Jun 2018 07:56:01 -0700 (PDT) Received: from localhost ([::1]:49345 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSOEd-000290-QP for importer@patchew.org; Mon, 11 Jun 2018 10:55:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53531) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSNmt-00056J-Ag for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSNms-00028z-6I for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:27:15 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35552 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSNmo-00024G-DP; Mon, 11 Jun 2018 10:27:10 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0EC99BB409; Mon, 11 Jun 2018 14:27:10 +0000 (UTC) Received: from localhost (unknown [10.40.205.155]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AEBB48442A; Mon, 11 Jun 2018 14:27:09 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 11 Jun 2018 16:26:11 +0200 Message-Id: <20180611142611.6609-30-mreitz@redhat.com> In-Reply-To: <20180611142611.6609-1-mreitz@redhat.com> References: <20180611142611.6609-1-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:27:10 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 11 Jun 2018 14:27:10 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'mreitz@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PULL 29/29] iotests: Add case for a corrupted inactive image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Max Reitz 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" Reviewed-by: John Snow Tested-by: Jeff Cody Reviewed-by: Jeff Cody Signed-off-by: Max Reitz Message-id: 20180606193702.7113-4-mreitz@redhat.com Signed-off-by: Max Reitz --- tests/qemu-iotests/060 | 30 ++++++++++++++++++++++++++++++ tests/qemu-iotests/060.out | 14 ++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/tests/qemu-iotests/060 b/tests/qemu-iotests/060 index 6c7407f499..7bdf609f3f 100755 --- a/tests/qemu-iotests/060 +++ b/tests/qemu-iotests/060 @@ -440,6 +440,36 @@ echo "{'execute': 'qmp_capabilities'} -drive if=3Dnone,node-name=3Ddrive,file=3D"$TEST_IMG",driver= =3Dqcow2 \ | _filter_qmp | _filter_qemu_io =20 +echo +echo "=3D=3D=3D Testing incoming inactive corrupted image =3D=3D=3D" +echo + +_make_test_img 64M +# Create an unaligned L1 entry, so qemu will signal a corruption when +# reading from the covered area +poke_file "$TEST_IMG" "$l1_offset" "\x00\x00\x00\x00\x2a\x2a\x2a\x2a" + +# Inactive images are effectively read-only images, so this should be a +# non-fatal corruption (which does not modify the image) +echo "{'execute': 'qmp_capabilities'} + {'execute': 'human-monitor-command', + 'arguments': {'command-line': 'qemu-io drive \"read 0 512\"'}} + {'execute': 'quit'}" \ + | $QEMU -qmp stdio -nographic -nodefaults \ + -blockdev "{'node-name': 'drive', + 'driver': 'qcow2', + 'file': { + 'driver': 'file', + 'filename': '$TEST_IMG' + }}" \ + -incoming exec:'cat /dev/null' \ + 2>&1 \ + | _filter_qmp | _filter_qemu_io + +echo +# Image should not have been marked corrupt +_img_info --format-specific | grep 'corrupt:' + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/060.out b/tests/qemu-iotests/060.out index 5f4264cff6..bff023d889 100644 --- a/tests/qemu-iotests/060.out +++ b/tests/qemu-iotests/060.out @@ -420,4 +420,18 @@ write failed: Input/output error {"return": ""} {"return": {}} {"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false}} + +=3D=3D=3D Testing incoming inactive corrupted image =3D=3D=3D + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 +QMP_VERSION +{"return": {}} +qcow2: Image is corrupt: L2 table offset 0x2a2a2a00 unaligned (L1 index: 0= ); further non-fatal corruption events will be suppressed +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "BLOCK_IMAGE_CORRUPTED", "data": {"device": "", "msg": "L2 table offset 0= x2a2a2a00 unaligned (L1 index: 0)", "node-name": "drive", "fatal": false}} +read failed: Input/output error +{"return": ""} +{"return": {}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false}} + + corrupt: false *** done --=20 2.17.1