Skip to content

Commit

Permalink
mm/block: convert rw_page users to bio op use
Browse files Browse the repository at this point in the history
The rw_page users were not converted to use bio/req ops. As a result
bdev_write_page is not passing down REQ_OP_WRITE and the IOs will
be sent down as reads.

Signed-off-by: Mike Christie <[email protected]>
Fixes: 4e1b2d5 ("block, fs, drivers: remove REQ_OP compat defs and related code")

Modified by me to:

1) Drop op_flags passing into ->rw_page(), as we don't use it.
2) Make op_is_write() and friends safe to use for !CONFIG_BLOCK

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Mike Christie authored and axboe committed Aug 4, 2016
1 parent c1c87c2 commit abf5454
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 59 deletions.
17 changes: 7 additions & 10 deletions drivers/block/brd.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,20 +300,20 @@ static void copy_from_brd(void *dst, struct brd_device *brd,
* Process a single bvec of a bio.
*/
static int brd_do_bvec(struct brd_device *brd, struct page *page,
unsigned int len, unsigned int off, int rw,
unsigned int len, unsigned int off, int op,
sector_t sector)
{
void *mem;
int err = 0;

if (rw != READ) {
if (op_is_write(op)) {
err = copy_to_brd_setup(brd, sector, len);
if (err)
goto out;
}

mem = kmap_atomic(page);
if (rw == READ) {
if (!op_is_write(op)) {
copy_from_brd(mem + off, brd, sector, len);
flush_dcache_page(page);
} else {
Expand All @@ -330,7 +330,6 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
{
struct block_device *bdev = bio->bi_bdev;
struct brd_device *brd = bdev->bd_disk->private_data;
int rw;
struct bio_vec bvec;
sector_t sector;
struct bvec_iter iter;
Expand All @@ -347,14 +346,12 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
goto out;
}

rw = bio_data_dir(bio);

bio_for_each_segment(bvec, bio, iter) {
unsigned int len = bvec.bv_len;
int err;

err = brd_do_bvec(brd, bvec.bv_page, len,
bvec.bv_offset, rw, sector);
bvec.bv_offset, bio_op(bio), sector);
if (err)
goto io_error;
sector += len >> SECTOR_SHIFT;
Expand All @@ -369,11 +366,11 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
}

static int brd_rw_page(struct block_device *bdev, sector_t sector,
struct page *page, int rw)
struct page *page, int op)
{
struct brd_device *brd = bdev->bd_disk->private_data;
int err = brd_do_bvec(brd, page, PAGE_SIZE, 0, rw, sector);
page_endio(page, rw & WRITE, err);
int err = brd_do_bvec(brd, page, PAGE_SIZE, 0, op, sector);
page_endio(page, op, err);
return err;
}

Expand Down
28 changes: 15 additions & 13 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -843,26 +843,26 @@ static void zram_bio_discard(struct zram *zram, u32 index,
}

static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,
int offset, int rw)
int offset, int op)
{
unsigned long start_time = jiffies;
int ret;

generic_start_io_acct(rw, bvec->bv_len >> SECTOR_SHIFT,
generic_start_io_acct(op, bvec->bv_len >> SECTOR_SHIFT,
&zram->disk->part0);

if (rw == READ) {
if (!op_is_write(op)) {
atomic64_inc(&zram->stats.num_reads);
ret = zram_bvec_read(zram, bvec, index, offset);
} else {
atomic64_inc(&zram->stats.num_writes);
ret = zram_bvec_write(zram, bvec, index, offset);
}

generic_end_io_acct(rw, &zram->disk->part0, start_time);
generic_end_io_acct(op, &zram->disk->part0, start_time);

if (unlikely(ret)) {
if (rw == READ)
if (!op_is_write(op))
atomic64_inc(&zram->stats.failed_reads);
else
atomic64_inc(&zram->stats.failed_writes);
Expand All @@ -873,7 +873,7 @@ static int zram_bvec_rw(struct zram *zram, struct bio_vec *bvec, u32 index,

static void __zram_make_request(struct zram *zram, struct bio *bio)
{
int offset, rw;
int offset;
u32 index;
struct bio_vec bvec;
struct bvec_iter iter;
Expand All @@ -888,7 +888,6 @@ static void __zram_make_request(struct zram *zram, struct bio *bio)
return;
}

rw = bio_data_dir(bio);
bio_for_each_segment(bvec, bio, iter) {
int max_transfer_size = PAGE_SIZE - offset;

Expand All @@ -903,15 +902,18 @@ static void __zram_make_request(struct zram *zram, struct bio *bio)
bv.bv_len = max_transfer_size;
bv.bv_offset = bvec.bv_offset;

if (zram_bvec_rw(zram, &bv, index, offset, rw) < 0)
if (zram_bvec_rw(zram, &bv, index, offset,
bio_op(bio)) < 0)
goto out;

bv.bv_len = bvec.bv_len - max_transfer_size;
bv.bv_offset += max_transfer_size;
if (zram_bvec_rw(zram, &bv, index + 1, 0, rw) < 0)
if (zram_bvec_rw(zram, &bv, index + 1, 0,
bio_op(bio)) < 0)
goto out;
} else
if (zram_bvec_rw(zram, &bvec, index, offset, rw) < 0)
if (zram_bvec_rw(zram, &bvec, index, offset,
bio_op(bio)) < 0)
goto out;

update_position(&index, &offset, &bvec);
Expand Down Expand Up @@ -968,7 +970,7 @@ static void zram_slot_free_notify(struct block_device *bdev,
}

static int zram_rw_page(struct block_device *bdev, sector_t sector,
struct page *page, int rw)
struct page *page, int op)
{
int offset, err = -EIO;
u32 index;
Expand All @@ -992,7 +994,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
bv.bv_len = PAGE_SIZE;
bv.bv_offset = 0;

err = zram_bvec_rw(zram, &bv, index, offset, rw);
err = zram_bvec_rw(zram, &bv, index, offset, op);
put_zram:
zram_meta_put(zram);
out:
Expand All @@ -1005,7 +1007,7 @@ static int zram_rw_page(struct block_device *bdev, sector_t sector,
* (e.g., SetPageError, set_page_dirty and extra works).
*/
if (err == 0)
page_endio(page, rw, 0);
page_endio(page, op, 0);
return err;
}

Expand Down
18 changes: 9 additions & 9 deletions drivers/nvdimm/btt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,11 +1133,11 @@ static int btt_write_pg(struct btt *btt, struct bio_integrity_payload *bip,

static int btt_do_bvec(struct btt *btt, struct bio_integrity_payload *bip,
struct page *page, unsigned int len, unsigned int off,
int rw, sector_t sector)
int op, sector_t sector)
{
int ret;

if (rw == READ) {
if (!op_is_write(op)) {
ret = btt_read_pg(btt, bip, page, off, sector, len);
flush_dcache_page(page);
} else {
Expand All @@ -1155,7 +1155,7 @@ static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
struct bvec_iter iter;
unsigned long start;
struct bio_vec bvec;
int err = 0, rw;
int err = 0;
bool do_acct;

/*
Expand All @@ -1170,7 +1170,6 @@ static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
}

do_acct = nd_iostat_start(bio, &start);
rw = bio_data_dir(bio);
bio_for_each_segment(bvec, bio, iter) {
unsigned int len = bvec.bv_len;

Expand All @@ -1181,11 +1180,12 @@ static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
BUG_ON(len % btt->sector_size);

err = btt_do_bvec(btt, bip, bvec.bv_page, len, bvec.bv_offset,
rw, iter.bi_sector);
bio_op(bio), iter.bi_sector);
if (err) {
dev_info(&btt->nd_btt->dev,
"io error in %s sector %lld, len %d,\n",
(rw == READ) ? "READ" : "WRITE",
(op_is_write(bio_op(bio))) ? "WRITE" :
"READ",
(unsigned long long) iter.bi_sector, len);
bio->bi_error = err;
break;
Expand All @@ -1200,12 +1200,12 @@ static blk_qc_t btt_make_request(struct request_queue *q, struct bio *bio)
}

static int btt_rw_page(struct block_device *bdev, sector_t sector,
struct page *page, int rw)
struct page *page, int op)
{
struct btt *btt = bdev->bd_disk->private_data;

btt_do_bvec(btt, NULL, page, PAGE_SIZE, 0, rw, sector);
page_endio(page, rw & WRITE, 0);
btt_do_bvec(btt, NULL, page, PAGE_SIZE, 0, op, sector);
page_endio(page, op, 0);
return 0;
}

Expand Down
12 changes: 6 additions & 6 deletions drivers/nvdimm/pmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static void pmem_clear_poison(struct pmem_device *pmem, phys_addr_t offset,
}

static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
unsigned int len, unsigned int off, int rw,
unsigned int len, unsigned int off, int op,
sector_t sector)
{
int rc = 0;
Expand All @@ -79,7 +79,7 @@ static int pmem_do_bvec(struct pmem_device *pmem, struct page *page,
if (unlikely(is_bad_pmem(&pmem->bb, sector, len)))
bad_pmem = true;

if (rw == READ) {
if (!op_is_write(op)) {
if (unlikely(bad_pmem))
rc = -EIO;
else {
Expand Down Expand Up @@ -134,7 +134,7 @@ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
do_acct = nd_iostat_start(bio, &start);
bio_for_each_segment(bvec, bio, iter) {
rc = pmem_do_bvec(pmem, bvec.bv_page, bvec.bv_len,
bvec.bv_offset, bio_data_dir(bio),
bvec.bv_offset, bio_op(bio),
iter.bi_sector);
if (rc) {
bio->bi_error = rc;
Expand All @@ -152,12 +152,12 @@ static blk_qc_t pmem_make_request(struct request_queue *q, struct bio *bio)
}

static int pmem_rw_page(struct block_device *bdev, sector_t sector,
struct page *page, int rw)
struct page *page, int op)
{
struct pmem_device *pmem = bdev->bd_queue->queuedata;
int rc;

rc = pmem_do_bvec(pmem, page, PAGE_SIZE, 0, rw, sector);
rc = pmem_do_bvec(pmem, page, PAGE_SIZE, 0, op, sector);

/*
* The ->rw_page interface is subtle and tricky. The core
Expand All @@ -166,7 +166,7 @@ static int pmem_rw_page(struct block_device *bdev, sector_t sector,
* caused by double completion.
*/
if (rc == 0)
page_endio(page, rw & WRITE, 0);
page_endio(page, op, 0);

return rc;
}
Expand Down
7 changes: 4 additions & 3 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ int bdev_read_page(struct block_device *bdev, sector_t sector,
result = blk_queue_enter(bdev->bd_queue, false);
if (result)
return result;
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, READ);
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page,
REQ_OP_READ);
blk_queue_exit(bdev->bd_queue);
return result;
}
Expand Down Expand Up @@ -445,7 +446,6 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
struct page *page, struct writeback_control *wbc)
{
int result;
int rw = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : WRITE;
const struct block_device_operations *ops = bdev->bd_disk->fops;

if (!ops->rw_page || bdev_get_integrity(bdev))
Expand All @@ -455,7 +455,8 @@ int bdev_write_page(struct block_device *bdev, sector_t sector,
return result;

set_page_writeback(page);
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page, rw);
result = ops->rw_page(bdev, sector + get_start_sect(bdev), page,
REQ_OP_WRITE);
if (result)
end_page_writeback(page);
else
Expand Down
2 changes: 1 addition & 1 deletion fs/mpage.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static void mpage_end_io(struct bio *bio)

bio_for_each_segment_all(bv, bio, i) {
struct page *page = bv->bv_page;
page_endio(page, bio_data_dir(bio), bio->bi_error);
page_endio(page, bio_op(bio), bio->bi_error);
}

bio_put(bio);
Expand Down
22 changes: 11 additions & 11 deletions include/linux/blk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ struct cgroup_subsys_state;
typedef void (bio_end_io_t) (struct bio *);
typedef void (bio_destructor_t) (struct bio *);

enum req_op {
REQ_OP_READ,
REQ_OP_WRITE,
REQ_OP_DISCARD, /* request to discard sectors */
REQ_OP_SECURE_ERASE, /* request to securely erase sectors */
REQ_OP_WRITE_SAME, /* write same block many times */
REQ_OP_FLUSH, /* request for cache flush */
};

#define REQ_OP_BITS 3

#ifdef CONFIG_BLOCK
/*
* main unit of I/O for the block layer and lower layers (ie drivers and
Expand Down Expand Up @@ -228,17 +239,6 @@ enum rq_flag_bits {
#define REQ_HASHED (1ULL << __REQ_HASHED)
#define REQ_MQ_INFLIGHT (1ULL << __REQ_MQ_INFLIGHT)

enum req_op {
REQ_OP_READ,
REQ_OP_WRITE,
REQ_OP_DISCARD, /* request to discard sectors */
REQ_OP_SECURE_ERASE, /* request to securely erase sectors */
REQ_OP_WRITE_SAME, /* write same block many times */
REQ_OP_FLUSH, /* request for cache flush */
};

#define REQ_OP_BITS 3

typedef unsigned int blk_qc_t;
#define BLK_QC_T_NONE -1U
#define BLK_QC_T_SHIFT 16
Expand Down
2 changes: 1 addition & 1 deletion include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,7 @@ struct blk_dax_ctl {
struct block_device_operations {
int (*open) (struct block_device *, fmode_t);
void (*release) (struct gendisk *, fmode_t);
int (*rw_page)(struct block_device *, sector_t, struct page *, int rw);
int (*rw_page)(struct block_device *, sector_t, struct page *, int op);
int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long);
long (*direct_access)(struct block_device *, sector_t, void **, pfn_t *,
Expand Down
3 changes: 2 additions & 1 deletion include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2480,12 +2480,13 @@ extern void init_special_inode(struct inode *, umode_t, dev_t);
extern void make_bad_inode(struct inode *);
extern bool is_bad_inode(struct inode *);

#ifdef CONFIG_BLOCK
static inline bool op_is_write(unsigned int op)
{
return op == REQ_OP_READ ? false : true;
}

#ifdef CONFIG_BLOCK

/*
* return data direction, READ or WRITE
*/
Expand Down
2 changes: 1 addition & 1 deletion include/linux/pagemap.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ static inline void wait_on_page_writeback(struct page *page)
extern void end_page_writeback(struct page *page);
void wait_for_stable_page(struct page *page);

void page_endio(struct page *page, int rw, int err);
void page_endio(struct page *page, int op, int err);

/*
* Add an arbitrary waiter to a page's wait queue
Expand Down
Loading

0 comments on commit abf5454

Please sign in to comment.