From: Darrick J. Wong <djwong@xxxxxxxxxx> If the fs has parent pointers, we need to check that each child dirent points to a file that has a parent pointer pointing back at us. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- libxfs/xfs_parent.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ libxfs/xfs_parent.h | 10 +++++++++ 2 files changed, 64 insertions(+) diff --git a/libxfs/xfs_parent.c b/libxfs/xfs_parent.c index 92b541737cb..024e89756e6 100644 --- a/libxfs/xfs_parent.c +++ b/libxfs/xfs_parent.c @@ -367,3 +367,57 @@ xfs_parent_irec_hashname( irec->p_namehash = xfs_dir2_hashname(mp, &dname); } + +static inline void +xfs_parent_scratch_init( + struct xfs_trans *tp, + struct xfs_inode *ip, + const struct xfs_parent_name_irec *pptr, + struct xfs_parent_scratch *scr) +{ + memset(&scr->args, 0, sizeof(struct xfs_da_args)); + scr->args.attr_filter = XFS_ATTR_PARENT; + scr->args.dp = ip; + scr->args.geo = ip->i_mount->m_attr_geo; + scr->args.name = (const unsigned char *)&scr->rec; + scr->args.namelen = sizeof(struct xfs_parent_name_rec); + scr->args.op_flags = XFS_DA_OP_NVLOOKUP; + scr->args.trans = tp; + scr->args.value = (void *)pptr->p_name; + scr->args.valuelen = pptr->p_namelen; + scr->args.whichfork = XFS_ATTR_FORK; + scr->args.hashval = xfs_da_hashname((const void *)&scr->rec, + sizeof(struct xfs_parent_name_rec)); +} + +/* + * Look up the @name associated with the parent pointer (@pptr) of @ip. + * Caller must hold at least ILOCK_SHARED. Returns 0 if the pointer is found, + * -ENOATTR if there is no match, or a negative errno. The scratchpad need not + * be initialized. + */ +int +xfs_parent_lookup( + struct xfs_trans *tp, + struct xfs_inode *ip, + const struct xfs_parent_name_irec *pptr, + struct xfs_parent_scratch *scr) +{ + int error; + + /* + * Make sure the attr fork iext tree is loaded in transaction context + * before we start down the rest of the call path. + */ + if (xfs_inode_hasattr(ip)) { + error = xfs_iread_extents(tp, ip, XFS_ATTR_FORK); + if (error) + return error; + } + + xfs_parent_irec_to_disk(&scr->rec, pptr); + xfs_parent_scratch_init(tp, ip, pptr, scr); + scr->args.op_flags |= XFS_DA_OP_OKNOENT; + + return xfs_attr_get_ilocked(&scr->args); +} diff --git a/libxfs/xfs_parent.h b/libxfs/xfs_parent.h index e43ae5a7df8..e4443da1d86 100644 --- a/libxfs/xfs_parent.h +++ b/libxfs/xfs_parent.h @@ -152,4 +152,14 @@ void xfs_parent_irec_hashname(struct xfs_mount *mp, bool xfs_parent_verify_irec(struct xfs_mount *mp, const struct xfs_parent_name_irec *irec); +/* Scratchpad memory so that raw parent operations don't burn stack space. */ +struct xfs_parent_scratch { + struct xfs_parent_name_rec rec; + struct xfs_da_args args; +}; + +int xfs_parent_lookup(struct xfs_trans *tp, struct xfs_inode *ip, + const struct xfs_parent_name_irec *pptr, + struct xfs_parent_scratch *scratch); + #endif /* __XFS_PARENT_H__ */