Skip to contentSkip to conversation

misc fixes

PATCH In review Christoph Hellwig 5 participants 13 messages Jun 5, 2025 – Jun 16, 2025 XFS filesystem

lore
Share & tools
lore
#0 lore raw

Hi Carlos,

a few misc fixes for the zoned code infrastructure updated by it.

Diffstat:

 xfs_mru_cache.c  |    4 ----
 xfs_super.c      |    5 ++---
 xfs_zone_alloc.c |   42 +++++++++++++++++++++---------------------
 3 files changed, 23 insertions(+), 28 deletions(-)
#1 lore raw

PATCH 1/4 xfs: check for shutdown before going to sleep in xfs_select_zone

Ensure the file system hasn't been shut down before waiting for a free zone to become available, because that won't happen on a shut down file system. Without this processes can occasionally get stuck in the allocator wait loop when racing with a file system shutdown. This sporadically happens when running generic/388 or generic/475.

Fixes 4e4d52075577 ("xfs: add the zoned space allocator")
---
 fs/xfs/xfs_zone_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +1 -1
index 80add26c0111..0de6f64b3169 100644
@@ -727,7 +727,7 @@ xfs_select_zone(
 	for (;;) {
 		prepare_to_wait(&zi->zi_zone_wait, &wait, TASK_UNINTERRUPTIBLE);
 		oz = xfs_select_zone_nowait(mp, write_hint, pack_tight);
-		if (oz)
+		if (oz || xfs_is_shutdown(mp))
 			break;
 		schedule();
 	}
Signature · 1 line
2.47.2
Tested-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] xfs: check for shutdown before going to sleep in xfs_select_zone

Quoted 9 lines · Christoph Hellwig

Ensure the file system hasn't been shut down before waiting for a free zone to become available, because that won't happen on a shut down file system. Without this processes can occasionally get stuck in the allocator wait loop when racing with a file system shutdown. This sporadically happens when running generic/388 or generic/475.

Fixes 4e4d52075577 ("xfs: add the zoned space allocator")

Thanks for the fix. I ran fstests twice on each of various zoned block devices and confirmed the hang did not happen.

Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] xfs: check for shutdown before going to sleep in xfs_select_zone

In reply to Christoph Hellwig
Quoted 18 lines · Christoph Hellwig

Ensure the file system hasn't been shut down before waiting for a free zone to become available, because that won't happen on a shut down file system. Without this processes can occasionally get stuck in the allocator wait loop when racing with a file system shutdown. This sporadically happens when running generic/388 or generic/475.

Fixes 4e4d52075577 ("xfs: add the zoned space allocator")
---
 fs/xfs/xfs_zone_alloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/xfs/xfs_zone_alloc.c +0 -0
index 80add26c0111..0de6f64b3169 100644

fs/xfs/xfs_zone_alloc.c xfs_select_zone( · line 733

Quoted 8 lines
fs/xfs/xfs_zone_alloc.c +1 -1
@@ -727,7 +727,7 @@ xfs_select_zone(
 	for (;;) {
 		prepare_to_wait(&zi->zi_zone_wait, &wait, TASK_UNINTERRUPTIBLE);
 		oz = xfs_select_zone_nowait(mp, write_hint, pack_tight);
-		if (oz)
+		if (oz || xfs_is_shutdown(mp))
 			break;
 		schedule();
 	}

Looks good to me.

#4 lore raw

PATCH 2/4 xfs: remove NULL pointer checks in xfs_mru_cache_insert

In reply to Christoph Hellwig

Remove the check for a NULL mru or mru->list in xfs_mru_cache_insert as this API misused lead to a direct NULL pointer dereference on first use and is not user triggerable. As a smatch run by Dan points out with the recent cleanup it would otherwise try to free the object we just determined to be NULL for this impossible to reach case.

Fixes 70b95cb86513 ("xfs: free the item in xfs_mru_cache_insert on failure")
---
 fs/xfs/xfs_mru_cache.c | 4 ----
 1 file changed, 4 deletions(-)
fs/xfs/xfs_mru_cache.c +0 -4
index 08443ceec329..c95401de8397 100644
@@ -425,10 +425,6 @@ xfs_mru_cache_insert(
 {
 	int			error = -EINVAL;
 
-	ASSERT(mru && mru->lists);
-	if (!mru || !mru->lists)
-		goto out_free;
-
 	error = -ENOMEM;
 	if (radix_tree_preload(GFP_KERNEL))
 		goto out_free;
Signature · 1 line
2.47.2
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] xfs: remove NULL pointer checks in xfs_mru_cache_insert

Quoted 18 lines · Christoph Hellwig

Remove the check for a NULL mru or mru->list in xfs_mru_cache_insert as this API misused lead to a direct NULL pointer dereference on first use and is not user triggerable. As a smatch run by Dan points out with the recent cleanup it would otherwise try to free the object we just determined to be NULL for this impossible to reach case.

Fixes 70b95cb86513 ("xfs: free the item in xfs_mru_cache_insert on failure")
---
 fs/xfs/xfs_mru_cache.c | 4 ----
 1 file changed, 4 deletions(-)
fs/xfs/xfs_mru_cache.c +0 -0
index 08443ceec329..c95401de8397 100644

fs/xfs/xfs_mru_cache.c xfs_mru_cache_insert( · line 430

Quoted 10 lines
fs/xfs/xfs_mru_cache.c +0 -4
@@ -425,10 +425,6 @@ xfs_mru_cache_insert(
 {
 	int			error = -EINVAL;
 
-	ASSERT(mru && mru->lists);
-	if (!mru || !mru->lists)
-		goto out_free;
-
 	error = -ENOMEM;
 	if (radix_tree_preload(GFP_KERNEL))
 		goto out_free;

Looks good to me.

#6 lore raw

PATCH 3/4 xfs: use xfs_readonly_buftarg in xfs_remount_rw

In reply to Christoph Hellwig

Use xfs_readonly_buftarg instead of open coding it.

---
 fs/xfs/xfs_super.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/xfs/xfs_super.c +2 -3
index 0bc4b5489078..bb0a82635a77 100644
@@ -2020,14 +2020,13 @@ xfs_remount_rw(
 	int error;
 
 	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp &&
-	    bdev_read_only(mp->m_logdev_targp->bt_bdev)) {
+	    xfs_readonly_buftarg(mp->m_logdev_targp)) {
 		xfs_warn(mp,
 			"ro->rw transition prohibited by read-only logdev");
 		return -EACCES;
 	}
 
-	if (mp->m_rtdev_targp &&
-	    bdev_read_only(mp->m_rtdev_targp->bt_bdev)) {
+	if (mp->m_rtdev_targp && xfs_readonly_buftarg(mp->m_rtdev_targp)) {
 		xfs_warn(mp,
 			"ro->rw transition prohibited by read-only rtdev");
 		return -EACCES;
Signature · 1 line
2.47.2
Reviewed-by on v1 3/4
#8 lore raw

Re: [PATCH 3/4] xfs: use xfs_readonly_buftarg in xfs_remount_rw

In reply to Christoph Hellwig
Quoted 18 lines · Christoph Hellwig

Use xfs_readonly_buftarg instead of open coding it.

---
 fs/xfs/xfs_super.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/xfs/xfs_super.c +1 -1
index 0bc4b5489078..bb0a82635a77 100644
@@ -2020,14 +2020,13 @@ xfs_remount_rw(
 	int error;
 
 	if (mp->m_logdev_targp && mp->m_logdev_targp != mp->m_ddev_targp &&
-	    bdev_read_only(mp->m_logdev_targp->bt_bdev)) {
+	    xfs_readonly_buftarg(mp->m_logdev_targp)) {
 		xfs_warn(mp,

fs/xfs/xfs_super.c xfs_remount_rw( · line 2032

Quoted 10 lines
fs/xfs/xfs_super.c +1 -2
 			"ro->rw transition prohibited by read-only logdev");
 		return -EACCES;
 	}
 
-	if (mp->m_rtdev_targp &&
-	    bdev_read_only(mp->m_rtdev_targp->bt_bdev)) {
+	if (mp->m_rtdev_targp && xfs_readonly_buftarg(mp->m_rtdev_targp)) {
 		xfs_warn(mp,
 			"ro->rw transition prohibited by read-only rtdev");
 		return -EACCES;

Looks good to me.

#9 lore raw

PATCH 4/4 xfs: move xfs_submit_zoned_bio a bit

In reply to Christoph Hellwig

Commit f3e2e53823b9 ("xfs: add inode to zone caching for data placement") add the new code right between xfs_submit_zoned_bio and xfs_zone_alloc_and_submit which implement the main zoned write path. Move xfs_submit_zoned_bio down to keep it together again.

---
 fs/xfs/xfs_zone_alloc.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
fs/xfs/xfs_zone_alloc.c +20 -20
index 0de6f64b3169..01315ed75502 100644
@@ -777,26 +777,6 @@ xfs_mark_rtg_boundary(
 		ioend->io_flags |= IOMAP_IOEND_BOUNDARY;
 }
 
-static void
-xfs_submit_zoned_bio(
-	struct iomap_ioend	*ioend,
-	struct xfs_open_zone	*oz,
-	bool			is_seq)
-{
-	ioend->io_bio.bi_iter.bi_sector = ioend->io_sector;
-	ioend->io_private = oz;
-	atomic_inc(&oz->oz_ref); /* for xfs_zoned_end_io */
-
-	if (is_seq) {
-		ioend->io_bio.bi_opf &= ~REQ_OP_WRITE;
-		ioend->io_bio.bi_opf |= REQ_OP_ZONE_APPEND;
-	} else {
-		xfs_mark_rtg_boundary(ioend);
-	}
-
-	submit_bio(&ioend->io_bio);
-}
-
 /*
  * Cache the last zone written to for an inode so that it is considered first
  * for subsequent writes.
@@ -891,6 +871,26 @@ xfs_zone_cache_create_association(
 	xfs_mru_cache_insert(mp->m_zone_cache, ip->i_ino, &item->mru);
 }
 
+static void
+xfs_submit_zoned_bio(
+	struct iomap_ioend	*ioend,
+	struct xfs_open_zone	*oz,
+	bool			is_seq)
+{
+	ioend->io_bio.bi_iter.bi_sector = ioend->io_sector;
+	ioend->io_private = oz;
+	atomic_inc(&oz->oz_ref); /* for xfs_zoned_end_io */
+
+	if (is_seq) {
+		ioend->io_bio.bi_opf &= ~REQ_OP_WRITE;
+		ioend->io_bio.bi_opf |= REQ_OP_ZONE_APPEND;
+	} else {
+		xfs_mark_rtg_boundary(ioend);
+	}
+
+	submit_bio(&ioend->io_bio);
+}
+
 void
 xfs_zone_alloc_and_submit(
 	struct iomap_ioend	*ioend,
Signature · 1 line
2.47.2
Reviewed-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] xfs: move xfs_submit_zoned_bio a bit

Quoted 58 lines · Christoph Hellwig

Commit f3e2e53823b9 ("xfs: add inode to zone caching for data placement") add the new code right between xfs_submit_zoned_bio and xfs_zone_alloc_and_submit which implement the main zoned write path. Move xfs_submit_zoned_bio down to keep it together again.

---
 fs/xfs/xfs_zone_alloc.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
fs/xfs/xfs_zone_alloc.c +13 -20
index 0de6f64b3169..01315ed75502 100644
@@ -777,26 +777,6 @@ xfs_mark_rtg_boundary(
 		ioend->io_flags |= IOMAP_IOEND_BOUNDARY;
 }
 
-static void
-xfs_submit_zoned_bio(
-	struct iomap_ioend	*ioend,
-	struct xfs_open_zone	*oz,
-	bool			is_seq)
-{
-	ioend->io_bio.bi_iter.bi_sector = ioend->io_sector;
-	ioend->io_private = oz;
-	atomic_inc(&oz->oz_ref); /* for xfs_zoned_end_io */
-
-	if (is_seq) {
-		ioend->io_bio.bi_opf &= ~REQ_OP_WRITE;
-		ioend->io_bio.bi_opf |= REQ_OP_ZONE_APPEND;
-	} else {
-		xfs_mark_rtg_boundary(ioend);
-	}
-
-	submit_bio(&ioend->io_bio);
-}
-
 /*
  * Cache the last zone written to for an inode so that it is considered first
  * for subsequent writes.
@@ -891,6 +871,26 @@ xfs_zone_cache_create_association(
 	xfs_mru_cache_insert(mp->m_zone_cache, ip->i_ino, &item->mru);
 }
 
+static void
+xfs_submit_zoned_bio(
+	struct iomap_ioend	*ioend,
+	struct xfs_open_zone	*oz,
+	bool			is_seq)
+{
+	ioend->io_bio.bi_iter.bi_sector = ioend->io_sector;
+	ioend->io_private = oz;
+	atomic_inc(&oz->oz_ref); /* for xfs_zoned_end_io */
+
+	if (is_seq) {
+		ioend->io_bio.bi_opf &= ~REQ_OP_WRITE;
+		ioend->io_bio.bi_opf |= REQ_OP_ZONE_APPEND;

fs/xfs/xfs_zone_alloc.c xfs_zone_cache_create_association( · line 896

Quoted 10 lines
fs/xfs/xfs_zone_alloc.c +7 -0
+	} else {
+		xfs_mark_rtg_boundary(ioend);
+	}
+
+	submit_bio(&ioend->io_bio);
+}
+
 void
 xfs_zone_alloc_and_submit(
 	struct iomap_ioend	*ioend,

Looks good to me.

maintainer Reviewed-by on v1 4/4
#11 lore raw

Re: [PATCH 4/4] xfs: move xfs_submit_zoned_bio a bit

In reply to Christoph Hellwig
Quoted 6 lines · Christoph Hellwig

Commit f3e2e53823b9 ("xfs: add inode to zone caching for data placement") add the new code right between xfs_submit_zoned_bio and xfs_zone_alloc_and_submit which implement the main zoned write path. Move xfs_submit_zoned_bio down to keep it together again.

Looks good,

Quoted 66 lines
---
 fs/xfs/xfs_zone_alloc.c | 40 ++++++++++++++++++++--------------------
 1 file changed, 20 insertions(+), 20 deletions(-)
fs/xfs/xfs_zone_alloc.c +20 -21
index 0de6f64b3169..01315ed75502 100644
@@ -777,26 +777,6 @@ xfs_mark_rtg_boundary(
 		ioend->io_flags |= IOMAP_IOEND_BOUNDARY;
 }
 
-static void
-xfs_submit_zoned_bio(
-	struct iomap_ioend	*ioend,
-	struct xfs_open_zone	*oz,
-	bool			is_seq)
-{
-	ioend->io_bio.bi_iter.bi_sector = ioend->io_sector;
-	ioend->io_private = oz;
-	atomic_inc(&oz->oz_ref); /* for xfs_zoned_end_io */
-
-	if (is_seq) {
-		ioend->io_bio.bi_opf &= ~REQ_OP_WRITE;
-		ioend->io_bio.bi_opf |= REQ_OP_ZONE_APPEND;
-	} else {
-		xfs_mark_rtg_boundary(ioend);
-	}
-
-	submit_bio(&ioend->io_bio);
-}
-
 /*
  * Cache the last zone written to for an inode so that it is considered first
  * for subsequent writes.
@@ -891,6 +871,26 @@ xfs_zone_cache_create_association(
 	xfs_mru_cache_insert(mp->m_zone_cache, ip->i_ino, &item->mru);
 }
 
+static void
+xfs_submit_zoned_bio(
+	struct iomap_ioend	*ioend,
+	struct xfs_open_zone	*oz,
+	bool			is_seq)
+{
+	ioend->io_bio.bi_iter.bi_sector = ioend->io_sector;
+	ioend->io_private = oz;
+	atomic_inc(&oz->oz_ref); /* for xfs_zoned_end_io */
+
+	if (is_seq) {
+		ioend->io_bio.bi_opf &= ~REQ_OP_WRITE;
+		ioend->io_bio.bi_opf |= REQ_OP_ZONE_APPEND;
+	} else {
+		xfs_mark_rtg_boundary(ioend);
+	}
+
+	submit_bio(&ioend->io_bio);
+}
+
 void
 xfs_zone_alloc_and_submit(
 	struct iomap_ioend	*ioend,
--

2.47.2

maintainer Applied
#12 lore raw
In reply to Christoph Hellwig
Quoted 9 lines · Christoph Hellwig

a few misc fixes for the zoned code infrastructure updated by it.

Diffstat:

 xfs_mru_cache.c  |    4 ----
 xfs_super.c      |    5 ++---
 xfs_zone_alloc.c |   42 +++++++++++++++++++++---------------------
 3 files changed, 23 insertions(+), 28 deletions(-)

[...]

Applied to for-next, thanks!

[1/4] xfs: check for shutdown before going to sleep in xfs_select_zone

      commit: b0f77d301eb2b4e1fc816f33ade8519ae7f894f4
[2/4] xfs: remove NULL pointer checks in xfs_mru_cache_insert
      commit: a593c89ac5a417605b165cbc9768b3663ab4d8ad
[3/4] xfs: use xfs_readonly_buftarg in xfs_remount_rw
      commit: df3b7e2b56d271f93e2d1f395c13235a1a277639
[4/4] xfs: move xfs_submit_zoned_bio a bit
      commit: 0989dfa61f438150c4f1110604ba0787856fe8b0

Best regards,

Signature · 1 line
Carlos Maiolino <[email protected]>