Just like label change, use sb_want_write() to do a correct protection.
Signed-off-by: Qu Wenruo <[email protected]>
---
v4:
Newly introduced.
v5:
Change to sb_want_write().
---
fs/btrfs/sysfs.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
index 3218245..64f876e 100644
--- a/fs/btrfs/sysfs.c
+++ b/fs/btrfs/sysfs.c
@@ -154,9 +154,15 @@ 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);
+ ret = sb_want_write(fs_info->sb);
+ if (ret)
+ 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 +174,12 @@ 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:
+ sb_drop_write(fs_info->sb);
+ if (!ret)
+ return count;
+ return ret;
}
static umode_t btrfs_feature_visible(struct kobject *kobj,
--
2.2.2
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html