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 A5B7F803F6 for ; Tue, 10 Nov 2026 07:53:32 +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 6AA7qEeZ011964; Tue, 10 Nov 2026 10:52:15 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6AA7qEeZ011964 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="cReCa1Xm" 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 6AA7pla7011880 (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 6AA7pla7011880 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-48e0fc747a7so1161602f8f.1 for ; Mon, 09 Nov 2026 23:51:47 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErFiGk2yngTPA904Z9PAS1LBDsgB3sU9XUq1fGAr6dJO0n7ga9+z4Ouh4eui95i/RZ0wEFPLbg==@openvz.org X-Gm-Message-State: APuU4Z/IO+soTQBoZJZe1sGgqcCjqra98kN38gOcbdfarF6sDzy9jv2e blZRInRYvfEwQBmwY6CNwu+/opycT2sl/5J4yLO6cFVY7i8mE/uTffA9LTEFLIwTwNbcLnQVJbI eYgahI4Ce8wbhceIlVMzHJKIq1AIZu4TMmMi4B3NXrz+/FlmB74+lcQ== X-Gm-Gg: AYBFou2feYYuST4RezCN2ChUtky/BG1S0EsgocF/emszPvbYxqx1nMXHJwmudAIcuB/ 0TnBFw90Vf2JqcVcXXn9intMpr5vdfmEuEvNhle4siiwsm6/v84CMxiELYTzPqb0te1Rl61Sl/8 Pvi0DG4f6DSvhn0aMkqQnGuMRvLN9JwIykfdQjeSW8SBu4k7jzJYxZOhCFJLjZK0McCkkdHoJqp Spr5QOxB1NxFU8nXJbbnulDeEuGooZNnBqojpYpKk0yMpLV4CvQqu87/LlB6e1+60J7q+8dND3o HDUdp9cGb0reGIQTdx5SKMGRaonoRsjXl/TvSnIHUo3Hb9MJQar/4osCmqBicYVPkOyz8WOLtys 4pSSnZMaNCmJaQIKFV839Lfsg6mU= X-Received: by 2002:a05:6000:25c3:b0:48e:3df8:74cb with SMTP id ffacd0b85a97d-4982b289bb9mr2961908f8f.6.1794297106944; Mon, 09 Nov 2026 23:51:46 -0800 (PST) X-Received: by 2002:a05:6000:25c3:b0:48e:3df8:74cb with SMTP id ffacd0b85a97d-4982b289bb9mr2961869f8f.6.1794297106433; 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=Omu8NwW9bYbZFaeAH1G4eHKDyQ5H2yU4CIevj3BCrV34Q1AKzw0JbznzF/KdLbi4BO ykJeIkidbAkXQFIJX2EI7R6MWtPgbMxT7okLPe7K7Vw1S2CgTH+wCo7DDCc6CxOQk4BI y0+JA9IQYu+4jS5KouUsx/VDBmQ0zGWiwgoNvg3wc4VAREc+UMbyGsuKfBAzZF2Wpf/u v/i0jC3FZFG7FJxFFNQ/2R/POzw+f6Ch/wp4tldA7nlwlwrV1RGuB2nzAfj3SB4OQQcS 7hZPBfWSSJdMUqpGAqTz7ccQWu+0zK44tFsVstSmQz2FGgbZZxhjPxr2Z3RHX6ZLY77E kW0A== 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=COQ2ARqe8SYjl3yh2uFVcr86PaJ97mT4Y8FyYmjmG8o=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=dzUw2kXN4WUOR5Gwelp4raLKL4tE6irkrzkGhSYkcqTG+cZ/L7NsQbN4VMTmg4mP3L /C15mDDW8tXBdKZz8psF9XOFr6d5yXK+A6pJsHD+sN8JN4/7GOu6hH9uo9ZfRHFtYBx7 9KEvNtCoB1IkpraSrBgwduZV/QuSJYRjO8czI9AKxcB8iGWdJ2IgSOFjJTfP0mJlnyGZ MTXEQjvPFWGsOjIbwULCDU8jlTEERaIK4y5bsBsllyZ7C0iIl2Q+uzYnwmg3GCPQeTVp fY+xJ5CMbLZ3ZRicUbPpCtXte1i0+1a07dq4MH1ZaTK+n+k1EjFhFtbIYZk7kNsq0lPY TMtg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=cReCa1Xm; 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-498361000d1si3426676f8f.218.2026.11.09.23.51.46 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=cReCa1Xm; 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=COQ2ARqe8SYjl3yh2uFVcr86PaJ97mT4Y8FyYmjmG8o=; b=cReCa1XmRKCG AHZOZ7duIOx6y0H1VeLdkHY0KIeS6/7L5+E9m+qTmsLCTdaT8Y1KI24i96zxqgSxSceccpvcnmKSJ iZgg7ttw/2wT8WMc1VuAMx6xRWkF/pvwh/zZAjvLgvZCtpz+JlkpiZExRxJPoDvax4ag1fp9XKRjY LjDwpNQ3QWqfQnkA0m6lFmvUcSLn84w2DFhC2yicaIyIwPPtZ+fdo9B8herrBNXpqscyZKmy3/RKz SmPJOROZDjuDzk0+kD8Yl/5mA0mtmcgwJUCG6HBDGpNZG/T2bHpn2HAXPq5Oy2XxaiF9w6HfSF61t Uxr4cMMKEUz9+2RJuVOPzA==; 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-1t; Tue, 10 Nov 2026 08:51:36 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Tue, 10 Nov 2026 08:51:37 +0100 Message-ID: <20261110075140.1475607-10-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 09/12] dm-qcow2: leak clusters allocated for a failed L1/L2 writeback 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 A failed L1/L2 writeback reverts the page in memory and frees each cluster allocated for it: revert_l_entries_update() drops the refcount of a newly allocated cluster, and a COW qio waiting on the page frees its cluster through FREE_ALLOCATED_CLU when it ends with the error. The write may still have partially reached the disk, so L1/L2 on disk may point to such a cluster. Until the page is rewritten, the allocator may give the cluster to another offset, and two guest offsets then share it. If the page is not rewritten before suspend, the image is left with a reference to a free cluster. Keep the refcount of these clusters instead. If L1/L2 on disk points to such a cluster, the image stays consistent; otherwise the cluster is leaked. A request ends with the error once its L1 or L2 write fails, so each failed write leaks one cluster per request: the L2 table for an L1 write, the data cluster for an L2 write. Check frees them, so the image needs no check and resume needs no refusal. 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 | 53 ++++++++---------------------------- drivers/md/dm-qcow2-target.c | 4 --- 2 files changed, 11 insertions(+), 46 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 7f61ff67646c..8dfdbedac10d 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -1331,50 +1331,15 @@ static void do_md_page_read_complete(int ret, struct qcow2 *qcow2, /* Be careful with dirty_or_writeback()/etc! Check races. */ static void revert_l_entries_update(struct qcow2 *qcow2, struct wb_desc *wbd) { - struct qcow2_map_item r1, r2; - struct page *pe_page; - bool skip_odd; - u64 pos, old; - bool cleared; - int i, ret; - - skip_odd = qcow2->ext_l2 && wbd->lx_level == L2_LEVEL; + struct page *pe_page = wbd->pe_page; + u64 old; + int i; lockdep_assert_held(&qcow2->md_pages_lock); for_each_set_bit(i, wbd->changed_indexes, LX_INDEXES_PER_PAGE) { - pos = get_u64_from_be_page(wbd->md->page, i); - - cleared = !(pos & ~(u64)L2_READS_ALL_ZEROES); - /* Here we restore prealloced and compressed clu mappings */ - pe_page = wbd->pe_page; - if (pe_page) { /* Only L2 has this. */ - old = get_u64_from_be_page(pe_page, i); - if (old != 0) { - set_u64_to_be_page(wbd->md->page, i, old); - continue; /* Avoid mark_cluster_unused() */ - } - } - - set_u64_to_be_page(wbd->md->page, i, 0); - if (skip_odd && (i & 1)) - continue; /* pos contains ext_l2 part of L2 entry */ - if (cleared) - continue; /* no cluster was allocated */ - - spin_unlock(&qcow2->md_pages_lock); - pos &= ~LX_REFCOUNT_EXACTLY_ONE; - - /* - * R1/R2 should be cached, since we was able - * to submit cluster allocation. - */ - ret = qcow2_handle_r1r2_maps(qcow2, pos, NULL, &r1, &r2, false); - if (WARN_ON_ONCE(ret <= 0)) - continue; - - mark_cluster_unused(qcow2, r2.md, r2.index_in_page, pos); - spin_lock(&qcow2->md_pages_lock); + old = pe_page ? get_u64_from_be_page(pe_page, i) : 0; + set_u64_to_be_page(wbd->md->page, i, old); } } @@ -1408,6 +1373,7 @@ static void complete_wbd(struct qcow2 *qcow2, struct wb_desc *wbd) LIST_HEAD(wait_list); LIST_HEAD(end_list); unsigned long flags; + struct qio *qio; spin_lock_irqsave(&qcow2->md_pages_lock, flags); revert_l_entries_update(qcow2, wbd); @@ -1415,6 +1381,10 @@ static void complete_wbd(struct qcow2 *qcow2, struct wb_desc *wbd) &wait_list, &end_list); spin_unlock_irqrestore(&qcow2->md_pages_lock, flags); + list_for_each_entry(qio, &end_list, link) { + if (qio->ext) + qio->ext->cleanup_mask &= ~FREE_ALLOCATED_CLU; + } qcow2_dispatch_qios(qcow2, NULL, &wait_list); end_qios(&end_list, errno_to_blk_status(wbd->ret)); } @@ -1445,8 +1415,7 @@ static void do_md_page_write_complete(int ret, struct qcow2 *qcow2, /* * We can finish wb only in case of success. * Otherwise this is done in finalize_wbd() - * after data qios stopped use wbd clusters - * and clusters allocations reverted. + * after data qios stopped use wbd clusters. */ if (likely(ret == 0)) { clear_writeback_status(qcow2, md, ret, diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c index 6824d95193ae..99fb68a5535e 100644 --- a/drivers/md/dm-qcow2-target.c +++ b/drivers/md/dm-qcow2-target.c @@ -173,10 +173,6 @@ void qcow2_flush_deferred_activity(struct qcow2_target *tgt, struct qcow2 *qcow2 struct md_page *md; int i; - /* - * We need second iteration, since revert_l_entries_update() - * may start timer again after failed wb. - */ for (i = 0; i < 2; i++) { if (timer_delete_sync_try(&qcow2->slow_wb_timer) != -1) qcow2_slow_wb_timer_fn(&qcow2->slow_wb_timer); -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel