From nobody Thu Nov 13 20:35:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582823087; cv=none; d=zohomail.com; s=zohoarc; b=OCZlaP8z3uphWTF4Ba2QqJbZlnu6AN9nWn4Ob7RoFYeKkxxbRiqfE+v213Ob/Wixg8IzSe180cFduK6N1nDA6olGrpN+u+jNDbtyGhNhXRCxso2nPM2N7DO4JDulvNvyReqacw5mVIcKfGJogEqpb9tHFW0Os1jL6j81lktLz2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582823087; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=uB42dRl0LlscnacMEzUBk9LawgSO8o4BEQBgFsoNVOo=; b=LaPDsw24Iyk7PiEtPGu6TRNVeCE5VHnDsiusm7jVnNO3jmJukIflmO75tA1z5CYnAYzfvzOxGFbXlUuGt1o7n4ahqdx6PNd7bsPrCe3g/tkbmYfC9eceSLEqP4xZddbDqYJ+kRjyukZqTU9NrDr4qCvLvvOFgJzViJRqkRMau24= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15828230873057.718123892269318; Thu, 27 Feb 2020 09:04:47 -0800 (PST) Received: from localhost ([::1]:35044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7Mab-0004UH-O2 for importer@patchew.org; Thu, 27 Feb 2020 12:04:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47202) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7MYw-0001m0-KW for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7MYv-0000T7-9x for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:02 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40632 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j7MYv-0000Sj-5L for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:01 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-YR-PcMy0NOK6H-QRPp5-NQ-1; Thu, 27 Feb 2020 12:02:56 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A7E7E190D358; Thu, 27 Feb 2020 17:02:55 +0000 (UTC) Received: from localhost (unknown [10.36.118.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 450E95DA75; Thu, 27 Feb 2020 17:02:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582822980; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uB42dRl0LlscnacMEzUBk9LawgSO8o4BEQBgFsoNVOo=; b=hi/HyCiT9eU0RNJCyKrr4aysCXeQdioRVSfNqrH+7+MHh11gbNTnB0UTqvhi4RDj19rXmT 6Ju3Ximo/P+VA6x9qJXheaexN/3/4XF04Pe0wBZgvlgvJAE5ZhA6iwaLyDTAmPMy1EFSnN 185yTE8F/Z2ZNIokavonIE2zZTBqJK0= X-MC-Unique: YR-PcMy0NOK6H-QRPp5-NQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 1/3] qemu-img: Fix check's leak/corruption fix report Date: Thu, 27 Feb 2020 18:02:49 +0100 Message-Id: <20200227170251.86113-2-mreitz@redhat.com> In-Reply-To: <20200227170251.86113-1-mreitz@redhat.com> References: <20200227170251.86113-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" There are two problems with qemu-img check's report on how many leaks and/or corruptions have been fixed: (1) ImageCheck.has_leaks_fixed and ImageCheck.has_corruptions_fixed are only true when ImageCheck.leaks or ImageCheck.corruptions (respectively) are non-zero. qcow2's check implementation will set the latter to zero after it has fixed leaks and corruptions, though, so leaks-fixed and corruptions-fixed are actually never reported after successful repairs. We should always report them when they are non-zero, just like all the other fields of ImageCheck. (2) After something has been fixed and we run the check a second time, leaks_fixed and corruptions_fixed are taken from the first run; but has_leaks_fixed and has_corruptions_fixed are not. The second run actually cannot fix anything, so with (1) fixed, has_leaks_fixed and has_corruptions_fixed will always be false here. (With (1) unfixed, they will at least be false on successful runs, because then the number of leaks and corruptions found in the second run should be 0.) We should save has_leaks_fixed and has_corruptions_fixed just like we save leaks_fixed and corruptions_fixed. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- qemu-img.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/qemu-img.c b/qemu-img.c index 7b7087dd60..c7567e1979 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -647,9 +647,9 @@ static int collect_image_check(BlockDriverState *bs, check->leaks =3D result.leaks; check->has_leaks =3D result.leaks !=3D 0; check->corruptions_fixed =3D result.corruptions_fixed; - check->has_corruptions_fixed =3D result.corruptions !=3D 0; + check->has_corruptions_fixed =3D result.corruptions_fixed !=3D 0; check->leaks_fixed =3D result.leaks_fixed; - check->has_leaks_fixed =3D result.leaks !=3D 0; + check->has_leaks_fixed =3D result.leaks_fixed !=3D 0; check->image_end_offset =3D result.image_end_offset; check->has_image_end_offset =3D result.image_end_offset !=3D 0; check->total_clusters =3D result.bfi.total_clusters; @@ -803,9 +803,12 @@ static int img_check(int argc, char **argv) =20 if (check->corruptions_fixed || check->leaks_fixed) { int corruptions_fixed, leaks_fixed; + bool has_leaks_fixed, has_corruptions_fixed; =20 leaks_fixed =3D check->leaks_fixed; + has_leaks_fixed =3D check->has_leaks_fixed; corruptions_fixed =3D check->corruptions_fixed; + has_corruptions_fixed =3D check->has_corruptions_fixed; =20 if (output_format =3D=3D OFORMAT_HUMAN) { qprintf(quiet, @@ -822,7 +825,9 @@ static int img_check(int argc, char **argv) ret =3D collect_image_check(bs, check, filename, fmt, 0); =20 check->leaks_fixed =3D leaks_fixed; + check->has_leaks_fixed =3D has_leaks_fixed; check->corruptions_fixed =3D corruptions_fixed; + check->has_corruptions_fixed =3D has_corruptions_fixed; } =20 if (!ret) { --=20 2.24.1 From nobody Thu Nov 13 20:35:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582823129; cv=none; d=zohomail.com; s=zohoarc; b=QHqUjFbarUAueKJ37bxyz0ra5AH2OTrY84Xyq+vaNHQF4mfG0pOEFNUIGtVKGm1Fx2ldzKMvNWxcZOenDRc2BUDIbZFRKUu8qZCYKg4LF3SWPZZB5B5F2a63wroNYkiubwA95/xau7Inw26Owd9Qx4zF39tNv/SFHDeOzAUYrIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582823129; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=fNNuMeUDHOCcalcEBI6sJ90tiH3NcqHgqyX/YOhqAdw=; b=Y/XKz1fJcYYZCias9uydktHagc+Zu6JPiX+SXlLzIstdcNFOlckbBWtm51LIBa+XRXLFLcDLUQC+RfxHikGj8vLFrSUAUdI6z/UYeVTKvxyK2w/YzNUUoSlIxCFICYDxqT2O+yprc74APepSw8KX6JNKppSeQpght6fdkoYgalo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582823129485686.1185985004986; Thu, 27 Feb 2020 09:05:29 -0800 (PST) Received: from localhost ([::1]:35062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7MbI-0005sv-Ao for importer@patchew.org; Thu, 27 Feb 2020 12:05:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47207) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7MYw-0001mT-Si for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7MYv-0000TQ-RE for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:02 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:54115 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j7MYv-0000TG-LC for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:01 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-guzpLXHePfOHKh2fpUTGew-1; Thu, 27 Feb 2020 12:02:58 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C332185EE7B; Thu, 27 Feb 2020 17:02:57 +0000 (UTC) Received: from localhost (unknown [10.36.118.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6546C60C18; Thu, 27 Feb 2020 17:02:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582822981; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fNNuMeUDHOCcalcEBI6sJ90tiH3NcqHgqyX/YOhqAdw=; b=DPQo74DZvW+RV6NMG55h30CLmUAFCpPJ5yuZBFl15qz+OR+QDiiUUffcIifie1hsctdn0v bNP5UNctJTMaOvzxVM0eDDguPjgBOju72mA4dSEuYuPXiIWWYkxOYJMyK6um3wIAFczrUv kryqWP1E/16IUrgsJvNX2DFyTOZm+DY= X-MC-Unique: guzpLXHePfOHKh2fpUTGew-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 2/3] iotests: Add poke_file_[bl]e functions Date: Thu, 27 Feb 2020 18:02:50 +0100 Message-Id: <20200227170251.86113-3-mreitz@redhat.com> In-Reply-To: <20200227170251.86113-1-mreitz@redhat.com> References: <20200227170251.86113-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Similarly to peek_file_[bl]e, we may want to write binary integers into a file. Currently, this often means messing around with poke_file and raw binary strings. I hope these functions make it a bit more comfortable. Signed-off-by: Max Reitz --- tests/qemu-iotests/common.rc | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index 4c246c0450..604f837668 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -53,6 +53,43 @@ poke_file() printf "$3" | dd "of=3D$1" bs=3D1 "seek=3D$2" conv=3Dnotrunc &>/dev/nu= ll } =20 +# poke_file_le 'test.img' 512 2 65534 +poke_file_le() +{ + local img=3D$1 ofs=3D$2 len=3D$3 val=3D$4 str=3D'' + + for i in $(seq 0 $((len - 1))); do + byte=3D$((val & 0xff)) + if [ $byte !=3D 0 ]; then + chr=3D"$(printf "\x$(printf %x $byte)")" + else + chr=3D"\0" + fi + str+=3D"$chr" + val=3D$((val >> 8)) + done + + poke_file "$img" "$ofs" "$str" +} + +# poke_file_be 'test.img' 512 2 65279 +poke_file_be() +{ + local img=3D$1 ofs=3D$2 len=3D$3 val=3D$4 str=3D'' + + for i in $(seq 0 $((len - 1))); do + byte=3D$(((val >> ((len - 1 - i) * 8)) & 0xff)) + if [ $byte !=3D 0 ]; then + chr=3D"$(printf "\x$(printf %x $byte)")" + else + chr=3D"\0" + fi + str+=3D$chr + done + + poke_file "$img" "$ofs" "$str" +} + # peek_file_le 'test.img' 512 2 =3D> 65534 peek_file_le() { --=20 2.24.1 From nobody Thu Nov 13 20:35:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582823204; cv=none; d=zohomail.com; s=zohoarc; b=KTVyjnuipTU9jLbWqUpF84Erixj0RLv3fu6ppYO47HcGFFbtpuBPvHIQJQcqc7FDVQMbsD1WbpGG4rBfpnH6RadLBZofvWQ3lZoA9nMQ3azWG+ubPfPCQB15xO3kUAvLSJ4LNYj8CwcA9260z0p0ociVsyNlJB6UnK1jc2LSzqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582823204; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=9bDbO6KfewA7HuAfE2F3liY299JJeFspK5VWfGudlE4=; b=mAX89Sv/HmkDKMNkOymMBx3r/ZODJSocDUWeXlLDKPQlJP35E7yQbvf8mG/ewx9Oz/s57vyUnkhCHHtem558fpJZ6cqkeqhGdLjwJaidhWQuBetxTnyz/bxOyx88dqw9SJSi8QTgxGMDw1k6pCRwXsyoZZm+WcGd54ZbCHitLI8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582823204900596.3134570357332; Thu, 27 Feb 2020 09:06:44 -0800 (PST) Received: from localhost ([::1]:35106 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7McV-0007Mk-EW for importer@patchew.org; Thu, 27 Feb 2020 12:06:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47282) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7MZ4-00023l-DZ for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:11 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7MZ3-0000Vl-6A for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:10 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:49444 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j7MZ3-0000VC-2h for qemu-devel@nongnu.org; Thu, 27 Feb 2020 12:03:09 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-82-DzRqpXGMMw6IYQIJfftrbQ-1; Thu, 27 Feb 2020 12:03:00 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E22B9800D5A; Thu, 27 Feb 2020 17:02:59 +0000 (UTC) Received: from localhost (unknown [10.36.118.111]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7CAFA5C57D; Thu, 27 Feb 2020 17:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582822987; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9bDbO6KfewA7HuAfE2F3liY299JJeFspK5VWfGudlE4=; b=a0SdUHLTZ7QVYGXCf99DB5VnTcEgltjTu+JM20BdMNzfl+ZCxmpNFxJKuyAEJ2Ksd2+Rt8 cmg/tDSmpeSO9Mn46eHGnzKxqpvnRNMYDrWhVOtKyn6c9LTMr1S605xfpplcC85Tk3Tcwc PWunafPpJu3vyJ+zRzuQ2m4OWWF55Xs= X-MC-Unique: DzRqpXGMMw6IYQIJfftrbQ-1 From: Max Reitz To: qemu-block@nongnu.org Subject: [PATCH 3/3] iotests/138: Test leaks/corruptions fixed report Date: Thu, 27 Feb 2020 18:02:51 +0100 Message-Id: <20200227170251.86113-4-mreitz@redhat.com> In-Reply-To: <20200227170251.86113-1-mreitz@redhat.com> References: <20200227170251.86113-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Test that qemu-img check reports the number of leaks and corruptions fixed in its JSON report (after a successful run). Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- tests/qemu-iotests/138 | 41 ++++++++++++++++++++++++++++++++++++-- tests/qemu-iotests/138.out | 14 +++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/138 b/tests/qemu-iotests/138 index 54b01046ad..25bfbd4cca 100755 --- a/tests/qemu-iotests/138 +++ b/tests/qemu-iotests/138 @@ -41,8 +41,10 @@ _supported_fmt qcow2 _supported_proto file _supported_os Linux # With an external data file, data clusters are not refcounted -# (and so qemu-img check does not check their refcount) -_unsupported_imgopts data_file +# (and so qemu-img check does not check their refcount); +# we want to modify the refcounts, so we need them to have a specific +# format (namely u16) +_unsupported_imgopts data_file 'refcount_bits=3D\([^1]\|.\([^6]\|$\)\)' =20 echo echo '=3D=3D=3D Check on an image with a multiple of 2^32 clusters =3D=3D= =3D' @@ -65,6 +67,41 @@ poke_file "$TEST_IMG" $((2048 + 8)) "\x00\x80\x00\x00\x0= 0\x00\x00\x00" # allocate memory", we have an error showing that l2 entry is invalid. _check_test_img =20 +echo +echo '=3D=3D=3D Check leaks-fixed/corruptions-fixed report' +echo + +# After leaks and corruptions were fixed, those numbers should be +# reported by qemu-img check +_make_test_img 64k + +# Allocate data cluster +$QEMU_IO -c 'write 0 64k' "$TEST_IMG" | _filter_qemu_io + +reftable_ofs=3D$(peek_file_be "$TEST_IMG" 48 8) +refblock_ofs=3D$(peek_file_be "$TEST_IMG" $reftable_ofs 8) + +# Introduce a leak: Make the image header's refcount 2 +poke_file "$TEST_IMG" "$refblock_ofs" "\x00\x02" + +l1_ofs=3D$(peek_file_be "$TEST_IMG" 40 8) + +# Introduce a corruption: Drop the COPIED flag from the (first) L1 entry +l1_entry=3D$(peek_file_be "$TEST_IMG" $l1_ofs 8) +l1_entry=3D$((l1_entry & ~(1 << 63))) +poke_file_be "$TEST_IMG" $l1_ofs 8 $l1_entry + +echo +# Should print the number of corruptions and leaks fixed +# (Filter out all JSON fields (recognizable by their four-space +# indentation), but keep the "-fixed" fields (by removing two spaces +# from their indentation)) +# (Also filter out the L1 entry, because why not) +_check_test_img -r all --output=3Djson \ + | sed -e 's/^ \(.*\)-fixed"/\1-fixed"/' \ + | grep -v '^ ' \ + | sed -e "s/\\<$(printf %x $l1_entry)\\>/L1_ENTRY_VALUE/" + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/138.out b/tests/qemu-iotests/138.out index aca7d47a80..79681e7cc9 100644 --- a/tests/qemu-iotests/138.out +++ b/tests/qemu-iotests/138.out @@ -9,4 +9,18 @@ ERROR: counting reference for region exceeding the end of = the file by one cluste =20 1 errors were found on the image. Data may be corrupted, or further writes to the image may corrupt it. + +=3D=3D=3D Check leaks-fixed/corruptions-fixed report + +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D65536 +wrote 65536/65536 bytes at offset 0 +64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +Leaked cluster 0 refcount=3D2 reference=3D1 +Repairing cluster 0 refcount=3D2 reference=3D1 +Repairing OFLAG_COPIED L2 cluster: l1_index=3D0 l1_entry=3DL1_ENTRY_VALUE = refcount=3D1 +{ + "corruptions-fixed": 1, + "leaks-fixed": 1, +} *** done --=20 2.24.1