prints.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748
  1. /*
  2. * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  3. */
  4. #include <linux/time.h>
  5. #include <linux/fs.h>
  6. #include <linux/reiserfs_fs.h>
  7. #include <linux/string.h>
  8. #include <linux/buffer_head.h>
  9. #include <stdarg.h>
  10. static char error_buf[1024];
  11. static char fmt_buf[1024];
  12. static char off_buf[80];
  13. static char *reiserfs_cpu_offset(struct cpu_key *key)
  14. {
  15. if (cpu_key_k_type(key) == TYPE_DIRENTRY)
  16. sprintf(off_buf, "%Lu(%Lu)",
  17. (unsigned long long)
  18. GET_HASH_VALUE(cpu_key_k_offset(key)),
  19. (unsigned long long)
  20. GET_GENERATION_NUMBER(cpu_key_k_offset(key)));
  21. else
  22. sprintf(off_buf, "0x%Lx",
  23. (unsigned long long)cpu_key_k_offset(key));
  24. return off_buf;
  25. }
  26. static char *le_offset(struct reiserfs_key *key)
  27. {
  28. int version;
  29. version = le_key_version(key);
  30. if (le_key_k_type(version, key) == TYPE_DIRENTRY)
  31. sprintf(off_buf, "%Lu(%Lu)",
  32. (unsigned long long)
  33. GET_HASH_VALUE(le_key_k_offset(version, key)),
  34. (unsigned long long)
  35. GET_GENERATION_NUMBER(le_key_k_offset(version, key)));
  36. else
  37. sprintf(off_buf, "0x%Lx",
  38. (unsigned long long)le_key_k_offset(version, key));
  39. return off_buf;
  40. }
  41. static char *cpu_type(struct cpu_key *key)
  42. {
  43. if (cpu_key_k_type(key) == TYPE_STAT_DATA)
  44. return "SD";
  45. if (cpu_key_k_type(key) == TYPE_DIRENTRY)
  46. return "DIR";
  47. if (cpu_key_k_type(key) == TYPE_DIRECT)
  48. return "DIRECT";
  49. if (cpu_key_k_type(key) == TYPE_INDIRECT)
  50. return "IND";
  51. return "UNKNOWN";
  52. }
  53. static char *le_type(struct reiserfs_key *key)
  54. {
  55. int version;
  56. version = le_key_version(key);
  57. if (le_key_k_type(version, key) == TYPE_STAT_DATA)
  58. return "SD";
  59. if (le_key_k_type(version, key) == TYPE_DIRENTRY)
  60. return "DIR";
  61. if (le_key_k_type(version, key) == TYPE_DIRECT)
  62. return "DIRECT";
  63. if (le_key_k_type(version, key) == TYPE_INDIRECT)
  64. return "IND";
  65. return "UNKNOWN";
  66. }
  67. /* %k */
  68. static void sprintf_le_key(char *buf, struct reiserfs_key *key)
  69. {
  70. if (key)
  71. sprintf(buf, "[%d %d %s %s]", le32_to_cpu(key->k_dir_id),
  72. le32_to_cpu(key->k_objectid), le_offset(key),
  73. le_type(key));
  74. else
  75. sprintf(buf, "[NULL]");
  76. }
  77. /* %K */
  78. static void sprintf_cpu_key(char *buf, struct cpu_key *key)
  79. {
  80. if (key)
  81. sprintf(buf, "[%d %d %s %s]", key->on_disk_key.k_dir_id,
  82. key->on_disk_key.k_objectid, reiserfs_cpu_offset(key),
  83. cpu_type(key));
  84. else
  85. sprintf(buf, "[NULL]");
  86. }
  87. static void sprintf_de_head(char *buf, struct reiserfs_de_head *deh)
  88. {
  89. if (deh)
  90. sprintf(buf,
  91. "[offset=%d dir_id=%d objectid=%d location=%d state=%04x]",
  92. deh_offset(deh), deh_dir_id(deh), deh_objectid(deh),
  93. deh_location(deh), deh_state(deh));
  94. else
  95. sprintf(buf, "[NULL]");
  96. }
  97. static void sprintf_item_head(char *buf, struct item_head *ih)
  98. {
  99. if (ih) {
  100. strcpy(buf,
  101. (ih_version(ih) == KEY_FORMAT_3_6) ? "*3.6* " : "*3.5*");
  102. sprintf_le_key(buf + strlen(buf), &(ih->ih_key));
  103. sprintf(buf + strlen(buf), ", item_len %d, item_location %d, "
  104. "free_space(entry_count) %d",
  105. ih_item_len(ih), ih_location(ih), ih_free_space(ih));
  106. } else
  107. sprintf(buf, "[NULL]");
  108. }
  109. static void sprintf_direntry(char *buf, struct reiserfs_dir_entry *de)
  110. {
  111. char name[20];
  112. memcpy(name, de->de_name, de->de_namelen > 19 ? 19 : de->de_namelen);
  113. name[de->de_namelen > 19 ? 19 : de->de_namelen] = 0;
  114. sprintf(buf, "\"%s\"==>[%d %d]", name, de->de_dir_id, de->de_objectid);
  115. }
  116. static void sprintf_block_head(char *buf, struct buffer_head *bh)
  117. {
  118. sprintf(buf, "level=%d, nr_items=%d, free_space=%d rdkey ",
  119. B_LEVEL(bh), B_NR_ITEMS(bh), B_FREE_SPACE(bh));
  120. }
  121. static void sprintf_buffer_head(char *buf, struct buffer_head *bh)
  122. {
  123. char b[BDEVNAME_SIZE];
  124. sprintf(buf,
  125. "dev %s, size %zd, blocknr %llu, count %d, state 0x%lx, page %p, (%s, %s, %s)",
  126. bdevname(bh->b_bdev, b), bh->b_size,
  127. (unsigned long long)bh->b_blocknr, atomic_read(&(bh->b_count)),
  128. bh->b_state, bh->b_page,
  129. buffer_uptodate(bh) ? "UPTODATE" : "!UPTODATE",
  130. buffer_dirty(bh) ? "DIRTY" : "CLEAN",
  131. buffer_locked(bh) ? "LOCKED" : "UNLOCKED");
  132. }
  133. static void sprintf_disk_child(char *buf, struct disk_child *dc)
  134. {
  135. sprintf(buf, "[dc_number=%d, dc_size=%u]", dc_block_number(dc),
  136. dc_size(dc));
  137. }
  138. static char *is_there_reiserfs_struct(char *fmt, int *what, int *skip)
  139. {
  140. char *k = fmt;
  141. *skip = 0;
  142. while ((k = strchr(k, '%')) != NULL) {
  143. if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
  144. k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') {
  145. *what = k[1];
  146. break;
  147. }
  148. (*skip)++;
  149. k++;
  150. }
  151. return k;
  152. }
  153. /* debugging reiserfs we used to print out a lot of different
  154. variables, like keys, item headers, buffer heads etc. Values of
  155. most fields matter. So it took a long time just to write
  156. appropriative printk. With this reiserfs_warning you can use format
  157. specification for complex structures like you used to do with
  158. printfs for integers, doubles and pointers. For instance, to print
  159. out key structure you have to write just:
  160. reiserfs_warning ("bad key %k", key);
  161. instead of
  162. printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,
  163. key->k_offset, key->k_uniqueness);
  164. */
  165. static void prepare_error_buf(const char *fmt, va_list args)
  166. {
  167. char *fmt1 = fmt_buf;
  168. char *k;
  169. char *p = error_buf;
  170. int i, j, what, skip;
  171. strcpy(fmt1, fmt);
  172. while ((k = is_there_reiserfs_struct(fmt1, &what, &skip)) != NULL) {
  173. *k = 0;
  174. p += vsprintf(p, fmt1, args);
  175. for (i = 0; i < skip; i++)
  176. j = va_arg(args, int);
  177. switch (what) {
  178. case 'k':
  179. sprintf_le_key(p, va_arg(args, struct reiserfs_key *));
  180. break;
  181. case 'K':
  182. sprintf_cpu_key(p, va_arg(args, struct cpu_key *));
  183. break;
  184. case 'h':
  185. sprintf_item_head(p, va_arg(args, struct item_head *));
  186. break;
  187. case 't':
  188. sprintf_direntry(p,
  189. va_arg(args,
  190. struct reiserfs_dir_entry *));
  191. break;
  192. case 'y':
  193. sprintf_disk_child(p,
  194. va_arg(args, struct disk_child *));
  195. break;
  196. case 'z':
  197. sprintf_block_head(p,
  198. va_arg(args, struct buffer_head *));
  199. break;
  200. case 'b':
  201. sprintf_buffer_head(p,
  202. va_arg(args, struct buffer_head *));
  203. break;
  204. case 'a':
  205. sprintf_de_head(p,
  206. va_arg(args,
  207. struct reiserfs_de_head *));
  208. break;
  209. }
  210. p += strlen(p);
  211. fmt1 = k + 2;
  212. }
  213. vsprintf(p, fmt1, args);
  214. }
  215. /* in addition to usual conversion specifiers this accepts reiserfs
  216. specific conversion specifiers:
  217. %k to print little endian key,
  218. %K to print cpu key,
  219. %h to print item_head,
  220. %t to print directory entry
  221. %z to print block head (arg must be struct buffer_head *
  222. %b to print buffer_head
  223. */
  224. #define do_reiserfs_warning(fmt)\
  225. {\
  226. va_list args;\
  227. va_start( args, fmt );\
  228. prepare_error_buf( fmt, args );\
  229. va_end( args );\
  230. }
  231. void reiserfs_warning(struct super_block *sb, const char *fmt, ...)
  232. {
  233. do_reiserfs_warning(fmt);
  234. if (sb)
  235. printk(KERN_WARNING "ReiserFS: %s: warning: %s\n",
  236. reiserfs_bdevname(sb), error_buf);
  237. else
  238. printk(KERN_WARNING "ReiserFS: warning: %s\n", error_buf);
  239. }
  240. /* No newline.. reiserfs_info calls can be followed by printk's */
  241. void reiserfs_info(struct super_block *sb, const char *fmt, ...)
  242. {
  243. do_reiserfs_warning(fmt);
  244. if (sb)
  245. printk(KERN_NOTICE "ReiserFS: %s: %s",
  246. reiserfs_bdevname(sb), error_buf);
  247. else
  248. printk(KERN_NOTICE "ReiserFS: %s", error_buf);
  249. }
  250. /* No newline.. reiserfs_printk calls can be followed by printk's */
  251. static void reiserfs_printk(const char *fmt, ...)
  252. {
  253. do_reiserfs_warning(fmt);
  254. printk(error_buf);
  255. }
  256. void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
  257. {
  258. #ifdef CONFIG_REISERFS_CHECK
  259. do_reiserfs_warning(fmt);
  260. if (s)
  261. printk(KERN_DEBUG "ReiserFS: %s: %s\n",
  262. reiserfs_bdevname(s), error_buf);
  263. else
  264. printk(KERN_DEBUG "ReiserFS: %s\n", error_buf);
  265. #endif
  266. }
  267. /* The format:
  268. maintainer-errorid: [function-name:] message
  269. where errorid is unique to the maintainer and function-name is
  270. optional, is recommended, so that anyone can easily find the bug
  271. with a simple grep for the short to type string
  272. maintainer-errorid. Don't bother with reusing errorids, there are
  273. lots of numbers out there.
  274. Example:
  275. reiserfs_panic(
  276. p_sb, "reiser-29: reiserfs_new_blocknrs: "
  277. "one of search_start or rn(%d) is equal to MAX_B_NUM,"
  278. "which means that we are optimizing location based on the bogus location of a temp buffer (%p).",
  279. rn, bh
  280. );
  281. Regular panic()s sometimes clear the screen before the message can
  282. be read, thus the need for the while loop.
  283. Numbering scheme for panic used by Vladimir and Anatoly( Hans completely ignores this scheme, and considers it
  284. pointless complexity):
  285. panics in reiserfs_fs.h have numbers from 1000 to 1999
  286. super.c 2000 to 2999
  287. preserve.c (unused) 3000 to 3999
  288. bitmap.c 4000 to 4999
  289. stree.c 5000 to 5999
  290. prints.c 6000 to 6999
  291. namei.c 7000 to 7999
  292. fix_nodes.c 8000 to 8999
  293. dir.c 9000 to 9999
  294. lbalance.c 10000 to 10999
  295. ibalance.c 11000 to 11999 not ready
  296. do_balan.c 12000 to 12999
  297. inode.c 13000 to 13999
  298. file.c 14000 to 14999
  299. objectid.c 15000 - 15999
  300. buffer.c 16000 - 16999
  301. symlink.c 17000 - 17999
  302. . */
  303. #ifdef CONFIG_REISERFS_CHECK
  304. extern struct tree_balance *cur_tb;
  305. #endif
  306. void reiserfs_panic(struct super_block *sb, const char *fmt, ...)
  307. {
  308. do_reiserfs_warning(fmt);
  309. printk(KERN_EMERG "REISERFS: panic (device %s): %s\n",
  310. reiserfs_bdevname(sb), error_buf);
  311. BUG();
  312. /* this is not actually called, but makes reiserfs_panic() "noreturn" */
  313. panic("REISERFS: panic (device %s): %s\n",
  314. reiserfs_bdevname(sb), error_buf);
  315. }
  316. void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
  317. {
  318. do_reiserfs_warning(fmt);
  319. if (reiserfs_error_panic(sb)) {
  320. panic(KERN_CRIT "REISERFS: panic (device %s): %s\n",
  321. reiserfs_bdevname(sb), error_buf);
  322. }
  323. if (sb->s_flags & MS_RDONLY)
  324. return;
  325. printk(KERN_CRIT "REISERFS: abort (device %s): %s\n",
  326. reiserfs_bdevname(sb), error_buf);
  327. sb->s_flags |= MS_RDONLY;
  328. reiserfs_journal_abort(sb, errno);
  329. }
  330. /* this prints internal nodes (4 keys/items in line) (dc_number,
  331. dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number,
  332. dc_size)...*/
  333. static int print_internal(struct buffer_head *bh, int first, int last)
  334. {
  335. struct reiserfs_key *key;
  336. struct disk_child *dc;
  337. int i;
  338. int from, to;
  339. if (!B_IS_KEYS_LEVEL(bh))
  340. return 1;
  341. check_internal(bh);
  342. if (first == -1) {
  343. from = 0;
  344. to = B_NR_ITEMS(bh);
  345. } else {
  346. from = first;
  347. to = last < B_NR_ITEMS(bh) ? last : B_NR_ITEMS(bh);
  348. }
  349. reiserfs_printk("INTERNAL NODE (%ld) contains %z\n", bh->b_blocknr, bh);
  350. dc = B_N_CHILD(bh, from);
  351. reiserfs_printk("PTR %d: %y ", from, dc);
  352. for (i = from, key = B_N_PDELIM_KEY(bh, from), dc++; i < to;
  353. i++, key++, dc++) {
  354. reiserfs_printk("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);
  355. if (i && i % 4 == 0)
  356. printk("\n");
  357. }
  358. printk("\n");
  359. return 0;
  360. }
  361. static int print_leaf(struct buffer_head *bh, int print_mode, int first,
  362. int last)
  363. {
  364. struct block_head *blkh;
  365. struct item_head *ih;
  366. int i, nr;
  367. int from, to;
  368. if (!B_IS_ITEMS_LEVEL(bh))
  369. return 1;
  370. check_leaf(bh);
  371. blkh = B_BLK_HEAD(bh);
  372. ih = B_N_PITEM_HEAD(bh, 0);
  373. nr = blkh_nr_item(blkh);
  374. printk
  375. ("\n===================================================================\n");
  376. reiserfs_printk("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
  377. if (!(print_mode & PRINT_LEAF_ITEMS)) {
  378. reiserfs_printk("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
  379. &(ih->ih_key), &((ih + nr - 1)->ih_key));
  380. return 0;
  381. }
  382. if (first < 0 || first > nr - 1)
  383. from = 0;
  384. else
  385. from = first;
  386. if (last < 0 || last > nr)
  387. to = nr;
  388. else
  389. to = last;
  390. ih += from;
  391. printk
  392. ("-------------------------------------------------------------------------------\n");
  393. printk
  394. ("|##| type | key | ilen | free_space | version | loc |\n");
  395. for (i = from; i < to; i++, ih++) {
  396. printk
  397. ("-------------------------------------------------------------------------------\n");
  398. reiserfs_printk("|%2d| %h |\n", i, ih);
  399. if (print_mode & PRINT_LEAF_ITEMS)
  400. op_print_item(ih, B_I_PITEM(bh, ih));
  401. }
  402. printk
  403. ("===================================================================\n");
  404. return 0;
  405. }
  406. char *reiserfs_hashname(int code)
  407. {
  408. if (code == YURA_HASH)
  409. return "rupasov";
  410. if (code == TEA_HASH)
  411. return "tea";
  412. if (code == R5_HASH)
  413. return "r5";
  414. return "unknown";
  415. }
  416. /* return 1 if this is not super block */
  417. static int print_super_block(struct buffer_head *bh)
  418. {
  419. struct reiserfs_super_block *rs =
  420. (struct reiserfs_super_block *)(bh->b_data);
  421. int skipped, data_blocks;
  422. char *version;
  423. char b[BDEVNAME_SIZE];
  424. if (is_reiserfs_3_5(rs)) {
  425. version = "3.5";
  426. } else if (is_reiserfs_3_6(rs)) {
  427. version = "3.6";
  428. } else if (is_reiserfs_jr(rs)) {
  429. version = ((sb_version(rs) == REISERFS_VERSION_2) ?
  430. "3.6" : "3.5");
  431. } else {
  432. return 1;
  433. }
  434. printk("%s\'s super block is in block %llu\n", bdevname(bh->b_bdev, b),
  435. (unsigned long long)bh->b_blocknr);
  436. printk("Reiserfs version %s\n", version);
  437. printk("Block count %u\n", sb_block_count(rs));
  438. printk("Blocksize %d\n", sb_blocksize(rs));
  439. printk("Free blocks %u\n", sb_free_blocks(rs));
  440. // FIXME: this would be confusing if
  441. // someone stores reiserfs super block in some data block ;)
  442. // skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs);
  443. skipped = bh->b_blocknr;
  444. data_blocks = sb_block_count(rs) - skipped - 1 - sb_bmap_nr(rs) -
  445. (!is_reiserfs_jr(rs) ? sb_jp_journal_size(rs) +
  446. 1 : sb_reserved_for_journal(rs)) - sb_free_blocks(rs);
  447. printk
  448. ("Busy blocks (skipped %d, bitmaps - %d, journal (or reserved) blocks - %d\n"
  449. "1 super block, %d data blocks\n", skipped, sb_bmap_nr(rs),
  450. (!is_reiserfs_jr(rs) ? (sb_jp_journal_size(rs) + 1) :
  451. sb_reserved_for_journal(rs)), data_blocks);
  452. printk("Root block %u\n", sb_root_block(rs));
  453. printk("Journal block (first) %d\n", sb_jp_journal_1st_block(rs));
  454. printk("Journal dev %d\n", sb_jp_journal_dev(rs));
  455. printk("Journal orig size %d\n", sb_jp_journal_size(rs));
  456. printk("FS state %d\n", sb_fs_state(rs));
  457. printk("Hash function \"%s\"\n",
  458. reiserfs_hashname(sb_hash_function_code(rs)));
  459. printk("Tree height %d\n", sb_tree_height(rs));
  460. return 0;
  461. }
  462. static int print_desc_block(struct buffer_head *bh)
  463. {
  464. struct reiserfs_journal_desc *desc;
  465. if (memcmp(get_journal_desc_magic(bh), JOURNAL_DESC_MAGIC, 8))
  466. return 1;
  467. desc = (struct reiserfs_journal_desc *)(bh->b_data);
  468. printk("Desc block %llu (j_trans_id %d, j_mount_id %d, j_len %d)",
  469. (unsigned long long)bh->b_blocknr, get_desc_trans_id(desc),
  470. get_desc_mount_id(desc), get_desc_trans_len(desc));
  471. return 0;
  472. }
  473. void print_block(struct buffer_head *bh, ...) //int print_mode, int first, int last)
  474. {
  475. va_list args;
  476. int mode, first, last;
  477. va_start(args, bh);
  478. if (!bh) {
  479. printk("print_block: buffer is NULL\n");
  480. return;
  481. }
  482. mode = va_arg(args, int);
  483. first = va_arg(args, int);
  484. last = va_arg(args, int);
  485. if (print_leaf(bh, mode, first, last))
  486. if (print_internal(bh, first, last))
  487. if (print_super_block(bh))
  488. if (print_desc_block(bh))
  489. printk
  490. ("Block %llu contains unformatted data\n",
  491. (unsigned long long)bh->b_blocknr);
  492. }
  493. static char print_tb_buf[2048];
  494. /* this stores initial state of tree balance in the print_tb_buf */
  495. void store_print_tb(struct tree_balance *tb)
  496. {
  497. int h = 0;
  498. int i;
  499. struct buffer_head *tbSh, *tbFh;
  500. if (!tb)
  501. return;
  502. sprintf(print_tb_buf, "\n"
  503. "BALANCING %d\n"
  504. "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n"
  505. "=====================================================================\n"
  506. "* h * S * L * R * F * FL * FR * CFL * CFR *\n",
  507. REISERFS_SB(tb->tb_sb)->s_do_balance,
  508. tb->tb_mode, PATH_LAST_POSITION(tb->tb_path),
  509. tb->tb_path->pos_in_item);
  510. for (h = 0; h < ARRAY_SIZE(tb->insert_size); h++) {
  511. if (PATH_H_PATH_OFFSET(tb->tb_path, h) <=
  512. tb->tb_path->path_length
  513. && PATH_H_PATH_OFFSET(tb->tb_path,
  514. h) > ILLEGAL_PATH_ELEMENT_OFFSET) {
  515. tbSh = PATH_H_PBUFFER(tb->tb_path, h);
  516. tbFh = PATH_H_PPARENT(tb->tb_path, h);
  517. } else {
  518. tbSh = NULL;
  519. tbFh = NULL;
  520. }
  521. sprintf(print_tb_buf + strlen(print_tb_buf),
  522. "* %d * %3lld(%2d) * %3lld(%2d) * %3lld(%2d) * %5lld * %5lld * %5lld * %5lld * %5lld *\n",
  523. h,
  524. (tbSh) ? (long long)(tbSh->b_blocknr) : (-1LL),
  525. (tbSh) ? atomic_read(&(tbSh->b_count)) : -1,
  526. (tb->L[h]) ? (long long)(tb->L[h]->b_blocknr) : (-1LL),
  527. (tb->L[h]) ? atomic_read(&(tb->L[h]->b_count)) : -1,
  528. (tb->R[h]) ? (long long)(tb->R[h]->b_blocknr) : (-1LL),
  529. (tb->R[h]) ? atomic_read(&(tb->R[h]->b_count)) : -1,
  530. (tbFh) ? (long long)(tbFh->b_blocknr) : (-1LL),
  531. (tb->FL[h]) ? (long long)(tb->FL[h]->
  532. b_blocknr) : (-1LL),
  533. (tb->FR[h]) ? (long long)(tb->FR[h]->
  534. b_blocknr) : (-1LL),
  535. (tb->CFL[h]) ? (long long)(tb->CFL[h]->
  536. b_blocknr) : (-1LL),
  537. (tb->CFR[h]) ? (long long)(tb->CFR[h]->
  538. b_blocknr) : (-1LL));
  539. }
  540. sprintf(print_tb_buf + strlen(print_tb_buf),
  541. "=====================================================================\n"
  542. "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
  543. "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
  544. tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],
  545. tb->rbytes, tb->blknum[0], tb->s0num, tb->s1num, tb->s1bytes,
  546. tb->s2num, tb->s2bytes, tb->cur_blknum, tb->lkey[0],
  547. tb->rkey[0]);
  548. /* this prints balance parameters for non-leaf levels */
  549. h = 0;
  550. do {
  551. h++;
  552. sprintf(print_tb_buf + strlen(print_tb_buf),
  553. "* %d * %4d * %2d * * %2d * * %2d *\n",
  554. h, tb->insert_size[h], tb->lnum[h], tb->rnum[h],
  555. tb->blknum[h]);
  556. } while (tb->insert_size[h]);
  557. sprintf(print_tb_buf + strlen(print_tb_buf),
  558. "=====================================================================\n"
  559. "FEB list: ");
  560. /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */
  561. h = 0;
  562. for (i = 0; i < ARRAY_SIZE(tb->FEB); i++)
  563. sprintf(print_tb_buf + strlen(print_tb_buf),
  564. "%p (%llu %d)%s", tb->FEB[i],
  565. tb->FEB[i] ? (unsigned long long)tb->FEB[i]->
  566. b_blocknr : 0ULL,
  567. tb->FEB[i] ? atomic_read(&(tb->FEB[i]->b_count)) : 0,
  568. (i == ARRAY_SIZE(tb->FEB) - 1) ? "\n" : ", ");
  569. sprintf(print_tb_buf + strlen(print_tb_buf),
  570. "======================== the end ====================================\n");
  571. }
  572. void print_cur_tb(char *mes)
  573. {
  574. printk("%s\n%s", mes, print_tb_buf);
  575. }
  576. static void check_leaf_block_head(struct buffer_head *bh)
  577. {
  578. struct block_head *blkh;
  579. int nr;
  580. blkh = B_BLK_HEAD(bh);
  581. nr = blkh_nr_item(blkh);
  582. if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
  583. reiserfs_panic(NULL,
  584. "vs-6010: check_leaf_block_head: invalid item number %z",
  585. bh);
  586. if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
  587. reiserfs_panic(NULL,
  588. "vs-6020: check_leaf_block_head: invalid free space %z",
  589. bh);
  590. }
  591. static void check_internal_block_head(struct buffer_head *bh)
  592. {
  593. struct block_head *blkh;
  594. blkh = B_BLK_HEAD(bh);
  595. if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
  596. reiserfs_panic(NULL,
  597. "vs-6025: check_internal_block_head: invalid level %z",
  598. bh);
  599. if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
  600. reiserfs_panic(NULL,
  601. "vs-6030: check_internal_block_head: invalid item number %z",
  602. bh);
  603. if (B_FREE_SPACE(bh) !=
  604. bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
  605. DC_SIZE * (B_NR_ITEMS(bh) + 1))
  606. reiserfs_panic(NULL,
  607. "vs-6040: check_internal_block_head: invalid free space %z",
  608. bh);
  609. }
  610. void check_leaf(struct buffer_head *bh)
  611. {
  612. int i;
  613. struct item_head *ih;
  614. if (!bh)
  615. return;
  616. check_leaf_block_head(bh);
  617. for (i = 0, ih = B_N_PITEM_HEAD(bh, 0); i < B_NR_ITEMS(bh); i++, ih++)
  618. op_check_item(ih, B_I_PITEM(bh, ih));
  619. }
  620. void check_internal(struct buffer_head *bh)
  621. {
  622. if (!bh)
  623. return;
  624. check_internal_block_head(bh);
  625. }
  626. void print_statistics(struct super_block *s)
  627. {
  628. /*
  629. printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \
  630. bmap with search %d, without %d, dir2ind %d, ind2dir %d\n",
  631. REISERFS_SB(s)->s_do_balance, REISERFS_SB(s)->s_fix_nodes,
  632. REISERFS_SB(s)->s_bmaps, REISERFS_SB(s)->s_bmaps_without_search,
  633. REISERFS_SB(s)->s_direct2indirect, REISERFS_SB(s)->s_indirect2direct);
  634. */
  635. }