[dm-devel] [PATCH 3/4] persistent-data: simplify struct ro_spine

Mikulas Patocka mpatocka at redhat.com
Mon Oct 10 12:36:54 UTC 2022


The struct ro_spine holds pointers to two last blocks when doing read-only
btree walk. The second block is never accessed (note that the function
ro_pop is never called), so we can simplify the code so that it holds
pointer to just one block.

Signed-off-by: Mikulas Patocka <mpatocka at redhat.com>

---
 drivers/md/persistent-data/dm-btree-internal.h |    4 --
 drivers/md/persistent-data/dm-btree-spine.c    |   41 +++++--------------------
 2 files changed, 10 insertions(+), 35 deletions(-)

Index: linux-2.6/drivers/md/persistent-data/dm-btree-internal.h
===================================================================
--- linux-2.6.orig/drivers/md/persistent-data/dm-btree-internal.h	2022-10-10 11:20:17.000000000 +0200
+++ linux-2.6/drivers/md/persistent-data/dm-btree-internal.h	2022-10-10 11:20:55.000000000 +0200
@@ -63,14 +63,12 @@ void unlock_block(struct dm_btree_info *
 struct ro_spine {
 	struct dm_btree_info *info;
 
-	int count;
-	struct dm_block *nodes[2];
+	struct dm_block *node;
 };
 
 void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info);
 void exit_ro_spine(struct ro_spine *s);
 int ro_step(struct ro_spine *s, dm_block_t new_child);
-void ro_pop(struct ro_spine *s);
 struct btree_node *ro_node(struct ro_spine *s);
 
 struct shadow_spine {
Index: linux-2.6/drivers/md/persistent-data/dm-btree-spine.c
===================================================================
--- linux-2.6.orig/drivers/md/persistent-data/dm-btree-spine.c	2022-10-10 11:20:17.000000000 +0200
+++ linux-2.6/drivers/md/persistent-data/dm-btree-spine.c	2022-10-10 11:20:42.000000000 +0200
@@ -123,52 +123,29 @@ void unlock_block(struct dm_btree_info *
 void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info)
 {
 	s->info = info;
-	s->count = 0;
-	s->nodes[0] = NULL;
-	s->nodes[1] = NULL;
+	s->node = NULL;
 }
 
 void exit_ro_spine(struct ro_spine *s)
 {
-	int i;
-
-	for (i = 0; i < s->count; i++) {
-		unlock_block(s->info, s->nodes[i]);
-	}
+	if (s->node)
+		unlock_block(s->info, s->node);
 }
 
 int ro_step(struct ro_spine *s, dm_block_t new_child)
 {
-	int r;
-
-	if (s->count == 2) {
-		unlock_block(s->info, s->nodes[0]);
-		s->nodes[0] = s->nodes[1];
-		s->count--;
+	if (s->node) {
+		unlock_block(s->info, s->node);
+		s->node = NULL;
 	}
 
-	r = bn_read_lock(s->info, new_child, s->nodes + s->count);
-	if (!r)
-		s->count++;
-
-	return r;
-}
-
-void ro_pop(struct ro_spine *s)
-{
-	BUG_ON(!s->count);
-	--s->count;
-	unlock_block(s->info, s->nodes[s->count]);
+	return bn_read_lock(s->info, new_child, &s->node);
 }
 
 struct btree_node *ro_node(struct ro_spine *s)
 {
-	struct dm_block *block;
-
-	BUG_ON(!s->count);
-	block = s->nodes[s->count - 1];
-
-	return dm_block_data(block);
+	BUG_ON(!s->node);
+	return dm_block_data(s->node);
 }
 
 /*----------------------------------------------------------------*/



More information about the dm-devel mailing list