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/config.h>
14 #include <linux/module.h>
15 #include <linux/time.h>
16 #include <asm/uaccess.h>
17 #include <linux/reiserfs_fs.h>
18 #include <linux/reiserfs_fs_sb.h>
19 #include <linux/smp_lock.h>
20 #include <linux/init.h>
21 #include <linux/proc_fs.h>
23 #if defined( REISERFS_PROC_INFO )
28 * We rely on new Alexander Viro's super-block locking.
32 static struct super_block *procinfo_prologue(dev_t dev)
34 struct super_block *result;
36 /* get super-block by device */
37 result = user_get_super(dev);
38 if( result != NULL ) {
39 if( !is_reiserfs_super( result ) ) {
40 printk( KERN_DEBUG "reiserfs: procfs-52: "
41 "non-reiserfs super found\n" );
46 printk( KERN_DEBUG "reiserfs: procfs-74: "
47 "race between procinfo and umount\n" );
51 int procinfo_epilogue( struct super_block *super )
57 int reiserfs_proc_tail( int len, char *buffer, char **start,
58 off_t offset, int count, int *eof )
60 /* this is black procfs magic */
66 *start = buffer + offset;
67 if( ( len -= offset ) > count ) {
74 int reiserfs_version_in_proc( char *buffer, char **start, off_t offset,
75 int count, int *eof, void *data )
78 struct super_block *sb;
81 sb = procinfo_prologue((int)data);
84 if ( REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6) ) {
86 } else if ( REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5) ) {
92 len += sprintf( &buffer[ len ], "%s format\twith checks %s\n",
94 #if defined( CONFIG_REISERFS_CHECK )
100 procinfo_epilogue( sb );
101 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
104 int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset,
105 int count, int *eof, void *data )
108 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
111 #define SF( x ) ( r -> x )
112 #define SFP( x ) SF( s_proc_info_data.x )
113 #define SFPL( x ) SFP( x[ level ] )
114 #define SFPF( x ) SFP( scan_bitmap.x )
115 #define SFPJ( x ) SFP( journal.x )
117 #define D2C( x ) le16_to_cpu( x )
118 #define D4C( x ) le32_to_cpu( x )
119 #define DF( x ) D2C( rs -> s_v1.x )
120 #define DFL( x ) D4C( rs -> s_v1.x )
122 #define objectid_map( s, rs ) (old_format_only (s) ? \
123 (__u32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
125 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
127 #define DJF( x ) le32_to_cpu( rs -> x )
128 #define DJV( x ) le32_to_cpu( s_v1 -> x )
129 #define DJP( x ) le32_to_cpu( jp -> x )
130 #define JF( x ) ( r -> s_journal -> x )
132 int reiserfs_super_in_proc( char *buffer, char **start, off_t offset,
133 int count, int *eof, void *data )
135 struct super_block *sb;
136 struct reiserfs_sb_info *r;
139 sb = procinfo_prologue((int)data);
143 len += sprintf( &buffer[ len ],
145 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s%s\n"
146 "gen. counter: \t%i\n"
148 "s_disk_reads: \t%i\n"
149 "s_disk_writes: \t%i\n"
150 "s_fix_nodes: \t%i\n"
151 "s_do_balance: \t%i\n"
152 "s_unneeded_left_neighbor: \t%i\n"
153 "s_good_search_by_key_reada: \t%i\n"
155 "s_bmaps_without_search: \t%i\n"
156 "s_direct2indirect: \t%i\n"
157 "s_indirect2direct: \t%i\n"
159 "max_hash_collisions: \t%i\n"
162 "bread_misses: \t%lu\n"
164 "search_by_key: \t%lu\n"
165 "search_by_key_fs_changed: \t%lu\n"
166 "search_by_key_restarted: \t%lu\n"
168 "insert_item_restarted: \t%lu\n"
169 "paste_into_item_restarted: \t%lu\n"
170 "cut_from_item_restarted: \t%lu\n"
171 "delete_solid_item_restarted: \t%lu\n"
172 "delete_item_restarted: \t%lu\n"
174 "leaked_oid: \t%lu\n"
175 "leaves_removable: \t%lu\n",
177 SF( s_mount_state ) == REISERFS_VALID_FS ?
178 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
179 reiserfs_r5_hash( sb ) ? "FORCE_R5 " : "",
180 reiserfs_rupasov_hash( sb ) ? "FORCE_RUPASOV " : "",
181 reiserfs_tea_hash( sb ) ? "FORCE_TEA " : "",
182 reiserfs_hash_detect( sb ) ? "DETECT_HASH " : "",
183 reiserfs_no_border( sb ) ? "NO_BORDER " : "BORDER ",
184 reiserfs_no_unhashed_relocation( sb ) ? "NO_UNHASHED_RELOCATION " : "",
185 reiserfs_hashed_relocation( sb ) ? "UNHASHED_RELOCATION " : "",
186 reiserfs_test4( sb ) ? "TEST4 " : "",
187 have_large_tails( sb ) ? "TAILS " : have_small_tails(sb)?"SMALL_TAILS ":"NO_TAILS ",
188 replay_only( sb ) ? "REPLAY_ONLY " : "",
189 reiserfs_dont_log( sb ) ? "DONT_LOG " : "LOG ",
190 convert_reiserfs( sb ) ? "CONV " : "",
192 atomic_read( &r -> s_generation_counter ),
198 SF( s_unneeded_left_neighbor ),
199 SF( s_good_search_by_key_reada ),
201 SF( s_bmaps_without_search ),
202 SF( s_direct2indirect ),
203 SF( s_indirect2direct ),
204 SFP( max_hash_collisions ),
207 SFP( search_by_key ),
208 SFP( search_by_key_fs_changed ),
209 SFP( search_by_key_restarted ),
211 SFP( insert_item_restarted ),
212 SFP( paste_into_item_restarted ),
213 SFP( cut_from_item_restarted ),
214 SFP( delete_solid_item_restarted ),
215 SFP( delete_item_restarted ),
218 SFP( leaves_removable ) );
220 procinfo_epilogue( sb );
221 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
224 int reiserfs_per_level_in_proc( char *buffer, char **start, off_t offset,
225 int count, int *eof, void *data )
227 struct super_block *sb;
228 struct reiserfs_sb_info *r;
232 sb = procinfo_prologue((int)data);
237 len += sprintf( &buffer[ len ],
258 for( level = 0 ; level < MAX_HEIGHT ; ++ level ) {
259 if( len > PAGE_SIZE - 240 ) {
260 len += sprintf( &buffer[ len ], "... and more\n" );
263 len += sprintf( &buffer[ len ],
284 SFPL( sbk_fs_changed ),
285 SFPL( sbk_restarted ),
288 SFPL( can_node_be_removed ),
293 SFPL( get_neighbors ),
294 SFPL( get_neighbors_restart ),
295 SFPL( need_l_neighbor ),
296 SFPL( need_r_neighbor )
300 procinfo_epilogue( sb );
301 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
304 int reiserfs_bitmap_in_proc( char *buffer, char **start, off_t offset,
305 int count, int *eof, void *data )
307 struct super_block *sb;
308 struct reiserfs_sb_info *r;
311 sb = procinfo_prologue((int)data);
316 len += sprintf( &buffer[ len ], "free_block: %lu\n"
339 SFPF( in_journal_hint ),
340 SFPF( in_journal_nohint ) );
342 procinfo_epilogue( sb );
343 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
346 int reiserfs_on_disk_super_in_proc( char *buffer, char **start, off_t offset,
347 int count, int *eof, void *data )
349 struct super_block *sb;
350 struct reiserfs_sb_info *sb_info;
351 struct reiserfs_super_block *rs;
356 sb = procinfo_prologue((int)data);
359 sb_info = REISERFS_SB(sb);
360 rs = sb_info -> s_rs;
361 hash_code = DFL( s_hash_function_code );
362 flags = DJF( s_flags );
364 len += sprintf( &buffer[ len ],
365 "block_count: \t%i\n"
366 "free_blocks: \t%i\n"
369 "oid_maxsize: \t%i\n"
370 "oid_cursize: \t%i\n"
371 "umount_state: \t%i\n"
375 "tree_height: \t%i\n"
379 "reserved_for_journal: \t%i\n",
381 DFL( s_block_count ),
382 DFL( s_free_blocks ),
387 DF( s_umount_state ),
390 hash_code == TEA_HASH ? "tea" :
391 ( hash_code == YURA_HASH ) ? "rupasov" :
392 ( hash_code == R5_HASH ) ? "r5" :
393 ( hash_code == UNSET_HASH ) ? "unset" : "unknown",
398 ( flags & reiserfs_attrs_cleared )
399 ? "attrs_cleared" : "",
400 DF (s_reserved_for_journal));
402 procinfo_epilogue( sb );
403 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
406 int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
407 int count, int *eof, void *data )
409 struct super_block *sb;
410 struct reiserfs_sb_info *sb_info;
411 struct reiserfs_super_block *rs;
413 unsigned int mapsize;
414 unsigned long total_used;
418 sb = procinfo_prologue((int)data);
421 sb_info = REISERFS_SB(sb);
422 rs = sb_info -> s_rs;
423 mapsize = le16_to_cpu( rs -> s_v1.s_oid_cursize );
426 for( i = 0 ; i < mapsize ; ++i ) {
429 right = ( i == mapsize - 1 ) ? MAX_KEY_OBJECTID : MAP( i + 1 );
430 len += sprintf( &buffer[ len ], "%s: [ %x .. %x )\n",
431 ( i & 1 ) ? "free" : "used", MAP( i ), right );
433 total_used += right - MAP( i );
435 if( len > PAGE_SIZE - 100 ) {
436 len += sprintf( &buffer[ len ], "... and more\n" );
440 #if defined( REISERFS_USE_OIDMAPF )
441 if( sb_info -> oidmap.use_file && ( sb_info -> oidmap.mapf != NULL ) ) {
444 size = sb_info -> oidmap.mapf -> f_dentry -> d_inode -> i_size;
445 total_used += size / sizeof( reiserfs_oidinterval_d_t );
450 exact = ( i == mapsize );
452 len += sprintf( &buffer[ len ], "total: \t%i [%i/%i] used: %lu [%s]\n",
454 mapsize, le16_to_cpu( rs -> s_v1.s_oid_maxsize ),
455 total_used, exact ? "exact" : "estimation" );
457 procinfo_epilogue( sb );
458 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
461 int reiserfs_journal_in_proc( char *buffer, char **start, off_t offset,
462 int count, int *eof, void *data )
464 struct super_block *sb;
465 struct reiserfs_sb_info *r;
466 struct reiserfs_super_block *rs;
467 struct journal_params *jp;
469 char b[BDEVNAME_SIZE];
471 sb = procinfo_prologue((int)data);
476 jp = &rs->s_v1.s_journal;
478 len += sprintf( &buffer[ len ],
480 "jp_journal_1st_block: \t%i\n"
481 "jp_journal_dev: \t%s[%x]\n"
482 "jp_journal_size: \t%i\n"
483 "jp_journal_trans_max: \t%i\n"
484 "jp_journal_magic: \t%i\n"
485 "jp_journal_max_batch: \t%i\n"
486 "jp_journal_max_commit_age: \t%i\n"
487 "jp_journal_max_trans_age: \t%i\n"
489 "j_1st_reserved_block: \t%i\n"
491 "j_trans_id: \t%lu\n"
492 "j_mount_id: \t%lu\n"
495 "j_len_alloc: \t%lu\n"
498 "j_first_unflushed_offset: \t%lu\n"
499 "j_last_flush_trans_id: \t%lu\n"
500 "j_trans_start_time: \t%li\n"
501 "j_journal_list_index: \t%i\n"
502 "j_list_bitmap_index: \t%i\n"
503 "j_must_wait: \t%i\n"
504 "j_next_full_flush: \t%i\n"
505 "j_next_async_flush: \t%i\n"
506 "j_cnode_used: \t%i\n"
507 "j_cnode_free: \t%i\n"
509 /* reiserfs_proc_info_data_t.journal fields */
510 "in_journal: \t%12lu\n"
511 "in_journal_bitmap: \t%12lu\n"
512 "in_journal_reusable: \t%12lu\n"
513 "lock_journal: \t%12lu\n"
514 "lock_journal_wait: \t%12lu\n"
515 "journal_begin: \t%12lu\n"
516 "journal_relock_writers: \t%12lu\n"
517 "journal_relock_wcount: \t%12lu\n"
518 "mark_dirty: \t%12lu\n"
519 "mark_dirty_already: \t%12lu\n"
520 "mark_dirty_notjournal: \t%12lu\n"
521 "restore_prepared: \t%12lu\n"
523 "prepare_retry: \t%12lu\n",
525 DJP( jp_journal_1st_block ),
526 bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
527 DJP( jp_journal_dev ),
528 DJP( jp_journal_size ),
529 DJP( jp_journal_trans_max ),
530 DJP( jp_journal_magic ),
531 DJP( jp_journal_max_batch ),
532 DJP( jp_journal_max_commit_age ),
533 DJP( jp_journal_max_trans_age ),
535 JF( j_1st_reserved_block ),
542 atomic_read( & r -> s_journal -> j_wcount ),
544 JF( j_first_unflushed_offset ),
545 JF( j_last_flush_trans_id ),
546 JF( j_trans_start_time ),
547 JF( j_journal_list_index ),
548 JF( j_list_bitmap_index ),
550 JF( j_next_full_flush ),
551 JF( j_next_async_flush ),
556 SFPJ( in_journal_bitmap ),
557 SFPJ( in_journal_reusable ),
558 SFPJ( lock_journal ),
559 SFPJ( lock_journal_wait ),
560 SFPJ( journal_being ),
561 SFPJ( journal_relock_writers ),
562 SFPJ( journal_relock_wcount ),
564 SFPJ( mark_dirty_already ),
565 SFPJ( mark_dirty_notjournal ),
566 SFPJ( restore_prepared ),
568 SFPJ( prepare_retry )
571 procinfo_epilogue( sb );
572 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
576 static struct proc_dir_entry *proc_info_root = NULL;
577 static const char proc_info_root_name[] = "fs/reiserfs";
579 int reiserfs_proc_info_init( struct super_block *sb )
581 spin_lock_init( & __PINFO( sb ).lock );
582 REISERFS_SB(sb)->procdir = proc_mkdir(reiserfs_bdevname (sb), proc_info_root);
583 if( REISERFS_SB(sb)->procdir ) {
584 REISERFS_SB(sb)->procdir -> owner = THIS_MODULE;
587 reiserfs_warning( "reiserfs: cannot create /proc/%s/%s\n",
588 proc_info_root_name, reiserfs_bdevname (sb) );
593 int reiserfs_proc_info_done( struct super_block *sb )
595 spin_lock( & __PINFO( sb ).lock );
596 __PINFO( sb ).exiting = 1;
597 spin_unlock( & __PINFO( sb ).lock );
598 if ( proc_info_root ) {
599 remove_proc_entry( reiserfs_bdevname (sb), proc_info_root );
600 REISERFS_SB(sb)->procdir = NULL;
605 /* Create /proc/fs/reiserfs/DEV/name and attach read procedure @func
606 to it. Other parts of reiserfs use this function to make their
607 per-device statistics available via /proc */
609 struct proc_dir_entry *reiserfs_proc_register( struct super_block *sb,
610 char *name, read_proc_t *func )
612 return ( REISERFS_SB(sb)->procdir ) ? create_proc_read_entry
613 ( name, 0, REISERFS_SB(sb)->procdir, func,
614 ( void * )(int) sb->s_bdev->bd_dev) : NULL;
617 void reiserfs_proc_unregister( struct super_block *sb, const char *name )
619 remove_proc_entry( name, REISERFS_SB(sb)->procdir );
622 struct proc_dir_entry *reiserfs_proc_register_global( char *name,
625 return ( proc_info_root ) ? create_proc_read_entry( name, 0,
630 void reiserfs_proc_unregister_global( const char *name )
632 remove_proc_entry( name, proc_info_root );
635 int reiserfs_proc_info_global_init( void )
637 if( proc_info_root == NULL ) {
638 proc_info_root = proc_mkdir( proc_info_root_name, 0 );
639 if( proc_info_root ) {
640 proc_info_root -> owner = THIS_MODULE;
642 reiserfs_warning( "reiserfs: cannot create /proc/%s\n",
643 proc_info_root_name );
650 int reiserfs_proc_info_global_done( void )
652 if ( proc_info_root != NULL ) {
653 proc_info_root = NULL;
654 remove_proc_entry( proc_info_root_name, 0 );
659 /* REISERFS_PROC_INFO */
662 int reiserfs_proc_info_init( struct super_block *sb ) { return 0; }
663 int reiserfs_proc_info_done( struct super_block *sb ) { return 0; }
665 struct proc_dir_entry *reiserfs_proc_register( struct super_block *sb,
670 void reiserfs_proc_unregister( struct super_block *sb, const char *name )
673 struct proc_dir_entry *reiserfs_proc_register_global( char *name,
677 void reiserfs_proc_unregister_global( const char *name ) {;}
679 int reiserfs_proc_info_global_init( void ) { return 0; }
680 int reiserfs_proc_info_global_done( void ) { return 0; }
682 int reiserfs_global_version_in_proc( char *buffer, char **start,
684 int count, int *eof, void *data )
687 int reiserfs_version_in_proc( char *buffer, char **start, off_t offset,
688 int count, int *eof, void *data )
691 int reiserfs_super_in_proc( char *buffer, char **start, off_t offset,
692 int count, int *eof, void *data )
695 int reiserfs_per_level_in_proc( char *buffer, char **start, off_t offset,
696 int count, int *eof, void *data )
699 int reiserfs_bitmap_in_proc( char *buffer, char **start, off_t offset,
700 int count, int *eof, void *data )
703 int reiserfs_on_disk_super_in_proc( char *buffer, char **start, off_t offset,
704 int count, int *eof, void *data )
707 int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
708 int count, int *eof, void *data )
711 int reiserfs_journal_in_proc( char *buffer, char **start, off_t offset,
712 int count, int *eof, void *data )
715 /* REISERFS_PROC_INFO */
720 * Revision 1.1.8.2 2001/07/15 17:08:42 god
721 * . use get_super() in procfs.c
722 * . remove remove_save_link() from reiserfs_do_truncate()
724 * I accept terms and conditions stated in the Legal Agreement
725 * (available at http://www.namesys.com/legalese.html)
727 * Revision 1.1.8.1 2001/07/11 16:48:50 god
730 * I accept terms and conditions stated in the Legal Agreement
731 * (available at http://www.namesys.com/legalese.html)
738 * c-indentation-style: "K&R"