Commit ee17fc80 authored by David Sterba's avatar David Sterba

btrfs: sysfs: protect reading label by lock

If the label setting ioctl races with sysfs label handler, we could get
mixed result in the output, part old part new. We should either get the
old or new label. The chances to hit this race are low.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 66ac9fe7
...@@ -367,7 +367,13 @@ static ssize_t btrfs_label_show(struct kobject *kobj, ...@@ -367,7 +367,13 @@ static ssize_t btrfs_label_show(struct kobject *kobj,
{ {
struct btrfs_fs_info *fs_info = to_fs_info(kobj); struct btrfs_fs_info *fs_info = to_fs_info(kobj);
char *label = fs_info->super_copy->label; char *label = fs_info->super_copy->label;
return snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label); ssize_t ret;
spin_lock(&fs_info->super_lock);
ret = snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label);
spin_unlock(&fs_info->super_lock);
return ret;
} }
static ssize_t btrfs_label_store(struct kobject *kobj, static ssize_t btrfs_label_store(struct kobject *kobj,
......
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