From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.openvz.org (mail.openvz.org [69.168.225.77]) by lore.virtuozzo.com (Postfix) with ESMTPS id 242A7803F9 for ; Tue, 10 Nov 2026 07:53:25 +0000 (UTC) Received: from mail.openvz.org (localhost [127.0.0.1]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AA7qCRZ011955; Tue, 10 Nov 2026 10:52:12 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AA7qCRZ011955 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="l3C4nrSD" Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6AA7pkHi011872 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 10 Nov 2026 10:51:47 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AA7pkHi011872 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-49166c8a60dso1306134f8f.0 for ; Mon, 09 Nov 2026 23:51:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH+allfqwOuqMcaZM++h8V0RZkSkztoEvZLM6g/votZBI8Z8O2WfMmKyIKxRlCjca81vvXfTA==@openvz.org X-Gm-Message-State: APuU4Z/vaG50kYlYPIC0xWBwOs+IzCFnvetcDBd3cpdc2KADESN5hBSt DzohgB0QMe5iHGsCoZgl909S8Qo282I/3IRA0v//xoyIbRHPErZNmx4PAX+0EliCuosLaTaFQ+3 cTCBnhIHGuOh7BxIdeH1uCSC+eIQ3nhqcVbqzz+Q5R+GDZtqAz8r3gw== X-Gm-Gg: AYBFou39tPjXaP8/7kd5oM7KRsV3J2IMMBlpepSXLPubOIanPswE1l02fO0CG8kZcq9 4BDXcrWNOIPg7TkJBX1ij9Y3gHn4zDvvAN/xMTlpIxWsgkUsPtARc3MeiCPo7qRldpH0f4xecjX yYo8ph+9MYdX885INDKEwf8/U4sifTX9c/Om+9Xz9gHp3oq2dhTY1sU0ve/YP3JNFG5OYVU+6zN 8td8r6uk8TRp+OK66bui/I8litl2mACZu0Imbj/SJdnm75s6XYK9RaahZLmynb+yHlY++9nluYZ TPwKM1WPbnG/PENLm+hRudQ0m9bCCmDqCUjzLHhpyv1bWzy+LL6H5rbGEQE/spNiv11vfgHi4Ry UMETm3CsKgsXnQC6dtH89R7jxBuk= X-Received: by 2002:a05:6000:200e:b0:492:b5d9:f627 with SMTP id ffacd0b85a97d-498317116b3mr3245424f8f.46.1794297106585; Mon, 09 Nov 2026 23:51:46 -0800 (PST) X-Received: by 2002:a05:6000:200e:b0:492:b5d9:f627 with SMTP id ffacd0b85a97d-498317116b3mr3245379f8f.46.1794297106024; Mon, 09 Nov 2026 23:51:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794297106; cv=none; d=google.com; s=arc-20260327; b=A++40igM9f2kWrZlcZ7rUK6rGs337oWVw4PJKK7tLE2be9SThvKSXwL1srtPEK2tiN jBnnJs7bVo5BYe1oTKlZK0YSFhAVh44KQ6wlm9fBtl6CTMXpdv3RjxPuSiEFk4cP0s7d CtklwXRc/5rtpOHAxg9rQi80dBrXQ+IAPXR1xThvwsnCC3PguSrvDAsiTpVHSs9k5VlL DgE6id0YzDjhQk4jJBb9ZFDPUR4M0o2vd79lzynpm8Hb3eosSSJxqW4Fc7pLB+ykrtBk TOef8fkhtSCa3wjo50Z/1zkufI1wFnC99o6vWVl+58llwJduvXQKw9PQQvbeWwjnk3nJ /0Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=cfP/GEzHG5rFsKud8LIPOcuGyvPVyu1JTfSjtiyckEI=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=Tml3NJCSuyyFxzQFNok6vBUysuNIyvlLnlboFbRRcgz1TBcqsVzaI1xNv3l+9P3o49 lqvLP3Q3AOYy2nMOzQHiA6Y9jUZdhzlR8OSzh8KX+L6BJrnt1H84Gq2j/dhC9hhPt4kd BpWbH7KkrVBnEOWH/UiSPwIR9+qIT7JVIRfP+jhbxqr4toUmCEJLSQ0yoqkloaEkhjuP +d+dSnvP4vRyN+zgH7MguzCw8oUA67y/kFjj/Ulw/gxLZOZUntSh1V27SnbA30haXsNj l5qCbgQHPZWvN9HzMm66HDlqHCT1Ydvsb56cHD/AG7UwgV7aZiSnYhqnAWB+PrsA9WVU i2RA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=l3C4nrSD; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com Received: from relay.virtuozzo.com (relay.virtuozzo.com. [130.117.225.111]) by mx.google.com with ESMTPS id ffacd0b85a97d-498320a565esi3317773f8f.8.2026.11.09.23.51.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 23:51:46 -0800 (PST) Received-SPF: pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) client-ip=130.117.225.111; Authentication-Results: mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=l3C4nrSD; spf=pass (google.com: domain of alexander.ivanov@virtuozzo.com designates 130.117.225.111 as permitted sender) smtp.mailfrom=alexander.ivanov@virtuozzo.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=virtuozzo.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=cfP/GEzHG5rFsKud8LIPOcuGyvPVyu1JTfSjtiyckEI=; b=l3C4nrSDwIry qYGPI/gF9vgiGp5Hg5Udrr4ZLDirKGOitvo43GRpeydDGPBCWI0cv9JlEGKCh6YQFWwHH97RgzNpp BJz3hllWex0EmBpGigR/YlsPuub3d2PZe151BEUwo4lNiRMQoOkf/ZcAVDU3pBI/Y2G/WMftyGA8H qa9UqZPHkLR+ZSVpS2/X6Ccnn/ijC5LiAYQK92DagdIze5C/HF/uxZcUSMgm7qI8c0EI7Izj/7P7U a8LUc4qYvlDQRi+Rj75KaIifgPMDCpBcWmcPupa9u/E73xcww/Cvqii3Udrq/McE2CH0F/jmlofyu z2cblGsCwCKp36cxxvUk2Q==; Received: from ch-vpn.virtuozzo.com ([130.117.225.6] helo=sky) by relay.virtuozzo.com with esmtps (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1xQgZo-008dOX-0b; Tue, 10 Nov 2026 08:51:36 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 10 Nov 2026 08:51:35 +0100 Message-ID: <20261110075140.1475607-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261110075140.1475607-1-alexander.ivanov@virtuozzo.com> References: <20261110075140.1475607-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v12 07/12] dm-qcow2: flag the image for check if reftable relocation fails late X-BeenThere: devel@openvz.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: OpenVZ development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: devel-bounces@openvz.org Errors-To: devel-bounces@openvz.org Once relocate_refcount_table() has issued the header write pointing to the new reftable, any failure returns -EIO. The header on disk may already point to the new reftable even if its own write fails: a short write is reported as -ENODATA, and the old reftable position is restored only in the cached header page, which a v2 image never rewrites on suspend. The new reftable on disk may then be unfilled or miss the new refblocks, while refcounts of the new and old reftable clusters may not be updated. Refcounts no longer match the header, but nothing reports that, so the device can be resumed and the image reopened as if it were consistent. Set md_writeback_error on these paths, so wants_check reports the image and resume is refused until it is checked, and log the failure. https://virtuozzo.atlassian.net/browse/VSTOR-148171 Feature: dm-qcow2: block device over QCOW2 files driver Fixes: 222b6f1291c1c ("dm-qcow2: Introduce driver to create block devices over QCOW2 files") Signed-off-by: Alexander Ivanov --- drivers/md/dm-qcow2-map.c | 44 ++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 7866c791325b..995f611ae5bb 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -2247,7 +2247,7 @@ static void set_reftable_in_raw_hdr(struct page *page0, loff_t pos, loff_t clus) * complicated, we should not demonstrate excessive creativity * and optimize it in prejudice of readability. * - * We act in the way to provide safe rollback throughout whole function. + * We act in the way to provide safe rollback until new hdr is written. * Firstly, we cache every related md we're going to use on relocation. * New reftable (R1) is placed next to max cluster covered by old R1. * Since new reftable (R1) clusters should be marked as used after @@ -2256,8 +2256,10 @@ static void set_reftable_in_raw_hdr(struct page *page0, loff_t pos, loff_t clus) * clusters are in the part of file, which is not covered by old R1. * * Then, we try to write new hdr on disk. In case of failure, we - * restore old hdr in memory and do safe rollback. In case of success, - * there should not be more reasons to fail (only this driver's bugs). + * restore old hdr in memory, but the write may have reached the disk, + * so the image is flagged for check (md_writeback_error). In case of + * success, there should not be more reasons to fail (only this driver's + * bugs); such a failure flags the image for check too. * Cached old reftable (R1) pages we renumber to point to new reftable (R1) * place. Then we mark old reftable (R1) clusters as unused, while * new reftable (R1) clusters as used. @@ -2351,6 +2353,10 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) if (ret) { /* Restore old R1 */ set_reftable_in_raw_hdr(md0->page, old_pos, old_clus); + QC_ERR(qcow2->tgt->ti, + "failed to write header with relocated refcount table: %d", + ret); + qcow2->tgt->md_writeback_error = true; goto err_free_r2_pages; } @@ -2372,24 +2378,27 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) if (!WARN_ON_ONCE(!md)) qcow2_md_make_dirty(qcow2, md, true); if (!md) - break; /* goto err_eio */ + break; } spin_unlock_irq(&qcow2->md_pages_lock); - if (i != nr_pages) - goto err_eio; + if (i != nr_pages) { + ret = -ENOENT; + goto err_hdr_written; + } /* Connect new R2 to new R1: one for each group new R1 and R2 span */ group_size = (u64)qcow2->refblock_entries * clu_size; for (i = pos, r2_pos = end; i < r2_end; i += group_size, r2_pos += clu_size) { - if (WARN_ON_ONCE(r2_pos >= r2_end)) - goto err_eio; - if (calc_refcounters_map(qcow2, i, &r1, &r2) < 0) { - WARN_ON_ONCE(1); - goto err_eio; + if (WARN_ON_ONCE(r2_pos >= r2_end)) { + ret = -ERANGE; + goto err_hdr_written; } + ret = calc_refcounters_map(qcow2, i, &r1, &r2); + if (WARN_ON_ONCE(ret < 0)) + goto err_hdr_written; ret = handle_md_page(qcow2, r1.page_id, NULL, &md); if (WARN_ON_ONCE(ret <= 0)) - goto err_eio; + goto err_hdr_written; spin_lock_irq(&qcow2->md_pages_lock); set_u64_to_be_page(md->page, r1.index_in_page, r2_pos); qcow2_md_make_dirty(qcow2, md, true); @@ -2400,7 +2409,7 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) for (i = pos; i < r2_end; i += clu_size) { ret = qcow2_handle_r1r2_maps(qcow2, i, NULL, &r1, &r2, false); if (WARN_ON_ONCE(ret <= 0)) - goto err_eio; + goto err_hdr_written; mark_cluster_used(qcow2, r2.md, r2.index_in_page); } @@ -2408,12 +2417,18 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) for (i = old_pos; i < old_end; i += clu_size) { ret = qcow2_handle_r1r2_maps(qcow2, i, NULL, &r1, &r2, false); if (WARN_ON_ONCE(ret <= 0)) - goto err_eio; + goto err_hdr_written; mark_cluster_unused(qcow2, r2.md, r2.index_in_page, i); } return 1; +err_hdr_written: + /* 0: md page is not cached */ + QC_ERR(qcow2->tgt->ti, "failed to fill relocated refcount table: %d", + ret ?: -ENOENT); + qcow2->tgt->md_writeback_error = true; + return -EIO; err_free_r2_pages: for (i = new_md_start; i < new_md_end; i += PAGE_SIZE) { ret = handle_md_page(qcow2, i >> PAGE_SHIFT, NULL, &md); @@ -2424,7 +2439,6 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) spin_unlock_irq(&qcow2->md_pages_lock); qcow2_free_md_page(md); } -err_eio: /* TODO: switch to RO */ return -EIO; } -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel