xfs_buf_item.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_types.h"
  21. #include "xfs_bit.h"
  22. #include "xfs_log.h"
  23. #include "xfs_inum.h"
  24. #include "xfs_trans.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_dmapi.h"
  27. #include "xfs_mount.h"
  28. #include "xfs_buf_item.h"
  29. #include "xfs_trans_priv.h"
  30. #include "xfs_error.h"
  31. kmem_zone_t *xfs_buf_item_zone;
  32. #ifdef XFS_TRANS_DEBUG
  33. /*
  34. * This function uses an alternate strategy for tracking the bytes
  35. * that the user requests to be logged. This can then be used
  36. * in conjunction with the bli_orig array in the buf log item to
  37. * catch bugs in our callers' code.
  38. *
  39. * We also double check the bits set in xfs_buf_item_log using a
  40. * simple algorithm to check that every byte is accounted for.
  41. */
  42. STATIC void
  43. xfs_buf_item_log_debug(
  44. xfs_buf_log_item_t *bip,
  45. uint first,
  46. uint last)
  47. {
  48. uint x;
  49. uint byte;
  50. uint nbytes;
  51. uint chunk_num;
  52. uint word_num;
  53. uint bit_num;
  54. uint bit_set;
  55. uint *wordp;
  56. ASSERT(bip->bli_logged != NULL);
  57. byte = first;
  58. nbytes = last - first + 1;
  59. bfset(bip->bli_logged, first, nbytes);
  60. for (x = 0; x < nbytes; x++) {
  61. chunk_num = byte >> XFS_BLI_SHIFT;
  62. word_num = chunk_num >> BIT_TO_WORD_SHIFT;
  63. bit_num = chunk_num & (NBWORD - 1);
  64. wordp = &(bip->bli_format.blf_data_map[word_num]);
  65. bit_set = *wordp & (1 << bit_num);
  66. ASSERT(bit_set);
  67. byte++;
  68. }
  69. }
  70. /*
  71. * This function is called when we flush something into a buffer without
  72. * logging it. This happens for things like inodes which are logged
  73. * separately from the buffer.
  74. */
  75. void
  76. xfs_buf_item_flush_log_debug(
  77. xfs_buf_t *bp,
  78. uint first,
  79. uint last)
  80. {
  81. xfs_buf_log_item_t *bip;
  82. uint nbytes;
  83. bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
  84. if ((bip == NULL) || (bip->bli_item.li_type != XFS_LI_BUF)) {
  85. return;
  86. }
  87. ASSERT(bip->bli_logged != NULL);
  88. nbytes = last - first + 1;
  89. bfset(bip->bli_logged, first, nbytes);
  90. }
  91. /*
  92. * This function is called to verify that our callers have logged
  93. * all the bytes that they changed.
  94. *
  95. * It does this by comparing the original copy of the buffer stored in
  96. * the buf log item's bli_orig array to the current copy of the buffer
  97. * and ensuring that all bytes which mismatch are set in the bli_logged
  98. * array of the buf log item.
  99. */
  100. STATIC void
  101. xfs_buf_item_log_check(
  102. xfs_buf_log_item_t *bip)
  103. {
  104. char *orig;
  105. char *buffer;
  106. int x;
  107. xfs_buf_t *bp;
  108. ASSERT(bip->bli_orig != NULL);
  109. ASSERT(bip->bli_logged != NULL);
  110. bp = bip->bli_buf;
  111. ASSERT(XFS_BUF_COUNT(bp) > 0);
  112. ASSERT(XFS_BUF_PTR(bp) != NULL);
  113. orig = bip->bli_orig;
  114. buffer = XFS_BUF_PTR(bp);
  115. for (x = 0; x < XFS_BUF_COUNT(bp); x++) {
  116. if (orig[x] != buffer[x] && !btst(bip->bli_logged, x))
  117. cmn_err(CE_PANIC,
  118. "xfs_buf_item_log_check bip %x buffer %x orig %x index %d",
  119. bip, bp, orig, x);
  120. }
  121. }
  122. #else
  123. #define xfs_buf_item_log_debug(x,y,z)
  124. #define xfs_buf_item_log_check(x)
  125. #endif
  126. STATIC void xfs_buf_error_relse(xfs_buf_t *bp);
  127. STATIC void xfs_buf_do_callbacks(xfs_buf_t *bp, xfs_log_item_t *lip);
  128. /*
  129. * This returns the number of log iovecs needed to log the
  130. * given buf log item.
  131. *
  132. * It calculates this as 1 iovec for the buf log format structure
  133. * and 1 for each stretch of non-contiguous chunks to be logged.
  134. * Contiguous chunks are logged in a single iovec.
  135. *
  136. * If the XFS_BLI_STALE flag has been set, then log nothing.
  137. */
  138. STATIC uint
  139. xfs_buf_item_size(
  140. xfs_buf_log_item_t *bip)
  141. {
  142. uint nvecs;
  143. int next_bit;
  144. int last_bit;
  145. xfs_buf_t *bp;
  146. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  147. if (bip->bli_flags & XFS_BLI_STALE) {
  148. /*
  149. * The buffer is stale, so all we need to log
  150. * is the buf log format structure with the
  151. * cancel flag in it.
  152. */
  153. xfs_buf_item_trace("SIZE STALE", bip);
  154. ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
  155. return 1;
  156. }
  157. bp = bip->bli_buf;
  158. ASSERT(bip->bli_flags & XFS_BLI_LOGGED);
  159. nvecs = 1;
  160. last_bit = xfs_next_bit(bip->bli_format.blf_data_map,
  161. bip->bli_format.blf_map_size, 0);
  162. ASSERT(last_bit != -1);
  163. nvecs++;
  164. while (last_bit != -1) {
  165. /*
  166. * This takes the bit number to start looking from and
  167. * returns the next set bit from there. It returns -1
  168. * if there are no more bits set or the start bit is
  169. * beyond the end of the bitmap.
  170. */
  171. next_bit = xfs_next_bit(bip->bli_format.blf_data_map,
  172. bip->bli_format.blf_map_size,
  173. last_bit + 1);
  174. /*
  175. * If we run out of bits, leave the loop,
  176. * else if we find a new set of bits bump the number of vecs,
  177. * else keep scanning the current set of bits.
  178. */
  179. if (next_bit == -1) {
  180. last_bit = -1;
  181. } else if (next_bit != last_bit + 1) {
  182. last_bit = next_bit;
  183. nvecs++;
  184. } else if (xfs_buf_offset(bp, next_bit * XFS_BLI_CHUNK) !=
  185. (xfs_buf_offset(bp, last_bit * XFS_BLI_CHUNK) +
  186. XFS_BLI_CHUNK)) {
  187. last_bit = next_bit;
  188. nvecs++;
  189. } else {
  190. last_bit++;
  191. }
  192. }
  193. xfs_buf_item_trace("SIZE NORM", bip);
  194. return nvecs;
  195. }
  196. /*
  197. * This is called to fill in the vector of log iovecs for the
  198. * given log buf item. It fills the first entry with a buf log
  199. * format structure, and the rest point to contiguous chunks
  200. * within the buffer.
  201. */
  202. STATIC void
  203. xfs_buf_item_format(
  204. xfs_buf_log_item_t *bip,
  205. xfs_log_iovec_t *log_vector)
  206. {
  207. uint base_size;
  208. uint nvecs;
  209. xfs_log_iovec_t *vecp;
  210. xfs_buf_t *bp;
  211. int first_bit;
  212. int last_bit;
  213. int next_bit;
  214. uint nbits;
  215. uint buffer_offset;
  216. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  217. ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
  218. (bip->bli_flags & XFS_BLI_STALE));
  219. bp = bip->bli_buf;
  220. ASSERT(XFS_BUF_BP_ISMAPPED(bp));
  221. vecp = log_vector;
  222. /*
  223. * The size of the base structure is the size of the
  224. * declared structure plus the space for the extra words
  225. * of the bitmap. We subtract one from the map size, because
  226. * the first element of the bitmap is accounted for in the
  227. * size of the base structure.
  228. */
  229. base_size =
  230. (uint)(sizeof(xfs_buf_log_format_t) +
  231. ((bip->bli_format.blf_map_size - 1) * sizeof(uint)));
  232. vecp->i_addr = (xfs_caddr_t)&bip->bli_format;
  233. vecp->i_len = base_size;
  234. XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_BFORMAT);
  235. vecp++;
  236. nvecs = 1;
  237. if (bip->bli_flags & XFS_BLI_STALE) {
  238. /*
  239. * The buffer is stale, so all we need to log
  240. * is the buf log format structure with the
  241. * cancel flag in it.
  242. */
  243. xfs_buf_item_trace("FORMAT STALE", bip);
  244. ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
  245. bip->bli_format.blf_size = nvecs;
  246. return;
  247. }
  248. /*
  249. * Fill in an iovec for each set of contiguous chunks.
  250. */
  251. first_bit = xfs_next_bit(bip->bli_format.blf_data_map,
  252. bip->bli_format.blf_map_size, 0);
  253. ASSERT(first_bit != -1);
  254. last_bit = first_bit;
  255. nbits = 1;
  256. for (;;) {
  257. /*
  258. * This takes the bit number to start looking from and
  259. * returns the next set bit from there. It returns -1
  260. * if there are no more bits set or the start bit is
  261. * beyond the end of the bitmap.
  262. */
  263. next_bit = xfs_next_bit(bip->bli_format.blf_data_map,
  264. bip->bli_format.blf_map_size,
  265. (uint)last_bit + 1);
  266. /*
  267. * If we run out of bits fill in the last iovec and get
  268. * out of the loop.
  269. * Else if we start a new set of bits then fill in the
  270. * iovec for the series we were looking at and start
  271. * counting the bits in the new one.
  272. * Else we're still in the same set of bits so just
  273. * keep counting and scanning.
  274. */
  275. if (next_bit == -1) {
  276. buffer_offset = first_bit * XFS_BLI_CHUNK;
  277. vecp->i_addr = xfs_buf_offset(bp, buffer_offset);
  278. vecp->i_len = nbits * XFS_BLI_CHUNK;
  279. XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_BCHUNK);
  280. nvecs++;
  281. break;
  282. } else if (next_bit != last_bit + 1) {
  283. buffer_offset = first_bit * XFS_BLI_CHUNK;
  284. vecp->i_addr = xfs_buf_offset(bp, buffer_offset);
  285. vecp->i_len = nbits * XFS_BLI_CHUNK;
  286. XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_BCHUNK);
  287. nvecs++;
  288. vecp++;
  289. first_bit = next_bit;
  290. last_bit = next_bit;
  291. nbits = 1;
  292. } else if (xfs_buf_offset(bp, next_bit << XFS_BLI_SHIFT) !=
  293. (xfs_buf_offset(bp, last_bit << XFS_BLI_SHIFT) +
  294. XFS_BLI_CHUNK)) {
  295. buffer_offset = first_bit * XFS_BLI_CHUNK;
  296. vecp->i_addr = xfs_buf_offset(bp, buffer_offset);
  297. vecp->i_len = nbits * XFS_BLI_CHUNK;
  298. XLOG_VEC_SET_TYPE(vecp, XLOG_REG_TYPE_BCHUNK);
  299. /* You would think we need to bump the nvecs here too, but we do not
  300. * this number is used by recovery, and it gets confused by the boundary
  301. * split here
  302. * nvecs++;
  303. */
  304. vecp++;
  305. first_bit = next_bit;
  306. last_bit = next_bit;
  307. nbits = 1;
  308. } else {
  309. last_bit++;
  310. nbits++;
  311. }
  312. }
  313. bip->bli_format.blf_size = nvecs;
  314. /*
  315. * Check to make sure everything is consistent.
  316. */
  317. xfs_buf_item_trace("FORMAT NORM", bip);
  318. xfs_buf_item_log_check(bip);
  319. }
  320. /*
  321. * This is called to pin the buffer associated with the buf log
  322. * item in memory so it cannot be written out. Simply call bpin()
  323. * on the buffer to do this.
  324. */
  325. STATIC void
  326. xfs_buf_item_pin(
  327. xfs_buf_log_item_t *bip)
  328. {
  329. xfs_buf_t *bp;
  330. bp = bip->bli_buf;
  331. ASSERT(XFS_BUF_ISBUSY(bp));
  332. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  333. ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
  334. (bip->bli_flags & XFS_BLI_STALE));
  335. xfs_buf_item_trace("PIN", bip);
  336. xfs_buftrace("XFS_PIN", bp);
  337. xfs_bpin(bp);
  338. }
  339. /*
  340. * This is called to unpin the buffer associated with the buf log
  341. * item which was previously pinned with a call to xfs_buf_item_pin().
  342. * Just call bunpin() on the buffer to do this.
  343. *
  344. * Also drop the reference to the buf item for the current transaction.
  345. * If the XFS_BLI_STALE flag is set and we are the last reference,
  346. * then free up the buf log item and unlock the buffer.
  347. */
  348. STATIC void
  349. xfs_buf_item_unpin(
  350. xfs_buf_log_item_t *bip,
  351. int stale)
  352. {
  353. xfs_mount_t *mp;
  354. xfs_buf_t *bp;
  355. int freed;
  356. SPLDECL(s);
  357. bp = bip->bli_buf;
  358. ASSERT(bp != NULL);
  359. ASSERT(XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *) == bip);
  360. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  361. xfs_buf_item_trace("UNPIN", bip);
  362. xfs_buftrace("XFS_UNPIN", bp);
  363. freed = atomic_dec_and_test(&bip->bli_refcount);
  364. mp = bip->bli_item.li_mountp;
  365. xfs_bunpin(bp);
  366. if (freed && stale) {
  367. ASSERT(bip->bli_flags & XFS_BLI_STALE);
  368. ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
  369. ASSERT(!(XFS_BUF_ISDELAYWRITE(bp)));
  370. ASSERT(XFS_BUF_ISSTALE(bp));
  371. ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
  372. xfs_buf_item_trace("UNPIN STALE", bip);
  373. xfs_buftrace("XFS_UNPIN STALE", bp);
  374. /*
  375. * If we get called here because of an IO error, we may
  376. * or may not have the item on the AIL. xfs_trans_delete_ail()
  377. * will take care of that situation.
  378. * xfs_trans_delete_ail() drops the AIL lock.
  379. */
  380. if (bip->bli_flags & XFS_BLI_STALE_INODE) {
  381. xfs_buf_do_callbacks(bp, (xfs_log_item_t *)bip);
  382. XFS_BUF_SET_FSPRIVATE(bp, NULL);
  383. XFS_BUF_CLR_IODONE_FUNC(bp);
  384. } else {
  385. AIL_LOCK(mp,s);
  386. xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip, s);
  387. xfs_buf_item_relse(bp);
  388. ASSERT(XFS_BUF_FSPRIVATE(bp, void *) == NULL);
  389. }
  390. xfs_buf_relse(bp);
  391. }
  392. }
  393. /*
  394. * this is called from uncommit in the forced-shutdown path.
  395. * we need to check to see if the reference count on the log item
  396. * is going to drop to zero. If so, unpin will free the log item
  397. * so we need to free the item's descriptor (that points to the item)
  398. * in the transaction.
  399. */
  400. STATIC void
  401. xfs_buf_item_unpin_remove(
  402. xfs_buf_log_item_t *bip,
  403. xfs_trans_t *tp)
  404. {
  405. xfs_buf_t *bp;
  406. xfs_log_item_desc_t *lidp;
  407. int stale = 0;
  408. bp = bip->bli_buf;
  409. /*
  410. * will xfs_buf_item_unpin() call xfs_buf_item_relse()?
  411. */
  412. if ((atomic_read(&bip->bli_refcount) == 1) &&
  413. (bip->bli_flags & XFS_BLI_STALE)) {
  414. ASSERT(XFS_BUF_VALUSEMA(bip->bli_buf) <= 0);
  415. xfs_buf_item_trace("UNPIN REMOVE", bip);
  416. xfs_buftrace("XFS_UNPIN_REMOVE", bp);
  417. /*
  418. * yes -- clear the xaction descriptor in-use flag
  419. * and free the chunk if required. We can safely
  420. * do some work here and then call buf_item_unpin
  421. * to do the rest because if the if is true, then
  422. * we are holding the buffer locked so no one else
  423. * will be able to bump up the refcount.
  424. */
  425. lidp = xfs_trans_find_item(tp, (xfs_log_item_t *) bip);
  426. stale = lidp->lid_flags & XFS_LID_BUF_STALE;
  427. xfs_trans_free_item(tp, lidp);
  428. /*
  429. * Since the transaction no longer refers to the buffer,
  430. * the buffer should no longer refer to the transaction.
  431. */
  432. XFS_BUF_SET_FSPRIVATE2(bp, NULL);
  433. }
  434. xfs_buf_item_unpin(bip, stale);
  435. return;
  436. }
  437. /*
  438. * This is called to attempt to lock the buffer associated with this
  439. * buf log item. Don't sleep on the buffer lock. If we can't get
  440. * the lock right away, return 0. If we can get the lock, pull the
  441. * buffer from the free list, mark it busy, and return 1.
  442. */
  443. STATIC uint
  444. xfs_buf_item_trylock(
  445. xfs_buf_log_item_t *bip)
  446. {
  447. xfs_buf_t *bp;
  448. bp = bip->bli_buf;
  449. if (XFS_BUF_ISPINNED(bp)) {
  450. return XFS_ITEM_PINNED;
  451. }
  452. if (!XFS_BUF_CPSEMA(bp)) {
  453. return XFS_ITEM_LOCKED;
  454. }
  455. /*
  456. * Remove the buffer from the free list. Only do this
  457. * if it's on the free list. Private buffers like the
  458. * superblock buffer are not.
  459. */
  460. XFS_BUF_HOLD(bp);
  461. ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
  462. xfs_buf_item_trace("TRYLOCK SUCCESS", bip);
  463. return XFS_ITEM_SUCCESS;
  464. }
  465. /*
  466. * Release the buffer associated with the buf log item.
  467. * If there is no dirty logged data associated with the
  468. * buffer recorded in the buf log item, then free the
  469. * buf log item and remove the reference to it in the
  470. * buffer.
  471. *
  472. * This call ignores the recursion count. It is only called
  473. * when the buffer should REALLY be unlocked, regardless
  474. * of the recursion count.
  475. *
  476. * If the XFS_BLI_HOLD flag is set in the buf log item, then
  477. * free the log item if necessary but do not unlock the buffer.
  478. * This is for support of xfs_trans_bhold(). Make sure the
  479. * XFS_BLI_HOLD field is cleared if we don't free the item.
  480. */
  481. STATIC void
  482. xfs_buf_item_unlock(
  483. xfs_buf_log_item_t *bip)
  484. {
  485. int aborted;
  486. xfs_buf_t *bp;
  487. uint hold;
  488. bp = bip->bli_buf;
  489. xfs_buftrace("XFS_UNLOCK", bp);
  490. /*
  491. * Clear the buffer's association with this transaction.
  492. */
  493. XFS_BUF_SET_FSPRIVATE2(bp, NULL);
  494. /*
  495. * If this is a transaction abort, don't return early.
  496. * Instead, allow the brelse to happen.
  497. * Normally it would be done for stale (cancelled) buffers
  498. * at unpin time, but we'll never go through the pin/unpin
  499. * cycle if we abort inside commit.
  500. */
  501. aborted = (bip->bli_item.li_flags & XFS_LI_ABORTED) != 0;
  502. /*
  503. * If the buf item is marked stale, then don't do anything.
  504. * We'll unlock the buffer and free the buf item when the
  505. * buffer is unpinned for the last time.
  506. */
  507. if (bip->bli_flags & XFS_BLI_STALE) {
  508. bip->bli_flags &= ~XFS_BLI_LOGGED;
  509. xfs_buf_item_trace("UNLOCK STALE", bip);
  510. ASSERT(bip->bli_format.blf_flags & XFS_BLI_CANCEL);
  511. if (!aborted)
  512. return;
  513. }
  514. /*
  515. * Drop the transaction's reference to the log item if
  516. * it was not logged as part of the transaction. Otherwise
  517. * we'll drop the reference in xfs_buf_item_unpin() when
  518. * the transaction is really through with the buffer.
  519. */
  520. if (!(bip->bli_flags & XFS_BLI_LOGGED)) {
  521. atomic_dec(&bip->bli_refcount);
  522. } else {
  523. /*
  524. * Clear the logged flag since this is per
  525. * transaction state.
  526. */
  527. bip->bli_flags &= ~XFS_BLI_LOGGED;
  528. }
  529. /*
  530. * Before possibly freeing the buf item, determine if we should
  531. * release the buffer at the end of this routine.
  532. */
  533. hold = bip->bli_flags & XFS_BLI_HOLD;
  534. xfs_buf_item_trace("UNLOCK", bip);
  535. /*
  536. * If the buf item isn't tracking any data, free it.
  537. * Otherwise, if XFS_BLI_HOLD is set clear it.
  538. */
  539. if (xfs_count_bits(bip->bli_format.blf_data_map,
  540. bip->bli_format.blf_map_size, 0) == 0) {
  541. xfs_buf_item_relse(bp);
  542. } else if (hold) {
  543. bip->bli_flags &= ~XFS_BLI_HOLD;
  544. }
  545. /*
  546. * Release the buffer if XFS_BLI_HOLD was not set.
  547. */
  548. if (!hold) {
  549. xfs_buf_relse(bp);
  550. }
  551. }
  552. /*
  553. * This is called to find out where the oldest active copy of the
  554. * buf log item in the on disk log resides now that the last log
  555. * write of it completed at the given lsn.
  556. * We always re-log all the dirty data in a buffer, so usually the
  557. * latest copy in the on disk log is the only one that matters. For
  558. * those cases we simply return the given lsn.
  559. *
  560. * The one exception to this is for buffers full of newly allocated
  561. * inodes. These buffers are only relogged with the XFS_BLI_INODE_BUF
  562. * flag set, indicating that only the di_next_unlinked fields from the
  563. * inodes in the buffers will be replayed during recovery. If the
  564. * original newly allocated inode images have not yet been flushed
  565. * when the buffer is so relogged, then we need to make sure that we
  566. * keep the old images in the 'active' portion of the log. We do this
  567. * by returning the original lsn of that transaction here rather than
  568. * the current one.
  569. */
  570. STATIC xfs_lsn_t
  571. xfs_buf_item_committed(
  572. xfs_buf_log_item_t *bip,
  573. xfs_lsn_t lsn)
  574. {
  575. xfs_buf_item_trace("COMMITTED", bip);
  576. if ((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) &&
  577. (bip->bli_item.li_lsn != 0)) {
  578. return bip->bli_item.li_lsn;
  579. }
  580. return (lsn);
  581. }
  582. /*
  583. * This is called when the transaction holding the buffer is aborted.
  584. * Just behave as if the transaction had been cancelled. If we're shutting down
  585. * and have aborted this transaction, we'll trap this buffer when it tries to
  586. * get written out.
  587. */
  588. STATIC void
  589. xfs_buf_item_abort(
  590. xfs_buf_log_item_t *bip)
  591. {
  592. xfs_buf_t *bp;
  593. bp = bip->bli_buf;
  594. xfs_buftrace("XFS_ABORT", bp);
  595. XFS_BUF_SUPER_STALE(bp);
  596. xfs_buf_item_unlock(bip);
  597. return;
  598. }
  599. /*
  600. * This is called to asynchronously write the buffer associated with this
  601. * buf log item out to disk. The buffer will already have been locked by
  602. * a successful call to xfs_buf_item_trylock(). If the buffer still has
  603. * B_DELWRI set, then get it going out to disk with a call to bawrite().
  604. * If not, then just release the buffer.
  605. */
  606. STATIC void
  607. xfs_buf_item_push(
  608. xfs_buf_log_item_t *bip)
  609. {
  610. xfs_buf_t *bp;
  611. ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
  612. xfs_buf_item_trace("PUSH", bip);
  613. bp = bip->bli_buf;
  614. if (XFS_BUF_ISDELAYWRITE(bp)) {
  615. xfs_bawrite(bip->bli_item.li_mountp, bp);
  616. } else {
  617. xfs_buf_relse(bp);
  618. }
  619. }
  620. /* ARGSUSED */
  621. STATIC void
  622. xfs_buf_item_committing(xfs_buf_log_item_t *bip, xfs_lsn_t commit_lsn)
  623. {
  624. }
  625. /*
  626. * This is the ops vector shared by all buf log items.
  627. */
  628. STATIC struct xfs_item_ops xfs_buf_item_ops = {
  629. .iop_size = (uint(*)(xfs_log_item_t*))xfs_buf_item_size,
  630. .iop_format = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
  631. xfs_buf_item_format,
  632. .iop_pin = (void(*)(xfs_log_item_t*))xfs_buf_item_pin,
  633. .iop_unpin = (void(*)(xfs_log_item_t*, int))xfs_buf_item_unpin,
  634. .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t *))
  635. xfs_buf_item_unpin_remove,
  636. .iop_trylock = (uint(*)(xfs_log_item_t*))xfs_buf_item_trylock,
  637. .iop_unlock = (void(*)(xfs_log_item_t*))xfs_buf_item_unlock,
  638. .iop_committed = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
  639. xfs_buf_item_committed,
  640. .iop_push = (void(*)(xfs_log_item_t*))xfs_buf_item_push,
  641. .iop_abort = (void(*)(xfs_log_item_t*))xfs_buf_item_abort,
  642. .iop_pushbuf = NULL,
  643. .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
  644. xfs_buf_item_committing
  645. };
  646. /*
  647. * Allocate a new buf log item to go with the given buffer.
  648. * Set the buffer's b_fsprivate field to point to the new
  649. * buf log item. If there are other item's attached to the
  650. * buffer (see xfs_buf_attach_iodone() below), then put the
  651. * buf log item at the front.
  652. */
  653. void
  654. xfs_buf_item_init(
  655. xfs_buf_t *bp,
  656. xfs_mount_t *mp)
  657. {
  658. xfs_log_item_t *lip;
  659. xfs_buf_log_item_t *bip;
  660. int chunks;
  661. int map_size;
  662. /*
  663. * Check to see if there is already a buf log item for
  664. * this buffer. If there is, it is guaranteed to be
  665. * the first. If we do already have one, there is
  666. * nothing to do here so return.
  667. */
  668. if (XFS_BUF_FSPRIVATE3(bp, xfs_mount_t *) != mp)
  669. XFS_BUF_SET_FSPRIVATE3(bp, mp);
  670. XFS_BUF_SET_BDSTRAT_FUNC(bp, xfs_bdstrat_cb);
  671. if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
  672. lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
  673. if (lip->li_type == XFS_LI_BUF) {
  674. return;
  675. }
  676. }
  677. /*
  678. * chunks is the number of XFS_BLI_CHUNK size pieces
  679. * the buffer can be divided into. Make sure not to
  680. * truncate any pieces. map_size is the size of the
  681. * bitmap needed to describe the chunks of the buffer.
  682. */
  683. chunks = (int)((XFS_BUF_COUNT(bp) + (XFS_BLI_CHUNK - 1)) >> XFS_BLI_SHIFT);
  684. map_size = (int)((chunks + NBWORD) >> BIT_TO_WORD_SHIFT);
  685. bip = (xfs_buf_log_item_t*)kmem_zone_zalloc(xfs_buf_item_zone,
  686. KM_SLEEP);
  687. bip->bli_item.li_type = XFS_LI_BUF;
  688. bip->bli_item.li_ops = &xfs_buf_item_ops;
  689. bip->bli_item.li_mountp = mp;
  690. bip->bli_buf = bp;
  691. bip->bli_format.blf_type = XFS_LI_BUF;
  692. bip->bli_format.blf_blkno = (__int64_t)XFS_BUF_ADDR(bp);
  693. bip->bli_format.blf_len = (ushort)BTOBB(XFS_BUF_COUNT(bp));
  694. bip->bli_format.blf_map_size = map_size;
  695. #ifdef XFS_BLI_TRACE
  696. bip->bli_trace = ktrace_alloc(XFS_BLI_TRACE_SIZE, KM_SLEEP);
  697. #endif
  698. #ifdef XFS_TRANS_DEBUG
  699. /*
  700. * Allocate the arrays for tracking what needs to be logged
  701. * and what our callers request to be logged. bli_orig
  702. * holds a copy of the original, clean buffer for comparison
  703. * against, and bli_logged keeps a 1 bit flag per byte in
  704. * the buffer to indicate which bytes the callers have asked
  705. * to have logged.
  706. */
  707. bip->bli_orig = (char *)kmem_alloc(XFS_BUF_COUNT(bp), KM_SLEEP);
  708. memcpy(bip->bli_orig, XFS_BUF_PTR(bp), XFS_BUF_COUNT(bp));
  709. bip->bli_logged = (char *)kmem_zalloc(XFS_BUF_COUNT(bp) / NBBY, KM_SLEEP);
  710. #endif
  711. /*
  712. * Put the buf item into the list of items attached to the
  713. * buffer at the front.
  714. */
  715. if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
  716. bip->bli_item.li_bio_list =
  717. XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
  718. }
  719. XFS_BUF_SET_FSPRIVATE(bp, bip);
  720. }
  721. /*
  722. * Mark bytes first through last inclusive as dirty in the buf
  723. * item's bitmap.
  724. */
  725. void
  726. xfs_buf_item_log(
  727. xfs_buf_log_item_t *bip,
  728. uint first,
  729. uint last)
  730. {
  731. uint first_bit;
  732. uint last_bit;
  733. uint bits_to_set;
  734. uint bits_set;
  735. uint word_num;
  736. uint *wordp;
  737. uint bit;
  738. uint end_bit;
  739. uint mask;
  740. /*
  741. * Mark the item as having some dirty data for
  742. * quick reference in xfs_buf_item_dirty.
  743. */
  744. bip->bli_flags |= XFS_BLI_DIRTY;
  745. /*
  746. * Convert byte offsets to bit numbers.
  747. */
  748. first_bit = first >> XFS_BLI_SHIFT;
  749. last_bit = last >> XFS_BLI_SHIFT;
  750. /*
  751. * Calculate the total number of bits to be set.
  752. */
  753. bits_to_set = last_bit - first_bit + 1;
  754. /*
  755. * Get a pointer to the first word in the bitmap
  756. * to set a bit in.
  757. */
  758. word_num = first_bit >> BIT_TO_WORD_SHIFT;
  759. wordp = &(bip->bli_format.blf_data_map[word_num]);
  760. /*
  761. * Calculate the starting bit in the first word.
  762. */
  763. bit = first_bit & (uint)(NBWORD - 1);
  764. /*
  765. * First set any bits in the first word of our range.
  766. * If it starts at bit 0 of the word, it will be
  767. * set below rather than here. That is what the variable
  768. * bit tells us. The variable bits_set tracks the number
  769. * of bits that have been set so far. End_bit is the number
  770. * of the last bit to be set in this word plus one.
  771. */
  772. if (bit) {
  773. end_bit = MIN(bit + bits_to_set, (uint)NBWORD);
  774. mask = ((1 << (end_bit - bit)) - 1) << bit;
  775. *wordp |= mask;
  776. wordp++;
  777. bits_set = end_bit - bit;
  778. } else {
  779. bits_set = 0;
  780. }
  781. /*
  782. * Now set bits a whole word at a time that are between
  783. * first_bit and last_bit.
  784. */
  785. while ((bits_to_set - bits_set) >= NBWORD) {
  786. *wordp |= 0xffffffff;
  787. bits_set += NBWORD;
  788. wordp++;
  789. }
  790. /*
  791. * Finally, set any bits left to be set in one last partial word.
  792. */
  793. end_bit = bits_to_set - bits_set;
  794. if (end_bit) {
  795. mask = (1 << end_bit) - 1;
  796. *wordp |= mask;
  797. }
  798. xfs_buf_item_log_debug(bip, first, last);
  799. }
  800. /*
  801. * Return 1 if the buffer has some data that has been logged (at any
  802. * point, not just the current transaction) and 0 if not.
  803. */
  804. uint
  805. xfs_buf_item_dirty(
  806. xfs_buf_log_item_t *bip)
  807. {
  808. return (bip->bli_flags & XFS_BLI_DIRTY);
  809. }
  810. /*
  811. * This is called when the buf log item is no longer needed. It should
  812. * free the buf log item associated with the given buffer and clear
  813. * the buffer's pointer to the buf log item. If there are no more
  814. * items in the list, clear the b_iodone field of the buffer (see
  815. * xfs_buf_attach_iodone() below).
  816. */
  817. void
  818. xfs_buf_item_relse(
  819. xfs_buf_t *bp)
  820. {
  821. xfs_buf_log_item_t *bip;
  822. xfs_buftrace("XFS_RELSE", bp);
  823. bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t*);
  824. XFS_BUF_SET_FSPRIVATE(bp, bip->bli_item.li_bio_list);
  825. if ((XFS_BUF_FSPRIVATE(bp, void *) == NULL) &&
  826. (XFS_BUF_IODONE_FUNC(bp) != NULL)) {
  827. ASSERT((XFS_BUF_ISUNINITIAL(bp)) == 0);
  828. XFS_BUF_CLR_IODONE_FUNC(bp);
  829. }
  830. #ifdef XFS_TRANS_DEBUG
  831. kmem_free(bip->bli_orig, XFS_BUF_COUNT(bp));
  832. bip->bli_orig = NULL;
  833. kmem_free(bip->bli_logged, XFS_BUF_COUNT(bp) / NBBY);
  834. bip->bli_logged = NULL;
  835. #endif /* XFS_TRANS_DEBUG */
  836. #ifdef XFS_BLI_TRACE
  837. ktrace_free(bip->bli_trace);
  838. #endif
  839. kmem_zone_free(xfs_buf_item_zone, bip);
  840. }
  841. /*
  842. * Add the given log item with its callback to the list of callbacks
  843. * to be called when the buffer's I/O completes. If it is not set
  844. * already, set the buffer's b_iodone() routine to be
  845. * xfs_buf_iodone_callbacks() and link the log item into the list of
  846. * items rooted at b_fsprivate. Items are always added as the second
  847. * entry in the list if there is a first, because the buf item code
  848. * assumes that the buf log item is first.
  849. */
  850. void
  851. xfs_buf_attach_iodone(
  852. xfs_buf_t *bp,
  853. void (*cb)(xfs_buf_t *, xfs_log_item_t *),
  854. xfs_log_item_t *lip)
  855. {
  856. xfs_log_item_t *head_lip;
  857. ASSERT(XFS_BUF_ISBUSY(bp));
  858. ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
  859. lip->li_cb = cb;
  860. if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
  861. head_lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
  862. lip->li_bio_list = head_lip->li_bio_list;
  863. head_lip->li_bio_list = lip;
  864. } else {
  865. XFS_BUF_SET_FSPRIVATE(bp, lip);
  866. }
  867. ASSERT((XFS_BUF_IODONE_FUNC(bp) == xfs_buf_iodone_callbacks) ||
  868. (XFS_BUF_IODONE_FUNC(bp) == NULL));
  869. XFS_BUF_SET_IODONE_FUNC(bp, xfs_buf_iodone_callbacks);
  870. }
  871. STATIC void
  872. xfs_buf_do_callbacks(
  873. xfs_buf_t *bp,
  874. xfs_log_item_t *lip)
  875. {
  876. xfs_log_item_t *nlip;
  877. while (lip != NULL) {
  878. nlip = lip->li_bio_list;
  879. ASSERT(lip->li_cb != NULL);
  880. /*
  881. * Clear the next pointer so we don't have any
  882. * confusion if the item is added to another buf.
  883. * Don't touch the log item after calling its
  884. * callback, because it could have freed itself.
  885. */
  886. lip->li_bio_list = NULL;
  887. lip->li_cb(bp, lip);
  888. lip = nlip;
  889. }
  890. }
  891. /*
  892. * This is the iodone() function for buffers which have had callbacks
  893. * attached to them by xfs_buf_attach_iodone(). It should remove each
  894. * log item from the buffer's list and call the callback of each in turn.
  895. * When done, the buffer's fsprivate field is set to NULL and the buffer
  896. * is unlocked with a call to iodone().
  897. */
  898. void
  899. xfs_buf_iodone_callbacks(
  900. xfs_buf_t *bp)
  901. {
  902. xfs_log_item_t *lip;
  903. static ulong lasttime;
  904. static xfs_buftarg_t *lasttarg;
  905. xfs_mount_t *mp;
  906. ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
  907. lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
  908. if (XFS_BUF_GETERROR(bp) != 0) {
  909. /*
  910. * If we've already decided to shutdown the filesystem
  911. * because of IO errors, there's no point in giving this
  912. * a retry.
  913. */
  914. mp = lip->li_mountp;
  915. if (XFS_FORCED_SHUTDOWN(mp)) {
  916. ASSERT(XFS_BUF_TARGET(bp) == mp->m_ddev_targp);
  917. XFS_BUF_SUPER_STALE(bp);
  918. xfs_buftrace("BUF_IODONE_CB", bp);
  919. xfs_buf_do_callbacks(bp, lip);
  920. XFS_BUF_SET_FSPRIVATE(bp, NULL);
  921. XFS_BUF_CLR_IODONE_FUNC(bp);
  922. /*
  923. * XFS_SHUT flag gets set when we go thru the
  924. * entire buffer cache and deliberately start
  925. * throwing away delayed write buffers.
  926. * Since there's no biowait done on those,
  927. * we should just brelse them.
  928. */
  929. if (XFS_BUF_ISSHUT(bp)) {
  930. XFS_BUF_UNSHUT(bp);
  931. xfs_buf_relse(bp);
  932. } else {
  933. xfs_biodone(bp);
  934. }
  935. return;
  936. }
  937. if ((XFS_BUF_TARGET(bp) != lasttarg) ||
  938. (time_after(jiffies, (lasttime + 5*HZ)))) {
  939. lasttime = jiffies;
  940. cmn_err(CE_ALERT, "Device %s, XFS metadata write error"
  941. " block 0x%llx in %s",
  942. XFS_BUFTARG_NAME(XFS_BUF_TARGET(bp)),
  943. (__uint64_t)XFS_BUF_ADDR(bp), mp->m_fsname);
  944. }
  945. lasttarg = XFS_BUF_TARGET(bp);
  946. if (XFS_BUF_ISASYNC(bp)) {
  947. /*
  948. * If the write was asynchronous then noone will be
  949. * looking for the error. Clear the error state
  950. * and write the buffer out again delayed write.
  951. *
  952. * XXXsup This is OK, so long as we catch these
  953. * before we start the umount; we don't want these
  954. * DELWRI metadata bufs to be hanging around.
  955. */
  956. XFS_BUF_ERROR(bp,0); /* errno of 0 unsets the flag */
  957. if (!(XFS_BUF_ISSTALE(bp))) {
  958. XFS_BUF_DELAYWRITE(bp);
  959. XFS_BUF_DONE(bp);
  960. XFS_BUF_SET_START(bp);
  961. }
  962. ASSERT(XFS_BUF_IODONE_FUNC(bp));
  963. xfs_buftrace("BUF_IODONE ASYNC", bp);
  964. xfs_buf_relse(bp);
  965. } else {
  966. /*
  967. * If the write of the buffer was not asynchronous,
  968. * then we want to make sure to return the error
  969. * to the caller of bwrite(). Because of this we
  970. * cannot clear the B_ERROR state at this point.
  971. * Instead we install a callback function that
  972. * will be called when the buffer is released, and
  973. * that routine will clear the error state and
  974. * set the buffer to be written out again after
  975. * some delay.
  976. */
  977. /* We actually overwrite the existing b-relse
  978. function at times, but we're gonna be shutting down
  979. anyway. */
  980. XFS_BUF_SET_BRELSE_FUNC(bp,xfs_buf_error_relse);
  981. XFS_BUF_DONE(bp);
  982. XFS_BUF_V_IODONESEMA(bp);
  983. }
  984. return;
  985. }
  986. #ifdef XFSERRORDEBUG
  987. xfs_buftrace("XFS BUFCB NOERR", bp);
  988. #endif
  989. xfs_buf_do_callbacks(bp, lip);
  990. XFS_BUF_SET_FSPRIVATE(bp, NULL);
  991. XFS_BUF_CLR_IODONE_FUNC(bp);
  992. xfs_biodone(bp);
  993. }
  994. /*
  995. * This is a callback routine attached to a buffer which gets an error
  996. * when being written out synchronously.
  997. */
  998. STATIC void
  999. xfs_buf_error_relse(
  1000. xfs_buf_t *bp)
  1001. {
  1002. xfs_log_item_t *lip;
  1003. xfs_mount_t *mp;
  1004. lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
  1005. mp = (xfs_mount_t *)lip->li_mountp;
  1006. ASSERT(XFS_BUF_TARGET(bp) == mp->m_ddev_targp);
  1007. XFS_BUF_STALE(bp);
  1008. XFS_BUF_DONE(bp);
  1009. XFS_BUF_UNDELAYWRITE(bp);
  1010. XFS_BUF_ERROR(bp,0);
  1011. xfs_buftrace("BUF_ERROR_RELSE", bp);
  1012. if (! XFS_FORCED_SHUTDOWN(mp))
  1013. xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
  1014. /*
  1015. * We have to unpin the pinned buffers so do the
  1016. * callbacks.
  1017. */
  1018. xfs_buf_do_callbacks(bp, lip);
  1019. XFS_BUF_SET_FSPRIVATE(bp, NULL);
  1020. XFS_BUF_CLR_IODONE_FUNC(bp);
  1021. XFS_BUF_SET_BRELSE_FUNC(bp,NULL);
  1022. xfs_buf_relse(bp);
  1023. }
  1024. /*
  1025. * This is the iodone() function for buffers which have been
  1026. * logged. It is called when they are eventually flushed out.
  1027. * It should remove the buf item from the AIL, and free the buf item.
  1028. * It is called by xfs_buf_iodone_callbacks() above which will take
  1029. * care of cleaning up the buffer itself.
  1030. */
  1031. /* ARGSUSED */
  1032. void
  1033. xfs_buf_iodone(
  1034. xfs_buf_t *bp,
  1035. xfs_buf_log_item_t *bip)
  1036. {
  1037. struct xfs_mount *mp;
  1038. SPLDECL(s);
  1039. ASSERT(bip->bli_buf == bp);
  1040. mp = bip->bli_item.li_mountp;
  1041. /*
  1042. * If we are forcibly shutting down, this may well be
  1043. * off the AIL already. That's because we simulate the
  1044. * log-committed callbacks to unpin these buffers. Or we may never
  1045. * have put this item on AIL because of the transaction was
  1046. * aborted forcibly. xfs_trans_delete_ail() takes care of these.
  1047. *
  1048. * Either way, AIL is useless if we're forcing a shutdown.
  1049. */
  1050. AIL_LOCK(mp,s);
  1051. /*
  1052. * xfs_trans_delete_ail() drops the AIL lock.
  1053. */
  1054. xfs_trans_delete_ail(mp, (xfs_log_item_t *)bip, s);
  1055. #ifdef XFS_TRANS_DEBUG
  1056. kmem_free(bip->bli_orig, XFS_BUF_COUNT(bp));
  1057. bip->bli_orig = NULL;
  1058. kmem_free(bip->bli_logged, XFS_BUF_COUNT(bp) / NBBY);
  1059. bip->bli_logged = NULL;
  1060. #endif /* XFS_TRANS_DEBUG */
  1061. #ifdef XFS_BLI_TRACE
  1062. ktrace_free(bip->bli_trace);
  1063. #endif
  1064. kmem_zone_free(xfs_buf_item_zone, bip);
  1065. }
  1066. #if defined(XFS_BLI_TRACE)
  1067. void
  1068. xfs_buf_item_trace(
  1069. char *id,
  1070. xfs_buf_log_item_t *bip)
  1071. {
  1072. xfs_buf_t *bp;
  1073. ASSERT(bip->bli_trace != NULL);
  1074. bp = bip->bli_buf;
  1075. ktrace_enter(bip->bli_trace,
  1076. (void *)id,
  1077. (void *)bip->bli_buf,
  1078. (void *)((unsigned long)bip->bli_flags),
  1079. (void *)((unsigned long)bip->bli_recur),
  1080. (void *)((unsigned long)atomic_read(&bip->bli_refcount)),
  1081. (void *)((unsigned long)
  1082. (0xFFFFFFFF & XFS_BUF_ADDR(bp) >> 32)),
  1083. (void *)((unsigned long)(0xFFFFFFFF & XFS_BUF_ADDR(bp))),
  1084. (void *)((unsigned long)XFS_BUF_COUNT(bp)),
  1085. (void *)((unsigned long)XFS_BUF_BFLAGS(bp)),
  1086. XFS_BUF_FSPRIVATE(bp, void *),
  1087. XFS_BUF_FSPRIVATE2(bp, void *),
  1088. (void *)(unsigned long)XFS_BUF_ISPINNED(bp),
  1089. (void *)XFS_BUF_IODONE_FUNC(bp),
  1090. (void *)((unsigned long)(XFS_BUF_VALUSEMA(bp))),
  1091. (void *)bip->bli_item.li_desc,
  1092. (void *)((unsigned long)bip->bli_item.li_flags));
  1093. }
  1094. #endif /* XFS_BLI_TRACE */