From: Andreas Gruenbacher <agruenba@redhat.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Gruenbacher <agruenba@redhat.com>,
Josef Bacik <josef@redhat.com>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org
Subject: [PATCH 1/3] fs: Add activate_super function
Date: Wed, 30 Nov 2022 00:07:33 +0100 [thread overview]
Message-ID: <20221129230736.3462830-2-agruenba@redhat.com> (raw)
In-Reply-To: <20221129230736.3462830-1-agruenba@redhat.com>
Add function activate_super() for grabbing an active reference on a
super block. Fails if the filesystem is already shutting down.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/super.c | 19 +++++++++++++++++++
include/linux/fs.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/fs/super.c b/fs/super.c
index 8d39e4f11cfa..051241cf408b 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -393,6 +393,25 @@ static int grab_super(struct super_block *s) __releases(sb_lock)
return 0;
}
+/**
+ * activate_super - try to grab an active reference on the superblock
+ * @sb: reference we are trying to grab
+ *
+ * Try to grab an active reference on the superblock to prevent filesystem
+ * shutdown. Fails if the filesystem is already shutting down (see
+ * deactivate_locked_super()).
+ */
+bool activate_super(struct super_block *sb)
+{
+ if (atomic_inc_not_zero(&sb->s_active)) {
+ smp_mb__after_atomic();
+ BUG_ON(!(sb->s_flags & SB_BORN));
+ return true;
+ }
+ return false;
+}
+EXPORT_SYMBOL(activate_super);
+
/*
* trylock_super - try to grab ->s_umount shared
* @sb: reference we are trying to grab
diff --git a/include/linux/fs.h b/include/linux/fs.h
index e654435f1651..84c609123a25 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2573,6 +2573,7 @@ void generic_shutdown_super(struct super_block *sb);
void kill_block_super(struct super_block *sb);
void kill_anon_super(struct super_block *sb);
void kill_litter_super(struct super_block *sb);
+bool activate_super(struct super_block *sb);
void deactivate_super(struct super_block *sb);
void deactivate_locked_super(struct super_block *sb);
int set_anon_super(struct super_block *s, void *data);
--
2.38.1
next prev parent reply other threads:[~2022-11-29 23:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-29 23:07 [RFC 0/3] Shut down frozen filesystems on last unmount Andreas Gruenbacher
2022-11-29 23:07 ` Andreas Gruenbacher [this message]
2022-11-29 23:07 ` [PATCH 2/3] fs: Introduce { freeze, thaw }_active_super functions Andreas Gruenbacher
2023-01-12 17:54 ` Al Viro
2022-11-29 23:07 ` [PATCH 3/3] gfs2: Shut down frozen filesystem on last unmount Andreas Gruenbacher
2023-01-12 19:07 ` Al Viro
2023-01-12 12:25 ` [RFC 0/3] Shut down frozen filesystems " Jan Kara
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=20221129230736.3462830-2-agruenba@redhat.com \
--to=agruenba@redhat.com \
--cc=jack@suse.cz \
--cc=josef@redhat.com \
--cc=linux-fsdevel@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;
as well as URLs for NNTP newsgroup(s).