summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/sysfs.c
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2016-04-26 16:22:06 +0200
committerDavid Sterba <dsterba@suse.com>2016-05-06 15:22:49 +0200
commitee17fc8005287d2d6ca7cab6e814e5043d773735 (patch)
tree17d8f4c3a5bf27587fa7dadf730a2ef4f88798cd /fs/btrfs/sysfs.c
parent66ac9fe7bacf9fa76c472efc7a7aaa590c7bce6a (diff)
downloadlinux-0-day-ee17fc8005287d2d6ca7cab6e814e5043d773735.tar.gz
linux-0-day-ee17fc8005287d2d6ca7cab6e814e5043d773735.tar.xz
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: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/sysfs.c')
-rw-r--r--fs/btrfs/sysfs.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 3d14618ce54be..4879656bda3cd 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -367,7 +367,13 @@ static ssize_t btrfs_label_show(struct kobject *kobj,
{
struct btrfs_fs_info *fs_info = to_fs_info(kobj);
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,