Skip to content

Commit b2197a3

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: remove XFS_IFEXTENTS
The in-memory XFS_IFEXTENTS is now only used to check if an inode with extents still needs the extents to be read into memory before doing operations that need the extent map. Add a new xfs_need_iread_extents helper that returns true for btree format forks that do not have any entries in the in-memory extent btree, and use that instead of checking the XFS_IFEXTENTS flag. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 0779f4a commit b2197a3

File tree

12 files changed

+19
-49
lines changed

12 files changed

+19
-49
lines changed

fs/xfs/libxfs/xfs_attr_leaf.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,10 +651,8 @@ xfs_attr_shortform_create(
651651
trace_xfs_attr_sf_create(args);
652652

653653
ASSERT(ifp->if_bytes == 0);
654-
if (ifp->if_format == XFS_DINODE_FMT_EXTENTS) {
655-
ifp->if_flags &= ~XFS_IFEXTENTS; /* just in case */
654+
if (ifp->if_format == XFS_DINODE_FMT_EXTENTS)
656655
ifp->if_format = XFS_DINODE_FMT_LOCAL;
657-
}
658656
xfs_idata_realloc(dp, sizeof(*hdr), XFS_ATTR_FORK);
659657
hdr = (struct xfs_attr_sf_hdr *)ifp->if_u1.if_data;
660658
memset(hdr, 0, sizeof(*hdr));

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ xfs_bmap_btree_to_extents(
605605

606606
ASSERT(cur);
607607
ASSERT(whichfork != XFS_COW_FORK);
608-
ASSERT(ifp->if_flags & XFS_IFEXTENTS);
608+
ASSERT(!xfs_need_iread_extents(ifp));
609609
ASSERT(ifp->if_format == XFS_DINODE_FMT_BTREE);
610610
ASSERT(be16_to_cpu(rblock->bb_level) == 1);
611611
ASSERT(be16_to_cpu(rblock->bb_numrecs) == 1);
@@ -805,7 +805,6 @@ xfs_bmap_local_to_extents_empty(
805805
ASSERT(ifp->if_nextents == 0);
806806

807807
xfs_bmap_forkoff_reset(ip, whichfork);
808-
ifp->if_flags |= XFS_IFEXTENTS;
809808
ifp->if_u1.if_root = NULL;
810809
ifp->if_height = 0;
811810
ifp->if_format = XFS_DINODE_FMT_EXTENTS;
@@ -849,7 +848,6 @@ xfs_bmap_local_to_extents(
849848

850849
flags = 0;
851850
error = 0;
852-
ASSERT(!(ifp->if_flags & XFS_IFEXTENTS));
853851
memset(&args, 0, sizeof(args));
854852
args.tp = tp;
855853
args.mp = ip->i_mount;
@@ -1098,7 +1096,6 @@ xfs_bmap_add_attrfork(
10981096
ASSERT(ip->i_afp == NULL);
10991097

11001098
ip->i_afp = xfs_ifork_alloc(XFS_DINODE_FMT_EXTENTS, 0);
1101-
ip->i_afp->if_flags = XFS_IFEXTENTS;
11021099
logflags = 0;
11031100
switch (ip->i_df.if_format) {
11041101
case XFS_DINODE_FMT_LOCAL:
@@ -1224,16 +1221,11 @@ xfs_iread_extents(
12241221
struct xfs_btree_cur *cur;
12251222
int error;
12261223

1227-
if (ifp->if_flags & XFS_IFEXTENTS)
1224+
if (!xfs_need_iread_extents(ifp))
12281225
return 0;
12291226

12301227
ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
12311228

1232-
if (XFS_IS_CORRUPT(mp, ifp->if_format != XFS_DINODE_FMT_BTREE)) {
1233-
error = -EFSCORRUPTED;
1234-
goto out;
1235-
}
1236-
12371229
ir.loaded = 0;
12381230
xfs_iext_first(ifp, &ir.icur);
12391231
cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork);
@@ -1248,8 +1240,6 @@ xfs_iread_extents(
12481240
goto out;
12491241
}
12501242
ASSERT(ir.loaded == xfs_iext_count(ifp));
1251-
1252-
ifp->if_flags |= XFS_IFEXTENTS;
12531243
return 0;
12541244
out:
12551245
xfs_iext_destroy(ifp);

fs/xfs/libxfs/xfs_dir2_sf.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,6 @@ xfs_dir2_sf_create(
827827
* convert it to local format.
828828
*/
829829
if (dp->i_df.if_format == XFS_DINODE_FMT_EXTENTS) {
830-
dp->i_df.if_flags &= ~XFS_IFEXTENTS; /* just in case */
831830
dp->i_df.if_format = XFS_DINODE_FMT_LOCAL;
832831
xfs_trans_log_inode(args->trans, dp, XFS_ILOG_CORE);
833832
}

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ xfs_init_local_fork(
6060
}
6161

6262
ifp->if_bytes = size;
63-
ifp->if_flags &= ~XFS_IFEXTENTS;
6463
}
6564

6665
/*
@@ -150,7 +149,6 @@ xfs_iformat_extents(
150149
xfs_iext_next(ifp, &icur);
151150
}
152151
}
153-
ifp->if_flags |= XFS_IFEXTENTS;
154152
return 0;
155153
}
156154

@@ -212,7 +210,6 @@ xfs_iformat_btree(
212210
*/
213211
xfs_bmdr_to_bmbt(ip, dfp, XFS_DFORK_SIZE(dip, ip->i_mount, whichfork),
214212
ifp->if_broot, size);
215-
ifp->if_flags &= ~XFS_IFEXTENTS;
216213

217214
ifp->if_bytes = 0;
218215
ifp->if_u1.if_root = NULL;
@@ -622,8 +619,6 @@ xfs_iflush_fork(
622619
break;
623620

624621
case XFS_DINODE_FMT_EXTENTS:
625-
ASSERT((ifp->if_flags & XFS_IFEXTENTS) ||
626-
!(iip->ili_fields & extflag[whichfork]));
627622
if ((iip->ili_fields & extflag[whichfork]) &&
628623
(ifp->if_bytes > 0)) {
629624
ASSERT(ifp->if_nextents > 0);
@@ -683,7 +678,6 @@ xfs_ifork_init_cow(
683678

684679
ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_zone,
685680
GFP_NOFS | __GFP_NOFAIL);
686-
ip->i_cowfp->if_flags = XFS_IFEXTENTS;
687681
ip->i_cowfp->if_format = XFS_DINODE_FMT_EXTENTS;
688682
}
689683

fs/xfs/libxfs/xfs_inode_fork.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,10 @@ struct xfs_ifork {
2222
char *if_data; /* inline file data */
2323
} if_u1;
2424
short if_broot_bytes; /* bytes allocated for root */
25-
unsigned char if_flags; /* per-fork flags */
2625
int8_t if_format; /* format of this fork */
2726
xfs_extnum_t if_nextents; /* # of extents in this fork */
2827
};
2928

30-
/*
31-
* Per-fork incore inode flags.
32-
*/
33-
#define XFS_IFEXTENTS 0x02 /* All extent pointers are read in */
34-
3529
/*
3630
* Worst-case increase in the fork extent count when we're adding a single
3731
* extent to a fork and there's no possibility of splitting an existing mapping.
@@ -236,4 +230,10 @@ int xfs_ifork_verify_local_attr(struct xfs_inode *ip);
236230
int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork,
237231
int nr_to_add);
238232

233+
/* returns true if the fork has extents but they are not read in yet. */
234+
static inline bool xfs_need_iread_extents(struct xfs_ifork *ifp)
235+
{
236+
return ifp->if_format == XFS_DINODE_FMT_BTREE && ifp->if_height == 0;
237+
}
238+
239239
#endif /* __XFS_INODE_FORK_H__ */

fs/xfs/scrub/bmap.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ xchk_bmap_btree(
447447
int error;
448448

449449
/* Load the incore bmap cache if it's not loaded. */
450-
info->was_loaded = ifp->if_flags & XFS_IFEXTENTS;
450+
info->was_loaded = !xfs_need_iread_extents(ifp);
451451

452452
error = xfs_iread_extents(sc->tp, ip, whichfork);
453453
if (!xchk_fblock_process_error(sc, whichfork, 0, &error))
@@ -673,10 +673,6 @@ xchk_bmap(
673673
/* No mappings to check. */
674674
goto out;
675675
case XFS_DINODE_FMT_EXTENTS:
676-
if (!(ifp->if_flags & XFS_IFEXTENTS)) {
677-
xchk_fblock_set_corrupt(sc, whichfork, 0);
678-
goto out;
679-
}
680676
break;
681677
case XFS_DINODE_FMT_BTREE:
682678
if (whichfork == XFS_COW_FORK) {

fs/xfs/xfs_aops.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,7 @@ xfs_map_blocks(
291291
cow_fsb = NULLFILEOFF;
292292
whichfork = XFS_DATA_FORK;
293293
xfs_ilock(ip, XFS_ILOCK_SHARED);
294-
ASSERT(ip->i_df.if_format != XFS_DINODE_FMT_BTREE ||
295-
(ip->i_df.if_flags & XFS_IFEXTENTS));
294+
ASSERT(!xfs_need_iread_extents(&ip->i_df));
296295

297296
/*
298297
* Check if this is offset is covered by a COW extents, and if yes use

fs/xfs/xfs_bmap_util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ xfs_bmap_punch_delalloc_range(
554554
struct xfs_iext_cursor icur;
555555
int error = 0;
556556

557-
ASSERT(ifp->if_flags & XFS_IFEXTENTS);
557+
ASSERT(!xfs_need_iread_extents(ifp));
558558

559559
xfs_ilock(ip, XFS_ILOCK_EXCL);
560560
if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got))
@@ -625,7 +625,7 @@ xfs_can_free_eofblocks(
625625
return false;
626626

627627
/* If we haven't read in the extent list, then don't do it now. */
628-
if (!(ip->i_df.if_flags & XFS_IFEXTENTS))
628+
if (xfs_need_iread_extents(&ip->i_df))
629629
return false;
630630

631631
/*

fs/xfs/xfs_inode.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ xfs_ilock_data_map_shared(
111111
{
112112
uint lock_mode = XFS_ILOCK_SHARED;
113113

114-
if (ip->i_df.if_format == XFS_DINODE_FMT_BTREE &&
115-
(ip->i_df.if_flags & XFS_IFEXTENTS) == 0)
114+
if (xfs_need_iread_extents(&ip->i_df))
116115
lock_mode = XFS_ILOCK_EXCL;
117116
xfs_ilock(ip, lock_mode);
118117
return lock_mode;
@@ -124,9 +123,7 @@ xfs_ilock_attr_map_shared(
124123
{
125124
uint lock_mode = XFS_ILOCK_SHARED;
126125

127-
if (ip->i_afp &&
128-
ip->i_afp->if_format == XFS_DINODE_FMT_BTREE &&
129-
(ip->i_afp->if_flags & XFS_IFEXTENTS) == 0)
126+
if (ip->i_afp && xfs_need_iread_extents(ip->i_afp))
130127
lock_mode = XFS_ILOCK_EXCL;
131128
xfs_ilock(ip, lock_mode);
132129
return lock_mode;
@@ -843,7 +840,6 @@ xfs_init_new_inode(
843840
case S_IFBLK:
844841
case S_IFSOCK:
845842
ip->i_df.if_format = XFS_DINODE_FMT_DEV;
846-
ip->i_df.if_flags = 0;
847843
flags |= XFS_ILOG_DEV;
848844
break;
849845
case S_IFREG:
@@ -855,7 +851,6 @@ xfs_init_new_inode(
855851
/* FALLTHROUGH */
856852
case S_IFLNK:
857853
ip->i_df.if_format = XFS_DINODE_FMT_EXTENTS;
858-
ip->i_df.if_flags = XFS_IFEXTENTS;
859854
ip->i_df.if_bytes = 0;
860855
ip->i_df.if_u1.if_root = NULL;
861856
break;
@@ -875,7 +870,6 @@ xfs_init_new_inode(
875870
if (init_xattrs && xfs_sb_version_hasattr(&mp->m_sb)) {
876871
ip->i_forkoff = xfs_default_attroffset(ip) >> 3;
877872
ip->i_afp = xfs_ifork_alloc(XFS_DINODE_FMT_EXTENTS, 0);
878-
ip->i_afp->if_flags = XFS_IFEXTENTS;
879873
}
880874

881875
/*

fs/xfs/xfs_ioctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ xfs_fill_fsxattr(
11261126
if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
11271127
fa->fsx_cowextsize = XFS_FSB_TO_B(mp, ip->i_cowextsize);
11281128
fa->fsx_projid = ip->i_projid;
1129-
if (ifp && (ifp->if_flags & XFS_IFEXTENTS))
1129+
if (ifp && !xfs_need_iread_extents(ifp))
11301130
fa->fsx_nextents = xfs_iext_count(ifp);
11311131
else
11321132
fa->fsx_nextents = xfs_ifork_nextents(ifp);

0 commit comments

Comments
 (0)