xfs_buf_item.c 33 KB

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