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>
16 #include <linux/init.h>
17 #include <linux/proc_fs.h>
22 * We rely on new Alexander Viro's super-block locking.
26 static int show_version(struct seq_file *m, struct super_block *sb)
30 if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
32 } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
38 seq_printf(m, "%s format\twith checks %s\n", format,
39 #if defined( CONFIG_REISERFS_CHECK )
48 #define SF( x ) ( r -> x )
49 #define SFP( x ) SF( s_proc_info_data.x )
50 #define SFPL( x ) SFP( x[ level ] )
51 #define SFPF( x ) SFP( scan_bitmap.x )
52 #define SFPJ( x ) SFP( journal.x )
54 #define D2C( x ) le16_to_cpu( x )
55 #define D4C( x ) le32_to_cpu( x )
56 #define DF( x ) D2C( rs -> s_v1.x )
57 #define DFL( x ) D4C( rs -> s_v1.x )
59 #define objectid_map( s, rs ) (old_format_only (s) ? \
60 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
62 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
64 #define DJF( x ) le32_to_cpu( rs -> x )
65 #define DJV( x ) le32_to_cpu( s_v1 -> x )
66 #define DJP( x ) le32_to_cpu( jp -> x )
67 #define JF( x ) ( r -> s_journal -> x )
69 static int show_super(struct seq_file *m, struct super_block *sb)
71 struct reiserfs_sb_info *r = REISERFS_SB(sb);
73 seq_printf(m, "state: \t%s\n"
74 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
75 "gen. counter: \t%i\n"
76 "s_disk_reads: \t%i\n"
77 "s_disk_writes: \t%i\n"
79 "s_do_balance: \t%i\n"
80 "s_unneeded_left_neighbor: \t%i\n"
81 "s_good_search_by_key_reada: \t%i\n"
83 "s_bmaps_without_search: \t%i\n"
84 "s_direct2indirect: \t%i\n"
85 "s_indirect2direct: \t%i\n"
87 "max_hash_collisions: \t%i\n"
89 "bread_misses: \t%lu\n"
90 "search_by_key: \t%lu\n"
91 "search_by_key_fs_changed: \t%lu\n"
92 "search_by_key_restarted: \t%lu\n"
93 "insert_item_restarted: \t%lu\n"
94 "paste_into_item_restarted: \t%lu\n"
95 "cut_from_item_restarted: \t%lu\n"
96 "delete_solid_item_restarted: \t%lu\n"
97 "delete_item_restarted: \t%lu\n"
99 "leaves_removable: \t%lu\n",
100 SF(s_mount_state) == REISERFS_VALID_FS ?
101 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
102 reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
103 reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
104 reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
105 reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
106 reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
107 reiserfs_no_unhashed_relocation(sb) ?
108 "NO_UNHASHED_RELOCATION " : "",
109 reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
110 reiserfs_test4(sb) ? "TEST4 " : "",
111 have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
112 "SMALL_TAILS " : "NO_TAILS ",
113 replay_only(sb) ? "REPLAY_ONLY " : "",
114 convert_reiserfs(sb) ? "CONV " : "",
115 atomic_read(&r->s_generation_counter),
116 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
117 SF(s_do_balance), SF(s_unneeded_left_neighbor),
118 SF(s_good_search_by_key_reada), SF(s_bmaps),
119 SF(s_bmaps_without_search), SF(s_direct2indirect),
120 SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
121 SFP(bread_miss), SFP(search_by_key),
122 SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
123 SFP(insert_item_restarted), SFP(paste_into_item_restarted),
124 SFP(cut_from_item_restarted),
125 SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
126 SFP(leaked_oid), SFP(leaves_removable));
131 static int show_per_level(struct seq_file *m, struct super_block *sb)
133 struct reiserfs_sb_info *r = REISERFS_SB(sb);
136 seq_printf(m, "level\t"
149 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
151 for (level = 0; level < MAX_HEIGHT; ++level) {
172 SFPL(sbk_fs_changed),
176 SFPL(can_node_be_removed),
182 SFPL(get_neighbors_restart),
183 SFPL(need_l_neighbor), SFPL(need_r_neighbor)
189 static int show_bitmap(struct seq_file *m, struct super_block *sb)
191 struct reiserfs_sb_info *r = REISERFS_SB(sb);
193 seq_printf(m, "free_block: %lu\n"
216 SFPF(in_journal_hint), SFPF(in_journal_nohint));
221 static int show_on_disk_super(struct seq_file *m, struct super_block *sb)
223 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
224 struct reiserfs_super_block *rs = sb_info->s_rs;
225 int hash_code = DFL(s_hash_function_code);
226 __u32 flags = DJF(s_flags);
228 seq_printf(m, "block_count: \t%i\n"
229 "free_blocks: \t%i\n"
232 "oid_maxsize: \t%i\n"
233 "oid_cursize: \t%i\n"
234 "umount_state: \t%i\n"
238 "tree_height: \t%i\n"
242 "reserved_for_journal: \t%i\n",
252 hash_code == TEA_HASH ? "tea" :
253 (hash_code == YURA_HASH) ? "rupasov" :
254 (hash_code == R5_HASH) ? "r5" :
255 (hash_code == UNSET_HASH) ? "unset" : "unknown",
258 DF(s_version), flags, (flags & reiserfs_attrs_cleared)
259 ? "attrs_cleared" : "", DF(s_reserved_for_journal));
264 static int show_oidmap(struct seq_file *m, struct super_block *sb)
266 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
267 struct reiserfs_super_block *rs = sb_info->s_rs;
268 unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
269 unsigned long total_used = 0;
272 for (i = 0; i < mapsize; ++i) {
275 right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
276 seq_printf(m, "%s: [ %x .. %x )\n",
277 (i & 1) ? "free" : "used", MAP(i), right);
279 total_used += right - MAP(i);
282 #if defined( REISERFS_USE_OIDMAPF )
283 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
284 loff_t size = sb_info->oidmap.mapf->f_path.dentry->d_inode->i_size;
285 total_used += size / sizeof(reiserfs_oidinterval_d_t);
288 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
290 mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
294 static int show_journal(struct seq_file *m, struct super_block *sb)
296 struct reiserfs_sb_info *r = REISERFS_SB(sb);
297 struct reiserfs_super_block *rs = r->s_rs;
298 struct journal_params *jp = &rs->s_v1.s_journal;
299 char b[BDEVNAME_SIZE];
301 seq_printf(m, /* on-disk fields */
302 "jp_journal_1st_block: \t%i\n"
303 "jp_journal_dev: \t%s[%x]\n"
304 "jp_journal_size: \t%i\n"
305 "jp_journal_trans_max: \t%i\n"
306 "jp_journal_magic: \t%i\n"
307 "jp_journal_max_batch: \t%i\n"
308 "jp_journal_max_commit_age: \t%i\n"
309 "jp_journal_max_trans_age: \t%i\n"
311 "j_1st_reserved_block: \t%i\n"
314 "j_mount_id: \t%lu\n"
317 "j_len_alloc: \t%lu\n"
320 "j_first_unflushed_offset: \t%lu\n"
321 "j_last_flush_trans_id: \t%u\n"
322 "j_trans_start_time: \t%li\n"
323 "j_list_bitmap_index: \t%i\n"
324 "j_must_wait: \t%i\n"
325 "j_next_full_flush: \t%i\n"
326 "j_next_async_flush: \t%i\n"
327 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
328 /* reiserfs_proc_info_data_t.journal fields */
329 "in_journal: \t%12lu\n"
330 "in_journal_bitmap: \t%12lu\n"
331 "in_journal_reusable: \t%12lu\n"
332 "lock_journal: \t%12lu\n"
333 "lock_journal_wait: \t%12lu\n"
334 "journal_begin: \t%12lu\n"
335 "journal_relock_writers: \t%12lu\n"
336 "journal_relock_wcount: \t%12lu\n"
337 "mark_dirty: \t%12lu\n"
338 "mark_dirty_already: \t%12lu\n"
339 "mark_dirty_notjournal: \t%12lu\n"
340 "restore_prepared: \t%12lu\n"
342 "prepare_retry: \t%12lu\n",
343 DJP(jp_journal_1st_block),
344 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
346 DJP(jp_journal_size),
347 DJP(jp_journal_trans_max),
348 DJP(jp_journal_magic),
349 DJP(jp_journal_max_batch),
350 SB_JOURNAL(sb)->j_max_commit_age,
351 DJP(jp_journal_max_trans_age),
352 JF(j_1st_reserved_block),
359 atomic_read(&r->s_journal->j_wcount),
361 JF(j_first_unflushed_offset),
362 JF(j_last_flush_trans_id),
363 JF(j_trans_start_time),
364 JF(j_list_bitmap_index),
366 JF(j_next_full_flush),
367 JF(j_next_async_flush),
371 SFPJ(in_journal_bitmap),
372 SFPJ(in_journal_reusable),
374 SFPJ(lock_journal_wait),
376 SFPJ(journal_relock_writers),
377 SFPJ(journal_relock_wcount),
379 SFPJ(mark_dirty_already),
380 SFPJ(mark_dirty_notjournal),
381 SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
387 static int test_sb(struct super_block *sb, void *data)
392 static int set_sb(struct super_block *sb, void *data)
397 static void *r_start(struct seq_file *m, loff_t * pos)
399 struct proc_dir_entry *de = m->private;
400 struct super_block *s = de->parent->data;
406 if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, s)))
409 up_write(&s->s_umount);
413 static void *r_next(struct seq_file *m, void *v, loff_t * pos)
421 static void r_stop(struct seq_file *m, void *v)
427 static int r_show(struct seq_file *m, void *v)
429 struct proc_dir_entry *de = m->private;
430 int (*show) (struct seq_file *, struct super_block *) = de->data;
434 static const struct seq_operations r_ops = {
441 static int r_open(struct inode *inode, struct file *file)
443 int ret = seq_open(file, &r_ops);
446 struct seq_file *m = file->private_data;
447 m->private = PDE(inode);
452 static const struct file_operations r_file_operations = {
456 .release = seq_release,
457 .owner = THIS_MODULE,
460 static struct proc_dir_entry *proc_info_root = NULL;
461 static const char proc_info_root_name[] = "fs/reiserfs";
463 static void add_file(struct super_block *sb, char *name,
464 int (*func) (struct seq_file *, struct super_block *))
466 proc_create_data(name, 0, REISERFS_SB(sb)->procdir,
467 &r_file_operations, func);
470 int reiserfs_proc_info_init(struct super_block *sb)
472 char b[BDEVNAME_SIZE];
475 /* Some block devices use /'s */
476 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
481 spin_lock_init(&__PINFO(sb).lock);
482 REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root);
483 if (REISERFS_SB(sb)->procdir) {
484 REISERFS_SB(sb)->procdir->data = sb;
485 add_file(sb, "version", show_version);
486 add_file(sb, "super", show_super);
487 add_file(sb, "per-level", show_per_level);
488 add_file(sb, "bitmap", show_bitmap);
489 add_file(sb, "on-disk-super", show_on_disk_super);
490 add_file(sb, "oidmap", show_oidmap);
491 add_file(sb, "journal", show_journal);
494 reiserfs_warning(sb, "cannot create /proc/%s/%s",
495 proc_info_root_name, b);
499 int reiserfs_proc_info_done(struct super_block *sb)
501 struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
502 char b[BDEVNAME_SIZE];
505 /* Some block devices use /'s */
506 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
512 remove_proc_entry("journal", de);
513 remove_proc_entry("oidmap", de);
514 remove_proc_entry("on-disk-super", de);
515 remove_proc_entry("bitmap", de);
516 remove_proc_entry("per-level", de);
517 remove_proc_entry("super", de);
518 remove_proc_entry("version", de);
520 spin_lock(&__PINFO(sb).lock);
521 __PINFO(sb).exiting = 1;
522 spin_unlock(&__PINFO(sb).lock);
523 if (proc_info_root) {
524 remove_proc_entry(b, proc_info_root);
525 REISERFS_SB(sb)->procdir = NULL;
530 int reiserfs_proc_info_global_init(void)
532 if (proc_info_root == NULL) {
533 proc_info_root = proc_mkdir(proc_info_root_name, NULL);
534 if (!proc_info_root) {
535 reiserfs_warning(NULL, "cannot create /proc/%s",
536 proc_info_root_name);
543 int reiserfs_proc_info_global_done(void)
545 if (proc_info_root != NULL) {
546 proc_info_root = NULL;
547 remove_proc_entry(proc_info_root_name, NULL);
552 * Revision 1.1.8.2 2001/07/15 17:08:42 god
553 * . use get_super() in procfs.c
554 * . remove remove_save_link() from reiserfs_do_truncate()
556 * I accept terms and conditions stated in the Legal Agreement
557 * (available at http://www.namesys.com/legalese.html)
559 * Revision 1.1.8.1 2001/07/11 16:48:50 god
562 * I accept terms and conditions stated in the Legal Agreement
563 * (available at http://www.namesys.com/legalese.html)
570 * c-indentation-style: "K&R"