[Devel] [PATCH rh7 06/12] ploop: Add cluster_log local variable

Kirill Tkhai ktkhai at virtuozzo.com
Fri Mar 1 18:13:53 MSK 2019


This refactoring adds local variable in functions,
where the construction "plo->cluster_log" is used
more then once.

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/dev.c     |   23 +++++++++++++----------
 drivers/block/ploop/fmt_raw.c |    7 ++++---
 drivers/block/ploop/io_kaio.c |    2 +-
 3 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 42b8a1b7af99..df35c4d011ec 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -661,9 +661,10 @@ static struct ploop_delta *
 ploop_fast_lookup(struct ploop_device * plo, sector_t sec,
 		  unsigned long rw, sector_t * isec)
 {
+	unsigned int cluster_log = plo->cluster_log;
 	struct ploop_delta * top_delta, * delta;
 	int level;
-	cluster_t bio_cluster = sec >> plo->cluster_log;
+	cluster_t bio_cluster = sec >> cluster_log;
 	iblock_t iblk;
 
 	level = ploop_fastmap(&plo->map, bio_cluster, &iblk);
@@ -687,8 +688,8 @@ ploop_fast_lookup(struct ploop_device * plo, sector_t sec,
 		delta = find_delta(plo, level);
 	}
 	if (delta) {
-		*isec = ((sector_t)iblk << plo->cluster_log) +
-			(sec & ((1 << plo->cluster_log) - 1));
+		*isec = ((sector_t)iblk << cluster_log) +
+			(sec & ((1 << cluster_log) - 1));
 	}
 	return delta;
 }
@@ -847,6 +848,7 @@ static void ploop_make_request(struct request_queue *q, struct bio *bio)
 {
 	struct bio * nbio;
 	struct ploop_device * plo = q->queuedata;
+	unsigned int cluster_log = plo->cluster_log;
 	unsigned long rw = bio_data_dir(bio);
 	struct hd_struct *part;
 	int cpu;
@@ -895,11 +897,11 @@ static void ploop_make_request(struct request_queue *q, struct bio *bio)
 	 * not depending on any alignment constraints. So be it.
 	 */
 	if (!(bio->bi_rw & REQ_DISCARD) && bio->bi_size &&
-	    (bio->bi_sector >> plo->cluster_log) !=
-	    ((bio->bi_sector + (bio->bi_size >> 9) - 1) >> plo->cluster_log)) {
+	    (bio->bi_sector >> cluster_log) !=
+	    ((bio->bi_sector + (bio->bi_size >> 9) - 1) >> cluster_log)) {
 		struct bio_pair *bp;
-		unsigned int first_sectors = (1<<plo->cluster_log)
-			- (bio->bi_sector & ((1<<plo->cluster_log) - 1));
+		unsigned int first_sectors = (1<<cluster_log)
+			- (bio->bi_sector & ((1<<cluster_log) - 1));
 
 		plo->st.bio_splits++;
 
@@ -981,7 +983,7 @@ static void ploop_make_request(struct request_queue *q, struct bio *bio)
 	    bio->bi_size) {
 		struct ploop_request * preq;
 		struct rb_node * n = req_entry_tree(plo, bio->bi_rw)->rb_node;
-		u32 bio_cluster = bio->bi_sector >> plo->cluster_log;
+		u32 bio_cluster = bio->bi_sector >> cluster_log;
 
 		while (n) {
 			preq = rb_entry(n, struct ploop_request, lockout_link);
@@ -1103,6 +1105,7 @@ ploop_merge_bvec(struct request_queue *q, struct bvec_merge_data *bm_data,
 		 struct bio_vec *bvec)
 {
 	struct ploop_device *plo = q->queuedata;
+	unsigned int cluster_log = plo->cluster_log;
 	struct ploop_delta * delta;
 	sector_t sec;
 	sector_t isector;
@@ -1122,8 +1125,8 @@ ploop_merge_bvec(struct request_queue *q, struct bvec_merge_data *bm_data,
 
 	len >>= 9;
 
-	if ((sec >> plo->cluster_log) != 
-	    ((sec + len - 1) >> plo->cluster_log)) {
+	if ((sec >> cluster_log) !=
+	    ((sec + len - 1) >> cluster_log)) {
 		plo->st.merge_neg_cluster++;
 		return 0;
 	}
diff --git a/drivers/block/ploop/fmt_raw.c b/drivers/block/ploop/fmt_raw.c
index f7efa86a80ce..529ea625e917 100644
--- a/drivers/block/ploop/fmt_raw.c
+++ b/drivers/block/ploop/fmt_raw.c
@@ -74,6 +74,7 @@ raw_open(struct ploop_delta * delta)
 static int
 raw_refresh(struct ploop_delta * delta)
 {
+	unsigned int cluster_log = delta->plo->cluster_log;
 	loff_t pos;
 
 	pos = delta->io.ops->i_size_read(&delta->io);
@@ -81,15 +82,15 @@ raw_refresh(struct ploop_delta * delta)
 		printk("raw delta is not aligned (%llu bytes)\n", pos);
 		return -EINVAL;
 	}
-	if ((pos >> (delta->plo->cluster_log + 9)) < delta->io.alloc_head) {
+	if ((pos >> (cluster_log + 9)) < delta->io.alloc_head) {
 		printk("raw delta was corrupted "
 		       "(old_size=%u new_size=%llu iblocks)\n",
 		       delta->io.alloc_head,
-		       pos >> (delta->plo->cluster_log + 9));
+		       pos >> (cluster_log + 9));
 		return -EINVAL;
 	}
 
-	delta->io.alloc_head = pos >> (delta->plo->cluster_log + 9);
+	delta->io.alloc_head = pos >> (cluster_log + 9);
 	return 0;
 }
 
diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index df55533458a3..f5d9936d4cd4 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -554,7 +554,7 @@ kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
 	iblock_t iblk;
 	int log = preq->plo->cluster_log + 9;
 	loff_t clu_siz = 1 << log;
-	loff_t end_pos = (loff_t)io->alloc_head << (io->plo->cluster_log + 9);
+	loff_t end_pos = (loff_t)io->alloc_head << log;
 
 	if (delta->flags & PLOOP_FMT_RDONLY) {
 		PLOOP_FAIL_REQUEST(preq, -EBADF);



More information about the Devel mailing list