blob: 6549e50d852c0e3f87d14db64680b57a8db7c2f8 [file] [log] [blame]
Dave Chinner0b61f8a2018-06-05 19:42:14 -07001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Nathan Scott7b718762005-11-02 14:58:39 +11003 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +11007#include "xfs_fs.h"
Dave Chinner70a98832013-10-23 10:36:05 +11008#include "xfs_shared.h"
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11009#include "xfs_format.h"
Dave Chinner239880e2013-10-23 10:50:10 +110010#include "xfs_log_format.h"
11#include "xfs_trans_resv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include "xfs_mount.h"
Dave Chinner239880e2013-10-23 10:50:10 +110013#include "xfs_trans.h"
Nathan Scotta844f452005-11-02 14:38:42 +110014#include "xfs_buf_item.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include "xfs_trans_priv.h"
Christoph Hellwig0b1b2132009-12-14 23:14:59 +000016#include "xfs_trace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Christoph Hellwig4a5224d2010-04-18 00:10:45 +000018/*
19 * Check to see if a buffer matching the given parameters is already
20 * a part of the given transaction.
21 */
22STATIC struct xfs_buf *
23xfs_trans_buf_item_match(
24 struct xfs_trans *tp,
25 struct xfs_buftarg *target,
Dave Chinnerde2a4f52012-06-22 18:50:11 +100026 struct xfs_buf_map *map,
27 int nmaps)
Christoph Hellwig4a5224d2010-04-18 00:10:45 +000028{
Dave Chinnere6631f82018-05-09 07:49:37 -070029 struct xfs_log_item *lip;
Christoph Hellwige98c4142010-06-23 18:11:15 +100030 struct xfs_buf_log_item *blip;
Dave Chinnerde2a4f52012-06-22 18:50:11 +100031 int len = 0;
32 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Dave Chinnerde2a4f52012-06-22 18:50:11 +100034 for (i = 0; i < nmaps; i++)
35 len += map[i].bm_len;
36
Dave Chinnere6631f82018-05-09 07:49:37 -070037 list_for_each_entry(lip, &tp->t_items, li_trans) {
38 blip = (struct xfs_buf_log_item *)lip;
Christoph Hellwige98c4142010-06-23 18:11:15 +100039 if (blip->bli_item.li_type == XFS_LI_BUF &&
Chandra Seetharaman49074c02011-07-22 23:40:40 +000040 blip->bli_buf->b_target == target &&
Dave Chinner04fcad82021-08-18 18:46:57 -070041 xfs_buf_daddr(blip->bli_buf) == map[0].bm_bn &&
Dave Chinnerde2a4f52012-06-22 18:50:11 +100042 blip->bli_buf->b_length == len) {
43 ASSERT(blip->bli_buf->b_map_count == nmaps);
Christoph Hellwige98c4142010-06-23 18:11:15 +100044 return blip->bli_buf;
Dave Chinnerde2a4f52012-06-22 18:50:11 +100045 }
Christoph Hellwig4a5224d2010-04-18 00:10:45 +000046 }
47
48 return NULL;
49}
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000051/*
52 * Add the locked buffer to the transaction.
53 *
54 * The buffer must be locked, and it cannot be associated with any
55 * transaction.
56 *
57 * If the buffer does not yet have a buf log item associated with it,
58 * then allocate one for it. Then add the buf item to the transaction.
59 */
60STATIC void
61_xfs_trans_bjoin(
62 struct xfs_trans *tp,
63 struct xfs_buf *bp,
64 int reset_recur)
65{
66 struct xfs_buf_log_item *bip;
67
Christoph Hellwigbf9d9012011-07-13 13:43:49 +020068 ASSERT(bp->b_transp == NULL);
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000069
70 /*
Carlos Maiolinofb1755a2018-01-24 13:38:48 -080071 * The xfs_buf_log_item pointer is stored in b_log_item. If
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000072 * it doesn't have one yet, then allocate one and initialize it.
73 * The checks to see if one is there are in xfs_buf_item_init().
74 */
75 xfs_buf_item_init(bp, tp->t_mountp);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -080076 bip = bp->b_log_item;
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000077 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -060078 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000079 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
80 if (reset_recur)
81 bip->bli_recur = 0;
82
83 /*
84 * Take a reference for this transaction on the buf item.
85 */
86 atomic_inc(&bip->bli_refcount);
87
88 /*
Dave Chinnere6631f82018-05-09 07:49:37 -070089 * Attach the item to the transaction so we can find it in
90 * xfs_trans_get_buf() and friends.
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000091 */
Christoph Hellwige98c4142010-06-23 18:11:15 +100092 xfs_trans_add_item(tp, &bip->bli_item);
Christoph Hellwigbf9d9012011-07-13 13:43:49 +020093 bp->b_transp = tp;
Christoph Hellwigd7e84f42010-02-15 23:35:09 +000094
95}
96
97void
98xfs_trans_bjoin(
99 struct xfs_trans *tp,
100 struct xfs_buf *bp)
101{
102 _xfs_trans_bjoin(tp, bp, 0);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800103 trace_xfs_trans_bjoin(bp->b_log_item);
Christoph Hellwigd7e84f42010-02-15 23:35:09 +0000104}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106/*
107 * Get and lock the buffer for the caller if it is not already
108 * locked within the given transaction. If it is already locked
109 * within the transaction, just increment its lock recursion count
110 * and return a pointer to it.
111 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * If the transaction pointer is NULL, make this just a normal
113 * get_buf() call.
114 */
Darrick J. Wong9676b542020-01-23 17:01:18 -0800115int
Dave Chinnerde2a4f52012-06-22 18:50:11 +1000116xfs_trans_get_buf_map(
117 struct xfs_trans *tp,
118 struct xfs_buftarg *target,
119 struct xfs_buf_map *map,
120 int nmaps,
Darrick J. Wong9676b542020-01-23 17:01:18 -0800121 xfs_buf_flags_t flags,
122 struct xfs_buf **bpp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123{
Dave Chinnere8222612020-12-16 16:07:34 -0800124 struct xfs_buf *bp;
Carlos Maiolino70a20652018-01-24 13:38:48 -0800125 struct xfs_buf_log_item *bip;
Darrick J. Wong3848b5f2020-01-23 17:01:15 -0800126 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Darrick J. Wong9676b542020-01-23 17:01:18 -0800128 *bpp = NULL;
129 if (!tp)
130 return xfs_buf_get_map(target, map, nmaps, flags, bpp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /*
133 * If we find the buffer in the cache with this transaction
134 * pointer in its b_fsprivate2 field, then we know we already
135 * have it locked. In this case we just increment the lock
136 * recursion count and return the buffer to the caller.
137 */
Dave Chinnerde2a4f52012-06-22 18:50:11 +1000138 bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (bp != NULL) {
Christoph Hellwig0c842ad2011-07-08 14:36:19 +0200140 ASSERT(xfs_buf_islocked(bp));
Dave Chinner75c8c50f2021-08-18 18:46:53 -0700141 if (xfs_is_shutdown(tp->t_mountp)) {
Christoph Hellwigc867cb62011-10-10 16:52:46 +0000142 xfs_buf_stale(bp);
Dave Chinnerb0388bf2016-02-10 15:01:11 +1100143 bp->b_flags |= XBF_DONE;
Christoph Hellwigc867cb62011-10-10 16:52:46 +0000144 }
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000145
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200146 ASSERT(bp->b_transp == tp);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800147 bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 ASSERT(bip != NULL);
149 ASSERT(atomic_read(&bip->bli_refcount) > 0);
150 bip->bli_recur++;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000151 trace_xfs_trans_get_buf_recur(bip);
Darrick J. Wong9676b542020-01-23 17:01:18 -0800152 *bpp = bp;
153 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 }
155
Darrick J. Wong3848b5f2020-01-23 17:01:15 -0800156 error = xfs_buf_get_map(target, map, nmaps, flags, &bp);
157 if (error)
Darrick J. Wong9676b542020-01-23 17:01:18 -0800158 return error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Chandra Seetharaman5a52c2a582011-07-22 23:39:51 +0000160 ASSERT(!bp->b_error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Christoph Hellwigd7e84f42010-02-15 23:35:09 +0000162 _xfs_trans_bjoin(tp, bp, 1);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800163 trace_xfs_trans_get_buf(bp->b_log_item);
Darrick J. Wong9676b542020-01-23 17:01:18 -0800164 *bpp = bp;
165 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168/*
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700169 * Get and lock the superblock buffer for the given transaction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 */
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700171struct xfs_buf *
Carlos Maiolino70a20652018-01-24 13:38:48 -0800172xfs_trans_getsb(
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700173 struct xfs_trans *tp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700175 struct xfs_buf *bp = tp->t_mountp->m_sb_bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 /*
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700178 * Just increment the lock recursion count if the buffer is already
179 * attached to this transaction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 */
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200181 if (bp->b_transp == tp) {
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700182 struct xfs_buf_log_item *bip = bp->b_log_item;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 ASSERT(bip != NULL);
185 ASSERT(atomic_read(&bip->bli_refcount) > 0);
186 bip->bli_recur++;
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700187
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000188 trace_xfs_trans_getsb_recur(bip);
Christoph Hellwigcead0b12020-09-01 10:55:47 -0700189 } else {
190 xfs_buf_lock(bp);
191 xfs_buf_hold(bp);
192 _xfs_trans_bjoin(tp, bp, 1);
193
194 trace_xfs_trans_getsb(bp->b_log_item);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
Eric Sandeend99831f2014-06-22 15:03:54 +1000197 return bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198}
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200/*
201 * Get and lock the buffer for the caller if it is not already
202 * locked within the given transaction. If it has not yet been
203 * read in, read it from disk. If it is already locked
204 * within the transaction and already read in, just increment its
205 * lock recursion count and return a pointer to it.
206 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 * If the transaction pointer is NULL, make this just a normal
208 * read_buf() call.
209 */
210int
Dave Chinnerde2a4f52012-06-22 18:50:11 +1000211xfs_trans_read_buf_map(
212 struct xfs_mount *mp,
213 struct xfs_trans *tp,
214 struct xfs_buftarg *target,
215 struct xfs_buf_map *map,
216 int nmaps,
217 xfs_buf_flags_t flags,
Dave Chinnerc3f8fc72012-11-12 22:54:01 +1100218 struct xfs_buf **bpp,
Dave Chinner1813dd62012-11-14 17:54:40 +1100219 const struct xfs_buf_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100221 struct xfs_buf *bp = NULL;
222 struct xfs_buf_log_item *bip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 int error;
224
Dave Chinner7ca790a2012-04-23 15:58:55 +1000225 *bpp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 /*
227 * If we find the buffer in the cache with this transaction
228 * pointer in its b_fsprivate2 field, then we know we already
229 * have it locked. If it is already read in we just increment
230 * the lock recursion count and return the buffer to the caller.
231 * If the buffer is not yet read in, then we read it in, increment
232 * the lock recursion count, and return it to the caller.
233 */
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100234 if (tp)
235 bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
236 if (bp) {
Christoph Hellwig0c842ad2011-07-08 14:36:19 +0200237 ASSERT(xfs_buf_islocked(bp));
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200238 ASSERT(bp->b_transp == tp);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800239 ASSERT(bp->b_log_item != NULL);
Chandra Seetharaman5a52c2a582011-07-22 23:39:51 +0000240 ASSERT(!bp->b_error);
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100241 ASSERT(bp->b_flags & XBF_DONE);
Christoph Hellwig83a0adc2013-12-17 00:03:52 -0800242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 /*
244 * We never locked this buf ourselves, so we shouldn't
245 * brelse it either. Just get out.
246 */
Dave Chinner75c8c50f2021-08-18 18:46:53 -0700247 if (xfs_is_shutdown(mp)) {
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000248 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
Dave Chinner24513372014-06-25 14:58:08 +1000249 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 }
251
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100252 /*
253 * Check if the caller is trying to read a buffer that is
254 * already attached to the transaction yet has no buffer ops
255 * assigned. Ops are usually attached when the buffer is
256 * attached to the transaction, or by the read caller if
257 * special circumstances. That didn't happen, which is not
258 * how this is supposed to go.
259 *
260 * If the buffer passes verification we'll let this go, but if
261 * not we have to shut down. Let the transaction cleanup code
262 * release this buffer when it kills the tranaction.
263 */
264 ASSERT(bp->b_ops != NULL);
Brian Foster75d02302019-02-06 09:25:29 -0800265 error = xfs_buf_reverify(bp, ops);
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100266 if (error) {
Darrick J. Wongcdbcf822020-01-23 17:01:20 -0800267 xfs_buf_ioerror_alert(bp, __return_address);
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100268
269 if (tp->t_flags & XFS_TRANS_DIRTY)
270 xfs_force_shutdown(tp->t_mountp,
271 SHUTDOWN_META_IO_ERROR);
272
273 /* bad CRC means corrupted metadata */
274 if (error == -EFSBADCRC)
275 error = -EFSCORRUPTED;
276 return error;
277 }
278
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800279 bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 bip->bli_recur++;
281
282 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000283 trace_xfs_trans_read_buf_recur(bip);
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100284 ASSERT(bp->b_ops != NULL || ops == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 *bpp = bp;
286 return 0;
287 }
288
Darrick J. Wongcdbcf822020-01-23 17:01:20 -0800289 error = xfs_buf_read_map(target, map, nmaps, flags, &bp, ops,
290 __return_address);
Darrick J. Wong4ed8e272020-01-23 17:01:16 -0800291 switch (error) {
292 case 0:
293 break;
294 default:
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100295 if (tp && (tp->t_flags & XFS_TRANS_DIRTY))
Nathan Scott7d04a332006-06-09 14:58:38 +1000296 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
Gustavo A. R. Silva53004ee2021-04-20 17:54:36 -0500297 fallthrough;
Darrick J. Wong4ed8e272020-01-23 17:01:16 -0800298 case -ENOMEM:
299 case -EAGAIN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return error;
301 }
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100302
Dave Chinner75c8c50f2021-08-18 18:46:53 -0700303 if (xfs_is_shutdown(mp)) {
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100304 xfs_buf_relse(bp);
305 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
306 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Dave Chinnere9892d32015-02-10 09:23:40 +1100309 if (tp) {
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100310 _xfs_trans_bjoin(tp, bp, 1);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800311 trace_xfs_trans_read_buf(bp->b_log_item);
Dave Chinnere9892d32015-02-10 09:23:40 +1100312 }
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100313 ASSERT(bp->b_ops != NULL || ops == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 *bpp = bp;
315 return 0;
316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
Darrick J. Wong38b62382018-10-18 17:20:35 +1100319/* Has this buffer been dirtied by anyone? */
320bool
321xfs_trans_buf_is_dirty(
322 struct xfs_buf *bp)
323{
324 struct xfs_buf_log_item *bip = bp->b_log_item;
325
326 if (!bip)
327 return false;
328 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
329 return test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
330}
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332/*
Brian Foster23420d02018-09-29 13:45:02 +1000333 * Release a buffer previously joined to the transaction. If the buffer is
334 * modified within this transaction, decrement the recursion count but do not
335 * release the buffer even if the count goes to 0. If the buffer is not modified
336 * within the transaction, decrement the recursion count and release the buffer
337 * if the recursion count goes to 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 *
Brian Foster23420d02018-09-29 13:45:02 +1000339 * If the buffer is to be released and it was not already dirty before this
340 * transaction began, then also free the buf_log_item associated with it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 *
Brian Foster23420d02018-09-29 13:45:02 +1000342 * If the transaction pointer is NULL, this is a normal xfs_buf_relse() call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 */
344void
Carlos Maiolino70a20652018-01-24 13:38:48 -0800345xfs_trans_brelse(
Brian Foster23420d02018-09-29 13:45:02 +1000346 struct xfs_trans *tp,
347 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Brian Foster23420d02018-09-29 13:45:02 +1000349 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Brian Foster23420d02018-09-29 13:45:02 +1000351 ASSERT(bp->b_transp == tp);
352
353 if (!tp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 xfs_buf_relse(bp);
355 return;
356 }
357
Brian Foster23420d02018-09-29 13:45:02 +1000358 trace_xfs_trans_brelse(bip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 ASSERT(atomic_read(&bip->bli_refcount) > 0);
361
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 /*
Brian Foster23420d02018-09-29 13:45:02 +1000363 * If the release is for a recursive lookup, then decrement the count
364 * and return.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 */
366 if (bip->bli_recur > 0) {
367 bip->bli_recur--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 return;
369 }
370
371 /*
Brian Foster23420d02018-09-29 13:45:02 +1000372 * If the buffer is invalidated or dirty in this transaction, we can't
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 * release it until we commit.
374 */
Dave Chinnere6631f82018-05-09 07:49:37 -0700375 if (test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000377 if (bip->bli_flags & XFS_BLI_STALE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Brian Foster23420d02018-09-29 13:45:02 +1000380 /*
381 * Unlink the log item from the transaction and clear the hold flag, if
382 * set. We wouldn't want the next user of the buffer to get confused.
383 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
Christoph Hellwige98c4142010-06-23 18:11:15 +1000385 xfs_trans_del_item(&bip->bli_item);
Brian Foster23420d02018-09-29 13:45:02 +1000386 bip->bli_flags &= ~XFS_BLI_HOLD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Brian Foster95808452018-09-29 13:45:26 +1000388 /* drop the reference to the bli */
389 xfs_buf_item_put(bip);
Christoph Hellwig5b03ff12012-02-20 02:31:22 +0000390
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200391 bp->b_transp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 xfs_buf_relse(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393}
394
395/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 * Mark the buffer as not needing to be unlocked when the buf item's
Christoph Hellwigddf92052019-06-28 19:27:32 -0700397 * iop_committing() routine is called. The buffer must already be locked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 * and associated with the given transaction.
399 */
400/* ARGSUSED */
401void
Carlos Maiolino70a20652018-01-24 13:38:48 -0800402xfs_trans_bhold(
403 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800404 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800406 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200408 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200409 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600411 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 bip->bli_flags |= XFS_BLI_HOLD;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000415 trace_xfs_trans_bhold(bip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
418/*
Tim Shimminefa092f2005-09-05 08:29:01 +1000419 * Cancel the previous buffer hold request made on this buffer
420 * for this transaction.
421 */
422void
Carlos Maiolino70a20652018-01-24 13:38:48 -0800423xfs_trans_bhold_release(
424 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800425 struct xfs_buf *bp)
Tim Shimminefa092f2005-09-05 08:29:01 +1000426{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800427 struct xfs_buf_log_item *bip = bp->b_log_item;
Tim Shimminefa092f2005-09-05 08:29:01 +1000428
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200429 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200430 ASSERT(bip != NULL);
Tim Shimminefa092f2005-09-05 08:29:01 +1000431 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600432 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
Tim Shimminefa092f2005-09-05 08:29:01 +1000433 ASSERT(atomic_read(&bip->bli_refcount) > 0);
434 ASSERT(bip->bli_flags & XFS_BLI_HOLD);
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000435
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200436 bip->bli_flags &= ~XFS_BLI_HOLD;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000437 trace_xfs_trans_bhold_release(bip);
Tim Shimminefa092f2005-09-05 08:29:01 +1000438}
439
440/*
Brian Foster96840102017-08-29 10:08:38 -0700441 * Mark a buffer dirty in the transaction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 */
443void
Brian Foster96840102017-08-29 10:08:38 -0700444xfs_trans_dirty_buf(
445 struct xfs_trans *tp,
446 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800448 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200450 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200451 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 /*
454 * Mark the buffer as needing to be written out eventually,
455 * and set its iodone function to remove the buffer's buf log
456 * item from the AIL and free it when the buffer is flushed
Dave Chinnerb01d1462020-06-29 14:48:47 -0700457 * to disk.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 */
Dave Chinnerb0388bf2016-02-10 15:01:11 +1100459 bp->b_flags |= XBF_DONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 /*
464 * If we invalidated the buffer within this transaction, then
465 * cancel the invalidation now that we're dirtying the buffer
466 * again. There are no races with the code in xfs_buf_item_unpin(),
467 * because we have a reference to the buffer this entire time.
468 */
469 if (bip->bli_flags & XFS_BLI_STALE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 bip->bli_flags &= ~XFS_BLI_STALE;
Dave Chinner5cfd28b2016-02-10 15:01:11 +1100471 ASSERT(bp->b_flags & XBF_STALE);
472 bp->b_flags &= ~XBF_STALE;
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600473 bip->__bli_format.blf_flags &= ~XFS_BLF_CANCEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
Brian Foster96840102017-08-29 10:08:38 -0700475 bip->bli_flags |= XFS_BLI_DIRTY | XFS_BLI_LOGGED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 tp->t_flags |= XFS_TRANS_DIRTY;
Dave Chinnere6631f82018-05-09 07:49:37 -0700478 set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
Brian Foster96840102017-08-29 10:08:38 -0700479}
480
481/*
482 * This is called to mark bytes first through last inclusive of the given
483 * buffer as needing to be logged when the transaction is committed.
484 * The buffer must already be associated with the given transaction.
485 *
486 * First and last are numbers relative to the beginning of this buffer,
487 * so the first byte in the buffer is numbered 0 regardless of the
488 * value of b_blkno.
489 */
490void
491xfs_trans_log_buf(
492 struct xfs_trans *tp,
493 struct xfs_buf *bp,
494 uint first,
495 uint last)
496{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800497 struct xfs_buf_log_item *bip = bp->b_log_item;
Brian Foster96840102017-08-29 10:08:38 -0700498
499 ASSERT(first <= last && last < BBTOB(bp->b_length));
Brian Foster8dc518d2017-08-29 10:08:38 -0700500 ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED));
Brian Foster96840102017-08-29 10:08:38 -0700501
502 xfs_trans_dirty_buf(tp, bp);
Dave Chinner5f6bed72013-06-27 16:04:52 +1000503
Brian Foster96840102017-08-29 10:08:38 -0700504 trace_xfs_trans_log_buf(bip);
Brian Foster8dc518d2017-08-29 10:08:38 -0700505 xfs_buf_item_log(bip, first, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506}
507
508
509/*
Christoph Hellwig43ff2122012-04-23 15:58:39 +1000510 * Invalidate a buffer that is being used within a transaction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 *
Christoph Hellwig43ff2122012-04-23 15:58:39 +1000512 * Typically this is because the blocks in the buffer are being freed, so we
513 * need to prevent it from being written out when we're done. Allowing it
514 * to be written again might overwrite data in the free blocks if they are
515 * reallocated to a file.
516 *
517 * We prevent the buffer from being written out by marking it stale. We can't
518 * get rid of the buf log item at this point because the buffer may still be
519 * pinned by another transaction. If that is the case, then we'll wait until
520 * the buffer is committed to disk for the last time (we can tell by the ref
521 * count) and free it in xfs_buf_item_unpin(). Until that happens we will
522 * keep the buffer locked so that the buffer and buf log item are not reused.
523 *
524 * We also set the XFS_BLF_CANCEL flag in the buf log format structure and log
525 * the buf item. This will be used at recovery time to determine that copies
526 * of the buffer in the log before this should not be replayed.
527 *
528 * We mark the item descriptor and the transaction dirty so that we'll hold
529 * the buffer until after the commit.
530 *
531 * Since we're invalidating the buffer, we also clear the state about which
532 * parts of the buffer have been logged. We also clear the flag indicating
533 * that this is an inode buffer since the data in the buffer will no longer
534 * be valid.
535 *
536 * We set the stale bit in the buffer as well since we're getting rid of it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 */
538void
539xfs_trans_binval(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800540 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800541 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800543 struct xfs_buf_log_item *bip = bp->b_log_item;
Mark Tinguely91e4bac2012-12-04 17:18:05 -0600544 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200546 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200547 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 ASSERT(atomic_read(&bip->bli_refcount) > 0);
549
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000550 trace_xfs_trans_binval(bip);
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (bip->bli_flags & XFS_BLI_STALE) {
553 /*
554 * If the buffer is already invalidated, then
555 * just return.
556 */
Dave Chinner5cfd28b2016-02-10 15:01:11 +1100557 ASSERT(bp->b_flags & XBF_STALE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600559 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_INODE_BUF));
Dave Chinner61fe1352013-04-03 16:11:30 +1100560 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLFT_MASK));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600561 ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
Dave Chinnere6631f82018-05-09 07:49:37 -0700562 ASSERT(test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 return;
565 }
566
Christoph Hellwigc867cb62011-10-10 16:52:46 +0000567 xfs_buf_stale(bp);
Christoph Hellwig43ff2122012-04-23 15:58:39 +1000568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 bip->bli_flags |= XFS_BLI_STALE;
Dave Chinnerccf7c232010-05-20 23:19:42 +1000570 bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600571 bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
572 bip->__bli_format.blf_flags |= XFS_BLF_CANCEL;
Dave Chinner61fe1352013-04-03 16:11:30 +1100573 bip->__bli_format.blf_flags &= ~XFS_BLFT_MASK;
Mark Tinguely91e4bac2012-12-04 17:18:05 -0600574 for (i = 0; i < bip->bli_format_count; i++) {
575 memset(bip->bli_formats[i].blf_data_map, 0,
576 (bip->bli_formats[i].blf_map_size * sizeof(uint)));
577 }
Dave Chinnere6631f82018-05-09 07:49:37 -0700578 set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 tp->t_flags |= XFS_TRANS_DIRTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580}
581
582/*
Dave Chinnerccf7c232010-05-20 23:19:42 +1000583 * This call is used to indicate that the buffer contains on-disk inodes which
584 * must be handled specially during recovery. They require special handling
585 * because only the di_next_unlinked from the inodes in the buffer should be
586 * recovered. The rest of the data in the buffer is logged via the inodes
587 * themselves.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 *
Dave Chinnerccf7c232010-05-20 23:19:42 +1000589 * All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be
590 * transferred to the buffer's log format structure so that we'll know what to
591 * do at recovery time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593void
594xfs_trans_inode_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800595 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800596 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800598 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200600 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200601 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 ASSERT(atomic_read(&bip->bli_refcount) > 0);
603
Dave Chinnerccf7c232010-05-20 23:19:42 +1000604 bip->bli_flags |= XFS_BLI_INODE_BUF;
Dave Chinnerf593bf12020-06-29 14:48:46 -0700605 bp->b_flags |= _XBF_INODES;
Dave Chinner61fe1352013-04-03 16:11:30 +1100606 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
609/*
610 * This call is used to indicate that the buffer is going to
611 * be staled and was an inode buffer. This means it gets
Christoph Hellwig93848a92013-04-03 16:11:17 +1100612 * special processing during unpin - where any inodes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 * associated with the buffer should be removed from ail.
614 * There is also special processing during recovery,
615 * any replay of the inodes in the buffer needs to be
616 * prevented as the buffer may have been reused.
617 */
618void
619xfs_trans_stale_inode_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800620 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800621 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800623 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200625 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200626 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 ASSERT(atomic_read(&bip->bli_refcount) > 0);
628
629 bip->bli_flags |= XFS_BLI_STALE_INODE;
Dave Chinnerf593bf12020-06-29 14:48:46 -0700630 bp->b_flags |= _XBF_INODES;
Dave Chinner61fe1352013-04-03 16:11:30 +1100631 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}
633
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634/*
635 * Mark the buffer as being one which contains newly allocated
636 * inodes. We need to make sure that even if this buffer is
637 * relogged as an 'inode buf' we still recover all of the inode
638 * images in the face of a crash. This works in coordination with
639 * xfs_buf_item_committed() to ensure that the buffer remains in the
640 * AIL at its original location even after it has been relogged.
641 */
642/* ARGSUSED */
643void
644xfs_trans_inode_alloc_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800645 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800646 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800648 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200650 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200651 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 ASSERT(atomic_read(&bip->bli_refcount) > 0);
653
654 bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
Dave Chinnerf593bf12020-06-29 14:48:46 -0700655 bp->b_flags |= _XBF_INODES;
Dave Chinner61fe1352013-04-03 16:11:30 +1100656 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500659/*
Brian Foster8dc518d2017-08-29 10:08:38 -0700660 * Mark the buffer as ordered for this transaction. This means that the contents
661 * of the buffer are not recorded in the transaction but it is tracked in the
662 * AIL as though it was. This allows us to record logical changes in
663 * transactions rather than the physical changes we make to the buffer without
664 * changing writeback ordering constraints of metadata buffers.
Dave Chinner5f6bed72013-06-27 16:04:52 +1000665 */
Brian Fostera5814bc2017-08-29 10:08:40 -0700666bool
Dave Chinner5f6bed72013-06-27 16:04:52 +1000667xfs_trans_ordered_buf(
668 struct xfs_trans *tp,
669 struct xfs_buf *bp)
670{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800671 struct xfs_buf_log_item *bip = bp->b_log_item;
Dave Chinner5f6bed72013-06-27 16:04:52 +1000672
673 ASSERT(bp->b_transp == tp);
674 ASSERT(bip != NULL);
675 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Brian Fostera5814bc2017-08-29 10:08:40 -0700676
677 if (xfs_buf_item_dirty_format(bip))
678 return false;
Dave Chinner5f6bed72013-06-27 16:04:52 +1000679
680 bip->bli_flags |= XFS_BLI_ORDERED;
681 trace_xfs_buf_item_ordered(bip);
Brian Foster8dc518d2017-08-29 10:08:38 -0700682
683 /*
684 * We don't log a dirty range of an ordered buffer but it still needs
685 * to be marked dirty and that it has been logged.
686 */
687 xfs_trans_dirty_buf(tp, bp);
Brian Fostera5814bc2017-08-29 10:08:40 -0700688 return true;
Dave Chinner5f6bed72013-06-27 16:04:52 +1000689}
690
691/*
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500692 * Set the type of the buffer for log recovery so that it can correctly identify
693 * and hence attach the correct buffer ops to the buffer after replay.
694 */
695void
696xfs_trans_buf_set_type(
697 struct xfs_trans *tp,
698 struct xfs_buf *bp,
Dave Chinner61fe1352013-04-03 16:11:30 +1100699 enum xfs_blft type)
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500700{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800701 struct xfs_buf_log_item *bip = bp->b_log_item;
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500702
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100703 if (!tp)
704 return;
705
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500706 ASSERT(bp->b_transp == tp);
707 ASSERT(bip != NULL);
708 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500709
Dave Chinner61fe1352013-04-03 16:11:30 +1100710 xfs_blft_to_flags(&bip->__bli_format, type);
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500711}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100713void
714xfs_trans_buf_copy_type(
715 struct xfs_buf *dst_bp,
716 struct xfs_buf *src_bp)
717{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800718 struct xfs_buf_log_item *sbip = src_bp->b_log_item;
719 struct xfs_buf_log_item *dbip = dst_bp->b_log_item;
Dave Chinner61fe1352013-04-03 16:11:30 +1100720 enum xfs_blft type;
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100721
Dave Chinner61fe1352013-04-03 16:11:30 +1100722 type = xfs_blft_from_flags(&sbip->__bli_format);
723 xfs_blft_to_flags(&dbip->__bli_format, type);
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100724}
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726/*
727 * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
728 * dquots. However, unlike in inode buffer recovery, dquot buffers get
729 * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
730 * The only thing that makes dquot buffers different from regular
731 * buffers is that we must not replay dquot bufs when recovering
732 * if a _corresponding_ quotaoff has happened. We also have to distinguish
733 * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
734 * can be turned off independently.
735 */
736/* ARGSUSED */
737void
738xfs_trans_dquot_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800739 xfs_trans_t *tp,
Dave Chinnere8222612020-12-16 16:07:34 -0800740 struct xfs_buf *bp,
Carlos Maiolino70a20652018-01-24 13:38:48 -0800741 uint type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800743 struct xfs_buf_log_item *bip = bp->b_log_item;
Dave Chinner61fe1352013-04-03 16:11:30 +1100744
Dave Chinnerc1155412010-05-07 11:05:19 +1000745 ASSERT(type == XFS_BLF_UDQUOT_BUF ||
746 type == XFS_BLF_PDQUOT_BUF ||
747 type == XFS_BLF_GDQUOT_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Dave Chinner61fe1352013-04-03 16:11:30 +1100749 bip->__bli_format.blf_flags |= type;
750
751 switch (type) {
752 case XFS_BLF_UDQUOT_BUF:
753 type = XFS_BLFT_UDQUOT_BUF;
754 break;
755 case XFS_BLF_PDQUOT_BUF:
756 type = XFS_BLFT_PDQUOT_BUF;
757 break;
758 case XFS_BLF_GDQUOT_BUF:
759 type = XFS_BLFT_GDQUOT_BUF;
760 break;
761 default:
762 type = XFS_BLFT_UNKNOWN_BUF;
763 break;
764 }
765
Dave Chinner0c7e5af2020-06-29 14:48:46 -0700766 bp->b_flags |= _XBF_DQUOTS;
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500767 xfs_trans_buf_set_type(tp, bp, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}