]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: Conditionally upgrade existing inodes to use large extent counters
authorChandan Babu R <chandan.babu@oracle.com>
Wed, 22 Jun 2022 19:28:52 +0000 (14:28 -0500)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 22 Jun 2022 19:28:52 +0000 (14:28 -0500)
Source kernel commit: 4f86bb4b66c999ad9ddcfd49fec93992eeba2715

This commit enables upgrading existing inodes to use large extent counters
provided that underlying filesystem's superblock has large extent counter
feature enabled.

Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Chandan Babu R <chandan.babu@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/xfs_attr.c
libxfs/xfs_bmap.c
libxfs/xfs_format.h
libxfs/xfs_inode_fork.c
libxfs/xfs_inode_fork.h

index 9a9da4594d1102c3dc00b032fdd85f65da3cf498..f08918024cf595c59c15ab39d86a053ca47abb0f 100644 (file)
@@ -776,6 +776,9 @@ xfs_attr_set(
        if (args->value || xfs_inode_hasattr(dp)) {
                error = xfs_iext_count_may_overflow(dp, XFS_ATTR_FORK,
                                XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
+               if (error == -EFBIG)
+                       error = xfs_iext_count_upgrade(args->trans, dp,
+                                       XFS_IEXT_ATTR_MANIP_CNT(rmt_blks));
                if (error)
                        goto out_trans_cancel;
        }
index 591d79c4033b4ceebf3d204f7a45ccf330207aba..793092460872bdb81efc27ec944e0ea69136e6b1 100644 (file)
@@ -4517,14 +4517,16 @@ xfs_bmapi_convert_delalloc(
                return error;
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, ip, 0);
 
        error = xfs_iext_count_may_overflow(ip, whichfork,
                        XFS_IEXT_ADD_NOSPLIT_CNT);
+       if (error == -EFBIG)
+               error = xfs_iext_count_upgrade(tp, ip,
+                               XFS_IEXT_ADD_NOSPLIT_CNT);
        if (error)
                goto out_trans_cancel;
 
-       xfs_trans_ijoin(tp, ip, 0);
-
        if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) ||
            bma.got.br_startoff > offset_fsb) {
                /*
index 43de892d030579cd92457575011b1a99b9e33345..3beaa819b790e32a601fc2089b6769b2285b3726 100644 (file)
@@ -934,6 +934,17 @@ enum xfs_dinode_fmt {
 #define XFS_MAX_EXTCNT_DATA_FORK_SMALL ((xfs_extnum_t)((1ULL << 31) - 1))
 #define XFS_MAX_EXTCNT_ATTR_FORK_SMALL ((xfs_extnum_t)((1ULL << 15) - 1))
 
+/*
+ * When we upgrade an inode to the large extent counts, the maximum value by
+ * which the extent count can increase is bound by the change in size of the
+ * on-disk field. No upgrade operation should ever be adding more than a few
+ * tens of extents, so if we get a really large value it is a sign of a code bug
+ * or corruption.
+ */
+#define XFS_MAX_EXTCNT_UPGRADE_NR      \
+       min(XFS_MAX_EXTCNT_ATTR_FORK_LARGE - XFS_MAX_EXTCNT_ATTR_FORK_SMALL,    \
+           XFS_MAX_EXTCNT_DATA_FORK_LARGE - XFS_MAX_EXTCNT_DATA_FORK_SMALL)
+
 /*
  * Inode minimum and maximum sizes.
  */
index 568c0ff4e5cdd535a1f28845247202b32a7c7f60..da592329188ef710ac4baeffc6998116f334d1ea 100644 (file)
@@ -754,3 +754,27 @@ xfs_iext_count_may_overflow(
 
        return 0;
 }
+
+/*
+ * Upgrade this inode's extent counter fields to be able to handle a potential
+ * increase in the extent count by nr_to_add.  Normally this is the same
+ * quantity that caused xfs_iext_count_may_overflow() to return -EFBIG.
+ */
+int
+xfs_iext_count_upgrade(
+       struct xfs_trans        *tp,
+       struct xfs_inode        *ip,
+       uint                    nr_to_add)
+{
+       ASSERT(nr_to_add <= XFS_MAX_EXTCNT_UPGRADE_NR);
+
+       if (!xfs_has_large_extent_counts(ip->i_mount) ||
+           xfs_inode_has_large_extent_counts(ip) ||
+           XFS_TEST_ERROR(false, ip->i_mount, XFS_ERRTAG_REDUCE_MAX_IEXTENTS))
+               return -EFBIG;
+
+       ip->i_diflags2 |= XFS_DIFLAG2_NREXT64;
+       xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+
+       return 0;
+}
index 6f9d69f8896e05ad6a719339b774b709348c9ad1..4f68c1f20beb386f2009062bb44ab1488b97eafa 100644 (file)
@@ -275,6 +275,8 @@ int xfs_ifork_verify_local_data(struct xfs_inode *ip);
 int xfs_ifork_verify_local_attr(struct xfs_inode *ip);
 int xfs_iext_count_may_overflow(struct xfs_inode *ip, int whichfork,
                int nr_to_add);
+int xfs_iext_count_upgrade(struct xfs_trans *tp, struct xfs_inode *ip,
+               uint nr_to_add);
 
 /* returns true if the fork has extents but they are not read in yet. */
 static inline bool xfs_need_iread_extents(struct xfs_ifork *ifp)