diff options
author | Namhyung Kim <namhyung@gmail.com> | 2011-07-26 21:00:36 -0400 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-07-26 21:00:36 -0400 |
commit | 36fad858a7404a9656122a9e560a224ae2a00979 (patch) | |
tree | 95f8a7a6b8dad6bb8d7c7735f7845888b5e702db /drivers/md/md.c | |
parent | 8bda470e8ebde35f9349e98ecbce4dfb508a60fa (diff) |
md: introduce link/unlink_rdev() helpers
There are places where sysfs links to rdev are handled
in a same way. Add the helper functions to consolidate
them.
Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md/md.c')
-rw-r--r-- | drivers/md/md.c | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/drivers/md/md.c b/drivers/md/md.c index 91e31e260b4a..0398dc42a956 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c | |||
@@ -2459,7 +2459,6 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) | |||
2459 | { | 2459 | { |
2460 | char *e; | 2460 | char *e; |
2461 | int err; | 2461 | int err; |
2462 | char nm[20]; | ||
2463 | int slot = simple_strtoul(buf, &e, 10); | 2462 | int slot = simple_strtoul(buf, &e, 10); |
2464 | if (strncmp(buf, "none", 4)==0) | 2463 | if (strncmp(buf, "none", 4)==0) |
2465 | slot = -1; | 2464 | slot = -1; |
@@ -2482,8 +2481,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) | |||
2482 | hot_remove_disk(rdev->mddev, rdev->raid_disk); | 2481 | hot_remove_disk(rdev->mddev, rdev->raid_disk); |
2483 | if (err) | 2482 | if (err) |
2484 | return err; | 2483 | return err; |
2485 | sprintf(nm, "rd%d", rdev->raid_disk); | 2484 | sysfs_unlink_rdev(rdev->mddev, rdev); |
2486 | sysfs_remove_link(&rdev->mddev->kobj, nm); | ||
2487 | rdev->raid_disk = -1; | 2485 | rdev->raid_disk = -1; |
2488 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); | 2486 | set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery); |
2489 | md_wakeup_thread(rdev->mddev->thread); | 2487 | md_wakeup_thread(rdev->mddev->thread); |
@@ -2522,8 +2520,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) | |||
2522 | return err; | 2520 | return err; |
2523 | } else | 2521 | } else |
2524 | sysfs_notify_dirent_safe(rdev->sysfs_state); | 2522 | sysfs_notify_dirent_safe(rdev->sysfs_state); |
2525 | sprintf(nm, "rd%d", rdev->raid_disk); | 2523 | if (sysfs_link_rdev(rdev->mddev, rdev)) |
2526 | if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) | ||
2527 | /* failure here is OK */; | 2524 | /* failure here is OK */; |
2528 | /* don't wakeup anyone, leave that to userspace. */ | 2525 | /* don't wakeup anyone, leave that to userspace. */ |
2529 | } else { | 2526 | } else { |
@@ -3149,15 +3146,13 @@ level_store(mddev_t *mddev, const char *buf, size_t len) | |||
3149 | } | 3146 | } |
3150 | 3147 | ||
3151 | list_for_each_entry(rdev, &mddev->disks, same_set) { | 3148 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
3152 | char nm[20]; | ||
3153 | if (rdev->raid_disk < 0) | 3149 | if (rdev->raid_disk < 0) |
3154 | continue; | 3150 | continue; |
3155 | if (rdev->new_raid_disk >= mddev->raid_disks) | 3151 | if (rdev->new_raid_disk >= mddev->raid_disks) |
3156 | rdev->new_raid_disk = -1; | 3152 | rdev->new_raid_disk = -1; |
3157 | if (rdev->new_raid_disk == rdev->raid_disk) | 3153 | if (rdev->new_raid_disk == rdev->raid_disk) |
3158 | continue; | 3154 | continue; |
3159 | sprintf(nm, "rd%d", rdev->raid_disk); | 3155 | sysfs_unlink_rdev(mddev, rdev); |
3160 | sysfs_remove_link(&mddev->kobj, nm); | ||
3161 | } | 3156 | } |
3162 | list_for_each_entry(rdev, &mddev->disks, same_set) { | 3157 | list_for_each_entry(rdev, &mddev->disks, same_set) { |
3163 | if (rdev->raid_disk < 0) | 3158 | if (rdev->raid_disk < 0) |
@@ -3168,11 +3163,10 @@ level_store(mddev_t *mddev, const char *buf, size_t len) | |||
3168 | if (rdev->raid_disk < 0) | 3163 | if (rdev->raid_disk < 0) |
3169 | clear_bit(In_sync, &rdev->flags); | 3164 | clear_bit(In_sync, &rdev->flags); |
3170 | else { | 3165 | else { |
3171 | char nm[20]; | 3166 | if (sysfs_link_rdev(mddev, rdev)) |
3172 | sprintf(nm, "rd%d", rdev->raid_disk); | 3167 | printk(KERN_WARNING "md: cannot register rd%d" |
3173 | if(sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) | 3168 | " for %s after level change\n", |
3174 | printk("md: cannot register %s for %s after level change\n", | 3169 | rdev->raid_disk, mdname(mddev)); |
3175 | nm, mdname(mddev)); | ||
3176 | } | 3170 | } |
3177 | } | 3171 | } |
3178 | 3172 | ||
@@ -4621,12 +4615,9 @@ int md_run(mddev_t *mddev) | |||
4621 | smp_wmb(); | 4615 | smp_wmb(); |
4622 | mddev->ready = 1; | 4616 | mddev->ready = 1; |
4623 | list_for_each_entry(rdev, &mddev->disks, same_set) | 4617 | list_for_each_entry(rdev, &mddev->disks, same_set) |
4624 | if (rdev->raid_disk >= 0) { | 4618 | if (rdev->raid_disk >= 0) |
4625 | char nm[20]; | 4619 | if (sysfs_link_rdev(mddev, rdev)) |
4626 | sprintf(nm, "rd%d", rdev->raid_disk); | ||
4627 | if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm)) | ||
4628 | /* failure here is OK */; | 4620 | /* failure here is OK */; |
4629 | } | ||
4630 | 4621 | ||
4631 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); | 4622 | set_bit(MD_RECOVERY_NEEDED, &mddev->recovery); |
4632 | 4623 | ||
@@ -4854,11 +4845,8 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open) | |||
4854 | sysfs_notify_dirent_safe(mddev->sysfs_state); | 4845 | sysfs_notify_dirent_safe(mddev->sysfs_state); |
4855 | 4846 | ||
4856 | list_for_each_entry(rdev, &mddev->disks, same_set) | 4847 | list_for_each_entry(rdev, &mddev->disks, same_set) |
4857 | if (rdev->raid_disk >= 0) { | 4848 | if (rdev->raid_disk >= 0) |
4858 | char nm[20]; | 4849 | sysfs_unlink_rdev(mddev, rdev); |
4859 | sprintf(nm, "rd%d", rdev->raid_disk); | ||
4860 | sysfs_remove_link(&mddev->kobj, nm); | ||
4861 | } | ||
4862 | 4850 | ||
4863 | set_capacity(disk, 0); | 4851 | set_capacity(disk, 0); |
4864 | mutex_unlock(&mddev->open_mutex); | 4852 | mutex_unlock(&mddev->open_mutex); |
@@ -7077,9 +7065,7 @@ static int remove_and_add_spares(mddev_t *mddev) | |||
7077 | atomic_read(&rdev->nr_pending)==0) { | 7065 | atomic_read(&rdev->nr_pending)==0) { |
7078 | if (mddev->pers->hot_remove_disk( | 7066 | if (mddev->pers->hot_remove_disk( |
7079 | mddev, rdev->raid_disk)==0) { | 7067 | mddev, rdev->raid_disk)==0) { |
7080 | char nm[20]; | 7068 | sysfs_unlink_rdev(mddev, rdev); |
7081 | sprintf(nm,"rd%d", rdev->raid_disk); | ||
7082 | sysfs_remove_link(&mddev->kobj, nm); | ||
7083 | rdev->raid_disk = -1; | 7069 | rdev->raid_disk = -1; |
7084 | } | 7070 | } |
7085 | } | 7071 | } |
@@ -7096,10 +7082,7 @@ static int remove_and_add_spares(mddev_t *mddev) | |||
7096 | rdev->recovery_offset = 0; | 7082 | rdev->recovery_offset = 0; |
7097 | if (mddev->pers-> | 7083 | if (mddev->pers-> |
7098 | hot_add_disk(mddev, rdev) == 0) { | 7084 | hot_add_disk(mddev, rdev) == 0) { |
7099 | char nm[20]; | 7085 | if (sysfs_link_rdev(mddev, rdev)) |
7100 | sprintf(nm, "rd%d", rdev->raid_disk); | ||
7101 | if (sysfs_create_link(&mddev->kobj, | ||
7102 | &rdev->kobj, nm)) | ||
7103 | /* failure here is OK */; | 7086 | /* failure here is OK */; |
7104 | spares++; | 7087 | spares++; |
7105 | md_new_event(mddev); | 7088 | md_new_event(mddev); |
@@ -7219,9 +7202,7 @@ void md_check_recovery(mddev_t *mddev) | |||
7219 | atomic_read(&rdev->nr_pending)==0) { | 7202 | atomic_read(&rdev->nr_pending)==0) { |
7220 | if (mddev->pers->hot_remove_disk( | 7203 | if (mddev->pers->hot_remove_disk( |
7221 | mddev, rdev->raid_disk)==0) { | 7204 | mddev, rdev->raid_disk)==0) { |
7222 | char nm[20]; | 7205 | sysfs_unlink_rdev(mddev, rdev); |
7223 | sprintf(nm,"rd%d", rdev->raid_disk); | ||
7224 | sysfs_remove_link(&mddev->kobj, nm); | ||
7225 | rdev->raid_disk = -1; | 7206 | rdev->raid_disk = -1; |
7226 | } | 7207 | } |
7227 | } | 7208 | } |