diff options
| author | Ming Lei <ming.lei@redhat.com> | 2025-10-15 19:07:26 +0800 |
|---|---|---|
| committer | Jens Axboe <axboe@kernel.dk> | 2025-11-18 06:49:51 -0700 |
| commit | c3e6c11147f6f05c15e9c2d74f5d234a6661013c (patch) | |
| tree | 94ac37c86c4c26ff7ea83ad554d8542c51b188db | |
| parent | 2c6d792d4b7676e2b340df05425330452fee1f40 (diff) | |
loop: add helper lo_cmd_nr_bvec()
Add lo_cmd_nr_bvec() and prepare for refactoring lo_rw_aio().
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
| -rw-r--r-- | drivers/block/loop.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 13ce229d450c..c6c37c9df193 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -337,6 +337,19 @@ static void lo_rw_aio_complete(struct kiocb *iocb, long ret) lo_rw_aio_do_completion(cmd); } +static inline unsigned lo_cmd_nr_bvec(struct loop_cmd *cmd) +{ + struct request *rq = blk_mq_rq_from_pdu(cmd); + struct req_iterator rq_iter; + struct bio_vec tmp; + int nr_bvec = 0; + + rq_for_each_bvec(tmp, rq, rq_iter) + nr_bvec++; + + return nr_bvec; +} + static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, loff_t pos, int rw) { @@ -348,12 +361,9 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd, struct file *file = lo->lo_backing_file; struct bio_vec tmp; unsigned int offset; - int nr_bvec = 0; + int nr_bvec = lo_cmd_nr_bvec(cmd); int ret; - rq_for_each_bvec(tmp, rq, rq_iter) - nr_bvec++; - if (rq->bio != rq->biotail) { bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), |
