@@ -113,6 +113,7 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
struct btrfs_fs_info *fs_info;
struct btrfs_feature_attr *fa = to_btrfs_feature_attr(a);
struct btrfs_trans_handle *trans;
+ struct vfsmount *vfsmount;
u64 features, set, clear;
unsigned long val;
int ret;
@@ -154,9 +155,20 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
btrfs_info(fs_info, "%s %s feature flag",
val ? "Setting" : "Clearing", fa->kobj_attr.attr.name);
+ vfsmount = get_vfsmount_sb(fs_info->sb);
+ if (!vfsmount)
+ return -EINVAL;
+
+ ret = mnt_want_write(vfsmount);
+ if (ret) {
+ mntput(vfsmount);
+ return ret;
+ }
trans = btrfs_start_transaction(fs_info->fs_root, 0);
- if (IS_ERR(trans))
- return PTR_ERR(trans);
+ if (IS_ERR(trans)) {
+ ret = PTR_ERR(trans);
+ goto out;
+ }
spin_lock(&fs_info->super_lock);
features = get_features(fs_info, fa->feature_set);
@@ -168,10 +180,13 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,
spin_unlock(&fs_info->super_lock);
ret = btrfs_commit_transaction(trans, fs_info->fs_root);
- if (ret)
- return ret;
- return count;
+out:
+ mnt_drop_write(vfsmount);
+ mntput(vfsmount);
+ if (!ret)
+ return count;
+ return ret;
}
static umode_t btrfs_feature_visible(struct kobject *kobj,
Just like label change, use mnt_want_write() to do a correct protection. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- fs/btrfs/sysfs.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)