Skip to contentSkip to conversation

zoned growfs fix

PATCH In review Christoph Hellwig 3 participants 10 messages Jun 9 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi all,

this series fixes growfs on zoned file systems, which so far has been completely broken. A test to verify it properly will be sent out as well.

Diffstat:

 xfs_rtalloc.c    |    9 +++++----
 xfs_zone_alloc.c |   11 +++++++++--
 xfs_zone_alloc.h |    1 +
 xfs_zone_gc.c    |    4 +---
 4 files changed, 16 insertions(+), 9 deletions(-)
#1 lore raw

PATCH 1/3 xfs: factor out a xfs_add_free_zone helper

Add a helper for adding a zone to the free pool in preparation of adding another caller.

---
 fs/xfs/xfs_zone_alloc.c | 11 +++++++++--
 fs/xfs/xfs_zone_alloc.h |  1 +
 fs/xfs/xfs_zone_gc.c    |  4 +---
 3 files changed, 11 insertions(+), 5 deletions(-)
fs/xfs/xfs_zone_alloc.c +9 -2
index 5e297b75a85f..0a7c4863eefb 100644
@@ -944,6 +944,14 @@ xfs_zone_rgbno_is_valid(
 			rtg_rgno(rtg), XFS_RTG_FREE);
 }
 
+void
+xfs_add_free_zone(
+	struct xfs_rtgroup	*rtg)
+{
+	xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
+	atomic_inc(&rtg_mount(rtg)->m_zone_info->zi_nr_free_zones);
+}
+
 static void
 xfs_free_open_zones(
 	struct xfs_zone_info	*zi)
@@ -1082,8 +1090,7 @@ xfs_init_zone(
 
 	if (write_pointer == 0) {
 		/* zone is empty */
-		atomic_inc(&zi->zi_nr_free_zones);
-		xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
+		xfs_add_free_zone(rtg);
 		iz->available += rtg_blocks(rtg);
 	} else if (write_pointer < rtg_blocks(rtg)) {
 		/* zone is open */
fs/xfs/xfs_zone_alloc.h +1 -0
index 8b2ef98c81ef..cc16cc328763 100644
@@ -42,6 +42,7 @@ void xfs_zoned_wake_all(struct xfs_mount *mp);
 bool xfs_zone_rgbno_is_valid(struct xfs_rtgroup *rtg, xfs_rgnumber_t rgbno);
 void xfs_mark_rtg_boundary(struct iomap_ioend *ioend);
 
+void xfs_add_free_zone(struct xfs_rtgroup *rtg);
 uint64_t xfs_zoned_default_resblks(struct xfs_mount *mp,
 		enum xfs_free_counter ctr);
 void xfs_zoned_show_stats(struct seq_file *m, struct xfs_mount *mp);
fs/xfs/xfs_zone_gc.c +1 -3
index f03211e4354a..670e05d2dadd 100644
@@ -924,9 +924,7 @@ xfs_zone_gc_finish_reset(
 		goto out;
 	}
 
-	xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
-	atomic_inc(&zi->zi_nr_free_zones);
-
+	xfs_add_free_zone(rtg);
 	xfs_zoned_add_available(mp, rtg_blocks(rtg));
 
 	wake_up_all(&zi->zi_zone_wait);
Signature · 1 line
2.53.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] xfs: factor out a xfs_add_free_zone helper

Quoted 4 lines · Christoph Hellwig

Add a helper for adding a zone to the free pool in preparation of adding another caller.

I might've called this xfs_zone_mark_free but I don't care passionately about the name.

--D

Quoted 66 lines
---
 fs/xfs/xfs_zone_alloc.c | 11 +++++++++--
 fs/xfs/xfs_zone_alloc.h |  1 +
 fs/xfs/xfs_zone_gc.c    |  4 +---
 3 files changed, 11 insertions(+), 5 deletions(-)
fs/xfs/xfs_zone_alloc.c +9 -2
index 5e297b75a85f..0a7c4863eefb 100644
@@ -944,6 +944,14 @@ xfs_zone_rgbno_is_valid(
 			rtg_rgno(rtg), XFS_RTG_FREE);
 }
 
+void
+xfs_add_free_zone(
+	struct xfs_rtgroup	*rtg)
+{
+	xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
+	atomic_inc(&rtg_mount(rtg)->m_zone_info->zi_nr_free_zones);
+}
+
 static void
 xfs_free_open_zones(
 	struct xfs_zone_info	*zi)
@@ -1082,8 +1090,7 @@ xfs_init_zone(
 
 	if (write_pointer == 0) {
 		/* zone is empty */
-		atomic_inc(&zi->zi_nr_free_zones);
-		xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
+		xfs_add_free_zone(rtg);
 		iz->available += rtg_blocks(rtg);
 	} else if (write_pointer < rtg_blocks(rtg)) {
 		/* zone is open */
fs/xfs/xfs_zone_alloc.h +1 -0
index 8b2ef98c81ef..cc16cc328763 100644
@@ -42,6 +42,7 @@ void xfs_zoned_wake_all(struct xfs_mount *mp);
 bool xfs_zone_rgbno_is_valid(struct xfs_rtgroup *rtg, xfs_rgnumber_t rgbno);
 void xfs_mark_rtg_boundary(struct iomap_ioend *ioend);
 
+void xfs_add_free_zone(struct xfs_rtgroup *rtg);
 uint64_t xfs_zoned_default_resblks(struct xfs_mount *mp,
 		enum xfs_free_counter ctr);
 void xfs_zoned_show_stats(struct seq_file *m, struct xfs_mount *mp);
fs/xfs/xfs_zone_gc.c +1 -3
index f03211e4354a..670e05d2dadd 100644
@@ -924,9 +924,7 @@ xfs_zone_gc_finish_reset(
 		goto out;
 	}
 
-	xfs_group_set_mark(rtg_group(rtg), XFS_RTG_FREE);
-	atomic_inc(&zi->zi_nr_free_zones);
-
+	xfs_add_free_zone(rtg);
 	xfs_zoned_add_available(mp, rtg_blocks(rtg));
 
 	wake_up_all(&zi->zi_zone_wait);
Signature · 1 line
2.53.0
Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] xfs: factor out a xfs_add_free_zone helper

In reply to Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

Add a helper for adding a zone to the free pool in preparation of adding another caller.

Same comment as Darrick: to match xfs_group_set_mark(), xfs_mark_zone_free() or xfs_zone_mark_free() may be a better name.
Other than that,

Signature · 2 lines
Damien Le Moal
Western Digital Research
#4 lore raw

PATCH 2/3 xfs: account newly added RTGs as free zones in growfs

In reply to Christoph Hellwig

When growing a zoned RT section, the newly added RTGs also need to be tagged as free in the radix tree and add to the nr_free_zones counters. Call xfs_add_free_zone to do that, otherwise using up the newly added space will wait for free zones forever.

Fixes 01b71e64bb87 ("xfs: support growfs on zoned file systems")
---
 fs/xfs/xfs_rtalloc.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_rtalloc.c +1 -0
index 153f3c378f9f..fd07c1a18615 100644
@@ -933,6 +933,7 @@ xfs_growfs_rt_zoned(
 	mp->m_features |= XFS_FEAT_REALTIME;
 	xfs_rtrmapbt_compute_maxlevels(mp);
 	xfs_rtrefcountbt_compute_maxlevels(mp);
+	xfs_add_free_zone(rtg);
 	xfs_zoned_add_available(mp, freed_rtx);
 out_free:
 	kfree(nmp);
Signature · 1 line
2.53.0
Reviewed-by on v1 2/3
#5 lore raw

Re: [PATCH 2/3] xfs: account newly added RTGs as free zones in growfs

Quoted 7 lines · Christoph Hellwig

When growing a zoned RT section, the newly added RTGs also need to be tagged as free in the radix tree and add to the nr_free_zones counters. Call xfs_add_free_zone to do that, otherwise using up the newly added space will wait for free zones forever.

Fixes 01b71e64bb87 ("xfs: support growfs on zoned file systems")

Good catch; glad there's a new fstest for it.

--D

Quoted 20 lines
---
 fs/xfs/xfs_rtalloc.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_rtalloc.c +1 -0
index 153f3c378f9f..fd07c1a18615 100644
@@ -933,6 +933,7 @@ xfs_growfs_rt_zoned(
 	mp->m_features |= XFS_FEAT_REALTIME;
 	xfs_rtrmapbt_compute_maxlevels(mp);
 	xfs_rtrefcountbt_compute_maxlevels(mp);
+	xfs_add_free_zone(rtg);
 	xfs_zoned_add_available(mp, freed_rtx);
 out_free:
 	kfree(nmp);
Signature · 1 line
2.53.0
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] xfs: account newly added RTGs as free zones in growfs

In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig

When growing a zoned RT section, the newly added RTGs also need to be tagged as free in the radix tree and add to the nr_free_zones counters. Call xfs_add_free_zone to do that, otherwise using up the newly added space will wait for free zones forever.

Fixes 01b71e64bb87 ("xfs: support growfs on zoned file systems")
Signature · 2 lines
Damien Le Moal
Western Digital Research
#7 lore raw

PATCH 3/3 xfs: only log freed extents for the current RTG in zoned growfs

In reply to Christoph Hellwig

Otherwise a power fail or crash during growfs could lead to an elevated sb_rblocks counter.

Note that the step function is much simpler compared to the classic RT allocator, as zoned RT sections must be allocated to zone and thus realtime group boundaries, and also because the rtextsize is fixed to a single FSB.

Fixes 01b71e64bb87 ("xfs: support growfs on zoned file systems")
---
 fs/xfs/xfs_rtalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_rtalloc.c +4 -4
index fd07c1a18615..728f444fbc30 100644
@@ -890,8 +890,7 @@ xfs_growfs_rt_sb_fields(
 
 static int
 xfs_growfs_rt_zoned(
-	struct xfs_rtgroup	*rtg,
-	xfs_rfsblock_t		nrblocks)
+	struct xfs_rtgroup	*rtg)
 {
 	struct xfs_mount	*mp = rtg_mount(rtg);
 	struct xfs_mount	*nmp;
@@ -903,7 +902,8 @@ xfs_growfs_rt_zoned(
 	 * Calculate new sb and mount fields for this round.  Also ensure the
 	 * rtg_extents value is uptodate as the rtbitmap code relies on it.
 	 */
-	nmp = xfs_growfs_rt_alloc_fake_mount(mp, nrblocks,
+	nmp = xfs_growfs_rt_alloc_fake_mount(mp,
+			mp->m_sb.sb_rgextents * (rtg_rgno(rtg) + 1),
 			mp->m_sb.sb_rextsize);
 	if (!nmp)
 		return -ENOMEM;
@@ -1219,7 +1219,7 @@ xfs_growfs_rtg(
 	}
 
 	if (xfs_has_zoned(mp)) {
-		error = xfs_growfs_rt_zoned(rtg, nrblocks);
+		error = xfs_growfs_rt_zoned(rtg);
 		goto out_rele;
 	}
 
Signature · 1 line
2.53.0
#8 lore raw

Re: [PATCH 3/3] xfs: only log freed extents for the current RTG in zoned growfs

Quoted 29 lines · Christoph Hellwig

Otherwise a power fail or crash during growfs could lead to an elevated sb_rblocks counter.

Note that the step function is much simpler compared to the classic RT allocator, as zoned RT sections must be allocated to zone and thus realtime group boundaries, and also because the rtextsize is fixed to a single FSB.

Fixes 01b71e64bb87 ("xfs: support growfs on zoned file systems")
---
 fs/xfs/xfs_rtalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_rtalloc.c +1 -2
index fd07c1a18615..728f444fbc30 100644
@@ -890,8 +890,7 @@ xfs_growfs_rt_sb_fields(
 
 static int
 xfs_growfs_rt_zoned(
-	struct xfs_rtgroup	*rtg,
-	xfs_rfsblock_t		nrblocks)
+	struct xfs_rtgroup	*rtg)
 {
 	struct xfs_mount	*mp = rtg_mount(rtg);
 	struct xfs_mount	*nmp;

fs/xfs/xfs_rtalloc.c xfs_growfs_rt_zoned( · line 906

Quoted 6 lines
fs/xfs/xfs_rtalloc.c +2 -1
@@ -903,7 +902,8 @@ xfs_growfs_rt_zoned(
 	 * Calculate new sb and mount fields for this round.  Also ensure the
 	 * rtg_extents value is uptodate as the rtbitmap code relies on it.
 	 */
-	nmp = xfs_growfs_rt_alloc_fake_mount(mp, nrblocks,
+	nmp = xfs_growfs_rt_alloc_fake_mount(mp,
+			mp->m_sb.sb_rgextents * (rtg_rgno(rtg) + 1),

I wonder, do you have to be careful about the multiplication overflowing here because rgextents and rgno are both 32-bit variables?

--D

Quoted 16 lines
fs/xfs/xfs_rtalloc.c +1 -1
 			mp->m_sb.sb_rextsize);
 	if (!nmp)
 		return -ENOMEM;
@@ -1219,7 +1219,7 @@ xfs_growfs_rtg(
 	}
 
 	if (xfs_has_zoned(mp)) {
-		error = xfs_growfs_rt_zoned(rtg, nrblocks);
+		error = xfs_growfs_rt_zoned(rtg);
 		goto out_rele;
 	}
 
Signature · 1 line
2.53.0
#9 lore raw

Re: [PATCH 3/3] xfs: only log freed extents for the current RTG in zoned growfs

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

Otherwise a power fail or crash during growfs could lead to an elevated sb_rblocks counter.

Note that the step function is much simpler compared to the classic RT allocator, as zoned RT sections must be allocated to zone and thus

s/zone/zones

Quoted 42 lines

realtime group boundaries, and also because the rtextsize is fixed to a single FSB.

Fixes 01b71e64bb87 ("xfs: support growfs on zoned file systems")
---
 fs/xfs/xfs_rtalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_rtalloc.c +4 -4
index fd07c1a18615..728f444fbc30 100644
@@ -890,8 +890,7 @@ xfs_growfs_rt_sb_fields(
 
 static int
 xfs_growfs_rt_zoned(
-	struct xfs_rtgroup	*rtg,
-	xfs_rfsblock_t		nrblocks)
+	struct xfs_rtgroup	*rtg)
 {
 	struct xfs_mount	*mp = rtg_mount(rtg);
 	struct xfs_mount	*nmp;
@@ -903,7 +902,8 @@ xfs_growfs_rt_zoned(
 	 * Calculate new sb and mount fields for this round.  Also ensure the
 	 * rtg_extents value is uptodate as the rtbitmap code relies on it.
 	 */
-	nmp = xfs_growfs_rt_alloc_fake_mount(mp, nrblocks,
+	nmp = xfs_growfs_rt_alloc_fake_mount(mp,
+			mp->m_sb.sb_rgextents * (rtg_rgno(rtg) + 1),
 			mp->m_sb.sb_rextsize);
 	if (!nmp)
 		return -ENOMEM;
@@ -1219,7 +1219,7 @@ xfs_growfs_rtg(
 	}
 
 	if (xfs_has_zoned(mp)) {
-		error = xfs_growfs_rt_zoned(rtg, nrblocks);
+		error = xfs_growfs_rt_zoned(rtg);
 		goto out_rele;
 	}
 
Signature · 2 lines
Damien Le Moal
Western Digital Research