Skip to content

Commit 0a3140e

Browse files
Chaitanya Kulkarniaxboe
authored andcommitted
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 <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 3b005bf commit 0a3140e

File tree

6 files changed

+18
-27
lines changed

6 files changed

+18
-27
lines changed

block/bio.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,14 @@ void bio_chain(struct bio *bio, struct bio *parent)
344344
}
345345
EXPORT_SYMBOL(bio_chain);
346346

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)
348349
{
349350
struct bio *new = bio_alloc(gfp, nr_pages);
350351

352+
bio_set_dev(new, bdev);
353+
new->bi_opf = opf;
354+
351355
if (bio) {
352356
bio_chain(bio, new);
353357
submit_bio(bio);

block/blk-lib.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,8 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
8282

8383
WARN_ON_ONCE((req_sects << 9) > UINT_MAX);
8484

85-
bio = blk_next_bio(bio, 0, gfp_mask);
85+
bio = blk_next_bio(bio, bdev, 0, op, gfp_mask);
8686
bio->bi_iter.bi_sector = sector;
87-
bio_set_dev(bio, bdev);
88-
bio_set_op_attrs(bio, op, 0);
89-
9087
bio->bi_iter.bi_size = req_sects << 9;
9188
sector += req_sects;
9289
nr_sects -= req_sects;
@@ -176,14 +173,12 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
176173
max_write_same_sectors = bio_allowed_max_sectors(q);
177174

178175
while (nr_sects) {
179-
bio = blk_next_bio(bio, 1, gfp_mask);
176+
bio = blk_next_bio(bio, bdev, 1, REQ_OP_WRITE_SAME, gfp_mask);
180177
bio->bi_iter.bi_sector = sector;
181-
bio_set_dev(bio, bdev);
182178
bio->bi_vcnt = 1;
183179
bio->bi_io_vec->bv_page = page;
184180
bio->bi_io_vec->bv_offset = 0;
185181
bio->bi_io_vec->bv_len = bdev_logical_block_size(bdev);
186-
bio_set_op_attrs(bio, REQ_OP_WRITE_SAME, 0);
187182

188183
if (nr_sects > max_write_same_sectors) {
189184
bio->bi_iter.bi_size = max_write_same_sectors << 9;
@@ -252,10 +247,8 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
252247
return -EOPNOTSUPP;
253248

254249
while (nr_sects) {
255-
bio = blk_next_bio(bio, 0, gfp_mask);
250+
bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask);
256251
bio->bi_iter.bi_sector = sector;
257-
bio_set_dev(bio, bdev);
258-
bio->bi_opf = REQ_OP_WRITE_ZEROES;
259252
if (flags & BLKDEV_ZERO_NOUNMAP)
260253
bio->bi_opf |= REQ_NOUNMAP;
261254

@@ -303,11 +296,9 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
303296
return -EPERM;
304297

305298
while (nr_sects != 0) {
306-
bio = blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects),
307-
gfp_mask);
299+
bio = blk_next_bio(bio, bdev, __blkdev_sectors_to_bio_pages(nr_sects),
300+
REQ_OP_WRITE, gfp_mask);
308301
bio->bi_iter.bi_sector = sector;
309-
bio_set_dev(bio, bdev);
310-
bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
311302

312303
while (nr_sects != 0) {
313304
sz = min((sector_t) PAGE_SIZE, nr_sects << 9);

block/blk-zoned.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,8 @@ static int blkdev_zone_reset_all_emulated(struct block_device *bdev,
215215
continue;
216216
}
217217

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);
221220
bio->bi_iter.bi_sector = sector;
222221
sector += zone_sectors;
223222

@@ -306,9 +305,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
306305
}
307306

308307
while (sector < end_sector) {
309-
bio = blk_next_bio(bio, 0, gfp_mask);
310-
bio_set_dev(bio, bdev);
311-
bio->bi_opf = op | REQ_SYNC;
308+
bio = blk_next_bio(bio, bdev, 0, op | REQ_SYNC, gfp_mask);
312309
bio->bi_iter.bi_sector = sector;
313310
sector += zone_sectors;
314311

block/blk.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ extern int blk_iolatency_init(struct request_queue *q);
406406
static inline int blk_iolatency_init(struct request_queue *q) { return 0; }
407407
#endif
408408

409-
struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp);
410-
411409
#ifdef CONFIG_BLK_DEV_ZONED
412410
void blk_queue_free_zone_bitmaps(struct request_queue *q);
413411
void blk_queue_clear_zone_settings(struct request_queue *q);

drivers/nvme/target/zns.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,10 @@ static u16 nvmet_bdev_zone_mgmt_emulate_all(struct nvmet_req *req)
412412

413413
while (sector < get_capacity(bdev->bd_disk)) {
414414
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);
417418
bio->bi_iter.bi_sector = sector;
418-
bio_set_dev(bio, bdev);
419419
/* This may take a while, so be nice to others */
420420
cond_resched();
421421
}

include/linux/bio.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
790790
bio->bi_opf |= REQ_NOWAIT;
791791
}
792792

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);
794795

795796
#endif /* __LINUX_BIO_H */

0 commit comments

Comments
 (0)