xfs_buf_item.c 32 KB

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