blob: 93d62cb864c1549c609ffd9faf51bfac6773c267 [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 Chinnerde2a4f52012-06-22 18:50:11 +100041 XFS_BUF_ADDR(blip->bli_buf) == map[0].bm_bn &&
42 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{
124 xfs_buf_t *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));
Christoph Hellwigc867cb62011-10-10 16:52:46 +0000141 if (XFS_FORCED_SHUTDOWN(tp->t_mountp)) {
142 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/*
169 * Get and lock the superblock buffer of this file system for the
170 * given transaction.
171 *
172 * We don't need to use incore_match() here, because the superblock
173 * buffer is a private buffer which we keep a pointer to in the
174 * mount structure.
175 */
176xfs_buf_t *
Carlos Maiolino70a20652018-01-24 13:38:48 -0800177xfs_trans_getsb(
178 xfs_trans_t *tp,
Eric Sandeen8c9ce2f2019-06-12 08:59:58 -0700179 struct xfs_mount *mp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180{
181 xfs_buf_t *bp;
Carlos Maiolino70a20652018-01-24 13:38:48 -0800182 struct xfs_buf_log_item *bip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /*
185 * Default to just trying to lock the superblock buffer
186 * if tp is NULL.
187 */
Eric Sandeend99831f2014-06-22 15:03:54 +1000188 if (tp == NULL)
Eric Sandeen8c9ce2f2019-06-12 08:59:58 -0700189 return xfs_getsb(mp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /*
192 * If the superblock buffer already has this transaction
193 * pointer in its b_fsprivate2 field, then we know we already
194 * have it locked. In this case we just increment the lock
195 * recursion count and return the buffer to the caller.
196 */
197 bp = mp->m_sb_bp;
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200198 if (bp->b_transp == tp) {
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800199 bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 ASSERT(bip != NULL);
201 ASSERT(atomic_read(&bip->bli_refcount) > 0);
202 bip->bli_recur++;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000203 trace_xfs_trans_getsb_recur(bip);
Eric Sandeend99831f2014-06-22 15:03:54 +1000204 return bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 }
206
Eric Sandeen8c9ce2f2019-06-12 08:59:58 -0700207 bp = xfs_getsb(mp);
Christoph Hellwigd7e84f42010-02-15 23:35:09 +0000208 if (bp == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Christoph Hellwigd7e84f42010-02-15 23:35:09 +0000211 _xfs_trans_bjoin(tp, bp, 1);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800212 trace_xfs_trans_getsb(bp->b_log_item);
Eric Sandeend99831f2014-06-22 15:03:54 +1000213 return bp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214}
215
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216/*
217 * Get and lock the buffer for the caller if it is not already
218 * locked within the given transaction. If it has not yet been
219 * read in, read it from disk. If it is already locked
220 * within the transaction and already read in, just increment its
221 * lock recursion count and return a pointer to it.
222 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 * If the transaction pointer is NULL, make this just a normal
224 * read_buf() call.
225 */
226int
Dave Chinnerde2a4f52012-06-22 18:50:11 +1000227xfs_trans_read_buf_map(
228 struct xfs_mount *mp,
229 struct xfs_trans *tp,
230 struct xfs_buftarg *target,
231 struct xfs_buf_map *map,
232 int nmaps,
233 xfs_buf_flags_t flags,
Dave Chinnerc3f8fc72012-11-12 22:54:01 +1100234 struct xfs_buf **bpp,
Dave Chinner1813dd62012-11-14 17:54:40 +1100235 const struct xfs_buf_ops *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100237 struct xfs_buf *bp = NULL;
238 struct xfs_buf_log_item *bip;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 int error;
240
Dave Chinner7ca790a2012-04-23 15:58:55 +1000241 *bpp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 /*
243 * If we find the buffer in the cache with this transaction
244 * pointer in its b_fsprivate2 field, then we know we already
245 * have it locked. If it is already read in we just increment
246 * the lock recursion count and return the buffer to the caller.
247 * If the buffer is not yet read in, then we read it in, increment
248 * the lock recursion count, and return it to the caller.
249 */
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100250 if (tp)
251 bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
252 if (bp) {
Christoph Hellwig0c842ad2011-07-08 14:36:19 +0200253 ASSERT(xfs_buf_islocked(bp));
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200254 ASSERT(bp->b_transp == tp);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800255 ASSERT(bp->b_log_item != NULL);
Chandra Seetharaman5a52c2a582011-07-22 23:39:51 +0000256 ASSERT(!bp->b_error);
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100257 ASSERT(bp->b_flags & XBF_DONE);
Christoph Hellwig83a0adc2013-12-17 00:03:52 -0800258
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /*
260 * We never locked this buf ourselves, so we shouldn't
261 * brelse it either. Just get out.
262 */
263 if (XFS_FORCED_SHUTDOWN(mp)) {
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000264 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
Dave Chinner24513372014-06-25 14:58:08 +1000265 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100268 /*
269 * Check if the caller is trying to read a buffer that is
270 * already attached to the transaction yet has no buffer ops
271 * assigned. Ops are usually attached when the buffer is
272 * attached to the transaction, or by the read caller if
273 * special circumstances. That didn't happen, which is not
274 * how this is supposed to go.
275 *
276 * If the buffer passes verification we'll let this go, but if
277 * not we have to shut down. Let the transaction cleanup code
278 * release this buffer when it kills the tranaction.
279 */
280 ASSERT(bp->b_ops != NULL);
Brian Foster75d02302019-02-06 09:25:29 -0800281 error = xfs_buf_reverify(bp, ops);
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100282 if (error) {
Darrick J. Wongcdbcf822020-01-23 17:01:20 -0800283 xfs_buf_ioerror_alert(bp, __return_address);
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100284
285 if (tp->t_flags & XFS_TRANS_DIRTY)
286 xfs_force_shutdown(tp->t_mountp,
287 SHUTDOWN_META_IO_ERROR);
288
289 /* bad CRC means corrupted metadata */
290 if (error == -EFSBADCRC)
291 error = -EFSCORRUPTED;
292 return error;
293 }
294
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800295 bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 bip->bli_recur++;
297
298 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000299 trace_xfs_trans_read_buf_recur(bip);
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100300 ASSERT(bp->b_ops != NULL || ops == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 *bpp = bp;
302 return 0;
303 }
304
Darrick J. Wongcdbcf822020-01-23 17:01:20 -0800305 error = xfs_buf_read_map(target, map, nmaps, flags, &bp, ops,
306 __return_address);
Darrick J. Wong4ed8e272020-01-23 17:01:16 -0800307 switch (error) {
308 case 0:
309 break;
310 default:
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100311 if (tp && (tp->t_flags & XFS_TRANS_DIRTY))
Nathan Scott7d04a332006-06-09 14:58:38 +1000312 xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
Darrick J. Wong4ed8e272020-01-23 17:01:16 -0800313 /* fall through */
314 case -ENOMEM:
315 case -EAGAIN:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return error;
317 }
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100318
319 if (XFS_FORCED_SHUTDOWN(mp)) {
320 xfs_buf_relse(bp);
321 trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
322 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Dave Chinnere9892d32015-02-10 09:23:40 +1100325 if (tp) {
Dave Chinner2d3d0c52014-12-04 09:43:13 +1100326 _xfs_trans_bjoin(tp, bp, 1);
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800327 trace_xfs_trans_read_buf(bp->b_log_item);
Dave Chinnere9892d32015-02-10 09:23:40 +1100328 }
Darrick J. Wong1aff5692018-10-18 17:20:30 +1100329 ASSERT(bp->b_ops != NULL || ops == NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 *bpp = bp;
331 return 0;
332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334
Darrick J. Wong38b62382018-10-18 17:20:35 +1100335/* Has this buffer been dirtied by anyone? */
336bool
337xfs_trans_buf_is_dirty(
338 struct xfs_buf *bp)
339{
340 struct xfs_buf_log_item *bip = bp->b_log_item;
341
342 if (!bip)
343 return false;
344 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
345 return test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
346}
347
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348/*
Brian Foster23420d02018-09-29 13:45:02 +1000349 * Release a buffer previously joined to the transaction. If the buffer is
350 * modified within this transaction, decrement the recursion count but do not
351 * release the buffer even if the count goes to 0. If the buffer is not modified
352 * within the transaction, decrement the recursion count and release the buffer
353 * if the recursion count goes to 0.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 *
Brian Foster23420d02018-09-29 13:45:02 +1000355 * If the buffer is to be released and it was not already dirty before this
356 * transaction began, then also free the buf_log_item associated with it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 *
Brian Foster23420d02018-09-29 13:45:02 +1000358 * If the transaction pointer is NULL, this is a normal xfs_buf_relse() call.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359 */
360void
Carlos Maiolino70a20652018-01-24 13:38:48 -0800361xfs_trans_brelse(
Brian Foster23420d02018-09-29 13:45:02 +1000362 struct xfs_trans *tp,
363 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
Brian Foster23420d02018-09-29 13:45:02 +1000365 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Brian Foster23420d02018-09-29 13:45:02 +1000367 ASSERT(bp->b_transp == tp);
368
369 if (!tp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 xfs_buf_relse(bp);
371 return;
372 }
373
Brian Foster23420d02018-09-29 13:45:02 +1000374 trace_xfs_trans_brelse(bip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 ASSERT(atomic_read(&bip->bli_refcount) > 0);
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 /*
Brian Foster23420d02018-09-29 13:45:02 +1000379 * If the release is for a recursive lookup, then decrement the count
380 * and return.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 */
382 if (bip->bli_recur > 0) {
383 bip->bli_recur--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 return;
385 }
386
387 /*
Brian Foster23420d02018-09-29 13:45:02 +1000388 * If the buffer is invalidated or dirty in this transaction, we can't
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 * release it until we commit.
390 */
Dave Chinnere6631f82018-05-09 07:49:37 -0700391 if (test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000393 if (bip->bli_flags & XFS_BLI_STALE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Brian Foster23420d02018-09-29 13:45:02 +1000396 /*
397 * Unlink the log item from the transaction and clear the hold flag, if
398 * set. We wouldn't want the next user of the buffer to get confused.
399 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
Christoph Hellwige98c4142010-06-23 18:11:15 +1000401 xfs_trans_del_item(&bip->bli_item);
Brian Foster23420d02018-09-29 13:45:02 +1000402 bip->bli_flags &= ~XFS_BLI_HOLD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Brian Foster95808452018-09-29 13:45:26 +1000404 /* drop the reference to the bli */
405 xfs_buf_item_put(bip);
Christoph Hellwig5b03ff12012-02-20 02:31:22 +0000406
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200407 bp->b_transp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 xfs_buf_relse(bp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409}
410
411/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 * Mark the buffer as not needing to be unlocked when the buf item's
Christoph Hellwigddf92052019-06-28 19:27:32 -0700413 * iop_committing() routine is called. The buffer must already be locked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 * and associated with the given transaction.
415 */
416/* ARGSUSED */
417void
Carlos Maiolino70a20652018-01-24 13:38:48 -0800418xfs_trans_bhold(
419 xfs_trans_t *tp,
420 xfs_buf_t *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800422 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200424 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200425 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600427 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 bip->bli_flags |= XFS_BLI_HOLD;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000431 trace_xfs_trans_bhold(bip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432}
433
434/*
Tim Shimminefa092f2005-09-05 08:29:01 +1000435 * Cancel the previous buffer hold request made on this buffer
436 * for this transaction.
437 */
438void
Carlos Maiolino70a20652018-01-24 13:38:48 -0800439xfs_trans_bhold_release(
440 xfs_trans_t *tp,
441 xfs_buf_t *bp)
Tim Shimminefa092f2005-09-05 08:29:01 +1000442{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800443 struct xfs_buf_log_item *bip = bp->b_log_item;
Tim Shimminefa092f2005-09-05 08:29:01 +1000444
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200445 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200446 ASSERT(bip != NULL);
Tim Shimminefa092f2005-09-05 08:29:01 +1000447 ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600448 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
Tim Shimminefa092f2005-09-05 08:29:01 +1000449 ASSERT(atomic_read(&bip->bli_refcount) > 0);
450 ASSERT(bip->bli_flags & XFS_BLI_HOLD);
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000451
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200452 bip->bli_flags &= ~XFS_BLI_HOLD;
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000453 trace_xfs_trans_bhold_release(bip);
Tim Shimminefa092f2005-09-05 08:29:01 +1000454}
455
456/*
Brian Foster96840102017-08-29 10:08:38 -0700457 * Mark a buffer dirty in the transaction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 */
459void
Brian Foster96840102017-08-29 10:08:38 -0700460xfs_trans_dirty_buf(
461 struct xfs_trans *tp,
462 struct xfs_buf *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800464 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200466 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200467 ASSERT(bip != NULL);
Christoph Hellwigcb669ca2011-07-13 13:43:49 +0200468 ASSERT(bp->b_iodone == NULL ||
469 bp->b_iodone == xfs_buf_iodone_callbacks);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 /*
472 * Mark the buffer as needing to be written out eventually,
473 * and set its iodone function to remove the buffer's buf log
474 * item from the AIL and free it when the buffer is flushed
475 * to disk. See xfs_buf_attach_iodone() for more details
476 * on li_cb and xfs_buf_iodone_callbacks().
477 * If we end up aborting this transaction, we trap this buffer
478 * inside the b_bdstrat callback so that this won't get written to
479 * disk.
480 */
Dave Chinnerb0388bf2016-02-10 15:01:11 +1100481 bp->b_flags |= XBF_DONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwigcb669ca2011-07-13 13:43:49 +0200484 bp->b_iodone = xfs_buf_iodone_callbacks;
Christoph Hellwigca30b2a2010-06-23 18:11:15 +1000485 bip->bli_item.li_cb = xfs_buf_iodone;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 /*
488 * If we invalidated the buffer within this transaction, then
489 * cancel the invalidation now that we're dirtying the buffer
490 * again. There are no races with the code in xfs_buf_item_unpin(),
491 * because we have a reference to the buffer this entire time.
492 */
493 if (bip->bli_flags & XFS_BLI_STALE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 bip->bli_flags &= ~XFS_BLI_STALE;
Dave Chinner5cfd28b2016-02-10 15:01:11 +1100495 ASSERT(bp->b_flags & XBF_STALE);
496 bp->b_flags &= ~XBF_STALE;
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600497 bip->__bli_format.blf_flags &= ~XFS_BLF_CANCEL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 }
Brian Foster96840102017-08-29 10:08:38 -0700499 bip->bli_flags |= XFS_BLI_DIRTY | XFS_BLI_LOGGED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 tp->t_flags |= XFS_TRANS_DIRTY;
Dave Chinnere6631f82018-05-09 07:49:37 -0700502 set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
Brian Foster96840102017-08-29 10:08:38 -0700503}
504
505/*
506 * This is called to mark bytes first through last inclusive of the given
507 * buffer as needing to be logged when the transaction is committed.
508 * The buffer must already be associated with the given transaction.
509 *
510 * First and last are numbers relative to the beginning of this buffer,
511 * so the first byte in the buffer is numbered 0 regardless of the
512 * value of b_blkno.
513 */
514void
515xfs_trans_log_buf(
516 struct xfs_trans *tp,
517 struct xfs_buf *bp,
518 uint first,
519 uint last)
520{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800521 struct xfs_buf_log_item *bip = bp->b_log_item;
Brian Foster96840102017-08-29 10:08:38 -0700522
523 ASSERT(first <= last && last < BBTOB(bp->b_length));
Brian Foster8dc518d2017-08-29 10:08:38 -0700524 ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED));
Brian Foster96840102017-08-29 10:08:38 -0700525
526 xfs_trans_dirty_buf(tp, bp);
Dave Chinner5f6bed72013-06-27 16:04:52 +1000527
Brian Foster96840102017-08-29 10:08:38 -0700528 trace_xfs_trans_log_buf(bip);
Brian Foster8dc518d2017-08-29 10:08:38 -0700529 xfs_buf_item_log(bip, first, last);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530}
531
532
533/*
Christoph Hellwig43ff2122012-04-23 15:58:39 +1000534 * Invalidate a buffer that is being used within a transaction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 *
Christoph Hellwig43ff2122012-04-23 15:58:39 +1000536 * Typically this is because the blocks in the buffer are being freed, so we
537 * need to prevent it from being written out when we're done. Allowing it
538 * to be written again might overwrite data in the free blocks if they are
539 * reallocated to a file.
540 *
541 * We prevent the buffer from being written out by marking it stale. We can't
542 * get rid of the buf log item at this point because the buffer may still be
543 * pinned by another transaction. If that is the case, then we'll wait until
544 * the buffer is committed to disk for the last time (we can tell by the ref
545 * count) and free it in xfs_buf_item_unpin(). Until that happens we will
546 * keep the buffer locked so that the buffer and buf log item are not reused.
547 *
548 * We also set the XFS_BLF_CANCEL flag in the buf log format structure and log
549 * the buf item. This will be used at recovery time to determine that copies
550 * of the buffer in the log before this should not be replayed.
551 *
552 * We mark the item descriptor and the transaction dirty so that we'll hold
553 * the buffer until after the commit.
554 *
555 * Since we're invalidating the buffer, we also clear the state about which
556 * parts of the buffer have been logged. We also clear the flag indicating
557 * that this is an inode buffer since the data in the buffer will no longer
558 * be valid.
559 *
560 * We set the stale bit in the buffer as well since we're getting rid of it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 */
562void
563xfs_trans_binval(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800564 xfs_trans_t *tp,
565 xfs_buf_t *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800567 struct xfs_buf_log_item *bip = bp->b_log_item;
Mark Tinguely91e4bac2012-12-04 17:18:05 -0600568 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200570 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200571 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 ASSERT(atomic_read(&bip->bli_refcount) > 0);
573
Christoph Hellwig0b1b2132009-12-14 23:14:59 +0000574 trace_xfs_trans_binval(bip);
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (bip->bli_flags & XFS_BLI_STALE) {
577 /*
578 * If the buffer is already invalidated, then
579 * just return.
580 */
Dave Chinner5cfd28b2016-02-10 15:01:11 +1100581 ASSERT(bp->b_flags & XBF_STALE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600583 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_INODE_BUF));
Dave Chinner61fe1352013-04-03 16:11:30 +1100584 ASSERT(!(bip->__bli_format.blf_flags & XFS_BLFT_MASK));
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600585 ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
Dave Chinnere6631f82018-05-09 07:49:37 -0700586 ASSERT(test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 return;
589 }
590
Christoph Hellwigc867cb62011-10-10 16:52:46 +0000591 xfs_buf_stale(bp);
Christoph Hellwig43ff2122012-04-23 15:58:39 +1000592
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 bip->bli_flags |= XFS_BLI_STALE;
Dave Chinnerccf7c232010-05-20 23:19:42 +1000594 bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
Mark Tinguely0f22f9d2012-12-04 17:18:03 -0600595 bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
596 bip->__bli_format.blf_flags |= XFS_BLF_CANCEL;
Dave Chinner61fe1352013-04-03 16:11:30 +1100597 bip->__bli_format.blf_flags &= ~XFS_BLFT_MASK;
Mark Tinguely91e4bac2012-12-04 17:18:05 -0600598 for (i = 0; i < bip->bli_format_count; i++) {
599 memset(bip->bli_formats[i].blf_data_map, 0,
600 (bip->bli_formats[i].blf_map_size * sizeof(uint)));
601 }
Dave Chinnere6631f82018-05-09 07:49:37 -0700602 set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 tp->t_flags |= XFS_TRANS_DIRTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604}
605
606/*
Dave Chinnerccf7c232010-05-20 23:19:42 +1000607 * This call is used to indicate that the buffer contains on-disk inodes which
608 * must be handled specially during recovery. They require special handling
609 * because only the di_next_unlinked from the inodes in the buffer should be
610 * recovered. The rest of the data in the buffer is logged via the inodes
611 * themselves.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 *
Dave Chinnerccf7c232010-05-20 23:19:42 +1000613 * All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be
614 * transferred to the buffer's log format structure so that we'll know what to
615 * do at recovery time.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617void
618xfs_trans_inode_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800619 xfs_trans_t *tp,
620 xfs_buf_t *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800622 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200624 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200625 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 ASSERT(atomic_read(&bip->bli_refcount) > 0);
627
Dave Chinnerccf7c232010-05-20 23:19:42 +1000628 bip->bli_flags |= XFS_BLI_INODE_BUF;
Dave Chinnerf593bf12020-06-29 14:48:46 -0700629 bp->b_flags |= _XBF_INODES;
Dave Chinner61fe1352013-04-03 16:11:30 +1100630 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
632
633/*
634 * This call is used to indicate that the buffer is going to
635 * be staled and was an inode buffer. This means it gets
Christoph Hellwig93848a92013-04-03 16:11:17 +1100636 * special processing during unpin - where any inodes
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 * associated with the buffer should be removed from ail.
638 * There is also special processing during recovery,
639 * any replay of the inodes in the buffer needs to be
640 * prevented as the buffer may have been reused.
641 */
642void
643xfs_trans_stale_inode_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800644 xfs_trans_t *tp,
645 xfs_buf_t *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800647 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200649 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200650 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 ASSERT(atomic_read(&bip->bli_refcount) > 0);
652
653 bip->bli_flags |= XFS_BLI_STALE_INODE;
Christoph Hellwigca30b2a2010-06-23 18:11:15 +1000654 bip->bli_item.li_cb = xfs_buf_iodone;
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659/*
660 * Mark the buffer as being one which contains newly allocated
661 * inodes. We need to make sure that even if this buffer is
662 * relogged as an 'inode buf' we still recover all of the inode
663 * images in the face of a crash. This works in coordination with
664 * xfs_buf_item_committed() to ensure that the buffer remains in the
665 * AIL at its original location even after it has been relogged.
666 */
667/* ARGSUSED */
668void
669xfs_trans_inode_alloc_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800670 xfs_trans_t *tp,
671 xfs_buf_t *bp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800673 struct xfs_buf_log_item *bip = bp->b_log_item;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Christoph Hellwigbf9d9012011-07-13 13:43:49 +0200675 ASSERT(bp->b_transp == tp);
Christoph Hellwigadadbee2011-07-13 13:43:49 +0200676 ASSERT(bip != NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 ASSERT(atomic_read(&bip->bli_refcount) > 0);
678
679 bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
Dave Chinnerf593bf12020-06-29 14:48:46 -0700680 bp->b_flags |= _XBF_INODES;
Dave Chinner61fe1352013-04-03 16:11:30 +1100681 xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682}
683
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500684/*
Brian Foster8dc518d2017-08-29 10:08:38 -0700685 * Mark the buffer as ordered for this transaction. This means that the contents
686 * of the buffer are not recorded in the transaction but it is tracked in the
687 * AIL as though it was. This allows us to record logical changes in
688 * transactions rather than the physical changes we make to the buffer without
689 * changing writeback ordering constraints of metadata buffers.
Dave Chinner5f6bed72013-06-27 16:04:52 +1000690 */
Brian Fostera5814bc2017-08-29 10:08:40 -0700691bool
Dave Chinner5f6bed72013-06-27 16:04:52 +1000692xfs_trans_ordered_buf(
693 struct xfs_trans *tp,
694 struct xfs_buf *bp)
695{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800696 struct xfs_buf_log_item *bip = bp->b_log_item;
Dave Chinner5f6bed72013-06-27 16:04:52 +1000697
698 ASSERT(bp->b_transp == tp);
699 ASSERT(bip != NULL);
700 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Brian Fostera5814bc2017-08-29 10:08:40 -0700701
702 if (xfs_buf_item_dirty_format(bip))
703 return false;
Dave Chinner5f6bed72013-06-27 16:04:52 +1000704
705 bip->bli_flags |= XFS_BLI_ORDERED;
706 trace_xfs_buf_item_ordered(bip);
Brian Foster8dc518d2017-08-29 10:08:38 -0700707
708 /*
709 * We don't log a dirty range of an ordered buffer but it still needs
710 * to be marked dirty and that it has been logged.
711 */
712 xfs_trans_dirty_buf(tp, bp);
Brian Fostera5814bc2017-08-29 10:08:40 -0700713 return true;
Dave Chinner5f6bed72013-06-27 16:04:52 +1000714}
715
716/*
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500717 * Set the type of the buffer for log recovery so that it can correctly identify
718 * and hence attach the correct buffer ops to the buffer after replay.
719 */
720void
721xfs_trans_buf_set_type(
722 struct xfs_trans *tp,
723 struct xfs_buf *bp,
Dave Chinner61fe1352013-04-03 16:11:30 +1100724 enum xfs_blft type)
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500725{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800726 struct xfs_buf_log_item *bip = bp->b_log_item;
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500727
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100728 if (!tp)
729 return;
730
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500731 ASSERT(bp->b_transp == tp);
732 ASSERT(bip != NULL);
733 ASSERT(atomic_read(&bip->bli_refcount) > 0);
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500734
Dave Chinner61fe1352013-04-03 16:11:30 +1100735 xfs_blft_to_flags(&bip->__bli_format, type);
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500736}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100738void
739xfs_trans_buf_copy_type(
740 struct xfs_buf *dst_bp,
741 struct xfs_buf *src_bp)
742{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800743 struct xfs_buf_log_item *sbip = src_bp->b_log_item;
744 struct xfs_buf_log_item *dbip = dst_bp->b_log_item;
Dave Chinner61fe1352013-04-03 16:11:30 +1100745 enum xfs_blft type;
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100746
Dave Chinner61fe1352013-04-03 16:11:30 +1100747 type = xfs_blft_from_flags(&sbip->__bli_format);
748 xfs_blft_to_flags(&dbip->__bli_format, type);
Dave Chinnerd75afeb2013-04-03 16:11:29 +1100749}
750
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751/*
752 * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
753 * dquots. However, unlike in inode buffer recovery, dquot buffers get
754 * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
755 * The only thing that makes dquot buffers different from regular
756 * buffers is that we must not replay dquot bufs when recovering
757 * if a _corresponding_ quotaoff has happened. We also have to distinguish
758 * between usr dquot bufs and grp dquot bufs, because usr and grp quotas
759 * can be turned off independently.
760 */
761/* ARGSUSED */
762void
763xfs_trans_dquot_buf(
Carlos Maiolino70a20652018-01-24 13:38:48 -0800764 xfs_trans_t *tp,
765 xfs_buf_t *bp,
766 uint type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Carlos Maiolinofb1755a2018-01-24 13:38:48 -0800768 struct xfs_buf_log_item *bip = bp->b_log_item;
Dave Chinner61fe1352013-04-03 16:11:30 +1100769
Dave Chinnerc1155412010-05-07 11:05:19 +1000770 ASSERT(type == XFS_BLF_UDQUOT_BUF ||
771 type == XFS_BLF_PDQUOT_BUF ||
772 type == XFS_BLF_GDQUOT_BUF);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773
Dave Chinner61fe1352013-04-03 16:11:30 +1100774 bip->__bli_format.blf_flags |= type;
775
776 switch (type) {
777 case XFS_BLF_UDQUOT_BUF:
778 type = XFS_BLFT_UDQUOT_BUF;
779 break;
780 case XFS_BLF_PDQUOT_BUF:
781 type = XFS_BLFT_PDQUOT_BUF;
782 break;
783 case XFS_BLF_GDQUOT_BUF:
784 type = XFS_BLFT_GDQUOT_BUF;
785 break;
786 default:
787 type = XFS_BLFT_UNKNOWN_BUF;
788 break;
789 }
790
Dave Chinner0c7e5af2020-06-29 14:48:46 -0700791 bp->b_flags |= _XBF_DQUOTS;
Christoph Hellwigee1a47a2013-04-21 14:53:46 -0500792 xfs_trans_buf_set_type(tp, bp, type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793}