xref: /linux/fs/btrfs/fs.c (revision 43d5f5d63699724d47f0d9e0eae516a260d232b4)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include "messages.h"
4 #include "ctree.h"
5 #include "fs.h"
6 #include "accessors.h"
7 
8 void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,
9 			     const char *name)
10 {
11 	struct btrfs_super_block *disk_super;
12 	u64 features;
13 
14 	disk_super = fs_info->super_copy;
15 	features = btrfs_super_incompat_flags(disk_super);
16 	if (!(features & flag)) {
17 		spin_lock(&fs_info->super_lock);
18 		features = btrfs_super_incompat_flags(disk_super);
19 		if (!(features & flag)) {
20 			features |= flag;
21 			btrfs_set_super_incompat_flags(disk_super, features);
22 			btrfs_info(fs_info,
23 				"setting incompat feature flag for %s (0x%llx)",
24 				name, flag);
25 		}
26 		spin_unlock(&fs_info->super_lock);
27 	}
28 }
29 
30 void __btrfs_clear_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,
31 			       const char *name)
32 {
33 	struct btrfs_super_block *disk_super;
34 	u64 features;
35 
36 	disk_super = fs_info->super_copy;
37 	features = btrfs_super_incompat_flags(disk_super);
38 	if (features & flag) {
39 		spin_lock(&fs_info->super_lock);
40 		features = btrfs_super_incompat_flags(disk_super);
41 		if (features & flag) {
42 			features &= ~flag;
43 			btrfs_set_super_incompat_flags(disk_super, features);
44 			btrfs_info(fs_info,
45 				"clearing incompat feature flag for %s (0x%llx)",
46 				name, flag);
47 		}
48 		spin_unlock(&fs_info->super_lock);
49 	}
50 }
51 
52 void __btrfs_set_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
53 			      const char *name)
54 {
55 	struct btrfs_super_block *disk_super;
56 	u64 features;
57 
58 	disk_super = fs_info->super_copy;
59 	features = btrfs_super_compat_ro_flags(disk_super);
60 	if (!(features & flag)) {
61 		spin_lock(&fs_info->super_lock);
62 		features = btrfs_super_compat_ro_flags(disk_super);
63 		if (!(features & flag)) {
64 			features |= flag;
65 			btrfs_set_super_compat_ro_flags(disk_super, features);
66 			btrfs_info(fs_info,
67 				"setting compat-ro feature flag for %s (0x%llx)",
68 				name, flag);
69 		}
70 		spin_unlock(&fs_info->super_lock);
71 	}
72 }
73 
74 void __btrfs_clear_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag,
75 				const char *name)
76 {
77 	struct btrfs_super_block *disk_super;
78 	u64 features;
79 
80 	disk_super = fs_info->super_copy;
81 	features = btrfs_super_compat_ro_flags(disk_super);
82 	if (features & flag) {
83 		spin_lock(&fs_info->super_lock);
84 		features = btrfs_super_compat_ro_flags(disk_super);
85 		if (features & flag) {
86 			features &= ~flag;
87 			btrfs_set_super_compat_ro_flags(disk_super, features);
88 			btrfs_info(fs_info,
89 				"clearing compat-ro feature flag for %s (0x%llx)",
90 				name, flag);
91 		}
92 		spin_unlock(&fs_info->super_lock);
93 	}
94 }
95