[Devel] [PATCH RH8] ploop: Introduce option "off=" to cut beginning of device

Kirill Tkhai ktkhai at virtuozzo.com
Tue Oct 12 19:01:24 MSK 2021


This is like the functionality of dm-linear.

https://jira.sw.ru/browse/PSBM-132445

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

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index e3cf0ab73c98..79142acddecc 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -42,6 +42,11 @@ static unsigned int pio_nr_segs(struct pio *pio)
         return nr_segs;
 }
 
+static sector_t ploop_rq_pos(struct ploop *ploop, struct request *rq)
+{
+	return blk_rq_pos(rq) + ploop->skip_off;
+}
+
 void ploop_index_wb_init(struct ploop_index_wb *piwb, struct ploop *ploop)
 {
 	piwb->ploop = ploop;
@@ -85,7 +90,7 @@ void init_pio(struct ploop *ploop, unsigned int bi_op, struct pio *pio)
 /* Get clu related to pio sectors */
 static int ploop_rq_valid(struct ploop *ploop, struct request *rq)
 {
-	sector_t sector = blk_rq_pos(rq);
+	sector_t sector = ploop_rq_pos(ploop, rq);
 	loff_t end_byte;
 	u32 end_clu;
 
@@ -1651,7 +1656,6 @@ static void prepare_one_embedded_pio(struct ploop *ploop, struct pio *pio,
 			goto err_nomem;
 		prq->bvec = bvec;
 skip_bvec:
-		pio->bi_iter.bi_sector = blk_rq_pos(rq);
 		pio->bi_iter.bi_size = blk_rq_bytes(rq);
 		pio->bi_iter.bi_idx = 0;
 		pio->bi_iter.bi_bvec_done = 0;
@@ -1661,6 +1665,7 @@ static void prepare_one_embedded_pio(struct ploop *ploop, struct pio *pio,
 
 		pio->bi_iter = rq->bio->bi_iter;
 	}
+	pio->bi_iter.bi_sector = ploop_rq_pos(ploop, rq);
 	pio->bi_io_vec = bvec;
 
 	pio->queue_list_id = PLOOP_LIST_DEFERRED;
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index ec0efddef2ac..327095f75359 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -389,16 +389,26 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 		goto err;
 	}
 
-	/* Optional parameter */
-	if (strcmp(argv[0], "falloc_new_clu") == 0) {
-		if (argc < 2) {
-			ret = -EINVAL;
-			goto err;
+	ret = -EINVAL;
+	/* Optional parameters */
+	while (argc > 0) {
+		if (strcmp(argv[0], "falloc_new_clu") == 0) {
+			ploop->falloc_new_clu = true;
+			EAT_ARG(argc, argv);
+			continue;
+		}
+		if (strncmp(argv[0], "off=", 4) == 0) {
+			if (kstrtou64(argv[0] + 4, 10, &ploop->skip_off) < 0)
+				goto err;
+			EAT_ARG(argc, argv);
+			continue;
 		}
-		ploop->falloc_new_clu = true;
-		EAT_ARG(argc, argv);
+		break;
 	}
 
+	if (argc <= 0)
+		goto err;
+
 	ret = ploop_add_deltas_stack(ploop, &argv[0], argc);
 	if (ret)
 		goto err;
@@ -435,7 +445,7 @@ static void ploop_status(struct dm_target *ti, status_type_t type,
 			 unsigned int maxlen)
 {
 	struct ploop *ploop = ti->private;
-	char stat[16] = { 0 }, *p = stat;
+	char stat[32] = { 0 }, *p = stat;
 	ssize_t sz = 0;
 
 	down_read(&ploop->ctl_rwsem);
@@ -447,6 +457,8 @@ static void ploop_status(struct dm_target *ti, status_type_t type,
 		p += sprintf(p, "n");
 	if (p == stat)
 		p += sprintf(p, "o");
+	if (ploop->skip_off)
+		p += sprintf(p, " off=%llu", ploop->skip_off);
 	up_read(&ploop->ctl_rwsem);
 
 	BUG_ON(p - stat >= sizeof(stat));
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 8de2a28b2dec..a7ca942c4670 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -148,6 +148,7 @@ struct ploop {
 	bool falloc_new_clu; /* fallocate() instead of truncate() */
 	u32 nr_bat_entries;
 	unsigned int cluster_log; /* In sectors */
+	sector_t skip_off; /* To cut beginning of ploop device */
 
 	u8 m_Sig[16]; /* Signature */
 	u32 m_Type; /* Disk type */




More information about the Devel mailing list