From: Darrick J. Wong <djwong@xxxxxxxxxx> Add a couple of utility functions to set or remove parent pointers from a file. These functions will be used by repair code, hence they skip the xattr logging that regular parent pointer updates use. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- libxfs/xfs_dir2.c | 2 +- libxfs/xfs_dir2.h | 2 +- libxfs/xfs_parent.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 8 ++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c index 79b6ec893fd..b906f39e0fe 100644 --- a/libxfs/xfs_dir2.c +++ b/libxfs/xfs_dir2.c @@ -439,7 +439,7 @@ int xfs_dir_removename( struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t total) /* bmap's total block count */ { diff --git a/libxfs/xfs_dir2.h b/libxfs/xfs_dir2.h index f99788a1f3e..ca1949ed4f5 100644 --- a/libxfs/xfs_dir2.h +++ b/libxfs/xfs_dir2.h @@ -55,7 +55,7 @@ extern int xfs_dir_lookup(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t *inum, struct xfs_name *ci_name); extern int xfs_dir_removename(struct xfs_trans *tp, struct xfs_inode *dp, - struct xfs_name *name, xfs_ino_t ino, + const struct xfs_name *name, xfs_ino_t ino, xfs_extlen_t tot); extern int xfs_dir_replace(struct xfs_trans *tp, struct xfs_inode *dp, const struct xfs_name *name, xfs_ino_t inum, diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 024e89756e6..f7cef51e1ec 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -421,3 +421,49 @@ xfs_parent_lookup( return xfs_attr_get_ilocked(&scr->args); } + +/* + * Attach the parent pointer (@pptr -> @name) to @ip immediately. Caller must + * not have a transaction or hold the ILOCK. This is for specialized repair + * functions only. The scratchpad need not be initialized. + */ +int +xfs_parent_set( + struct xfs_inode *ip, + const struct xfs_parent_name_irec *pptr, + struct xfs_parent_scratch *scr) +{ + if (XFS_IS_CORRUPT(ip->i_mount, + !xfs_parent_verify_irec(ip->i_mount, pptr))) { + return -EFSCORRUPTED; + } + + xfs_parent_irec_to_disk(&scr->rec, pptr); + xfs_parent_scratch_init(NULL, ip, pptr, scr); + scr->args.op_flags |= XFS_DA_OP_LOGGED; + + return xfs_attr_set(&scr->args); +} + +/* + * Remove the parent pointer (@rec -> @name) from @ip immediately. Caller must + * not have a transaction or hold the ILOCK. This is for specialized repair + * functions only. The scratchpad need not be initialized. + */ +int +xfs_parent_unset( + struct xfs_inode *ip, + const struct xfs_parent_name_irec *pptr, + struct xfs_parent_scratch *scr) +{ + if (XFS_IS_CORRUPT(ip->i_mount, + !xfs_parent_verify_irec(ip->i_mount, pptr))) { + return -EFSCORRUPTED; + } + + xfs_parent_irec_to_disk(&scr->rec, pptr); + xfs_parent_scratch_init(NULL, ip, pptr, scr); + scr->args.op_flags |= XFS_DA_OP_LOGGED | XFS_DA_OP_REMOVE; + + return xfs_attr_set(&scr->args); +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index e4443da1d86..58e59af818b 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -162,4 +162,12 @@ int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip, const struct xfs_parent_name_irec *pptr, struct xfs_parent_scratch *scratch); +int xfs_parent_set(struct xfs_inode *ip, + const struct xfs_parent_name_irec *pptr, + struct xfs_parent_scratch *scratch); + +int xfs_parent_unset(struct xfs_inode *ip, + const struct xfs_parent_name_irec *rec, + struct xfs_parent_scratch *scratch); + #endif /* __XFS_PARENT_H__ */