xfs: automatic dfops inode relogging

Inodes that are held across deferred operations are explicitly
joined to the dfops structure to ensure appropriate relogging.
While inodes are currently joined explicitly, we can detect the
conditions that require relogging at dfops finish time by inspecting
the transaction item list for inodes with ili_lock_flags == 0.

Replace the xfs_defer_ijoin() infrastructure with such detection and
automatic relogging of held inodes. This eliminates the need for the
per-dfops inode list, replaced by an on-stack variant in
xfs_defer_trans_roll().

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
This commit is contained in:
Brian Foster
2018-08-01 07:20:32 -07:00
committed by Darrick J. Wong
parent 82ff27bc52
commit a8198666fb
11 changed files with 21 additions and 75 deletions

View File

@@ -15,6 +15,8 @@
#include "xfs_defer.h"
#include "xfs_trans.h"
#include "xfs_buf_item.h"
#include "xfs_inode.h"
#include "xfs_inode_item.h"
#include "xfs_trace.h"
/*
@@ -230,16 +232,14 @@ xfs_defer_trans_roll(
{
struct xfs_defer_ops *dop = (*tp)->t_dfops;
struct xfs_buf_log_item *bli;
struct xfs_inode_log_item *ili;
struct xfs_log_item *lip;
struct xfs_buf *bplist[XFS_DEFER_OPS_NR_BUFS];
int bpcount = 0;
struct xfs_inode *iplist[XFS_DEFER_OPS_NR_INODES];
int bpcount = 0, ipcount = 0;
int i;
int error;
/* Log all the joined inodes. */
for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
xfs_trans_log_inode(*tp, dop->dop_inodes[i], XFS_ILOG_CORE);
list_for_each_entry(lip, &(*tp)->t_items, li_trans) {
switch (lip->li_type) {
case XFS_LI_BUF:
@@ -254,6 +254,19 @@ xfs_defer_trans_roll(
bplist[bpcount++] = bli->bli_buf;
}
break;
case XFS_LI_INODE:
ili = container_of(lip, struct xfs_inode_log_item,
ili_item);
if (ili->ili_lock_flags == 0) {
if (ipcount >= XFS_DEFER_OPS_NR_INODES) {
ASSERT(0);
return -EFSCORRUPTED;
}
xfs_trans_log_inode(*tp, ili->ili_inode,
XFS_ILOG_CORE);
iplist[ipcount++] = ili->ili_inode;
}
break;
default:
break;
}
@@ -271,8 +284,8 @@ xfs_defer_trans_roll(
}
/* Rejoin the joined inodes. */
for (i = 0; i < XFS_DEFER_OPS_NR_INODES && dop->dop_inodes[i]; i++)
xfs_trans_ijoin(*tp, dop->dop_inodes[i], 0);
for (i = 0; i < ipcount; i++)
xfs_trans_ijoin(*tp, iplist[i], 0);
/* Rejoin the buffers and dirty them so the log moves forward. */
for (i = 0; i < bpcount; i++) {
@@ -291,30 +304,6 @@ xfs_defer_has_unfinished_work(
return !list_empty(&dop->dop_pending) || !list_empty(&dop->dop_intake);
}
/*
* Add this inode to the deferred op. Each joined inode is relogged
* each time we roll the transaction.
*/
int
xfs_defer_ijoin(
struct xfs_defer_ops *dop,
struct xfs_inode *ip)
{
int i;
for (i = 0; i < XFS_DEFER_OPS_NR_INODES; i++) {
if (dop->dop_inodes[i] == ip)
return 0;
else if (dop->dop_inodes[i] == NULL) {
dop->dop_inodes[i] = ip;
return 0;
}
}
ASSERT(0);
return -EFSCORRUPTED;
}
/*
* Reset an already used dfops after finish.
*/
@@ -322,11 +311,7 @@ static void
xfs_defer_reset(
struct xfs_trans *tp)
{
struct xfs_defer_ops *dop = tp->t_dfops;
ASSERT(!xfs_defer_has_unfinished_work(dop));
memset(dop->dop_inodes, 0, sizeof(dop->dop_inodes));
ASSERT(!xfs_defer_has_unfinished_work(tp->t_dfops));
/*
* Low mode state transfers across transaction rolls to mirror dfops
@@ -588,8 +573,6 @@ xfs_defer_move(
list_splice_init(&src->dop_intake, &dst->dop_intake);
list_splice_init(&src->dop_pending, &dst->dop_pending);
memcpy(dst->dop_inodes, src->dop_inodes, sizeof(dst->dop_inodes));
/*
* Low free space mode was historically controlled by a dfops field.
* This meant that low mode state potentially carried across multiple