]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: apply rt extent alignment constraints to CoW extsize hint
authorDarrick J. Wong <djwong@kernel.org>
Wed, 29 May 2024 04:13:19 +0000 (21:13 -0700)
committerChristoph Hellwig <hch@lst.de>
Mon, 12 Aug 2024 11:53:09 +0000 (13:53 +0200)
The copy-on-write extent size hint is subject to the same alignment
constraints as the regular extent size hint.  Since we're in the process
of adding reflink (and therefore CoW) to the realtime device, we must
apply the same scattered rextsize alignment validation strategies to
both hints to deal with the possibility of rextsize changing.

Therefore, fix the inode validator to perform rextsize alignment checks
on regular realtime files, and to remove misaligned directory hints.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_inode_buf.c
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_ioctl.c

index f3eb45f016ae87963ac5668d0c7a98314a3391d8..2d50fbbd66f83f58512ca7af1ea6cbf883fd3394 100644 (file)
@@ -902,11 +902,29 @@ xfs_inode_validate_cowextsize(
        bool                            rt_flag;
        bool                            hint_flag;
        uint32_t                        cowextsize_bytes;
+       uint32_t                        blocksize_bytes;
 
        rt_flag = (flags & XFS_DIFLAG_REALTIME);
        hint_flag = (flags2 & XFS_DIFLAG2_COWEXTSIZE);
        cowextsize_bytes = XFS_FSB_TO_B(mp, cowextsize);
 
+       /*
+        * Similar to extent size hints, a directory can be configured to
+        * propagate realtime status and a CoW extent size hint to newly
+        * created files even if there is no realtime device, and the hints on
+        * disk can become misaligned if the sysadmin changes the rt extent
+        * size while adding the realtime device.
+        *
+        * Therefore, we can only enforce the rextsize alignment check against
+        * regular realtime files, and rely on callers to decide when alignment
+        * checks are appropriate, and fix things up as needed.
+        */
+
+       if (rt_flag)
+               blocksize_bytes = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize);
+       else
+               blocksize_bytes = mp->m_sb.sb_blocksize;
+
        if (hint_flag && !xfs_has_reflink(mp))
                return __this_address;
 
@@ -920,16 +938,13 @@ xfs_inode_validate_cowextsize(
        if (mode && !hint_flag && cowextsize != 0)
                return __this_address;
 
-       if (hint_flag && rt_flag)
-               return __this_address;
-
-       if (cowextsize_bytes % mp->m_sb.sb_blocksize)
+       if (cowextsize_bytes % blocksize_bytes)
                return __this_address;
 
        if (cowextsize > XFS_MAX_BMBT_EXTLEN)
                return __this_address;
 
-       if (cowextsize > mp->m_sb.sb_agblocks / 2)
+       if (!rt_flag && cowextsize > mp->m_sb.sb_agblocks / 2)
                return __this_address;
 
        return NULL;
index 1275e8a35ea4fddedfc696e32f62492435d45511..5338c7fa12c972e6ca0c859678315534e5c7a0f4 100644 (file)
@@ -157,6 +157,20 @@ xfs_inode_item_precommit(
        if (flags & XFS_ILOG_IVERSION)
                flags = ((flags & ~XFS_ILOG_IVERSION) | XFS_ILOG_CORE);
 
+       /*
+        * Inode verifiers do not check that the CoW extent size hint is an
+        * integer multiple of the rt extent size on a directory with both
+        * rtinherit and cowextsize flags set.  If we're logging a directory
+        * that is misconfigured in this way, clear the hint.
+        */
+       if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
+           (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) &&
+           xfs_extlen_to_rtxmod(ip->i_mount, ip->i_cowextsize) > 0) {
+               ip->i_diflags2 &= ~XFS_DIFLAG2_COWEXTSIZE;
+               ip->i_cowextsize = 0;
+               flags |= XFS_ILOG_CORE;
+       }
+
        if (!iip->ili_item.li_buf) {
                struct xfs_buf  *bp;
                int             error;
index ccaaf9dc5cfad3f411ae044e44b994777ad6cff4..99f461ccf66bdda7b433bb80e8a711520aa4aa27 100644 (file)
@@ -467,8 +467,21 @@ xfs_fill_fsxattr(
                }
        }
 
-       if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
-               fa->fsx_cowextsize = XFS_FSB_TO_B(mp, ip->i_cowextsize);
+       if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE) {
+               /*
+                * Don't let a misaligned CoW extent size hint on a directory
+                * escape to userspace if it won't pass the setattr checks
+                * later.
+                */
+               if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
+                   ip->i_cowextsize % mp->m_sb.sb_rextsize > 0) {
+                       fa->fsx_xflags &= ~FS_XFLAG_COWEXTSIZE;
+                       fa->fsx_cowextsize = 0;
+               } else {
+                       fa->fsx_cowextsize = XFS_FSB_TO_B(mp, ip->i_cowextsize);
+               }
+       }
+
        fa->fsx_projid = ip->i_projid;
        if (ifp && !xfs_need_iread_extents(ifp))
                fa->fsx_nextents = xfs_iext_count(ifp);