]> Git Repo - J-linux.git/commitdiff
block: fix discard request merge
authorMing Lei <[email protected]>
Mon, 28 Jun 2021 02:33:12 +0000 (10:33 +0800)
committerJens Axboe <[email protected]>
Tue, 29 Jun 2021 13:41:08 +0000 (07:41 -0600)
ll_new_hw_segment() is reached only in case of single range discard
merge, and we don't have max discard segment size limit actually, so
it is wrong to run the following check:

if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))

it may be always false since req->nr_phys_segments is initialized as
one, and bio's segment count is still 1, blk_rq_get_max_segments(reg)
is 1 too.

Fix the issue by not doing the check and bypassing the calculation of
discard request's nr_phys_segments.

Based on analysis from Wang Shanker.

Cc: Christoph Hellwig <[email protected]>
Reported-by: Wang Shanker <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
block/blk-merge.c

index 1398b52a24b419cdfae5e93b9418501d6909f951..a11b3b53717efe7433d449b089b982c5956edb47 100644 (file)
@@ -559,10 +559,14 @@ static inline unsigned int blk_rq_get_max_segments(struct request *rq)
 static inline int ll_new_hw_segment(struct request *req, struct bio *bio,
                unsigned int nr_phys_segs)
 {
-       if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))
+       if (blk_integrity_merge_bio(req->q, req, bio) == false)
                goto no_merge;
 
-       if (blk_integrity_merge_bio(req->q, req, bio) == false)
+       /* discard request merge won't add new segment */
+       if (req_op(req) == REQ_OP_DISCARD)
+               return 1;
+
+       if (req->nr_phys_segments + nr_phys_segs > blk_rq_get_max_segments(req))
                goto no_merge;
 
        /*
This page took 0.055791 seconds and 4 git commands to generate.