xfs_buf_item.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_format.h"
  21. #include "xfs_log_format.h"
  22. #include "xfs_trans_resv.h"
  23. #include "xfs_bit.h"
  24. #include "xfs_sb.h"
  25. #include "xfs_mount.h"
  26. #include "xfs_trans.h"
  27. #include "xfs_buf_item.h"
  28. #include "xfs_trans_priv.h"
  29. #include "xfs_error.h"
  30. #include "xfs_trace.h"
  31. #include "xfs_log.h"
  32. #include "xfs_inode.h"
  33. kmem_zone_t *xfs_buf_item_zone;
  34. static inline struct xfs_buf_log_item *BUF_ITEM(struct xfs_log_item *lip)
  35. {
  36. return container_of(lip, struct xfs_buf_log_item, bli_item);
  37. }
  38. STATIC void xfs_buf_do_callbacks(struct xfs_buf *bp);
  39. static inline int
  40. xfs_buf_log_format_size(
  41. struct xfs_buf_log_format *blfp)
  42. {
  43. return offsetof(struct xfs_buf_log_format, blf_data_map) +
  44. (blfp->blf_map_size * sizeof(blfp->blf_data_map[0]));
  45. }
  46. /*
  47. * This returns the number of log iovecs needed to log the
  48. * given buf log item.
  49. *
  50. * It calculates this as 1 iovec for the buf log format structure
  51. * and 1 for each stretch of non-contiguous chunks to be logged.
  52. * Contiguous chunks are logged in a single iovec.
  53. *
  54. * If the XFS_BLI_STALE flag has been set, then log nothing.
  55. */
  56. STATIC void
  57. xfs_buf_item_size_segment(
  58. struct xfs_buf_log_item *bip,
  59. struct xfs_buf_log_format *blfp,
  60. int *nvecs,
  61. int *nbytes)
  62. {
  63. struct xfs_buf *bp = bip->bli_buf;
  64. int next_bit;
  65. int last_bit;
  66. last_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size, 0);
  67. if (last_bit == -1)
  68. return;
  69. /*
  70. * initial count for a dirty buffer is 2 vectors - the format structure
  71. * and the first dirty region.
  72. */
  73. *nvecs += 2;
  74. *nbytes += xfs_buf_log_format_size(blfp) + XFS_BLF_CHUNK;
  75. while (last_bit != -1) {
  76. /*
  77. * This takes the bit number to start looking from and
  78. * returns the next set bit from there. It returns -1
  79. * if there are no more bits set or the start bit is
  80. * beyond the end of the bitmap.
  81. */
  82. next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size,
  83. last_bit + 1);
  84. /*
  85. * If we run out of bits, leave the loop,
  86. * else if we find a new set of bits bump the number of vecs,
  87. * else keep scanning the current set of bits.
  88. */
  89. if (next_bit == -1) {
  90. break;
  91. } else if (next_bit != last_bit + 1) {
  92. last_bit = next_bit;
  93. (*nvecs)++;
  94. } else if (xfs_buf_offset(bp, next_bit * XFS_BLF_CHUNK) !=
  95. (xfs_buf_offset(bp, last_bit * XFS_BLF_CHUNK) +
  96. XFS_BLF_CHUNK)) {
  97. last_bit = next_bit;
  98. (*nvecs)++;
  99. } else {
  100. last_bit++;
  101. }
  102. *nbytes += XFS_BLF_CHUNK;
  103. }
  104. }
  105. /*
  106. * This returns the number of log iovecs needed to log the given buf log item.
  107. *
  108. * It calculates this as 1 iovec for the buf log format structure and 1 for each
  109. * stretch of non-contiguous chunks to be logged. Contiguous chunks are logged
  110. * in a single iovec.
  111. *
  112. * Discontiguous buffers need a format structure per region that that is being
  113. * logged. This makes the changes in the buffer appear to log recovery as though
  114. * they came from separate buffers, just like would occur if multiple buffers
  115. * were used instead of a single discontiguous buffer. This enables
  116. * discontiguous buffers to be in-memory constructs, completely transparent to
  117. * what ends up on disk.
  118. *
  119. * If the XFS_BLI_STALE flag has been set, then log nothing but the buf log
  120. * format structures.
  121. */
  122. STATIC void
  123. xfs_buf_item_size(
  124. struct xfs_log_item *lip,
  125. int *nvecs,
  126. int *nbytes)
  127. {
  128. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  129. int i;
  130. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  131. if (bip->bli_flags & XFS_BLI_STALE) {
  132. /*
  133. * The buffer is stale, so all we need to log
  134. * is the buf log format structure with the
  135. * cancel flag in it.
  136. */
  137. trace_xfs_buf_item_size_stale(bip);
  138. ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
  139. *nvecs += bip->bli_format_count;
  140. for (i = 0; i < bip->bli_format_count; i++) {
  141. *nbytes += xfs_buf_log_format_size(&bip->bli_formats[i]);
  142. }
  143. return;
  144. }
  145. ASSERT(bip->bli_flags & XFS_BLI_LOGGED);
  146. if (bip->bli_flags & XFS_BLI_ORDERED) {
  147. /*
  148. * The buffer has been logged just to order it.
  149. * It is not being included in the transaction
  150. * commit, so no vectors are used at all.
  151. */
  152. trace_xfs_buf_item_size_ordered(bip);
  153. *nvecs = XFS_LOG_VEC_ORDERED;
  154. return;
  155. }
  156. /*
  157. * the vector count is based on the number of buffer vectors we have
  158. * dirty bits in. This will only be greater than one when we have a
  159. * compound buffer with more than one segment dirty. Hence for compound
  160. * buffers we need to track which segment the dirty bits correspond to,
  161. * and when we move from one segment to the next increment the vector
  162. * count for the extra buf log format structure that will need to be
  163. * written.
  164. */
  165. for (i = 0; i < bip->bli_format_count; i++) {
  166. xfs_buf_item_size_segment(bip, &bip->bli_formats[i],
  167. nvecs, nbytes);
  168. }
  169. trace_xfs_buf_item_size(bip);
  170. }
  171. static inline void
  172. xfs_buf_item_copy_iovec(
  173. struct xfs_log_vec *lv,
  174. struct xfs_log_iovec **vecp,
  175. struct xfs_buf *bp,
  176. uint offset,
  177. int first_bit,
  178. uint nbits)
  179. {
  180. offset += first_bit * XFS_BLF_CHUNK;
  181. xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_BCHUNK,
  182. xfs_buf_offset(bp, offset),
  183. nbits * XFS_BLF_CHUNK);
  184. }
  185. static inline bool
  186. xfs_buf_item_straddle(
  187. struct xfs_buf *bp,
  188. uint offset,
  189. int next_bit,
  190. int last_bit)
  191. {
  192. return xfs_buf_offset(bp, offset + (next_bit << XFS_BLF_SHIFT)) !=
  193. (xfs_buf_offset(bp, offset + (last_bit << XFS_BLF_SHIFT)) +
  194. XFS_BLF_CHUNK);
  195. }
  196. static void
  197. xfs_buf_item_format_segment(
  198. struct xfs_buf_log_item *bip,
  199. struct xfs_log_vec *lv,
  200. struct xfs_log_iovec **vecp,
  201. uint offset,
  202. struct xfs_buf_log_format *blfp)
  203. {
  204. struct xfs_buf *bp = bip->bli_buf;
  205. uint base_size;
  206. int first_bit;
  207. int last_bit;
  208. int next_bit;
  209. uint nbits;
  210. /* copy the flags across from the base format item */
  211. blfp->blf_flags = bip->__bli_format.blf_flags;
  212. /*
  213. * Base size is the actual size of the ondisk structure - it reflects
  214. * the actual size of the dirty bitmap rather than the size of the in
  215. * memory structure.
  216. */
  217. base_size = xfs_buf_log_format_size(blfp);
  218. first_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size, 0);
  219. if (!(bip->bli_flags & XFS_BLI_STALE) && first_bit == -1) {
  220. /*
  221. * If the map is not be dirty in the transaction, mark
  222. * the size as zero and do not advance the vector pointer.
  223. */
  224. return;
  225. }
  226. blfp = xlog_copy_iovec(lv, vecp, XLOG_REG_TYPE_BFORMAT, blfp, base_size);
  227. blfp->blf_size = 1;
  228. if (bip->bli_flags & XFS_BLI_STALE) {
  229. /*
  230. * The buffer is stale, so all we need to log
  231. * is the buf log format structure with the
  232. * cancel flag in it.
  233. */
  234. trace_xfs_buf_item_format_stale(bip);
  235. ASSERT(blfp->blf_flags & XFS_BLF_CANCEL);
  236. return;
  237. }
  238. /*
  239. * Fill in an iovec for each set of contiguous chunks.
  240. */
  241. last_bit = first_bit;
  242. nbits = 1;
  243. for (;;) {
  244. /*
  245. * This takes the bit number to start looking from and
  246. * returns the next set bit from there. It returns -1
  247. * if there are no more bits set or the start bit is
  248. * beyond the end of the bitmap.
  249. */
  250. next_bit = xfs_next_bit(blfp->blf_data_map, blfp->blf_map_size,
  251. (uint)last_bit + 1);
  252. /*
  253. * If we run out of bits fill in the last iovec and get out of
  254. * the loop. Else if we start a new set of bits then fill in
  255. * the iovec for the series we were looking at and start
  256. * counting the bits in the new one. Else we're still in the
  257. * same set of bits so just keep counting and scanning.
  258. */
  259. if (next_bit == -1) {
  260. xfs_buf_item_copy_iovec(lv, vecp, bp, offset,
  261. first_bit, nbits);
  262. blfp->blf_size++;
  263. break;
  264. } else if (next_bit != last_bit + 1 ||
  265. xfs_buf_item_straddle(bp, offset, next_bit, last_bit)) {
  266. xfs_buf_item_copy_iovec(lv, vecp, bp, offset,
  267. first_bit, nbits);
  268. blfp->blf_size++;
  269. first_bit = next_bit;
  270. last_bit = next_bit;
  271. nbits = 1;
  272. } else {
  273. last_bit++;
  274. nbits++;
  275. }
  276. }
  277. }
  278. /*
  279. * This is called to fill in the vector of log iovecs for the
  280. * given log buf item. It fills the first entry with a buf log
  281. * format structure, and the rest point to contiguous chunks
  282. * within the buffer.
  283. */
  284. STATIC void
  285. xfs_buf_item_format(
  286. struct xfs_log_item *lip,
  287. struct xfs_log_vec *lv)
  288. {
  289. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  290. struct xfs_buf *bp = bip->bli_buf;
  291. struct xfs_log_iovec *vecp = NULL;
  292. uint offset = 0;
  293. int i;
  294. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  295. ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
  296. (bip->bli_flags & XFS_BLI_STALE));
  297. ASSERT((bip->bli_flags & XFS_BLI_STALE) ||
  298. (xfs_blft_from_flags(&bip->__bli_format) > XFS_BLFT_UNKNOWN_BUF
  299. && xfs_blft_from_flags(&bip->__bli_format) < XFS_BLFT_MAX_BUF));
  300. ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED) ||
  301. (bip->bli_flags & XFS_BLI_STALE));
  302. /*
  303. * If it is an inode buffer, transfer the in-memory state to the
  304. * format flags and clear the in-memory state.
  305. *
  306. * For buffer based inode allocation, we do not transfer
  307. * this state if the inode buffer allocation has not yet been committed
  308. * to the log as setting the XFS_BLI_INODE_BUF flag will prevent
  309. * correct replay of the inode allocation.
  310. *
  311. * For icreate item based inode allocation, the buffers aren't written
  312. * to the journal during allocation, and hence we should always tag the
  313. * buffer as an inode buffer so that the correct unlinked list replay
  314. * occurs during recovery.
  315. */
  316. if (bip->bli_flags & XFS_BLI_INODE_BUF) {
  317. if (xfs_sb_version_hascrc(&lip->li_mountp->m_sb) ||
  318. !((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) &&
  319. xfs_log_item_in_current_chkpt(lip)))
  320. bip->__bli_format.blf_flags |= XFS_BLF_INODE_BUF;
  321. bip->bli_flags &= ~XFS_BLI_INODE_BUF;
  322. }
  323. for (i = 0; i < bip->bli_format_count; i++) {
  324. xfs_buf_item_format_segment(bip, lv, &vecp, offset,
  325. &bip->bli_formats[i]);
  326. offset += BBTOB(bp->b_maps[i].bm_len);
  327. }
  328. /*
  329. * Check to make sure everything is consistent.
  330. */
  331. trace_xfs_buf_item_format(bip);
  332. }
  333. /*
  334. * This is called to pin the buffer associated with the buf log item in memory
  335. * so it cannot be written out.
  336. *
  337. * We also always take a reference to the buffer log item here so that the bli
  338. * is held while the item is pinned in memory. This means that we can
  339. * unconditionally drop the reference count a transaction holds when the
  340. * transaction is completed.
  341. */
  342. STATIC void
  343. xfs_buf_item_pin(
  344. struct xfs_log_item *lip)
  345. {
  346. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  347. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  348. ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
  349. (bip->bli_flags & XFS_BLI_ORDERED) ||
  350. (bip->bli_flags & XFS_BLI_STALE));
  351. trace_xfs_buf_item_pin(bip);
  352. atomic_inc(&bip->bli_refcount);
  353. atomic_inc(&bip->bli_buf->b_pin_count);
  354. }
  355. /*
  356. * This is called to unpin the buffer associated with the buf log
  357. * item which was previously pinned with a call to xfs_buf_item_pin().
  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. * If the remove flag is set we are called from uncommit in the
  364. * forced-shutdown path. If that is true and the reference count on
  365. * the log item is going to drop to zero we need to free the item's
  366. * descriptor in the transaction.
  367. */
  368. STATIC void
  369. xfs_buf_item_unpin(
  370. struct xfs_log_item *lip,
  371. int remove)
  372. {
  373. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  374. xfs_buf_t *bp = bip->bli_buf;
  375. struct xfs_ail *ailp = lip->li_ailp;
  376. int stale = bip->bli_flags & XFS_BLI_STALE;
  377. int freed;
  378. ASSERT(bp->b_fspriv == bip);
  379. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  380. trace_xfs_buf_item_unpin(bip);
  381. freed = atomic_dec_and_test(&bip->bli_refcount);
  382. if (atomic_dec_and_test(&bp->b_pin_count))
  383. wake_up_all(&bp->b_waiters);
  384. if (freed && stale) {
  385. ASSERT(bip->bli_flags & XFS_BLI_STALE);
  386. ASSERT(xfs_buf_islocked(bp));
  387. ASSERT(bp->b_flags & XBF_STALE);
  388. ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
  389. trace_xfs_buf_item_unpin_stale(bip);
  390. if (remove) {
  391. /*
  392. * If we are in a transaction context, we have to
  393. * remove the log item from the transaction as we are
  394. * about to release our reference to the buffer. If we
  395. * don't, the unlock that occurs later in
  396. * xfs_trans_uncommit() will try to reference the
  397. * buffer which we no longer have a hold on.
  398. */
  399. if (lip->li_desc)
  400. xfs_trans_del_item(lip);
  401. /*
  402. * Since the transaction no longer refers to the buffer,
  403. * the buffer should no longer refer to the transaction.
  404. */
  405. bp->b_transp = NULL;
  406. }
  407. /*
  408. * If we get called here because of an IO error, we may
  409. * or may not have the item on the AIL. xfs_trans_ail_delete()
  410. * will take care of that situation.
  411. * xfs_trans_ail_delete() drops the AIL lock.
  412. */
  413. if (bip->bli_flags & XFS_BLI_STALE_INODE) {
  414. xfs_buf_do_callbacks(bp);
  415. bp->b_fspriv = NULL;
  416. bp->b_iodone = NULL;
  417. } else {
  418. spin_lock(&ailp->xa_lock);
  419. xfs_trans_ail_delete(ailp, lip, SHUTDOWN_LOG_IO_ERROR);
  420. xfs_buf_item_relse(bp);
  421. ASSERT(bp->b_fspriv == NULL);
  422. }
  423. xfs_buf_relse(bp);
  424. } else if (freed && remove) {
  425. /*
  426. * There are currently two references to the buffer - the active
  427. * LRU reference and the buf log item. What we are about to do
  428. * here - simulate a failed IO completion - requires 3
  429. * references.
  430. *
  431. * The LRU reference is removed by the xfs_buf_stale() call. The
  432. * buf item reference is removed by the xfs_buf_iodone()
  433. * callback that is run by xfs_buf_do_callbacks() during ioend
  434. * processing (via the bp->b_iodone callback), and then finally
  435. * the ioend processing will drop the IO reference if the buffer
  436. * is marked XBF_ASYNC.
  437. *
  438. * Hence we need to take an additional reference here so that IO
  439. * completion processing doesn't free the buffer prematurely.
  440. */
  441. xfs_buf_lock(bp);
  442. xfs_buf_hold(bp);
  443. bp->b_flags |= XBF_ASYNC;
  444. xfs_buf_ioerror(bp, -EIO);
  445. bp->b_flags &= ~XBF_DONE;
  446. xfs_buf_stale(bp);
  447. xfs_buf_ioend(bp);
  448. }
  449. }
  450. /*
  451. * Buffer IO error rate limiting. Limit it to no more than 10 messages per 30
  452. * seconds so as to not spam logs too much on repeated detection of the same
  453. * buffer being bad..
  454. */
  455. static DEFINE_RATELIMIT_STATE(xfs_buf_write_fail_rl_state, 30 * HZ, 10);
  456. STATIC uint
  457. xfs_buf_item_push(
  458. struct xfs_log_item *lip,
  459. struct list_head *buffer_list)
  460. {
  461. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  462. struct xfs_buf *bp = bip->bli_buf;
  463. uint rval = XFS_ITEM_SUCCESS;
  464. if (xfs_buf_ispinned(bp))
  465. return XFS_ITEM_PINNED;
  466. if (!xfs_buf_trylock(bp)) {
  467. /*
  468. * If we have just raced with a buffer being pinned and it has
  469. * been marked stale, we could end up stalling until someone else
  470. * issues a log force to unpin the stale buffer. Check for the
  471. * race condition here so xfsaild recognizes the buffer is pinned
  472. * and queues a log force to move it along.
  473. */
  474. if (xfs_buf_ispinned(bp))
  475. return XFS_ITEM_PINNED;
  476. return XFS_ITEM_LOCKED;
  477. }
  478. ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
  479. trace_xfs_buf_item_push(bip);
  480. /* has a previous flush failed due to IO errors? */
  481. if ((bp->b_flags & XBF_WRITE_FAIL) &&
  482. ___ratelimit(&xfs_buf_write_fail_rl_state, "XFS: Failing async write")) {
  483. xfs_warn(bp->b_target->bt_mount,
  484. "Failing async write on buffer block 0x%llx. Retrying async write.",
  485. (long long)bp->b_bn);
  486. }
  487. if (!xfs_buf_delwri_queue(bp, buffer_list))
  488. rval = XFS_ITEM_FLUSHING;
  489. xfs_buf_unlock(bp);
  490. return rval;
  491. }
  492. /*
  493. * Release the buffer associated with the buf log item. If there is no dirty
  494. * logged data associated with the buffer recorded in the buf log item, then
  495. * free the buf log item and remove the reference to it in the buffer.
  496. *
  497. * This call ignores the recursion count. It is only called when the buffer
  498. * should REALLY be unlocked, regardless of the recursion count.
  499. *
  500. * We unconditionally drop the transaction's reference to the log item. If the
  501. * item was logged, then another reference was taken when it was pinned, so we
  502. * can safely drop the transaction reference now. This also allows us to avoid
  503. * potential races with the unpin code freeing the bli by not referencing the
  504. * bli after we've dropped the reference count.
  505. *
  506. * If the XFS_BLI_HOLD flag is set in the buf log item, then free the log item
  507. * if necessary but do not unlock the buffer. This is for support of
  508. * xfs_trans_bhold(). Make sure the XFS_BLI_HOLD field is cleared if we don't
  509. * free the item.
  510. */
  511. STATIC void
  512. xfs_buf_item_unlock(
  513. struct xfs_log_item *lip)
  514. {
  515. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  516. struct xfs_buf *bp = bip->bli_buf;
  517. bool aborted = !!(lip->li_flags & XFS_LI_ABORTED);
  518. bool hold = !!(bip->bli_flags & XFS_BLI_HOLD);
  519. bool dirty = !!(bip->bli_flags & XFS_BLI_DIRTY);
  520. #if defined(DEBUG) || defined(XFS_WARN)
  521. bool ordered = !!(bip->bli_flags & XFS_BLI_ORDERED);
  522. #endif
  523. /* Clear the buffer's association with this transaction. */
  524. bp->b_transp = NULL;
  525. /*
  526. * The per-transaction state has been copied above so clear it from the
  527. * bli.
  528. */
  529. bip->bli_flags &= ~(XFS_BLI_LOGGED | XFS_BLI_HOLD | XFS_BLI_ORDERED);
  530. /*
  531. * If the buf item is marked stale, then don't do anything. We'll
  532. * unlock the buffer and free the buf item when the buffer is unpinned
  533. * for the last time.
  534. */
  535. if (bip->bli_flags & XFS_BLI_STALE) {
  536. trace_xfs_buf_item_unlock_stale(bip);
  537. ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
  538. if (!aborted) {
  539. atomic_dec(&bip->bli_refcount);
  540. return;
  541. }
  542. }
  543. trace_xfs_buf_item_unlock(bip);
  544. /*
  545. * If the buf item isn't tracking any data, free it, otherwise drop the
  546. * reference we hold to it. If we are aborting the transaction, this may
  547. * be the only reference to the buf item, so we free it anyway
  548. * regardless of whether it is dirty or not. A dirty abort implies a
  549. * shutdown, anyway.
  550. *
  551. * The bli dirty state should match whether the blf has logged segments
  552. * except for ordered buffers, where only the bli should be dirty.
  553. */
  554. ASSERT((!ordered && dirty == xfs_buf_item_dirty_format(bip)) ||
  555. (ordered && dirty && !xfs_buf_item_dirty_format(bip)));
  556. /*
  557. * Clean buffers, by definition, cannot be in the AIL. However, aborted
  558. * buffers may be in the AIL regardless of dirty state. An aborted
  559. * transaction that invalidates a buffer already in the AIL may have
  560. * marked it stale and cleared the dirty state, for example.
  561. *
  562. * Therefore if we are aborting a buffer and we've just taken the last
  563. * reference away, we have to check if it is in the AIL before freeing
  564. * it. We need to free it in this case, because an aborted transaction
  565. * has already shut the filesystem down and this is the last chance we
  566. * will have to do so.
  567. */
  568. if (atomic_dec_and_test(&bip->bli_refcount)) {
  569. if (aborted) {
  570. ASSERT(XFS_FORCED_SHUTDOWN(lip->li_mountp));
  571. xfs_trans_ail_remove(lip, SHUTDOWN_LOG_IO_ERROR);
  572. xfs_buf_item_relse(bp);
  573. } else if (!dirty)
  574. xfs_buf_item_relse(bp);
  575. }
  576. if (!hold)
  577. xfs_buf_relse(bp);
  578. }
  579. /*
  580. * This is called to find out where the oldest active copy of the
  581. * buf log item in the on disk log resides now that the last log
  582. * write of it completed at the given lsn.
  583. * We always re-log all the dirty data in a buffer, so usually the
  584. * latest copy in the on disk log is the only one that matters. For
  585. * those cases we simply return the given lsn.
  586. *
  587. * The one exception to this is for buffers full of newly allocated
  588. * inodes. These buffers are only relogged with the XFS_BLI_INODE_BUF
  589. * flag set, indicating that only the di_next_unlinked fields from the
  590. * inodes in the buffers will be replayed during recovery. If the
  591. * original newly allocated inode images have not yet been flushed
  592. * when the buffer is so relogged, then we need to make sure that we
  593. * keep the old images in the 'active' portion of the log. We do this
  594. * by returning the original lsn of that transaction here rather than
  595. * the current one.
  596. */
  597. STATIC xfs_lsn_t
  598. xfs_buf_item_committed(
  599. struct xfs_log_item *lip,
  600. xfs_lsn_t lsn)
  601. {
  602. struct xfs_buf_log_item *bip = BUF_ITEM(lip);
  603. trace_xfs_buf_item_committed(bip);
  604. if ((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) && lip->li_lsn != 0)
  605. return lip->li_lsn;
  606. return lsn;
  607. }
  608. STATIC void
  609. xfs_buf_item_committing(
  610. struct xfs_log_item *lip,
  611. xfs_lsn_t commit_lsn)
  612. {
  613. }
  614. /*
  615. * This is the ops vector shared by all buf log items.
  616. */
  617. static const struct xfs_item_ops xfs_buf_item_ops = {
  618. .iop_size = xfs_buf_item_size,
  619. .iop_format = xfs_buf_item_format,
  620. .iop_pin = xfs_buf_item_pin,
  621. .iop_unpin = xfs_buf_item_unpin,
  622. .iop_unlock = xfs_buf_item_unlock,
  623. .iop_committed = xfs_buf_item_committed,
  624. .iop_push = xfs_buf_item_push,
  625. .iop_committing = xfs_buf_item_committing
  626. };
  627. STATIC int
  628. xfs_buf_item_get_format(
  629. struct xfs_buf_log_item *bip,
  630. int count)
  631. {
  632. ASSERT(bip->bli_formats == NULL);
  633. bip->bli_format_count = count;
  634. if (count == 1) {
  635. bip->bli_formats = &bip->__bli_format;
  636. return 0;
  637. }
  638. bip->bli_formats = kmem_zalloc(count * sizeof(struct xfs_buf_log_format),
  639. KM_SLEEP);
  640. if (!bip->bli_formats)
  641. return -ENOMEM;
  642. return 0;
  643. }
  644. STATIC void
  645. xfs_buf_item_free_format(
  646. struct xfs_buf_log_item *bip)
  647. {
  648. if (bip->bli_formats != &bip->__bli_format) {
  649. kmem_free(bip->bli_formats);
  650. bip->bli_formats = NULL;
  651. }
  652. }
  653. /*
  654. * Allocate a new buf log item to go with the given buffer.
  655. * Set the buffer's b_fsprivate field to point to the new
  656. * buf log item. If there are other item's attached to the
  657. * buffer (see xfs_buf_attach_iodone() below), then put the
  658. * buf log item at the front.
  659. */
  660. int
  661. xfs_buf_item_init(
  662. struct xfs_buf *bp,
  663. struct xfs_mount *mp)
  664. {
  665. struct xfs_log_item *lip = bp->b_fspriv;
  666. struct xfs_buf_log_item *bip;
  667. int chunks;
  668. int map_size;
  669. int error;
  670. int i;
  671. /*
  672. * Check to see if there is already a buf log item for
  673. * this buffer. If there is, it is guaranteed to be
  674. * the first. If we do already have one, there is
  675. * nothing to do here so return.
  676. */
  677. ASSERT(bp->b_target->bt_mount == mp);
  678. if (lip != NULL && lip->li_type == XFS_LI_BUF)
  679. return 0;
  680. bip = kmem_zone_zalloc(xfs_buf_item_zone, KM_SLEEP);
  681. xfs_log_item_init(mp, &bip->bli_item, XFS_LI_BUF, &xfs_buf_item_ops);
  682. bip->bli_buf = bp;
  683. /*
  684. * chunks is the number of XFS_BLF_CHUNK size pieces the buffer
  685. * can be divided into. Make sure not to truncate any pieces.
  686. * map_size is the size of the bitmap needed to describe the
  687. * chunks of the buffer.
  688. *
  689. * Discontiguous buffer support follows the layout of the underlying
  690. * buffer. This makes the implementation as simple as possible.
  691. */
  692. error = xfs_buf_item_get_format(bip, bp->b_map_count);
  693. ASSERT(error == 0);
  694. if (error) { /* to stop gcc throwing set-but-unused warnings */
  695. kmem_zone_free(xfs_buf_item_zone, bip);
  696. return error;
  697. }
  698. for (i = 0; i < bip->bli_format_count; i++) {
  699. chunks = DIV_ROUND_UP(BBTOB(bp->b_maps[i].bm_len),
  700. XFS_BLF_CHUNK);
  701. map_size = DIV_ROUND_UP(chunks, NBWORD);
  702. bip->bli_formats[i].blf_type = XFS_LI_BUF;
  703. bip->bli_formats[i].blf_blkno = bp->b_maps[i].bm_bn;
  704. bip->bli_formats[i].blf_len = bp->b_maps[i].bm_len;
  705. bip->bli_formats[i].blf_map_size = map_size;
  706. }
  707. /*
  708. * Put the buf item into the list of items attached to the
  709. * buffer at the front.
  710. */
  711. if (bp->b_fspriv)
  712. bip->bli_item.li_bio_list = bp->b_fspriv;
  713. bp->b_fspriv = bip;
  714. xfs_buf_hold(bp);
  715. return 0;
  716. }
  717. /*
  718. * Mark bytes first through last inclusive as dirty in the buf
  719. * item's bitmap.
  720. */
  721. static void
  722. xfs_buf_item_log_segment(
  723. uint first,
  724. uint last,
  725. uint *map)
  726. {
  727. uint first_bit;
  728. uint last_bit;
  729. uint bits_to_set;
  730. uint bits_set;
  731. uint word_num;
  732. uint *wordp;
  733. uint bit;
  734. uint end_bit;
  735. uint mask;
  736. /*
  737. * Convert byte offsets to bit numbers.
  738. */
  739. first_bit = first >> XFS_BLF_SHIFT;
  740. last_bit = last >> XFS_BLF_SHIFT;
  741. /*
  742. * Calculate the total number of bits to be set.
  743. */
  744. bits_to_set = last_bit - first_bit + 1;
  745. /*
  746. * Get a pointer to the first word in the bitmap
  747. * to set a bit in.
  748. */
  749. word_num = first_bit >> BIT_TO_WORD_SHIFT;
  750. wordp = &map[word_num];
  751. /*
  752. * Calculate the starting bit in the first word.
  753. */
  754. bit = first_bit & (uint)(NBWORD - 1);
  755. /*
  756. * First set any bits in the first word of our range.
  757. * If it starts at bit 0 of the word, it will be
  758. * set below rather than here. That is what the variable
  759. * bit tells us. The variable bits_set tracks the number
  760. * of bits that have been set so far. End_bit is the number
  761. * of the last bit to be set in this word plus one.
  762. */
  763. if (bit) {
  764. end_bit = MIN(bit + bits_to_set, (uint)NBWORD);
  765. mask = ((1U << (end_bit - bit)) - 1) << bit;
  766. *wordp |= mask;
  767. wordp++;
  768. bits_set = end_bit - bit;
  769. } else {
  770. bits_set = 0;
  771. }
  772. /*
  773. * Now set bits a whole word at a time that are between
  774. * first_bit and last_bit.
  775. */
  776. while ((bits_to_set - bits_set) >= NBWORD) {
  777. *wordp |= 0xffffffff;
  778. bits_set += NBWORD;
  779. wordp++;
  780. }
  781. /*
  782. * Finally, set any bits left to be set in one last partial word.
  783. */
  784. end_bit = bits_to_set - bits_set;
  785. if (end_bit) {
  786. mask = (1U << end_bit) - 1;
  787. *wordp |= mask;
  788. }
  789. }
  790. /*
  791. * Mark bytes first through last inclusive as dirty in the buf
  792. * item's bitmap.
  793. */
  794. void
  795. xfs_buf_item_log(
  796. xfs_buf_log_item_t *bip,
  797. uint first,
  798. uint last)
  799. {
  800. int i;
  801. uint start;
  802. uint end;
  803. struct xfs_buf *bp = bip->bli_buf;
  804. /*
  805. * walk each buffer segment and mark them dirty appropriately.
  806. */
  807. start = 0;
  808. for (i = 0; i < bip->bli_format_count; i++) {
  809. if (start > last)
  810. break;
  811. end = start + BBTOB(bp->b_maps[i].bm_len) - 1;
  812. /* skip to the map that includes the first byte to log */
  813. if (first > end) {
  814. start += BBTOB(bp->b_maps[i].bm_len);
  815. continue;
  816. }
  817. /*
  818. * Trim the range to this segment and mark it in the bitmap.
  819. * Note that we must convert buffer offsets to segment relative
  820. * offsets (e.g., the first byte of each segment is byte 0 of
  821. * that segment).
  822. */
  823. if (first < start)
  824. first = start;
  825. if (end > last)
  826. end = last;
  827. xfs_buf_item_log_segment(first - start, end - start,
  828. &bip->bli_formats[i].blf_data_map[0]);
  829. start += BBTOB(bp->b_maps[i].bm_len);
  830. }
  831. }
  832. /*
  833. * Return true if the buffer has any ranges logged/dirtied by a transaction,
  834. * false otherwise.
  835. */
  836. bool
  837. xfs_buf_item_dirty_format(
  838. struct xfs_buf_log_item *bip)
  839. {
  840. int i;
  841. for (i = 0; i < bip->bli_format_count; i++) {
  842. if (!xfs_bitmap_empty(bip->bli_formats[i].blf_data_map,
  843. bip->bli_formats[i].blf_map_size))
  844. return true;
  845. }
  846. return false;
  847. }
  848. STATIC void
  849. xfs_buf_item_free(
  850. xfs_buf_log_item_t *bip)
  851. {
  852. xfs_buf_item_free_format(bip);
  853. kmem_free(bip->bli_item.li_lv_shadow);
  854. kmem_zone_free(xfs_buf_item_zone, bip);
  855. }
  856. /*
  857. * This is called when the buf log item is no longer needed. It should
  858. * free the buf log item associated with the given buffer and clear
  859. * the buffer's pointer to the buf log item. If there are no more
  860. * items in the list, clear the b_iodone field of the buffer (see
  861. * xfs_buf_attach_iodone() below).
  862. */
  863. void
  864. xfs_buf_item_relse(
  865. xfs_buf_t *bp)
  866. {
  867. xfs_buf_log_item_t *bip = bp->b_fspriv;
  868. trace_xfs_buf_item_relse(bp, _RET_IP_);
  869. ASSERT(!(bip->bli_item.li_flags & XFS_LI_IN_AIL));
  870. bp->b_fspriv = bip->bli_item.li_bio_list;
  871. if (bp->b_fspriv == NULL)
  872. bp->b_iodone = NULL;
  873. xfs_buf_rele(bp);
  874. xfs_buf_item_free(bip);
  875. }
  876. /*
  877. * Add the given log item with its callback to the list of callbacks
  878. * to be called when the buffer's I/O completes. If it is not set
  879. * already, set the buffer's b_iodone() routine to be
  880. * xfs_buf_iodone_callbacks() and link the log item into the list of
  881. * items rooted at b_fsprivate. Items are always added as the second
  882. * entry in the list if there is a first, because the buf item code
  883. * assumes that the buf log item is first.
  884. */
  885. void
  886. xfs_buf_attach_iodone(
  887. xfs_buf_t *bp,
  888. void (*cb)(xfs_buf_t *, xfs_log_item_t *),
  889. xfs_log_item_t *lip)
  890. {
  891. xfs_log_item_t *head_lip;
  892. ASSERT(xfs_buf_islocked(bp));
  893. lip->li_cb = cb;
  894. head_lip = bp->b_fspriv;
  895. if (head_lip) {
  896. lip->li_bio_list = head_lip->li_bio_list;
  897. head_lip->li_bio_list = lip;
  898. } else {
  899. bp->b_fspriv = lip;
  900. }
  901. ASSERT(bp->b_iodone == NULL ||
  902. bp->b_iodone == xfs_buf_iodone_callbacks);
  903. bp->b_iodone = xfs_buf_iodone_callbacks;
  904. }
  905. /*
  906. * We can have many callbacks on a buffer. Running the callbacks individually
  907. * can cause a lot of contention on the AIL lock, so we allow for a single
  908. * callback to be able to scan the remaining lip->li_bio_list for other items
  909. * of the same type and callback to be processed in the first call.
  910. *
  911. * As a result, the loop walking the callback list below will also modify the
  912. * list. it removes the first item from the list and then runs the callback.
  913. * The loop then restarts from the new head of the list. This allows the
  914. * callback to scan and modify the list attached to the buffer and we don't
  915. * have to care about maintaining a next item pointer.
  916. */
  917. STATIC void
  918. xfs_buf_do_callbacks(
  919. struct xfs_buf *bp)
  920. {
  921. struct xfs_log_item *lip;
  922. while ((lip = bp->b_fspriv) != NULL) {
  923. bp->b_fspriv = lip->li_bio_list;
  924. ASSERT(lip->li_cb != NULL);
  925. /*
  926. * Clear the next pointer so we don't have any
  927. * confusion if the item is added to another buf.
  928. * Don't touch the log item after calling its
  929. * callback, because it could have freed itself.
  930. */
  931. lip->li_bio_list = NULL;
  932. lip->li_cb(bp, lip);
  933. }
  934. }
  935. /*
  936. * Invoke the error state callback for each log item affected by the failed I/O.
  937. *
  938. * If a metadata buffer write fails with a non-permanent error, the buffer is
  939. * eventually resubmitted and so the completion callbacks are not run. The error
  940. * state may need to be propagated to the log items attached to the buffer,
  941. * however, so the next AIL push of the item knows hot to handle it correctly.
  942. */
  943. STATIC void
  944. xfs_buf_do_callbacks_fail(
  945. struct xfs_buf *bp)
  946. {
  947. struct xfs_log_item *next;
  948. struct xfs_log_item *lip = bp->b_fspriv;
  949. struct xfs_ail *ailp = lip->li_ailp;
  950. spin_lock(&ailp->xa_lock);
  951. for (; lip; lip = next) {
  952. next = lip->li_bio_list;
  953. if (lip->li_ops->iop_error)
  954. lip->li_ops->iop_error(lip, bp);
  955. }
  956. spin_unlock(&ailp->xa_lock);
  957. }
  958. static bool
  959. xfs_buf_iodone_callback_error(
  960. struct xfs_buf *bp)
  961. {
  962. struct xfs_log_item *lip = bp->b_fspriv;
  963. struct xfs_mount *mp = lip->li_mountp;
  964. static ulong lasttime;
  965. static xfs_buftarg_t *lasttarg;
  966. struct xfs_error_cfg *cfg;
  967. /*
  968. * If we've already decided to shutdown the filesystem because of
  969. * I/O errors, there's no point in giving this a retry.
  970. */
  971. if (XFS_FORCED_SHUTDOWN(mp))
  972. goto out_stale;
  973. if (bp->b_target != lasttarg ||
  974. time_after(jiffies, (lasttime + 5*HZ))) {
  975. lasttime = jiffies;
  976. xfs_buf_ioerror_alert(bp, __func__);
  977. }
  978. lasttarg = bp->b_target;
  979. /* synchronous writes will have callers process the error */
  980. if (!(bp->b_flags & XBF_ASYNC))
  981. goto out_stale;
  982. trace_xfs_buf_item_iodone_async(bp, _RET_IP_);
  983. ASSERT(bp->b_iodone != NULL);
  984. cfg = xfs_error_get_cfg(mp, XFS_ERR_METADATA, bp->b_error);
  985. /*
  986. * If the write was asynchronous then no one will be looking for the
  987. * error. If this is the first failure of this type, clear the error
  988. * state and write the buffer out again. This means we always retry an
  989. * async write failure at least once, but we also need to set the buffer
  990. * up to behave correctly now for repeated failures.
  991. */
  992. if (!(bp->b_flags & (XBF_STALE | XBF_WRITE_FAIL)) ||
  993. bp->b_last_error != bp->b_error) {
  994. bp->b_flags |= (XBF_WRITE | XBF_DONE | XBF_WRITE_FAIL);
  995. bp->b_last_error = bp->b_error;
  996. if (cfg->retry_timeout != XFS_ERR_RETRY_FOREVER &&
  997. !bp->b_first_retry_time)
  998. bp->b_first_retry_time = jiffies;
  999. xfs_buf_ioerror(bp, 0);
  1000. xfs_buf_submit(bp);
  1001. return true;
  1002. }
  1003. /*
  1004. * Repeated failure on an async write. Take action according to the
  1005. * error configuration we have been set up to use.
  1006. */
  1007. if (cfg->max_retries != XFS_ERR_RETRY_FOREVER &&
  1008. ++bp->b_retries > cfg->max_retries)
  1009. goto permanent_error;
  1010. if (cfg->retry_timeout != XFS_ERR_RETRY_FOREVER &&
  1011. time_after(jiffies, cfg->retry_timeout + bp->b_first_retry_time))
  1012. goto permanent_error;
  1013. /* At unmount we may treat errors differently */
  1014. if ((mp->m_flags & XFS_MOUNT_UNMOUNTING) && mp->m_fail_unmount)
  1015. goto permanent_error;
  1016. /*
  1017. * Still a transient error, run IO completion failure callbacks and let
  1018. * the higher layers retry the buffer.
  1019. */
  1020. xfs_buf_do_callbacks_fail(bp);
  1021. xfs_buf_ioerror(bp, 0);
  1022. xfs_buf_relse(bp);
  1023. return true;
  1024. /*
  1025. * Permanent error - we need to trigger a shutdown if we haven't already
  1026. * to indicate that inconsistency will result from this action.
  1027. */
  1028. permanent_error:
  1029. xfs_force_shutdown(mp, SHUTDOWN_META_IO_ERROR);
  1030. out_stale:
  1031. xfs_buf_stale(bp);
  1032. bp->b_flags |= XBF_DONE;
  1033. trace_xfs_buf_error_relse(bp, _RET_IP_);
  1034. return false;
  1035. }
  1036. /*
  1037. * This is the iodone() function for buffers which have had callbacks attached
  1038. * to them by xfs_buf_attach_iodone(). We need to iterate the items on the
  1039. * callback list, mark the buffer as having no more callbacks and then push the
  1040. * buffer through IO completion processing.
  1041. */
  1042. void
  1043. xfs_buf_iodone_callbacks(
  1044. struct xfs_buf *bp)
  1045. {
  1046. /*
  1047. * If there is an error, process it. Some errors require us
  1048. * to run callbacks after failure processing is done so we
  1049. * detect that and take appropriate action.
  1050. */
  1051. if (bp->b_error && xfs_buf_iodone_callback_error(bp))
  1052. return;
  1053. /*
  1054. * Successful IO or permanent error. Either way, we can clear the
  1055. * retry state here in preparation for the next error that may occur.
  1056. */
  1057. bp->b_last_error = 0;
  1058. bp->b_retries = 0;
  1059. bp->b_first_retry_time = 0;
  1060. xfs_buf_do_callbacks(bp);
  1061. bp->b_fspriv = NULL;
  1062. bp->b_iodone = NULL;
  1063. xfs_buf_ioend(bp);
  1064. }
  1065. /*
  1066. * This is the iodone() function for buffers which have been
  1067. * logged. It is called when they are eventually flushed out.
  1068. * It should remove the buf item from the AIL, and free the buf item.
  1069. * It is called by xfs_buf_iodone_callbacks() above which will take
  1070. * care of cleaning up the buffer itself.
  1071. */
  1072. void
  1073. xfs_buf_iodone(
  1074. struct xfs_buf *bp,
  1075. struct xfs_log_item *lip)
  1076. {
  1077. struct xfs_ail *ailp = lip->li_ailp;
  1078. ASSERT(BUF_ITEM(lip)->bli_buf == bp);
  1079. xfs_buf_rele(bp);
  1080. /*
  1081. * If we are forcibly shutting down, this may well be
  1082. * off the AIL already. That's because we simulate the
  1083. * log-committed callbacks to unpin these buffers. Or we may never
  1084. * have put this item on AIL because of the transaction was
  1085. * aborted forcibly. xfs_trans_ail_delete() takes care of these.
  1086. *
  1087. * Either way, AIL is useless if we're forcing a shutdown.
  1088. */
  1089. spin_lock(&ailp->xa_lock);
  1090. xfs_trans_ail_delete(ailp, lip, SHUTDOWN_CORRUPT_INCORE);
  1091. xfs_buf_item_free(BUF_ITEM(lip));
  1092. }
  1093. /*
  1094. * Requeue a failed buffer for writeback
  1095. *
  1096. * Return true if the buffer has been re-queued properly, false otherwise
  1097. */
  1098. bool
  1099. xfs_buf_resubmit_failed_buffers(
  1100. struct xfs_buf *bp,
  1101. struct xfs_log_item *lip,
  1102. struct list_head *buffer_list)
  1103. {
  1104. struct xfs_log_item *next;
  1105. /*
  1106. * Clear XFS_LI_FAILED flag from all items before resubmit
  1107. *
  1108. * XFS_LI_FAILED set/clear is protected by xa_lock, caller this
  1109. * function already have it acquired
  1110. */
  1111. for (; lip; lip = next) {
  1112. next = lip->li_bio_list;
  1113. xfs_clear_li_failed(lip);
  1114. }
  1115. /* Add this buffer back to the delayed write list */
  1116. return xfs_buf_delwri_queue(bp, buffer_list);
  1117. }