Skip to content

Commit 14e46e0

Browse files
committed
btrfs: synchronize incompat feature bits with sysfs files
The files under /sys/fs/UUID/features get out of sync with the actual incompat bits set for the filesystem if they change after mount (eg. the LZO compression). Synchronize the feature bits with the sysfs files representing them right after we set/clear them. Signed-off-by: David Sterba <[email protected]>
1 parent 444e751 commit 14e46e0

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

fs/btrfs/free-space-tree.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "locking.h"
2424
#include "free-space-tree.h"
2525
#include "transaction.h"
26+
#include "sysfs.h"
2627

2728
static int __add_block_group_free_space(struct btrfs_trans_handle *trans,
2829
struct btrfs_fs_info *fs_info,
@@ -1169,6 +1170,9 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
11691170
}
11701171

11711172
btrfs_set_fs_compat_ro(fs_info, FREE_SPACE_TREE);
1173+
btrfs_sysfs_feature_update(fs_info,
1174+
BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE, FEAT_COMPAT_RO);
1175+
11721176
fs_info->creating_free_space_tree = 0;
11731177

11741178
ret = btrfs_commit_transaction(trans, tree_root);
@@ -1237,6 +1241,9 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
12371241
return PTR_ERR(trans);
12381242

12391243
btrfs_clear_fs_compat_ro(fs_info, FREE_SPACE_TREE);
1244+
btrfs_sysfs_feature_update(fs_info,
1245+
BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE, FEAT_COMPAT_RO);
1246+
12401247
fs_info->free_space_root = NULL;
12411248

12421249
ret = clear_free_space_tree(trans, free_space_root);

fs/btrfs/ioctl.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
14551455

14561456
if (range->compress_type == BTRFS_COMPRESS_LZO) {
14571457
btrfs_set_fs_incompat(root->fs_info, COMPRESS_LZO);
1458+
btrfs_sysfs_feature_update(root->fs_info,
1459+
BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO, FEAT_INCOMPAT);
14581460
}
14591461

14601462
ret = defrag_count;
@@ -4063,6 +4065,8 @@ static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp)
40634065
btrfs_free_path(path);
40644066

40654067
btrfs_set_fs_incompat(root->fs_info, DEFAULT_SUBVOL);
4068+
btrfs_sysfs_feature_update(root->fs_info,
4069+
BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL, FEAT_INCOMPAT);
40664070
btrfs_end_transaction(trans, root);
40674071
out:
40684072
mnt_drop_write_file(file);

fs/btrfs/super.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include "dev-replace.h"
5959
#include "free-space-cache.h"
6060
#include "backref.h"
61+
#include "sysfs.h"
6162
#include "tests/btrfs-tests.h"
6263

6364
#include "qgroup.h"
@@ -477,6 +478,9 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
477478
btrfs_clear_opt(info->mount_opt, NODATACOW);
478479
btrfs_clear_opt(info->mount_opt, NODATASUM);
479480
btrfs_set_fs_incompat(info, COMPRESS_LZO);
481+
btrfs_sysfs_feature_update(root->fs_info,
482+
BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO,
483+
FEAT_INCOMPAT);
480484
} else if (strncmp(args[0].from, "no", 2) == 0) {
481485
compress_type = "no";
482486
btrfs_clear_opt(info->mount_opt, COMPRESS);

fs/btrfs/volumes.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4468,6 +4468,8 @@ static void check_raid56_incompat_flag(struct btrfs_fs_info *info, u64 type)
44684468
return;
44694469

44704470
btrfs_set_fs_incompat(info, RAID56);
4471+
btrfs_sysfs_feature_update(info, BTRFS_FEATURE_INCOMPAT_RAID56,
4472+
FEAT_INCOMPAT);
44714473
}
44724474

44734475
#define BTRFS_MAX_DEVS(r) ((BTRFS_LEAF_DATA_SIZE(r) \

0 commit comments

Comments
 (0)