Commit eda5cc99 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: move blk_mq_sched_try_merge to blk-merge.c

Move blk_mq_sched_try_merge to blk-merge.c, which allows to mark
a lot of the merge infrastructure static there.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent d59da419
...@@ -580,7 +580,8 @@ int ll_back_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs) ...@@ -580,7 +580,8 @@ int ll_back_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs)
return ll_new_hw_segment(req, bio, nr_segs); return ll_new_hw_segment(req, bio, nr_segs);
} }
int ll_front_merge_fn(struct request *req, struct bio *bio, unsigned int nr_segs) static int ll_front_merge_fn(struct request *req, struct bio *bio,
unsigned int nr_segs)
{ {
if (req_gap_front_merge(req, bio)) if (req_gap_front_merge(req, bio))
return 0; return 0;
...@@ -810,7 +811,8 @@ static struct request *attempt_merge(struct request_queue *q, ...@@ -810,7 +811,8 @@ static struct request *attempt_merge(struct request_queue *q,
return next; return next;
} }
struct request *attempt_back_merge(struct request_queue *q, struct request *rq) static struct request *attempt_back_merge(struct request_queue *q,
struct request *rq)
{ {
struct request *next = elv_latter_request(q, rq); struct request *next = elv_latter_request(q, rq);
...@@ -820,7 +822,8 @@ struct request *attempt_back_merge(struct request_queue *q, struct request *rq) ...@@ -820,7 +822,8 @@ struct request *attempt_back_merge(struct request_queue *q, struct request *rq)
return NULL; return NULL;
} }
struct request *attempt_front_merge(struct request_queue *q, struct request *rq) static struct request *attempt_front_merge(struct request_queue *q,
struct request *rq)
{ {
struct request *prev = elv_former_request(q, rq); struct request *prev = elv_former_request(q, rq);
...@@ -907,9 +910,14 @@ static void blk_account_io_merge_bio(struct request *req) ...@@ -907,9 +910,14 @@ static void blk_account_io_merge_bio(struct request *req)
part_stat_unlock(); part_stat_unlock();
} }
enum bio_merge_status bio_attempt_back_merge(struct request *req, enum bio_merge_status {
struct bio *bio, BIO_MERGE_OK,
unsigned int nr_segs) BIO_MERGE_NONE,
BIO_MERGE_FAILED,
};
static enum bio_merge_status bio_attempt_back_merge(struct request *req,
struct bio *bio, unsigned int nr_segs)
{ {
const int ff = bio->bi_opf & REQ_FAILFAST_MASK; const int ff = bio->bi_opf & REQ_FAILFAST_MASK;
...@@ -932,9 +940,8 @@ enum bio_merge_status bio_attempt_back_merge(struct request *req, ...@@ -932,9 +940,8 @@ enum bio_merge_status bio_attempt_back_merge(struct request *req,
return BIO_MERGE_OK; return BIO_MERGE_OK;
} }
enum bio_merge_status bio_attempt_front_merge(struct request *req, static enum bio_merge_status bio_attempt_front_merge(struct request *req,
struct bio *bio, struct bio *bio, unsigned int nr_segs)
unsigned int nr_segs)
{ {
const int ff = bio->bi_opf & REQ_FAILFAST_MASK; const int ff = bio->bi_opf & REQ_FAILFAST_MASK;
...@@ -959,9 +966,8 @@ enum bio_merge_status bio_attempt_front_merge(struct request *req, ...@@ -959,9 +966,8 @@ enum bio_merge_status bio_attempt_front_merge(struct request *req,
return BIO_MERGE_OK; return BIO_MERGE_OK;
} }
enum bio_merge_status bio_attempt_discard_merge(struct request_queue *q, static enum bio_merge_status bio_attempt_discard_merge(struct request_queue *q,
struct request *req, struct request *req, struct bio *bio)
struct bio *bio)
{ {
unsigned short segments = blk_rq_nr_discard_segments(req); unsigned short segments = blk_rq_nr_discard_segments(req);
...@@ -1096,3 +1102,35 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list, ...@@ -1096,3 +1102,35 @@ bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,
return false; return false;
} }
EXPORT_SYMBOL_GPL(blk_bio_list_merge); EXPORT_SYMBOL_GPL(blk_bio_list_merge);
bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
unsigned int nr_segs, struct request **merged_request)
{
struct request *rq;
switch (elv_merge(q, &rq, bio)) {
case ELEVATOR_BACK_MERGE:
if (!blk_mq_sched_allow_merge(q, rq, bio))
return false;
if (bio_attempt_back_merge(rq, bio, nr_segs) != BIO_MERGE_OK)
return false;
*merged_request = attempt_back_merge(q, rq);
if (!*merged_request)
elv_merged_request(q, rq, ELEVATOR_BACK_MERGE);
return true;
case ELEVATOR_FRONT_MERGE:
if (!blk_mq_sched_allow_merge(q, rq, bio))
return false;
if (bio_attempt_front_merge(rq, bio, nr_segs) != BIO_MERGE_OK)
return false;
*merged_request = attempt_front_merge(q, rq);
if (!*merged_request)
elv_merged_request(q, rq, ELEVATOR_FRONT_MERGE);
return true;
case ELEVATOR_DISCARD_MERGE:
return bio_attempt_discard_merge(q, rq, bio) == BIO_MERGE_OK;
default:
return false;
}
}
EXPORT_SYMBOL_GPL(blk_mq_sched_try_merge);
...@@ -344,38 +344,6 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx) ...@@ -344,38 +344,6 @@ void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx)
} }
} }
bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
unsigned int nr_segs, struct request **merged_request)
{
struct request *rq;
switch (elv_merge(q, &rq, bio)) {
case ELEVATOR_BACK_MERGE:
if (!blk_mq_sched_allow_merge(q, rq, bio))
return false;
if (bio_attempt_back_merge(rq, bio, nr_segs) != BIO_MERGE_OK)
return false;
*merged_request = attempt_back_merge(q, rq);
if (!*merged_request)
elv_merged_request(q, rq, ELEVATOR_BACK_MERGE);
return true;
case ELEVATOR_FRONT_MERGE:
if (!blk_mq_sched_allow_merge(q, rq, bio))
return false;
if (bio_attempt_front_merge(rq, bio, nr_segs) != BIO_MERGE_OK)
return false;
*merged_request = attempt_front_merge(q, rq);
if (!*merged_request)
elv_merged_request(q, rq, ELEVATOR_FRONT_MERGE);
return true;
case ELEVATOR_DISCARD_MERGE:
return bio_attempt_discard_merge(q, rq, bio) == BIO_MERGE_OK;
default:
return false;
}
}
EXPORT_SYMBOL_GPL(blk_mq_sched_try_merge);
bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio, bool __blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio,
unsigned int nr_segs) unsigned int nr_segs)
{ {
......
...@@ -29,12 +29,6 @@ struct blk_flush_queue { ...@@ -29,12 +29,6 @@ struct blk_flush_queue {
spinlock_t mq_flush_lock; spinlock_t mq_flush_lock;
}; };
enum bio_merge_status {
BIO_MERGE_OK,
BIO_MERGE_NONE,
BIO_MERGE_FAILED,
};
extern struct kmem_cache *blk_requestq_cachep; extern struct kmem_cache *blk_requestq_cachep;
extern struct kobj_type blk_queue_ktype; extern struct kobj_type blk_queue_ktype;
extern struct ida blk_queue_ida; extern struct ida blk_queue_ida;
...@@ -190,15 +184,6 @@ static inline void blk_integrity_del(struct gendisk *disk) ...@@ -190,15 +184,6 @@ static inline void blk_integrity_del(struct gendisk *disk)
unsigned long blk_rq_timeout(unsigned long timeout); unsigned long blk_rq_timeout(unsigned long timeout);
void blk_add_timer(struct request *req); void blk_add_timer(struct request *req);
enum bio_merge_status bio_attempt_front_merge(struct request *req,
struct bio *bio,
unsigned int nr_segs);
enum bio_merge_status bio_attempt_back_merge(struct request *req,
struct bio *bio,
unsigned int nr_segs);
enum bio_merge_status bio_attempt_discard_merge(struct request_queue *q,
struct request *req,
struct bio *bio);
bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio, bool blk_attempt_plug_merge(struct request_queue *q, struct bio *bio,
unsigned int nr_segs, struct request **same_queue_rq); unsigned int nr_segs, struct request **same_queue_rq);
bool blk_bio_list_merge(struct request_queue *q, struct list_head *list, bool blk_bio_list_merge(struct request_queue *q, struct list_head *list,
...@@ -249,10 +234,6 @@ ssize_t part_timeout_store(struct device *, struct device_attribute *, ...@@ -249,10 +234,6 @@ ssize_t part_timeout_store(struct device *, struct device_attribute *,
void __blk_queue_split(struct bio **bio, unsigned int *nr_segs); void __blk_queue_split(struct bio **bio, unsigned int *nr_segs);
int ll_back_merge_fn(struct request *req, struct bio *bio, int ll_back_merge_fn(struct request *req, struct bio *bio,
unsigned int nr_segs); unsigned int nr_segs);
int ll_front_merge_fn(struct request *req, struct bio *bio,
unsigned int nr_segs);
struct request *attempt_back_merge(struct request_queue *q, struct request *rq);
struct request *attempt_front_merge(struct request_queue *q, struct request *rq);
int blk_attempt_req_merge(struct request_queue *q, struct request *rq, int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
struct request *next); struct request *next);
unsigned int blk_recalc_rq_segments(struct request *rq); unsigned int blk_recalc_rq_segments(struct request *rq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment