Skip to content

Commit

Permalink
block: convert merge/insert code to check for REQ_OPs.
Browse files Browse the repository at this point in the history
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 <mchristi@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
  • Loading branch information
Mike Christie authored and Jens Axboe committed Jun 7, 2016
1 parent 63a4cc2 commit 8fe0d47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 1 addition & 1 deletion block/blk-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ EXPORT_SYMBOL(submit_bio);
static int blk_cloned_rq_check_limits(struct request_queue *q,
struct request *rq)
{
if (blk_rq_sectors(rq) > blk_queue_get_max_sectors(q, rq->cmd_flags)) {
if (blk_rq_sectors(rq) > blk_queue_get_max_sectors(q, req_op(rq))) {
printk(KERN_ERR "%s: over max size limit.\n", __func__);
return -EIO;
}
Expand Down
10 changes: 6 additions & 4 deletions block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,8 @@ static int attempt_merge(struct request_queue *q, struct request *req,
if (!rq_mergeable(req) || !rq_mergeable(next))
return 0;

if (!blk_check_merge_flags(req->cmd_flags, next->cmd_flags))
if (!blk_check_merge_flags(req->cmd_flags, req_op(req), next->cmd_flags,
req_op(next)))
return 0;

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

if (req->cmd_flags & REQ_WRITE_SAME &&
if (req_op(req) == REQ_OP_WRITE_SAME &&
!blk_write_same_mergeable(req->bio, next->bio))
return 0;

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

if (!blk_check_merge_flags(rq->cmd_flags, bio->bi_rw))
if (!blk_check_merge_flags(rq->cmd_flags, req_op(rq), bio->bi_rw,
bio_op(bio)))
return false;

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

/* must be using the same buffer */
if (rq->cmd_flags & REQ_WRITE_SAME &&
if (req_op(rq) == REQ_OP_WRITE_SAME &&
!blk_write_same_mergeable(rq->bio, bio))
return false;

Expand Down
20 changes: 10 additions & 10 deletions include/linux/blkdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -666,16 +666,16 @@ static inline bool rq_mergeable(struct request *rq)
return true;
}

static inline bool blk_check_merge_flags(unsigned int flags1,
unsigned int flags2)
static inline bool blk_check_merge_flags(unsigned int flags1, unsigned int op1,
unsigned int flags2, unsigned int op2)
{
if ((flags1 & REQ_DISCARD) != (flags2 & REQ_DISCARD))
if ((op1 == REQ_OP_DISCARD) != (op2 == REQ_OP_DISCARD))
return false;

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

if ((flags1 & REQ_WRITE_SAME) != (flags2 & REQ_WRITE_SAME))
if ((op1 == REQ_OP_WRITE_SAME) != (op2 == REQ_OP_WRITE_SAME))
return false;

return true;
Expand Down Expand Up @@ -887,12 +887,12 @@ static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
}

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

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

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

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

return min(blk_max_size_offset(q, blk_rq_pos(rq)),
blk_queue_get_max_sectors(q, rq->cmd_flags));
blk_queue_get_max_sectors(q, req_op(rq)));
}

static inline unsigned int blk_rq_count_bios(struct request *rq)
Expand Down

0 comments on commit 8fe0d47

Please sign in to comment.