[Devel] [PATCH RH8 40/61] ploop: Kill loop

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 14 18:58:12 MSK 2021


Everything submits IO via top delta file,
so loop is not needed anymore. Remove it
and unneeded interfaces.

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

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index 632077ad781e..21eadbb69746 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -306,7 +306,6 @@ static int ploop_delta_check_header(struct ploop *ploop, struct page *page,
 {
 	unsigned int bytes, delta_nr_be, offset_clusters, bat_clusters, cluster_log;
 	struct ploop_pvd_header *d_hdr, *hdr;
-	u64 size, delta_size;
 	struct md_page *md;
 	int ret = -EPROTO;
 
@@ -322,15 +321,13 @@ static int ploop_delta_check_header(struct ploop *ploop, struct page *page,
 	    d_hdr->m_Type != hdr->m_Type)
 		goto out;
 
-	delta_size = le64_to_cpu(d_hdr->m_SizeInSectors_v2);
 	delta_nr_be = le32_to_cpu(d_hdr->m_Size);
-	size = hdr->m_SizeInSectors_v2;
 	cluster_log = ploop->cluster_log;
 	offset_clusters = le32_to_cpu(d_hdr->m_FirstBlockOffset) >> cluster_log;
 	bytes = (PLOOP_MAP_OFFSET + delta_nr_be) * sizeof(map_index_t);
 	bat_clusters = DIV_ROUND_UP(bytes, 1 << (cluster_log + 9));
 
-	if (delta_size > size || delta_nr_be > ploop->nr_bat_entries ||
+	if (delta_nr_be > ploop->nr_bat_entries ||
 	    bat_clusters != offset_clusters)
 		goto out;
 
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 4c8bfdb49971..fb1d5d9af53e 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -975,9 +975,8 @@ static void process_flip_upper_deltas(struct ploop *ploop, struct ploop_cmd *cmd
 		kunmap_atomic(bat_entries);
 	}
 
-	swap(ploop->origin_dev, cmd->flip_upper_deltas.origin_dev);
 	/* FIXME */
-	swap(ploop->deltas[level].file, cmd->flip_upper_deltas.file);
+	swap(ploop->deltas[level], ploop->deltas[level+1]);
 	write_unlock_irq(&ploop->bat_rwlock);
 	/* Device is suspended, but anyway... */
 	ploop_inflight_bios_ref_switch(ploop, false);
@@ -1179,12 +1178,10 @@ static int ploop_set_noresume(struct ploop *ploop, char *mode)
 	return 0;
 }
 
-static int ploop_flip_upper_deltas(struct ploop *ploop, char *new_dev,
-				   char *new_ro_fd)
+static int ploop_flip_upper_deltas(struct ploop *ploop)
 {
 	struct dm_target *ti = ploop->ti;
 	struct ploop_cmd cmd = { {0} };
-	int new_fd, ret;
 
 	cmd.type = PLOOP_CMD_FLIP_UPPER_DELTAS;
 	cmd.ploop = ploop;
@@ -1197,22 +1194,12 @@ static int ploop_flip_upper_deltas(struct ploop *ploop, char *new_dev,
 		return -ENOENT;
 	if (ploop->deltas[ploop->nr_deltas - 2].is_raw)
 		return -EBADSLT;
-	if (kstrtou32(new_ro_fd, 10, &new_fd) < 0 ||
-	    !(cmd.flip_upper_deltas.file = fget(new_fd)))
-		return -EBADF;
-	ret = dm_get_device(ti, new_dev, dm_table_get_mode(ti->table),
-			    &cmd.flip_upper_deltas.origin_dev);
-	if (ret)
-		goto fput;
 
 	init_completion(&cmd.comp);
 	ploop_queue_deferred_cmd(ploop, &cmd);
 	wait_for_completion(&cmd.comp);
-	ret = cmd.retval;
-	dm_put_device(ploop->ti, cmd.flip_upper_deltas.origin_dev);
-fput:
-	fput(cmd.flip_upper_deltas.file);
-	return ret;
+
+	return cmd.retval;
 }
 
 static void process_set_push_backup(struct ploop *ploop, struct ploop_cmd *cmd)
@@ -1636,9 +1623,9 @@ int ploop_message(struct dm_target *ti, unsigned int argc, char **argv,
 			goto unlock;
 		ret = ploop_set_noresume(ploop, argv[1]);
 	} else if (!strcmp(argv[0], "flip_upper_deltas")) {
-		if (argc != 3)
+		if (argc != 1)
 			goto unlock;
-		ret = ploop_flip_upper_deltas(ploop, argv[1], argv[2]);
+		ret = ploop_flip_upper_deltas(ploop);
 	} else if (!strcmp(argv[0], "push_backup_start")) {
 		if (argc != 4 || kstrtou64(argv[2], 10, &val) < 0 ||
 				 kstrtos32(argv[3], 10, &ival) < 0)
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index a4d2dfb71454..289114511246 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -1648,8 +1648,6 @@ int ploop_map(struct dm_target *ti, struct bio *bio)
 
 	ploop_init_end_io(ploop, pio);
 
-	remap_to_origin(ploop, bio);
-
 	pio->bi_iter = bio->bi_iter;
 	pio->bi_io_vec = bio->bi_io_vec;
 	pio->bi_opf = bio->bi_opf;
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index bac1d74c4dcf..020b05dbfb0f 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -151,11 +151,6 @@ static void ploop_destroy(struct ploop *ploop)
 		ploop_flush_workqueue(ploop);
 		destroy_workqueue(ploop->wq);
 	}
-	if (ploop->origin_dev) {
-		WARN_ON(blkdev_issue_flush(ploop->origin_dev->bdev, GFP_NOIO, NULL));
-		dm_put_device(ploop->ti, ploop->origin_dev);
-	}
-
 	for (i = 0; i < 2; i++)
 		percpu_ref_exit(&ploop->inflight_bios_ref[i]);
 	/* Nobody uses it after destroy_workqueue() */
@@ -189,41 +184,30 @@ static struct file * get_delta_file(int fd)
 
 static int check_top_delta(struct ploop *ploop, struct file *file)
 {
-	u32 nr, *bat_entries;
-	struct md_page *md0;
+	struct page *page = NULL;
+	u32 i, nr, *bat_entries;
 	int ret;
 
 	/* Prealloc a page to read hdr */
-	ret = prealloc_md_pages(&ploop->bat_entries, 0, 1);
-	if (ret)
-		goto out;
-
-	ret = -ENXIO;
-	md0 = md_page_find(ploop, 0);
-	if (!md0)
+	ret = -ENOMEM;
+	page = alloc_page(GFP_KERNEL);
+	if (!page)
 		goto out;
 
-	ret = rw_page_sync(READ, file, 0, md0->page);
+	ret = rw_page_sync(READ, file, 0, page);
 	if (ret < 0)
 		goto out;
 
-	bat_entries = kmap(md0->page);
-	nr = PAGE_SIZE / sizeof(u32) - PLOOP_MAP_OFFSET;
-	ret = convert_bat_entries(bat_entries + PLOOP_MAP_OFFSET, nr);
-	kunmap(md0->page);
-	if (ret) {
-		pr_err("Can't read BAT\n");
-		goto out;
-	}
-
-	ret = ploop_setup_metadata(ploop, md0->page);
+	ret = ploop_setup_metadata(ploop, page);
 	if (ret)
 		goto out;
-	/* Alloc rest of pages */
-	ret = prealloc_md_pages(&ploop->bat_entries, 1, ploop->nr_bat_entries);
+
+	ret = prealloc_md_pages(&ploop->bat_entries, 0, ploop->nr_bat_entries);
 	if (ret)
 		goto out;
 out:
+	if (page)
+		put_page(page);
 	return ret;
 }
 
@@ -353,18 +337,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		goto err;
 	}
 
-	/*
-	 * We do not add FMODE_EXCL, because further open_table_device()
-	 * unconditionally adds it. See call stack.
-	 */
-	ret = dm_get_device(ti, argv[1], dm_table_get_mode(ti->table),
-			    &ploop->origin_dev);
-	if (ret) {
-		ti->error = "Error opening origin device";
-		goto err;
-	}
-
-	ret = ploop_add_deltas_stack(ploop, &argv[2], argc - 2);
+	ret = ploop_add_deltas_stack(ploop, &argv[1], argc - 1);
 	if (ret)
 		goto err;
 
@@ -390,7 +363,6 @@ 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;
 
-	/* TODO: take into account the origin_dev */
 	limits->max_discard_sectors = 1 << cluster_log;
 	limits->max_hw_discard_sectors = 1 << cluster_log;
 	limits->discard_granularity = 1 << (cluster_log + SECTOR_SHIFT);
@@ -398,29 +370,6 @@ static void ploop_io_hints(struct dm_target *ti, struct queue_limits *limits)
 	limits->discard_misaligned = 0;
 }
 
-static sector_t get_dev_size(struct dm_dev *dev)
-{
-	return i_size_read(dev->bdev->bd_inode) >> SECTOR_SHIFT;
-}
-
-static int ploop_iterate_devices(struct dm_target *ti,
-				 iterate_devices_callout_fn fn, void *data)
-{
-	struct ploop *ploop = ti->private;
-	sector_t size;
-
-	size = get_dev_size(ploop->origin_dev);
-
-	return fn(ti, ploop->origin_dev, 0, size, data);
-}
-
-static void ploop_postsuspend(struct dm_target *ti)
-{
-	struct ploop *ploop = ti->private;
-
-	blkdev_issue_flush(ploop->origin_dev->bdev, GFP_NOIO, NULL);
-}
-
 static void ploop_status(struct dm_target *ti, status_type_t type,
 			 unsigned int status_flags, char *result,
 			 unsigned int maxlen)
@@ -472,8 +421,6 @@ static struct target_type ploop_target = {
 	.end_io = ploop_endio,
 	.message = ploop_message,
 	.io_hints = ploop_io_hints,
-	.iterate_devices = ploop_iterate_devices,
-	.postsuspend = ploop_postsuspend,
 	.preresume = ploop_preresume,
 	.status = ploop_status,
 };
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 1418e3bd53a2..a8abd89164a1 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -86,10 +86,6 @@ struct ploop_cmd {
 			void *tracking_bitmap;
 			unsigned int tb_nr;
 		} tracking_start;
-		struct {
-			struct dm_dev *origin_dev;
-			struct file *file;
-		} flip_upper_deltas;
 		struct {
 			struct push_backup *pb;
 		} set_push_backup;
@@ -157,7 +153,6 @@ struct md_page {
 struct ploop {
 	struct dm_target *ti;
 
-	struct dm_dev *origin_dev;
 	struct rb_root bat_entries;
 	struct ploop_delta *deltas;
 	u8 nr_deltas;
@@ -305,11 +300,6 @@ static inline bool ploop_is_ro(struct ploop *ploop)
 	return (dm_table_get_mode(ploop->ti->table) & FMODE_WRITE) == 0;
 }
 
-static inline void remap_to_origin(struct ploop *ploop, struct bio *bio)
-{
-	bio_set_dev(bio, ploop->origin_dev->bdev);
-}
-
 static inline void remap_to_cluster(struct ploop *ploop, struct pio *pio,
 				    unsigned int cluster)
 {




More information about the Devel mailing list