]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
null_blk: pass transfer size to null_handle_rq()
authorShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Wed, 26 Feb 2025 10:06:12 +0000 (19:06 +0900)
committerJens Axboe <axboe@kernel.dk>
Mon, 3 Mar 2025 18:17:52 +0000 (11:17 -0700)
As preparation to support partial data transfer, add a new argument to
null_handle_rq() to pass the number of sectors to transfer. While at it,
rename the function from null_handle_rq to null_handle_data_transfer.
This commit does not change the behavior.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Link: https://lore.kernel.org/r/20250226100613.1622564-5-shinichiro.kawasaki@wdc.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/null_blk/main.c

index 87037cb375c94e5767ad070f04eacabfa28e47de..8025766988124b8711d4b64c0ac7b2d5d3cb9711 100644 (file)
@@ -1263,25 +1263,37 @@ static int null_transfer(struct nullb *nullb, struct page *page,
        return err;
 }
 
-static blk_status_t null_handle_rq(struct nullb_cmd *cmd)
+/*
+ * Transfer data for the given request. The transfer size is capped with the
+ * nr_sectors argument.
+ */
+static blk_status_t null_handle_data_transfer(struct nullb_cmd *cmd,
+                                             sector_t nr_sectors)
 {
        struct request *rq = blk_mq_rq_from_pdu(cmd);
        struct nullb *nullb = cmd->nq->dev->nullb;
        int err = 0;
        unsigned int len;
        sector_t sector = blk_rq_pos(rq);
+       unsigned int max_bytes = nr_sectors << SECTOR_SHIFT;
+       unsigned int transferred_bytes = 0;
        struct req_iterator iter;
        struct bio_vec bvec;
 
        spin_lock_irq(&nullb->lock);
        rq_for_each_segment(bvec, rq, iter) {
                len = bvec.bv_len;
+               if (transferred_bytes + len > max_bytes)
+                       len = max_bytes - transferred_bytes;
                err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset,
                                     op_is_write(req_op(rq)), sector,
                                     rq->cmd_flags & REQ_FUA);
                if (err)
                        break;
                sector += len >> SECTOR_SHIFT;
+               transferred_bytes += len;
+               if (transferred_bytes >= max_bytes)
+                       break;
        }
        spin_unlock_irq(&nullb->lock);
 
@@ -1333,7 +1345,7 @@ blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, enum req_op op,
        if (op == REQ_OP_DISCARD)
                return null_handle_discard(dev, sector, nr_sectors);
 
-       return null_handle_rq(cmd);
+       return null_handle_data_transfer(cmd, nr_sectors);
 }
 
 static void nullb_zero_read_cmd_buffer(struct nullb_cmd *cmd)