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 5359F8017D for ; Mon, 9 Nov 2026 14:04:06 +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 6A9E1m7b032522; Mon, 9 Nov 2026 17:01:50 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E1m7b032522 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="KU5osqZt" Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 6A9E1l4r032494 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Mon, 9 Nov 2026 17:01:47 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E1l4r032494 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-4a20e41008cso6392565e9.1 for ; Mon, 09 Nov 2026 06:01:47 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHa2GprEqAwZg/PVW7aplVnk7dhA4FExQTNpS2bt3f2ydsto5Acj20nH+i2Own5QOqGsSePGg==@openvz.org X-Gm-Message-State: APuU4Z84zjC1p1TVxgg3YdySlmsirgTMuJRySJkqAXvIGAkXJ3UDiOib bkBv59vqqvXQTYZ2PuJrKk4+Qjb8+lOIoyg09kOUit8EK4/8zzYK3Jx5U2tYdCy3hlXhhovhVop 9ej1B9ienDwijRa1HUmZSiJtBJ6ic3e5le8qbe0znqVMKyHl9BBNhQQ== X-Gm-Gg: AYBFou3qaZ1J7zWLg5LcP0quuqqnNTeHT5Aaj8ZlCzvF9sikZ9/oKqzGaFJd7lL1bno AH1qAa3A0S90gcY0hIhPtyXG2mmXhKUDGvdql2dE5+TlrawkqiztRUUDGmHaVw7iGNx9W3c7uiZ lItyrhAp/eyc+h7srFK7dWDeIihJHl538+V8QO+hLlZ/fhRiQf+BbH/BjUnFnghCoOcoHmCd1Q5 bbTXWoPIrt7Nj4c2DTMJQtsZbBHuL3eqp8VjDVM9qiEx9jhimNlpwI7CwlQlAJYM5+U7NoT8wv8 vUcJU6C6FyA0F2nkGQKwAqkisb6o1nJScDGQqojXVDRPZC70/2Uf0MpGJkIrkez2c/OQRuS1fmV LOn7NmpSDds+enNH+vnuQQRGNz94= X-Received: by 2002:a05:600d:82e3:b0:4a1:9661:14b5 with SMTP id 5b1f17b1804b1-4b963c9def2mr85800515e9.29.1794232906789; Mon, 09 Nov 2026 06:01:46 -0800 (PST) X-Received: by 2002:a05:600d:82e3:b0:4a1:9661:14b5 with SMTP id 5b1f17b1804b1-4b963c9def2mr85799915e9.29.1794232906134; Mon, 09 Nov 2026 06:01:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1794232906; cv=none; d=google.com; s=arc-20260327; b=XRMhxAfM5yJWWDAf+1l+jMvn3/mVDM4mDZ1glGnkmjvwNU8nWhEl3SZailEhwHYGvp YCFeJ7baiWTTehQ4aRRhDSZPY1l+XTnHgrB+CIen4mjnwttMKnlBL5Y+p6WqDKH36/do YoohFPXTk3i64h3j/Nhp9KYLOlsp+AP9uRr8KjeLC7/+5PV206XH6f+VFfwl6I2WTE6T y1fJ/xbIPHnuI+6NQlmXj7c2v1TXaZBPah/GM59sKHJSd2XUJFqOsgHwfiH10kYozryK zxas+FuFT9MLXOJxmOrZfQp32ws59HvTVihFyjXsZ7KCDuUXQZNOU2OxUHyCEKgk/hcv WlKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=x8UoVY7qAPNpjYoH2w/iUWlJSqmAkCYvGdSjW9gikD8=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=Pj64UE2HF7Yi6zqlPJNy+YdZD5ekCgZHZ9VsW8uEH4gNpQ6CGxp4FoFnXDkL2kojwQ X+58T0iL8W+W8ZyqpiqWzMFkf6pRvUlypYzEUePaR+adb9utfMqObMkZh3+JjBZgZgJm V9aCiIXQGQdJX17UlPqXV6MZJsA4Fjc+m1rz9mBroO4XDnm0+CkjkCzY2cenNdZdq8h3 +kn8Jd0HoLJUrvVrDk64biYgOHMQ7q0tbncQ2KhdkksaYrFajGnoiQnScDH5f8iIMZy9 ZJnD5blVg+Rho3DNItiPGQ5VuvNFBBBEQSibONK6yKOkcO1VMmmCiLNu8neOj32fU8M+ O3bw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=KU5osqZt; 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-495980e0c61si9143296f8f.309.2026.11.09.06.01.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 06:01:45 -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=KU5osqZt; 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=x8UoVY7qAPNpjYoH2w/iUWlJSqmAkCYvGdSjW9gikD8=; b=KU5osqZttObs PxYnEl9C4LYvjLjIxZqzu21ZJ/MO9Z5Eh2pEl5vMV2US8cB3S6f5SC+sRbD96mZ36tK8x3+NLPRMY 8i6A/Uz1iMXr7+k/nYHzf8qFQhHC2VgLG3YsDPkyq58+hVVs2pzwdLtAnbfCtYwSkJ5G3baclnTFK vrkSQlauCSZTQCuTYNATMK5RhxDswVl7bWQJA7iNwD1L6sj4PxxWLQC+N8jFDxKOCpNFWAUCyPdyt qxUph6leOOE5AXr6f1CLIEkmDFJnUYavFWzDI+68UNfeh7YyQWv6bNcDycc37G8l34dZb1WvE1kC/ kEYGWZDN9w8ozLYfhdOrqg==; 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 1xQPsK-005vFF-38; Mon, 09 Nov 2026 15:01:37 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Mon, 9 Nov 2026 15:01:33 +0100 Message-ID: <20261109140143.1408038-1-alexander.ivanov@virtuozzo.com> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 v11 00/10] dm-qcow2: truncate unused tail of image on suspend 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 Discard punches holes in place of freed clusters, but doesn't change the file size. On postsuspend dm-qcow2 truncates the image file only down to file_preallocated_area_start, so if clusters at the end of the file are freed, the file never shrinks. This series makes postsuspend scan the refcount blocks backward and truncate the file to the end of the last used cluster. Close and reload to RO go through postsuspend too, so the file is shrunk in these cases as well. Patch 1 adds qcow2_md_page_read_sync() helper, which is needed by the scan. Patch 2 is a small cleanup of duplicate prefixes in QC_ERR/QC_INFO messages. Patches 3-8 fix existing cases where the refcounts or the dirty bit on disk don't reflect real cluster usage, or where such an image is not flagged for check, which the scan relies on. Patch 9 retries an R1/R2 writeback that failed with ENOSPC, so the next resume is refused only if the space is still missing at suspend. Patch 10 does the actual truncation. https://virtuozzo.atlassian.net/browse/VSTOR-148171 v11: - Patch 7: set ret to -ERANGE when the new R2 position runs past its end, instead of returning a stale ret. Update the relocate_refcount_table() comment about rollback. - Patch 8: drop the comments about reverted cluster allocations in do_md_page_write_complete() and qcow2_flush_deferred_activity(). - Patch 9: retry the R1/R2 writeback once on every flush of deferred md activity (suspend, merge, target destruction) via a new md_wb_no_retry flag instead of checking wants_suspend, so no timer is left armed before the image is freed. - Patch 10: say in the commit message that the scan trusts refcounts. v10: - Rebase onto 22.19. - Drop patch 7 "fix md page cleanup on failed reftable relocation", merged as beada5e3721a ("dm-qcow2: fix a failed refcount table relocation leaking md pages"). - Add Fixes tag to patches 3, 4, 5, 7 and 8. - Patch 1: set *md to NULL on error, document that a lookup of the page while it is read is never woken. - Patch 4: describe what happens to the R2 page dirtied after the flush. - Patch 5: drop the claims about L2 tables and a missed md writeback error from the commit message, retitle. - Patches 4-6: add a blank line before Signed-off-by. - Patch 7 (was 8): log the error code and tell the two failures apart. - Patch 8 (was 9): keep the refcounts of clusters allocated for a failed L1/L2 writeback, leaking them, instead of flagging the image with MD_LX_REVERTED / lx_writeback_error. Retitled accordingly. - Patch 9: new patch. - Patch 10: drop lx_writeback_error handling, mention v2 images in the commit message. v9: - Patch 5: new patch. - Patch 6: also keep the dirty bit while wants_check is set, as md_writeback_error is kept only in the target and is lost on table reload or host restart. Rename kernel_dirty_bit to kernel_dirty_bit_set. Retitled accordingly. - Patch 7: new patch. - Patches 8, 9: split from patch 10: setting md_writeback_error on a late reftable relocation failure and the MD_LX_REVERTED / lx_writeback_error tracking are separate fixes now. - Patch 10: rename qcow2_truncate_preallocations() to qcow2_truncate_unused_tail() and update the dm-ploop comment that refers to it. Move the rationale from code comments to the commit message. v8: - Patch 3: instead of extending the file in place_r2(), make find_unused_cluster() return the position for the new refblock and let allocate_cluster() prepare it the same way as a data cluster (punch, extend, watermark update moved into prepare_unused_cluster()) before calling place_r2(). Retitled accordingly. v7: - Patch 5: track whether the image was opened dirty in a new opened_dirty flag instead of checking the parsed header, which is reread on resume and may carry the bit set by the kernel itself (e.g. on the lower image of a cancelled backward merge). A new kernel_dirty_bit flag tells whether the bit on disk is the kernel's own. - Patch 6: use opened_dirty to skip the scan. v6: - Add Reviewed-by lines to patches 1 and 2. - Patch 2: fix "pase" typo in a message touched by the patch. - Patches 3-5: new patches. - Patch 6: drop Reviewed-by, as the patch changed a lot. - Patch 6: mark L1/L2 pages, whose failed writeback reverted refcounts of new clusters, with MD_LX_REVERTED and report it via the new lx_writeback_error flag, which skips the scan and is included in wants_check. Set md_writeback_error if relocate_refcount_table() fails after the new header is written, and clamp the scan start to reftable_max_file_size. Skip the scan for an image opened with the dirty bit set when kernel_sets_dirty_bit is enabled. Check the R1 entry before calc_r2_page_id(), so a corrupted one fails the scan without WARN. Reword the commit message to make clear that discard does free the clusters but doesn't shrink the file. v5: - Add Reviewed-by line. v4: - Patch 1: document in the comment that the caller must ensure no read of the page is in flight. - Patch 3: say in the commit message that close and reload to RO go through postsuspend too. v3: - Split from the common series with dm-ploop: dm-ploop patches are sent as a separate series. - Patch 1: rename qcow2_get_md_page_sync() to qcow2_md_page_read_sync(), reword commit message and comment. - Patch 2: new patch. - Patch 3: start the scan from file_preallocated_area_start instead of the end of the file and clamp the result to it, as the last cluster may be partial; print the scan error with %pe and drop the duplicate "dm-qcow2:" prefix from it. v2: - Add dm-ploop support (patches 3-6), as requested in v1 review. - dm-qcow2: move get_md_page_sync() to a separate patch as qcow2_md_page_read_sync() and use it in qcow2_parse_header() as well. - dm-qcow2: start the refcount scan below file_preallocated_area_start instead of the end of the file, and truncate to the used end directly instead of min(file_preallocated_area_start, used end). Alexander Ivanov (10): dm-qcow2: add qcow2_md_page_read_sync() helper dm-qcow2: drop duplicate prefix from QC_ERR/QC_INFO messages dm-qcow2: extend the file for a new refblock in allocate_cluster() dm-qcow2: complete wbd before ending the data qio dm-qcow2: flush lower md before clearing dirty bit on merge failure dm-qcow2: keep the dirty bit of an image that needs check dm-qcow2: flag the image for check if reftable relocation fails late dm-qcow2: leak clusters allocated for a failed L1/L2 writeback dm-qcow2: retry R1/R2 writeback that failed with ENOSPC dm-qcow2: truncate unused tail of image on suspend drivers/md/dm-ploop-target.c | 2 +- drivers/md/dm-qcow2-cmd.c | 1 + drivers/md/dm-qcow2-map.c | 257 +++++++++++++++++++++-------------- drivers/md/dm-qcow2-target.c | 119 ++++++++++++---- drivers/md/dm-qcow2.h | 6 + 5 files changed, 253 insertions(+), 132 deletions(-) -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel