xfs: initialize default acls for ->tmpfile()

The current tmpfile handler does not initialize default ACLs. Doing so
within xfs_vn_tmpfile() makes it roughly equivalent to xfs_vn_mknod(),
which is already used as a common create handler.

xfs_vn_mknod() does not currently have a mechanism to determine whether
to link the file into the namespace. Therefore, further abstract
xfs_vn_mknod() into a new xfs_generic_create() handler with a tmpfile
parameter. This new handler calls xfs_create_tmpfile() and d_tmpfile()
on the dentry when called via ->tmpfile().

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>

authored by Brian Foster and committed by Dave Chinner d540e43b c99d609a

Changed files
+29 -26
fs
+29 -26
fs/xfs/xfs_iops.c
··· 124 124 xfs_dentry_to_name(&teardown, dentry, 0); 125 125 126 126 xfs_remove(XFS_I(dir), &teardown, XFS_I(inode)); 127 - iput(inode); 128 127 } 129 128 130 129 STATIC int 131 - xfs_vn_mknod( 130 + xfs_generic_create( 132 131 struct inode *dir, 133 132 struct dentry *dentry, 134 133 umode_t mode, 135 - dev_t rdev) 134 + dev_t rdev, 135 + bool tmpfile) /* unnamed file */ 136 136 { 137 137 struct inode *inode; 138 138 struct xfs_inode *ip = NULL; ··· 156 156 if (error) 157 157 return error; 158 158 159 - xfs_dentry_to_name(&name, dentry, mode); 160 - error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip); 159 + if (!tmpfile) { 160 + xfs_dentry_to_name(&name, dentry, mode); 161 + error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip); 162 + } else { 163 + error = xfs_create_tmpfile(XFS_I(dir), dentry, mode, &ip); 164 + } 161 165 if (unlikely(error)) 162 166 goto out_free_acl; 163 167 ··· 184 180 } 185 181 #endif 186 182 187 - d_instantiate(dentry, inode); 183 + if (tmpfile) 184 + d_tmpfile(dentry, inode); 185 + else 186 + d_instantiate(dentry, inode); 187 + 188 188 out_free_acl: 189 189 if (default_acl) 190 190 posix_acl_release(default_acl); ··· 197 189 return -error; 198 190 199 191 out_cleanup_inode: 200 - xfs_cleanup_inode(dir, inode, dentry); 192 + if (!tmpfile) 193 + xfs_cleanup_inode(dir, inode, dentry); 194 + iput(inode); 201 195 goto out_free_acl; 196 + } 197 + 198 + STATIC int 199 + xfs_vn_mknod( 200 + struct inode *dir, 201 + struct dentry *dentry, 202 + umode_t mode, 203 + dev_t rdev) 204 + { 205 + return xfs_generic_create(dir, dentry, mode, rdev, false); 202 206 } 203 207 204 208 STATIC int ··· 373 353 374 354 out_cleanup_inode: 375 355 xfs_cleanup_inode(dir, inode, dentry); 356 + iput(inode); 376 357 out: 377 358 return -error; 378 359 } ··· 1074 1053 struct dentry *dentry, 1075 1054 umode_t mode) 1076 1055 { 1077 - int error; 1078 - struct xfs_inode *ip; 1079 - struct inode *inode; 1080 - 1081 - error = xfs_create_tmpfile(XFS_I(dir), dentry, mode, &ip); 1082 - if (unlikely(error)) 1083 - return -error; 1084 - 1085 - inode = VFS_I(ip); 1086 - 1087 - error = xfs_init_security(inode, dir, &dentry->d_name); 1088 - if (unlikely(error)) { 1089 - iput(inode); 1090 - return -error; 1091 - } 1092 - 1093 - d_tmpfile(dentry, inode); 1094 - 1095 - return 0; 1056 + return xfs_generic_create(dir, dentry, mode, 0, true); 1096 1057 } 1097 1058 1098 1059 static const struct inode_operations xfs_inode_operations = {