[PATCH 8/8] null_blk: adjusts the code with latest changes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that we have support for more than on special operations
REQ_OP_DISCARD and REQ_OP_WRITE_ZEROES create a helper to isolate the
code common code.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@xxxxxxx>
---
 drivers/block/null_blk_main.c | 41 +++++++++++++++++------------------
 1 file changed, 20 insertions(+), 21 deletions(-)

diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index c734ddaa697f..f59a05bcf56f 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1107,28 +1107,36 @@ static int null_transfer(struct nullb *nullb, struct page *page,
 	return err;
 }
 
+static inline bool null_handle_special_op(struct nullb *nullb, sector_t sector,
+					  unsigned int bytes, enum req_opf op)
+{
+	switch (op) {
+	case REQ_OP_DISCARD:
+		null_handle_discard(nullb, sector, bytes);
+		return true;
+	case REQ_OP_WRITE_ZEROES:
+		null_handle_write_zeroes(nullb, sector, bytes);
+		return true;
+	default:
+		break;
+	}
+	return false;
+}
+
 static int null_handle_rq(struct nullb_cmd *cmd)
 {
 	struct request *rq = cmd->rq;
 	struct nullb *nullb = cmd->nq->dev->nullb;
 	int err;
-	unsigned int len;
+	unsigned int len = blk_rq_bytes(rq);
 	sector_t sector;
 	struct req_iterator iter;
 	struct bio_vec bvec;
 
 	sector = blk_rq_pos(rq);
 
-	switch (req_op(rq)) {
-	case REQ_OP_DISCARD:
-		null_handle_discard(nullb, sector, blk_rq_bytes(rq));
+	if (null_handle_special_op(nullb, sector, len, req_op(rq)))
 		return 0;
-	case REQ_OP_WRITE_ZEROES:
-		null_handle_write_zeroes(nullb, sector, blk_rq_bytes(rq));
-		return 0;
-	default:
-		break;
-	}
 
 	spin_lock_irq(&nullb->lock);
 	rq_for_each_segment(bvec, rq, iter) {
@@ -1149,27 +1157,18 @@ static int null_handle_rq(struct nullb_cmd *cmd)
 
 static int null_handle_bio(struct nullb_cmd *cmd)
 {
-	unsigned int blk_bio_bytes = bio_sectors(cmd->bio) << SECTOR_SHIFT;
+	unsigned int len = bio_sectors(cmd->bio) << SECTOR_SHIFT;
 	struct bio *bio = cmd->bio;
 	struct nullb *nullb = cmd->nq->dev->nullb;
 	int err;
-	unsigned int len;
 	sector_t sector;
 	struct bio_vec bvec;
 	struct bvec_iter iter;
 
 	sector = bio->bi_iter.bi_sector;
 
-	switch (bio_op(bio)) {
-	case REQ_OP_DISCARD:
-		null_handle_discard(nullb, sector, blk_bio_bytes);
+	if (null_handle_special_op(nullb, sector, len, bio_op(bio)))
 		return 0;
-	case REQ_OP_WRITE_ZEROES:
-		null_handle_write_zeroes(nullb, sector, blk_bio_bytes);
-		return 0;
-	default:
-		break;
-	}
 
 	spin_lock_irq(&nullb->lock);
 	bio_for_each_segment(bvec, bio, iter) {
-- 
2.17.0




[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux