Skip to content

Commit e45d7cb

Browse files
author
Darrick J. Wong
committed
xfs: use XFS_IFORK_Q to determine the presence of an xattr fork
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>
1 parent 2ed5b09 commit e45d7cb

11 files changed

Lines changed: 12 additions & 29 deletions

fs/xfs/libxfs/xfs_attr.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ xfs_inode_hasattr(
6969
{
7070
if (!XFS_IFORK_Q(ip))
7171
return 0;
72-
if (!ip->i_af.if_present)
73-
return 0;
7472
if (ip->i_af.if_format == XFS_DINODE_FMT_EXTENTS &&
7573
ip->i_af.if_nextents == 0)
7674
return 0;

fs/xfs/libxfs/xfs_attr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ xfs_attr_init_add_state(struct xfs_da_args *args)
576576
* context, i_af is guaranteed to exist. Hence if the attr fork is
577577
* null, we were called from a pure remove operation and so we are done.
578578
*/
579-
if (!args->dp->i_af.if_present)
579+
if (!XFS_IFORK_Q(args->dp))
580580
return XFS_DAS_DONE;
581581

582582
args->op_flags |= XFS_DA_OP_ADDNAME;

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ xfs_bmap_add_attrfork(
10411041
error = xfs_bmap_set_attrforkoff(ip, size, &version);
10421042
if (error)
10431043
goto trans_cancel;
1044-
ASSERT(!ip->i_af.if_present);
10451044

10461045
xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);
10471046
logflags = 0;

fs/xfs/libxfs/xfs_inode_buf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ xfs_inode_from_disk(
177177
xfs_failaddr_t fa;
178178

179179
ASSERT(ip->i_cowfp == NULL);
180-
ASSERT(!ip->i_af.if_present);
181180

182181
fa = xfs_dinode_verify(ip->i_mount, ip->i_ino, from);
183182
if (fa) {

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,6 @@ xfs_ifork_init_attr(
282282
enum xfs_dinode_fmt format,
283283
xfs_extnum_t nextents)
284284
{
285-
ASSERT(!ip->i_af.if_present);
286-
287-
ip->i_af.if_present = 1;
288285
ip->i_af.if_format = format;
289286
ip->i_af.if_nextents = nextents;
290287
}
@@ -293,7 +290,6 @@ void
293290
xfs_ifork_zap_attr(
294291
struct xfs_inode *ip)
295292
{
296-
ASSERT(ip->i_af.if_present);
297293
ASSERT(ip->i_af.if_broot == NULL);
298294
ASSERT(ip->i_af.if_u1.if_data == NULL);
299295
ASSERT(ip->i_af.if_height == 0);
@@ -683,7 +679,6 @@ xfs_ifork_init_cow(
683679

684680
ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_cache,
685681
GFP_NOFS | __GFP_NOFAIL);
686-
ip->i_cowfp->if_present = 1;
687682
ip->i_cowfp->if_format = XFS_DINODE_FMT_EXTENTS;
688683
}
689684

@@ -722,7 +717,7 @@ xfs_ifork_verify_local_attr(
722717
struct xfs_ifork *ifp = &ip->i_af;
723718
xfs_failaddr_t fa;
724719

725-
if (!ifp->if_present)
720+
if (!XFS_IFORK_Q(ip))
726721
fa = __this_address;
727722
else
728723
fa = xfs_attr_shortform_verify(ip);

fs/xfs/libxfs/xfs_inode_fork.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ struct xfs_ifork {
2424
xfs_extnum_t if_nextents; /* # of extents in this fork */
2525
short if_broot_bytes; /* bytes allocated for root */
2626
int8_t if_format; /* format of this fork */
27-
int8_t if_present; /* 1 if present */
2827
};
2928

3029
/*

fs/xfs/xfs_attr_inactive.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,11 @@ xfs_attr_inactive(
362362

363363
/*
364364
* Invalidate and truncate the attribute fork extents. Make sure the
365-
* fork actually has attributes as otherwise the invalidation has no
365+
* fork actually has xattr blocks as otherwise the invalidation has no
366366
* blocks to read and returns an error. In this case, just do the fork
367367
* removal below.
368368
*/
369-
if (xfs_inode_hasattr(dp) &&
370-
dp->i_af.if_format != XFS_DINODE_FMT_LOCAL) {
369+
if (dp->i_af.if_nextents > 0) {
371370
error = xfs_attr3_root_inactive(&trans, dp);
372371
if (error)
373372
goto out_cancel;
@@ -388,10 +387,8 @@ xfs_attr_inactive(
388387
xfs_trans_cancel(trans);
389388
out_destroy_fork:
390389
/* kill the in-core attr fork before we drop the inode lock */
391-
if (dp->i_af.if_present) {
392-
xfs_idestroy_fork(&dp->i_af);
393-
xfs_ifork_zap_attr(dp);
394-
}
390+
xfs_idestroy_fork(&dp->i_af);
391+
xfs_ifork_zap_attr(dp);
395392
if (lock_mode)
396393
xfs_iunlock(dp, lock_mode);
397394
return error;

fs/xfs/xfs_attr_list.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ xfs_attr_shortform_list(
6161
int sbsize, nsbuf, count, i;
6262
int error = 0;
6363

64-
ASSERT(dp->i_af.if_present);
6564
sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data;
6665
ASSERT(sf != NULL);
6766
if (!sf->hdr.count)

fs/xfs/xfs_icache.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ xfs_inode_alloc(
102102
memset(&ip->i_af, 0, sizeof(ip->i_af));
103103
ip->i_af.if_format = XFS_DINODE_FMT_EXTENTS;
104104
memset(&ip->i_df, 0, sizeof(ip->i_df));
105-
ip->i_df.if_present = 1;
106105
ip->i_flags = 0;
107106
ip->i_delayed_blks = 0;
108107
ip->i_diflags2 = mp->m_ino_geo.new_diflags2;
@@ -132,10 +131,9 @@ xfs_inode_free_callback(
132131
break;
133132
}
134133

135-
if (ip->i_af.if_present) {
136-
xfs_idestroy_fork(&ip->i_af);
137-
xfs_ifork_zap_attr(ip);
138-
}
134+
xfs_idestroy_fork(&ip->i_af);
135+
xfs_ifork_zap_attr(ip);
136+
139137
if (ip->i_cowfp) {
140138
xfs_idestroy_fork(ip->i_cowfp);
141139
kmem_cache_free(xfs_ifork_cache, ip->i_cowfp);

fs/xfs/xfs_inode.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ xfs_ilock_attr_map_shared(
125125
{
126126
uint lock_mode = XFS_ILOCK_SHARED;
127127

128-
if (ip->i_af.if_present && xfs_need_iread_extents(&ip->i_af))
128+
if (XFS_IFORK_Q(ip) && xfs_need_iread_extents(&ip->i_af))
129129
lock_mode = XFS_ILOCK_EXCL;
130130
xfs_ilock(ip, lock_mode);
131131
return lock_mode;
@@ -1768,7 +1768,6 @@ xfs_inactive(
17681768
goto out;
17691769
}
17701770

1771-
ASSERT(!ip->i_af.if_present);
17721771
ASSERT(ip->i_forkoff == 0);
17731772

17741773
/*
@@ -3502,7 +3501,7 @@ xfs_iflush(
35023501
if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL &&
35033502
xfs_ifork_verify_local_data(ip))
35043503
goto flush_out;
3505-
if (ip->i_af.if_present &&
3504+
if (XFS_IFORK_Q(ip) &&
35063505
ip->i_af.if_format == XFS_DINODE_FMT_LOCAL &&
35073506
xfs_ifork_verify_local_attr(ip))
35083507
goto flush_out;

0 commit comments

Comments
 (0)