summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 10:58:09 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-10-22 16:40:44 -0700
commit0180c1e1bf58d7f7ef875506a48c1db7e368ff06 (patch)
tree298177db24169c1e124acc5c4265fb675ceace28
parentddece74dd6813897d64cd1c392276a0ef0bf56ca (diff)
xfs: condense extended attributes after an atomic swap
Add a new swapext flag that enables us to perform post-swap processing on file2 once we're done swapping the extent maps. If we were swapping the extended attributes, we want to be able to convert file2's attr fork from block to inline format. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online xattr repair feature can create salvaged attrs in a temporary file and swap the attr forks when ready. If one file is in extents format and the other is inline, we will have to promote both to extents format to perform the swap. After the swap, we can try to condense the fixed file's attr fork back down to inline format if possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/libxfs/xfs_log_format.h9
-rw-r--r--fs/xfs/libxfs/xfs_swapext.c80
-rw-r--r--fs/xfs/libxfs/xfs_swapext.h11
3 files changed, 93 insertions, 7 deletions
diff --git a/fs/xfs/libxfs/xfs_log_format.h b/fs/xfs/libxfs/xfs_log_format.h
index 1c316776429f..bd711d244c4b 100644
--- a/fs/xfs/libxfs/xfs_log_format.h
+++ b/fs/xfs/libxfs/xfs_log_format.h
@@ -820,14 +820,19 @@ struct xfs_swap_extent {
/* Do not swap any part of the range where file1's mapping is a hole. */
#define XFS_SWAP_EXT_SKIP_FILE1_HOLES (1ULL << 2)
+/* Try to convert inode2 from block to short format at the end, if possible. */
+#define XFS_SWAP_EXT_FILE2_CVT_SF (1ULL << 3)
+
#define XFS_SWAP_EXT_FLAGS (XFS_SWAP_EXT_ATTR_FORK | \
XFS_SWAP_EXT_SET_SIZES | \
- XFS_SWAP_EXT_SKIP_FILE1_HOLES)
+ XFS_SWAP_EXT_SKIP_FILE1_HOLES | \
+ XFS_SWAP_EXT_FILE2_CVT_SF)
#define XFS_SWAP_EXT_STRINGS \
{ XFS_SWAP_EXT_ATTR_FORK, "ATTRFORK" }, \
{ XFS_SWAP_EXT_SET_SIZES, "SETSIZES" }, \
- { XFS_SWAP_EXT_SKIP_FILE1_HOLES, "SKIP_FILE1_HOLES" }
+ { XFS_SWAP_EXT_SKIP_FILE1_HOLES, "SKIP_FILE1_HOLES" }, \
+ { XFS_SWAP_EXT_FILE2_CVT_SF, "INO2_SHORTFORM" }
/* This is the structure used to lay out an sxi log item in the log. */
struct xfs_sxi_log_format {
diff --git a/fs/xfs/libxfs/xfs_swapext.c b/fs/xfs/libxfs/xfs_swapext.c
index db325fa2eac3..d5d8d4146340 100644
--- a/fs/xfs/libxfs/xfs_swapext.c
+++ b/fs/xfs/libxfs/xfs_swapext.c
@@ -22,6 +22,10 @@
#include "xfs_trans_space.h"
#include "xfs_errortag.h"
#include "xfs_error.h"
+#include "xfs_da_format.h"
+#include "xfs_da_btree.h"
+#include "xfs_attr_leaf.h"
+#include "xfs_attr.h"
/* bmbt mappings adjacent to a pair of records. */
struct xfs_swapext_adjacent {
@@ -201,6 +205,12 @@ sxi_has_more_swap_work(const struct xfs_swapext_intent *sxi)
return sxi->sxi_blockcount > 0;
}
+static inline bool
+sxi_has_postop_work(const struct xfs_swapext_intent *sxi)
+{
+ return sxi->sxi_flags & XFS_SWAP_EXT_FILE2_CVT_SF;
+}
+
static inline void
sxi_advance(
struct xfs_swapext_intent *sxi,
@@ -422,6 +432,55 @@ xfs_swapext_exchange_mappings(
sxi_advance(sxi, irec1);
}
+/* Convert inode2's leaf attr fork back to shortform, if possible.. */
+STATIC int
+xfs_swapext_attr_to_sf(
+ struct xfs_trans *tp,
+ struct xfs_swapext_intent *sxi)
+{
+ struct xfs_da_args args = {
+ .dp = sxi->sxi_ip2,
+ .geo = tp->t_mountp->m_attr_geo,
+ .whichfork = XFS_ATTR_FORK,
+ .trans = tp,
+ };
+ struct xfs_buf *bp;
+ int forkoff;
+ int error;
+
+ if (!xfs_attr_is_leaf(sxi->sxi_ip2))
+ return 0;
+
+ error = xfs_attr3_leaf_read(tp, sxi->sxi_ip2, 0, &bp);
+ if (error)
+ return error;
+
+ forkoff = xfs_attr_shortform_allfit(bp, sxi->sxi_ip2);
+ if (forkoff == 0)
+ return 0;
+
+ return xfs_attr3_leaf_to_shortform(bp, &args, forkoff);
+}
+
+/* Finish whatever work might come after a swap operation. */
+static int
+xfs_swapext_postop_work(
+ struct xfs_trans *tp,
+ struct xfs_swapext_intent *sxi)
+{
+ int error = 0;
+
+ if (sxi->sxi_flags & XFS_SWAP_EXT_FILE2_CVT_SF) {
+ if (sxi->sxi_flags & XFS_SWAP_EXT_ATTR_FORK)
+ error = xfs_swapext_attr_to_sf(tp, sxi);
+ sxi->sxi_flags &= ~XFS_SWAP_EXT_FILE2_CVT_SF;
+ if (error)
+ return error;
+ }
+
+ return 0;
+}
+
/* Finish one extent swap, possibly log more. */
int
xfs_swapext_finish_one(
@@ -429,7 +488,18 @@ xfs_swapext_finish_one(
struct xfs_swapext_intent *sxi)
{
struct xfs_bmbt_irec irec1, irec2;
- int error;
+ int error = 0;
+
+ /*
+ * If there isn't any exchange work to do, the previous transaction
+ * finished the extent swap and now we need to do some post-op cleanup
+ * work on file2.
+ */
+ if (!sxi_has_more_swap_work(sxi)) {
+ ASSERT(sxi_has_postop_work(sxi));
+
+ return xfs_swapext_postop_work(tp, sxi);
+ }
/* Find something to swap and swap it. */
error = xfs_swapext_find_mappings(sxi, &irec1, &irec2, NULL);
@@ -457,7 +527,7 @@ xfs_swapext_finish_one(
return -EIO;
/* If we still have work to do, ask for a new transaction. */
- if (sxi_has_more_swap_work(sxi)) {
+ if (sxi_has_more_swap_work(sxi) || sxi_has_postop_work(sxi)) {
trace_xfs_swapext_defer(tp->t_mountp, sxi);
return -EAGAIN;
}
@@ -466,7 +536,7 @@ xfs_swapext_finish_one(
}
/* Estimate the bmbt and rmapbt overhead required to exchange extents. */
-static int
+int
xfs_swapext_estimate_overhead(
const struct xfs_swapext_req *req,
struct xfs_swapext_res *res)
@@ -725,6 +795,8 @@ xfs_swapext_init_intent(
if (req->req_flags & XFS_SWAP_REQ_SKIP_FILE1_HOLES)
sxi->sxi_flags |= XFS_SWAP_EXT_SKIP_FILE1_HOLES;
+ if (req->req_flags & XFS_SWAP_REQ_FILE2_CVT_SF)
+ sxi->sxi_flags |= XFS_SWAP_EXT_FILE2_CVT_SF;
return sxi;
}
@@ -867,6 +939,8 @@ xfs_swapext(
ASSERT(!(req->req_flags & ~XFS_SWAP_REQ_FLAGS));
if (req->req_flags & XFS_SWAP_REQ_SET_SIZES)
ASSERT(req->whichfork == XFS_DATA_FORK);
+ if (req->req_flags & XFS_SWAP_REQ_FILE2_CVT_SF)
+ ASSERT(req->whichfork == XFS_ATTR_FORK);
if (req->blockcount == 0)
return 0;
diff --git a/fs/xfs/libxfs/xfs_swapext.h b/fs/xfs/libxfs/xfs_swapext.h
index 591fd2adf054..c92c20fc7f32 100644
--- a/fs/xfs/libxfs/xfs_swapext.h
+++ b/fs/xfs/libxfs/xfs_swapext.h
@@ -63,12 +63,17 @@ struct xfs_swapext_req {
/* Do not swap any part of the range where file1's mapping is a hole. */
#define XFS_SWAP_REQ_SKIP_FILE1_HOLES (1U << 2)
+/* Try to convert inode2's fork to local format, if possible. */
+#define XFS_SWAP_REQ_FILE2_CVT_SF (1U << 3)
+
#define XFS_SWAP_REQ_FLAGS (XFS_SWAP_REQ_SET_SIZES | \
- XFS_SWAP_REQ_SKIP_FILE1_HOLES)
+ XFS_SWAP_REQ_SKIP_FILE1_HOLES | \
+ XFS_SWAP_REQ_FILE2_CVT_SF)
#define XFS_SWAP_REQ_STRINGS \
{ XFS_SWAP_REQ_SET_SIZES, "SETSIZES" }, \
- { XFS_SWAP_REQ_SKIP_FILE1_HOLES, "SKIP_FILE1_HOLES" }
+ { XFS_SWAP_REQ_SKIP_FILE1_HOLES, "SKIP_FILE1_HOLES" }, \
+ { XFS_SWAP_REQ_FILE2_CVT_SF, "INO2_SHORTFORM" }
/* Estimated resource requirements for a swapext operation. */
struct xfs_swapext_res {
@@ -84,6 +89,8 @@ unsigned int xfs_swapext_reflink_prep(const struct xfs_swapext_req *req);
void xfs_swapext_reflink_finish(struct xfs_trans *tp,
const struct xfs_swapext_req *req, unsigned int reflink_state);
+int xfs_swapext_estimate_overhead(const struct xfs_swapext_req *req,
+ struct xfs_swapext_res *res);
int xfs_swapext_estimate(const struct xfs_swapext_req *req,
struct xfs_swapext_res *res);