[Devel] [PATCH RHEL8 COMMIT] ploop: Introduce more helpers

Konstantin Khorenko khorenko at virtuozzo.com
Mon May 24 12:57:23 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.31
------>
commit fe0a79570697e345b95c11000fba409839658ed6
Author: Kirill Tkhai <ktkhai at virtuozzo.com>
Date:   Mon May 24 12:57:23 2021 +0300

    ploop: Introduce more helpers
    
    .. to minimize code line.
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
    
    =====================
    Patchset description:
    
    ploop: Truncate top delta from kernel
    
    and refactoring at tail.
    
    https://jira.sw.ru/browse/PSBM-129278
    
    Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c    | 12 +++++-------
 drivers/md/dm-ploop-cmd.c    | 15 +++++++--------
 drivers/md/dm-ploop-map.c    |  4 ++--
 drivers/md/dm-ploop-target.c | 10 ++++------
 drivers/md/dm-ploop.h        |  2 ++
 5 files changed, 20 insertions(+), 23 deletions(-)

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 56242e5c1285..126646bfeb09 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -258,12 +258,11 @@ static int ploop_setup_holes_bitmap(struct ploop *ploop,
 
 int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 {
-	unsigned int bat_clusters, offset_clusters, cluster_log;
+	unsigned int bat_clusters, offset_clusters;
 	struct ploop_pvd_header *m_hdr = NULL;
 	unsigned long size;
 	int ret;
 
-	cluster_log = ploop->cluster_log;
 	m_hdr = kmap(page);
 
 	ret = -ENOTSUPP;
@@ -276,7 +275,7 @@ int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 		goto out;
 
 	ret = -EINVAL;
-	if (le32_to_cpu(m_hdr->m_Sectors) != 1 << cluster_log)
+	if (le32_to_cpu(m_hdr->m_Sectors) != CLU_TO_SEC(ploop, 1))
 		goto out;
 
 	memcpy(ploop->m_Sig, m_hdr->m_Sig, sizeof(ploop->m_Sig));
@@ -289,7 +288,7 @@ int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 	bat_clusters = DIV_ROUND_UP(size, CLU_SIZE(ploop));
 
 	/* Clusters from start of file to first data block */
-	offset_clusters = le32_to_cpu(m_hdr->m_FirstBlockOffset) >> cluster_log;
+	offset_clusters = SEC_TO_CLU(ploop, le32_to_cpu(m_hdr->m_FirstBlockOffset));
 	if (bat_clusters != offset_clusters) {
 		pr_err("ploop: custom FirstBlockOffset\n");
 		goto out;
@@ -307,7 +306,7 @@ int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 static int ploop_delta_check_header(struct ploop *ploop, struct page *page,
 		       unsigned int *nr_pages, unsigned int *last_page_len)
 {
-	unsigned int bytes, delta_nr_be, offset_clusters, bat_clusters, cluster_log;
+	unsigned int bytes, delta_nr_be, offset_clusters, bat_clusters;
 	struct ploop_pvd_header *d_hdr;
 	int ret = -EPROTO;
 
@@ -319,8 +318,7 @@ static int ploop_delta_check_header(struct ploop *ploop, struct page *page,
 		goto out;
 
 	delta_nr_be = le32_to_cpu(d_hdr->m_Size);
-	cluster_log = ploop->cluster_log;
-	offset_clusters = le32_to_cpu(d_hdr->m_FirstBlockOffset) >> cluster_log;
+	offset_clusters = SEC_TO_CLU(ploop, le32_to_cpu(d_hdr->m_FirstBlockOffset));
 	bytes = (PLOOP_MAP_OFFSET + delta_nr_be) * sizeof(map_index_t);
 	bat_clusters = DIV_ROUND_UP(bytes, CLU_SIZE(ploop));
 
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 56d0de1b9339..f6fc549d34da 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -162,7 +162,6 @@ static unsigned int ploop_find_bat_entry(struct ploop *ploop,
 void pio_prepare_offsets(struct ploop *ploop, struct pio *pio,
 			 unsigned int cluster)
 {
-	unsigned int cluster_log = ploop->cluster_log;
 	int i, nr_pages = nr_pages_in_cluster(ploop);
 
 	pio->bi_iter.bi_idx = 0;
@@ -173,7 +172,7 @@ void pio_prepare_offsets(struct ploop *ploop, struct pio *pio,
 		pio->bi_io_vec[i].bv_offset = 0;
 		pio->bi_io_vec[i].bv_len = PAGE_SIZE;
 	}
-	pio->bi_iter.bi_sector = cluster << cluster_log;
+	pio->bi_iter.bi_sector = CLU_TO_SEC(ploop, cluster);
 	pio->bi_iter.bi_size = CLU_SIZE(ploop);
 }
 
@@ -329,7 +328,7 @@ static int ploop_grow_update_header(struct ploop *ploop,
 				    struct ploop_index_wb *piwb,
 				    struct ploop_cmd *cmd)
 {
-	unsigned int size, first_block_off, cluster_log = ploop->cluster_log;
+	unsigned int size, first_block_off;
 	struct ploop_pvd_header *hdr;
 	u32 nr_be, offset, clus;
 	u64 sectors;
@@ -343,7 +342,7 @@ static int ploop_grow_update_header(struct ploop *ploop,
 	size = (PLOOP_MAP_OFFSET + cmd->resize.nr_bat_entries);
 	size *= sizeof(map_index_t);
 	clus = DIV_ROUND_UP(size, CLU_SIZE(ploop));
-	first_block_off = clus << cluster_log;
+	first_block_off = CLU_TO_SEC(ploop, clus);
 
 	hdr = kmap_atomic(piwb->bat_page);
 	/* TODO: head and cylinders */
@@ -486,9 +485,9 @@ void free_pio_with_pages(struct ploop *ploop, struct pio *pio)
 /* @new_size is in sectors */
 static int ploop_resize(struct ploop *ploop, sector_t new_sectors)
 {
-	unsigned int hb_nr, size, old_size, cluster_log = ploop->cluster_log;
 	unsigned int nr_bat_entries, nr_old_bat_clusters, nr_bat_clusters;
 	struct ploop_cmd cmd = { .resize.md_pages_root = RB_ROOT };
+	unsigned int hb_nr, size, old_size;
 	struct ploop_pvd_header *hdr;
 	sector_t old_sectors;
 	struct md_page *md0;
@@ -511,15 +510,15 @@ static int ploop_resize(struct ploop *ploop, sector_t new_sectors)
 	if (old_sectors > new_sectors) {
 		DMWARN("online shrink is not supported");
 		return -EINVAL;
-	} else if ((new_sectors >> cluster_log) >= UINT_MAX - 2) {
+	} else if (SEC_TO_CLU(ploop, new_sectors) >= UINT_MAX - 2) {
 		DMWARN("resize: too large size is requested");
 		return -EINVAL;
-	} else if (new_sectors & ((1 << cluster_log) - 1)) {
+	} else if (new_sectors & (CLU_TO_SEC(ploop, 1) - 1)) {
 		DMWARN("resize: new_sectors is not aligned");
 		return -EINVAL;
 	}
 
-	nr_bat_entries = new_sectors >> cluster_log;
+	nr_bat_entries = SEC_TO_CLU(ploop, new_sectors);
 
 	/* Memory for new md pages */
 	if (prealloc_md_pages(&cmd.resize.md_pages_root,
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index b6c134ffe503..8f53e247b778 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -296,7 +296,7 @@ void track_dst_cluster(struct ploop *ploop, u32 dst_cluster)
  */
 void __track_pio(struct ploop *ploop, struct pio *pio)
 {
-	unsigned int dst_cluster = pio->bi_iter.bi_sector >> ploop->cluster_log;
+	unsigned int dst_cluster = SEC_TO_CLU(ploop, pio->bi_iter.bi_sector);
 
 	if (!op_is_write(pio->bi_op) || !bvec_iter_sectors((pio)->bi_iter))
 		return;
@@ -1487,7 +1487,7 @@ static int process_one_deferred_bio(struct ploop *ploop, struct pio *pio,
 	 * ploop_advance_local_after_bat_wb(), which we start
 	 * and wait synchronously from *this* kwork.
 	 */
-	cluster = sector >> ploop->cluster_log;
+	cluster = SEC_TO_CLU(ploop, sector);
 	dst_cluster = ploop_bat_entries(ploop, cluster, &level);
 
 	if (postpone_if_cluster_locked(ploop, pio, cluster))
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index a33147165de3..ec0a940ebb14 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -332,7 +332,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		ti->error = "could not parse cluster_log";
 		goto err;
 	}
-	ret = dm_set_target_max_io_len(ti, 1 << ploop->cluster_log);
+	ret = dm_set_target_max_io_len(ti, CLU_TO_SEC(ploop, 1));
 	if (ret) {
 		ti->error = "could not set max_io_len";
 		goto err;
@@ -369,10 +369,9 @@ static void ploop_dtr(struct dm_target *ti)
 static void ploop_io_hints(struct dm_target *ti, struct queue_limits *limits)
 {
 	struct ploop *ploop = ti->private;
-	unsigned int cluster_log = ploop->cluster_log;
 
-	limits->max_discard_sectors = 1 << cluster_log;
-	limits->max_hw_discard_sectors = 1 << cluster_log;
+	limits->max_discard_sectors = CLU_TO_SEC(ploop, 1);
+	limits->max_hw_discard_sectors = CLU_TO_SEC(ploop, 1);
 	limits->discard_granularity = CLU_SIZE(ploop);
 	limits->discard_alignment = 0;
 	limits->discard_misaligned = 0;
@@ -400,8 +399,7 @@ static void ploop_status(struct dm_target *ti, status_type_t type,
 	if (p == stat)
 		p += sprintf(p, "o");
 	BUG_ON(p - stat >= sizeof(stat));
-	DMEMIT("%u v2 %u %s", ploop->nr_deltas,
-		1 << ploop->cluster_log, stat);
+	DMEMIT("%u v2 %u %s", ploop->nr_deltas, (u32)CLU_TO_SEC(ploop, 1), stat);
 	read_unlock_irq(&ploop->bat_rwlock);
 }
 
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index a0faffe2d0e6..f9af4d59459e 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -106,6 +106,8 @@ struct ploop_cmd {
 #define CLU_OFF(ploop, pos) (pos & (to_bytes(1 << ploop->cluster_log) - 1))
 #define CLU_TO_POS(ploop, clu) to_bytes((loff_t)clu << ploop->cluster_log)
 #define POS_TO_CLU(ploop, pos) (to_sector(pos) >> ploop->cluster_log)
+#define SEC_TO_CLU(ploop, sec) (sec >> ploop->cluster_log)
+#define CLU_TO_SEC(ploop, clu) ((sector_t)clu << ploop->cluster_log)
 #define CLU_SIZE(ploop) to_bytes((u32)1 << ploop->cluster_log)
 
 enum piwb_type {


More information about the Devel mailing list