]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: Add parent pointers to rename
authorAllison Henderson <allison.henderson@oracle.com>
Mon, 29 Jul 2024 23:22:48 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:03 +0000 (17:01 -0700)
Source kernel commit: 5a8338c88284df4e9e697225aa65f2709333a659

This patch removes the old parent pointer attribute during the rename
operation, and re-adds the updated parent pointer.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
[djwong: adjust to new ondisk format]
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_parent.c
libxfs/xfs_parent.h
libxfs/xfs_trans_space.c
libxfs/xfs_trans_space.h

index 0657728e681cafc052971c9aff0f9745562bbed6..a53b7d13d324a8c552e26caf478c025d5ea9cf90 100644 (file)
@@ -224,3 +224,33 @@ xfs_parent_removename(
        xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REMOVE);
        return 0;
 }
+
+/* Replace one parent pointer with another to reflect a rename. */
+int
+xfs_parent_replacename(
+       struct xfs_trans        *tp,
+       struct xfs_parent_args  *ppargs,
+       struct xfs_inode        *old_dp,
+       const struct xfs_name   *old_name,
+       struct xfs_inode        *new_dp,
+       const struct xfs_name   *new_name,
+       struct xfs_inode        *child)
+{
+       int                     error;
+
+       error = xfs_parent_iread_extents(tp, child);
+       if (error)
+               return error;
+
+       xfs_inode_to_parent_rec(&ppargs->rec, old_dp);
+       xfs_parent_da_args_init(&ppargs->args, tp, &ppargs->rec, child,
+                       child->i_ino, old_name);
+
+       xfs_inode_to_parent_rec(&ppargs->new_rec, new_dp);
+       ppargs->args.new_name = new_name->name;
+       ppargs->args.new_namelen = new_name->len;
+       ppargs->args.new_value = &ppargs->new_rec;
+       ppargs->args.new_valuelen = sizeof(struct xfs_parent_rec);
+       xfs_attr_defer_add(&ppargs->args, XFS_ATTR_DEFER_REPLACE);
+       return 0;
+}
index 4a7fd48c226a4345d959ef80e9ce7a1c7c45aa73..768633b313671a32f23fc7a8477e8bed4a1b4c38 100644 (file)
@@ -45,6 +45,7 @@ extern struct kmem_cache      *xfs_parent_args_cache;
  */
 struct xfs_parent_args {
        struct xfs_parent_rec   rec;
+       struct xfs_parent_rec   new_rec;
        struct xfs_da_args      args;
 };
 
@@ -84,5 +85,10 @@ int xfs_parent_addname(struct xfs_trans *tp, struct xfs_parent_args *ppargs,
 int xfs_parent_removename(struct xfs_trans *tp, struct xfs_parent_args *ppargs,
                struct xfs_inode *dp, const struct xfs_name *parent_name,
                struct xfs_inode *child);
+int xfs_parent_replacename(struct xfs_trans *tp,
+               struct xfs_parent_args *ppargs,
+               struct xfs_inode *old_dp, const struct xfs_name *old_name,
+               struct xfs_inode *new_dp, const struct xfs_name *new_name,
+               struct xfs_inode *child);
 
 #endif /* __XFS_PARENT_H__ */
index 86a91a3a844140274cc0e13d2c2c1ac029e1ef29..373f5cc24977a8b99d0ff5638c915e26a5f3151d 100644 (file)
@@ -94,3 +94,28 @@ xfs_remove_space_res(
 
        return ret;
 }
+
+unsigned int
+xfs_rename_space_res(
+       struct xfs_mount        *mp,
+       unsigned int            src_namelen,
+       bool                    target_exists,
+       unsigned int            target_namelen,
+       bool                    has_whiteout)
+{
+       unsigned int            ret;
+
+       ret = XFS_DIRREMOVE_SPACE_RES(mp) +
+                       XFS_DIRENTER_SPACE_RES(mp, target_namelen);
+
+       if (xfs_has_parent(mp)) {
+               if (has_whiteout)
+                       ret += xfs_parent_calc_space_res(mp, src_namelen);
+               ret += 2 * xfs_parent_calc_space_res(mp, target_namelen);
+       }
+
+       if (target_exists)
+               ret += xfs_parent_calc_space_res(mp, target_namelen);
+
+       return ret;
+}
index a4490813c56f132183159680686c9bb106f94836..1155ff2d37e29f7d1519d2f406c9137562bf9568 100644 (file)
@@ -91,8 +91,6 @@
         XFS_DQUOT_CLUSTER_SIZE_FSB)
 #define        XFS_QM_QINOCREATE_SPACE_RES(mp) \
        XFS_IALLOC_SPACE_RES(mp)
-#define        XFS_RENAME_SPACE_RES(mp,nl)     \
-       (XFS_DIRREMOVE_SPACE_RES(mp) + XFS_DIRENTER_SPACE_RES(mp,nl))
 #define XFS_IFREE_SPACE_RES(mp)                \
        (xfs_has_finobt(mp) ? M_IGEO(mp)->inobt_maxlevels : 0)
 
@@ -106,4 +104,8 @@ unsigned int xfs_symlink_space_res(struct xfs_mount *mp, unsigned int namelen,
                unsigned int fsblocks);
 unsigned int xfs_remove_space_res(struct xfs_mount *mp, unsigned int namelen);
 
+unsigned int xfs_rename_space_res(struct xfs_mount *mp,
+               unsigned int src_namelen, bool target_exists,
+               unsigned int target_namelen, bool has_whiteout);
+
 #endif /* __XFS_TRANS_SPACE_H__ */