diff mbox series

[7/8] xfs: report AG health via AG geometry ioctl

Message ID 155494717070.1090518.15401214807663806671.stgit@magnolia (mailing list archive)
State Superseded
Headers show
Series xfs: online health tracking support | expand

Commit Message

Darrick J. Wong April 11, 2019, 1:46 a.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Use the AG geometry info ioctl to report health status too.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/libxfs/xfs_fs.h     |   14 +++++++++++++-
 fs/xfs/libxfs/xfs_health.h |    2 ++
 fs/xfs/xfs_health.c        |   43 +++++++++++++++++++++++++++++++++++++++++++
 fs/xfs/xfs_ioctl.c         |    2 ++
 4 files changed, 60 insertions(+), 1 deletion(-)

Comments

Brian Foster April 11, 2019, 1:09 p.m. UTC | #1
On Wed, Apr 10, 2019 at 06:46:10PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Use the AG geometry info ioctl to report health status too.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  fs/xfs/libxfs/xfs_fs.h     |   14 +++++++++++++-
>  fs/xfs/libxfs/xfs_health.h |    2 ++
>  fs/xfs/xfs_health.c        |   43 +++++++++++++++++++++++++++++++++++++++++++
>  fs/xfs/xfs_ioctl.c         |    2 ++
>  4 files changed, 60 insertions(+), 1 deletion(-)
> 
> 
...
> diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
> index eb8dbc3a952a..0315b95a8d84 100644
> --- a/fs/xfs/xfs_health.c
> +++ b/fs/xfs/xfs_health.c
> @@ -321,3 +321,46 @@ xfs_fsop_geom_health(
...
> +/* Fill out ag geometry health info. */
> +void
> +xfs_ag_geom_health(
> +	struct xfs_mount	*mp,
> +	xfs_agnumber_t		agno,
> +	struct xfs_ag_geometry	*ageo)
> +{
> +	struct xfs_perag	*pag;
> +	const struct ioctl_sick_map *m;
> +	unsigned int		sick;
> +	unsigned int		checked;
> +
> +	ASSERT(agno < mp->m_sb.sb_agcount);
> +
> +	ageo->ag_sick = 0;
> +	ageo->ag_checked = 0;
> +
> +	pag = xfs_perag_get(mp, agno);
> +	xfs_ag_measure_sickness(pag, &sick, &checked);
> +	for (m = ag_map; m->sick_mask; m++) {
> +		if (checked & m->sick_mask)
> +			ageo->ag_checked |= m->ioctl_mask;
> +		if (sick & m->sick_mask)
> +			ageo->ag_sick |= m->ioctl_mask;
> +	}

FWIW this is pretty much what I was asking for in the mapping helper in
the previous patch. I didn't realize this was going to be reused for
another ioctl/struct, however, so disregard my previous comment about
renaming ->ioctl_mask. ;)

> +
> +	xfs_perag_put(pag);
> +}
> diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> index 3e3ee197bd0f..c47f4201452c 100644
> --- a/fs/xfs/xfs_ioctl.c
> +++ b/fs/xfs/xfs_ioctl.c
> @@ -822,6 +822,8 @@ xfs_ioc_ag_geometry(
>  	if (error)
>  		return error;
>  
> +	xfs_ag_geom_health(mp, ageo.ag_number, &ageo);
> +

Any reason not to push this down into the get_geom() helper since it's
part of the initial version of the ag geometry structure and we already
have the xfs_perag there?

Brian

>  	if (copy_to_user(arg, &ageo, sizeof(ageo)))
>  		return -EFAULT;
>  	return 0;
>
Darrick J. Wong April 11, 2019, 3:33 p.m. UTC | #2
On Thu, Apr 11, 2019 at 09:09:57AM -0400, Brian Foster wrote:
> On Wed, Apr 10, 2019 at 06:46:10PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Use the AG geometry info ioctl to report health status too.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  fs/xfs/libxfs/xfs_fs.h     |   14 +++++++++++++-
> >  fs/xfs/libxfs/xfs_health.h |    2 ++
> >  fs/xfs/xfs_health.c        |   43 +++++++++++++++++++++++++++++++++++++++++++
> >  fs/xfs/xfs_ioctl.c         |    2 ++
> >  4 files changed, 60 insertions(+), 1 deletion(-)
> > 
> > 
> ...
> > diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
> > index eb8dbc3a952a..0315b95a8d84 100644
> > --- a/fs/xfs/xfs_health.c
> > +++ b/fs/xfs/xfs_health.c
> > @@ -321,3 +321,46 @@ xfs_fsop_geom_health(
> ...
> > +/* Fill out ag geometry health info. */
> > +void
> > +xfs_ag_geom_health(
> > +	struct xfs_mount	*mp,
> > +	xfs_agnumber_t		agno,
> > +	struct xfs_ag_geometry	*ageo)
> > +{
> > +	struct xfs_perag	*pag;
> > +	const struct ioctl_sick_map *m;
> > +	unsigned int		sick;
> > +	unsigned int		checked;
> > +
> > +	ASSERT(agno < mp->m_sb.sb_agcount);
> > +
> > +	ageo->ag_sick = 0;
> > +	ageo->ag_checked = 0;
> > +
> > +	pag = xfs_perag_get(mp, agno);
> > +	xfs_ag_measure_sickness(pag, &sick, &checked);
> > +	for (m = ag_map; m->sick_mask; m++) {
> > +		if (checked & m->sick_mask)
> > +			ageo->ag_checked |= m->ioctl_mask;
> > +		if (sick & m->sick_mask)
> > +			ageo->ag_sick |= m->ioctl_mask;
> > +	}
> 
> FWIW this is pretty much what I was asking for in the mapping helper in
> the previous patch. I didn't realize this was going to be reused for
> another ioctl/struct, however, so disregard my previous comment about
> renaming ->ioctl_mask. ;)
> 
> > +
> > +	xfs_perag_put(pag);
> > +}
> > diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
> > index 3e3ee197bd0f..c47f4201452c 100644
> > --- a/fs/xfs/xfs_ioctl.c
> > +++ b/fs/xfs/xfs_ioctl.c
> > @@ -822,6 +822,8 @@ xfs_ioc_ag_geometry(
> >  	if (error)
> >  		return error;
> >  
> > +	xfs_ag_geom_health(mp, ageo.ag_number, &ageo);
> > +
> 
> Any reason not to push this down into the get_geom() helper since it's
> part of the initial version of the ag geometry structure and we already
> have the xfs_perag there?

No particularly strong reason not to.  Will fix.

Thanks for reviewing all this stuff!

--D

> Brian
> 
> >  	if (copy_to_user(arg, &ageo, sizeof(ageo)))
> >  		return -EFAULT;
> >  	return 0;
> >
diff mbox series

Patch

diff --git a/fs/xfs/libxfs/xfs_fs.h b/fs/xfs/libxfs/xfs_fs.h
index 6b8956dbf49d..35d60f8017cd 100644
--- a/fs/xfs/libxfs/xfs_fs.h
+++ b/fs/xfs/libxfs/xfs_fs.h
@@ -285,9 +285,21 @@  struct xfs_ag_geometry {
 	uint32_t	ag_freeblks;	/* o: free space */
 	uint32_t	ag_icount;	/* o: inodes allocated */
 	uint32_t	ag_ifree;	/* o: inodes free */
+	uint32_t	ag_sick;	/* o: sick things in ag */
+	uint32_t	ag_checked;	/* o: checked metadata in ag */
 	uint32_t	ag_reserved32;	/* o: zero */
-	uint64_t	ag_reserved[13];/* o: zero */
+	uint64_t	ag_reserved[12];/* o: zero */
 };
+#define XFS_AG_GEOM_SICK_SB	(1 << 0)  /* superblock */
+#define XFS_AG_GEOM_SICK_AGF	(1 << 1)  /* AGF header */
+#define XFS_AG_GEOM_SICK_AGFL	(1 << 2)  /* AGFL header */
+#define XFS_AG_GEOM_SICK_AGI	(1 << 3)  /* AGI header */
+#define XFS_AG_GEOM_SICK_BNOBT	(1 << 4)  /* free space by block */
+#define XFS_AG_GEOM_SICK_CNTBT	(1 << 5)  /* free space by length */
+#define XFS_AG_GEOM_SICK_INOBT	(1 << 6)  /* inode index */
+#define XFS_AG_GEOM_SICK_FINOBT	(1 << 7)  /* free inode index */
+#define XFS_AG_GEOM_SICK_RMAPBT	(1 << 8)  /* reverse mappings */
+#define XFS_AG_GEOM_SICK_REFCNTBT (1 << 9)  /* reference counts */
 
 /*
  * Structures for XFS_IOC_FSGROWFSDATA, XFS_IOC_FSGROWFSLOG & XFS_IOC_FSGROWFSRT
diff --git a/fs/xfs/libxfs/xfs_health.h b/fs/xfs/libxfs/xfs_health.h
index c72142ec7cbb..adf9d41843a5 100644
--- a/fs/xfs/libxfs/xfs_health.h
+++ b/fs/xfs/libxfs/xfs_health.h
@@ -176,5 +176,7 @@  xfs_inode_is_healthy(struct xfs_inode *ip)
 }
 
 void xfs_fsop_geom_health(struct xfs_mount *mp, struct xfs_fsop_geom *geo);
+void xfs_ag_geom_health(struct xfs_mount *mp, xfs_agnumber_t agno,
+		struct xfs_ag_geometry *ageo);
 
 #endif	/* __XFS_HEALTH_H__ */
diff --git a/fs/xfs/xfs_health.c b/fs/xfs/xfs_health.c
index eb8dbc3a952a..0315b95a8d84 100644
--- a/fs/xfs/xfs_health.c
+++ b/fs/xfs/xfs_health.c
@@ -321,3 +321,46 @@  xfs_fsop_geom_health(
 		xfgeo_health_tick(geo, sick, checked, m->sick_mask,
 				m->ioctl_mask);
 }
+
+static const struct ioctl_sick_map ag_map[] = {
+	{ XFS_SICK_AG_SB,	XFS_AG_GEOM_SICK_SB },
+	{ XFS_SICK_AG_AGF,	XFS_AG_GEOM_SICK_AGF },
+	{ XFS_SICK_AG_AGFL,	XFS_AG_GEOM_SICK_AGFL },
+	{ XFS_SICK_AG_AGI,	XFS_AG_GEOM_SICK_AGI },
+	{ XFS_SICK_AG_BNOBT,	XFS_AG_GEOM_SICK_BNOBT },
+	{ XFS_SICK_AG_CNTBT,	XFS_AG_GEOM_SICK_CNTBT },
+	{ XFS_SICK_AG_INOBT,	XFS_AG_GEOM_SICK_INOBT },
+	{ XFS_SICK_AG_FINOBT,	XFS_AG_GEOM_SICK_FINOBT },
+	{ XFS_SICK_AG_RMAPBT,	XFS_AG_GEOM_SICK_RMAPBT },
+	{ XFS_SICK_AG_REFCNTBT,	XFS_AG_GEOM_SICK_REFCNTBT },
+	{ 0, 0 },
+};
+
+/* Fill out ag geometry health info. */
+void
+xfs_ag_geom_health(
+	struct xfs_mount	*mp,
+	xfs_agnumber_t		agno,
+	struct xfs_ag_geometry	*ageo)
+{
+	struct xfs_perag	*pag;
+	const struct ioctl_sick_map *m;
+	unsigned int		sick;
+	unsigned int		checked;
+
+	ASSERT(agno < mp->m_sb.sb_agcount);
+
+	ageo->ag_sick = 0;
+	ageo->ag_checked = 0;
+
+	pag = xfs_perag_get(mp, agno);
+	xfs_ag_measure_sickness(pag, &sick, &checked);
+	for (m = ag_map; m->sick_mask; m++) {
+		if (checked & m->sick_mask)
+			ageo->ag_checked |= m->ioctl_mask;
+		if (sick & m->sick_mask)
+			ageo->ag_sick |= m->ioctl_mask;
+	}
+
+	xfs_perag_put(pag);
+}
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 3e3ee197bd0f..c47f4201452c 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -822,6 +822,8 @@  xfs_ioc_ag_geometry(
 	if (error)
 		return error;
 
+	xfs_ag_geom_health(mp, ageo.ag_number, &ageo);
+
 	if (copy_to_user(arg, &ageo, sizeof(ageo)))
 		return -EFAULT;
 	return 0;