Skip to content

Commit e5db298

Browse files
djwongsnitm
authored andcommitted
dm io: deal with wandering queue limits when handling REQ_DISCARD and REQ_WRITE_SAME
Since it's possible for the discard and write same queue limits to change while the upper level command is being sliced and diced, fix up both of them (a) to reject IO if the special command is unsupported at the start of the function and (b) read the limits once and let the commands error out on their own if the status happens to change. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com> Cc: stable@vger.kernel.org
1 parent 09ee96b commit e5db298

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

drivers/md/dm-io.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,16 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
289289
struct request_queue *q = bdev_get_queue(where->bdev);
290290
unsigned short logical_block_size = queue_logical_block_size(q);
291291
sector_t num_sectors;
292+
unsigned int uninitialized_var(special_cmd_max_sectors);
292293

293-
/* Reject unsupported discard requests */
294-
if ((rw & REQ_DISCARD) && !blk_queue_discard(q)) {
294+
/*
295+
* Reject unsupported discard and write same requests.
296+
*/
297+
if (rw & REQ_DISCARD)
298+
special_cmd_max_sectors = q->limits.max_discard_sectors;
299+
else if (rw & REQ_WRITE_SAME)
300+
special_cmd_max_sectors = q->limits.max_write_same_sectors;
301+
if ((rw & (REQ_DISCARD | REQ_WRITE_SAME)) && special_cmd_max_sectors == 0) {
295302
dec_count(io, region, -EOPNOTSUPP);
296303
return;
297304
}
@@ -317,7 +324,7 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
317324
store_io_and_region_in_bio(bio, io, region);
318325

319326
if (rw & REQ_DISCARD) {
320-
num_sectors = min_t(sector_t, q->limits.max_discard_sectors, remaining);
327+
num_sectors = min_t(sector_t, special_cmd_max_sectors, remaining);
321328
bio->bi_iter.bi_size = num_sectors << SECTOR_SHIFT;
322329
remaining -= num_sectors;
323330
} else if (rw & REQ_WRITE_SAME) {
@@ -326,7 +333,7 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
326333
*/
327334
dp->get_page(dp, &page, &len, &offset);
328335
bio_add_page(bio, page, logical_block_size, offset);
329-
num_sectors = min_t(sector_t, q->limits.max_write_same_sectors, remaining);
336+
num_sectors = min_t(sector_t, special_cmd_max_sectors, remaining);
330337
bio->bi_iter.bi_size = num_sectors << SECTOR_SHIFT;
331338

332339
offset = 0;

0 commit comments

Comments
 (0)