xfs_buf_item.c 35 KB

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