From 30b4d5d66fa1fa6543080c2df1d30594927712bd Mon Sep 17 00:00:00 2001 From: "Darrick J. Wong" Date: Mon, 29 Jul 2024 16:23:24 -0700 Subject: [PATCH] libxfs: create new files with attr forks if necessary Create new files with attr forks if they're going to have parent pointers. In the next patch we'll fix mkfs to use the same parent creation functions as the kernel, so we're going to need this. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- libxfs/init.c | 4 ++++ libxfs/util.c | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libxfs/init.c b/libxfs/init.c index 95de1e6d..90a539e0 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -602,14 +602,18 @@ void libxfs_compute_all_maxlevels( struct xfs_mount *mp) { + struct xfs_ino_geometry *igeo = M_IGEO(mp); + xfs_alloc_compute_maxlevels(mp); xfs_bmap_compute_maxlevels(mp, XFS_DATA_FORK); xfs_bmap_compute_maxlevels(mp, XFS_ATTR_FORK); + igeo->attr_fork_offset = xfs_bmap_compute_attr_offset(mp); xfs_ialloc_setup_geometry(mp); xfs_rmapbt_compute_maxlevels(mp); xfs_refcountbt_compute_maxlevels(mp); xfs_agbtree_compute_maxlevels(mp); + } /* diff --git a/libxfs/util.c b/libxfs/util.c index 74eea0fc..37374945 100644 --- a/libxfs/util.c +++ b/libxfs/util.c @@ -274,11 +274,12 @@ libxfs_init_new_inode( struct fsxattr *fsx, struct xfs_inode **ipp) { + struct xfs_mount *mp = tp->t_mountp; struct xfs_inode *ip; unsigned int flags; int error; - error = libxfs_iget(tp->t_mountp, tp, ino, XFS_IGET_CREATE, &ip); + error = libxfs_iget(mp, tp, ino, XFS_IGET_CREATE, &ip); if (error != 0) return error; ASSERT(ip != NULL); @@ -340,6 +341,22 @@ libxfs_init_new_inode( ASSERT(0); } + /* + * If we're going to set a parent pointer on this file, we need to + * create an attr fork to receive that parent pointer. + */ + if (pip && xfs_has_parent(mp)) { + ip->i_forkoff = xfs_default_attroffset(ip) >> 3; + xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); + + if (!xfs_has_attr(mp)) { + spin_lock(&mp->m_sb_lock); + xfs_add_attr(mp); + spin_unlock(&mp->m_sb_lock); + xfs_log_sb(tp); + } + } + /* * Log the new values stuffed into the inode. */ -- 2.47.2