From: Jeff Mahoney <jeffm@suse.com>
Subject: kabi: only use sops->get_inode_dev with proper fsflag
Patch-mainline: Never, KABI fix

In order to maintain kABI compatibility, we can't add members to
super_operations and expect that the new members will be NULL.  With
third party modules, the new members will contain whatever happens
to be in memory after the original super_operations struct for that
file system.

In order to safely extend it, we add a new flag to file_system_type->fs_flags
that file systems which use get_inode_dev can set to indicate it is
safe to access that member.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 include/linux/fs.h |   10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1626,7 +1626,13 @@ struct super_operations {
 	int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
 	long (*nr_cached_objects)(struct super_block *, int);
 	long (*free_cached_objects)(struct super_block *, long, int);
+#ifndef __GENKSYMS__
+	/*
+	 * Will not even be accessed unless the FS_USES_GET_INODE_DEV flag
+	 * is set in file_system_type.
+	 */
 	dev_t (*get_inode_dev)(const struct inode *);
+#endif
 };
 
 /*
@@ -1822,6 +1828,7 @@ struct file_system_type {
 #define FS_USERNS_MOUNT		8	/* Can be mounted by userns root */
 #define FS_USERNS_DEV_MOUNT	16 /* A userns mount does not imply MNT_NODEV */
 #define FS_RENAME_DOES_D_MOVE	32768	/* FS will handle d_move() during rename() internally. */
+#define FS_USES_GET_INODE_DEV	65536 /* FS defines sops->get_inode_dev */
 	struct dentry *(*mount) (struct file_system_type *, int,
 		       const char *, void *);
 	void (*kill_sb) (struct super_block *);
@@ -2759,7 +2766,8 @@ static inline bool dir_relax(struct inod
 
 static inline dev_t inode_get_dev(const struct inode *inode)
 {
-	if (inode->i_sb->s_op->get_inode_dev)
+	if ((inode->i_sb->s_type->fs_flags & FS_USES_GET_INODE_DEV) &&
+	    inode->i_sb->s_op->get_inode_dev)
 		return inode->i_sb->s_op->get_inode_dev(inode);
 
 	return inode->i_sb->s_dev;
