Skip to content

Commit e2a60da

Browse files
martinkpetersenaxboe
authored andcommitted
block: Clean up special command handling logic
Remove special-casing of non-rw fs style requests (discard). The nomerge flags are consolidated in blk_types.h, and rq_mergeable() and bio_mergeable() have been modified to use them. bio_is_rw() is used in place of bio_has_data() a few places. This is done to to distinguish true reads and writes from other fs type requests that carry a payload (e.g. write same). Signed-off-by: Martin K. Petersen <[email protected]> Acked-by: Mike Snitzer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent d41570b commit e2a60da

File tree

7 files changed

+46
-49
lines changed

7 files changed

+46
-49
lines changed

block/blk-core.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,8 @@ generic_make_request_checks(struct bio *bio)
16571657
goto end_io;
16581658
}
16591659

1660-
if (unlikely(!(bio->bi_rw & REQ_DISCARD) &&
1661-
nr_sectors > queue_max_hw_sectors(q))) {
1660+
if (likely(bio_is_rw(bio) &&
1661+
nr_sectors > queue_max_hw_sectors(q))) {
16621662
printk(KERN_ERR "bio too big device %s (%u > %u)\n",
16631663
bdevname(bio->bi_bdev, b),
16641664
bio_sectors(bio),
@@ -1699,8 +1699,7 @@ generic_make_request_checks(struct bio *bio)
16991699

17001700
if ((bio->bi_rw & REQ_DISCARD) &&
17011701
(!blk_queue_discard(q) ||
1702-
((bio->bi_rw & REQ_SECURE) &&
1703-
!blk_queue_secdiscard(q)))) {
1702+
((bio->bi_rw & REQ_SECURE) && !blk_queue_secdiscard(q)))) {
17041703
err = -EOPNOTSUPP;
17051704
goto end_io;
17061705
}
@@ -1818,7 +1817,7 @@ void submit_bio(int rw, struct bio *bio)
18181817
* If it's a regular read/write or a barrier with data attached,
18191818
* go through the normal accounting stuff before submission.
18201819
*/
1821-
if (bio_has_data(bio) && !(rw & REQ_DISCARD)) {
1820+
if (bio_has_data(bio)) {
18221821
if (rw & WRITE) {
18231822
count_vm_events(PGPGOUT, count);
18241823
} else {
@@ -1864,7 +1863,7 @@ EXPORT_SYMBOL(submit_bio);
18641863
*/
18651864
int blk_rq_check_limits(struct request_queue *q, struct request *rq)
18661865
{
1867-
if (rq->cmd_flags & REQ_DISCARD)
1866+
if (!rq_mergeable(rq))
18681867
return 0;
18691868

18701869
if (blk_rq_sectors(rq) > queue_max_sectors(q) ||
@@ -2338,7 +2337,7 @@ bool blk_update_request(struct request *req, int error, unsigned int nr_bytes)
23382337
req->buffer = bio_data(req->bio);
23392338

23402339
/* update sector only for requests with clear definition of sector */
2341-
if (req->cmd_type == REQ_TYPE_FS || (req->cmd_flags & REQ_DISCARD))
2340+
if (req->cmd_type == REQ_TYPE_FS)
23422341
req->__sector += total_bytes >> 9;
23432342

23442343
/* mixed attributes always follow the first bio */

block/blk-merge.c

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -417,18 +417,6 @@ static int attempt_merge(struct request_queue *q, struct request *req,
417417
if (!rq_mergeable(req) || !rq_mergeable(next))
418418
return 0;
419419

420-
/*
421-
* Don't merge file system requests and discard requests
422-
*/
423-
if ((req->cmd_flags & REQ_DISCARD) != (next->cmd_flags & REQ_DISCARD))
424-
return 0;
425-
426-
/*
427-
* Don't merge discard requests and secure discard requests
428-
*/
429-
if ((req->cmd_flags & REQ_SECURE) != (next->cmd_flags & REQ_SECURE))
430-
return 0;
431-
432420
/*
433421
* not contiguous
434422
*/
@@ -521,15 +509,7 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
521509

522510
bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
523511
{
524-
if (!rq_mergeable(rq))
525-
return false;
526-
527-
/* don't merge file system requests and discard requests */
528-
if ((bio->bi_rw & REQ_DISCARD) != (rq->bio->bi_rw & REQ_DISCARD))
529-
return false;
530-
531-
/* don't merge discard requests and secure discard requests */
532-
if ((bio->bi_rw & REQ_SECURE) != (rq->bio->bi_rw & REQ_SECURE))
512+
if (!rq_mergeable(rq) || !bio_mergeable(bio))
533513
return false;
534514

535515
/* different data direction or already started, don't merge */

block/blk.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,13 @@ static inline int queue_congestion_off_threshold(struct request_queue *q)
171171
*
172172
* a) it's attached to a gendisk, and
173173
* b) the queue had IO stats enabled when this request was started, and
174-
* c) it's a file system request or a discard request
174+
* c) it's a file system request
175175
*/
176176
static inline int blk_do_io_stat(struct request *rq)
177177
{
178178
return rq->rq_disk &&
179179
(rq->cmd_flags & REQ_IO_STAT) &&
180-
(rq->cmd_type == REQ_TYPE_FS ||
181-
(rq->cmd_flags & REQ_DISCARD));
180+
(rq->cmd_type == REQ_TYPE_FS);
182181
}
183182

184183
/*

block/elevator.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
562562

563563
if (rq->cmd_flags & REQ_SOFTBARRIER) {
564564
/* barriers are scheduling boundary, update end_sector */
565-
if (rq->cmd_type == REQ_TYPE_FS ||
566-
(rq->cmd_flags & REQ_DISCARD)) {
565+
if (rq->cmd_type == REQ_TYPE_FS) {
567566
q->end_sector = rq_end_sector(rq);
568567
q->boundary_rq = rq;
569568
}
@@ -605,8 +604,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where)
605604
if (elv_attempt_insert_merge(q, rq))
606605
break;
607606
case ELEVATOR_INSERT_SORT:
608-
BUG_ON(rq->cmd_type != REQ_TYPE_FS &&
609-
!(rq->cmd_flags & REQ_DISCARD));
607+
BUG_ON(rq->cmd_type != REQ_TYPE_FS);
610608
rq->cmd_flags |= REQ_SORTED;
611609
q->nr_sorted++;
612610
if (rq_mergeable(rq)) {

include/linux/bio.h

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,28 @@ static inline char *__bio_kmap_irq(struct bio *bio, unsigned short idx,
386386
/*
387387
* Check whether this bio carries any data or not. A NULL bio is allowed.
388388
*/
389-
static inline int bio_has_data(struct bio *bio)
389+
static inline bool bio_has_data(struct bio *bio)
390390
{
391-
return bio && bio->bi_io_vec != NULL;
391+
if (bio && bio->bi_vcnt)
392+
return true;
393+
394+
return false;
395+
}
396+
397+
static inline bool bio_is_rw(struct bio *bio)
398+
{
399+
if (!bio_has_data(bio))
400+
return false;
401+
402+
return true;
403+
}
404+
405+
static inline bool bio_mergeable(struct bio *bio)
406+
{
407+
if (bio->bi_rw & REQ_NOMERGE_FLAGS)
408+
return false;
409+
410+
return true;
392411
}
393412

394413
/*

include/linux/blk_types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ enum rq_flag_bits {
194194
REQ_DISCARD | REQ_NOIDLE | REQ_FLUSH | REQ_FUA | REQ_SECURE)
195195
#define REQ_CLONE_MASK REQ_COMMON_MASK
196196

197+
/* This mask is used for both bio and request merge checking */
198+
#define REQ_NOMERGE_FLAGS \
199+
(REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA)
200+
197201
#define REQ_RAHEAD (1 << __REQ_RAHEAD)
198202
#define REQ_THROTTLED (1 << __REQ_THROTTLED)
199203

include/linux/blkdev.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
540540

541541
#define blk_account_rq(rq) \
542542
(((rq)->cmd_flags & REQ_STARTED) && \
543-
((rq)->cmd_type == REQ_TYPE_FS || \
544-
((rq)->cmd_flags & REQ_DISCARD)))
543+
((rq)->cmd_type == REQ_TYPE_FS))
545544

546545
#define blk_pm_request(rq) \
547546
((rq)->cmd_type == REQ_TYPE_PM_SUSPEND || \
@@ -595,17 +594,16 @@ static inline void blk_clear_rl_full(struct request_list *rl, bool sync)
595594
rl->flags &= ~flag;
596595
}
597596

597+
static inline bool rq_mergeable(struct request *rq)
598+
{
599+
if (rq->cmd_type != REQ_TYPE_FS)
600+
return false;
598601

599-
/*
600-
* mergeable request must not have _NOMERGE or _BARRIER bit set, nor may
601-
* it already be started by driver.
602-
*/
603-
#define RQ_NOMERGE_FLAGS \
604-
(REQ_NOMERGE | REQ_STARTED | REQ_SOFTBARRIER | REQ_FLUSH | REQ_FUA | REQ_DISCARD)
605-
#define rq_mergeable(rq) \
606-
(!((rq)->cmd_flags & RQ_NOMERGE_FLAGS) && \
607-
(((rq)->cmd_flags & REQ_DISCARD) || \
608-
(rq)->cmd_type == REQ_TYPE_FS))
602+
if (rq->cmd_flags & REQ_NOMERGE_FLAGS)
603+
return false;
604+
605+
return true;
606+
}
609607

610608
/*
611609
* q->prep_rq_fn return values

0 commit comments

Comments
 (0)