[Devel] [PATCH RH8 27/61] ploop: Convert whole_cluster()

Kirill Tkhai ktkhai at virtuozzo.com
Fri May 14 18:57:01 MSK 2021


Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/md/dm-ploop-map.c |    7 +++----
 drivers/md/dm-ploop.h     |    8 +++++---
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index 89cfd7b82868..d30c055c2d50 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -194,15 +194,14 @@ static void queue_discard_index_wb(struct ploop *ploop, struct pio *pio)
 }
 
 /* This 1)defers looking suitable discard bios and 2)ends the rest of them. */
-static int ploop_map_discard(struct ploop *ploop, struct bio *bio)
+static int ploop_map_discard(struct ploop *ploop, struct pio *pio)
 {
-	struct pio *pio = bio_to_endio_hook(bio);
 	bool supported = false;
 	unsigned int cluster;
 	unsigned long flags;
 
 	/* Only whole cluster in no-snapshots case can be discarded. */
-	if (whole_cluster(ploop, bio)) {
+	if (whole_cluster(ploop, pio)) {
 		cluster = pio->bi_iter.bi_sector >> ploop->cluster_log;
 		read_lock_irqsave(&ploop->bat_rwlock, flags);
 		/* Early checks to not wake up work for nought. */
@@ -1652,7 +1651,7 @@ int ploop_map(struct dm_target *ti, struct bio *bio)
 		if (ploop_pio_cluster(ploop, pio, &cluster) < 0)
 			return DM_MAPIO_KILL;
 		if (op_is_discard(pio->bi_opf))
-			return ploop_map_discard(ploop, bio);
+			return ploop_map_discard(ploop, pio);
 
 		defer_pios(ploop, pio, NULL);
 		return DM_MAPIO_SUBMITTED;
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index 6abe21d0ad0f..a692b49f7ae6 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -322,15 +322,17 @@ static inline void remap_to_cluster_bio(struct ploop *ploop, struct bio *bio,
 	bio->bi_iter.bi_sector |= (cluster << ploop->cluster_log);
 }
 
-static inline bool whole_cluster(struct ploop *ploop, struct bio *bio)
+static inline bool whole_cluster(struct ploop *ploop, struct pio *pio)
 {
-	if (bio_sectors(bio) != (1 << ploop->cluster_log))
+	sector_t end_sector = bvec_iter_end_sector(pio->bi_iter);
+
+	if (pio->bi_iter.bi_size != to_bytes(1 << ploop->cluster_log))
 		return false;
 	/*
 	 * There is no sacral meaning in bio_end_sector(),
 	 * it's just a suitable and existing primitive.
 	 */
-	return !(bio_end_sector(bio) & ((1 << ploop->cluster_log) - 1));
+	return !(end_sector & ((1 << ploop->cluster_log) - 1));
 }
 
 #define BAT_LEVEL_MAX		(U8_MAX - 1)




More information about the Devel mailing list