xfs: refactor log recovery RUI item dispatch for pass2 commit functions

Move the rmap update intent and intent-done pass2 commit code into the
per-item source code files and use dispatch functions to call them.  We
do these one at a time because there's a lot of code to move.  No
functional changes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Darrick J. Wong 2020-05-01 16:00:49 -07:00
parent 9817aa80dc
commit 07590a9d38
3 changed files with 101 additions and 104 deletions

View File

@ -2034,99 +2034,6 @@ xlog_buf_readahead(
xfs_buf_readahead(log->l_mp->m_ddev_targp, blkno, len, ops);
}
/*
* This routine is called to create an in-core extent rmap update
* item from the rui format structure which was logged on disk.
* It allocates an in-core rui, copies the extents from the format
* structure into it, and adds the rui to the AIL with the given
* LSN.
*/
STATIC int
xlog_recover_rui_pass2(
struct xlog *log,
struct xlog_recover_item *item,
xfs_lsn_t lsn)
{
int error;
struct xfs_mount *mp = log->l_mp;
struct xfs_rui_log_item *ruip;
struct xfs_rui_log_format *rui_formatp;
rui_formatp = item->ri_buf[0].i_addr;
ruip = xfs_rui_init(mp, rui_formatp->rui_nextents);
error = xfs_rui_copy_format(&item->ri_buf[0], &ruip->rui_format);
if (error) {
xfs_rui_item_free(ruip);
return error;
}
atomic_set(&ruip->rui_next_extent, rui_formatp->rui_nextents);
spin_lock(&log->l_ailp->ail_lock);
/*
* The RUI has two references. One for the RUD and one for RUI to ensure
* it makes it into the AIL. Insert the RUI into the AIL directly and
* drop the RUI reference. Note that xfs_trans_ail_update() drops the
* AIL lock.
*/
xfs_trans_ail_update(log->l_ailp, &ruip->rui_item, lsn);
xfs_rui_release(ruip);
return 0;
}
/*
* This routine is called when an RUD format structure is found in a committed
* transaction in the log. Its purpose is to cancel the corresponding RUI if it
* was still in the log. To do this it searches the AIL for the RUI with an id
* equal to that in the RUD format structure. If we find it we drop the RUD
* reference, which removes the RUI from the AIL and frees it.
*/
STATIC int
xlog_recover_rud_pass2(
struct xlog *log,
struct xlog_recover_item *item)
{
struct xfs_rud_log_format *rud_formatp;
struct xfs_rui_log_item *ruip = NULL;
struct xfs_log_item *lip;
uint64_t rui_id;
struct xfs_ail_cursor cur;
struct xfs_ail *ailp = log->l_ailp;
rud_formatp = item->ri_buf[0].i_addr;
ASSERT(item->ri_buf[0].i_len == sizeof(struct xfs_rud_log_format));
rui_id = rud_formatp->rud_rui_id;
/*
* Search for the RUI with the id in the RUD format structure in the
* AIL.
*/
spin_lock(&ailp->ail_lock);
lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
while (lip != NULL) {
if (lip->li_type == XFS_LI_RUI) {
ruip = (struct xfs_rui_log_item *)lip;
if (ruip->rui_format.rui_id == rui_id) {
/*
* Drop the RUD reference to the RUI. This
* removes the RUI from the AIL and frees it.
*/
spin_unlock(&ailp->ail_lock);
xfs_rui_release(ruip);
spin_lock(&ailp->ail_lock);
break;
}
}
lip = xfs_trans_ail_cursor_next(ailp, &cur);
}
xfs_trans_ail_cursor_done(&cur);
spin_unlock(&ailp->ail_lock);
return 0;
}
/*
* Copy an CUI format buffer from the given buf, and into the destination
* CUI format structure. The CUI/CUD items were designed not to need any
@ -2385,10 +2292,6 @@ xlog_recover_commit_pass2(
trans->r_lsn);
switch (ITEM_TYPE(item)) {
case XFS_LI_RUI:
return xlog_recover_rui_pass2(log, item, trans->r_lsn);
case XFS_LI_RUD:
return xlog_recover_rud_pass2(log, item);
case XFS_LI_CUI:
return xlog_recover_cui_pass2(log, item, trans->r_lsn);
case XFS_LI_CUD:

View File

@ -18,6 +18,7 @@
#include "xfs_log.h"
#include "xfs_rmap.h"
#include "xfs_error.h"
#include "xfs_log_priv.h"
#include "xfs_log_recover.h"
kmem_zone_t *xfs_rui_zone;
@ -28,7 +29,7 @@ static inline struct xfs_rui_log_item *RUI_ITEM(struct xfs_log_item *lip)
return container_of(lip, struct xfs_rui_log_item, rui_item);
}
void
STATIC void
xfs_rui_item_free(
struct xfs_rui_log_item *ruip)
{
@ -133,7 +134,7 @@ static const struct xfs_item_ops xfs_rui_item_ops = {
/*
* Allocate and initialize an rui item with the given number of extents.
*/
struct xfs_rui_log_item *
STATIC struct xfs_rui_log_item *
xfs_rui_init(
struct xfs_mount *mp,
uint nextents)
@ -161,7 +162,7 @@ xfs_rui_init(
* RUI format structure. The RUI/RUD items were designed not to need any
* special alignment handling.
*/
int
STATIC int
xfs_rui_copy_format(
struct xfs_log_iovec *buf,
struct xfs_rui_log_format *dst_rui_fmt)
@ -587,10 +588,107 @@ abort_error:
return error;
}
/*
* This routine is called to create an in-core extent rmap update
* item from the rui format structure which was logged on disk.
* It allocates an in-core rui, copies the extents from the format
* structure into it, and adds the rui to the AIL with the given
* LSN.
*/
STATIC int
xlog_recover_rui_commit_pass2(
struct xlog *log,
struct list_head *buffer_list,
struct xlog_recover_item *item,
xfs_lsn_t lsn)
{
int error;
struct xfs_mount *mp = log->l_mp;
struct xfs_rui_log_item *ruip;
struct xfs_rui_log_format *rui_formatp;
rui_formatp = item->ri_buf[0].i_addr;
ruip = xfs_rui_init(mp, rui_formatp->rui_nextents);
error = xfs_rui_copy_format(&item->ri_buf[0], &ruip->rui_format);
if (error) {
xfs_rui_item_free(ruip);
return error;
}
atomic_set(&ruip->rui_next_extent, rui_formatp->rui_nextents);
spin_lock(&log->l_ailp->ail_lock);
/*
* The RUI has two references. One for the RUD and one for RUI to ensure
* it makes it into the AIL. Insert the RUI into the AIL directly and
* drop the RUI reference. Note that xfs_trans_ail_update() drops the
* AIL lock.
*/
xfs_trans_ail_update(log->l_ailp, &ruip->rui_item, lsn);
xfs_rui_release(ruip);
return 0;
}
const struct xlog_recover_item_ops xlog_rui_item_ops = {
.item_type = XFS_LI_RUI,
.commit_pass2 = xlog_recover_rui_commit_pass2,
};
/*
* This routine is called when an RUD format structure is found in a committed
* transaction in the log. Its purpose is to cancel the corresponding RUI if it
* was still in the log. To do this it searches the AIL for the RUI with an id
* equal to that in the RUD format structure. If we find it we drop the RUD
* reference, which removes the RUI from the AIL and frees it.
*/
STATIC int
xlog_recover_rud_commit_pass2(
struct xlog *log,
struct list_head *buffer_list,
struct xlog_recover_item *item,
xfs_lsn_t lsn)
{
struct xfs_rud_log_format *rud_formatp;
struct xfs_rui_log_item *ruip = NULL;
struct xfs_log_item *lip;
uint64_t rui_id;
struct xfs_ail_cursor cur;
struct xfs_ail *ailp = log->l_ailp;
rud_formatp = item->ri_buf[0].i_addr;
ASSERT(item->ri_buf[0].i_len == sizeof(struct xfs_rud_log_format));
rui_id = rud_formatp->rud_rui_id;
/*
* Search for the RUI with the id in the RUD format structure in the
* AIL.
*/
spin_lock(&ailp->ail_lock);
lip = xfs_trans_ail_cursor_first(ailp, &cur, 0);
while (lip != NULL) {
if (lip->li_type == XFS_LI_RUI) {
ruip = (struct xfs_rui_log_item *)lip;
if (ruip->rui_format.rui_id == rui_id) {
/*
* Drop the RUD reference to the RUI. This
* removes the RUI from the AIL and frees it.
*/
spin_unlock(&ailp->ail_lock);
xfs_rui_release(ruip);
spin_lock(&ailp->ail_lock);
break;
}
}
lip = xfs_trans_ail_cursor_next(ailp, &cur);
}
xfs_trans_ail_cursor_done(&cur);
spin_unlock(&ailp->ail_lock);
return 0;
}
const struct xlog_recover_item_ops xlog_rud_item_ops = {
.item_type = XFS_LI_RUD,
.commit_pass2 = xlog_recover_rud_commit_pass2,
};

View File

@ -77,10 +77,6 @@ struct xfs_rud_log_item {
extern struct kmem_zone *xfs_rui_zone;
extern struct kmem_zone *xfs_rud_zone;
struct xfs_rui_log_item *xfs_rui_init(struct xfs_mount *, uint);
int xfs_rui_copy_format(struct xfs_log_iovec *buf,
struct xfs_rui_log_format *dst_rui_fmt);
void xfs_rui_item_free(struct xfs_rui_log_item *);
void xfs_rui_release(struct xfs_rui_log_item *);
int xfs_rui_recover(struct xfs_mount *mp, struct xfs_rui_log_item *ruip);