Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: pass a block_device and opf to blk_next_bio

All callers need to set the block_device and operation, so lift that into
the common code.

Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20220124091107.642561-15-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Chaitanya Kulkarni and committed by
Jens Axboe
0a3140ea 3b005bf6

+18 -27
+5 -1
block/bio.c
··· 344 344 } 345 345 EXPORT_SYMBOL(bio_chain); 346 346 347 - struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) 347 + struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev, 348 + unsigned int nr_pages, unsigned int opf, gfp_t gfp) 348 349 { 349 350 struct bio *new = bio_alloc(gfp, nr_pages); 351 + 352 + bio_set_dev(new, bdev); 353 + new->bi_opf = opf; 350 354 351 355 if (bio) { 352 356 bio_chain(bio, new);
+5 -14
block/blk-lib.c
··· 82 82 83 83 WARN_ON_ONCE((req_sects << 9) > UINT_MAX); 84 84 85 - bio = blk_next_bio(bio, 0, gfp_mask); 85 + bio = blk_next_bio(bio, bdev, 0, op, gfp_mask); 86 86 bio->bi_iter.bi_sector = sector; 87 - bio_set_dev(bio, bdev); 88 - bio_set_op_attrs(bio, op, 0); 89 - 90 87 bio->bi_iter.bi_size = req_sects << 9; 91 88 sector += req_sects; 92 89 nr_sects -= req_sects; ··· 173 176 max_write_same_sectors = bio_allowed_max_sectors(q); 174 177 175 178 while (nr_sects) { 176 - bio = blk_next_bio(bio, 1, gfp_mask); 179 + bio = blk_next_bio(bio, bdev, 1, REQ_OP_WRITE_SAME, gfp_mask); 177 180 bio->bi_iter.bi_sector = sector; 178 - bio_set_dev(bio, bdev); 179 181 bio->bi_vcnt = 1; 180 182 bio->bi_io_vec->bv_page = page; 181 183 bio->bi_io_vec->bv_offset = 0; 182 184 bio->bi_io_vec->bv_len = bdev_logical_block_size(bdev); 183 - bio_set_op_attrs(bio, REQ_OP_WRITE_SAME, 0); 184 185 185 186 if (nr_sects > max_write_same_sectors) { 186 187 bio->bi_iter.bi_size = max_write_same_sectors << 9; ··· 247 252 return -EOPNOTSUPP; 248 253 249 254 while (nr_sects) { 250 - bio = blk_next_bio(bio, 0, gfp_mask); 255 + bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask); 251 256 bio->bi_iter.bi_sector = sector; 252 - bio_set_dev(bio, bdev); 253 - bio->bi_opf = REQ_OP_WRITE_ZEROES; 254 257 if (flags & BLKDEV_ZERO_NOUNMAP) 255 258 bio->bi_opf |= REQ_NOUNMAP; 256 259 ··· 296 303 return -EPERM; 297 304 298 305 while (nr_sects != 0) { 299 - bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), 300 - gfp_mask); 306 + bio = blk_next_bio(bio, bdev, __blkdev_sectors_to_bio_pages(nr_sects), 307 + REQ_OP_WRITE, gfp_mask); 301 308 bio->bi_iter.bi_sector = sector; 302 - bio_set_dev(bio, bdev); 303 - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); 304 309 305 310 while (nr_sects != 0) { 306 311 sz = min((sector_t) PAGE_SIZE, nr_sects << 9);
+3 -6
block/blk-zoned.c
··· 215 215 continue; 216 216 } 217 217 218 - bio = blk_next_bio(bio, 0, gfp_mask); 219 - bio_set_dev(bio, bdev); 220 - bio->bi_opf = REQ_OP_ZONE_RESET | REQ_SYNC; 218 + bio = blk_next_bio(bio, bdev, 0, REQ_OP_ZONE_RESET | REQ_SYNC, 219 + gfp_mask); 221 220 bio->bi_iter.bi_sector = sector; 222 221 sector += zone_sectors; 223 222 ··· 305 306 } 306 307 307 308 while (sector < end_sector) { 308 - bio = blk_next_bio(bio, 0, gfp_mask); 309 - bio_set_dev(bio, bdev); 310 - bio->bi_opf = op | REQ_SYNC; 309 + bio = blk_next_bio(bio, bdev, 0, op | REQ_SYNC, gfp_mask); 311 310 bio->bi_iter.bi_sector = sector; 312 311 sector += zone_sectors; 313 312
-2
block/blk.h
··· 406 406 static inline int blk_iolatency_init(struct request_queue *q) { return 0; } 407 407 #endif 408 408 409 - struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp); 410 - 411 409 #ifdef CONFIG_BLK_DEV_ZONED 412 410 void blk_queue_free_zone_bitmaps(struct request_queue *q); 413 411 void blk_queue_clear_zone_settings(struct request_queue *q);
+3 -3
drivers/nvme/target/zns.c
··· 412 412 413 413 while (sector < get_capacity(bdev->bd_disk)) { 414 414 if (test_bit(blk_queue_zone_no(q, sector), d.zbitmap)) { 415 - bio = blk_next_bio(bio, 0, GFP_KERNEL); 416 - bio->bi_opf = zsa_req_op(req->cmd->zms.zsa) | REQ_SYNC; 415 + bio = blk_next_bio(bio, bdev, 0, 416 + zsa_req_op(req->cmd->zms.zsa) | REQ_SYNC, 417 + GFP_KERNEL); 417 418 bio->bi_iter.bi_sector = sector; 418 - bio_set_dev(bio, bdev); 419 419 /* This may take a while, so be nice to others */ 420 420 cond_resched(); 421 421 }
+2 -1
include/linux/bio.h
··· 790 790 bio->bi_opf |= REQ_NOWAIT; 791 791 } 792 792 793 - struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp); 793 + struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev, 794 + unsigned int nr_pages, unsigned int opf, gfp_t gfp); 794 795 795 796 #endif /* __LINUX_BIO_H */