提交 00c4fc3b 编写于 作者: M Mike Snitzer

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: NMike Snitzer <snitzer@redhat.com>
Signed-off-by: NAlasdair G Kergon <agk@redhat.com>
上级 c2b04824
...@@ -1264,9 +1264,12 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1264,9 +1264,12 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
if (r) if (r)
goto out; goto out;
/* Protect md->type and md->queue against concurrent table loads. */
dm_lock_md_type(md);
r = populate_table(t, param, param_size); r = populate_table(t, param, param_size);
if (r) { if (r) {
dm_table_destroy(t); dm_table_destroy(t);
dm_unlock_md_type(md);
goto out; goto out;
} }
...@@ -1276,12 +1279,11 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1276,12 +1279,11 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
DMWARN("can't replace immutable target type %s", DMWARN("can't replace immutable target type %s",
immutable_target_type->name); immutable_target_type->name);
dm_table_destroy(t); dm_table_destroy(t);
dm_unlock_md_type(md);
r = -EINVAL; r = -EINVAL;
goto out; goto out;
} }
/* Protect md->type and md->queue against concurrent table loads. */
dm_lock_md_type(md);
if (dm_get_md_type(md) == DM_TYPE_NONE) if (dm_get_md_type(md) == DM_TYPE_NONE)
/* Initial table load: acquire type of table. */ /* Initial table load: acquire type of table. */
dm_set_md_type(md, dm_table_get_type(t)); dm_set_md_type(md, dm_table_get_type(t));
......
...@@ -888,9 +888,7 @@ static int dm_table_set_type(struct dm_table *t) ...@@ -888,9 +888,7 @@ static int dm_table_set_type(struct dm_table *t)
* Determine the type from the live device. * Determine the type from the live device.
* Default to bio-based if device is new. * Default to bio-based if device is new.
*/ */
dm_lock_md_type(t->md);
live_md_type = dm_get_md_type(t->md); live_md_type = dm_get_md_type(t->md);
dm_unlock_md_type(t->md);
if (live_md_type == DM_TYPE_REQUEST_BASED) if (live_md_type == DM_TYPE_REQUEST_BASED)
request_based = 1; request_based = 1;
else else
......
...@@ -2235,11 +2235,13 @@ void dm_unlock_md_type(struct mapped_device *md) ...@@ -2235,11 +2235,13 @@ void dm_unlock_md_type(struct mapped_device *md)
void dm_set_md_type(struct mapped_device *md, unsigned type) void dm_set_md_type(struct mapped_device *md, unsigned type)
{ {
BUG_ON(!mutex_is_locked(&md->type_lock));
md->type = type; md->type = type;
} }
unsigned dm_get_md_type(struct mapped_device *md) unsigned dm_get_md_type(struct mapped_device *md)
{ {
BUG_ON(!mutex_is_locked(&md->type_lock));
return md->type; return md->type;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册