Skip to content

Commit c11f0c0

Browse files
committed
block/mm: make bdev_ops->rw_page() take a bool for read/write
Commit abf5454 changed it from an 'rw' flags type to the newer ops based interface, but now we're effectively leaking some bdev internals to the rest of the kernel. Since we only care about whether it's a read or a write at that level, just pass in a bool 'is_write' parameter instead. Then we can also move op_is_write() and friends back under CONFIG_BLOCK protection. Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 52ddb7e commit c11f0c0

File tree

11 files changed

+51
-53
lines changed

11 files changed

+51
-53
lines changed

drivers/block/brd.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,20 @@ static void copy_from_brd(void *dst, struct brd_device *brd,
300300
* Process a single bvec of a bio.
301301
*/
302302
static int brd_do_bvec(struct brd_device *brd, struct page *page,
303-
unsigned int len, unsigned int off, int op,
303+
unsigned int len, unsigned int off, bool is_write,
304304
sector_t sector)
305305
{
306306
void *mem;
307307
int err = 0;
308308

309-
if (op_is_write(op)) {
309+
if (is_write) {
310310
err = copy_to_brd_setup(brd, sector, len);
311311
if (err)
312312
goto out;
313313
}
314314

315315
mem = kmap_atomic(page);
316-
if (!op_is_write(op)) {
316+
if (!is_write) {
317317
copy_from_brd(mem + off, brd, sector, len);
318318
flush_dcache_page(page);
319319
} else {
@@ -350,8 +350,8 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
350350
unsigned int len = bvec.bv_len;
351351
int err;
352352

353-
err = brd_do_bvec(brd, bvec.bv_page, len,
354-
bvec.bv_offset, bio_op(bio), sector);
353+
err = brd_do_bvec(brd, bvec.bv_page, len, bvec.bv_offset,
354+
op_is_write(bio_op(bio)), sector);
355355
if (err)
356356
goto io_error;
357357
sector += len >> SECTOR_SHIFT;
@@ -366,11 +366,11 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
366366
}
367367

368368
static int brd_rw_page(struct block_device *bdev, sector_t sector,
369-
struct page *page, int op)
369+
struct page *page, bool is_write)
370370
{
371371
struct brd_device *brd = bdev->bd_disk->private_data;
372-
int err = brd_do_bvec(brd, page, PAGE_SIZE, 0, op, sector);
373-
page_endio(page, op, err);
372+
int err = brd_do_bvec(brd, page, PAGE_SIZE, 0, is_write, sector);
373+
page_endio(page, is_write, err);
374374
return err;
375375
}
376376

drivers/block/zram/zram_drv.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -843,26 +843,27 @@ static void zram_bio_discard(struct zram *zram, u32 index,
843843
}
844844

845845
static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
846-
int offset, int op)
846+
int offset, bool is_write)
847847
{
848848
unsigned long start_time = jiffies;
849+
int rw_acct = is_write ? REQ_OP_WRITE : REQ_OP_READ;
849850
int ret;
850851

851-
generic_start_io_acct(op, bvec->bv_len >> SECTOR_SHIFT,
852+
generic_start_io_acct(rw_acct, bvec->bv_len >> SECTOR_SHIFT,
852853
&zram->disk->part0);
853854

854-
if (!op_is_write(op)) {
855+
if (!is_write) {
855856
atomic64_inc(&zram->stats.num_reads);
856857
ret = zram_bvec_read(zram, bvec, index, offset);
857858
} else {
858859
atomic64_inc(&zram->stats.num_writes);
859860
ret = zram_bvec_write(zram, bvec, index, offset);
860861
}
861862

862-
generic_end_io_acct(op, &zram->disk->part0, start_time);
863+
generic_end_io_acct(rw_acct, &zram->disk->part0, start_time);
863864

864865
if (unlikely(ret)) {
865-
if (!op_is_write(op))
866+
if (!is_write)
866867
atomic64_inc(&zram->stats.failed_reads);
867868
else
868869
atomic64_inc(&zram->stats.failed_writes);
@@ -903,17 +904,17 @@ static void __zram_make_request(struct zram *zram, struct bio *bio)
903904
bv.bv_offset = bvec.bv_offset;
904905

905906
if (zram_bvec_rw(zram, &bv, index, offset,
906-
bio_op(bio)) < 0)
907+
op_is_write(bio_op(bio))) < 0)
907908
goto out;
908909

909910
bv.bv_len = bvec.bv_len - max_transfer_size;
910911
bv.bv_offset += max_transfer_size;
911912
if (zram_bvec_rw(zram, &bv, index + 1, 0,
912-
bio_op(bio)) < 0)
913+
op_is_write(bio_op(bio))) < 0)
913914
goto out;
914915
} else
915916
if (zram_bvec_rw(zram, &bvec, index, offset,
916-
bio_op(bio)) < 0)
917+
op_is_write(bio_op(bio))) < 0)
917918
goto out;
918919

919920
update_position(&index, &offset, &bvec);
@@ -970,7 +971,7 @@ static void zram_slot_free_notify(struct block_device *bdev,
970971
}
971972

972973
static int zram_rw_page(struct block_device *bdev, sector_t sector,
973-
struct page *page, int op)
974+
struct page *page, bool is_write)
974975
{
975976
int offset, err = -EIO;
976977
u32 index;
@@ -994,7 +995,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
994995
bv.bv_len = PAGE_SIZE;
995996
bv.bv_offset = 0;
996997

997-
err = zram_bvec_rw(zram, &bv, index, offset, op);
998+
err = zram_bvec_rw(zram, &bv, index, offset, is_write);
998999
put_zram:
9991000
zram_meta_put(zram);
10001001
out:
@@ -1007,7 +1008,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
10071008
* (e.g., SetPageError, set_page_dirty and extra works).
10081009
*/
10091010
if (err == 0)
1010-
page_endio(page, op, 0);
1011+
page_endio(page, is_write, 0);
10111012
return err;
10121013
}
10131014

drivers/nvdimm/btt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,11 +1133,11 @@ static int btt_write_pg(struct btt *btt, struct bio_integrity_payload *bip,
11331133

11341134
static int btt_do_bvec(struct btt *btt, struct bio_integrity_payload *bip,
11351135
struct page *page, unsigned int len, unsigned int off,
1136-
int op, sector_t sector)
1136+
bool is_write, sector_t sector)
11371137
{
11381138
int ret;
11391139

1140-
if (!op_is_write(op)) {
1140+
if (!is_write) {
11411141
ret = btt_read_pg(btt, bip, page, off, sector, len);
11421142
flush_dcache_page(page);
11431143
} else {
@@ -1180,7 +1180,7 @@ static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
11801180
BUG_ON(len % btt->sector_size);
11811181

11821182
err = btt_do_bvec(btt, bip, bvec.bv_page, len, bvec.bv_offset,
1183-
bio_op(bio), iter.bi_sector);
1183+
op_is_write(bio_op(bio)), iter.bi_sector);
11841184
if (err) {
11851185
dev_info(&btt->nd_btt->dev,
11861186
"io error in %s sector %lld, len %d,\n",
@@ -1200,12 +1200,12 @@ static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
12001200
}
12011201

12021202
static int btt_rw_page(struct block_device *bdev, sector_t sector,
1203-
struct page *page, int op)
1203+
struct page *page, bool is_write)
12041204
{
12051205
struct btt *btt = bdev->bd_disk->private_data;
12061206

1207-
btt_do_bvec(btt, NULL, page, PAGE_SIZE, 0, op, sector);
1208-
page_endio(page, op, 0);
1207+
btt_do_bvec(btt, NULL, page, PAGE_SIZE, 0, is_write, sector);
1208+
page_endio(page, is_write, 0);
12091209
return 0;
12101210
}
12111211

drivers/nvdimm/pmem.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
6767
}
6868

6969
static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
70-
unsigned int len, unsigned int off, int op,
70+
unsigned int len, unsigned int off, bool is_write,
7171
sector_t sector)
7272
{
7373
int rc = 0;
@@ -79,7 +79,7 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
7979
if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
8080
bad_pmem = true;
8181

82-
if (!op_is_write(op)) {
82+
if (!is_write) {
8383
if (unlikely(bad_pmem))
8484
rc = -EIO;
8585
else {
@@ -134,7 +134,7 @@ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
134134
do_acct = nd_iostat_start(bio, &start);
135135
bio_for_each_segment(bvec, bio, iter) {
136136
rc = pmem_do_bvec(pmem, bvec.bv_page, bvec.bv_len,
137-
bvec.bv_offset, bio_op(bio),
137+
bvec.bv_offset, op_is_write(bio_op(bio)),
138138
iter.bi_sector);
139139
if (rc) {
140140
bio->bi_error = rc;
@@ -152,12 +152,12 @@ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
152152
}
153153

154154
static int pmem_rw_page(struct block_device *bdev, sector_t sector,
155-
struct page *page, int op)
155+
struct page *page, bool is_write)
156156
{
157157
struct pmem_device *pmem = bdev->bd_queue->queuedata;
158158
int rc;
159159

160-
rc = pmem_do_bvec(pmem, page, PAGE_SIZE, 0, op, sector);
160+
rc = pmem_do_bvec(pmem, page, PAGE_SIZE, 0, is_write, sector);
161161

162162
/*
163163
* The ->rw_page interface is subtle and tricky. The core
@@ -166,7 +166,7 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector,
166166
* caused by double completion.
167167
*/
168168
if (rc == 0)
169-
page_endio(page, op, 0);
169+
page_endio(page, is_write, 0);
170170

171171
return rc;
172172
}

fs/block_dev.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ int bdev_read_page(struct block_device *bdev, sector_t sector,
416416
result = blk_queue_enter(bdev->bd_queue, false);
417417
if (result)
418418
return result;
419-
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page,
420-
REQ_OP_READ);
419+
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, false);
421420
blk_queue_exit(bdev->bd_queue);
422421
return result;
423422
}
@@ -455,8 +454,7 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
455454
return result;
456455

457456
set_page_writeback(page);
458-
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page,
459-
REQ_OP_WRITE);
457+
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, true);
460458
if (result)
461459
end_page_writeback(page);
462460
else

fs/mpage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void mpage_end_io(struct bio *bio)
5050

5151
bio_for_each_segment_all(bv, bio, i) {
5252
struct page *page = bv->bv_page;
53-
page_endio(page, bio_op(bio), bio->bi_error);
53+
page_endio(page, op_is_write(bio_op(bio)), bio->bi_error);
5454
}
5555

5656
bio_put(bio);

include/linux/blk_types.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ struct cgroup_subsys_state;
1818
typedef void (bio_end_io_t) (struct bio *);
1919
typedef void (bio_destructor_t) (struct bio *);
2020

21-
enum req_op {
22-
REQ_OP_READ,
23-
REQ_OP_WRITE,
24-
REQ_OP_DISCARD, /* request to discard sectors */
25-
REQ_OP_SECURE_ERASE, /* request to securely erase sectors */
26-
REQ_OP_WRITE_SAME, /* write same block many times */
27-
REQ_OP_FLUSH, /* request for cache flush */
28-
};
29-
30-
#define REQ_OP_BITS 3
31-
3221
#ifdef CONFIG_BLOCK
3322
/*
3423
* main unit of I/O for the block layer and lower layers (ie drivers and
@@ -239,6 +228,17 @@ enum rq_flag_bits {
239228
#define REQ_HASHED (1ULL << __REQ_HASHED)
240229
#define REQ_MQ_INFLIGHT (1ULL << __REQ_MQ_INFLIGHT)
241230

231+
enum req_op {
232+
REQ_OP_READ,
233+
REQ_OP_WRITE,
234+
REQ_OP_DISCARD, /* request to discard sectors */
235+
REQ_OP_SECURE_ERASE, /* request to securely erase sectors */
236+
REQ_OP_WRITE_SAME, /* write same block many times */
237+
REQ_OP_FLUSH, /* request for cache flush */
238+
};
239+
240+
#define REQ_OP_BITS 3
241+
242242
typedef unsigned int blk_qc_t;
243243
#define BLK_QC_T_NONE -1U
244244
#define BLK_QC_T_SHIFT 16

include/linux/blkdev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,7 +1672,7 @@ struct blk_dax_ctl {
16721672
struct block_device_operations {
16731673
int (*open) (struct block_device *, fmode_t);
16741674
void (*release) (struct gendisk *, fmode_t);
1675-
int (*rw_page)(struct block_device *, sector_t, struct page *, int op);
1675+
int (*rw_page)(struct block_device *, sector_t, struct page *, bool);
16761676
int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
16771677
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
16781678
long (*direct_access)(struct block_device *, sector_t, void **, pfn_t *,

include/linux/fs.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2480,13 +2480,12 @@ extern void init_special_inode(struct inode *, umode_t, dev_t);
24802480
extern void make_bad_inode(struct inode *);
24812481
extern bool is_bad_inode(struct inode *);
24822482

2483+
#ifdef CONFIG_BLOCK
24832484
static inline bool op_is_write(unsigned int op)
24842485
{
24852486
return op == REQ_OP_READ ? false : true;
24862487
}
24872488

2488-
#ifdef CONFIG_BLOCK
2489-
24902489
/*
24912490
* return data direction, READ or WRITE
24922491
*/

include/linux/pagemap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ static inline void wait_on_page_writeback(struct page *page)
510510
extern void end_page_writeback(struct page *page);
511511
void wait_for_stable_page(struct page *page);
512512

513-
void page_endio(struct page *page, int op, int err);
513+
void page_endio(struct page *page, bool is_write, int err);
514514

515515
/*
516516
* Add an arbitrary waiter to a page's wait queue

mm/filemap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ EXPORT_SYMBOL(end_page_writeback);
887887
* After completing I/O on a page, call this routine to update the page
888888
* flags appropriately
889889
*/
890-
void page_endio(struct page *page, int op, int err)
890+
void page_endio(struct page *page, bool is_write, int err)
891891
{
892-
if (!op_is_write(op)) {
892+
if (!is_write) {
893893
if (!err) {
894894
SetPageUptodate(page);
895895
} else {

0 commit comments

Comments
 (0)