@@ -27,6 +27,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;
@@ -385,6 +387,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;
+ bool 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_inode_data_fork_size(sxi->sxi_ip2))
+ return 0;
+
+ return xfs_dir2_block_to_sf(&args, bp, size, &sfh);
+}
+
static inline void
xfs_swapext_clear_reflink(
struct xfs_trans *tp,
@@ -407,6 +445,8 @@ xfs_swapext_do_postop_work(
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_CVT_INO2_SF;
if (error)
return error;
@@ -1061,7 +1101,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_CVT_INO2_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;