Merge branch 'omap-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6/mini2440.git] / fs / reiserfs / procfs.c
blob9229e5514a4e13eef0fbaaef47f547bc90989a10
1 /* -*- linux-c -*- */
3 /* fs/reiserfs/procfs.c */
5 /*
6 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
7 */
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
23 * LOCKING:
25 * We rely on new Alexander Viro's super-block locking.
29 static int show_version(struct seq_file *m, struct super_block *sb)
31 char *format;
33 if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
34 format = "3.6";
35 } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
36 format = "3.5";
37 } else {
38 format = "unknown";
41 seq_printf(m, "%s format\twith checks %s\n", format,
42 #if defined( CONFIG_REISERFS_CHECK )
43 "on"
44 #else
45 "off"
46 #endif
48 return 0;
51 int reiserfs_global_version_in_proc(char *buffer, char **start, off_t offset,
52 int count, int *eof, void *data)
54 *start = buffer;
55 *eof = 1;
56 return 0;
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) : \
72 (__le32 *)(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"
89 "s_fix_nodes: \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"
93 "s_bmaps: \t%i\n"
94 "s_bmaps_without_search: \t%i\n"
95 "s_direct2indirect: \t%i\n"
96 "s_indirect2direct: \t%i\n"
97 "\n"
98 "max_hash_collisions: \t%i\n"
99 "breads: \t%lu\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));
139 return 0;
142 static int show_per_level(struct seq_file *m, struct super_block *sb)
144 struct reiserfs_sb_info *r = REISERFS_SB(sb);
145 int level;
147 seq_printf(m, "level\t"
148 " balances"
149 " [sbk: reads"
150 " fs_changed"
151 " restarted]"
152 " free space"
153 " items"
154 " can_remove"
155 " lnum"
156 " rnum"
157 " lbytes"
158 " rbytes"
159 " get_neig"
160 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
162 for (level = 0; level < MAX_HEIGHT; ++level) {
163 seq_printf(m, "%i\t"
164 " %12lu"
165 " %12lu"
166 " %12lu"
167 " %12lu"
168 " %12lu"
169 " %12lu"
170 " %12lu"
171 " %12li"
172 " %12li"
173 " %12li"
174 " %12li"
175 " %12lu"
176 " %12lu"
177 " %12lu"
178 " %12lu"
179 "\n",
180 level,
181 SFPL(balance_at),
182 SFPL(sbk_read_at),
183 SFPL(sbk_fs_changed),
184 SFPL(sbk_restarted),
185 SFPL(free_at),
186 SFPL(items_at),
187 SFPL(can_node_be_removed),
188 SFPL(lnum),
189 SFPL(rnum),
190 SFPL(lbytes),
191 SFPL(rbytes),
192 SFPL(get_neighbors),
193 SFPL(get_neighbors_restart),
194 SFPL(need_l_neighbor), SFPL(need_r_neighbor)
197 return 0;
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"
205 " scan_bitmap:"
206 " wait"
207 " bmap"
208 " retry"
209 " stolen"
210 " journal_hint"
211 "journal_nohint"
212 "\n"
213 " %14lu"
214 " %14lu"
215 " %14lu"
216 " %14lu"
217 " %14lu"
218 " %14lu"
219 " %14lu"
220 "\n",
221 SFP(free_block),
222 SFPF(call),
223 SFPF(wait),
224 SFPF(bmap),
225 SFPF(retry),
226 SFPF(stolen),
227 SFPF(in_journal_hint), SFPF(in_journal_nohint));
229 return 0;
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"
241 "root_block: \t%i\n"
242 "blocksize: \t%i\n"
243 "oid_maxsize: \t%i\n"
244 "oid_cursize: \t%i\n"
245 "umount_state: \t%i\n"
246 "magic: \t%10.10s\n"
247 "fs_state: \t%i\n"
248 "hash: \t%s\n"
249 "tree_height: \t%i\n"
250 "bmap_nr: \t%i\n"
251 "version: \t%i\n"
252 "flags: \t%x[%s]\n"
253 "reserved_for_journal: \t%i\n",
254 DFL(s_block_count),
255 DFL(s_free_blocks),
256 DFL(s_root_block),
257 DF(s_blocksize),
258 DF(s_oid_maxsize),
259 DF(s_oid_cursize),
260 DF(s_umount_state),
261 rs->s_v1.s_magic,
262 DF(s_fs_state),
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",
267 DF(s_tree_height),
268 DF(s_bmap_nr),
269 DF(s_version), flags, (flags & reiserfs_attrs_cleared)
270 ? "attrs_cleared" : "", DF(s_reserved_for_journal));
272 return 0;
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;
281 int i;
283 for (i = 0; i < mapsize; ++i) {
284 __u32 right;
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);
289 if (!(i & 1)) {
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);
298 #endif
299 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
300 mapsize,
301 mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
302 return 0;
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"
321 /* incore fields */
322 "j_1st_reserved_block: \t%i\n"
323 "j_state: \t%li\n"
324 "j_trans_id: \t%u\n"
325 "j_mount_id: \t%lu\n"
326 "j_start: \t%lu\n"
327 "j_len: \t%lu\n"
328 "j_len_alloc: \t%lu\n"
329 "j_wcount: \t%i\n"
330 "j_bcount: \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"
352 "prepare: \t%12lu\n"
353 "prepare_retry: \t%12lu\n",
354 DJP(jp_journal_1st_block),
355 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
356 DJP(jp_journal_dev),
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),
364 JF(j_state),
365 JF(j_trans_id),
366 JF(j_mount_id),
367 JF(j_start),
368 JF(j_len),
369 JF(j_len_alloc),
370 atomic_read(&r->s_journal->j_wcount),
371 JF(j_bcount),
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),
376 JF(j_must_wait),
377 JF(j_next_full_flush),
378 JF(j_next_async_flush),
379 JF(j_cnode_used),
380 JF(j_cnode_free),
381 SFPJ(in_journal),
382 SFPJ(in_journal_bitmap),
383 SFPJ(in_journal_reusable),
384 SFPJ(lock_journal),
385 SFPJ(lock_journal_wait),
386 SFPJ(journal_being),
387 SFPJ(journal_relock_writers),
388 SFPJ(journal_relock_wcount),
389 SFPJ(mark_dirty),
390 SFPJ(mark_dirty_already),
391 SFPJ(mark_dirty_notjournal),
392 SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
394 return 0;
397 /* iterator */
398 static int test_sb(struct super_block *sb, void *data)
400 return data == sb;
403 static int set_sb(struct super_block *sb, void *data)
405 return -ENOENT;
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;
412 loff_t l = *pos;
414 if (l)
415 return NULL;
417 if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, s)))
418 return NULL;
420 up_write(&s->s_umount);
421 return s;
424 static void *r_next(struct seq_file *m, void *v, loff_t * pos)
426 ++*pos;
427 if (v)
428 deactivate_super(v);
429 return NULL;
432 static void r_stop(struct seq_file *m, void *v)
434 if (v)
435 deactivate_super(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;
442 return show(m, v);
445 static const struct seq_operations r_ops = {
446 .start = r_start,
447 .next = r_next,
448 .stop = r_stop,
449 .show = r_show,
452 static int r_open(struct inode *inode, struct file *file)
454 int ret = seq_open(file, &r_ops);
456 if (!ret) {
457 struct seq_file *m = file->private_data;
458 m->private = PDE(inode);
460 return ret;
463 static const struct file_operations r_file_operations = {
464 .open = r_open,
465 .read = seq_read,
466 .llseek = seq_lseek,
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];
484 char *s;
486 /* Some block devices use /'s */
487 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
488 s = strchr(b, '/');
489 if (s)
490 *s = '!';
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);
503 return 0;
505 reiserfs_warning(sb, "cannot create /proc/%s/%s",
506 proc_info_root_name, b);
507 return 1;
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];
514 char *s;
516 /* Some block devices use /'s */
517 strlcpy(b, reiserfs_bdevname(sb), BDEVNAME_SIZE);
518 s = strchr(b, '/');
519 if (s)
520 *s = '!';
522 if (de) {
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;
538 return 0;
541 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
542 read_proc_t * func)
544 return (proc_info_root) ? create_proc_read_entry(name, 0,
545 proc_info_root,
546 func, NULL) : NULL;
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);
561 return 1;
564 return 0;
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);
573 return 0;
576 /* REISERFS_PROC_INFO */
577 #else
579 int reiserfs_proc_info_init(struct super_block *sb)
581 return 0;
583 int reiserfs_proc_info_done(struct super_block *sb)
585 return 0;
588 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
589 read_proc_t * func)
591 return NULL;
594 void reiserfs_proc_unregister_global(const char *name)
598 int reiserfs_proc_info_global_init(void)
600 return 0;
602 int reiserfs_proc_info_global_done(void)
604 return 0;
607 int reiserfs_global_version_in_proc(char *buffer, char **start,
608 off_t offset,
609 int count, int *eof, void *data)
611 return 0;
614 /* REISERFS_PROC_INFO */
615 #endif
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
626 * proc info support
628 * I accept terms and conditions stated in the Legal Agreement
629 * (available at http://www.namesys.com/legalese.html)
634 * Make Linus happy.
635 * Local variables:
636 * c-indentation-style: "K&R"
637 * mode-name: "LC"
638 * c-basic-offset: 8
639 * tab-width: 8
640 * End: