Source
x
* item with the value of @lsn, then it sets the cursor to the last item with an
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
* Copyright (c) 2008 Dave Chinner
* All Rights Reserved.
*/
/*
* Check that the list is sorted as it should be.
*
* Called with the ail lock held, but we don't want to assert fail with it
* held otherwise we'll lock everything up and won't be able to debug the
* cause. Hence we sample and check the state under the AIL lock and return if
* everything is fine, otherwise we drop the lock and run the ASSERT checks.
* Asserts may not be fatal, so pick the lock back up and continue onwards.
*/
STATIC void
xfs_ail_check(
struct xfs_ail *ailp,
struct xfs_log_item *lip)
{
struct xfs_log_item *prev_lip;
struct xfs_log_item *next_lip;
xfs_lsn_t prev_lsn = NULLCOMMITLSN;
xfs_lsn_t next_lsn = NULLCOMMITLSN;
xfs_lsn_t lsn;
bool in_ail;
if (list_empty(&ailp->ail_head))
return;
/*
* Sample then check the next and previous entries are valid.
*/
in_ail = test_bit(XFS_LI_IN_AIL, &lip->li_flags);
prev_lip = list_entry(lip->li_ail.prev, struct xfs_log_item, li_ail);
if (&prev_lip->li_ail != &ailp->ail_head)
prev_lsn = prev_lip->li_lsn;
next_lip = list_entry(lip->li_ail.next, struct xfs_log_item, li_ail);
if (&next_lip->li_ail != &ailp->ail_head)
next_lsn = next_lip->li_lsn;
lsn = lip->li_lsn;
if (in_ail &&
(prev_lsn == NULLCOMMITLSN || XFS_LSN_CMP(prev_lsn, lsn) <= 0) &&
(next_lsn == NULLCOMMITLSN || XFS_LSN_CMP(next_lsn, lsn) >= 0))
return;
spin_unlock(&ailp->ail_lock);
ASSERT(in_ail);
ASSERT(prev_lsn == NULLCOMMITLSN || XFS_LSN_CMP(prev_lsn, lsn) <= 0);
ASSERT(next_lsn == NULLCOMMITLSN || XFS_LSN_CMP(next_lsn, lsn) >= 0);
spin_lock(&ailp->ail_lock);
}
/* !DEBUG */
/* DEBUG */
/*
* Return a pointer to the last item in the AIL. If the AIL is empty, then
* return NULL.
*/
static xfs_log_item_t *
xfs_ail_max(
struct xfs_ail *ailp)
{
if (list_empty(&ailp->ail_head))
return NULL;
return list_entry(ailp->ail_head.prev, xfs_log_item_t, li_ail);
}
/*
* Return a pointer to the item which follows the given item in the AIL. If
* the given item is the last item in the list, then return NULL.
*/
static xfs_log_item_t *
xfs_ail_next(