Skip to content

Commit

Permalink
block: prevent merges of discard and write requests
Browse files Browse the repository at this point in the history
Add logic to prevent two I/O requests being merged if
only one of them is a discard.  Ditto secure discard.

Without this fix, it is possible for write requests
to transform into discard requests.  For example:

  Submit bio 1 to discard 8 sectors from sector n
  Submit bio 2 to write 8 sectors from sector n + 16
  Submit bio 3 to write 8 sectors from sector n + 8

Bio 1 becomes request 1.  Bio 2 becomes request 2.
Bio 3 is merged with request 2, and then subsequently
request 2 is merged with request 1 resulting in just
one I/O request which discards all 24 sectors.

Signed-off-by: Adrian Hunter <[email protected]>

(Moved the checks above the position checks /Jens)

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Adrian Hunter authored and Jens Axboe committed Sep 25, 2010
1 parent a850ea3 commit f281fb5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions block/blk-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,18 @@ static int attempt_merge(struct request_queue *q, struct request *req,
if (!rq_mergeable(req) || !rq_mergeable(next))
return 0;

/*
* Don't merge file system requests and discard requests
*/
if ((req->cmd_flags & REQ_DISCARD) != (next->cmd_flags & REQ_DISCARD))
return 0;

/*
* Don't merge discard requests and secure discard requests
*/
if ((req->cmd_flags & REQ_SECURE) != (next->cmd_flags & REQ_SECURE))
return 0;

/*
* not contiguous
*/
Expand Down

0 comments on commit f281fb5

Please sign in to comment.