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

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'vfs-6.15-rc1.async.dir' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull vfs async dir updates from Christian Brauner:
"This contains cleanups that fell out of the work from async directory
handling:

- Change kern_path_locked() and user_path_locked_at() to never return
a negative dentry. This simplifies the usability of these helpers
in various places

- Drop d_exact_alias() from the remaining place in NFS where it is
still used. This also allows us to drop the d_exact_alias() helper
completely

- Drop an unnecessary call to fh_update() from nfsd_create_locked()

- Change i_op->mkdir() to return a struct dentry

Change vfs_mkdir() to return a dentry provided by the filesystems
which is hashed and positive. This allows us to reduce the number
of cases where the resulting dentry is not positive to very few
cases. The code in these places becomes simpler and easier to
understand.

- Repack DENTRY_* and LOOKUP_* flags"

* tag 'vfs-6.15-rc1.async.dir' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
doc: fix inline emphasis warning
VFS: Change vfs_mkdir() to return the dentry.
nfs: change mkdir inode_operation to return alternate dentry if needed.
fuse: return correct dentry for ->mkdir
ceph: return the correct dentry on mkdir
hostfs: store inode in dentry after mkdir if possible.
Change inode_operations.mkdir to return struct dentry *
nfsd: drop fh_update() from S_IFDIR branch of nfsd_create_locked()
nfs/vfs: discard d_exact_alias()
VFS: add common error checks to lookup_one_qstr_excl()
VFS: change kern_path_locked() and user_path_locked_at() to never return negative dentry
VFS: repack LOOKUP_ bit flags.
VFS: repack DENTRY_ flags.

+618 -599
+1 -1
Documentation/filesystems/locking.rst
··· 66 66 int (*link) (struct dentry *,struct inode *,struct dentry *); 67 67 int (*unlink) (struct inode *,struct dentry *); 68 68 int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *,const char *); 69 - int (*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t); 69 + struct dentry *(*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t); 70 70 int (*rmdir) (struct inode *,struct dentry *); 71 71 int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t,dev_t); 72 72 int (*rename) (struct mnt_idmap *, struct inode *, struct dentry *,
+43 -2
Documentation/filesystems/porting.rst
··· 1144 1144 1145 1145 --- 1146 1146 1147 - ** mandatory** 1147 + **mandatory** 1148 1148 1149 1149 ->d_revalidate() gets two extra arguments - inode of parent directory and 1150 1150 name our dentry is expected to have. Both are stable (dir is pinned in ··· 1160 1160 1161 1161 --- 1162 1162 1163 - ** mandatory ** 1163 + **recommended** 1164 + 1165 + kern_path_locked() and user_path_locked() no longer return a negative 1166 + dentry so this doesn't need to be checked. If the name cannot be found, 1167 + ERR_PTR(-ENOENT) is returned. 1168 + 1169 + --- 1170 + 1171 + **recommended** 1172 + 1173 + lookup_one_qstr_excl() is changed to return errors in more cases, so 1174 + these conditions don't require explicit checks: 1175 + 1176 + - if LOOKUP_CREATE is NOT given, then the dentry won't be negative, 1177 + ERR_PTR(-ENOENT) is returned instead 1178 + - if LOOKUP_EXCL IS given, then the dentry won't be positive, 1179 + ERR_PTR(-EEXIST) is rreturned instread 1180 + 1181 + LOOKUP_EXCL now means "target must not exist". It can be combined with 1182 + LOOK_CREATE or LOOKUP_RENAME_TARGET. 1183 + 1184 + --- 1185 + 1186 + **mandatory** 1164 1187 invalidate_inodes() is gone use evict_inodes() instead. 1188 + 1189 + --- 1190 + 1191 + **mandatory** 1192 + 1193 + ->mkdir() now returns a dentry. If the created inode is found to 1194 + already be in cache and have a dentry (often IS_ROOT()), it will need to 1195 + be spliced into the given name in place of the given dentry. That dentry 1196 + now needs to be returned. If the original dentry is used, NULL should 1197 + be returned. Any error should be returned with ERR_PTR(). 1198 + 1199 + In general, filesystems which use d_instantiate_new() to install the new 1200 + inode can safely return NULL. Filesystems which may not have an I_NEW inode 1201 + should use d_drop();d_splice_alias() and return the result of the latter. 1202 + 1203 + If a positive dentry cannot be returned for some reason, in-kernel 1204 + clients such as cachefiles, nfsd, smb/server may not perform ideally but 1205 + will fail-safe.
+21 -2
Documentation/filesystems/vfs.rst
··· 495 495 int (*link) (struct dentry *,struct inode *,struct dentry *); 496 496 int (*unlink) (struct inode *,struct dentry *); 497 497 int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *,const char *); 498 - int (*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t); 498 + struct dentry *(*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t); 499 499 int (*rmdir) (struct inode *,struct dentry *); 500 500 int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *,umode_t,dev_t); 501 501 int (*rename) (struct mnt_idmap *, struct inode *, struct dentry *, ··· 562 562 ``mkdir`` 563 563 called by the mkdir(2) system call. Only required if you want 564 564 to support creating subdirectories. You will probably need to 565 - call d_instantiate() just as you would in the create() method 565 + call d_instantiate_new() just as you would in the create() method. 566 + 567 + If d_instantiate_new() is not used and if the fh_to_dentry() 568 + export operation is provided, or if the storage might be 569 + accessible by another path (e.g. with a network filesystem) 570 + then more care may be needed. Importantly d_instantate() 571 + should not be used with an inode that is no longer I_NEW if there 572 + any chance that the inode could already be attached to a dentry. 573 + This is because of a hard rule in the VFS that a directory must 574 + only ever have one dentry. 575 + 576 + For example, if an NFS filesystem is mounted twice the new directory 577 + could be visible on the other mount before it is on the original 578 + mount, and a pair of name_to_handle_at(), open_by_handle_at() 579 + calls could instantiate the directory inode with an IS_ROOT() 580 + dentry before the first mkdir returns. 581 + 582 + If there is any chance this could happen, then the new inode 583 + should be d_drop()ed and attached with d_splice_alias(). The 584 + returned dentry (if any) should be returned by ->mkdir(). 566 585 567 586 ``rmdir`` 568 587 called by the rmdir(2) system call. Only required if you want
+33 -39
drivers/base/devtmpfs.c
··· 175 175 { 176 176 struct dentry *dentry; 177 177 struct path path; 178 - int err; 179 178 180 179 dentry = kern_path_create(AT_FDCWD, name, &path, LOOKUP_DIRECTORY); 181 180 if (IS_ERR(dentry)) 182 181 return PTR_ERR(dentry); 183 182 184 - err = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode); 185 - if (!err) 183 + dentry = vfs_mkdir(&nop_mnt_idmap, d_inode(path.dentry), dentry, mode); 184 + if (!IS_ERR(dentry)) 186 185 /* mark as kernel-created inode */ 187 186 d_inode(dentry)->i_private = &thread; 188 187 done_path_create(&path, dentry); 189 - return err; 188 + return PTR_ERR_OR_ZERO(dentry); 190 189 } 191 190 192 191 static int create_path(const char *nodepath) ··· 259 260 dentry = kern_path_locked(name, &parent); 260 261 if (IS_ERR(dentry)) 261 262 return PTR_ERR(dentry); 262 - if (d_really_is_positive(dentry)) { 263 - if (d_inode(dentry)->i_private == &thread) 264 - err = vfs_rmdir(&nop_mnt_idmap, d_inode(parent.dentry), 265 - dentry); 266 - else 267 - err = -EPERM; 268 - } else { 269 - err = -ENOENT; 270 - } 263 + if (d_inode(dentry)->i_private == &thread) 264 + err = vfs_rmdir(&nop_mnt_idmap, d_inode(parent.dentry), 265 + dentry); 266 + else 267 + err = -EPERM; 268 + 271 269 dput(dentry); 272 270 inode_unlock(d_inode(parent.dentry)); 273 271 path_put(&parent); ··· 321 325 { 322 326 struct path parent; 323 327 struct dentry *dentry; 328 + struct kstat stat; 329 + struct path p; 324 330 int deleted = 0; 325 331 int err; 326 332 ··· 330 332 if (IS_ERR(dentry)) 331 333 return PTR_ERR(dentry); 332 334 333 - if (d_really_is_positive(dentry)) { 334 - struct kstat stat; 335 - struct path p = {.mnt = parent.mnt, .dentry = dentry}; 336 - err = vfs_getattr(&p, &stat, STATX_TYPE | STATX_MODE, 337 - AT_STATX_SYNC_AS_STAT); 338 - if (!err && dev_mynode(dev, d_inode(dentry), &stat)) { 339 - struct iattr newattrs; 340 - /* 341 - * before unlinking this node, reset permissions 342 - * of possible references like hardlinks 343 - */ 344 - newattrs.ia_uid = GLOBAL_ROOT_UID; 345 - newattrs.ia_gid = GLOBAL_ROOT_GID; 346 - newattrs.ia_mode = stat.mode & ~0777; 347 - newattrs.ia_valid = 348 - ATTR_UID|ATTR_GID|ATTR_MODE; 349 - inode_lock(d_inode(dentry)); 350 - notify_change(&nop_mnt_idmap, dentry, &newattrs, NULL); 351 - inode_unlock(d_inode(dentry)); 352 - err = vfs_unlink(&nop_mnt_idmap, d_inode(parent.dentry), 353 - dentry, NULL); 354 - if (!err || err == -ENOENT) 355 - deleted = 1; 356 - } 357 - } else { 358 - err = -ENOENT; 335 + p.mnt = parent.mnt; 336 + p.dentry = dentry; 337 + err = vfs_getattr(&p, &stat, STATX_TYPE | STATX_MODE, 338 + AT_STATX_SYNC_AS_STAT); 339 + if (!err && dev_mynode(dev, d_inode(dentry), &stat)) { 340 + struct iattr newattrs; 341 + /* 342 + * before unlinking this node, reset permissions 343 + * of possible references like hardlinks 344 + */ 345 + newattrs.ia_uid = GLOBAL_ROOT_UID; 346 + newattrs.ia_gid = GLOBAL_ROOT_GID; 347 + newattrs.ia_mode = stat.mode & ~0777; 348 + newattrs.ia_valid = 349 + ATTR_UID|ATTR_GID|ATTR_MODE; 350 + inode_lock(d_inode(dentry)); 351 + notify_change(&nop_mnt_idmap, dentry, &newattrs, NULL); 352 + inode_unlock(d_inode(dentry)); 353 + err = vfs_unlink(&nop_mnt_idmap, d_inode(parent.dentry), 354 + dentry, NULL); 355 + if (!err || err == -ENOENT) 356 + deleted = 1; 359 357 } 360 358 dput(dentry); 361 359 inode_unlock(d_inode(parent.dentry));
+3 -4
fs/9p/vfs_inode.c
··· 669 669 * 670 670 */ 671 671 672 - static int v9fs_vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 673 - struct dentry *dentry, umode_t mode) 672 + static struct dentry *v9fs_vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 673 + struct dentry *dentry, umode_t mode) 674 674 { 675 675 int err; 676 676 u32 perm; ··· 692 692 693 693 if (fid) 694 694 p9_fid_put(fid); 695 - 696 - return err; 695 + return ERR_PTR(err); 697 696 } 698 697 699 698 /**
+4 -4
fs/9p/vfs_inode_dotl.c
··· 350 350 * 351 351 */ 352 352 353 - static int v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap, 354 - struct inode *dir, struct dentry *dentry, 355 - umode_t omode) 353 + static struct dentry *v9fs_vfs_mkdir_dotl(struct mnt_idmap *idmap, 354 + struct inode *dir, struct dentry *dentry, 355 + umode_t omode) 356 356 { 357 357 int err; 358 358 struct v9fs_session_info *v9ses; ··· 417 417 p9_fid_put(fid); 418 418 v9fs_put_acl(dacl, pacl); 419 419 p9_fid_put(dfid); 420 - return err; 420 + return ERR_PTR(err); 421 421 } 422 422 423 423 static int
+1 -1
fs/affs/affs.h
··· 168 168 extern int affs_unlink(struct inode *dir, struct dentry *dentry); 169 169 extern int affs_create(struct mnt_idmap *idmap, struct inode *dir, 170 170 struct dentry *dentry, umode_t mode, bool); 171 - extern int affs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 171 + extern struct dentry *affs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 172 172 struct dentry *dentry, umode_t mode); 173 173 extern int affs_rmdir(struct inode *dir, struct dentry *dentry); 174 174 extern int affs_link(struct dentry *olddentry, struct inode *dir,
+4 -4
fs/affs/namei.c
··· 273 273 return 0; 274 274 } 275 275 276 - int 276 + struct dentry * 277 277 affs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 278 278 struct dentry *dentry, umode_t mode) 279 279 { ··· 285 285 286 286 inode = affs_new_inode(dir); 287 287 if (!inode) 288 - return -ENOSPC; 288 + return ERR_PTR(-ENOSPC); 289 289 290 290 inode->i_mode = S_IFDIR | mode; 291 291 affs_mode_to_prot(inode); ··· 298 298 clear_nlink(inode); 299 299 mark_inode_dirty(inode); 300 300 iput(inode); 301 - return error; 301 + return ERR_PTR(error); 302 302 } 303 - return 0; 303 + return NULL; 304 304 } 305 305 306 306 int
+6 -6
fs/afs/dir.c
··· 33 33 loff_t fpos, u64 ino, unsigned dtype); 34 34 static int afs_create(struct mnt_idmap *idmap, struct inode *dir, 35 35 struct dentry *dentry, umode_t mode, bool excl); 36 - static int afs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 37 - struct dentry *dentry, umode_t mode); 36 + static struct dentry *afs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 37 + struct dentry *dentry, umode_t mode); 38 38 static int afs_rmdir(struct inode *dir, struct dentry *dentry); 39 39 static int afs_unlink(struct inode *dir, struct dentry *dentry); 40 40 static int afs_link(struct dentry *from, struct inode *dir, ··· 1315 1315 /* 1316 1316 * create a directory on an AFS filesystem 1317 1317 */ 1318 - static int afs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1319 - struct dentry *dentry, umode_t mode) 1318 + static struct dentry *afs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1319 + struct dentry *dentry, umode_t mode) 1320 1320 { 1321 1321 struct afs_operation *op; 1322 1322 struct afs_vnode *dvnode = AFS_FS_I(dir); ··· 1328 1328 op = afs_alloc_operation(NULL, dvnode->volume); 1329 1329 if (IS_ERR(op)) { 1330 1330 d_drop(dentry); 1331 - return PTR_ERR(op); 1331 + return ERR_CAST(op); 1332 1332 } 1333 1333 1334 1334 fscache_use_cookie(afs_vnode_cache(dvnode), true); ··· 1344 1344 op->ops = &afs_mkdir_operation; 1345 1345 ret = afs_do_sync_operation(op); 1346 1346 afs_dir_unuse_cookie(dvnode, ret); 1347 - return ret; 1347 + return ERR_PTR(ret); 1348 1348 } 1349 1349 1350 1350 /*
+7 -7
fs/autofs/root.c
··· 15 15 struct dentry *, const char *); 16 16 static int autofs_dir_unlink(struct inode *, struct dentry *); 17 17 static int autofs_dir_rmdir(struct inode *, struct dentry *); 18 - static int autofs_dir_mkdir(struct mnt_idmap *, struct inode *, 19 - struct dentry *, umode_t); 18 + static struct dentry *autofs_dir_mkdir(struct mnt_idmap *, struct inode *, 19 + struct dentry *, umode_t); 20 20 static long autofs_root_ioctl(struct file *, unsigned int, unsigned long); 21 21 #ifdef CONFIG_COMPAT 22 22 static long autofs_root_compat_ioctl(struct file *, ··· 720 720 return 0; 721 721 } 722 722 723 - static int autofs_dir_mkdir(struct mnt_idmap *idmap, 724 - struct inode *dir, struct dentry *dentry, 725 - umode_t mode) 723 + static struct dentry *autofs_dir_mkdir(struct mnt_idmap *idmap, 724 + struct inode *dir, struct dentry *dentry, 725 + umode_t mode) 726 726 { 727 727 struct autofs_sb_info *sbi = autofs_sbi(dir->i_sb); 728 728 struct autofs_info *ino = autofs_dentry_ino(dentry); ··· 739 739 740 740 inode = autofs_get_inode(dir->i_sb, S_IFDIR | mode); 741 741 if (!inode) 742 - return -ENOMEM; 742 + return ERR_PTR(-ENOMEM); 743 743 d_add(dentry, inode); 744 744 745 745 if (sbi->version < 5) ··· 751 751 inc_nlink(dir); 752 752 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 753 753 754 - return 0; 754 + return NULL; 755 755 } 756 756 757 757 /* Get/set timeout ioctl() operation */
+3 -3
fs/bad_inode.c
··· 58 58 return -EIO; 59 59 } 60 60 61 - static int bad_inode_mkdir(struct mnt_idmap *idmap, struct inode *dir, 62 - struct dentry *dentry, umode_t mode) 61 + static struct dentry *bad_inode_mkdir(struct mnt_idmap *idmap, struct inode *dir, 62 + struct dentry *dentry, umode_t mode) 63 63 { 64 - return -EIO; 64 + return ERR_PTR(-EIO); 65 65 } 66 66 67 67 static int bad_inode_rmdir (struct inode *dir, struct dentry *dentry)
-4
fs/bcachefs/fs-ioctl.c
··· 511 511 ret = -EXDEV; 512 512 goto err; 513 513 } 514 - if (!d_is_positive(victim)) { 515 - ret = -ENOENT; 516 - goto err; 517 - } 518 514 ret = __bch2_unlink(dir, victim, true); 519 515 if (!ret) { 520 516 fsnotify_rmdir(dir, victim);
+3 -3
fs/bcachefs/fs.c
··· 858 858 return bch2_err_class(ret); 859 859 } 860 860 861 - static int bch2_mkdir(struct mnt_idmap *idmap, 862 - struct inode *vdir, struct dentry *dentry, umode_t mode) 861 + static struct dentry *bch2_mkdir(struct mnt_idmap *idmap, 862 + struct inode *vdir, struct dentry *dentry, umode_t mode) 863 863 { 864 - return bch2_mknod(idmap, vdir, dentry, mode|S_IFDIR, 0); 864 + return ERR_PTR(bch2_mknod(idmap, vdir, dentry, mode|S_IFDIR, 0)); 865 865 } 866 866 867 867 static int bch2_rename2(struct mnt_idmap *idmap,
+4 -4
fs/btrfs/inode.c
··· 6744 6744 return err; 6745 6745 } 6746 6746 6747 - static int btrfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 6748 - struct dentry *dentry, umode_t mode) 6747 + static struct dentry *btrfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 6748 + struct dentry *dentry, umode_t mode) 6749 6749 { 6750 6750 struct inode *inode; 6751 6751 6752 6752 inode = new_inode(dir->i_sb); 6753 6753 if (!inode) 6754 - return -ENOMEM; 6754 + return ERR_PTR(-ENOMEM); 6755 6755 inode_init_owner(idmap, inode, dir, S_IFDIR | mode); 6756 6756 inode->i_op = &btrfs_dir_inode_operations; 6757 6757 inode->i_fop = &btrfs_dir_file_operations; 6758 - return btrfs_create_common(dir, dentry, inode); 6758 + return ERR_PTR(btrfs_create_common(dir, dentry, inode)); 6759 6759 } 6760 6760 6761 6761 static noinline int uncompress_inline(struct btrfs_path *path,
+9 -7
fs/cachefiles/namei.c
··· 128 128 ret = security_path_mkdir(&path, subdir, 0700); 129 129 if (ret < 0) 130 130 goto mkdir_error; 131 - ret = cachefiles_inject_write_error(); 132 - if (ret == 0) 133 - ret = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700); 134 - if (ret < 0) { 131 + subdir = ERR_PTR(cachefiles_inject_write_error()); 132 + if (!IS_ERR(subdir)) 133 + subdir = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), subdir, 0700); 134 + ret = PTR_ERR(subdir); 135 + if (IS_ERR(subdir)) { 135 136 trace_cachefiles_vfs_error(NULL, d_inode(dir), ret, 136 137 cachefiles_trace_mkdir_error); 137 138 goto mkdir_error; 138 139 } 139 140 trace_cachefiles_mkdir(dir, subdir); 140 141 141 - if (unlikely(d_unhashed(subdir))) { 142 - cachefiles_put_directory(subdir); 142 + if (unlikely(d_unhashed(subdir) || d_is_negative(subdir))) { 143 + dput(subdir); 143 144 goto retry; 144 145 } 145 146 ASSERT(d_backing_inode(subdir)); ··· 196 195 197 196 mkdir_error: 198 197 inode_unlock(d_inode(dir)); 199 - dput(subdir); 198 + if (!IS_ERR(subdir)) 199 + dput(subdir); 200 200 pr_err("mkdir %s failed with error %d\n", dirname, ret); 201 201 return ERR_PTR(ret); 202 202
+19 -11
fs/ceph/dir.c
··· 1092 1092 return err; 1093 1093 } 1094 1094 1095 - static int ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1096 - struct dentry *dentry, umode_t mode) 1095 + static struct dentry *ceph_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1096 + struct dentry *dentry, umode_t mode) 1097 1097 { 1098 1098 struct ceph_mds_client *mdsc = ceph_sb_to_mdsc(dir->i_sb); 1099 1099 struct ceph_client *cl = mdsc->fsc->client; 1100 1100 struct ceph_mds_request *req; 1101 1101 struct ceph_acl_sec_ctx as_ctx = {}; 1102 + struct dentry *ret; 1102 1103 int err; 1103 1104 int op; 1104 1105 1105 1106 err = ceph_wait_on_conflict_unlink(dentry); 1106 1107 if (err) 1107 - return err; 1108 + return ERR_PTR(err); 1108 1109 1109 1110 if (ceph_snap(dir) == CEPH_SNAPDIR) { 1110 1111 /* mkdir .snap/foo is a MKSNAP */ ··· 1117 1116 ceph_vinop(dir), dentry, dentry, mode); 1118 1117 op = CEPH_MDS_OP_MKDIR; 1119 1118 } else { 1120 - err = -EROFS; 1119 + ret = ERR_PTR(-EROFS); 1121 1120 goto out; 1122 1121 } 1123 1122 1124 1123 if (op == CEPH_MDS_OP_MKDIR && 1125 1124 ceph_quota_is_max_files_exceeded(dir)) { 1126 - err = -EDQUOT; 1125 + ret = ERR_PTR(-EDQUOT); 1127 1126 goto out; 1128 1127 } 1129 1128 if ((op == CEPH_MDS_OP_MKSNAP) && IS_ENCRYPTED(dir) && 1130 1129 !fscrypt_has_encryption_key(dir)) { 1131 - err = -ENOKEY; 1130 + ret = ERR_PTR(-ENOKEY); 1132 1131 goto out; 1133 1132 } 1134 1133 1135 1134 1136 1135 req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS); 1137 1136 if (IS_ERR(req)) { 1138 - err = PTR_ERR(req); 1137 + ret = ERR_CAST(req); 1139 1138 goto out; 1140 1139 } 1141 1140 1142 1141 mode |= S_IFDIR; 1143 1142 req->r_new_inode = ceph_new_inode(dir, dentry, &mode, &as_ctx); 1144 1143 if (IS_ERR(req->r_new_inode)) { 1145 - err = PTR_ERR(req->r_new_inode); 1144 + ret = ERR_CAST(req->r_new_inode); 1146 1145 req->r_new_inode = NULL; 1147 1146 goto out_req; 1148 1147 } ··· 1166 1165 !req->r_reply_info.head->is_target && 1167 1166 !req->r_reply_info.head->is_dentry) 1168 1167 err = ceph_handle_notrace_create(dir, dentry); 1168 + ret = ERR_PTR(err); 1169 1169 out_req: 1170 + if (!IS_ERR(ret) && req->r_dentry != dentry) 1171 + /* Some other dentry was spliced in */ 1172 + ret = dget(req->r_dentry); 1170 1173 ceph_mdsc_put_request(req); 1171 1174 out: 1172 - if (!err) 1175 + if (!IS_ERR(ret)) { 1176 + if (ret) 1177 + dentry = ret; 1173 1178 ceph_init_inode_acls(d_inode(dentry), &as_ctx); 1174 - else 1179 + } else { 1175 1180 d_drop(dentry); 1181 + } 1176 1182 ceph_release_acl_sec_ctx(&as_ctx); 1177 - return err; 1183 + return ret; 1178 1184 } 1179 1185 1180 1186 static int ceph_link(struct dentry *old_dentry, struct inode *dir,
+7 -7
fs/coda/dir.c
··· 166 166 return error; 167 167 } 168 168 169 - static int coda_mkdir(struct mnt_idmap *idmap, struct inode *dir, 170 - struct dentry *de, umode_t mode) 169 + static struct dentry *coda_mkdir(struct mnt_idmap *idmap, struct inode *dir, 170 + struct dentry *de, umode_t mode) 171 171 { 172 172 struct inode *inode; 173 173 struct coda_vattr attrs; ··· 177 177 struct CodaFid newfid; 178 178 179 179 if (is_root_inode(dir) && coda_iscontrol(name, len)) 180 - return -EPERM; 180 + return ERR_PTR(-EPERM); 181 181 182 182 attrs.va_mode = mode; 183 - error = venus_mkdir(dir->i_sb, coda_i2f(dir), 183 + error = venus_mkdir(dir->i_sb, coda_i2f(dir), 184 184 name, len, &newfid, &attrs); 185 185 if (error) 186 186 goto err_out; 187 - 187 + 188 188 inode = coda_iget(dir->i_sb, &newfid, &attrs); 189 189 if (IS_ERR(inode)) { 190 190 error = PTR_ERR(inode); ··· 195 195 coda_dir_inc_nlink(dir); 196 196 coda_dir_update_mtime(dir); 197 197 d_instantiate(de, inode); 198 - return 0; 198 + return NULL; 199 199 err_out: 200 200 d_drop(de); 201 - return error; 201 + return ERR_PTR(error); 202 202 } 203 203 204 204 /* try to make de an entry in dir_inodde linked to source_de */
+3 -3
fs/configfs/dir.c
··· 1280 1280 } 1281 1281 EXPORT_SYMBOL(configfs_depend_item_unlocked); 1282 1282 1283 - static int configfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1284 - struct dentry *dentry, umode_t mode) 1283 + static struct dentry *configfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1284 + struct dentry *dentry, umode_t mode) 1285 1285 { 1286 1286 int ret = 0; 1287 1287 int module_got = 0; ··· 1461 1461 put_fragment(frag); 1462 1462 1463 1463 out: 1464 - return ret; 1464 + return ERR_PTR(ret); 1465 1465 } 1466 1466 1467 1467 static int configfs_rmdir(struct inode *dir, struct dentry *dentry)
-46
fs/dcache.c
··· 2688 2688 } 2689 2689 EXPORT_SYMBOL(d_add); 2690 2690 2691 - /** 2692 - * d_exact_alias - find and hash an exact unhashed alias 2693 - * @entry: dentry to add 2694 - * @inode: The inode to go with this dentry 2695 - * 2696 - * If an unhashed dentry with the same name/parent and desired 2697 - * inode already exists, hash and return it. Otherwise, return 2698 - * NULL. 2699 - * 2700 - * Parent directory should be locked. 2701 - */ 2702 - struct dentry *d_exact_alias(struct dentry *entry, struct inode *inode) 2703 - { 2704 - struct dentry *alias; 2705 - unsigned int hash = entry->d_name.hash; 2706 - 2707 - spin_lock(&inode->i_lock); 2708 - hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) { 2709 - /* 2710 - * Don't need alias->d_lock here, because aliases with 2711 - * d_parent == entry->d_parent are not subject to name or 2712 - * parent changes, because the parent inode i_mutex is held. 2713 - */ 2714 - if (alias->d_name.hash != hash) 2715 - continue; 2716 - if (alias->d_parent != entry->d_parent) 2717 - continue; 2718 - if (!d_same_name(alias, entry->d_parent, &entry->d_name)) 2719 - continue; 2720 - spin_lock(&alias->d_lock); 2721 - if (!d_unhashed(alias)) { 2722 - spin_unlock(&alias->d_lock); 2723 - alias = NULL; 2724 - } else { 2725 - dget_dlock(alias); 2726 - __d_rehash(alias); 2727 - spin_unlock(&alias->d_lock); 2728 - } 2729 - spin_unlock(&inode->i_lock); 2730 - return alias; 2731 - } 2732 - spin_unlock(&inode->i_lock); 2733 - return NULL; 2734 - } 2735 - EXPORT_SYMBOL(d_exact_alias); 2736 - 2737 2691 static void swap_names(struct dentry *dentry, struct dentry *target) 2738 2692 { 2739 2693 if (unlikely(dname_external(target))) {
+13 -7
fs/ecryptfs/inode.c
··· 503 503 return rc; 504 504 } 505 505 506 - static int ecryptfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 507 - struct dentry *dentry, umode_t mode) 506 + static struct dentry *ecryptfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 507 + struct dentry *dentry, umode_t mode) 508 508 { 509 509 int rc; 510 510 struct dentry *lower_dentry; 511 511 struct inode *lower_dir; 512 512 513 513 rc = lock_parent(dentry, &lower_dentry, &lower_dir); 514 - if (!rc) 515 - rc = vfs_mkdir(&nop_mnt_idmap, lower_dir, 516 - lower_dentry, mode); 517 - if (rc || d_really_is_negative(lower_dentry)) 514 + if (rc) 515 + goto out; 516 + 517 + lower_dentry = vfs_mkdir(&nop_mnt_idmap, lower_dir, 518 + lower_dentry, mode); 519 + rc = PTR_ERR(lower_dentry); 520 + if (IS_ERR(lower_dentry)) 521 + goto out; 522 + rc = 0; 523 + if (d_unhashed(lower_dentry)) 518 524 goto out; 519 525 rc = ecryptfs_interpose(lower_dentry, dentry, dir->i_sb); 520 526 if (rc) ··· 532 526 inode_unlock(lower_dir); 533 527 if (d_really_is_negative(dentry)) 534 528 d_drop(dentry); 535 - return rc; 529 + return ERR_PTR(rc); 536 530 } 537 531 538 532 static int ecryptfs_rmdir(struct inode *dir, struct dentry *dentry)
+4 -4
fs/exfat/namei.c
··· 840 840 return err; 841 841 } 842 842 843 - static int exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, 844 - struct dentry *dentry, umode_t mode) 843 + static struct dentry *exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, 844 + struct dentry *dentry, umode_t mode) 845 845 { 846 846 struct super_block *sb = dir->i_sb; 847 847 struct inode *inode; ··· 851 851 loff_t size = i_size_read(dir); 852 852 853 853 if (unlikely(exfat_forced_shutdown(sb))) 854 - return -EIO; 854 + return ERR_PTR(-EIO); 855 855 856 856 mutex_lock(&EXFAT_SB(sb)->s_lock); 857 857 exfat_set_volume_dirty(sb); ··· 882 882 883 883 unlock: 884 884 mutex_unlock(&EXFAT_SB(sb)->s_lock); 885 - return err; 885 + return ERR_PTR(err); 886 886 } 887 887 888 888 static int exfat_check_dir_empty(struct super_block *sb,
+5 -4
fs/ext2/namei.c
··· 225 225 return err; 226 226 } 227 227 228 - static int ext2_mkdir(struct mnt_idmap * idmap, 229 - struct inode * dir, struct dentry * dentry, umode_t mode) 228 + static struct dentry *ext2_mkdir(struct mnt_idmap * idmap, 229 + struct inode * dir, struct dentry * dentry, 230 + umode_t mode) 230 231 { 231 232 struct inode * inode; 232 233 int err; 233 234 234 235 err = dquot_initialize(dir); 235 236 if (err) 236 - return err; 237 + return ERR_PTR(err); 237 238 238 239 inode_inc_link_count(dir); 239 240 ··· 259 258 260 259 d_instantiate_new(dentry, inode); 261 260 out: 262 - return err; 261 + return ERR_PTR(err); 263 262 264 263 out_fail: 265 264 inode_dec_link_count(inode);
+5 -5
fs/ext4/namei.c
··· 3004 3004 return err; 3005 3005 } 3006 3006 3007 - static int ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir, 3008 - struct dentry *dentry, umode_t mode) 3007 + static struct dentry *ext4_mkdir(struct mnt_idmap *idmap, struct inode *dir, 3008 + struct dentry *dentry, umode_t mode) 3009 3009 { 3010 3010 handle_t *handle; 3011 3011 struct inode *inode; 3012 3012 int err, err2 = 0, credits, retries = 0; 3013 3013 3014 3014 if (EXT4_DIR_LINK_MAX(dir)) 3015 - return -EMLINK; 3015 + return ERR_PTR(-EMLINK); 3016 3016 3017 3017 err = dquot_initialize(dir); 3018 3018 if (err) 3019 - return err; 3019 + return ERR_PTR(err); 3020 3020 3021 3021 credits = (EXT4_DATA_TRANS_BLOCKS(dir->i_sb) + 3022 3022 EXT4_INDEX_EXTRA_TRANS_BLOCKS + 3); ··· 3066 3066 out_retry: 3067 3067 if (err == -ENOSPC && ext4_should_retry_alloc(dir->i_sb, &retries)) 3068 3068 goto retry; 3069 - return err; 3069 + return ERR_PTR(err); 3070 3070 } 3071 3071 3072 3072 /*
+7 -7
fs/f2fs/namei.c
··· 684 684 return err; 685 685 } 686 686 687 - static int f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 688 - struct dentry *dentry, umode_t mode) 687 + static struct dentry *f2fs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 688 + struct dentry *dentry, umode_t mode) 689 689 { 690 690 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 691 691 struct inode *inode; 692 692 int err; 693 693 694 694 if (unlikely(f2fs_cp_error(sbi))) 695 - return -EIO; 695 + return ERR_PTR(-EIO); 696 696 697 697 err = f2fs_dquot_initialize(dir); 698 698 if (err) 699 - return err; 699 + return ERR_PTR(err); 700 700 701 701 inode = f2fs_new_inode(idmap, dir, S_IFDIR | mode, NULL); 702 702 if (IS_ERR(inode)) 703 - return PTR_ERR(inode); 703 + return ERR_CAST(inode); 704 704 705 705 inode->i_op = &f2fs_dir_inode_operations; 706 706 inode->i_fop = &f2fs_dir_operations; ··· 722 722 f2fs_sync_fs(sbi->sb, 1); 723 723 724 724 f2fs_balance_fs(sbi, true); 725 - return 0; 725 + return NULL; 726 726 727 727 out_fail: 728 728 clear_inode_flag(inode, FI_INC_LINK); 729 729 f2fs_handle_failed_inode(inode); 730 - return err; 730 + return ERR_PTR(err); 731 731 } 732 732 733 733 static int f2fs_rmdir(struct inode *dir, struct dentry *dentry)
+4 -4
fs/fat/namei_msdos.c
··· 339 339 } 340 340 341 341 /***** Make a directory */ 342 - static int msdos_mkdir(struct mnt_idmap *idmap, struct inode *dir, 343 - struct dentry *dentry, umode_t mode) 342 + static struct dentry *msdos_mkdir(struct mnt_idmap *idmap, struct inode *dir, 343 + struct dentry *dentry, umode_t mode) 344 344 { 345 345 struct super_block *sb = dir->i_sb; 346 346 struct fat_slot_info sinfo; ··· 389 389 390 390 mutex_unlock(&MSDOS_SB(sb)->s_lock); 391 391 fat_flush_inodes(sb, dir, inode); 392 - return 0; 392 + return NULL; 393 393 394 394 out_free: 395 395 fat_free_clusters(dir, cluster); 396 396 out: 397 397 mutex_unlock(&MSDOS_SB(sb)->s_lock); 398 - return err; 398 + return ERR_PTR(err); 399 399 } 400 400 401 401 /***** Unlink a file */
+4 -4
fs/fat/namei_vfat.c
··· 841 841 return err; 842 842 } 843 843 844 - static int vfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, 845 - struct dentry *dentry, umode_t mode) 844 + static struct dentry *vfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, 845 + struct dentry *dentry, umode_t mode) 846 846 { 847 847 struct super_block *sb = dir->i_sb; 848 848 struct inode *inode; ··· 877 877 d_instantiate(dentry, inode); 878 878 879 879 mutex_unlock(&MSDOS_SB(sb)->s_lock); 880 - return 0; 880 + return NULL; 881 881 882 882 out_free: 883 883 fat_free_clusters(dir, cluster); 884 884 out: 885 885 mutex_unlock(&MSDOS_SB(sb)->s_lock); 886 - return err; 886 + return ERR_PTR(err); 887 887 } 888 888 889 889 static int vfat_get_dotdot_de(struct inode *inode, struct buffer_head **bh,
+32 -18
fs/fuse/dir.c
··· 781 781 /* 782 782 * Code shared between mknod, mkdir, symlink and link 783 783 */ 784 - static int create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm, 785 - struct fuse_args *args, struct inode *dir, 786 - struct dentry *entry, umode_t mode) 784 + static struct dentry *create_new_entry(struct mnt_idmap *idmap, struct fuse_mount *fm, 785 + struct fuse_args *args, struct inode *dir, 786 + struct dentry *entry, umode_t mode) 787 787 { 788 788 struct fuse_entry_out outarg; 789 789 struct inode *inode; ··· 792 792 struct fuse_forget_link *forget; 793 793 794 794 if (fuse_is_bad(dir)) 795 - return -EIO; 795 + return ERR_PTR(-EIO); 796 796 797 797 forget = fuse_alloc_forget(); 798 798 if (!forget) 799 - return -ENOMEM; 799 + return ERR_PTR(-ENOMEM); 800 800 801 801 memset(&outarg, 0, sizeof(outarg)); 802 802 args->nodeid = get_node_id(dir); ··· 826 826 &outarg.attr, ATTR_TIMEOUT(&outarg), 0, 0); 827 827 if (!inode) { 828 828 fuse_queue_forget(fm->fc, forget, outarg.nodeid, 1); 829 - return -ENOMEM; 829 + return ERR_PTR(-ENOMEM); 830 830 } 831 831 kfree(forget); 832 832 833 833 d_drop(entry); 834 834 d = d_splice_alias(inode, entry); 835 835 if (IS_ERR(d)) 836 - return PTR_ERR(d); 836 + return d; 837 837 838 - if (d) { 838 + if (d) 839 839 fuse_change_entry_timeout(d, &outarg); 840 - dput(d); 841 - } else { 840 + else 842 841 fuse_change_entry_timeout(entry, &outarg); 843 - } 844 842 fuse_dir_changed(dir); 845 - return 0; 843 + return d; 846 844 847 845 out_put_forget_req: 848 846 if (err == -EEXIST) 849 847 fuse_invalidate_entry(entry); 850 848 kfree(forget); 851 - return err; 849 + return ERR_PTR(err); 850 + } 851 + 852 + static int create_new_nondir(struct mnt_idmap *idmap, struct fuse_mount *fm, 853 + struct fuse_args *args, struct inode *dir, 854 + struct dentry *entry, umode_t mode) 855 + { 856 + /* 857 + * Note that when creating anything other than a directory we 858 + * can be sure create_new_entry() will NOT return an alternate 859 + * dentry as d_splice_alias() only returns an alternate dentry 860 + * for directories. So we don't need to check for that case 861 + * when passing back the result. 862 + */ 863 + WARN_ON_ONCE(S_ISDIR(mode)); 864 + 865 + return PTR_ERR(create_new_entry(idmap, fm, args, dir, entry, mode)); 852 866 } 853 867 854 868 static int fuse_mknod(struct mnt_idmap *idmap, struct inode *dir, ··· 885 871 args.in_args[0].value = &inarg; 886 872 args.in_args[1].size = entry->d_name.len + 1; 887 873 args.in_args[1].value = entry->d_name.name; 888 - return create_new_entry(idmap, fm, &args, dir, entry, mode); 874 + return create_new_nondir(idmap, fm, &args, dir, entry, mode); 889 875 } 890 876 891 877 static int fuse_create(struct mnt_idmap *idmap, struct inode *dir, ··· 912 898 return err; 913 899 } 914 900 915 - static int fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir, 916 - struct dentry *entry, umode_t mode) 901 + static struct dentry *fuse_mkdir(struct mnt_idmap *idmap, struct inode *dir, 902 + struct dentry *entry, umode_t mode) 917 903 { 918 904 struct fuse_mkdir_in inarg; 919 905 struct fuse_mount *fm = get_fuse_mount(dir); ··· 948 934 args.in_args[1].value = entry->d_name.name; 949 935 args.in_args[2].size = len; 950 936 args.in_args[2].value = link; 951 - return create_new_entry(idmap, fm, &args, dir, entry, S_IFLNK); 937 + return create_new_nondir(idmap, fm, &args, dir, entry, S_IFLNK); 952 938 } 953 939 954 940 void fuse_flush_time_update(struct inode *inode) ··· 1145 1131 args.in_args[0].value = &inarg; 1146 1132 args.in_args[1].size = newent->d_name.len + 1; 1147 1133 args.in_args[1].value = newent->d_name.name; 1148 - err = create_new_entry(&invalid_mnt_idmap, fm, &args, newdir, newent, inode->i_mode); 1134 + err = create_new_nondir(&invalid_mnt_idmap, fm, &args, newdir, newent, inode->i_mode); 1149 1135 if (!err) 1150 1136 fuse_update_ctime_in_cache(inode); 1151 1137 else if (err == -EINTR)
+5 -4
fs/gfs2/inode.c
··· 1248 1248 * @dentry: The dentry of the new directory 1249 1249 * @mode: The mode of the new directory 1250 1250 * 1251 - * Returns: errno 1251 + * Returns: the dentry, or ERR_PTR(errno) 1252 1252 */ 1253 1253 1254 - static int gfs2_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1255 - struct dentry *dentry, umode_t mode) 1254 + static struct dentry *gfs2_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1255 + struct dentry *dentry, umode_t mode) 1256 1256 { 1257 1257 unsigned dsize = gfs2_max_stuffed_size(GFS2_I(dir)); 1258 - return gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0); 1258 + 1259 + return ERR_PTR(gfs2_create_inode(dir, dentry, NULL, S_IFDIR | mode, 0, NULL, dsize, 0)); 1259 1260 } 1260 1261 1261 1262 /**
+5 -5
fs/hfs/dir.c
··· 219 219 * in a directory, given the inode for the parent directory and the 220 220 * name (and its length) of the new directory. 221 221 */ 222 - static int hfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 223 - struct dentry *dentry, umode_t mode) 222 + static struct dentry *hfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 223 + struct dentry *dentry, umode_t mode) 224 224 { 225 225 struct inode *inode; 226 226 int res; 227 227 228 228 inode = hfs_new_inode(dir, &dentry->d_name, S_IFDIR | mode); 229 229 if (!inode) 230 - return -ENOMEM; 230 + return ERR_PTR(-ENOMEM); 231 231 232 232 res = hfs_cat_create(inode->i_ino, dir, &dentry->d_name, inode); 233 233 if (res) { 234 234 clear_nlink(inode); 235 235 hfs_delete_inode(inode); 236 236 iput(inode); 237 - return res; 237 + return ERR_PTR(res); 238 238 } 239 239 d_instantiate(dentry, inode); 240 240 mark_inode_dirty(inode); 241 - return 0; 241 + return NULL; 242 242 } 243 243 244 244 /*
+3 -3
fs/hfsplus/dir.c
··· 523 523 return hfsplus_mknod(&nop_mnt_idmap, dir, dentry, mode, 0); 524 524 } 525 525 526 - static int hfsplus_mkdir(struct mnt_idmap *idmap, struct inode *dir, 527 - struct dentry *dentry, umode_t mode) 526 + static struct dentry *hfsplus_mkdir(struct mnt_idmap *idmap, struct inode *dir, 527 + struct dentry *dentry, umode_t mode) 528 528 { 529 - return hfsplus_mknod(&nop_mnt_idmap, dir, dentry, mode | S_IFDIR, 0); 529 + return ERR_PTR(hfsplus_mknod(&nop_mnt_idmap, dir, dentry, mode | S_IFDIR, 0)); 530 530 } 531 531 532 532 static int hfsplus_rename(struct mnt_idmap *idmap,
+12 -4
fs/hostfs/hostfs_kern.c
··· 679 679 return err; 680 680 } 681 681 682 - static int hostfs_mkdir(struct mnt_idmap *idmap, struct inode *ino, 683 - struct dentry *dentry, umode_t mode) 682 + static struct dentry *hostfs_mkdir(struct mnt_idmap *idmap, struct inode *ino, 683 + struct dentry *dentry, umode_t mode) 684 684 { 685 + struct inode *inode; 685 686 char *file; 686 687 int err; 687 688 688 689 if ((file = dentry_name(dentry)) == NULL) 689 - return -ENOMEM; 690 + return ERR_PTR(-ENOMEM); 690 691 err = do_mkdir(file, mode); 692 + if (err) { 693 + dentry = ERR_PTR(err); 694 + } else { 695 + inode = hostfs_iget(dentry->d_sb, file); 696 + d_drop(dentry); 697 + dentry = d_splice_alias(inode, dentry); 698 + } 691 699 __putname(file); 692 - return err; 700 + return dentry; 693 701 } 694 702 695 703 static int hostfs_rmdir(struct inode *ino, struct dentry *dentry)
+5 -5
fs/hpfs/namei.c
··· 19 19 hpfs_write_inode_nolock(dir); 20 20 } 21 21 22 - static int hpfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 23 - struct dentry *dentry, umode_t mode) 22 + static struct dentry *hpfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 23 + struct dentry *dentry, umode_t mode) 24 24 { 25 25 const unsigned char *name = dentry->d_name.name; 26 26 unsigned len = dentry->d_name.len; ··· 35 35 int r; 36 36 struct hpfs_dirent dee; 37 37 int err; 38 - if ((err = hpfs_chk_name(name, &len))) return err==-ENOENT ? -EINVAL : err; 38 + if ((err = hpfs_chk_name(name, &len))) return ERR_PTR(err==-ENOENT ? -EINVAL : err); 39 39 hpfs_lock(dir->i_sb); 40 40 err = -ENOSPC; 41 41 fnode = hpfs_alloc_fnode(dir->i_sb, hpfs_i(dir)->i_dno, &fno, &bh); ··· 112 112 hpfs_update_directory_times(dir); 113 113 d_instantiate(dentry, result); 114 114 hpfs_unlock(dir->i_sb); 115 - return 0; 115 + return NULL; 116 116 bail3: 117 117 iput(result); 118 118 bail2: ··· 123 123 hpfs_free_sectors(dir->i_sb, fno, 1); 124 124 bail: 125 125 hpfs_unlock(dir->i_sb); 126 - return err; 126 + return ERR_PTR(err); 127 127 } 128 128 129 129 static int hpfs_create(struct mnt_idmap *idmap, struct inode *dir,
+3 -3
fs/hugetlbfs/inode.c
··· 991 991 return 0; 992 992 } 993 993 994 - static int hugetlbfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 995 - struct dentry *dentry, umode_t mode) 994 + static struct dentry *hugetlbfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 995 + struct dentry *dentry, umode_t mode) 996 996 { 997 997 int retval = hugetlbfs_mknod(idmap, dir, dentry, 998 998 mode | S_IFDIR, 0); 999 999 if (!retval) 1000 1000 inc_nlink(dir); 1001 - return retval; 1001 + return ERR_PTR(retval); 1002 1002 } 1003 1003 1004 1004 static int hugetlbfs_create(struct mnt_idmap *idmap,
+5 -2
fs/init.c
··· 230 230 return PTR_ERR(dentry); 231 231 mode = mode_strip_umask(d_inode(path.dentry), mode); 232 232 error = security_path_mkdir(&path, dentry, mode); 233 - if (!error) 234 - error = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode, 233 + if (!error) { 234 + dentry = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode, 235 235 dentry, mode); 236 + if (IS_ERR(dentry)) 237 + error = PTR_ERR(dentry); 238 + } 236 239 done_path_create(&path, dentry); 237 240 return error; 238 241 }
+9 -9
fs/jffs2/dir.c
··· 32 32 static int jffs2_unlink (struct inode *,struct dentry *); 33 33 static int jffs2_symlink (struct mnt_idmap *, struct inode *, 34 34 struct dentry *, const char *); 35 - static int jffs2_mkdir (struct mnt_idmap *, struct inode *,struct dentry *, 36 - umode_t); 35 + static struct dentry *jffs2_mkdir (struct mnt_idmap *, struct inode *,struct dentry *, 36 + umode_t); 37 37 static int jffs2_rmdir (struct inode *,struct dentry *); 38 38 static int jffs2_mknod (struct mnt_idmap *, struct inode *,struct dentry *, 39 39 umode_t,dev_t); ··· 446 446 } 447 447 448 448 449 - static int jffs2_mkdir (struct mnt_idmap *idmap, struct inode *dir_i, 450 - struct dentry *dentry, umode_t mode) 449 + static struct dentry *jffs2_mkdir (struct mnt_idmap *idmap, struct inode *dir_i, 450 + struct dentry *dentry, umode_t mode) 451 451 { 452 452 struct jffs2_inode_info *f, *dir_f; 453 453 struct jffs2_sb_info *c; ··· 464 464 465 465 ri = jffs2_alloc_raw_inode(); 466 466 if (!ri) 467 - return -ENOMEM; 467 + return ERR_PTR(-ENOMEM); 468 468 469 469 c = JFFS2_SB_INFO(dir_i->i_sb); 470 470 ··· 477 477 478 478 if (ret) { 479 479 jffs2_free_raw_inode(ri); 480 - return ret; 480 + return ERR_PTR(ret); 481 481 } 482 482 483 483 inode = jffs2_new_inode(dir_i, mode, ri); ··· 485 485 if (IS_ERR(inode)) { 486 486 jffs2_free_raw_inode(ri); 487 487 jffs2_complete_reservation(c); 488 - return PTR_ERR(inode); 488 + return ERR_CAST(inode); 489 489 } 490 490 491 491 inode->i_op = &jffs2_dir_inode_operations; ··· 584 584 jffs2_complete_reservation(c); 585 585 586 586 d_instantiate_new(dentry, inode); 587 - return 0; 587 + return NULL; 588 588 589 589 fail: 590 590 iget_failed(inode); 591 - return ret; 591 + return ERR_PTR(ret); 592 592 } 593 593 594 594 static int jffs2_rmdir (struct inode *dir_i, struct dentry *dentry)
+4 -4
fs/jfs/namei.c
··· 187 187 * dentry - dentry of child directory 188 188 * mode - create mode (rwxrwxrwx). 189 189 * 190 - * RETURN: Errors from subroutines 190 + * RETURN: ERR_PTR() of errors from subroutines. 191 191 * 192 192 * note: 193 193 * EACCES: user needs search+write permission on the parent directory 194 194 */ 195 - static int jfs_mkdir(struct mnt_idmap *idmap, struct inode *dip, 196 - struct dentry *dentry, umode_t mode) 195 + static struct dentry *jfs_mkdir(struct mnt_idmap *idmap, struct inode *dip, 196 + struct dentry *dentry, umode_t mode) 197 197 { 198 198 int rc = 0; 199 199 tid_t tid; /* transaction id */ ··· 308 308 out1: 309 309 310 310 jfs_info("jfs_mkdir: rc:%d", rc); 311 - return rc; 311 + return ERR_PTR(rc); 312 312 } 313 313 314 314 /*
+6 -6
fs/kernfs/dir.c
··· 1230 1230 return d_splice_alias(inode, dentry); 1231 1231 } 1232 1232 1233 - static int kernfs_iop_mkdir(struct mnt_idmap *idmap, 1234 - struct inode *dir, struct dentry *dentry, 1235 - umode_t mode) 1233 + static struct dentry *kernfs_iop_mkdir(struct mnt_idmap *idmap, 1234 + struct inode *dir, struct dentry *dentry, 1235 + umode_t mode) 1236 1236 { 1237 1237 struct kernfs_node *parent = dir->i_private; 1238 1238 struct kernfs_syscall_ops *scops = kernfs_root(parent)->syscall_ops; 1239 1239 int ret; 1240 1240 1241 1241 if (!scops || !scops->mkdir) 1242 - return -EPERM; 1242 + return ERR_PTR(-EPERM); 1243 1243 1244 1244 if (!kernfs_get_active(parent)) 1245 - return -ENODEV; 1245 + return ERR_PTR(-ENODEV); 1246 1246 1247 1247 ret = scops->mkdir(parent, dentry->d_name.name, mode); 1248 1248 1249 1249 kernfs_put_active(parent); 1250 - return ret; 1250 + return ERR_PTR(ret); 1251 1251 } 1252 1252 1253 1253 static int kernfs_iop_rmdir(struct inode *dir, struct dentry *dentry)
+4 -4
fs/minix/namei.c
··· 104 104 return add_nondir(dentry, inode); 105 105 } 106 106 107 - static int minix_mkdir(struct mnt_idmap *idmap, struct inode *dir, 108 - struct dentry *dentry, umode_t mode) 107 + static struct dentry *minix_mkdir(struct mnt_idmap *idmap, struct inode *dir, 108 + struct dentry *dentry, umode_t mode) 109 109 { 110 110 struct inode * inode; 111 111 int err; 112 112 113 113 inode = minix_new_inode(dir, S_IFDIR | mode); 114 114 if (IS_ERR(inode)) 115 - return PTR_ERR(inode); 115 + return ERR_CAST(inode); 116 116 117 117 inode_inc_link_count(dir); 118 118 minix_set_inode(inode, 0); ··· 128 128 129 129 d_instantiate(dentry, inode); 130 130 out: 131 - return err; 131 + return ERR_PTR(err); 132 132 133 133 out_fail: 134 134 inode_dec_link_count(inode);
+56 -49
fs/namei.c
··· 1671 1671 * dentries - as the matter of fact, this only gets called 1672 1672 * when directory is guaranteed to have no in-lookup children 1673 1673 * at all. 1674 + * Will return -ENOENT if name isn't found and LOOKUP_CREATE wasn't passed. 1675 + * Will return -EEXIST if name is found and LOOKUP_EXCL was passed. 1674 1676 */ 1675 1677 struct dentry *lookup_one_qstr_excl(const struct qstr *name, 1676 1678 struct dentry *base, ··· 1683 1681 struct inode *dir = base->d_inode; 1684 1682 1685 1683 if (dentry) 1686 - return dentry; 1684 + goto found; 1687 1685 1688 1686 /* Don't create child dentry for a dead directory. */ 1689 1687 if (unlikely(IS_DEADDIR(dir))) ··· 1697 1695 if (unlikely(old)) { 1698 1696 dput(dentry); 1699 1697 dentry = old; 1698 + } 1699 + found: 1700 + if (IS_ERR(dentry)) 1701 + return dentry; 1702 + if (d_is_negative(dentry) && !(flags & LOOKUP_CREATE)) { 1703 + dput(dentry); 1704 + return ERR_PTR(-ENOENT); 1705 + } 1706 + if (d_is_positive(dentry) && (flags & LOOKUP_EXCL)) { 1707 + dput(dentry); 1708 + return ERR_PTR(-EEXIST); 1700 1709 } 1701 1710 return dentry; 1702 1711 } ··· 4093 4080 * '/', and a directory wasn't requested. 4094 4081 */ 4095 4082 if (last.name[last.len] && !want_dir) 4096 - create_flags = 0; 4083 + create_flags &= ~LOOKUP_CREATE; 4097 4084 inode_lock_nested(path->dentry->d_inode, I_MUTEX_PARENT); 4098 4085 dentry = lookup_one_qstr_excl(&last, path->dentry, 4099 4086 reval_flag | create_flags); 4100 4087 if (IS_ERR(dentry)) 4101 4088 goto unlock; 4102 4089 4103 - error = -EEXIST; 4104 - if (d_is_positive(dentry)) 4105 - goto fail; 4106 - 4107 - /* 4108 - * Special case - lookup gave negative, but... we had foo/bar/ 4109 - * From the vfs_mknod() POV we just have a negative dentry - 4110 - * all is fine. Let's be bastards - you had / on the end, you've 4111 - * been asking for (non-existent) directory. -ENOENT for you. 4112 - */ 4113 - if (unlikely(!create_flags)) { 4114 - error = -ENOENT; 4115 - goto fail; 4116 - } 4117 4090 if (unlikely(err2)) { 4118 4091 error = err2; 4119 4092 goto fail; ··· 4130 4131 4131 4132 void done_path_create(struct path *path, struct dentry *dentry) 4132 4133 { 4133 - dput(dentry); 4134 + if (!IS_ERR(dentry)) 4135 + dput(dentry); 4134 4136 inode_unlock(path->dentry->d_inode); 4135 4137 mnt_drop_write(path->mnt); 4136 4138 path_put(path); ··· 4277 4277 } 4278 4278 4279 4279 /** 4280 - * vfs_mkdir - create directory 4280 + * vfs_mkdir - create directory returning correct dentry if possible 4281 4281 * @idmap: idmap of the mount the inode was found from 4282 4282 * @dir: inode of the parent directory 4283 4283 * @dentry: dentry of the child directory ··· 4290 4290 * care to map the inode according to @idmap before checking permissions. 4291 4291 * On non-idmapped mounts or if permission checking is to be performed on the 4292 4292 * raw inode simply pass @nop_mnt_idmap. 4293 + * 4294 + * In the event that the filesystem does not use the *@dentry but leaves it 4295 + * negative or unhashes it and possibly splices a different one returning it, 4296 + * the original dentry is dput() and the alternate is returned. 4297 + * 4298 + * In case of an error the dentry is dput() and an ERR_PTR() is returned. 4293 4299 */ 4294 - int vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 4295 - struct dentry *dentry, umode_t mode) 4300 + struct dentry *vfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 4301 + struct dentry *dentry, umode_t mode) 4296 4302 { 4297 4303 int error; 4298 4304 unsigned max_links = dir->i_sb->s_max_links; 4305 + struct dentry *de; 4299 4306 4300 4307 error = may_create(idmap, dir, dentry); 4301 4308 if (error) 4302 - return error; 4309 + goto err; 4303 4310 4311 + error = -EPERM; 4304 4312 if (!dir->i_op->mkdir) 4305 - return -EPERM; 4313 + goto err; 4306 4314 4307 4315 mode = vfs_prepare_mode(idmap, dir, mode, S_IRWXUGO | S_ISVTX, 0); 4308 4316 error = security_inode_mkdir(dir, dentry, mode); 4309 4317 if (error) 4310 - return error; 4318 + goto err; 4311 4319 4320 + error = -EMLINK; 4312 4321 if (max_links && dir->i_nlink >= max_links) 4313 - return -EMLINK; 4322 + goto err; 4314 4323 4315 - error = dir->i_op->mkdir(idmap, dir, dentry, mode); 4316 - if (!error) 4317 - fsnotify_mkdir(dir, dentry); 4318 - return error; 4324 + de = dir->i_op->mkdir(idmap, dir, dentry, mode); 4325 + error = PTR_ERR(de); 4326 + if (IS_ERR(de)) 4327 + goto err; 4328 + if (de) { 4329 + dput(dentry); 4330 + dentry = de; 4331 + } 4332 + fsnotify_mkdir(dir, dentry); 4333 + return dentry; 4334 + 4335 + err: 4336 + dput(dentry); 4337 + return ERR_PTR(error); 4319 4338 } 4320 4339 EXPORT_SYMBOL(vfs_mkdir); 4321 4340 ··· 4354 4335 error = security_path_mkdir(&path, dentry, 4355 4336 mode_strip_umask(path.dentry->d_inode, mode)); 4356 4337 if (!error) { 4357 - error = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode, 4338 + dentry = vfs_mkdir(mnt_idmap(path.mnt), path.dentry->d_inode, 4358 4339 dentry, mode); 4340 + if (IS_ERR(dentry)) 4341 + error = PTR_ERR(dentry); 4359 4342 } 4360 4343 done_path_create(&path, dentry); 4361 4344 if (retry_estale(error, lookup_flags)) { ··· 4468 4447 error = PTR_ERR(dentry); 4469 4448 if (IS_ERR(dentry)) 4470 4449 goto exit3; 4471 - if (!dentry->d_inode) { 4472 - error = -ENOENT; 4473 - goto exit4; 4474 - } 4475 4450 error = security_path_rmdir(&path, dentry); 4476 4451 if (error) 4477 4452 goto exit4; ··· 4598 4581 if (!IS_ERR(dentry)) { 4599 4582 4600 4583 /* Why not before? Because we want correct error value */ 4601 - if (last.name[last.len] || d_is_negative(dentry)) 4584 + if (last.name[last.len]) 4602 4585 goto slashes; 4603 4586 inode = dentry->d_inode; 4604 4587 ihold(inode); ··· 4632 4615 return error; 4633 4616 4634 4617 slashes: 4635 - if (d_is_negative(dentry)) 4636 - error = -ENOENT; 4637 - else if (d_is_dir(dentry)) 4618 + if (d_is_dir(dentry)) 4638 4619 error = -EISDIR; 4639 4620 else 4640 4621 error = -ENOTDIR; ··· 5132 5117 struct qstr old_last, new_last; 5133 5118 int old_type, new_type; 5134 5119 struct inode *delegated_inode = NULL; 5135 - unsigned int lookup_flags = 0, target_flags = LOOKUP_RENAME_TARGET; 5120 + unsigned int lookup_flags = 0, target_flags = 5121 + LOOKUP_RENAME_TARGET | LOOKUP_CREATE; 5136 5122 bool should_retry = false; 5137 5123 int error = -EINVAL; 5138 5124 ··· 5146 5130 5147 5131 if (flags & RENAME_EXCHANGE) 5148 5132 target_flags = 0; 5133 + if (flags & RENAME_NOREPLACE) 5134 + target_flags |= LOOKUP_EXCL; 5149 5135 5150 5136 retry: 5151 5137 error = filename_parentat(olddfd, from, lookup_flags, &old_path, ··· 5189 5171 error = PTR_ERR(old_dentry); 5190 5172 if (IS_ERR(old_dentry)) 5191 5173 goto exit3; 5192 - /* source must exist */ 5193 - error = -ENOENT; 5194 - if (d_is_negative(old_dentry)) 5195 - goto exit4; 5196 5174 new_dentry = lookup_one_qstr_excl(&new_last, new_path.dentry, 5197 5175 lookup_flags | target_flags); 5198 5176 error = PTR_ERR(new_dentry); 5199 5177 if (IS_ERR(new_dentry)) 5200 5178 goto exit4; 5201 - error = -EEXIST; 5202 - if ((flags & RENAME_NOREPLACE) && d_is_positive(new_dentry)) 5203 - goto exit5; 5204 5179 if (flags & RENAME_EXCHANGE) { 5205 - error = -ENOENT; 5206 - if (d_is_negative(new_dentry)) 5207 - goto exit5; 5208 - 5209 5180 if (!d_is_dir(new_dentry)) { 5210 5181 error = -ENOTDIR; 5211 5182 if (new_last.name[new_last.len])
+8 -12
fs/nfs/dir.c
··· 1532 1532 { 1533 1533 if (NFS_PROTO(dir)->version == 2) 1534 1534 return 0; 1535 - return flags & LOOKUP_EXCL; 1535 + return (flags & (LOOKUP_CREATE | LOOKUP_EXCL)) == 1536 + (LOOKUP_CREATE | LOOKUP_EXCL); 1536 1537 } 1537 1538 1538 1539 /* ··· 2422 2421 /* 2423 2422 * See comments for nfs_proc_create regarding failed operations. 2424 2423 */ 2425 - int nfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 2426 - struct dentry *dentry, umode_t mode) 2424 + struct dentry *nfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 2425 + struct dentry *dentry, umode_t mode) 2427 2426 { 2428 2427 struct iattr attr; 2429 - int error; 2428 + struct dentry *ret; 2430 2429 2431 2430 dfprintk(VFS, "NFS: mkdir(%s/%lu), %pd\n", 2432 2431 dir->i_sb->s_id, dir->i_ino, dentry); ··· 2435 2434 attr.ia_mode = mode | S_IFDIR; 2436 2435 2437 2436 trace_nfs_mkdir_enter(dir, dentry); 2438 - error = NFS_PROTO(dir)->mkdir(dir, dentry, &attr); 2439 - trace_nfs_mkdir_exit(dir, dentry, error); 2440 - if (error != 0) 2441 - goto out_err; 2442 - return 0; 2443 - out_err: 2444 - d_drop(dentry); 2445 - return error; 2437 + ret = NFS_PROTO(dir)->mkdir(dir, dentry, &attr); 2438 + trace_nfs_mkdir_exit(dir, dentry, PTR_ERR_OR_ZERO(ret)); 2439 + return ret; 2446 2440 } 2447 2441 EXPORT_SYMBOL_GPL(nfs_mkdir); 2448 2442
+2 -2
fs/nfs/internal.h
··· 400 400 void nfs_d_prune_case_insensitive_aliases(struct inode *inode); 401 401 int nfs_create(struct mnt_idmap *, struct inode *, struct dentry *, 402 402 umode_t, bool); 403 - int nfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *, 404 - umode_t); 403 + struct dentry *nfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *, 404 + umode_t); 405 405 int nfs_rmdir(struct inode *, struct dentry *); 406 406 int nfs_unlink(struct inode *, struct dentry *); 407 407 int nfs_symlink(struct mnt_idmap *, struct inode *, struct dentry *,
+16 -13
fs/nfs/nfs3proc.c
··· 578 578 return status; 579 579 } 580 580 581 - static int 581 + static struct dentry * 582 582 nfs3_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) 583 583 { 584 584 struct posix_acl *default_acl, *acl; 585 585 struct nfs3_createdata *data; 586 - struct dentry *d_alias; 587 - int status = -ENOMEM; 586 + struct dentry *ret = ERR_PTR(-ENOMEM); 587 + int status; 588 588 589 589 dprintk("NFS call mkdir %pd\n", dentry); 590 590 ··· 592 592 if (data == NULL) 593 593 goto out; 594 594 595 - status = posix_acl_create(dir, &sattr->ia_mode, &default_acl, &acl); 596 - if (status) 595 + ret = ERR_PTR(posix_acl_create(dir, &sattr->ia_mode, 596 + &default_acl, &acl)); 597 + if (IS_ERR(ret)) 597 598 goto out; 598 599 599 600 data->msg.rpc_proc = &nfs3_procedures[NFS3PROC_MKDIR]; ··· 603 602 data->arg.mkdir.len = dentry->d_name.len; 604 603 data->arg.mkdir.sattr = sattr; 605 604 606 - d_alias = nfs3_do_create(dir, dentry, data); 607 - status = PTR_ERR_OR_ZERO(d_alias); 605 + ret = nfs3_do_create(dir, dentry, data); 608 606 609 - if (status != 0) 607 + if (IS_ERR(ret)) 610 608 goto out_release_acls; 611 609 612 - if (d_alias) 613 - dentry = d_alias; 610 + if (ret) 611 + dentry = ret; 614 612 615 613 status = nfs3_proc_setacls(d_inode(dentry), acl, default_acl); 614 + if (status) { 615 + dput(ret); 616 + ret = ERR_PTR(status); 617 + } 616 618 617 - dput(d_alias); 618 619 out_release_acls: 619 620 posix_acl_release(acl); 620 621 posix_acl_release(default_acl); 621 622 out: 622 623 nfs3_free_createdata(data); 623 - dprintk("NFS reply mkdir: %d\n", status); 624 - return status; 624 + dprintk("NFS reply mkdir: %d\n", PTR_ERR_OR_ZERO(ret)); 625 + return ret; 625 626 } 626 627 627 628 static int
+32 -15
fs/nfs/nfs4proc.c
··· 3154 3154 if (d_really_is_negative(dentry)) { 3155 3155 struct dentry *alias; 3156 3156 d_drop(dentry); 3157 - alias = d_exact_alias(dentry, state->inode); 3158 - if (!alias) 3159 - alias = d_splice_alias(igrab(state->inode), dentry); 3157 + alias = d_splice_alias(igrab(state->inode), dentry); 3160 3158 /* d_splice_alias() can't fail here - it's a non-directory */ 3161 3159 if (alias) { 3162 3160 dput(ctx->dentry); ··· 5137 5139 &data->arg.seq_args, &data->res.seq_res, 1); 5138 5140 if (status == 0) { 5139 5141 spin_lock(&dir->i_lock); 5140 - /* Creating a directory bumps nlink in the parent */ 5141 - if (data->arg.ftype == NF4DIR) 5142 - nfs4_inc_nlink_locked(dir); 5143 5142 nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, 5144 5143 data->res.fattr->time_start, 5145 5144 NFS_INO_INVALID_DATA); ··· 5144 5149 status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); 5145 5150 } 5146 5151 return status; 5152 + } 5153 + 5154 + static struct dentry *nfs4_do_mkdir(struct inode *dir, struct dentry *dentry, 5155 + struct nfs4_createdata *data) 5156 + { 5157 + int status = nfs4_call_sync(NFS_SERVER(dir)->client, NFS_SERVER(dir), &data->msg, 5158 + &data->arg.seq_args, &data->res.seq_res, 1); 5159 + 5160 + if (status) 5161 + return ERR_PTR(status); 5162 + 5163 + spin_lock(&dir->i_lock); 5164 + /* Creating a directory bumps nlink in the parent */ 5165 + nfs4_inc_nlink_locked(dir); 5166 + nfs4_update_changeattr_locked(dir, &data->res.dir_cinfo, 5167 + data->res.fattr->time_start, 5168 + NFS_INO_INVALID_DATA); 5169 + spin_unlock(&dir->i_lock); 5170 + return nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr); 5147 5171 } 5148 5172 5149 5173 static void nfs4_free_createdata(struct nfs4_createdata *data) ··· 5221 5207 return err; 5222 5208 } 5223 5209 5224 - static int _nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, 5225 - struct iattr *sattr, struct nfs4_label *label) 5210 + static struct dentry *_nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, 5211 + struct iattr *sattr, 5212 + struct nfs4_label *label) 5226 5213 { 5227 5214 struct nfs4_createdata *data; 5228 - int status = -ENOMEM; 5215 + struct dentry *ret = ERR_PTR(-ENOMEM); 5229 5216 5230 5217 data = nfs4_alloc_createdata(dir, &dentry->d_name, sattr, NF4DIR); 5231 5218 if (data == NULL) 5232 5219 goto out; 5233 5220 5234 5221 data->arg.label = label; 5235 - status = nfs4_do_create(dir, dentry, data); 5222 + ret = nfs4_do_mkdir(dir, dentry, data); 5236 5223 5237 5224 nfs4_free_createdata(data); 5238 5225 out: 5239 - return status; 5226 + return ret; 5240 5227 } 5241 5228 5242 - static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, 5243 - struct iattr *sattr) 5229 + static struct dentry *nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry, 5230 + struct iattr *sattr) 5244 5231 { 5245 5232 struct nfs_server *server = NFS_SERVER(dir); 5246 5233 struct nfs4_exception exception = { 5247 5234 .interruptible = true, 5248 5235 }; 5249 5236 struct nfs4_label l, *label; 5237 + struct dentry *alias; 5250 5238 int err; 5251 5239 5252 5240 label = nfs4_label_init_security(dir, dentry, sattr, &l); ··· 5256 5240 if (!(server->attr_bitmask[2] & FATTR4_WORD2_MODE_UMASK)) 5257 5241 sattr->ia_mode &= ~current_umask(); 5258 5242 do { 5259 - err = _nfs4_proc_mkdir(dir, dentry, sattr, label); 5243 + alias = _nfs4_proc_mkdir(dir, dentry, sattr, label); 5244 + err = PTR_ERR_OR_ZERO(alias); 5260 5245 trace_nfs4_mkdir(dir, &dentry->d_name, err); 5261 5246 err = nfs4_handle_exception(NFS_SERVER(dir), err, 5262 5247 &exception); 5263 5248 } while (exception.retry); 5264 5249 nfs4_label_release_security(label); 5265 5250 5266 - return err; 5251 + return alias; 5267 5252 } 5268 5253 5269 5254 static int _nfs4_proc_readdir(struct nfs_readdir_arg *nr_arg,
+8 -4
fs/nfs/proc.c
··· 446 446 return status; 447 447 } 448 448 449 - static int 449 + static struct dentry * 450 450 nfs_proc_mkdir(struct inode *dir, struct dentry *dentry, struct iattr *sattr) 451 451 { 452 452 struct nfs_createdata *data; 453 453 struct rpc_message msg = { 454 454 .rpc_proc = &nfs_procedures[NFSPROC_MKDIR], 455 455 }; 456 + struct dentry *alias = NULL; 456 457 int status = -ENOMEM; 457 458 458 459 dprintk("NFS call mkdir %pd\n", dentry); ··· 465 464 466 465 status = rpc_call_sync(NFS_CLIENT(dir), &msg, 0); 467 466 nfs_mark_for_revalidate(dir); 468 - if (status == 0) 469 - status = nfs_instantiate(dentry, data->res.fh, data->res.fattr); 467 + if (status == 0) { 468 + alias = nfs_add_or_obtain(dentry, data->res.fh, data->res.fattr); 469 + status = PTR_ERR_OR_ZERO(alias); 470 + } else 471 + alias = ERR_PTR(status); 470 472 nfs_free_createdata(data); 471 473 out: 472 474 dprintk("NFS reply mkdir: %d\n", status); 473 - return status; 475 + return alias; 474 476 } 475 477 476 478 static int
+5 -2
fs/nfsd/nfs4recover.c
··· 233 233 * as well be forgiving and just succeed silently. 234 234 */ 235 235 goto out_put; 236 - status = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), dentry, S_IRWXU); 236 + dentry = vfs_mkdir(&nop_mnt_idmap, d_inode(dir), dentry, S_IRWXU); 237 + if (IS_ERR(dentry)) 238 + status = PTR_ERR(dentry); 237 239 out_put: 238 - dput(dentry); 240 + if (!status) 241 + dput(dentry); 239 242 out_unlock: 240 243 inode_unlock(d_inode(dir)); 241 244 if (status == 0) {
+11 -23
fs/nfsd/vfs.c
··· 1461 1461 struct inode *dirp; 1462 1462 struct iattr *iap = attrs->na_iattr; 1463 1463 __be32 err; 1464 - int host_err; 1464 + int host_err = 0; 1465 1465 1466 1466 dentry = fhp->fh_dentry; 1467 1467 dirp = d_inode(dentry); ··· 1488 1488 nfsd_check_ignore_resizing(iap); 1489 1489 break; 1490 1490 case S_IFDIR: 1491 - host_err = vfs_mkdir(&nop_mnt_idmap, dirp, dchild, iap->ia_mode); 1492 - if (!host_err && unlikely(d_unhashed(dchild))) { 1493 - struct dentry *d; 1494 - d = lookup_one_len(dchild->d_name.name, 1495 - dchild->d_parent, 1496 - dchild->d_name.len); 1497 - if (IS_ERR(d)) { 1498 - host_err = PTR_ERR(d); 1499 - break; 1500 - } 1501 - if (unlikely(d_is_negative(d))) { 1502 - dput(d); 1503 - err = nfserr_serverfault; 1504 - goto out; 1505 - } 1491 + dchild = vfs_mkdir(&nop_mnt_idmap, dirp, dchild, iap->ia_mode); 1492 + if (IS_ERR(dchild)) { 1493 + host_err = PTR_ERR(dchild); 1494 + } else if (d_is_negative(dchild)) { 1495 + err = nfserr_serverfault; 1496 + goto out; 1497 + } else if (unlikely(dchild != resfhp->fh_dentry)) { 1506 1498 dput(resfhp->fh_dentry); 1507 - resfhp->fh_dentry = dget(d); 1508 - err = fh_update(resfhp); 1509 - dput(dchild); 1510 - dchild = d; 1511 - if (err) 1512 - goto out; 1499 + resfhp->fh_dentry = dget(dchild); 1513 1500 } 1514 1501 break; 1515 1502 case S_IFCHR: ··· 1517 1530 err = nfsd_create_setattr(rqstp, fhp, resfhp, attrs); 1518 1531 1519 1532 out: 1520 - dput(dchild); 1533 + if (!IS_ERR(dchild)) 1534 + dput(dchild); 1521 1535 return err; 1522 1536 1523 1537 out_nfserr:
+4 -4
fs/nilfs2/namei.c
··· 218 218 return err; 219 219 } 220 220 221 - static int nilfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 222 - struct dentry *dentry, umode_t mode) 221 + static struct dentry *nilfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 222 + struct dentry *dentry, umode_t mode) 223 223 { 224 224 struct inode *inode; 225 225 struct nilfs_transaction_info ti; ··· 227 227 228 228 err = nilfs_transaction_begin(dir->i_sb, &ti, 1); 229 229 if (err) 230 - return err; 230 + return ERR_PTR(err); 231 231 232 232 inc_nlink(dir); 233 233 ··· 258 258 else 259 259 nilfs_transaction_abort(dir->i_sb); 260 260 261 - return err; 261 + return ERR_PTR(err); 262 262 263 263 out_fail: 264 264 drop_nlink(inode);
+4 -4
fs/ntfs3/namei.c
··· 201 201 /* 202 202 * ntfs_mkdir- inode_operations::mkdir 203 203 */ 204 - static int ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 205 - struct dentry *dentry, umode_t mode) 204 + static struct dentry *ntfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 205 + struct dentry *dentry, umode_t mode) 206 206 { 207 - return ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0, 208 - NULL, 0, NULL); 207 + return ERR_PTR(ntfs_create_inode(idmap, dir, dentry, NULL, S_IFDIR | mode, 0, 208 + NULL, 0, NULL)); 209 209 } 210 210 211 211 /*
+5 -5
fs/ocfs2/dlmfs/dlmfs.c
··· 402 402 * File creation. Allocate an inode, and we're done.. 403 403 */ 404 404 /* SMP-safe */ 405 - static int dlmfs_mkdir(struct mnt_idmap * idmap, 406 - struct inode * dir, 407 - struct dentry * dentry, 408 - umode_t mode) 405 + static struct dentry *dlmfs_mkdir(struct mnt_idmap * idmap, 406 + struct inode * dir, 407 + struct dentry * dentry, 408 + umode_t mode) 409 409 { 410 410 int status; 411 411 struct inode *inode = NULL; ··· 448 448 bail: 449 449 if (status < 0) 450 450 iput(inode); 451 - return status; 451 + return ERR_PTR(status); 452 452 } 453 453 454 454 static int dlmfs_create(struct mnt_idmap *idmap,
+5 -5
fs/ocfs2/namei.c
··· 644 644 suballoc_loc, suballoc_bit); 645 645 } 646 646 647 - static int ocfs2_mkdir(struct mnt_idmap *idmap, 648 - struct inode *dir, 649 - struct dentry *dentry, 650 - umode_t mode) 647 + static struct dentry *ocfs2_mkdir(struct mnt_idmap *idmap, 648 + struct inode *dir, 649 + struct dentry *dentry, 650 + umode_t mode) 651 651 { 652 652 int ret; 653 653 ··· 657 657 if (ret) 658 658 mlog_errno(ret); 659 659 660 - return ret; 660 + return ERR_PTR(ret); 661 661 } 662 662 663 663 static int ocfs2_create(struct mnt_idmap *idmap,
+3 -3
fs/omfs/dir.c
··· 279 279 return err; 280 280 } 281 281 282 - static int omfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 283 - struct dentry *dentry, umode_t mode) 282 + static struct dentry *omfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 283 + struct dentry *dentry, umode_t mode) 284 284 { 285 - return omfs_add_node(dir, dentry, mode | S_IFDIR); 285 + return ERR_PTR(omfs_add_node(dir, dentry, mode | S_IFDIR)); 286 286 } 287 287 288 288 static int omfs_create(struct mnt_idmap *idmap, struct inode *dir,
+4 -4
fs/orangefs/namei.c
··· 300 300 return ret; 301 301 } 302 302 303 - static int orangefs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 304 - struct dentry *dentry, umode_t mode) 303 + static struct dentry *orangefs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 304 + struct dentry *dentry, umode_t mode) 305 305 { 306 306 struct orangefs_inode_s *parent = ORANGEFS_I(dir); 307 307 struct orangefs_kernel_op_s *new_op; ··· 312 312 313 313 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); 314 314 if (!new_op) 315 - return -ENOMEM; 315 + return ERR_PTR(-ENOMEM); 316 316 317 317 new_op->upcall.req.mkdir.parent_refn = parent->refn; 318 318 ··· 366 366 __orangefs_setattr(dir, &iattr); 367 367 out: 368 368 op_release(new_op); 369 - return ret; 369 + return ERR_PTR(ret); 370 370 } 371 371 372 372 static int orangefs_rename(struct mnt_idmap *idmap,
+9 -37
fs/overlayfs/dir.c
··· 138 138 goto out; 139 139 } 140 140 141 - int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir, 142 - struct dentry **newdentry, umode_t mode) 143 - { 144 - int err; 145 - struct dentry *d, *dentry = *newdentry; 146 - 147 - err = ovl_do_mkdir(ofs, dir, dentry, mode); 148 - if (err) 149 - return err; 150 - 151 - if (likely(!d_unhashed(dentry))) 152 - return 0; 153 - 154 - /* 155 - * vfs_mkdir() may succeed and leave the dentry passed 156 - * to it unhashed and negative. If that happens, try to 157 - * lookup a new hashed and positive dentry. 158 - */ 159 - d = ovl_lookup_upper(ofs, dentry->d_name.name, dentry->d_parent, 160 - dentry->d_name.len); 161 - if (IS_ERR(d)) { 162 - pr_warn("failed lookup after mkdir (%pd2, err=%i).\n", 163 - dentry, err); 164 - return PTR_ERR(d); 165 - } 166 - dput(dentry); 167 - *newdentry = d; 168 - 169 - return 0; 170 - } 171 - 172 141 struct dentry *ovl_create_real(struct ovl_fs *ofs, struct inode *dir, 173 142 struct dentry *newdentry, struct ovl_cattr *attr) 174 143 { ··· 160 191 161 192 case S_IFDIR: 162 193 /* mkdir is special... */ 163 - err = ovl_mkdir_real(ofs, dir, &newdentry, attr->mode); 194 + newdentry = ovl_do_mkdir(ofs, dir, newdentry, attr->mode); 195 + err = PTR_ERR_OR_ZERO(newdentry); 164 196 break; 165 197 166 198 case S_IFCHR: ··· 189 219 } 190 220 out: 191 221 if (err) { 192 - dput(newdentry); 222 + if (!IS_ERR(newdentry)) 223 + dput(newdentry); 193 224 return ERR_PTR(err); 194 225 } 195 226 return newdentry; ··· 253 282 * XXX: if we ever use ovl_obtain_alias() to decode directory 254 283 * file handles, need to use ovl_get_inode_locked() and 255 284 * d_instantiate_new() here to prevent from creating two 256 - * hashed directory inode aliases. 285 + * hashed directory inode aliases. We then need to return 286 + * the obtained alias to ovl_mkdir(). 257 287 */ 258 288 inode = ovl_get_inode(dentry->d_sb, &oip); 259 289 if (IS_ERR(inode)) ··· 659 687 return ovl_create_object(dentry, (mode & 07777) | S_IFREG, 0, NULL); 660 688 } 661 689 662 - static int ovl_mkdir(struct mnt_idmap *idmap, struct inode *dir, 663 - struct dentry *dentry, umode_t mode) 690 + static struct dentry *ovl_mkdir(struct mnt_idmap *idmap, struct inode *dir, 691 + struct dentry *dentry, umode_t mode) 664 692 { 665 - return ovl_create_object(dentry, (mode & 07777) | S_IFDIR, 0, NULL); 693 + return ERR_PTR(ovl_create_object(dentry, (mode & 07777) | S_IFDIR, 0, NULL)); 666 694 } 667 695 668 696 static int ovl_mknod(struct mnt_idmap *idmap, struct inode *dir,
+7 -8
fs/overlayfs/overlayfs.h
··· 241 241 return err; 242 242 } 243 243 244 - static inline int ovl_do_mkdir(struct ovl_fs *ofs, 245 - struct inode *dir, struct dentry *dentry, 246 - umode_t mode) 244 + static inline struct dentry *ovl_do_mkdir(struct ovl_fs *ofs, 245 + struct inode *dir, 246 + struct dentry *dentry, 247 + umode_t mode) 247 248 { 248 - int err = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode); 249 - pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, err); 250 - return err; 249 + dentry = vfs_mkdir(ovl_upper_mnt_idmap(ofs), dir, dentry, mode); 250 + pr_debug("mkdir(%pd2, 0%o) = %i\n", dentry, mode, PTR_ERR_OR_ZERO(dentry)); 251 + return dentry; 251 252 } 252 253 253 254 static inline int ovl_do_mknod(struct ovl_fs *ofs, ··· 839 838 840 839 #define OVL_CATTR(m) (&(struct ovl_cattr) { .mode = (m) }) 841 840 842 - int ovl_mkdir_real(struct ovl_fs *ofs, struct inode *dir, 843 - struct dentry **newdentry, umode_t mode); 844 841 struct dentry *ovl_create_real(struct ovl_fs *ofs, 845 842 struct inode *dir, struct dentry *newdentry, 846 843 struct ovl_cattr *attr);
+4 -3
fs/overlayfs/super.c
··· 327 327 goto retry; 328 328 } 329 329 330 - err = ovl_mkdir_real(ofs, dir, &work, attr.ia_mode); 331 - if (err) 332 - goto out_dput; 330 + work = ovl_do_mkdir(ofs, dir, work, attr.ia_mode); 331 + err = PTR_ERR(work); 332 + if (IS_ERR(work)) 333 + goto out_err; 333 334 334 335 /* Weird filesystem returning with hashed negative (kernfs)? */ 335 336 err = -EINVAL;
+3 -3
fs/ramfs/inode.c
··· 119 119 return error; 120 120 } 121 121 122 - static int ramfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 123 - struct dentry *dentry, umode_t mode) 122 + static struct dentry *ramfs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 123 + struct dentry *dentry, umode_t mode) 124 124 { 125 125 int retval = ramfs_mknod(&nop_mnt_idmap, dir, dentry, mode | S_IFDIR, 0); 126 126 if (!retval) 127 127 inc_nlink(dir); 128 - return retval; 128 + return ERR_PTR(retval); 129 129 } 130 130 131 131 static int ramfs_create(struct mnt_idmap *idmap, struct inode *dir,
+2 -2
fs/smb/client/cifsfs.h
··· 59 59 extern int cifs_hardlink(struct dentry *, struct inode *, struct dentry *); 60 60 extern int cifs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, 61 61 umode_t, dev_t); 62 - extern int cifs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *, 63 - umode_t); 62 + extern struct dentry *cifs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *, 63 + umode_t); 64 64 extern int cifs_rmdir(struct inode *, struct dentry *); 65 65 extern int cifs_rename2(struct mnt_idmap *, struct inode *, 66 66 struct dentry *, struct inode *, struct dentry *,
+5 -5
fs/smb/client/inode.c
··· 2207 2207 } 2208 2208 #endif /* CONFIG_CIFS_ALLOW_INSECURE_LEGACY */ 2209 2209 2210 - int cifs_mkdir(struct mnt_idmap *idmap, struct inode *inode, 2211 - struct dentry *direntry, umode_t mode) 2210 + struct dentry *cifs_mkdir(struct mnt_idmap *idmap, struct inode *inode, 2211 + struct dentry *direntry, umode_t mode) 2212 2212 { 2213 2213 int rc = 0; 2214 2214 unsigned int xid; ··· 2224 2224 2225 2225 cifs_sb = CIFS_SB(inode->i_sb); 2226 2226 if (unlikely(cifs_forced_shutdown(cifs_sb))) 2227 - return -EIO; 2227 + return ERR_PTR(-EIO); 2228 2228 tlink = cifs_sb_tlink(cifs_sb); 2229 2229 if (IS_ERR(tlink)) 2230 - return PTR_ERR(tlink); 2230 + return ERR_CAST(tlink); 2231 2231 tcon = tlink_tcon(tlink); 2232 2232 2233 2233 xid = get_xid(); ··· 2283 2283 free_dentry_path(page); 2284 2284 free_xid(xid); 2285 2285 cifs_put_tlink(tlink); 2286 - return rc; 2286 + return ERR_PTR(rc); 2287 2287 } 2288 2288 2289 2289 int cifs_rmdir(struct inode *inode, struct dentry *direntry)
+20 -38
fs/smb/server/vfs.c
··· 113 113 if (IS_ERR(d)) 114 114 goto err_out; 115 115 116 - if (d_is_negative(d)) { 117 - dput(d); 118 - goto err_out; 119 - } 120 - 121 116 path->dentry = d; 122 117 path->mnt = mntget(parent_path->mnt); 123 118 ··· 206 211 { 207 212 struct mnt_idmap *idmap; 208 213 struct path path; 209 - struct dentry *dentry; 210 - int err; 214 + struct dentry *dentry, *d; 215 + int err = 0; 211 216 212 217 dentry = ksmbd_vfs_kern_path_create(work, name, 213 218 LOOKUP_NO_SYMLINKS | LOOKUP_DIRECTORY, ··· 222 227 223 228 idmap = mnt_idmap(path.mnt); 224 229 mode |= S_IFDIR; 225 - err = vfs_mkdir(idmap, d_inode(path.dentry), dentry, mode); 226 - if (!err && d_unhashed(dentry)) { 227 - struct dentry *d; 230 + d = dentry; 231 + dentry = vfs_mkdir(idmap, d_inode(path.dentry), dentry, mode); 232 + if (IS_ERR(dentry)) 233 + err = PTR_ERR(dentry); 234 + else if (d_is_negative(dentry)) 235 + err = -ENOENT; 236 + if (!err && dentry != d) 237 + ksmbd_vfs_inherit_owner(work, d_inode(path.dentry), d_inode(dentry)); 228 238 229 - d = lookup_one(idmap, dentry->d_name.name, dentry->d_parent, 230 - dentry->d_name.len); 231 - if (IS_ERR(d)) { 232 - err = PTR_ERR(d); 233 - goto out_err; 234 - } 235 - if (unlikely(d_is_negative(d))) { 236 - dput(d); 237 - err = -ENOENT; 238 - goto out_err; 239 - } 240 - 241 - ksmbd_vfs_inherit_owner(work, d_inode(path.dentry), d_inode(d)); 242 - dput(d); 243 - } 244 - 245 - out_err: 246 239 done_path_create(&path, dentry); 247 240 if (err) 248 241 pr_err("mkdir(%s): creation failed (err:%d)\n", name, err); ··· 676 693 struct ksmbd_file *parent_fp; 677 694 int new_type; 678 695 int err, lookup_flags = LOOKUP_NO_SYMLINKS; 696 + int target_lookup_flags = LOOKUP_RENAME_TARGET; 679 697 680 698 if (ksmbd_override_fsids(work)) 681 699 return -ENOMEM; ··· 686 702 err = PTR_ERR(to); 687 703 goto revert_fsids; 688 704 } 705 + 706 + /* 707 + * explicitly handle file overwrite case, for compatibility with 708 + * filesystems that may not support rename flags (e.g: fuse) 709 + */ 710 + if (flags & RENAME_NOREPLACE) 711 + target_lookup_flags |= LOOKUP_EXCL; 712 + flags &= ~(RENAME_NOREPLACE); 689 713 690 714 retry: 691 715 err = vfs_path_parent_lookup(to, lookup_flags | LOOKUP_BENEATH, ··· 735 743 } 736 744 737 745 new_dentry = lookup_one_qstr_excl(&new_last, new_path.dentry, 738 - lookup_flags | LOOKUP_RENAME_TARGET); 746 + lookup_flags | target_lookup_flags); 739 747 if (IS_ERR(new_dentry)) { 740 748 err = PTR_ERR(new_dentry); 741 749 goto out3; ··· 745 753 err = -EACCES; 746 754 goto out4; 747 755 } 748 - 749 - /* 750 - * explicitly handle file overwrite case, for compatibility with 751 - * filesystems that may not support rename flags (e.g: fuse) 752 - */ 753 - if ((flags & RENAME_NOREPLACE) && d_is_positive(new_dentry)) { 754 - err = -EEXIST; 755 - goto out4; 756 - } 757 - flags &= ~(RENAME_NOREPLACE); 758 756 759 757 if (old_child == trap) { 760 758 err = -EINVAL;
+3 -3
fs/sysv/namei.c
··· 110 110 return add_nondir(dentry, inode); 111 111 } 112 112 113 - static int sysv_mkdir(struct mnt_idmap *idmap, struct inode *dir, 114 - struct dentry *dentry, umode_t mode) 113 + static struct dentry *sysv_mkdir(struct mnt_idmap *idmap, struct inode *dir, 114 + struct dentry *dentry, umode_t mode) 115 115 { 116 116 struct inode * inode; 117 117 int err; ··· 137 137 138 138 d_instantiate(dentry, inode); 139 139 out: 140 - return err; 140 + return ERR_PTR(err); 141 141 142 142 out_fail: 143 143 inode_dec_link_count(inode);
+5 -5
fs/tracefs/inode.c
··· 109 109 return name; 110 110 } 111 111 112 - static int tracefs_syscall_mkdir(struct mnt_idmap *idmap, 113 - struct inode *inode, struct dentry *dentry, 114 - umode_t mode) 112 + static struct dentry *tracefs_syscall_mkdir(struct mnt_idmap *idmap, 113 + struct inode *inode, struct dentry *dentry, 114 + umode_t mode) 115 115 { 116 116 struct tracefs_inode *ti; 117 117 char *name; ··· 119 119 120 120 name = get_dname(dentry); 121 121 if (!name) 122 - return -ENOMEM; 122 + return ERR_PTR(-ENOMEM); 123 123 124 124 /* 125 125 * This is a new directory that does not take the default of ··· 141 141 142 142 kfree(name); 143 143 144 - return ret; 144 + return ERR_PTR(ret); 145 145 } 146 146 147 147 static int tracefs_syscall_rmdir(struct inode *inode, struct dentry *dentry)
+5 -5
fs/ubifs/dir.c
··· 1002 1002 return err; 1003 1003 } 1004 1004 1005 - static int ubifs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1006 - struct dentry *dentry, umode_t mode) 1005 + static struct dentry *ubifs_mkdir(struct mnt_idmap *idmap, struct inode *dir, 1006 + struct dentry *dentry, umode_t mode) 1007 1007 { 1008 1008 struct inode *inode; 1009 1009 struct ubifs_inode *dir_ui = ubifs_inode(dir); ··· 1023 1023 1024 1024 err = ubifs_budget_space(c, &req); 1025 1025 if (err) 1026 - return err; 1026 + return ERR_PTR(err); 1027 1027 1028 1028 err = ubifs_prepare_create(dir, dentry, &nm); 1029 1029 if (err) ··· 1060 1060 ubifs_release_budget(c, &req); 1061 1061 d_instantiate(dentry, inode); 1062 1062 fscrypt_free_filename(&nm); 1063 - return 0; 1063 + return NULL; 1064 1064 1065 1065 out_cancel: 1066 1066 dir->i_size -= sz_change; ··· 1074 1074 fscrypt_free_filename(&nm); 1075 1075 out_budg: 1076 1076 ubifs_release_budget(c, &req); 1077 - return err; 1077 + return ERR_PTR(err); 1078 1078 } 1079 1079 1080 1080 static int ubifs_mknod(struct mnt_idmap *idmap, struct inode *dir,
+6 -6
fs/udf/namei.c
··· 419 419 return udf_add_nondir(dentry, inode); 420 420 } 421 421 422 - static int udf_mkdir(struct mnt_idmap *idmap, struct inode *dir, 423 - struct dentry *dentry, umode_t mode) 422 + static struct dentry *udf_mkdir(struct mnt_idmap *idmap, struct inode *dir, 423 + struct dentry *dentry, umode_t mode) 424 424 { 425 425 struct inode *inode; 426 426 struct udf_fileident_iter iter; ··· 430 430 431 431 inode = udf_new_inode(dir, S_IFDIR | mode); 432 432 if (IS_ERR(inode)) 433 - return PTR_ERR(inode); 433 + return ERR_CAST(inode); 434 434 435 435 iinfo = UDF_I(inode); 436 436 inode->i_op = &udf_dir_inode_operations; ··· 439 439 if (err) { 440 440 clear_nlink(inode); 441 441 discard_new_inode(inode); 442 - return err; 442 + return ERR_PTR(err); 443 443 } 444 444 set_nlink(inode, 2); 445 445 iter.fi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); ··· 456 456 if (err) { 457 457 clear_nlink(inode); 458 458 discard_new_inode(inode); 459 - return err; 459 + return ERR_PTR(err); 460 460 } 461 461 iter.fi.icb.extLength = cpu_to_le32(inode->i_sb->s_blocksize); 462 462 iter.fi.icb.extLocation = cpu_to_lelb(iinfo->i_location); ··· 471 471 mark_inode_dirty(dir); 472 472 d_instantiate_new(dentry, inode); 473 473 474 - return 0; 474 + return NULL; 475 475 } 476 476 477 477 static int empty_dir(struct inode *dir)
+4 -4
fs/ufs/namei.c
··· 166 166 return error; 167 167 } 168 168 169 - static int ufs_mkdir(struct mnt_idmap * idmap, struct inode * dir, 170 - struct dentry * dentry, umode_t mode) 169 + static struct dentry *ufs_mkdir(struct mnt_idmap * idmap, struct inode * dir, 170 + struct dentry * dentry, umode_t mode) 171 171 { 172 172 struct inode * inode; 173 173 int err; ··· 194 194 goto out_fail; 195 195 196 196 d_instantiate_new(dentry, inode); 197 - return 0; 197 + return NULL; 198 198 199 199 out_fail: 200 200 inode_dec_link_count(inode); ··· 202 202 discard_new_inode(inode); 203 203 out_dir: 204 204 inode_dec_link_count(dir); 205 - return err; 205 + return ERR_PTR(err); 206 206 } 207 207 208 208 static int ufs_unlink(struct inode *dir, struct dentry *dentry)
+4 -4
fs/vboxsf/dir.c
··· 303 303 return vboxsf_dir_create(parent, dentry, mode, false, excl, NULL); 304 304 } 305 305 306 - static int vboxsf_dir_mkdir(struct mnt_idmap *idmap, 307 - struct inode *parent, struct dentry *dentry, 308 - umode_t mode) 306 + static struct dentry *vboxsf_dir_mkdir(struct mnt_idmap *idmap, 307 + struct inode *parent, struct dentry *dentry, 308 + umode_t mode) 309 309 { 310 - return vboxsf_dir_create(parent, dentry, mode, true, true, NULL); 310 + return ERR_PTR(vboxsf_dir_create(parent, dentry, mode, true, true, NULL)); 311 311 } 312 312 313 313 static int vboxsf_dir_atomic_open(struct inode *parent, struct dentry *dentry,
+5 -4
fs/xfs/scrub/orphanage.c
··· 167 167 * directory to control access to a file we put in here. 168 168 */ 169 169 if (d_really_is_negative(orphanage_dentry)) { 170 - error = vfs_mkdir(&nop_mnt_idmap, root_inode, orphanage_dentry, 171 - 0750); 172 - if (error) 173 - goto out_dput_orphanage; 170 + orphanage_dentry = vfs_mkdir(&nop_mnt_idmap, root_inode, 171 + orphanage_dentry, 0750); 172 + error = PTR_ERR(orphanage_dentry); 173 + if (IS_ERR(orphanage_dentry)) 174 + goto out_unlock_root; 174 175 } 175 176 176 177 /* Not a directory? Bail out. */
+2 -2
fs/xfs/xfs_iops.c
··· 298 298 return xfs_generic_create(idmap, dir, dentry, mode, 0, NULL); 299 299 } 300 300 301 - STATIC int 301 + STATIC struct dentry * 302 302 xfs_vn_mkdir( 303 303 struct mnt_idmap *idmap, 304 304 struct inode *dir, 305 305 struct dentry *dentry, 306 306 umode_t mode) 307 307 { 308 - return xfs_generic_create(idmap, dir, dentry, mode | S_IFDIR, 0, NULL); 308 + return ERR_PTR(xfs_generic_create(idmap, dir, dentry, mode | S_IFDIR, 0, NULL)); 309 309 } 310 310 311 311 STATIC struct dentry *
+19 -20
include/linux/dcache.h
··· 203 203 #define DCACHE_NFSFS_RENAMED BIT(12) 204 204 /* this dentry has been "silly renamed" and has to be deleted on the last 205 205 * dput() */ 206 - #define DCACHE_FSNOTIFY_PARENT_WATCHED BIT(14) 206 + #define DCACHE_FSNOTIFY_PARENT_WATCHED BIT(13) 207 207 /* Parent inode is watched by some fsnotify listener */ 208 208 209 - #define DCACHE_DENTRY_KILLED BIT(15) 209 + #define DCACHE_DENTRY_KILLED BIT(14) 210 210 211 - #define DCACHE_MOUNTED BIT(16) /* is a mountpoint */ 212 - #define DCACHE_NEED_AUTOMOUNT BIT(17) /* handle automount on this dir */ 213 - #define DCACHE_MANAGE_TRANSIT BIT(18) /* manage transit from this dirent */ 211 + #define DCACHE_MOUNTED BIT(15) /* is a mountpoint */ 212 + #define DCACHE_NEED_AUTOMOUNT BIT(16) /* handle automount on this dir */ 213 + #define DCACHE_MANAGE_TRANSIT BIT(17) /* manage transit from this dirent */ 214 214 #define DCACHE_MANAGED_DENTRY \ 215 215 (DCACHE_MOUNTED|DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT) 216 216 217 - #define DCACHE_LRU_LIST BIT(19) 217 + #define DCACHE_LRU_LIST BIT(18) 218 218 219 - #define DCACHE_ENTRY_TYPE (7 << 20) /* bits 20..22 are for storing type: */ 220 - #define DCACHE_MISS_TYPE (0 << 20) /* Negative dentry */ 221 - #define DCACHE_WHITEOUT_TYPE (1 << 20) /* Whiteout dentry (stop pathwalk) */ 222 - #define DCACHE_DIRECTORY_TYPE (2 << 20) /* Normal directory */ 223 - #define DCACHE_AUTODIR_TYPE (3 << 20) /* Lookupless directory (presumed automount) */ 224 - #define DCACHE_REGULAR_TYPE (4 << 20) /* Regular file type */ 225 - #define DCACHE_SPECIAL_TYPE (5 << 20) /* Other file type */ 226 - #define DCACHE_SYMLINK_TYPE (6 << 20) /* Symlink */ 219 + #define DCACHE_ENTRY_TYPE (7 << 19) /* bits 19..21 are for storing type: */ 220 + #define DCACHE_MISS_TYPE (0 << 19) /* Negative dentry */ 221 + #define DCACHE_WHITEOUT_TYPE (1 << 19) /* Whiteout dentry (stop pathwalk) */ 222 + #define DCACHE_DIRECTORY_TYPE (2 << 19) /* Normal directory */ 223 + #define DCACHE_AUTODIR_TYPE (3 << 19) /* Lookupless directory (presumed automount) */ 224 + #define DCACHE_REGULAR_TYPE (4 << 19) /* Regular file type */ 225 + #define DCACHE_SPECIAL_TYPE (5 << 19) /* Other file type */ 226 + #define DCACHE_SYMLINK_TYPE (6 << 19) /* Symlink */ 227 227 228 - #define DCACHE_NOKEY_NAME BIT(25) /* Encrypted name encoded without key */ 229 - #define DCACHE_OP_REAL BIT(26) 228 + #define DCACHE_NOKEY_NAME BIT(22) /* Encrypted name encoded without key */ 229 + #define DCACHE_OP_REAL BIT(23) 230 230 231 - #define DCACHE_PAR_LOOKUP BIT(28) /* being looked up (with parent locked shared) */ 232 - #define DCACHE_DENTRY_CURSOR BIT(29) 233 - #define DCACHE_NORCU BIT(30) /* No RCU delay for freeing */ 231 + #define DCACHE_PAR_LOOKUP BIT(24) /* being looked up (with parent locked shared) */ 232 + #define DCACHE_DENTRY_CURSOR BIT(25) 233 + #define DCACHE_NORCU BIT(26) /* No RCU delay for freeing */ 234 234 235 235 extern seqlock_t rename_lock; 236 236 ··· 253 253 extern struct dentry * d_add_ci(struct dentry *, struct inode *, struct qstr *); 254 254 extern bool d_same_name(const struct dentry *dentry, const struct dentry *parent, 255 255 const struct qstr *name); 256 - extern struct dentry * d_exact_alias(struct dentry *, struct inode *); 257 256 extern struct dentry *d_find_any_alias(struct inode *inode); 258 257 extern struct dentry * d_obtain_alias(struct inode *); 259 258 extern struct dentry * d_obtain_root(struct inode *);
+4 -4
include/linux/fs.h
··· 1971 1971 */ 1972 1972 int vfs_create(struct mnt_idmap *, struct inode *, 1973 1973 struct dentry *, umode_t, bool); 1974 - int vfs_mkdir(struct mnt_idmap *, struct inode *, 1975 - struct dentry *, umode_t); 1974 + struct dentry *vfs_mkdir(struct mnt_idmap *, struct inode *, 1975 + struct dentry *, umode_t); 1976 1976 int vfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, 1977 1977 umode_t, dev_t); 1978 1978 int vfs_symlink(struct mnt_idmap *, struct inode *, ··· 2201 2201 int (*unlink) (struct inode *,struct dentry *); 2202 2202 int (*symlink) (struct mnt_idmap *, struct inode *,struct dentry *, 2203 2203 const char *); 2204 - int (*mkdir) (struct mnt_idmap *, struct inode *,struct dentry *, 2205 - umode_t); 2204 + struct dentry *(*mkdir) (struct mnt_idmap *, struct inode *, 2205 + struct dentry *, umode_t); 2206 2206 int (*rmdir) (struct inode *,struct dentry *); 2207 2207 int (*mknod) (struct mnt_idmap *, struct inode *,struct dentry *, 2208 2208 umode_t,dev_t);
+23 -22
include/linux/namei.h
··· 18 18 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT}; 19 19 20 20 /* pathwalk mode */ 21 - #define LOOKUP_FOLLOW 0x0001 /* follow links at the end */ 22 - #define LOOKUP_DIRECTORY 0x0002 /* require a directory */ 23 - #define LOOKUP_AUTOMOUNT 0x0004 /* force terminal automount */ 24 - #define LOOKUP_EMPTY 0x4000 /* accept empty path [user_... only] */ 25 - #define LOOKUP_DOWN 0x8000 /* follow mounts in the starting point */ 26 - #define LOOKUP_MOUNTPOINT 0x0080 /* follow mounts in the end */ 27 - 28 - #define LOOKUP_REVAL 0x0020 /* tell ->d_revalidate() to trust no cache */ 29 - #define LOOKUP_RCU 0x0040 /* RCU pathwalk mode; semi-internal */ 21 + #define LOOKUP_FOLLOW BIT(0) /* follow links at the end */ 22 + #define LOOKUP_DIRECTORY BIT(1) /* require a directory */ 23 + #define LOOKUP_AUTOMOUNT BIT(2) /* force terminal automount */ 24 + #define LOOKUP_EMPTY BIT(3) /* accept empty path [user_... only] */ 25 + #define LOOKUP_LINKAT_EMPTY BIT(4) /* Linkat request with empty path. */ 26 + #define LOOKUP_DOWN BIT(5) /* follow mounts in the starting point */ 27 + #define LOOKUP_MOUNTPOINT BIT(6) /* follow mounts in the end */ 28 + #define LOOKUP_REVAL BIT(7) /* tell ->d_revalidate() to trust no cache */ 29 + #define LOOKUP_RCU BIT(8) /* RCU pathwalk mode; semi-internal */ 30 + #define LOOKUP_CACHED BIT(9) /* Only do cached lookup */ 31 + #define LOOKUP_PARENT BIT(10) /* Looking up final parent in path */ 32 + /* 5 spare bits for pathwalk */ 30 33 31 34 /* These tell filesystem methods that we are dealing with the final component... */ 32 - #define LOOKUP_OPEN 0x0100 /* ... in open */ 33 - #define LOOKUP_CREATE 0x0200 /* ... in object creation */ 34 - #define LOOKUP_EXCL 0x0400 /* ... in exclusive creation */ 35 - #define LOOKUP_RENAME_TARGET 0x0800 /* ... in destination of rename() */ 35 + #define LOOKUP_OPEN BIT(16) /* ... in open */ 36 + #define LOOKUP_CREATE BIT(17) /* ... in object creation */ 37 + #define LOOKUP_EXCL BIT(18) /* ... in target must not exist */ 38 + #define LOOKUP_RENAME_TARGET BIT(19) /* ... in destination of rename() */ 36 39 37 - /* internal use only */ 38 - #define LOOKUP_PARENT 0x0010 40 + /* 4 spare bits for intent */ 39 41 40 42 /* Scoping flags for lookup. */ 41 - #define LOOKUP_NO_SYMLINKS 0x010000 /* No symlink crossing. */ 42 - #define LOOKUP_NO_MAGICLINKS 0x020000 /* No nd_jump_link() crossing. */ 43 - #define LOOKUP_NO_XDEV 0x040000 /* No mountpoint crossing. */ 44 - #define LOOKUP_BENEATH 0x080000 /* No escaping from starting point. */ 45 - #define LOOKUP_IN_ROOT 0x100000 /* Treat dirfd as fs root. */ 46 - #define LOOKUP_CACHED 0x200000 /* Only do cached lookup */ 47 - #define LOOKUP_LINKAT_EMPTY 0x400000 /* Linkat request with empty path. */ 43 + #define LOOKUP_NO_SYMLINKS BIT(24) /* No symlink crossing. */ 44 + #define LOOKUP_NO_MAGICLINKS BIT(25) /* No nd_jump_link() crossing. */ 45 + #define LOOKUP_NO_XDEV BIT(26) /* No mountpoint crossing. */ 46 + #define LOOKUP_BENEATH BIT(27) /* No escaping from starting point. */ 47 + #define LOOKUP_IN_ROOT BIT(28) /* Treat dirfd as fs root. */ 48 48 /* LOOKUP_* flags which do scope-related checks based on the dirfd. */ 49 49 #define LOOKUP_IS_SCOPED (LOOKUP_BENEATH | LOOKUP_IN_ROOT) 50 + /* 3 spare bits for scoping */ 50 51 51 52 extern int path_pts(struct path *path); 52 53
+1 -1
include/linux/nfs_xdr.h
··· 1802 1802 int (*link) (struct inode *, struct inode *, const struct qstr *); 1803 1803 int (*symlink) (struct inode *, struct dentry *, struct folio *, 1804 1804 unsigned int, struct iattr *); 1805 - int (*mkdir) (struct inode *, struct dentry *, struct iattr *); 1805 + struct dentry *(*mkdir) (struct inode *, struct dentry *, struct iattr *); 1806 1806 int (*rmdir) (struct inode *, const struct qstr *); 1807 1807 int (*readdir) (struct nfs_readdir_arg *, struct nfs_readdir_res *); 1808 1808 int (*mknod) (struct inode *, struct dentry *, struct iattr *,
+6 -6
kernel/audit_watch.c
··· 350 350 struct dentry *d = kern_path_locked(watch->path, parent); 351 351 if (IS_ERR(d)) 352 352 return PTR_ERR(d); 353 - if (d_is_positive(d)) { 354 - /* update watch filter fields */ 355 - watch->dev = d->d_sb->s_dev; 356 - watch->ino = d_backing_inode(d)->i_ino; 357 - } 353 + /* update watch filter fields */ 354 + watch->dev = d->d_sb->s_dev; 355 + watch->ino = d_backing_inode(d)->i_ino; 356 + 358 357 inode_unlock(d_backing_inode(parent->dentry)); 359 358 dput(d); 360 359 return 0; ··· 418 419 /* caller expects mutex locked */ 419 420 mutex_lock(&audit_filter_mutex); 420 421 421 - if (ret) { 422 + if (ret && ret != -ENOENT) { 422 423 audit_put_watch(watch); 423 424 return ret; 424 425 } 426 + ret = 0; 425 427 426 428 /* either find an old parent or attach a new one */ 427 429 parent = audit_find_parent(d_backing_inode(parent_path.dentry));
+4 -4
kernel/bpf/inode.c
··· 150 150 inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); 151 151 } 152 152 153 - static int bpf_mkdir(struct mnt_idmap *idmap, struct inode *dir, 154 - struct dentry *dentry, umode_t mode) 153 + static struct dentry *bpf_mkdir(struct mnt_idmap *idmap, struct inode *dir, 154 + struct dentry *dentry, umode_t mode) 155 155 { 156 156 struct inode *inode; 157 157 158 158 inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFDIR); 159 159 if (IS_ERR(inode)) 160 - return PTR_ERR(inode); 160 + return ERR_CAST(inode); 161 161 162 162 inode->i_op = &bpf_dir_iops; 163 163 inode->i_fop = &simple_dir_operations; ··· 166 166 inc_nlink(dir); 167 167 168 168 bpf_dentry_finalize(dentry, inode, dir); 169 - return 0; 169 + return NULL; 170 170 } 171 171 172 172 struct map_iter {
+4 -4
mm/shmem.c
··· 3912 3912 return error; 3913 3913 } 3914 3914 3915 - static int shmem_mkdir(struct mnt_idmap *idmap, struct inode *dir, 3916 - struct dentry *dentry, umode_t mode) 3915 + static struct dentry *shmem_mkdir(struct mnt_idmap *idmap, struct inode *dir, 3916 + struct dentry *dentry, umode_t mode) 3917 3917 { 3918 3918 int error; 3919 3919 3920 3920 error = shmem_mknod(idmap, dir, dentry, mode | S_IFDIR, 0); 3921 3921 if (error) 3922 - return error; 3922 + return ERR_PTR(error); 3923 3923 inc_nlink(dir); 3924 - return 0; 3924 + return NULL; 3925 3925 } 3926 3926 3927 3927 static int shmem_create(struct mnt_idmap *idmap, struct inode *dir,
+4 -4
security/apparmor/apparmorfs.c
··· 1795 1795 return error; 1796 1796 } 1797 1797 1798 - static int ns_mkdir_op(struct mnt_idmap *idmap, struct inode *dir, 1799 - struct dentry *dentry, umode_t mode) 1798 + static struct dentry *ns_mkdir_op(struct mnt_idmap *idmap, struct inode *dir, 1799 + struct dentry *dentry, umode_t mode) 1800 1800 { 1801 1801 struct aa_ns *ns, *parent; 1802 1802 /* TODO: improve permission check */ ··· 1808 1808 AA_MAY_LOAD_POLICY); 1809 1809 end_current_label_crit_section(label); 1810 1810 if (error) 1811 - return error; 1811 + return ERR_PTR(error); 1812 1812 1813 1813 parent = aa_get_ns(dir->i_private); 1814 1814 AA_BUG(d_inode(ns_subns_dir(parent)) != dir); ··· 1843 1843 mutex_unlock(&parent->lock); 1844 1844 aa_put_ns(parent); 1845 1845 1846 - return error; 1846 + return ERR_PTR(error); 1847 1847 } 1848 1848 1849 1849 static int ns_rmdir_op(struct inode *dir, struct dentry *dentry)