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

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

Pull vfs async directory updates from Christian Brauner:
"This contains further preparatory changes for the asynchronous directory
locking scheme:

- Add lookup_one_positive_killable() which allows overlayfs to
perform lookup that won't block on a fatal signal

- Unify the mount idmap handling in struct renamedata as a rename can
only happen within a single mount

- Introduce kern_path_parent() for audit which sets the path to the
parent and returns a dentry for the target without holding any
locks on return

- Rename kern_path_locked() as it is only used to prepare for the
removal of an object from the filesystem:

kern_path_locked() => start_removing_path()
kern_path_create() => start_creating_path()
user_path_create() => start_creating_user_path()
user_path_locked_at() => start_removing_user_path_at()
done_path_create() => end_creating_path()
NA => end_removing_path()"

* tag 'vfs-6.18-rc1.async' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
debugfs: rename start_creating() to debugfs_start_creating()
VFS: rename kern_path_locked() and related functions.
VFS/audit: introduce kern_path_parent() for audit
VFS: unify old_mnt_idmap and new_mnt_idmap in renamedata
VFS: discard err2 in filename_create()
VFS/ovl: add lookup_one_positive_killable()

+215 -129
+12
Documentation/filesystems/porting.rst
··· 1285 1285 The vm_area_desc provides the minimum required information for a filesystem 1286 1286 to initialise state upon memory mapping of a file-backed region, and output 1287 1287 parameters for the file system to set this state. 1288 + 1289 + --- 1290 + 1291 + **mandatory** 1292 + 1293 + Several functions are renamed: 1294 + 1295 + - kern_path_locked -> start_removing_path 1296 + - kern_path_create -> start_creating_path 1297 + - user_path_create -> start_creating_user_path 1298 + - user_path_locked_at -> start_removing_user_path_at 1299 + - done_path_create -> end_creating_path
+2 -2
arch/powerpc/platforms/cell/spufs/syscalls.c
··· 67 67 struct dentry *dentry; 68 68 int ret; 69 69 70 - dentry = user_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY); 70 + dentry = start_creating_user_path(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY); 71 71 ret = PTR_ERR(dentry); 72 72 if (!IS_ERR(dentry)) { 73 73 ret = spufs_create(&path, dentry, flags, mode, neighbor); 74 - done_path_create(&path, dentry); 74 + end_creating_path(&path, dentry); 75 75 } 76 76 77 77 return ret;
+9 -13
drivers/base/devtmpfs.c
··· 176 176 struct dentry *dentry; 177 177 struct path path; 178 178 179 - dentry = kern_path_create(AT_FDCWD, name, &path, LOOKUP_DIRECTORY); 179 + dentry = start_creating_path(AT_FDCWD, name, &path, LOOKUP_DIRECTORY); 180 180 if (IS_ERR(dentry)) 181 181 return PTR_ERR(dentry); 182 182 ··· 184 184 if (!IS_ERR(dentry)) 185 185 /* mark as kernel-created inode */ 186 186 d_inode(dentry)->i_private = &thread; 187 - done_path_create(&path, dentry); 187 + end_creating_path(&path, dentry); 188 188 return PTR_ERR_OR_ZERO(dentry); 189 189 } 190 190 ··· 222 222 struct path path; 223 223 int err; 224 224 225 - dentry = kern_path_create(AT_FDCWD, nodename, &path, 0); 225 + dentry = start_creating_path(AT_FDCWD, nodename, &path, 0); 226 226 if (dentry == ERR_PTR(-ENOENT)) { 227 227 create_path(nodename); 228 - dentry = kern_path_create(AT_FDCWD, nodename, &path, 0); 228 + dentry = start_creating_path(AT_FDCWD, nodename, &path, 0); 229 229 } 230 230 if (IS_ERR(dentry)) 231 231 return PTR_ERR(dentry); ··· 246 246 /* mark as kernel-created inode */ 247 247 d_inode(dentry)->i_private = &thread; 248 248 } 249 - done_path_create(&path, dentry); 249 + end_creating_path(&path, dentry); 250 250 return err; 251 251 } 252 252 ··· 256 256 struct dentry *dentry; 257 257 int err; 258 258 259 - dentry = kern_path_locked(name, &parent); 259 + dentry = start_removing_path(name, &parent); 260 260 if (IS_ERR(dentry)) 261 261 return PTR_ERR(dentry); 262 262 if (d_inode(dentry)->i_private == &thread) ··· 265 265 else 266 266 err = -EPERM; 267 267 268 - dput(dentry); 269 - inode_unlock(d_inode(parent.dentry)); 270 - path_put(&parent); 268 + end_removing_path(&parent, dentry); 271 269 return err; 272 270 } 273 271 ··· 323 325 int deleted = 0; 324 326 int err = 0; 325 327 326 - dentry = kern_path_locked(nodename, &parent); 328 + dentry = start_removing_path(nodename, &parent); 327 329 if (IS_ERR(dentry)) 328 330 return PTR_ERR(dentry); 329 331 ··· 347 349 if (!err || err == -ENOENT) 348 350 deleted = 1; 349 351 } 350 - dput(dentry); 351 - inode_unlock(d_inode(parent.dentry)); 352 + end_removing_path(&parent, dentry); 352 353 353 - path_put(&parent); 354 354 if (deleted && strchr(nodename, '/')) 355 355 delete_path(nodename); 356 356 return err;
+4 -6
fs/bcachefs/fs-ioctl.c
··· 255 255 snapshot_src = inode_inum(to_bch_ei(src_path.dentry->d_inode)); 256 256 } 257 257 258 - dst_dentry = user_path_create(arg.dirfd, 258 + dst_dentry = start_creating_user_path(arg.dirfd, 259 259 (const char __user *)(unsigned long)arg.dst_ptr, 260 260 &dst_path, lookup_flags); 261 261 error = PTR_ERR_OR_ZERO(dst_dentry); ··· 314 314 d_instantiate(dst_dentry, &inode->v); 315 315 fsnotify_mkdir(dir, dst_dentry); 316 316 err3: 317 - done_path_create(&dst_path, dst_dentry); 317 + end_creating_path(&dst_path, dst_dentry); 318 318 err2: 319 319 if (arg.src_ptr) 320 320 path_put(&src_path); ··· 334 334 if (arg.flags) 335 335 return -EINVAL; 336 336 337 - victim = user_path_locked_at(arg.dirfd, name, &path); 337 + victim = start_removing_user_path_at(arg.dirfd, name, &path); 338 338 if (IS_ERR(victim)) 339 339 return PTR_ERR(victim); 340 340 ··· 351 351 d_invalidate(victim); 352 352 } 353 353 err: 354 - inode_unlock(dir); 355 - dput(victim); 356 - path_put(&path); 354 + end_removing_path(&path, victim); 357 355 return ret; 358 356 } 359 357
+1 -2
fs/cachefiles/namei.c
··· 387 387 cachefiles_io_error(cache, "Rename security error %d", ret); 388 388 } else { 389 389 struct renamedata rd = { 390 - .old_mnt_idmap = &nop_mnt_idmap, 390 + .mnt_idmap = &nop_mnt_idmap, 391 391 .old_parent = dir, 392 392 .old_dentry = rep, 393 - .new_mnt_idmap = &nop_mnt_idmap, 394 393 .new_parent = cache->graveyard, 395 394 .new_dentry = grave, 396 395 };
+6 -5
fs/debugfs/inode.c
··· 362 362 } 363 363 EXPORT_SYMBOL_GPL(debugfs_lookup); 364 364 365 - static struct dentry *start_creating(const char *name, struct dentry *parent) 365 + static struct dentry *debugfs_start_creating(const char *name, 366 + struct dentry *parent) 366 367 { 367 368 struct dentry *dentry; 368 369 int error; ··· 429 428 if (!(mode & S_IFMT)) 430 429 mode |= S_IFREG; 431 430 BUG_ON(!S_ISREG(mode)); 432 - dentry = start_creating(name, parent); 431 + dentry = debugfs_start_creating(name, parent); 433 432 434 433 if (IS_ERR(dentry)) 435 434 return dentry; ··· 578 577 */ 579 578 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) 580 579 { 581 - struct dentry *dentry = start_creating(name, parent); 580 + struct dentry *dentry = debugfs_start_creating(name, parent); 582 581 struct inode *inode; 583 582 584 583 if (IS_ERR(dentry)) ··· 625 624 debugfs_automount_t f, 626 625 void *data) 627 626 { 628 - struct dentry *dentry = start_creating(name, parent); 627 + struct dentry *dentry = debugfs_start_creating(name, parent); 629 628 struct inode *inode; 630 629 631 630 if (IS_ERR(dentry)) ··· 688 687 if (!link) 689 688 return ERR_PTR(-ENOMEM); 690 689 691 - dentry = start_creating(name, parent); 690 + dentry = debugfs_start_creating(name, parent); 692 691 if (IS_ERR(dentry)) { 693 692 kfree(link); 694 693 return dentry;
+1 -2
fs/ecryptfs/inode.c
··· 634 634 goto out_lock; 635 635 } 636 636 637 - rd.old_mnt_idmap = &nop_mnt_idmap; 637 + rd.mnt_idmap = &nop_mnt_idmap; 638 638 rd.old_parent = lower_old_dir_dentry; 639 639 rd.old_dentry = lower_old_dentry; 640 - rd.new_mnt_idmap = &nop_mnt_idmap; 641 640 rd.new_parent = lower_new_dir_dentry; 642 641 rd.new_dentry = lower_new_dentry; 643 642 rc = vfs_rename(&rd);
+9 -8
fs/init.c
··· 149 149 else if (!(S_ISBLK(mode) || S_ISCHR(mode))) 150 150 return -EINVAL; 151 151 152 - dentry = kern_path_create(AT_FDCWD, filename, &path, 0); 152 + dentry = start_creating_path(AT_FDCWD, filename, &path, 0); 153 153 if (IS_ERR(dentry)) 154 154 return PTR_ERR(dentry); 155 155 ··· 158 158 if (!error) 159 159 error = vfs_mknod(mnt_idmap(path.mnt), path.dentry->d_inode, 160 160 dentry, mode, new_decode_dev(dev)); 161 - done_path_create(&path, dentry); 161 + end_creating_path(&path, dentry); 162 162 return error; 163 163 } 164 164 ··· 173 173 if (error) 174 174 return error; 175 175 176 - new_dentry = kern_path_create(AT_FDCWD, newname, &new_path, 0); 176 + new_dentry = start_creating_path(AT_FDCWD, newname, &new_path, 0); 177 177 error = PTR_ERR(new_dentry); 178 178 if (IS_ERR(new_dentry)) 179 179 goto out; ··· 191 191 error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode, 192 192 new_dentry, NULL); 193 193 out_dput: 194 - done_path_create(&new_path, new_dentry); 194 + end_creating_path(&new_path, new_dentry); 195 195 out: 196 196 path_put(&old_path); 197 197 return error; ··· 203 203 struct path path; 204 204 int error; 205 205 206 - dentry = kern_path_create(AT_FDCWD, newname, &path, 0); 206 + dentry = start_creating_path(AT_FDCWD, newname, &path, 0); 207 207 if (IS_ERR(dentry)) 208 208 return PTR_ERR(dentry); 209 209 error = security_path_symlink(&path, dentry, oldname); 210 210 if (!error) 211 211 error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode, 212 212 dentry, oldname); 213 - done_path_create(&path, dentry); 213 + end_creating_path(&path, dentry); 214 214 return error; 215 215 } 216 216 ··· 225 225 struct path path; 226 226 int error; 227 227 228 - dentry = kern_path_create(AT_FDCWD, pathname, &path, LOOKUP_DIRECTORY); 228 + dentry = start_creating_path(AT_FDCWD, pathname, &path, 229 + LOOKUP_DIRECTORY); 229 230 if (IS_ERR(dentry)) 230 231 return PTR_ERR(dentry); 231 232 mode = mode_strip_umask(d_inode(path.dentry), mode); ··· 237 236 if (IS_ERR(dentry)) 238 237 error = PTR_ERR(dentry); 239 238 } 240 - done_path_create(&path, dentry); 239 + end_creating_path(&path, dentry); 241 240 return error; 242 241 } 243 242
+121 -43
fs/namei.c
··· 1835 1835 return res; 1836 1836 } 1837 1837 1838 + static struct dentry *lookup_slow_killable(const struct qstr *name, 1839 + struct dentry *dir, 1840 + unsigned int flags) 1841 + { 1842 + struct inode *inode = dir->d_inode; 1843 + struct dentry *res; 1844 + 1845 + if (inode_lock_shared_killable(inode)) 1846 + return ERR_PTR(-EINTR); 1847 + res = __lookup_slow(name, dir, flags); 1848 + inode_unlock_shared(inode); 1849 + return res; 1850 + } 1851 + 1838 1852 static inline int may_lookup(struct mnt_idmap *idmap, 1839 1853 struct nameidata *restrict nd) 1840 1854 { ··· 2766 2752 } 2767 2753 2768 2754 /* does lookup, returns the object with parent locked */ 2769 - static struct dentry *__kern_path_locked(int dfd, struct filename *name, struct path *path) 2755 + static struct dentry *__start_removing_path(int dfd, struct filename *name, 2756 + struct path *path) 2770 2757 { 2771 2758 struct path parent_path __free(path_put) = {}; 2772 2759 struct dentry *d; ··· 2779 2764 return ERR_PTR(error); 2780 2765 if (unlikely(type != LAST_NORM)) 2781 2766 return ERR_PTR(-EINVAL); 2767 + /* don't fail immediately if it's r/o, at least try to report other errors */ 2768 + error = mnt_want_write(parent_path.mnt); 2782 2769 inode_lock_nested(parent_path.dentry->d_inode, I_MUTEX_PARENT); 2783 2770 d = lookup_one_qstr_excl(&last, parent_path.dentry, 0); 2784 - if (IS_ERR(d)) { 2785 - inode_unlock(parent_path.dentry->d_inode); 2786 - return d; 2787 - } 2771 + if (IS_ERR(d)) 2772 + goto unlock; 2773 + if (error) 2774 + goto fail; 2788 2775 path->dentry = no_free_ptr(parent_path.dentry); 2789 2776 path->mnt = no_free_ptr(parent_path.mnt); 2790 2777 return d; 2778 + 2779 + fail: 2780 + dput(d); 2781 + d = ERR_PTR(error); 2782 + unlock: 2783 + inode_unlock(parent_path.dentry->d_inode); 2784 + if (!error) 2785 + mnt_drop_write(parent_path.mnt); 2786 + return d; 2791 2787 } 2792 2788 2793 - struct dentry *kern_path_locked_negative(const char *name, struct path *path) 2789 + /** 2790 + * kern_path_parent: lookup path returning parent and target 2791 + * @name: path name 2792 + * @path: path to store parent in 2793 + * 2794 + * The path @name should end with a normal component, not "." or ".." or "/". 2795 + * A lookup is performed and if successful the parent information 2796 + * is store in @parent and the dentry is returned. 2797 + * 2798 + * The dentry maybe negative, the parent will be positive. 2799 + * 2800 + * Returns: dentry or error. 2801 + */ 2802 + struct dentry *kern_path_parent(const char *name, struct path *path) 2794 2803 { 2795 2804 struct path parent_path __free(path_put) = {}; 2796 2805 struct filename *filename __free(putname) = getname_kernel(name); ··· 2827 2788 return ERR_PTR(error); 2828 2789 if (unlikely(type != LAST_NORM)) 2829 2790 return ERR_PTR(-EINVAL); 2830 - inode_lock_nested(parent_path.dentry->d_inode, I_MUTEX_PARENT); 2831 - d = lookup_one_qstr_excl(&last, parent_path.dentry, LOOKUP_CREATE); 2832 - if (IS_ERR(d)) { 2833 - inode_unlock(parent_path.dentry->d_inode); 2791 + 2792 + d = lookup_noperm_unlocked(&last, parent_path.dentry); 2793 + if (IS_ERR(d)) 2834 2794 return d; 2835 - } 2836 2795 path->dentry = no_free_ptr(parent_path.dentry); 2837 2796 path->mnt = no_free_ptr(parent_path.mnt); 2838 2797 return d; 2839 2798 } 2840 2799 2841 - struct dentry *kern_path_locked(const char *name, struct path *path) 2800 + struct dentry *start_removing_path(const char *name, struct path *path) 2842 2801 { 2843 2802 struct filename *filename = getname_kernel(name); 2844 - struct dentry *res = __kern_path_locked(AT_FDCWD, filename, path); 2803 + struct dentry *res = __start_removing_path(AT_FDCWD, filename, path); 2845 2804 2846 2805 putname(filename); 2847 2806 return res; 2848 2807 } 2849 2808 2850 - struct dentry *user_path_locked_at(int dfd, const char __user *name, struct path *path) 2809 + struct dentry *start_removing_user_path_at(int dfd, 2810 + const char __user *name, 2811 + struct path *path) 2851 2812 { 2852 2813 struct filename *filename = getname(name); 2853 - struct dentry *res = __kern_path_locked(dfd, filename, path); 2814 + struct dentry *res = __start_removing_path(dfd, filename, path); 2854 2815 2855 2816 putname(filename); 2856 2817 return res; 2857 2818 } 2858 - EXPORT_SYMBOL(user_path_locked_at); 2819 + EXPORT_SYMBOL(start_removing_user_path_at); 2859 2820 2860 2821 int kern_path(const char *name, unsigned int flags, struct path *path) 2861 2822 { ··· 3056 3017 return ret; 3057 3018 } 3058 3019 EXPORT_SYMBOL(lookup_one_unlocked); 3020 + 3021 + /** 3022 + * lookup_one_positive_killable - lookup single pathname component 3023 + * @idmap: idmap of the mount the lookup is performed from 3024 + * @name: qstr olding pathname component to lookup 3025 + * @base: base directory to lookup from 3026 + * 3027 + * This helper will yield ERR_PTR(-ENOENT) on negatives. The helper returns 3028 + * known positive or ERR_PTR(). This is what most of the users want. 3029 + * 3030 + * Note that pinned negative with unlocked parent _can_ become positive at any 3031 + * time, so callers of lookup_one_unlocked() need to be very careful; pinned 3032 + * positives have >d_inode stable, so this one avoids such problems. 3033 + * 3034 + * This can be used for in-kernel filesystem clients such as file servers. 3035 + * 3036 + * It should be called without the parent i_rwsem held, and will take 3037 + * the i_rwsem itself if necessary. If a fatal signal is pending or 3038 + * delivered, it will return %-EINTR if the lock is needed. 3039 + */ 3040 + struct dentry *lookup_one_positive_killable(struct mnt_idmap *idmap, 3041 + struct qstr *name, 3042 + struct dentry *base) 3043 + { 3044 + int err; 3045 + struct dentry *ret; 3046 + 3047 + err = lookup_one_common(idmap, name, base); 3048 + if (err) 3049 + return ERR_PTR(err); 3050 + 3051 + ret = lookup_dcache(name, base, 0); 3052 + if (!ret) 3053 + ret = lookup_slow_killable(name, base, 0); 3054 + if (!IS_ERR(ret) && d_flags_negative(smp_load_acquire(&ret->d_flags))) { 3055 + dput(ret); 3056 + ret = ERR_PTR(-ENOENT); 3057 + } 3058 + return ret; 3059 + } 3060 + EXPORT_SYMBOL(lookup_one_positive_killable); 3059 3061 3060 3062 /** 3061 3063 * lookup_one_positive_unlocked - lookup single pathname component ··· 4202 4122 unsigned int reval_flag = lookup_flags & LOOKUP_REVAL; 4203 4123 unsigned int create_flags = LOOKUP_CREATE | LOOKUP_EXCL; 4204 4124 int type; 4205 - int err2; 4206 4125 int error; 4207 4126 4208 4127 error = filename_parentat(dfd, name, reval_flag, path, &last, &type); ··· 4216 4137 goto out; 4217 4138 4218 4139 /* don't fail immediately if it's r/o, at least try to report other errors */ 4219 - err2 = mnt_want_write(path->mnt); 4140 + error = mnt_want_write(path->mnt); 4220 4141 /* 4221 4142 * Do the final lookup. Suppress 'create' if there is a trailing 4222 4143 * '/', and a directory wasn't requested. ··· 4229 4150 if (IS_ERR(dentry)) 4230 4151 goto unlock; 4231 4152 4232 - if (unlikely(err2)) { 4233 - error = err2; 4153 + if (unlikely(error)) 4234 4154 goto fail; 4235 - } 4155 + 4236 4156 return dentry; 4237 4157 fail: 4238 4158 dput(dentry); 4239 4159 dentry = ERR_PTR(error); 4240 4160 unlock: 4241 4161 inode_unlock(path->dentry->d_inode); 4242 - if (!err2) 4162 + if (!error) 4243 4163 mnt_drop_write(path->mnt); 4244 4164 out: 4245 4165 path_put(path); 4246 4166 return dentry; 4247 4167 } 4248 4168 4249 - struct dentry *kern_path_create(int dfd, const char *pathname, 4250 - struct path *path, unsigned int lookup_flags) 4169 + struct dentry *start_creating_path(int dfd, const char *pathname, 4170 + struct path *path, unsigned int lookup_flags) 4251 4171 { 4252 4172 struct filename *filename = getname_kernel(pathname); 4253 4173 struct dentry *res = filename_create(dfd, filename, path, lookup_flags); ··· 4254 4176 putname(filename); 4255 4177 return res; 4256 4178 } 4257 - EXPORT_SYMBOL(kern_path_create); 4179 + EXPORT_SYMBOL(start_creating_path); 4258 4180 4259 - void done_path_create(struct path *path, struct dentry *dentry) 4181 + void end_creating_path(struct path *path, struct dentry *dentry) 4260 4182 { 4261 4183 if (!IS_ERR(dentry)) 4262 4184 dput(dentry); ··· 4264 4186 mnt_drop_write(path->mnt); 4265 4187 path_put(path); 4266 4188 } 4267 - EXPORT_SYMBOL(done_path_create); 4189 + EXPORT_SYMBOL(end_creating_path); 4268 4190 4269 - inline struct dentry *user_path_create(int dfd, const char __user *pathname, 4270 - struct path *path, unsigned int lookup_flags) 4191 + inline struct dentry *start_creating_user_path( 4192 + int dfd, const char __user *pathname, 4193 + struct path *path, unsigned int lookup_flags) 4271 4194 { 4272 4195 struct filename *filename = getname(pathname); 4273 4196 struct dentry *res = filename_create(dfd, filename, path, lookup_flags); ··· 4276 4197 putname(filename); 4277 4198 return res; 4278 4199 } 4279 - EXPORT_SYMBOL(user_path_create); 4200 + EXPORT_SYMBOL(start_creating_user_path); 4280 4201 4281 4202 /** 4282 4203 * vfs_mknod - create device node or file ··· 4384 4305 break; 4385 4306 } 4386 4307 out2: 4387 - done_path_create(&path, dentry); 4308 + end_creating_path(&path, dentry); 4388 4309 if (retry_estale(error, lookup_flags)) { 4389 4310 lookup_flags |= LOOKUP_REVAL; 4390 4311 goto retry; ··· 4488 4409 if (IS_ERR(dentry)) 4489 4410 error = PTR_ERR(dentry); 4490 4411 } 4491 - done_path_create(&path, dentry); 4412 + end_creating_path(&path, dentry); 4492 4413 if (retry_estale(error, lookup_flags)) { 4493 4414 lookup_flags |= LOOKUP_REVAL; 4494 4415 goto retry; ··· 4842 4763 if (!error) 4843 4764 error = vfs_symlink(mnt_idmap(path.mnt), path.dentry->d_inode, 4844 4765 dentry, from->name); 4845 - done_path_create(&path, dentry); 4766 + end_creating_path(&path, dentry); 4846 4767 if (retry_estale(error, lookup_flags)) { 4847 4768 lookup_flags |= LOOKUP_REVAL; 4848 4769 goto retry; ··· 5011 4932 error = vfs_link(old_path.dentry, idmap, new_path.dentry->d_inode, 5012 4933 new_dentry, &delegated_inode); 5013 4934 out_dput: 5014 - done_path_create(&new_path, new_dentry); 4935 + end_creating_path(&new_path, new_dentry); 5015 4936 if (delegated_inode) { 5016 4937 error = break_deleg_wait(&delegated_inode); 5017 4938 if (!error) { ··· 5111 5032 if (source == target) 5112 5033 return 0; 5113 5034 5114 - error = may_delete(rd->old_mnt_idmap, old_dir, old_dentry, is_dir); 5035 + error = may_delete(rd->mnt_idmap, old_dir, old_dentry, is_dir); 5115 5036 if (error) 5116 5037 return error; 5117 5038 5118 5039 if (!target) { 5119 - error = may_create(rd->new_mnt_idmap, new_dir, new_dentry); 5040 + error = may_create(rd->mnt_idmap, new_dir, new_dentry); 5120 5041 } else { 5121 5042 new_is_dir = d_is_dir(new_dentry); 5122 5043 5123 5044 if (!(flags & RENAME_EXCHANGE)) 5124 - error = may_delete(rd->new_mnt_idmap, new_dir, 5045 + error = may_delete(rd->mnt_idmap, new_dir, 5125 5046 new_dentry, is_dir); 5126 5047 else 5127 - error = may_delete(rd->new_mnt_idmap, new_dir, 5048 + error = may_delete(rd->mnt_idmap, new_dir, 5128 5049 new_dentry, new_is_dir); 5129 5050 } 5130 5051 if (error) ··· 5139 5060 */ 5140 5061 if (new_dir != old_dir) { 5141 5062 if (is_dir) { 5142 - error = inode_permission(rd->old_mnt_idmap, source, 5063 + error = inode_permission(rd->mnt_idmap, source, 5143 5064 MAY_WRITE); 5144 5065 if (error) 5145 5066 return error; 5146 5067 } 5147 5068 if ((flags & RENAME_EXCHANGE) && new_is_dir) { 5148 - error = inode_permission(rd->new_mnt_idmap, target, 5069 + error = inode_permission(rd->mnt_idmap, target, 5149 5070 MAY_WRITE); 5150 5071 if (error) 5151 5072 return error; ··· 5213 5134 if (error) 5214 5135 goto out; 5215 5136 } 5216 - error = old_dir->i_op->rename(rd->new_mnt_idmap, old_dir, old_dentry, 5137 + error = old_dir->i_op->rename(rd->mnt_idmap, old_dir, old_dentry, 5217 5138 new_dir, new_dentry, flags); 5218 5139 if (error) 5219 5140 goto out; ··· 5356 5277 5357 5278 rd.old_parent = old_path.dentry; 5358 5279 rd.old_dentry = old_dentry; 5359 - rd.old_mnt_idmap = mnt_idmap(old_path.mnt); 5280 + rd.mnt_idmap = mnt_idmap(old_path.mnt); 5360 5281 rd.new_parent = new_path.dentry; 5361 5282 rd.new_dentry = new_dentry; 5362 - rd.new_mnt_idmap = mnt_idmap(new_path.mnt); 5363 5283 rd.delegated_inode = &delegated_inode; 5364 5284 rd.flags = flags; 5365 5285 error = vfs_rename(&rd);
+1 -2
fs/nfsd/vfs.c
··· 1951 1951 goto out_dput_old; 1952 1952 } else { 1953 1953 struct renamedata rd = { 1954 - .old_mnt_idmap = &nop_mnt_idmap, 1954 + .mnt_idmap = &nop_mnt_idmap, 1955 1955 .old_parent = fdentry, 1956 1956 .old_dentry = odentry, 1957 - .new_mnt_idmap = &nop_mnt_idmap, 1958 1957 .new_parent = tdentry, 1959 1958 .new_dentry = ndentry, 1960 1959 };
+2 -2
fs/ocfs2/refcounttree.c
··· 4418 4418 return error; 4419 4419 } 4420 4420 4421 - new_dentry = user_path_create(AT_FDCWD, newname, &new_path, 0); 4421 + new_dentry = start_creating_user_path(AT_FDCWD, newname, &new_path, 0); 4422 4422 error = PTR_ERR(new_dentry); 4423 4423 if (IS_ERR(new_dentry)) { 4424 4424 mlog_errno(error); ··· 4435 4435 d_inode(new_path.dentry), 4436 4436 new_dentry, preserve); 4437 4437 out_dput: 4438 - done_path_create(&new_path, new_dentry); 4438 + end_creating_path(&new_path, new_dentry); 4439 4439 out: 4440 4440 path_put(&old_path); 4441 4441
+1 -2
fs/overlayfs/overlayfs.h
··· 361 361 { 362 362 int err; 363 363 struct renamedata rd = { 364 - .old_mnt_idmap = ovl_upper_mnt_idmap(ofs), 364 + .mnt_idmap = ovl_upper_mnt_idmap(ofs), 365 365 .old_parent = olddir, 366 366 .old_dentry = olddentry, 367 - .new_mnt_idmap = ovl_upper_mnt_idmap(ofs), 368 367 .new_parent = newdir, 369 368 .new_dentry = newdentry, 370 369 .flags = flags,
+14 -14
fs/overlayfs/readdir.c
··· 270 270 271 271 static int ovl_check_whiteouts(const struct path *path, struct ovl_readdir_data *rdd) 272 272 { 273 - int err; 273 + int err = 0; 274 274 struct dentry *dentry, *dir = path->dentry; 275 275 const struct cred *old_cred; 276 276 277 277 old_cred = ovl_override_creds(rdd->dentry->d_sb); 278 278 279 - err = down_write_killable(&dir->d_inode->i_rwsem); 280 - if (!err) { 281 - while (rdd->first_maybe_whiteout) { 282 - struct ovl_cache_entry *p = 283 - rdd->first_maybe_whiteout; 284 - rdd->first_maybe_whiteout = p->next_maybe_whiteout; 285 - dentry = lookup_one(mnt_idmap(path->mnt), 286 - &QSTR_LEN(p->name, p->len), dir); 287 - if (!IS_ERR(dentry)) { 288 - p->is_whiteout = ovl_is_whiteout(dentry); 289 - dput(dentry); 290 - } 279 + while (rdd->first_maybe_whiteout) { 280 + struct ovl_cache_entry *p = 281 + rdd->first_maybe_whiteout; 282 + rdd->first_maybe_whiteout = p->next_maybe_whiteout; 283 + dentry = lookup_one_positive_killable(mnt_idmap(path->mnt), 284 + &QSTR_LEN(p->name, p->len), 285 + dir); 286 + if (!IS_ERR(dentry)) { 287 + p->is_whiteout = ovl_is_whiteout(dentry); 288 + dput(dentry); 289 + } else if (PTR_ERR(dentry) == -EINTR) { 290 + err = -EINTR; 291 + break; 291 292 } 292 - inode_unlock(dir->d_inode); 293 293 } 294 294 ovl_revert_creds(old_cred); 295 295
+5 -6
fs/smb/server/vfs.c
··· 196 196 pr_err("File(%s): creation failed (err:%d)\n", name, err); 197 197 } 198 198 199 - done_path_create(&path, dentry); 199 + end_creating_path(&path, dentry); 200 200 return err; 201 201 } 202 202 ··· 237 237 if (!err && dentry != d) 238 238 ksmbd_vfs_inherit_owner(work, d_inode(path.dentry), d_inode(dentry)); 239 239 240 - done_path_create(&path, dentry); 240 + end_creating_path(&path, dentry); 241 241 if (err) 242 242 pr_err("mkdir(%s): creation failed (err:%d)\n", name, err); 243 243 return err; ··· 669 669 ksmbd_debug(VFS, "vfs_link failed err %d\n", err); 670 670 671 671 out3: 672 - done_path_create(&newpath, dentry); 672 + end_creating_path(&newpath, dentry); 673 673 out2: 674 674 path_put(&oldpath); 675 675 out1: ··· 770 770 goto out4; 771 771 } 772 772 773 - rd.old_mnt_idmap = mnt_idmap(old_path->mnt), 773 + rd.mnt_idmap = mnt_idmap(old_path->mnt), 774 774 rd.old_parent = old_parent, 775 775 rd.old_dentry = old_child, 776 - rd.new_mnt_idmap = mnt_idmap(new_path.mnt), 777 776 rd.new_parent = new_path.dentry, 778 777 rd.new_dentry = new_dentry, 779 778 rd.flags = flags, ··· 1325 1326 if (!abs_name) 1326 1327 return ERR_PTR(-ENOMEM); 1327 1328 1328 - dent = kern_path_create(AT_FDCWD, abs_name, path, flags); 1329 + dent = start_creating_path(AT_FDCWD, abs_name, path, flags); 1329 1330 kfree(abs_name); 1330 1331 return dent; 1331 1332 }
+2 -4
include/linux/fs.h
··· 2118 2118 2119 2119 /** 2120 2120 * struct renamedata - contains all information required for renaming 2121 - * @old_mnt_idmap: idmap of the old mount the inode was found from 2121 + * @mnt_idmap: idmap of the mount in which the rename is happening. 2122 2122 * @old_parent: parent of source 2123 2123 * @old_dentry: source 2124 - * @new_mnt_idmap: idmap of the new mount the inode was found from 2125 2124 * @new_parent: parent of destination 2126 2125 * @new_dentry: destination 2127 2126 * @delegated_inode: returns an inode needing a delegation break 2128 2127 * @flags: rename flags 2129 2128 */ 2130 2129 struct renamedata { 2131 - struct mnt_idmap *old_mnt_idmap; 2130 + struct mnt_idmap *mnt_idmap; 2132 2131 struct dentry *old_parent; 2133 2132 struct dentry *old_dentry; 2134 - struct mnt_idmap *new_mnt_idmap; 2135 2133 struct dentry *new_parent; 2136 2134 struct dentry *new_dentry; 2137 2135 struct inode **delegated_inode;
+13 -6
include/linux/namei.h
··· 57 57 struct dentry *base, 58 58 unsigned int flags); 59 59 extern int kern_path(const char *, unsigned, struct path *); 60 + struct dentry *kern_path_parent(const char *name, struct path *parent); 60 61 61 - extern struct dentry *kern_path_create(int, const char *, struct path *, unsigned int); 62 - extern struct dentry *user_path_create(int, const char __user *, struct path *, unsigned int); 63 - extern void done_path_create(struct path *, struct dentry *); 64 - extern struct dentry *kern_path_locked(const char *, struct path *); 65 - extern struct dentry *kern_path_locked_negative(const char *, struct path *); 66 - extern struct dentry *user_path_locked_at(int , const char __user *, struct path *); 62 + extern struct dentry *start_creating_path(int, const char *, struct path *, unsigned int); 63 + extern struct dentry *start_creating_user_path(int, const char __user *, struct path *, unsigned int); 64 + extern void end_creating_path(struct path *, struct dentry *); 65 + extern struct dentry *start_removing_path(const char *, struct path *); 66 + extern struct dentry *start_removing_user_path_at(int , const char __user *, struct path *); 67 + static inline void end_removing_path(struct path *path , struct dentry *dentry) 68 + { 69 + end_creating_path(path, dentry); 70 + } 67 71 int vfs_path_parent_lookup(struct filename *filename, unsigned int flags, 68 72 struct path *parent, struct qstr *last, int *type, 69 73 const struct path *root); ··· 82 78 struct dentry *lookup_one_unlocked(struct mnt_idmap *idmap, 83 79 struct qstr *name, struct dentry *base); 84 80 struct dentry *lookup_one_positive_unlocked(struct mnt_idmap *idmap, 81 + struct qstr *name, 82 + struct dentry *base); 83 + struct dentry *lookup_one_positive_killable(struct mnt_idmap *idmap, 85 84 struct qstr *name, 86 85 struct dentry *base); 87 86
+6 -5
kernel/audit_fsnotify.c
··· 76 76 struct audit_fsnotify_mark *audit_mark; 77 77 struct path path; 78 78 struct dentry *dentry; 79 - struct inode *inode; 80 79 int ret; 81 80 82 81 if (pathname[0] != '/' || pathname[len-1] == '/') 83 82 return ERR_PTR(-EINVAL); 84 83 85 - dentry = kern_path_locked(pathname, &path); 84 + dentry = kern_path_parent(pathname, &path); 86 85 if (IS_ERR(dentry)) 87 86 return ERR_CAST(dentry); /* returning an error */ 88 - inode = path.dentry->d_inode; 89 - inode_unlock(inode); 87 + if (d_really_is_negative(dentry)) { 88 + audit_mark = ERR_PTR(-ENOENT); 89 + goto out; 90 + } 90 91 91 92 audit_mark = kzalloc(sizeof(*audit_mark), GFP_KERNEL); 92 93 if (unlikely(!audit_mark)) { ··· 101 100 audit_update_mark(audit_mark, dentry->d_inode); 102 101 audit_mark->rule = krule; 103 102 104 - ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, 0); 103 + ret = fsnotify_add_inode_mark(&audit_mark->mark, path.dentry->d_inode, 0); 105 104 if (ret < 0) { 106 105 audit_mark->path = NULL; 107 106 fsnotify_put_mark(&audit_mark->mark);
+1 -2
kernel/audit_watch.c
··· 349 349 { 350 350 struct dentry *d; 351 351 352 - d = kern_path_locked_negative(watch->path, parent); 352 + d = kern_path_parent(watch->path, parent); 353 353 if (IS_ERR(d)) 354 354 return PTR_ERR(d); 355 355 ··· 359 359 watch->ino = d_backing_inode(d)->i_ino; 360 360 } 361 361 362 - inode_unlock(d_backing_inode(parent->dentry)); 363 362 dput(d); 364 363 return 0; 365 364 }
+2 -2
kernel/bpf/inode.c
··· 442 442 umode_t mode; 443 443 int ret; 444 444 445 - dentry = user_path_create(path_fd, pathname, &path, 0); 445 + dentry = start_creating_user_path(path_fd, pathname, &path, 0); 446 446 if (IS_ERR(dentry)) 447 447 return PTR_ERR(dentry); 448 448 ··· 471 471 ret = -EPERM; 472 472 } 473 473 out: 474 - done_path_create(&path, dentry); 474 + end_creating_path(&path, dentry); 475 475 return ret; 476 476 } 477 477
+3 -3
net/unix/af_unix.c
··· 1387 1387 * Get the parent directory, calculate the hash for last 1388 1388 * component. 1389 1389 */ 1390 - dentry = kern_path_create(AT_FDCWD, addr->name->sun_path, &parent, 0); 1390 + dentry = start_creating_path(AT_FDCWD, addr->name->sun_path, &parent, 0); 1391 1391 if (IS_ERR(dentry)) { 1392 1392 err = PTR_ERR(dentry); 1393 1393 goto out; ··· 1417 1417 unix_table_double_unlock(net, old_hash, new_hash); 1418 1418 unix_insert_bsd_socket(sk); 1419 1419 mutex_unlock(&u->bindlock); 1420 - done_path_create(&parent, dentry); 1420 + end_creating_path(&parent, dentry); 1421 1421 return 0; 1422 1422 1423 1423 out_unlock: ··· 1427 1427 /* failed after successful mknod? unlink what we'd created... */ 1428 1428 vfs_unlink(idmap, d_inode(parent.dentry), dentry, NULL); 1429 1429 out_path: 1430 - done_path_create(&parent, dentry); 1430 + end_creating_path(&parent, dentry); 1431 1431 out: 1432 1432 unix_release_addr(addr); 1433 1433 return err == -EEXIST ? -EADDRINUSE : err;