Skip to content

Commit 6abc494

Browse files
koct9iaxboe
authored andcommitted
dm: add support for REQ_NOWAIT and enable it for linear target
Add DM target feature flag DM_TARGET_NOWAIT which advertises that target works with REQ_NOWAIT bios. Add dm_table_supports_nowait() and update dm_table_set_restrictions() to set/clear QUEUE_FLAG_NOWAIT accordingly. Signed-off-by: Konstantin Khlebnikov <[email protected]> Signed-off-by: Mike Snitzer <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 021a244 commit 6abc494

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

drivers/md/dm-linear.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,11 @@ static struct target_type linear_target = {
228228
.name = "linear",
229229
.version = {1, 4, 0},
230230
#ifdef CONFIG_BLK_DEV_ZONED
231-
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_ZONED_HM,
231+
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT |
232+
DM_TARGET_ZONED_HM,
232233
.report_zones = linear_report_zones,
233234
#else
234-
.features = DM_TARGET_PASSES_INTEGRITY,
235+
.features = DM_TARGET_PASSES_INTEGRITY | DM_TARGET_NOWAIT,
235236
#endif
236237
.module = THIS_MODULE,
237238
.ctr = linear_ctr,

drivers/md/dm-table.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,33 @@ static bool dm_table_supports_write_zeroes(struct dm_table *t)
17481748
return true;
17491749
}
17501750

1751+
static int device_not_nowait_capable(struct dm_target *ti, struct dm_dev *dev,
1752+
sector_t start, sector_t len, void *data)
1753+
{
1754+
struct request_queue *q = bdev_get_queue(dev->bdev);
1755+
1756+
return q && !blk_queue_nowait(q);
1757+
}
1758+
1759+
static bool dm_table_supports_nowait(struct dm_table *t)
1760+
{
1761+
struct dm_target *ti;
1762+
unsigned i = 0;
1763+
1764+
while (i < dm_table_get_num_targets(t)) {
1765+
ti = dm_table_get_target(t, i++);
1766+
1767+
if (!dm_target_supports_nowait(ti->type))
1768+
return false;
1769+
1770+
if (!ti->type->iterate_devices ||
1771+
ti->type->iterate_devices(ti, device_not_nowait_capable, NULL))
1772+
return false;
1773+
}
1774+
1775+
return true;
1776+
}
1777+
17511778
static int device_not_discard_capable(struct dm_target *ti, struct dm_dev *dev,
17521779
sector_t start, sector_t len, void *data)
17531780
{
@@ -1850,6 +1877,11 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
18501877
*/
18511878
q->limits = *limits;
18521879

1880+
if (dm_table_supports_nowait(t))
1881+
blk_queue_flag_set(QUEUE_FLAG_NOWAIT, q);
1882+
else
1883+
blk_queue_flag_clear(QUEUE_FLAG_NOWAIT, q);
1884+
18531885
if (!dm_table_supports_discards(t)) {
18541886
blk_queue_flag_clear(QUEUE_FLAG_DISCARD, q);
18551887
/* Must also clear discard limits... */

drivers/md/dm.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,9 @@ static blk_qc_t dm_submit_bio(struct bio *bio)
18021802
if (unlikely(test_bit(DMF_BLOCK_IO_FOR_SUSPEND, &md->flags))) {
18031803
dm_put_live_table(md, srcu_idx);
18041804

1805-
if (!(bio->bi_opf & REQ_RAHEAD))
1805+
if (bio->bi_opf & REQ_NOWAIT)
1806+
bio_wouldblock_error(bio);
1807+
else if (!(bio->bi_opf & REQ_RAHEAD))
18061808
queue_io(md, bio);
18071809
else
18081810
bio_io_error(bio);

include/linux/device-mapper.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ struct target_type {
252252
#define DM_TARGET_ZONED_HM 0x00000040
253253
#define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM)
254254

255+
/*
256+
* A target handles REQ_NOWAIT
257+
*/
258+
#define DM_TARGET_NOWAIT 0x00000080
259+
#define dm_target_supports_nowait(type) ((type)->features & DM_TARGET_NOWAIT)
260+
255261
struct dm_target {
256262
struct dm_table *table;
257263
struct target_type *type;

0 commit comments

Comments
 (0)