xref: /openbmc/linux/fs/btrfs/sysfs.c (revision 5ac1d209)
16cbd5570SChris Mason /*
26cbd5570SChris Mason  * Copyright (C) 2007 Oracle.  All rights reserved.
36cbd5570SChris Mason  *
46cbd5570SChris Mason  * This program is free software; you can redistribute it and/or
56cbd5570SChris Mason  * modify it under the terms of the GNU General Public
66cbd5570SChris Mason  * License v2 as published by the Free Software Foundation.
76cbd5570SChris Mason  *
86cbd5570SChris Mason  * This program is distributed in the hope that it will be useful,
96cbd5570SChris Mason  * but WITHOUT ANY WARRANTY; without even the implied warranty of
106cbd5570SChris Mason  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
116cbd5570SChris Mason  * General Public License for more details.
126cbd5570SChris Mason  *
136cbd5570SChris Mason  * You should have received a copy of the GNU General Public
146cbd5570SChris Mason  * License along with this program; if not, write to the
156cbd5570SChris Mason  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
166cbd5570SChris Mason  * Boston, MA 021110-1307, USA.
176cbd5570SChris Mason  */
186cbd5570SChris Mason 
1958176a96SJosef Bacik #include <linux/sched.h>
2058176a96SJosef Bacik #include <linux/slab.h>
2158176a96SJosef Bacik #include <linux/spinlock.h>
2258176a96SJosef Bacik #include <linux/completion.h>
2358176a96SJosef Bacik #include <linux/buffer_head.h>
2458176a96SJosef Bacik #include <linux/kobject.h>
2558176a96SJosef Bacik 
26bae45de0SChris Mason #include "ctree.h"
27bae45de0SChris Mason #include "disk-io.h"
28bae45de0SChris Mason #include "transaction.h"
29079b72bcSJeff Mahoney #include "sysfs.h"
30079b72bcSJeff Mahoney 
315ac1d209SJeff Mahoney static void btrfs_release_super_kobj(struct kobject *kobj);
325ac1d209SJeff Mahoney static struct kobj_type btrfs_ktype = {
335ac1d209SJeff Mahoney 	.sysfs_ops	= &kobj_sysfs_ops,
345ac1d209SJeff Mahoney 	.release	= btrfs_release_super_kobj,
355ac1d209SJeff Mahoney };
365ac1d209SJeff Mahoney 
375ac1d209SJeff Mahoney static inline struct btrfs_fs_info *to_fs_info(struct kobject *kobj)
385ac1d209SJeff Mahoney {
395ac1d209SJeff Mahoney 	if (kobj->ktype != &btrfs_ktype)
405ac1d209SJeff Mahoney 		return NULL;
415ac1d209SJeff Mahoney 	return container_of(kobj, struct btrfs_fs_info, super_kobj);
425ac1d209SJeff Mahoney }
435ac1d209SJeff Mahoney 
445ac1d209SJeff Mahoney static void btrfs_release_super_kobj(struct kobject *kobj)
455ac1d209SJeff Mahoney {
465ac1d209SJeff Mahoney 	struct btrfs_fs_info *fs_info = to_fs_info(kobj);
475ac1d209SJeff Mahoney 	complete(&fs_info->kobj_unregister);
485ac1d209SJeff Mahoney }
495ac1d209SJeff Mahoney 
50079b72bcSJeff Mahoney static ssize_t btrfs_feature_attr_show(struct kobject *kobj,
51079b72bcSJeff Mahoney 				       struct kobj_attribute *a, char *buf)
52079b72bcSJeff Mahoney {
53079b72bcSJeff Mahoney 	return snprintf(buf, PAGE_SIZE, "0\n");
54079b72bcSJeff Mahoney }
55079b72bcSJeff Mahoney 
56079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(mixed_backref, MIXED_BACKREF);
57079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(default_subvol, DEFAULT_SUBVOL);
58079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(mixed_groups, MIXED_GROUPS);
59079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(compress_lzo, COMPRESS_LZO);
60079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(compress_lzov2, COMPRESS_LZOv2);
61079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(big_metadata, BIG_METADATA);
62079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(extended_iref, EXTENDED_IREF);
63079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(raid56, RAID56);
64079b72bcSJeff Mahoney BTRFS_FEAT_ATTR_INCOMPAT(skinny_metadata, SKINNY_METADATA);
65079b72bcSJeff Mahoney 
66079b72bcSJeff Mahoney static struct attribute *btrfs_supported_feature_attrs[] = {
67079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(mixed_backref),
68079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(default_subvol),
69079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(mixed_groups),
70079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(compress_lzo),
71079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(compress_lzov2),
72079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(big_metadata),
73079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(extended_iref),
74079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(raid56),
75079b72bcSJeff Mahoney 	BTRFS_FEAT_ATTR_PTR(skinny_metadata),
76079b72bcSJeff Mahoney 	NULL
77079b72bcSJeff Mahoney };
78079b72bcSJeff Mahoney 
79079b72bcSJeff Mahoney static const struct attribute_group btrfs_feature_attr_group = {
80079b72bcSJeff Mahoney 	.name = "features",
81079b72bcSJeff Mahoney 	.attrs = btrfs_supported_feature_attrs,
82079b72bcSJeff Mahoney };
8358176a96SJosef Bacik 
84e3fe4e71SGreg KH /* /sys/fs/btrfs/ entry */
85e3fe4e71SGreg KH static struct kset *btrfs_kset;
8658176a96SJosef Bacik 
875ac1d209SJeff Mahoney void btrfs_sysfs_remove_one(struct btrfs_fs_info *fs_info)
885ac1d209SJeff Mahoney {
895ac1d209SJeff Mahoney 	kobject_del(&fs_info->super_kobj);
905ac1d209SJeff Mahoney 	kobject_put(&fs_info->super_kobj);
915ac1d209SJeff Mahoney 	wait_for_completion(&fs_info->kobj_unregister);
925ac1d209SJeff Mahoney }
935ac1d209SJeff Mahoney 
945ac1d209SJeff Mahoney int btrfs_sysfs_add_one(struct btrfs_fs_info *fs_info)
955ac1d209SJeff Mahoney {
965ac1d209SJeff Mahoney 	int error;
975ac1d209SJeff Mahoney 
985ac1d209SJeff Mahoney 	init_completion(&fs_info->kobj_unregister);
995ac1d209SJeff Mahoney 	error = kobject_init_and_add(&fs_info->super_kobj, &btrfs_ktype, NULL,
1005ac1d209SJeff Mahoney 				     "%pU", fs_info->fsid);
1015ac1d209SJeff Mahoney 	return error;
1025ac1d209SJeff Mahoney }
1035ac1d209SJeff Mahoney 
104b214107eSChristoph Hellwig int btrfs_init_sysfs(void)
10558176a96SJosef Bacik {
106079b72bcSJeff Mahoney 	int ret;
107e3fe4e71SGreg KH 	btrfs_kset = kset_create_and_add("btrfs", NULL, fs_kobj);
108e3fe4e71SGreg KH 	if (!btrfs_kset)
109e3fe4e71SGreg KH 		return -ENOMEM;
110079b72bcSJeff Mahoney 
111079b72bcSJeff Mahoney 	ret = sysfs_create_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
112079b72bcSJeff Mahoney 	if (ret) {
113079b72bcSJeff Mahoney 		kset_unregister(btrfs_kset);
114079b72bcSJeff Mahoney 		return ret;
115079b72bcSJeff Mahoney 	}
116079b72bcSJeff Mahoney 
117e3fe4e71SGreg KH 	return 0;
11858176a96SJosef Bacik }
11958176a96SJosef Bacik 
120b214107eSChristoph Hellwig void btrfs_exit_sysfs(void)
12158176a96SJosef Bacik {
122079b72bcSJeff Mahoney 	sysfs_remove_group(&btrfs_kset->kobj, &btrfs_feature_attr_group);
123e3fe4e71SGreg KH 	kset_unregister(btrfs_kset);
12458176a96SJosef Bacik }
12555d47414SChris Mason 
126