[RHEL7,COMMIT] ms/vfs: Allocate anon_inode_inode in anon_inode_init()

Submitted by Konstantin Khorenko on Dec. 19, 2017, 11:03 a.m.

Details

Message ID 201712191103.vBJB3W1c017464@finist_ce7.work
State New
Series "ms/vfs: Allocate anon_inode_inode in anon_inode_init()"
Headers show

Commit Message

Konstantin Khorenko Dec. 19, 2017, 11:03 a.m.
The commit is pushed to "branch-rh7-3.10.0-693.11.1.vz7.39.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.11.1.vz7.39.7
------>
commit 623bd3e96a87857da694414f5161a2df92a8e0cd
Author: Jan Kara <jack@suse.cz>
Date:   Tue Dec 19 14:03:32 2017 +0300

    ms/vfs: Allocate anon_inode_inode in anon_inode_init()
    
    Currently we allocated anon_inode_inode in anon_inodefs_mount. This is
    somewhat fragile as if that function ever gets called again, it will
    overwrite anon_inode_inode pointer. So move the initialization of
    anon_inode_inode to anon_inode_init().
    
    Signed-off-by: Jan Kara <jack@suse.cz>
    [ Further simplified on suggestion from Dave Jones ]
    Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
    
    ms commit: ("75c5a52da3fc vfs: Allocate anon_inode_inode in anon_inode_init()")
    
    https://jira.sw.ru/browse/PSBM-75068
    
    Signed-off-by: Evgenii Shatokhin <eshatokhin@virtuozzo.com>
---
 fs/anon_inodes.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 42fcc46e2cca..80ef38c73e5a 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -41,19 +41,8 @@  static const struct dentry_operations anon_inodefs_dentry_operations = {
 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
 				int flags, const char *dev_name, void *data)
 {
-	struct dentry *root;
-	root = mount_pseudo(fs_type, "anon_inode:", NULL,
+	return mount_pseudo(fs_type, "anon_inode:", NULL,
 			&anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
-	if (!IS_ERR(root)) {
-		struct super_block *s = root->d_sb;
-		anon_inode_inode = alloc_anon_inode(s);
-		if (IS_ERR(anon_inode_inode)) {
-			dput(root);
-			deactivate_locked_super(s);
-			root = ERR_CAST(anon_inode_inode);
-		}
-	}
-	return root;
 }
 
 static struct file_system_type anon_inode_fs_type = {
@@ -175,18 +164,15 @@  EXPORT_SYMBOL_GPL(anon_inode_getfd);
 
 static int __init anon_inode_init(void)
 {
-	int error;
-
 	anon_inode_mnt = kern_mount(&anon_inode_fs_type);
-	if (IS_ERR(anon_inode_mnt)) {
-		error = PTR_ERR(anon_inode_mnt);
-		goto err_unregister_filesystem;
-	}
-	return 0;
+	if (IS_ERR(anon_inode_mnt))
+		panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
 
-err_unregister_filesystem:
-	unregister_filesystem(&anon_inode_fs_type);
-	panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
+	anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
+	if (IS_ERR(anon_inode_inode))
+		panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
+
+	return 0;
 }
 
 fs_initcall(anon_inode_init);