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>
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:
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);
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);
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;
{
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;
* 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;
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;
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) {
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;
}
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);
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;
}
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);
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 */
};
/*
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 */
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 */
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 .. */