2 /* fs/reiserfs/procfs.c */
4 * Copyright 2000-2002 by Hans Reiser, licensing governed by reiserfs/README
7 /* proc info support a la one created by Sizif@Botik.RU for PGC */
9 /* $Id: procfs.c,v 1.1.1.1 2005/04/11 02:50:50 jack Exp $ */
11 #include <linux/config.h>
12 #include <linux/module.h>
13 #include <linux/sched.h>
14 #include <asm/uaccess.h>
15 #include <linux/reiserfs_fs.h>
16 #include <linux/reiserfs_fs_sb.h>
17 #include <linux/smp_lock.h>
18 #include <linux/locks.h>
19 #include <linux/init.h>
20 #include <linux/proc_fs.h>
22 #if defined( REISERFS_PROC_INFO )
27 * We rely on new Alexander Viro's super-block locking.
31 static struct super_block *procinfo_prologue( kdev_t dev )
33 struct super_block *result;
35 /* get super-block by device */
36 result = get_super( dev );
37 if( result != NULL ) {
38 if( !reiserfs_is_super( result ) ) {
39 printk( KERN_DEBUG "reiserfs: procfs-52: "
40 "non-reiserfs super found\n" );
45 printk( KERN_DEBUG "reiserfs: procfs-74: "
46 "race between procinfo and umount\n" );
50 int procinfo_epilogue( struct super_block *super )
56 int reiserfs_proc_tail( int len, char *buffer, char **start,
57 off_t offset, int count, int *eof )
59 /* this is black procfs magic */
65 *start = buffer + offset;
66 if( ( len -= offset ) > count ) {
73 int reiserfs_version_in_proc( char *buffer, char **start, off_t offset,
74 int count, int *eof, void *data )
77 struct super_block *sb;
80 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
83 if ( sb->u.reiserfs_sb.s_properties & (1 << REISERFS_3_6) ) {
85 } else if ( sb->u.reiserfs_sb.s_properties & (1 << REISERFS_3_5) ) {
90 len += sprintf( &buffer[ len ], "%s format\twith checks %s\n",
92 #if defined( CONFIG_REISERFS_CHECK )
98 procinfo_epilogue( sb );
99 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
102 int reiserfs_global_version_in_proc( char *buffer, char **start, off_t offset,
103 int count, int *eof, void *data )
107 len += sprintf( &buffer[ len ], "%s [%s]\n",
108 reiserfs_get_version_string(),
109 #if defined( CONFIG_REISERFS_FS_MODULE )
115 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
118 #define SF( x ) ( r -> x )
119 #define SFP( x ) SF( s_proc_info_data.x )
120 #define SFPL( x ) SFP( x[ level ] )
121 #define SFPF( x ) SFP( scan_bitmap.x )
122 #define SFPJ( x ) SFP( journal.x )
124 #define D2C( x ) le16_to_cpu( x )
125 #define D4C( x ) le32_to_cpu( x )
126 #define DF( x ) D2C( rs -> x )
127 #define DFL( x ) D4C( rs -> x )
129 #define objectid_map( s, rs ) (old_format_only (s) ? \
130 (__u32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
132 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
134 #define DJF( x ) le32_to_cpu( rs -> x )
135 #define JF( x ) ( r -> s_journal -> x )
137 int reiserfs_super_in_proc( char *buffer, char **start, off_t offset,
138 int count, int *eof, void *data )
140 struct super_block *sb;
141 struct reiserfs_sb_info *r;
144 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
147 r = &sb->u.reiserfs_sb;
148 len += sprintf( &buffer[ len ],
150 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s%s\n"
151 "gen. counter: \t%i\n"
153 "s_disk_reads: \t%i\n"
154 "s_disk_writes: \t%i\n"
155 "s_fix_nodes: \t%i\n"
156 "s_do_balance: \t%i\n"
157 "s_unneeded_left_neighbor: \t%i\n"
158 "s_good_search_by_key_reada: \t%i\n"
160 "s_bmaps_without_search: \t%i\n"
161 "s_direct2indirect: \t%i\n"
162 "s_indirect2direct: \t%i\n"
164 "max_hash_collisions: \t%i\n"
167 "bread_misses: \t%lu\n"
169 "search_by_key: \t%lu\n"
170 "search_by_key_fs_changed: \t%lu\n"
171 "search_by_key_restarted: \t%lu\n"
173 "insert_item_restarted: \t%lu\n"
174 "paste_into_item_restarted: \t%lu\n"
175 "cut_from_item_restarted: \t%lu\n"
176 "delete_solid_item_restarted: \t%lu\n"
177 "delete_item_restarted: \t%lu\n"
179 "leaked_oid: \t%lu\n"
180 "leaves_removable: \t%lu\n",
182 SF( s_mount_state ) == REISERFS_VALID_FS ?
183 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
184 reiserfs_r5_hash( sb ) ? "FORCE_R5 " : "",
185 reiserfs_rupasov_hash( sb ) ? "FORCE_RUPASOV " : "",
186 reiserfs_tea_hash( sb ) ? "FORCE_TEA " : "",
187 reiserfs_hash_detect( sb ) ? "DETECT_HASH " : "",
188 reiserfs_no_border( sb ) ? "NO_BORDER " : "BORDER ",
189 reiserfs_no_unhashed_relocation( sb ) ? "NO_UNHASHED_RELOCATION " : "",
190 reiserfs_hashed_relocation( sb ) ? "UNHASHED_RELOCATION " : "",
191 reiserfs_test4( sb ) ? "TEST4 " : "",
192 have_large_tails( sb ) ? "TAILS " : have_small_tails(sb)?"SMALL_TAILS ":"NO_TAILS ",
193 replay_only( sb ) ? "REPLAY_ONLY " : "",
194 reiserfs_dont_log( sb ) ? "DONT_LOG " : "LOG ",
195 convert_reiserfs( sb ) ? "CONV " : "",
197 atomic_read( &r -> s_generation_counter ),
203 SF( s_unneeded_left_neighbor ),
204 SF( s_good_search_by_key_reada ),
206 SF( s_bmaps_without_search ),
207 SF( s_direct2indirect ),
208 SF( s_indirect2direct ),
209 SFP( max_hash_collisions ),
212 SFP( search_by_key ),
213 SFP( search_by_key_fs_changed ),
214 SFP( search_by_key_restarted ),
216 SFP( insert_item_restarted ),
217 SFP( paste_into_item_restarted ),
218 SFP( cut_from_item_restarted ),
219 SFP( delete_solid_item_restarted ),
220 SFP( delete_item_restarted ),
223 SFP( leaves_removable ) );
225 procinfo_epilogue( sb );
226 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
229 int reiserfs_per_level_in_proc( char *buffer, char **start, off_t offset,
230 int count, int *eof, void *data )
232 struct super_block *sb;
233 struct reiserfs_sb_info *r;
237 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
240 r = &sb->u.reiserfs_sb;
242 len += sprintf( &buffer[ len ],
263 for( level = 0 ; level < MAX_HEIGHT ; ++ level ) {
264 if( len > PAGE_SIZE - 240 ) {
265 len += sprintf( &buffer[ len ], "... and more\n" );
268 len += sprintf( &buffer[ len ],
289 SFPL( sbk_fs_changed ),
290 SFPL( sbk_restarted ),
293 SFPL( can_node_be_removed ),
298 SFPL( get_neighbors ),
299 SFPL( get_neighbors_restart ),
300 SFPL( need_l_neighbor ),
301 SFPL( need_r_neighbor )
305 procinfo_epilogue( sb );
306 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
309 int reiserfs_bitmap_in_proc( char *buffer, char **start, off_t offset,
310 int count, int *eof, void *data )
312 struct super_block *sb;
313 struct reiserfs_sb_info *r = &sb->u.reiserfs_sb;
316 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
319 r = &sb->u.reiserfs_sb;
321 len += sprintf( &buffer[ len ], "free_block: %lu\n"
344 SFPF( in_journal_hint ),
345 SFPF( in_journal_nohint ) );
347 procinfo_epilogue( sb );
348 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
351 int reiserfs_on_disk_super_in_proc( char *buffer, char **start, off_t offset,
352 int count, int *eof, void *data )
354 struct super_block *sb;
355 struct reiserfs_sb_info *sb_info;
356 struct reiserfs_super_block *rs;
361 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
364 sb_info = &sb->u.reiserfs_sb;
365 rs = sb_info -> s_rs;
366 hash_code = DFL( s_hash_function_code );
367 flags = DFL( s_flags );
369 len += sprintf( &buffer[ len ],
370 "block_count: \t%i\n"
371 "free_blocks: \t%i\n"
374 "oid_maxsize: \t%i\n"
375 "oid_cursize: \t%i\n"
379 "tree_height: \t%i\n"
384 DFL( s_block_count ),
385 DFL( s_free_blocks ),
392 hash_code == TEA_HASH ? "tea" :
393 ( hash_code == YURA_HASH ) ? "rupasov" :
394 ( hash_code == R5_HASH ) ? "r5" :
395 ( hash_code == UNSET_HASH ) ? "unset" : "unknown",
400 ( flags & reiserfs_attrs_cleared )
401 ? "attrs_cleared" : "" );
403 procinfo_epilogue( sb );
404 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
407 int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
408 int count, int *eof, void *data )
410 struct super_block *sb;
411 struct reiserfs_sb_info *sb_info;
412 struct reiserfs_super_block *rs;
414 unsigned int mapsize;
415 unsigned long total_used;
419 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
422 sb_info = &sb->u.reiserfs_sb;
423 rs = sb_info -> s_rs;
424 mapsize = le16_to_cpu( rs -> s_oid_cursize );
427 for( i = 0 ; i < mapsize ; ++i ) {
430 right = ( i == mapsize - 1 ) ? MAX_KEY_OBJECTID : MAP( i + 1 );
431 len += sprintf( &buffer[ len ], "%s: [ %x .. %x )\n",
432 ( i & 1 ) ? "free" : "used", MAP( i ), right );
434 total_used += right - MAP( i );
436 if( len > PAGE_SIZE - 100 ) {
437 len += sprintf( &buffer[ len ], "... and more\n" );
441 #if defined( REISERFS_USE_OIDMAPF )
442 if( sb_info -> oidmap.use_file && ( sb_info -> oidmap.mapf != NULL ) ) {
445 size = sb_info -> oidmap.mapf -> f_dentry -> d_inode -> i_size;
446 total_used += size / sizeof( reiserfs_oidinterval_d_t );
451 exact = ( i == mapsize );
453 len += sprintf( &buffer[ len ], "total: \t%i [%i/%i] used: %lu [%s]\n",
455 mapsize, le16_to_cpu( rs -> s_oid_maxsize ),
456 total_used, exact ? "exact" : "estimation" );
458 procinfo_epilogue( sb );
459 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
462 int reiserfs_journal_in_proc( char *buffer, char **start, off_t offset,
463 int count, int *eof, void *data )
465 struct super_block *sb;
466 struct reiserfs_sb_info *r;
467 struct reiserfs_super_block *rs;
470 sb = procinfo_prologue( ( kdev_t ) ( long ) data );
473 r = &sb->u.reiserfs_sb;
476 len += sprintf( &buffer[ len ],
478 "s_journal_block: \t%i\n"
479 "s_journal_dev: \t%s[%x]\n"
480 "s_orig_journal_size: \t%i\n"
481 "s_journal_trans_max: \t%i\n"
482 "s_journal_block_count: \t%i\n"
483 "s_journal_max_batch: \t%i\n"
484 "s_journal_max_commit_age: \t%i\n"
485 "s_journal_max_trans_age: \t%i\n"
488 "j_trans_id: \t%lu\n"
489 "j_mount_id: \t%lu\n"
492 "j_len_alloc: \t%lu\n"
495 "j_first_unflushed_offset: \t%lu\n"
496 "j_last_flush_trans_id: \t%lu\n"
497 "j_trans_start_time: \t%li\n"
498 "j_journal_list_index: \t%i\n"
499 "j_list_bitmap_index: \t%i\n"
500 "j_must_wait: \t%i\n"
501 "j_next_full_flush: \t%i\n"
502 "j_next_async_flush: \t%i\n"
503 "j_cnode_used: \t%i\n"
504 "j_cnode_free: \t%i\n"
506 /* reiserfs_proc_info_data_t.journal fields */
507 "in_journal: \t%12lu\n"
508 "in_journal_bitmap: \t%12lu\n"
509 "in_journal_reusable: \t%12lu\n"
510 "lock_journal: \t%12lu\n"
511 "lock_journal_wait: \t%12lu\n"
512 "journal_begin: \t%12lu\n"
513 "journal_relock_writers: \t%12lu\n"
514 "journal_relock_wcount: \t%12lu\n"
515 "mark_dirty: \t%12lu\n"
516 "mark_dirty_already: \t%12lu\n"
517 "mark_dirty_notjournal: \t%12lu\n"
518 "restore_prepared: \t%12lu\n"
520 "prepare_retry: \t%12lu\n",
522 DJF( s_journal_block ),
523 DJF( s_journal_dev ) == 0 ? "none" : bdevname( DJF( s_journal_dev ) ),
524 DJF( s_journal_dev ),
525 DJF( s_orig_journal_size ),
526 DJF( s_journal_trans_max ),
527 DJF( s_journal_block_count ),
528 DJF( s_journal_max_batch ),
529 DJF( s_journal_max_commit_age ),
530 DJF( s_journal_max_trans_age ),
538 atomic_read( & r -> s_journal -> j_wcount ),
540 JF( j_first_unflushed_offset ),
541 JF( j_last_flush_trans_id ),
542 JF( j_trans_start_time ),
543 JF( j_journal_list_index ),
544 JF( j_list_bitmap_index ),
546 JF( j_next_full_flush ),
547 JF( j_next_async_flush ),
552 SFPJ( in_journal_bitmap ),
553 SFPJ( in_journal_reusable ),
554 SFPJ( lock_journal ),
555 SFPJ( lock_journal_wait ),
556 SFPJ( journal_being ),
557 SFPJ( journal_relock_writers ),
558 SFPJ( journal_relock_wcount ),
560 SFPJ( mark_dirty_already ),
561 SFPJ( mark_dirty_notjournal ),
562 SFPJ( restore_prepared ),
564 SFPJ( prepare_retry )
567 procinfo_epilogue( sb );
568 return reiserfs_proc_tail( len, buffer, start, offset, count, eof );
572 static struct proc_dir_entry *proc_info_root = NULL;
573 static const char *proc_info_root_name = "fs/reiserfs";
575 int reiserfs_proc_info_init( struct super_block *sb )
577 spin_lock_init( & __PINFO( sb ).lock );
578 sb->u.reiserfs_sb.procdir = proc_mkdir( bdevname( sb -> s_dev ),
580 if( sb->u.reiserfs_sb.procdir ) {
581 sb->u.reiserfs_sb.procdir -> owner = THIS_MODULE;
584 reiserfs_warning( "reiserfs: cannot create /proc/%s/%s\n",
585 proc_info_root_name, bdevname( sb -> s_dev ) );
590 int reiserfs_proc_info_done( struct super_block *sb )
592 spin_lock( & __PINFO( sb ).lock );
593 __PINFO( sb ).exiting = 1;
594 spin_unlock( & __PINFO( sb ).lock );
595 if ( proc_info_root ) {
596 remove_proc_entry( bdevname( sb -> s_dev ), proc_info_root );
597 sb->u.reiserfs_sb.procdir = NULL;
602 /* Create /proc/fs/reiserfs/DEV/name and attach read procedure @func
603 to it. Other parts of reiserfs use this function to make their
604 per-device statistics available via /proc */
606 struct proc_dir_entry *reiserfs_proc_register( struct super_block *sb,
607 char *name, read_proc_t *func )
609 return ( sb->u.reiserfs_sb.procdir ) ? create_proc_read_entry
610 ( name, 0, sb->u.reiserfs_sb.procdir, func,
611 ( void * ) ( long ) sb -> s_dev ) : NULL;
614 void reiserfs_proc_unregister( struct super_block *sb, const char *name )
616 remove_proc_entry( name, sb->u.reiserfs_sb.procdir );
619 struct proc_dir_entry *reiserfs_proc_register_global( char *name,
622 return ( proc_info_root ) ? create_proc_read_entry( name, 0,
627 void reiserfs_proc_unregister_global( const char *name )
629 remove_proc_entry( name, proc_info_root );
632 int reiserfs_proc_info_global_init( void )
634 if( proc_info_root == NULL ) {
635 proc_info_root = proc_mkdir( proc_info_root_name, 0 );
636 if( proc_info_root ) {
637 proc_info_root -> owner = THIS_MODULE;
639 reiserfs_warning( "reiserfs: cannot create /proc/%s\n",
640 proc_info_root_name );
647 int reiserfs_proc_info_global_done( void )
649 if ( proc_info_root != NULL ) {
650 proc_info_root = NULL;
651 remove_proc_entry( proc_info_root_name, 0 );
656 /* REISERFS_PROC_INFO */
659 int reiserfs_proc_info_init( struct super_block *sb ) { return 0; }
660 int reiserfs_proc_info_done( struct super_block *sb ) { return 0; }
662 struct proc_dir_entry *reiserfs_proc_register( struct super_block *sb,
667 void reiserfs_proc_unregister( struct super_block *sb, const char *name )
670 struct proc_dir_entry *reiserfs_proc_register_global( char *name,
674 void reiserfs_proc_unregister_global( const char *name ) {;}
676 int reiserfs_proc_info_global_init( void ) { return 0; }
677 int reiserfs_proc_info_global_done( void ) { return 0; }
679 int reiserfs_global_version_in_proc( char *buffer, char **start,
681 int count, int *eof, void *data )
684 int reiserfs_version_in_proc( char *buffer, char **start, off_t offset,
685 int count, int *eof, void *data )
688 int reiserfs_super_in_proc( char *buffer, char **start, off_t offset,
689 int count, int *eof, void *data )
692 int reiserfs_per_level_in_proc( char *buffer, char **start, off_t offset,
693 int count, int *eof, void *data )
696 int reiserfs_bitmap_in_proc( char *buffer, char **start, off_t offset,
697 int count, int *eof, void *data )
700 int reiserfs_on_disk_super_in_proc( char *buffer, char **start, off_t offset,
701 int count, int *eof, void *data )
704 int reiserfs_oidmap_in_proc( char *buffer, char **start, off_t offset,
705 int count, int *eof, void *data )
708 int reiserfs_journal_in_proc( char *buffer, char **start, off_t offset,
709 int count, int *eof, void *data )
712 /* REISERFS_PROC_INFO */
717 * Revision 1.1.1.1 2005/04/11 02:50:50 jack
720 * Revision 1.1.1.1 2005/01/10 13:16:52 jack
723 * Revision 1.1.8.2 2001/07/15 17:08:42 god
724 * . use get_super() in procfs.c
725 * . remove remove_save_link() from reiserfs_do_truncate()
727 * I accept terms and conditions stated in the Legal Agreement
728 * (available at http://www.namesys.com/legalese.html)
730 * Revision 1.1.8.1 2001/07/11 16:48:50 god
733 * I accept terms and conditions stated in the Legal Agreement
734 * (available at http://www.namesys.com/legalese.html)
741 * c-indentation-style: "K&R"