]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: use XFS_IFORK_Q to determine the presence of an xattr fork
authorDarrick J. Wong <djwong@kernel.org>
Wed, 24 Aug 2022 12:27:38 +0000 (14:27 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 30 Aug 2022 08:24:07 +0000 (10:24 +0200)
Source kernel commit: e45d7cb2356e6b59fe64da28324025cc6fcd3fbd

Modify xfs_ifork_ptr to return a NULL pointer if the caller asks for the
attribute fork but i_forkoff is zero.  This eliminates the ambiguity
between i_forkoff and i_af.if_present, which should make it easier to
understand the lifetime of attr forks.

While we're at it, remove the if_present checks around calls to
xfs_idestroy_fork and xfs_ifork_zap_attr since they can both handle attr
forks that have already been torn down.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
include/xfs_inode.h
libxfs/rdwr.c
libxfs/util.c
libxfs/xfs_attr.c
libxfs/xfs_attr.h
libxfs/xfs_bmap.c
libxfs/xfs_inode_buf.c
libxfs/xfs_inode_fork.c
libxfs/xfs_inode_fork.h
repair/phase6.c

index 93ebf80233dfd60bd20a3545238f1d28d0f3ad34..6470fe4d7164f43fd584f1e54315de6c6dd11601 100644 (file)
@@ -109,7 +109,7 @@ xfs_ifork_ptr(
        case XFS_DATA_FORK:
                return &ip->i_df;
        case XFS_ATTR_FORK:
-               if (!ip->i_af.if_present)
+               if (!XFS_IFORK_Q(ip))
                        return NULL;
                return &ip->i_af;
        case XFS_COW_FORK:
index c6b4db0f7a7545775c2afe88934e9458c35f2e74..ad8e324dccede273dc4a446f6c594111550f92e8 100644 (file)
@@ -1087,7 +1087,6 @@ libxfs_iget(
        ip->i_ino = ino;
        ip->i_mount = mp;
        ip->i_af.if_format = XFS_DINODE_FMT_EXTENTS;
-       ip->i_df.if_present = 1;
        spin_lock_init(&VFS_I(ip)->i_lock);
 
        error = xfs_imap(mp, tp, ip->i_ino, &ip->i_imap, 0);
@@ -1126,10 +1125,10 @@ libxfs_idestroy(xfs_inode_t *ip)
                        libxfs_idestroy_fork(&ip->i_df);
                        break;
        }
-       if (ip->i_af.if_present) {
-               libxfs_idestroy_fork(&ip->i_af);
-               libxfs_ifork_zap_attr(ip);
-       }
+
+       libxfs_idestroy_fork(&ip->i_af);
+       libxfs_ifork_zap_attr(ip);
+
        if (ip->i_cowfp) {
                libxfs_idestroy_fork(ip->i_cowfp);
                kmem_cache_free(xfs_ifork_cache, ip->i_cowfp);
index 974d0e27e6692527199bf8dd92848d646c59ec7c..3e12a188f6200aa044a43126b4ad853851d0cce1 100644 (file)
@@ -374,7 +374,7 @@ libxfs_iflush_int(
        if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL &&
            xfs_ifork_verify_local_data(ip))
                return -EFSCORRUPTED;
-       if (ip->i_af.if_present &&
+       if (XFS_IFORK_Q(ip) &&
            ip->i_af.if_format == XFS_DINODE_FMT_LOCAL &&
            xfs_ifork_verify_local_attr(ip))
                return -EFSCORRUPTED;
index a0d65a37444d293d67d1a929e89b4506004b6dbe..404cff6791cb5a6d258dff409f902bd6c96d903f 100644 (file)
@@ -67,8 +67,6 @@ xfs_inode_hasattr(
 {
        if (!XFS_IFORK_Q(ip))
                return 0;
-       if (!ip->i_af.if_present)
-               return 0;
        if (ip->i_af.if_format == XFS_DINODE_FMT_EXTENTS &&
            ip->i_af.if_nextents == 0)
                return 0;
index 0f100db504eefca2050f58f3297559aca24b1074..36371c3b9069c4b05013572dfc2999316334a850 100644 (file)
@@ -576,7 +576,7 @@ xfs_attr_init_add_state(struct xfs_da_args *args)
         * context, i_af is guaranteed to exist. Hence if the attr fork is
         * null, we were called from a pure remove operation and so we are done.
         */
-       if (!args->dp->i_af.if_present)
+       if (!XFS_IFORK_Q(args->dp))
                return XFS_DAS_DONE;
 
        args->op_flags |= XFS_DA_OP_ADDNAME;
index 9e5e6cd61ea3375e76a289266147f7f2d1a1f3fd..c2f87bbbd2f61dc9b4b310abc04eee750d28f678 100644 (file)
@@ -1034,7 +1034,6 @@ xfs_bmap_add_attrfork(
        error = xfs_bmap_set_attrforkoff(ip, size, &version);
        if (error)
                goto trans_cancel;
-       ASSERT(!ip->i_af.if_present);
 
        xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);
        logflags = 0;
index 5e30f94df0510c89833a5c60c1a99ea187d4f946..e8283e0d77d7fb430ee5837a5691aa5edd59db20 100644 (file)
@@ -174,7 +174,6 @@ xfs_inode_from_disk(
        xfs_failaddr_t          fa;
 
        ASSERT(ip->i_cowfp == NULL);
-       ASSERT(!ip->i_af.if_present);
 
        fa = xfs_dinode_verify(ip->i_mount, ip->i_ino, from);
        if (fa) {
index 92ca8095a5aa3518955a7bc4211a1eb469b83c81..225b7f8ca4855a06cab4d403c8b215d1fe39f8a5 100644 (file)
@@ -280,9 +280,6 @@ xfs_ifork_init_attr(
        enum xfs_dinode_fmt     format,
        xfs_extnum_t            nextents)
 {
-       ASSERT(!ip->i_af.if_present);
-
-       ip->i_af.if_present = 1;
        ip->i_af.if_format = format;
        ip->i_af.if_nextents = nextents;
 }
@@ -291,7 +288,6 @@ void
 xfs_ifork_zap_attr(
        struct xfs_inode        *ip)
 {
-       ASSERT(ip->i_af.if_present);
        ASSERT(ip->i_af.if_broot == NULL);
        ASSERT(ip->i_af.if_u1.if_data == NULL);
        ASSERT(ip->i_af.if_height == 0);
@@ -681,7 +677,6 @@ xfs_ifork_init_cow(
 
        ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_cache,
                                       GFP_NOFS | __GFP_NOFAIL);
-       ip->i_cowfp->if_present = 1;
        ip->i_cowfp->if_format = XFS_DINODE_FMT_EXTENTS;
 }
 
@@ -720,7 +715,7 @@ xfs_ifork_verify_local_attr(
        struct xfs_ifork        *ifp = &ip->i_af;
        xfs_failaddr_t          fa;
 
-       if (!ifp->if_present)
+       if (!XFS_IFORK_Q(ip))
                fa = __this_address;
        else
                fa = xfs_attr_shortform_verify(ip);
index 63015e9cee14182693b3a1315a2cfbb73ded412d..0b912bbe4f4bcf9b2aa7c3829ae9b02f1c2c91f5 100644 (file)
@@ -24,7 +24,6 @@ struct xfs_ifork {
        xfs_extnum_t            if_nextents;    /* # of extents in this fork */
        short                   if_broot_bytes; /* bytes allocated for root */
        int8_t                  if_format;      /* format of this fork */
-       int8_t                  if_present;     /* 1 if present */
 };
 
 /*
index e533daf4015793b811aa0f06a5e9801e3c882ec0..d8b23ba5286ca6f617d3477b92f8d414dc726eac 100644 (file)
@@ -499,8 +499,7 @@ mk_rbmino(xfs_mount_t *mp)
 
        VFS_I(ip)->i_mode = S_IFREG;
        ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS;
-       if (ip->i_af.if_present)
-               libxfs_ifork_zap_attr(ip);
+       libxfs_ifork_zap_attr(ip);
 
        set_nlink(VFS_I(ip), 1);        /* account for sb ptr */
 
@@ -739,8 +738,7 @@ mk_rsumino(xfs_mount_t *mp)
 
        VFS_I(ip)->i_mode = S_IFREG;
        ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS;
-       if (ip->i_af.if_present)
-               libxfs_ifork_zap_attr(ip);
+       libxfs_ifork_zap_attr(ip);
 
        set_nlink(VFS_I(ip), 1);        /* account for sb ptr */
 
@@ -838,8 +836,7 @@ mk_root_dir(xfs_mount_t *mp)
 
        VFS_I(ip)->i_mode = mode|S_IFDIR;
        ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS;
-       if (ip->i_af.if_present)
-               libxfs_ifork_zap_attr(ip);
+       libxfs_ifork_zap_attr(ip);
 
        set_nlink(VFS_I(ip), 2);        /* account for . and .. */