summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <darrick.wong@oracle.com>2020-10-25 17:15:42 -0700
committerDarrick J. Wong <darrick.wong@oracle.com>2020-10-26 18:32:22 -0700
commita46b8f83632df9026f1545f0cadafddbfe813da6 (patch)
tree92b994231b51dd458b8265681141a8bbe67aebca
parent03cc9d97c7875f30b420b5ca6dc81c9c7b04ea0c (diff)
xfs: support two inodes in the defer capture structure
Make it so that xfs_defer_ops_capture_and_commit can capture two inodes. This will be needed by the atomic extent swap log item so that it can recover an operation involving two inodes. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
-rw-r--r--fs/xfs/libxfs/xfs_defer.c48
-rw-r--r--fs/xfs/libxfs/xfs_defer.h9
-rw-r--r--fs/xfs/xfs_bmap_item.c2
-rw-r--r--fs/xfs/xfs_extfree_item.c2
-rw-r--r--fs/xfs/xfs_log_recover.c14
-rw-r--r--fs/xfs/xfs_refcount_item.c2
-rw-r--r--fs/xfs/xfs_rmap_item.c2
7 files changed, 52 insertions, 27 deletions
diff --git a/fs/xfs/libxfs/xfs_defer.c b/fs/xfs/libxfs/xfs_defer.c
index eff4a127188e..a7d1357687d0 100644
--- a/fs/xfs/libxfs/xfs_defer.c
+++ b/fs/xfs/libxfs/xfs_defer.c
@@ -628,7 +628,8 @@ xfs_defer_move(
static struct xfs_defer_capture *
xfs_defer_ops_capture(
struct xfs_trans *tp,
- struct xfs_inode *capture_ip)
+ struct xfs_inode *capture_ip1,
+ struct xfs_inode *capture_ip2)
{
struct xfs_defer_capture *dfc;
@@ -658,9 +659,13 @@ xfs_defer_ops_capture(
* Grab an extra reference to this inode and attach it to the capture
* structure.
*/
- if (capture_ip) {
- ihold(VFS_I(capture_ip));
- dfc->dfc_capture_ip = capture_ip;
+ if (capture_ip1) {
+ ihold(VFS_I(capture_ip1));
+ dfc->dfc_capture_ip1 = capture_ip1;
+ }
+ if (capture_ip2 && capture_ip2 != capture_ip1) {
+ ihold(VFS_I(capture_ip2));
+ dfc->dfc_capture_ip2 = capture_ip2;
}
return dfc;
@@ -673,8 +678,10 @@ xfs_defer_ops_release(
struct xfs_defer_capture *dfc)
{
xfs_defer_cancel_list(mp, &dfc->dfc_dfops);
- if (dfc->dfc_capture_ip)
- xfs_irele(dfc->dfc_capture_ip);
+ if (dfc->dfc_capture_ip1)
+ xfs_irele(dfc->dfc_capture_ip1);
+ if (dfc->dfc_capture_ip2)
+ xfs_irele(dfc->dfc_capture_ip2);
kmem_free(dfc);
}
@@ -684,22 +691,26 @@ xfs_defer_ops_release(
* of the deferred ops operate on an inode, the caller must pass in that inode
* so that the reference can be transferred to the capture structure. The
* caller must hold ILOCK_EXCL on the inode, and must unlock it before calling
- * xfs_defer_ops_continue.
+ * xfs_defer_ops_continue. Do not pass a null capture_ip1 and a non-null
+ * capture_ip2.
*/
int
xfs_defer_ops_capture_and_commit(
struct xfs_trans *tp,
- struct xfs_inode *capture_ip,
+ struct xfs_inode *capture_ip1,
+ struct xfs_inode *capture_ip2,
struct list_head *capture_list)
{
struct xfs_mount *mp = tp->t_mountp;
struct xfs_defer_capture *dfc;
int error;
- ASSERT(!capture_ip || xfs_isilocked(capture_ip, XFS_ILOCK_EXCL));
+ ASSERT(!capture_ip1 || xfs_isilocked(capture_ip1, XFS_ILOCK_EXCL));
+ ASSERT(!capture_ip2 || xfs_isilocked(capture_ip2, XFS_ILOCK_EXCL));
+ ASSERT(capture_ip2 == NULL || capture_ip1 != NULL);
/* If we don't capture anything, commit transaction and exit. */
- dfc = xfs_defer_ops_capture(tp, capture_ip);
+ dfc = xfs_defer_ops_capture(tp, capture_ip1, capture_ip2);
if (!dfc)
return xfs_trans_commit(tp);
@@ -724,17 +735,24 @@ void
xfs_defer_ops_continue(
struct xfs_defer_capture *dfc,
struct xfs_trans *tp,
- struct xfs_inode **captured_ipp)
+ struct xfs_inode **captured_ipp1,
+ struct xfs_inode **captured_ipp2)
{
ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
ASSERT(!(tp->t_flags & XFS_TRANS_DIRTY));
/* Lock and join the captured inode to the new transaction. */
- if (dfc->dfc_capture_ip) {
- xfs_ilock(dfc->dfc_capture_ip, XFS_ILOCK_EXCL);
- xfs_trans_ijoin(tp, dfc->dfc_capture_ip, 0);
+ if (dfc->dfc_capture_ip1 && dfc->dfc_capture_ip2) {
+ xfs_lock_two_inodes(dfc->dfc_capture_ip1, XFS_ILOCK_EXCL,
+ dfc->dfc_capture_ip2, XFS_ILOCK_EXCL);
+ xfs_trans_ijoin(tp, dfc->dfc_capture_ip1, 0);
+ xfs_trans_ijoin(tp, dfc->dfc_capture_ip2, 0);
+ } else if (dfc->dfc_capture_ip1) {
+ xfs_ilock(dfc->dfc_capture_ip1, XFS_ILOCK_EXCL);
+ xfs_trans_ijoin(tp, dfc->dfc_capture_ip1, 0);
}
- *captured_ipp = dfc->dfc_capture_ip;
+ *captured_ipp1 = dfc->dfc_capture_ip1;
+ *captured_ipp2 = dfc->dfc_capture_ip2;
/* Move captured dfops chain and state to the transaction. */
list_splice_init(&dfc->dfc_dfops, &tp->t_dfops);
diff --git a/fs/xfs/libxfs/xfs_defer.h b/fs/xfs/libxfs/xfs_defer.h
index 05472f71fffe..f5e3ca17aa26 100644
--- a/fs/xfs/libxfs/xfs_defer.h
+++ b/fs/xfs/libxfs/xfs_defer.h
@@ -87,7 +87,8 @@ struct xfs_defer_capture {
* An inode reference that must be maintained to complete the deferred
* work.
*/
- struct xfs_inode *dfc_capture_ip;
+ struct xfs_inode *dfc_capture_ip1;
+ struct xfs_inode *dfc_capture_ip2;
};
/*
@@ -95,9 +96,11 @@ struct xfs_defer_capture {
* This doesn't normally happen except log recovery.
*/
int xfs_defer_ops_capture_and_commit(struct xfs_trans *tp,
- struct xfs_inode *capture_ip, struct list_head *capture_list);
+ struct xfs_inode *capture_ip1, struct xfs_inode *capture_ip2,
+ struct list_head *capture_list);
void xfs_defer_ops_continue(struct xfs_defer_capture *d, struct xfs_trans *tp,
- struct xfs_inode **captured_ipp);
+ struct xfs_inode **captured_ipp1,
+ struct xfs_inode **captured_ipp2);
void xfs_defer_ops_release(struct xfs_mount *mp, struct xfs_defer_capture *d);
#endif /* __XFS_DEFER_H__ */
diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c
index 3101dd6b8384..1c286ba38865 100644
--- a/fs/xfs/xfs_bmap_item.c
+++ b/fs/xfs/xfs_bmap_item.c
@@ -517,7 +517,7 @@ xfs_bui_item_recover(
* Commit transaction, which frees the transaction and saves the inode
* for later replay activities.
*/
- error = xfs_defer_ops_capture_and_commit(tp, ip, capture_list);
+ error = xfs_defer_ops_capture_and_commit(tp, ip, NULL, capture_list);
if (error)
goto err_unlock;
diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c
index 429eca33399c..12401cf62131 100644
--- a/fs/xfs/xfs_extfree_item.c
+++ b/fs/xfs/xfs_extfree_item.c
@@ -625,7 +625,7 @@ xfs_efi_item_recover(
}
- return xfs_defer_ops_capture_and_commit(tp, NULL, capture_list);
+ return xfs_defer_ops_capture_and_commit(tp, NULL, NULL, capture_list);
abort_error:
xfs_trans_cancel(tp);
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
index d9f5f4aa4d35..6eee1abdc84d 100644
--- a/fs/xfs/xfs_log_recover.c
+++ b/fs/xfs/xfs_log_recover.c
@@ -2439,7 +2439,7 @@ xlog_finish_defer_ops(
{
struct xfs_defer_capture *dfc, *next;
struct xfs_trans *tp;
- struct xfs_inode *ip;
+ struct xfs_inode *ip1, *ip2;
int error = 0;
list_for_each_entry_safe(dfc, next, capture_list, dfc_list) {
@@ -2465,12 +2465,16 @@ xlog_finish_defer_ops(
* from recovering a single intent item.
*/
list_del_init(&dfc->dfc_list);
- xfs_defer_ops_continue(dfc, tp, &ip);
+ xfs_defer_ops_continue(dfc, tp, &ip1, &ip2);
error = xfs_trans_commit(tp);
- if (ip) {
- xfs_iunlock(ip, XFS_ILOCK_EXCL);
- xfs_irele(ip);
+ if (ip1) {
+ xfs_iunlock(ip1, XFS_ILOCK_EXCL);
+ xfs_irele(ip1);
+ }
+ if (ip2) {
+ xfs_iunlock(ip2, XFS_ILOCK_EXCL);
+ xfs_irele(ip2);
}
if (error)
return error;
diff --git a/fs/xfs/xfs_refcount_item.c b/fs/xfs/xfs_refcount_item.c
index 7529eb63ce94..52a615584afa 100644
--- a/fs/xfs/xfs_refcount_item.c
+++ b/fs/xfs/xfs_refcount_item.c
@@ -544,7 +544,7 @@ xfs_cui_item_recover(
}
xfs_refcount_finish_one_cleanup(tp, rcur, error);
- return xfs_defer_ops_capture_and_commit(tp, NULL, capture_list);
+ return xfs_defer_ops_capture_and_commit(tp, NULL, NULL, capture_list);
abort_error:
xfs_refcount_finish_one_cleanup(tp, rcur, error);
diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c
index 7adc996ca6e3..d2e85b87a1c0 100644
--- a/fs/xfs/xfs_rmap_item.c
+++ b/fs/xfs/xfs_rmap_item.c
@@ -567,7 +567,7 @@ xfs_rui_item_recover(
}
xfs_rmap_finish_one_cleanup(tp, rcur, error);
- return xfs_defer_ops_capture_and_commit(tp, NULL, capture_list);
+ return xfs_defer_ops_capture_and_commit(tp, NULL, NULL, capture_list);
abort_error:
xfs_rmap_finish_one_cleanup(tp, rcur, error);