blob: 79be4a187af9e0478f882bda03ef6593125c9a72 [file] [log] [blame]
Chris Mason6cbd5572007-06-12 09:07:21 -04001/*
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 Bacik58176a92007-08-29 15:47:34 -040019#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 Bacik58176a92007-08-29 15:47:34 -040024#include <linux/kobject.h>
25
Chris Masonbae45de2007-04-04 21:22:22 -040026#include "ctree.h"
27#include "disk-io.h"
28#include "transaction.h"
Jeff Mahoney079b72b2013-11-01 13:06:57 -040029#include "sysfs.h"
30
Jeff Mahoney5ac1d202013-11-01 13:06:58 -040031static void btrfs_release_super_kobj(struct kobject *kobj);
32static struct kobj_type btrfs_ktype = {
33 .sysfs_ops = &kobj_sysfs_ops,
34 .release = btrfs_release_super_kobj,
35};
36
37static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
38{
39 if (kobj->ktype != &btrfs_ktype)
40 return NULL;
41 return container_of(kobj, struct btrfs_fs_info, super_kobj);
42}
43
44static void btrfs_release_super_kobj(struct kobject *kobj)
45{
46 struct btrfs_fs_info *fs_info = to_fs_info(kobj);
47 complete(&fs_info->kobj_unregister);
48}
49
Jeff Mahoney079b72b2013-11-01 13:06:57 -040050static ssize_t btrfs_feature_attr_show(struct kobject *kobj,
51 struct kobj_attribute *a, char *buf)
52{
53 return snprintf(buf, PAGE_SIZE, "0\n");
54}
55
56BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF);
57BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL);
58BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS);
59BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo, COMPRESS_LZO);
60BTRFS_FEAT_ATTR_INCOMPAT(compress_lzov2, COMPRESS_LZOv2);
61BTRFS_FEAT_ATTR_INCOMPAT(big_metadata, BIG_METADATA);
62BTRFS_FEAT_ATTR_INCOMPAT(extended_iref, EXTENDED_IREF);
63BTRFS_FEAT_ATTR_INCOMPAT(raid56, RAID56);
64BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA);
65
66static 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),
76 NULL
77};
78
79static const struct attribute_group btrfs_feature_attr_group = {
80 .name = "features",
81 .attrs = btrfs_supported_feature_attrs,
82};
Josef Bacik58176a92007-08-29 15:47:34 -040083
Greg KHe3fe4e72008-02-20 14:14:16 -050084/* /sys/fs/btrfs/ entry */
85static struct kset *btrfs_kset;
Josef Bacik58176a92007-08-29 15:47:34 -040086
Jeff Mahoney5ac1d202013-11-01 13:06:58 -040087void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
88{
89 kobject_del(&fs_info->super_kobj);
90 kobject_put(&fs_info->super_kobj);
91 wait_for_completion(&fs_info->kobj_unregister);
92}
93
94int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
95{
96 int error;
97
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);
101 return error;
102}
103
Christoph Hellwigb2141072008-09-05 16:43:31 -0400104int btrfs_init_sysfs(void)
Josef Bacik58176a92007-08-29 15:47:34 -0400105{
Jeff Mahoney079b72b2013-11-01 13:06:57 -0400106 int ret;
Greg KHe3fe4e72008-02-20 14:14:16 -0500107 btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);
108 if (!btrfs_kset)
109 return -ENOMEM;
Jeff Mahoney079b72b2013-11-01 13:06:57 -0400110
111 ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
112 if (ret) {
113 kset_unregister(btrfs_kset);
114 return ret;
115 }
116
Greg KHe3fe4e72008-02-20 14:14:16 -0500117 return 0;
Josef Bacik58176a92007-08-29 15:47:34 -0400118}
119
Christoph Hellwigb2141072008-09-05 16:43:31 -0400120void btrfs_exit_sysfs(void)
Josef Bacik58176a92007-08-29 15:47:34 -0400121{
Jeff Mahoney079b72b2013-11-01 13:06:57 -0400122 sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
Greg KHe3fe4e72008-02-20 14:14:16 -0500123 kset_unregister(btrfs_kset);
Josef Bacik58176a92007-08-29 15:47:34 -0400124}
Chris Mason55d47412008-02-20 16:02:51 -0500125