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 B79E381377 for ; Mon, 9 Nov 2026 14:03:45 +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 6A9E2NKR032590; Mon, 9 Nov 2026 17:02:24 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E2NKR032590 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="heb48684" Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A9E1mV4032516 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 9 Nov 2026 17:01:48 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E1mV4032516 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-4903fc8537aso651486f8f.0 for ; Mon, 09 Nov 2026 06:01:48 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFAx8p0wejzfIqjYPmTiRkjSRCU9TaAqhxVEzTc3u7ZttoycJ0i0FzI0QXmndgcP0Zav2ozdQ==@openvz.org X-Gm-Message-State: APuU4Z/FwR4caucfDve341MFzSD0gUyNlEcy5h+T3gXYLE2AEEms9Ij0 XfezZ9Z905RZo3er+MKaIl4eSxuKzIx67k79NMtdVGXv1WQTEPXjkZCdCvn+2A81/FS7A8e20rU PqYGb3P3NkkLRUkEAAFJVw3ftpmnqZjICSOshKEk4FN+DwBeJV1H7aw== X-Gm-Gg: AYBFou3bWafASxO/q+tlBXxg/Fl+wM5Xn7nUfCHrhRsLueo8JZd1VIfG/rM0YvK7Wlj R1xgXq5aLYlA1E2d2HM3jhIbrVCrXijokP5fubGGfA9HhPd62sB9Wo0sUmQHEyeCvgShw54S3FI 2ltNxjXmt/8Owb1RMCBstkAFVmOMPbSMMdX8CLtOrlFGlElIy3rNbGeidvHRD8ieVZh85T30Q8z 42wHEwRItwDhLTGtKJOn7nMe332874EpQz4jk1cK6fY4kWae6CX+QXAab+SrfANGYlJ47a4zxBb 5AKulk0Mcd3UDieC9AVqeoHc2ROyRBiuIA7e7Kl/Q/h9pVu/qXoXKTfFcflWo23yZaDKoPkX7JB hUmWeNEEreJhmiN/+te4nNHU2Xmuj X-Received: by 2002:adf:e196:0:b0:491:66b9:625b with SMTP id ffacd0b85a97d-49583cf527amr7541635f8f.31.1794232908051; Mon, 09 Nov 2026 06:01:48 -0800 (PST) X-Received: by 2002:adf:e196:0:b0:491:66b9:625b with SMTP id ffacd0b85a97d-49583cf527amr7541559f8f.31.1794232907415; Mon, 09 Nov 2026 06:01:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794232907; cv=none; d=google.com; s=arc-20260327; b=PyupvVcWKkTMAxMgu3kz40DotABPOCMo5BICMCGm7wz96isdZj4vBpRscgcYIQSZ3v AbbNa5oAFq8TL5Ce8sEiIPUYnAZ0xtJ1gwOLxh6NCL5d2GLqHgcRtFSBoRdvlVxcDMk/ kRic4/7t8iahTmkPGNzHwNLSa02gc1XjIVZFOHpkda4QDMWU3qkg8jIlaIoyO8UmYO2J Wf3Vznf07t9S+LJyI78zCpxcEn26GllzvXw/geTnYtTW6++J4VJ/kLZyBIqnBJn0HL32 H4jCOSTKnRllFyYwvgu639dMJxun9/ns+rgwxdAVob8IR9udp+v6BQBhUciP+uzxF/cU bvuw== 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=g3ugid+4s0auxBSsve4FPLBC9//TVKc+cSiJ+a5CQ/GukKC1BEyHrcK5+7jS+PHA3f 3kI+uTsRYCpzMn1C5i66NL84DNVbJqvFBWi/bz6UmR4ADRJEIjhp3eYzXiMIj7PDVIN7 pCLjDzuUg+SONoSZnTsigpmS23LLusyENl+j/BgpRNctAS+FupHyzZaLalkuzIB8pcTr mGCv447Z4K+qXBnCiqg22SdF6Wa7I83ggDK/lmECS6/mSQn51ygykuoYvcTOSrNr12mh E1T5tnxcNnci37OFftmZIPq/6ulf+B7xWIyVpZcHkwcVl6BdnWznG2XGUI4wfVId/UCC 161A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=heb48684; 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-497f9d104a7si228115f8f.395.2026.11.09.06.01.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 06:01:47 -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=heb48684; 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=heb48684eiEI 6ZLmvSZczFx1zs6a7dM5WVY/IXqt+x//x0H+4H4su4NCHMIhdbBUDZvyXriGBYgRc5ukk4vcQQfmj rVEOzKrQjkZvmxJbjRZhYLOCNe93ERqYaOxLgUeKB8WyfitnWr2urb8k/+tDLMX2kWzuDj5mnWVLb ENCzE/s74+7sw0INPTRa+R5TGIi/Q14LX8URb9vVH2nJrLBO1gtNA9G6mjuVQWRm+tLlk6abGhbCE 4Na7j7lvdcNqnD/feuPAWqfOyvgeyHbr6JD9sPIgI2wtAbD1y7f2Hfx3foEF5tYWEG3QpW3gAqO3/ nXCBzeqNG7eakC/U/YqRrg==; 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 1xQPsM-005vFF-1O; Mon, 09 Nov 2026 15:01:38 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Mon, 9 Nov 2026 15:01:40 +0100 Message-ID: <20261109140143.1408038-8-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261109140143.1408038-1-alexander.ivanov@virtuozzo.com> References: <20261109140143.1408038-1-alexander.ivanov@virtuozzo.com> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v11 07/10] 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