From: Christian Brauner <brauner@kernel.org>
To: Christoph Hellwig <hch@lst.de>, Jan Kara <jack@suse.com>,
linux-fsdevel@vger.kernel.org
Cc: Christian Brauner <brauner@kernel.org>
Subject: [PATCH 1/2] super: massage wait event mechanism
Date: Mon, 27 Nov 2023 12:51:30 +0100 [thread overview]
Message-ID: <20231127-vfs-super-massage-wait-v1-1-9ab277bfd01a@kernel.org> (raw)
In-Reply-To: <20231127-vfs-super-massage-wait-v1-0-9ab277bfd01a@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/super.c | 51 ++++++++++++++-------------------------------------
1 file changed, 14 insertions(+), 37 deletions(-)
diff --git a/fs/super.c b/fs/super.c
index aa4e5c11ee32..f3227b22879d 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -81,16 +81,13 @@ static inline void super_unlock_shared(struct super_block *sb)
super_unlock(sb, false);
}
-static inline bool wait_born(struct super_block *sb)
+static bool super_load_flags(const struct super_block *sb, unsigned int flags)
{
- unsigned int flags;
-
/*
* Pairs with smp_store_release() in super_wake() and ensures
- * that we see SB_BORN or SB_DYING after we're woken.
+ * that we see @flags after we're woken.
*/
- flags = smp_load_acquire(&sb->s_flags);
- return flags & (SB_BORN | SB_DYING);
+ return smp_load_acquire(&sb->s_flags) & flags;
}
/**
@@ -111,10 +108,15 @@ static inline bool wait_born(struct super_block *sb)
*/
static __must_check bool super_lock(struct super_block *sb, bool excl)
{
-
lockdep_assert_not_held(&sb->s_umount);
-relock:
+ /* wait until the superblock is ready or dying */
+ wait_var_event(&sb->s_flags, super_load_flags(sb, SB_BORN | SB_DYING));
+
+ /* Don't pointlessly acquire s_umount. */
+ if (super_load_flags(sb, SB_DYING))
+ return false;
+
__super_lock(sb, excl);
/*
@@ -127,20 +129,8 @@ static __must_check bool super_lock(struct super_block *sb, bool excl)
return false;
}
- /* Has called ->get_tree() successfully. */
- if (sb->s_flags & SB_BORN)
- return true;
-
- super_unlock(sb, excl);
-
- /* wait until the superblock is ready or dying */
- wait_var_event(&sb->s_flags, wait_born(sb));
-
- /*
- * Neither SB_BORN nor SB_DYING are ever unset so we never loop.
- * Just reacquire @sb->s_umount for the caller.
- */
- goto relock;
+ WARN_ON_ONCE(!(sb->s_flags & SB_BORN));
+ return true;
}
/* wait and try to acquire read-side of @sb->s_umount */
@@ -523,18 +513,6 @@ void deactivate_super(struct super_block *s)
EXPORT_SYMBOL(deactivate_super);
-static inline bool wait_dead(struct super_block *sb)
-{
- unsigned int flags;
-
- /*
- * Pairs with memory barrier in super_wake() and ensures
- * that we see SB_DEAD after we're woken.
- */
- flags = smp_load_acquire(&sb->s_flags);
- return flags & SB_DEAD;
-}
-
/**
* grab_super - acquire an active reference to a superblock
* @sb: superblock to acquire
@@ -561,7 +539,7 @@ static bool grab_super(struct super_block *sb)
}
super_unlock_excl(sb);
}
- wait_var_event(&sb->s_flags, wait_dead(sb));
+ wait_var_event(&sb->s_flags, super_load_flags(sb, SB_DEAD));
put_super(sb);
return false;
}
@@ -908,8 +886,7 @@ static void __iterate_supers(void (*f)(struct super_block *))
spin_lock(&sb_lock);
list_for_each_entry(sb, &super_blocks, s_list) {
- /* Pairs with memory marrier in super_wake(). */
- if (smp_load_acquire(&sb->s_flags) & SB_DYING)
+ if (super_load_flags(sb, SB_DYING))
continue;
sb->s_count++;
spin_unlock(&sb_lock);
--
2.42.0
next prev parent reply other threads:[~2023-11-27 11:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 11:51 [PATCH 0/2] super: small tweaks Christian Brauner
2023-11-27 11:51 ` Christian Brauner [this message]
2023-11-27 13:59 ` [PATCH 1/2] super: massage wait event mechanism Christoph Hellwig
2023-11-27 14:52 ` Christian Brauner
2023-11-27 14:54 ` Christoph Hellwig
2023-11-27 16:46 ` Christoph Hellwig
2023-11-28 15:56 ` Christian Brauner
2023-11-27 11:51 ` [PATCH 2/2] super: don't bother with WARN_ON_ONCE() Christian Brauner
2023-11-27 13:59 ` Christoph Hellwig
2023-11-27 14:53 ` Christian Brauner
2023-11-27 16:48 ` Christoph Hellwig
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=20231127-vfs-super-massage-wait-v1-1-9ab277bfd01a@kernel.org \
--to=brauner@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.com \
--cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).