diff mbox series

[43/43] xfs: export max_open_zones in sysfs

Message ID 20250206064511.2323878-44-hch@lst.de (mailing list archive)
State Not Applicable, archived
Headers show
Series [01/43] xfs: factor out a xfs_rt_check_size helper | expand

Commit Message

hch Feb. 6, 2025, 6:44 a.m. UTC
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>
---
 fs/xfs/xfs_mount.h |  1 +
 fs/xfs/xfs_sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

Comments

Darrick J. Wong Feb. 7, 2025, 12:52 a.m. UTC | #1
On Thu, Feb 06, 2025 at 07:44:59AM +0100, Christoph Hellwig wrote:
> 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>

It occurs to me -- what happens to all this zoned code if you build
without RT support?

Creating a whole sysfs kobj just to export a single attribute seems a
little overkill but I guess that beats revving the fs geometry ioctl.

Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_mount.h |  1 +
>  fs/xfs/xfs_sysfs.c | 40 ++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 41 insertions(+)
> 
> diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
> index 7c7fd94375c1..390d9d5882f4 100644
> --- a/fs/xfs/xfs_mount.h
> +++ b/fs/xfs/xfs_mount.h
> @@ -277,6 +277,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 */
> diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
> index c3bd7dff229d..797a92908647 100644
> --- a/fs/xfs/xfs_sysfs.c
> +++ b/fs/xfs/xfs_sysfs.c
> @@ -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 @@ xfs_error_sysfs_init_class(
>  	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 (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 (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];
> -- 
> 2.45.2
> 
>
hch Feb. 7, 2025, 4:23 a.m. UTC | #2
On Thu, Feb 06, 2025 at 04:52:59PM -0800, Darrick J. Wong wrote:
> On Thu, Feb 06, 2025 at 07:44:59AM +0100, Christoph Hellwig wrote:
> > 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>
> 
> It occurs to me -- what happens to all this zoned code if you build
> without RT support?

Where this code is all of it, or the sysfs support here?

In general the code is keyed off IS_ENABLED(CONFIG_XFS_RT) wherever
possible.  But the sysfs code here is missing that, so it should
be added.
Darrick J. Wong Feb. 7, 2025, 4:27 a.m. UTC | #3
On Fri, Feb 07, 2025 at 05:23:45AM +0100, Christoph Hellwig wrote:
> On Thu, Feb 06, 2025 at 04:52:59PM -0800, Darrick J. Wong wrote:
> > On Thu, Feb 06, 2025 at 07:44:59AM +0100, Christoph Hellwig wrote:
> > > 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>
> > 
> > It occurs to me -- what happens to all this zoned code if you build
> > without RT support?
> 
> Where this code is all of it, or the sysfs support here?

Both, but mostly the sysfs stuff here. :)

> In general the code is keyed off IS_ENABLED(CONFIG_XFS_RT) wherever
> possible.  But the sysfs code here is missing that, so it should
> be added.

<nod>

--D
diff mbox series

Patch

diff --git a/fs/xfs/xfs_mount.h b/fs/xfs/xfs_mount.h
index 7c7fd94375c1..390d9d5882f4 100644
--- a/fs/xfs/xfs_mount.h
+++ b/fs/xfs/xfs_mount.h
@@ -277,6 +277,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 */
diff --git a/fs/xfs/xfs_sysfs.c b/fs/xfs/xfs_sysfs.c
index c3bd7dff229d..797a92908647 100644
--- a/fs/xfs/xfs_sysfs.c
+++ b/fs/xfs/xfs_sysfs.c
@@ -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 @@  xfs_error_sysfs_init_class(
 	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 (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 (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];