David Sterba | c1d7c51 | 2018-04-03 19:23:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Chris Mason | 6cbd557 | 2007-06-12 09:07:21 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007 Oracle. All rights reserved. |
Chris Mason | 6cbd557 | 2007-06-12 09:07:21 -0400 | [diff] [blame] | 4 | */ |
| 5 | |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 6 | #include <linux/sched.h> |
| 7 | #include <linux/slab.h> |
| 8 | #include <linux/spinlock.h> |
| 9 | #include <linux/completion.h> |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 10 | #include <linux/kobject.h> |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 11 | #include <linux/bug.h> |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 13 | |
Chris Mason | bae45de | 2007-04-04 21:22:22 -0400 | [diff] [blame] | 14 | #include "ctree.h" |
| 15 | #include "disk-io.h" |
| 16 | #include "transaction.h" |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 17 | #include "sysfs.h" |
Jeff Mahoney | 29e5be2 | 2013-11-01 13:07:05 -0400 | [diff] [blame] | 18 | #include "volumes.h" |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 19 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 20 | static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj); |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 21 | static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj); |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 22 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 23 | static u64 get_features(struct btrfs_fs_info *fs_info, |
| 24 | enum btrfs_feature_set set) |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 25 | { |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 26 | struct btrfs_super_block *disk_super = fs_info->super_copy; |
| 27 | if (set == FEAT_COMPAT) |
| 28 | return btrfs_super_compat_flags(disk_super); |
| 29 | else if (set == FEAT_COMPAT_RO) |
| 30 | return btrfs_super_compat_ro_flags(disk_super); |
| 31 | else |
| 32 | return btrfs_super_incompat_flags(disk_super); |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 33 | } |
| 34 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 35 | static void set_features(struct btrfs_fs_info *fs_info, |
| 36 | enum btrfs_feature_set set, u64 features) |
| 37 | { |
| 38 | struct btrfs_super_block *disk_super = fs_info->super_copy; |
| 39 | if (set == FEAT_COMPAT) |
| 40 | btrfs_set_super_compat_flags(disk_super, features); |
| 41 | else if (set == FEAT_COMPAT_RO) |
| 42 | btrfs_set_super_compat_ro_flags(disk_super, features); |
| 43 | else |
| 44 | btrfs_set_super_incompat_flags(disk_super, features); |
| 45 | } |
| 46 | |
| 47 | static int can_modify_feature(struct btrfs_feature_attr *fa) |
| 48 | { |
| 49 | int val = 0; |
| 50 | u64 set, clear; |
| 51 | switch (fa->feature_set) { |
| 52 | case FEAT_COMPAT: |
| 53 | set = BTRFS_FEATURE_COMPAT_SAFE_SET; |
| 54 | clear = BTRFS_FEATURE_COMPAT_SAFE_CLEAR; |
| 55 | break; |
| 56 | case FEAT_COMPAT_RO: |
| 57 | set = BTRFS_FEATURE_COMPAT_RO_SAFE_SET; |
| 58 | clear = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR; |
| 59 | break; |
| 60 | case FEAT_INCOMPAT: |
| 61 | set = BTRFS_FEATURE_INCOMPAT_SAFE_SET; |
| 62 | clear = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR; |
| 63 | break; |
| 64 | default: |
Jeff Mahoney | 62e8557 | 2016-09-20 10:05:01 -0400 | [diff] [blame] | 65 | pr_warn("btrfs: sysfs: unknown feature set %d\n", |
David Sterba | cc37bb0 | 2013-11-19 13:36:21 +0100 | [diff] [blame] | 66 | fa->feature_set); |
| 67 | return 0; |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | if (set & fa->feature_bit) |
| 71 | val |= 1; |
| 72 | if (clear & fa->feature_bit) |
| 73 | val |= 2; |
| 74 | |
| 75 | return val; |
| 76 | } |
| 77 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 78 | static ssize_t btrfs_feature_attr_show(struct kobject *kobj, |
| 79 | struct kobj_attribute *a, char *buf) |
| 80 | { |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 81 | int val = 0; |
| 82 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 83 | struct btrfs_feature_attr *fa = to_btrfs_feature_attr(a); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 84 | if (fs_info) { |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 85 | u64 features = get_features(fs_info, fa->feature_set); |
| 86 | if (features & fa->feature_bit) |
| 87 | val = 1; |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 88 | } else |
| 89 | val = can_modify_feature(fa); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 90 | |
| 91 | return snprintf(buf, PAGE_SIZE, "%d\n", val); |
| 92 | } |
| 93 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 94 | static ssize_t btrfs_feature_attr_store(struct kobject *kobj, |
| 95 | struct kobj_attribute *a, |
| 96 | const char *buf, size_t count) |
| 97 | { |
| 98 | struct btrfs_fs_info *fs_info; |
| 99 | struct btrfs_feature_attr *fa = to_btrfs_feature_attr(a); |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 100 | u64 features, set, clear; |
| 101 | unsigned long val; |
| 102 | int ret; |
| 103 | |
| 104 | fs_info = to_fs_info(kobj); |
| 105 | if (!fs_info) |
| 106 | return -EPERM; |
| 107 | |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 108 | if (sb_rdonly(fs_info->sb)) |
David Sterba | ee61113 | 2015-01-23 18:43:31 +0100 | [diff] [blame] | 109 | return -EROFS; |
| 110 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 111 | ret = kstrtoul(skip_spaces(buf), 0, &val); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | |
| 115 | if (fa->feature_set == FEAT_COMPAT) { |
| 116 | set = BTRFS_FEATURE_COMPAT_SAFE_SET; |
| 117 | clear = BTRFS_FEATURE_COMPAT_SAFE_CLEAR; |
| 118 | } else if (fa->feature_set == FEAT_COMPAT_RO) { |
| 119 | set = BTRFS_FEATURE_COMPAT_RO_SAFE_SET; |
| 120 | clear = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR; |
| 121 | } else { |
| 122 | set = BTRFS_FEATURE_INCOMPAT_SAFE_SET; |
| 123 | clear = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR; |
| 124 | } |
| 125 | |
| 126 | features = get_features(fs_info, fa->feature_set); |
| 127 | |
| 128 | /* Nothing to do */ |
| 129 | if ((val && (features & fa->feature_bit)) || |
| 130 | (!val && !(features & fa->feature_bit))) |
| 131 | return count; |
| 132 | |
| 133 | if ((val && !(set & fa->feature_bit)) || |
| 134 | (!val && !(clear & fa->feature_bit))) { |
| 135 | btrfs_info(fs_info, |
| 136 | "%sabling feature %s on mounted fs is not supported.", |
| 137 | val ? "En" : "Dis", fa->kobj_attr.attr.name); |
| 138 | return -EPERM; |
| 139 | } |
| 140 | |
| 141 | btrfs_info(fs_info, "%s %s feature flag", |
| 142 | val ? "Setting" : "Clearing", fa->kobj_attr.attr.name); |
| 143 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 144 | spin_lock(&fs_info->super_lock); |
| 145 | features = get_features(fs_info, fa->feature_set); |
| 146 | if (val) |
| 147 | features |= fa->feature_bit; |
| 148 | else |
| 149 | features &= ~fa->feature_bit; |
| 150 | set_features(fs_info, fa->feature_set, features); |
| 151 | spin_unlock(&fs_info->super_lock); |
| 152 | |
David Sterba | 0eae274 | 2014-11-12 14:22:21 +0100 | [diff] [blame] | 153 | /* |
| 154 | * We don't want to do full transaction commit from inside sysfs |
| 155 | */ |
| 156 | btrfs_set_pending(fs_info, COMMIT); |
| 157 | wake_up_process(fs_info->transaction_kthread); |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 158 | |
| 159 | return count; |
| 160 | } |
| 161 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 162 | static umode_t btrfs_feature_visible(struct kobject *kobj, |
| 163 | struct attribute *attr, int unused) |
| 164 | { |
| 165 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 166 | umode_t mode = attr->mode; |
| 167 | |
| 168 | if (fs_info) { |
| 169 | struct btrfs_feature_attr *fa; |
| 170 | u64 features; |
| 171 | |
| 172 | fa = attr_to_btrfs_feature_attr(attr); |
| 173 | features = get_features(fs_info, fa->feature_set); |
| 174 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 175 | if (can_modify_feature(fa)) |
| 176 | mode |= S_IWUSR; |
| 177 | else if (!(features & fa->feature_bit)) |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 178 | mode = 0; |
| 179 | } |
| 180 | |
| 181 | return mode; |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF); |
| 185 | BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL); |
| 186 | BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS); |
| 187 | BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo, COMPRESS_LZO); |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 188 | BTRFS_FEAT_ATTR_INCOMPAT(compress_zstd, COMPRESS_ZSTD); |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 189 | BTRFS_FEAT_ATTR_INCOMPAT(big_metadata, BIG_METADATA); |
| 190 | BTRFS_FEAT_ATTR_INCOMPAT(extended_iref, EXTENDED_IREF); |
| 191 | BTRFS_FEAT_ATTR_INCOMPAT(raid56, RAID56); |
| 192 | BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA); |
David Sterba | c736c09 | 2014-01-21 18:56:09 +0100 | [diff] [blame] | 193 | BTRFS_FEAT_ATTR_INCOMPAT(no_holes, NO_HOLES); |
Nikolay Borisov | 56f20f4 | 2018-11-19 17:37:45 +0200 | [diff] [blame^] | 194 | BTRFS_FEAT_ATTR_INCOMPAT(metadata_uuid, METADATA_UUID); |
David Sterba | 3b5bb73 | 2016-01-21 18:36:46 +0100 | [diff] [blame] | 195 | BTRFS_FEAT_ATTR_COMPAT_RO(free_space_tree, FREE_SPACE_TREE); |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 196 | |
| 197 | static struct attribute *btrfs_supported_feature_attrs[] = { |
| 198 | BTRFS_FEAT_ATTR_PTR(mixed_backref), |
| 199 | BTRFS_FEAT_ATTR_PTR(default_subvol), |
| 200 | BTRFS_FEAT_ATTR_PTR(mixed_groups), |
| 201 | BTRFS_FEAT_ATTR_PTR(compress_lzo), |
Nick Terrell | 5c1aab1 | 2017-08-09 19:39:02 -0700 | [diff] [blame] | 202 | BTRFS_FEAT_ATTR_PTR(compress_zstd), |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 203 | BTRFS_FEAT_ATTR_PTR(big_metadata), |
| 204 | BTRFS_FEAT_ATTR_PTR(extended_iref), |
| 205 | BTRFS_FEAT_ATTR_PTR(raid56), |
| 206 | BTRFS_FEAT_ATTR_PTR(skinny_metadata), |
David Sterba | c736c09 | 2014-01-21 18:56:09 +0100 | [diff] [blame] | 207 | BTRFS_FEAT_ATTR_PTR(no_holes), |
Nikolay Borisov | 56f20f4 | 2018-11-19 17:37:45 +0200 | [diff] [blame^] | 208 | BTRFS_FEAT_ATTR_PTR(metadata_uuid), |
David Sterba | 3b5bb73 | 2016-01-21 18:36:46 +0100 | [diff] [blame] | 209 | BTRFS_FEAT_ATTR_PTR(free_space_tree), |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 210 | NULL |
| 211 | }; |
| 212 | |
Misono Tomohiro | f902bd3 | 2018-05-17 14:24:51 +0900 | [diff] [blame] | 213 | /* |
| 214 | * Features which depend on feature bits and may differ between each fs. |
| 215 | * |
| 216 | * /sys/fs/btrfs/features lists all available features of this kernel while |
| 217 | * /sys/fs/btrfs/UUID/features shows features of the fs which are enabled or |
| 218 | * can be changed online. |
| 219 | */ |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 220 | static const struct attribute_group btrfs_feature_attr_group = { |
| 221 | .name = "features", |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 222 | .is_visible = btrfs_feature_visible, |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 223 | .attrs = btrfs_supported_feature_attrs, |
| 224 | }; |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 225 | |
Misono Tomohiro | f902bd3 | 2018-05-17 14:24:51 +0900 | [diff] [blame] | 226 | static ssize_t rmdir_subvol_show(struct kobject *kobj, |
| 227 | struct kobj_attribute *ka, char *buf) |
| 228 | { |
| 229 | return snprintf(buf, PAGE_SIZE, "0\n"); |
| 230 | } |
| 231 | BTRFS_ATTR(static_feature, rmdir_subvol, rmdir_subvol_show); |
| 232 | |
| 233 | static struct attribute *btrfs_supported_static_feature_attrs[] = { |
| 234 | BTRFS_ATTR_PTR(static_feature, rmdir_subvol), |
| 235 | NULL |
| 236 | }; |
| 237 | |
| 238 | /* |
| 239 | * Features which only depend on kernel version. |
| 240 | * |
| 241 | * These are listed in /sys/fs/btrfs/features along with |
| 242 | * btrfs_feature_attr_group |
| 243 | */ |
| 244 | static const struct attribute_group btrfs_static_feature_attr_group = { |
| 245 | .name = "features", |
| 246 | .attrs = btrfs_supported_static_feature_attrs, |
| 247 | }; |
| 248 | |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 249 | static ssize_t btrfs_show_u64(u64 *value_ptr, spinlock_t *lock, char *buf) |
| 250 | { |
| 251 | u64 val; |
| 252 | if (lock) |
| 253 | spin_lock(lock); |
| 254 | val = *value_ptr; |
| 255 | if (lock) |
| 256 | spin_unlock(lock); |
| 257 | return snprintf(buf, PAGE_SIZE, "%llu\n", val); |
| 258 | } |
| 259 | |
| 260 | static ssize_t global_rsv_size_show(struct kobject *kobj, |
| 261 | struct kobj_attribute *ka, char *buf) |
| 262 | { |
| 263 | struct btrfs_fs_info *fs_info = to_fs_info(kobj->parent); |
| 264 | struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; |
| 265 | return btrfs_show_u64(&block_rsv->size, &block_rsv->lock, buf); |
| 266 | } |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 267 | BTRFS_ATTR(allocation, global_rsv_size, global_rsv_size_show); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 268 | |
| 269 | static ssize_t global_rsv_reserved_show(struct kobject *kobj, |
| 270 | struct kobj_attribute *a, char *buf) |
| 271 | { |
| 272 | struct btrfs_fs_info *fs_info = to_fs_info(kobj->parent); |
| 273 | struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv; |
| 274 | return btrfs_show_u64(&block_rsv->reserved, &block_rsv->lock, buf); |
| 275 | } |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 276 | BTRFS_ATTR(allocation, global_rsv_reserved, global_rsv_reserved_show); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 277 | |
| 278 | #define to_space_info(_kobj) container_of(_kobj, struct btrfs_space_info, kobj) |
Jeff Mahoney | c189544 | 2014-05-27 12:59:57 -0400 | [diff] [blame] | 279 | #define to_raid_kobj(_kobj) container_of(_kobj, struct raid_kobject, kobj) |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 280 | |
| 281 | static ssize_t raid_bytes_show(struct kobject *kobj, |
| 282 | struct kobj_attribute *attr, char *buf); |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 283 | BTRFS_ATTR(raid, total_bytes, raid_bytes_show); |
| 284 | BTRFS_ATTR(raid, used_bytes, raid_bytes_show); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 285 | |
| 286 | static ssize_t raid_bytes_show(struct kobject *kobj, |
| 287 | struct kobj_attribute *attr, char *buf) |
| 288 | |
| 289 | { |
| 290 | struct btrfs_space_info *sinfo = to_space_info(kobj->parent); |
| 291 | struct btrfs_block_group_cache *block_group; |
Jeff Mahoney | 75cb379 | 2018-03-20 15:25:26 -0400 | [diff] [blame] | 292 | int index = btrfs_bg_flags_to_raid_index(to_raid_kobj(kobj)->flags); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 293 | u64 val = 0; |
| 294 | |
| 295 | down_read(&sinfo->groups_sem); |
| 296 | list_for_each_entry(block_group, &sinfo->block_groups[index], list) { |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 297 | if (&attr->attr == BTRFS_ATTR_PTR(raid, total_bytes)) |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 298 | val += block_group->key.offset; |
| 299 | else |
| 300 | val += btrfs_block_group_used(&block_group->item); |
| 301 | } |
| 302 | up_read(&sinfo->groups_sem); |
| 303 | return snprintf(buf, PAGE_SIZE, "%llu\n", val); |
| 304 | } |
| 305 | |
| 306 | static struct attribute *raid_attributes[] = { |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 307 | BTRFS_ATTR_PTR(raid, total_bytes), |
| 308 | BTRFS_ATTR_PTR(raid, used_bytes), |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 309 | NULL |
| 310 | }; |
| 311 | |
| 312 | static void release_raid_kobj(struct kobject *kobj) |
| 313 | { |
Jeff Mahoney | c189544 | 2014-05-27 12:59:57 -0400 | [diff] [blame] | 314 | kfree(to_raid_kobj(kobj)); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | struct kobj_type btrfs_raid_ktype = { |
| 318 | .sysfs_ops = &kobj_sysfs_ops, |
| 319 | .release = release_raid_kobj, |
| 320 | .default_attrs = raid_attributes, |
| 321 | }; |
| 322 | |
| 323 | #define SPACE_INFO_ATTR(field) \ |
| 324 | static ssize_t btrfs_space_info_show_##field(struct kobject *kobj, \ |
| 325 | struct kobj_attribute *a, \ |
| 326 | char *buf) \ |
| 327 | { \ |
| 328 | struct btrfs_space_info *sinfo = to_space_info(kobj); \ |
| 329 | return btrfs_show_u64(&sinfo->field, &sinfo->lock, buf); \ |
| 330 | } \ |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 331 | BTRFS_ATTR(space_info, field, btrfs_space_info_show_##field) |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 332 | |
| 333 | static ssize_t btrfs_space_info_show_total_bytes_pinned(struct kobject *kobj, |
| 334 | struct kobj_attribute *a, |
| 335 | char *buf) |
| 336 | { |
| 337 | struct btrfs_space_info *sinfo = to_space_info(kobj); |
| 338 | s64 val = percpu_counter_sum(&sinfo->total_bytes_pinned); |
| 339 | return snprintf(buf, PAGE_SIZE, "%lld\n", val); |
| 340 | } |
| 341 | |
| 342 | SPACE_INFO_ATTR(flags); |
| 343 | SPACE_INFO_ATTR(total_bytes); |
| 344 | SPACE_INFO_ATTR(bytes_used); |
| 345 | SPACE_INFO_ATTR(bytes_pinned); |
| 346 | SPACE_INFO_ATTR(bytes_reserved); |
| 347 | SPACE_INFO_ATTR(bytes_may_use); |
Wang Xiaoguang | c1fd5c3 | 2016-06-21 11:12:56 +0800 | [diff] [blame] | 348 | SPACE_INFO_ATTR(bytes_readonly); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 349 | SPACE_INFO_ATTR(disk_used); |
| 350 | SPACE_INFO_ATTR(disk_total); |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 351 | BTRFS_ATTR(space_info, total_bytes_pinned, |
| 352 | btrfs_space_info_show_total_bytes_pinned); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 353 | |
| 354 | static struct attribute *space_info_attrs[] = { |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 355 | BTRFS_ATTR_PTR(space_info, flags), |
| 356 | BTRFS_ATTR_PTR(space_info, total_bytes), |
| 357 | BTRFS_ATTR_PTR(space_info, bytes_used), |
| 358 | BTRFS_ATTR_PTR(space_info, bytes_pinned), |
| 359 | BTRFS_ATTR_PTR(space_info, bytes_reserved), |
| 360 | BTRFS_ATTR_PTR(space_info, bytes_may_use), |
| 361 | BTRFS_ATTR_PTR(space_info, bytes_readonly), |
| 362 | BTRFS_ATTR_PTR(space_info, disk_used), |
| 363 | BTRFS_ATTR_PTR(space_info, disk_total), |
| 364 | BTRFS_ATTR_PTR(space_info, total_bytes_pinned), |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 365 | NULL, |
| 366 | }; |
| 367 | |
| 368 | static void space_info_release(struct kobject *kobj) |
| 369 | { |
| 370 | struct btrfs_space_info *sinfo = to_space_info(kobj); |
| 371 | percpu_counter_destroy(&sinfo->total_bytes_pinned); |
| 372 | kfree(sinfo); |
| 373 | } |
| 374 | |
| 375 | struct kobj_type space_info_ktype = { |
| 376 | .sysfs_ops = &kobj_sysfs_ops, |
| 377 | .release = space_info_release, |
| 378 | .default_attrs = space_info_attrs, |
| 379 | }; |
| 380 | |
| 381 | static const struct attribute *allocation_attrs[] = { |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 382 | BTRFS_ATTR_PTR(allocation, global_rsv_reserved), |
| 383 | BTRFS_ATTR_PTR(allocation, global_rsv_size), |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 384 | NULL, |
| 385 | }; |
| 386 | |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 387 | static ssize_t btrfs_label_show(struct kobject *kobj, |
| 388 | struct kobj_attribute *a, char *buf) |
| 389 | { |
| 390 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
Satoru Takeuchi | 48fcc3f | 2014-07-01 17:00:07 +0900 | [diff] [blame] | 391 | char *label = fs_info->super_copy->label; |
David Sterba | ee17fc8 | 2016-04-26 16:22:06 +0200 | [diff] [blame] | 392 | ssize_t ret; |
| 393 | |
| 394 | spin_lock(&fs_info->super_lock); |
| 395 | ret = snprintf(buf, PAGE_SIZE, label[0] ? "%s\n" : "%s", label); |
| 396 | spin_unlock(&fs_info->super_lock); |
| 397 | |
| 398 | return ret; |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static ssize_t btrfs_label_store(struct kobject *kobj, |
| 402 | struct kobj_attribute *a, |
| 403 | const char *buf, size_t len) |
| 404 | { |
| 405 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
Satoru Takeuchi | 48fcc3f | 2014-07-01 17:00:07 +0900 | [diff] [blame] | 406 | size_t p_len; |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 407 | |
David Sterba | 66ac9fe | 2016-04-26 16:03:57 +0200 | [diff] [blame] | 408 | if (!fs_info) |
| 409 | return -EPERM; |
| 410 | |
David Howells | bc98a42 | 2017-07-17 08:45:34 +0100 | [diff] [blame] | 411 | if (sb_rdonly(fs_info->sb)) |
Anand Jain | 79aec2b | 2014-07-30 20:04:10 +0800 | [diff] [blame] | 412 | return -EROFS; |
| 413 | |
Satoru Takeuchi | 48fcc3f | 2014-07-01 17:00:07 +0900 | [diff] [blame] | 414 | /* |
| 415 | * p_len is the len until the first occurrence of either |
| 416 | * '\n' or '\0' |
| 417 | */ |
| 418 | p_len = strcspn(buf, "\n"); |
| 419 | |
| 420 | if (p_len >= BTRFS_LABEL_SIZE) |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 421 | return -EINVAL; |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 422 | |
David Sterba | a6f69dc | 2014-05-30 19:29:05 +0200 | [diff] [blame] | 423 | spin_lock(&fs_info->super_lock); |
Satoru Takeuchi | 48fcc3f | 2014-07-01 17:00:07 +0900 | [diff] [blame] | 424 | memset(fs_info->super_copy->label, 0, BTRFS_LABEL_SIZE); |
| 425 | memcpy(fs_info->super_copy->label, buf, p_len); |
David Sterba | a6f69dc | 2014-05-30 19:29:05 +0200 | [diff] [blame] | 426 | spin_unlock(&fs_info->super_lock); |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 427 | |
David Sterba | a6f69dc | 2014-05-30 19:29:05 +0200 | [diff] [blame] | 428 | /* |
| 429 | * We don't want to do full transaction commit from inside sysfs |
| 430 | */ |
| 431 | btrfs_set_pending(fs_info, COMMIT); |
| 432 | wake_up_process(fs_info->transaction_kthread); |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 433 | |
David Sterba | a6f69dc | 2014-05-30 19:29:05 +0200 | [diff] [blame] | 434 | return len; |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 435 | } |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 436 | BTRFS_ATTR_RW(, label, btrfs_label_show, btrfs_label_store); |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 437 | |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 438 | static ssize_t btrfs_nodesize_show(struct kobject *kobj, |
| 439 | struct kobj_attribute *a, char *buf) |
| 440 | { |
| 441 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 442 | |
David Sterba | 093e037 | 2018-03-16 14:31:43 +0100 | [diff] [blame] | 443 | return snprintf(buf, PAGE_SIZE, "%u\n", fs_info->super_copy->nodesize); |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 444 | } |
| 445 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 446 | BTRFS_ATTR(, nodesize, btrfs_nodesize_show); |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 447 | |
| 448 | static ssize_t btrfs_sectorsize_show(struct kobject *kobj, |
| 449 | struct kobj_attribute *a, char *buf) |
| 450 | { |
| 451 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 452 | |
David Sterba | 093e037 | 2018-03-16 14:31:43 +0100 | [diff] [blame] | 453 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 454 | fs_info->super_copy->sectorsize); |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 455 | } |
| 456 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 457 | BTRFS_ATTR(, sectorsize, btrfs_sectorsize_show); |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 458 | |
| 459 | static ssize_t btrfs_clone_alignment_show(struct kobject *kobj, |
| 460 | struct kobj_attribute *a, char *buf) |
| 461 | { |
| 462 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 463 | |
David Sterba | 093e037 | 2018-03-16 14:31:43 +0100 | [diff] [blame] | 464 | return snprintf(buf, PAGE_SIZE, "%u\n", |
| 465 | fs_info->super_copy->sectorsize); |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 466 | } |
| 467 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 468 | BTRFS_ATTR(, clone_alignment, btrfs_clone_alignment_show); |
David Sterba | df93589 | 2014-05-07 18:17:16 +0200 | [diff] [blame] | 469 | |
Sargun Dhillon | 2723480 | 2017-05-11 21:18:03 +0000 | [diff] [blame] | 470 | static ssize_t quota_override_show(struct kobject *kobj, |
| 471 | struct kobj_attribute *a, char *buf) |
| 472 | { |
| 473 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 474 | int quota_override; |
| 475 | |
| 476 | quota_override = test_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags); |
| 477 | return snprintf(buf, PAGE_SIZE, "%d\n", quota_override); |
| 478 | } |
| 479 | |
| 480 | static ssize_t quota_override_store(struct kobject *kobj, |
| 481 | struct kobj_attribute *a, |
| 482 | const char *buf, size_t len) |
| 483 | { |
| 484 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 485 | unsigned long knob; |
| 486 | int err; |
| 487 | |
| 488 | if (!fs_info) |
| 489 | return -EPERM; |
| 490 | |
| 491 | if (!capable(CAP_SYS_RESOURCE)) |
| 492 | return -EPERM; |
| 493 | |
| 494 | err = kstrtoul(buf, 10, &knob); |
| 495 | if (err) |
| 496 | return err; |
| 497 | if (knob > 1) |
| 498 | return -EINVAL; |
| 499 | |
| 500 | if (knob) |
| 501 | set_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags); |
| 502 | else |
| 503 | clear_bit(BTRFS_FS_QUOTA_OVERRIDE, &fs_info->flags); |
| 504 | |
| 505 | return len; |
| 506 | } |
| 507 | |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 508 | BTRFS_ATTR_RW(, quota_override, quota_override_show, quota_override_store); |
Sargun Dhillon | 2723480 | 2017-05-11 21:18:03 +0000 | [diff] [blame] | 509 | |
Nikolay Borisov | 56f20f4 | 2018-11-19 17:37:45 +0200 | [diff] [blame^] | 510 | static ssize_t btrfs_metadata_uuid_show(struct kobject *kobj, |
| 511 | struct kobj_attribute *a, char *buf) |
| 512 | { |
| 513 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 514 | |
| 515 | return snprintf(buf, PAGE_SIZE, "%pU\n", |
| 516 | fs_info->fs_devices->metadata_uuid); |
| 517 | } |
| 518 | |
| 519 | BTRFS_ATTR(, metadata_uuid, btrfs_metadata_uuid_show); |
| 520 | |
Anand Jain | 0dd2906 | 2015-03-10 06:38:27 +0800 | [diff] [blame] | 521 | static const struct attribute *btrfs_attrs[] = { |
Hans van Kranenburg | a969f4c | 2017-10-08 22:30:58 +0200 | [diff] [blame] | 522 | BTRFS_ATTR_PTR(, label), |
| 523 | BTRFS_ATTR_PTR(, nodesize), |
| 524 | BTRFS_ATTR_PTR(, sectorsize), |
| 525 | BTRFS_ATTR_PTR(, clone_alignment), |
| 526 | BTRFS_ATTR_PTR(, quota_override), |
Nikolay Borisov | 56f20f4 | 2018-11-19 17:37:45 +0200 | [diff] [blame^] | 527 | BTRFS_ATTR_PTR(, metadata_uuid), |
Jeff Mahoney | f8ba9c1 | 2013-11-01 13:07:06 -0400 | [diff] [blame] | 528 | NULL, |
| 529 | }; |
| 530 | |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 531 | static void btrfs_release_fsid_kobj(struct kobject *kobj) |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 532 | { |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 533 | struct btrfs_fs_devices *fs_devs = to_fs_devs(kobj); |
Anand Jain | 248d200 | 2015-03-10 06:38:19 +0800 | [diff] [blame] | 534 | |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 535 | memset(&fs_devs->fsid_kobj, 0, sizeof(struct kobject)); |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 536 | complete(&fs_devs->kobj_unregister); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | static struct kobj_type btrfs_ktype = { |
| 540 | .sysfs_ops = &kobj_sysfs_ops, |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 541 | .release = btrfs_release_fsid_kobj, |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 542 | }; |
| 543 | |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 544 | static inline struct btrfs_fs_devices *to_fs_devs(struct kobject *kobj) |
| 545 | { |
| 546 | if (kobj->ktype != &btrfs_ktype) |
| 547 | return NULL; |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 548 | return container_of(kobj, struct btrfs_fs_devices, fsid_kobj); |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 549 | } |
| 550 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 551 | static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj) |
| 552 | { |
| 553 | if (kobj->ktype != &btrfs_ktype) |
| 554 | return NULL; |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 555 | return to_fs_devs(kobj)->fs_info; |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 556 | } |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 557 | |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 558 | #define NUM_FEATURE_BITS 64 |
Tomohiro Misono | 6c52157 | 2018-05-16 17:09:26 +0900 | [diff] [blame] | 559 | #define BTRFS_FEATURE_NAME_MAX 13 |
| 560 | static char btrfs_unknown_feature_names[FEAT_MAX][NUM_FEATURE_BITS][BTRFS_FEATURE_NAME_MAX]; |
| 561 | static struct btrfs_feature_attr btrfs_feature_attrs[FEAT_MAX][NUM_FEATURE_BITS]; |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 562 | |
Tomohiro Misono | 6c52157 | 2018-05-16 17:09:26 +0900 | [diff] [blame] | 563 | static const u64 supported_feature_masks[FEAT_MAX] = { |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 564 | [FEAT_COMPAT] = BTRFS_FEATURE_COMPAT_SUPP, |
| 565 | [FEAT_COMPAT_RO] = BTRFS_FEATURE_COMPAT_RO_SUPP, |
| 566 | [FEAT_INCOMPAT] = BTRFS_FEATURE_INCOMPAT_SUPP, |
| 567 | }; |
| 568 | |
| 569 | static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add) |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 570 | { |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 571 | int set; |
| 572 | |
| 573 | for (set = 0; set < FEAT_MAX; set++) { |
| 574 | int i; |
| 575 | struct attribute *attrs[2]; |
| 576 | struct attribute_group agroup = { |
| 577 | .name = "features", |
| 578 | .attrs = attrs, |
| 579 | }; |
| 580 | u64 features = get_features(fs_info, set); |
| 581 | features &= ~supported_feature_masks[set]; |
| 582 | |
| 583 | if (!features) |
| 584 | continue; |
| 585 | |
| 586 | attrs[1] = NULL; |
| 587 | for (i = 0; i < NUM_FEATURE_BITS; i++) { |
| 588 | struct btrfs_feature_attr *fa; |
| 589 | |
| 590 | if (!(features & (1ULL << i))) |
| 591 | continue; |
| 592 | |
| 593 | fa = &btrfs_feature_attrs[set][i]; |
| 594 | attrs[0] = &fa->kobj_attr.attr; |
| 595 | if (add) { |
| 596 | int ret; |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 597 | ret = sysfs_merge_group(&fs_info->fs_devices->fsid_kobj, |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 598 | &agroup); |
| 599 | if (ret) |
| 600 | return ret; |
| 601 | } else |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 602 | sysfs_unmerge_group(&fs_info->fs_devices->fsid_kobj, |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 603 | &agroup); |
| 604 | } |
| 605 | |
| 606 | } |
| 607 | return 0; |
| 608 | } |
| 609 | |
Anand Jain | 2e3e128 | 2015-03-10 06:38:32 +0800 | [diff] [blame] | 610 | static void __btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs) |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 611 | { |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 612 | if (fs_devs->device_dir_kobj) { |
| 613 | kobject_del(fs_devs->device_dir_kobj); |
| 614 | kobject_put(fs_devs->device_dir_kobj); |
| 615 | fs_devs->device_dir_kobj = NULL; |
Anand Jain | aaf1330 | 2015-03-10 06:38:24 +0800 | [diff] [blame] | 616 | } |
| 617 | |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 618 | if (fs_devs->fsid_kobj.state_initialized) { |
| 619 | kobject_del(&fs_devs->fsid_kobj); |
| 620 | kobject_put(&fs_devs->fsid_kobj); |
Anand Jain | f90fc54 | 2015-06-22 18:18:32 +0800 | [diff] [blame] | 621 | wait_for_completion(&fs_devs->kobj_unregister); |
| 622 | } |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 623 | } |
| 624 | |
Anand Jain | 2e3e128 | 2015-03-10 06:38:32 +0800 | [diff] [blame] | 625 | /* when fs_devs is NULL it will remove all fsid kobject */ |
Anand Jain | 1d1c1be | 2015-03-10 06:38:37 +0800 | [diff] [blame] | 626 | void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs) |
Anand Jain | 2e3e128 | 2015-03-10 06:38:32 +0800 | [diff] [blame] | 627 | { |
| 628 | struct list_head *fs_uuids = btrfs_get_fs_uuids(); |
| 629 | |
| 630 | if (fs_devs) { |
| 631 | __btrfs_sysfs_remove_fsid(fs_devs); |
| 632 | return; |
| 633 | } |
| 634 | |
Anand Jain | c4babc5 | 2018-04-12 10:29:25 +0800 | [diff] [blame] | 635 | list_for_each_entry(fs_devs, fs_uuids, fs_list) { |
Anand Jain | 2e3e128 | 2015-03-10 06:38:32 +0800 | [diff] [blame] | 636 | __btrfs_sysfs_remove_fsid(fs_devs); |
| 637 | } |
| 638 | } |
| 639 | |
Anand Jain | 6618a59 | 2015-08-14 18:32:47 +0800 | [diff] [blame] | 640 | void btrfs_sysfs_remove_mounted(struct btrfs_fs_info *fs_info) |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 641 | { |
Anand Jain | 5a13f43 | 2015-03-10 06:38:31 +0800 | [diff] [blame] | 642 | btrfs_reset_fs_info_ptr(fs_info); |
| 643 | |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 644 | if (fs_info->space_info_kobj) { |
| 645 | sysfs_remove_files(fs_info->space_info_kobj, allocation_attrs); |
| 646 | kobject_del(fs_info->space_info_kobj); |
| 647 | kobject_put(fs_info->space_info_kobj); |
| 648 | } |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 649 | addrm_unknown_feature_attrs(fs_info, false); |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 650 | sysfs_remove_group(&fs_info->fs_devices->fsid_kobj, &btrfs_feature_attr_group); |
| 651 | sysfs_remove_files(&fs_info->fs_devices->fsid_kobj, btrfs_attrs); |
Anand Jain | 3257604 | 2015-08-14 18:32:49 +0800 | [diff] [blame] | 652 | btrfs_sysfs_rm_device_link(fs_info->fs_devices, NULL); |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 653 | } |
| 654 | |
Tomohiro Misono | 6c52157 | 2018-05-16 17:09:26 +0900 | [diff] [blame] | 655 | const char * const btrfs_feature_set_names[FEAT_MAX] = { |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 656 | [FEAT_COMPAT] = "compat", |
| 657 | [FEAT_COMPAT_RO] = "compat_ro", |
| 658 | [FEAT_INCOMPAT] = "incompat", |
| 659 | }; |
| 660 | |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame] | 661 | char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags) |
| 662 | { |
| 663 | size_t bufsize = 4096; /* safe max, 64 names * 64 bytes */ |
| 664 | int len = 0; |
| 665 | int i; |
| 666 | char *str; |
| 667 | |
| 668 | str = kmalloc(bufsize, GFP_KERNEL); |
| 669 | if (!str) |
| 670 | return str; |
| 671 | |
| 672 | for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[set]); i++) { |
| 673 | const char *name; |
| 674 | |
| 675 | if (!(flags & (1ULL << i))) |
| 676 | continue; |
| 677 | |
| 678 | name = btrfs_feature_attrs[set][i].kobj_attr.attr.name; |
| 679 | len += snprintf(str + len, bufsize - len, "%s%s", |
| 680 | len ? "," : "", name); |
| 681 | } |
| 682 | |
| 683 | return str; |
| 684 | } |
| 685 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 686 | static void init_feature_attrs(void) |
| 687 | { |
| 688 | struct btrfs_feature_attr *fa; |
| 689 | int set, i; |
| 690 | |
| 691 | BUILD_BUG_ON(ARRAY_SIZE(btrfs_unknown_feature_names) != |
| 692 | ARRAY_SIZE(btrfs_feature_attrs)); |
| 693 | BUILD_BUG_ON(ARRAY_SIZE(btrfs_unknown_feature_names[0]) != |
| 694 | ARRAY_SIZE(btrfs_feature_attrs[0])); |
| 695 | |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame] | 696 | memset(btrfs_feature_attrs, 0, sizeof(btrfs_feature_attrs)); |
| 697 | memset(btrfs_unknown_feature_names, 0, |
| 698 | sizeof(btrfs_unknown_feature_names)); |
| 699 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 700 | for (i = 0; btrfs_supported_feature_attrs[i]; i++) { |
| 701 | struct btrfs_feature_attr *sfa; |
| 702 | struct attribute *a = btrfs_supported_feature_attrs[i]; |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame] | 703 | int bit; |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 704 | sfa = attr_to_btrfs_feature_attr(a); |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame] | 705 | bit = ilog2(sfa->feature_bit); |
| 706 | fa = &btrfs_feature_attrs[sfa->feature_set][bit]; |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 707 | |
| 708 | fa->kobj_attr.attr.name = sfa->kobj_attr.attr.name; |
| 709 | } |
| 710 | |
| 711 | for (set = 0; set < FEAT_MAX; set++) { |
| 712 | for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[set]); i++) { |
| 713 | char *name = btrfs_unknown_feature_names[set][i]; |
| 714 | fa = &btrfs_feature_attrs[set][i]; |
| 715 | |
| 716 | if (fa->kobj_attr.attr.name) |
| 717 | continue; |
| 718 | |
Tomohiro Misono | 6c52157 | 2018-05-16 17:09:26 +0900 | [diff] [blame] | 719 | snprintf(name, BTRFS_FEATURE_NAME_MAX, "%s:%u", |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 720 | btrfs_feature_set_names[set], i); |
| 721 | |
| 722 | fa->kobj_attr.attr.name = name; |
| 723 | fa->kobj_attr.attr.mode = S_IRUGO; |
| 724 | fa->feature_set = set; |
| 725 | fa->feature_bit = 1ULL << i; |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | |
Anand Jain | e7e1aa9 | 2015-03-10 06:38:21 +0800 | [diff] [blame] | 730 | /* when one_device is NULL, it removes all device links */ |
| 731 | |
Anand Jain | 3257604 | 2015-08-14 18:32:49 +0800 | [diff] [blame] | 732 | int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices, |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 733 | struct btrfs_device *one_device) |
| 734 | { |
| 735 | struct hd_struct *disk; |
| 736 | struct kobject *disk_kobj; |
| 737 | |
Anand Jain | 6c14a16 | 2015-03-10 06:38:34 +0800 | [diff] [blame] | 738 | if (!fs_devices->device_dir_kobj) |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 739 | return -EINVAL; |
| 740 | |
Liu Bo | 87fa3bb | 2014-07-29 19:09:39 +0800 | [diff] [blame] | 741 | if (one_device && one_device->bdev) { |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 742 | disk = one_device->bdev->bd_part; |
| 743 | disk_kobj = &part_to_dev(disk)->kobj; |
| 744 | |
Anand Jain | 6c14a16 | 2015-03-10 06:38:34 +0800 | [diff] [blame] | 745 | sysfs_remove_link(fs_devices->device_dir_kobj, |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 746 | disk_kobj->name); |
| 747 | } |
| 748 | |
Anand Jain | e7e1aa9 | 2015-03-10 06:38:21 +0800 | [diff] [blame] | 749 | if (one_device) |
| 750 | return 0; |
| 751 | |
| 752 | list_for_each_entry(one_device, |
Anand Jain | 6c14a16 | 2015-03-10 06:38:34 +0800 | [diff] [blame] | 753 | &fs_devices->devices, dev_list) { |
Anand Jain | e7e1aa9 | 2015-03-10 06:38:21 +0800 | [diff] [blame] | 754 | if (!one_device->bdev) |
| 755 | continue; |
| 756 | disk = one_device->bdev->bd_part; |
| 757 | disk_kobj = &part_to_dev(disk)->kobj; |
| 758 | |
Anand Jain | 6c14a16 | 2015-03-10 06:38:34 +0800 | [diff] [blame] | 759 | sysfs_remove_link(fs_devices->device_dir_kobj, |
Anand Jain | e7e1aa9 | 2015-03-10 06:38:21 +0800 | [diff] [blame] | 760 | disk_kobj->name); |
| 761 | } |
| 762 | |
Anand Jain | 99994cd | 2014-06-03 11:36:00 +0800 | [diff] [blame] | 763 | return 0; |
| 764 | } |
| 765 | |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 766 | int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs) |
Anand Jain | 00c921c | 2015-03-10 06:38:28 +0800 | [diff] [blame] | 767 | { |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 768 | if (!fs_devs->device_dir_kobj) |
| 769 | fs_devs->device_dir_kobj = kobject_create_and_add("devices", |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 770 | &fs_devs->fsid_kobj); |
Anand Jain | 00c921c | 2015-03-10 06:38:28 +0800 | [diff] [blame] | 771 | |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 772 | if (!fs_devs->device_dir_kobj) |
Anand Jain | 00c921c | 2015-03-10 06:38:28 +0800 | [diff] [blame] | 773 | return -ENOMEM; |
| 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
Anand Jain | e3bd697 | 2015-08-14 18:32:48 +0800 | [diff] [blame] | 778 | int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices, |
Anand Jain | 1ba4381 | 2015-03-10 06:38:33 +0800 | [diff] [blame] | 779 | struct btrfs_device *one_device) |
Jeff Mahoney | 29e5be2 | 2013-11-01 13:07:05 -0400 | [diff] [blame] | 780 | { |
| 781 | int error = 0; |
Jeff Mahoney | 29e5be2 | 2013-11-01 13:07:05 -0400 | [diff] [blame] | 782 | struct btrfs_device *dev; |
| 783 | |
Jeff Mahoney | 29e5be2 | 2013-11-01 13:07:05 -0400 | [diff] [blame] | 784 | list_for_each_entry(dev, &fs_devices->devices, dev_list) { |
Anand Jain | f085381 | 2014-01-15 17:22:28 +0800 | [diff] [blame] | 785 | struct hd_struct *disk; |
| 786 | struct kobject *disk_kobj; |
| 787 | |
| 788 | if (!dev->bdev) |
| 789 | continue; |
| 790 | |
Anand Jain | 0d39376 | 2014-06-03 11:36:01 +0800 | [diff] [blame] | 791 | if (one_device && one_device != dev) |
| 792 | continue; |
| 793 | |
Anand Jain | f085381 | 2014-01-15 17:22:28 +0800 | [diff] [blame] | 794 | disk = dev->bdev->bd_part; |
| 795 | disk_kobj = &part_to_dev(disk)->kobj; |
Jeff Mahoney | 29e5be2 | 2013-11-01 13:07:05 -0400 | [diff] [blame] | 796 | |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 797 | error = sysfs_create_link(fs_devices->device_dir_kobj, |
Jeff Mahoney | 29e5be2 | 2013-11-01 13:07:05 -0400 | [diff] [blame] | 798 | disk_kobj, disk_kobj->name); |
| 799 | if (error) |
| 800 | break; |
| 801 | } |
| 802 | |
| 803 | return error; |
| 804 | } |
| 805 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 806 | /* /sys/fs/btrfs/ entry */ |
| 807 | static struct kset *btrfs_kset; |
| 808 | |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 809 | /* /sys/kernel/debug/btrfs */ |
| 810 | static struct dentry *btrfs_debugfs_root_dentry; |
| 811 | |
| 812 | /* Debugging tunables and exported data */ |
| 813 | u64 btrfs_debugfs_test; |
| 814 | |
Anand Jain | 7205921 | 2015-03-10 06:38:26 +0800 | [diff] [blame] | 815 | /* |
| 816 | * Can be called by the device discovery thread. |
| 817 | * And parent can be specified for seed device |
| 818 | */ |
Anand Jain | 0c10e2d | 2015-03-10 06:38:35 +0800 | [diff] [blame] | 819 | int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs, |
Anand Jain | 7205921 | 2015-03-10 06:38:26 +0800 | [diff] [blame] | 820 | struct kobject *parent) |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 821 | { |
| 822 | int error; |
| 823 | |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 824 | init_completion(&fs_devs->kobj_unregister); |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 825 | fs_devs->fsid_kobj.kset = btrfs_kset; |
| 826 | error = kobject_init_and_add(&fs_devs->fsid_kobj, |
Anand Jain | 24bd69c | 2015-03-10 06:38:39 +0800 | [diff] [blame] | 827 | &btrfs_ktype, parent, "%pU", fs_devs->fsid); |
Anand Jain | 7205921 | 2015-03-10 06:38:26 +0800 | [diff] [blame] | 828 | return error; |
| 829 | } |
| 830 | |
Anand Jain | 96f3136 | 2015-08-14 18:32:46 +0800 | [diff] [blame] | 831 | int btrfs_sysfs_add_mounted(struct btrfs_fs_info *fs_info) |
Anand Jain | 7205921 | 2015-03-10 06:38:26 +0800 | [diff] [blame] | 832 | { |
| 833 | int error; |
Anand Jain | 2e7910d | 2015-03-10 06:38:29 +0800 | [diff] [blame] | 834 | struct btrfs_fs_devices *fs_devs = fs_info->fs_devices; |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 835 | struct kobject *fsid_kobj = &fs_devs->fsid_kobj; |
Anand Jain | 7205921 | 2015-03-10 06:38:26 +0800 | [diff] [blame] | 836 | |
Anand Jain | 5a13f43 | 2015-03-10 06:38:31 +0800 | [diff] [blame] | 837 | btrfs_set_fs_info_ptr(fs_info); |
| 838 | |
Anand Jain | e3bd697 | 2015-08-14 18:32:48 +0800 | [diff] [blame] | 839 | error = btrfs_sysfs_add_device_link(fs_devs, NULL); |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 840 | if (error) |
| 841 | return error; |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 842 | |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 843 | error = sysfs_create_files(fsid_kobj, btrfs_attrs); |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 844 | if (error) { |
Anand Jain | 3257604 | 2015-08-14 18:32:49 +0800 | [diff] [blame] | 845 | btrfs_sysfs_rm_device_link(fs_devs, NULL); |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 846 | return error; |
| 847 | } |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 848 | |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 849 | error = sysfs_create_group(fsid_kobj, |
Anand Jain | 0dd2906 | 2015-03-10 06:38:27 +0800 | [diff] [blame] | 850 | &btrfs_feature_attr_group); |
| 851 | if (error) |
| 852 | goto failure; |
| 853 | |
Jeff Mahoney | e453d98 | 2013-11-21 10:37:16 -0500 | [diff] [blame] | 854 | error = addrm_unknown_feature_attrs(fs_info, true); |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 855 | if (error) |
| 856 | goto failure; |
| 857 | |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 858 | fs_info->space_info_kobj = kobject_create_and_add("allocation", |
Anand Jain | c1b7e47 | 2015-08-14 18:32:50 +0800 | [diff] [blame] | 859 | fsid_kobj); |
Jeff Mahoney | 6ab0a20 | 2013-11-01 13:07:04 -0400 | [diff] [blame] | 860 | if (!fs_info->space_info_kobj) { |
| 861 | error = -ENOMEM; |
| 862 | goto failure; |
| 863 | } |
| 864 | |
| 865 | error = sysfs_create_files(fs_info->space_info_kobj, allocation_attrs); |
| 866 | if (error) |
| 867 | goto failure; |
| 868 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 869 | return 0; |
| 870 | failure: |
Anand Jain | 6618a59 | 2015-08-14 18:32:47 +0800 | [diff] [blame] | 871 | btrfs_sysfs_remove_mounted(fs_info); |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 872 | return error; |
| 873 | } |
| 874 | |
David Sterba | 444e751 | 2016-01-21 18:50:40 +0100 | [diff] [blame] | 875 | |
| 876 | /* |
| 877 | * Change per-fs features in /sys/fs/btrfs/UUID/features to match current |
| 878 | * values in superblock. Call after any changes to incompat/compat_ro flags |
| 879 | */ |
| 880 | void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info, |
| 881 | u64 bit, enum btrfs_feature_set set) |
| 882 | { |
| 883 | struct btrfs_fs_devices *fs_devs; |
| 884 | struct kobject *fsid_kobj; |
| 885 | u64 features; |
| 886 | int ret; |
| 887 | |
| 888 | if (!fs_info) |
| 889 | return; |
| 890 | |
| 891 | features = get_features(fs_info, set); |
| 892 | ASSERT(bit & supported_feature_masks[set]); |
| 893 | |
| 894 | fs_devs = fs_info->fs_devices; |
| 895 | fsid_kobj = &fs_devs->fsid_kobj; |
| 896 | |
David Sterba | bf60920 | 2016-01-27 14:06:29 +0100 | [diff] [blame] | 897 | if (!fsid_kobj->state_initialized) |
| 898 | return; |
| 899 | |
David Sterba | 444e751 | 2016-01-21 18:50:40 +0100 | [diff] [blame] | 900 | /* |
| 901 | * FIXME: this is too heavy to update just one value, ideally we'd like |
| 902 | * to use sysfs_update_group but some refactoring is needed first. |
| 903 | */ |
| 904 | sysfs_remove_group(fsid_kobj, &btrfs_feature_attr_group); |
| 905 | ret = sysfs_create_group(fsid_kobj, &btrfs_feature_attr_group); |
| 906 | } |
| 907 | |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 908 | static int btrfs_init_debugfs(void) |
| 909 | { |
| 910 | #ifdef CONFIG_DEBUG_FS |
| 911 | btrfs_debugfs_root_dentry = debugfs_create_dir("btrfs", NULL); |
| 912 | if (!btrfs_debugfs_root_dentry) |
| 913 | return -ENOMEM; |
| 914 | |
David Sterba | b0de6c4 | 2016-09-01 14:37:53 +0200 | [diff] [blame] | 915 | /* |
| 916 | * Example code, how to export data through debugfs. |
| 917 | * |
| 918 | * file: /sys/kernel/debug/btrfs/test |
| 919 | * contents of: btrfs_debugfs_test |
| 920 | */ |
| 921 | #ifdef CONFIG_BTRFS_DEBUG |
Eric Sandeen | 07f6a48 | 2016-08-31 16:49:29 -0500 | [diff] [blame] | 922 | debugfs_create_u64("test", S_IRUGO | S_IWUSR, btrfs_debugfs_root_dentry, |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 923 | &btrfs_debugfs_test); |
| 924 | #endif |
David Sterba | b0de6c4 | 2016-09-01 14:37:53 +0200 | [diff] [blame] | 925 | |
| 926 | #endif |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 927 | return 0; |
| 928 | } |
| 929 | |
Liu Bo | f5c29bd | 2017-11-02 17:21:50 -0600 | [diff] [blame] | 930 | int __init btrfs_init_sysfs(void) |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 931 | { |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 932 | int ret; |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 933 | |
Greg KH | e3fe4e7 | 2008-02-20 14:14:16 -0500 | [diff] [blame] | 934 | btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); |
| 935 | if (!btrfs_kset) |
| 936 | return -ENOMEM; |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 937 | |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 938 | ret = btrfs_init_debugfs(); |
| 939 | if (ret) |
Filipe Manana | 001a648 | 2015-01-23 18:27:00 +0000 | [diff] [blame] | 940 | goto out1; |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 941 | |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 942 | init_feature_attrs(); |
| 943 | ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
Filipe Manana | 001a648 | 2015-01-23 18:27:00 +0000 | [diff] [blame] | 944 | if (ret) |
| 945 | goto out2; |
Misono Tomohiro | f902bd3 | 2018-05-17 14:24:51 +0900 | [diff] [blame] | 946 | ret = sysfs_merge_group(&btrfs_kset->kobj, |
| 947 | &btrfs_static_feature_attr_group); |
| 948 | if (ret) |
| 949 | goto out_remove_group; |
Filipe Manana | 001a648 | 2015-01-23 18:27:00 +0000 | [diff] [blame] | 950 | |
| 951 | return 0; |
Misono Tomohiro | f902bd3 | 2018-05-17 14:24:51 +0900 | [diff] [blame] | 952 | |
| 953 | out_remove_group: |
| 954 | sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
Filipe Manana | 001a648 | 2015-01-23 18:27:00 +0000 | [diff] [blame] | 955 | out2: |
| 956 | debugfs_remove_recursive(btrfs_debugfs_root_dentry); |
| 957 | out1: |
| 958 | kset_unregister(btrfs_kset); |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 959 | |
| 960 | return ret; |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 961 | } |
| 962 | |
David Sterba | e67c718 | 2018-02-19 17:24:18 +0100 | [diff] [blame] | 963 | void __cold btrfs_exit_sysfs(void) |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 964 | { |
Misono Tomohiro | f902bd3 | 2018-05-17 14:24:51 +0900 | [diff] [blame] | 965 | sysfs_unmerge_group(&btrfs_kset->kobj, |
| 966 | &btrfs_static_feature_attr_group); |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 967 | sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
Greg KH | e3fe4e7 | 2008-02-20 14:14:16 -0500 | [diff] [blame] | 968 | kset_unregister(btrfs_kset); |
David Sterba | 1bae309 | 2014-02-05 15:36:18 +0100 | [diff] [blame] | 969 | debugfs_remove_recursive(btrfs_debugfs_root_dentry); |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 970 | } |
Chris Mason | 55d4741 | 2008-02-20 16:02:51 -0500 | [diff] [blame] | 971 | |