From: Christian Brauner <brauner@kernel.org>
To: Jan Kara <jack@suse.cz>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Josef Bacik <josef@toxicpanda.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
"Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH 1/5] super: add super_wait()
Date: Fri, 23 Oct 2026 11:41:01 +0200 [thread overview]
Message-ID: <20261023-work-super-lock_helpers-v1-1-d0fcb3f2f275@kernel.org> (raw)
In-Reply-To: <20261023-work-super-lock_helpers-v1-0-d0fcb3f2f275@kernel.org>
We wait for SB_BORN, SB_DYING and SB_DEAD in five places now, each with
an open-coded wait_var_event(), wait_var_event_killable() or
wait_var_event_state() on sb->s_flags and super_lock_common() picking
between the first two depending on @killable. Add super_wait() which
takes the flags to wait for and the task state to sleep in and use it
everywhere.
No functional changes.
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/super.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index 63e85794ea4d..16b9d7ac381c 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -102,6 +102,17 @@ static bool super_flags(const struct super_block *sb, unsigned int flags)
return smp_load_acquire(&sb->s_flags) & flags;
}
+/*
+ * Wait for one of @sb_flags to be set on @sb, sleeping in @state. Returns 0
+ * or -ERESTARTSYS if @state allowed the wait to be cut short.
+ */
+static int super_wait(struct super_block *sb, unsigned int sb_flags,
+ unsigned int state)
+{
+ return wait_var_event_state(&sb->s_flags, super_flags(sb, sb_flags),
+ state);
+}
+
/*
* Returns 0 with s_umount held, -ENOENT if the superblock is going away, or,
* if @killable, the error from a wait which was cut short.
@@ -122,12 +133,8 @@ static int super_lock_common(struct super_block *sb, bool excl, bool killable)
return -ENOENT;
/* wait until the superblock is ready or dying */
- if (killable)
- ret = wait_var_event_killable(&sb->s_flags,
- super_flags(sb, SB_BORN | SB_DYING));
- else
- wait_var_event(&sb->s_flags,
- super_flags(sb, SB_BORN | SB_DYING));
+ ret = super_wait(sb, SB_BORN | SB_DYING,
+ killable ? TASK_KILLABLE : TASK_UNINTERRUPTIBLE);
if (ret)
return ret;
@@ -216,7 +223,7 @@ static __must_check int super_lock_killable(struct super_block *sb, bool excl)
*/
static int super_wait_shutdown_killable(struct super_block *sb)
{
- return wait_var_event_killable(&sb->s_flags, super_flags(sb, SB_DYING));
+ return super_wait(sb, SB_DYING, TASK_KILLABLE);
}
/**
@@ -230,7 +237,7 @@ static int super_wait_shutdown_killable(struct super_block *sb)
*/
static void super_wait_shutdown(struct super_block *sb)
{
- wait_var_event(&sb->s_flags, super_flags(sb, SB_DYING));
+ super_wait(sb, SB_DYING, TASK_UNINTERRUPTIBLE);
}
/* wait and try to acquire read-side of @sb->s_umount */
@@ -606,9 +613,7 @@ static struct super_block *super_dev_next(struct super_dev *cursor,
return sb;
}
}
- ret = wait_var_event_state(&sb->s_flags,
- super_flags(sb, SB_BORN | SB_DYING),
- state);
+ ret = super_wait(sb, SB_BORN | SB_DYING, state);
put_super(sb);
if (ret) {
super_dev_walk_end(cursor);
@@ -731,8 +736,7 @@ static int grab_super(struct super_block *sb)
ret = -ENOENT;
}
if (ret == -ENOENT)
- ret = wait_var_event_killable(&sb->s_flags,
- super_flags(sb, SB_DEAD));
+ ret = super_wait(sb, SB_DEAD, TASK_KILLABLE);
put_super(sb);
return ret ? ret : -EAGAIN;
}
--
2.53.0
next prev parent reply other threads:[~2026-10-23 9:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-23 9:41 [PATCH 0/5] super: rework super_lock() Christian Brauner
2026-10-23 9:41 ` Christian Brauner [this message]
2026-10-23 9:41 ` [PATCH 2/5] super: let super_lock() take flags Christian Brauner
2026-10-23 9:41 ` [PATCH 3/5] super: let super_lock() wait for a superblock being shut down Christian Brauner
2026-10-23 9:41 ` [PATCH 4/5] super: make sync(2)'s wait for s_umount killable Christian Brauner
2026-10-23 9:41 ` [PATCH 5/5] super: add a guard for super_lock() Christian Brauner
2026-10-23 13:54 ` [PATCH 0/5] super: rework super_lock() Josef Bacik
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=20261023-work-super-lock_helpers-v1-1-d0fcb3f2f275@kernel.org \
--to=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=josef@toxicpanda.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®