2 * Copyright (C) 2007 Oracle. All rights reserved.
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.
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.
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.
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>
24 #include <linux/kobject.h>
28 #include "transaction.h"
31 static void btrfs_release_super_kobj(struct kobject
*kobj
);
32 static struct kobj_type btrfs_ktype
= {
33 .sysfs_ops
= &kobj_sysfs_ops
,
34 .release
= btrfs_release_super_kobj
,
37 static inline struct btrfs_fs_info
*to_fs_info(struct kobject
*kobj
)
39 if (kobj
->ktype
!= &btrfs_ktype
)
41 return container_of(kobj
, struct btrfs_fs_info
, super_kobj
);
44 static void btrfs_release_super_kobj(struct kobject
*kobj
)
46 struct btrfs_fs_info
*fs_info
= to_fs_info(kobj
);
47 complete(&fs_info
->kobj_unregister
);
50 static ssize_t
btrfs_feature_attr_show(struct kobject
*kobj
,
51 struct kobj_attribute
*a
, char *buf
)
53 return snprintf(buf
, PAGE_SIZE
, "0\n");
56 BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref
, MIXED_BACKREF
);
57 BTRFS_FEAT_ATTR_INCOMPAT(default_subvol
, DEFAULT_SUBVOL
);
58 BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups
, MIXED_GROUPS
);
59 BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo
, COMPRESS_LZO
);
60 BTRFS_FEAT_ATTR_INCOMPAT(compress_lzov2
, COMPRESS_LZOv2
);
61 BTRFS_FEAT_ATTR_INCOMPAT(big_metadata
, BIG_METADATA
);
62 BTRFS_FEAT_ATTR_INCOMPAT(extended_iref
, EXTENDED_IREF
);
63 BTRFS_FEAT_ATTR_INCOMPAT(raid56
, RAID56
);
64 BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata
, SKINNY_METADATA
);
66 static struct attribute
*btrfs_supported_feature_attrs
[] = {
67 BTRFS_FEAT_ATTR_PTR(mixed_backref
),
68 BTRFS_FEAT_ATTR_PTR(default_subvol
),
69 BTRFS_FEAT_ATTR_PTR(mixed_groups
),
70 BTRFS_FEAT_ATTR_PTR(compress_lzo
),
71 BTRFS_FEAT_ATTR_PTR(compress_lzov2
),
72 BTRFS_FEAT_ATTR_PTR(big_metadata
),
73 BTRFS_FEAT_ATTR_PTR(extended_iref
),
74 BTRFS_FEAT_ATTR_PTR(raid56
),
75 BTRFS_FEAT_ATTR_PTR(skinny_metadata
),
79 static const struct attribute_group btrfs_feature_attr_group
= {
81 .attrs
= btrfs_supported_feature_attrs
,
84 /* /sys/fs/btrfs/ entry */
85 static struct kset
*btrfs_kset
;
87 void btrfs_sysfs_remove_one(struct btrfs_fs_info
*fs_info
)
89 kobject_del(&fs_info
->super_kobj
);
90 kobject_put(&fs_info
->super_kobj
);
91 wait_for_completion(&fs_info
->kobj_unregister
);
94 int btrfs_sysfs_add_one(struct btrfs_fs_info
*fs_info
)
98 init_completion(&fs_info
->kobj_unregister
);
99 error
= kobject_init_and_add(&fs_info
->super_kobj
, &btrfs_ktype
, NULL
,
100 "%pU", fs_info
->fsid
);
104 int btrfs_init_sysfs(void)
107 btrfs_kset
= kset_create_and_add("btrfs", NULL
, fs_kobj
);
111 ret
= sysfs_create_group(&btrfs_kset
->kobj
, &btrfs_feature_attr_group
);
113 kset_unregister(btrfs_kset
);
120 void btrfs_exit_sysfs(void)
122 sysfs_remove_group(&btrfs_kset
->kobj
, &btrfs_feature_attr_group
);
123 kset_unregister(btrfs_kset
);