xfs_trans_buf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. */
  6. #include "xfs.h"
  7. #include "xfs_fs.h"
  8. #include "xfs_shared.h"
  9. #include "xfs_format.h"
  10. #include "xfs_log_format.h"
  11. #include "xfs_trans_resv.h"
  12. #include "xfs_mount.h"
  13. #include "xfs_trans.h"
  14. #include "xfs_buf_item.h"
  15. #include "xfs_trans_priv.h"
  16. #include "xfs_trace.h"
  17. /*
  18. * Check to see if a buffer matching the given parameters is already
  19. * a part of the given transaction.
  20. */
  21. STATIC struct xfs_buf *
  22. xfs_trans_buf_item_match(
  23. struct xfs_trans *tp,
  24. struct xfs_buftarg *target,
  25. struct xfs_buf_map *map,
  26. int nmaps)
  27. {
  28. struct xfs_log_item *lip;
  29. struct xfs_buf_log_item *blip;
  30. int len = 0;
  31. int i;
  32. for (i = 0; i < nmaps; i++)
  33. len += map[i].bm_len;
  34. list_for_each_entry(lip, &tp->t_items, li_trans) {
  35. blip = (struct xfs_buf_log_item *)lip;
  36. if (blip->bli_item.li_type == XFS_LI_BUF &&
  37. blip->bli_buf->b_target == target &&
  38. XFS_BUF_ADDR(blip->bli_buf) == map[0].bm_bn &&
  39. blip->bli_buf->b_length == len) {
  40. ASSERT(blip->bli_buf->b_map_count == nmaps);
  41. return blip->bli_buf;
  42. }
  43. }
  44. return NULL;
  45. }
  46. /*
  47. * Add the locked buffer to the transaction.
  48. *
  49. * The buffer must be locked, and it cannot be associated with any
  50. * transaction.
  51. *
  52. * If the buffer does not yet have a buf log item associated with it,
  53. * then allocate one for it. Then add the buf item to the transaction.
  54. */
  55. STATIC void
  56. _xfs_trans_bjoin(
  57. struct xfs_trans *tp,
  58. struct xfs_buf *bp,
  59. int reset_recur)
  60. {
  61. struct xfs_buf_log_item *bip;
  62. ASSERT(bp->b_transp == NULL);
  63. /*
  64. * The xfs_buf_log_item pointer is stored in b_log_item. If
  65. * it doesn't have one yet, then allocate one and initialize it.
  66. * The checks to see if one is there are in xfs_buf_item_init().
  67. */
  68. xfs_buf_item_init(bp, tp->t_mountp);
  69. bip = bp->b_log_item;
  70. ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
  71. ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
  72. ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
  73. if (reset_recur)
  74. bip->bli_recur = 0;
  75. /*
  76. * Take a reference for this transaction on the buf item.
  77. */
  78. atomic_inc(&bip->bli_refcount);
  79. /*
  80. * Attach the item to the transaction so we can find it in
  81. * xfs_trans_get_buf() and friends.
  82. */
  83. xfs_trans_add_item(tp, &bip->bli_item);
  84. bp->b_transp = tp;
  85. }
  86. void
  87. xfs_trans_bjoin(
  88. struct xfs_trans *tp,
  89. struct xfs_buf *bp)
  90. {
  91. _xfs_trans_bjoin(tp, bp, 0);
  92. trace_xfs_trans_bjoin(bp->b_log_item);
  93. }
  94. /*
  95. * Get and lock the buffer for the caller if it is not already
  96. * locked within the given transaction. If it is already locked
  97. * within the transaction, just increment its lock recursion count
  98. * and return a pointer to it.
  99. *
  100. * If the transaction pointer is NULL, make this just a normal
  101. * get_buf() call.
  102. */
  103. int
  104. xfs_trans_get_buf_map(
  105. struct xfs_trans *tp,
  106. struct xfs_buftarg *target,
  107. struct xfs_buf_map *map,
  108. int nmaps,
  109. xfs_buf_flags_t flags,
  110. struct xfs_buf **bpp)
  111. {
  112. xfs_buf_t *bp;
  113. struct xfs_buf_log_item *bip;
  114. int error;
  115. *bpp = NULL;
  116. if (!tp)
  117. return xfs_buf_get_map(target, map, nmaps, flags, bpp);
  118. /*
  119. * If we find the buffer in the cache with this transaction
  120. * pointer in its b_fsprivate2 field, then we know we already
  121. * have it locked. In this case we just increment the lock
  122. * recursion count and return the buffer to the caller.
  123. */
  124. bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
  125. if (bp != NULL) {
  126. ASSERT(xfs_buf_islocked(bp));
  127. if (XFS_FORCED_SHUTDOWN(tp->t_mountp)) {
  128. xfs_buf_stale(bp);
  129. bp->b_flags |= XBF_DONE;
  130. }
  131. ASSERT(bp->b_transp == tp);
  132. bip = bp->b_log_item;
  133. ASSERT(bip != NULL);
  134. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  135. bip->bli_recur++;
  136. trace_xfs_trans_get_buf_recur(bip);
  137. *bpp = bp;
  138. return 0;
  139. }
  140. error = xfs_buf_get_map(target, map, nmaps, flags, &bp);
  141. if (error)
  142. return error;
  143. ASSERT(!bp->b_error);
  144. _xfs_trans_bjoin(tp, bp, 1);
  145. trace_xfs_trans_get_buf(bp->b_log_item);
  146. *bpp = bp;
  147. return 0;
  148. }
  149. /*
  150. * Get and lock the superblock buffer for the given transaction.
  151. */
  152. struct xfs_buf *
  153. xfs_trans_getsb(
  154. struct xfs_trans *tp)
  155. {
  156. struct xfs_buf *bp = tp->t_mountp->m_sb_bp;
  157. /*
  158. * Just increment the lock recursion count if the buffer is already
  159. * attached to this transaction.
  160. */
  161. if (bp->b_transp == tp) {
  162. struct xfs_buf_log_item *bip = bp->b_log_item;
  163. ASSERT(bip != NULL);
  164. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  165. bip->bli_recur++;
  166. trace_xfs_trans_getsb_recur(bip);
  167. } else {
  168. xfs_buf_lock(bp);
  169. xfs_buf_hold(bp);
  170. _xfs_trans_bjoin(tp, bp, 1);
  171. trace_xfs_trans_getsb(bp->b_log_item);
  172. }
  173. return bp;
  174. }
  175. /*
  176. * Get and lock the buffer for the caller if it is not already
  177. * locked within the given transaction. If it has not yet been
  178. * read in, read it from disk. If it is already locked
  179. * within the transaction and already read in, just increment its
  180. * lock recursion count and return a pointer to it.
  181. *
  182. * If the transaction pointer is NULL, make this just a normal
  183. * read_buf() call.
  184. */
  185. int
  186. xfs_trans_read_buf_map(
  187. struct xfs_mount *mp,
  188. struct xfs_trans *tp,
  189. struct xfs_buftarg *target,
  190. struct xfs_buf_map *map,
  191. int nmaps,
  192. xfs_buf_flags_t flags,
  193. struct xfs_buf **bpp,
  194. const struct xfs_buf_ops *ops)
  195. {
  196. struct xfs_buf *bp = NULL;
  197. struct xfs_buf_log_item *bip;
  198. int error;
  199. *bpp = NULL;
  200. /*
  201. * If we find the buffer in the cache with this transaction
  202. * pointer in its b_fsprivate2 field, then we know we already
  203. * have it locked. If it is already read in we just increment
  204. * the lock recursion count and return the buffer to the caller.
  205. * If the buffer is not yet read in, then we read it in, increment
  206. * the lock recursion count, and return it to the caller.
  207. */
  208. if (tp)
  209. bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
  210. if (bp) {
  211. ASSERT(xfs_buf_islocked(bp));
  212. ASSERT(bp->b_transp == tp);
  213. ASSERT(bp->b_log_item != NULL);
  214. ASSERT(!bp->b_error);
  215. ASSERT(bp->b_flags & XBF_DONE);
  216. /*
  217. * We never locked this buf ourselves, so we shouldn't
  218. * brelse it either. Just get out.
  219. */
  220. if (XFS_FORCED_SHUTDOWN(mp)) {
  221. trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
  222. return -EIO;
  223. }
  224. /*
  225. * Check if the caller is trying to read a buffer that is
  226. * already attached to the transaction yet has no buffer ops
  227. * assigned. Ops are usually attached when the buffer is
  228. * attached to the transaction, or by the read caller if
  229. * special circumstances. That didn't happen, which is not
  230. * how this is supposed to go.
  231. *
  232. * If the buffer passes verification we'll let this go, but if
  233. * not we have to shut down. Let the transaction cleanup code
  234. * release this buffer when it kills the tranaction.
  235. */
  236. ASSERT(bp->b_ops != NULL);
  237. error = xfs_buf_reverify(bp, ops);
  238. if (error) {
  239. xfs_buf_ioerror_alert(bp, __return_address);
  240. if (tp->t_flags & XFS_TRANS_DIRTY)
  241. xfs_force_shutdown(tp->t_mountp,
  242. SHUTDOWN_META_IO_ERROR);
  243. /* bad CRC means corrupted metadata */
  244. if (error == -EFSBADCRC)
  245. error = -EFSCORRUPTED;
  246. return error;
  247. }
  248. bip = bp->b_log_item;
  249. bip->bli_recur++;
  250. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  251. trace_xfs_trans_read_buf_recur(bip);
  252. ASSERT(bp->b_ops != NULL || ops == NULL);
  253. *bpp = bp;
  254. return 0;
  255. }
  256. error = xfs_buf_read_map(target, map, nmaps, flags, &bp, ops,
  257. __return_address);
  258. switch (error) {
  259. case 0:
  260. break;
  261. default:
  262. if (tp && (tp->t_flags & XFS_TRANS_DIRTY))
  263. xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
  264. /* fall through */
  265. case -ENOMEM:
  266. case -EAGAIN:
  267. return error;
  268. }
  269. if (XFS_FORCED_SHUTDOWN(mp)) {
  270. xfs_buf_relse(bp);
  271. trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
  272. return -EIO;
  273. }
  274. if (tp) {
  275. _xfs_trans_bjoin(tp, bp, 1);
  276. trace_xfs_trans_read_buf(bp->b_log_item);
  277. }
  278. ASSERT(bp->b_ops != NULL || ops == NULL);
  279. *bpp = bp;
  280. return 0;
  281. }
  282. /* Has this buffer been dirtied by anyone? */
  283. bool
  284. xfs_trans_buf_is_dirty(
  285. struct xfs_buf *bp)
  286. {
  287. struct xfs_buf_log_item *bip = bp->b_log_item;
  288. if (!bip)
  289. return false;
  290. ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
  291. return test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
  292. }
  293. /*
  294. * Release a buffer previously joined to the transaction. If the buffer is
  295. * modified within this transaction, decrement the recursion count but do not
  296. * release the buffer even if the count goes to 0. If the buffer is not modified
  297. * within the transaction, decrement the recursion count and release the buffer
  298. * if the recursion count goes to 0.
  299. *
  300. * If the buffer is to be released and it was not already dirty before this
  301. * transaction began, then also free the buf_log_item associated with it.
  302. *
  303. * If the transaction pointer is NULL, this is a normal xfs_buf_relse() call.
  304. */
  305. void
  306. xfs_trans_brelse(
  307. struct xfs_trans *tp,
  308. struct xfs_buf *bp)
  309. {
  310. struct xfs_buf_log_item *bip = bp->b_log_item;
  311. ASSERT(bp->b_transp == tp);
  312. if (!tp) {
  313. xfs_buf_relse(bp);
  314. return;
  315. }
  316. trace_xfs_trans_brelse(bip);
  317. ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
  318. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  319. /*
  320. * If the release is for a recursive lookup, then decrement the count
  321. * and return.
  322. */
  323. if (bip->bli_recur > 0) {
  324. bip->bli_recur--;
  325. return;
  326. }
  327. /*
  328. * If the buffer is invalidated or dirty in this transaction, we can't
  329. * release it until we commit.
  330. */
  331. if (test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags))
  332. return;
  333. if (bip->bli_flags & XFS_BLI_STALE)
  334. return;
  335. /*
  336. * Unlink the log item from the transaction and clear the hold flag, if
  337. * set. We wouldn't want the next user of the buffer to get confused.
  338. */
  339. ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
  340. xfs_trans_del_item(&bip->bli_item);
  341. bip->bli_flags &= ~XFS_BLI_HOLD;
  342. /* drop the reference to the bli */
  343. xfs_buf_item_put(bip);
  344. bp->b_transp = NULL;
  345. xfs_buf_relse(bp);
  346. }
  347. /*
  348. * Mark the buffer as not needing to be unlocked when the buf item's
  349. * iop_committing() routine is called. The buffer must already be locked
  350. * and associated with the given transaction.
  351. */
  352. /* ARGSUSED */
  353. void
  354. xfs_trans_bhold(
  355. xfs_trans_t *tp,
  356. xfs_buf_t *bp)
  357. {
  358. struct xfs_buf_log_item *bip = bp->b_log_item;
  359. ASSERT(bp->b_transp == tp);
  360. ASSERT(bip != NULL);
  361. ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
  362. ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
  363. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  364. bip->bli_flags |= XFS_BLI_HOLD;
  365. trace_xfs_trans_bhold(bip);
  366. }
  367. /*
  368. * Cancel the previous buffer hold request made on this buffer
  369. * for this transaction.
  370. */
  371. void
  372. xfs_trans_bhold_release(
  373. xfs_trans_t *tp,
  374. xfs_buf_t *bp)
  375. {
  376. struct xfs_buf_log_item *bip = bp->b_log_item;
  377. ASSERT(bp->b_transp == tp);
  378. ASSERT(bip != NULL);
  379. ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
  380. ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
  381. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  382. ASSERT(bip->bli_flags & XFS_BLI_HOLD);
  383. bip->bli_flags &= ~XFS_BLI_HOLD;
  384. trace_xfs_trans_bhold_release(bip);
  385. }
  386. /*
  387. * Mark a buffer dirty in the transaction.
  388. */
  389. void
  390. xfs_trans_dirty_buf(
  391. struct xfs_trans *tp,
  392. struct xfs_buf *bp)
  393. {
  394. struct xfs_buf_log_item *bip = bp->b_log_item;
  395. ASSERT(bp->b_transp == tp);
  396. ASSERT(bip != NULL);
  397. /*
  398. * Mark the buffer as needing to be written out eventually,
  399. * and set its iodone function to remove the buffer's buf log
  400. * item from the AIL and free it when the buffer is flushed
  401. * to disk.
  402. */
  403. bp->b_flags |= XBF_DONE;
  404. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  405. /*
  406. * If we invalidated the buffer within this transaction, then
  407. * cancel the invalidation now that we're dirtying the buffer
  408. * again. There are no races with the code in xfs_buf_item_unpin(),
  409. * because we have a reference to the buffer this entire time.
  410. */
  411. if (bip->bli_flags & XFS_BLI_STALE) {
  412. bip->bli_flags &= ~XFS_BLI_STALE;
  413. ASSERT(bp->b_flags & XBF_STALE);
  414. bp->b_flags &= ~XBF_STALE;
  415. bip->__bli_format.blf_flags &= ~XFS_BLF_CANCEL;
  416. }
  417. bip->bli_flags |= XFS_BLI_DIRTY | XFS_BLI_LOGGED;
  418. tp->t_flags |= XFS_TRANS_DIRTY;
  419. set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
  420. }
  421. /*
  422. * This is called to mark bytes first through last inclusive of the given
  423. * buffer as needing to be logged when the transaction is committed.
  424. * The buffer must already be associated with the given transaction.
  425. *
  426. * First and last are numbers relative to the beginning of this buffer,
  427. * so the first byte in the buffer is numbered 0 regardless of the
  428. * value of b_blkno.
  429. */
  430. void
  431. xfs_trans_log_buf(
  432. struct xfs_trans *tp,
  433. struct xfs_buf *bp,
  434. uint first,
  435. uint last)
  436. {
  437. struct xfs_buf_log_item *bip = bp->b_log_item;
  438. ASSERT(first <= last && last < BBTOB(bp->b_length));
  439. ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED));
  440. xfs_trans_dirty_buf(tp, bp);
  441. trace_xfs_trans_log_buf(bip);
  442. xfs_buf_item_log(bip, first, last);
  443. }
  444. /*
  445. * Invalidate a buffer that is being used within a transaction.
  446. *
  447. * Typically this is because the blocks in the buffer are being freed, so we
  448. * need to prevent it from being written out when we're done. Allowing it
  449. * to be written again might overwrite data in the free blocks if they are
  450. * reallocated to a file.
  451. *
  452. * We prevent the buffer from being written out by marking it stale. We can't
  453. * get rid of the buf log item at this point because the buffer may still be
  454. * pinned by another transaction. If that is the case, then we'll wait until
  455. * the buffer is committed to disk for the last time (we can tell by the ref
  456. * count) and free it in xfs_buf_item_unpin(). Until that happens we will
  457. * keep the buffer locked so that the buffer and buf log item are not reused.
  458. *
  459. * We also set the XFS_BLF_CANCEL flag in the buf log format structure and log
  460. * the buf item. This will be used at recovery time to determine that copies
  461. * of the buffer in the log before this should not be replayed.
  462. *
  463. * We mark the item descriptor and the transaction dirty so that we'll hold
  464. * the buffer until after the commit.
  465. *
  466. * Since we're invalidating the buffer, we also clear the state about which
  467. * parts of the buffer have been logged. We also clear the flag indicating
  468. * that this is an inode buffer since the data in the buffer will no longer
  469. * be valid.
  470. *
  471. * We set the stale bit in the buffer as well since we're getting rid of it.
  472. */
  473. void
  474. xfs_trans_binval(
  475. xfs_trans_t *tp,
  476. xfs_buf_t *bp)
  477. {
  478. struct xfs_buf_log_item *bip = bp->b_log_item;
  479. int i;
  480. ASSERT(bp->b_transp == tp);
  481. ASSERT(bip != NULL);
  482. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  483. trace_xfs_trans_binval(bip);
  484. if (bip->bli_flags & XFS_BLI_STALE) {
  485. /*
  486. * If the buffer is already invalidated, then
  487. * just return.
  488. */
  489. ASSERT(bp->b_flags & XBF_STALE);
  490. ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
  491. ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_INODE_BUF));
  492. ASSERT(!(bip->__bli_format.blf_flags & XFS_BLFT_MASK));
  493. ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
  494. ASSERT(test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags));
  495. ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
  496. return;
  497. }
  498. xfs_buf_stale(bp);
  499. bip->bli_flags |= XFS_BLI_STALE;
  500. bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
  501. bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
  502. bip->__bli_format.blf_flags |= XFS_BLF_CANCEL;
  503. bip->__bli_format.blf_flags &= ~XFS_BLFT_MASK;
  504. for (i = 0; i < bip->bli_format_count; i++) {
  505. memset(bip->bli_formats[i].blf_data_map, 0,
  506. (bip->bli_formats[i].blf_map_size * sizeof(uint)));
  507. }
  508. set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
  509. tp->t_flags |= XFS_TRANS_DIRTY;
  510. }
  511. /*
  512. * This call is used to indicate that the buffer contains on-disk inodes which
  513. * must be handled specially during recovery. They require special handling
  514. * because only the di_next_unlinked from the inodes in the buffer should be
  515. * recovered. The rest of the data in the buffer is logged via the inodes
  516. * themselves.
  517. *
  518. * All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be
  519. * transferred to the buffer's log format structure so that we'll know what to
  520. * do at recovery time.
  521. */
  522. void
  523. xfs_trans_inode_buf(
  524. xfs_trans_t *tp,
  525. xfs_buf_t *bp)
  526. {
  527. struct xfs_buf_log_item *bip = bp->b_log_item;
  528. ASSERT(bp->b_transp == tp);
  529. ASSERT(bip != NULL);
  530. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  531. bip->bli_flags |= XFS_BLI_INODE_BUF;
  532. bp->b_flags |= _XBF_INODES;
  533. xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
  534. }
  535. /*
  536. * This call is used to indicate that the buffer is going to
  537. * be staled and was an inode buffer. This means it gets
  538. * special processing during unpin - where any inodes
  539. * associated with the buffer should be removed from ail.
  540. * There is also special processing during recovery,
  541. * any replay of the inodes in the buffer needs to be
  542. * prevented as the buffer may have been reused.
  543. */
  544. void
  545. xfs_trans_stale_inode_buf(
  546. xfs_trans_t *tp,
  547. xfs_buf_t *bp)
  548. {
  549. struct xfs_buf_log_item *bip = bp->b_log_item;
  550. ASSERT(bp->b_transp == tp);
  551. ASSERT(bip != NULL);
  552. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  553. bip->bli_flags |= XFS_BLI_STALE_INODE;
  554. bp->b_flags |= _XBF_INODES;
  555. xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
  556. }
  557. /*
  558. * Mark the buffer as being one which contains newly allocated
  559. * inodes. We need to make sure that even if this buffer is
  560. * relogged as an 'inode buf' we still recover all of the inode
  561. * images in the face of a crash. This works in coordination with
  562. * xfs_buf_item_committed() to ensure that the buffer remains in the
  563. * AIL at its original location even after it has been relogged.
  564. */
  565. /* ARGSUSED */
  566. void
  567. xfs_trans_inode_alloc_buf(
  568. xfs_trans_t *tp,
  569. xfs_buf_t *bp)
  570. {
  571. struct xfs_buf_log_item *bip = bp->b_log_item;
  572. ASSERT(bp->b_transp == tp);
  573. ASSERT(bip != NULL);
  574. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  575. bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
  576. bp->b_flags |= _XBF_INODES;
  577. xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
  578. }
  579. /*
  580. * Mark the buffer as ordered for this transaction. This means that the contents
  581. * of the buffer are not recorded in the transaction but it is tracked in the
  582. * AIL as though it was. This allows us to record logical changes in
  583. * transactions rather than the physical changes we make to the buffer without
  584. * changing writeback ordering constraints of metadata buffers.
  585. */
  586. bool
  587. xfs_trans_ordered_buf(
  588. struct xfs_trans *tp,
  589. struct xfs_buf *bp)
  590. {
  591. struct xfs_buf_log_item *bip = bp->b_log_item;
  592. ASSERT(bp->b_transp == tp);
  593. ASSERT(bip != NULL);
  594. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  595. if (xfs_buf_item_dirty_format(bip))
  596. return false;
  597. bip->bli_flags |= XFS_BLI_ORDERED;
  598. trace_xfs_buf_item_ordered(bip);
  599. /*
  600. * We don't log a dirty range of an ordered buffer but it still needs
  601. * to be marked dirty and that it has been logged.
  602. */
  603. xfs_trans_dirty_buf(tp, bp);
  604. return true;
  605. }
  606. /*
  607. * Set the type of the buffer for log recovery so that it can correctly identify
  608. * and hence attach the correct buffer ops to the buffer after replay.
  609. */
  610. void
  611. xfs_trans_buf_set_type(
  612. struct xfs_trans *tp,
  613. struct xfs_buf *bp,
  614. enum xfs_blft type)
  615. {
  616. struct xfs_buf_log_item *bip = bp->b_log_item;
  617. if (!tp)
  618. return;
  619. ASSERT(bp->b_transp == tp);
  620. ASSERT(bip != NULL);
  621. ASSERT(atomic_read(&bip->bli_refcount) > 0);
  622. xfs_blft_to_flags(&bip->__bli_format, type);
  623. }
  624. void
  625. xfs_trans_buf_copy_type(
  626. struct xfs_buf *dst_bp,
  627. struct xfs_buf *src_bp)
  628. {
  629. struct xfs_buf_log_item *sbip = src_bp->b_log_item;
  630. struct xfs_buf_log_item *dbip = dst_bp->b_log_item;
  631. enum xfs_blft type;
  632. type = xfs_blft_from_flags(&sbip->__bli_format);
  633. xfs_blft_to_flags(&dbip->__bli_format, type);
  634. }
  635. /*
  636. * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
  637. * dquots. However, unlike in inode buffer recovery, dquot buffers get
  638. * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
  639. * The only thing that makes dquot buffers different from regular
  640. * buffers is that we must not replay dquot bufs when recovering
  641. * if a _corresponding_ quotaoff has happened. We also have to distinguish
  642. * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
  643. * can be turned off independently.
  644. */
  645. /* ARGSUSED */
  646. void
  647. xfs_trans_dquot_buf(
  648. xfs_trans_t *tp,
  649. xfs_buf_t *bp,
  650. uint type)
  651. {
  652. struct xfs_buf_log_item *bip = bp->b_log_item;
  653. ASSERT(type == XFS_BLF_UDQUOT_BUF ||
  654. type == XFS_BLF_PDQUOT_BUF ||
  655. type == XFS_BLF_GDQUOT_BUF);
  656. bip->__bli_format.blf_flags |= type;
  657. switch (type) {
  658. case XFS_BLF_UDQUOT_BUF:
  659. type = XFS_BLFT_UDQUOT_BUF;
  660. break;
  661. case XFS_BLF_PDQUOT_BUF:
  662. type = XFS_BLFT_PDQUOT_BUF;
  663. break;
  664. case XFS_BLF_GDQUOT_BUF:
  665. type = XFS_BLFT_GDQUOT_BUF;
  666. break;
  667. default:
  668. type = XFS_BLFT_UNKNOWN_BUF;
  669. break;
  670. }
  671. bp->b_flags |= _XBF_DQUOTS;
  672. xfs_trans_buf_set_type(tp, bp, type);
  673. }