summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2022-07-14 11:06:43 -0700
committerDarrick J. Wong <djwong@kernel.org>2022-10-14 14:16:49 -0700
commit021348feb8f7d8793a3316d5596d6534698c69be (patch)
tree90b602cb95d137761e7c1a953ecaf6bfb2ba7934
parentc6aea2c295ad73535a071ad21c19a7ee4c57266d (diff)
xfs: refactor non-power-of-two alignment checks
Create a helper function that can compute if a 64-bit number is an integer multiple of a 32-bit number, where the 32-bit number is not required to be an even power of two. This is needed for some new code for the realtime device, where we can set 37k allocation units and then have to remap them. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
-rw-r--r--fs/xfs/xfs_file.c12
-rw-r--r--fs/xfs/xfs_linux.h5
2 files changed, 8 insertions, 9 deletions
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c
index a3d95fb5d523..3a66a1a4623a 100644
--- a/fs/xfs/xfs_file.c
+++ b/fs/xfs/xfs_file.c
@@ -46,15 +46,9 @@ xfs_is_falloc_aligned(
{
unsigned int alloc_unit = xfs_inode_alloc_unitsize(ip);
- if (XFS_IS_REALTIME_INODE(ip) && !is_power_of_2(alloc_unit)) {
- u32 mod;
-
- div_u64_rem(pos, alloc_unit, &mod);
- if (mod)
- return false;
- div_u64_rem(len, alloc_unit, &mod);
- return mod == 0;
- }
+ if (XFS_IS_REALTIME_INODE(ip) && !is_power_of_2(alloc_unit))
+ return isaligned_64(pos, alloc_unit) &&
+ isaligned_64(len, alloc_unit);
return !((pos | len) & (alloc_unit - 1));
}
diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
index f9878021e7d0..29bd87f0b357 100644
--- a/fs/xfs/xfs_linux.h
+++ b/fs/xfs/xfs_linux.h
@@ -195,6 +195,11 @@ static inline uint64_t howmany_64(uint64_t x, uint32_t y)
return x;
}
+static inline bool isaligned_64(uint64_t x, uint32_t y)
+{
+ return do_div(x, y) == 0;
+}
+
int xfs_rw_bdev(struct block_device *bdev, sector_t sector, unsigned int count,
char *data, enum req_op op);