Skip to contentSkip to conversation

zoned fixes

PATCH Applied Christoph Hellwig 3 participants 9 messages Mar 17, 2025 – Mar 24, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi all,

this is a small set of zoned fixes, one reported by Dan through smatch, and reported and draft fixed by Darrick, and a little cleanup I noticed while going through the report from Dan.

#1 lore raw

PATCH 1/3 xfs: fix a missing unlock in xfs_growfs_data

The newly added check for the internal RT device needs to unlock m_growlock just like all ther other error cases.

Fixes bdc03eb5f98f ("xfs: allow internal RT devices for zoned mode")
---
 fs/xfs/xfs_fsops.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/xfs/xfs_fsops.c +5 -3
index ee2cefbd5df8..d7658b7dcdbd 100644
@@ -301,7 +301,7 @@ xfs_growfs_data(
 	struct xfs_mount	*mp,
 	struct xfs_growfs_data	*in)
 {
-	int			error = 0;
+	int			error;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -309,8 +309,10 @@ xfs_growfs_data(
 		return -EWOULDBLOCK;
 
 	/* we can't grow the data section when an internal RT section exists */
-	if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart)
-		return -EINVAL;
+	if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) {
+		error = -EINVAL;
+		goto out_error;
+	}
 
 	/* update imaxpct separately to the physical grow of the filesystem */
 	if (in->imaxpct != mp->m_sb.sb_imax_pct) {
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] xfs: fix a missing unlock in xfs_growfs_data

Quoted 6 lines · Christoph Hellwig

The newly added check for the internal RT device needs to unlock m_growlock just like all ther other error cases.

Fixes bdc03eb5f98f ("xfs: allow internal RT devices for zoned mode")
Quoted 33 lines
---
 fs/xfs/xfs_fsops.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
fs/xfs/xfs_fsops.c +5 -4
index ee2cefbd5df8..d7658b7dcdbd 100644
@@ -301,7 +301,7 @@ xfs_growfs_data(
 	struct xfs_mount	*mp,
 	struct xfs_growfs_data	*in)
 {
-	int			error = 0;
+	int			error;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -309,8 +309,10 @@ xfs_growfs_data(
 		return -EWOULDBLOCK;
 
 	/* we can't grow the data section when an internal RT section exists */
-	if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart)
-		return -EINVAL;
+	if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) {
+		error = -EINVAL;
+		goto out_error;
+	}
 
 	/* update imaxpct separately to the physical grow of the filesystem */
 	if (in->imaxpct != mp->m_sb.sb_imax_pct) {
--

2.45.2

maintainer Applied
#3 lore raw

Re: [PATCH 1/3] xfs: fix a missing unlock in xfs_growfs_data

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

The newly added check for the internal RT device needs to unlock m_growlock just like all ther other error cases.

Applied to for-next, thanks!

[1/3] xfs: fix a missing unlock in xfs_growfs_data

      commit: beba9487138151c17dec17105364b35935f21562
[2/3] xfs: don't increment m_generation for all errors in xfs_growfs_data
      commit: 9ec3f7977a32f2045ef14445f165bcd96e596344
[3/3] xfs: don't wake zone space waiters without m_zone_info
      commit: f56f73ebf8bb13d72b93e490c1f175a0a2c836f2

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>
#4 lore raw

PATCH 2/3 xfs: don't increment m_generation for all errors in xfs_growfs_data

In reply to Christoph Hellwig

xfs_growfs_data needs to increment m_generation as soon as the primary superblock has been updated. As the update of the secondary superblocks was part of xfs_growfs_data_private that mean the incremented had to be done unconditionally once that was called. Later, commit 83a7f86e39ff ("xfs: separate secondary sb update in growfs") split the secondary superblock update into a separate helper, so now the increment on error can be limited to failed calls to xfs_update_secondary_sbs.

---
 fs/xfs/xfs_fsops.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/xfs_fsops.c +6 -7
index d7658b7dcdbd..b6f3d7abdae5 100644
@@ -311,20 +311,20 @@ xfs_growfs_data(
 	/* we can't grow the data section when an internal RT section exists */
 	if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) {
 		error = -EINVAL;
-		goto out_error;
+		goto out_unlock;
 	}
 
 	/* update imaxpct separately to the physical grow of the filesystem */
 	if (in->imaxpct != mp->m_sb.sb_imax_pct) {
 		error = xfs_growfs_imaxpct(mp, in->imaxpct);
 		if (error)
-			goto out_error;
+			goto out_unlock;
 	}
 
 	if (in->newblocks != mp->m_sb.sb_dblocks) {
 		error = xfs_growfs_data_private(mp, in);
 		if (error)
-			goto out_error;
+			goto out_unlock;
 	}
 
 	/* Post growfs calculations needed to reflect new state in operations */
@@ -338,13 +338,12 @@ xfs_growfs_data(
 	/* Update secondary superblocks now the physical grow has completed */
 	error = xfs_update_secondary_sbs(mp);
 
-out_error:
 	/*
-	 * Increment the generation unconditionally, the error could be from
-	 * updating the secondary superblocks, in which case the new size
-	 * is live already.
+	 * Increment the generation unconditionally, after trying to update the
+	 * secondary superblocks, as the new size is live already at this point.
 	 */
 	mp->m_generation++;
+out_unlock:
 	mutex_unlock(&mp->m_growlock);
 	return error;
 }
Signature · 1 line
2.45.2
maintainer Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] xfs: don't increment m_generation for all errors in xfs_growfs_data

Quoted 9 lines · Christoph Hellwig

xfs_growfs_data needs to increment m_generation as soon as the primary superblock has been updated. As the update of the secondary superblocks was part of xfs_growfs_data_private that mean the incremented had to be done unconditionally once that was called. Later, commit 83a7f86e39ff ("xfs: separate secondary sb update in growfs") split the secondary superblock update into a separate helper, so now the increment on error can be limited to failed calls to xfs_update_secondary_sbs.

Quoted 53 lines
---
 fs/xfs/xfs_fsops.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
fs/xfs/xfs_fsops.c +6 -8
index d7658b7dcdbd..b6f3d7abdae5 100644
@@ -311,20 +311,20 @@ xfs_growfs_data(
 	/* we can't grow the data section when an internal RT section exists */
 	if (in->newblocks != mp->m_sb.sb_dblocks && mp->m_sb.sb_rtstart) {
 		error = -EINVAL;
-		goto out_error;
+		goto out_unlock;
 	}
 
 	/* update imaxpct separately to the physical grow of the filesystem */
 	if (in->imaxpct != mp->m_sb.sb_imax_pct) {
 		error = xfs_growfs_imaxpct(mp, in->imaxpct);
 		if (error)
-			goto out_error;
+			goto out_unlock;
 	}
 
 	if (in->newblocks != mp->m_sb.sb_dblocks) {
 		error = xfs_growfs_data_private(mp, in);
 		if (error)
-			goto out_error;
+			goto out_unlock;
 	}
 
 	/* Post growfs calculations needed to reflect new state in operations */
@@ -338,13 +338,12 @@ xfs_growfs_data(
 	/* Update secondary superblocks now the physical grow has completed */
 	error = xfs_update_secondary_sbs(mp);
 
-out_error:
 	/*
-	 * Increment the generation unconditionally, the error could be from
-	 * updating the secondary superblocks, in which case the new size
-	 * is live already.
+	 * Increment the generation unconditionally, after trying to update the
+	 * secondary superblocks, as the new size is live already at this point.
 	 */
 	mp->m_generation++;
+out_unlock:
 	mutex_unlock(&mp->m_growlock);
 	return error;
 }
--

2.45.2

#6 lore raw

PATCH 3/3 xfs: don't wake zone space waiters without m_zone_info

In reply to Christoph Hellwig

From: "Darrick J. Wong" <[email protected]>

xfs_zoned_wake_all checks SB_ACTIVE to make sure it does the right thing when a shutdown happens during unmount, but it fails to account for the log recovery special case that sets SB_ACTIVE temporarily. Add a NULL check to cover both cases.

[hch: added a commit log and comment]
---
 fs/xfs/xfs_zone_alloc.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +12 -3
index fd4c60a050e6..52af234936a2 100644
@@ -853,13 +853,22 @@ xfs_zone_alloc_and_submit(
 	bio_io_error(&ioend->io_bio);
 }
 
+/*
+ * Wake up all threads waiting for a zoned space allocation when the file system
+ * is shut down.
+ */
 void
 xfs_zoned_wake_all(
 	struct xfs_mount	*mp)
 {
-	if (!(mp->m_super->s_flags & SB_ACTIVE))
-		return; /* can happen during log recovery */
-	wake_up_all(&mp->m_zone_info->zi_zone_wait);
+	/*
+	 * Don't wake up if there is no m_zone_info.  This is complicated by the
+	 * fact that unmount can't atomically clear m_zone_info and thus we need
+	 * to check SB_ACTIVE for that, but mount temporarily enables SB_ACTIVE
+	 * during log recovery so we can't entirely rely on that either.
+	 */
+	if ((mp->m_super->s_flags & SB_ACTIVE) && mp->m_zone_info)
+		wake_up_all(&mp->m_zone_info->zi_zone_wait);
 }
 
 /*
Signature · 1 line
2.45.2
Reviewed-by on v1 3/3
#7 lore raw

Re: [PATCH 3/3] xfs: don't wake zone space waiters without m_zone_info

Quoted 34 lines · Christoph Hellwig

From: "Darrick J. Wong" <[email protected]>

xfs_zoned_wake_all checks SB_ACTIVE to make sure it does the right thing when a shutdown happens during unmount, but it fails to account for the log recovery special case that sets SB_ACTIVE temporarily. Add a NULL check to cover both cases.

[hch: added a commit log and comment]
---
 fs/xfs/xfs_zone_alloc.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +5 -3
index fd4c60a050e6..52af234936a2 100644
@@ -853,13 +853,22 @@ xfs_zone_alloc_and_submit(
 	bio_io_error(&ioend->io_bio);
 }
 
+/*
+ * Wake up all threads waiting for a zoned space allocation when the file system
+ * is shut down.
+ */
 void
 xfs_zoned_wake_all(
 	struct xfs_mount	*mp)
 {
-	if (!(mp->m_super->s_flags & SB_ACTIVE))
-		return; /* can happen during log recovery */
-	wake_up_all(&mp->m_zone_info->zi_zone_wait);
+	/*

fs/xfs/xfs_zone_alloc.c xfs_zone_alloc_and_submit( · line 874

Quoted 10 lines
fs/xfs/xfs_zone_alloc.c +7 -0
+	 * Don't wake up if there is no m_zone_info.  This is complicated by the
+	 * fact that unmount can't atomically clear m_zone_info and thus we need
+	 * to check SB_ACTIVE for that, but mount temporarily enables SB_ACTIVE
+	 * during log recovery so we can't entirely rely on that either.
+	 */
+	if ((mp->m_super->s_flags & SB_ACTIVE) && mp->m_zone_info)
+		wake_up_all(&mp->m_zone_info->zi_zone_wait);
 }
 
 /*

Looks good,

maintainer Reviewed-by on v1 3/3
#8 lore raw

Re: [PATCH 3/3] xfs: don't wake zone space waiters without m_zone_info

In reply to Christoph Hellwig
Quoted 10 lines · Christoph Hellwig

From: "Darrick J. Wong" <[email protected]>

xfs_zoned_wake_all checks SB_ACTIVE to make sure it does the right thing when a shutdown happens during unmount, but it fails to account for the log recovery special case that sets SB_ACTIVE temporarily. Add a NULL check to cover both cases.

[hch: added a commit log and comment]
Quoted 37 lines
---
 fs/xfs/xfs_zone_alloc.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
fs/xfs/xfs_zone_alloc.c +12 -4
index fd4c60a050e6..52af234936a2 100644
@@ -853,13 +853,22 @@ xfs_zone_alloc_and_submit(
 	bio_io_error(&ioend->io_bio);
 }
 
+/*
+ * Wake up all threads waiting for a zoned space allocation when the file system
+ * is shut down.
+ */
 void
 xfs_zoned_wake_all(
 	struct xfs_mount	*mp)
 {
-	if (!(mp->m_super->s_flags & SB_ACTIVE))
-		return; /* can happen during log recovery */
-	wake_up_all(&mp->m_zone_info->zi_zone_wait);
+	/*
+	 * Don't wake up if there is no m_zone_info.  This is complicated by the
+	 * fact that unmount can't atomically clear m_zone_info and thus we need
+	 * to check SB_ACTIVE for that, but mount temporarily enables SB_ACTIVE
+	 * during log recovery so we can't entirely rely on that either.
+	 */
+	if ((mp->m_super->s_flags & SB_ACTIVE) && mp->m_zone_info)
+		wake_up_all(&mp->m_zone_info->zi_zone_wait);
 }
 
 /*
--

2.45.2