]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: refactor xfs_mount_zones
authorChristoph Hellwig <hch@lst.de>
Tue, 31 Mar 2026 15:26:05 +0000 (17:26 +0200)
committerCarlos Maiolino <cem@kernel.org>
Tue, 7 Apr 2026 11:16:59 +0000 (13:16 +0200)
xfs_mount_zones has grown a bit too big and unorganized.  Split the
zone reporting loop into a separate helper, hiding the rtg variable
there.  Print the mount message last, and also keep the VFS writeback
chunk size last instead of in the middle of the logic to calculate
the free/available blocks.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com>
Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
fs/xfs/xfs_zone_alloc.c

index 06e2cb79030e2f64d5210dca272510a875538edc..e9f1d9d086202dddaddf57ce7528b08e6fdefa42 100644 (file)
@@ -1230,6 +1230,29 @@ xfs_free_zone_info(
        kfree(zi);
 }
 
+static int
+xfs_report_zones(
+       struct xfs_mount        *mp,
+       struct xfs_init_zones   *iz)
+{
+       struct xfs_rtgroup      *rtg = NULL;
+
+       while ((rtg = xfs_rtgroup_next(mp, rtg))) {
+               xfs_rgblock_t           write_pointer;
+               int                     error;
+
+               error = xfs_query_write_pointer(iz, rtg, &write_pointer);
+               if (!error)
+                       error = xfs_init_zone(iz, rtg, write_pointer);
+               if (error) {
+                       xfs_rtgroup_rele(rtg);
+                       return error;
+               }
+       }
+
+       return 0;
+}
+
 int
 xfs_mount_zones(
        struct xfs_mount        *mp)
@@ -1238,7 +1261,6 @@ xfs_mount_zones(
                .zone_capacity  = mp->m_groups[XG_TYPE_RTG].blocks,
                .zone_size      = xfs_rtgroup_raw_size(mp),
        };
-       struct xfs_rtgroup      *rtg = NULL;
        int                     error;
 
        if (!mp->m_rtdev_targp) {
@@ -1268,9 +1290,13 @@ xfs_mount_zones(
        if (!mp->m_zone_info)
                return -ENOMEM;
 
-       xfs_info(mp, "%u zones of %u blocks (%u max open zones)",
-                mp->m_sb.sb_rgcount, iz.zone_capacity, mp->m_max_open_zones);
-       trace_xfs_zones_mount(mp);
+       error = xfs_report_zones(mp, &iz);
+       if (error)
+               goto out_free_zone_info;
+
+       xfs_set_freecounter(mp, XC_FREE_RTAVAILABLE, iz.available);
+       xfs_set_freecounter(mp, XC_FREE_RTEXTENTS,
+                       iz.available + iz.reclaimable);
 
        /*
         * The writeback code switches between inodes regularly to provide
@@ -1296,22 +1322,6 @@ xfs_mount_zones(
                XFS_FSB_TO_B(mp, min(iz.zone_capacity, XFS_MAX_BMBT_EXTLEN)) >>
                        PAGE_SHIFT;
 
-       while ((rtg = xfs_rtgroup_next(mp, rtg))) {
-               xfs_rgblock_t           write_pointer;
-
-               error = xfs_query_write_pointer(&iz, rtg, &write_pointer);
-               if (!error)
-                       error = xfs_init_zone(&iz, rtg, write_pointer);
-               if (error) {
-                       xfs_rtgroup_rele(rtg);
-                       goto out_free_zone_info;
-               }
-       }
-
-       xfs_set_freecounter(mp, XC_FREE_RTAVAILABLE, iz.available);
-       xfs_set_freecounter(mp, XC_FREE_RTEXTENTS,
-                       iz.available + iz.reclaimable);
-
        /*
         * The user may configure GC to free up a percentage of unused blocks.
         * By default this is 0. GC will always trigger at the minimum level
@@ -1322,6 +1332,10 @@ xfs_mount_zones(
        error = xfs_zone_gc_mount(mp);
        if (error)
                goto out_free_zone_info;
+
+       xfs_info(mp, "%u zones of %u blocks (%u max open zones)",
+                mp->m_sb.sb_rgcount, iz.zone_capacity, mp->m_max_open_zones);
+       trace_xfs_zones_mount(mp);
        return 0;
 
 out_free_zone_info: