Commit cfa57ab0 authored by Darrick J. Wong's avatar Darrick J. Wong Committed by Zefan Li

dm io: deal with wandering queue limits when handling REQ_DISCARD and REQ_WRITE_SAME

commit e5db2980 upstream.

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: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
[lizf: Backported to 3.4:
 - adjust context
 - 3.4 doesn't support REQ_WRITE_SAME]
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent fe9af155
......@@ -298,12 +298,18 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
sector_t remaining = where->count;
struct request_queue *q = bdev_get_queue(where->bdev);
sector_t discard_sectors;
unsigned int uninitialized_var(special_cmd_max_sectors);
/* Reject unsupported discard requests */
if ((rw & REQ_DISCARD) && !blk_queue_discard(q)) {
/*
* Reject unsupported discard and write same requests.
*/
if (rw & REQ_DISCARD) {
special_cmd_max_sectors = q->limits.max_discard_sectors;
if (special_cmd_max_sectors == 0) {
dec_count(io, region, -EOPNOTSUPP);
return;
}
}
/*
* where->count may be zero if rw holds a flush and we need to
......@@ -327,7 +333,7 @@ static void do_region(int rw, unsigned region, struct dm_io_region *where,
store_io_and_region_in_bio(bio, io, region);
if (rw & REQ_DISCARD) {
discard_sectors = min_t(sector_t, q->limits.max_discard_sectors, remaining);
discard_sectors = min_t(sector_t, special_cmd_max_sectors, remaining);
bio->bi_size = discard_sectors << SECTOR_SHIFT;
remaining -= discard_sectors;
} else while (remaining) {
......
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