[Devel] [PATCH RH9 1/2] dm-ploop: Rename size_in_clus

Kirill Tkhai ktkhai at virtuozzo.com
Tue Nov 23 13:58:10 MSK 2021


It's not clear whether size_in_clus is about nr BAT entries
or about file size in clusters. Rename it to improve readability.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c |   20 +++++++++-----------
 drivers/md/dm-ploop-cmd.c |   25 ++++++++++++-------------
 drivers/md/dm-ploop.h     |    2 +-
 3 files changed, 22 insertions(+), 25 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 347d5ff265ba..b7b1dd2f2a0c 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -390,7 +390,7 @@ static void ploop_set_not_hole(struct ploop *ploop, u32 dst_clu)
  * n)add oldest delta
  */
 static void apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas,
-				 u32 level, struct rb_root *md_root, u64 size_in_clus)
+				 u32 level, struct rb_root *md_root, u64 nr_be)
 {
 	map_index_t *bat_entries, *d_bat_entries = NULL;
 	bool is_top_level, is_raw, stop = false;
@@ -416,11 +416,11 @@ static void apply_delta_mappings(struct ploop *ploop, struct ploop_delta *deltas
 			       sizeof(struct ploop_pvd_header));
 		}
 
-		init_be_iter(size_in_clus, md->id, &i, &end);
+		init_be_iter(nr_be, md->id, &i, &end);
 
 		for (; i <= end; i++) {
 			clu = page_clu_idx_to_bat_clu(md->id, i);
-			if (clu == size_in_clus - 1)
+			if (clu == nr_be - 1)
 				stop = true;
 
 			if (bat_entries[i] != BAT_ENTRY_NONE) {
@@ -473,7 +473,7 @@ int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_r
 	struct ploop_delta *deltas = ploop->deltas;
 	struct rb_root md_root = RB_ROOT;
 	loff_t file_size;
-	u32 size_in_clus;
+	u32 nr_be;
 	int ret;
 
 	ret = ploop_check_delta_length(ploop, file, &file_size);
@@ -481,25 +481,23 @@ int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_r
 		goto out;
 
 	if (!is_raw) {
-		ret = ploop_read_delta_metadata(ploop, file, &md_root,
-						&size_in_clus);
+		ret = ploop_read_delta_metadata(ploop, file, &md_root, &nr_be);
 		if (ret)
 			goto out;
 	} else {
-		size_in_clus = POS_TO_CLU(ploop, file_size);
+		nr_be = POS_TO_CLU(ploop, file_size);
 	}
 
 	ret = -EBADSLT; /* Lower delta can't be bigger then upper */
-	if (level != top_level(ploop) &&
-	    size_in_clus > deltas[level + 1].size_in_clus)
+	if (level != top_level(ploop) && nr_be > deltas[level + 1].nr_be)
 		goto out;
 
-	apply_delta_mappings(ploop, deltas, level, &md_root, size_in_clus);
+	apply_delta_mappings(ploop, deltas, level, &md_root, nr_be);
 
 	deltas[level].file = file;
 	deltas[level].file_size = file_size;
 	deltas[level].file_preallocated_area_start = file_size;
-	deltas[level].size_in_clus = size_in_clus;
+	deltas[level].nr_be = nr_be;
 	deltas[level].is_raw = is_raw;
 	ret = 0;
 out:
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index ed46da98b8d7..9d0c1cae935f 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -691,7 +691,7 @@ static int ploop_merge_latest_snapshot(struct ploop *ploop)
 
 static void notify_delta_merged(struct ploop *ploop, u8 level,
 				struct rb_root *md_root,
-				bool forward, u32 size_in_clus)
+				bool forward, u32 nr_be)
 {
 	u32 i, end, *bat_entries, *d_bat_entries;
 	struct md_page *md, *d_md;
@@ -704,12 +704,12 @@ static void notify_delta_merged(struct ploop *ploop, u8 level,
 
 	write_lock_irq(&ploop->bat_rwlock);
 	ploop_for_each_md_page(ploop, md, node) {
-		init_be_iter(size_in_clus, md->id, &i, &end);
+		init_be_iter(nr_be, md->id, &i, &end);
 		bat_entries = kmap_atomic(md->page);
 		d_bat_entries = kmap_atomic(d_md->page);
 		for (; i <= end; i++) {
 			clu = page_clu_idx_to_bat_clu(md->id, i);
-			if (clu == size_in_clus - 1)
+			if (clu == nr_be - 1)
 				stop = true;
 
 			/* deltas above @level become renumbered */
@@ -793,8 +793,8 @@ static int ploop_delta_clusters_merged(struct ploop *ploop, u8 level,
 	struct rb_root md_root = RB_ROOT;
 	struct file *file;
 	loff_t file_size;
-	u32 size_in_clus;
 	u8 changed_level;
+	u32 nr_be;
 	int ret;
 
 	/* Reread BAT of deltas[@level + 1] (or [@level - 1]) */
@@ -805,24 +805,24 @@ static int ploop_delta_clusters_merged(struct ploop *ploop, u8 level,
 	if (ret)
 		goto out;
 
-	ret = ploop_read_delta_metadata(ploop, file, &md_root, &size_in_clus);
+	ret = ploop_read_delta_metadata(ploop, file, &md_root, &nr_be);
 	if (ret)
 		goto out;
 
 	ret = -EFBIG;
 	if (changed_level != top_level(ploop) &&
-	    size_in_clus > deltas[changed_level + 1].size_in_clus)
+	    nr_be > deltas[changed_level + 1].nr_be)
 		goto out;
 
 	ret = ploop_suspend_submitting_pios(ploop);
 	if (ret)
 		goto out;
 
-	notify_delta_merged(ploop, level, &md_root, forward, size_in_clus);
+	notify_delta_merged(ploop, level, &md_root, forward, nr_be);
 
 	deltas[changed_level].file_size = file_size;
 	deltas[changed_level].file_preallocated_area_start = file_size;
-	deltas[changed_level].size_in_clus = size_in_clus;
+	deltas[changed_level].nr_be = nr_be;
 
 	ploop_resume_submitting_pios(ploop);
 	ret = 0;
@@ -1003,14 +1003,13 @@ static int ploop_check_delta_before_flip(struct ploop *ploop, struct file *file)
 {
 	int ret = 0;
 #ifdef PLOOP_DEBUG
-	u32 i, end, *d_bat_entries, clu, size_in_clus;
+	u32 i, end, *d_bat_entries, clu, nr_be;
 	struct rb_root md_root = RB_ROOT;
 	struct md_page *md, *d_md;
 	struct rb_node *node;
 	bool stop = false;
 
-	ret = ploop_read_delta_metadata(ploop, file, &md_root,
-					&size_in_clus);
+	ret = ploop_read_delta_metadata(ploop, file, &md_root, &nr_be);
 	if (ret) {
 		pr_err("Error reading metadata\n");
 		goto out;
@@ -1021,7 +1020,7 @@ static int ploop_check_delta_before_flip(struct ploop *ploop, struct file *file)
 
 	write_lock_irq(&ploop->bat_rwlock);
 	ploop_for_each_md_page(ploop, md, node) {
-		init_be_iter(size_in_clus, md->id, &i, &end);
+		init_be_iter(nr_be, md->id, &i, &end);
 		d_bat_entries = kmap_atomic(d_md->page);
 		for (; i <= end; i++) {
 			if (md_page_cluster_is_in_top_delta(ploop, md, i) &&
@@ -1033,7 +1032,7 @@ static int ploop_check_delta_before_flip(struct ploop *ploop, struct file *file)
 		}
 
 		clu = page_clu_idx_to_bat_clu(md->id, i);
-		if (clu == size_in_clus - 1) {
+		if (clu == nr_be - 1) {
 			stop = true;
 			goto unmap;
 		}
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 05824851ba92..fade3e394343 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -43,7 +43,7 @@ struct ploop_delta {
 	struct file *file;
 	loff_t file_size;
 	loff_t file_preallocated_area_start;
-	u32 size_in_clus;
+	u32 nr_be; /* nr BAT entries (or file length in clus if RAW) */
 	bool is_raw;
 };
 




More information about the Devel mailing list