Commit b60f0c2b authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] md_import_device() cleanup

	* md_import_device() returns resulting rdev or ERR_PTR(error)
instead of returning 0 or error an letting caller find rdev.
parent 881c3bc1
...@@ -1001,19 +1001,19 @@ void md_update_sb(mddev_t *mddev) ...@@ -1001,19 +1001,19 @@ void md_update_sb(mddev_t *mddev)
* *
* a faulty rdev _never_ has rdev->sb set. * a faulty rdev _never_ has rdev->sb set.
*/ */
static int md_import_device(kdev_t newdev, int on_disk) static mdk_rdev_t *md_import_device(kdev_t newdev, int on_disk)
{ {
int err; int err;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
unsigned int size; unsigned int size;
if (find_rdev_all(newdev)) if (find_rdev_all(newdev))
return -EEXIST; return ERR_PTR(-EEXIST);
rdev = (mdk_rdev_t *) kmalloc(sizeof(*rdev), GFP_KERNEL); rdev = (mdk_rdev_t *) kmalloc(sizeof(*rdev), GFP_KERNEL);
if (!rdev) { if (!rdev) {
printk(KERN_ERR "md: could not alloc mem for %s!\n", partition_name(newdev)); printk(KERN_ERR "md: could not alloc mem for %s!\n", partition_name(newdev));
return -ENOMEM; return ERR_PTR(-ENOMEM);
} }
memset(rdev, 0, sizeof(*rdev)); memset(rdev, 0, sizeof(*rdev));
...@@ -1066,7 +1066,7 @@ static int md_import_device(kdev_t newdev, int on_disk) ...@@ -1066,7 +1066,7 @@ static int md_import_device(kdev_t newdev, int on_disk)
if (rdev->faulty && rdev->sb) if (rdev->faulty && rdev->sb)
free_disk_sb(rdev); free_disk_sb(rdev);
return 0; return rdev;
abort_free: abort_free:
if (rdev->sb) { if (rdev->sb) {
...@@ -1075,7 +1075,7 @@ static int md_import_device(kdev_t newdev, int on_disk) ...@@ -1075,7 +1075,7 @@ static int md_import_device(kdev_t newdev, int on_disk)
free_disk_sb(rdev); free_disk_sb(rdev);
} }
kfree(rdev); kfree(rdev);
return err; return ERR_PTR(err);
} }
/* /*
...@@ -1950,16 +1950,12 @@ static int autostart_array(kdev_t startdev) ...@@ -1950,16 +1950,12 @@ static int autostart_array(kdev_t startdev)
mdp_super_t *sb = NULL; mdp_super_t *sb = NULL;
mdk_rdev_t *start_rdev = NULL, *rdev; mdk_rdev_t *start_rdev = NULL, *rdev;
if (md_import_device(startdev, 1)) { start_rdev = md_import_device(startdev, 1);
if (IS_ERR(start_rdev)) {
printk(KERN_WARNING "md: could not import %s!\n", partition_name(startdev)); printk(KERN_WARNING "md: could not import %s!\n", partition_name(startdev));
goto abort; goto abort;
} }
start_rdev = find_rdev_all(startdev);
if (!start_rdev) {
MD_BUG();
goto abort;
}
if (start_rdev->faulty) { if (start_rdev->faulty) {
printk(KERN_WARNING "md: can not autostart based on faulty %s!\n", printk(KERN_WARNING "md: can not autostart based on faulty %s!\n",
partition_name(startdev)); partition_name(startdev));
...@@ -1988,16 +1984,12 @@ static int autostart_array(kdev_t startdev) ...@@ -1988,16 +1984,12 @@ static int autostart_array(kdev_t startdev)
continue; continue;
if (kdev_same(dev, startdev)) if (kdev_same(dev, startdev))
continue; continue;
if (md_import_device(dev, 1)) { rdev = md_import_device(dev, 1);
if (IS_ERR(rdev)) {
printk(KERN_WARNING "md: could not import %s, trying to run array nevertheless.\n", printk(KERN_WARNING "md: could not import %s, trying to run array nevertheless.\n",
partition_name(dev)); partition_name(dev));
continue; continue;
} }
rdev = find_rdev_all(dev);
if (!rdev) {
MD_BUG();
goto abort;
}
list_add(&rdev->pending, &pending_raid_disks); list_add(&rdev->pending, &pending_raid_disks);
} }
...@@ -2107,7 +2099,7 @@ static int get_disk_info(mddev_t * mddev, void * arg) ...@@ -2107,7 +2099,7 @@ static int get_disk_info(mddev_t * mddev, void * arg)
static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
{ {
int err, size, persistent; int size, persistent;
mdk_rdev_t *rdev; mdk_rdev_t *rdev;
unsigned int nr; unsigned int nr;
kdev_t dev; kdev_t dev;
...@@ -2120,14 +2112,9 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) ...@@ -2120,14 +2112,9 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
} }
if (!mddev->sb) { if (!mddev->sb) {
/* expecting a device which has a superblock */ /* expecting a device which has a superblock */
err = md_import_device(dev, 1); rdev = md_import_device(dev, 1);
if (err) { if (IS_ERR(rdev)) {
printk(KERN_WARNING "md: md_import_device returned %d\n", err); printk(KERN_WARNING "md: md_import_device returned %ld\n", PTR_ERR(rdev));
return -EINVAL;
}
rdev = find_rdev_all(dev);
if (!rdev) {
MD_BUG();
return -EINVAL; return -EINVAL;
} }
if (!list_empty(&mddev->disks)) { if (!list_empty(&mddev->disks)) {
...@@ -2164,17 +2151,11 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) ...@@ -2164,17 +2151,11 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
SET_SB(state); SET_SB(state);
if (!(info->state & (1<<MD_DISK_FAULTY))) { if (!(info->state & (1<<MD_DISK_FAULTY))) {
err = md_import_device (dev, 0); rdev = md_import_device (dev, 0);
if (err) { if (IS_ERR(rdev)) {
printk(KERN_WARNING "md: error, md_import_device() returned %d\n", err); printk(KERN_WARNING "md: error, md_import_device() returned %ld\n", PTR_ERR(rdev));
return -EINVAL; return -EINVAL;
} }
rdev = find_rdev_all(dev);
if (!rdev) {
MD_BUG();
return -EINVAL;
}
rdev->old_dev = dev; rdev->old_dev = dev;
rdev->desc_nr = info->number; rdev->desc_nr = info->number;
...@@ -2317,17 +2298,11 @@ static int hot_add_disk(mddev_t * mddev, kdev_t dev) ...@@ -2317,17 +2298,11 @@ static int hot_add_disk(mddev_t * mddev, kdev_t dev)
if (rdev) if (rdev)
return -EBUSY; return -EBUSY;
err = md_import_device (dev, 0); rdev = md_import_device (dev, 0);
if (err) { if (IS_ERR(rdev)) {
printk(KERN_WARNING "md: error, md_import_device() returned %d\n", err); printk(KERN_WARNING "md: error, md_import_device() returned %ld\n", PTR_ERR(rdev));
return -EINVAL;
}
rdev = find_rdev_all(dev);
if (!rdev) {
MD_BUG();
return -EINVAL; return -EINVAL;
} }
persistent = !mddev->sb->not_persistent; persistent = !mddev->sb->not_persistent;
size = calc_dev_size(rdev, mddev, persistent); size = calc_dev_size(rdev, mddev, persistent);
...@@ -3594,19 +3569,12 @@ static void autostart_arrays(void) ...@@ -3594,19 +3569,12 @@ static void autostart_arrays(void)
for (i = 0; i < dev_cnt; i++) { for (i = 0; i < dev_cnt; i++) {
kdev_t dev = detected_devices[i]; kdev_t dev = detected_devices[i];
if (md_import_device(dev,1)) { rdev = md_import_device(dev,1);
if (IS_ERR(rdev)) {
printk(KERN_ALERT "md: could not import %s!\n", printk(KERN_ALERT "md: could not import %s!\n",
partition_name(dev)); partition_name(dev));
continue; continue;
} }
/*
* Sanity checks:
*/
rdev = find_rdev_all(dev);
if (!rdev) {
MD_BUG();
continue;
}
if (rdev->faulty) { if (rdev->faulty) {
MD_BUG(); MD_BUG();
continue; continue;
......
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