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 73F3480E7E for ; Mon, 9 Nov 2026 14:03:23 +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 6A9E26Po032555; Mon, 9 Nov 2026 17:02:07 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 6A9E26Po032555 Authentication-Results: mail.openvz.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="QGFGRLlY" 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 6A9E1le0032500 (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 6A9E1le0032500 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-48e4d1e29f3so915119f8f.3 for ; Mon, 09 Nov 2026 06:01:47 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErHvRQWS5hCIqKwB8lTDF4oq2z9kKO/mbVV6oY8LrKXjIQgx9/KqbW+ev3yCsKz1agPWWw6zmQ==@openvz.org X-Gm-Message-State: APuU4Z+NzwXJsj6VEd2CF+7mJK9ELMOwFEenBDsEtOhJyv+xGix/NeMt LqPaL+pbGEsZyTznaxud7CChpQGtRrd6rg6pt/1QhE4ojdHyiKNLLNHRWnVLcK1yl39XHvOXSAn 3b/4p8gPFNPDZD9lrDTlZSrsVUE6SD3Nf09BkxXm3Qksq6pY24fTJjA== X-Gm-Gg: AYBFou0stwx1uQehmYL4eoB1aKjtnUm5mFZp7QCK5VIoFZLcT7isG0I1d8TsJmwZZ2I RZIVEiGmCpL0CuQK7tGfmdMiPeSKJNWMG3phAW6R7EDsrueF3JWehpc7zYS+uOlJ28OMsKmMsfp Xm/uElM7WFH5MEk2Z45yCOiBzSjm0fLvDgsJDkdqYrPNELFKn1HHJCt3rygM/9Ys/z16ac0Amu7 ctVk32S3f5Y4lBsOEzCs3X5f9ayxM+V1YsXBbwN9dZtJCtWjZ7t4ggr/TYHOjIkQ+O5t6AreS6i e6BDMZgFBojvopZiqVTmgbz7xdlUdCs5HAkWFf8H9Klp0dyupiaGPjjjpsjml97wYoSj4pu5uJ8 Ss1VeJVVvmau2OmltMl0xdA+izEg= X-Received: by 2002:a05:6000:26d3:b0:48d:c29e:40c3 with SMTP id ffacd0b85a97d-4958b72488fmr7999912f8f.33.1794232907131; Mon, 09 Nov 2026 06:01:47 -0800 (PST) X-Received: by 2002:a05:6000:26d3:b0:48d:c29e:40c3 with SMTP id ffacd0b85a97d-4958b72488fmr7999841f8f.33.1794232906393; 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=nSMBS2w4m/8KFo3ct7sP/LNKuv6+PVletRBkK75IAfgemx8IJx9VIVkinAiWdZiMpj RVe3U7XFPY/9Fpx9Mqj6GnjvuGuC3MR4h09zf1st7a51hZTSSVBNQwjha/ncU4BrKy8D rsT2271OQg/3wtcxBMY+iltpQOz5QDbAXL3somOMuRoL43m4hNJPprWk0EODjhaVOfyD U5Dbsw/VkoIZ8f5gk+HtGRU06+TGgC6EBAYPfoeDHoGRYFaUIf3ejdTlQxjujKR1JujG yEGdrkaZJ1rFM1CzXTRlla94kZN4kZ6f/crc/hWV0gvptR1Sl/hw/9JL+kL8mycWz2Vl a2SQ== 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=3bDtoN/bZaVT5xsqdiUIgyzlhi3hWjvDAkjGEaMsGfc=; fh=CMILZ+goaghq6B4UpCDhf0EQp6kYD0LAlmOkUiVCOvs=; b=BrpWZYJvoj7fU61b+0ALZkPswfyv4ovaQk5cV59RQKQSCKk/ymWHzNxC7qwf3a7+8p WUFtio2jvkN9oEIMXvMy4K/mFqWC3bqK013fBOa1WWvz+lMvUsmzHofh0oCSvEcrsTBu 6QpvKYiWNTqViK0wjFAFoLcoZijvTbXVRR71DWkZp4K8DgjJvhPId7zFMH7ycZ+YJzPh 4AOu14P2DHaCl5qppRWP3SG1h1GqsXgV3rf6LxjwlNPgkYrgIMJeB+e1qMyXigfSPg/4 hlU9cIzBFjEDWm6mrwOC75+N0+7Dyp3AI5Oioo8CqyZfJELvy5k5HiKpTGBsDNZ5NcN9 CD0w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=relay header.b=QGFGRLlY; 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-49597652cb5si9474652f8f.195.2026.11.09.06.01.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2026 06:01: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=QGFGRLlY; 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=3bDtoN/bZaVT5xsqdiUIgyzlhi3hWjvDAkjGEaMsGfc=; b=QGFGRLlYzUjq j7qdhBpQrAWKmfM5QZNkqKFoN7LzXpJ+5c6vS+wwObxxx64U8zgtcaXirhL7qw2qA9GIDcmO38TYG 8SD8/DofpNqIapVj4+apxzYNyT89joaj/q1G6XLecq8CQvwxEkXCSNLgvShH3Pb7ZFgU7uTZCWPZc X2K5wAWJo9enCLxS7h0ccSilkKcf1GXXTDpUs5BovFPJdGuojRiSt14hM0A5RbIThJrzWo2FArvj1 FOhFfx1teDW2XKysi/DfdueEEwHA30u/H4uuNG7WhKxdQlK6CIENoZvslb8jkywArb5B6AbsKsFf6 pFiOQayVdHS5zpDH0ojbmA==; 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 1xQPsL-005vFF-25; Mon, 09 Nov 2026 15:01:37 +0100 From: Alexander Ivanov To: andrey.zhadchenko@virtuozzo.com Date: Mon, 9 Nov 2026 15:01:36 +0100 Message-ID: <20261109140143.1408038-4-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 03/10] dm-qcow2: extend the file for a new refblock in allocate_cluster() 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 place_r2() links a new refblock into R1, but moves neither file_size nor file_preallocated_area_start. The refblock stays at or above the watermark if truncate_prealloc_safe() in allocate_cluster() fails after place_r2(), or if a parallel mark_cluster_unused() lowers free_cluster_search_pos before the second pass of find_unused_cluster(). Truncation of preallocations on suspend then cuts the file under the refblock: R1 on disk points past EOF, and the next session gets -EIO on allocations in the range it covers. Make find_unused_cluster() report a position not covered by R2 instead of placing the refblock there itself. allocate_cluster() prepares that cluster the same way as a data cluster, with the punch, extend and watermark update moved into prepare_unused_cluster(), and calls place_r2() before searching again. 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 | 88 ++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c index 34d9d9810f60..e8a41954c4c6 100644 --- a/drivers/md/dm-qcow2-map.c +++ b/drivers/md/dm-qcow2-map.c @@ -2083,21 +2083,12 @@ static int parse_metadata(struct qcow2 *qcow2, struct qio **qio, * and connects it to R1 table entry. */ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1, - struct qcow2_map_item *r2, loff_t r2_pos, struct qio **qio) + struct qcow2_map_item *r2, loff_t r2_pos) { struct dm_target *ti = qcow2->tgt->ti; u64 page_id = r2_pos >> PAGE_SHIFT; int ret; - if (delay_if_writeback(qcow2, r1->md, r1->index_in_page, qio, true)) - return 0; - - ret = qcow2_punch_hole(qcow2->file, r2_pos, qcow2->clu_size); - if (ret) { - QC_ERR(ti, "punch hole: %d", ret); - return ret; - } - ret = qcow2_alloc_and_insert_md_page(qcow2, page_id, &r2->md); if (ret < 0) { QC_ERR(ti, "Can't alloc: ret=%d, page_id=%llu", ret, page_id); @@ -2113,7 +2104,7 @@ static int place_r2(struct qcow2 *qcow2, struct qcow2_map_item *r1, spin_unlock_irq(&qcow2->md_pages_lock); mark_cluster_used(qcow2, r2->md, r2->index_in_page); - return 1; + return 0; } static s32 find_unused_block_entry(struct qcow2 *qcow2, struct md_page *md, @@ -2135,11 +2126,13 @@ static s32 find_unused_block_entry(struct qcow2 *qcow2, struct md_page *md, static loff_t find_unused_cluster(struct qcow2 *qcow2, struct qio **qio, struct qcow2_map_item *r1, - struct qcow2_map_item *r2) + struct qcow2_map_item *r2, bool *needs_r2) { u32 clu_size = qcow2->clu_size; s32 index, ret; loff_t pos; + + *needs_r2 = false; again: pos = READ_ONCE(qcow2->free_cluster_search_pos); if (pos >= qcow2->reftable_max_file_size) @@ -2151,15 +2144,15 @@ static loff_t find_unused_cluster(struct qcow2 *qcow2, struct qio **qio, return ret; /* * Since pos is not covered by R2, the whole cluster - * must be unused. Use it to store R2 cluster. + * must be unused. The caller stores R2 cluster there. * Both indexes must be 0 here, because of we allocate * clusters from small to big. */ WARN_ON_ONCE(r2->index_in_page != 0 || r2->index != 0); - ret = place_r2(qcow2, r1, r2, pos, qio); - if (ret <= 0) - return ret; - goto again; + if (delay_if_writeback(qcow2, r1->md, r1->index_in_page, qio, true)) + return 0; + *needs_r2 = true; + return pos; } spin_lock_irq(&qcow2->md_pages_lock); @@ -2436,6 +2429,37 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) return -EIO; } +/* + * Zero the unused cluster at @pos and make the file size and + * file_preallocated_area_start cover it. + */ +static int prepare_unused_cluster(struct qcow2 *qcow2, loff_t pos) +{ + loff_t off, end = pos + qcow2->clu_size; + loff_t old_size = qcow2->file_size; + int ret; + + if (pos < qcow2->file_preallocated_area_start) { + /* Clu at @pos may contain dirty data */ + off = min_t(loff_t, old_size, end); + ret = qcow2_punch_hole(qcow2->file, pos, off - pos); + if (ret) { + QC_ERR(qcow2->tgt->ti, "punch hole: %d", ret); + return ret; + } + } + + if (end > old_size) { + ret = truncate_prealloc_safe(qcow2, end, __func__); + if (ret) + return ret; + } + + if (end > qcow2->file_preallocated_area_start) + qcow2->file_preallocated_area_start = end; + return 0; +} + /* * This function is aimed to be called only from main work. * In case of wish to use it from more places, it's needed @@ -2445,13 +2469,12 @@ static int relocate_refcount_table(struct qcow2 *qcow2, struct qio **qio) static loff_t allocate_cluster(struct qcow2 *qcow2, struct qio *qio, struct md_page **r2_md, u32 *r2_index_in_page) { - u32 clu_size = qcow2->clu_size; - struct file *file = qcow2->file; - loff_t pos, off, end, old_size; struct qcow2_map_item r1, r2; + bool needs_r2; + loff_t pos; int ret; again: - pos = find_unused_cluster(qcow2, &qio, &r1, &r2); + pos = find_unused_cluster(qcow2, &qio, &r1, &r2, &needs_r2); if (unlikely(pos == -ENOENT)) { ret = relocate_refcount_table(qcow2, &qio); if (ret <= 0) @@ -2461,28 +2484,17 @@ static loff_t allocate_cluster(struct qcow2 *qcow2, struct qio *qio, if (pos <= 0) return pos; - end = pos + clu_size; - old_size = qcow2->file_size; - - if (pos < qcow2->file_preallocated_area_start) { - /* Clu at @pos may contain dirty data */ - off = min_t(loff_t, old_size, end); - ret = qcow2_punch_hole(file, pos, off - pos); - if (ret) { - QC_ERR(qcow2->tgt->ti, "punch hole: %d", ret); - return ret; - } - } + ret = prepare_unused_cluster(qcow2, pos); + if (ret) + return ret; - if (end > old_size) { - ret = truncate_prealloc_safe(qcow2, end, __func__); + if (needs_r2) { + ret = place_r2(qcow2, &r1, &r2, pos); if (ret) return ret; + goto again; } - if (end > qcow2->file_preallocated_area_start) - qcow2->file_preallocated_area_start = end; - mark_cluster_used(qcow2, r2.md, r2.index_in_page); if (r2_md) *r2_md = r2.md; -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel