xfs_buf_item.c 33 KB

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