sysfs.c 16.0 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6 7 8 9 10 11 12 13
/*
 *  linux/fs/ext4/sysfs.c
 *
 * Copyright (C) 1992, 1993, 1994, 1995
 * Remy Card (card@masi.ibp.fr)
 * Theodore Ts'o (tytso@mit.edu)
 *
 */

#include <linux/time.h>
#include <linux/fs.h>
#include <linux/seq_file.h>
14
#include <linux/slab.h>
15
#include <linux/proc_fs.h>
16
#include <linux/part_stat.h>
17 18 19 20

#include "ext4.h"
#include "ext4_jbd2.h"

21 22 23 24 25 26
typedef enum {
	attr_noop,
	attr_delayed_allocation_blocks,
	attr_session_write_kbytes,
	attr_lifetime_write_kbytes,
	attr_reserved_clusters,
27
	attr_sra_exceeded_retry_limit,
28 29
	attr_inode_readahead,
	attr_trigger_test_error,
30 31
	attr_first_error_time,
	attr_last_error_time,
32 33
	attr_feature,
	attr_pointer_ui,
34
	attr_pointer_ul,
35 36 37
	attr_pointer_u64,
	attr_pointer_u8,
	attr_pointer_string,
38
	attr_pointer_atomic,
39
	attr_journal_task,
40 41 42 43 44 45 46 47
} attr_id_t;

typedef enum {
	ptr_explicit,
	ptr_ext4_sb_info_offset,
	ptr_ext4_super_block_offset,
} attr_ptr_t;

48
static const char proc_dirname[] = "fs/ext4";
49 50
static struct proc_dir_entry *ext4_proc_root;

51 52
struct ext4_attr {
	struct attribute attr;
53 54
	short attr_id;
	short attr_ptr;
55
	unsigned short attr_size;
56 57
	union {
		int offset;
58
		void *explicit_ptr;
59 60 61
	} u;
};

62
static ssize_t session_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
63 64 65 66
{
	struct super_block *sb = sbi->s_buddy_cache->i_sb;

	return snprintf(buf, PAGE_SIZE, "%lu\n",
67
			(part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
68 69 70
			 sbi->s_sectors_written_start) >> 1);
}

71
static ssize_t lifetime_write_kbytes_show(struct ext4_sb_info *sbi, char *buf)
72 73 74 75 76
{
	struct super_block *sb = sbi->s_buddy_cache->i_sb;

	return snprintf(buf, PAGE_SIZE, "%llu\n",
			(unsigned long long)(sbi->s_kbytes_written +
77
			((part_stat_read(sb->s_bdev, sectors[STAT_WRITE]) -
78 79 80
			  EXT4_SB(sb)->s_sectors_written_start) >> 1)));
}

81
static ssize_t inode_readahead_blks_store(struct ext4_sb_info *sbi,
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
					  const char *buf, size_t count)
{
	unsigned long t;
	int ret;

	ret = kstrtoul(skip_spaces(buf), 0, &t);
	if (ret)
		return ret;

	if (t && (!is_power_of_2(t) || t > 0x40000000))
		return -EINVAL;

	sbi->s_inode_readahead_blks = t;
	return count;
}

98
static ssize_t reserved_clusters_store(struct ext4_sb_info *sbi,
99 100 101 102 103
				   const char *buf, size_t count)
{
	unsigned long long val;
	ext4_fsblk_t clusters = (ext4_blocks_count(sbi->s_es) >>
				 sbi->s_cluster_bits);
104
	int ret;
105

106
	ret = kstrtoull(skip_spaces(buf), 0, &val);
107
	if (ret || val >= clusters)
108 109 110 111 112 113
		return -EINVAL;

	atomic64_set(&sbi->s_resv_clusters, val);
	return count;
}

114
static ssize_t trigger_test_error(struct ext4_sb_info *sbi,
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
				  const char *buf, size_t count)
{
	int len = count;

	if (!capable(CAP_SYS_ADMIN))
		return -EPERM;

	if (len && buf[len-1] == '\n')
		len--;

	if (len)
		ext4_error(sbi->s_sb, "%.*s", len, buf);
	return count;
}

130 131 132 133 134 135 136 137
static ssize_t journal_task_show(struct ext4_sb_info *sbi, char *buf)
{
	if (!sbi->s_journal)
		return snprintf(buf, PAGE_SIZE, "<none>\n");
	return snprintf(buf, PAGE_SIZE, "%d\n",
			task_pid_vnr(sbi->s_journal->j_task));
}

138 139 140 141
#define EXT4_ATTR(_name,_mode,_id)					\
static struct ext4_attr ext4_attr_##_name = {				\
	.attr = {.name = __stringify(_name), .mode = _mode },		\
	.attr_id = attr_##_id,						\
142 143
}

144 145 146 147 148
#define EXT4_ATTR_FUNC(_name,_mode)  EXT4_ATTR(_name,_mode,_name)

#define EXT4_ATTR_FEATURE(_name)   EXT4_ATTR(_name, 0444, feature)

#define EXT4_ATTR_OFFSET(_name,_mode,_id,_struct,_elname)	\
149 150
static struct ext4_attr ext4_attr_##_name = {			\
	.attr = {.name = __stringify(_name), .mode = _mode },	\
151 152
	.attr_id = attr_##_id,					\
	.attr_ptr = ptr_##_struct##_offset,			\
153
	.u = {							\
154
		.offset = offsetof(struct _struct, _elname),\
155 156 157
	},							\
}

158 159 160 161 162 163 164 165 166 167 168
#define EXT4_ATTR_STRING(_name,_mode,_size,_struct,_elname)	\
static struct ext4_attr ext4_attr_##_name = {			\
	.attr = {.name = __stringify(_name), .mode = _mode },	\
	.attr_id = attr_pointer_string,				\
	.attr_size = _size,					\
	.attr_ptr = ptr_##_struct##_offset,			\
	.u = {							\
		.offset = offsetof(struct _struct, _elname),\
	},							\
}

169 170
#define EXT4_RO_ATTR_ES_UI(_name,_elname)				\
	EXT4_ATTR_OFFSET(_name, 0444, pointer_ui, ext4_super_block, _elname)
171

172 173 174 175 176 177 178 179 180
#define EXT4_RO_ATTR_ES_U8(_name,_elname)				\
	EXT4_ATTR_OFFSET(_name, 0444, pointer_u8, ext4_super_block, _elname)

#define EXT4_RO_ATTR_ES_U64(_name,_elname)				\
	EXT4_ATTR_OFFSET(_name, 0444, pointer_u64, ext4_super_block, _elname)

#define EXT4_RO_ATTR_ES_STRING(_name,_elname,_size)			\
	EXT4_ATTR_STRING(_name, 0444, _size, ext4_super_block, _elname)

181 182
#define EXT4_RW_ATTR_SBI_UI(_name,_elname)	\
	EXT4_ATTR_OFFSET(_name, 0644, pointer_ui, ext4_sb_info, _elname)
183

184 185 186
#define EXT4_RW_ATTR_SBI_UL(_name,_elname)	\
	EXT4_ATTR_OFFSET(_name, 0644, pointer_ul, ext4_sb_info, _elname)

187 188 189
#define EXT4_RO_ATTR_SBI_ATOMIC(_name,_elname)	\
	EXT4_ATTR_OFFSET(_name, 0444, pointer_atomic, ext4_sb_info, _elname)

190
#define EXT4_ATTR_PTR(_name,_mode,_id,_ptr) \
191
static struct ext4_attr ext4_attr_##_name = {			\
192 193 194
	.attr = {.name = __stringify(_name), .mode = _mode },	\
	.attr_id = attr_##_id,					\
	.attr_ptr = ptr_explicit,				\
195
	.u = {							\
196
		.explicit_ptr = _ptr,				\
197 198 199
	},							\
}

200 201 202 203 204 205
#define ATTR_LIST(name) &ext4_attr_##name.attr

EXT4_ATTR_FUNC(delayed_allocation_blocks, 0444);
EXT4_ATTR_FUNC(session_write_kbytes, 0444);
EXT4_ATTR_FUNC(lifetime_write_kbytes, 0444);
EXT4_ATTR_FUNC(reserved_clusters, 0644);
206
EXT4_ATTR_FUNC(sra_exceeded_retry_limit, 0444);
207 208 209

EXT4_ATTR_OFFSET(inode_readahead_blks, 0644, inode_readahead,
		 ext4_sb_info, s_inode_readahead_blks);
210 211 212 213 214 215 216
EXT4_RW_ATTR_SBI_UI(inode_goal, s_inode_goal);
EXT4_RW_ATTR_SBI_UI(mb_stats, s_mb_stats);
EXT4_RW_ATTR_SBI_UI(mb_max_to_scan, s_mb_max_to_scan);
EXT4_RW_ATTR_SBI_UI(mb_min_to_scan, s_mb_min_to_scan);
EXT4_RW_ATTR_SBI_UI(mb_order2_req, s_mb_order2_reqs);
EXT4_RW_ATTR_SBI_UI(mb_stream_req, s_mb_stream_request);
EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
217
EXT4_RW_ATTR_SBI_UI(mb_max_inode_prealloc, s_mb_max_inode_prealloc);
218
EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
219
EXT4_ATTR(trigger_fs_error, 0200, trigger_test_error);
220 221 222 223 224 225
EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
226 227 228
#ifdef CONFIG_EXT4_DEBUG
EXT4_RW_ATTR_SBI_UL(simulate_fail, s_simulate_fail);
#endif
229 230
EXT4_RO_ATTR_SBI_ATOMIC(warning_count, s_warning_count);
EXT4_RO_ATTR_SBI_ATOMIC(msg_count, s_msg_count);
231
EXT4_RO_ATTR_ES_UI(errors_count, s_error_count);
232 233 234 235 236 237 238 239 240 241
EXT4_RO_ATTR_ES_U8(first_error_errcode, s_first_error_errcode);
EXT4_RO_ATTR_ES_U8(last_error_errcode, s_last_error_errcode);
EXT4_RO_ATTR_ES_UI(first_error_ino, s_first_error_ino);
EXT4_RO_ATTR_ES_UI(last_error_ino, s_last_error_ino);
EXT4_RO_ATTR_ES_U64(first_error_block, s_first_error_block);
EXT4_RO_ATTR_ES_U64(last_error_block, s_last_error_block);
EXT4_RO_ATTR_ES_UI(first_error_line, s_first_error_line);
EXT4_RO_ATTR_ES_UI(last_error_line, s_last_error_line);
EXT4_RO_ATTR_ES_STRING(first_error_func, s_first_error_func, 32);
EXT4_RO_ATTR_ES_STRING(last_error_func, s_last_error_func, 32);
242 243
EXT4_ATTR(first_error_time, 0444, first_error_time);
EXT4_ATTR(last_error_time, 0444, last_error_time);
244
EXT4_ATTR(journal_task, 0444, journal_task);
245 246
EXT4_RW_ATTR_SBI_UI(mb_prefetch, s_mb_prefetch);
EXT4_RW_ATTR_SBI_UI(mb_prefetch_limit, s_mb_prefetch_limit);
247

248 249 250
static unsigned int old_bump_val = 128;
EXT4_ATTR_PTR(max_writeback_mb_bump, 0444, pointer_ui, &old_bump_val);

251 252 253 254 255
static struct attribute *ext4_attrs[] = {
	ATTR_LIST(delayed_allocation_blocks),
	ATTR_LIST(session_write_kbytes),
	ATTR_LIST(lifetime_write_kbytes),
	ATTR_LIST(reserved_clusters),
256
	ATTR_LIST(sra_exceeded_retry_limit),
257 258 259 260 261 262 263 264
	ATTR_LIST(inode_readahead_blks),
	ATTR_LIST(inode_goal),
	ATTR_LIST(mb_stats),
	ATTR_LIST(mb_max_to_scan),
	ATTR_LIST(mb_min_to_scan),
	ATTR_LIST(mb_order2_req),
	ATTR_LIST(mb_stream_req),
	ATTR_LIST(mb_group_prealloc),
265
	ATTR_LIST(mb_max_inode_prealloc),
266 267 268 269 270 271 272 273 274 275
	ATTR_LIST(max_writeback_mb_bump),
	ATTR_LIST(extent_max_zeroout_kb),
	ATTR_LIST(trigger_fs_error),
	ATTR_LIST(err_ratelimit_interval_ms),
	ATTR_LIST(err_ratelimit_burst),
	ATTR_LIST(warning_ratelimit_interval_ms),
	ATTR_LIST(warning_ratelimit_burst),
	ATTR_LIST(msg_ratelimit_interval_ms),
	ATTR_LIST(msg_ratelimit_burst),
	ATTR_LIST(errors_count),
276 277
	ATTR_LIST(warning_count),
	ATTR_LIST(msg_count),
278 279 280 281 282 283 284 285 286 287
	ATTR_LIST(first_error_ino),
	ATTR_LIST(last_error_ino),
	ATTR_LIST(first_error_block),
	ATTR_LIST(last_error_block),
	ATTR_LIST(first_error_line),
	ATTR_LIST(last_error_line),
	ATTR_LIST(first_error_func),
	ATTR_LIST(last_error_func),
	ATTR_LIST(first_error_errcode),
	ATTR_LIST(last_error_errcode),
288 289
	ATTR_LIST(first_error_time),
	ATTR_LIST(last_error_time),
290
	ATTR_LIST(journal_task),
291 292 293
#ifdef CONFIG_EXT4_DEBUG
	ATTR_LIST(simulate_fail),
#endif
294 295
	ATTR_LIST(mb_prefetch),
	ATTR_LIST(mb_prefetch_limit),
296 297
	NULL,
};
298
ATTRIBUTE_GROUPS(ext4);
299 300

/* Features this copy of ext4 supports */
301 302 303
EXT4_ATTR_FEATURE(lazy_itable_init);
EXT4_ATTR_FEATURE(batched_discard);
EXT4_ATTR_FEATURE(meta_bg_resize);
304
#ifdef CONFIG_FS_ENCRYPTION
305
EXT4_ATTR_FEATURE(encryption);
306
EXT4_ATTR_FEATURE(test_dummy_encryption_v2);
307
#endif
308 309 310
#ifdef CONFIG_UNICODE
EXT4_ATTR_FEATURE(casefold);
#endif
E
Eric Biggers 已提交
311 312 313
#ifdef CONFIG_FS_VERITY
EXT4_ATTR_FEATURE(verity);
#endif
314
EXT4_ATTR_FEATURE(metadata_csum_seed);
315
EXT4_ATTR_FEATURE(fast_commit);
316
EXT4_ATTR_FEATURE(encrypted_casefold);
317 318 319 320 321

static struct attribute *ext4_feat_attrs[] = {
	ATTR_LIST(lazy_itable_init),
	ATTR_LIST(batched_discard),
	ATTR_LIST(meta_bg_resize),
322
#ifdef CONFIG_FS_ENCRYPTION
323
	ATTR_LIST(encryption),
324
	ATTR_LIST(test_dummy_encryption_v2),
325 326 327
#endif
#ifdef CONFIG_UNICODE
	ATTR_LIST(casefold),
E
Eric Biggers 已提交
328 329 330
#endif
#ifdef CONFIG_FS_VERITY
	ATTR_LIST(verity),
331
#endif
332
	ATTR_LIST(metadata_csum_seed),
333
	ATTR_LIST(fast_commit),
334
	ATTR_LIST(encrypted_casefold),
335 336
	NULL,
};
337
ATTRIBUTE_GROUPS(ext4_feat);
338

339 340 341 342 343 344 345 346 347 348 349 350 351
static void *calc_ptr(struct ext4_attr *a, struct ext4_sb_info *sbi)
{
	switch (a->attr_ptr) {
	case ptr_explicit:
		return a->u.explicit_ptr;
	case ptr_ext4_sb_info_offset:
		return (void *) (((char *) sbi) + a->u.offset);
	case ptr_ext4_super_block_offset:
		return (void *) (((char *) sbi->s_es) + a->u.offset);
	}
	return NULL;
}

352 353
static ssize_t __print_tstamp(char *buf, __le32 lo, __u8 hi)
{
354
	return snprintf(buf, PAGE_SIZE, "%lld\n",
355 356 357 358 359 360
			((time64_t)hi << 32) + le32_to_cpu(lo));
}

#define print_tstamp(buf, es, tstamp) \
	__print_tstamp(buf, (es)->tstamp, (es)->tstamp ## _hi)

361 362 363 364 365 366
static ssize_t ext4_attr_show(struct kobject *kobj,
			      struct attribute *attr, char *buf)
{
	struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
						s_kobj);
	struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
367 368 369 370 371 372 373 374
	void *ptr = calc_ptr(a, sbi);

	switch (a->attr_id) {
	case attr_delayed_allocation_blocks:
		return snprintf(buf, PAGE_SIZE, "%llu\n",
				(s64) EXT4_C2B(sbi,
		       percpu_counter_sum(&sbi->s_dirtyclusters_counter)));
	case attr_session_write_kbytes:
375
		return session_write_kbytes_show(sbi, buf);
376
	case attr_lifetime_write_kbytes:
377
		return lifetime_write_kbytes_show(sbi, buf);
378 379 380 381
	case attr_reserved_clusters:
		return snprintf(buf, PAGE_SIZE, "%llu\n",
				(unsigned long long)
				atomic64_read(&sbi->s_resv_clusters));
382 383 384 385
	case attr_sra_exceeded_retry_limit:
		return snprintf(buf, PAGE_SIZE, "%llu\n",
				(unsigned long long)
			percpu_counter_sum(&sbi->s_sra_exceeded_retry_limit));
386 387 388 389
	case attr_inode_readahead:
	case attr_pointer_ui:
		if (!ptr)
			return 0;
390 391 392 393 394 395
		if (a->attr_ptr == ptr_ext4_super_block_offset)
			return snprintf(buf, PAGE_SIZE, "%u\n",
					le32_to_cpup(ptr));
		else
			return snprintf(buf, PAGE_SIZE, "%u\n",
					*((unsigned int *) ptr));
396 397 398 399 400
	case attr_pointer_ul:
		if (!ptr)
			return 0;
		return snprintf(buf, PAGE_SIZE, "%lu\n",
				*((unsigned long *) ptr));
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
	case attr_pointer_u8:
		if (!ptr)
			return 0;
		return snprintf(buf, PAGE_SIZE, "%u\n",
				*((unsigned char *) ptr));
	case attr_pointer_u64:
		if (!ptr)
			return 0;
		if (a->attr_ptr == ptr_ext4_super_block_offset)
			return snprintf(buf, PAGE_SIZE, "%llu\n",
					le64_to_cpup(ptr));
		else
			return snprintf(buf, PAGE_SIZE, "%llu\n",
					*((unsigned long long *) ptr));
	case attr_pointer_string:
		if (!ptr)
			return 0;
		return snprintf(buf, PAGE_SIZE, "%.*s\n", a->attr_size,
				(char *) ptr);
420 421 422 423 424 425 426
	case attr_pointer_atomic:
		if (!ptr)
			return 0;
		return snprintf(buf, PAGE_SIZE, "%d\n",
				atomic_read((atomic_t *) ptr));
	case attr_feature:
		return snprintf(buf, PAGE_SIZE, "supported\n");
427 428 429 430
	case attr_first_error_time:
		return print_tstamp(buf, sbi->s_es, s_first_error_time);
	case attr_last_error_time:
		return print_tstamp(buf, sbi->s_es, s_last_error_time);
431 432
	case attr_journal_task:
		return journal_task_show(sbi, buf);
433 434 435
	}

	return 0;
436 437 438 439 440 441 442 443 444
}

static ssize_t ext4_attr_store(struct kobject *kobj,
			       struct attribute *attr,
			       const char *buf, size_t len)
{
	struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
						s_kobj);
	struct ext4_attr *a = container_of(attr, struct ext4_attr, attr);
445 446 447
	void *ptr = calc_ptr(a, sbi);
	unsigned long t;
	int ret;
448

449 450
	switch (a->attr_id) {
	case attr_reserved_clusters:
451
		return reserved_clusters_store(sbi, buf, len);
452 453 454 455 456 457
	case attr_pointer_ui:
		if (!ptr)
			return 0;
		ret = kstrtoul(skip_spaces(buf), 0, &t);
		if (ret)
			return ret;
458 459 460 461
		if (a->attr_ptr == ptr_ext4_super_block_offset)
			*((__le32 *) ptr) = cpu_to_le32(t);
		else
			*((unsigned int *) ptr) = t;
462
		return len;
463 464 465 466 467 468 469 470
	case attr_pointer_ul:
		if (!ptr)
			return 0;
		ret = kstrtoul(skip_spaces(buf), 0, &t);
		if (ret)
			return ret;
		*((unsigned long *) ptr) = t;
		return len;
471
	case attr_inode_readahead:
472
		return inode_readahead_blks_store(sbi, buf, len);
473
	case attr_trigger_test_error:
474
		return trigger_test_error(sbi, buf, len);
475 476
	}
	return 0;
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
}

static void ext4_sb_release(struct kobject *kobj)
{
	struct ext4_sb_info *sbi = container_of(kobj, struct ext4_sb_info,
						s_kobj);
	complete(&sbi->s_kobj_unregister);
}

static const struct sysfs_ops ext4_attr_ops = {
	.show	= ext4_attr_show,
	.store	= ext4_attr_store,
};

static struct kobj_type ext4_sb_ktype = {
492
	.default_groups = ext4_groups,
493 494 495 496 497
	.sysfs_ops	= &ext4_attr_ops,
	.release	= ext4_sb_release,
};

static struct kobj_type ext4_feat_ktype = {
498
	.default_groups = ext4_feat_groups,
499
	.sysfs_ops	= &ext4_attr_ops,
500
	.release	= (void (*)(struct kobject *))kfree,
501 502
};

T
Tyson Nottingham 已提交
503 504
static struct kobject *ext4_root;

505
static struct kobject *ext4_feat;
506 507 508 509

int ext4_register_sysfs(struct super_block *sb)
{
	struct ext4_sb_info *sbi = EXT4_SB(sb);
510
	int err;
511 512

	init_completion(&sbi->s_kobj_unregister);
T
Tyson Nottingham 已提交
513
	err = kobject_init_and_add(&sbi->s_kobj, &ext4_sb_ktype, ext4_root,
514
				   "%s", sb->s_id);
515 516 517
	if (err) {
		kobject_put(&sbi->s_kobj);
		wait_for_completion(&sbi->s_kobj_unregister);
518
		return err;
519
	}
520 521 522 523

	if (ext4_proc_root)
		sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);
	if (sbi->s_proc) {
C
Christoph Hellwig 已提交
524 525 526 527 528
		proc_create_single_data("options", S_IRUGO, sbi->s_proc,
				ext4_seq_options_show, sb);
		proc_create_single_data("es_shrinker_info", S_IRUGO,
				sbi->s_proc, ext4_seq_es_shrinker_info_show,
				sb);
529 530
		proc_create_single_data("fc_info", 0444, sbi->s_proc,
					ext4_fc_info_show, sb);
C
Christoph Hellwig 已提交
531 532
		proc_create_seq_data("mb_groups", S_IRUGO, sbi->s_proc,
				&ext4_mb_seq_groups_ops, sb);
533 534 535 536 537 538 539 540
	}
	return 0;
}

void ext4_unregister_sysfs(struct super_block *sb)
{
	struct ext4_sb_info *sbi = EXT4_SB(sb);

C
Christoph Hellwig 已提交
541 542
	if (sbi->s_proc)
		remove_proc_subtree(sb->s_id, ext4_proc_root);
543
	kobject_del(&sbi->s_kobj);
544 545 546 547 548 549
}

int __init ext4_init_sysfs(void)
{
	int ret;

T
Tyson Nottingham 已提交
550 551
	ext4_root = kobject_create_and_add("ext4", fs_kobj);
	if (!ext4_root)
552 553
		return -ENOMEM;

554 555 556
	ext4_feat = kzalloc(sizeof(*ext4_feat), GFP_KERNEL);
	if (!ext4_feat) {
		ret = -ENOMEM;
T
Tyson Nottingham 已提交
557
		goto root_err;
558
	}
559 560

	ret = kobject_init_and_add(ext4_feat, &ext4_feat_ktype,
T
Tyson Nottingham 已提交
561
				   ext4_root, "features");
562 563 564 565 566 567 568 569
	if (ret)
		goto feat_err;

	ext4_proc_root = proc_mkdir(proc_dirname, NULL);
	return ret;

feat_err:
	kobject_put(ext4_feat);
570
	ext4_feat = NULL;
T
Tyson Nottingham 已提交
571 572 573
root_err:
	kobject_put(ext4_root);
	ext4_root = NULL;
574 575 576 577 578
	return ret;
}

void ext4_exit_sysfs(void)
{
579
	kobject_put(ext4_feat);
580
	ext4_feat = NULL;
T
Tyson Nottingham 已提交
581 582
	kobject_put(ext4_root);
	ext4_root = NULL;
583 584
	remove_proc_entry(proc_dirname, NULL);
	ext4_proc_root = NULL;
585 586
}