Skip to content

Commit 4a0b4dd

Browse files
snitmkergon
authored andcommitted
dm: do not initialise full request queue when bio based
Change bio-based mapped devices no longer to have a fully initialized request_queue (request_fn, elevator, etc). This means bio-based DM devices no longer register elevator sysfs attributes ('iosched/' tree or 'scheduler' other than "none"). In contrast, a request-based DM device will continue to have a full request_queue and will register elevator sysfs attributes. Therefore a user can determine a DM device's type by checking if elevator sysfs attributes exist. First allocate a minimalist request_queue structure for a DM device (needed for both bio and request-based DM). Initialization of a full request_queue is deferred until it is known that the DM device is request-based, at the end of the table load sequence. Factor DM device's request_queue initialization: - common to both request-based and bio-based into dm_init_md_queue(). - specific to request-based into dm_init_request_based_queue(). The md->type_lock mutex is used to protect md->queue, in addition to md->type, during table_load(). A DM device's first table_load will establish the immutable md->type. But md->queue initialization, based on md->type, may fail at that time (because blk_init_allocated_queue cannot allocate memory). Therefore any subsequent table_load must (re)try dm_setup_md_queue independently of establishing md->type. Signed-off-by: Mike Snitzer <snitzer@redhat.com> Acked-by: Kiyoshi Ueda <k-ueda@ct.jp.nec.com> Signed-off-by: Alasdair G Kergon <agk@redhat.com>
1 parent a5664da commit 4a0b4dd

3 files changed

Lines changed: 79 additions & 26 deletions

File tree

‎drivers/md/dm-ioctl.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
11891189
goto out;
11901190
}
11911191

1192-
/* Protect md->type against concurrent table loads. */
1192+
/* Protect md->type and md->queue against concurrent table loads. */
11931193
dm_lock_md_type(md);
11941194
if (dm_get_md_type(md) == DM_TYPE_NONE)
11951195
/* Initial table load: acquire type of table. */
@@ -1201,6 +1201,15 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
12011201
r = -EINVAL;
12021202
goto out;
12031203
}
1204+
1205+
/* setup md->queue to reflect md's type (may block) */
1206+
r = dm_setup_md_queue(md);
1207+
if (r) {
1208+
DMWARN("unable to set up device queue for new table.");
1209+
dm_table_destroy(t);
1210+
dm_unlock_md_type(md);
1211+
goto out;
1212+
}
12041213
dm_unlock_md_type(md);
12051214

12061215
/* stage inactive table */

‎drivers/md/dm.c‎

Lines changed: 67 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ struct mapped_device {
126126

127127
struct request_queue *queue;
128128
unsigned type;
129-
/* Protect type against concurrent access. */
129+
/* Protect queue and type against concurrent access. */
130130
struct mutex type_lock;
131131

132132
struct gendisk *disk;
@@ -1856,6 +1856,28 @@ static const struct block_device_operations dm_blk_dops;
18561856
static void dm_wq_work(struct work_struct *work);
18571857
static void dm_rq_barrier_work(struct work_struct *work);
18581858

1859+
static void dm_init_md_queue(struct mapped_device *md)
1860+
{
1861+
/*
1862+
* Request-based dm devices cannot be stacked on top of bio-based dm
1863+
* devices. The type of this dm device has not been decided yet.
1864+
* The type is decided at the first table loading time.
1865+
* To prevent problematic device stacking, clear the queue flag
1866+
* for request stacking support until then.
1867+
*
1868+
* This queue is new, so no concurrency on the queue_flags.
1869+
*/
1870+
queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1871+
1872+
md->queue->queuedata = md;
1873+
md->queue->backing_dev_info.congested_fn = dm_any_congested;
1874+
md->queue->backing_dev_info.congested_data = md;
1875+
blk_queue_make_request(md->queue, dm_request);
1876+
blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1877+
md->queue->unplug_fn = dm_unplug_all;
1878+
blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1879+
}
1880+
18591881
/*
18601882
* Allocate and initialise a blank device with a given minor.
18611883
*/
@@ -1895,33 +1917,11 @@ static struct mapped_device *alloc_dev(int minor)
18951917
INIT_LIST_HEAD(&md->uevent_list);
18961918
spin_lock_init(&md->uevent_lock);
18971919

1898-
md->queue = blk_init_queue(dm_request_fn, NULL);
1920+
md->queue = blk_alloc_queue(GFP_KERNEL);
18991921
if (!md->queue)
19001922
goto bad_queue;
19011923

1902-
/*
1903-
* Request-based dm devices cannot be stacked on top of bio-based dm
1904-
* devices. The type of this dm device has not been decided yet,
1905-
* although we initialized the queue using blk_init_queue().
1906-
* The type is decided at the first table loading time.
1907-
* To prevent problematic device stacking, clear the queue flag
1908-
* for request stacking support until then.
1909-
*
1910-
* This queue is new, so no concurrency on the queue_flags.
1911-
*/
1912-
queue_flag_clear_unlocked(QUEUE_FLAG_STACKABLE, md->queue);
1913-
md->saved_make_request_fn = md->queue->make_request_fn;
1914-
md->queue->queuedata = md;
1915-
md->queue->backing_dev_info.congested_fn = dm_any_congested;
1916-
md->queue->backing_dev_info.congested_data = md;
1917-
blk_queue_make_request(md->queue, dm_request);
1918-
blk_queue_bounce_limit(md->queue, BLK_BOUNCE_ANY);
1919-
md->queue->unplug_fn = dm_unplug_all;
1920-
blk_queue_merge_bvec(md->queue, dm_merge_bvec);
1921-
blk_queue_softirq_done(md->queue, dm_softirq_done);
1922-
blk_queue_prep_rq(md->queue, dm_prep_fn);
1923-
blk_queue_lld_busy(md->queue, dm_lld_busy);
1924-
blk_queue_ordered(md->queue, QUEUE_ORDERED_DRAIN_FLUSH);
1924+
dm_init_md_queue(md);
19251925

19261926
md->disk = alloc_disk(1);
19271927
if (!md->disk)
@@ -2160,6 +2160,48 @@ unsigned dm_get_md_type(struct mapped_device *md)
21602160
return md->type;
21612161
}
21622162

2163+
/*
2164+
* Fully initialize a request-based queue (->elevator, ->request_fn, etc).
2165+
*/
2166+
static int dm_init_request_based_queue(struct mapped_device *md)
2167+
{
2168+
struct request_queue *q = NULL;
2169+
2170+
if (md->queue->elevator)
2171+
return 1;
2172+
2173+
/* Fully initialize the queue */
2174+
q = blk_init_allocated_queue(md->queue, dm_request_fn, NULL);
2175+
if (!q)
2176+
return 0;
2177+
2178+
md->queue = q;
2179+
md->saved_make_request_fn = md->queue->make_request_fn;
2180+
dm_init_md_queue(md);
2181+
blk_queue_softirq_done(md->queue, dm_softirq_done);
2182+
blk_queue_prep_rq(md->queue, dm_prep_fn);
2183+
blk_queue_lld_busy(md->queue, dm_lld_busy);
2184+
blk_queue_ordered(md->queue, QUEUE_ORDERED_DRAIN_FLUSH);
2185+
2186+
elv_register_queue(md->queue);
2187+
2188+
return 1;
2189+
}
2190+
2191+
/*
2192+
* Setup the DM device's queue based on md's type
2193+
*/
2194+
int dm_setup_md_queue(struct mapped_device *md)
2195+
{
2196+
if ((dm_get_md_type(md) == DM_TYPE_REQUEST_BASED) &&
2197+
!dm_init_request_based_queue(md)) {
2198+
DMWARN("Cannot initialize queue for request-based mapped device");
2199+
return -EINVAL;
2200+
}
2201+
2202+
return 0;
2203+
}
2204+
21632205
static struct mapped_device *dm_find_md(dev_t dev)
21642206
{
21652207
struct mapped_device *md;

‎drivers/md/dm.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ void dm_unlock_md_type(struct mapped_device *md);
7171
void dm_set_md_type(struct mapped_device *md, unsigned type);
7272
unsigned dm_get_md_type(struct mapped_device *md);
7373

74+
int dm_setup_md_queue(struct mapped_device *md);
75+
7476
/*
7577
* To check the return value from dm_table_find_target().
7678
*/

0 commit comments

Comments
 (0)