diff options
author | Mike Snitzer <snitzer@redhat.com> | 2013-08-27 18:57:03 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2013-09-05 20:46:06 -0400 |
commit | 00c4fc3b1f590288cb3c42f36da50f49a513cfcf (patch) | |
tree | e185bc97fc6529d1299e5e13987fe5b86cf21868 /drivers/md | |
parent | c2b04824620f30b52bb2fdcdd14c758b8c62c70f (diff) |
dm ioctl: increase granularity of type_lock when loading table
Hold the mapped device's type_lock before calling populate_table() since
it is where the table's type is determined based on the specified
targets. There is no need to allow concurrent table loads to race to
establish the table's targets or type.
This eliminates the need to grab the lock in dm_table_set_type().
Also verify that the type_lock is held in both dm_set_md_type() and
dm_get_md_type().
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/dm-ioctl.c | 6 | ||||
-rw-r--r-- | drivers/md/dm-table.c | 2 | ||||
-rw-r--r-- | drivers/md/dm.c | 2 |
3 files changed, 6 insertions, 4 deletions
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 5667cea55e71..42cca3642010 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c | |||
@@ -1264,9 +1264,12 @@ static int table_load(struct dm_ioctl *param, size_t param_size) | |||
1264 | if (r) | 1264 | if (r) |
1265 | goto out; | 1265 | goto out; |
1266 | 1266 | ||
1267 | /* Protect md->type and md->queue against concurrent table loads. */ | ||
1268 | dm_lock_md_type(md); | ||
1267 | r = populate_table(t, param, param_size); | 1269 | r = populate_table(t, param, param_size); |
1268 | if (r) { | 1270 | if (r) { |
1269 | dm_table_destroy(t); | 1271 | dm_table_destroy(t); |
1272 | dm_unlock_md_type(md); | ||
1270 | goto out; | 1273 | goto out; |
1271 | } | 1274 | } |
1272 | 1275 | ||
@@ -1276,12 +1279,11 @@ static int table_load(struct dm_ioctl *param, size_t param_size) | |||
1276 | DMWARN("can't replace immutable target type %s", | 1279 | DMWARN("can't replace immutable target type %s", |
1277 | immutable_target_type->name); | 1280 | immutable_target_type->name); |
1278 | dm_table_destroy(t); | 1281 | dm_table_destroy(t); |
1282 | dm_unlock_md_type(md); | ||
1279 | r = -EINVAL; | 1283 | r = -EINVAL; |
1280 | goto out; | 1284 | goto out; |
1281 | } | 1285 | } |
1282 | 1286 | ||
1283 | /* Protect md->type and md->queue against concurrent table loads. */ | ||
1284 | dm_lock_md_type(md); | ||
1285 | if (dm_get_md_type(md) == DM_TYPE_NONE) | 1287 | if (dm_get_md_type(md) == DM_TYPE_NONE) |
1286 | /* Initial table load: acquire type of table. */ | 1288 | /* Initial table load: acquire type of table. */ |
1287 | dm_set_md_type(md, dm_table_get_type(t)); | 1289 | dm_set_md_type(md, dm_table_get_type(t)); |
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index f309477d7efe..8f8783533ac7 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c | |||
@@ -888,9 +888,7 @@ static int dm_table_set_type(struct dm_table *t) | |||
888 | * Determine the type from the live device. | 888 | * Determine the type from the live device. |
889 | * Default to bio-based if device is new. | 889 | * Default to bio-based if device is new. |
890 | */ | 890 | */ |
891 | dm_lock_md_type(t->md); | ||
892 | live_md_type = dm_get_md_type(t->md); | 891 | live_md_type = dm_get_md_type(t->md); |
893 | dm_unlock_md_type(t->md); | ||
894 | if (live_md_type == DM_TYPE_REQUEST_BASED) | 892 | if (live_md_type == DM_TYPE_REQUEST_BASED) |
895 | request_based = 1; | 893 | request_based = 1; |
896 | else | 894 | else |
diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ef095a96d039..7faeaa3d4835 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c | |||
@@ -2235,11 +2235,13 @@ void dm_unlock_md_type(struct mapped_device *md) | |||
2235 | 2235 | ||
2236 | void dm_set_md_type(struct mapped_device *md, unsigned type) | 2236 | void dm_set_md_type(struct mapped_device *md, unsigned type) |
2237 | { | 2237 | { |
2238 | BUG_ON(!mutex_is_locked(&md->type_lock)); | ||
2238 | md->type = type; | 2239 | md->type = type; |
2239 | } | 2240 | } |
2240 | 2241 | ||
2241 | unsigned dm_get_md_type(struct mapped_device *md) | 2242 | unsigned dm_get_md_type(struct mapped_device *md) |
2242 | { | 2243 | { |
2244 | BUG_ON(!mutex_is_locked(&md->type_lock)); | ||
2243 | return md->type; | 2245 | return md->type; |
2244 | } | 2246 | } |
2245 | 2247 | ||