Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

anon_inodes: move allocation of anon_inode into ->mount()

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

Al Viro ca7068c4 2226a288

+56 -53
+56 -53
fs/anon_inodes.c
··· 39 39 .d_dname = anon_inodefs_dname, 40 40 }; 41 41 42 - static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type, 43 - int flags, const char *dev_name, void *data) 44 - { 45 - return mount_pseudo(fs_type, "anon_inode:", NULL, 46 - &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC); 47 - } 48 - 49 - static struct file_system_type anon_inode_fs_type = { 50 - .name = "anon_inodefs", 51 - .mount = anon_inodefs_mount, 52 - .kill_sb = kill_anon_super, 53 - }; 54 - 55 42 /* 56 43 * nop .set_page_dirty method so that people can use .page_mkwrite on 57 44 * anon inodes. ··· 50 63 51 64 static const struct address_space_operations anon_aops = { 52 65 .set_page_dirty = anon_set_page_dirty, 66 + }; 67 + 68 + /* 69 + * A single inode exists for all anon_inode files. Contrary to pipes, 70 + * anon_inode inodes have no associated per-instance data, so we need 71 + * only allocate one of them. 72 + */ 73 + static struct inode *anon_inode_mkinode(struct super_block *s) 74 + { 75 + struct inode *inode = new_inode_pseudo(s); 76 + 77 + if (!inode) 78 + return ERR_PTR(-ENOMEM); 79 + 80 + inode->i_ino = get_next_ino(); 81 + inode->i_fop = &anon_inode_fops; 82 + 83 + inode->i_mapping->a_ops = &anon_aops; 84 + 85 + /* 86 + * Mark the inode dirty from the very beginning, 87 + * that way it will never be moved to the dirty 88 + * list because mark_inode_dirty() will think 89 + * that it already _is_ on the dirty list. 90 + */ 91 + inode->i_state = I_DIRTY; 92 + inode->i_mode = S_IRUSR | S_IWUSR; 93 + inode->i_uid = current_fsuid(); 94 + inode->i_gid = current_fsgid(); 95 + inode->i_flags |= S_PRIVATE; 96 + inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 97 + return inode; 98 + } 99 + 100 + static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type, 101 + int flags, const char *dev_name, void *data) 102 + { 103 + struct dentry *root; 104 + root = mount_pseudo(fs_type, "anon_inode:", NULL, 105 + &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC); 106 + if (!IS_ERR(root)) { 107 + struct super_block *s = root->d_sb; 108 + anon_inode_inode = anon_inode_mkinode(s); 109 + if (IS_ERR(anon_inode_inode)) { 110 + dput(root); 111 + deactivate_locked_super(s); 112 + root = ERR_CAST(anon_inode_inode); 113 + } 114 + } 115 + return root; 116 + } 117 + 118 + static struct file_system_type anon_inode_fs_type = { 119 + .name = "anon_inodefs", 120 + .mount = anon_inodefs_mount, 121 + .kill_sb = kill_anon_super, 53 122 }; 54 123 55 124 /** ··· 223 180 } 224 181 EXPORT_SYMBOL_GPL(anon_inode_getfd); 225 182 226 - /* 227 - * A single inode exists for all anon_inode files. Contrary to pipes, 228 - * anon_inode inodes have no associated per-instance data, so we need 229 - * only allocate one of them. 230 - */ 231 - static struct inode *anon_inode_mkinode(void) 232 - { 233 - struct inode *inode = new_inode_pseudo(anon_inode_mnt->mnt_sb); 234 - 235 - if (!inode) 236 - return ERR_PTR(-ENOMEM); 237 - 238 - inode->i_ino = get_next_ino(); 239 - inode->i_fop = &anon_inode_fops; 240 - 241 - inode->i_mapping->a_ops = &anon_aops; 242 - 243 - /* 244 - * Mark the inode dirty from the very beginning, 245 - * that way it will never be moved to the dirty 246 - * list because mark_inode_dirty() will think 247 - * that it already _is_ on the dirty list. 248 - */ 249 - inode->i_state = I_DIRTY; 250 - inode->i_mode = S_IRUSR | S_IWUSR; 251 - inode->i_uid = current_fsuid(); 252 - inode->i_gid = current_fsgid(); 253 - inode->i_flags |= S_PRIVATE; 254 - inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; 255 - return inode; 256 - } 257 - 258 183 static int __init anon_inode_init(void) 259 184 { 260 185 int error; ··· 235 224 error = PTR_ERR(anon_inode_mnt); 236 225 goto err_unregister_filesystem; 237 226 } 238 - anon_inode_inode = anon_inode_mkinode(); 239 - if (IS_ERR(anon_inode_inode)) { 240 - error = PTR_ERR(anon_inode_inode); 241 - goto err_mntput; 242 - } 243 - 244 227 return 0; 245 228 246 - err_mntput: 247 - kern_unmount(anon_inode_mnt); 248 229 err_unregister_filesystem: 249 230 unregister_filesystem(&anon_inode_fs_type); 250 231 err_exit: