diff mbox

[v3,05/39] fs: super: introduce a get_super_cdev to get super by a cdev reference

Message ID 1442307754-13233-6-git-send-email-yangds.fnst@cn.fujitsu.com
State Not Applicable
Headers show

Commit Message

Dongsheng Yang Sept. 15, 2015, 9:02 a.m. UTC
As we have cdev in superblock now, we can provide get_super_cdev
to get super_block by a cdev reference, similar with get_super
which is working only for block_device.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Reviewed-by: Jan Kara <jack@suse.com>
---
 fs/super.c         | 15 +++++++++++++++
 include/linux/fs.h |  1 +
 2 files changed, 16 insertions(+)

Comments

Christoph Hellwig Oct. 4, 2015, 6:32 a.m. UTC | #1
As mentioned before I don't think the cdev has any business in core VFS
code.  You must alredy have an anonymous block device for the st_dev
value, please use that.
diff mbox

Patch

diff --git a/fs/super.c b/fs/super.c
index 4d667fe..321d16b 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -613,6 +613,21 @@  struct super_block *get_super(struct block_device *bdev)
 }
 EXPORT_SYMBOL(get_super);
 
+static int cdev_compare(struct super_block *sb, void *key)
+{
+	return (sb->s_cdev == (struct cdev *)key);
+}
+
+/**
+ * get_super_cdev - get the superblock of a cdev
+ * @cdev: char device to get the superblock for
+ */
+struct super_block *get_super_cdev(struct cdev *cdev)
+{
+	return __get_super(cdev_compare, cdev);
+}
+EXPORT_SYMBOL(get_super_cdev);
+
 /**
  * get_super_thawed - get thawed superblock of a device
  * @bdev: device to get the superblock for
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 9896b62..df71cbb 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2796,6 +2796,7 @@  extern void get_filesystem(struct file_system_type *fs);
 extern void put_filesystem(struct file_system_type *fs);
 extern struct file_system_type *get_fs_type(const char *name);
 extern struct super_block *get_super(struct block_device *);
+extern struct super_block *get_super_cdev(struct cdev *);
 extern struct super_block *get_super_thawed(struct block_device *);
 extern struct super_block *get_active_super(struct block_device *bdev);
 extern void drop_super(struct super_block *sb);