Skip to content

Commit 4e26445

Browse files
lizf-oshtejun
authored andcommitted
kernfs: introduce kernfs_pin_sb()
kernfs_pin_sb() tries to get a refcnt of the superblock. This will be used by cgroupfs. v2: - make kernfs_pin_sb() return the superblock. - drop kernfs_drop_sb(). tj: Updated the comment a bit. [ This is a prerequisite for a bugfix. ] Cc: <stable@vger.kernel.org> # 3.15 Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Li Zefan <lizefan@huawei.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 970317a commit 4e26445

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

fs/kernfs/mount.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,36 @@ void kernfs_kill_sb(struct super_block *sb)
211211
kernfs_put(root_kn);
212212
}
213213

214+
/**
215+
* kernfs_pin_sb: try to pin the superblock associated with a kernfs_root
216+
* @kernfs_root: the kernfs_root in question
217+
* @ns: the namespace tag
218+
*
219+
* Pin the superblock so the superblock won't be destroyed in subsequent
220+
* operations. This can be used to block ->kill_sb() which may be useful
221+
* for kernfs users which dynamically manage superblocks.
222+
*
223+
* Returns NULL if there's no superblock associated to this kernfs_root, or
224+
* -EINVAL if the superblock is being freed.
225+
*/
226+
struct super_block *kernfs_pin_sb(struct kernfs_root *root, const void *ns)
227+
{
228+
struct kernfs_super_info *info;
229+
struct super_block *sb = NULL;
230+
231+
mutex_lock(&kernfs_mutex);
232+
list_for_each_entry(info, &root->supers, node) {
233+
if (info->ns == ns) {
234+
sb = info->sb;
235+
if (!atomic_inc_not_zero(&info->sb->s_active))
236+
sb = ERR_PTR(-EINVAL);
237+
break;
238+
}
239+
}
240+
mutex_unlock(&kernfs_mutex);
241+
return sb;
242+
}
243+
214244
void __init kernfs_init(void)
215245
{
216246
kernfs_node_cache = kmem_cache_create("kernfs_node_cache",

include/linux/kernfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
304304
struct kernfs_root *root, unsigned long magic,
305305
bool *new_sb_created, const void *ns);
306306
void kernfs_kill_sb(struct super_block *sb);
307+
struct super_block *kernfs_pin_sb(struct kernfs_root *root, const void *ns);
307308

308309
void kernfs_init(void);
309310

0 commit comments

Comments
 (0)