Skip to content

Commit 25576c5

Browse files
Christoph HellwigChandan Babu R
authored andcommitted
xfs: simplify iext overflow checking and upgrade
Currently the calls to xfs_iext_count_may_overflow and xfs_iext_count_upgrade are always paired. Merge them into a single function to simplify the callers and the actual check and upgrade logic itself. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: "Darrick J. Wong" <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com> Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
1 parent 86de848 commit 25576c5

File tree

10 files changed

+41
-87
lines changed

10 files changed

+41
-87
lines changed

fs/xfs/libxfs/xfs_attr.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,11 +1050,8 @@ xfs_attr_set(
10501050
return error;
10511051

10521052
if (op != XFS_ATTRUPDATE_REMOVE || xfs_inode_hasattr(dp)) {
1053-
error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK,
1053+
error = xfs_iext_count_extend(args->trans, dp, XFS_ATTR_FORK,
10541054
XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
1055-
if (error == -EFBIG)
1056-
error = xfs_iext_count_upgrade(args->trans, dp,
1057-
XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
10581055
if (error)
10591056
goto out_trans_cancel;
10601057
}

fs/xfs/libxfs/xfs_bmap.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4651,11 +4651,8 @@ xfs_bmapi_convert_one_delalloc(
46514651
xfs_ilock(ip, XFS_ILOCK_EXCL);
46524652
xfs_trans_ijoin(tp, ip, 0);
46534653

4654-
error = xfs_iext_count_may_overflow(ip, whichfork,
4654+
error = xfs_iext_count_extend(tp, ip, whichfork,
46554655
XFS_IEXT_ADD_NOSPLIT_CNT);
4656-
if (error == -EFBIG)
4657-
error = xfs_iext_count_upgrade(tp, ip,
4658-
XFS_IEXT_ADD_NOSPLIT_CNT);
46594656
if (error)
46604657
goto out_trans_cancel;
46614658

fs/xfs/libxfs/xfs_inode_fork.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -765,53 +765,46 @@ xfs_ifork_verify_local_attr(
765765
return 0;
766766
}
767767

768+
/*
769+
* Check if the inode fork supports adding nr_to_add more extents.
770+
*
771+
* If it doesn't but we can upgrade it to large extent counters, do the upgrade.
772+
* If we can't upgrade or are already using big counters but still can't fit the
773+
* additional extents, return -EFBIG.
774+
*/
768775
int
769-
xfs_iext_count_may_overflow(
776+
xfs_iext_count_extend(
777+
struct xfs_trans *tp,
770778
struct xfs_inode *ip,
771779
int whichfork,
772-
int nr_to_add)
780+
uint nr_to_add)
773781
{
782+
struct xfs_mount *mp = ip->i_mount;
783+
bool has_large =
784+
xfs_inode_has_large_extent_counts(ip);
774785
struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork);
775-
uint64_t max_exts;
776786
uint64_t nr_exts;
777787

788+
ASSERT(nr_to_add <= XFS_MAX_EXTCNT_UPGRADE_NR);
789+
778790
if (whichfork == XFS_COW_FORK)
779791
return 0;
780792

781-
max_exts = xfs_iext_max_nextents(xfs_inode_has_large_extent_counts(ip),
782-
whichfork);
783-
784-
if (XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS))
785-
max_exts = 10;
786-
793+
/* no point in upgrading if if_nextents overflows */
787794
nr_exts = ifp->if_nextents + nr_to_add;
788-
if (nr_exts < ifp->if_nextents || nr_exts > max_exts)
795+
if (nr_exts < ifp->if_nextents)
789796
return -EFBIG;
790797

791-
return 0;
792-
}
793-
794-
/*
795-
* Upgrade this inode's extent counter fields to be able to handle a potential
796-
* increase in the extent count by nr_to_add. Normally this is the same
797-
* quantity that caused xfs_iext_count_may_overflow() to return -EFBIG.
798-
*/
799-
int
800-
xfs_iext_count_upgrade(
801-
struct xfs_trans *tp,
802-
struct xfs_inode *ip,
803-
uint nr_to_add)
804-
{
805-
ASSERT(nr_to_add <= XFS_MAX_EXTCNT_UPGRADE_NR);
806-
807-
if (!xfs_has_large_extent_counts(ip->i_mount) ||
808-
xfs_inode_has_large_extent_counts(ip) ||
809-
XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS))
798+
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REDUCE_MAX_IEXTENTS) &&
799+
nr_exts > 10)
810800
return -EFBIG;
811801

812-
ip->i_diflags2 |= XFS_DIFLAG2_NREXT64;
813-
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
814-
802+
if (nr_exts > xfs_iext_max_nextents(has_large, whichfork)) {
803+
if (has_large || !xfs_has_large_extent_counts(mp))
804+
return -EFBIG;
805+
ip->i_diflags2 |= XFS_DIFLAG2_NREXT64;
806+
xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
807+
}
815808
return 0;
816809
}
817810

fs/xfs/libxfs/xfs_inode_fork.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,8 @@ extern void xfs_ifork_init_cow(struct xfs_inode *ip);
256256

257257
int xfs_ifork_verify_local_data(struct xfs_inode *ip);
258258
int xfs_ifork_verify_local_attr(struct xfs_inode *ip);
259-
int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork,
260-
int nr_to_add);
261-
int xfs_iext_count_upgrade(struct xfs_trans *tp, struct xfs_inode *ip,
262-
uint nr_to_add);
259+
int xfs_iext_count_extend(struct xfs_trans *tp, struct xfs_inode *ip,
260+
int whichfork, uint nr_to_add);
263261
bool xfs_ifork_is_realtime(struct xfs_inode *ip, int whichfork);
264262

265263
/* returns true if the fork has extents but they are not read in yet. */

fs/xfs/xfs_bmap_item.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,7 @@ xfs_bmap_recover_work(
524524
else
525525
iext_delta = XFS_IEXT_PUNCH_HOLE_CNT;
526526

527-
error = xfs_iext_count_may_overflow(ip, work->bi_whichfork, iext_delta);
528-
if (error == -EFBIG)
529-
error = xfs_iext_count_upgrade(tp, ip, iext_delta);
527+
error = xfs_iext_count_extend(tp, ip, work->bi_whichfork, iext_delta);
530528
if (error)
531529
goto err_cancel;
532530

fs/xfs/xfs_bmap_util.c

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -710,11 +710,8 @@ xfs_alloc_file_space(
710710
if (error)
711711
break;
712712

713-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
713+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
714714
XFS_IEXT_ADD_NOSPLIT_CNT);
715-
if (error == -EFBIG)
716-
error = xfs_iext_count_upgrade(tp, ip,
717-
XFS_IEXT_ADD_NOSPLIT_CNT);
718715
if (error)
719716
goto error;
720717

@@ -771,10 +768,8 @@ xfs_unmap_extent(
771768
if (error)
772769
return error;
773770

774-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
771+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
775772
XFS_IEXT_PUNCH_HOLE_CNT);
776-
if (error == -EFBIG)
777-
error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT);
778773
if (error)
779774
goto out_trans_cancel;
780775

@@ -1050,10 +1045,8 @@ xfs_insert_file_space(
10501045
xfs_ilock(ip, XFS_ILOCK_EXCL);
10511046
xfs_trans_ijoin(tp, ip, 0);
10521047

1053-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
1048+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
10541049
XFS_IEXT_PUNCH_HOLE_CNT);
1055-
if (error == -EFBIG)
1056-
error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT);
10571050
if (error)
10581051
goto out_trans_cancel;
10591052

@@ -1279,23 +1272,17 @@ xfs_swap_extent_rmap(
12791272
trace_xfs_swap_extent_rmap_remap_piece(tip, &uirec);
12801273

12811274
if (xfs_bmap_is_real_extent(&uirec)) {
1282-
error = xfs_iext_count_may_overflow(ip,
1275+
error = xfs_iext_count_extend(tp, ip,
12831276
XFS_DATA_FORK,
12841277
XFS_IEXT_SWAP_RMAP_CNT);
1285-
if (error == -EFBIG)
1286-
error = xfs_iext_count_upgrade(tp, ip,
1287-
XFS_IEXT_SWAP_RMAP_CNT);
12881278
if (error)
12891279
goto out;
12901280
}
12911281

12921282
if (xfs_bmap_is_real_extent(&irec)) {
1293-
error = xfs_iext_count_may_overflow(tip,
1283+
error = xfs_iext_count_extend(tp, tip,
12941284
XFS_DATA_FORK,
12951285
XFS_IEXT_SWAP_RMAP_CNT);
1296-
if (error == -EFBIG)
1297-
error = xfs_iext_count_upgrade(tp, ip,
1298-
XFS_IEXT_SWAP_RMAP_CNT);
12991286
if (error)
13001287
goto out;
13011288
}

fs/xfs/xfs_dquot.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,11 +341,8 @@ xfs_dquot_disk_alloc(
341341
goto err_cancel;
342342
}
343343

344-
error = xfs_iext_count_may_overflow(quotip, XFS_DATA_FORK,
344+
error = xfs_iext_count_extend(tp, quotip, XFS_DATA_FORK,
345345
XFS_IEXT_ADD_NOSPLIT_CNT);
346-
if (error == -EFBIG)
347-
error = xfs_iext_count_upgrade(tp, quotip,
348-
XFS_IEXT_ADD_NOSPLIT_CNT);
349346
if (error)
350347
goto err_cancel;
351348

fs/xfs/xfs_iomap.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,7 @@ xfs_iomap_write_direct(
299299
if (error)
300300
return error;
301301

302-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, nr_exts);
303-
if (error == -EFBIG)
304-
error = xfs_iext_count_upgrade(tp, ip, nr_exts);
302+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, nr_exts);
305303
if (error)
306304
goto out_trans_cancel;
307305

@@ -617,11 +615,8 @@ xfs_iomap_write_unwritten(
617615
if (error)
618616
return error;
619617

620-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
618+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
621619
XFS_IEXT_WRITE_UNWRITTEN_CNT);
622-
if (error == -EFBIG)
623-
error = xfs_iext_count_upgrade(tp, ip,
624-
XFS_IEXT_WRITE_UNWRITTEN_CNT);
625620
if (error)
626621
goto error_on_bmapi_transaction;
627622

fs/xfs/xfs_reflink.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,8 @@ xfs_reflink_end_cow_extent(
754754
del = got;
755755
xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb);
756756

757-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
757+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
758758
XFS_IEXT_REFLINK_END_COW_CNT);
759-
if (error == -EFBIG)
760-
error = xfs_iext_count_upgrade(tp, ip,
761-
XFS_IEXT_REFLINK_END_COW_CNT);
762759
if (error)
763760
goto out_cancel;
764761

@@ -1258,9 +1255,7 @@ xfs_reflink_remap_extent(
12581255
if (dmap_written)
12591256
++iext_delta;
12601257

1261-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, iext_delta);
1262-
if (error == -EFBIG)
1263-
error = xfs_iext_count_upgrade(tp, ip, iext_delta);
1258+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, iext_delta);
12641259
if (error)
12651260
goto out_cancel;
12661261

fs/xfs/xfs_rtalloc.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,8 @@ xfs_growfs_rt_alloc(
695695
xfs_ilock(ip, XFS_ILOCK_EXCL);
696696
xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
697697

698-
error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK,
698+
error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK,
699699
XFS_IEXT_ADD_NOSPLIT_CNT);
700-
if (error == -EFBIG)
701-
error = xfs_iext_count_upgrade(tp, ip,
702-
XFS_IEXT_ADD_NOSPLIT_CNT);
703700
if (error)
704701
goto out_trans_cancel;
705702

0 commit comments

Comments
 (0)