procfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /* -*- linux-c -*- */
  2. /* fs/reiserfs/procfs.c */
  3. /*
  4. * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  5. */
  6. /* proc info support a la one created by Sizif@Botik.RU for PGC */
  7. #include <linux/module.h>
  8. #include <linux/time.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/uaccess.h>
  11. #include "reiserfs.h"
  12. #include <linux/init.h>
  13. #include <linux/proc_fs.h>
  14. /*
  15. * LOCKING:
  16. *
  17. * These guys are evicted from procfs as the very first step in ->kill_sb().
  18. *
  19. */
  20. static int show_version(struct seq_file *m, void *unused)
  21. {
  22. struct super_block *sb = m->private;
  23. char *format;
  24. if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_6)) {
  25. format = "3.6";
  26. } else if (REISERFS_SB(sb)->s_properties & (1 << REISERFS_3_5)) {
  27. format = "3.5";
  28. } else {
  29. format = "unknown";
  30. }
  31. seq_printf(m, "%s format\twith checks %s\n", format,
  32. #if defined( CONFIG_REISERFS_CHECK )
  33. "on"
  34. #else
  35. "off"
  36. #endif
  37. );
  38. return 0;
  39. }
  40. #define SF( x ) ( r -> x )
  41. #define SFP( x ) SF( s_proc_info_data.x )
  42. #define SFPL( x ) SFP( x[ level ] )
  43. #define SFPF( x ) SFP( scan_bitmap.x )
  44. #define SFPJ( x ) SFP( journal.x )
  45. #define D2C( x ) le16_to_cpu( x )
  46. #define D4C( x ) le32_to_cpu( x )
  47. #define DF( x ) D2C( rs -> s_v1.x )
  48. #define DFL( x ) D4C( rs -> s_v1.x )
  49. #define objectid_map( s, rs ) (old_format_only (s) ? \
  50. (__le32 *)((struct reiserfs_super_block_v1 *)rs + 1) : \
  51. (__le32 *)(rs + 1))
  52. #define MAP( i ) D4C( objectid_map( sb, rs )[ i ] )
  53. #define DJF( x ) le32_to_cpu( rs -> x )
  54. #define DJV( x ) le32_to_cpu( s_v1 -> x )
  55. #define DJP( x ) le32_to_cpu( jp -> x )
  56. #define JF( x ) ( r -> s_journal -> x )
  57. static int show_super(struct seq_file *m, void *unused)
  58. {
  59. struct super_block *sb = m->private;
  60. struct reiserfs_sb_info *r = REISERFS_SB(sb);
  61. seq_printf(m, "state: \t%s\n"
  62. "mount options: \t%s%s%s%s%s%s%s%s%s%s%s\n"
  63. "gen. counter: \t%i\n"
  64. "s_disk_reads: \t%i\n"
  65. "s_disk_writes: \t%i\n"
  66. "s_fix_nodes: \t%i\n"
  67. "s_do_balance: \t%i\n"
  68. "s_unneeded_left_neighbor: \t%i\n"
  69. "s_good_search_by_key_reada: \t%i\n"
  70. "s_bmaps: \t%i\n"
  71. "s_bmaps_without_search: \t%i\n"
  72. "s_direct2indirect: \t%i\n"
  73. "s_indirect2direct: \t%i\n"
  74. "\n"
  75. "max_hash_collisions: \t%i\n"
  76. "breads: \t%lu\n"
  77. "bread_misses: \t%lu\n"
  78. "search_by_key: \t%lu\n"
  79. "search_by_key_fs_changed: \t%lu\n"
  80. "search_by_key_restarted: \t%lu\n"
  81. "insert_item_restarted: \t%lu\n"
  82. "paste_into_item_restarted: \t%lu\n"
  83. "cut_from_item_restarted: \t%lu\n"
  84. "delete_solid_item_restarted: \t%lu\n"
  85. "delete_item_restarted: \t%lu\n"
  86. "leaked_oid: \t%lu\n"
  87. "leaves_removable: \t%lu\n",
  88. SF(s_mount_state) == REISERFS_VALID_FS ?
  89. "REISERFS_VALID_FS" : "REISERFS_ERROR_FS",
  90. reiserfs_r5_hash(sb) ? "FORCE_R5 " : "",
  91. reiserfs_rupasov_hash(sb) ? "FORCE_RUPASOV " : "",
  92. reiserfs_tea_hash(sb) ? "FORCE_TEA " : "",
  93. reiserfs_hash_detect(sb) ? "DETECT_HASH " : "",
  94. reiserfs_no_border(sb) ? "NO_BORDER " : "BORDER ",
  95. reiserfs_no_unhashed_relocation(sb) ?
  96. "NO_UNHASHED_RELOCATION " : "",
  97. reiserfs_hashed_relocation(sb) ? "UNHASHED_RELOCATION " : "",
  98. reiserfs_test4(sb) ? "TEST4 " : "",
  99. have_large_tails(sb) ? "TAILS " : have_small_tails(sb) ?
  100. "SMALL_TAILS " : "NO_TAILS ",
  101. replay_only(sb) ? "REPLAY_ONLY " : "",
  102. convert_reiserfs(sb) ? "CONV " : "",
  103. atomic_read(&r->s_generation_counter),
  104. SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
  105. SF(s_do_balance), SF(s_unneeded_left_neighbor),
  106. SF(s_good_search_by_key_reada), SF(s_bmaps),
  107. SF(s_bmaps_without_search), SF(s_direct2indirect),
  108. SF(s_indirect2direct), SFP(max_hash_collisions), SFP(breads),
  109. SFP(bread_miss), SFP(search_by_key),
  110. SFP(search_by_key_fs_changed), SFP(search_by_key_restarted),
  111. SFP(insert_item_restarted), SFP(paste_into_item_restarted),
  112. SFP(cut_from_item_restarted),
  113. SFP(delete_solid_item_restarted), SFP(delete_item_restarted),
  114. SFP(leaked_oid), SFP(leaves_removable));
  115. return 0;
  116. }
  117. static int show_per_level(struct seq_file *m, void *unused)
  118. {
  119. struct super_block *sb = m->private;
  120. struct reiserfs_sb_info *r = REISERFS_SB(sb);
  121. int level;
  122. seq_printf(m, "level\t"
  123. " balances"
  124. " [sbk: reads"
  125. " fs_changed"
  126. " restarted]"
  127. " free space"
  128. " items"
  129. " can_remove"
  130. " lnum"
  131. " rnum"
  132. " lbytes"
  133. " rbytes"
  134. " get_neig"
  135. " get_neig_res" " need_l_neig" " need_r_neig" "\n");
  136. for (level = 0; level < MAX_HEIGHT; ++level) {
  137. seq_printf(m, "%i\t"
  138. " %12lu"
  139. " %12lu"
  140. " %12lu"
  141. " %12lu"
  142. " %12lu"
  143. " %12lu"
  144. " %12lu"
  145. " %12li"
  146. " %12li"
  147. " %12li"
  148. " %12li"
  149. " %12lu"
  150. " %12lu"
  151. " %12lu"
  152. " %12lu"
  153. "\n",
  154. level,
  155. SFPL(balance_at),
  156. SFPL(sbk_read_at),
  157. SFPL(sbk_fs_changed),
  158. SFPL(sbk_restarted),
  159. SFPL(free_at),
  160. SFPL(items_at),
  161. SFPL(can_node_be_removed),
  162. SFPL(lnum),
  163. SFPL(rnum),
  164. SFPL(lbytes),
  165. SFPL(rbytes),
  166. SFPL(get_neighbors),
  167. SFPL(get_neighbors_restart),
  168. SFPL(need_l_neighbor), SFPL(need_r_neighbor)
  169. );
  170. }
  171. return 0;
  172. }
  173. static int show_bitmap(struct seq_file *m, void *unused)
  174. {
  175. struct super_block *sb = m->private;
  176. struct reiserfs_sb_info *r = REISERFS_SB(sb);
  177. seq_printf(m, "free_block: %lu\n"
  178. " scan_bitmap:"
  179. " wait"
  180. " bmap"
  181. " retry"
  182. " stolen"
  183. " journal_hint"
  184. "journal_nohint"
  185. "\n"
  186. " %14lu"
  187. " %14lu"
  188. " %14lu"
  189. " %14lu"
  190. " %14lu"
  191. " %14lu"
  192. " %14lu"
  193. "\n",
  194. SFP(free_block),
  195. SFPF(call),
  196. SFPF(wait),
  197. SFPF(bmap),
  198. SFPF(retry),
  199. SFPF(stolen),
  200. SFPF(in_journal_hint), SFPF(in_journal_nohint));
  201. return 0;
  202. }
  203. static int show_on_disk_super(struct seq_file *m, void *unused)
  204. {
  205. struct super_block *sb = m->private;
  206. struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
  207. struct reiserfs_super_block *rs = sb_info->s_rs;
  208. int hash_code = DFL(s_hash_function_code);
  209. __u32 flags = DJF(s_flags);
  210. seq_printf(m, "block_count: \t%i\n"
  211. "free_blocks: \t%i\n"
  212. "root_block: \t%i\n"
  213. "blocksize: \t%i\n"
  214. "oid_maxsize: \t%i\n"
  215. "oid_cursize: \t%i\n"
  216. "umount_state: \t%i\n"
  217. "magic: \t%10.10s\n"
  218. "fs_state: \t%i\n"
  219. "hash: \t%s\n"
  220. "tree_height: \t%i\n"
  221. "bmap_nr: \t%i\n"
  222. "version: \t%i\n"
  223. "flags: \t%x[%s]\n"
  224. "reserved_for_journal: \t%i\n",
  225. DFL(s_block_count),
  226. DFL(s_free_blocks),
  227. DFL(s_root_block),
  228. DF(s_blocksize),
  229. DF(s_oid_maxsize),
  230. DF(s_oid_cursize),
  231. DF(s_umount_state),
  232. rs->s_v1.s_magic,
  233. DF(s_fs_state),
  234. hash_code == TEA_HASH ? "tea" :
  235. (hash_code == YURA_HASH) ? "rupasov" :
  236. (hash_code == R5_HASH) ? "r5" :
  237. (hash_code == UNSET_HASH) ? "unset" : "unknown",
  238. DF(s_tree_height),
  239. DF(s_bmap_nr),
  240. DF(s_version), flags, (flags & reiserfs_attrs_cleared)
  241. ? "attrs_cleared" : "", DF(s_reserved_for_journal));
  242. return 0;
  243. }
  244. static int show_oidmap(struct seq_file *m, void *unused)
  245. {
  246. struct super_block *sb = m->private;
  247. struct reiserfs_sb_info *sb_info = REISERFS_SB(sb);
  248. struct reiserfs_super_block *rs = sb_info->s_rs;
  249. unsigned int mapsize = le16_to_cpu(rs->s_v1.s_oid_cursize);
  250. unsigned long total_used = 0;
  251. int i;
  252. for (i = 0; i < mapsize; ++i) {
  253. __u32 right;
  254. right = (i == mapsize - 1) ? MAX_KEY_OBJECTID : MAP(i + 1);
  255. seq_printf(m, "%s: [ %x .. %x )\n",
  256. (i & 1) ? "free" : "used", MAP(i), right);
  257. if (!(i & 1)) {
  258. total_used += right - MAP(i);
  259. }
  260. }
  261. #if defined( REISERFS_USE_OIDMAPF )
  262. if (sb_info->oidmap.use_file && (sb_info->oidmap.mapf != NULL)) {
  263. loff_t size = file_inode(sb_info->oidmap.mapf)->i_size;
  264. total_used += size / sizeof(reiserfs_oidinterval_d_t);
  265. }
  266. #endif
  267. seq_printf(m, "total: \t%i [%i/%i] used: %lu [exact]\n",
  268. mapsize,
  269. mapsize, le16_to_cpu(rs->s_v1.s_oid_maxsize), total_used);
  270. return 0;
  271. }
  272. static int show_journal(struct seq_file *m, void *unused)
  273. {
  274. struct super_block *sb = m->private;
  275. struct reiserfs_sb_info *r = REISERFS_SB(sb);
  276. struct reiserfs_super_block *rs = r->s_rs;
  277. struct journal_params *jp = &rs->s_v1.s_journal;
  278. char b[BDEVNAME_SIZE];
  279. seq_printf(m, /* on-disk fields */
  280. "jp_journal_1st_block: \t%i\n"
  281. "jp_journal_dev: \t%s[%x]\n"
  282. "jp_journal_size: \t%i\n"
  283. "jp_journal_trans_max: \t%i\n"
  284. "jp_journal_magic: \t%i\n"
  285. "jp_journal_max_batch: \t%i\n"
  286. "jp_journal_max_commit_age: \t%i\n"
  287. "jp_journal_max_trans_age: \t%i\n"
  288. /* incore fields */
  289. "j_1st_reserved_block: \t%i\n"
  290. "j_state: \t%li\n"
  291. "j_trans_id: \t%u\n"
  292. "j_mount_id: \t%lu\n"
  293. "j_start: \t%lu\n"
  294. "j_len: \t%lu\n"
  295. "j_len_alloc: \t%lu\n"
  296. "j_wcount: \t%i\n"
  297. "j_bcount: \t%lu\n"
  298. "j_first_unflushed_offset: \t%lu\n"
  299. "j_last_flush_trans_id: \t%u\n"
  300. "j_trans_start_time: \t%li\n"
  301. "j_list_bitmap_index: \t%i\n"
  302. "j_must_wait: \t%i\n"
  303. "j_next_full_flush: \t%i\n"
  304. "j_next_async_flush: \t%i\n"
  305. "j_cnode_used: \t%i\n" "j_cnode_free: \t%i\n" "\n"
  306. /* reiserfs_proc_info_data_t.journal fields */
  307. "in_journal: \t%12lu\n"
  308. "in_journal_bitmap: \t%12lu\n"
  309. "in_journal_reusable: \t%12lu\n"
  310. "lock_journal: \t%12lu\n"
  311. "lock_journal_wait: \t%12lu\n"
  312. "journal_begin: \t%12lu\n"
  313. "journal_relock_writers: \t%12lu\n"
  314. "journal_relock_wcount: \t%12lu\n"
  315. "mark_dirty: \t%12lu\n"
  316. "mark_dirty_already: \t%12lu\n"
  317. "mark_dirty_notjournal: \t%12lu\n"
  318. "restore_prepared: \t%12lu\n"
  319. "prepare: \t%12lu\n"
  320. "prepare_retry: \t%12lu\n",
  321. DJP(jp_journal_1st_block),
  322. bdevname(SB_JOURNAL(sb)->j_dev_bd, b),
  323. DJP(jp_journal_dev),
  324. DJP(jp_journal_size),
  325. DJP(jp_journal_trans_max),
  326. DJP(jp_journal_magic),
  327. DJP(jp_journal_max_batch),
  328. SB_JOURNAL(sb)->j_max_commit_age,
  329. DJP(jp_journal_max_trans_age),
  330. JF(j_1st_reserved_block),
  331. JF(j_state),
  332. JF(j_trans_id),
  333. JF(j_mount_id),
  334. JF(j_start),
  335. JF(j_len),
  336. JF(j_len_alloc),
  337. atomic_read(&r->s_journal->j_wcount),
  338. JF(j_bcount),
  339. JF(j_first_unflushed_offset),
  340. JF(j_last_flush_trans_id),
  341. JF(j_trans_start_time),
  342. JF(j_list_bitmap_index),
  343. JF(j_must_wait),
  344. JF(j_next_full_flush),
  345. JF(j_next_async_flush),
  346. JF(j_cnode_used),
  347. JF(j_cnode_free),
  348. SFPJ(in_journal),
  349. SFPJ(in_journal_bitmap),
  350. SFPJ(in_journal_reusable),
  351. SFPJ(lock_journal),
  352. SFPJ(lock_journal_wait),
  353. SFPJ(journal_being),
  354. SFPJ(journal_relock_writers),
  355. SFPJ(journal_relock_wcount),
  356. SFPJ(mark_dirty),
  357. SFPJ(mark_dirty_already),
  358. SFPJ(mark_dirty_notjournal),
  359. SFPJ(restore_prepared), SFPJ(prepare), SFPJ(prepare_retry)
  360. );
  361. return 0;
  362. }
  363. static int r_open(struct inode *inode, struct file *file)
  364. {
  365. return single_open(file, PDE_DATA(inode),
  366. proc_get_parent_data(inode));
  367. }
  368. static const struct file_operations r_file_operations = {
  369. .open = r_open,
  370. .read = seq_read,
  371. .llseek = seq_lseek,
  372. .release = single_release,
  373. };
  374. static struct proc_dir_entry *proc_info_root = NULL;
  375. static const char proc_info_root_name[] = "fs/reiserfs";
  376. static void add_file(struct super_block *sb, char *name,
  377. int (*func) (struct seq_file *, void *))
  378. {
  379. proc_create_data(name, 0, REISERFS_SB(sb)->procdir,
  380. &r_file_operations, func);
  381. }
  382. int reiserfs_proc_info_init(struct super_block *sb)
  383. {
  384. char b[BDEVNAME_SIZE];
  385. char *s;
  386. /* Some block devices use /'s */
  387. strlcpy(b, sb->s_id, BDEVNAME_SIZE);
  388. s = strchr(b, '/');
  389. if (s)
  390. *s = '!';
  391. spin_lock_init(&__PINFO(sb).lock);
  392. REISERFS_SB(sb)->procdir = proc_mkdir_data(b, 0, proc_info_root, sb);
  393. if (REISERFS_SB(sb)->procdir) {
  394. add_file(sb, "version", show_version);
  395. add_file(sb, "super", show_super);
  396. add_file(sb, "per-level", show_per_level);
  397. add_file(sb, "bitmap", show_bitmap);
  398. add_file(sb, "on-disk-super", show_on_disk_super);
  399. add_file(sb, "oidmap", show_oidmap);
  400. add_file(sb, "journal", show_journal);
  401. return 0;
  402. }
  403. reiserfs_warning(sb, "cannot create /proc/%s/%s",
  404. proc_info_root_name, b);
  405. return 1;
  406. }
  407. int reiserfs_proc_info_done(struct super_block *sb)
  408. {
  409. struct proc_dir_entry *de = REISERFS_SB(sb)->procdir;
  410. if (de) {
  411. char b[BDEVNAME_SIZE];
  412. char *s;
  413. /* Some block devices use /'s */
  414. strlcpy(b, sb->s_id, BDEVNAME_SIZE);
  415. s = strchr(b, '/');
  416. if (s)
  417. *s = '!';
  418. remove_proc_subtree(b, proc_info_root);
  419. REISERFS_SB(sb)->procdir = NULL;
  420. }
  421. return 0;
  422. }
  423. int reiserfs_proc_info_global_init(void)
  424. {
  425. if (proc_info_root == NULL) {
  426. proc_info_root = proc_mkdir(proc_info_root_name, NULL);
  427. if (!proc_info_root) {
  428. reiserfs_warning(NULL, "cannot create /proc/%s",
  429. proc_info_root_name);
  430. return 1;
  431. }
  432. }
  433. return 0;
  434. }
  435. int reiserfs_proc_info_global_done(void)
  436. {
  437. if (proc_info_root != NULL) {
  438. proc_info_root = NULL;
  439. remove_proc_entry(proc_info_root_name, NULL);
  440. }
  441. return 0;
  442. }
  443. /*
  444. * Revision 1.1.8.2 2001/07/15 17:08:42 god
  445. * . use get_super() in procfs.c
  446. * . remove remove_save_link() from reiserfs_do_truncate()
  447. *
  448. * I accept terms and conditions stated in the Legal Agreement
  449. * (available at http://www.namesys.com/legalese.html)
  450. *
  451. * Revision 1.1.8.1 2001/07/11 16:48:50 god
  452. * proc info support
  453. *
  454. * I accept terms and conditions stated in the Legal Agreement
  455. * (available at http://www.namesys.com/legalese.html)
  456. *
  457. */
  458. /*
  459. * Make Linus happy.
  460. * Local variables:
  461. * c-indentation-style: "K&R"
  462. * mode-name: "LC"
  463. * c-basic-offset: 8
  464. * tab-width: 8
  465. * End:
  466. */