[Devel] [PATCH RH8 1/2] dm-ploop: Make target not immutable

Kirill Tkhai ktkhai at virtuozzo.com
Thu Aug 19 20:37:42 MSK 2021


Immutable target can't be replaced with another one.
For our this means we can't replace it with push backup.
So, we declare it as !immutable.

Since target is not immutable now, we can't ask dm about
per_io_data_size (since different targets need different
sizes). So, we allocate prq directly.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c    |   15 ++++++++++-----
 drivers/md/dm-ploop-target.c |    3 +--
 drivers/md/dm-ploop.h        |   22 ----------------------
 3 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 67d61bd757bd..9a49867e4800 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -22,6 +22,7 @@
 #define PREALLOC_SIZE (128ULL * 1024 * 1024)
 
 static void handle_cleanup(struct ploop *ploop, struct pio *pio);
+static void prq_endio(struct pio *pio, void *prq_ptr, blk_status_t bi_status);
 
 #define DM_MSG_PREFIX "ploop"
 
@@ -175,7 +176,7 @@ static bool ploop_try_delay_enospc(struct ploop_rq *prq, struct pio *pio)
 	return delayed;
 }
 
-void prq_endio(struct pio *pio, void *prq_ptr, blk_status_t bi_status)
+static void prq_endio(struct pio *pio, void *prq_ptr, blk_status_t bi_status)
 {
         struct ploop_rq *prq = prq_ptr;
         struct request *rq = prq->rq;
@@ -197,6 +198,7 @@ void prq_endio(struct pio *pio, void *prq_ptr, blk_status_t bi_status)
 			return;
 	}
 
+	kfree(prq);
 	dm_complete_request(rq, bi_status);
 }
 
@@ -1631,7 +1633,7 @@ static struct bio_vec *create_bvec_from_rq(struct request *rq)
 static void prepare_one_embedded_pio(struct ploop *ploop, struct pio *pio,
 				     struct list_head *deferred_pios)
 {
-	struct ploop_rq *prq = embedded_pio_to_prq(pio);
+	struct ploop_rq *prq = pio->endio_cb_data;
 	struct request *rq = prq->rq;
 	struct bio_vec *bvec = NULL;
 	LIST_HEAD(list);
@@ -1837,7 +1839,7 @@ void do_ploop_fsync_work(struct work_struct *ws)
 
 static void submit_embedded_pio(struct ploop *ploop, struct pio *pio)
 {
-	struct ploop_rq *prq = embedded_pio_to_prq(pio);
+	struct ploop_rq *prq = pio->endio_cb_data;
 	struct request *rq = prq->rq;
 	struct work_struct *worker;
 	unsigned long flags;
@@ -1886,8 +1888,11 @@ int ploop_clone_and_map(struct dm_target *ti, struct request *rq,
 	if (blk_rq_bytes(rq) && ploop_rq_valid(ploop, rq) < 0)
 		return DM_MAPIO_KILL;
 
-	prq = map_info_to_embedded_prq(info);
-	pio = map_info_to_embedded_pio(info);
+	prq = kmalloc(sizeof(*prq) + sizeof(*pio), GFP_ATOMIC); /* TODO: memcache */
+	if (!prq)
+		return DM_MAPIO_KILL;
+	pio = (void *)prq + sizeof(*prq);
+
 	init_prq_and_embedded_pio(ploop, rq, prq, pio);
 
 	submit_embedded_pio(ploop, pio);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 4a15767f9bc9..94442597c839 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -399,7 +399,6 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	if (ret)
 		goto err;
 
-	ti->per_io_data_size = ploop_per_io_data_size();
 	ti->num_flush_bios = 1;
 	ti->flush_supported = true;
 	ti->num_discard_bios = 1;
@@ -513,7 +512,7 @@ static int ploop_preresume(struct dm_target *ti)
 static struct target_type ploop_target = {
 	.name = "ploop",
 	.version = {1, 0, 0},
-	.features = DM_TARGET_SINGLETON|DM_TARGET_IMMUTABLE,
+	.features = DM_TARGET_SINGLETON,
 	.module = THIS_MODULE,
 	.ctr = ploop_ctr,
 	.dtr = ploop_dtr,
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 6d92b82cbe1b..aa35d620fe56 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -323,28 +323,6 @@ static inline bool whole_cluster(struct ploop *ploop, struct pio *pio)
 	return !(end_sector & ((1 << ploop->cluster_log) - 1));
 }
 
-static inline ssize_t ploop_per_io_data_size(void)
-{
-	return sizeof(struct ploop_rq) + sizeof(struct pio);
-}
-static inline struct ploop_rq *map_info_to_embedded_prq(union map_info *info)
-{
-	return (void *)info->ptr;
-}
-static inline struct pio *map_info_to_embedded_pio(union map_info *info)
-{
-	return (void *)info->ptr + sizeof(struct ploop_rq);
-}
-
-extern void prq_endio(struct pio *pio, void *prq_ptr, blk_status_t bi_status);
-
-static inline struct ploop_rq *embedded_pio_to_prq(struct pio *pio)
-{
-	struct ploop_rq *prq = (void *)pio - sizeof(struct ploop_rq);
-	WARN_ON_ONCE(pio->endio_cb != prq_endio);
-	return prq;
-}
-
 #define BAT_LEVEL_MAX		(U8_MAX - 1)
 #define BAT_LEVEL_INVALID	U8_MAX
 static inline u8 top_level(struct ploop *ploop)




More information about the Devel mailing list