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/module.h>
14 #include <linux/time.h>
15 #include <linux/seq_file.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 int show_version(struct seq_file
*m
, struct super_block
*sb
)
36 if (REISERFS_SB(sb
)->s_properties
& (1 << REISERFS_3_6
)) {
38 } else if (REISERFS_SB(sb
)->s_properties
& (1 << REISERFS_3_5
)) {
44 seq_printf(m
, "%s format\twith checks %s\n", format
,
45 #if defined( CONFIG_REISERFS_CHECK )
54 int reiserfs_global_version_in_proc(char *buffer
, char **start
, off_t offset
,
55 int count
, int *eof
, void *data
)
62 #define SF( x ) ( r -> x )
63 #define SFP( x ) SF( s_proc_info_data.x )
64 #define SFPL( x ) SFP( x[ level ] )
65 #define SFPF( x ) SFP( scan_bitmap.x )
66 #define SFPJ( x ) SFP( journal.x )
68 #define D2C( x ) le16_to_cpu( x )
69 #define D4C( x ) le32_to_cpu( x )
70 #define DF( x ) D2C( rs -> s_v1.x )
71 #define DFL( x ) D4C( rs -> s_v1.x )
73 #define objectid_map( s, rs ) (old_format_only (s) ? \
74 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
76 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
78 #define DJF( x ) le32_to_cpu( rs -> x )
79 #define DJV( x ) le32_to_cpu( s_v1 -> x )
80 #define DJP( x ) le32_to_cpu( jp -> x )
81 #define JF( x ) ( r -> s_journal -> x )
83 static int show_super(struct seq_file
*m
, struct super_block
*sb
)
85 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
87 seq_printf(m
, "state: \t%s\n"
88 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
89 "gen. counter: \t%i\n"
90 "s_disk_reads: \t%i\n"
91 "s_disk_writes: \t%i\n"
93 "s_do_balance: \t%i\n"
94 "s_unneeded_left_neighbor: \t%i\n"
95 "s_good_search_by_key_reada: \t%i\n"
97 "s_bmaps_without_search: \t%i\n"
98 "s_direct2indirect: \t%i\n"
99 "s_indirect2direct: \t%i\n"
101 "max_hash_collisions: \t%i\n"
103 "bread_misses: \t%lu\n"
104 "search_by_key: \t%lu\n"
105 "search_by_key_fs_changed: \t%lu\n"
106 "search_by_key_restarted: \t%lu\n"
107 "insert_item_restarted: \t%lu\n"
108 "paste_into_item_restarted: \t%lu\n"
109 "cut_from_item_restarted: \t%lu\n"
110 "delete_solid_item_restarted: \t%lu\n"
111 "delete_item_restarted: \t%lu\n"
112 "leaked_oid: \t%lu\n"
113 "leaves_removable: \t%lu\n",
114 SF(s_mount_state
) == REISERFS_VALID_FS
?
115 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
116 reiserfs_r5_hash(sb
) ? "FORCE_R5 " : "",
117 reiserfs_rupasov_hash(sb
) ? "FORCE_RUPASOV " : "",
118 reiserfs_tea_hash(sb
) ? "FORCE_TEA " : "",
119 reiserfs_hash_detect(sb
) ? "DETECT_HASH " : "",
120 reiserfs_no_border(sb
) ? "NO_BORDER " : "BORDER ",
121 reiserfs_no_unhashed_relocation(sb
) ?
122 "NO_UNHASHED_RELOCATION " : "",
123 reiserfs_hashed_relocation(sb
) ? "UNHASHED_RELOCATION " : "",
124 reiserfs_test4(sb
) ? "TEST4 " : "",
125 have_large_tails(sb
) ? "TAILS " : have_small_tails(sb
) ?
126 "SMALL_TAILS " : "NO_TAILS ",
127 replay_only(sb
) ? "REPLAY_ONLY " : "",
128 convert_reiserfs(sb
) ? "CONV " : "",
129 atomic_read(&r
->s_generation_counter
),
130 SF(s_disk_reads
), SF(s_disk_writes
), SF(s_fix_nodes
),
131 SF(s_do_balance
), SF(s_unneeded_left_neighbor
),
132 SF(s_good_search_by_key_reada
), SF(s_bmaps
),
133 SF(s_bmaps_without_search
), SF(s_direct2indirect
),
134 SF(s_indirect2direct
), SFP(max_hash_collisions
), SFP(breads
),
135 SFP(bread_miss
), SFP(search_by_key
),
136 SFP(search_by_key_fs_changed
), SFP(search_by_key_restarted
),
137 SFP(insert_item_restarted
), SFP(paste_into_item_restarted
),
138 SFP(cut_from_item_restarted
),
139 SFP(delete_solid_item_restarted
), SFP(delete_item_restarted
),
140 SFP(leaked_oid
), SFP(leaves_removable
));
145 static int show_per_level(struct seq_file
*m
, struct super_block
*sb
)
147 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
150 seq_printf(m
, "level\t"
163 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
165 for (level
= 0; level
< MAX_HEIGHT
; ++level
) {
186 SFPL(sbk_fs_changed
),
190 SFPL(can_node_be_removed
),
196 SFPL(get_neighbors_restart
),
197 SFPL(need_l_neighbor
), SFPL(need_r_neighbor
)
203 static int show_bitmap(struct seq_file
*m
, struct super_block
*sb
)
205 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
207 seq_printf(m
, "free_block: %lu\n"
230 SFPF(in_journal_hint
), SFPF(in_journal_nohint
));
235 static int show_on_disk_super(struct seq_file
*m
, struct super_block
*sb
)
237 struct reiserfs_sb_info
*sb_info
= REISERFS_SB(sb
);
238 struct reiserfs_super_block
*rs
= sb_info
->s_rs
;
239 int hash_code
= DFL(s_hash_function_code
);
240 __u32 flags
= DJF(s_flags
);
242 seq_printf(m
, "block_count: \t%i\n"
243 "free_blocks: \t%i\n"
246 "oid_maxsize: \t%i\n"
247 "oid_cursize: \t%i\n"
248 "umount_state: \t%i\n"
252 "tree_height: \t%i\n"
256 "reserved_for_journal: \t%i\n",
266 hash_code
== TEA_HASH
? "tea" :
267 (hash_code
== YURA_HASH
) ? "rupasov" :
268 (hash_code
== R5_HASH
) ? "r5" :
269 (hash_code
== UNSET_HASH
) ? "unset" : "unknown",
272 DF(s_version
), flags
, (flags
& reiserfs_attrs_cleared
)
273 ? "attrs_cleared" : "", DF(s_reserved_for_journal
));
278 static int show_oidmap(struct seq_file
*m
, struct super_block
*sb
)
280 struct reiserfs_sb_info
*sb_info
= REISERFS_SB(sb
);
281 struct reiserfs_super_block
*rs
= sb_info
->s_rs
;
282 unsigned int mapsize
= le16_to_cpu(rs
->s_v1
.s_oid_cursize
);
283 unsigned long total_used
= 0;
286 for (i
= 0; i
< mapsize
; ++i
) {
289 right
= (i
== mapsize
- 1) ? MAX_KEY_OBJECTID
: MAP(i
+ 1);
290 seq_printf(m
, "%s: [ %x .. %x )\n",
291 (i
& 1) ? "free" : "used", MAP(i
), right
);
293 total_used
+= right
- MAP(i
);
296 #if defined( REISERFS_USE_OIDMAPF )
297 if (sb_info
->oidmap
.use_file
&& (sb_info
->oidmap
.mapf
!= NULL
)) {
298 loff_t size
= sb_info
->oidmap
.mapf
->f_dentry
->d_inode
->i_size
;
299 total_used
+= size
/ sizeof(reiserfs_oidinterval_d_t
);
302 seq_printf(m
, "total: \t%i [%i/%i] used: %lu [exact]\n",
304 mapsize
, le16_to_cpu(rs
->s_v1
.s_oid_maxsize
), total_used
);
308 static int show_journal(struct seq_file
*m
, struct super_block
*sb
)
310 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
311 struct reiserfs_super_block
*rs
= r
->s_rs
;
312 struct journal_params
*jp
= &rs
->s_v1
.s_journal
;
313 char b
[BDEVNAME_SIZE
];
315 seq_printf(m
, /* on-disk fields */
316 "jp_journal_1st_block: \t%i\n"
317 "jp_journal_dev: \t%s[%x]\n"
318 "jp_journal_size: \t%i\n"
319 "jp_journal_trans_max: \t%i\n"
320 "jp_journal_magic: \t%i\n"
321 "jp_journal_max_batch: \t%i\n"
322 "jp_journal_max_commit_age: \t%i\n"
323 "jp_journal_max_trans_age: \t%i\n"
325 "j_1st_reserved_block: \t%i\n"
327 "j_trans_id: \t%lu\n"
328 "j_mount_id: \t%lu\n"
331 "j_len_alloc: \t%lu\n"
334 "j_first_unflushed_offset: \t%lu\n"
335 "j_last_flush_trans_id: \t%lu\n"
336 "j_trans_start_time: \t%li\n"
337 "j_list_bitmap_index: \t%i\n"
338 "j_must_wait: \t%i\n"
339 "j_next_full_flush: \t%i\n"
340 "j_next_async_flush: \t%i\n"
341 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
342 /* reiserfs_proc_info_data_t.journal fields */
343 "in_journal: \t%12lu\n"
344 "in_journal_bitmap: \t%12lu\n"
345 "in_journal_reusable: \t%12lu\n"
346 "lock_journal: \t%12lu\n"
347 "lock_journal_wait: \t%12lu\n"
348 "journal_begin: \t%12lu\n"
349 "journal_relock_writers: \t%12lu\n"
350 "journal_relock_wcount: \t%12lu\n"
351 "mark_dirty: \t%12lu\n"
352 "mark_dirty_already: \t%12lu\n"
353 "mark_dirty_notjournal: \t%12lu\n"
354 "restore_prepared: \t%12lu\n"
356 "prepare_retry: \t%12lu\n",
357 DJP(jp_journal_1st_block
),
358 bdevname(SB_JOURNAL(sb
)->j_dev_bd
, b
),
360 DJP(jp_journal_size
),
361 DJP(jp_journal_trans_max
),
362 DJP(jp_journal_magic
),
363 DJP(jp_journal_max_batch
),
364 SB_JOURNAL(sb
)->j_max_commit_age
,
365 DJP(jp_journal_max_trans_age
),
366 JF(j_1st_reserved_block
),
373 atomic_read(&r
->s_journal
->j_wcount
),
375 JF(j_first_unflushed_offset
),
376 JF(j_last_flush_trans_id
),
377 JF(j_trans_start_time
),
378 JF(j_list_bitmap_index
),
380 JF(j_next_full_flush
),
381 JF(j_next_async_flush
),
385 SFPJ(in_journal_bitmap
),
386 SFPJ(in_journal_reusable
),
388 SFPJ(lock_journal_wait
),
390 SFPJ(journal_relock_writers
),
391 SFPJ(journal_relock_wcount
),
393 SFPJ(mark_dirty_already
),
394 SFPJ(mark_dirty_notjournal
),
395 SFPJ(restore_prepared
), SFPJ(prepare
), SFPJ(prepare_retry
)
401 static int test_sb(struct super_block
*sb
, void *data
)
406 static int set_sb(struct super_block
*sb
, void *data
)
411 static void *r_start(struct seq_file
*m
, loff_t
* pos
)
413 struct proc_dir_entry
*de
= m
->private;
414 struct super_block
*s
= de
->parent
->data
;
420 if (IS_ERR(sget(&reiserfs_fs_type
, test_sb
, set_sb
, s
)))
423 up_write(&s
->s_umount
);
433 static void *r_next(struct seq_file
*m
, void *v
, loff_t
* pos
)
441 static void r_stop(struct seq_file
*m
, void *v
)
447 static int r_show(struct seq_file
*m
, void *v
)
449 struct proc_dir_entry
*de
= m
->private;
450 int (*show
) (struct seq_file
*, struct super_block
*) = de
->data
;
454 static struct seq_operations r_ops
= {
461 static int r_open(struct inode
*inode
, struct file
*file
)
463 int ret
= seq_open(file
, &r_ops
);
466 struct seq_file
*m
= file
->private_data
;
467 m
->private = PDE(inode
);
472 static const struct file_operations r_file_operations
= {
476 .release
= seq_release
,
479 static struct proc_dir_entry
*proc_info_root
= NULL
;
480 static const char proc_info_root_name
[] = "fs/reiserfs";
482 static void add_file(struct super_block
*sb
, char *name
,
483 int (*func
) (struct seq_file
*, struct super_block
*))
485 struct proc_dir_entry
*de
;
486 de
= create_proc_entry(name
, 0, REISERFS_SB(sb
)->procdir
);
489 de
->proc_fops
= &r_file_operations
;
493 int reiserfs_proc_info_init(struct super_block
*sb
)
495 char b
[BDEVNAME_SIZE
];
498 /* Some block devices use /'s */
499 strlcpy(b
, reiserfs_bdevname(sb
), BDEVNAME_SIZE
);
504 spin_lock_init(&__PINFO(sb
).lock
);
505 REISERFS_SB(sb
)->procdir
= proc_mkdir(b
, proc_info_root
);
506 if (REISERFS_SB(sb
)->procdir
) {
507 REISERFS_SB(sb
)->procdir
->owner
= THIS_MODULE
;
508 REISERFS_SB(sb
)->procdir
->data
= sb
;
509 add_file(sb
, "version", show_version
);
510 add_file(sb
, "super", show_super
);
511 add_file(sb
, "per-level", show_per_level
);
512 add_file(sb
, "bitmap", show_bitmap
);
513 add_file(sb
, "on-disk-super", show_on_disk_super
);
514 add_file(sb
, "oidmap", show_oidmap
);
515 add_file(sb
, "journal", show_journal
);
518 reiserfs_warning(sb
, "reiserfs: cannot create /proc/%s/%s",
519 proc_info_root_name
, b
);
523 int reiserfs_proc_info_done(struct super_block
*sb
)
525 struct proc_dir_entry
*de
= REISERFS_SB(sb
)->procdir
;
526 char b
[BDEVNAME_SIZE
];
529 /* Some block devices use /'s */
530 strlcpy(b
, reiserfs_bdevname(sb
), BDEVNAME_SIZE
);
536 remove_proc_entry("journal", de
);
537 remove_proc_entry("oidmap", de
);
538 remove_proc_entry("on-disk-super", de
);
539 remove_proc_entry("bitmap", de
);
540 remove_proc_entry("per-level", de
);
541 remove_proc_entry("super", de
);
542 remove_proc_entry("version", de
);
544 spin_lock(&__PINFO(sb
).lock
);
545 __PINFO(sb
).exiting
= 1;
546 spin_unlock(&__PINFO(sb
).lock
);
547 if (proc_info_root
) {
548 remove_proc_entry(b
, proc_info_root
);
549 REISERFS_SB(sb
)->procdir
= NULL
;
554 struct proc_dir_entry
*reiserfs_proc_register_global(char *name
,
557 return (proc_info_root
) ? create_proc_read_entry(name
, 0,
562 void reiserfs_proc_unregister_global(const char *name
)
564 remove_proc_entry(name
, proc_info_root
);
567 int reiserfs_proc_info_global_init(void)
569 if (proc_info_root
== NULL
) {
570 proc_info_root
= proc_mkdir(proc_info_root_name
, NULL
);
571 if (proc_info_root
) {
572 proc_info_root
->owner
= THIS_MODULE
;
574 reiserfs_warning(NULL
,
575 "reiserfs: cannot create /proc/%s",
576 proc_info_root_name
);
583 int reiserfs_proc_info_global_done(void)
585 if (proc_info_root
!= NULL
) {
586 proc_info_root
= NULL
;
587 remove_proc_entry(proc_info_root_name
, NULL
);
592 /* REISERFS_PROC_INFO */
595 int reiserfs_proc_info_init(struct super_block
*sb
)
599 int reiserfs_proc_info_done(struct super_block
*sb
)
604 struct proc_dir_entry
*reiserfs_proc_register_global(char *name
,
610 void reiserfs_proc_unregister_global(const char *name
)
614 int reiserfs_proc_info_global_init(void)
618 int reiserfs_proc_info_global_done(void)
623 int reiserfs_global_version_in_proc(char *buffer
, char **start
,
625 int count
, int *eof
, void *data
)
630 /* REISERFS_PROC_INFO */
635 * Revision 1.1.8.2 2001/07/15 17:08:42 god
636 * . use get_super() in procfs.c
637 * . remove remove_save_link() from reiserfs_do_truncate()
639 * I accept terms and conditions stated in the Legal Agreement
640 * (available at http://www.namesys.com/legalese.html)
642 * Revision 1.1.8.1 2001/07/11 16:48:50 god
645 * I accept terms and conditions stated in the Legal Agreement
646 * (available at http://www.namesys.com/legalese.html)
653 * c-indentation-style: "K&R"