Chris Mason | 6cbd557 | 2007-06-12 09:07:21 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Oracle. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public |
| 6 | * License v2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public |
| 14 | * License along with this program; if not, write to the |
| 15 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 16 | * Boston, MA 021110-1307, USA. |
| 17 | */ |
| 18 | |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 19 | #include <linux/sched.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/spinlock.h> |
| 22 | #include <linux/completion.h> |
| 23 | #include <linux/buffer_head.h> |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 24 | #include <linux/kobject.h> |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 25 | #include <linux/bug.h> |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 26 | |
Chris Mason | bae45de | 2007-04-04 21:22:22 -0400 | [diff] [blame] | 27 | #include "ctree.h" |
| 28 | #include "disk-io.h" |
| 29 | #include "transaction.h" |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 30 | #include "sysfs.h" |
| 31 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 32 | static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj); |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 33 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 34 | static u64 get_features(struct btrfs_fs_info *fs_info, |
| 35 | enum btrfs_feature_set set) |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 36 | { |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 37 | struct btrfs_super_block *disk_super = fs_info->super_copy; |
| 38 | if (set == FEAT_COMPAT) |
| 39 | return btrfs_super_compat_flags(disk_super); |
| 40 | else if (set == FEAT_COMPAT_RO) |
| 41 | return btrfs_super_compat_ro_flags(disk_super); |
| 42 | else |
| 43 | return btrfs_super_incompat_flags(disk_super); |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 44 | } |
| 45 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 46 | static void set_features(struct btrfs_fs_info *fs_info, |
| 47 | enum btrfs_feature_set set, u64 features) |
| 48 | { |
| 49 | struct btrfs_super_block *disk_super = fs_info->super_copy; |
| 50 | if (set == FEAT_COMPAT) |
| 51 | btrfs_set_super_compat_flags(disk_super, features); |
| 52 | else if (set == FEAT_COMPAT_RO) |
| 53 | btrfs_set_super_compat_ro_flags(disk_super, features); |
| 54 | else |
| 55 | btrfs_set_super_incompat_flags(disk_super, features); |
| 56 | } |
| 57 | |
| 58 | static int can_modify_feature(struct btrfs_feature_attr *fa) |
| 59 | { |
| 60 | int val = 0; |
| 61 | u64 set, clear; |
| 62 | switch (fa->feature_set) { |
| 63 | case FEAT_COMPAT: |
| 64 | set = BTRFS_FEATURE_COMPAT_SAFE_SET; |
| 65 | clear = BTRFS_FEATURE_COMPAT_SAFE_CLEAR; |
| 66 | break; |
| 67 | case FEAT_COMPAT_RO: |
| 68 | set = BTRFS_FEATURE_COMPAT_RO_SAFE_SET; |
| 69 | clear = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR; |
| 70 | break; |
| 71 | case FEAT_INCOMPAT: |
| 72 | set = BTRFS_FEATURE_INCOMPAT_SAFE_SET; |
| 73 | clear = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR; |
| 74 | break; |
| 75 | default: |
| 76 | BUG(); |
| 77 | } |
| 78 | |
| 79 | if (set & fa->feature_bit) |
| 80 | val |= 1; |
| 81 | if (clear & fa->feature_bit) |
| 82 | val |= 2; |
| 83 | |
| 84 | return val; |
| 85 | } |
| 86 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 87 | static ssize_t btrfs_feature_attr_show(struct kobject *kobj, |
| 88 | struct kobj_attribute *a, char *buf) |
| 89 | { |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 90 | int val = 0; |
| 91 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 92 | struct btrfs_feature_attr *fa = to_btrfs_feature_attr(a); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 93 | if (fs_info) { |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 94 | u64 features = get_features(fs_info, fa->feature_set); |
| 95 | if (features & fa->feature_bit) |
| 96 | val = 1; |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 97 | } else |
| 98 | val = can_modify_feature(fa); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 99 | |
| 100 | return snprintf(buf, PAGE_SIZE, "%d\n", val); |
| 101 | } |
| 102 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 103 | static ssize_t btrfs_feature_attr_store(struct kobject *kobj, |
| 104 | struct kobj_attribute *a, |
| 105 | const char *buf, size_t count) |
| 106 | { |
| 107 | struct btrfs_fs_info *fs_info; |
| 108 | struct btrfs_feature_attr *fa = to_btrfs_feature_attr(a); |
| 109 | struct btrfs_trans_handle *trans; |
| 110 | u64 features, set, clear; |
| 111 | unsigned long val; |
| 112 | int ret; |
| 113 | |
| 114 | fs_info = to_fs_info(kobj); |
| 115 | if (!fs_info) |
| 116 | return -EPERM; |
| 117 | |
| 118 | ret = kstrtoul(skip_spaces(buf), 0, &val); |
| 119 | if (ret) |
| 120 | return ret; |
| 121 | |
| 122 | if (fa->feature_set == FEAT_COMPAT) { |
| 123 | set = BTRFS_FEATURE_COMPAT_SAFE_SET; |
| 124 | clear = BTRFS_FEATURE_COMPAT_SAFE_CLEAR; |
| 125 | } else if (fa->feature_set == FEAT_COMPAT_RO) { |
| 126 | set = BTRFS_FEATURE_COMPAT_RO_SAFE_SET; |
| 127 | clear = BTRFS_FEATURE_COMPAT_RO_SAFE_CLEAR; |
| 128 | } else { |
| 129 | set = BTRFS_FEATURE_INCOMPAT_SAFE_SET; |
| 130 | clear = BTRFS_FEATURE_INCOMPAT_SAFE_CLEAR; |
| 131 | } |
| 132 | |
| 133 | features = get_features(fs_info, fa->feature_set); |
| 134 | |
| 135 | /* Nothing to do */ |
| 136 | if ((val && (features & fa->feature_bit)) || |
| 137 | (!val && !(features & fa->feature_bit))) |
| 138 | return count; |
| 139 | |
| 140 | if ((val && !(set & fa->feature_bit)) || |
| 141 | (!val && !(clear & fa->feature_bit))) { |
| 142 | btrfs_info(fs_info, |
| 143 | "%sabling feature %s on mounted fs is not supported.", |
| 144 | val ? "En" : "Dis", fa->kobj_attr.attr.name); |
| 145 | return -EPERM; |
| 146 | } |
| 147 | |
| 148 | btrfs_info(fs_info, "%s %s feature flag", |
| 149 | val ? "Setting" : "Clearing", fa->kobj_attr.attr.name); |
| 150 | |
| 151 | trans = btrfs_start_transaction(fs_info->fs_root, 1); |
| 152 | if (IS_ERR(trans)) |
| 153 | return PTR_ERR(trans); |
| 154 | |
| 155 | spin_lock(&fs_info->super_lock); |
| 156 | features = get_features(fs_info, fa->feature_set); |
| 157 | if (val) |
| 158 | features |= fa->feature_bit; |
| 159 | else |
| 160 | features &= ~fa->feature_bit; |
| 161 | set_features(fs_info, fa->feature_set, features); |
| 162 | spin_unlock(&fs_info->super_lock); |
| 163 | |
| 164 | ret = btrfs_commit_transaction(trans, fs_info->fs_root); |
| 165 | if (ret) |
| 166 | return ret; |
| 167 | |
| 168 | return count; |
| 169 | } |
| 170 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 171 | static umode_t btrfs_feature_visible(struct kobject *kobj, |
| 172 | struct attribute *attr, int unused) |
| 173 | { |
| 174 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 175 | umode_t mode = attr->mode; |
| 176 | |
| 177 | if (fs_info) { |
| 178 | struct btrfs_feature_attr *fa; |
| 179 | u64 features; |
| 180 | |
| 181 | fa = attr_to_btrfs_feature_attr(attr); |
| 182 | features = get_features(fs_info, fa->feature_set); |
| 183 | |
Jeff Mahoney | ba63194 | 2013-11-01 13:07:01 -0400 | [diff] [blame] | 184 | if (can_modify_feature(fa)) |
| 185 | mode |= S_IWUSR; |
| 186 | else if (!(features & fa->feature_bit)) |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 187 | mode = 0; |
| 188 | } |
| 189 | |
| 190 | return mode; |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF); |
| 194 | BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL); |
| 195 | BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS); |
| 196 | BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo, COMPRESS_LZO); |
| 197 | BTRFS_FEAT_ATTR_INCOMPAT(compress_lzov2, COMPRESS_LZOv2); |
| 198 | BTRFS_FEAT_ATTR_INCOMPAT(big_metadata, BIG_METADATA); |
| 199 | BTRFS_FEAT_ATTR_INCOMPAT(extended_iref, EXTENDED_IREF); |
| 200 | BTRFS_FEAT_ATTR_INCOMPAT(raid56, RAID56); |
| 201 | BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA); |
| 202 | |
| 203 | static struct attribute *btrfs_supported_feature_attrs[] = { |
| 204 | BTRFS_FEAT_ATTR_PTR(mixed_backref), |
| 205 | BTRFS_FEAT_ATTR_PTR(default_subvol), |
| 206 | BTRFS_FEAT_ATTR_PTR(mixed_groups), |
| 207 | BTRFS_FEAT_ATTR_PTR(compress_lzo), |
| 208 | BTRFS_FEAT_ATTR_PTR(compress_lzov2), |
| 209 | BTRFS_FEAT_ATTR_PTR(big_metadata), |
| 210 | BTRFS_FEAT_ATTR_PTR(extended_iref), |
| 211 | BTRFS_FEAT_ATTR_PTR(raid56), |
| 212 | BTRFS_FEAT_ATTR_PTR(skinny_metadata), |
| 213 | NULL |
| 214 | }; |
| 215 | |
| 216 | static const struct attribute_group btrfs_feature_attr_group = { |
| 217 | .name = "features", |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 218 | .is_visible = btrfs_feature_visible, |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 219 | .attrs = btrfs_supported_feature_attrs, |
| 220 | }; |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 221 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 222 | static void btrfs_release_super_kobj(struct kobject *kobj) |
| 223 | { |
| 224 | struct btrfs_fs_info *fs_info = to_fs_info(kobj); |
| 225 | complete(&fs_info->kobj_unregister); |
| 226 | } |
| 227 | |
| 228 | static struct kobj_type btrfs_ktype = { |
| 229 | .sysfs_ops = &kobj_sysfs_ops, |
| 230 | .release = btrfs_release_super_kobj, |
| 231 | }; |
| 232 | |
| 233 | static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj) |
| 234 | { |
| 235 | if (kobj->ktype != &btrfs_ktype) |
| 236 | return NULL; |
| 237 | return container_of(kobj, struct btrfs_fs_info, super_kobj); |
| 238 | } |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 239 | |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 240 | void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info) |
| 241 | { |
| 242 | kobject_del(&fs_info->super_kobj); |
| 243 | kobject_put(&fs_info->super_kobj); |
| 244 | wait_for_completion(&fs_info->kobj_unregister); |
| 245 | } |
| 246 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 247 | const char * const btrfs_feature_set_names[3] = { |
| 248 | [FEAT_COMPAT] = "compat", |
| 249 | [FEAT_COMPAT_RO] = "compat_ro", |
| 250 | [FEAT_INCOMPAT] = "incompat", |
| 251 | }; |
| 252 | |
| 253 | #define NUM_FEATURE_BITS 64 |
| 254 | static char btrfs_unknown_feature_names[3][NUM_FEATURE_BITS][13]; |
| 255 | static struct btrfs_feature_attr btrfs_feature_attrs[3][NUM_FEATURE_BITS]; |
| 256 | |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame^] | 257 | char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags) |
| 258 | { |
| 259 | size_t bufsize = 4096; /* safe max, 64 names * 64 bytes */ |
| 260 | int len = 0; |
| 261 | int i; |
| 262 | char *str; |
| 263 | |
| 264 | str = kmalloc(bufsize, GFP_KERNEL); |
| 265 | if (!str) |
| 266 | return str; |
| 267 | |
| 268 | for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[set]); i++) { |
| 269 | const char *name; |
| 270 | |
| 271 | if (!(flags & (1ULL << i))) |
| 272 | continue; |
| 273 | |
| 274 | name = btrfs_feature_attrs[set][i].kobj_attr.attr.name; |
| 275 | len += snprintf(str + len, bufsize - len, "%s%s", |
| 276 | len ? "," : "", name); |
| 277 | } |
| 278 | |
| 279 | return str; |
| 280 | } |
| 281 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 282 | static void init_feature_attrs(void) |
| 283 | { |
| 284 | struct btrfs_feature_attr *fa; |
| 285 | int set, i; |
| 286 | |
| 287 | BUILD_BUG_ON(ARRAY_SIZE(btrfs_unknown_feature_names) != |
| 288 | ARRAY_SIZE(btrfs_feature_attrs)); |
| 289 | BUILD_BUG_ON(ARRAY_SIZE(btrfs_unknown_feature_names[0]) != |
| 290 | ARRAY_SIZE(btrfs_feature_attrs[0])); |
| 291 | |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame^] | 292 | memset(btrfs_feature_attrs, 0, sizeof(btrfs_feature_attrs)); |
| 293 | memset(btrfs_unknown_feature_names, 0, |
| 294 | sizeof(btrfs_unknown_feature_names)); |
| 295 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 296 | for (i = 0; btrfs_supported_feature_attrs[i]; i++) { |
| 297 | struct btrfs_feature_attr *sfa; |
| 298 | struct attribute *a = btrfs_supported_feature_attrs[i]; |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame^] | 299 | int bit; |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 300 | sfa = attr_to_btrfs_feature_attr(a); |
Jeff Mahoney | 3b02a68 | 2013-11-01 13:07:02 -0400 | [diff] [blame^] | 301 | bit = ilog2(sfa->feature_bit); |
| 302 | fa = &btrfs_feature_attrs[sfa->feature_set][bit]; |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 303 | |
| 304 | fa->kobj_attr.attr.name = sfa->kobj_attr.attr.name; |
| 305 | } |
| 306 | |
| 307 | for (set = 0; set < FEAT_MAX; set++) { |
| 308 | for (i = 0; i < ARRAY_SIZE(btrfs_feature_attrs[set]); i++) { |
| 309 | char *name = btrfs_unknown_feature_names[set][i]; |
| 310 | fa = &btrfs_feature_attrs[set][i]; |
| 311 | |
| 312 | if (fa->kobj_attr.attr.name) |
| 313 | continue; |
| 314 | |
| 315 | snprintf(name, 13, "%s:%u", |
| 316 | btrfs_feature_set_names[set], i); |
| 317 | |
| 318 | fa->kobj_attr.attr.name = name; |
| 319 | fa->kobj_attr.attr.mode = S_IRUGO; |
| 320 | fa->feature_set = set; |
| 321 | fa->feature_bit = 1ULL << i; |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | static u64 supported_feature_masks[3] = { |
| 327 | [FEAT_COMPAT] = BTRFS_FEATURE_COMPAT_SUPP, |
| 328 | [FEAT_COMPAT_RO] = BTRFS_FEATURE_COMPAT_RO_SUPP, |
| 329 | [FEAT_INCOMPAT] = BTRFS_FEATURE_INCOMPAT_SUPP, |
| 330 | }; |
| 331 | |
| 332 | static int add_unknown_feature_attrs(struct btrfs_fs_info *fs_info) |
| 333 | { |
| 334 | int set; |
| 335 | |
| 336 | for (set = 0; set < FEAT_MAX; set++) { |
| 337 | int i, count, ret, index = 0; |
| 338 | struct attribute **attrs; |
| 339 | struct attribute_group agroup = { |
| 340 | .name = "features", |
| 341 | }; |
| 342 | u64 features = get_features(fs_info, set); |
| 343 | features &= ~supported_feature_masks[set]; |
| 344 | |
| 345 | count = hweight64(features); |
| 346 | |
| 347 | if (!count) |
| 348 | continue; |
| 349 | |
| 350 | attrs = kcalloc(count + 1, sizeof(void *), GFP_KERNEL); |
| 351 | |
| 352 | for (i = 0; i < NUM_FEATURE_BITS; i++) { |
| 353 | struct btrfs_feature_attr *fa; |
| 354 | |
| 355 | if (!(features & (1ULL << i))) |
| 356 | continue; |
| 357 | |
| 358 | fa = &btrfs_feature_attrs[set][i]; |
| 359 | attrs[index++] = &fa->kobj_attr.attr; |
| 360 | } |
| 361 | |
| 362 | attrs[index] = NULL; |
| 363 | agroup.attrs = attrs; |
| 364 | |
| 365 | ret = sysfs_merge_group(&fs_info->super_kobj, &agroup); |
| 366 | kfree(attrs); |
| 367 | if (ret) |
| 368 | return ret; |
| 369 | } |
| 370 | return 0; |
| 371 | } |
| 372 | |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 373 | /* /sys/fs/btrfs/ entry */ |
| 374 | static struct kset *btrfs_kset; |
| 375 | |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 376 | int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info) |
| 377 | { |
| 378 | int error; |
| 379 | |
| 380 | init_completion(&fs_info->kobj_unregister); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 381 | fs_info->super_kobj.kset = btrfs_kset; |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 382 | error = kobject_init_and_add(&fs_info->super_kobj, &btrfs_ktype, NULL, |
| 383 | "%pU", fs_info->fsid); |
Jeff Mahoney | 510d736 | 2013-11-01 13:06:59 -0400 | [diff] [blame] | 384 | |
| 385 | error = sysfs_create_group(&fs_info->super_kobj, |
| 386 | &btrfs_feature_attr_group); |
| 387 | if (error) |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 388 | goto failure; |
| 389 | |
| 390 | error = add_unknown_feature_attrs(fs_info); |
| 391 | if (error) |
| 392 | goto failure; |
| 393 | |
| 394 | return 0; |
| 395 | failure: |
| 396 | btrfs_sysfs_remove_one(fs_info); |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame] | 397 | return error; |
| 398 | } |
| 399 | |
Christoph Hellwig | b214107 | 2008-09-05 16:43:31 -0400 | [diff] [blame] | 400 | int btrfs_init_sysfs(void) |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 401 | { |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 402 | int ret; |
Greg KH | e3fe4e7 | 2008-02-20 14:14:16 -0500 | [diff] [blame] | 403 | btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj); |
| 404 | if (!btrfs_kset) |
| 405 | return -ENOMEM; |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 406 | |
Jeff Mahoney | 79da4fa | 2013-11-01 13:07:00 -0400 | [diff] [blame] | 407 | init_feature_attrs(); |
| 408 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 409 | ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
| 410 | if (ret) { |
| 411 | kset_unregister(btrfs_kset); |
| 412 | return ret; |
| 413 | } |
| 414 | |
Greg KH | e3fe4e7 | 2008-02-20 14:14:16 -0500 | [diff] [blame] | 415 | return 0; |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 416 | } |
| 417 | |
Christoph Hellwig | b214107 | 2008-09-05 16:43:31 -0400 | [diff] [blame] | 418 | void btrfs_exit_sysfs(void) |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 419 | { |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 420 | sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group); |
Greg KH | e3fe4e7 | 2008-02-20 14:14:16 -0500 | [diff] [blame] | 421 | kset_unregister(btrfs_kset); |
Josef Bacik | 58176a9 | 2007-08-29 15:47:34 -0400 | [diff] [blame] | 422 | } |
Chris Mason | 55d4741 | 2008-02-20 16:02:51 -0500 | [diff] [blame] | 423 | |