Skip to content

Commit 7024628

Browse files
Christoph Hellwigaxboe
authored andcommitted
block: get rid of bio_rw and READA
These two are confusing leftover of the old world order, combining values of the REQ_OP_ and REQ_ namespaces. For callers that don't special case we mostly just replace bi_rw with bio_data_dir or op_is_write, except for the few cases where a switch over the REQ_OP_ values makes more sense. Any check for READA is replaced with an explicit check for REQ_RAHEAD. Also remove the READA alias for REQ_RAHEAD. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Reviewed-by: Mike Christie <mchristi@redhat.com> Signed-off-by: Jens Axboe <axboe@fb.com>
1 parent 3f40bf2 commit 7024628

26 files changed

Lines changed: 95 additions & 96 deletions

File tree

‎drivers/block/brd.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,9 +347,7 @@ static blk_qc_t brd_make_request(struct request_queue *q, struct bio *bio)
347347
goto out;
348348
}
349349

350-
rw = bio_rw(bio);
351-
if (rw == READA)
352-
rw = READ;
350+
rw = bio_data_dir(bio);
353351

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

‎drivers/block/drbd/drbd_req.c‎

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m)
219219
{
220220
const unsigned s = req->rq_state;
221221
struct drbd_device *device = req->device;
222-
int rw;
223222
int error, ok;
224223

225224
/* we must not complete the master bio, while it is
@@ -243,8 +242,6 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m)
243242
return;
244243
}
245244

246-
rw = bio_rw(req->master_bio);
247-
248245
/*
249246
* figure out whether to report success or failure.
250247
*
@@ -268,7 +265,7 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m)
268265
* epoch number. If they match, increase the current_tle_nr,
269266
* and reset the transfer log epoch write_cnt.
270267
*/
271-
if (rw == WRITE &&
268+
if (op_is_write(bio_op(req->master_bio)) &&
272269
req->epoch == atomic_read(&first_peer_device(device)->connection->current_tle_nr))
273270
start_new_tl_epoch(first_peer_device(device)->connection);
274271

@@ -285,11 +282,14 @@ void drbd_req_complete(struct drbd_request *req, struct bio_and_error *m)
285282
* because no path was available, in which case
286283
* it was not even added to the transfer_log.
287284
*
288-
* READA may fail, and will not be retried.
285+
* read-ahead may fail, and will not be retried.
289286
*
290287
* WRITE should have used all available paths already.
291288
*/
292-
if (!ok && rw == READ && !list_empty(&req->tl_requests))
289+
if (!ok &&
290+
bio_op(req->master_bio) == REQ_OP_READ &&
291+
!(req->master_bio->bi_rw & REQ_RAHEAD) &&
292+
!list_empty(&req->tl_requests))
293293
req->rq_state |= RQ_POSTPONED;
294294

295295
if (!(req->rq_state & RQ_POSTPONED)) {
@@ -645,7 +645,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
645645
__drbd_chk_io_error(device, DRBD_READ_ERROR);
646646
/* fall through. */
647647
case READ_AHEAD_COMPLETED_WITH_ERROR:
648-
/* it is legal to fail READA, no __drbd_chk_io_error in that case. */
648+
/* it is legal to fail read-ahead, no __drbd_chk_io_error in that case. */
649649
mod_rq_state(req, m, RQ_LOCAL_PENDING, RQ_LOCAL_COMPLETED);
650650
break;
651651

@@ -657,7 +657,7 @@ int __req_mod(struct drbd_request *req, enum drbd_req_event what,
657657
break;
658658

659659
case QUEUE_FOR_NET_READ:
660-
/* READ or READA, and
660+
/* READ, and
661661
* no local disk,
662662
* or target area marked as invalid,
663663
* or just got an io-error. */
@@ -1172,7 +1172,14 @@ drbd_submit_req_private_bio(struct drbd_request *req)
11721172
{
11731173
struct drbd_device *device = req->device;
11741174
struct bio *bio = req->private_bio;
1175-
const int rw = bio_rw(bio);
1175+
unsigned int type;
1176+
1177+
if (bio_op(bio) != REQ_OP_READ)
1178+
type = DRBD_FAULT_DT_WR;
1179+
else if (bio->bi_rw & REQ_RAHEAD)
1180+
type = DRBD_FAULT_DT_RA;
1181+
else
1182+
type = DRBD_FAULT_DT_RD;
11761183

11771184
bio->bi_bdev = device->ldev->backing_bdev;
11781185

@@ -1182,10 +1189,7 @@ drbd_submit_req_private_bio(struct drbd_request *req)
11821189
* stable storage, and this is a WRITE, we may not even submit
11831190
* this bio. */
11841191
if (get_ldev(device)) {
1185-
if (drbd_insert_fault(device,
1186-
rw == WRITE ? DRBD_FAULT_DT_WR
1187-
: rw == READ ? DRBD_FAULT_DT_RD
1188-
: DRBD_FAULT_DT_RA))
1192+
if (drbd_insert_fault(device, type))
11891193
bio_io_error(bio);
11901194
else if (bio_op(bio) == REQ_OP_DISCARD)
11911195
drbd_process_discard_req(req);
@@ -1278,7 +1282,7 @@ static bool may_do_writes(struct drbd_device *device)
12781282
static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request *req)
12791283
{
12801284
struct drbd_resource *resource = device->resource;
1281-
const int rw = bio_rw(req->master_bio);
1285+
const int rw = bio_data_dir(req->master_bio);
12821286
struct bio_and_error m = { NULL, };
12831287
bool no_remote = false;
12841288
bool submit_private_bio = false;
@@ -1308,7 +1312,7 @@ static void drbd_send_and_submit(struct drbd_device *device, struct drbd_request
13081312
goto out;
13091313
}
13101314

1311-
/* We fail READ/READA early, if we can not serve it.
1315+
/* We fail READ early, if we can not serve it.
13121316
* We must do this before req is registered on any lists.
13131317
* Otherwise, drbd_req_complete() will queue failed READ for retry. */
13141318
if (rw != WRITE) {

‎drivers/block/drbd/drbd_worker.c‎

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,18 +248,26 @@ void drbd_request_endio(struct bio *bio)
248248

249249
/* to avoid recursion in __req_mod */
250250
if (unlikely(bio->bi_error)) {
251-
if (bio_op(bio) == REQ_OP_DISCARD)
252-
what = (bio->bi_error == -EOPNOTSUPP)
253-
? DISCARD_COMPLETED_NOTSUPP
254-
: DISCARD_COMPLETED_WITH_ERROR;
255-
else
256-
what = (bio_data_dir(bio) == WRITE)
257-
? WRITE_COMPLETED_WITH_ERROR
258-
: (bio_rw(bio) == READ)
259-
? READ_COMPLETED_WITH_ERROR
260-
: READ_AHEAD_COMPLETED_WITH_ERROR;
261-
} else
251+
switch (bio_op(bio)) {
252+
case REQ_OP_DISCARD:
253+
if (bio->bi_error == -EOPNOTSUPP)
254+
what = DISCARD_COMPLETED_NOTSUPP;
255+
else
256+
what = DISCARD_COMPLETED_WITH_ERROR;
257+
break;
258+
case REQ_OP_READ:
259+
if (bio->bi_rw & REQ_RAHEAD)
260+
what = READ_AHEAD_COMPLETED_WITH_ERROR;
261+
else
262+
what = READ_COMPLETED_WITH_ERROR;
263+
break;
264+
default:
265+
what = WRITE_COMPLETED_WITH_ERROR;
266+
break;
267+
}
268+
} else {
262269
what = COMPLETED_OK;
270+
}
263271

264272
bio_put(req->private_bio);
265273
req->private_bio = ERR_PTR(bio->bi_error);

‎drivers/block/null_blk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static int null_lnvm_submit_io(struct nvm_dev *dev, struct nvm_rq *rqd)
448448
struct request *rq;
449449
struct bio *bio = rqd->bio;
450450

451-
rq = blk_mq_alloc_request(q, bio_rw(bio), 0);
451+
rq = blk_mq_alloc_request(q, bio_data_dir(bio), 0);
452452
if (IS_ERR(rq))
453453
return -ENOMEM;
454454

‎drivers/block/umem.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,6 @@ static int add_bio(struct cardinfo *card)
344344
int offset;
345345
struct bio *bio;
346346
struct bio_vec vec;
347-
int rw;
348347

349348
bio = card->currentbio;
350349
if (!bio && card->bio) {
@@ -359,7 +358,6 @@ static int add_bio(struct cardinfo *card)
359358
if (!bio)
360359
return 0;
361360

362-
rw = bio_rw(bio);
363361
if (card->mm_pages[card->Ready].cnt >= DESC_PER_PAGE)
364362
return 0;
365363

@@ -369,7 +367,7 @@ static int add_bio(struct cardinfo *card)
369367
vec.bv_page,
370368
vec.bv_offset,
371369
vec.bv_len,
372-
(rw == READ) ?
370+
bio_op(bio) == REQ_OP_READ ?
373371
PCI_DMA_FROMDEVICE : PCI_DMA_TODEVICE);
374372

375373
p = &card->mm_pages[card->Ready];
@@ -398,7 +396,7 @@ static int add_bio(struct cardinfo *card)
398396
DMASCR_CHAIN_EN |
399397
DMASCR_SEM_EN |
400398
pci_cmds);
401-
if (rw == WRITE)
399+
if (bio_op(bio) == REQ_OP_WRITE)
402400
desc->control_bits |= cpu_to_le32(DMASCR_TRANSFER_READ);
403401
desc->sem_control_bits = desc->control_bits;
404402

‎drivers/lightnvm/rrpc.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,14 +853,14 @@ static int rrpc_setup_rq(struct rrpc *rrpc, struct bio *bio,
853853
return NVM_IO_ERR;
854854
}
855855

856-
if (bio_rw(bio) == WRITE)
856+
if (bio_op(bio) == REQ_OP_WRITE)
857857
return rrpc_write_ppalist_rq(rrpc, bio, rqd, flags,
858858
npages);
859859

860860
return rrpc_read_ppalist_rq(rrpc, bio, rqd, flags, npages);
861861
}
862862

863-
if (bio_rw(bio) == WRITE)
863+
if (bio_op(bio) == REQ_OP_WRITE)
864864
return rrpc_write_rq(rrpc, bio, rqd, flags);
865865

866866
return rrpc_read_rq(rrpc, bio, rqd, flags);

‎drivers/md/dm-raid1.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ static void read_callback(unsigned long error, void *context)
528528
DMWARN_LIMIT("Read failure on mirror device %s. "
529529
"Trying alternative device.",
530530
m->dev->name);
531-
queue_bio(m->ms, bio, bio_rw(bio));
531+
queue_bio(m->ms, bio, bio_data_dir(bio));
532532
return;
533533
}
534534

@@ -1193,7 +1193,7 @@ static void mirror_dtr(struct dm_target *ti)
11931193
*/
11941194
static int mirror_map(struct dm_target *ti, struct bio *bio)
11951195
{
1196-
int r, rw = bio_rw(bio);
1196+
int r, rw = bio_data_dir(bio);
11971197
struct mirror *m;
11981198
struct mirror_set *ms = ti->private;
11991199
struct dm_dirty_log *log = dm_rh_dirty_log(ms->rh);
@@ -1217,7 +1217,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
12171217
* If region is not in-sync queue the bio.
12181218
*/
12191219
if (!r || (r == -EWOULDBLOCK)) {
1220-
if (rw == READA)
1220+
if (bio->bi_rw & REQ_RAHEAD)
12211221
return -EWOULDBLOCK;
12221222

12231223
queue_bio(ms, bio, rw);
@@ -1242,7 +1242,7 @@ static int mirror_map(struct dm_target *ti, struct bio *bio)
12421242

12431243
static int mirror_end_io(struct dm_target *ti, struct bio *bio, int error)
12441244
{
1245-
int rw = bio_rw(bio);
1245+
int rw = bio_data_dir(bio);
12461246
struct mirror_set *ms = (struct mirror_set *) ti->private;
12471247
struct mirror *m = NULL;
12481248
struct dm_bio_details *bd = NULL;

‎drivers/md/dm-snap.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1696,7 +1696,8 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
16961696
* to copy an exception */
16971697
down_write(&s->lock);
16981698

1699-
if (!s->valid || (unlikely(s->snapshot_overflowed) && bio_rw(bio) == WRITE)) {
1699+
if (!s->valid || (unlikely(s->snapshot_overflowed) &&
1700+
bio_data_dir(bio) == WRITE)) {
17001701
r = -EIO;
17011702
goto out_unlock;
17021703
}
@@ -1713,7 +1714,7 @@ static int snapshot_map(struct dm_target *ti, struct bio *bio)
17131714
* flags so we should only get this if we are
17141715
* writeable.
17151716
*/
1716-
if (bio_rw(bio) == WRITE) {
1717+
if (bio_data_dir(bio) == WRITE) {
17171718
pe = __lookup_pending_exception(s, chunk);
17181719
if (!pe) {
17191720
up_write(&s->lock);
@@ -1819,7 +1820,7 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio)
18191820
e = dm_lookup_exception(&s->complete, chunk);
18201821
if (e) {
18211822
/* Queue writes overlapping with chunks being merged */
1822-
if (bio_rw(bio) == WRITE &&
1823+
if (bio_data_dir(bio) == WRITE &&
18231824
chunk >= s->first_merging_chunk &&
18241825
chunk < (s->first_merging_chunk +
18251826
s->num_merging_chunks)) {
@@ -1831,15 +1832,15 @@ static int snapshot_merge_map(struct dm_target *ti, struct bio *bio)
18311832

18321833
remap_exception(s, e, bio, chunk);
18331834

1834-
if (bio_rw(bio) == WRITE)
1835+
if (bio_data_dir(bio) == WRITE)
18351836
track_chunk(s, bio, chunk);
18361837
goto out_unlock;
18371838
}
18381839

18391840
redirect_to_origin:
18401841
bio->bi_bdev = s->origin->bdev;
18411842

1842-
if (bio_rw(bio) == WRITE) {
1843+
if (bio_data_dir(bio) == WRITE) {
18431844
up_write(&s->lock);
18441845
return do_origin(s->origin, bio);
18451846
}
@@ -2288,7 +2289,7 @@ static int origin_map(struct dm_target *ti, struct bio *bio)
22882289
if (unlikely(bio->bi_rw & REQ_PREFLUSH))
22892290
return DM_MAPIO_REMAPPED;
22902291

2291-
if (bio_rw(bio) != WRITE)
2292+
if (bio_data_dir(bio) != WRITE)
22922293
return DM_MAPIO_REMAPPED;
22932294

22942295
available_sectors = o->split_boundary -

‎drivers/md/dm-zero.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
3535
*/
3636
static int zero_map(struct dm_target *ti, struct bio *bio)
3737
{
38-
switch(bio_rw(bio)) {
39-
case READ:
38+
switch (bio_op(bio)) {
39+
case REQ_OP_READ:
40+
if (bio->bi_rw & REQ_RAHEAD) {
41+
/* readahead of null bytes only wastes buffer cache */
42+
return -EIO;
43+
}
4044
zero_fill_bio(bio);
4145
break;
42-
case READA:
43-
/* readahead of null bytes only wastes buffer cache */
44-
return -EIO;
45-
case WRITE:
46+
case REQ_OP_WRITE:
4647
/* writes get silently dropped */
4748
break;
49+
default:
50+
return -EIO;
4851
}
4952

5053
bio_endio(bio);

‎drivers/md/dm.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ static blk_qc_t dm_make_request(struct request_queue *q, struct bio *bio)
18331833
if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))) {
18341834
dm_put_live_table(md, srcu_idx);
18351835

1836-
if (bio_rw(bio) != READA)
1836+
if (!(bio->bi_rw & REQ_RAHEAD))
18371837
queue_io(md, bio);
18381838
else
18391839
bio_io_error(bio);

0 commit comments

Comments
 (0)