Commit b973cb7e authored by Jens Axboe's avatar Jens Axboe

blk-merge: return the merged request

When we attempt to merge request-to-request, we return a 0/1 if we
ended up merging or not. Change that to return the pointer to the
request that we freed. We will use this to move the freeing of
that request out of the merge logic, so that callers can drop
locks before freeing the request.

There should be no functional changes in this patch.
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
Reviewed-by: default avatarOmar Sandoval <osandov@fb.com>
parent 9b54d816
...@@ -659,31 +659,32 @@ static void blk_account_io_merge(struct request *req) ...@@ -659,31 +659,32 @@ static void blk_account_io_merge(struct request *req)
} }
/* /*
* Has to be called with the request spinlock acquired * For non-mq, this has to be called with the request spinlock acquired.
* For mq with scheduling, the appropriate queue wide lock should be held.
*/ */
static int attempt_merge(struct request_queue *q, struct request *req, static struct request *attempt_merge(struct request_queue *q,
struct request *next) struct request *req, struct request *next)
{ {
if (!rq_mergeable(req) || !rq_mergeable(next)) if (!rq_mergeable(req) || !rq_mergeable(next))
return 0; return NULL;
if (req_op(req) != req_op(next)) if (req_op(req) != req_op(next))
return 0; return NULL;
/* /*
* not contiguous * not contiguous
*/ */
if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next)) if (blk_rq_pos(req) + blk_rq_sectors(req) != blk_rq_pos(next))
return 0; return NULL;
if (rq_data_dir(req) != rq_data_dir(next) if (rq_data_dir(req) != rq_data_dir(next)
|| req->rq_disk != next->rq_disk || req->rq_disk != next->rq_disk
|| req_no_special_merge(next)) || req_no_special_merge(next))
return 0; return NULL;
if (req_op(req) == REQ_OP_WRITE_SAME && if (req_op(req) == REQ_OP_WRITE_SAME &&
!blk_write_same_mergeable(req->bio, next->bio)) !blk_write_same_mergeable(req->bio, next->bio))
return 0; return NULL;
/* /*
* If we are allowed to merge, then append bio list * If we are allowed to merge, then append bio list
...@@ -692,7 +693,7 @@ static int attempt_merge(struct request_queue *q, struct request *req, ...@@ -692,7 +693,7 @@ static int attempt_merge(struct request_queue *q, struct request *req,
* counts here. * counts here.
*/ */
if (!ll_merge_requests_fn(q, req, next)) if (!ll_merge_requests_fn(q, req, next))
return 0; return NULL;
/* /*
* If failfast settings disagree or any of the two is already * If failfast settings disagree or any of the two is already
...@@ -735,27 +736,27 @@ static int attempt_merge(struct request_queue *q, struct request *req, ...@@ -735,27 +736,27 @@ static int attempt_merge(struct request_queue *q, struct request *req,
/* owner-ship of bio passed from next to req */ /* owner-ship of bio passed from next to req */
next->bio = NULL; next->bio = NULL;
__blk_put_request(q, next); __blk_put_request(q, next);
return 1; return next;
} }
int attempt_back_merge(struct request_queue *q, struct request *rq) 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);
if (next) if (next)
return attempt_merge(q, rq, next); return attempt_merge(q, rq, next);
return 0; return NULL;
} }
int attempt_front_merge(struct request_queue *q, struct request *rq) 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);
if (prev) if (prev)
return attempt_merge(q, prev, rq); return attempt_merge(q, prev, rq);
return 0; return NULL;
} }
int blk_attempt_req_merge(struct request_queue *q, struct request *rq, int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
...@@ -767,7 +768,7 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq, ...@@ -767,7 +768,7 @@ int blk_attempt_req_merge(struct request_queue *q, struct request *rq,
if (!e->type->ops.sq.elevator_allow_rq_merge_fn(q, rq, next)) if (!e->type->ops.sq.elevator_allow_rq_merge_fn(q, rq, next))
return 0; return 0;
return attempt_merge(q, rq, next); return attempt_merge(q, rq, next) != NULL;
} }
bool blk_rq_merge_ok(struct request *rq, struct bio *bio) bool blk_rq_merge_ok(struct request *rq, struct bio *bio)
......
...@@ -208,8 +208,8 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req, ...@@ -208,8 +208,8 @@ int ll_back_merge_fn(struct request_queue *q, struct request *req,
struct bio *bio); struct bio *bio);
int ll_front_merge_fn(struct request_queue *q, struct request *req, int ll_front_merge_fn(struct request_queue *q, struct request *req,
struct bio *bio); struct bio *bio);
int attempt_back_merge(struct request_queue *q, struct request *rq); struct request *attempt_back_merge(struct request_queue *q, struct request *rq);
int attempt_front_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);
void blk_recalc_rq_segments(struct request *rq); void 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