diff options
author | Mike Snitzer <snitzer@redhat.com> | 2013-08-27 20:03:00 -0400 |
---|---|---|
committer | Mike Snitzer <snitzer@redhat.com> | 2013-09-05 20:46:06 -0400 |
commit | f11c1c5693fac339d412b0b59b54693ddcb776ff (patch) | |
tree | b38fbde0a4d8bdeb1341dc65c60d736c7b74254a /drivers/md/dm-ioctl.c | |
parent | 00c4fc3b1f590288cb3c42f36da50f49a513cfcf (diff) |
dm ioctl: cleanup error handling in table_load
Make use of common cleanup code.
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm-ioctl.c')
-rw-r--r-- | drivers/md/dm-ioctl.c | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c index 42cca3642010..e9c0de75010e 100644 --- a/drivers/md/dm-ioctl.c +++ b/drivers/md/dm-ioctl.c | |||
@@ -1262,26 +1262,21 @@ static int table_load(struct dm_ioctl *param, size_t param_size) | |||
1262 | 1262 | ||
1263 | r = dm_table_create(&t, get_mode(param), param->target_count, md); | 1263 | r = dm_table_create(&t, get_mode(param), param->target_count, md); |
1264 | if (r) | 1264 | if (r) |
1265 | goto out; | 1265 | goto err; |
1266 | 1266 | ||
1267 | /* Protect md->type and md->queue against concurrent table loads. */ | 1267 | /* Protect md->type and md->queue against concurrent table loads. */ |
1268 | dm_lock_md_type(md); | 1268 | dm_lock_md_type(md); |
1269 | r = populate_table(t, param, param_size); | 1269 | r = populate_table(t, param, param_size); |
1270 | if (r) { | 1270 | if (r) |
1271 | dm_table_destroy(t); | 1271 | goto err_unlock_md_type; |
1272 | dm_unlock_md_type(md); | ||
1273 | goto out; | ||
1274 | } | ||
1275 | 1272 | ||
1276 | immutable_target_type = dm_get_immutable_target_type(md); | 1273 | immutable_target_type = dm_get_immutable_target_type(md); |
1277 | if (immutable_target_type && | 1274 | if (immutable_target_type && |
1278 | (immutable_target_type != dm_table_get_immutable_target_type(t))) { | 1275 | (immutable_target_type != dm_table_get_immutable_target_type(t))) { |
1279 | DMWARN("can't replace immutable target type %s", | 1276 | DMWARN("can't replace immutable target type %s", |
1280 | immutable_target_type->name); | 1277 | immutable_target_type->name); |
1281 | dm_table_destroy(t); | ||
1282 | dm_unlock_md_type(md); | ||
1283 | r = -EINVAL; | 1278 | r = -EINVAL; |
1284 | goto out; | 1279 | goto err_unlock_md_type; |
1285 | } | 1280 | } |
1286 | 1281 | ||
1287 | if (dm_get_md_type(md) == DM_TYPE_NONE) | 1282 | 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 | dm_set_md_type(md, dm_table_get_type(t)); | 1284 | dm_set_md_type(md, dm_table_get_type(t)); |
1290 | else if (dm_get_md_type(md) != dm_table_get_type(t)) { | 1285 | else if (dm_get_md_type(md) != dm_table_get_type(t)) { |
1291 | DMWARN("can't change device type after initial table load."); | 1286 | DMWARN("can't change device type after initial table load."); |
1292 | dm_table_destroy(t); | ||
1293 | dm_unlock_md_type(md); | ||
1294 | r = -EINVAL; | 1287 | r = -EINVAL; |
1295 | goto out; | 1288 | goto err_unlock_md_type; |
1296 | } | 1289 | } |
1297 | 1290 | ||
1298 | /* setup md->queue to reflect md's type (may block) */ | 1291 | /* setup md->queue to reflect md's type (may block) */ |
1299 | r = dm_setup_md_queue(md); | 1292 | r = dm_setup_md_queue(md); |
1300 | if (r) { | 1293 | if (r) { |
1301 | DMWARN("unable to set up device queue for new table."); | 1294 | DMWARN("unable to set up device queue for new table."); |
1302 | dm_table_destroy(t); | 1295 | goto err_unlock_md_type; |
1303 | dm_unlock_md_type(md); | ||
1304 | goto out; | ||
1305 | } | 1296 | } |
1306 | dm_unlock_md_type(md); | 1297 | dm_unlock_md_type(md); |
1307 | 1298 | ||
@@ -1311,9 +1302,8 @@ static int table_load(struct dm_ioctl *param, size_t param_size) | |||
1311 | if (!hc || hc->md != md) { | 1302 | if (!hc || hc->md != md) { |
1312 | DMWARN("device has been removed from the dev hash table."); | 1303 | DMWARN("device has been removed from the dev hash table."); |
1313 | up_write(&_hash_lock); | 1304 | up_write(&_hash_lock); |
1314 | dm_table_destroy(t); | ||
1315 | r = -ENXIO; | 1305 | r = -ENXIO; |
1316 | goto out; | 1306 | goto err_destroy_table; |
1317 | } | 1307 | } |
1318 | 1308 | ||
1319 | if (hc->new_map) | 1309 | if (hc->new_map) |
@@ -1324,7 +1314,6 @@ static int table_load(struct dm_ioctl *param, size_t param_size) | |||
1324 | param->flags |= DM_INACTIVE_PRESENT_FLAG; | 1314 | param->flags |= DM_INACTIVE_PRESENT_FLAG; |
1325 | __dev_status(md, param); | 1315 | __dev_status(md, param); |
1326 | 1316 | ||
1327 | out: | ||
1328 | if (old_map) { | 1317 | if (old_map) { |
1329 | dm_sync_table(md); | 1318 | dm_sync_table(md); |
1330 | dm_table_destroy(old_map); | 1319 | dm_table_destroy(old_map); |
@@ -1332,6 +1321,15 @@ out: | |||
1332 | 1321 | ||
1333 | dm_put(md); | 1322 | dm_put(md); |
1334 | 1323 | ||
1324 | return 0; | ||
1325 | |||
1326 | err_unlock_md_type: | ||
1327 | dm_unlock_md_type(md); | ||
1328 | err_destroy_table: | ||
1329 | dm_table_destroy(t); | ||
1330 | err: | ||
1331 | dm_put(md); | ||
1332 | |||
1335 | return r; | 1333 | return r; |
1336 | } | 1334 | } |
1337 | 1335 | ||