Skip to content

Commit 7b6d91d

Browse files
Christoph HellwigJens Axboe
authored andcommitted
block: unify flags for struct bio and struct request
Remove the current bio flags and reuse the request flags for the bio, too. This allows to more easily trace the type of I/O from the filesystem down to the block driver. There were two flags in the bio that were missing in the requests: BIO_RW_UNPLUG and BIO_RW_AHEAD. Also I've renamed two request flags that had a superflous RW in them. Note that the flags are in bio.h despite having the REQ_ name - as blkdev.h includes bio.h that is the only way to go for now. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 33659eb commit 7b6d91d

47 files changed

Lines changed: 242 additions & 289 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎block/blk-barrier.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static inline bool start_ordered(struct request_queue *q, struct request **rqp)
203203
/* initialize proxy request and queue it */
204204
blk_rq_init(q, rq);
205205
if (bio_data_dir(q->orig_bar_rq->bio) == WRITE)
206-
rq->cmd_flags |= REQ_RW;
206+
rq->cmd_flags |= REQ_WRITE;
207207
if (q->ordered & QUEUE_ORDERED_DO_FUA)
208208
rq->cmd_flags |= REQ_FUA;
209209
init_request_from_bio(rq, q->orig_bar_rq->bio);

‎block/blk-core.c‎

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,25 +1140,9 @@ void init_request_from_bio(struct request *req, struct bio *bio)
11401140
req->cpu = bio->bi_comp_cpu;
11411141
req->cmd_type = REQ_TYPE_FS;
11421142

1143-
/*
1144-
* Inherit FAILFAST from bio (for read-ahead, and explicit
1145-
* FAILFAST). FAILFAST flags are identical for req and bio.
1146-
*/
1147-
if (bio_rw_flagged(bio, BIO_RW_AHEAD))
1143+
req->cmd_flags |= bio->bi_rw & REQ_COMMON_MASK;
1144+
if (bio->bi_rw & REQ_RAHEAD)
11481145
req->cmd_flags |= REQ_FAILFAST_MASK;
1149-
else
1150-
req->cmd_flags |= bio->bi_rw & REQ_FAILFAST_MASK;
1151-
1152-
if (bio_rw_flagged(bio, BIO_RW_DISCARD))
1153-
req->cmd_flags |= REQ_DISCARD;
1154-
if (bio_rw_flagged(bio, BIO_RW_BARRIER))
1155-
req->cmd_flags |= REQ_HARDBARRIER;
1156-
if (bio_rw_flagged(bio, BIO_RW_SYNCIO))
1157-
req->cmd_flags |= REQ_RW_SYNC;
1158-
if (bio_rw_flagged(bio, BIO_RW_META))
1159-
req->cmd_flags |= REQ_RW_META;
1160-
if (bio_rw_flagged(bio, BIO_RW_NOIDLE))
1161-
req->cmd_flags |= REQ_NOIDLE;
11621146

11631147
req->errors = 0;
11641148
req->__sector = bio->bi_sector;
@@ -1181,12 +1165,12 @@ static int __make_request(struct request_queue *q, struct bio *bio)
11811165
int el_ret;
11821166
unsigned int bytes = bio->bi_size;
11831167
const unsigned short prio = bio_prio(bio);
1184-
const bool sync = bio_rw_flagged(bio, BIO_RW_SYNCIO);
1185-
const bool unplug = bio_rw_flagged(bio, BIO_RW_UNPLUG);
1168+
const bool sync = (bio->bi_rw & REQ_SYNC);
1169+
const bool unplug = (bio->bi_rw & REQ_UNPLUG);
11861170
const unsigned int ff = bio->bi_rw & REQ_FAILFAST_MASK;
11871171
int rw_flags;
11881172

1189-
if (bio_rw_flagged(bio, BIO_RW_BARRIER) &&
1173+
if ((bio->bi_rw & REQ_HARDBARRIER) &&
11901174
(q->next_ordered == QUEUE_ORDERED_NONE)) {
11911175
bio_endio(bio, -EOPNOTSUPP);
11921176
return 0;
@@ -1200,7 +1184,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
12001184

12011185
spin_lock_irq(q->queue_lock);
12021186

1203-
if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER)) || elv_queue_empty(q))
1187+
if (unlikely((bio->bi_rw & REQ_HARDBARRIER)) || elv_queue_empty(q))
12041188
goto get_rq;
12051189

12061190
el_ret = elv_merge(q, &req, bio);
@@ -1275,7 +1259,7 @@ static int __make_request(struct request_queue *q, struct bio *bio)
12751259
*/
12761260
rw_flags = bio_data_dir(bio);
12771261
if (sync)
1278-
rw_flags |= REQ_RW_SYNC;
1262+
rw_flags |= REQ_SYNC;
12791263

12801264
/*
12811265
* Grab a free request. This is might sleep but can not fail.
@@ -1464,7 +1448,7 @@ static inline void __generic_make_request(struct bio *bio)
14641448
goto end_io;
14651449
}
14661450

1467-
if (unlikely(!bio_rw_flagged(bio, BIO_RW_DISCARD) &&
1451+
if (unlikely(!(bio->bi_rw & REQ_DISCARD) &&
14681452
nr_sectors > queue_max_hw_sectors(q))) {
14691453
printk(KERN_ERR "bio too big device %s (%u > %u)\n",
14701454
bdevname(bio->bi_bdev, b),
@@ -1497,8 +1481,7 @@ static inline void __generic_make_request(struct bio *bio)
14971481
if (bio_check_eod(bio, nr_sectors))
14981482
goto end_io;
14991483

1500-
if (bio_rw_flagged(bio, BIO_RW_DISCARD) &&
1501-
!blk_queue_discard(q)) {
1484+
if ((bio->bi_rw & REQ_DISCARD) && !blk_queue_discard(q)) {
15021485
err = -EOPNOTSUPP;
15031486
goto end_io;
15041487
}
@@ -2365,7 +2348,7 @@ void blk_rq_bio_prep(struct request_queue *q, struct request *rq,
23652348
struct bio *bio)
23662349
{
23672350
/* Bit 0 (R/W) is identical in rq->cmd_flags and bio->bi_rw */
2368-
rq->cmd_flags |= bio->bi_rw & REQ_RW;
2351+
rq->cmd_flags |= bio->bi_rw & REQ_WRITE;
23692352

23702353
if (bio_has_data(bio)) {
23712354
rq->nr_phys_segments = bio_phys_segments(q, bio);

‎block/blk-map.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
307307
return PTR_ERR(bio);
308308

309309
if (rq_data_dir(rq) == WRITE)
310-
bio->bi_rw |= (1 << BIO_RW);
310+
bio->bi_rw |= (1 << REQ_WRITE);
311311

312312
if (do_copy)
313313
rq->cmd_flags |= REQ_COPY_USER;

‎block/blk-merge.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
180180
}
181181

182182
if (q->dma_drain_size && q->dma_drain_needed(rq)) {
183-
if (rq->cmd_flags & REQ_RW)
183+
if (rq->cmd_flags & REQ_WRITE)
184184
memset(q->dma_drain_buffer, 0, q->dma_drain_size);
185185

186186
sg->page_link &= ~0x02;

‎block/cfq-iosched.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ static inline struct cfq_data *cic_to_cfqd(struct cfq_io_context *cic)
458458
*/
459459
static inline bool cfq_bio_sync(struct bio *bio)
460460
{
461-
return bio_data_dir(bio) == READ || bio_rw_flagged(bio, BIO_RW_SYNCIO);
461+
return bio_data_dir(bio) == READ || (bio->bi_rw & REQ_SYNC);
462462
}
463463

464464
/*
@@ -646,10 +646,10 @@ cfq_choose_req(struct cfq_data *cfqd, struct request *rq1, struct request *rq2,
646646
return rq1;
647647
else if (rq_is_sync(rq2) && !rq_is_sync(rq1))
648648
return rq2;
649-
if ((rq1->cmd_flags & REQ_RW_META) && !(rq2->cmd_flags & REQ_RW_META))
649+
if ((rq1->cmd_flags & REQ_META) && !(rq2->cmd_flags & REQ_META))
650650
return rq1;
651-
else if ((rq2->cmd_flags & REQ_RW_META) &&
652-
!(rq1->cmd_flags & REQ_RW_META))
651+
else if ((rq2->cmd_flags & REQ_META) &&
652+
!(rq1->cmd_flags & REQ_META))
653653
return rq2;
654654

655655
s1 = blk_rq_pos(rq1);
@@ -1485,7 +1485,7 @@ static void cfq_remove_request(struct request *rq)
14851485
cfqq->cfqd->rq_queued--;
14861486
cfq_blkiocg_update_io_remove_stats(&(RQ_CFQG(rq))->blkg,
14871487
rq_data_dir(rq), rq_is_sync(rq));
1488-
if (rq->cmd_flags & REQ_RW_META) {
1488+
if (rq->cmd_flags & REQ_META) {
14891489
WARN_ON(!cfqq->meta_pending);
14901490
cfqq->meta_pending--;
14911491
}
@@ -3177,7 +3177,7 @@ cfq_should_preempt(struct cfq_data *cfqd, struct cfq_queue *new_cfqq,
31773177
* So both queues are sync. Let the new request get disk time if
31783178
* it's a metadata request and the current queue is doing regular IO.
31793179
*/
3180-
if ((rq->cmd_flags & REQ_RW_META) && !cfqq->meta_pending)
3180+
if ((rq->cmd_flags & REQ_META) && !cfqq->meta_pending)
31813181
return true;
31823182

31833183
/*
@@ -3231,7 +3231,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq,
32313231
struct cfq_io_context *cic = RQ_CIC(rq);
32323232

32333233
cfqd->rq_queued++;
3234-
if (rq->cmd_flags & REQ_RW_META)
3234+
if (rq->cmd_flags & REQ_META)
32353235
cfqq->meta_pending++;
32363236

32373237
cfq_update_io_thinktime(cfqd, cic);

‎block/elevator.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ int elv_rq_merge_ok(struct request *rq, struct bio *bio)
7979
/*
8080
* Don't merge file system requests and discard requests
8181
*/
82-
if (bio_rw_flagged(bio, BIO_RW_DISCARD) !=
83-
bio_rw_flagged(rq->bio, BIO_RW_DISCARD))
82+
if ((bio->bi_rw & REQ_DISCARD) != (rq->bio->bi_rw & REQ_DISCARD))
8483
return 0;
8584

8685
/*

‎drivers/ata/libata-scsi.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ static int atapi_drain_needed(struct request *rq)
11141114
if (likely(rq->cmd_type != REQ_TYPE_BLOCK_PC))
11151115
return 0;
11161116

1117-
if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_RW))
1117+
if (!blk_rq_bytes(rq) || (rq->cmd_flags & REQ_WRITE))
11181118
return 0;
11191119

11201120
return atapi_cmd_type(rq->cmd[0]) == ATAPI_MISC;

‎drivers/block/aoe/aoeblk.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
173173
BUG();
174174
bio_endio(bio, -ENXIO);
175175
return 0;
176-
} else if (bio_rw_flagged(bio, BIO_RW_BARRIER)) {
176+
} else if (bio->bi_rw & REQ_HARDBARRIER) {
177177
bio_endio(bio, -EOPNOTSUPP);
178178
return 0;
179179
} else if (bio->bi_io_vec == NULL) {

‎drivers/block/brd.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int brd_make_request(struct request_queue *q, struct bio *bio)
340340
get_capacity(bdev->bd_disk))
341341
goto out;
342342

343-
if (unlikely(bio_rw_flagged(bio, BIO_RW_DISCARD))) {
343+
if (unlikely(bio->bi_rw & REQ_DISCARD)) {
344344
err = 0;
345345
discard_from_brd(brd, sector, bio->bi_size);
346346
goto out;

‎drivers/block/drbd/drbd_actlog.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
7979
md_io.error = 0;
8080

8181
if ((rw & WRITE) && !test_bit(MD_NO_BARRIER, &mdev->flags))
82-
rw |= (1 << BIO_RW_BARRIER);
83-
rw |= ((1<<BIO_RW_UNPLUG) | (1<<BIO_RW_SYNCIO));
82+
rw |= REQ_HARDBARRIER;
83+
rw |= REQ_UNPLUG | REQ_SYNC;
8484

8585
retry:
8686
bio = bio_alloc(GFP_NOIO, 1);
@@ -103,11 +103,11 @@ static int _drbd_md_sync_page_io(struct drbd_conf *mdev,
103103
/* check for unsupported barrier op.
104104
* would rather check on EOPNOTSUPP, but that is not reliable.
105105
* don't try again for ANY return value != 0 */
106-
if (unlikely(bio_rw_flagged(bio, BIO_RW_BARRIER) && !ok)) {
106+
if (unlikely((bio->bi_rw & REQ_HARDBARRIER) && !ok)) {
107107
/* Try again with no barrier */
108108
dev_warn(DEV, "Barriers not supported on meta data device - disabling\n");
109109
set_bit(MD_NO_BARRIER, &mdev->flags);
110-
rw &= ~(1 << BIO_RW_BARRIER);
110+
rw &= ~REQ_HARDBARRIER;
111111
bio_put(bio);
112112
goto retry;
113113
}

0 commit comments

Comments
 (0)