prints.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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 "reiserfs.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, "%llu(%llu)",
  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, "%llu(%llu)",
  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)
  139. {
  140. char *k = fmt;
  141. while ((k = strchr(k, '%')) != NULL) {
  142. if (k[1] == 'k' || k[1] == 'K' || k[1] == 'h' || k[1] == 't' ||
  143. k[1] == 'z' || k[1] == 'b' || k[1] == 'y' || k[1] == 'a') {
  144. *what = k[1];
  145. break;
  146. }
  147. k++;
  148. }
  149. return k;
  150. }
  151. /*
  152. * debugging reiserfs we used to print out a lot of different
  153. * variables, like keys, item headers, buffer heads etc. Values of
  154. * most fields matter. So it took a long time just to write
  155. * appropriative printk. With this reiserfs_warning you can use format
  156. * specification for complex structures like you used to do with
  157. * printfs for integers, doubles and pointers. For instance, to print
  158. * out key structure you have to write just:
  159. * reiserfs_warning ("bad key %k", key);
  160. * instead of
  161. * printk ("bad key %lu %lu %lu %lu", key->k_dir_id, key->k_objectid,
  162. * key->k_offset, key->k_uniqueness);
  163. */
  164. static DEFINE_SPINLOCK(error_lock);
  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 what;
  171. spin_lock(&error_lock);
  172. strcpy(fmt1, fmt);
  173. while ((k = is_there_reiserfs_struct(fmt1, &what)) != NULL) {
  174. *k = 0;
  175. p += vsprintf(p, fmt1, args);
  176. switch (what) {
  177. case 'k':
  178. sprintf_le_key(p, va_arg(args, struct reiserfs_key *));
  179. break;
  180. case 'K':
  181. sprintf_cpu_key(p, va_arg(args, struct cpu_key *));
  182. break;
  183. case 'h':
  184. sprintf_item_head(p, va_arg(args, struct item_head *));
  185. break;
  186. case 't':
  187. sprintf_direntry(p,
  188. va_arg(args,
  189. struct reiserfs_dir_entry *));
  190. break;
  191. case 'y':
  192. sprintf_disk_child(p,
  193. va_arg(args, struct disk_child *));
  194. break;
  195. case 'z':
  196. sprintf_block_head(p,
  197. va_arg(args, struct buffer_head *));
  198. break;
  199. case 'b':
  200. sprintf_buffer_head(p,
  201. va_arg(args, struct buffer_head *));
  202. break;
  203. case 'a':
  204. sprintf_de_head(p,
  205. va_arg(args,
  206. struct reiserfs_de_head *));
  207. break;
  208. }
  209. p += strlen(p);
  210. fmt1 = k + 2;
  211. }
  212. vsprintf(p, fmt1, args);
  213. spin_unlock(&error_lock);
  214. }
  215. /*
  216. * in addition to usual conversion specifiers this accepts reiserfs
  217. * specific conversion specifiers:
  218. * %k to print little endian key,
  219. * %K to print cpu key,
  220. * %h to print item_head,
  221. * %t to print directory entry
  222. * %z to print block head (arg must be struct buffer_head *
  223. * %b to print buffer_head
  224. */
  225. #define do_reiserfs_warning(fmt)\
  226. {\
  227. va_list args;\
  228. va_start( args, fmt );\
  229. prepare_error_buf( fmt, args );\
  230. va_end( args );\
  231. }
  232. void __reiserfs_warning(struct super_block *sb, const char *id,
  233. const char *function, const char *fmt, ...)
  234. {
  235. do_reiserfs_warning(fmt);
  236. if (sb)
  237. printk(KERN_WARNING "REISERFS warning (device %s): %s%s%s: "
  238. "%s\n", sb->s_id, id ? id : "", id ? " " : "",
  239. function, error_buf);
  240. else
  241. printk(KERN_WARNING "REISERFS warning: %s%s%s: %s\n",
  242. id ? id : "", id ? " " : "", function, error_buf);
  243. }
  244. /* No newline.. reiserfs_info calls can be followed by printk's */
  245. void reiserfs_info(struct super_block *sb, const char *fmt, ...)
  246. {
  247. do_reiserfs_warning(fmt);
  248. if (sb)
  249. printk(KERN_NOTICE "REISERFS (device %s): %s",
  250. sb->s_id, error_buf);
  251. else
  252. printk(KERN_NOTICE "REISERFS %s:", error_buf);
  253. }
  254. /* No newline.. reiserfs_printk calls can be followed by printk's */
  255. static void reiserfs_printk(const char *fmt, ...)
  256. {
  257. do_reiserfs_warning(fmt);
  258. printk(error_buf);
  259. }
  260. void reiserfs_debug(struct super_block *s, int level, const char *fmt, ...)
  261. {
  262. #ifdef CONFIG_REISERFS_CHECK
  263. do_reiserfs_warning(fmt);
  264. if (s)
  265. printk(KERN_DEBUG "REISERFS debug (device %s): %s\n",
  266. s->s_id, error_buf);
  267. else
  268. printk(KERN_DEBUG "REISERFS debug: %s\n", error_buf);
  269. #endif
  270. }
  271. /*
  272. * The format:
  273. *
  274. * maintainer-errorid: [function-name:] message
  275. *
  276. * where errorid is unique to the maintainer and function-name is
  277. * optional, is recommended, so that anyone can easily find the bug
  278. * with a simple grep for the short to type string
  279. * maintainer-errorid. Don't bother with reusing errorids, there are
  280. * lots of numbers out there.
  281. *
  282. * Example:
  283. *
  284. * reiserfs_panic(
  285. * p_sb, "reiser-29: reiserfs_new_blocknrs: "
  286. * "one of search_start or rn(%d) is equal to MAX_B_NUM,"
  287. * "which means that we are optimizing location based on the "
  288. * "bogus location of a temp buffer (%p).",
  289. * rn, bh
  290. * );
  291. *
  292. * Regular panic()s sometimes clear the screen before the message can
  293. * be read, thus the need for the while loop.
  294. *
  295. * Numbering scheme for panic used by Vladimir and Anatoly( Hans completely
  296. * ignores this scheme, and considers it pointless complexity):
  297. *
  298. * panics in reiserfs_fs.h have numbers from 1000 to 1999
  299. * super.c 2000 to 2999
  300. * preserve.c (unused) 3000 to 3999
  301. * bitmap.c 4000 to 4999
  302. * stree.c 5000 to 5999
  303. * prints.c 6000 to 6999
  304. * namei.c 7000 to 7999
  305. * fix_nodes.c 8000 to 8999
  306. * dir.c 9000 to 9999
  307. * lbalance.c 10000 to 10999
  308. * ibalance.c 11000 to 11999 not ready
  309. * do_balan.c 12000 to 12999
  310. * inode.c 13000 to 13999
  311. * file.c 14000 to 14999
  312. * objectid.c 15000 - 15999
  313. * buffer.c 16000 - 16999
  314. * symlink.c 17000 - 17999
  315. *
  316. * . */
  317. void __reiserfs_panic(struct super_block *sb, const char *id,
  318. const char *function, const char *fmt, ...)
  319. {
  320. do_reiserfs_warning(fmt);
  321. #ifdef CONFIG_REISERFS_CHECK
  322. dump_stack();
  323. #endif
  324. if (sb)
  325. printk(KERN_WARNING "REISERFS panic (device %s): %s%s%s: %s\n",
  326. sb->s_id, id ? id : "", id ? " " : "",
  327. function, error_buf);
  328. else
  329. printk(KERN_WARNING "REISERFS panic: %s%s%s: %s\n",
  330. id ? id : "", id ? " " : "", function, error_buf);
  331. BUG();
  332. }
  333. void __reiserfs_error(struct super_block *sb, const char *id,
  334. const char *function, const char *fmt, ...)
  335. {
  336. do_reiserfs_warning(fmt);
  337. BUG_ON(sb == NULL);
  338. if (reiserfs_error_panic(sb))
  339. __reiserfs_panic(sb, id, function, error_buf);
  340. if (id && id[0])
  341. printk(KERN_CRIT "REISERFS error (device %s): %s %s: %s\n",
  342. sb->s_id, id, function, error_buf);
  343. else
  344. printk(KERN_CRIT "REISERFS error (device %s): %s: %s\n",
  345. sb->s_id, function, error_buf);
  346. if (sb->s_flags & MS_RDONLY)
  347. return;
  348. reiserfs_info(sb, "Remounting filesystem read-only\n");
  349. sb->s_flags |= MS_RDONLY;
  350. reiserfs_abort_journal(sb, -EIO);
  351. }
  352. void reiserfs_abort(struct super_block *sb, int errno, const char *fmt, ...)
  353. {
  354. do_reiserfs_warning(fmt);
  355. if (reiserfs_error_panic(sb)) {
  356. panic(KERN_CRIT "REISERFS panic (device %s): %s\n", sb->s_id,
  357. error_buf);
  358. }
  359. if (reiserfs_is_journal_aborted(SB_JOURNAL(sb)))
  360. return;
  361. printk(KERN_CRIT "REISERFS abort (device %s): %s\n", sb->s_id,
  362. error_buf);
  363. sb->s_flags |= MS_RDONLY;
  364. reiserfs_abort_journal(sb, errno);
  365. }
  366. /*
  367. * this prints internal nodes (4 keys/items in line) (dc_number,
  368. * dc_size)[k_dirid, k_objectid, k_offset, k_uniqueness](dc_number,
  369. * dc_size)...
  370. */
  371. static int print_internal(struct buffer_head *bh, int first, int last)
  372. {
  373. struct reiserfs_key *key;
  374. struct disk_child *dc;
  375. int i;
  376. int from, to;
  377. if (!B_IS_KEYS_LEVEL(bh))
  378. return 1;
  379. check_internal(bh);
  380. if (first == -1) {
  381. from = 0;
  382. to = B_NR_ITEMS(bh);
  383. } else {
  384. from = first;
  385. to = last < B_NR_ITEMS(bh) ? last : B_NR_ITEMS(bh);
  386. }
  387. reiserfs_printk("INTERNAL NODE (%ld) contains %z\n", bh->b_blocknr, bh);
  388. dc = B_N_CHILD(bh, from);
  389. reiserfs_printk("PTR %d: %y ", from, dc);
  390. for (i = from, key = internal_key(bh, from), dc++; i < to;
  391. i++, key++, dc++) {
  392. reiserfs_printk("KEY %d: %k PTR %d: %y ", i, key, i + 1, dc);
  393. if (i && i % 4 == 0)
  394. printk("\n");
  395. }
  396. printk("\n");
  397. return 0;
  398. }
  399. static int print_leaf(struct buffer_head *bh, int print_mode, int first,
  400. int last)
  401. {
  402. struct block_head *blkh;
  403. struct item_head *ih;
  404. int i, nr;
  405. int from, to;
  406. if (!B_IS_ITEMS_LEVEL(bh))
  407. return 1;
  408. check_leaf(bh);
  409. blkh = B_BLK_HEAD(bh);
  410. ih = item_head(bh, 0);
  411. nr = blkh_nr_item(blkh);
  412. printk
  413. ("\n===================================================================\n");
  414. reiserfs_printk("LEAF NODE (%ld) contains %z\n", bh->b_blocknr, bh);
  415. if (!(print_mode & PRINT_LEAF_ITEMS)) {
  416. reiserfs_printk("FIRST ITEM_KEY: %k, LAST ITEM KEY: %k\n",
  417. &(ih->ih_key), &((ih + nr - 1)->ih_key));
  418. return 0;
  419. }
  420. if (first < 0 || first > nr - 1)
  421. from = 0;
  422. else
  423. from = first;
  424. if (last < 0 || last > nr)
  425. to = nr;
  426. else
  427. to = last;
  428. ih += from;
  429. printk
  430. ("-------------------------------------------------------------------------------\n");
  431. printk
  432. ("|##| type | key | ilen | free_space | version | loc |\n");
  433. for (i = from; i < to; i++, ih++) {
  434. printk
  435. ("-------------------------------------------------------------------------------\n");
  436. reiserfs_printk("|%2d| %h |\n", i, ih);
  437. if (print_mode & PRINT_LEAF_ITEMS)
  438. op_print_item(ih, ih_item_body(bh, ih));
  439. }
  440. printk
  441. ("===================================================================\n");
  442. return 0;
  443. }
  444. char *reiserfs_hashname(int code)
  445. {
  446. if (code == YURA_HASH)
  447. return "rupasov";
  448. if (code == TEA_HASH)
  449. return "tea";
  450. if (code == R5_HASH)
  451. return "r5";
  452. return "unknown";
  453. }
  454. /* return 1 if this is not super block */
  455. static int print_super_block(struct buffer_head *bh)
  456. {
  457. struct reiserfs_super_block *rs =
  458. (struct reiserfs_super_block *)(bh->b_data);
  459. int skipped, data_blocks;
  460. char *version;
  461. char b[BDEVNAME_SIZE];
  462. if (is_reiserfs_3_5(rs)) {
  463. version = "3.5";
  464. } else if (is_reiserfs_3_6(rs)) {
  465. version = "3.6";
  466. } else if (is_reiserfs_jr(rs)) {
  467. version = ((sb_version(rs) == REISERFS_VERSION_2) ?
  468. "3.6" : "3.5");
  469. } else {
  470. return 1;
  471. }
  472. printk("%s\'s super block is in block %llu\n", bdevname(bh->b_bdev, b),
  473. (unsigned long long)bh->b_blocknr);
  474. printk("Reiserfs version %s\n", version);
  475. printk("Block count %u\n", sb_block_count(rs));
  476. printk("Blocksize %d\n", sb_blocksize(rs));
  477. printk("Free blocks %u\n", sb_free_blocks(rs));
  478. /*
  479. * FIXME: this would be confusing if
  480. * someone stores reiserfs super block in some data block ;)
  481. // skipped = (bh->b_blocknr * bh->b_size) / sb_blocksize(rs);
  482. */
  483. skipped = bh->b_blocknr;
  484. data_blocks = sb_block_count(rs) - skipped - 1 - sb_bmap_nr(rs) -
  485. (!is_reiserfs_jr(rs) ? sb_jp_journal_size(rs) +
  486. 1 : sb_reserved_for_journal(rs)) - sb_free_blocks(rs);
  487. printk
  488. ("Busy blocks (skipped %d, bitmaps - %d, journal (or reserved) blocks - %d\n"
  489. "1 super block, %d data blocks\n", skipped, sb_bmap_nr(rs),
  490. (!is_reiserfs_jr(rs) ? (sb_jp_journal_size(rs) + 1) :
  491. sb_reserved_for_journal(rs)), data_blocks);
  492. printk("Root block %u\n", sb_root_block(rs));
  493. printk("Journal block (first) %d\n", sb_jp_journal_1st_block(rs));
  494. printk("Journal dev %d\n", sb_jp_journal_dev(rs));
  495. printk("Journal orig size %d\n", sb_jp_journal_size(rs));
  496. printk("FS state %d\n", sb_fs_state(rs));
  497. printk("Hash function \"%s\"\n",
  498. reiserfs_hashname(sb_hash_function_code(rs)));
  499. printk("Tree height %d\n", sb_tree_height(rs));
  500. return 0;
  501. }
  502. static int print_desc_block(struct buffer_head *bh)
  503. {
  504. struct reiserfs_journal_desc *desc;
  505. if (memcmp(get_journal_desc_magic(bh), JOURNAL_DESC_MAGIC, 8))
  506. return 1;
  507. desc = (struct reiserfs_journal_desc *)(bh->b_data);
  508. printk("Desc block %llu (j_trans_id %d, j_mount_id %d, j_len %d)",
  509. (unsigned long long)bh->b_blocknr, get_desc_trans_id(desc),
  510. get_desc_mount_id(desc), get_desc_trans_len(desc));
  511. return 0;
  512. }
  513. /* ..., int print_mode, int first, int last) */
  514. void print_block(struct buffer_head *bh, ...)
  515. {
  516. va_list args;
  517. int mode, first, last;
  518. if (!bh) {
  519. printk("print_block: buffer is NULL\n");
  520. return;
  521. }
  522. va_start(args, bh);
  523. mode = va_arg(args, int);
  524. first = va_arg(args, int);
  525. last = va_arg(args, int);
  526. if (print_leaf(bh, mode, first, last))
  527. if (print_internal(bh, first, last))
  528. if (print_super_block(bh))
  529. if (print_desc_block(bh))
  530. printk
  531. ("Block %llu contains unformatted data\n",
  532. (unsigned long long)bh->b_blocknr);
  533. va_end(args);
  534. }
  535. static char print_tb_buf[2048];
  536. /* this stores initial state of tree balance in the print_tb_buf */
  537. void store_print_tb(struct tree_balance *tb)
  538. {
  539. int h = 0;
  540. int i;
  541. struct buffer_head *tbSh, *tbFh;
  542. if (!tb)
  543. return;
  544. sprintf(print_tb_buf, "\n"
  545. "BALANCING %d\n"
  546. "MODE=%c, ITEM_POS=%d POS_IN_ITEM=%d\n"
  547. "=====================================================================\n"
  548. "* h * S * L * R * F * FL * FR * CFL * CFR *\n",
  549. REISERFS_SB(tb->tb_sb)->s_do_balance,
  550. tb->tb_mode, PATH_LAST_POSITION(tb->tb_path),
  551. tb->tb_path->pos_in_item);
  552. for (h = 0; h < ARRAY_SIZE(tb->insert_size); h++) {
  553. if (PATH_H_PATH_OFFSET(tb->tb_path, h) <=
  554. tb->tb_path->path_length
  555. && PATH_H_PATH_OFFSET(tb->tb_path,
  556. h) > ILLEGAL_PATH_ELEMENT_OFFSET) {
  557. tbSh = PATH_H_PBUFFER(tb->tb_path, h);
  558. tbFh = PATH_H_PPARENT(tb->tb_path, h);
  559. } else {
  560. tbSh = NULL;
  561. tbFh = NULL;
  562. }
  563. sprintf(print_tb_buf + strlen(print_tb_buf),
  564. "* %d * %3lld(%2d) * %3lld(%2d) * %3lld(%2d) * %5lld * %5lld * %5lld * %5lld * %5lld *\n",
  565. h,
  566. (tbSh) ? (long long)(tbSh->b_blocknr) : (-1LL),
  567. (tbSh) ? atomic_read(&tbSh->b_count) : -1,
  568. (tb->L[h]) ? (long long)(tb->L[h]->b_blocknr) : (-1LL),
  569. (tb->L[h]) ? atomic_read(&tb->L[h]->b_count) : -1,
  570. (tb->R[h]) ? (long long)(tb->R[h]->b_blocknr) : (-1LL),
  571. (tb->R[h]) ? atomic_read(&tb->R[h]->b_count) : -1,
  572. (tbFh) ? (long long)(tbFh->b_blocknr) : (-1LL),
  573. (tb->FL[h]) ? (long long)(tb->FL[h]->
  574. b_blocknr) : (-1LL),
  575. (tb->FR[h]) ? (long long)(tb->FR[h]->
  576. b_blocknr) : (-1LL),
  577. (tb->CFL[h]) ? (long long)(tb->CFL[h]->
  578. b_blocknr) : (-1LL),
  579. (tb->CFR[h]) ? (long long)(tb->CFR[h]->
  580. b_blocknr) : (-1LL));
  581. }
  582. sprintf(print_tb_buf + strlen(print_tb_buf),
  583. "=====================================================================\n"
  584. "* h * size * ln * lb * rn * rb * blkn * s0 * s1 * s1b * s2 * s2b * curb * lk * rk *\n"
  585. "* 0 * %4d * %2d * %2d * %2d * %2d * %4d * %2d * %2d * %3d * %2d * %3d * %4d * %2d * %2d *\n",
  586. tb->insert_size[0], tb->lnum[0], tb->lbytes, tb->rnum[0],
  587. tb->rbytes, tb->blknum[0], tb->s0num, tb->snum[0],
  588. tb->sbytes[0], tb->snum[1], tb->sbytes[1],
  589. tb->cur_blknum, tb->lkey[0], tb->rkey[0]);
  590. /* this prints balance parameters for non-leaf levels */
  591. h = 0;
  592. do {
  593. h++;
  594. sprintf(print_tb_buf + strlen(print_tb_buf),
  595. "* %d * %4d * %2d * * %2d * * %2d *\n",
  596. h, tb->insert_size[h], tb->lnum[h], tb->rnum[h],
  597. tb->blknum[h]);
  598. } while (tb->insert_size[h]);
  599. sprintf(print_tb_buf + strlen(print_tb_buf),
  600. "=====================================================================\n"
  601. "FEB list: ");
  602. /* print FEB list (list of buffers in form (bh (b_blocknr, b_count), that will be used for new nodes) */
  603. h = 0;
  604. for (i = 0; i < ARRAY_SIZE(tb->FEB); i++)
  605. sprintf(print_tb_buf + strlen(print_tb_buf),
  606. "%p (%llu %d)%s", tb->FEB[i],
  607. tb->FEB[i] ? (unsigned long long)tb->FEB[i]->
  608. b_blocknr : 0ULL,
  609. tb->FEB[i] ? atomic_read(&tb->FEB[i]->b_count) : 0,
  610. (i == ARRAY_SIZE(tb->FEB) - 1) ? "\n" : ", ");
  611. sprintf(print_tb_buf + strlen(print_tb_buf),
  612. "======================== the end ====================================\n");
  613. }
  614. void print_cur_tb(char *mes)
  615. {
  616. printk("%s\n%s", mes, print_tb_buf);
  617. }
  618. static void check_leaf_block_head(struct buffer_head *bh)
  619. {
  620. struct block_head *blkh;
  621. int nr;
  622. blkh = B_BLK_HEAD(bh);
  623. nr = blkh_nr_item(blkh);
  624. if (nr > (bh->b_size - BLKH_SIZE) / IH_SIZE)
  625. reiserfs_panic(NULL, "vs-6010", "invalid item number %z",
  626. bh);
  627. if (blkh_free_space(blkh) > bh->b_size - BLKH_SIZE - IH_SIZE * nr)
  628. reiserfs_panic(NULL, "vs-6020", "invalid free space %z",
  629. bh);
  630. }
  631. static void check_internal_block_head(struct buffer_head *bh)
  632. {
  633. struct block_head *blkh;
  634. blkh = B_BLK_HEAD(bh);
  635. if (!(B_LEVEL(bh) > DISK_LEAF_NODE_LEVEL && B_LEVEL(bh) <= MAX_HEIGHT))
  636. reiserfs_panic(NULL, "vs-6025", "invalid level %z", bh);
  637. if (B_NR_ITEMS(bh) > (bh->b_size - BLKH_SIZE) / IH_SIZE)
  638. reiserfs_panic(NULL, "vs-6030", "invalid item number %z", bh);
  639. if (B_FREE_SPACE(bh) !=
  640. bh->b_size - BLKH_SIZE - KEY_SIZE * B_NR_ITEMS(bh) -
  641. DC_SIZE * (B_NR_ITEMS(bh) + 1))
  642. reiserfs_panic(NULL, "vs-6040", "invalid free space %z", bh);
  643. }
  644. void check_leaf(struct buffer_head *bh)
  645. {
  646. int i;
  647. struct item_head *ih;
  648. if (!bh)
  649. return;
  650. check_leaf_block_head(bh);
  651. for (i = 0, ih = item_head(bh, 0); i < B_NR_ITEMS(bh); i++, ih++)
  652. op_check_item(ih, ih_item_body(bh, ih));
  653. }
  654. void check_internal(struct buffer_head *bh)
  655. {
  656. if (!bh)
  657. return;
  658. check_internal_block_head(bh);
  659. }
  660. void print_statistics(struct super_block *s)
  661. {
  662. /*
  663. printk ("reiserfs_put_super: session statistics: balances %d, fix_nodes %d, \
  664. bmap with search %d, without %d, dir2ind %d, ind2dir %d\n",
  665. REISERFS_SB(s)->s_do_balance, REISERFS_SB(s)->s_fix_nodes,
  666. REISERFS_SB(s)->s_bmaps, REISERFS_SB(s)->s_bmaps_without_search,
  667. REISERFS_SB(s)->s_direct2indirect, REISERFS_SB(s)->s_indirect2direct);
  668. */
  669. }