Commit 3c0ee63a authored by NeilBrown's avatar NeilBrown

md: use sysfs_notify_dirent to notify changes to md/dev-xxx/state

The 'state' file for a device reports, for example, when the device
has failed.  Changes should be reported to userspace ASAP without
the possibility of blocking on low-memory.  sysfs_notify does
have that possibility (as it takes a mutex which can be held
across a kmalloc) so use sysfs_notify_dirent instead.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent b62b7590
...@@ -1462,6 +1462,8 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) ...@@ -1462,6 +1462,8 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
kobject_del(&rdev->kobj); kobject_del(&rdev->kobj);
goto fail; goto fail;
} }
rdev->sysfs_state = sysfs_get_dirent(rdev->kobj.sd, "state");
list_add_rcu(&rdev->same_set, &mddev->disks); list_add_rcu(&rdev->same_set, &mddev->disks);
bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk); bd_claim_by_disk(rdev->bdev, rdev->bdev->bd_holder, mddev->gendisk);
return 0; return 0;
...@@ -1491,7 +1493,8 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev) ...@@ -1491,7 +1493,8 @@ static void unbind_rdev_from_array(mdk_rdev_t * rdev)
printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b)); printk(KERN_INFO "md: unbind<%s>\n", bdevname(rdev->bdev,b));
rdev->mddev = NULL; rdev->mddev = NULL;
sysfs_remove_link(&rdev->kobj, "block"); sysfs_remove_link(&rdev->kobj, "block");
sysfs_put(rdev->sysfs_state);
rdev->sysfs_state = NULL;
/* We need to delay this, otherwise we can deadlock when /* We need to delay this, otherwise we can deadlock when
* writing to 'remove' to "dev/state". We also need * writing to 'remove' to "dev/state". We also need
* to delay it due to rcu usage. * to delay it due to rcu usage.
...@@ -1926,8 +1929,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len) ...@@ -1926,8 +1929,8 @@ state_store(mdk_rdev_t *rdev, const char *buf, size_t len)
err = 0; err = 0;
} }
if (!err) if (!err && rdev->sysfs_state)
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
return err ? err : len; return err ? err : len;
} }
static struct rdev_sysfs_entry rdev_state = static struct rdev_sysfs_entry rdev_state =
...@@ -2022,7 +2025,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) ...@@ -2022,7 +2025,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
rdev->raid_disk = -1; rdev->raid_disk = -1;
return err; return err;
} else } else
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
sprintf(nm, "rd%d", rdev->raid_disk); sprintf(nm, "rd%d", rdev->raid_disk);
if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm)) if (sysfs_create_link(&rdev->mddev->kobj, &rdev->kobj, nm))
printk(KERN_WARNING printk(KERN_WARNING
...@@ -2039,7 +2042,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len) ...@@ -2039,7 +2042,7 @@ slot_store(mdk_rdev_t *rdev, const char *buf, size_t len)
clear_bit(Faulty, &rdev->flags); clear_bit(Faulty, &rdev->flags);
clear_bit(WriteMostly, &rdev->flags); clear_bit(WriteMostly, &rdev->flags);
set_bit(In_sync, &rdev->flags); set_bit(In_sync, &rdev->flags);
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
} }
return len; return len;
} }
...@@ -3583,7 +3586,7 @@ static int do_md_run(mddev_t * mddev) ...@@ -3583,7 +3586,7 @@ static int do_md_run(mddev_t * mddev)
return -EINVAL; return -EINVAL;
} }
} }
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
} }
md_probe(mddev->unit, NULL, NULL); md_probe(mddev->unit, NULL, NULL);
...@@ -4302,7 +4305,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info) ...@@ -4302,7 +4305,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
if (err) if (err)
export_rdev(rdev); export_rdev(rdev);
else else
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
md_update_sb(mddev, 1); md_update_sb(mddev, 1);
if (mddev->degraded) if (mddev->degraded)
...@@ -6113,7 +6116,7 @@ void md_check_recovery(mddev_t *mddev) ...@@ -6113,7 +6116,7 @@ void md_check_recovery(mddev_t *mddev)
rdev_for_each(rdev, rtmp, mddev) rdev_for_each(rdev, rtmp, mddev)
if (test_and_clear_bit(StateChanged, &rdev->flags)) if (test_and_clear_bit(StateChanged, &rdev->flags))
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) && if (test_bit(MD_RECOVERY_RUNNING, &mddev->recovery) &&
...@@ -6223,7 +6226,7 @@ void md_check_recovery(mddev_t *mddev) ...@@ -6223,7 +6226,7 @@ void md_check_recovery(mddev_t *mddev)
void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev) void md_wait_for_blocked_rdev(mdk_rdev_t *rdev, mddev_t *mddev)
{ {
sysfs_notify(&rdev->kobj, NULL, "state"); sysfs_notify_dirent(rdev->sysfs_state);
wait_event_timeout(rdev->blocked_wait, wait_event_timeout(rdev->blocked_wait,
!test_bit(Blocked, &rdev->flags), !test_bit(Blocked, &rdev->flags),
msecs_to_jiffies(5000)); msecs_to_jiffies(5000));
......
...@@ -115,6 +115,9 @@ struct mdk_rdev_s ...@@ -115,6 +115,9 @@ struct mdk_rdev_s
* in superblock. * in superblock.
*/ */
struct work_struct del_work; /* used for delayed sysfs removal */ struct work_struct del_work; /* used for delayed sysfs removal */
struct sysfs_dirent *sysfs_state; /* handle for 'state'
* sysfs entry */
}; };
struct mddev_s struct mddev_s
......
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