Commit f11c1c56 authored by Mike Snitzer's avatar Mike Snitzer

dm ioctl: cleanup error handling in table_load

Make use of common cleanup code.
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Signed-off-by: default avatarAlasdair G Kergon <agk@redhat.com>
parent 00c4fc3b
...@@ -1262,26 +1262,21 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1262,26 +1262,21 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
r = dm_table_create(&t, get_mode(param), param->target_count, md); r = dm_table_create(&t, get_mode(param), param->target_count, md);
if (r) if (r)
goto out; goto err;
/* Protect md->type and md->queue against concurrent table loads. */ /* Protect md->type and md->queue against concurrent table loads. */
dm_lock_md_type(md); 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); goto err_unlock_md_type;
dm_unlock_md_type(md);
goto out;
}
immutable_target_type = dm_get_immutable_target_type(md); immutable_target_type = dm_get_immutable_target_type(md);
if (immutable_target_type && if (immutable_target_type &&
(immutable_target_type != dm_table_get_immutable_target_type(t))) { (immutable_target_type != dm_table_get_immutable_target_type(t))) {
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_unlock_md_type(md);
r = -EINVAL; r = -EINVAL;
goto out; goto err_unlock_md_type;
} }
if (dm_get_md_type(md) == DM_TYPE_NONE) if (dm_get_md_type(md) == DM_TYPE_NONE)
...@@ -1289,19 +1284,15 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1289,19 +1284,15 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
dm_set_md_type(md, dm_table_get_type(t)); dm_set_md_type(md, dm_table_get_type(t));
else if (dm_get_md_type(md) != dm_table_get_type(t)) { else if (dm_get_md_type(md) != dm_table_get_type(t)) {
DMWARN("can't change device type after initial table load."); DMWARN("can't change device type after initial table load.");
dm_table_destroy(t);
dm_unlock_md_type(md);
r = -EINVAL; r = -EINVAL;
goto out; goto err_unlock_md_type;
} }
/* setup md->queue to reflect md's type (may block) */ /* setup md->queue to reflect md's type (may block) */
r = dm_setup_md_queue(md); r = dm_setup_md_queue(md);
if (r) { if (r) {
DMWARN("unable to set up device queue for new table."); DMWARN("unable to set up device queue for new table.");
dm_table_destroy(t); goto err_unlock_md_type;
dm_unlock_md_type(md);
goto out;
} }
dm_unlock_md_type(md); dm_unlock_md_type(md);
...@@ -1311,9 +1302,8 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1311,9 +1302,8 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
if (!hc || hc->md != md) { if (!hc || hc->md != md) {
DMWARN("device has been removed from the dev hash table."); DMWARN("device has been removed from the dev hash table.");
up_write(&_hash_lock); up_write(&_hash_lock);
dm_table_destroy(t);
r = -ENXIO; r = -ENXIO;
goto out; goto err_destroy_table;
} }
if (hc->new_map) if (hc->new_map)
...@@ -1324,7 +1314,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1324,7 +1314,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
param->flags |= DM_INACTIVE_PRESENT_FLAG; param->flags |= DM_INACTIVE_PRESENT_FLAG;
__dev_status(md, param); __dev_status(md, param);
out:
if (old_map) { if (old_map) {
dm_sync_table(md); dm_sync_table(md);
dm_table_destroy(old_map); dm_table_destroy(old_map);
...@@ -1332,6 +1321,15 @@ static int table_load(struct dm_ioctl *param, size_t param_size) ...@@ -1332,6 +1321,15 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
dm_put(md); dm_put(md);
return 0;
err_unlock_md_type:
dm_unlock_md_type(md);
err_destroy_table:
dm_table_destroy(t);
err:
dm_put(md);
return r; return r;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment