From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: cem@kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: Re: [PATCH 03/11] xfs: create event queuing, formatting, and discovery infrastructure
Date: Wed, 7 Jan 2026 11:01:41 -0800 [thread overview]
Message-ID: <20260107190141.GF15551@frogsfrogsfrogs> (raw)
In-Reply-To: <20260107093245.GA24264@lst.de>
On Wed, Jan 07, 2026 at 10:32:45AM +0100, Christoph Hellwig wrote:
> On Mon, Jan 05, 2026 at 11:11:24PM -0800, Darrick J. Wong wrote:
> > diff --git a/fs/xfs/xfs_healthmon.c b/fs/xfs/xfs_healthmon.c
> > index 3fdac72b478f3f..799e0687ae3263 100644
> > --- a/fs/xfs/xfs_healthmon.c
> > +++ b/fs/xfs/xfs_healthmon.c
> > @@ -45,6 +45,13 @@
> > /* sign of a detached health monitor */
> > #define DETACHED_MOUNT_COOKIE ((uintptr_t)0)
> >
> > +/* Constrain the number of event objects that can build up in memory. */
> > +#define XFS_HEALTHMON_MAX_EVENTS \
> > + (SZ_32K / sizeof(struct xfs_healthmon_event))
>
> The double tab indent here looks a bit weird.
>
> > +/* Free all events */
> > +STATIC void
> > +xfs_healthmon_free_events(
> > + struct xfs_healthmon *hm)
> > +{
> > + struct xfs_healthmon_event *event, *next;
> > +
> > + event = hm->first_event;
> > + while (event != NULL) {
> > + trace_xfs_healthmon_drop(hm, event);
> > + next = event->next;
> > + kfree(event);
> > + event = next;
> > + }
>
> This could be simplified a bit to:
>
> struct xfs_healthmon_event *event = hm->first_event;
>
> while (event) {
> struct xfs_healthmon_event *next = event->next;
>
> trace_xfs_healthmon_drop(hm, event);
> kfree(event);
> event = next;
> }
>
> or alternatively:
>
> struct xfs_healthmon_event *event, *next = hm->first_event;
>
> while ((event = next) != NULL) {
> trace_xfs_healthmon_drop(hm, event);
> next = event->next;
> kfree(event);
> }
Changed.
> > + hm->first_event = hm->last_event = NULL;
>
> Always personal preference, but I always hate decoding double assignments
> like this vs the more verbose:
>
> hm->first_event = NULL;
> hm->last_event = NULL;
>
> that beeing said, do we even need to zero these given that hm gets freed
> right after?
Nope.
> > + return false;
> > +
> > + switch (existing->type) {
> > + case XFS_HEALTHMON_RUNNING:
> > + /* should only ever be one of these events anyway */
> > + return false;
> > +
> > + case XFS_HEALTHMON_LOST:
> > + existing->lostcount += new->lostcount;
> > + return true;
> > + }
> > +
> > + return false;
>
> I think the XFS_HEALTHMON_RUNNING check here is redundant, so you could
> just special case XFS_HEALTHMON_LOST with an if instead of the switch
> statement.
The switch statement fills out as we add more event types, and with the
way it's written now, gcc will complain if someone enlarges the enum
without adding a switch case here. So I'd prefer to keep this the way
it is now.
> > +/* Make a stack event dynamic so we can put it on the list. */
> > +static inline struct xfs_healthmon_event *
> > +xfs_healthmon_event_dup(
> > + const struct xfs_healthmon_event *event)
> > +{
> > + return kmemdup(event, sizeof(struct xfs_healthmon_event), GFP_NOFS);
> > +}
>
> The callers of this and and xfs_healthmon_merge_events seem to share
> the same logic. Maybe add a helper for the two calls and the
> XFS_HEALTHMON_MAX_EVENTS check, and fold at least xfs_healthmon_event_dup
> (and maybe xfs_healthmon_merge_events if it works out) into that?
_event_dup can be folded into its callers.
I'm less sure about _merge_events -- it would be pretty easy to
opencode its logic in _clear_lost_prev:
if (hm->last_event &&
hm->last_event->type == XFS_HEALTHMON_LOST &&
hm->last_event->domain == XFS_HEALTHMON_MOUNT) {
hm->last_event->lostcount += hm->lost_prev_event;
trace_xfs_healthmon_merge(hm, hm->last_event);
wake_up(&hm->wait);
goto cleared;
}
But the downside is that either we leave the dead XFS_HEALTHMON_LOST
case in the switch statement in _merge_events to avoid giving up the
compiler checking, or we add a default: case which then means that
authors of future extensions can miss things without noticing.
I think I'll remove _event_dup but leave the merge function.
> > + if (file->f_flags & O_NONBLOCK) {
> > + if (!xfs_healthmon_has_eventdata(hm))
> > + return -EAGAIN;
> > + } else {
> > + ret = wait_event_interruptible(hm->wait,
> > + xfs_healthmon_has_eventdata(hm));
> > + if (ret)
> > + return ret;
> > + }
> > +
> > + inode_lock(inode);
>
> should this be a trylock + -EAGAIN for O_NONBLOCK?
Oops yes.
--D
next prev parent reply other threads:[~2026-01-07 19:01 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-06 7:10 [PATCHSET V4] xfs: autonomous self healing of filesystems Darrick J. Wong
2026-01-06 7:10 ` [PATCH 01/11] docs: discuss autonomous self healing in the xfs online repair design doc Darrick J. Wong
2026-01-07 9:08 ` Christoph Hellwig
2026-01-07 19:15 ` Darrick J. Wong
2026-01-06 7:11 ` [PATCH 02/11] xfs: start creating infrastructure for health monitoring Darrick J. Wong
2026-01-07 9:17 ` Christoph Hellwig
2026-01-07 18:50 ` Darrick J. Wong
2026-01-08 10:21 ` Christoph Hellwig
2026-01-06 7:11 ` [PATCH 03/11] xfs: create event queuing, formatting, and discovery infrastructure Darrick J. Wong
2026-01-07 9:32 ` Christoph Hellwig
2026-01-07 19:01 ` Darrick J. Wong [this message]
2026-01-06 7:11 ` [PATCH 04/11] xfs: convey filesystem unmount events to the health monitor Darrick J. Wong
2026-01-06 7:11 ` [PATCH 05/11] xfs: convey metadata health " Darrick J. Wong
2026-01-06 7:12 ` [PATCH 06/11] xfs: convey filesystem shutdown " Darrick J. Wong
2026-01-06 7:12 ` [PATCH 07/11] xfs: convey externally discovered fsdax media errors " Darrick J. Wong
2026-01-06 7:12 ` [PATCH 08/11] xfs: convey file I/O " Darrick J. Wong
2026-01-06 7:12 ` [PATCH 09/11] xfs: allow reconfiguration of the health monitoring device Darrick J. Wong
2026-01-06 7:13 ` [PATCH 10/11] xfs: check if an open file is on the health monitored fs Darrick J. Wong
2026-01-06 7:13 ` [PATCH 11/11] xfs: add media error reporting ioctl Darrick J. Wong
2026-01-07 9:36 ` Christoph Hellwig
2026-01-07 16:30 ` Darrick J. Wong
2026-01-08 10:25 ` Christoph Hellwig
2026-01-08 16:09 ` Darrick J. Wong
2026-01-08 16:14 ` Christoph Hellwig
2026-01-08 16:18 ` Darrick J. Wong
2026-01-08 16:20 ` Christoph Hellwig
2026-01-08 16:53 ` Darrick J. Wong
2026-01-12 5:24 ` Darrick J. Wong
-- strict thread matches above, loose matches on Subject: below --
2026-01-13 0:32 [PATCHSET v5] xfs: autonomous self healing of filesystems Darrick J. Wong
2026-01-13 0:33 ` [PATCH 03/11] xfs: create event queuing, formatting, and discovery infrastructure Darrick J. Wong
2026-01-13 16:05 ` Christoph Hellwig
2026-01-16 5:42 [PATCHSET v6] xfs: autonomous self healing of filesystems Darrick J. Wong
2026-01-16 5:42 ` [PATCH 03/11] xfs: create event queuing, formatting, and discovery infrastructure Darrick J. Wong
2026-01-21 6:34 [PATCHSET v7 1/3] xfs: autonomous self healing of filesystems Darrick J. Wong
2026-01-21 6:35 ` [PATCH 03/11] xfs: create event queuing, formatting, and discovery infrastructure Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260107190141.GF15551@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=hch@lst.de \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox