[CPUFREQ] Misc cleanups in ondemand.
[linux-2.6/next.git] / fs / reiserfs / procfs.c
blob731688e1cfe334608001da8648f9d8c051d2b1c1
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 /* $Id: procfs.c,v 1.1.8.2 2001/07/15 17:08:42 god Exp $ */
13 #include <linux/config.h>
14 #include <linux/module.h>
15 #include <linux/time.h>
16 #include <linux/seq_file.h>
17 #include <asm/uaccess.h>
18 #include <linux/reiserfs_fs.h>
19 #include <linux/reiserfs_fs_sb.h>
20 #include <linux/smp_lock.h>
21 #include <linux/init.h>
22 #include <linux/proc_fs.h>
24 #if defined( REISERFS_PROC_INFO )
27 * LOCKING:
29 * We rely on new Alexander Viro's super-block locking.
33 static int show_version(struct seq_file *m, struct super_block *sb)
35 char *format;
37 if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
38 format = "3.6";
39 } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
40 format = "3.5";
41 } else {
42 format = "unknown";
45 seq_printf(m, "%s format\twith checks %s\n", format,
46 #if defined( CONFIG_REISERFS_CHECK )
47 "on"
48 #else
49 "off"
50 #endif
52 return 0;
55 int reiserfs_global_version_in_proc(char *buffer, char **start, off_t offset,
56 int count, int *eof, void *data)
58 *start = buffer;
59 *eof = 1;
60 return 0;
63 #define SF( x ) ( r -> x )
64 #define SFP( x ) SF( s_proc_info_data.x )
65 #define SFPL( x ) SFP( x[ level ] )
66 #define SFPF( x ) SFP( scan_bitmap.x )
67 #define SFPJ( x ) SFP( journal.x )
69 #define D2C( x ) le16_to_cpu( x )
70 #define D4C( x ) le32_to_cpu( x )
71 #define DF( x ) D2C( rs -> s_v1.x )
72 #define DFL( x ) D4C( rs -> s_v1.x )
74 #define objectid_map( s, rs ) (old_format_only (s) ? \
75 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
76 (__le32 *)(rs + 1))
77 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
79 #define DJF( x ) le32_to_cpu( rs -> x )
80 #define DJV( x ) le32_to_cpu( s_v1 -> x )
81 #define DJP( x ) le32_to_cpu( jp -> x )
82 #define JF( x ) ( r -> s_journal -> x )
84 static int show_super(struct seq_file *m, struct super_block *sb)
86 struct reiserfs_sb_info *r = REISERFS_SB(sb);
88 seq_printf(m, "state: \t%s\n"
89 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
90 "gen. counter: \t%i\n"
91 "s_disk_reads: \t%i\n"
92 "s_disk_writes: \t%i\n"
93 "s_fix_nodes: \t%i\n"
94 "s_do_balance: \t%i\n"
95 "s_unneeded_left_neighbor: \t%i\n"
96 "s_good_search_by_key_reada: \t%i\n"
97 "s_bmaps: \t%i\n"
98 "s_bmaps_without_search: \t%i\n"
99 "s_direct2indirect: \t%i\n"
100 "s_indirect2direct: \t%i\n"
101 "\n"
102 "max_hash_collisions: \t%i\n"
103 "breads: \t%lu\n"
104 "bread_misses: \t%lu\n"
105 "search_by_key: \t%lu\n"
106 "search_by_key_fs_changed: \t%lu\n"
107 "search_by_key_restarted: \t%lu\n"
108 "insert_item_restarted: \t%lu\n"
109 "paste_into_item_restarted: \t%lu\n"
110 "cut_from_item_restarted: \t%lu\n"
111 "delete_solid_item_restarted: \t%lu\n"
112 "delete_item_restarted: \t%lu\n"
113 "leaked_oid: \t%lu\n"
114 "leaves_removable: \t%lu\n",
115 SF(s_mount_state) == REISERFS_VALID_FS ?
116 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
117 reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
118 reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
119 reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
120 reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
121 reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
122 reiserfs_no_unhashed_relocation(sb) ?
123 "NO_UNHASHED_RELOCATION " : "",
124 reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
125 reiserfs_test4(sb) ? "TEST4 " : "",
126 have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
127 "SMALL_TAILS " : "NO_TAILS ",
128 replay_only(sb) ? "REPLAY_ONLY " : "",
129 convert_reiserfs(sb) ? "CONV " : "",
130 atomic_read(&r->s_generation_counter),
131 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
132 SF(s_do_balance), SF(s_unneeded_left_neighbor),
133 SF(s_good_search_by_key_reada), SF(s_bmaps),
134 SF(s_bmaps_without_search), SF(s_direct2indirect),
135 SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
136 SFP(bread_miss), SFP(search_by_key),
137 SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
138 SFP(insert_item_restarted), SFP(paste_into_item_restarted),
139 SFP(cut_from_item_restarted),
140 SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
141 SFP(leaked_oid), SFP(leaves_removable));
143 return 0;
146 static int show_per_level(struct seq_file *m, struct super_block *sb)
148 struct reiserfs_sb_info *r = REISERFS_SB(sb);
149 int level;
151 seq_printf(m, "level\t"
152 " balances"
153 " [sbk: reads"
154 " fs_changed"
155 " restarted]"
156 " free space"
157 " items"
158 " can_remove"
159 " lnum"
160 " rnum"
161 " lbytes"
162 " rbytes"
163 " get_neig"
164 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
166 for (level = 0; level < MAX_HEIGHT; ++level) {
167 seq_printf(m, "%i\t"
168 " %12lu"
169 " %12lu"
170 " %12lu"
171 " %12lu"
172 " %12lu"
173 " %12lu"
174 " %12lu"
175 " %12li"
176 " %12li"
177 " %12li"
178 " %12li"
179 " %12lu"
180 " %12lu"
181 " %12lu"
182 " %12lu"
183 "\n",
184 level,
185 SFPL(balance_at),
186 SFPL(sbk_read_at),
187 SFPL(sbk_fs_changed),
188 SFPL(sbk_restarted),
189 SFPL(free_at),
190 SFPL(items_at),
191 SFPL(can_node_be_removed),
192 SFPL(lnum),
193 SFPL(rnum),
194 SFPL(lbytes),
195 SFPL(rbytes),
196 SFPL(get_neighbors),
197 SFPL(get_neighbors_restart),
198 SFPL(need_l_neighbor), SFPL(need_r_neighbor)
201 return 0;
204 static int show_bitmap(struct seq_file *m, struct super_block *sb)
206 struct reiserfs_sb_info *r = REISERFS_SB(sb);
208 seq_printf(m, "free_block: %lu\n"
209 " scan_bitmap:"
210 " wait"
211 " bmap"
212 " retry"
213 " stolen"
214 " journal_hint"
215 "journal_nohint"
216 "\n"
217 " %14lu"
218 " %14lu"
219 " %14lu"
220 " %14lu"
221 " %14lu"
222 " %14lu"
223 " %14lu"
224 "\n",
225 SFP(free_block),
226 SFPF(call),
227 SFPF(wait),
228 SFPF(bmap),
229 SFPF(retry),
230 SFPF(stolen),
231 SFPF(in_journal_hint), SFPF(in_journal_nohint));
233 return 0;
236 static int show_on_disk_super(struct seq_file *m, struct super_block *sb)
238 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
239 struct reiserfs_super_block *rs = sb_info->s_rs;
240 int hash_code = DFL(s_hash_function_code);
241 __u32 flags = DJF(s_flags);
243 seq_printf(m, "block_count: \t%i\n"
244 "free_blocks: \t%i\n"
245 "root_block: \t%i\n"
246 "blocksize: \t%i\n"
247 "oid_maxsize: \t%i\n"
248 "oid_cursize: \t%i\n"
249 "umount_state: \t%i\n"
250 "magic: \t%10.10s\n"
251 "fs_state: \t%i\n"
252 "hash: \t%s\n"
253 "tree_height: \t%i\n"
254 "bmap_nr: \t%i\n"
255 "version: \t%i\n"
256 "flags: \t%x[%s]\n"
257 "reserved_for_journal: \t%i\n",
258 DFL(s_block_count),
259 DFL(s_free_blocks),
260 DFL(s_root_block),
261 DF(s_blocksize),
262 DF(s_oid_maxsize),
263 DF(s_oid_cursize),
264 DF(s_umount_state),
265 rs->s_v1.s_magic,
266 DF(s_fs_state),
267 hash_code == TEA_HASH ? "tea" :
268 (hash_code == YURA_HASH) ? "rupasov" :
269 (hash_code == R5_HASH) ? "r5" :
270 (hash_code == UNSET_HASH) ? "unset" : "unknown",
271 DF(s_tree_height),
272 DF(s_bmap_nr),
273 DF(s_version), flags, (flags & reiserfs_attrs_cleared)
274 ? "attrs_cleared" : "", DF(s_reserved_for_journal));
276 return 0;
279 static int show_oidmap(struct seq_file *m, struct super_block *sb)
281 struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
282 struct reiserfs_super_block *rs = sb_info->s_rs;
283 unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
284 unsigned long total_used = 0;
285 int i;
287 for (i = 0; i < mapsize; ++i) {
288 __u32 right;
290 right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
291 seq_printf(m, "%s: [ %x .. %x )\n",
292 (i & 1) ? "free" : "used", MAP(i), right);
293 if (!(i & 1)) {
294 total_used += right - MAP(i);
297 #if defined( REISERFS_USE_OIDMAPF )
298 if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
299 loff_t size = sb_info->oidmap.mapf->f_dentry->d_inode->i_size;
300 total_used += size / sizeof(reiserfs_oidinterval_d_t);
302 #endif
303 seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
304 mapsize,
305 mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
306 return 0;
309 static int show_journal(struct seq_file *m, struct super_block *sb)
311 struct reiserfs_sb_info *r = REISERFS_SB(sb);
312 struct reiserfs_super_block *rs = r->s_rs;
313 struct journal_params *jp = &rs->s_v1.s_journal;
314 char b[BDEVNAME_SIZE];
316 seq_printf(m, /* on-disk fields */
317 "jp_journal_1st_block: \t%i\n"
318 "jp_journal_dev: \t%s[%x]\n"
319 "jp_journal_size: \t%i\n"
320 "jp_journal_trans_max: \t%i\n"
321 "jp_journal_magic: \t%i\n"
322 "jp_journal_max_batch: \t%i\n"
323 "jp_journal_max_commit_age: \t%i\n"
324 "jp_journal_max_trans_age: \t%i\n"
325 /* incore fields */
326 "j_1st_reserved_block: \t%i\n"
327 "j_state: \t%li\n"
328 "j_trans_id: \t%lu\n"
329 "j_mount_id: \t%lu\n"
330 "j_start: \t%lu\n"
331 "j_len: \t%lu\n"
332 "j_len_alloc: \t%lu\n"
333 "j_wcount: \t%i\n"
334 "j_bcount: \t%lu\n"
335 "j_first_unflushed_offset: \t%lu\n"
336 "j_last_flush_trans_id: \t%lu\n"
337 "j_trans_start_time: \t%li\n"
338 "j_list_bitmap_index: \t%i\n"
339 "j_must_wait: \t%i\n"
340 "j_next_full_flush: \t%i\n"
341 "j_next_async_flush: \t%i\n"
342 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
343 /* reiserfs_proc_info_data_t.journal fields */
344 "in_journal: \t%12lu\n"
345 "in_journal_bitmap: \t%12lu\n"
346 "in_journal_reusable: \t%12lu\n"
347 "lock_journal: \t%12lu\n"
348 "lock_journal_wait: \t%12lu\n"
349 "journal_begin: \t%12lu\n"
350 "journal_relock_writers: \t%12lu\n"
351 "journal_relock_wcount: \t%12lu\n"
352 "mark_dirty: \t%12lu\n"
353 "mark_dirty_already: \t%12lu\n"
354 "mark_dirty_notjournal: \t%12lu\n"
355 "restore_prepared: \t%12lu\n"
356 "prepare: \t%12lu\n"
357 "prepare_retry: \t%12lu\n",
358 DJP(jp_journal_1st_block),
359 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
360 DJP(jp_journal_dev),
361 DJP(jp_journal_size),
362 DJP(jp_journal_trans_max),
363 DJP(jp_journal_magic),
364 DJP(jp_journal_max_batch),
365 SB_JOURNAL(sb)->j_max_commit_age,
366 DJP(jp_journal_max_trans_age),
367 JF(j_1st_reserved_block),
368 JF(j_state),
369 JF(j_trans_id),
370 JF(j_mount_id),
371 JF(j_start),
372 JF(j_len),
373 JF(j_len_alloc),
374 atomic_read(&r->s_journal->j_wcount),
375 JF(j_bcount),
376 JF(j_first_unflushed_offset),
377 JF(j_last_flush_trans_id),
378 JF(j_trans_start_time),
379 JF(j_list_bitmap_index),
380 JF(j_must_wait),
381 JF(j_next_full_flush),
382 JF(j_next_async_flush),
383 JF(j_cnode_used),
384 JF(j_cnode_free),
385 SFPJ(in_journal),
386 SFPJ(in_journal_bitmap),
387 SFPJ(in_journal_reusable),
388 SFPJ(lock_journal),
389 SFPJ(lock_journal_wait),
390 SFPJ(journal_being),
391 SFPJ(journal_relock_writers),
392 SFPJ(journal_relock_wcount),
393 SFPJ(mark_dirty),
394 SFPJ(mark_dirty_already),
395 SFPJ(mark_dirty_notjournal),
396 SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
398 return 0;
401 /* iterator */
402 static int test_sb(struct super_block *sb, void *data)
404 return data == sb;
407 static int set_sb(struct super_block *sb, void *data)
409 return -ENOENT;
412 static void *r_start(struct seq_file *m, loff_t * pos)
414 struct proc_dir_entry *de = m->private;
415 struct super_block *s = de->parent->data;
416 loff_t l = *pos;
418 if (l)
419 return NULL;
421 if (IS_ERR(sget(&reiserfs_fs_type, test_sb, set_sb, s)))
422 return NULL;
424 up_write(&s->s_umount);
426 if (de->deleted) {
427 deactivate_super(s);
428 return NULL;
431 return s;
434 static void *r_next(struct seq_file *m, void *v, loff_t * pos)
436 ++*pos;
437 if (v)
438 deactivate_super(v);
439 return NULL;
442 static void r_stop(struct seq_file *m, void *v)
444 if (v)
445 deactivate_super(v);
448 static int r_show(struct seq_file *m, void *v)
450 struct proc_dir_entry *de = m->private;
451 int (*show) (struct seq_file *, struct super_block *) = de->data;
452 return show(m, v);
455 static struct seq_operations r_ops = {
456 .start = r_start,
457 .next = r_next,
458 .stop = r_stop,
459 .show = r_show,
462 static int r_open(struct inode *inode, struct file *file)
464 int ret = seq_open(file, &r_ops);
466 if (!ret) {
467 struct seq_file *m = file->private_data;
468 m->private = PDE(inode);
470 return ret;
473 static const struct file_operations r_file_operations = {
474 .open = r_open,
475 .read = seq_read,
476 .llseek = seq_lseek,
477 .release = seq_release,
480 static struct proc_dir_entry *proc_info_root = NULL;
481 static const char proc_info_root_name[] = "fs/reiserfs";
483 static void add_file(struct super_block *sb, char *name,
484 int (*func) (struct seq_file *, struct super_block *))
486 struct proc_dir_entry *de;
487 de = create_proc_entry(name, 0, REISERFS_SB(sb)->procdir);
488 if (de) {
489 de->data = func;
490 de->proc_fops = &r_file_operations;
494 int reiserfs_proc_info_init(struct super_block *sb)
496 spin_lock_init(&__PINFO(sb).lock);
497 REISERFS_SB(sb)->procdir =
498 proc_mkdir(reiserfs_bdevname(sb), 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);
509 return 0;
511 reiserfs_warning(sb, "reiserfs: cannot create /proc/%s/%s",
512 proc_info_root_name, reiserfs_bdevname(sb));
513 return 1;
516 int reiserfs_proc_info_done(struct super_block *sb)
518 struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
519 if (de) {
520 remove_proc_entry("journal", de);
521 remove_proc_entry("oidmap", de);
522 remove_proc_entry("on-disk-super", de);
523 remove_proc_entry("bitmap", de);
524 remove_proc_entry("per-level", de);
525 remove_proc_entry("super", de);
526 remove_proc_entry("version", de);
528 spin_lock(&__PINFO(sb).lock);
529 __PINFO(sb).exiting = 1;
530 spin_unlock(&__PINFO(sb).lock);
531 if (proc_info_root) {
532 remove_proc_entry(reiserfs_bdevname(sb), proc_info_root);
533 REISERFS_SB(sb)->procdir = NULL;
535 return 0;
538 struct proc_dir_entry *reiserfs_proc_register_global(char *name,
539 read_proc_t * func)
541 return (proc_info_root) ? create_proc_read_entry(name, 0,
542 proc_info_root,
543 func, NULL) : NULL;
546 void reiserfs_proc_unregister_global(const char *name)
548 remove_proc_entry(name, proc_info_root);
551 int reiserfs_proc_info_global_init(void)
553 if (proc_info_root == NULL) {
554 proc_info_root = proc_mkdir(proc_info_root_name, NULL);
555 if (proc_info_root) {
556 proc_info_root->owner = THIS_MODULE;
557 } else {
558 reiserfs_warning(NULL,
559 "reiserfs: 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 * $Log: procfs.c,v $
619 * Revision 1.1.8.2 2001/07/15 17:08:42 god
620 * . use get_super() in procfs.c
621 * . remove remove_save_link() from reiserfs_do_truncate()
623 * I accept terms and conditions stated in the Legal Agreement
624 * (available at http://www.namesys.com/legalese.html)
626 * Revision 1.1.8.1 2001/07/11 16:48:50 god
627 * proc info support
629 * I accept terms and conditions stated in the Legal Agreement
630 * (available at http://www.namesys.com/legalese.html)
635 * Make Linus happy.
636 * Local variables:
637 * c-indentation-style: "K&R"
638 * mode-name: "LC"
639 * c-basic-offset: 8
640 * tab-width: 8
641 * End: