2018-06-06 10:42:14 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-11-02 11:58:39 +08:00
|
|
|
* Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
2005-11-02 11:38:42 +08:00
|
|
|
#include "xfs_fs.h"
|
2013-10-23 07:36:05 +08:00
|
|
|
#include "xfs_shared.h"
|
2013-10-23 07:51:50 +08:00
|
|
|
#include "xfs_format.h"
|
2013-10-23 07:50:10 +08:00
|
|
|
#include "xfs_log_format.h"
|
|
|
|
#include "xfs_trans_resv.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "xfs_mount.h"
|
2013-10-23 07:50:10 +08:00
|
|
|
#include "xfs_trans.h"
|
2005-11-02 11:38:42 +08:00
|
|
|
#include "xfs_buf_item.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "xfs_trans_priv.h"
|
2009-12-15 07:14:59 +08:00
|
|
|
#include "xfs_trace.h"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-04-18 08:10:45 +08:00
|
|
|
/*
|
|
|
|
* Check to see if a buffer matching the given parameters is already
|
|
|
|
* a part of the given transaction.
|
|
|
|
*/
|
|
|
|
STATIC struct xfs_buf *
|
|
|
|
xfs_trans_buf_item_match(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buftarg *target,
|
2012-06-22 16:50:11 +08:00
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps)
|
2010-04-18 08:10:45 +08:00
|
|
|
{
|
2018-05-09 22:49:37 +08:00
|
|
|
struct xfs_log_item *lip;
|
2010-06-23 16:11:15 +08:00
|
|
|
struct xfs_buf_log_item *blip;
|
2012-06-22 16:50:11 +08:00
|
|
|
int len = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nmaps; i++)
|
|
|
|
len += map[i].bm_len;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-05-09 22:49:37 +08:00
|
|
|
list_for_each_entry(lip, &tp->t_items, li_trans) {
|
|
|
|
blip = (struct xfs_buf_log_item *)lip;
|
2010-06-23 16:11:15 +08:00
|
|
|
if (blip->bli_item.li_type == XFS_LI_BUF &&
|
2011-07-23 07:40:40 +08:00
|
|
|
blip->bli_buf->b_target == target &&
|
2012-06-22 16:50:11 +08:00
|
|
|
XFS_BUF_ADDR(blip->bli_buf) == map[0].bm_bn &&
|
|
|
|
blip->bli_buf->b_length == len) {
|
|
|
|
ASSERT(blip->bli_buf->b_map_count == nmaps);
|
2010-06-23 16:11:15 +08:00
|
|
|
return blip->bli_buf;
|
2012-06-22 16:50:11 +08:00
|
|
|
}
|
2010-04-18 08:10:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-16 07:35:09 +08:00
|
|
|
/*
|
|
|
|
* Add the locked buffer to the transaction.
|
|
|
|
*
|
|
|
|
* The buffer must be locked, and it cannot be associated with any
|
|
|
|
* transaction.
|
|
|
|
*
|
|
|
|
* If the buffer does not yet have a buf log item associated with it,
|
|
|
|
* then allocate one for it. Then add the buf item to the transaction.
|
|
|
|
*/
|
|
|
|
STATIC void
|
|
|
|
_xfs_trans_bjoin(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
int reset_recur)
|
|
|
|
{
|
|
|
|
struct xfs_buf_log_item *bip;
|
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == NULL);
|
2010-02-16 07:35:09 +08:00
|
|
|
|
|
|
|
/*
|
2018-01-25 05:38:48 +08:00
|
|
|
* The xfs_buf_log_item pointer is stored in b_log_item. If
|
2010-02-16 07:35:09 +08:00
|
|
|
* it doesn't have one yet, then allocate one and initialize it.
|
|
|
|
* The checks to see if one is there are in xfs_buf_item_init().
|
|
|
|
*/
|
|
|
|
xfs_buf_item_init(bp, tp->t_mountp);
|
2018-01-25 05:38:48 +08:00
|
|
|
bip = bp->b_log_item;
|
2010-02-16 07:35:09 +08:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 07:18:03 +08:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2010-02-16 07:35:09 +08:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
|
|
|
|
if (reset_recur)
|
|
|
|
bip->bli_recur = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take a reference for this transaction on the buf item.
|
|
|
|
*/
|
|
|
|
atomic_inc(&bip->bli_refcount);
|
|
|
|
|
|
|
|
/*
|
2018-05-09 22:49:37 +08:00
|
|
|
* Attach the item to the transaction so we can find it in
|
|
|
|
* xfs_trans_get_buf() and friends.
|
2010-02-16 07:35:09 +08:00
|
|
|
*/
|
2010-06-23 16:11:15 +08:00
|
|
|
xfs_trans_add_item(tp, &bip->bli_item);
|
2011-07-13 19:43:49 +08:00
|
|
|
bp->b_transp = tp;
|
2010-02-16 07:35:09 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xfs_trans_bjoin(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
_xfs_trans_bjoin(tp, bp, 0);
|
2018-01-25 05:38:48 +08:00
|
|
|
trace_xfs_trans_bjoin(bp->b_log_item);
|
2010-02-16 07:35:09 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get and lock the buffer for the caller if it is not already
|
|
|
|
* locked within the given transaction. If it is already locked
|
|
|
|
* within the transaction, just increment its lock recursion count
|
|
|
|
* and return a pointer to it.
|
|
|
|
*
|
|
|
|
* If the transaction pointer is NULL, make this just a normal
|
|
|
|
* get_buf() call.
|
|
|
|
*/
|
2020-01-24 09:01:18 +08:00
|
|
|
int
|
2012-06-22 16:50:11 +08:00
|
|
|
xfs_trans_get_buf_map(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
2020-01-24 09:01:18 +08:00
|
|
|
xfs_buf_flags_t flags,
|
|
|
|
struct xfs_buf **bpp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp;
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip;
|
2020-01-24 09:01:15 +08:00
|
|
|
int error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-01-24 09:01:18 +08:00
|
|
|
*bpp = NULL;
|
|
|
|
if (!tp)
|
|
|
|
return xfs_buf_get_map(target, map, nmaps, flags, bpp);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we find the buffer in the cache with this transaction
|
|
|
|
* pointer in its b_fsprivate2 field, then we know we already
|
|
|
|
* have it locked. In this case we just increment the lock
|
|
|
|
* recursion count and return the buffer to the caller.
|
|
|
|
*/
|
2012-06-22 16:50:11 +08:00
|
|
|
bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (bp != NULL) {
|
2011-07-08 20:36:19 +08:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
2011-10-11 00:52:46 +08:00
|
|
|
if (XFS_FORCED_SHUTDOWN(tp->t_mountp)) {
|
|
|
|
xfs_buf_stale(bp);
|
2016-02-10 12:01:11 +08:00
|
|
|
bp->b_flags |= XBF_DONE;
|
2011-10-11 00:52:46 +08:00
|
|
|
}
|
2009-12-15 07:14:59 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2018-01-25 05:38:48 +08:00
|
|
|
bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
bip->bli_recur++;
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_get_buf_recur(bip);
|
2020-01-24 09:01:18 +08:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2020-01-24 09:01:15 +08:00
|
|
|
error = xfs_buf_get_map(target, map, nmaps, flags, &bp);
|
|
|
|
if (error)
|
2020-01-24 09:01:18 +08:00
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-23 07:39:51 +08:00
|
|
|
ASSERT(!bp->b_error);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-02-16 07:35:09 +08:00
|
|
|
_xfs_trans_bjoin(tp, bp, 1);
|
2018-01-25 05:38:48 +08:00
|
|
|
trace_xfs_trans_get_buf(bp->b_log_item);
|
2020-01-24 09:01:18 +08:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-09-02 01:55:47 +08:00
|
|
|
* Get and lock the superblock buffer for the given transaction.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2020-09-02 01:55:47 +08:00
|
|
|
struct xfs_buf *
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_getsb(
|
2020-09-02 01:55:47 +08:00
|
|
|
struct xfs_trans *tp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2020-09-02 01:55:47 +08:00
|
|
|
struct xfs_buf *bp = tp->t_mountp->m_sb_bp;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2020-09-02 01:55:47 +08:00
|
|
|
* Just increment the lock recursion count if the buffer is already
|
|
|
|
* attached to this transaction.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2011-07-13 19:43:49 +08:00
|
|
|
if (bp->b_transp == tp) {
|
2020-09-02 01:55:47 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
bip->bli_recur++;
|
2020-09-02 01:55:47 +08:00
|
|
|
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_getsb_recur(bip);
|
2020-09-02 01:55:47 +08:00
|
|
|
} else {
|
|
|
|
xfs_buf_lock(bp);
|
|
|
|
xfs_buf_hold(bp);
|
|
|
|
_xfs_trans_bjoin(tp, bp, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-09-02 01:55:47 +08:00
|
|
|
trace_xfs_trans_getsb(bp->b_log_item);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-06-22 13:03:54 +08:00
|
|
|
return bp;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get and lock the buffer for the caller if it is not already
|
|
|
|
* locked within the given transaction. If it has not yet been
|
|
|
|
* read in, read it from disk. If it is already locked
|
|
|
|
* within the transaction and already read in, just increment its
|
|
|
|
* lock recursion count and return a pointer to it.
|
|
|
|
*
|
|
|
|
* If the transaction pointer is NULL, make this just a normal
|
|
|
|
* read_buf() call.
|
|
|
|
*/
|
|
|
|
int
|
2012-06-22 16:50:11 +08:00
|
|
|
xfs_trans_read_buf_map(
|
|
|
|
struct xfs_mount *mp,
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
|
|
|
xfs_buf_flags_t flags,
|
2012-11-12 19:54:01 +08:00
|
|
|
struct xfs_buf **bpp,
|
2012-11-14 14:54:40 +08:00
|
|
|
const struct xfs_buf_ops *ops)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-12-04 06:43:13 +08:00
|
|
|
struct xfs_buf *bp = NULL;
|
|
|
|
struct xfs_buf_log_item *bip;
|
2005-04-17 06:20:36 +08:00
|
|
|
int error;
|
|
|
|
|
2012-04-23 13:58:55 +08:00
|
|
|
*bpp = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* If we find the buffer in the cache with this transaction
|
|
|
|
* pointer in its b_fsprivate2 field, then we know we already
|
|
|
|
* have it locked. If it is already read in we just increment
|
|
|
|
* the lock recursion count and return the buffer to the caller.
|
|
|
|
* If the buffer is not yet read in, then we read it in, increment
|
|
|
|
* the lock recursion count, and return it to the caller.
|
|
|
|
*/
|
2014-12-04 06:43:13 +08:00
|
|
|
if (tp)
|
|
|
|
bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
|
|
|
|
if (bp) {
|
2011-07-08 20:36:19 +08:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2018-01-25 05:38:48 +08:00
|
|
|
ASSERT(bp->b_log_item != NULL);
|
2011-07-23 07:39:51 +08:00
|
|
|
ASSERT(!bp->b_error);
|
2014-12-04 06:43:13 +08:00
|
|
|
ASSERT(bp->b_flags & XBF_DONE);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* We never locked this buf ourselves, so we shouldn't
|
|
|
|
* brelse it either. Just get out.
|
|
|
|
*/
|
|
|
|
if (XFS_FORCED_SHUTDOWN(mp)) {
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
|
2014-06-25 12:58:08 +08:00
|
|
|
return -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 14:20:30 +08:00
|
|
|
/*
|
|
|
|
* Check if the caller is trying to read a buffer that is
|
|
|
|
* already attached to the transaction yet has no buffer ops
|
|
|
|
* assigned. Ops are usually attached when the buffer is
|
|
|
|
* attached to the transaction, or by the read caller if
|
|
|
|
* special circumstances. That didn't happen, which is not
|
|
|
|
* how this is supposed to go.
|
|
|
|
*
|
|
|
|
* If the buffer passes verification we'll let this go, but if
|
|
|
|
* not we have to shut down. Let the transaction cleanup code
|
|
|
|
* release this buffer when it kills the tranaction.
|
|
|
|
*/
|
|
|
|
ASSERT(bp->b_ops != NULL);
|
2019-02-07 01:25:29 +08:00
|
|
|
error = xfs_buf_reverify(bp, ops);
|
2018-10-18 14:20:30 +08:00
|
|
|
if (error) {
|
2020-01-24 09:01:20 +08:00
|
|
|
xfs_buf_ioerror_alert(bp, __return_address);
|
2018-10-18 14:20:30 +08:00
|
|
|
|
|
|
|
if (tp->t_flags & XFS_TRANS_DIRTY)
|
|
|
|
xfs_force_shutdown(tp->t_mountp,
|
|
|
|
SHUTDOWN_META_IO_ERROR);
|
|
|
|
|
|
|
|
/* bad CRC means corrupted metadata */
|
|
|
|
if (error == -EFSBADCRC)
|
|
|
|
error = -EFSCORRUPTED;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-01-25 05:38:48 +08:00
|
|
|
bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
bip->bli_recur++;
|
|
|
|
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_read_buf_recur(bip);
|
2018-10-18 14:20:30 +08:00
|
|
|
ASSERT(bp->b_ops != NULL || ops == NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-24 09:01:20 +08:00
|
|
|
error = xfs_buf_read_map(target, map, nmaps, flags, &bp, ops,
|
|
|
|
__return_address);
|
2020-01-24 09:01:16 +08:00
|
|
|
switch (error) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
default:
|
2014-12-04 06:43:13 +08:00
|
|
|
if (tp && (tp->t_flags & XFS_TRANS_DIRTY))
|
2006-06-09 12:58:38 +08:00
|
|
|
xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
|
2020-01-24 09:01:16 +08:00
|
|
|
/* fall through */
|
|
|
|
case -ENOMEM:
|
|
|
|
case -EAGAIN:
|
2005-04-17 06:20:36 +08:00
|
|
|
return error;
|
|
|
|
}
|
2014-12-04 06:43:13 +08:00
|
|
|
|
|
|
|
if (XFS_FORCED_SHUTDOWN(mp)) {
|
|
|
|
xfs_buf_relse(bp);
|
|
|
|
trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
|
|
|
|
return -EIO;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2015-02-10 06:23:40 +08:00
|
|
|
if (tp) {
|
2014-12-04 06:43:13 +08:00
|
|
|
_xfs_trans_bjoin(tp, bp, 1);
|
2018-01-25 05:38:48 +08:00
|
|
|
trace_xfs_trans_read_buf(bp->b_log_item);
|
2015-02-10 06:23:40 +08:00
|
|
|
}
|
2018-10-18 14:20:30 +08:00
|
|
|
ASSERT(bp->b_ops != NULL || ops == NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-10-18 14:20:35 +08:00
|
|
|
/* Has this buffer been dirtied by anyone? */
|
|
|
|
bool
|
|
|
|
xfs_trans_buf_is_dirty(
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
|
|
|
|
|
|
|
if (!bip)
|
|
|
|
return false;
|
|
|
|
ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
|
|
|
|
return test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2018-09-29 11:45:02 +08:00
|
|
|
* Release a buffer previously joined to the transaction. If the buffer is
|
|
|
|
* modified within this transaction, decrement the recursion count but do not
|
|
|
|
* release the buffer even if the count goes to 0. If the buffer is not modified
|
|
|
|
* within the transaction, decrement the recursion count and release the buffer
|
|
|
|
* if the recursion count goes to 0.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2018-09-29 11:45:02 +08:00
|
|
|
* If the buffer is to be released and it was not already dirty before this
|
|
|
|
* transaction began, then also free the buf_log_item associated with it.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2018-09-29 11:45:02 +08:00
|
|
|
* If the transaction pointer is NULL, this is a normal xfs_buf_relse() call.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
void
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_brelse(
|
2018-09-29 11:45:02 +08:00
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-09-29 11:45:02 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-09-29 11:45:02 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
|
|
|
|
|
|
|
if (!tp) {
|
2005-04-17 06:20:36 +08:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-09-29 11:45:02 +08:00
|
|
|
trace_xfs_trans_brelse(bip);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
|
|
|
/*
|
2018-09-29 11:45:02 +08:00
|
|
|
* If the release is for a recursive lookup, then decrement the count
|
|
|
|
* and return.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if (bip->bli_recur > 0) {
|
|
|
|
bip->bli_recur--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-29 11:45:02 +08:00
|
|
|
* If the buffer is invalidated or dirty in this transaction, we can't
|
2005-04-17 06:20:36 +08:00
|
|
|
* release it until we commit.
|
|
|
|
*/
|
2018-05-09 22:49:37 +08:00
|
|
|
if (test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
2009-12-15 07:14:59 +08:00
|
|
|
if (bip->bli_flags & XFS_BLI_STALE)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
2018-09-29 11:45:02 +08:00
|
|
|
* Unlink the log item from the transaction and clear the hold flag, if
|
|
|
|
* set. We wouldn't want the next user of the buffer to get confused.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2018-09-29 11:45:02 +08:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
|
2010-06-23 16:11:15 +08:00
|
|
|
xfs_trans_del_item(&bip->bli_item);
|
2018-09-29 11:45:02 +08:00
|
|
|
bip->bli_flags &= ~XFS_BLI_HOLD;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
xfs: refactor xfs_buf_log_item reference count handling
The xfs_buf_log_item structure has a reference counter with slightly
tricky semantics. In the common case, a buffer is logged and
committed in a transaction, committed to the on-disk log (added to
the AIL) and then finally written back and removed from the AIL. The
bli refcount covers two potentially overlapping timeframes:
1. the bli is held in an active transaction
2. the bli is pinned by the log
The caveat to this approach is that the reference counter does not
purely dictate the lifetime of the bli. IOW, when a dirty buffer is
physically logged and unpinned, the bli refcount may go to zero as
the log item is inserted into the AIL. Only once the buffer is
written back can the bli finally be freed.
The above semantics means that it is not enough for the various
refcount decrementing contexts to release the bli on decrement to
zero. xfs_trans_brelse(), transaction commit (->iop_unlock()) and
unpin (->iop_unpin()) must all drop the associated reference and
make additional checks to determine if the current context is
responsible for freeing the item.
For example, if a transaction holds but does not dirty a particular
bli, the commit may drop the refcount to zero. If the bli itself is
clean, it is also not AIL resident and must be freed at this time.
The same is true for xfs_trans_brelse(). If the transaction dirties
a bli and then aborts or an unpin results in an abort due to a log
I/O error, the last reference count holder is expected to explicitly
remove the item from the AIL and release it (since an abort means
filesystem shutdown and metadata writeback will never occur).
This leads to fairly complex checks being replicated in a few
different places. Since ->iop_unlock() and xfs_trans_brelse() are
nearly identical, refactor the logic into a common helper that
implements and documents the semantics in one place. This patch does
not change behavior.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
2018-09-29 11:45:26 +08:00
|
|
|
/* drop the reference to the bli */
|
|
|
|
xfs_buf_item_put(bip);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-20 10:31:22 +08:00
|
|
|
bp->b_transp = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the buffer as not needing to be unlocked when the buf item's
|
2019-06-29 10:27:32 +08:00
|
|
|
* iop_committing() routine is called. The buffer must already be locked
|
2005-04-17 06:20:36 +08:00
|
|
|
* and associated with the given transaction.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_bhold(
|
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 07:18:03 +08:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
2011-07-13 19:43:49 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
bip->bli_flags |= XFS_BLI_HOLD;
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_bhold(bip);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-05 06:29:01 +08:00
|
|
|
/*
|
|
|
|
* Cancel the previous buffer hold request made on this buffer
|
|
|
|
* for this transaction.
|
|
|
|
*/
|
|
|
|
void
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_bhold_release(
|
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp)
|
2005-09-05 06:29:01 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-09-05 06:29:01 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-09-05 06:29:01 +08:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 07:18:03 +08:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2005-09-05 06:29:01 +08:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
ASSERT(bip->bli_flags & XFS_BLI_HOLD);
|
2009-12-15 07:14:59 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
bip->bli_flags &= ~XFS_BLI_HOLD;
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_bhold_release(bip);
|
2005-09-05 06:29:01 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2017-08-30 01:08:38 +08:00
|
|
|
* Mark a buffer dirty in the transaction.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
void
|
2017-08-30 01:08:38 +08:00
|
|
|
xfs_trans_dirty_buf(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the buffer as needing to be written out eventually,
|
|
|
|
* and set its iodone function to remove the buffer's buf log
|
|
|
|
* item from the AIL and free it when the buffer is flushed
|
2020-06-30 05:48:47 +08:00
|
|
|
* to disk.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2016-02-10 12:01:11 +08:00
|
|
|
bp->b_flags |= XBF_DONE;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we invalidated the buffer within this transaction, then
|
|
|
|
* cancel the invalidation now that we're dirtying the buffer
|
|
|
|
* again. There are no races with the code in xfs_buf_item_unpin(),
|
|
|
|
* because we have a reference to the buffer this entire time.
|
|
|
|
*/
|
|
|
|
if (bip->bli_flags & XFS_BLI_STALE) {
|
|
|
|
bip->bli_flags &= ~XFS_BLI_STALE;
|
2016-02-10 12:01:11 +08:00
|
|
|
ASSERT(bp->b_flags & XBF_STALE);
|
|
|
|
bp->b_flags &= ~XBF_STALE;
|
2012-12-05 07:18:03 +08:00
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLF_CANCEL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2017-08-30 01:08:38 +08:00
|
|
|
bip->bli_flags |= XFS_BLI_DIRTY | XFS_BLI_LOGGED;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
tp->t_flags |= XFS_TRANS_DIRTY;
|
2018-05-09 22:49:37 +08:00
|
|
|
set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
|
2017-08-30 01:08:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is called to mark bytes first through last inclusive of the given
|
|
|
|
* buffer as needing to be logged when the transaction is committed.
|
|
|
|
* The buffer must already be associated with the given transaction.
|
|
|
|
*
|
|
|
|
* First and last are numbers relative to the beginning of this buffer,
|
|
|
|
* so the first byte in the buffer is numbered 0 regardless of the
|
|
|
|
* value of b_blkno.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_log_buf(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp,
|
|
|
|
uint first,
|
|
|
|
uint last)
|
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2017-08-30 01:08:38 +08:00
|
|
|
|
|
|
|
ASSERT(first <= last && last < BBTOB(bp->b_length));
|
2017-08-30 01:08:38 +08:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_ORDERED));
|
2017-08-30 01:08:38 +08:00
|
|
|
|
|
|
|
xfs_trans_dirty_buf(tp, bp);
|
2013-06-27 14:04:52 +08:00
|
|
|
|
2017-08-30 01:08:38 +08:00
|
|
|
trace_xfs_trans_log_buf(bip);
|
2017-08-30 01:08:38 +08:00
|
|
|
xfs_buf_item_log(bip, first, last);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 13:58:39 +08:00
|
|
|
* Invalidate a buffer that is being used within a transaction.
|
|
|
|
*
|
|
|
|
* Typically this is because the blocks in the buffer are being freed, so we
|
|
|
|
* need to prevent it from being written out when we're done. Allowing it
|
|
|
|
* to be written again might overwrite data in the free blocks if they are
|
|
|
|
* reallocated to a file.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 13:58:39 +08:00
|
|
|
* We prevent the buffer from being written out by marking it stale. We can't
|
|
|
|
* get rid of the buf log item at this point because the buffer may still be
|
|
|
|
* pinned by another transaction. If that is the case, then we'll wait until
|
|
|
|
* the buffer is committed to disk for the last time (we can tell by the ref
|
|
|
|
* count) and free it in xfs_buf_item_unpin(). Until that happens we will
|
|
|
|
* keep the buffer locked so that the buffer and buf log item are not reused.
|
|
|
|
*
|
|
|
|
* We also set the XFS_BLF_CANCEL flag in the buf log format structure and log
|
|
|
|
* the buf item. This will be used at recovery time to determine that copies
|
|
|
|
* of the buffer in the log before this should not be replayed.
|
|
|
|
*
|
|
|
|
* We mark the item descriptor and the transaction dirty so that we'll hold
|
|
|
|
* the buffer until after the commit.
|
|
|
|
*
|
|
|
|
* Since we're invalidating the buffer, we also clear the state about which
|
|
|
|
* parts of the buffer have been logged. We also clear the flag indicating
|
|
|
|
* that this is an inode buffer since the data in the buffer will no longer
|
|
|
|
* be valid.
|
|
|
|
*
|
|
|
|
* We set the stale bit in the buffer as well since we're getting rid of it.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_binval(
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2012-12-05 07:18:05 +08:00
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
2009-12-15 07:14:59 +08:00
|
|
|
trace_xfs_trans_binval(bip);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (bip->bli_flags & XFS_BLI_STALE) {
|
|
|
|
/*
|
|
|
|
* If the buffer is already invalidated, then
|
|
|
|
* just return.
|
|
|
|
*/
|
2016-02-10 12:01:11 +08:00
|
|
|
ASSERT(bp->b_flags & XBF_STALE);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
|
2012-12-05 07:18:03 +08:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_INODE_BUF));
|
2013-04-03 13:11:30 +08:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLFT_MASK));
|
2012-12-05 07:18:03 +08:00
|
|
|
ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
|
2018-05-09 22:49:37 +08:00
|
|
|
ASSERT(test_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags));
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-11 00:52:46 +08:00
|
|
|
xfs_buf_stale(bp);
|
xfs: on-stack delayed write buffer lists
Queue delwri buffers on a local on-stack list instead of a per-buftarg one,
and write back the buffers per-process instead of by waking up xfsbufd.
This is now easily doable given that we have very few places left that write
delwri buffers:
- log recovery:
Only done at mount time, and already forcing out the buffers
synchronously using xfs_flush_buftarg
- quotacheck:
Same story.
- dquot reclaim:
Writes out dirty dquots on the LRU under memory pressure. We might
want to look into doing more of this via xfsaild, but it's already
more optimal than the synchronous inode reclaim that writes each
buffer synchronously.
- xfsaild:
This is the main beneficiary of the change. By keeping a local list
of buffers to write we reduce latency of writing out buffers, and
more importably we can remove all the delwri list promotions which
were hitting the buffer cache hard under sustained metadata loads.
The implementation is very straight forward - xfs_buf_delwri_queue now gets
a new list_head pointer that it adds the delwri buffers to, and all callers
need to eventually submit the list using xfs_buf_delwi_submit or
xfs_buf_delwi_submit_nowait. Buffers that already are on a delwri list are
skipped in xfs_buf_delwri_queue, assuming they already are on another delwri
list. The biggest change to pass down the buffer list was done to the AIL
pushing. Now that we operate on buffers the trylock, push and pushbuf log
item methods are merged into a single push routine, which tries to lock the
item, and if possible add the buffer that needs writeback to the buffer list.
This leads to much simpler code than the previous split but requires the
individual IOP_PUSH instances to unlock and reacquire the AIL around calls
to blocking routines.
Given that xfsailds now also handle writing out buffers, the conditions for
log forcing and the sleep times needed some small changes. The most
important one is that we consider an AIL busy as long we still have buffers
to push, and the other one is that we do increment the pushed LSN for
buffers that are under flushing at this moment, but still count them towards
the stuck items for restart purposes. Without this we could hammer on stuck
items without ever forcing the log and not make progress under heavy random
delete workloads on fast flash storage devices.
[ Dave Chinner:
- rebase on previous patches.
- improved comments for XBF_DELWRI_Q handling
- fix XBF_ASYNC handling in queue submission (test 106 failure)
- rename delwri submit function buffer list parameters for clarity
- xfs_efd_item_push() should return XFS_ITEM_PINNED ]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Mark Tinguely <tinguely@sgi.com>
Signed-off-by: Ben Myers <bpm@sgi.com>
2012-04-23 13:58:39 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
bip->bli_flags |= XFS_BLI_STALE;
|
2010-05-20 21:19:42 +08:00
|
|
|
bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
|
2012-12-05 07:18:03 +08:00
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
|
|
|
|
bip->__bli_format.blf_flags |= XFS_BLF_CANCEL;
|
2013-04-03 13:11:30 +08:00
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLFT_MASK;
|
2012-12-05 07:18:05 +08:00
|
|
|
for (i = 0; i < bip->bli_format_count; i++) {
|
|
|
|
memset(bip->bli_formats[i].blf_data_map, 0,
|
|
|
|
(bip->bli_formats[i].blf_map_size * sizeof(uint)));
|
|
|
|
}
|
2018-05-09 22:49:37 +08:00
|
|
|
set_bit(XFS_LI_DIRTY, &bip->bli_item.li_flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
tp->t_flags |= XFS_TRANS_DIRTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-20 21:19:42 +08:00
|
|
|
* This call is used to indicate that the buffer contains on-disk inodes which
|
|
|
|
* must be handled specially during recovery. They require special handling
|
|
|
|
* because only the di_next_unlinked from the inodes in the buffer should be
|
|
|
|
* recovered. The rest of the data in the buffer is logged via the inodes
|
|
|
|
* themselves.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2010-05-20 21:19:42 +08:00
|
|
|
* All we do is set the XFS_BLI_INODE_BUF flag in the items flags so it can be
|
|
|
|
* transferred to the buffer's log format structure so that we'll know what to
|
|
|
|
* do at recovery time.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_inode_buf(
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
2010-05-20 21:19:42 +08:00
|
|
|
bip->bli_flags |= XFS_BLI_INODE_BUF;
|
2020-06-30 05:48:46 +08:00
|
|
|
bp->b_flags |= _XBF_INODES;
|
2013-04-03 13:11:30 +08:00
|
|
|
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This call is used to indicate that the buffer is going to
|
|
|
|
* be staled and was an inode buffer. This means it gets
|
2013-04-03 13:11:17 +08:00
|
|
|
* special processing during unpin - where any inodes
|
2005-04-17 06:20:36 +08:00
|
|
|
* associated with the buffer should be removed from ail.
|
|
|
|
* There is also special processing during recovery,
|
|
|
|
* any replay of the inodes in the buffer needs to be
|
|
|
|
* prevented as the buffer may have been reused.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_stale_inode_buf(
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
|
|
|
bip->bli_flags |= XFS_BLI_STALE_INODE;
|
2020-06-30 05:48:46 +08:00
|
|
|
bp->b_flags |= _XBF_INODES;
|
2013-04-03 13:11:30 +08:00
|
|
|
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the buffer as being one which contains newly allocated
|
|
|
|
* inodes. We need to make sure that even if this buffer is
|
|
|
|
* relogged as an 'inode buf' we still recover all of the inode
|
|
|
|
* images in the face of a crash. This works in coordination with
|
|
|
|
* xfs_buf_item_committed() to ensure that the buffer remains in the
|
|
|
|
* AIL at its original location even after it has been relogged.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
xfs_trans_inode_alloc_buf(
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 19:43:49 +08:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
|
|
|
bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
|
2020-06-30 05:48:46 +08:00
|
|
|
bp->b_flags |= _XBF_INODES;
|
2013-04-03 13:11:30 +08:00
|
|
|
xfs_trans_buf_set_type(tp, bp, XFS_BLFT_DINO_BUF);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2013-06-27 14:04:52 +08:00
|
|
|
/*
|
2017-08-30 01:08:38 +08:00
|
|
|
* Mark the buffer as ordered for this transaction. This means that the contents
|
|
|
|
* of the buffer are not recorded in the transaction but it is tracked in the
|
|
|
|
* AIL as though it was. This allows us to record logical changes in
|
|
|
|
* transactions rather than the physical changes we make to the buffer without
|
|
|
|
* changing writeback ordering constraints of metadata buffers.
|
2013-06-27 14:04:52 +08:00
|
|
|
*/
|
2017-08-30 01:08:40 +08:00
|
|
|
bool
|
2013-06-27 14:04:52 +08:00
|
|
|
xfs_trans_ordered_buf(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2013-06-27 14:04:52 +08:00
|
|
|
|
|
|
|
ASSERT(bp->b_transp == tp);
|
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
2017-08-30 01:08:40 +08:00
|
|
|
|
|
|
|
if (xfs_buf_item_dirty_format(bip))
|
|
|
|
return false;
|
2013-06-27 14:04:52 +08:00
|
|
|
|
|
|
|
bip->bli_flags |= XFS_BLI_ORDERED;
|
|
|
|
trace_xfs_buf_item_ordered(bip);
|
2017-08-30 01:08:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't log a dirty range of an ordered buffer but it still needs
|
|
|
|
* to be marked dirty and that it has been logged.
|
|
|
|
*/
|
|
|
|
xfs_trans_dirty_buf(tp, bp);
|
2017-08-30 01:08:40 +08:00
|
|
|
return true;
|
2013-06-27 14:04:52 +08:00
|
|
|
}
|
|
|
|
|
2013-04-22 03:53:46 +08:00
|
|
|
/*
|
|
|
|
* Set the type of the buffer for log recovery so that it can correctly identify
|
|
|
|
* and hence attach the correct buffer ops to the buffer after replay.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_buf_set_type(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp,
|
2013-04-03 13:11:30 +08:00
|
|
|
enum xfs_blft type)
|
2013-04-22 03:53:46 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2013-04-22 03:53:46 +08:00
|
|
|
|
2013-04-03 13:11:29 +08:00
|
|
|
if (!tp)
|
|
|
|
return;
|
|
|
|
|
2013-04-22 03:53:46 +08:00
|
|
|
ASSERT(bp->b_transp == tp);
|
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
2013-04-03 13:11:30 +08:00
|
|
|
xfs_blft_to_flags(&bip->__bli_format, type);
|
2013-04-22 03:53:46 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-03 13:11:29 +08:00
|
|
|
void
|
|
|
|
xfs_trans_buf_copy_type(
|
|
|
|
struct xfs_buf *dst_bp,
|
|
|
|
struct xfs_buf *src_bp)
|
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *sbip = src_bp->b_log_item;
|
|
|
|
struct xfs_buf_log_item *dbip = dst_bp->b_log_item;
|
2013-04-03 13:11:30 +08:00
|
|
|
enum xfs_blft type;
|
2013-04-03 13:11:29 +08:00
|
|
|
|
2013-04-03 13:11:30 +08:00
|
|
|
type = xfs_blft_from_flags(&sbip->__bli_format);
|
|
|
|
xfs_blft_to_flags(&dbip->__bli_format, type);
|
2013-04-03 13:11:29 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Similar to xfs_trans_inode_buf(), this marks the buffer as a cluster of
|
|
|
|
* dquots. However, unlike in inode buffer recovery, dquot buffers get
|
|
|
|
* recovered in their entirety. (Hence, no XFS_BLI_DQUOT_ALLOC_BUF flag).
|
|
|
|
* The only thing that makes dquot buffers different from regular
|
|
|
|
* buffers is that we must not replay dquot bufs when recovering
|
|
|
|
* if a _corresponding_ quotaoff has happened. We also have to distinguish
|
|
|
|
* between usr dquot bufs and grp dquot bufs, because usr and grp quotas
|
|
|
|
* can be turned off independently.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
xfs_trans_dquot_buf(
|
2018-01-25 05:38:48 +08:00
|
|
|
xfs_trans_t *tp,
|
2020-12-17 08:07:34 +08:00
|
|
|
struct xfs_buf *bp,
|
2018-01-25 05:38:48 +08:00
|
|
|
uint type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-01-25 05:38:48 +08:00
|
|
|
struct xfs_buf_log_item *bip = bp->b_log_item;
|
2013-04-03 13:11:30 +08:00
|
|
|
|
2010-05-07 09:05:19 +08:00
|
|
|
ASSERT(type == XFS_BLF_UDQUOT_BUF ||
|
|
|
|
type == XFS_BLF_PDQUOT_BUF ||
|
|
|
|
type == XFS_BLF_GDQUOT_BUF);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-04-03 13:11:30 +08:00
|
|
|
bip->__bli_format.blf_flags |= type;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case XFS_BLF_UDQUOT_BUF:
|
|
|
|
type = XFS_BLFT_UDQUOT_BUF;
|
|
|
|
break;
|
|
|
|
case XFS_BLF_PDQUOT_BUF:
|
|
|
|
type = XFS_BLFT_PDQUOT_BUF;
|
|
|
|
break;
|
|
|
|
case XFS_BLF_GDQUOT_BUF:
|
|
|
|
type = XFS_BLFT_GDQUOT_BUF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = XFS_BLFT_UNKNOWN_BUF;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-30 05:48:46 +08:00
|
|
|
bp->b_flags |= _XBF_DQUOTS;
|
2013-04-22 03:53:46 +08:00
|
|
|
xfs_trans_buf_set_type(tp, bp, type);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|