History

dm: fix request-based DM to not bounce through indirect dm_submit_bio

It is unnecessary to force request-based DM to call into bio-based dm_submit_bio (via indirect disk->fops->submit_bio) only to have it then call blk_mq_submit_bio(). Fix this by establishing a request-based DM block_device_operations (dm_rq_blk_dops, which doesn't have .submit_bio) and update dm_setup_md_queue() to set md->disk->fops to it for DM_TYPE_REQUEST_BASED. Remove DM_TYPE_REQUEST_BASED conditional in dm_submit_bio and unexport blk_mq_submit_bio.

Mike Snitzer committed 6 years ago

Commit 681cc5e1 parent 9c37de22 files · +12 −14Browse files

Unified · Split

2 files
  1. block/blk-mq.c +0 −1
  2. drivers/md/dm.c +12 −13
block/blk-mq.c+0−1
@@ -2265,7 +2265,6 @@ queue_exit: · 2264 unmodified lines
2265 blk_queue_exit(q);2265 blk_queue_exit(q);
2266 return BLK_QC_T_NONE;2266 return BLK_QC_T_NONE;
2267}2267}
2268EXPORT_SYMBOL_GPL(blk_mq_submit_bio); /* only for request based dm */
2269 2268
2270void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,2269void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags,
2271 unsigned int hctx_idx)2270 unsigned int hctx_idx)
drivers/md/dm.c+12−13
@@ -1633,18 +1633,6 @@ static blk_qc_t dm_submit_bio(struct bio *bio) · 1632 unmodified lines
1633 int srcu_idx;1633 int srcu_idx;
1634 struct dm_table *map;1634 struct dm_table *map;
1635 1635
1636 if (dm_get_md_type(md) == DM_TYPE_REQUEST_BASED) {
1637 /*
1638 * We are called with a live reference on q_usage_counter, but
1639 * that one will be released as soon as we return. Grab an
1640 * extra one as blk_mq_submit_bio expects to be able to consume
1641 * a reference (which lives until the request is freed in case a
1642 * request is allocated).
1643 */
1644 percpu_ref_get(&bio->bi_disk->queue->q_usage_counter);
1645 return blk_mq_submit_bio(bio);
1646 }
1647
1648 map = dm_get_live_table(md, &srcu_idx);1636 map = dm_get_live_table(md, &srcu_idx);
1649 if (unlikely(!map)) {1637 if (unlikely(!map)) {
1650 DMERR_LIMIT("%s: mapping table unavailable, erroring io",1638 DMERR_LIMIT("%s: mapping table unavailable, erroring io",
@@ -1727,6 +1715,7 @@ static int next_free_minor(int *minor) · 76 unmodified lines
1727}1715}
1728 1716
1729static const struct block_device_operations dm_blk_dops;1717static const struct block_device_operations dm_blk_dops;
1718static const struct block_device_operations dm_rq_blk_dops;
1730static const struct dax_operations dm_dax_ops;1719static const struct dax_operations dm_dax_ops;
1731 1720
1732static void dm_wq_work(struct work_struct *work);1721static void dm_wq_work(struct work_struct *work);
@@ -2113,9 +2102,10 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) · 380 unmodified lines
2113 2102
2114 switch (type) {2103 switch (type) {
2115 case DM_TYPE_REQUEST_BASED:2104 case DM_TYPE_REQUEST_BASED:
2105 md->disk->fops = &dm_rq_blk_dops;
2116 r = dm_mq_init_request_queue(md, t);2106 r = dm_mq_init_request_queue(md, t);
2117 if (r) {2107 if (r) {
2118 DMERR("Cannot initialize queue for request-based dm-mq mapped device");2108 DMERR("Cannot initialize queue for request-based dm mapped device");
2119 return r;2109 return r;
2120 }2110 }
2121 break;2111 break;
@@ -3095,6 +3085,15 @@ static const struct block_device_operations dm_blk_dops = { · 973 unmodified lines
3095 .owner = THIS_MODULE3085 .owner = THIS_MODULE
3096};3086};
3097 3087
3088static const struct block_device_operations dm_rq_blk_dops = {
3089 .open = dm_blk_open,
3090 .release = dm_blk_close,
3091 .ioctl = dm_blk_ioctl,
3092 .getgeo = dm_blk_getgeo,
3093 .pr_ops = &dm_pr_ops,
3094 .owner = THIS_MODULE
3095};
3096
3098static const struct dax_operations dm_dax_ops = {3097static const struct dax_operations dm_dax_ops = {
3099 .direct_access = dm_dax_direct_access,3098 .direct_access = dm_dax_direct_access,
3100 .dax_supported = dm_dax_supported,3099 .dax_supported = dm_dax_supported,