diff mbox series

[v2,2/3] dm array: fix unreleased btree blocks on closing a faulty array cursor

Message ID 20241205114153.1496986-3-mtsai@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Mike Snitzer
Headers show
Series Fix dm_array_cursor skipping and error handling | expand

Commit Message

Ming Hung Tsai Dec. 5, 2024, 11:41 a.m. UTC
The cached block pointer in dm_array_cursor might be NULL if it reaches
an unreadable array block, or the array is empty. Therefore,
dm_array_cursor_end() should call dm_btree_cursor_end() unconditionally,
to prevent leaving unreleased btree blocks.

Signed-off-by: Ming-Hung Tsai <mtsai@redhat.com>
Fixes: fdd1315aa5f0 ("dm array: introduce cursor api")
---
 drivers/md/persistent-data/dm-array.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Ming Hung Tsai Dec. 11, 2024, 7:48 a.m. UTC | #1
On Thu, Dec 5, 2024 at 7:42 PM Ming-Hung Tsai <mtsai@redhat.com> wrote:
>
> The cached block pointer in dm_array_cursor might be NULL if it reaches
> an unreadable array block, or the array is empty. Therefore,
> dm_array_cursor_end() should call dm_btree_cursor_end() unconditionally,
> to prevent leaving unreleased btree blocks.
>

The patch can be verified using the "array_cursor/iterate/empty" test
in dm-unit:

dm-unit run /pdata/array_cursor/iterate/empty --kernel-dir <KERNEL_DIR>
diff mbox series

Patch

diff --git a/drivers/md/persistent-data/dm-array.c b/drivers/md/persistent-data/dm-array.c
index 4866ff56125f..0850dfdffc8c 100644
--- a/drivers/md/persistent-data/dm-array.c
+++ b/drivers/md/persistent-data/dm-array.c
@@ -960,10 +960,10 @@  EXPORT_SYMBOL_GPL(dm_array_cursor_begin);
 
 void dm_array_cursor_end(struct dm_array_cursor *c)
 {
-	if (c->block) {
+	if (c->block)
 		unlock_ablock(c->info, c->block);
-		dm_btree_cursor_end(&c->cursor);
-	}
+
+	dm_btree_cursor_end(&c->cursor);
 }
 EXPORT_SYMBOL_GPL(dm_array_cursor_end);