Skip to content

Commit

Permalink
xfs: move ->iop_relog to struct xfs_defer_op_type
Browse files Browse the repository at this point in the history
The only log items that need relogging are the ones created for deferred
work operations, and the only part of the code base that relogs log
items is the deferred work machinery.  Move the function pointers.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
  • Loading branch information
Darrick J. Wong committed Dec 7, 2023
1 parent 8a9aa76 commit a49c708
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 119 deletions.
31 changes: 20 additions & 11 deletions fs/xfs/libxfs/xfs_defer.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,25 @@ xfs_defer_cancel_list(
xfs_defer_pending_cancel_work(mp, dfp);
}

static inline void
xfs_defer_relog_intent(
struct xfs_trans *tp,
struct xfs_defer_pending *dfp)
{
struct xfs_log_item *lip;
const struct xfs_defer_op_type *ops = defer_op_types[dfp->dfp_type];

xfs_defer_create_done(tp, dfp);

lip = ops->relog_intent(tp, dfp->dfp_intent, dfp->dfp_done);
if (lip) {
xfs_trans_add_item(tp, lip);
set_bit(XFS_LI_DIRTY, &lip->li_flags);
}
dfp->dfp_done = NULL;
dfp->dfp_intent = lip;
}

/*
* Prevent a log intent item from pinning the tail of the log by logging a
* done item to release the intent item; and then log a new intent item.
Expand All @@ -477,8 +496,6 @@ xfs_defer_relog(
ASSERT((*tpp)->t_flags & XFS_TRANS_PERM_LOG_RES);

list_for_each_entry(dfp, dfops, dfp_list) {
struct xfs_log_item *lip;

/*
* If the log intent item for this deferred op is not a part of
* the current log checkpoint, relog the intent item to keep
Expand Down Expand Up @@ -506,15 +523,7 @@ xfs_defer_relog(
trace_xfs_defer_relog_intent((*tpp)->t_mountp, dfp);
XFS_STATS_INC((*tpp)->t_mountp, defer_relog);

xfs_defer_create_done(*tpp, dfp);
lip = xfs_trans_item_relog(dfp->dfp_intent, dfp->dfp_done,
*tpp);
if (lip) {
xfs_trans_add_item(*tpp, lip);
set_bit(XFS_LI_DIRTY, &lip->li_flags);
}
dfp->dfp_done = NULL;
dfp->dfp_intent = lip;
xfs_defer_relog_intent(*tpp, dfp);
}

if ((*tpp)->t_flags & XFS_TRANS_DIRTY)
Expand Down
3 changes: 3 additions & 0 deletions fs/xfs/libxfs/xfs_defer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ struct xfs_defer_op_type {
void (*cancel_item)(struct list_head *item);
int (*recover_work)(struct xfs_defer_pending *dfp,
struct list_head *capture_list);
struct xfs_log_item *(*relog_intent)(struct xfs_trans *tp,
struct xfs_log_item *intent,
struct xfs_log_item *done_item);
unsigned int max_items;
};

Expand Down
8 changes: 4 additions & 4 deletions fs/xfs/xfs_attr_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,10 +625,10 @@ xfs_attr_recover_work(

/* Re-log an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_attri_item_relog(
xfs_attr_relog_intent(
struct xfs_trans *tp,
struct xfs_log_item *intent,
struct xfs_log_item *done_item,
struct xfs_trans *tp)
struct xfs_log_item *done_item)
{
struct xfs_attri_log_item *old_attrip;
struct xfs_attri_log_item *new_attrip;
Expand Down Expand Up @@ -763,6 +763,7 @@ const struct xfs_defer_op_type xfs_attr_defer_type = {
.finish_item = xfs_attr_finish_item,
.cancel_item = xfs_attr_cancel_item,
.recover_work = xfs_attr_recover_work,
.relog_intent = xfs_attr_relog_intent,
};

/*
Expand Down Expand Up @@ -800,7 +801,6 @@ static const struct xfs_item_ops xfs_attri_item_ops = {
.iop_unpin = xfs_attri_item_unpin,
.iop_release = xfs_attri_item_release,
.iop_match = xfs_attri_item_match,
.iop_relog = xfs_attri_item_relog,
};

const struct xlog_recover_item_ops xlog_attri_item_ops = {
Expand Down
44 changes: 22 additions & 22 deletions fs/xfs/xfs_bmap_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,30 +541,12 @@ xfs_bmap_recover_work(
return error;
}

const struct xfs_defer_op_type xfs_bmap_update_defer_type = {
.max_items = XFS_BUI_MAX_FAST_EXTENTS,
.create_intent = xfs_bmap_update_create_intent,
.abort_intent = xfs_bmap_update_abort_intent,
.create_done = xfs_bmap_update_create_done,
.finish_item = xfs_bmap_update_finish_item,
.cancel_item = xfs_bmap_update_cancel_item,
.recover_work = xfs_bmap_recover_work,
};

STATIC bool
xfs_bui_item_match(
struct xfs_log_item *lip,
uint64_t intent_id)
{
return BUI_ITEM(lip)->bui_format.bui_id == intent_id;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_bui_item_relog(
xfs_bmap_relog_intent(
struct xfs_trans *tp,
struct xfs_log_item *intent,
struct xfs_log_item *done_item,
struct xfs_trans *tp)
struct xfs_log_item *done_item)
{
struct xfs_bui_log_item *buip;
struct xfs_map_extent *map;
Expand All @@ -580,14 +562,32 @@ xfs_bui_item_relog(
return &buip->bui_item;
}

const struct xfs_defer_op_type xfs_bmap_update_defer_type = {
.max_items = XFS_BUI_MAX_FAST_EXTENTS,
.create_intent = xfs_bmap_update_create_intent,
.abort_intent = xfs_bmap_update_abort_intent,
.create_done = xfs_bmap_update_create_done,
.finish_item = xfs_bmap_update_finish_item,
.cancel_item = xfs_bmap_update_cancel_item,
.recover_work = xfs_bmap_recover_work,
.relog_intent = xfs_bmap_relog_intent,
};

STATIC bool
xfs_bui_item_match(
struct xfs_log_item *lip,
uint64_t intent_id)
{
return BUI_ITEM(lip)->bui_format.bui_id == intent_id;
}

static const struct xfs_item_ops xfs_bui_item_ops = {
.flags = XFS_ITEM_INTENT,
.iop_size = xfs_bui_item_size,
.iop_format = xfs_bui_item_format,
.iop_unpin = xfs_bui_item_unpin,
.iop_release = xfs_bui_item_release,
.iop_match = xfs_bui_item_match,
.iop_relog = xfs_bui_item_relog,
};

static inline void
Expand Down
53 changes: 27 additions & 26 deletions fs/xfs/xfs_extfree_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,31 @@ xfs_extent_free_recover_work(
return error;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_extent_free_relog_intent(
struct xfs_trans *tp,
struct xfs_log_item *intent,
struct xfs_log_item *done_item)
{
struct xfs_efd_log_item *efdp = EFD_ITEM(done_item);
struct xfs_efi_log_item *efip;
struct xfs_extent *extp;
unsigned int count;

count = EFI_ITEM(intent)->efi_format.efi_nextents;
extp = EFI_ITEM(intent)->efi_format.efi_extents;

efdp->efd_next_extent = count;
memcpy(efdp->efd_format.efd_extents, extp, count * sizeof(*extp));

efip = xfs_efi_init(tp->t_mountp, count);
memcpy(efip->efi_format.efi_extents, extp, count * sizeof(*extp));
atomic_set(&efip->efi_next_extent, count);

return &efip->efi_item;
}

const struct xfs_defer_op_type xfs_extent_free_defer_type = {
.max_items = XFS_EFI_MAX_FAST_EXTENTS,
.create_intent = xfs_extent_free_create_intent,
Expand All @@ -651,6 +676,7 @@ const struct xfs_defer_op_type xfs_extent_free_defer_type = {
.finish_item = xfs_extent_free_finish_item,
.cancel_item = xfs_extent_free_cancel_item,
.recover_work = xfs_extent_free_recover_work,
.relog_intent = xfs_extent_free_relog_intent,
};

/* sub-type with special handling for AGFL deferred frees */
Expand All @@ -662,6 +688,7 @@ const struct xfs_defer_op_type xfs_agfl_free_defer_type = {
.finish_item = xfs_agfl_free_finish_item,
.cancel_item = xfs_extent_free_cancel_item,
.recover_work = xfs_extent_free_recover_work,
.relog_intent = xfs_extent_free_relog_intent,
};

STATIC bool
Expand All @@ -672,39 +699,13 @@ xfs_efi_item_match(
return EFI_ITEM(lip)->efi_format.efi_id == intent_id;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_efi_item_relog(
struct xfs_log_item *intent,
struct xfs_log_item *done_item,
struct xfs_trans *tp)
{
struct xfs_efd_log_item *efdp = EFD_ITEM(done_item);
struct xfs_efi_log_item *efip;
struct xfs_extent *extp;
unsigned int count;

count = EFI_ITEM(intent)->efi_format.efi_nextents;
extp = EFI_ITEM(intent)->efi_format.efi_extents;

efdp->efd_next_extent = count;
memcpy(efdp->efd_format.efd_extents, extp, count * sizeof(*extp));

efip = xfs_efi_init(tp->t_mountp, count);
memcpy(efip->efi_format.efi_extents, extp, count * sizeof(*extp));
atomic_set(&efip->efi_next_extent, count);

return &efip->efi_item;
}

static const struct xfs_item_ops xfs_efi_item_ops = {
.flags = XFS_ITEM_INTENT,
.iop_size = xfs_efi_item_size,
.iop_format = xfs_efi_item_format,
.iop_unpin = xfs_efi_item_unpin,
.iop_release = xfs_efi_item_release,
.iop_match = xfs_efi_item_match,
.iop_relog = xfs_efi_item_relog,
};

/*
Expand Down
44 changes: 22 additions & 22 deletions fs/xfs/xfs_refcount_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,27 @@ xfs_refcount_recover_work(
return error;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_refcount_relog_intent(
struct xfs_trans *tp,
struct xfs_log_item *intent,
struct xfs_log_item *done_item)
{
struct xfs_cui_log_item *cuip;
struct xfs_phys_extent *pmap;
unsigned int count;

count = CUI_ITEM(intent)->cui_format.cui_nextents;
pmap = CUI_ITEM(intent)->cui_format.cui_extents;

cuip = xfs_cui_init(tp->t_mountp, count);
memcpy(cuip->cui_format.cui_extents, pmap, count * sizeof(*pmap));
atomic_set(&cuip->cui_next_extent, count);

return &cuip->cui_item;
}

const struct xfs_defer_op_type xfs_refcount_update_defer_type = {
.max_items = XFS_CUI_MAX_FAST_EXTENTS,
.create_intent = xfs_refcount_update_create_intent,
Expand All @@ -510,6 +531,7 @@ const struct xfs_defer_op_type xfs_refcount_update_defer_type = {
.finish_cleanup = xfs_refcount_finish_one_cleanup,
.cancel_item = xfs_refcount_update_cancel_item,
.recover_work = xfs_refcount_recover_work,
.relog_intent = xfs_refcount_relog_intent,
};

STATIC bool
Expand All @@ -520,35 +542,13 @@ xfs_cui_item_match(
return CUI_ITEM(lip)->cui_format.cui_id == intent_id;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_cui_item_relog(
struct xfs_log_item *intent,
struct xfs_log_item *done_item,
struct xfs_trans *tp)
{
struct xfs_cui_log_item *cuip;
struct xfs_phys_extent *pmap;
unsigned int count;

count = CUI_ITEM(intent)->cui_format.cui_nextents;
pmap = CUI_ITEM(intent)->cui_format.cui_extents;

cuip = xfs_cui_init(tp->t_mountp, count);
memcpy(cuip->cui_format.cui_extents, pmap, count * sizeof(*pmap));
atomic_set(&cuip->cui_next_extent, count);

return &cuip->cui_item;
}

static const struct xfs_item_ops xfs_cui_item_ops = {
.flags = XFS_ITEM_INTENT,
.iop_size = xfs_cui_item_size,
.iop_format = xfs_cui_item_format,
.iop_unpin = xfs_cui_item_unpin,
.iop_release = xfs_cui_item_release,
.iop_match = xfs_cui_item_match,
.iop_relog = xfs_cui_item_relog,
};

static inline void
Expand Down
44 changes: 22 additions & 22 deletions fs/xfs/xfs_rmap_item.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,27 @@ xfs_rmap_recover_work(
return error;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_rmap_relog_intent(
struct xfs_trans *tp,
struct xfs_log_item *intent,
struct xfs_log_item *done_item)
{
struct xfs_rui_log_item *ruip;
struct xfs_map_extent *map;
unsigned int count;

count = RUI_ITEM(intent)->rui_format.rui_nextents;
map = RUI_ITEM(intent)->rui_format.rui_extents;

ruip = xfs_rui_init(tp->t_mountp, count);
memcpy(ruip->rui_format.rui_extents, map, count * sizeof(*map));
atomic_set(&ruip->rui_next_extent, count);

return &ruip->rui_item;
}

const struct xfs_defer_op_type xfs_rmap_update_defer_type = {
.max_items = XFS_RUI_MAX_FAST_EXTENTS,
.create_intent = xfs_rmap_update_create_intent,
Expand All @@ -563,6 +584,7 @@ const struct xfs_defer_op_type xfs_rmap_update_defer_type = {
.finish_cleanup = xfs_rmap_finish_one_cleanup,
.cancel_item = xfs_rmap_update_cancel_item,
.recover_work = xfs_rmap_recover_work,
.relog_intent = xfs_rmap_relog_intent,
};

STATIC bool
Expand All @@ -573,35 +595,13 @@ xfs_rui_item_match(
return RUI_ITEM(lip)->rui_format.rui_id == intent_id;
}

/* Relog an intent item to push the log tail forward. */
static struct xfs_log_item *
xfs_rui_item_relog(
struct xfs_log_item *intent,
struct xfs_log_item *done_item,
struct xfs_trans *tp)
{
struct xfs_rui_log_item *ruip;
struct xfs_map_extent *map;
unsigned int count;

count = RUI_ITEM(intent)->rui_format.rui_nextents;
map = RUI_ITEM(intent)->rui_format.rui_extents;

ruip = xfs_rui_init(tp->t_mountp, count);
memcpy(ruip->rui_format.rui_extents, map, count * sizeof(*map));
atomic_set(&ruip->rui_next_extent, count);

return &ruip->rui_item;
}

static const struct xfs_item_ops xfs_rui_item_ops = {
.flags = XFS_ITEM_INTENT,
.iop_size = xfs_rui_item_size,
.iop_format = xfs_rui_item_format,
.iop_unpin = xfs_rui_item_unpin,
.iop_release = xfs_rui_item_release,
.iop_match = xfs_rui_item_match,
.iop_relog = xfs_rui_item_relog,
};

static inline void
Expand Down
Loading

0 comments on commit a49c708

Please sign in to comment.