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 /* $Id: procfs.c,v 1.1.8.2 2001/07/15 17:08:42 god Exp $ */
13 #include <linux/module.h>
14 #include <linux/time.h>
15 #include <linux/seq_file.h>
16 #include <asm/uaccess.h>
17 #include <linux/reiserfs_fs.h>
18 #include <linux/reiserfs_fs_sb.h>
19 #include <linux/init.h>
20 #include <linux/proc_fs.h>
22 #ifdef CONFIG_REISERFS_PROC_INFO
27 * We rely on new Alexander Viro's super-block locking.
31 static int show_version(struct seq_file *m, struct super_block *sb)
35 if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
37 } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
43 seq_printf(m, "%s format\twith checks %s\n", format,
44 #if defined( CONFIG_REISERFS_CHECK )
53 int reiserfs_global_version_in_proc(char *buffer, char **start, off_t offset,
54 int count, int *eof, void *data)
61 #define SF( x ) ( r -> x )
62 #define SFP( x ) SF( s_proc_info_data.x )
63 #define SFPL( x ) SFP( x[ level ] )
64 #define SFPF( x ) SFP( scan_bitmap.x )
65 #define SFPJ( x ) SFP( journal.x )
67 #define D2C( x ) le16_to_cpu( x )
68 #define D4C( x ) le32_to_cpu( x )
69 #define DF( x ) D2C( rs -> s_v1.x )
70 #define DFL( x ) D4C( rs -> s_v1.x )
72 #define objectid_map( s, rs ) (old_format_only (s) ? \
73 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
75 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
77 #define DJF( x ) le32_to_cpu( rs -> x )
78 #define DJV( x ) le32_to_cpu( s_v1 -> x )
79 #define DJP( x ) le32_to_cpu( jp -> x )
80 #define JF( x ) ( r -> s_journal -> x )
82 static int show_super(struct seq_file *m, struct super_block *sb)
84 struct reiserfs_sb_info *r = REISERFS_SB(sb);
86 seq_printf(m, "state: \t%s\n"
87 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
88 "gen. counter: \t%i\n"
89 "s_disk_reads: \t%i\n"
90 "s_disk_writes: \t%i\n"
92 "s_do_balance: \t%i\n"
93 "s_unneeded_left_neighbor: \t%i\n"
94 "s_good_search_by_key_reada: \t%i\n"
96 "s_bmaps_without_search: \t%i\n"
97 "s_direct2indirect: \t%i\n"
98 "s_indirect2direct: \t%i\n"
100 "max_hash_collisions: \t%i\n"
102 "bread_misses: \t%lu\n"
103 "search_by_key: \t%lu\n"
104 "search_by_key_fs_changed: \t%lu\n"
105 "search_by_key_restarted: \t%lu\n"
106 "insert_item_restarted: \t%lu\n"
107 "paste_into_item_restarted: \t%lu\n"
108 "cut_from_item_restarted: \t%lu\n"
109 "delete_solid_item_restarted: \t%lu\n"
110 "delete_item_restarted: \t%lu\n"
111 "leaked_oid: \t%lu\n"
112 "leaves_removable: \t%lu\n",
113 SF(s_mount_state) == REISERFS_VALID_FS ?
114 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
115 reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
116 reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
117 reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
118 reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
119 reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
120 reiserfs_no_unhashed_relocation(sb) ?
121 "NO_UNHASHED_RELOCATION " : "",
122 reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
123 reiserfs_test4(sb) ? "TEST4 " : "",
124 have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
125 "SMALL_TAILS " : "NO_TAILS ",
126 replay_only(sb) ? "REPLAY_ONLY " : "",
127 convert_reiserfs(sb) ? "CONV " : "",
128 atomic_read(&r->s_generation_counter),
129 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
130 SF(s_do_balance), SF(s_unneeded_left_neighbor),
131 SF(s_good_search_by_key_reada), SF(s_bmaps),
132 SF(s_bmaps_without_search), SF(s_direct2indirect),
133 SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
134 SFP(bread_miss), SFP(search_by_key),
135 SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
136 SFP(insert_item_restarted), SFP(paste_into_item_restarted),
137 SFP(cut_from_item_restarted),
138 SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
139 SFP(leaked_oid), SFP(leaves_removable));
144 static int show_per_level(struct seq_file *m, struct super_block *sb)
146 struct reiserfs_sb_info *r = REISERFS_SB(sb);
149 seq_printf(m, "level\t"
162 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
164 for (level = 0; level < MAX_HEIGHT; ++level) {
185 SFPL(sbk_fs_changed),
189 SFPL(can_node_be_removed),
195 SFPL(get_neighbors_restart),
196 SFPL(need_l_neighbor), SFPL(need_r_neighbor)
202 static int show_bitmap(struct seq_file *m, struct super_block *sb)
204 struct reiserfs_sb_info *r = REISERFS_SB(sb);
206 seq_printf(m, "free_block: %lu\n"
229 SFPF(in_journal_hint), SFPF(in_journal_nohint));
234 static int show_on_disk_super(struct seq_file *m, struct super_block *sb)
236 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
237 struct reiserfs_super_block *rs = sb_info->s_rs;
238 int hash_code = DFL(s_hash_function_code);
239 __u32 flags = DJF(s_flags);
241 seq_printf(m, "block_count: \t%i\n"
242 "free_blocks: \t%i\n"
245 "oid_maxsize: \t%i\n"
246 "oid_cursize: \t%i\n"
247 "umount_state: \t%i\n"
251 "tree_height: \t%i\n"
255 "reserved_for_journal: \t%i\n",
265 hash_code == TEA_HASH ? "tea" :
266 (hash_code == YURA_HASH) ? "rupasov" :
267 (hash_code == R5_HASH) ? "r5" :
268 (hash_code == UNSET_HASH) ? "unset" : "unknown",
271 DF(s_version), flags, (flags & reiserfs_attrs_cleared)
272 ? "attrs_cleared" : "", DF(s_reserved_for_journal));
277 static int show_oidmap(struct seq_file *m, struct super_block *sb)
279 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
280 struct reiserfs_super_block *rs = sb_info->s_rs;
281 unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
282 unsigned long total_used = 0;
285 for (i = 0; i < mapsize; ++i) {
288 right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
289 seq_printf(m, "%s: [ %x .. %x )\n",
290 (i & 1) ? "free" : "used", MAP(i), right);
292 total_used += right - MAP(i);
295 #if defined( REISERFS_USE_OIDMAPF )
296 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
297 loff_t size = sb_info->oidmap.mapf->f_path.dentry->d_inode->i_size;
298 total_used += size / sizeof(reiserfs_oidinterval_d_t);
301 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
303 mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
307 static int show_journal(struct seq_file *m, struct super_block *sb)
309 struct reiserfs_sb_info *r = REISERFS_SB(sb);
310 struct reiserfs_super_block *rs = r->s_rs;
311 struct journal_params *jp = &rs->s_v1.s_journal;
312 char b[BDEVNAME_SIZE];
314 seq_printf(m, /* on-disk fields */
315 "jp_journal_1st_block: \t%i\n"
316 "jp_journal_dev: \t%s[%x]\n"
317 "jp_journal_size: \t%i\n"
318 "jp_journal_trans_max: \t%i\n"
319 "jp_journal_magic: \t%i\n"
320 "jp_journal_max_batch: \t%i\n"
321 "jp_journal_max_commit_age: \t%i\n"
322 "jp_journal_max_trans_age: \t%i\n"
324 "j_1st_reserved_block: \t%i\n"
326 "j_trans_id: \t%lu\n"
327 "j_mount_id: \t%lu\n"
330 "j_len_alloc: \t%lu\n"
333 "j_first_unflushed_offset: \t%lu\n"
334 "j_last_flush_trans_id: \t%lu\n"
335 "j_trans_start_time: \t%li\n"
336 "j_list_bitmap_index: \t%i\n"
337 "j_must_wait: \t%i\n"
338 "j_next_full_flush: \t%i\n"
339 "j_next_async_flush: \t%i\n"
340 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
341 /* reiserfs_proc_info_data_t.journal fields */
342 "in_journal: \t%12lu\n"
343 "in_journal_bitmap: \t%12lu\n"
344 "in_journal_reusable: \t%12lu\n"
345 "lock_journal: \t%12lu\n"
346 "lock_journal_wait: \t%12lu\n"
347 "journal_begin: \t%12lu\n"
348 "journal_relock_writers: \t%12lu\n"
349 "journal_relock_wcount: \t%12lu\n"
350 "mark_dirty: \t%12lu\n"
351 "mark_dirty_already: \t%12lu\n"
352 "mark_dirty_notjournal: \t%12lu\n"
353 "restore_prepared: \t%12lu\n"
355 "prepare_retry: \t%12lu\n",
356 DJP(jp_journal_1st_block),
357 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
359 DJP(jp_journal_size),
360 DJP(jp_journal_trans_max),
361 DJP(jp_journal_magic),
362 DJP(jp_journal_max_batch),
363 SB_JOURNAL(sb)->j_max_commit_age,
364 DJP(jp_journal_max_trans_age),
365 JF(j_1st_reserved_block),
372 atomic_read(&r->s_journal->j_wcount),
374 JF(j_first_unflushed_offset),
375 JF(j_last_flush_trans_id),
376 JF(j_trans_start_time),
377 JF(j_list_bitmap_index),
379 JF(j_next_full_flush),
380 JF(j_next_async_flush),
384 SFPJ(in_journal_bitmap),
385 SFPJ(in_journal_reusable),
387 SFPJ(lock_journal_wait),
389 SFPJ(journal_relock_writers),
390 SFPJ(journal_relock_wcount),
392 SFPJ(mark_dirty_already),
393 SFPJ(mark_dirty_notjournal),
394 SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
400 static int test_sb(struct super_block *sb, void *data)
405 static int set_sb(struct super_block *sb, void *data)
410 static void *r_start(struct seq_file *m, loff_t * pos)
412 struct proc_dir_entry *de = m->private;
413 struct super_block *s = de->parent->data;
419 if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, s)))
422 up_write(&s->s_umount);
426 static void *r_next(struct seq_file *m, void *v, loff_t * pos)
434 static void r_stop(struct seq_file *m, void *v)
440 static int r_show(struct seq_file *m, void *v)
442 struct proc_dir_entry *de = m->private;
443 int (*show) (struct seq_file *, struct super_block *) = de->data;
447 static struct seq_operations r_ops = {
454 static int r_open(struct inode *inode, struct file *file)
456 int ret = seq_open(file, &r_ops);
459 struct seq_file *m = file->private_data;
460 m->private = PDE(inode);
465 static const struct file_operations r_file_operations = {
469 .release = seq_release,
472 static struct proc_dir_entry *proc_info_root = NULL;
473 static const char proc_info_root_name[] = "fs/reiserfs";
475 static void add_file(struct super_block *sb, char *name,
476 int (*func) (struct seq_file *, struct super_block *))
478 struct proc_dir_entry *de;
479 de = create_proc_entry(name, 0, REISERFS_SB(sb)->procdir);
482 de->proc_fops = &r_file_operations;
486 int reiserfs_proc_info_init(struct super_block *sb)
488 char b[BDEVNAME_SIZE];
491 /* Some block devices use /'s */
492 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
497 spin_lock_init(&__PINFO(sb).lock);
498 REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root);
499 if (REISERFS_SB(sb)->procdir) {
500 REISERFS_SB(sb)->procdir->owner = THIS_MODULE;
501 REISERFS_SB(sb)->procdir->data = sb;
502 add_file(sb, "version", show_version);
503 add_file(sb, "super", show_super);
504 add_file(sb, "per-level", show_per_level);
505 add_file(sb, "bitmap", show_bitmap);
506 add_file(sb, "on-disk-super", show_on_disk_super);
507 add_file(sb, "oidmap", show_oidmap);
508 add_file(sb, "journal", show_journal);
511 reiserfs_warning(sb, "reiserfs: cannot create /proc/%s/%s",
512 proc_info_root_name, b);
516 int reiserfs_proc_info_done(struct super_block *sb)
518 struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
519 char b[BDEVNAME_SIZE];
522 /* Some block devices use /'s */
523 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
529 remove_proc_entry("journal", de);
530 remove_proc_entry("oidmap", de);
531 remove_proc_entry("on-disk-super", de);
532 remove_proc_entry("bitmap", de);
533 remove_proc_entry("per-level", de);
534 remove_proc_entry("super", de);
535 remove_proc_entry("version", de);
537 spin_lock(&__PINFO(sb).lock);
538 __PINFO(sb).exiting = 1;
539 spin_unlock(&__PINFO(sb).lock);
540 if (proc_info_root) {
541 remove_proc_entry(b, proc_info_root);
542 REISERFS_SB(sb)->procdir = NULL;
547 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
550 return (proc_info_root) ? create_proc_read_entry(name, 0,
555 void reiserfs_proc_unregister_global(const char *name)
557 remove_proc_entry(name, proc_info_root);
560 int reiserfs_proc_info_global_init(void)
562 if (proc_info_root == NULL) {
563 proc_info_root = proc_mkdir(proc_info_root_name, NULL);
564 if (proc_info_root) {
565 proc_info_root->owner = THIS_MODULE;
567 reiserfs_warning(NULL,
568 "reiserfs: cannot create /proc/%s",
569 proc_info_root_name);
576 int reiserfs_proc_info_global_done(void)
578 if (proc_info_root != NULL) {
579 proc_info_root = NULL;
580 remove_proc_entry(proc_info_root_name, NULL);
585 /* REISERFS_PROC_INFO */
588 int reiserfs_proc_info_init(struct super_block *sb)
592 int reiserfs_proc_info_done(struct super_block *sb)
597 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
603 void reiserfs_proc_unregister_global(const char *name)
607 int reiserfs_proc_info_global_init(void)
611 int reiserfs_proc_info_global_done(void)
616 int reiserfs_global_version_in_proc(char *buffer, char **start,
618 int count, int *eof, void *data)
623 /* REISERFS_PROC_INFO */
628 * Revision 1.1.8.2 2001/07/15 17:08:42 god
629 * . use get_super() in procfs.c
630 * . remove remove_save_link() from reiserfs_do_truncate()
632 * I accept terms and conditions stated in the Legal Agreement
633 * (available at http://www.namesys.com/legalese.html)
635 * Revision 1.1.8.1 2001/07/11 16:48:50 god
638 * I accept terms and conditions stated in the Legal Agreement
639 * (available at http://www.namesys.com/legalese.html)
646 * c-indentation-style: "K&R"