procfs.c 15 KB

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