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 2E2848045D for ; Tue, 27 Oct 2026 16:54:18 +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 69RGr33f030998; Tue, 27 Oct 2026 19:53:03 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69RGr33f030998 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=default; t=1793119986; bh=D7TF8w09IVTTOzJFkoCi2LhtmFNDqgSCcjOgIwhx8YQ=; h=From:To:Date:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe; b=eUcLTtVSK/hDBm1QH1v9Mb2cgpfjrMNlW6lv2ht6Ww3hRQIUcHgGNrEIztp6O4uXq aMHwhi64LVNF8WPE1PvRZgQaKRBB2pAs2T3pGtB54Jk4bGcvNbSrrLHUP1bNsqya+A QtmBz4AfFKUeXHEKMLlnWB5DvWtX/k3s1n9ShIEgOx4wncJOAE25w4eoAXg1MtIglg DshiLG9qg69bfAsLMvp9Qspvrrq+tyqFfkSJEgM2lhN3mZCr20pGgdqbLuVz8mlJd0 //0INPrc1gq8X+iB32u9ymKeF3rBZXbXXxEI0AgsqC/U5849o7xb1ZcX1fdv78eGAc KImKRm8pVqDYw== Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by mail.openvz.org (8.14.4/8.14.4) with ESMTP id 69RGr1nr030994 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=FAIL) for ; Tue, 27 Oct 2026 19:53:02 +0300 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.openvz.org 69RGr1nr030994 Authentication-Results: mail.openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="BOxoxGJd" Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-5bcd2b01d17so67759e87.0 for ; Tue, 27 Oct 2026 09:53:02 -0700 (PDT) X-Gm-Message-State: AFq9FYKiUmYzwrtQGeRKIKhLIo0ZZ/m3Y1U3EGExv+8KZ0Zvs7Bv90kD Q147UzLR88yhf83mNytjSWLApxEfmhGQuOGCyOTX0YAenyV33TY8JmYjvdoOBiv3WT7ZDg7cNx1 4sybSolAEpG9bvucmeh2qftMHBQoBLAXkJQaArcK+anOvIMGM8Qx3Bw== X-Gm-Gg: AYBFou0H/Hp3m6H0cl8ycvdcSMy2jFMUBS/qAirPtQ+FPdyyFYpvGH3aQJDpy3J5uW2 8bLcOIadDZI0/br2Xlpm3BRKgGmByWXrgpJ7voRO9BUDu/XpvPN3FXta88gUAfIBn7hYeeBI55u HfR3YL2tPjHvTUMC+RZp2di2pmYIZPyq7XanWxD31/HSJLSl5KDsaOWf32OjuwEAK4pel4HBb+t jLg+sEr/+elI7sPDHr4s15FehIGrT07i5g6G0BybURCWsSPvFgWVYFXGnzB4h1UJ+8hR+vbpK61 I2UBnIJTbQ== X-Received: by 2002:a05:600c:a103:b0:4a6:30c3:1114 with SMTP id 5b1f17b1804b1-4a630c3112bmr109381635e9.12.1793118786822; Tue, 27 Oct 2026 09:33:06 -0700 (PDT) X-Received: by 2002:a05:600c:a103:b0:4a6:30c3:1114 with SMTP id 5b1f17b1804b1-4a630c3112bmr109381045e9.12.1793118786246; Tue, 27 Oct 2026 09:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1793118786; cv=none; d=google.com; s=arc-20260327; b=aSbWFjIMZRck3g4Uy3fqk7qfdzw7SNjxN/I7grX5lr7p3m0dXAl+AK36wTp4Hjul64 s+5PQY/VTj3EQI3wksKHc5yGRq0TiBlv0bc2nrIVfDfuw2Q3ELdaplXhkf4u6OjU1XMe +6xI+jVXsx3+cnpPhF8GoPSIpILGM3E37fGZdhuOj87pLgP92TwzPvLLmbyd2X+RbITR wl0TVwMsb4LfRPWvH9xfByNVcuHFtSNteRW1aVXX9wZ2h8rH3fuxHWGSRdnEQLqx80WZ f4FbVjcskipEy2l/Ts5dYYFZfXnBCSwrPCRdfBlad/TsBN1PyjUUaYoyl8Qxp0ub8isx N05w== 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=zKE++ru+BJa2MMYijcE2tKtSinc9SdDX/OJ+qzfwEa0=; fh=Kr/R+ZQiC/tid3qUs5C3px+AHPSuipOrrdrDcZfSlMY=; b=TDRZwJvaUoPFcUBPE+tiZbl6wuxR7z+IwH938rsnoRPYWolghDI126RQwotuNEa+lu rhEHmdYJ9Wh1GlFsQ0MwA5Q6cqQiqCHzMPBe/+4vte6zRv3MAc8REXuhKxJYCxWGL7Ll f6vlqv/ItkPSDGORuqVxQWnkfaZuMuuzOTnWepBDH8eNrhaeg/MiPs6n17NnwKcUAMHR tgN12pokMLdcwf/ZbbfIPZgoiqi8GxtzA43+8Z5JlMQtL2EnohRan8Izum42my5TApT6 LL7G4zDlZTMUM5pjH83XG0HKZl+pnQNXqe6uPSXc/Ww9+yXey0wCAUPRD7yVxK4CAf+R whNw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=BOxoxGJd; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:a5e9:5d2:969c:16de as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5b1f17b1804b1-4a35a0afd30sor17278755e9.4.2026.10.27.09.33.06 for (Google Transport Security); Tue, 27 Oct 2026 09:33:06 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:a5e9:5d2:969c:16de as permitted sender) client-ip=2a06:5b06:b600:300:a5e9:5d2:969c:16de; Authentication-Results: mx.google.com; dkim=pass header.i=@openvz.org header.s=google header.b=BOxoxGJd; spf=softfail (google.com: domain of transitioning den@openvz.org does not designate 2a06:5b06:b600:300:a5e9:5d2:969c:16de as permitted sender) smtp.mailfrom=den@openvz.org; dara=neutral header.i=@openvz.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1793118786; x=1793723586; darn=openvz.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=zKE++ru+BJa2MMYijcE2tKtSinc9SdDX/OJ+qzfwEa0=; b=BOxoxGJdoAixK3wBT6vEwmVVpQhWu9ItUfq6uMBrUiPpk3Mdl5ITm8KoNkLKVIjreb NcIDE5ecX+NQOfiz5Sq8b/9LWHybhNgAN+36ZQHF+tBWmbM0XVc5HZexvFkNY4edgM5f Vb6XST1Sqb6qiPbZy+mQvwx3BwZMmNQZ6GmhGDo39xxysJAUh8zxBagSjGKBKKQ60GZ7 jbIO7i0Lueevvk78WpUCcXFbUJjZt8JJTsVCkWbjns7vbXrUG7bL0pIR9R4YiyCyI88N O3i6WtrGP2V1SphyQgCExHhRiHEM6kuzsX7ozmJBP0zyEppvhxjEhHeda5dtrSbd7pEU iMOQ== X-Received: by 2002:a05:600c:1c06:b0:4a1:e7ce:107b with SMTP id 5b1f17b1804b1-4a35ac407fdmr271334765e9.2.1793118785674; Tue, 27 Oct 2026 09:33:05 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:a5e9:5d2:969c:16de]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a9301b689asm870315e9.7.2026.10.27.09.33.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Oct 2026 09:33:05 -0700 (PDT) From: "Denis V. Lunev" To: andrey.zhadchenko@virtuozzo.com Date: Tue, 27 Oct 2026 17:32:59 +0100 Message-ID: <20261027163300.2166639-4-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261027163300.2166639-1-den@openvz.org> References: <20261027163300.2166639-1-den@openvz.org> MIME-Version: 1.0 X-OZ-Fwd: true Cc: devel@openvz.org Subject: [Devel] [PATCH hci-8.1 3/3] dm-ploop: fix lost BAT updates when alloc and discard share a 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 From: Denis V. Lunev Since "dm-ploop: fix and rework md updates" any update of a BAT page joins the pending index writeback of that page, whatever type it was prepared with. On completion ploop_advance_local_after_bat_wb() still applied the written page by type: a DISCARD writeback copied back only entries that became zero, an ALLOC one only non-zero entries. A first write to a cluster that joined a pending DISCARD writeback was acknowledged with its new mapping on disk but not in the local BAT. It read back as zeroes, the next write to the cluster allocated another one, and the next writeback of the page stored that, leaking the cluster with the acknowledged data. A discard that joined an ALLOC writeback left the local BAT mapped while disk had zero, so data written to that cluster afterwards was lost on the next open. Apply the changes of the pios attached to the writeback instead: the allocating data pios and COW pios set their entries, the discard pios clear theirs, other entries are left alone. The relocation on grow changes an entry that no pio stands for, so its writeback records that entry to be applied the same way. On failure the same rule as before frees only what this writeback allocated: a data pio may find its cluster already mapped by an earlier writeback. Entries nobody changed no longer get their level reset to the top one; nothing needs that once the merge of the latest snapshot renumbers the levels itself. The PLOOP_DELAYWB branch goes with the old loop; nothing defines that macro. Fixes: ddf38fa44df4 ("dm-ploop: fix and rework md updates") https://virtuozzo.atlassian.net/browse/VSTOR-151979 Signed-off-by: Denis V. Lunev Feature: dm-ploop: ploop target driver --- drivers/md/dm-ploop-map.c | 140 +++++++++++++++++++------------------- drivers/md/dm-ploop.h | 1 + 2 files changed, 71 insertions(+), 70 deletions(-) diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c index 34bf6487107f..a637df932495 100644 --- a/drivers/md/dm-ploop-map.c +++ b/drivers/md/dm-ploop-map.c @@ -86,6 +86,7 @@ void ploop_index_wb_init(struct ploop_index_wb *piwb, struct ploop *ploop) piwb->page_id = PAGE_NR_NONE; piwb->type = PIWB_TYPE_ALLOC; piwb->flush_pio = NULL; + piwb->reloc_clu = BAT_ENTRY_NONE; } void ploop_init_pio(struct ploop *ploop, unsigned int bi_op, struct pio *pio) @@ -802,80 +803,85 @@ static void ploop_complete_cow(struct ploop_cow *cow, blk_status_t bi_status) kmem_cache_free(cow_cache, cow); } +static void ploop_advance_allocated(struct ploop *ploop, struct md_page *md, + map_index_t *dst_clu, u32 clu, bool success) +{ + u32 i = ploop_bat_clu_idx_in_page(clu); + u32 *bat_entries = md->kmpage; + u32 new_clu = READ_ONCE(dst_clu[i]); + + if (WARN_ON_ONCE(!new_clu)) + return; + + if (success) { + WRITE_ONCE(bat_entries[i], new_clu); + WRITE_ONCE(md->bat_levels[i], ploop_top_level(ploop)); + } else if (new_clu != READ_ONCE(bat_entries[i]) || + md->bat_levels[i] < ploop_top_level(ploop)) { + ploop_hole_set_bit(new_clu, ploop); + } +} + +static void ploop_advance_discarded(struct ploop *ploop, struct md_page *md, + map_index_t *dst_clu, u32 clu, bool success) +{ + u32 i = ploop_bat_clu_idx_in_page(clu); + u32 *bat_entries = md->kmpage; + u8 level = md->bat_levels[i]; + u32 d_clu = READ_ONCE(bat_entries[i]); + + if (!success || dst_clu[i] || d_clu == BAT_ENTRY_NONE || + level < ploop_top_level(ploop)) + return; + + WARN_ON_ONCE(ploop->nr_deltas != 1); + WRITE_ONCE(bat_entries[i], BAT_ENTRY_NONE); + WRITE_ONCE(md->bat_levels[i], 0); + ploop_hole_set_bit(d_clu, ploop); +} + /* - * Update local BAT copy with written indexes on success. - * Mark allocate clusters as holes on failure. + * Apply to the local BAT copy the changes made by the pios attached + * to @piwb, whatever type @piwb was prepared with: allocations and + * discards of one page may share a writeback. * FIXME: a failure may mean some sectors are written, so * we have to reread BAT page to check that. */ static void ploop_advance_local_after_bat_wb(struct ploop *ploop, struct ploop_index_wb *piwb, + struct llist_node *ll_ready_pios, + struct llist_node *ll_cow_pios, bool success) { struct md_page *md = piwb->md; - u32 i, last, *bat_entries; - map_index_t *dst_clu, off; + map_index_t *dst_clu; unsigned long flags; LIST_HEAD(list); struct llist_node *wait_llist_pending; + struct ploop_cow *cow; struct pio *pio; struct llist_node *pos, *t; BUG_ON(!md); - bat_entries = md->kmpage; - - /* Absolute number of first index in page (negative for page#0) */ - off = piwb->page_id * PAGE_SIZE / sizeof(map_index_t); - off -= PLOOP_MAP_OFFSET; spin_lock_irqsave(&ploop->bat_lock, flags); - /* Last and first index in copied page */ - last = READ_ONCE(ploop->nr_bat_entries) - off; - if (last > PAGE_SIZE / sizeof(map_index_t)) - last = PAGE_SIZE / sizeof(map_index_t); - i = 0; - if (!piwb->page_id) - i = PLOOP_MAP_OFFSET; - dst_clu = kmap_local_page(piwb->bat_page); /* holes bit map requires bat_lock */ spin_lock(&md->md_lock); -#ifdef PLOOP_DELAYWB - if (piwb->type == PIWB_TYPE_ALLOC) - goto skip_apply; -#endif - for (; i < last; i++) { - if (piwb->type == PIWB_TYPE_DISCARD) { - /* discard completed */ - u8 level = md->bat_levels[i]; - u32 d_clu = READ_ONCE(bat_entries[i]); - - if (success && !dst_clu[i] && - (!(d_clu == BAT_ENTRY_NONE || - level < ploop_top_level(ploop)))) { - WARN_ON_ONCE(ploop->nr_deltas != 1); - WRITE_ONCE(bat_entries[i], BAT_ENTRY_NONE); - WRITE_ONCE(md->bat_levels[i], 0); - ploop_hole_set_bit(d_clu, ploop); - } - - continue; - } - - if (!dst_clu[i]) - continue; - - if (success) { - WRITE_ONCE(bat_entries[i], READ_ONCE(dst_clu[i])); - WRITE_ONCE(md->bat_levels[i], ploop_top_level(ploop)); - } else if (dst_clu[i] != bat_entries[i] || - md->bat_levels[i] < ploop_top_level(ploop)) { - ploop_hole_set_bit(dst_clu[i], ploop); - } + llist_for_each(pos, ll_ready_pios) { + pio = list_entry((struct list_head *)pos, typeof(*pio), list); + if (pio->wants_discard_index_cleanup) + ploop_advance_discarded(ploop, md, dst_clu, pio->clu, success); + else if (pio->is_data_alloc) + ploop_advance_allocated(ploop, md, dst_clu, pio->clu, success); } -#ifdef PLOOP_DELAYWB -skip_apply: -#endif + llist_for_each(pos, ll_cow_pios) { + pio = list_entry((struct list_head *)pos, typeof(*pio), list); + cow = pio->endio_cb_data; + ploop_advance_allocated(ploop, md, dst_clu, cow->cow_pio->clu, success); + } + if (piwb->reloc_clu != BAT_ENTRY_NONE) + ploop_advance_allocated(ploop, md, dst_clu, piwb->reloc_clu, success); WARN_ON_ONCE(!test_bit(MD_WRITEBACK, &md->status)); @@ -948,24 +954,6 @@ static void ploop_bat_write_finish(struct pio *pio, void *piwb_ptr, struct llist_node *ll_cow_pios; struct llist_node *ll_ready_pios; - if (!bi_status) { - /* - * Success: now update local BAT copy. We could do this - * from our delayed work, but we want to publish new - * mapping in the fastest way. This must be done before - * data bios completion, since right after we complete - * a bio, subsequent read wants to see written data - * (ploop_map() wants to see not zero bat_entries[.]). - */ - ploop_advance_local_after_bat_wb(ploop, piwb, true); - } else { - /* - * Index wb failed. Mark clusters as unallocated again. - * piwb->count is zero, so all data writers compeleted. - */ - ploop_advance_local_after_bat_wb(ploop, piwb, false); - } - spin_lock_irqsave(&piwb->lock, flags); ll_ready_pios = llist_del_all(&piwb->llready_data_pios); if (bi_status) @@ -973,6 +961,17 @@ static void ploop_bat_write_finish(struct pio *pio, void *piwb_ptr, spin_unlock_irqrestore(&piwb->lock, flags); ll_cow_pios = llist_reverse_order(llist_del_all(&piwb->cow_llist)); + /* + * On success publish the new mapping before the data bios + * complete, since right after we complete a bio, subsequent + * read wants to see written data (ploop_map() wants to see + * not zero bat_entries[.]). On failure mark the clusters + * allocated for this writeback as holes again: piwb->count + * is zero, so all data writers completed. + */ + ploop_advance_local_after_bat_wb(ploop, piwb, ll_ready_pios, + ll_cow_pios, !bi_status); + /* * End pending data bios. */ @@ -2737,6 +2736,7 @@ int ploop_prepare_reloc_index_wb(struct ploop *ploop, err = ploop_alloc_cluster(ploop, piwb, clu, dst_clu, file); if (err) goto out_reset; + piwb->reloc_clu = clu; } *ret_md = md; diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h index 23662943d56a..ce834df6df55 100644 --- a/drivers/md/dm-ploop.h +++ b/drivers/md/dm-ploop.h @@ -108,6 +108,7 @@ struct ploop_index_wb { blk_status_t bi_status; u32 page_id; struct bio_vec aux_bvec; + u32 reloc_clu; struct pio *flush_pio; }; -- 2.53.0 _______________________________________________ Devel mailing list Devel@openvz.org https://lists.openvz.org/mailman/listinfo/devel