Skip to content

Commit f281fb5

Browse files
Adrian HunterJens Axboe
authored andcommitted
block: prevent merges of discard and write requests
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 <adrian.hunter@nokia.com> (Moved the checks above the position checks /Jens) Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent a850ea3 commit f281fb5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

block/blk-merge.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,18 @@ static int attempt_merge(struct request_queue *q, struct request *req,
361361
if (!rq_mergeable(req) || !rq_mergeable(next))
362362
return 0;
363363

364+
/*
365+
* Don't merge file system requests and discard requests
366+
*/
367+
if ((req->cmd_flags & REQ_DISCARD) != (next->cmd_flags & REQ_DISCARD))
368+
return 0;
369+
370+
/*
371+
* Don't merge discard requests and secure discard requests
372+
*/
373+
if ((req->cmd_flags & REQ_SECURE) != (next->cmd_flags & REQ_SECURE))
374+
return 0;
375+
364376
/*
365377
* not contiguous
366378
*/

0 commit comments

Comments
 (0)