From: Jan Kara <jack@suse.cz>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: <linux-fsdevel@vger.kernel.org>, Jan Kara <jack@suse.cz>
Subject: [PATCH 1/2] vfs: Provide function to grab superblock reference
Date: Tue, 11 Dec 2018 18:24:22 +0100 [thread overview]
Message-ID: <20181211172423.7709-2-jack@suse.cz> (raw)
In-Reply-To: <20181211172423.7709-1-jack@suse.cz>
Provide function to hold superblock reference when we are sure the
superblock is active. This function will get used by code reading
/proc/mounts and friends.
Signed-off-by: Jan Kara <jack@suse.cz>
---
fs/internal.h | 1 +
fs/super.c | 16 ++++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/fs/internal.h b/fs/internal.h
index d410186bc369..608f4f276ba5 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -104,6 +104,7 @@ extern bool trylock_super(struct super_block *sb);
extern struct dentry *mount_fs(struct file_system_type *,
int, const char *, void *);
extern struct super_block *user_get_super(dev_t);
+extern void hold_sb(struct super_block *sb);
/*
* open.c
diff --git a/fs/super.c b/fs/super.c
index ca53a08497ed..d34b8c49af9d 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -775,6 +775,22 @@ struct super_block *get_super_exclusive_thawed(struct block_device *bdev)
}
EXPORT_SYMBOL(get_super_exclusive_thawed);
+/**
+ * hold_sb - get superblock reference for active superblock
+ * @sb: superblock to get reference for
+ *
+ * Get reference to superblock. The caller must make sure the superblock
+ * is currently active by other means (e.g. holding an active reference
+ * itself or holding namespace_sem preventing unmount).
+ */
+void hold_sb(struct super_block *sb)
+{
+ spin_lock(&sb_lock);
+ WARN_ON_ONCE(!atomic_read(&sb->s_active));
+ sb->s_count++;
+ spin_unlock(&sb_lock);
+}
+
/**
* get_active_super - get an active reference to the superblock of a device
* @bdev: device to get the superblock for
--
2.16.4
next prev parent reply other threads:[~2018-12-11 17:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 17:24 [PATCH 0/2 RESEND] vfs: Fix crashes when reading /proc/mounts Jan Kara
2018-12-11 17:24 ` Jan Kara [this message]
2018-12-11 17:24 ` [PATCH 2/2] proc: Protect readers of /proc/mounts from remount Jan Kara
2018-12-11 18:36 ` Al Viro
2018-12-11 18:37 ` Al Viro
2018-12-11 18:58 ` Al Viro
2018-12-11 19:14 ` Al Viro
2018-12-12 12:56 ` Jan Kara
-- strict thread matches above, loose matches on Subject: below --
2018-12-18 13:46 [PATCH 0/2 v2] vfs: Fix crashes when reading /proc/mounts Jan Kara
2018-12-18 13:46 ` [PATCH 1/2] vfs: Provide function to grab superblock reference Jan Kara
2018-10-18 13:17 [PATCH 0/2] vfs: Fix crashes when reading /proc/mounts Jan Kara
2018-10-18 13:17 ` [PATCH 1/2] vfs: Provide function to grab superblock reference Jan Kara
2018-10-18 13:17 ` 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=20181211172423.7709-2-jack@suse.cz \
--to=jack@suse.cz \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.