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 <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 )
29 * We rely on new Alexander Viro's super-block locking.
33 static int show_version(struct seq_file
*m
, struct super_block
*sb
)
37 if ( REISERFS_SB(sb
)->s_properties
& (1 << REISERFS_3_6
) ) {
39 } else if ( REISERFS_SB(sb
)->s_properties
& (1 << REISERFS_3_5
) ) {
45 seq_printf(m
, "%s format\twith checks %s\n",
47 #if defined( CONFIG_REISERFS_CHECK )
56 int reiserfs_global_version_in_proc( char *buffer
, char **start
, off_t offset
,
57 int count
, int *eof
, void *data
)
64 #define SF( x ) ( r -> x )
65 #define SFP( x ) SF( s_proc_info_data.x )
66 #define SFPL( x ) SFP( x[ level ] )
67 #define SFPF( x ) SFP( scan_bitmap.x )
68 #define SFPJ( x ) SFP( journal.x )
70 #define D2C( x ) le16_to_cpu( x )
71 #define D4C( x ) le32_to_cpu( x )
72 #define DF( x ) D2C( rs -> s_v1.x )
73 #define DFL( x ) D4C( rs -> s_v1.x )
75 #define objectid_map( s, rs ) (old_format_only (s) ? \
76 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
78 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
80 #define DJF( x ) le32_to_cpu( rs -> x )
81 #define DJV( x ) le32_to_cpu( s_v1 -> x )
82 #define DJP( x ) le32_to_cpu( jp -> x )
83 #define JF( x ) ( r -> s_journal -> x )
85 static int show_super(struct seq_file
*m
, struct super_block
*sb
)
87 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
89 seq_printf(m
, "state: \t%s\n"
90 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
91 "gen. counter: \t%i\n"
93 "s_disk_reads: \t%i\n"
94 "s_disk_writes: \t%i\n"
96 "s_do_balance: \t%i\n"
97 "s_unneeded_left_neighbor: \t%i\n"
98 "s_good_search_by_key_reada: \t%i\n"
100 "s_bmaps_without_search: \t%i\n"
101 "s_direct2indirect: \t%i\n"
102 "s_indirect2direct: \t%i\n"
104 "max_hash_collisions: \t%i\n"
107 "bread_misses: \t%lu\n"
109 "search_by_key: \t%lu\n"
110 "search_by_key_fs_changed: \t%lu\n"
111 "search_by_key_restarted: \t%lu\n"
113 "insert_item_restarted: \t%lu\n"
114 "paste_into_item_restarted: \t%lu\n"
115 "cut_from_item_restarted: \t%lu\n"
116 "delete_solid_item_restarted: \t%lu\n"
117 "delete_item_restarted: \t%lu\n"
119 "leaked_oid: \t%lu\n"
120 "leaves_removable: \t%lu\n",
122 SF( s_mount_state
) == REISERFS_VALID_FS
?
123 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
124 reiserfs_r5_hash( sb
) ? "FORCE_R5 " : "",
125 reiserfs_rupasov_hash( sb
) ? "FORCE_RUPASOV " : "",
126 reiserfs_tea_hash( sb
) ? "FORCE_TEA " : "",
127 reiserfs_hash_detect( sb
) ? "DETECT_HASH " : "",
128 reiserfs_no_border( sb
) ? "NO_BORDER " : "BORDER ",
129 reiserfs_no_unhashed_relocation( sb
) ? "NO_UNHASHED_RELOCATION " : "",
130 reiserfs_hashed_relocation( sb
) ? "UNHASHED_RELOCATION " : "",
131 reiserfs_test4( sb
) ? "TEST4 " : "",
132 have_large_tails( sb
) ? "TAILS " : have_small_tails(sb
)?"SMALL_TAILS ":"NO_TAILS ",
133 replay_only( sb
) ? "REPLAY_ONLY " : "",
134 convert_reiserfs( sb
) ? "CONV " : "",
136 atomic_read( &r
-> s_generation_counter
),
142 SF( s_unneeded_left_neighbor
),
143 SF( s_good_search_by_key_reada
),
145 SF( s_bmaps_without_search
),
146 SF( s_direct2indirect
),
147 SF( s_indirect2direct
),
148 SFP( max_hash_collisions
),
151 SFP( search_by_key
),
152 SFP( search_by_key_fs_changed
),
153 SFP( search_by_key_restarted
),
155 SFP( insert_item_restarted
),
156 SFP( paste_into_item_restarted
),
157 SFP( cut_from_item_restarted
),
158 SFP( delete_solid_item_restarted
),
159 SFP( delete_item_restarted
),
162 SFP( leaves_removable
) );
167 static int show_per_level(struct seq_file
*m
, struct super_block
*sb
)
169 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
172 seq_printf(m
, "level\t"
192 for( level
= 0 ; level
< MAX_HEIGHT
; ++ level
) {
213 SFPL( sbk_fs_changed
),
214 SFPL( sbk_restarted
),
217 SFPL( can_node_be_removed
),
222 SFPL( get_neighbors
),
223 SFPL( get_neighbors_restart
),
224 SFPL( need_l_neighbor
),
225 SFPL( need_r_neighbor
)
231 static int show_bitmap(struct seq_file
*m
, struct super_block
*sb
)
233 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
235 seq_printf(m
, "free_block: %lu\n"
258 SFPF( in_journal_hint
),
259 SFPF( in_journal_nohint
) );
264 static int show_on_disk_super(struct seq_file
*m
, struct super_block
*sb
)
266 struct reiserfs_sb_info
*sb_info
= REISERFS_SB(sb
);
267 struct reiserfs_super_block
*rs
= sb_info
-> s_rs
;
268 int hash_code
= DFL( s_hash_function_code
);
269 __u32 flags
= DJF( s_flags
);
271 seq_printf(m
, "block_count: \t%i\n"
272 "free_blocks: \t%i\n"
275 "oid_maxsize: \t%i\n"
276 "oid_cursize: \t%i\n"
277 "umount_state: \t%i\n"
281 "tree_height: \t%i\n"
285 "reserved_for_journal: \t%i\n",
287 DFL( s_block_count
),
288 DFL( s_free_blocks
),
293 DF( s_umount_state
),
296 hash_code
== TEA_HASH
? "tea" :
297 ( hash_code
== YURA_HASH
) ? "rupasov" :
298 ( hash_code
== R5_HASH
) ? "r5" :
299 ( hash_code
== UNSET_HASH
) ? "unset" : "unknown",
304 ( flags
& reiserfs_attrs_cleared
)
305 ? "attrs_cleared" : "",
306 DF (s_reserved_for_journal
));
311 static int show_oidmap(struct seq_file
*m
, struct super_block
*sb
)
313 struct reiserfs_sb_info
*sb_info
= REISERFS_SB(sb
);
314 struct reiserfs_super_block
*rs
= sb_info
-> s_rs
;
315 unsigned int mapsize
= le16_to_cpu( rs
-> s_v1
.s_oid_cursize
);
316 unsigned long total_used
= 0;
319 for( i
= 0 ; i
< mapsize
; ++i
) {
322 right
= ( i
== mapsize
- 1 ) ? MAX_KEY_OBJECTID
: MAP( i
+ 1 );
323 seq_printf(m
, "%s: [ %x .. %x )\n",
324 ( i
& 1 ) ? "free" : "used", MAP( i
), right
);
326 total_used
+= right
- MAP( i
);
329 #if defined( REISERFS_USE_OIDMAPF )
330 if( sb_info
-> oidmap
.use_file
&& ( sb_info
-> oidmap
.mapf
!= NULL
) ) {
331 loff_t size
= sb_info
->oidmap
.mapf
->f_dentry
->d_inode
->i_size
;
332 total_used
+= size
/ sizeof( reiserfs_oidinterval_d_t
);
335 seq_printf(m
, "total: \t%i [%i/%i] used: %lu [exact]\n",
337 mapsize
, le16_to_cpu( rs
-> s_v1
.s_oid_maxsize
),
342 static int show_journal(struct seq_file
*m
, struct super_block
*sb
)
344 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
345 struct reiserfs_super_block
*rs
= r
-> s_rs
;
346 struct journal_params
*jp
= &rs
->s_v1
.s_journal
;
347 char b
[BDEVNAME_SIZE
];
350 seq_printf(m
, /* on-disk fields */
351 "jp_journal_1st_block: \t%i\n"
352 "jp_journal_dev: \t%s[%x]\n"
353 "jp_journal_size: \t%i\n"
354 "jp_journal_trans_max: \t%i\n"
355 "jp_journal_magic: \t%i\n"
356 "jp_journal_max_batch: \t%i\n"
357 "jp_journal_max_commit_age: \t%i\n"
358 "jp_journal_max_trans_age: \t%i\n"
360 "j_1st_reserved_block: \t%i\n"
362 "j_trans_id: \t%lu\n"
363 "j_mount_id: \t%lu\n"
366 "j_len_alloc: \t%lu\n"
369 "j_first_unflushed_offset: \t%lu\n"
370 "j_last_flush_trans_id: \t%lu\n"
371 "j_trans_start_time: \t%li\n"
372 "j_list_bitmap_index: \t%i\n"
373 "j_must_wait: \t%i\n"
374 "j_next_full_flush: \t%i\n"
375 "j_next_async_flush: \t%i\n"
376 "j_cnode_used: \t%i\n"
377 "j_cnode_free: \t%i\n"
379 /* reiserfs_proc_info_data_t.journal fields */
380 "in_journal: \t%12lu\n"
381 "in_journal_bitmap: \t%12lu\n"
382 "in_journal_reusable: \t%12lu\n"
383 "lock_journal: \t%12lu\n"
384 "lock_journal_wait: \t%12lu\n"
385 "journal_begin: \t%12lu\n"
386 "journal_relock_writers: \t%12lu\n"
387 "journal_relock_wcount: \t%12lu\n"
388 "mark_dirty: \t%12lu\n"
389 "mark_dirty_already: \t%12lu\n"
390 "mark_dirty_notjournal: \t%12lu\n"
391 "restore_prepared: \t%12lu\n"
393 "prepare_retry: \t%12lu\n",
395 DJP( jp_journal_1st_block
),
396 bdevname(SB_JOURNAL(sb
)->j_dev_bd
, b
),
397 DJP( jp_journal_dev
),
398 DJP( jp_journal_size
),
399 DJP( jp_journal_trans_max
),
400 DJP( jp_journal_magic
),
401 DJP( jp_journal_max_batch
),
402 SB_JOURNAL(sb
)->j_max_commit_age
,
403 DJP( jp_journal_max_trans_age
),
405 JF( j_1st_reserved_block
),
412 atomic_read( & r
-> s_journal
-> j_wcount
),
414 JF( j_first_unflushed_offset
),
415 JF( j_last_flush_trans_id
),
416 JF( j_trans_start_time
),
417 JF( j_list_bitmap_index
),
419 JF( j_next_full_flush
),
420 JF( j_next_async_flush
),
425 SFPJ( in_journal_bitmap
),
426 SFPJ( in_journal_reusable
),
427 SFPJ( lock_journal
),
428 SFPJ( lock_journal_wait
),
429 SFPJ( journal_being
),
430 SFPJ( journal_relock_writers
),
431 SFPJ( journal_relock_wcount
),
433 SFPJ( mark_dirty_already
),
434 SFPJ( mark_dirty_notjournal
),
435 SFPJ( restore_prepared
),
437 SFPJ( prepare_retry
)
443 static int test_sb(struct super_block
*sb
, void *data
)
448 static int set_sb(struct super_block
*sb
, void *data
)
453 static void *r_start(struct seq_file
*m
, loff_t
*pos
)
455 struct proc_dir_entry
*de
= m
->private;
456 struct super_block
*s
= de
->parent
->data
;
462 if (IS_ERR(sget(&reiserfs_fs_type
, test_sb
, set_sb
, s
)))
465 up_write(&s
->s_umount
);
475 static void *r_next(struct seq_file
*m
, void *v
, loff_t
*pos
)
483 static void r_stop(struct seq_file
*m
, void *v
)
489 static int r_show(struct seq_file
*m
, void *v
)
491 struct proc_dir_entry
*de
= m
->private;
492 int (*show
)(struct seq_file
*, struct super_block
*) = de
->data
;
496 static struct seq_operations r_ops
= {
503 static int r_open(struct inode
*inode
, struct file
*file
)
505 int ret
= seq_open(file
, &r_ops
);
508 struct seq_file
*m
= file
->private_data
;
509 m
->private = PDE(inode
);
514 static struct file_operations r_file_operations
= {
518 .release
= seq_release
,
521 static struct proc_dir_entry
*proc_info_root
= NULL
;
522 static const char proc_info_root_name
[] = "fs/reiserfs";
524 static void add_file(struct super_block
*sb
, char *name
,
525 int (*func
)(struct seq_file
*, struct super_block
*))
527 struct proc_dir_entry
*de
;
528 de
= create_proc_entry(name
, 0, REISERFS_SB(sb
)->procdir
);
531 de
->proc_fops
= &r_file_operations
;
535 int reiserfs_proc_info_init( struct super_block
*sb
)
537 spin_lock_init( & __PINFO( sb
).lock
);
538 REISERFS_SB(sb
)->procdir
= proc_mkdir(reiserfs_bdevname (sb
), proc_info_root
);
539 if( REISERFS_SB(sb
)->procdir
) {
540 REISERFS_SB(sb
)->procdir
->owner
= THIS_MODULE
;
541 REISERFS_SB(sb
)->procdir
->data
= sb
;
542 add_file(sb
, "version", show_version
);
543 add_file(sb
, "super", show_super
);
544 add_file(sb
, "per-level", show_per_level
);
545 add_file(sb
, "bitmap", show_bitmap
);
546 add_file(sb
, "on-disk-super", show_on_disk_super
);
547 add_file(sb
, "oidmap", show_oidmap
);
548 add_file(sb
, "journal", show_journal
);
551 reiserfs_warning(sb
, "reiserfs: cannot create /proc/%s/%s",
552 proc_info_root_name
, reiserfs_bdevname (sb
) );
556 int reiserfs_proc_info_done( struct super_block
*sb
)
558 struct proc_dir_entry
*de
= REISERFS_SB(sb
)->procdir
;
560 remove_proc_entry("journal", de
);
561 remove_proc_entry("oidmap", de
);
562 remove_proc_entry("on-disk-super", de
);
563 remove_proc_entry("bitmap", de
);
564 remove_proc_entry("per-level", de
);
565 remove_proc_entry("super", de
);
566 remove_proc_entry("version", de
);
568 spin_lock( & __PINFO( sb
).lock
);
569 __PINFO( sb
).exiting
= 1;
570 spin_unlock( & __PINFO( sb
).lock
);
571 if ( proc_info_root
) {
572 remove_proc_entry( reiserfs_bdevname (sb
), proc_info_root
);
573 REISERFS_SB(sb
)->procdir
= NULL
;
578 struct proc_dir_entry
*reiserfs_proc_register_global( char *name
,
581 return ( proc_info_root
) ? create_proc_read_entry( name
, 0,
586 void reiserfs_proc_unregister_global( const char *name
)
588 remove_proc_entry( name
, proc_info_root
);
591 int reiserfs_proc_info_global_init( void )
593 if( proc_info_root
== NULL
) {
594 proc_info_root
= proc_mkdir(proc_info_root_name
, NULL
);
595 if( proc_info_root
) {
596 proc_info_root
-> owner
= THIS_MODULE
;
598 reiserfs_warning (NULL
,
599 "reiserfs: cannot create /proc/%s",
600 proc_info_root_name
);
607 int reiserfs_proc_info_global_done( void )
609 if ( proc_info_root
!= NULL
) {
610 proc_info_root
= NULL
;
611 remove_proc_entry(proc_info_root_name
, NULL
);
616 /* REISERFS_PROC_INFO */
619 int reiserfs_proc_info_init( struct super_block
*sb
) { return 0; }
620 int reiserfs_proc_info_done( struct super_block
*sb
) { return 0; }
622 struct proc_dir_entry
*reiserfs_proc_register_global( char *name
,
626 void reiserfs_proc_unregister_global( const char *name
) {;}
628 int reiserfs_proc_info_global_init( void ) { return 0; }
629 int reiserfs_proc_info_global_done( void ) { return 0; }
631 int reiserfs_global_version_in_proc( char *buffer
, char **start
,
633 int count
, int *eof
, void *data
)
636 /* REISERFS_PROC_INFO */
641 * Revision 1.1.8.2 2001/07/15 17:08:42 god
642 * . use get_super() in procfs.c
643 * . remove remove_save_link() from reiserfs_do_truncate()
645 * I accept terms and conditions stated in the Legal Agreement
646 * (available at http://www.namesys.com/legalese.html)
648 * Revision 1.1.8.1 2001/07/11 16:48:50 god
651 * I accept terms and conditions stated in the Legal Agreement
652 * (available at http://www.namesys.com/legalese.html)
659 * c-indentation-style: "K&R"