]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libxfs: create new files with attr forks if necessary
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:23:24 +0000 (16:23 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:12 +0000 (17:01 -0700)
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 <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/init.c
libxfs/util.c

index 95de1e6d1d4fb911622aa918cf5f13e86833df5e..90a539e04161bbbdf82899426a9d985d7555c885 100644 (file)
@@ -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);
+
 }
 
 /*
index 74eea0fcbe0712f3f3c630829fa7a74af896987e..373749457cc1048b619fc44f372fa71bc70681ff 100644 (file)
@@ -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.
         */