3 /* fs/reiserfs/procfs.c */
6 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
9 /* proc info support a la one created by Sizif@Botik.RU for PGC */
11 #include <linux/module.h>
12 #include <linux/time.h>
13 #include <linux/seq_file.h>
14 #include <asm/uaccess.h>
15 #include <linux/reiserfs_fs.h>
16 #include <linux/reiserfs_fs_sb.h>
17 #include <linux/init.h>
18 #include <linux/proc_fs.h>
20 #ifdef CONFIG_REISERFS_PROC_INFO
25 * We rely on new Alexander Viro's super-block locking.
29 static int show_version(struct seq_file *m, struct super_block *sb)
33 if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
35 } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
41 seq_printf(m, "%s format\twith checks %s\n", format,
42 #if defined( CONFIG_REISERFS_CHECK )
51 int reiserfs_global_version_in_proc(char *buffer, char **start, off_t offset,
52 int count, int *eof, void *data)
59 #define SF( x ) ( r -> x )
60 #define SFP( x ) SF( s_proc_info_data.x )
61 #define SFPL( x ) SFP( x[ level ] )
62 #define SFPF( x ) SFP( scan_bitmap.x )
63 #define SFPJ( x ) SFP( journal.x )
65 #define D2C( x ) le16_to_cpu( x )
66 #define D4C( x ) le32_to_cpu( x )
67 #define DF( x ) D2C( rs -> s_v1.x )
68 #define DFL( x ) D4C( rs -> s_v1.x )
70 #define objectid_map( s, rs ) (old_format_only (s) ? \
71 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
73 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
75 #define DJF( x ) le32_to_cpu( rs -> x )
76 #define DJV( x ) le32_to_cpu( s_v1 -> x )
77 #define DJP( x ) le32_to_cpu( jp -> x )
78 #define JF( x ) ( r -> s_journal -> x )
80 static int show_super(struct seq_file *m, struct super_block *sb)
82 struct reiserfs_sb_info *r = REISERFS_SB(sb);
84 seq_printf(m, "state: \t%s\n"
85 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
86 "gen. counter: \t%i\n"
87 "s_disk_reads: \t%i\n"
88 "s_disk_writes: \t%i\n"
90 "s_do_balance: \t%i\n"
91 "s_unneeded_left_neighbor: \t%i\n"
92 "s_good_search_by_key_reada: \t%i\n"
94 "s_bmaps_without_search: \t%i\n"
95 "s_direct2indirect: \t%i\n"
96 "s_indirect2direct: \t%i\n"
98 "max_hash_collisions: \t%i\n"
100 "bread_misses: \t%lu\n"
101 "search_by_key: \t%lu\n"
102 "search_by_key_fs_changed: \t%lu\n"
103 "search_by_key_restarted: \t%lu\n"
104 "insert_item_restarted: \t%lu\n"
105 "paste_into_item_restarted: \t%lu\n"
106 "cut_from_item_restarted: \t%lu\n"
107 "delete_solid_item_restarted: \t%lu\n"
108 "delete_item_restarted: \t%lu\n"
109 "leaked_oid: \t%lu\n"
110 "leaves_removable: \t%lu\n",
111 SF(s_mount_state) == REISERFS_VALID_FS ?
112 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
113 reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
114 reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
115 reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
116 reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
117 reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
118 reiserfs_no_unhashed_relocation(sb) ?
119 "NO_UNHASHED_RELOCATION " : "",
120 reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
121 reiserfs_test4(sb) ? "TEST4 " : "",
122 have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
123 "SMALL_TAILS " : "NO_TAILS ",
124 replay_only(sb) ? "REPLAY_ONLY " : "",
125 convert_reiserfs(sb) ? "CONV " : "",
126 atomic_read(&r->s_generation_counter),
127 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
128 SF(s_do_balance), SF(s_unneeded_left_neighbor),
129 SF(s_good_search_by_key_reada), SF(s_bmaps),
130 SF(s_bmaps_without_search), SF(s_direct2indirect),
131 SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
132 SFP(bread_miss), SFP(search_by_key),
133 SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
134 SFP(insert_item_restarted), SFP(paste_into_item_restarted),
135 SFP(cut_from_item_restarted),
136 SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
137 SFP(leaked_oid), SFP(leaves_removable));
142 static int show_per_level(struct seq_file *m, struct super_block *sb)
144 struct reiserfs_sb_info *r = REISERFS_SB(sb);
147 seq_printf(m, "level\t"
160 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
162 for (level = 0; level < MAX_HEIGHT; ++level) {
183 SFPL(sbk_fs_changed),
187 SFPL(can_node_be_removed),
193 SFPL(get_neighbors_restart),
194 SFPL(need_l_neighbor), SFPL(need_r_neighbor)
200 static int show_bitmap(struct seq_file *m, struct super_block *sb)
202 struct reiserfs_sb_info *r = REISERFS_SB(sb);
204 seq_printf(m, "free_block: %lu\n"
227 SFPF(in_journal_hint), SFPF(in_journal_nohint));
232 static int show_on_disk_super(struct seq_file *m, struct super_block *sb)
234 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
235 struct reiserfs_super_block *rs = sb_info->s_rs;
236 int hash_code = DFL(s_hash_function_code);
237 __u32 flags = DJF(s_flags);
239 seq_printf(m, "block_count: \t%i\n"
240 "free_blocks: \t%i\n"
243 "oid_maxsize: \t%i\n"
244 "oid_cursize: \t%i\n"
245 "umount_state: \t%i\n"
249 "tree_height: \t%i\n"
253 "reserved_for_journal: \t%i\n",
263 hash_code == TEA_HASH ? "tea" :
264 (hash_code == YURA_HASH) ? "rupasov" :
265 (hash_code == R5_HASH) ? "r5" :
266 (hash_code == UNSET_HASH) ? "unset" : "unknown",
269 DF(s_version), flags, (flags & reiserfs_attrs_cleared)
270 ? "attrs_cleared" : "", DF(s_reserved_for_journal));
275 static int show_oidmap(struct seq_file *m, struct super_block *sb)
277 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
278 struct reiserfs_super_block *rs = sb_info->s_rs;
279 unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
280 unsigned long total_used = 0;
283 for (i = 0; i < mapsize; ++i) {
286 right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
287 seq_printf(m, "%s: [ %x .. %x )\n",
288 (i & 1) ? "free" : "used", MAP(i), right);
290 total_used += right - MAP(i);
293 #if defined( REISERFS_USE_OIDMAPF )
294 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
295 loff_t size = sb_info->oidmap.mapf->f_path.dentry->d_inode->i_size;
296 total_used += size / sizeof(reiserfs_oidinterval_d_t);
299 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
301 mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
305 static int show_journal(struct seq_file *m, struct super_block *sb)
307 struct reiserfs_sb_info *r = REISERFS_SB(sb);
308 struct reiserfs_super_block *rs = r->s_rs;
309 struct journal_params *jp = &rs->s_v1.s_journal;
310 char b[BDEVNAME_SIZE];
312 seq_printf(m, /* on-disk fields */
313 "jp_journal_1st_block: \t%i\n"
314 "jp_journal_dev: \t%s[%x]\n"
315 "jp_journal_size: \t%i\n"
316 "jp_journal_trans_max: \t%i\n"
317 "jp_journal_magic: \t%i\n"
318 "jp_journal_max_batch: \t%i\n"
319 "jp_journal_max_commit_age: \t%i\n"
320 "jp_journal_max_trans_age: \t%i\n"
322 "j_1st_reserved_block: \t%i\n"
325 "j_mount_id: \t%lu\n"
328 "j_len_alloc: \t%lu\n"
331 "j_first_unflushed_offset: \t%lu\n"
332 "j_last_flush_trans_id: \t%u\n"
333 "j_trans_start_time: \t%li\n"
334 "j_list_bitmap_index: \t%i\n"
335 "j_must_wait: \t%i\n"
336 "j_next_full_flush: \t%i\n"
337 "j_next_async_flush: \t%i\n"
338 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
339 /* reiserfs_proc_info_data_t.journal fields */
340 "in_journal: \t%12lu\n"
341 "in_journal_bitmap: \t%12lu\n"
342 "in_journal_reusable: \t%12lu\n"
343 "lock_journal: \t%12lu\n"
344 "lock_journal_wait: \t%12lu\n"
345 "journal_begin: \t%12lu\n"
346 "journal_relock_writers: \t%12lu\n"
347 "journal_relock_wcount: \t%12lu\n"
348 "mark_dirty: \t%12lu\n"
349 "mark_dirty_already: \t%12lu\n"
350 "mark_dirty_notjournal: \t%12lu\n"
351 "restore_prepared: \t%12lu\n"
353 "prepare_retry: \t%12lu\n",
354 DJP(jp_journal_1st_block),
355 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
357 DJP(jp_journal_size),
358 DJP(jp_journal_trans_max),
359 DJP(jp_journal_magic),
360 DJP(jp_journal_max_batch),
361 SB_JOURNAL(sb)->j_max_commit_age,
362 DJP(jp_journal_max_trans_age),
363 JF(j_1st_reserved_block),
370 atomic_read(&r->s_journal->j_wcount),
372 JF(j_first_unflushed_offset),
373 JF(j_last_flush_trans_id),
374 JF(j_trans_start_time),
375 JF(j_list_bitmap_index),
377 JF(j_next_full_flush),
378 JF(j_next_async_flush),
382 SFPJ(in_journal_bitmap),
383 SFPJ(in_journal_reusable),
385 SFPJ(lock_journal_wait),
387 SFPJ(journal_relock_writers),
388 SFPJ(journal_relock_wcount),
390 SFPJ(mark_dirty_already),
391 SFPJ(mark_dirty_notjournal),
392 SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
398 static int test_sb(struct super_block *sb, void *data)
403 static int set_sb(struct super_block *sb, void *data)
408 static void *r_start(struct seq_file *m, loff_t * pos)
410 struct proc_dir_entry *de = m->private;
411 struct super_block *s = de->parent->data;
417 if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, s)))
420 up_write(&s->s_umount);
424 static void *r_next(struct seq_file *m, void *v, loff_t * pos)
432 static void r_stop(struct seq_file *m, void *v)
438 static int r_show(struct seq_file *m, void *v)
440 struct proc_dir_entry *de = m->private;
441 int (*show) (struct seq_file *, struct super_block *) = de->data;
445 static const struct seq_operations r_ops = {
452 static int r_open(struct inode *inode, struct file *file)
454 int ret = seq_open(file, &r_ops);
457 struct seq_file *m = file->private_data;
458 m->private = PDE(inode);
463 static const struct file_operations r_file_operations = {
467 .release = seq_release,
468 .owner = THIS_MODULE,
471 static struct proc_dir_entry *proc_info_root = NULL;
472 static const char proc_info_root_name[] = "fs/reiserfs";
474 static void add_file(struct super_block *sb, char *name,
475 int (*func) (struct seq_file *, struct super_block *))
477 proc_create_data(name, 0, REISERFS_SB(sb)->procdir,
478 &r_file_operations, func);
481 int reiserfs_proc_info_init(struct super_block *sb)
483 char b[BDEVNAME_SIZE];
486 /* Some block devices use /'s */
487 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
492 spin_lock_init(&__PINFO(sb).lock);
493 REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root);
494 if (REISERFS_SB(sb)->procdir) {
495 REISERFS_SB(sb)->procdir->data = sb;
496 add_file(sb, "version", show_version);
497 add_file(sb, "super", show_super);
498 add_file(sb, "per-level", show_per_level);
499 add_file(sb, "bitmap", show_bitmap);
500 add_file(sb, "on-disk-super", show_on_disk_super);
501 add_file(sb, "oidmap", show_oidmap);
502 add_file(sb, "journal", show_journal);
505 reiserfs_warning(sb, "cannot create /proc/%s/%s",
506 proc_info_root_name, b);
510 int reiserfs_proc_info_done(struct super_block *sb)
512 struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
513 char b[BDEVNAME_SIZE];
516 /* Some block devices use /'s */
517 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
523 remove_proc_entry("journal", de);
524 remove_proc_entry("oidmap", de);
525 remove_proc_entry("on-disk-super", de);
526 remove_proc_entry("bitmap", de);
527 remove_proc_entry("per-level", de);
528 remove_proc_entry("super", de);
529 remove_proc_entry("version", de);
531 spin_lock(&__PINFO(sb).lock);
532 __PINFO(sb).exiting = 1;
533 spin_unlock(&__PINFO(sb).lock);
534 if (proc_info_root) {
535 remove_proc_entry(b, proc_info_root);
536 REISERFS_SB(sb)->procdir = NULL;
541 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
544 return (proc_info_root) ? create_proc_read_entry(name, 0,
549 void reiserfs_proc_unregister_global(const char *name)
551 remove_proc_entry(name, proc_info_root);
554 int reiserfs_proc_info_global_init(void)
556 if (proc_info_root == NULL) {
557 proc_info_root = proc_mkdir(proc_info_root_name, NULL);
558 if (!proc_info_root) {
559 reiserfs_warning(NULL, "cannot create /proc/%s",
560 proc_info_root_name);
567 int reiserfs_proc_info_global_done(void)
569 if (proc_info_root != NULL) {
570 proc_info_root = NULL;
571 remove_proc_entry(proc_info_root_name, NULL);
576 /* REISERFS_PROC_INFO */
579 int reiserfs_proc_info_init(struct super_block *sb)
583 int reiserfs_proc_info_done(struct super_block *sb)
588 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
594 void reiserfs_proc_unregister_global(const char *name)
598 int reiserfs_proc_info_global_init(void)
602 int reiserfs_proc_info_global_done(void)
607 int reiserfs_global_version_in_proc(char *buffer, char **start,
609 int count, int *eof, void *data)
614 /* REISERFS_PROC_INFO */
618 * Revision 1.1.8.2 2001/07/15 17:08:42 god
619 * . use get_super() in procfs.c
620 * . remove remove_save_link() from reiserfs_do_truncate()
622 * I accept terms and conditions stated in the Legal Agreement
623 * (available at http://www.namesys.com/legalese.html)
625 * Revision 1.1.8.1 2001/07/11 16:48:50 god
628 * I accept terms and conditions stated in the Legal Agreement
629 * (available at http://www.namesys.com/legalese.html)
636 * c-indentation-style: "K&R"