162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc. 462306a36Sopenharmony_ci * All Rights Reserved. 562306a36Sopenharmony_ci */ 662306a36Sopenharmony_ci#include "xfs.h" 762306a36Sopenharmony_ci#include "xfs_fs.h" 862306a36Sopenharmony_ci#include "xfs_shared.h" 962306a36Sopenharmony_ci#include "xfs_format.h" 1062306a36Sopenharmony_ci#include "xfs_log_format.h" 1162306a36Sopenharmony_ci#include "xfs_trans_resv.h" 1262306a36Sopenharmony_ci#include "xfs_mount.h" 1362306a36Sopenharmony_ci#include "xfs_trans.h" 1462306a36Sopenharmony_ci#include "xfs_buf_item.h" 1562306a36Sopenharmony_ci#include "xfs_trans_priv.h" 1662306a36Sopenharmony_ci#include "xfs_trace.h" 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci/* 1962306a36Sopenharmony_ci * Check to see if a buffer matching the given parameters is already 2062306a36Sopenharmony_ci * a part of the given transaction. 2162306a36Sopenharmony_ci */ 2262306a36Sopenharmony_ciSTATIC struct xfs_buf * 2362306a36Sopenharmony_cixfs_trans_buf_item_match( 2462306a36Sopenharmony_ci struct xfs_trans *tp, 2562306a36Sopenharmony_ci struct xfs_buftarg *target, 2662306a36Sopenharmony_ci struct xfs_buf_map *map, 2762306a36Sopenharmony_ci int nmaps) 2862306a36Sopenharmony_ci{ 2962306a36Sopenharmony_ci struct xfs_log_item *lip; 3062306a36Sopenharmony_ci struct xfs_buf_log_item *blip; 3162306a36Sopenharmony_ci int len = 0; 3262306a36Sopenharmony_ci int i; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci for (i = 0; i < nmaps; i++) 3562306a36Sopenharmony_ci len += map[i].bm_len; 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci list_for_each_entry(lip, &tp->t_items, li_trans) { 3862306a36Sopenharmony_ci blip = (struct xfs_buf_log_item *)lip; 3962306a36Sopenharmony_ci if (blip->bli_item.li_type == XFS_LI_BUF && 4062306a36Sopenharmony_ci blip->bli_buf->b_target == target && 4162306a36Sopenharmony_ci xfs_buf_daddr(blip->bli_buf) == map[0].bm_bn && 4262306a36Sopenharmony_ci blip->bli_buf->b_length == len) { 4362306a36Sopenharmony_ci ASSERT(blip->bli_buf->b_map_count == nmaps); 4462306a36Sopenharmony_ci return blip->bli_buf; 4562306a36Sopenharmony_ci } 4662306a36Sopenharmony_ci } 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci return NULL; 4962306a36Sopenharmony_ci} 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci/* 5262306a36Sopenharmony_ci * Add the locked buffer to the transaction. 5362306a36Sopenharmony_ci * 5462306a36Sopenharmony_ci * The buffer must be locked, and it cannot be associated with any 5562306a36Sopenharmony_ci * transaction. 5662306a36Sopenharmony_ci * 5762306a36Sopenharmony_ci * If the buffer does not yet have a buf log item associated with it, 5862306a36Sopenharmony_ci * then allocate one for it. Then add the buf item to the transaction. 5962306a36Sopenharmony_ci */ 6062306a36Sopenharmony_ciSTATIC void 6162306a36Sopenharmony_ci_xfs_trans_bjoin( 6262306a36Sopenharmony_ci struct xfs_trans *tp, 6362306a36Sopenharmony_ci struct xfs_buf *bp, 6462306a36Sopenharmony_ci int reset_recur) 6562306a36Sopenharmony_ci{ 6662306a36Sopenharmony_ci struct xfs_buf_log_item *bip; 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci ASSERT(bp->b_transp == NULL); 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci /* 7162306a36Sopenharmony_ci * The xfs_buf_log_item pointer is stored in b_log_item. If 7262306a36Sopenharmony_ci * it doesn't have one yet, then allocate one and initialize it. 7362306a36Sopenharmony_ci * The checks to see if one is there are in xfs_buf_item_init(). 7462306a36Sopenharmony_ci */ 7562306a36Sopenharmony_ci xfs_buf_item_init(bp, tp->t_mountp); 7662306a36Sopenharmony_ci bip = bp->b_log_item; 7762306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & XFS_BLI_STALE)); 7862306a36Sopenharmony_ci ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL)); 7962306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED)); 8062306a36Sopenharmony_ci if (reset_recur) 8162306a36Sopenharmony_ci bip->bli_recur = 0; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci /* 8462306a36Sopenharmony_ci * Take a reference for this transaction on the buf item. 8562306a36Sopenharmony_ci */ 8662306a36Sopenharmony_ci atomic_inc(&bip->bli_refcount); 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci /* 8962306a36Sopenharmony_ci * Attach the item to the transaction so we can find it in 9062306a36Sopenharmony_ci * xfs_trans_get_buf() and friends. 9162306a36Sopenharmony_ci */ 9262306a36Sopenharmony_ci xfs_trans_add_item(tp, &bip->bli_item); 9362306a36Sopenharmony_ci bp->b_transp = tp; 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci} 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_civoid 9862306a36Sopenharmony_cixfs_trans_bjoin( 9962306a36Sopenharmony_ci struct xfs_trans *tp, 10062306a36Sopenharmony_ci struct xfs_buf *bp) 10162306a36Sopenharmony_ci{ 10262306a36Sopenharmony_ci _xfs_trans_bjoin(tp, bp, 0); 10362306a36Sopenharmony_ci trace_xfs_trans_bjoin(bp->b_log_item); 10462306a36Sopenharmony_ci} 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci/* 10762306a36Sopenharmony_ci * Get and lock the buffer for the caller if it is not already 10862306a36Sopenharmony_ci * locked within the given transaction. If it is already locked 10962306a36Sopenharmony_ci * within the transaction, just increment its lock recursion count 11062306a36Sopenharmony_ci * and return a pointer to it. 11162306a36Sopenharmony_ci * 11262306a36Sopenharmony_ci * If the transaction pointer is NULL, make this just a normal 11362306a36Sopenharmony_ci * get_buf() call. 11462306a36Sopenharmony_ci */ 11562306a36Sopenharmony_ciint 11662306a36Sopenharmony_cixfs_trans_get_buf_map( 11762306a36Sopenharmony_ci struct xfs_trans *tp, 11862306a36Sopenharmony_ci struct xfs_buftarg *target, 11962306a36Sopenharmony_ci struct xfs_buf_map *map, 12062306a36Sopenharmony_ci int nmaps, 12162306a36Sopenharmony_ci xfs_buf_flags_t flags, 12262306a36Sopenharmony_ci struct xfs_buf **bpp) 12362306a36Sopenharmony_ci{ 12462306a36Sopenharmony_ci struct xfs_buf *bp; 12562306a36Sopenharmony_ci struct xfs_buf_log_item *bip; 12662306a36Sopenharmony_ci int error; 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci *bpp = NULL; 12962306a36Sopenharmony_ci if (!tp) 13062306a36Sopenharmony_ci return xfs_buf_get_map(target, map, nmaps, flags, bpp); 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci /* 13362306a36Sopenharmony_ci * If we find the buffer in the cache with this transaction 13462306a36Sopenharmony_ci * pointer in its b_fsprivate2 field, then we know we already 13562306a36Sopenharmony_ci * have it locked. In this case we just increment the lock 13662306a36Sopenharmony_ci * recursion count and return the buffer to the caller. 13762306a36Sopenharmony_ci */ 13862306a36Sopenharmony_ci bp = xfs_trans_buf_item_match(tp, target, map, nmaps); 13962306a36Sopenharmony_ci if (bp != NULL) { 14062306a36Sopenharmony_ci ASSERT(xfs_buf_islocked(bp)); 14162306a36Sopenharmony_ci if (xfs_is_shutdown(tp->t_mountp)) { 14262306a36Sopenharmony_ci xfs_buf_stale(bp); 14362306a36Sopenharmony_ci bp->b_flags |= XBF_DONE; 14462306a36Sopenharmony_ci } 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 14762306a36Sopenharmony_ci bip = bp->b_log_item; 14862306a36Sopenharmony_ci ASSERT(bip != NULL); 14962306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 15062306a36Sopenharmony_ci bip->bli_recur++; 15162306a36Sopenharmony_ci trace_xfs_trans_get_buf_recur(bip); 15262306a36Sopenharmony_ci *bpp = bp; 15362306a36Sopenharmony_ci return 0; 15462306a36Sopenharmony_ci } 15562306a36Sopenharmony_ci 15662306a36Sopenharmony_ci error = xfs_buf_get_map(target, map, nmaps, flags, &bp); 15762306a36Sopenharmony_ci if (error) 15862306a36Sopenharmony_ci return error; 15962306a36Sopenharmony_ci 16062306a36Sopenharmony_ci ASSERT(!bp->b_error); 16162306a36Sopenharmony_ci 16262306a36Sopenharmony_ci _xfs_trans_bjoin(tp, bp, 1); 16362306a36Sopenharmony_ci trace_xfs_trans_get_buf(bp->b_log_item); 16462306a36Sopenharmony_ci *bpp = bp; 16562306a36Sopenharmony_ci return 0; 16662306a36Sopenharmony_ci} 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci/* 16962306a36Sopenharmony_ci * Get and lock the superblock buffer for the given transaction. 17062306a36Sopenharmony_ci */ 17162306a36Sopenharmony_cistruct xfs_buf * 17262306a36Sopenharmony_cixfs_trans_getsb( 17362306a36Sopenharmony_ci struct xfs_trans *tp) 17462306a36Sopenharmony_ci{ 17562306a36Sopenharmony_ci struct xfs_buf *bp = tp->t_mountp->m_sb_bp; 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci /* 17862306a36Sopenharmony_ci * Just increment the lock recursion count if the buffer is already 17962306a36Sopenharmony_ci * attached to this transaction. 18062306a36Sopenharmony_ci */ 18162306a36Sopenharmony_ci if (bp->b_transp == tp) { 18262306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 18362306a36Sopenharmony_ci 18462306a36Sopenharmony_ci ASSERT(bip != NULL); 18562306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 18662306a36Sopenharmony_ci bip->bli_recur++; 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci trace_xfs_trans_getsb_recur(bip); 18962306a36Sopenharmony_ci } else { 19062306a36Sopenharmony_ci xfs_buf_lock(bp); 19162306a36Sopenharmony_ci xfs_buf_hold(bp); 19262306a36Sopenharmony_ci _xfs_trans_bjoin(tp, bp, 1); 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci trace_xfs_trans_getsb(bp->b_log_item); 19562306a36Sopenharmony_ci } 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci return bp; 19862306a36Sopenharmony_ci} 19962306a36Sopenharmony_ci 20062306a36Sopenharmony_ci/* 20162306a36Sopenharmony_ci * Get and lock the buffer for the caller if it is not already 20262306a36Sopenharmony_ci * locked within the given transaction. If it has not yet been 20362306a36Sopenharmony_ci * read in, read it from disk. If it is already locked 20462306a36Sopenharmony_ci * within the transaction and already read in, just increment its 20562306a36Sopenharmony_ci * lock recursion count and return a pointer to it. 20662306a36Sopenharmony_ci * 20762306a36Sopenharmony_ci * If the transaction pointer is NULL, make this just a normal 20862306a36Sopenharmony_ci * read_buf() call. 20962306a36Sopenharmony_ci */ 21062306a36Sopenharmony_ciint 21162306a36Sopenharmony_cixfs_trans_read_buf_map( 21262306a36Sopenharmony_ci struct xfs_mount *mp, 21362306a36Sopenharmony_ci struct xfs_trans *tp, 21462306a36Sopenharmony_ci struct xfs_buftarg *target, 21562306a36Sopenharmony_ci struct xfs_buf_map *map, 21662306a36Sopenharmony_ci int nmaps, 21762306a36Sopenharmony_ci xfs_buf_flags_t flags, 21862306a36Sopenharmony_ci struct xfs_buf **bpp, 21962306a36Sopenharmony_ci const struct xfs_buf_ops *ops) 22062306a36Sopenharmony_ci{ 22162306a36Sopenharmony_ci struct xfs_buf *bp = NULL; 22262306a36Sopenharmony_ci struct xfs_buf_log_item *bip; 22362306a36Sopenharmony_ci int error; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci *bpp = NULL; 22662306a36Sopenharmony_ci /* 22762306a36Sopenharmony_ci * If we find the buffer in the cache with this transaction 22862306a36Sopenharmony_ci * pointer in its b_fsprivate2 field, then we know we already 22962306a36Sopenharmony_ci * have it locked. If it is already read in we just increment 23062306a36Sopenharmony_ci * the lock recursion count and return the buffer to the caller. 23162306a36Sopenharmony_ci * If the buffer is not yet read in, then we read it in, increment 23262306a36Sopenharmony_ci * the lock recursion count, and return it to the caller. 23362306a36Sopenharmony_ci */ 23462306a36Sopenharmony_ci if (tp) 23562306a36Sopenharmony_ci bp = xfs_trans_buf_item_match(tp, target, map, nmaps); 23662306a36Sopenharmony_ci if (bp) { 23762306a36Sopenharmony_ci ASSERT(xfs_buf_islocked(bp)); 23862306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 23962306a36Sopenharmony_ci ASSERT(bp->b_log_item != NULL); 24062306a36Sopenharmony_ci ASSERT(!bp->b_error); 24162306a36Sopenharmony_ci ASSERT(bp->b_flags & XBF_DONE); 24262306a36Sopenharmony_ci 24362306a36Sopenharmony_ci /* 24462306a36Sopenharmony_ci * We never locked this buf ourselves, so we shouldn't 24562306a36Sopenharmony_ci * brelse it either. Just get out. 24662306a36Sopenharmony_ci */ 24762306a36Sopenharmony_ci if (xfs_is_shutdown(mp)) { 24862306a36Sopenharmony_ci trace_xfs_trans_read_buf_shut(bp, _RET_IP_); 24962306a36Sopenharmony_ci return -EIO; 25062306a36Sopenharmony_ci } 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci /* 25362306a36Sopenharmony_ci * Check if the caller is trying to read a buffer that is 25462306a36Sopenharmony_ci * already attached to the transaction yet has no buffer ops 25562306a36Sopenharmony_ci * assigned. Ops are usually attached when the buffer is 25662306a36Sopenharmony_ci * attached to the transaction, or by the read caller if 25762306a36Sopenharmony_ci * special circumstances. That didn't happen, which is not 25862306a36Sopenharmony_ci * how this is supposed to go. 25962306a36Sopenharmony_ci * 26062306a36Sopenharmony_ci * If the buffer passes verification we'll let this go, but if 26162306a36Sopenharmony_ci * not we have to shut down. Let the transaction cleanup code 26262306a36Sopenharmony_ci * release this buffer when it kills the tranaction. 26362306a36Sopenharmony_ci */ 26462306a36Sopenharmony_ci ASSERT(bp->b_ops != NULL); 26562306a36Sopenharmony_ci error = xfs_buf_reverify(bp, ops); 26662306a36Sopenharmony_ci if (error) { 26762306a36Sopenharmony_ci xfs_buf_ioerror_alert(bp, __return_address); 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci if (tp->t_flags & XFS_TRANS_DIRTY) 27062306a36Sopenharmony_ci xfs_force_shutdown(tp->t_mountp, 27162306a36Sopenharmony_ci SHUTDOWN_META_IO_ERROR); 27262306a36Sopenharmony_ci 27362306a36Sopenharmony_ci /* bad CRC means corrupted metadata */ 27462306a36Sopenharmony_ci if (error == -EFSBADCRC) 27562306a36Sopenharmony_ci error = -EFSCORRUPTED; 27662306a36Sopenharmony_ci return error; 27762306a36Sopenharmony_ci } 27862306a36Sopenharmony_ci 27962306a36Sopenharmony_ci bip = bp->b_log_item; 28062306a36Sopenharmony_ci bip->bli_recur++; 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 28362306a36Sopenharmony_ci trace_xfs_trans_read_buf_recur(bip); 28462306a36Sopenharmony_ci ASSERT(bp->b_ops != NULL || ops == NULL); 28562306a36Sopenharmony_ci *bpp = bp; 28662306a36Sopenharmony_ci return 0; 28762306a36Sopenharmony_ci } 28862306a36Sopenharmony_ci 28962306a36Sopenharmony_ci error = xfs_buf_read_map(target, map, nmaps, flags, &bp, ops, 29062306a36Sopenharmony_ci __return_address); 29162306a36Sopenharmony_ci switch (error) { 29262306a36Sopenharmony_ci case 0: 29362306a36Sopenharmony_ci break; 29462306a36Sopenharmony_ci default: 29562306a36Sopenharmony_ci if (tp && (tp->t_flags & XFS_TRANS_DIRTY)) 29662306a36Sopenharmony_ci xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR); 29762306a36Sopenharmony_ci fallthrough; 29862306a36Sopenharmony_ci case -ENOMEM: 29962306a36Sopenharmony_ci case -EAGAIN: 30062306a36Sopenharmony_ci return error; 30162306a36Sopenharmony_ci } 30262306a36Sopenharmony_ci 30362306a36Sopenharmony_ci if (xfs_is_shutdown(mp)) { 30462306a36Sopenharmony_ci xfs_buf_relse(bp); 30562306a36Sopenharmony_ci trace_xfs_trans_read_buf_shut(bp, _RET_IP_); 30662306a36Sopenharmony_ci return -EIO; 30762306a36Sopenharmony_ci } 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci if (tp) { 31062306a36Sopenharmony_ci _xfs_trans_bjoin(tp, bp, 1); 31162306a36Sopenharmony_ci trace_xfs_trans_read_buf(bp->b_log_item); 31262306a36Sopenharmony_ci } 31362306a36Sopenharmony_ci ASSERT(bp->b_ops != NULL || ops == NULL); 31462306a36Sopenharmony_ci *bpp = bp; 31562306a36Sopenharmony_ci return 0; 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci} 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci/* Has this buffer been dirtied by anyone? */ 32062306a36Sopenharmony_cibool 32162306a36Sopenharmony_cixfs_trans_buf_is_dirty( 32262306a36Sopenharmony_ci struct xfs_buf *bp) 32362306a36Sopenharmony_ci{ 32462306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci if (!bip) 32762306a36Sopenharmony_ci return false; 32862306a36Sopenharmony_ci ASSERT(bip->bli_item.li_type == XFS_LI_BUF); 32962306a36Sopenharmony_ci return test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags); 33062306a36Sopenharmony_ci} 33162306a36Sopenharmony_ci 33262306a36Sopenharmony_ci/* 33362306a36Sopenharmony_ci * Release a buffer previously joined to the transaction. If the buffer is 33462306a36Sopenharmony_ci * modified within this transaction, decrement the recursion count but do not 33562306a36Sopenharmony_ci * release the buffer even if the count goes to 0. If the buffer is not modified 33662306a36Sopenharmony_ci * within the transaction, decrement the recursion count and release the buffer 33762306a36Sopenharmony_ci * if the recursion count goes to 0. 33862306a36Sopenharmony_ci * 33962306a36Sopenharmony_ci * If the buffer is to be released and it was not already dirty before this 34062306a36Sopenharmony_ci * transaction began, then also free the buf_log_item associated with it. 34162306a36Sopenharmony_ci * 34262306a36Sopenharmony_ci * If the transaction pointer is NULL, this is a normal xfs_buf_relse() call. 34362306a36Sopenharmony_ci */ 34462306a36Sopenharmony_civoid 34562306a36Sopenharmony_cixfs_trans_brelse( 34662306a36Sopenharmony_ci struct xfs_trans *tp, 34762306a36Sopenharmony_ci struct xfs_buf *bp) 34862306a36Sopenharmony_ci{ 34962306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci if (!tp) { 35462306a36Sopenharmony_ci xfs_buf_relse(bp); 35562306a36Sopenharmony_ci return; 35662306a36Sopenharmony_ci } 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci trace_xfs_trans_brelse(bip); 35962306a36Sopenharmony_ci ASSERT(bip->bli_item.li_type == XFS_LI_BUF); 36062306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_ci /* 36362306a36Sopenharmony_ci * If the release is for a recursive lookup, then decrement the count 36462306a36Sopenharmony_ci * and return. 36562306a36Sopenharmony_ci */ 36662306a36Sopenharmony_ci if (bip->bli_recur > 0) { 36762306a36Sopenharmony_ci bip->bli_recur--; 36862306a36Sopenharmony_ci return; 36962306a36Sopenharmony_ci } 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci /* 37262306a36Sopenharmony_ci * If the buffer is invalidated or dirty in this transaction, we can't 37362306a36Sopenharmony_ci * release it until we commit. 37462306a36Sopenharmony_ci */ 37562306a36Sopenharmony_ci if (test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags)) 37662306a36Sopenharmony_ci return; 37762306a36Sopenharmony_ci if (bip->bli_flags & XFS_BLI_STALE) 37862306a36Sopenharmony_ci return; 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci /* 38162306a36Sopenharmony_ci * Unlink the log item from the transaction and clear the hold flag, if 38262306a36Sopenharmony_ci * set. We wouldn't want the next user of the buffer to get confused. 38362306a36Sopenharmony_ci */ 38462306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED)); 38562306a36Sopenharmony_ci xfs_trans_del_item(&bip->bli_item); 38662306a36Sopenharmony_ci bip->bli_flags &= ~XFS_BLI_HOLD; 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_ci /* drop the reference to the bli */ 38962306a36Sopenharmony_ci xfs_buf_item_put(bip); 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci bp->b_transp = NULL; 39262306a36Sopenharmony_ci xfs_buf_relse(bp); 39362306a36Sopenharmony_ci} 39462306a36Sopenharmony_ci 39562306a36Sopenharmony_ci/* 39662306a36Sopenharmony_ci * Mark the buffer as not needing to be unlocked when the buf item's 39762306a36Sopenharmony_ci * iop_committing() routine is called. The buffer must already be locked 39862306a36Sopenharmony_ci * and associated with the given transaction. 39962306a36Sopenharmony_ci */ 40062306a36Sopenharmony_ci/* ARGSUSED */ 40162306a36Sopenharmony_civoid 40262306a36Sopenharmony_cixfs_trans_bhold( 40362306a36Sopenharmony_ci xfs_trans_t *tp, 40462306a36Sopenharmony_ci struct xfs_buf *bp) 40562306a36Sopenharmony_ci{ 40662306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 40962306a36Sopenharmony_ci ASSERT(bip != NULL); 41062306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & XFS_BLI_STALE)); 41162306a36Sopenharmony_ci ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL)); 41262306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_HOLD; 41562306a36Sopenharmony_ci trace_xfs_trans_bhold(bip); 41662306a36Sopenharmony_ci} 41762306a36Sopenharmony_ci 41862306a36Sopenharmony_ci/* 41962306a36Sopenharmony_ci * Cancel the previous buffer hold request made on this buffer 42062306a36Sopenharmony_ci * for this transaction. 42162306a36Sopenharmony_ci */ 42262306a36Sopenharmony_civoid 42362306a36Sopenharmony_cixfs_trans_bhold_release( 42462306a36Sopenharmony_ci xfs_trans_t *tp, 42562306a36Sopenharmony_ci struct xfs_buf *bp) 42662306a36Sopenharmony_ci{ 42762306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 42862306a36Sopenharmony_ci 42962306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 43062306a36Sopenharmony_ci ASSERT(bip != NULL); 43162306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & XFS_BLI_STALE)); 43262306a36Sopenharmony_ci ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL)); 43362306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 43462306a36Sopenharmony_ci ASSERT(bip->bli_flags & XFS_BLI_HOLD); 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_ci bip->bli_flags &= ~XFS_BLI_HOLD; 43762306a36Sopenharmony_ci trace_xfs_trans_bhold_release(bip); 43862306a36Sopenharmony_ci} 43962306a36Sopenharmony_ci 44062306a36Sopenharmony_ci/* 44162306a36Sopenharmony_ci * Mark a buffer dirty in the transaction. 44262306a36Sopenharmony_ci */ 44362306a36Sopenharmony_civoid 44462306a36Sopenharmony_cixfs_trans_dirty_buf( 44562306a36Sopenharmony_ci struct xfs_trans *tp, 44662306a36Sopenharmony_ci struct xfs_buf *bp) 44762306a36Sopenharmony_ci{ 44862306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 45162306a36Sopenharmony_ci ASSERT(bip != NULL); 45262306a36Sopenharmony_ci 45362306a36Sopenharmony_ci /* 45462306a36Sopenharmony_ci * Mark the buffer as needing to be written out eventually, 45562306a36Sopenharmony_ci * and set its iodone function to remove the buffer's buf log 45662306a36Sopenharmony_ci * item from the AIL and free it when the buffer is flushed 45762306a36Sopenharmony_ci * to disk. 45862306a36Sopenharmony_ci */ 45962306a36Sopenharmony_ci bp->b_flags |= XBF_DONE; 46062306a36Sopenharmony_ci 46162306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 46262306a36Sopenharmony_ci 46362306a36Sopenharmony_ci /* 46462306a36Sopenharmony_ci * If we invalidated the buffer within this transaction, then 46562306a36Sopenharmony_ci * cancel the invalidation now that we're dirtying the buffer 46662306a36Sopenharmony_ci * again. There are no races with the code in xfs_buf_item_unpin(), 46762306a36Sopenharmony_ci * because we have a reference to the buffer this entire time. 46862306a36Sopenharmony_ci */ 46962306a36Sopenharmony_ci if (bip->bli_flags & XFS_BLI_STALE) { 47062306a36Sopenharmony_ci bip->bli_flags &= ~XFS_BLI_STALE; 47162306a36Sopenharmony_ci ASSERT(bp->b_flags & XBF_STALE); 47262306a36Sopenharmony_ci bp->b_flags &= ~XBF_STALE; 47362306a36Sopenharmony_ci bip->__bli_format.blf_flags &= ~XFS_BLF_CANCEL; 47462306a36Sopenharmony_ci } 47562306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_DIRTY | XFS_BLI_LOGGED; 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_ci tp->t_flags |= XFS_TRANS_DIRTY; 47862306a36Sopenharmony_ci set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags); 47962306a36Sopenharmony_ci} 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci/* 48262306a36Sopenharmony_ci * This is called to mark bytes first through last inclusive of the given 48362306a36Sopenharmony_ci * buffer as needing to be logged when the transaction is committed. 48462306a36Sopenharmony_ci * The buffer must already be associated with the given transaction. 48562306a36Sopenharmony_ci * 48662306a36Sopenharmony_ci * First and last are numbers relative to the beginning of this buffer, 48762306a36Sopenharmony_ci * so the first byte in the buffer is numbered 0 regardless of the 48862306a36Sopenharmony_ci * value of b_blkno. 48962306a36Sopenharmony_ci */ 49062306a36Sopenharmony_civoid 49162306a36Sopenharmony_cixfs_trans_log_buf( 49262306a36Sopenharmony_ci struct xfs_trans *tp, 49362306a36Sopenharmony_ci struct xfs_buf *bp, 49462306a36Sopenharmony_ci uint first, 49562306a36Sopenharmony_ci uint last) 49662306a36Sopenharmony_ci{ 49762306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci ASSERT(first <= last && last < BBTOB(bp->b_length)); 50062306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED)); 50162306a36Sopenharmony_ci 50262306a36Sopenharmony_ci xfs_trans_dirty_buf(tp, bp); 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci trace_xfs_trans_log_buf(bip); 50562306a36Sopenharmony_ci xfs_buf_item_log(bip, first, last); 50662306a36Sopenharmony_ci} 50762306a36Sopenharmony_ci 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci/* 51062306a36Sopenharmony_ci * Invalidate a buffer that is being used within a transaction. 51162306a36Sopenharmony_ci * 51262306a36Sopenharmony_ci * Typically this is because the blocks in the buffer are being freed, so we 51362306a36Sopenharmony_ci * need to prevent it from being written out when we're done. Allowing it 51462306a36Sopenharmony_ci * to be written again might overwrite data in the free blocks if they are 51562306a36Sopenharmony_ci * reallocated to a file. 51662306a36Sopenharmony_ci * 51762306a36Sopenharmony_ci * We prevent the buffer from being written out by marking it stale. We can't 51862306a36Sopenharmony_ci * get rid of the buf log item at this point because the buffer may still be 51962306a36Sopenharmony_ci * pinned by another transaction. If that is the case, then we'll wait until 52062306a36Sopenharmony_ci * the buffer is committed to disk for the last time (we can tell by the ref 52162306a36Sopenharmony_ci * count) and free it in xfs_buf_item_unpin(). Until that happens we will 52262306a36Sopenharmony_ci * keep the buffer locked so that the buffer and buf log item are not reused. 52362306a36Sopenharmony_ci * 52462306a36Sopenharmony_ci * We also set the XFS_BLF_CANCEL flag in the buf log format structure and log 52562306a36Sopenharmony_ci * the buf item. This will be used at recovery time to determine that copies 52662306a36Sopenharmony_ci * of the buffer in the log before this should not be replayed. 52762306a36Sopenharmony_ci * 52862306a36Sopenharmony_ci * We mark the item descriptor and the transaction dirty so that we'll hold 52962306a36Sopenharmony_ci * the buffer until after the commit. 53062306a36Sopenharmony_ci * 53162306a36Sopenharmony_ci * Since we're invalidating the buffer, we also clear the state about which 53262306a36Sopenharmony_ci * parts of the buffer have been logged. We also clear the flag indicating 53362306a36Sopenharmony_ci * that this is an inode buffer since the data in the buffer will no longer 53462306a36Sopenharmony_ci * be valid. 53562306a36Sopenharmony_ci * 53662306a36Sopenharmony_ci * We set the stale bit in the buffer as well since we're getting rid of it. 53762306a36Sopenharmony_ci */ 53862306a36Sopenharmony_civoid 53962306a36Sopenharmony_cixfs_trans_binval( 54062306a36Sopenharmony_ci xfs_trans_t *tp, 54162306a36Sopenharmony_ci struct xfs_buf *bp) 54262306a36Sopenharmony_ci{ 54362306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 54462306a36Sopenharmony_ci int i; 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 54762306a36Sopenharmony_ci ASSERT(bip != NULL); 54862306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci trace_xfs_trans_binval(bip); 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_ci if (bip->bli_flags & XFS_BLI_STALE) { 55362306a36Sopenharmony_ci /* 55462306a36Sopenharmony_ci * If the buffer is already invalidated, then 55562306a36Sopenharmony_ci * just return. 55662306a36Sopenharmony_ci */ 55762306a36Sopenharmony_ci ASSERT(bp->b_flags & XBF_STALE); 55862306a36Sopenharmony_ci ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY))); 55962306a36Sopenharmony_ci ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_INODE_BUF)); 56062306a36Sopenharmony_ci ASSERT(!(bip->__bli_format.blf_flags & XFS_BLFT_MASK)); 56162306a36Sopenharmony_ci ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL); 56262306a36Sopenharmony_ci ASSERT(test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags)); 56362306a36Sopenharmony_ci ASSERT(tp->t_flags & XFS_TRANS_DIRTY); 56462306a36Sopenharmony_ci return; 56562306a36Sopenharmony_ci } 56662306a36Sopenharmony_ci 56762306a36Sopenharmony_ci xfs_buf_stale(bp); 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_STALE; 57062306a36Sopenharmony_ci bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY); 57162306a36Sopenharmony_ci bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF; 57262306a36Sopenharmony_ci bip->__bli_format.blf_flags |= XFS_BLF_CANCEL; 57362306a36Sopenharmony_ci bip->__bli_format.blf_flags &= ~XFS_BLFT_MASK; 57462306a36Sopenharmony_ci for (i = 0; i < bip->bli_format_count; i++) { 57562306a36Sopenharmony_ci memset(bip->bli_formats[i].blf_data_map, 0, 57662306a36Sopenharmony_ci (bip->bli_formats[i].blf_map_size * sizeof(uint))); 57762306a36Sopenharmony_ci } 57862306a36Sopenharmony_ci set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags); 57962306a36Sopenharmony_ci tp->t_flags |= XFS_TRANS_DIRTY; 58062306a36Sopenharmony_ci} 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci/* 58362306a36Sopenharmony_ci * This call is used to indicate that the buffer contains on-disk inodes which 58462306a36Sopenharmony_ci * must be handled specially during recovery. They require special handling 58562306a36Sopenharmony_ci * because only the di_next_unlinked from the inodes in the buffer should be 58662306a36Sopenharmony_ci * recovered. The rest of the data in the buffer is logged via the inodes 58762306a36Sopenharmony_ci * themselves. 58862306a36Sopenharmony_ci * 58962306a36Sopenharmony_ci * All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be 59062306a36Sopenharmony_ci * transferred to the buffer's log format structure so that we'll know what to 59162306a36Sopenharmony_ci * do at recovery time. 59262306a36Sopenharmony_ci */ 59362306a36Sopenharmony_civoid 59462306a36Sopenharmony_cixfs_trans_inode_buf( 59562306a36Sopenharmony_ci xfs_trans_t *tp, 59662306a36Sopenharmony_ci struct xfs_buf *bp) 59762306a36Sopenharmony_ci{ 59862306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 59962306a36Sopenharmony_ci 60062306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 60162306a36Sopenharmony_ci ASSERT(bip != NULL); 60262306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_INODE_BUF; 60562306a36Sopenharmony_ci bp->b_flags |= _XBF_INODES; 60662306a36Sopenharmony_ci xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF); 60762306a36Sopenharmony_ci} 60862306a36Sopenharmony_ci 60962306a36Sopenharmony_ci/* 61062306a36Sopenharmony_ci * This call is used to indicate that the buffer is going to 61162306a36Sopenharmony_ci * be staled and was an inode buffer. This means it gets 61262306a36Sopenharmony_ci * special processing during unpin - where any inodes 61362306a36Sopenharmony_ci * associated with the buffer should be removed from ail. 61462306a36Sopenharmony_ci * There is also special processing during recovery, 61562306a36Sopenharmony_ci * any replay of the inodes in the buffer needs to be 61662306a36Sopenharmony_ci * prevented as the buffer may have been reused. 61762306a36Sopenharmony_ci */ 61862306a36Sopenharmony_civoid 61962306a36Sopenharmony_cixfs_trans_stale_inode_buf( 62062306a36Sopenharmony_ci xfs_trans_t *tp, 62162306a36Sopenharmony_ci struct xfs_buf *bp) 62262306a36Sopenharmony_ci{ 62362306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 62462306a36Sopenharmony_ci 62562306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 62662306a36Sopenharmony_ci ASSERT(bip != NULL); 62762306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 62862306a36Sopenharmony_ci 62962306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_STALE_INODE; 63062306a36Sopenharmony_ci bp->b_flags |= _XBF_INODES; 63162306a36Sopenharmony_ci xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF); 63262306a36Sopenharmony_ci} 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ci/* 63562306a36Sopenharmony_ci * Mark the buffer as being one which contains newly allocated 63662306a36Sopenharmony_ci * inodes. We need to make sure that even if this buffer is 63762306a36Sopenharmony_ci * relogged as an 'inode buf' we still recover all of the inode 63862306a36Sopenharmony_ci * images in the face of a crash. This works in coordination with 63962306a36Sopenharmony_ci * xfs_buf_item_committed() to ensure that the buffer remains in the 64062306a36Sopenharmony_ci * AIL at its original location even after it has been relogged. 64162306a36Sopenharmony_ci */ 64262306a36Sopenharmony_ci/* ARGSUSED */ 64362306a36Sopenharmony_civoid 64462306a36Sopenharmony_cixfs_trans_inode_alloc_buf( 64562306a36Sopenharmony_ci xfs_trans_t *tp, 64662306a36Sopenharmony_ci struct xfs_buf *bp) 64762306a36Sopenharmony_ci{ 64862306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 64962306a36Sopenharmony_ci 65062306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 65162306a36Sopenharmony_ci ASSERT(bip != NULL); 65262306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 65362306a36Sopenharmony_ci 65462306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF; 65562306a36Sopenharmony_ci bp->b_flags |= _XBF_INODES; 65662306a36Sopenharmony_ci xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF); 65762306a36Sopenharmony_ci} 65862306a36Sopenharmony_ci 65962306a36Sopenharmony_ci/* 66062306a36Sopenharmony_ci * Mark the buffer as ordered for this transaction. This means that the contents 66162306a36Sopenharmony_ci * of the buffer are not recorded in the transaction but it is tracked in the 66262306a36Sopenharmony_ci * AIL as though it was. This allows us to record logical changes in 66362306a36Sopenharmony_ci * transactions rather than the physical changes we make to the buffer without 66462306a36Sopenharmony_ci * changing writeback ordering constraints of metadata buffers. 66562306a36Sopenharmony_ci */ 66662306a36Sopenharmony_cibool 66762306a36Sopenharmony_cixfs_trans_ordered_buf( 66862306a36Sopenharmony_ci struct xfs_trans *tp, 66962306a36Sopenharmony_ci struct xfs_buf *bp) 67062306a36Sopenharmony_ci{ 67162306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 67262306a36Sopenharmony_ci 67362306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 67462306a36Sopenharmony_ci ASSERT(bip != NULL); 67562306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 67662306a36Sopenharmony_ci 67762306a36Sopenharmony_ci if (xfs_buf_item_dirty_format(bip)) 67862306a36Sopenharmony_ci return false; 67962306a36Sopenharmony_ci 68062306a36Sopenharmony_ci bip->bli_flags |= XFS_BLI_ORDERED; 68162306a36Sopenharmony_ci trace_xfs_buf_item_ordered(bip); 68262306a36Sopenharmony_ci 68362306a36Sopenharmony_ci /* 68462306a36Sopenharmony_ci * We don't log a dirty range of an ordered buffer but it still needs 68562306a36Sopenharmony_ci * to be marked dirty and that it has been logged. 68662306a36Sopenharmony_ci */ 68762306a36Sopenharmony_ci xfs_trans_dirty_buf(tp, bp); 68862306a36Sopenharmony_ci return true; 68962306a36Sopenharmony_ci} 69062306a36Sopenharmony_ci 69162306a36Sopenharmony_ci/* 69262306a36Sopenharmony_ci * Set the type of the buffer for log recovery so that it can correctly identify 69362306a36Sopenharmony_ci * and hence attach the correct buffer ops to the buffer after replay. 69462306a36Sopenharmony_ci */ 69562306a36Sopenharmony_civoid 69662306a36Sopenharmony_cixfs_trans_buf_set_type( 69762306a36Sopenharmony_ci struct xfs_trans *tp, 69862306a36Sopenharmony_ci struct xfs_buf *bp, 69962306a36Sopenharmony_ci enum xfs_blft type) 70062306a36Sopenharmony_ci{ 70162306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 70262306a36Sopenharmony_ci 70362306a36Sopenharmony_ci if (!tp) 70462306a36Sopenharmony_ci return; 70562306a36Sopenharmony_ci 70662306a36Sopenharmony_ci ASSERT(bp->b_transp == tp); 70762306a36Sopenharmony_ci ASSERT(bip != NULL); 70862306a36Sopenharmony_ci ASSERT(atomic_read(&bip->bli_refcount) > 0); 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ci xfs_blft_to_flags(&bip->__bli_format, type); 71162306a36Sopenharmony_ci} 71262306a36Sopenharmony_ci 71362306a36Sopenharmony_civoid 71462306a36Sopenharmony_cixfs_trans_buf_copy_type( 71562306a36Sopenharmony_ci struct xfs_buf *dst_bp, 71662306a36Sopenharmony_ci struct xfs_buf *src_bp) 71762306a36Sopenharmony_ci{ 71862306a36Sopenharmony_ci struct xfs_buf_log_item *sbip = src_bp->b_log_item; 71962306a36Sopenharmony_ci struct xfs_buf_log_item *dbip = dst_bp->b_log_item; 72062306a36Sopenharmony_ci enum xfs_blft type; 72162306a36Sopenharmony_ci 72262306a36Sopenharmony_ci type = xfs_blft_from_flags(&sbip->__bli_format); 72362306a36Sopenharmony_ci xfs_blft_to_flags(&dbip->__bli_format, type); 72462306a36Sopenharmony_ci} 72562306a36Sopenharmony_ci 72662306a36Sopenharmony_ci/* 72762306a36Sopenharmony_ci * Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of 72862306a36Sopenharmony_ci * dquots. However, unlike in inode buffer recovery, dquot buffers get 72962306a36Sopenharmony_ci * recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag). 73062306a36Sopenharmony_ci * The only thing that makes dquot buffers different from regular 73162306a36Sopenharmony_ci * buffers is that we must not replay dquot bufs when recovering 73262306a36Sopenharmony_ci * if a _corresponding_ quotaoff has happened. We also have to distinguish 73362306a36Sopenharmony_ci * between usr dquot bufs and grp dquot bufs, because usr and grp quotas 73462306a36Sopenharmony_ci * can be turned off independently. 73562306a36Sopenharmony_ci */ 73662306a36Sopenharmony_ci/* ARGSUSED */ 73762306a36Sopenharmony_civoid 73862306a36Sopenharmony_cixfs_trans_dquot_buf( 73962306a36Sopenharmony_ci xfs_trans_t *tp, 74062306a36Sopenharmony_ci struct xfs_buf *bp, 74162306a36Sopenharmony_ci uint type) 74262306a36Sopenharmony_ci{ 74362306a36Sopenharmony_ci struct xfs_buf_log_item *bip = bp->b_log_item; 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_ci ASSERT(type == XFS_BLF_UDQUOT_BUF || 74662306a36Sopenharmony_ci type == XFS_BLF_PDQUOT_BUF || 74762306a36Sopenharmony_ci type == XFS_BLF_GDQUOT_BUF); 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci bip->__bli_format.blf_flags |= type; 75062306a36Sopenharmony_ci 75162306a36Sopenharmony_ci switch (type) { 75262306a36Sopenharmony_ci case XFS_BLF_UDQUOT_BUF: 75362306a36Sopenharmony_ci type = XFS_BLFT_UDQUOT_BUF; 75462306a36Sopenharmony_ci break; 75562306a36Sopenharmony_ci case XFS_BLF_PDQUOT_BUF: 75662306a36Sopenharmony_ci type = XFS_BLFT_PDQUOT_BUF; 75762306a36Sopenharmony_ci break; 75862306a36Sopenharmony_ci case XFS_BLF_GDQUOT_BUF: 75962306a36Sopenharmony_ci type = XFS_BLFT_GDQUOT_BUF; 76062306a36Sopenharmony_ci break; 76162306a36Sopenharmony_ci default: 76262306a36Sopenharmony_ci type = XFS_BLFT_UNKNOWN_BUF; 76362306a36Sopenharmony_ci break; 76462306a36Sopenharmony_ci } 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci bp->b_flags |= _XBF_DQUOTS; 76762306a36Sopenharmony_ci xfs_trans_buf_set_type(tp, bp, type); 76862306a36Sopenharmony_ci} 769