2005-04-17 05:20:36 +07:00
|
|
|
/*
|
2005-11-02 10:58:39 +07:00
|
|
|
* Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2005-11-02 10:58:39 +07:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
2005-04-17 05:20:36 +07:00
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
2005-11-02 10:58:39 +07:00
|
|
|
* This program is distributed in the hope that it would be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2005-11-02 10:58:39 +07:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
2005-11-02 10:38:42 +07:00
|
|
|
#include "xfs_fs.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
#include "xfs_types.h"
|
|
|
|
#include "xfs_log.h"
|
|
|
|
#include "xfs_trans.h"
|
|
|
|
#include "xfs_sb.h"
|
|
|
|
#include "xfs_ag.h"
|
|
|
|
#include "xfs_mount.h"
|
2005-11-02 10:38:42 +07:00
|
|
|
#include "xfs_bmap_btree.h"
|
|
|
|
#include "xfs_alloc_btree.h"
|
|
|
|
#include "xfs_ialloc_btree.h"
|
|
|
|
#include "xfs_dinode.h"
|
|
|
|
#include "xfs_inode.h"
|
|
|
|
#include "xfs_buf_item.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
#include "xfs_trans_priv.h"
|
|
|
|
#include "xfs_error.h"
|
2009-12-15 06:14:59 +07:00
|
|
|
#include "xfs_trace.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-04-18 07:10:45 +07: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 15:50:11 +07:00
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps)
|
2010-04-18 07:10:45 +07:00
|
|
|
{
|
2010-06-23 15:11:15 +07:00
|
|
|
struct xfs_log_item_desc *lidp;
|
|
|
|
struct xfs_buf_log_item *blip;
|
2012-06-22 15:50:11 +07:00
|
|
|
int len = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < nmaps; i++)
|
|
|
|
len += map[i].bm_len;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-06-23 15:11:15 +07:00
|
|
|
list_for_each_entry(lidp, &tp->t_items, lid_trans) {
|
|
|
|
blip = (struct xfs_buf_log_item *)lidp->lid_item;
|
|
|
|
if (blip->bli_item.li_type == XFS_LI_BUF &&
|
2011-07-23 06:40:40 +07:00
|
|
|
blip->bli_buf->b_target == target &&
|
2012-06-22 15:50:11 +07: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 15:11:15 +07:00
|
|
|
return blip->bli_buf;
|
2012-06-22 15:50:11 +07:00
|
|
|
}
|
2010-04-18 07:10:45 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-02-16 06:35:09 +07: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 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == NULL);
|
2010-02-16 06:35:09 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The xfs_buf_log_item pointer is stored in b_fsprivate. If
|
|
|
|
* 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);
|
2011-07-13 18:43:49 +07:00
|
|
|
bip = bp->b_fspriv;
|
2010-02-16 06:35:09 +07:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 06:18:03 +07:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2010-02-16 06:35:09 +07: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);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a log_item_desc to point at the new item.
|
|
|
|
*/
|
2010-06-23 15:11:15 +07:00
|
|
|
xfs_trans_add_item(tp, &bip->bli_item);
|
2010-02-16 06:35:09 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize b_fsprivate2 so we can find it with incore_match()
|
|
|
|
* in xfs_trans_get_buf() and friends above.
|
|
|
|
*/
|
2011-07-13 18:43:49 +07:00
|
|
|
bp->b_transp = tp;
|
2010-02-16 06:35:09 +07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xfs_trans_bjoin(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
_xfs_trans_bjoin(tp, bp, 0);
|
|
|
|
trace_xfs_trans_bjoin(bp->b_fspriv);
|
|
|
|
}
|
2005-04-17 05:20:36 +07: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.
|
|
|
|
*/
|
2012-06-22 15:50:11 +07:00
|
|
|
struct xfs_buf *
|
|
|
|
xfs_trans_get_buf_map(
|
|
|
|
struct xfs_trans *tp,
|
|
|
|
struct xfs_buftarg *target,
|
|
|
|
struct xfs_buf_map *map,
|
|
|
|
int nmaps,
|
|
|
|
xfs_buf_flags_t flags)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
xfs_buf_t *bp;
|
|
|
|
xfs_buf_log_item_t *bip;
|
|
|
|
|
2012-06-22 15:50:11 +07:00
|
|
|
if (!tp)
|
|
|
|
return xfs_buf_get_map(target, map, nmaps, flags);
|
2005-04-17 05:20:36 +07: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 15:50:11 +07:00
|
|
|
bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (bp != NULL) {
|
2011-07-08 19:36:19 +07:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
2011-10-10 23:52:46 +07:00
|
|
|
if (XFS_FORCED_SHUTDOWN(tp->t_mountp)) {
|
|
|
|
xfs_buf_stale(bp);
|
|
|
|
XFS_BUF_DONE(bp);
|
|
|
|
}
|
2009-12-15 06:14:59 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
bip->bli_recur++;
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_get_buf_recur(bip);
|
2005-04-17 05:20:36 +07:00
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
2012-06-22 15:50:11 +07:00
|
|
|
bp = xfs_buf_get_map(target, map, nmaps, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (bp == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-07-23 06:39:51 +07:00
|
|
|
ASSERT(!bp->b_error);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-02-16 06:35:09 +07:00
|
|
|
_xfs_trans_bjoin(tp, bp, 1);
|
|
|
|
trace_xfs_trans_get_buf(bp->b_fspriv);
|
2005-04-17 05:20:36 +07:00
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get and lock the superblock buffer of this file system for the
|
|
|
|
* given transaction.
|
|
|
|
*
|
|
|
|
* We don't need to use incore_match() here, because the superblock
|
|
|
|
* buffer is a private buffer which we keep a pointer to in the
|
|
|
|
* mount structure.
|
|
|
|
*/
|
|
|
|
xfs_buf_t *
|
|
|
|
xfs_trans_getsb(xfs_trans_t *tp,
|
|
|
|
struct xfs_mount *mp,
|
|
|
|
int flags)
|
|
|
|
{
|
|
|
|
xfs_buf_t *bp;
|
|
|
|
xfs_buf_log_item_t *bip;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default to just trying to lock the superblock buffer
|
|
|
|
* if tp is NULL.
|
|
|
|
*/
|
|
|
|
if (tp == NULL) {
|
|
|
|
return (xfs_getsb(mp, flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the superblock buffer already has 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.
|
|
|
|
*/
|
|
|
|
bp = mp->m_sb_bp;
|
2011-07-13 18:43:49 +07:00
|
|
|
if (bp->b_transp == tp) {
|
2011-07-13 18:43:49 +07:00
|
|
|
bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
bip->bli_recur++;
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_getsb_recur(bip);
|
2005-04-17 05:20:36 +07:00
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
bp = xfs_getsb(mp, flags);
|
2010-02-16 06:35:09 +07:00
|
|
|
if (bp == NULL)
|
2005-04-17 05:20:36 +07:00
|
|
|
return NULL;
|
|
|
|
|
2010-02-16 06:35:09 +07:00
|
|
|
_xfs_trans_bjoin(tp, bp, 1);
|
|
|
|
trace_xfs_trans_getsb(bp->b_fspriv);
|
2005-04-17 05:20:36 +07:00
|
|
|
return (bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
xfs_buftarg_t *xfs_error_target;
|
|
|
|
int xfs_do_error;
|
|
|
|
int xfs_req_num;
|
|
|
|
int xfs_error_mod = 33;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 15:50:11 +07: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 18:54:01 +07:00
|
|
|
struct xfs_buf **bpp,
|
2012-11-14 13:54:40 +07:00
|
|
|
const struct xfs_buf_ops *ops)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
xfs_buf_t *bp;
|
|
|
|
xfs_buf_log_item_t *bip;
|
|
|
|
int error;
|
|
|
|
|
2012-04-23 12:58:55 +07:00
|
|
|
*bpp = NULL;
|
2012-06-22 15:50:11 +07:00
|
|
|
if (!tp) {
|
2012-11-14 13:54:40 +07:00
|
|
|
bp = xfs_buf_read_map(target, map, nmaps, flags, ops);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!bp)
|
2010-01-19 16:56:44 +07:00
|
|
|
return (flags & XBF_TRYLOCK) ?
|
2008-03-06 09:43:42 +07:00
|
|
|
EAGAIN : XFS_ERROR(ENOMEM);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-23 06:39:51 +07:00
|
|
|
if (bp->b_error) {
|
|
|
|
error = bp->b_error;
|
2011-10-10 23:52:49 +07:00
|
|
|
xfs_buf_ioerror_alert(bp, __func__);
|
2012-04-23 12:58:55 +07:00
|
|
|
XFS_BUF_UNDONE(bp);
|
|
|
|
xfs_buf_stale(bp);
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
2009-07-27 23:15:25 +07:00
|
|
|
if (xfs_do_error) {
|
2005-04-17 05:20:36 +07:00
|
|
|
if (xfs_error_target == target) {
|
|
|
|
if (((xfs_req_num++) % xfs_error_mod) == 0) {
|
|
|
|
xfs_buf_relse(bp);
|
2011-03-07 06:08:35 +07:00
|
|
|
xfs_debug(mp, "Returning error!");
|
2005-04-17 05:20:36 +07:00
|
|
|
return XFS_ERROR(EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (XFS_FORCED_SHUTDOWN(mp))
|
|
|
|
goto shutdown_abort;
|
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2012-06-22 15:50:11 +07:00
|
|
|
bp = xfs_trans_buf_item_match(tp, target, map, nmaps);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (bp != NULL) {
|
2011-07-08 19:36:19 +07:00
|
|
|
ASSERT(xfs_buf_islocked(bp));
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_fspriv != NULL);
|
2011-07-23 06:39:51 +07:00
|
|
|
ASSERT(!bp->b_error);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!(XFS_BUF_ISDONE(bp))) {
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_read_buf_io(bp, _RET_IP_);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(!XFS_BUF_ISASYNC(bp));
|
2012-11-12 18:54:01 +07:00
|
|
|
ASSERT(bp->b_iodone == NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
XFS_BUF_READ(bp);
|
2012-11-14 13:54:40 +07:00
|
|
|
bp->b_ops = ops;
|
2005-04-17 05:20:36 +07:00
|
|
|
xfsbdstrat(tp->t_mountp, bp);
|
2010-10-07 01:41:18 +07:00
|
|
|
error = xfs_buf_iowait(bp);
|
2008-04-10 09:22:17 +07:00
|
|
|
if (error) {
|
2011-10-10 23:52:49 +07:00
|
|
|
xfs_buf_ioerror_alert(bp, __func__);
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
/*
|
2008-04-10 09:22:17 +07:00
|
|
|
* We can gracefully recover from most read
|
|
|
|
* errors. Ones we can't are those that happen
|
|
|
|
* after the transaction's already dirty.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
if (tp->t_flags & XFS_TRANS_DIRTY)
|
|
|
|
xfs_force_shutdown(tp->t_mountp,
|
2006-06-09 11:58:38 +07:00
|
|
|
SHUTDOWN_META_IO_ERROR);
|
2005-04-17 05:20:36 +07:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We never locked this buf ourselves, so we shouldn't
|
|
|
|
* brelse it either. Just get out.
|
|
|
|
*/
|
|
|
|
if (XFS_FORCED_SHUTDOWN(mp)) {
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
|
2005-04-17 05:20:36 +07:00
|
|
|
*bpp = NULL;
|
|
|
|
return XFS_ERROR(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
bip->bli_recur++;
|
|
|
|
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_read_buf_recur(bip);
|
2005-04-17 05:20:36 +07:00
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-14 13:54:40 +07:00
|
|
|
bp = xfs_buf_read_map(target, map, nmaps, flags, ops);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (bp == NULL) {
|
|
|
|
*bpp = NULL;
|
2011-03-26 05:14:44 +07:00
|
|
|
return (flags & XBF_TRYLOCK) ?
|
|
|
|
0 : XFS_ERROR(ENOMEM);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2011-07-23 06:39:51 +07:00
|
|
|
if (bp->b_error) {
|
|
|
|
error = bp->b_error;
|
2011-10-10 23:52:46 +07:00
|
|
|
xfs_buf_stale(bp);
|
|
|
|
XFS_BUF_DONE(bp);
|
2011-10-10 23:52:49 +07:00
|
|
|
xfs_buf_ioerror_alert(bp, __func__);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (tp->t_flags & XFS_TRANS_DIRTY)
|
2006-06-09 11:58:38 +07:00
|
|
|
xfs_force_shutdown(tp->t_mountp, SHUTDOWN_META_IO_ERROR);
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
if (xfs_do_error && !(tp->t_flags & XFS_TRANS_DIRTY)) {
|
|
|
|
if (xfs_error_target == target) {
|
|
|
|
if (((xfs_req_num++) % xfs_error_mod) == 0) {
|
|
|
|
xfs_force_shutdown(tp->t_mountp,
|
2006-06-09 11:58:38 +07:00
|
|
|
SHUTDOWN_META_IO_ERROR);
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
2011-03-07 06:08:35 +07:00
|
|
|
xfs_debug(mp, "Returning trans error!");
|
2005-04-17 05:20:36 +07:00
|
|
|
return XFS_ERROR(EIO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (XFS_FORCED_SHUTDOWN(mp))
|
|
|
|
goto shutdown_abort;
|
|
|
|
|
2010-02-16 06:35:09 +07:00
|
|
|
_xfs_trans_bjoin(tp, bp, 1);
|
|
|
|
trace_xfs_trans_read_buf(bp->b_fspriv);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
*bpp = bp;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
shutdown_abort:
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_read_buf_shut(bp, _RET_IP_);
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
*bpp = NULL;
|
|
|
|
return XFS_ERROR(EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the buffer bp which was previously acquired with one of the
|
|
|
|
* xfs_trans_... buffer allocation routines if the buffer has not
|
|
|
|
* been modified within this transaction. If the buffer is modified
|
|
|
|
* within this transaction, do 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.
|
|
|
|
*
|
|
|
|
* If the buffer is to be released and it was not modified before
|
|
|
|
* this transaction began, then free the buf_log_item associated with it.
|
|
|
|
*
|
|
|
|
* If the transaction pointer is NULL, make this just a normal
|
|
|
|
* brelse() call.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_brelse(xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
|
|
|
xfs_buf_log_item_t *bip;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default to a normal brelse() call if the tp is NULL.
|
|
|
|
*/
|
|
|
|
if (tp == NULL) {
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(bip->bli_item.li_type == XFS_LI_BUF);
|
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 06:18:03 +07:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_brelse(bip);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* If the release is just for a recursive lock,
|
|
|
|
* then decrement the count and return.
|
|
|
|
*/
|
|
|
|
if (bip->bli_recur > 0) {
|
|
|
|
bip->bli_recur--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the buffer is dirty within this transaction, we can't
|
|
|
|
* release it until we commit.
|
|
|
|
*/
|
2010-06-23 15:11:15 +07:00
|
|
|
if (bip->bli_item.li_desc->lid_flags & XFS_LID_DIRTY)
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the buffer has been invalidated, then we can't release
|
|
|
|
* it until the transaction commits to disk unless it is re-dirtied
|
|
|
|
* as part of this transaction. This prevents us from pulling
|
|
|
|
* the item from the AIL before we should.
|
|
|
|
*/
|
2009-12-15 06:14:59 +07:00
|
|
|
if (bip->bli_flags & XFS_BLI_STALE)
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
|
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_LOGGED));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free up the log item descriptor tracking the released item.
|
|
|
|
*/
|
2010-06-23 15:11:15 +07:00
|
|
|
xfs_trans_del_item(&bip->bli_item);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear the hold flag in the buf log item if it is set.
|
|
|
|
* We wouldn't want the next user of the buffer to
|
|
|
|
* get confused.
|
|
|
|
*/
|
|
|
|
if (bip->bli_flags & XFS_BLI_HOLD) {
|
|
|
|
bip->bli_flags &= ~XFS_BLI_HOLD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Drop our reference to the buf log item.
|
|
|
|
*/
|
|
|
|
atomic_dec(&bip->bli_refcount);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the buf item is not tracking data in the log, then
|
|
|
|
* we must free it before releasing the buffer back to the
|
|
|
|
* free pool. Before releasing the buffer to the free pool,
|
|
|
|
* clear the transaction pointer in b_fsprivate2 to dissolve
|
|
|
|
* its relation to this transaction.
|
|
|
|
*/
|
|
|
|
if (!xfs_buf_item_dirty(bip)) {
|
|
|
|
/***
|
|
|
|
ASSERT(bp->b_pincount == 0);
|
|
|
|
***/
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) == 0);
|
|
|
|
ASSERT(!(bip->bli_item.li_flags & XFS_LI_IN_AIL));
|
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF));
|
|
|
|
xfs_buf_item_relse(bp);
|
|
|
|
}
|
|
|
|
|
2012-02-20 09:31:22 +07:00
|
|
|
bp->b_transp = NULL;
|
2005-04-17 05:20:36 +07:00
|
|
|
xfs_buf_relse(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the buffer as not needing to be unlocked when the buf item's
|
|
|
|
* IOP_UNLOCK() routine is called. The buffer must already be locked
|
|
|
|
* and associated with the given transaction.
|
|
|
|
*/
|
|
|
|
/* ARGSUSED */
|
|
|
|
void
|
|
|
|
xfs_trans_bhold(xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 06:18:03 +07:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
2011-07-13 18:43:49 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
bip->bli_flags |= XFS_BLI_HOLD;
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_bhold(bip);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-09-05 05:29:01 +07:00
|
|
|
/*
|
|
|
|
* Cancel the previous buffer hold request made on this buffer
|
|
|
|
* for this transaction.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_bhold_release(xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2005-09-05 05:29:01 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2005-09-05 05:29:01 +07:00
|
|
|
ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
|
2012-12-05 06:18:03 +07:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_CANCEL));
|
2005-09-05 05:29:01 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
ASSERT(bip->bli_flags & XFS_BLI_HOLD);
|
2009-12-15 06:14:59 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
bip->bli_flags &= ~XFS_BLI_HOLD;
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_bhold_release(bip);
|
2005-09-05 05:29:01 +07:00
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07: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(xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp,
|
|
|
|
uint first,
|
|
|
|
uint last)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2012-04-23 12:58:52 +07:00
|
|
|
ASSERT(first <= last && last < BBTOB(bp->b_length));
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_iodone == NULL ||
|
|
|
|
bp->b_iodone == xfs_buf_iodone_callbacks);
|
2005-04-17 05:20:36 +07: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
|
|
|
|
* to disk. See xfs_buf_attach_iodone() for more details
|
|
|
|
* on li_cb and xfs_buf_iodone_callbacks().
|
|
|
|
* If we end up aborting this transaction, we trap this buffer
|
|
|
|
* inside the b_bdstrat callback so that this won't get written to
|
|
|
|
* disk.
|
|
|
|
*/
|
|
|
|
XFS_BUF_DONE(bp);
|
|
|
|
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
2011-07-13 18:43:49 +07:00
|
|
|
bp->b_iodone = xfs_buf_iodone_callbacks;
|
2010-06-23 15:11:15 +07:00
|
|
|
bip->bli_item.li_cb = xfs_buf_iodone;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_log_buf(bip);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
ASSERT(XFS_BUF_ISSTALE(bp));
|
|
|
|
XFS_BUF_UNSTALE(bp);
|
2012-12-05 06:18:03 +07:00
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLF_CANCEL;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
tp->t_flags |= XFS_TRANS_DIRTY;
|
2010-06-23 15:11:15 +07:00
|
|
|
bip->bli_item.li_desc->lid_flags |= XFS_LID_DIRTY;
|
2005-04-17 05:20:36 +07:00
|
|
|
bip->bli_flags |= XFS_BLI_LOGGED;
|
|
|
|
xfs_buf_item_log(bip, first, last);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
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 12:58:39 +07: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 05:20:36 +07: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 12:58:39 +07: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 05:20:36 +07:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_binval(
|
|
|
|
xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2012-12-05 06:18:05 +07:00
|
|
|
int i;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
2009-12-15 06:14:59 +07:00
|
|
|
trace_xfs_trans_binval(bip);
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
if (bip->bli_flags & XFS_BLI_STALE) {
|
|
|
|
/*
|
|
|
|
* If the buffer is already invalidated, then
|
|
|
|
* just return.
|
|
|
|
*/
|
|
|
|
ASSERT(XFS_BUF_ISSTALE(bp));
|
|
|
|
ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
|
2012-12-05 06:18:03 +07:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_INODE_BUF));
|
2013-04-22 02:53:46 +07:00
|
|
|
ASSERT(!(bip->__bli_format.blf_flags & XFS_BLF_TYPE_MASK));
|
2012-12-05 06:18:03 +07:00
|
|
|
ASSERT(bip->__bli_format.blf_flags & XFS_BLF_CANCEL);
|
2010-06-23 15:11:15 +07:00
|
|
|
ASSERT(bip->bli_item.li_desc->lid_flags & XFS_LID_DIRTY);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-10 23:52:46 +07: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 12:58:39 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
bip->bli_flags |= XFS_BLI_STALE;
|
2010-05-20 20:19:42 +07:00
|
|
|
bip->bli_flags &= ~(XFS_BLI_INODE_BUF | XFS_BLI_LOGGED | XFS_BLI_DIRTY);
|
2012-12-05 06:18:03 +07:00
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLF_INODE_BUF;
|
|
|
|
bip->__bli_format.blf_flags |= XFS_BLF_CANCEL;
|
2013-04-22 02:53:46 +07:00
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLF_TYPE_MASK;
|
2012-12-05 06:18:05 +07: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)));
|
|
|
|
}
|
2010-06-23 15:11:15 +07:00
|
|
|
bip->bli_item.li_desc->lid_flags |= XFS_LID_DIRTY;
|
2005-04-17 05:20:36 +07:00
|
|
|
tp->t_flags |= XFS_TRANS_DIRTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-05-20 20:19:42 +07: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 05:20:36 +07:00
|
|
|
*
|
2010-05-20 20:19:42 +07: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 05:20:36 +07:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
xfs_trans_inode_buf(
|
|
|
|
xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
2010-05-20 20:19:42 +07:00
|
|
|
bip->bli_flags |= XFS_BLI_INODE_BUF;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This call is used to indicate that the buffer is going to
|
|
|
|
* be staled and was an inode buffer. This means it gets
|
|
|
|
* special processing during unpin - where any inodes
|
|
|
|
* 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(
|
|
|
|
xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
|
|
|
bip->bli_flags |= XFS_BLI_STALE_INODE;
|
2010-06-23 15:11:15 +07:00
|
|
|
bip->bli_item.li_cb = xfs_buf_iodone;
|
2005-04-17 05:20:36 +07: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(
|
|
|
|
xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp)
|
|
|
|
{
|
2011-07-13 18:43:49 +07:00
|
|
|
xfs_buf_log_item_t *bip = bp->b_fspriv;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bp->b_transp == tp);
|
2011-07-13 18:43:49 +07:00
|
|
|
ASSERT(bip != NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
|
|
|
|
bip->bli_flags |= XFS_BLI_INODE_ALLOC_BUF;
|
|
|
|
}
|
|
|
|
|
2013-04-22 02:53:46 +07: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,
|
|
|
|
uint type)
|
|
|
|
{
|
|
|
|
struct xfs_buf_log_item *bip = bp->b_fspriv;
|
|
|
|
|
|
|
|
ASSERT(bp->b_transp == tp);
|
|
|
|
ASSERT(bip != NULL);
|
|
|
|
ASSERT(atomic_read(&bip->bli_refcount) > 0);
|
|
|
|
ASSERT((type & XFS_BLF_TYPE_MASK) != 0);
|
|
|
|
|
|
|
|
bip->__bli_format.blf_flags &= ~XFS_BLF_TYPE_MASK;
|
|
|
|
bip->__bli_format.blf_flags |= type;
|
|
|
|
}
|
2005-04-17 05:20:36 +07: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(
|
|
|
|
xfs_trans_t *tp,
|
|
|
|
xfs_buf_t *bp,
|
|
|
|
uint type)
|
|
|
|
{
|
2010-05-07 08:05:19 +07:00
|
|
|
ASSERT(type == XFS_BLF_UDQUOT_BUF ||
|
|
|
|
type == XFS_BLF_PDQUOT_BUF ||
|
|
|
|
type == XFS_BLF_GDQUOT_BUF);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-04-22 02:53:46 +07:00
|
|
|
xfs_trans_buf_set_type(tp, bp, type);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|