]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xfs: export max_open_zones in sysfs
authorChristoph Hellwig <hch@lst.de>
Tue, 21 Jan 2025 05:45:22 +0000 (06:45 +0100)
committerChristoph Hellwig <hch@lst.de>
Mon, 3 Mar 2025 15:17:10 +0000 (08:17 -0700)
Add a zoned group with an attribute for the maximum number of open zones.
This allows querying the open zones for data placement tests, or also
for placement aware applications that are in control of the entire
file system.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
fs/xfs/xfs_mount.h
fs/xfs/xfs_sysfs.c

index b34a496081dbfeb2dfd3f114f315aec3420dbacc..799b84220ebb84ac0f85470692373b585cf2ee5c 100644 (file)
@@ -287,6 +287,7 @@ typedef struct xfs_mount {
 #ifdef CONFIG_XFS_ONLINE_SCRUB_STATS
        struct xchk_stats       *m_scrub_stats;
 #endif
+       struct xfs_kobj         m_zoned_kobj;
        xfs_agnumber_t          m_agfrotor;     /* last ag where space found */
        atomic_t                m_agirotor;     /* last ag dir inode alloced */
        atomic_t                m_rtgrotor;     /* last rtgroup rtpicked */
index c3bd7dff229d1685b11614e9bf613f212764d1c8..b0857e3c12705eacf5c30c6028be36c90dffa858 100644 (file)
@@ -13,6 +13,7 @@
 #include "xfs_log.h"
 #include "xfs_log_priv.h"
 #include "xfs_mount.h"
+#include "xfs_zones.h"
 
 struct xfs_sysfs_attr {
        struct attribute attr;
@@ -701,6 +702,34 @@ out_error:
        return error;
 }
 
+static inline struct xfs_mount *zoned_to_mp(struct kobject *kobj)
+{
+       return container_of(to_kobj(kobj), struct xfs_mount, m_zoned_kobj);
+}
+
+static ssize_t
+max_open_zones_show(
+       struct kobject          *kobj,
+       char                    *buf)
+{
+       /* only report the open zones available for user data */
+       return sysfs_emit(buf, "%u\n",
+               zoned_to_mp(kobj)->m_max_open_zones - XFS_OPEN_GC_ZONES);
+}
+XFS_SYSFS_ATTR_RO(max_open_zones);
+
+static struct attribute *xfs_zoned_attrs[] = {
+       ATTR_LIST(max_open_zones),
+       NULL,
+};
+ATTRIBUTE_GROUPS(xfs_zoned);
+
+static const struct kobj_type xfs_zoned_ktype = {
+       .release = xfs_sysfs_release,
+       .sysfs_ops = &xfs_sysfs_ops,
+       .default_groups = xfs_zoned_groups,
+};
+
 int
 xfs_mount_sysfs_init(
        struct xfs_mount        *mp)
@@ -741,6 +770,14 @@ xfs_mount_sysfs_init(
        if (error)
                goto out_remove_error_dir;
 
+       if (IS_ENABLED(CONFIG_XFS_RT) && xfs_has_zoned(mp)) {
+               /* .../xfs/<dev>/zoned/ */
+               error = xfs_sysfs_init(&mp->m_zoned_kobj, &xfs_zoned_ktype,
+                                       &mp->m_kobj, "zoned");
+               if (error)
+                       goto out_remove_error_dir;
+       }
+
        return 0;
 
 out_remove_error_dir:
@@ -759,6 +796,9 @@ xfs_mount_sysfs_del(
        struct xfs_error_cfg    *cfg;
        int                     i, j;
 
+       if (IS_ENABLED(CONFIG_XFS_RT) && xfs_has_zoned(mp))
+               xfs_sysfs_del(&mp->m_zoned_kobj);
+
        for (i = 0; i < XFS_ERR_CLASS_MAX; i++) {
                for (j = 0; j < XFS_ERR_ERRNO_MAX; j++) {
                        cfg = &mp->m_error_cfg[i][j];