Skip to content

Commit 8fe0d47

Browse files
Mike Christieaxboe
authored andcommitted
block: convert merge/insert code to check for REQ_OPs.
This patch converts the block layer merging code to use separate variables for the operation and flags, and to check req_op for the REQ_OP. Signed-off-by: Mike Christie <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 63a4cc2 commit 8fe0d47

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

block/blk-core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ EXPORT_SYMBOL(submit_bio);
21612161
static int blk_cloned_rq_check_limits(struct request_queue *q,
21622162
struct request *rq)
21632163
{
2164-
if (blk_rq_sectors(rq) > blk_queue_get_max_sectors(q, rq->cmd_flags)) {
2164+
if (blk_rq_sectors(rq) > blk_queue_get_max_sectors(q, req_op(rq))) {
21652165
printk(KERN_ERR "%s: over max size limit.\n", __func__);
21662166
return -EIO;
21672167
}

block/blk-merge.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ static int attempt_merge(struct request_queue *q, struct request *req,
649649
if (!rq_mergeable(req) || !rq_mergeable(next))
650650
return 0;
651651

652-
if (!blk_check_merge_flags(req->cmd_flags, next->cmd_flags))
652+
if (!blk_check_merge_flags(req->cmd_flags, req_op(req), next->cmd_flags,
653+
req_op(next)))
653654
return 0;
654655

655656
/*
@@ -663,7 +664,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
663664
|| req_no_special_merge(next))
664665
return 0;
665666

666-
if (req->cmd_flags & REQ_WRITE_SAME &&
667+
if (req_op(req) == REQ_OP_WRITE_SAME &&
667668
!blk_write_same_mergeable(req->bio, next->bio))
668669
return 0;
669670

@@ -751,7 +752,8 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
751752
if (!rq_mergeable(rq) || !bio_mergeable(bio))
752753
return false;
753754

754-
if (!blk_check_merge_flags(rq->cmd_flags, bio->bi_rw))
755+
if (!blk_check_merge_flags(rq->cmd_flags, req_op(rq), bio->bi_rw,
756+
bio_op(bio)))
755757
return false;
756758

757759
/* different data direction or already started, don't merge */
@@ -767,7 +769,7 @@ bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
767769
return false;
768770

769771
/* must be using the same buffer */
770-
if (rq->cmd_flags & REQ_WRITE_SAME &&
772+
if (req_op(rq) == REQ_OP_WRITE_SAME &&
771773
!blk_write_same_mergeable(rq->bio, bio))
772774
return false;
773775

include/linux/blkdev.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,16 +666,16 @@ static inline bool rq_mergeable(struct request *rq)
666666
return true;
667667
}
668668

669-
static inline bool blk_check_merge_flags(unsigned int flags1,
670-
unsigned int flags2)
669+
static inline bool blk_check_merge_flags(unsigned int flags1, unsigned int op1,
670+
unsigned int flags2, unsigned int op2)
671671
{
672-
if ((flags1 & REQ_DISCARD) != (flags2 & REQ_DISCARD))
672+
if ((op1 == REQ_OP_DISCARD) != (op2 == REQ_OP_DISCARD))
673673
return false;
674674

675675
if ((flags1 & REQ_SECURE) != (flags2 & REQ_SECURE))
676676
return false;
677677

678-
if ((flags1 & REQ_WRITE_SAME) != (flags2 & REQ_WRITE_SAME))
678+
if ((op1 == REQ_OP_WRITE_SAME) != (op2 == REQ_OP_WRITE_SAME))
679679
return false;
680680

681681
return true;
@@ -887,12 +887,12 @@ static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
887887
}
888888

889889
static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
890-
unsigned int cmd_flags)
890+
int op)
891891
{
892-
if (unlikely(cmd_flags & REQ_DISCARD))
892+
if (unlikely(op == REQ_OP_DISCARD))
893893
return min(q->limits.max_discard_sectors, UINT_MAX >> 9);
894894

895-
if (unlikely(cmd_flags & REQ_WRITE_SAME))
895+
if (unlikely(op == REQ_OP_WRITE_SAME))
896896
return q->limits.max_write_same_sectors;
897897

898898
return q->limits.max_sectors;
@@ -919,11 +919,11 @@ static inline unsigned int blk_rq_get_max_sectors(struct request *rq)
919919
if (unlikely(rq->cmd_type != REQ_TYPE_FS))
920920
return q->limits.max_hw_sectors;
921921

922-
if (!q->limits.chunk_sectors || (rq->cmd_flags & REQ_DISCARD))
923-
return blk_queue_get_max_sectors(q, rq->cmd_flags);
922+
if (!q->limits.chunk_sectors || (req_op(rq) == REQ_OP_DISCARD))
923+
return blk_queue_get_max_sectors(q, req_op(rq));
924924

925925
return min(blk_max_size_offset(q, blk_rq_pos(rq)),
926-
blk_queue_get_max_sectors(q, rq->cmd_flags));
926+
blk_queue_get_max_sectors(q, req_op(rq)));
927927
}
928928

929929
static inline unsigned int blk_rq_count_bios(struct request *rq)

0 commit comments

Comments
 (0)