prints.c 21 KB

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