[Devel] [PATCH RH8 6/8] ploop: Introduce top_level()

Kirill Tkhai ktkhai at virtuozzo.com
Tue May 11 11:46:16 MSK 2021


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c    |    2 +-
 drivers/md/dm-ploop-cmd.c    |   12 ++++++------
 drivers/md/dm-ploop-map.c    |    2 +-
 drivers/md/dm-ploop-target.c |    2 +-
 drivers/md/dm-ploop.h        |   11 ++++++++---
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 6ac660ab8b8f..04698d99a67a 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -156,7 +156,7 @@ static int parse_bat_entries(struct ploop *ploop, map_index_t *bat_entries,
 		if (bat_entries[i] == BAT_ENTRY_NONE)
 			return -EINVAL;
 		if (bat_entries[i]) {
-			bat_levels[i] = BAT_LEVEL_TOP;
+			bat_levels[i] = nr_deltas; /* See top_level() */
 			/* Cluster may refer out holes_bitmap after shrinking */
 			if (bat_entries[i] < ploop->hb_nr)
 				ploop_hole_clear_bit(bat_entries[i], ploop);
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 57ab6a867db1..e150edc4136f 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -288,7 +288,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 
 	/* Update local BAT copy */
 	write_lock_irq(&ploop->bat_rwlock);
-	WARN_ON(!try_update_bat_entry(ploop, cluster, BAT_LEVEL_TOP, new_dst));
+	WARN_ON(!try_update_bat_entry(ploop, cluster, top_level(ploop), new_dst));
 	write_unlock_irq(&ploop->bat_rwlock);
 not_occupied:
 	/*
@@ -634,7 +634,7 @@ static void process_merge_latest_snapshot_cmd(struct ploop *ploop,
 		/*
 		 * This adds cluster lk. Further write bios to *cluster will go
 		 * from ploop_map to kwork (because bat_levels[*cluster] is not
-		 * BAT_LEVEL_TOP), so they will see the lk.
+		 * top_level()), so they will see the lk.
 		 */
 		if (submit_cluster_cow(ploop, level, *cluster, dst_cluster,
 				    ploop_queue_deferred_cmd_wrapper, cmd)) {
@@ -948,9 +948,9 @@ static void process_flip_upper_deltas(struct ploop *ploop, struct ploop_cmd *cmd
 			if (bat_entries[i] == BAT_ENTRY_NONE)
 				continue;
 			if (md->bat_levels[i] == level) {
-				md->bat_levels[i] = BAT_LEVEL_TOP;
+				md->bat_levels[i] = top_level(ploop);
 				clear_bit(bat_entries[i], holes_bitmap);
-			} else if (md->bat_levels[i] == BAT_LEVEL_TOP) {
+			} else if (md->bat_levels[i] == top_level(ploop)) {
 				md->bat_levels[i] = level;
 			}
 		}
@@ -1003,7 +1003,7 @@ static void process_tracking_start(struct ploop *ploop, struct ploop_cmd *cmd)
 		for (; i <= end; i++) {
 			dst_cluster = bat_entries[i];
 			if (dst_cluster == BAT_ENTRY_NONE ||
-			    md->bat_levels[i] != BAT_LEVEL_TOP)
+			    md->bat_levels[i] != top_level(ploop))
 				continue;
 			if (WARN_ON(dst_cluster >= tb_nr)) {
 				ret = -EIO;
@@ -1065,7 +1065,7 @@ static unsigned int max_dst_cluster_in_top_delta(struct ploop *ploop)
 		bat_entries = kmap_atomic(md->page);
 		for (; i <= end; i++) {
 			if (dst_cluster < bat_entries[i] &&
-			    md->bat_levels[i] == BAT_LEVEL_TOP)
+			    md->bat_levels[i] == top_level(ploop))
 				dst_cluster = bat_entries[i];
 		}
 		kunmap_atomic(bat_entries);
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 1e8a0a1561ce..4ad950afdda3 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -622,7 +622,7 @@ static void ploop_advance_local_after_bat_wb(struct ploop *ploop,
 
 		if (success) {
 			bat_entries[i] = dst_cluster[i];
-			md->bat_levels[i] = BAT_LEVEL_TOP;
+			md->bat_levels[i] = top_level(ploop);
 		} else {
 			/*
 			 * Despite set_bit() is atomic, we take read_lock()
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index a14d0d6cab4f..8a2a5312195e 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -142,7 +142,7 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
 	if (!argc)
 		goto out;
 	ret = -EINVAL;
-	if (argc > BAT_LEVEL_TOP - 1)
+	if (argc > BAT_LEVEL_MAX - 1)
 		goto out;
 
 	ret = -ENOMEM;
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index cee2a962802d..6644ef391791 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -100,7 +100,6 @@ struct ploop_cmd {
 /* We can't use 0 for unmapped clusters, since RAW image references 0 cluster */
 #define BAT_ENTRY_NONE		UINT_MAX
 
-#define BAT_LEVEL_TOP		U8_MAX
 #define CLEANUP_DELAY		20
 #define PLOOP_INFLIGHT_TIMEOUT	(60 * HZ)
 
@@ -310,6 +309,12 @@ static inline bool whole_cluster(struct ploop *ploop, struct bio *bio)
 	return !(bio_end_sector(bio) & ((1 << ploop->cluster_log) - 1));
 }
 
+#define BAT_LEVEL_MAX		(U8_MAX - 1)
+static inline u8 top_level(struct ploop *ploop)
+{
+	return ploop->nr_deltas;
+}
+
 static inline void ploop_hole_set_bit(unsigned long nr, struct ploop *ploop)
 {
 	if (!WARN_ON_ONCE(nr >= ploop->hb_nr))
@@ -400,7 +405,7 @@ static inline bool cluster_is_in_top_delta(struct ploop *ploop,
 		return false;
 	dst_cluster = ploop_bat_entries(ploop, cluster, &level);
 
-	if (dst_cluster == BAT_ENTRY_NONE || level < BAT_LEVEL_TOP)
+	if (dst_cluster == BAT_ENTRY_NONE || level < top_level(ploop))
 		return false;
 	return true;
 }
@@ -420,7 +425,7 @@ static inline bool md_page_cluster_is_in_top_delta(struct ploop *ploop,
 
 	bat_entries = kmap_atomic(md->page);
 	if (bat_entries[cluster] == BAT_ENTRY_NONE ||
-	    md->bat_levels[cluster] < BAT_LEVEL_TOP)
+	    md->bat_levels[cluster] < top_level(ploop))
 		ret = false;
 	kunmap_atomic(bat_entries);
 	return ret;




More information about the Devel mailing list