Commit 758bfc8a authored by NeilBrown's avatar NeilBrown

md: remove mddev_lock from rdev_attr_show()

No rdev attributes need locking for 'show', though
state_show() might benefit from ensuring it sees a
consistent set of flags.

None even use rdev->mddev, so testing for it isn't really
needed and it certainly doesn't need to be held constant.

So improve state_show() and remove the locking.
Signed-off-by: default avatarNeilBrown <neilb@suse.de>
parent b7b17c9b
...@@ -2419,40 +2419,41 @@ state_show(struct md_rdev *rdev, char *page) ...@@ -2419,40 +2419,41 @@ state_show(struct md_rdev *rdev, char *page)
{ {
char *sep = ""; char *sep = "";
size_t len = 0; size_t len = 0;
unsigned long flags = ACCESS_ONCE(rdev->flags);
if (test_bit(Faulty, &rdev->flags) || if (test_bit(Faulty, &flags) ||
rdev->badblocks.unacked_exist) { rdev->badblocks.unacked_exist) {
len+= sprintf(page+len, "%sfaulty",sep); len+= sprintf(page+len, "%sfaulty",sep);
sep = ","; sep = ",";
} }
if (test_bit(In_sync, &rdev->flags)) { if (test_bit(In_sync, &flags)) {
len += sprintf(page+len, "%sin_sync",sep); len += sprintf(page+len, "%sin_sync",sep);
sep = ","; sep = ",";
} }
if (test_bit(WriteMostly, &rdev->flags)) { if (test_bit(WriteMostly, &flags)) {
len += sprintf(page+len, "%swrite_mostly",sep); len += sprintf(page+len, "%swrite_mostly",sep);
sep = ","; sep = ",";
} }
if (test_bit(Blocked, &rdev->flags) || if (test_bit(Blocked, &flags) ||
(rdev->badblocks.unacked_exist (rdev->badblocks.unacked_exist
&& !test_bit(Faulty, &rdev->flags))) { && !test_bit(Faulty, &flags))) {
len += sprintf(page+len, "%sblocked", sep); len += sprintf(page+len, "%sblocked", sep);
sep = ","; sep = ",";
} }
if (!test_bit(Faulty, &rdev->flags) && if (!test_bit(Faulty, &flags) &&
!test_bit(In_sync, &rdev->flags)) { !test_bit(In_sync, &flags)) {
len += sprintf(page+len, "%sspare", sep); len += sprintf(page+len, "%sspare", sep);
sep = ","; sep = ",";
} }
if (test_bit(WriteErrorSeen, &rdev->flags)) { if (test_bit(WriteErrorSeen, &flags)) {
len += sprintf(page+len, "%swrite_error", sep); len += sprintf(page+len, "%swrite_error", sep);
sep = ","; sep = ",";
} }
if (test_bit(WantReplacement, &rdev->flags)) { if (test_bit(WantReplacement, &flags)) {
len += sprintf(page+len, "%swant_replacement", sep); len += sprintf(page+len, "%swant_replacement", sep);
sep = ","; sep = ",";
} }
if (test_bit(Replacement, &rdev->flags)) { if (test_bit(Replacement, &flags)) {
len += sprintf(page+len, "%sreplacement", sep); len += sprintf(page+len, "%sreplacement", sep);
sep = ","; sep = ",";
} }
...@@ -2965,21 +2966,12 @@ rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page) ...@@ -2965,21 +2966,12 @@ rdev_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
{ {
struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr); struct rdev_sysfs_entry *entry = container_of(attr, struct rdev_sysfs_entry, attr);
struct md_rdev *rdev = container_of(kobj, struct md_rdev, kobj); struct md_rdev *rdev = container_of(kobj, struct md_rdev, kobj);
struct mddev *mddev = rdev->mddev;
ssize_t rv;
if (!entry->show) if (!entry->show)
return -EIO; return -EIO;
if (!rdev->mddev)
rv = mddev ? mddev_lock(mddev) : -EBUSY; return -EBUSY;
if (!rv) { return entry->show(rdev, page);
if (rdev->mddev == NULL)
rv = -EBUSY;
else
rv = entry->show(rdev, page);
mddev_unlock(mddev);
}
return rv;
} }
static ssize_t static ssize_t
......
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