prints.c 21 KB

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