From nobody Wed Aug 26 07:25:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1786463030; cv=none; d=zohomail.com; s=zohoarc; b=Awu9F33r8InacHorDQwrufAV0GYpqtIzs7pnGCw6NfkiIXs+O8kh9rRB/u+FKyoFH3cKo0BAN1vh5DYVsxw5trkPJfJulGeRtdP2zT1IKJzRGmlQ2nURSWd1kZMy95Vk+m/yuImOT/wtfq52mH7+a8YyygJ+3Dkoon6e9jg8XE4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786463030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xdgqlKtTotTQsDwD3eVNqnrjorchCaz1rInhMcHrFds=; b=K6KCAcM1D+5hL4jJ76Nk7t7C25Ictm3ZWPn67g0BXWwifp6THAN5xrHrg+MSnM/s4djkRZcqrUPwiVR7VNuXlhsEreKSh+UloGDIje0QNEG1Za+Y8/tPOjXbj4lhRlbCr9z3twREpj7k/rkoFPxSKGyz+RoXSSEvcqROgm3j+Zo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786463029953255.12920440086282; Tue, 11 Aug 2026 08:43:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wtocf-0007w2-E3; Tue, 11 Aug 2026 11:42:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wtocd-0007uP-LG for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:35 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wtocN-00048A-6R for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:35 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-6a063d211ebso4226408a12.3 for ; Tue, 11 Aug 2026 08:42:18 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c43:d230:7bbc:68d4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a362e34d4bsm841128a12.12.2026.08.11.08.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1786462938; x=1787067738; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xdgqlKtTotTQsDwD3eVNqnrjorchCaz1rInhMcHrFds=; b=gde3Uv1Ix7FPu54YnMz/e4fmtl/PmZ/vm1w1Id+bVrSYigXx19xPaIKxEabpLHVGHg yj0JRMB6cPudTHGPyXOCYaT+53GWmyS/1KEm/f64W56EBOTh1DwC9Ff16QwOjy6VWZEp JGkz2+FiIuWQ3iQYTlXoq3QidaJYdG6qnGpZR2S5TFeXnZxLgp1MSZ+5h+9aBg/SfIAK 512DqXXvrZojAe0WPrWmv+6PCDrgMQTP6vCQAOapmPz2lcvSO8jpWXc+1plNN478MAN3 CL/8I8YPD9OiRZXT9s0gHlrHkTaXKT+lK+HOlZ+8Hmyg0zRLwp7i6E2ktTIGnuFwpGfO Q9OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462938; x=1787067738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xdgqlKtTotTQsDwD3eVNqnrjorchCaz1rInhMcHrFds=; b=ZdXqH10AapYT/lriUe8oN9u3DaSLaEgUhWrvDVgjsEAYa3XAD9XQC7fPm9R9CZ9RQc 273z+hQP8beWmUxuYxPYFhKziwK+SLg+tkL5kurVJHbKlJXvyICw5n7lKHCUAeN50tQZ f29P9qtVuZF83cINYZqqYiSNBhfogRSVf0ggPXXiWf0FwMZnFt7PmR6dKP71kOdbGFNh 5/gh5OzjLjHHjHxpI7k0AgLr0Lph1cnm5F7mlfq9MySbOJ3DdCcfsN6EosLCxK3x+cV4 sUzj6NHvtAR+aYxraO/tAOptgJ6RlK7MgthzPpDd4KdxbLDKjrNHQ8ratMlxTIw1vBXL g3Bw== X-Gm-Message-State: AOJu0YzGYQkKqgQsko6x5+SeD08iFILCPxmyJtETXAWFgms4N4KzvJJ1 l1p25Mb52cYHHrinXDDE/KfQmseO9o+adPYBF/HGYtbok5tsoTeg91BBIPX27ISZpTP4udgWj3V 1/51w X-Gm-Gg: AR+sD10/dpa08Xyx0U6FqLDdVArmofLo5H2/AR2vP2h5Lc9an6O22A/JV6io1DxomgA fdHlbZfV/J3ND1EPs1IHjQkaA+G4lXq56I8i7U4erWf75aWyyq++gMsVBGE0ea9dpVFolx37NDs foDqcH3jAHMod+JwEaIWabZTyIHqShrv+0gueJByRvwpgwgku+S5HXfgIzCYvDHaqH3oC9wJvZF WGVTfJRIfO4MPUn4LUZEA4jLurTlUA8dZHfjTryCsnkopJO27K+n1zGKguG39GPK3vjp1yftODW KuttmkbYEQVoCoJVwYYhdNIwRKHRY8NY7+j5mgcehE3yEYYjHPuy1aS6mfHUf81fDP8x0auazpD /EvT++eJk/2WlodYzQSbiWC8cawvva5oYfJgJAmENILNtAj1fEOa5kgW/xjftnzEY1d2JAK3xK+ rDTcT1JUCWr74og6IXtVkhCYM8wvQJG1+CFBBgrwFOZOUMEo4q57kq1qb7 X-Received: by 2002:a17:906:7953:b0:c12:67d2:3d6b with SMTP id a640c23a62f3a-c20e616f45amr199720266b.11.1786462937637; Tue, 11 Aug 2026 08:42:17 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Kevin Wolf , Hanna Reitz , Andrey Drobyshev , qemu-stable@nongnu.org Subject: [PATCH v2 1/4] qcow2: do not clear the dirty bit when reopening a read-only node Date: Tue, 11 Aug 2026 17:42:10 +0200 Message-ID: <20260811154213.184947-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811154213.184947-1-den@openvz.org> References: <20260811154213.184947-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=den@openvz.org; helo=mail-ed1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1786463031073158500 Content-Type: text/plain; charset="utf-8" qcow2_reopen_prepare() clears the dirty bit whenever the node is reopened read-only, with an unguarded header write. A read-only node can still be dirty, inherited from an earlier writable session, and it holds no BLK_PERM_WRITE to resolve that. A read-only to read-only reopen of a dirty image therefore fails outright: $ qemu-io -r -f qcow2 dirty.qcow2 <<< $'reopen -r\nquit' qemu-io: failed while preparing to reopen image 'dirty.qcow2' Clear it only for a node that is writable now, the predicate qcow2_do_open() already uses for the repair. bdrv_is_writable() also excludes an inactive node, whose header must not be touched either. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Andrey Drobyshev Cc: qemu-stable@nongnu.org Reviewed-by: Andrey Drobyshev --- block/qcow2.c | 8 +++++--- tests/qemu-iotests/039 | 10 ++++++++++ tests/qemu-iotests/039.out | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 7292dd036c..1543255eba 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2102,9 +2102,11 @@ qcow2_reopen_prepare(BDRVReopenState *state,BlockReo= penQueue *queue, goto fail; } =20 - ret =3D qcow2_mark_clean(state->bs); - if (ret < 0) { - goto fail; + if (bdrv_is_writable(state->bs)) { + ret =3D qcow2_mark_clean(state->bs); + if (ret < 0) { + goto fail; + } } } =20 diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039 index 94a8bfe754..db52c580d1 100755 --- a/tests/qemu-iotests/039 +++ b/tests/qemu-iotests/039 @@ -95,6 +95,16 @@ $QEMU_IMG info --image-opts \ # The dirty bit must still be set: this open never wrote any guest data _qcow2_dump_header | grep incompatible_features =20 +echo +echo "=3D=3D Read-only reopen must not clear the dirty bit =3D=3D" + +# A read-only node cannot write the header, and must keep the dirty bit +$QEMU_IO -r -c "reopen -r" -c "read -P 0x5a 0 512" "$TEST_IMG" \ + | _filter_qemu_io + +# The dirty bit must still be set +_qcow2_dump_header | grep incompatible_features + echo echo "=3D=3D Repairing the image file must succeed =3D=3D" =20 diff --git a/tests/qemu-iotests/039.out b/tests/qemu-iotests/039.out index c66361128f..3c71e5a3dd 100644 --- a/tests/qemu-iotests/039.out +++ b/tests/qemu-iotests/039.out @@ -27,6 +27,11 @@ incompatible_features [0] =3D=3D Read-only open must not crash on close =3D=3D incompatible_features [0] =20 +=3D=3D Read-only reopen must not clear the dirty bit =3D=3D +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +incompatible_features [0] + =3D=3D Repairing the image file must succeed =3D=3D ERROR cluster 5 refcount=3D0 reference=3D1 Rebuilding refcount structure --=20 2.53.0 From nobody Wed Aug 26 07:25:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1786463047; cv=none; d=zohomail.com; s=zohoarc; b=C+KYpEUT7nTBM6KbDmvLJIKOVj7Q0PzWocYpcpH1HSs4MJSGm/DQ9qoMOm4GspCP+LaEsz3SrJJpoSaizFvpA3dr3DI1xkIvq7IHGeV7pT36U+ALojTa1Q5QRfgMASzaENmac8FVjfDI4IMjY8AfVe8DdsgbLlv+ps+va1VR7Hs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786463047; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=XszDXri9oioBWSiRYQNcTPMrJR0fmQwMZNwkcF35QUY=; b=hnHUly+OPTh4JzgWX9FxF4c5Ien/RJ231LkpTBSVN0WbRQYiTnXz9BZuicI0oVqRn7WQesT7HbtOEDPDWZIsD/2XALpjHZFoLI1pYgLRY1JTeJxhqKWsfRaYnPbwDlTtQSiucW5BjE47EvWDFGPQC5kx2EMNmCqVLV0BHK0SiaA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178646304711775.14116585250576; Tue, 11 Aug 2026 08:44:07 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wtocg-0007wo-FG; Tue, 11 Aug 2026 11:42:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wtocf-0007vQ-1u for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:37 -0400 Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wtocO-00049R-JJ for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:36 -0400 Received: by mail-ed1-x530.google.com with SMTP id 4fb4d7f45d1cf-6a0a4a17f91so5025817a12.1 for ; Tue, 11 Aug 2026 08:42:20 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c43:d230:7bbc:68d4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a362e34d4bsm841128a12.12.2026.08.11.08.42.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:42:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1786462939; x=1787067739; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=XszDXri9oioBWSiRYQNcTPMrJR0fmQwMZNwkcF35QUY=; b=XwLo2PwHrNvU+Qz0ZNU5gDiBrRKaTKSiBkHbvRR0+H2SRztRlK1rtmu5DN1DMWODvg uMq2HQbyGAq6Hca1dIRXxWQIoF4s753LZA1YbYwqJoFnAwIqzVng5COodoFrcFitW9ME Ppdjv+HYYkEmF5OMu+bcHVQl0dqGRHngpXcKiUEb1z87Jb5lmrJA2U9KdccS8XkvifGw 76MWD1UzpoZKeHlPZo8YJpg347PLnKOZvmE5vJmrNR89uQOnuzvlErJZIxot33AShz3k hWuIdQAMHnSdsyGWuECGNA0YkESMtNiyifG+naOTeJTM5hm3zGbdGYQjc7LbRE8vN4RC CXjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462939; x=1787067739; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=XszDXri9oioBWSiRYQNcTPMrJR0fmQwMZNwkcF35QUY=; b=J2iUWTgiorzQ5fz4Sql2OtEDe0w76ApX94ryue+ew9hlY1wXuJ9pcVvF9uD+NgRZ58 45FVfluTQmhMYMQjjH3Qy697JDruG52U32JkpcGT0WXfItwjKkJ9T9Lfa5jQkpt+0HZb AU2hSEgpWkpCbbr2M1/oC9vD1KgJEj/6bjKNQCwNUDj0uUG/3S5JXLhJuvi/e1MMNiCg 6DpzRXUiY3Gd8JKhIdsXQT0glvOw22j+R0yrGDiEW4YfIs9j1bYnjzGdORTtIR/frxn4 sL9VWR5YGpUQpk6HAPgzC8mLHndGznLtlOUZXALDQTg9e/srJB6nVXpqAJAghHxhzjAH l/Ig== X-Gm-Message-State: AOJu0YwXUKEkJRUF9ISH4p1Fc7yhK5FQKfr9M8n2fw/JPNDfSSQBM44O 5tVHil8O+XpL2AkTEmUoKD8/h/XRvZ9wE8klkE8qH3bctCpmGzv7iiyW/3LZiGNyJPhnnCc6lRG +whmn X-Gm-Gg: AR+sD13kxQs9TBVzxH7Zf8HUHADsvGDODriqiTWHrtFfB3qLeHiX4bCyrKYxtb+Wpx6 3GFvRXHGq9Ayer4dMqtPcFl3i+z2+dCOznVNLLDQI98cldYuDuUJNJxRZkMC7au8aPypENo6zn/ Rl99EdXWIfaEfEGf6C3YNT+ihDvaSUc6UU4UJe1dBEJUbvtD0v3OdyUYHwr/g1wrGSsTzUB2g3V weN0K985gPzd2BBjORRZybfn3u5BiQOcy0LL1lQ4bW3QrUPyswoVjTJ4yScoZmO76rIlJ0ptnW7 EYzXmWdtiIirnRJ7fFXNWAS0IWqccvfLggGG7UyiMojuM9fPQb9kxGd2wG6NpexlYyKaI4Kio16 L/lSgwQn5toX57TSzEJdpAYBqiMAZjYUF+Hh9s1cdyS5oEeAG/L/fPXIW7qj35ITY793nsc6YKK LI3l0b2nrg04cejxi0BpJtEFgm3nLPPF4Z19l4JKvPXXBCRjpIjAytuRF0 X-Received: by 2002:a05:6402:24c4:b0:698:8847:e2f8 with SMTP id 4fb4d7f45d1cf-6a36450c2a0mr1888445a12.15.1786462938798; Tue, 11 Aug 2026 08:42:18 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Kevin Wolf , Hanna Reitz , Andrey Drobyshev , qemu-stable@nongnu.org Subject: [PATCH v2 2/4] block: let bdrv_reopen_commit_post() report a failure Date: Tue, 11 Aug 2026 17:42:11 +0200 Message-ID: <20260811154213.184947-3-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811154213.184947-1-den@openvz.org> References: <20260811154213.184947-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=den@openvz.org; helo=mail-ed1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1786463049294158500 Content-Type: text/plain; charset="utf-8" The callback runs after bdrv_reopen_multiple() has committed the transaction, so it cannot reject the reopen. It can still find that the node it has just made writable is unusable, and has no way to say so: bdrv_reopen() returns success and the caller carries on. Give it a return value and an Error argument. The reopen stays committed, the error only reports that the node is gone. Every queued node still gets its callback, the first error is the one reported. qcow2 is the only implementation and does not fail yet. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Andrey Drobyshev Cc: qemu-stable@nongnu.org --- block.c | 18 +++++++++++++++--- block/qcow2.c | 4 +++- include/block/block_int-common.h | 5 +++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index f0a6042e61..99ed06f8ca 100644 --- a/block.c +++ b/block.c @@ -4653,15 +4653,27 @@ int bdrv_reopen_multiple(BlockReopenQueue *bs_queue= , Error **errp) tran_commit(tran); bdrv_graph_wrunlock(); =20 + ret =3D 0; QTAILQ_FOREACH_REVERSE(bs_entry, bs_queue, entry) { BlockDriverState *bs =3D bs_entry->state.bs; + Error *local_err =3D NULL; + int commit_ret; =20 - if (bs->drv->bdrv_reopen_commit_post) { - bs->drv->bdrv_reopen_commit_post(&bs_entry->state); + if (!bs->drv->bdrv_reopen_commit_post) { + continue; + } + + commit_ret =3D bs->drv->bdrv_reopen_commit_post(&bs_entry->state, + &local_err); + if (commit_ret < 0 && ret =3D=3D 0) { + /* Committed already, so report the first failure and go on */ + error_propagate(errp, local_err); + ret =3D commit_ret; + } else { + error_free(local_err); } } =20 - ret =3D 0; goto cleanup; =20 abort: diff --git a/block/qcow2.c b/block/qcow2.c index 1543255eba..553a94d003 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2145,7 +2145,7 @@ static void qcow2_reopen_commit(BDRVReopenState *stat= e) g_free(state->opaque); } =20 -static void qcow2_reopen_commit_post(BDRVReopenState *state) +static int qcow2_reopen_commit_post(BDRVReopenState *state, Error **errp) { GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 @@ -2163,6 +2163,8 @@ static void qcow2_reopen_commit_post(BDRVReopenState = *state) bdrv_get_node_name(state->bs)); } } + + return 0; } =20 static void qcow2_reopen_abort(BDRVReopenState *state) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 147c08155f..61e6621c93 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -239,8 +239,9 @@ struct BlockDriver { BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **er= rp); void GRAPH_UNLOCKED_PTR (*bdrv_reopen_commit)( BDRVReopenState *reopen_state); - void GRAPH_UNLOCKED_PTR (*bdrv_reopen_commit_post)( - BDRVReopenState *reopen_state); + /* Cannot fail the reopen, an error only reports an unusable node */ + int GRAPH_UNLOCKED_PTR (*bdrv_reopen_commit_post)( + BDRVReopenState *reopen_state, Error **errp); void GRAPH_UNLOCKED_PTR (*bdrv_reopen_abort)( BDRVReopenState *reopen_state); void (*bdrv_join_options)(QDict *options, QDict *old_options); --=20 2.53.0 From nobody Wed Aug 26 07:25:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1786463030; cv=none; d=zohomail.com; s=zohoarc; b=lDT+D6KQUlkLqykZnd+L+KYNRf7lvatZ6Y8pyd3KPWGxZq6RpYAaVHcOwcyswTlgKVv44QOuFtsmno0t3VGNsBgU5b0fVQfTkc4wVhBOaOyi9HUDMiplBCApA+jDvFCIh1eS7y4mqA9vhzyC9hp2WBUZkbPfwYC8WJe6DgY7tPQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786463030; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7V+Ujk44PJvZHDttbRgVQxc94DYK+G9QIRN+pGmRpvA=; b=Lp6IcBeXXAXgTC6l3rIrmjR6Jz1WAdNv1/URtE4CP4uWK1IoepGxkoJJ70F8EnHM+qSJmZiFZZEGgGQeHWVvlND8M+eF1mnAtj3F1PwtjFAT0/KUlHr6SihdQbQZazVIMf5IJr9Z0ZmpC4ekSNI8b/9xsmj37Tg1fqe/hoHXlSc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786463030861592.3994456982045; Tue, 11 Aug 2026 08:43:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wtocj-0007yR-ER; Tue, 11 Aug 2026 11:42:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wtoch-0007xd-6L for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:39 -0400 Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wtocQ-0004CC-Cm for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:38 -0400 Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-6a144c8eea2so5161451a12.0 for ; Tue, 11 Aug 2026 08:42:21 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c43:d230:7bbc:68d4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a362e34d4bsm841128a12.12.2026.08.11.08.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1786462941; x=1787067741; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7V+Ujk44PJvZHDttbRgVQxc94DYK+G9QIRN+pGmRpvA=; b=goYlhNtYLGhzqyZYfc84jDGKRq7Ezdi0iwlrFrQRPWSiKln8X9J/+v2u7JhGlEwtGj 4d/Xbn3Vxrdz6z5FjYVnMCGeIMoZwr9h/HYDpFJzNdVhMfwN0Td1yanaUI129giYHkJR xyY2FtRgoqhNnSj4oMlqFLLiMpVfBjhdZ7IRJayl8KaQSrFnApabQKXTcJQ0J/OzgKiK NVzI1crNcKlrKswWh+MnIx50nWELd7ivZfvjdmLfAXFYYA7w9cyf5CRV6kZpCPA5eiqe CSUjNYZxpOXXZmOPUlGPrlagpGcS9n2b6xqKlIXsvgoGw/DlIv8uqfcmwsUlWTpPAJmZ RO4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462941; x=1787067741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=7V+Ujk44PJvZHDttbRgVQxc94DYK+G9QIRN+pGmRpvA=; b=dJEW1MmdwCNkXLAIiO6cK8ahkqlaMWVnI4fcwUi/f47Cb+lWXwsvrqQvDKS9XOGccP f15WEEgRV6rgFUsObQETAuFImZHJ6nE4V50FfxsE6JqeaFGyE/NQyZvVm4AR/EIkmd7V SWU76HBtOxHq3moBMM4rR4HdneNjzy6da6yQ74bKqGQSyqtul2FcrKuFfOsC5tqodOvW Mrymf1zX4aUXZ1XXqQJmBHOM/Bwp/IihJ+dQMiX/IeJcDt/ZnzvKOLhDrLtgjEXpCiOd v9OKJtRNRezy28E00LTN5Dl7INqs0IrVpyUHGxSwBiRwSD6oa4Qp/xrFey0f+QsZR3vL LQ0w== X-Gm-Message-State: AOJu0YzYoYA5NCA7cXFQ6Ql/UzuXhdZDOV331Y3p+wzWm9HY/eA5pnrk gJLJo843WOGh3jx6BbcvTg6rZO7RQ7KlbbAACU41zSL9aUJoR1mIDO49UDSY5ypPiv5kA/x50qv 5sV4E X-Gm-Gg: AR+sD13gTlxpGhn5u4Z25L9/L4KfEO9YI3apbOE+aIEIRSxRB0zjItH/8NunZPHc+RO qigT+uhEPqobAlS9MbkV9DB+OTZJUXo2KIbVpBJDCFMaLS7WrVUBcbFDFH6deDunUNJbzYJ6KxZ N354tTJVqnOD7aNATD0ytuI7U2bpfwb5MW1ocDnCpTawsnX+xhVbnyj4ECrs1LnazImL8MWYGj1 LYa8xWV68xRdX7KD8s2atXhbyVlLmfb1CX3uDGBx1NgpAlY/b8f/l2oc4TgODhGVcGFCL8mNXvg pRklTrzBmghoC2JgYCGxFih0XUsyPc59Yb2m5B5DGb4YpMxdAepcxjRx4D8A7hEdW2mXwoiGPJi 5biGW21aPiixDqJpkisCNmfvGfkj15k3lFYd29K/yEqFkAY8Dcs1XvnrjeDbKE/gG3Ml3vxCf+a SsPa0ySIzwaEHDiYNKCqqkV+HU3LirAOWJQl5ALOer98eV2rE1QRDR0xPV X-Received: by 2002:a05:6402:4283:b0:69c:6547:518b with SMTP id 4fb4d7f45d1cf-6a3644ed12amr2220408a12.12.1786462940709; Tue, 11 Aug 2026 08:42:20 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Kevin Wolf , Hanna Reitz , Andrey Drobyshev , qemu-stable@nongnu.org Subject: [PATCH v2 3/4] block: remember the writability a reopen starts from Date: Tue, 11 Aug 2026 17:42:12 +0200 Message-ID: <20260811154213.184947-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811154213.184947-1-den@openvz.org> References: <20260811154213.184947-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=den@openvz.org; helo=mail-ed1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1786463032887158500 Content-Type: text/plain; charset="utf-8" bdrv_reopen_commit() updates bs->open_flags, so by the time .bdrv_reopen_commit_post() runs a driver can no longer tell whether the node has just become writable or was writable all along. Only the transition is worth reacting to. Record the value while the queue is built, next to the other pre-reopen state BDRVReopenState already keeps. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Andrey Drobyshev Cc: qemu-stable@nongnu.org --- block.c | 1 + include/block/block-common.h | 1 + 2 files changed, 2 insertions(+) diff --git a/block.c b/block.c index 99ed06f8ca..c50d9474fc 100644 --- a/block.c +++ b/block.c @@ -4473,6 +4473,7 @@ bdrv_reopen_queue_child(BlockReopenQueue *bs_queue, B= lockDriverState *bs, bs_entry->state.options =3D options; bs_entry->state.explicit_options =3D explicit_options; bs_entry->state.flags =3D flags; + bs_entry->state.was_writable =3D bdrv_is_writable(bs); =20 /* * If keep_old_opts is false then it means that unspecified diff --git a/include/block/block-common.h b/include/block/block-common.h index 895ea17541..f64b2d6f35 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -360,6 +360,7 @@ typedef struct BDRVReopenState { int flags; BlockdevDetectZeroesOptions detect_zeroes; bool backing_missing; + bool was_writable; /* bs->open_flags is updated on commit */ BlockDriverState *old_backing_bs; /* keep pointer for permissions upda= te */ BlockDriverState *old_file_bs; /* keep pointer for permissions update = */ QDict *options; --=20 2.53.0 From nobody Wed Aug 26 07:25:03 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=quarantine dis=none) header.from=openvz.org ARC-Seal: i=1; a=rsa-sha256; t=1786463042; cv=none; d=zohomail.com; s=zohoarc; b=aekXfQuL8oqlu2uTj5D1h0mQPWYtMIQ+OerB2NE4EPT1KNY1VHpBzVSvWyOsKy1keWWTniPoNCaQIVgyhGPqqEBoytVXEpdt9nZGV8IZLPzm/RWgNiuKbtQOR5S0hBY63ZJ3hRgAMGl29WbGIjce6CeUT1HCwO5dYCUb9LzFn2Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1786463042; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=T8YkIbuYP6oHQdOgTR0NrIthQ4doKOz3zlklOIKET+U=; b=HHk9bT3BFF1xaU+kR/gYuuajuK/CDPGqBNUNRsRL4PfrZSW7iYvAlArGmlRaoHhsuu4m8PaD8MYD4CjNfBzJpWzYxfOxLwOEum04bIS/b5GgWgWtJS3tm4U2HhWwkdMh0VCbcAznKipnvEmAfHpmt4A0S/1GOYk3euYxC9Nzu1I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1786463041930718.3450058248825; Tue, 11 Aug 2026 08:44:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wtocj-0007zN-Sf; Tue, 11 Aug 2026 11:42:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wtoci-0007y8-63 for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:40 -0400 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1wtocR-0004EW-TN for qemu-devel@nongnu.org; Tue, 11 Aug 2026 11:42:39 -0400 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-69f7fa1c548so5117105a12.2 for ; Tue, 11 Aug 2026 08:42:23 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:c43:d230:7bbc:68d4]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a362e34d4bsm841128a12.12.2026.08.11.08.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Aug 2026 08:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1786462942; x=1787067742; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=T8YkIbuYP6oHQdOgTR0NrIthQ4doKOz3zlklOIKET+U=; b=PAC3beZ638BYg+suie0a8S5qqApJGG6fWxc5OQMHIaAkkQWZlQW/QZiwqmWfPk7YZ9 5uuFiakv2k1an+5AE+s+NdQGWnUYTxvplMZxntkJWVXcaRpXjssW1+7fWVa8ruk4tZMv JMigQ0G1WeB/wsTD51cbcvqQmmtlMBaMtEcPw3KwCSzvK5xed0kf1rPCF9wyDwQEG/xT dCgKAobCl3kYn+vs+xUxFkvaoKdJ3yc8hbC3hK968/RDkFf2GQupD76qJuScRhhb1cJp pC7yoCQnfDBR0OUr61c8eP7IVL6REXyeOYfS+q/M1jQw+XGx3a01W1vOOecAsYv19gCm 6m+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786462942; x=1787067742; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=T8YkIbuYP6oHQdOgTR0NrIthQ4doKOz3zlklOIKET+U=; b=Uru0EyBuBEc/RTunk/fs4L8L59JX+95SRIwrhMKrr+prEYrPaOmQgt12sGR/heeWLY FlXAYXwSQ1xXfvLtoznUw5qtbsAtECa7NMKMnQW2A3303DH4K7zlvevLDpRjhn9ffz4w ycneOZGidMC6hr18sIfKtVIVdAxazDUmxfPqCS5pF9Pm8P9z2kwMA6XfMJpX9YkzSRNs 9HxGO0Tr1F2UAah2ONztIz7b0o4Hx12ByPUgXUBYuSxYgE3RXKH6aHPT2WtmOoedg9kO YofXwXInBW2UuhkjWHRoqh2OAkZnQsLYW9NenF0AKgYZ1lBWfun/xp1cEgTaZgaS8L6h l+4w== X-Gm-Message-State: AOJu0YwRKo0vJ4AMq8tK1JExSezPhDuiKMWdAcP+rQ6doTNyUf9gETsp h8lCCyB9yPcBaKBdUdRxlcDIBff6q5qDjd/7va0PqLFbgHipWQDJLIVddcxKA376EZOhpdbXguE KncmC X-Gm-Gg: AR+sD12uobKzcsWJBY1vLhIo77qAMr6Fh5oCQdareJKOYOP18yK3BfVm8Qx18cD6nqP NHC56dIljEBULbLouIrqrmIRTk1ADzRWdKyXu+UTMzahXIeYXa/bskfaYSeAsZ8vOotK1egPV/j LXEj+40ksu4rEBNCs5ahiguR2moRsozK2LnxUM5Am18BlW3htqpS6YZoT7Q+kIMDc096e/2Aas1 0N2PkuiL5qxOaesDkui58efkIb3Z2L/nB6YSZsAHNz56GdBzXCmRondl8j8UCLOC2NMbv1Rc5Ua S6s+1wEMLfvMuzzGpzn/xexBw7/qolVXaZmgAQwbcPpwEmn0lQEaS+BglGPz2SQr45HD0FowG1p UliP5S5zQC2Z/GONRkQUe/f3zJIHEwfOzAb/JKzf9aQ0T7WKZ+TOgYSVNG/pX2BTyajzRdbh1wE 9u0IcvTjWxW17RgZMUSwE6JZCEG3i2PUUOHZi0nGsiSO4IQ33JMBNk5w8z X-Received: by 2002:a05:6402:4544:b0:698:4992:77e7 with SMTP id 4fb4d7f45d1cf-6a36449d25amr2161717a12.7.1786462942412; Tue, 11 Aug 2026 08:42:22 -0700 (PDT) From: "Denis V. Lunev" To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, "Denis V. Lunev" , Kevin Wolf , Hanna Reitz , Andrey Drobyshev , qemu-stable@nongnu.org Subject: [PATCH v2 4/4] qcow2: repair a dirty image when it becomes writable Date: Tue, 11 Aug 2026 17:42:13 +0200 Message-ID: <20260811154213.184947-5-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260811154213.184947-1-den@openvz.org> References: <20260811154213.184947-1-den@openvz.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=lists1p.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::52b; envelope-from=den@openvz.org; helo=mail-ed1-x52b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @openvz.org) X-ZM-MESSAGEID: 1786463042762158500 Content-Type: text/plain; charset="utf-8" A dirty image must be repaired before anything allocates a cluster in it. qcow2_do_open() does that, but only for a node that is writable from the start. A node opened read-only skips it, and nothing revisits the question once that node becomes writable, which block-commit does routinely: commit_active_start() and commit_start() reopen the base read-write for the duration of the job. With lazy refcounts the on-disk refcount block then still accounts for the metadata clusters only, so the allocator restarts at the front of the image and hands out clusters that L2 entries point at. Two guest offsets end up sharing one host cluster. Nothing fails, the corrupt bit stays clear, and a clean close clears the dirty bit, so no later open repairs the image either. Do the repair in qcow2_reopen_commit_post(). bdrv_reopen_prepare() runs before bdrv_list_refresh_perms(), so it holds no BLK_PERM_WRITE and, with auto-read-only, bs->file may still have an O_RDONLY descriptor. commit_post cannot reject the reopen, so signal corruption if the repair fails rather than let writes alias live clusters. That drops bs->drv, so return the error and skip the bitmaps. An inactive node is skipped: bdrv_activate() calls qcow2_do_open() again through qcow2_co_invalidate_cache(). With lazy refcounts the dirty bit stays set for the whole writable session, so a node that is merely writable says nothing. Repair only when it has just become writable, which BDRVReopenState remembers: a read-write to read-write reopen must not scan a live image. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Andrey Drobyshev Cc: qemu-stable@nongnu.org --- block/qcow2.c | 17 +++++++++++ tests/qemu-iotests/039 | 60 ++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/039.out | 36 +++++++++++++++++++++++ 3 files changed, 113 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 553a94d003..bac3e49cf5 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2147,8 +2147,25 @@ static void qcow2_reopen_commit(BDRVReopenState *sta= te) =20 static int qcow2_reopen_commit_post(BDRVReopenState *state, Error **errp) { + BDRVQcow2State *s =3D state->bs->opaque; + GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 + if (!state->was_writable && bdrv_is_writable(state->bs) && + (s->incompatible_features & QCOW2_INCOMPAT_DIRTY)) { + BdrvCheckResult result =3D {0}; + int ret; + + ret =3D bdrv_check(state->bs, &result, BDRV_FIX_ERRORS | BDRV_FIX_= LEAKS); + if (ret < 0 || result.check_errors) { + /* This clears bs->drv, there is nothing left to reopen */ + qcow2_signal_corruption(state->bs, true, -1, -1, + "Could not repair dirty image"); + error_setg(errp, "Could not repair dirty image"); + return -EIO; + } + } + if (state->flags & BDRV_O_RDWR) { Error *local_err =3D NULL; =20 diff --git a/tests/qemu-iotests/039 b/tests/qemu-iotests/039 index db52c580d1..dd4f48fa14 100755 --- a/tests/qemu-iotests/039 +++ b/tests/qemu-iotests/039 @@ -136,6 +136,66 @@ $QEMU_IO -c "write 0 512" "$TEST_IMG" | _filter_qemu_io # The dirty bit must not be set _qcow2_dump_header | grep incompatible_features =20 +echo +echo "=3D=3D Reopening a dirty image read/write should repair it =3D=3D" + +_make_test_img -o "compat=3D1.1,lazy_refcounts=3Don" $size + +_NO_VALGRIND \ +$QEMU_IO -c "write -P 0x5a 0 512" \ + -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ + | _filter_qemu_io + +# The dirty bit must be set +_qcow2_dump_header | grep incompatible_features + +# Without the repair this write would alias the cluster at offset 0 +$QEMU_IO -r -c "reopen -w" \ + -c "write -P 0xb1 1M 512" \ + -c "read -P 0x5a 0 512" "$TEST_IMG" | _filter_qemu_io + +# The dirty bit must not be set +_qcow2_dump_header | grep incompatible_features +_check_test_img + +echo +echo "=3D=3D A read/write reopen must not check the image =3D=3D" + +_make_test_img -o "compat=3D1.1,lazy_refcounts=3Don" $size + +_NO_VALGRIND \ +$QEMU_IO -c "write -P 0x5a 0 512" \ + -c "reopen -o l2-cache-size=3D1M" \ + -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ + | _filter_qemu_io + +# The dirty bit must still be set, it belongs to the running session +_qcow2_dump_header | grep incompatible_features + +echo +echo "=3D=3D A failed repair must fail the reopen =3D=3D" + +_make_test_img -o "compat=3D1.1,lazy_refcounts=3Don" $size + +_NO_VALGRIND \ +$QEMU_IO -c "write -P 0x5a 0 512" \ + -c "sigraise $(kill -l KILL)" "$TEST_IMG" 2>&1 \ + | _filter_qemu_io + +cat > "$TEST_DIR/blkdebug.conf" <&1 \ + | _filter_testdir | _filter_qemu_io + +rm -f "$TEST_DIR/blkdebug.conf" + echo echo "=3D=3D Creating an image file with lazy_refcounts=3Doff =3D=3D" =20 diff --git a/tests/qemu-iotests/039.out b/tests/qemu-iotests/039.out index 3c71e5a3dd..c0e1bf0a09 100644 --- a/tests/qemu-iotests/039.out +++ b/tests/qemu-iotests/039.out @@ -64,6 +64,42 @@ wrote 512/512 bytes at offset 0 512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) incompatible_features [] =20 +=3D=3D Reopening a dirty image read/write should repair it =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 +wrote 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +./common.rc: Killed ( VALGRIND_QEMU=3D"${VALGRIND_QEMU_IO}" _qemu_proc_exe= c "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" ) +incompatible_features [0] +ERROR cluster 5 refcount=3D0 reference=3D1 +Rebuilding refcount structure +Repairing cluster 1 refcount=3D1 reference=3D0 +Repairing cluster 2 refcount=3D1 reference=3D0 +wrote 512/512 bytes at offset 1048576 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +incompatible_features [] +No errors were found on the image. + +=3D=3D A read/write reopen must not check the image =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 +wrote 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +./common.rc: Killed ( VALGRIND_QEMU=3D"${VALGRIND_QEMU_IO}" _qemu_proc_exe= c "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" ) +incompatible_features [0] + +=3D=3D A failed repair must fail the reopen =3D=3D +Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 +wrote 512/512 bytes at offset 0 +512 bytes, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +./common.rc: Killed ( VALGRIND_QEMU=3D"${VALGRIND_QEMU_IO}" _qemu_proc_exe= c "${VALGRIND_LOGFILE}" "$QEMU_IO_PROG" $QEMU_IO_ARGS "$@" ) +ERROR cluster 5 refcount=3D0 reference=3D1 +Rebuilding refcount structure +qemu-io: ERROR writing refblock: Input/output error +qcow2: Marking image as corrupt: Could not repair dirty image; further cor= ruption events will be suppressed +qemu-io: Could not repair dirty image +read failed: No medium found + =3D=3D Creating an image file with lazy_refcounts=3Doff =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D134217728 wrote 512/512 bytes at offset 0 --=20 2.53.0