Skip to contentSkip to conversation

xfs: short circuit xfs_growfs_data_private() if delta is zero

PATCH In review Eric Sandeen 3 participants 3 messages Dec 14, 2023 – Dec 15, 2023 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: short circuit xfs_growfs_data_private() if delta is zero

Although xfs_growfs_data() doesn't call xfs_growfs_data_private() if in->newblocks == mp->m_sb.sb_dblocks, xfs_growfs_data_private() further massages the new block count so that we don't i.e. try to create a too-small new AG.

This may lead to a delta of "0" in xfs_growfs_data_private(), so we end up in the shrink case and emit the EXPERIMENTAL warning even if we're not changing anything at all.

Fix this by returning straightaway if the block delta is zero.

(nb: in older kernels, the result of entering the shrink case with delta == 0 may actually let an -ENOSPC escape to userspace, which is confusing for users.)

Fixes fb2fc1720185 ("xfs: support shrinking unused space in the last AG")

---

fs/xfs/xfs_fsops.c +4 -0
index 7cb75cb6b8e9..80811d16dde0 100644
@@ -134,6 +134,10 @@ xfs_growfs_data_private(
 	if (delta < 0 && nagcount < 2)
 		return -EINVAL;
 
+	/* No work to do */
+	if (delta == 0)
+		return 0;
+
 	oagcount = mp->m_sb.sb_agcount;
 	/* allocate the new per-ag structures */
 	if (nagcount > oagcount) {
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Eric Sandeen

Although xfs_growfs_data() doesn't call xfs_growfs_data_private() if in->newblocks == mp->m_sb.sb_dblocks, xfs_growfs_data_private() further massages the new block count so that we don't i.e. try to create a too-small new AG.

This may lead to a delta of "0" in xfs_growfs_data_private(), so we end up in the shrink case and emit the EXPERIMENTAL warning even if we're not changing anything at all.

Quoted 8 lines

Fix this by returning straightaway if the block delta is zero.

(nb: in older kernels, the result of entering the shrink case with delta == 0 may actually let an -ENOSPC escape to userspace, which is confusing for users.)

Fixes fb2fc1720185 ("xfs: support shrinking unused space in the last AG")

Seems like a reasonable addition...

--D

Quoted 19 lines

---

fs/xfs/xfs_fsops.c +4 -0
index 7cb75cb6b8e9..80811d16dde0 100644
@@ -134,6 +134,10 @@ xfs_growfs_data_private(
 	if (delta < 0 && nagcount < 2)
 		return -EINVAL;
 
+	/* No work to do */
+	if (delta == 0)
+		return 0;
+
 	oagcount = mp->m_sb.sb_agcount;
 	/* allocate the new per-ag structures */
 	if (nagcount > oagcount) {
Reviewed-by on v1 1/1
#2 lore raw
In reply to Eric Sandeen
Quoted 9 lines · Eric Sandeen

Although xfs_growfs_data() doesn't call xfs_growfs_data_private() if in->newblocks == mp->m_sb.sb_dblocks, xfs_growfs_data_private() further massages the new block count so that we don't i.e. try to create a too-small new AG.

This may lead to a delta of "0" in xfs_growfs_data_private(), so we end up in the shrink case and emit the EXPERIMENTAL warning even if we're not changing anything at all.

Quoted 8 lines

Fix this by returning straightaway if the block delta is zero.

(nb: in older kernels, the result of entering the shrink case with delta == 0 may actually let an -ENOSPC escape to userspace, which is confusing for users.)

Fixes fb2fc1720185 ("xfs: support shrinking unused space in the last AG")

Looks good: