mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-19 15:39:07 +00:00
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>
This commit is contained in:
parent
8bda470e8e
commit
36fad858a7
@ -2459,7 +2459,6 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
|
|||||||
{
|
{
|
||||||
char *e;
|
char *e;
|
||||||
int err;
|
int err;
|
||||||
char nm[20];
|
|
||||||
int slot = simple_strtoul(buf, &e, 10);
|
int slot = simple_strtoul(buf, &e, 10);
|
||||||
if (strncmp(buf, "none", 4)==0)
|
if (strncmp(buf, "none", 4)==0)
|
||||||
slot = -1;
|
slot = -1;
|
||||||
@ -2482,8 +2481,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
|
|||||||
hot_remove_disk(rdev->mddev, rdev->raid_disk);
|
hot_remove_disk(rdev->mddev, rdev->raid_disk);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
sysfs_unlink_rdev(rdev->mddev, rdev);
|
||||||
sysfs_remove_link(&rdev->mddev->kobj, nm);
|
|
||||||
rdev->raid_disk = -1;
|
rdev->raid_disk = -1;
|
||||||
set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
|
set_bit(MD_RECOVERY_NEEDED, &rdev->mddev->recovery);
|
||||||
md_wakeup_thread(rdev->mddev->thread);
|
md_wakeup_thread(rdev->mddev->thread);
|
||||||
@ -2522,8 +2520,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
|
|||||||
return err;
|
return err;
|
||||||
} else
|
} else
|
||||||
sysfs_notify_dirent_safe(rdev->sysfs_state);
|
sysfs_notify_dirent_safe(rdev->sysfs_state);
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
if (sysfs_link_rdev(rdev->mddev, rdev))
|
||||||
if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
|
|
||||||
/* failure here is OK */;
|
/* failure here is OK */;
|
||||||
/* don't wakeup anyone, leave that to userspace. */
|
/* don't wakeup anyone, leave that to userspace. */
|
||||||
} else {
|
} else {
|
||||||
@ -3149,15 +3146,13 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
list_for_each_entry(rdev, &mddev->disks, same_set) {
|
list_for_each_entry(rdev, &mddev->disks, same_set) {
|
||||||
char nm[20];
|
|
||||||
if (rdev->raid_disk < 0)
|
if (rdev->raid_disk < 0)
|
||||||
continue;
|
continue;
|
||||||
if (rdev->new_raid_disk >= mddev->raid_disks)
|
if (rdev->new_raid_disk >= mddev->raid_disks)
|
||||||
rdev->new_raid_disk = -1;
|
rdev->new_raid_disk = -1;
|
||||||
if (rdev->new_raid_disk == rdev->raid_disk)
|
if (rdev->new_raid_disk == rdev->raid_disk)
|
||||||
continue;
|
continue;
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
|
||||||
}
|
}
|
||||||
list_for_each_entry(rdev, &mddev->disks, same_set) {
|
list_for_each_entry(rdev, &mddev->disks, same_set) {
|
||||||
if (rdev->raid_disk < 0)
|
if (rdev->raid_disk < 0)
|
||||||
@ -3168,11 +3163,10 @@ level_store(mddev_t *mddev, const char *buf, size_t len)
|
|||||||
if (rdev->raid_disk < 0)
|
if (rdev->raid_disk < 0)
|
||||||
clear_bit(In_sync, &rdev->flags);
|
clear_bit(In_sync, &rdev->flags);
|
||||||
else {
|
else {
|
||||||
char nm[20];
|
if (sysfs_link_rdev(mddev, rdev))
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
printk(KERN_WARNING "md: cannot register rd%d"
|
||||||
if(sysfs_create_link(&mddev->kobj, &rdev->kobj, nm))
|
" for %s after level change\n",
|
||||||
printk("md: cannot register %s for %s after level change\n",
|
rdev->raid_disk, mdname(mddev));
|
||||||
nm, mdname(mddev));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4621,12 +4615,9 @@ int md_run(mddev_t *mddev)
|
|||||||
smp_wmb();
|
smp_wmb();
|
||||||
mddev->ready = 1;
|
mddev->ready = 1;
|
||||||
list_for_each_entry(rdev, &mddev->disks, same_set)
|
list_for_each_entry(rdev, &mddev->disks, same_set)
|
||||||
if (rdev->raid_disk >= 0) {
|
if (rdev->raid_disk >= 0)
|
||||||
char nm[20];
|
if (sysfs_link_rdev(mddev, rdev))
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
|
||||||
if (sysfs_create_link(&mddev->kobj, &rdev->kobj, nm))
|
|
||||||
/* failure here is OK */;
|
/* failure here is OK */;
|
||||||
}
|
|
||||||
|
|
||||||
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
set_bit(MD_RECOVERY_NEEDED, &mddev->recovery);
|
||||||
|
|
||||||
@ -4854,11 +4845,8 @@ static int do_md_stop(mddev_t * mddev, int mode, int is_open)
|
|||||||
sysfs_notify_dirent_safe(mddev->sysfs_state);
|
sysfs_notify_dirent_safe(mddev->sysfs_state);
|
||||||
|
|
||||||
list_for_each_entry(rdev, &mddev->disks, same_set)
|
list_for_each_entry(rdev, &mddev->disks, same_set)
|
||||||
if (rdev->raid_disk >= 0) {
|
if (rdev->raid_disk >= 0)
|
||||||
char nm[20];
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
|
||||||
}
|
|
||||||
|
|
||||||
set_capacity(disk, 0);
|
set_capacity(disk, 0);
|
||||||
mutex_unlock(&mddev->open_mutex);
|
mutex_unlock(&mddev->open_mutex);
|
||||||
@ -7077,9 +7065,7 @@ static int remove_and_add_spares(mddev_t *mddev)
|
|||||||
atomic_read(&rdev->nr_pending)==0) {
|
atomic_read(&rdev->nr_pending)==0) {
|
||||||
if (mddev->pers->hot_remove_disk(
|
if (mddev->pers->hot_remove_disk(
|
||||||
mddev, rdev->raid_disk)==0) {
|
mddev, rdev->raid_disk)==0) {
|
||||||
char nm[20];
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sprintf(nm,"rd%d", rdev->raid_disk);
|
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
|
||||||
rdev->raid_disk = -1;
|
rdev->raid_disk = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7096,10 +7082,7 @@ static int remove_and_add_spares(mddev_t *mddev)
|
|||||||
rdev->recovery_offset = 0;
|
rdev->recovery_offset = 0;
|
||||||
if (mddev->pers->
|
if (mddev->pers->
|
||||||
hot_add_disk(mddev, rdev) == 0) {
|
hot_add_disk(mddev, rdev) == 0) {
|
||||||
char nm[20];
|
if (sysfs_link_rdev(mddev, rdev))
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
|
||||||
if (sysfs_create_link(&mddev->kobj,
|
|
||||||
&rdev->kobj, nm))
|
|
||||||
/* failure here is OK */;
|
/* failure here is OK */;
|
||||||
spares++;
|
spares++;
|
||||||
md_new_event(mddev);
|
md_new_event(mddev);
|
||||||
@ -7219,9 +7202,7 @@ void md_check_recovery(mddev_t *mddev)
|
|||||||
atomic_read(&rdev->nr_pending)==0) {
|
atomic_read(&rdev->nr_pending)==0) {
|
||||||
if (mddev->pers->hot_remove_disk(
|
if (mddev->pers->hot_remove_disk(
|
||||||
mddev, rdev->raid_disk)==0) {
|
mddev, rdev->raid_disk)==0) {
|
||||||
char nm[20];
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sprintf(nm,"rd%d", rdev->raid_disk);
|
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
|
||||||
rdev->raid_disk = -1;
|
rdev->raid_disk = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,6 +413,20 @@ static inline char * mdname (mddev_t * mddev)
|
|||||||
return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
|
return mddev->gendisk ? mddev->gendisk->disk_name : "mdX";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int sysfs_link_rdev(mddev_t *mddev, mdk_rdev_t *rdev)
|
||||||
|
{
|
||||||
|
char nm[20];
|
||||||
|
sprintf(nm, "rd%d", rdev->raid_disk);
|
||||||
|
return sysfs_create_link(&mddev->kobj, &rdev->kobj, nm);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void sysfs_unlink_rdev(mddev_t *mddev, mdk_rdev_t *rdev)
|
||||||
|
{
|
||||||
|
char nm[20];
|
||||||
|
sprintf(nm, "rd%d", rdev->raid_disk);
|
||||||
|
sysfs_remove_link(&mddev->kobj, nm);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iterates through some rdev ringlist. It's safe to remove the
|
* iterates through some rdev ringlist. It's safe to remove the
|
||||||
* current 'rdev'. Dont touch 'tmp' though.
|
* current 'rdev'. Dont touch 'tmp' though.
|
||||||
|
@ -2159,18 +2159,13 @@ static int raid1_reshape(mddev_t *mddev)
|
|||||||
for (d = d2 = 0; d < conf->raid_disks; d++) {
|
for (d = d2 = 0; d < conf->raid_disks; d++) {
|
||||||
mdk_rdev_t *rdev = conf->mirrors[d].rdev;
|
mdk_rdev_t *rdev = conf->mirrors[d].rdev;
|
||||||
if (rdev && rdev->raid_disk != d2) {
|
if (rdev && rdev->raid_disk != d2) {
|
||||||
char nm[20];
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
|
||||||
rdev->raid_disk = d2;
|
rdev->raid_disk = d2;
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
if (sysfs_link_rdev(mddev, rdev))
|
||||||
if (sysfs_create_link(&mddev->kobj,
|
|
||||||
&rdev->kobj, nm))
|
|
||||||
printk(KERN_WARNING
|
printk(KERN_WARNING
|
||||||
"md/raid1:%s: cannot register "
|
"md/raid1:%s: cannot register rd%d\n",
|
||||||
"%s\n",
|
mdname(mddev), rdev->raid_disk);
|
||||||
mdname(mddev), nm);
|
|
||||||
}
|
}
|
||||||
if (rdev)
|
if (rdev)
|
||||||
newmirrors[d2++].rdev = rdev;
|
newmirrors[d2++].rdev = rdev;
|
||||||
|
@ -5152,16 +5152,14 @@ static int raid5_start_reshape(mddev_t *mddev)
|
|||||||
if (rdev->raid_disk < 0 &&
|
if (rdev->raid_disk < 0 &&
|
||||||
!test_bit(Faulty, &rdev->flags)) {
|
!test_bit(Faulty, &rdev->flags)) {
|
||||||
if (raid5_add_disk(mddev, rdev) == 0) {
|
if (raid5_add_disk(mddev, rdev) == 0) {
|
||||||
char nm[20];
|
|
||||||
if (rdev->raid_disk
|
if (rdev->raid_disk
|
||||||
>= conf->previous_raid_disks) {
|
>= conf->previous_raid_disks) {
|
||||||
set_bit(In_sync, &rdev->flags);
|
set_bit(In_sync, &rdev->flags);
|
||||||
added_devices++;
|
added_devices++;
|
||||||
} else
|
} else
|
||||||
rdev->recovery_offset = 0;
|
rdev->recovery_offset = 0;
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
|
||||||
if (sysfs_create_link(&mddev->kobj,
|
if (sysfs_link_rdev(mddev, rdev))
|
||||||
&rdev->kobj, nm))
|
|
||||||
/* Failure here is OK */;
|
/* Failure here is OK */;
|
||||||
}
|
}
|
||||||
} else if (rdev->raid_disk >= conf->previous_raid_disks
|
} else if (rdev->raid_disk >= conf->previous_raid_disks
|
||||||
@ -5257,9 +5255,7 @@ static void raid5_finish_reshape(mddev_t *mddev)
|
|||||||
d++) {
|
d++) {
|
||||||
mdk_rdev_t *rdev = conf->disks[d].rdev;
|
mdk_rdev_t *rdev = conf->disks[d].rdev;
|
||||||
if (rdev && raid5_remove_disk(mddev, d) == 0) {
|
if (rdev && raid5_remove_disk(mddev, d) == 0) {
|
||||||
char nm[20];
|
sysfs_unlink_rdev(mddev, rdev);
|
||||||
sprintf(nm, "rd%d", rdev->raid_disk);
|
|
||||||
sysfs_remove_link(&mddev->kobj, nm);
|
|
||||||
rdev->raid_disk = -1;
|
rdev->raid_disk = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user