xfs_buf_item.c 33 KB

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