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 #include <linux/module.h>
12 #include <linux/time.h>
13 #include <linux/seq_file.h>
14 #include <linux/uaccess.h>
16 #include <linux/init.h>
17 #include <linux/proc_fs.h>
22 * These guys are evicted from procfs as the very first step in ->kill_sb().
26 static int show_version(struct seq_file
*m
, void *unused
)
28 struct super_block
*sb
= m
->private;
31 if (REISERFS_SB(sb
)->s_properties
& (1 << REISERFS_3_6
)) {
33 } else if (REISERFS_SB(sb
)->s_properties
& (1 << REISERFS_3_5
)) {
39 seq_printf(m
, "%s format\twith checks %s\n", format
,
40 #if defined( CONFIG_REISERFS_CHECK )
49 #define SF( x ) ( r -> x )
50 #define SFP( x ) SF( s_proc_info_data.x )
51 #define SFPL( x ) SFP( x[ level ] )
52 #define SFPF( x ) SFP( scan_bitmap.x )
53 #define SFPJ( x ) SFP( journal.x )
55 #define D2C( x ) le16_to_cpu( x )
56 #define D4C( x ) le32_to_cpu( x )
57 #define DF( x ) D2C( rs -> s_v1.x )
58 #define DFL( x ) D4C( rs -> s_v1.x )
60 #define objectid_map( s, rs ) (old_format_only (s) ? \
61 (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
63 #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
65 #define DJF( x ) le32_to_cpu( rs -> x )
66 #define DJV( x ) le32_to_cpu( s_v1 -> x )
67 #define DJP( x ) le32_to_cpu( jp -> x )
68 #define JF( x ) ( r -> s_journal -> x )
70 static int show_super(struct seq_file
*m
, void *unused
)
72 struct super_block
*sb
= m
->private;
73 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
75 seq_printf(m
, "state: \t%s\n"
76 "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
77 "gen. counter: \t%i\n"
78 "s_disk_reads: \t%i\n"
79 "s_disk_writes: \t%i\n"
81 "s_do_balance: \t%i\n"
82 "s_unneeded_left_neighbor: \t%i\n"
83 "s_good_search_by_key_reada: \t%i\n"
85 "s_bmaps_without_search: \t%i\n"
86 "s_direct2indirect: \t%i\n"
87 "s_indirect2direct: \t%i\n"
89 "max_hash_collisions: \t%i\n"
91 "bread_misses: \t%lu\n"
92 "search_by_key: \t%lu\n"
93 "search_by_key_fs_changed: \t%lu\n"
94 "search_by_key_restarted: \t%lu\n"
95 "insert_item_restarted: \t%lu\n"
96 "paste_into_item_restarted: \t%lu\n"
97 "cut_from_item_restarted: \t%lu\n"
98 "delete_solid_item_restarted: \t%lu\n"
99 "delete_item_restarted: \t%lu\n"
100 "leaked_oid: \t%lu\n"
101 "leaves_removable: \t%lu\n",
102 SF(s_mount_state
) == REISERFS_VALID_FS
?
103 "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
104 reiserfs_r5_hash(sb
) ? "FORCE_R5 " : "",
105 reiserfs_rupasov_hash(sb
) ? "FORCE_RUPASOV " : "",
106 reiserfs_tea_hash(sb
) ? "FORCE_TEA " : "",
107 reiserfs_hash_detect(sb
) ? "DETECT_HASH " : "",
108 reiserfs_no_border(sb
) ? "NO_BORDER " : "BORDER ",
109 reiserfs_no_unhashed_relocation(sb
) ?
110 "NO_UNHASHED_RELOCATION " : "",
111 reiserfs_hashed_relocation(sb
) ? "UNHASHED_RELOCATION " : "",
112 reiserfs_test4(sb
) ? "TEST4 " : "",
113 have_large_tails(sb
) ? "TAILS " : have_small_tails(sb
) ?
114 "SMALL_TAILS " : "NO_TAILS ",
115 replay_only(sb
) ? "REPLAY_ONLY " : "",
116 convert_reiserfs(sb
) ? "CONV " : "",
117 atomic_read(&r
->s_generation_counter
),
118 SF(s_disk_reads
), SF(s_disk_writes
), SF(s_fix_nodes
),
119 SF(s_do_balance
), SF(s_unneeded_left_neighbor
),
120 SF(s_good_search_by_key_reada
), SF(s_bmaps
),
121 SF(s_bmaps_without_search
), SF(s_direct2indirect
),
122 SF(s_indirect2direct
), SFP(max_hash_collisions
), SFP(breads
),
123 SFP(bread_miss
), SFP(search_by_key
),
124 SFP(search_by_key_fs_changed
), SFP(search_by_key_restarted
),
125 SFP(insert_item_restarted
), SFP(paste_into_item_restarted
),
126 SFP(cut_from_item_restarted
),
127 SFP(delete_solid_item_restarted
), SFP(delete_item_restarted
),
128 SFP(leaked_oid
), SFP(leaves_removable
));
133 static int show_per_level(struct seq_file
*m
, void *unused
)
135 struct super_block
*sb
= m
->private;
136 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
139 seq_printf(m
, "level\t"
152 " get_neig_res" " need_l_neig" " need_r_neig" "\n");
154 for (level
= 0; level
< MAX_HEIGHT
; ++level
) {
175 SFPL(sbk_fs_changed
),
179 SFPL(can_node_be_removed
),
185 SFPL(get_neighbors_restart
),
186 SFPL(need_l_neighbor
), SFPL(need_r_neighbor
)
192 static int show_bitmap(struct seq_file
*m
, void *unused
)
194 struct super_block
*sb
= m
->private;
195 struct reiserfs_sb_info
*r
= REISERFS_SB(sb
);
197 seq_printf(m
, "free_block: %lu\n"
220 SFPF(in_journal_hint
), SFPF(in_journal_nohint
));
225 static int show_on_disk_super(struct seq_file
*m
, void *unused
)
227 struct super_block
*sb
= m
->private;
228 struct reiserfs_sb_info
*sb_info
= REISERFS_SB(sb
);
229 struct reiserfs_super_block
*rs
= sb_info
->s_rs
;
230 int hash_code
= DFL(s_hash_function_code
);
231 __u32 flags
= DJF(s_flags
);
233 seq_printf(m
, "block_count: \t%i\n"
234 "free_blocks: \t%i\n"
237 "oid_maxsize: \t%i\n"
238 "oid_cursize: \t%i\n"
239 "umount_state: \t%i\n"
243 "tree_height: \t%i\n"
247 "reserved_for_journal: \t%i\n",
257 hash_code
== TEA_HASH
? "tea" :
258 (hash_code
== YURA_HASH
) ? "rupasov" :
259 (hash_code
== R5_HASH
) ? "r5" :
260 (hash_code
== UNSET_HASH
) ? "unset" : "unknown",
263 DF(s_version
), flags
, (flags
& reiserfs_attrs_cleared
)
264 ? "attrs_cleared" : "", DF(s_reserved_for_journal
));
269 static int show_oidmap(struct seq_file
*m
, void *unused
)
271 struct super_block
*sb
= m
->private;
272 struct reiserfs_sb_info
*sb_info
= REISERFS_SB(sb
);
273 struct reiserfs_super_block
*rs
= sb_info
->s_rs
;
274 unsigned int mapsize
= le16_to_cpu(rs
->s_v1
.s_oid_cursize
);
275 unsigned long total_used
= 0;
278 for (i
= 0; i
< mapsize
; ++i
) {
281 right
= (i
== mapsize
- 1) ? MAX_KEY_OBJECTID
: MAP(i
+ 1);
282 seq_printf(m
, "%s: [ %x .. %x )\n",
283 (i
& 1) ? "free" : "used", MAP(i
), right
);
285 total_used
+= right
- MAP(i
);
288 #if defined( REISERFS_USE_OIDMAPF )
289 if (sb_info
->oidmap
.use_file
&& (sb_info
->oidmap
.mapf
!= NULL
)) {
290 loff_t size
= file_inode(sb_info
->oidmap
.mapf
)->i_size
;
291 total_used
+= size
/ sizeof(reiserfs_oidinterval_d_t
);
294 seq_printf(m
, "total: \t%i [%i/%i] used: %lu [exact]\n",
296 mapsize
, le16_to_cpu(rs
->s_v1
.s_oid_maxsize
), total_used
);
300 static time64_t
ktime_mono_to_real_seconds(time64_t mono
)
302 ktime_t kt
= ktime_set(mono
, NSEC_PER_SEC
/2);
304 return ktime_divns(ktime_mono_to_real(kt
), NSEC_PER_SEC
);
307 static int show_journal(struct seq_file
*m
, void *unused
)
309 struct super_block
*sb
= m
->private;
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
;
314 seq_printf(m
, /* on-disk fields */
315 "jp_journal_1st_block: \t%i\n"
316 "jp_journal_dev: \t%pg[%x]\n"
317 "jp_journal_size: \t%i\n"
318 "jp_journal_trans_max: \t%i\n"
319 "jp_journal_magic: \t%i\n"
320 "jp_journal_max_batch: \t%i\n"
321 "jp_journal_max_commit_age: \t%i\n"
322 "jp_journal_max_trans_age: \t%i\n"
324 "j_1st_reserved_block: \t%i\n"
327 "j_mount_id: \t%lu\n"
330 "j_len_alloc: \t%lu\n"
333 "j_first_unflushed_offset: \t%lu\n"
334 "j_last_flush_trans_id: \t%u\n"
335 "j_trans_start_time: \t%lli\n"
336 "j_list_bitmap_index: \t%i\n"
337 "j_must_wait: \t%i\n"
338 "j_next_full_flush: \t%i\n"
339 "j_next_async_flush: \t%i\n"
340 "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
341 /* reiserfs_proc_info_data_t.journal fields */
342 "in_journal: \t%12lu\n"
343 "in_journal_bitmap: \t%12lu\n"
344 "in_journal_reusable: \t%12lu\n"
345 "lock_journal: \t%12lu\n"
346 "lock_journal_wait: \t%12lu\n"
347 "journal_begin: \t%12lu\n"
348 "journal_relock_writers: \t%12lu\n"
349 "journal_relock_wcount: \t%12lu\n"
350 "mark_dirty: \t%12lu\n"
351 "mark_dirty_already: \t%12lu\n"
352 "mark_dirty_notjournal: \t%12lu\n"
353 "restore_prepared: \t%12lu\n"
355 "prepare_retry: \t%12lu\n",
356 DJP(jp_journal_1st_block
),
357 SB_JOURNAL(sb
)->j_dev_bd
,
359 DJP(jp_journal_size
),
360 DJP(jp_journal_trans_max
),
361 DJP(jp_journal_magic
),
362 DJP(jp_journal_max_batch
),
363 SB_JOURNAL(sb
)->j_max_commit_age
,
364 DJP(jp_journal_max_trans_age
),
365 JF(j_1st_reserved_block
),
372 atomic_read(&r
->s_journal
->j_wcount
),
374 JF(j_first_unflushed_offset
),
375 JF(j_last_flush_trans_id
),
376 ktime_mono_to_real_seconds(JF(j_trans_start_time
)),
377 JF(j_list_bitmap_index
),
379 JF(j_next_full_flush
),
380 JF(j_next_async_flush
),
384 SFPJ(in_journal_bitmap
),
385 SFPJ(in_journal_reusable
),
387 SFPJ(lock_journal_wait
),
389 SFPJ(journal_relock_writers
),
390 SFPJ(journal_relock_wcount
),
392 SFPJ(mark_dirty_already
),
393 SFPJ(mark_dirty_notjournal
),
394 SFPJ(restore_prepared
), SFPJ(prepare
), SFPJ(prepare_retry
)
399 static struct proc_dir_entry
*proc_info_root
= NULL
;
400 static const char proc_info_root_name
[] = "fs/reiserfs";
402 static void add_file(struct super_block
*sb
, char *name
,
403 int (*func
) (struct seq_file
*, void *))
405 proc_create_single_data(name
, 0, REISERFS_SB(sb
)->procdir
, func
, sb
);
408 int reiserfs_proc_info_init(struct super_block
*sb
)
410 char b
[BDEVNAME_SIZE
];
413 /* Some block devices use /'s */
414 strlcpy(b
, sb
->s_id
, BDEVNAME_SIZE
);
419 spin_lock_init(&__PINFO(sb
).lock
);
420 REISERFS_SB(sb
)->procdir
= proc_mkdir_data(b
, 0, proc_info_root
, sb
);
421 if (REISERFS_SB(sb
)->procdir
) {
422 add_file(sb
, "version", show_version
);
423 add_file(sb
, "super", show_super
);
424 add_file(sb
, "per-level", show_per_level
);
425 add_file(sb
, "bitmap", show_bitmap
);
426 add_file(sb
, "on-disk-super", show_on_disk_super
);
427 add_file(sb
, "oidmap", show_oidmap
);
428 add_file(sb
, "journal", show_journal
);
431 reiserfs_warning(sb
, "cannot create /proc/%s/%s",
432 proc_info_root_name
, b
);
436 int reiserfs_proc_info_done(struct super_block
*sb
)
438 struct proc_dir_entry
*de
= REISERFS_SB(sb
)->procdir
;
440 char b
[BDEVNAME_SIZE
];
443 /* Some block devices use /'s */
444 strlcpy(b
, sb
->s_id
, BDEVNAME_SIZE
);
449 remove_proc_subtree(b
, proc_info_root
);
450 REISERFS_SB(sb
)->procdir
= NULL
;
455 int reiserfs_proc_info_global_init(void)
457 if (proc_info_root
== NULL
) {
458 proc_info_root
= proc_mkdir(proc_info_root_name
, NULL
);
459 if (!proc_info_root
) {
460 reiserfs_warning(NULL
, "cannot create /proc/%s",
461 proc_info_root_name
);
468 int reiserfs_proc_info_global_done(void)
470 if (proc_info_root
!= NULL
) {
471 proc_info_root
= NULL
;
472 remove_proc_entry(proc_info_root_name
, NULL
);
477 * Revision 1.1.8.2 2001/07/15 17:08:42 god
478 * . use get_super() in procfs.c
479 * . remove remove_save_link() from reiserfs_do_truncate()
481 * I accept terms and conditions stated in the Legal Agreement
482 * (available at http://www.namesys.com/legalese.html)
484 * Revision 1.1.8.1 2001/07/11 16:48:50 god
487 * I accept terms and conditions stated in the Legal Agreement
488 * (available at http://www.namesys.com/legalese.html)
495 * c-indentation-style: "K&R"