xfs_buf_item.c 33 KB

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