summaryrefslogtreecommitdiff
path: root/fs/xfs
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 10:58:10 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-12-15 17:29:00 -0800
commitb849353b04270126bf5a089b61bf0d28432a2a57 (patch)
treeb0f23c29aadebb307a44de849d18764b26051644 /fs/xfs
parented9dbb73c6340292fa8f18d78a9ded266839e035 (diff)
xfs: condense directories after an atomic swap
The previous commit added a new swapext flag that enables us to perform post-swap processing on file2 once we're done swapping the extent maps. Now add this ability for directories. This isn't used anywhere right now, but we need to have the basic ondisk flags in place so that a future online directory repair feature can create salvaged dirents in a temporary directory and swap the data 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 directory down to inline format if possible. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs')
-rw-r--r--fs/xfs/libxfs/xfs_swapext.c44
1 files changed, 43 insertions, 1 deletions
diff --git a/fs/xfs/libxfs/xfs_swapext.c b/fs/xfs/libxfs/xfs_swapext.c
index c23017236cc7..23d5cc89fc19 100644
--- a/fs/xfs/libxfs/xfs_swapext.c
+++ b/fs/xfs/libxfs/xfs_swapext.c
@@ -26,6 +26,8 @@
#include "xfs_da_btree.h"
#include "xfs_attr_leaf.h"
#include "xfs_attr.h"
+#include "xfs_dir2_priv.h"
+#include "xfs_dir2.h"
struct kmem_cache *xfs_swapext_intent_cache;
@@ -464,6 +466,42 @@ xfs_swapext_attr_to_sf(
return xfs_attr3_leaf_to_shortform(bp, &args, forkoff);
}
+/* Convert inode2's block dir fork back to shortform, if possible.. */
+STATIC int
+xfs_swapext_dir_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_dir_geo,
+ .whichfork = XFS_DATA_FORK,
+ .trans = tp,
+ };
+ struct xfs_dir2_sf_hdr sfh;
+ struct xfs_buf *bp;
+ int isblock;
+ int size;
+ int error;
+
+ error = xfs_dir2_isblock(&args, &isblock);
+ if (error)
+ return error;
+
+ if (!isblock)
+ return 0;
+
+ error = xfs_dir3_block_read(tp, sxi->sxi_ip2, &bp);
+ if (error)
+ return error;
+
+ size = xfs_dir2_block_sfsize(sxi->sxi_ip2, bp->b_addr, &sfh);
+ if (size > XFS_IFORK_DSIZE(sxi->sxi_ip2))
+ return 0;
+
+ return xfs_dir2_block_to_sf(&args, bp, size, &sfh);
+}
+
/* Finish whatever work might come after a swap operation. */
static int
xfs_swapext_postop_work(
@@ -475,6 +513,8 @@ xfs_swapext_postop_work(
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);
+ else if (S_ISDIR(VFS_I(sxi->sxi_ip2)->i_mode))
+ error = xfs_swapext_dir_to_sf(tp, sxi);
sxi->sxi_flags &= ~XFS_SWAP_EXT_FILE2_CVT_SF;
if (error)
return error;
@@ -960,7 +1000,9 @@ xfs_swapext(
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);
+ ASSERT(req->whichfork == XFS_ATTR_FORK ||
+ (req->whichfork == XFS_DATA_FORK &&
+ S_ISDIR(VFS_I(req->ip2)->i_mode)));
if (req->blockcount == 0)
return 0;