Re: [PATCH v7.1 14/14] xfs: allow sysadmins to specify a maximum atomic write limit at mount time

From: John Garry
Date: Wed Apr 16 2025 - 06:09:14 EST


On 15/04/2025 23:36, Darrick J. Wong wrote:

Thanks for this, but it still seems to be problematic for me.

In my test, I have agsize=22400, and when I attempt to mount with atomic_write_max=8M, it passes when it shouldn't. It should not because max_pow_of_two_factor(22400) = 128, and 8MB > 128 FSB.

How about these addition checks:

+
+ if (new_max_bytes) {
+ xfs_extlen_t max_write_fsbs =
+ rounddown_pow_of_two(XFS_B_TO_FSB(mp, MAX_RW_COUNT));
+ xfs_extlen_t max_group_fsbs =
+ max(mp->m_groups[XG_TYPE_AG].blocks,
+ mp->m_groups[XG_TYPE_RTG].blocks);
+
+ ASSERT(max_write_fsbs <= U32_MAX);

if (!is_power_of_2(new_max_bytes)) {
xfs_warn(mp,
"max atomic write size of %llu bytes is not a power-of-2",
new_max_bytes);
return -EINVAL;
}

+
+ if (new_max_bytes % mp->m_sb.sb_blocksize > 0) {
+ xfs_warn(mp,
+ "max atomic write size of %llu bytes not aligned with fsblock",
+ new_max_bytes);
+ return -EINVAL;
+ }
+
+ if (new_max_fsbs > max_write_fsbs) {
+ xfs_warn(mp,
+ "max atomic write size of %lluk cannot be larger than max write size %lluk",
+ new_max_bytes >> 10,
+ XFS_FSB_TO_B(mp, max_write_fsbs) >> 10);
+ return -EINVAL;
+ }
+
+ if (new_max_fsbs > max_group_fsbs) {
+ xfs_warn(mp,
+ "max atomic write size of %lluk cannot be larger than allocation group size %lluk",
+ new_max_bytes >> 10,
+ XFS_FSB_TO_B(mp, max_group_fsbs) >> 10);
+ return -EINVAL;
+ }
+ }
+

if (new_max_fsbs > max_pow_of_two_factor(max_group_fsbs)) {
xfs_warn(mp,
"max atomic write size of %lluk not aligned with allocation group size %lluk",
new_max_bytes >> 10,
XFS_FSB_TO_B(mp, max_group_fsbs) >> 10);
return -EINVAL;
}

thanks,
John