xfs: create a helper to compute leftovers of realtime extents
authorDarrick J. Wong <djwong@kernel.org>
Mon, 16 Oct 2023 16:34:39 +0000 (09:34 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 17 Oct 2023 23:24:22 +0000 (16:24 -0700)
Create a helper to compute the misalignment between a file extent
(xfs_extlen_t) and a realtime extent.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_rtbitmap.h
fs/xfs/scrub/inode.c
fs/xfs/xfs_bmap_util.c
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_ioctl.c

index 4e7de4f2fd7ac5a5ae1c2053ee1b71051c3c0977..19203699b9925ccb95d83bfaaa191fe2bc2118d6 100644 (file)
@@ -2989,7 +2989,7 @@ xfs_bmap_extsize_align(
         * If realtime, and the result isn't a multiple of the realtime
         * extent size we need to remove blocks until it is.
         */
-       if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) {
+       if (rt && (temp = xfs_extlen_to_rtxmod(mp, align_alen))) {
                /*
                 * We're not covering the original request, or
                 * we won't be able to once we fix the length.
@@ -3016,7 +3016,7 @@ xfs_bmap_extsize_align(
                else {
                        align_alen -= orig_off - align_off;
                        align_off = orig_off;
-                       align_alen -= align_alen % mp->m_sb.sb_rextsize;
+                       align_alen -= xfs_extlen_to_rtxmod(mp, align_alen);
                }
                /*
                 * Result doesn't cover the request, fail it.
index 099ea8902aaaf59a334bfec54526af6418b05273..b6a4c46bddc0a4df32f682e676c33dd898440c4f 100644 (file)
@@ -22,6 +22,15 @@ xfs_rtxlen_to_extlen(
        return rtxlen * mp->m_sb.sb_rextsize;
 }
 
+/* Compute the misalignment between an extent length and a realtime extent .*/
+static inline unsigned int
+xfs_extlen_to_rtxmod(
+       struct xfs_mount        *mp,
+       xfs_extlen_t            len)
+{
+       return len % mp->m_sb.sb_rextsize;
+}
+
 /*
  * Functions for walking free space rtextents in the realtime bitmap.
  */
index 59d7912fb75f1eae7ad88fe4acac9ae95553f135..889f556bc98f60cde87832cd0d1612cf49d7c919 100644 (file)
@@ -20,6 +20,7 @@
 #include "xfs_reflink.h"
 #include "xfs_rmap.h"
 #include "xfs_bmap_util.h"
+#include "xfs_rtbitmap.h"
 #include "scrub/scrub.h"
 #include "scrub/common.h"
 #include "scrub/btree.h"
@@ -225,7 +226,7 @@ xchk_inode_extsize(
         */
        if ((flags & XFS_DIFLAG_RTINHERIT) &&
            (flags & XFS_DIFLAG_EXTSZINHERIT) &&
-           value % sc->mp->m_sb.sb_rextsize > 0)
+           xfs_extlen_to_rtxmod(sc->mp, value) > 0)
                xchk_ino_set_warning(sc, ino);
 }
 
index 2d747084c1993092acf906144823fdbc08ab26a2..8895184ff90a29066e5212509a1d63644c2333f7 100644 (file)
@@ -97,7 +97,7 @@ retry:
        if (error)
                return error;
        ASSERT(ap->length);
-       ASSERT(ap->length % mp->m_sb.sb_rextsize == 0);
+       ASSERT(xfs_extlen_to_rtxmod(mp, ap->length) == 0);
 
        /*
         * If we shifted the file offset downward to satisfy an extent size
index 127b2410eb206fada51f272d6717b1e6f437b16a..3183d0b03e0bc7abe1cd9104e1c712bc5e985820 100644 (file)
@@ -19,6 +19,7 @@
 #include "xfs_log.h"
 #include "xfs_log_priv.h"
 #include "xfs_error.h"
+#include "xfs_rtbitmap.h"
 
 #include <linux/iversion.h>
 
@@ -107,7 +108,7 @@ xfs_inode_item_precommit(
         */
        if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
            (ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT) &&
-           (ip->i_extsize % ip->i_mount->m_sb.sb_rextsize) > 0) {
+           xfs_extlen_to_rtxmod(ip->i_mount, ip->i_extsize) > 0) {
                ip->i_diflags &= ~(XFS_DIFLAG_EXTSIZE |
                                   XFS_DIFLAG_EXTSZINHERIT);
                ip->i_extsize = 0;
index 55bb01173cde8c06099a79b2bcd631fea25bf771..a82470e027f7278ac4b3271cd67a27ed97235c77 100644 (file)
@@ -38,6 +38,7 @@
 #include "xfs_reflink.h"
 #include "xfs_ioctl.h"
 #include "xfs_xattr.h"
+#include "xfs_rtbitmap.h"
 
 #include <linux/mount.h>
 #include <linux/namei.h>
@@ -1004,7 +1005,7 @@ xfs_fill_fsxattr(
                 * later.
                 */
                if ((ip->i_diflags & XFS_DIFLAG_RTINHERIT) &&
-                   ip->i_extsize % mp->m_sb.sb_rextsize > 0) {
+                   xfs_extlen_to_rtxmod(mp, ip->i_extsize) > 0) {
                        fa->fsx_xflags &= ~(FS_XFLAG_EXTSIZE |
                                            FS_XFLAG_EXTSZINHERIT);
                        fa->fsx_extsize = 0;
@@ -1130,7 +1131,7 @@ xfs_ioctl_setattr_xflags(
        /* If realtime flag is set then must have realtime device */
        if (fa->fsx_xflags & FS_XFLAG_REALTIME) {
                if (mp->m_sb.sb_rblocks == 0 || mp->m_sb.sb_rextsize == 0 ||
-                   (ip->i_extsize % mp->m_sb.sb_rextsize))
+                   xfs_extlen_to_rtxmod(mp, ip->i_extsize))
                        return -EINVAL;
        }