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-7.1-rc1.directory' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull vfs directory updates from Christian Brauner:
"Recently 'start_creating', 'start_removing', 'start_renaming' and
related interfaces were added which combine the locking and the
lookup.

At that time many callers were changed to use the new interfaces.
However there are still an assortment of places out side of the core
vfs where the directory is locked explictly, whether with inode_lock()
or lock_rename() or similar. These were missed in the first pass for
an assortment of uninteresting reasons.

This addresses the remaining places where explicit locking is used,
and changes them to use the new interfaces, or otherwise removes the
explicit locking.

The biggest changes are in overlayfs. The other changes are quite
simple, though maybe the cachefiles changes is the least simple of
those"

* tag 'vfs-7.1-rc1.directory' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs:
VFS: unexport lock_rename(), lock_rename_child(), unlock_rename()
ovl: remove ovl_lock_rename_workdir()
ovl: use is_subdir() for testing if one thing is a subdir of another
ovl: change ovl_create_real() to get a new lock when re-opening created file.
ovl: pass name buffer to ovl_start_creating_temp()
cachefiles: change cachefiles_bury_object to use start_renaming_dentry()
ovl: Simplify ovl_lookup_real_one()
VFS: make lookup_one_qstr_excl() static.
nfsd: switch purge_old() to use start_removing_noperm()
selinux: Use simple_start_creating() / simple_done_creating()
Apparmor: Use simple_start_creating() / simple_done_creating()
libfs: change simple_done_creating() to use end_creating()
VFS: move the start_dirop() kerndoc comment to before start_dirop()
fs/proc: Don't lock root inode when creating "self" and "thread-self"
VFS: note error returns in documentation for various lookup functions

+190 -244
+14
Documentation/filesystems/porting.rst
··· 1361 1361 1362 1362 However, if the string is freely accessible for the duration of inode's 1363 1363 lifetime, consider using inode_set_cached_link() instead. 1364 + 1365 + --- 1366 + 1367 + **mandatory** 1368 + 1369 + lookup_one_qstr_excl() is no longer exported - use start_creating() or 1370 + similar. 1371 + --- 1372 + 1373 + ** mandatory** 1374 + 1375 + lock_rename(), lock_rename_child(), unlock_rename() are no 1376 + longer available. Use start_renaming() or similar. 1377 +
+34 -63
fs/cachefiles/namei.c
··· 270 270 struct dentry *rep, 271 271 enum fscache_why_object_killed why) 272 272 { 273 - struct dentry *grave, *trap; 273 + struct dentry *grave; 274 + struct renamedata rd = {}; 274 275 struct path path, path_to_graveyard; 275 276 char nbuffer[8 + 8 + 1]; 276 277 int ret; ··· 303 302 (uint32_t) ktime_get_real_seconds(), 304 303 (uint32_t) atomic_inc_return(&cache->gravecounter)); 305 304 306 - /* do the multiway lock magic */ 307 - trap = lock_rename(cache->graveyard, dir); 308 - if (IS_ERR(trap)) 309 - return PTR_ERR(trap); 310 - 311 - /* do some checks before getting the grave dentry */ 312 - if (rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) { 313 - /* the entry was probably culled when we dropped the parent dir 314 - * lock */ 315 - unlock_rename(cache->graveyard, dir); 316 - _leave(" = 0 [culled?]"); 317 - return 0; 318 - } 319 - 320 - if (!d_can_lookup(cache->graveyard)) { 321 - unlock_rename(cache->graveyard, dir); 322 - cachefiles_io_error(cache, "Graveyard no longer a directory"); 323 - return -EIO; 324 - } 325 - 326 - if (trap == rep) { 327 - unlock_rename(cache->graveyard, dir); 328 - cachefiles_io_error(cache, "May not make directory loop"); 329 - return -EIO; 330 - } 331 - 332 - if (d_mountpoint(rep)) { 333 - unlock_rename(cache->graveyard, dir); 334 - cachefiles_io_error(cache, "Mountpoint in cache"); 335 - return -EIO; 336 - } 337 - 338 - grave = lookup_one(&nop_mnt_idmap, &QSTR(nbuffer), cache->graveyard); 339 - if (IS_ERR(grave)) { 340 - unlock_rename(cache->graveyard, dir); 341 - trace_cachefiles_vfs_error(object, d_inode(cache->graveyard), 342 - PTR_ERR(grave), 343 - cachefiles_trace_lookup_error); 344 - 345 - if (PTR_ERR(grave) == -ENOMEM) { 305 + rd.mnt_idmap = &nop_mnt_idmap; 306 + rd.old_parent = dir; 307 + rd.new_parent = cache->graveyard; 308 + rd.flags = 0; 309 + ret = start_renaming_dentry(&rd, 0, rep, &QSTR(nbuffer)); 310 + if (ret) { 311 + /* Some errors aren't fatal */ 312 + if (ret == -EXDEV) 313 + /* double-lock failed */ 314 + return ret; 315 + if (d_unhashed(rep) || rep->d_parent != dir || IS_DEADDIR(d_inode(rep))) { 316 + /* the entry was probably culled when we dropped the parent dir 317 + * lock */ 318 + _leave(" = 0 [culled?]"); 319 + return 0; 320 + } 321 + if (ret == -EINVAL || ret == -ENOTEMPTY) { 322 + cachefiles_io_error(cache, "May not make directory loop"); 323 + return -EIO; 324 + } 325 + if (ret == -ENOMEM) { 346 326 _leave(" = -ENOMEM"); 347 327 return -ENOMEM; 348 328 } 349 329 350 - cachefiles_io_error(cache, "Lookup error %ld", PTR_ERR(grave)); 330 + cachefiles_io_error(cache, "Lookup error %d", ret); 351 331 return -EIO; 352 332 } 353 333 334 + if (d_mountpoint(rep)) { 335 + end_renaming(&rd); 336 + cachefiles_io_error(cache, "Mountpoint in cache"); 337 + return -EIO; 338 + } 339 + 340 + grave = rd.new_dentry; 354 341 if (d_is_positive(grave)) { 355 - unlock_rename(cache->graveyard, dir); 356 - dput(grave); 342 + end_renaming(&rd); 357 343 grave = NULL; 358 344 cond_resched(); 359 345 goto try_again; 360 346 } 361 347 362 348 if (d_mountpoint(grave)) { 363 - unlock_rename(cache->graveyard, dir); 364 - dput(grave); 349 + end_renaming(&rd); 365 350 cachefiles_io_error(cache, "Mountpoint in graveyard"); 366 - return -EIO; 367 - } 368 - 369 - /* target should not be an ancestor of source */ 370 - if (trap == grave) { 371 - unlock_rename(cache->graveyard, dir); 372 - dput(grave); 373 - cachefiles_io_error(cache, "May not make directory loop"); 374 351 return -EIO; 375 352 } 376 353 ··· 361 382 if (ret < 0) { 362 383 cachefiles_io_error(cache, "Rename security error %d", ret); 363 384 } else { 364 - struct renamedata rd = { 365 - .mnt_idmap = &nop_mnt_idmap, 366 - .old_parent = dir, 367 - .old_dentry = rep, 368 - .new_parent = cache->graveyard, 369 - .new_dentry = grave, 370 - }; 371 385 trace_cachefiles_rename(object, d_inode(rep)->i_ino, why); 372 386 ret = cachefiles_inject_read_error(); 373 387 if (ret == 0) ··· 374 402 } 375 403 376 404 __cachefiles_unmark_inode_in_use(object, d_inode(rep)); 377 - unlock_rename(cache->graveyard, dir); 378 - dput(grave); 405 + end_renaming(&rd); 379 406 _leave(" = 0"); 380 407 return 0; 381 408 }
+1 -2
fs/libfs.c
··· 2318 2318 /* parent must have been held exclusive since simple_start_creating() */ 2319 2319 void simple_done_creating(struct dentry *child) 2320 2320 { 2321 - inode_unlock(child->d_parent->d_inode); 2322 - dput(child); 2321 + end_creating(child); 2323 2322 } 2324 2323 EXPORT_SYMBOL(simple_done_creating);
+46 -24
fs/namei.c
··· 1782 1782 * Will return -ENOENT if name isn't found and LOOKUP_CREATE wasn't passed. 1783 1783 * Will return -EEXIST if name is found and LOOKUP_EXCL was passed. 1784 1784 */ 1785 - struct dentry *lookup_one_qstr_excl(const struct qstr *name, 1786 - struct dentry *base, unsigned int flags) 1785 + static struct dentry *lookup_one_qstr_excl(const struct qstr *name, 1786 + struct dentry *base, unsigned int flags) 1787 1787 { 1788 1788 struct dentry *dentry; 1789 1789 struct dentry *old; ··· 1820 1820 } 1821 1821 return dentry; 1822 1822 } 1823 - EXPORT_SYMBOL(lookup_one_qstr_excl); 1824 1823 1825 1824 /** 1826 1825 * lookup_fast - do fast lockless (but racy) lookup of a dentry ··· 2898 2899 return __filename_parentat(dfd, name, flags, parent, last, type, NULL); 2899 2900 } 2900 2901 2901 - /** 2902 - * __start_dirop - begin a create or remove dirop, performing locking and lookup 2903 - * @parent: the dentry of the parent in which the operation will occur 2904 - * @name: a qstr holding the name within that parent 2905 - * @lookup_flags: intent and other lookup flags. 2906 - * @state: task state bitmask 2907 - * 2908 - * The lookup is performed and necessary locks are taken so that, on success, 2909 - * the returned dentry can be operated on safely. 2910 - * The qstr must already have the hash value calculated. 2911 - * 2912 - * Returns: a locked dentry, or an error. 2913 - * 2914 - */ 2915 2902 static struct dentry *__start_dirop(struct dentry *parent, struct qstr *name, 2916 2903 unsigned int lookup_flags, 2917 2904 unsigned int state) ··· 2919 2934 return dentry; 2920 2935 } 2921 2936 2937 + /** 2938 + * start_dirop - begin a create or remove dirop, performing locking and lookup 2939 + * @parent: the dentry of the parent in which the operation will occur 2940 + * @name: a qstr holding the name within that parent 2941 + * @lookup_flags: intent and other lookup flags. 2942 + * 2943 + * The lookup is performed and necessary locks are taken so that, on success, 2944 + * the returned dentry can be operated on safely. 2945 + * The qstr must already have the hash value calculated. 2946 + * 2947 + * Returns: a locked dentry, or an error. 2948 + * 2949 + */ 2922 2950 struct dentry *start_dirop(struct dentry *parent, struct qstr *name, 2923 2951 unsigned int lookup_flags) 2924 2952 { ··· 3128 3130 * @base: base directory to lookup from 3129 3131 * 3130 3132 * Look up a dentry by name in the dcache, returning NULL if it does not 3131 - * currently exist. The function does not try to create a dentry and if one 3133 + * currently exist or an error if there is a problem with the name. 3134 + * The function does not try to create a dentry and if one 3132 3135 * is found it doesn't try to revalidate it. 3133 3136 * 3134 3137 * Note that this routine is purely a helper for filesystem usage and should ··· 3137 3138 * 3138 3139 * No locks need be held - only a counted reference to @base is needed. 3139 3140 * 3141 + * Returns: 3142 + * - ref-counted dentry on success, or 3143 + * - %NULL if name could not be found, or 3144 + * - ERR_PTR(-EACCES) if name is dot or dotdot or contains a slash or nul, or 3145 + * - ERR_PTR() if fs provide ->d_hash, and this returned an error. 3140 3146 */ 3141 3147 struct dentry *try_lookup_noperm(struct qstr *name, struct dentry *base) 3142 3148 { ··· 3218 3214 * 3219 3215 * Unlike lookup_one, it should be called without the parent 3220 3216 * i_rwsem held, and will take the i_rwsem itself if necessary. 3217 + * 3218 + * Returns: - A dentry, possibly negative, or 3219 + * - same errors as try_lookup_noperm() or 3220 + * - ERR_PTR(-ENOENT) if parent has been removed, or 3221 + * - ERR_PTR(-EACCES) if parent directory is not searchable. 3221 3222 */ 3222 3223 struct dentry *lookup_one_unlocked(struct mnt_idmap *idmap, struct qstr *name, 3223 3224 struct dentry *base) ··· 3259 3250 * It should be called without the parent i_rwsem held, and will take 3260 3251 * the i_rwsem itself if necessary. If a fatal signal is pending or 3261 3252 * delivered, it will return %-EINTR if the lock is needed. 3253 + * 3254 + * Returns: A dentry, possibly negative, or 3255 + * - same errors as lookup_one_unlocked() or 3256 + * - ERR_PTR(-EINTR) if a fatal signal is pending. 3262 3257 */ 3263 3258 struct dentry *lookup_one_positive_killable(struct mnt_idmap *idmap, 3264 3259 struct qstr *name, ··· 3302 3289 * This can be used for in-kernel filesystem clients such as file servers. 3303 3290 * 3304 3291 * The helper should be called without i_rwsem held. 3292 + * 3293 + * Returns: A positive dentry, or 3294 + * - ERR_PTR(-ENOENT) if the name could not be found, or 3295 + * - same errors as lookup_one_unlocked(). 3305 3296 */ 3306 3297 struct dentry *lookup_one_positive_unlocked(struct mnt_idmap *idmap, 3307 3298 struct qstr *name, ··· 3334 3317 * 3335 3318 * Unlike try_lookup_noperm() it *does* revalidate the dentry if it already 3336 3319 * existed. 3320 + * 3321 + * Returns: A dentry, possibly negative, or 3322 + * - ERR_PTR(-ENOENT) if parent has been removed, or 3323 + * - same errors as try_lookup_noperm() 3337 3324 */ 3338 3325 struct dentry *lookup_noperm_unlocked(struct qstr *name, struct dentry *base) 3339 3326 { ··· 3362 3341 * _can_ become positive at any time, so callers of lookup_noperm_unlocked() 3363 3342 * need to be very careful; pinned positives have ->d_inode stable, so 3364 3343 * this one avoids such problems. 3344 + * 3345 + * Returns: A positive dentry, or 3346 + * - ERR_PTR(-ENOENT) if name cannot be found or parent has been removed, or 3347 + * - same errors as try_lookup_noperm() 3365 3348 */ 3366 3349 struct dentry *lookup_noperm_positive_unlocked(struct qstr *name, 3367 3350 struct dentry *base) ··· 3781 3756 /* 3782 3757 * p1 and p2 should be directories on the same fs. 3783 3758 */ 3784 - struct dentry *lock_rename(struct dentry *p1, struct dentry *p2) 3759 + static struct dentry *lock_rename(struct dentry *p1, struct dentry *p2) 3785 3760 { 3786 3761 if (p1 == p2) { 3787 3762 inode_lock_nested(p1->d_inode, I_MUTEX_PARENT); ··· 3791 3766 mutex_lock(&p1->d_sb->s_vfs_rename_mutex); 3792 3767 return lock_two_directories(p1, p2); 3793 3768 } 3794 - EXPORT_SYMBOL(lock_rename); 3795 3769 3796 3770 /* 3797 3771 * c1 and p2 should be on the same fs. 3798 3772 */ 3799 - struct dentry *lock_rename_child(struct dentry *c1, struct dentry *p2) 3773 + static struct dentry *lock_rename_child(struct dentry *c1, struct dentry *p2) 3800 3774 { 3801 3775 if (READ_ONCE(c1->d_parent) == p2) { 3802 3776 /* ··· 3832 3808 mutex_unlock(&c1->d_sb->s_vfs_rename_mutex); 3833 3809 return NULL; 3834 3810 } 3835 - EXPORT_SYMBOL(lock_rename_child); 3836 3811 3837 - void unlock_rename(struct dentry *p1, struct dentry *p2) 3812 + static void unlock_rename(struct dentry *p1, struct dentry *p2) 3838 3813 { 3839 3814 inode_unlock(p1->d_inode); 3840 3815 if (p1 != p2) { ··· 3841 3818 mutex_unlock(&p1->d_sb->s_vfs_rename_mutex); 3842 3819 } 3843 3820 } 3844 - EXPORT_SYMBOL(unlock_rename); 3845 3821 3846 3822 /** 3847 3823 * __start_renaming - lookup and lock names for rename
+2 -4
fs/nfsd/nfs4recover.c
··· 352 352 if (nfs4_has_reclaimed_state(name, nn)) 353 353 goto out_free; 354 354 355 - inode_lock_nested(d_inode(parent), I_MUTEX_PARENT); 356 - child = lookup_one(&nop_mnt_idmap, &QSTR(cname), parent); 355 + child = start_removing_noperm(parent, &QSTR(cname)); 357 356 if (!IS_ERR(child)) { 358 357 status = vfs_rmdir(&nop_mnt_idmap, d_inode(parent), child, NULL); 359 358 if (status) 360 359 printk("failed to remove client recovery directory %pd\n", 361 360 child); 362 - dput(child); 363 361 } 364 - inode_unlock(d_inode(parent)); 362 + end_removing(child); 365 363 366 364 out_free: 367 365 kfree(name.data);
+33 -18
fs/overlayfs/dir.c
··· 66 66 } 67 67 68 68 static struct dentry *ovl_start_creating_temp(struct ovl_fs *ofs, 69 - struct dentry *workdir) 69 + struct dentry *workdir, 70 + char name[OVL_TEMPNAME_SIZE]) 70 71 { 71 - char name[OVL_TEMPNAME_SIZE]; 72 - 73 72 ovl_tempname(name); 74 73 return start_creating(ovl_upper_mnt_idmap(ofs), workdir, 75 74 &QSTR(name)); ··· 80 81 struct dentry *whiteout, *link; 81 82 struct dentry *workdir = ofs->workdir; 82 83 struct inode *wdir = workdir->d_inode; 84 + char name[OVL_TEMPNAME_SIZE]; 83 85 84 86 guard(mutex)(&ofs->whiteout_lock); 85 87 86 88 if (!ofs->whiteout) { 87 - whiteout = ovl_start_creating_temp(ofs, workdir); 89 + whiteout = ovl_start_creating_temp(ofs, workdir, name); 88 90 if (IS_ERR(whiteout)) 89 91 return whiteout; 90 92 err = ovl_do_whiteout(ofs, wdir, whiteout); ··· 97 97 } 98 98 99 99 if (!ofs->no_shared_whiteout) { 100 - link = ovl_start_creating_temp(ofs, workdir); 100 + link = ovl_start_creating_temp(ofs, workdir, name); 101 101 if (IS_ERR(link)) 102 102 return link; 103 103 err = ovl_do_link(ofs, ofs->whiteout, wdir, link); ··· 159 159 } 160 160 161 161 struct dentry *ovl_create_real(struct ovl_fs *ofs, struct dentry *parent, 162 - struct dentry *newdentry, struct ovl_cattr *attr) 162 + struct dentry *newdentry, struct qstr *qname, 163 + struct ovl_cattr *attr) 163 164 { 164 165 struct inode *dir = parent->d_inode; 165 166 int err; ··· 222 221 struct dentry *d; 223 222 /* 224 223 * Some filesystems (i.e. casefolded) may return an unhashed 225 - * negative dentry from the ovl_lookup_upper() call before 224 + * negative dentry from the ovl_start_creating_upper() call before 226 225 * ovl_create_real(). 227 226 * In that case, lookup again after making the newdentry 228 227 * positive, so ovl_create_upper() always returns a hashed 229 - * positive dentry. 228 + * positive dentry. We lookup using qname which should be 229 + * the same name as newentry, but is certain not to change. 230 + * As we have to drop the lock before the lookup a race 231 + * could result in a lookup failure. In that case we return 232 + * an error. 230 233 */ 231 - d = ovl_lookup_upper(ofs, newdentry->d_name.name, parent, 232 - newdentry->d_name.len); 233 - dput(newdentry); 234 - if (IS_ERR_OR_NULL(d)) 234 + end_creating_keep(newdentry); 235 + d = ovl_start_creating_upper(ofs, parent, qname); 236 + 237 + if (IS_ERR_OR_NULL(d)) { 235 238 err = d ? PTR_ERR(d) : -ENOENT; 236 - else 239 + } else if (d->d_inode != newdentry->d_inode) { 240 + err = -EIO; 241 + } else { 242 + dput(newdentry); 237 243 return d; 244 + } 245 + end_creating(d); 246 + dput(newdentry); 247 + return ERR_PTR(err); 238 248 } 239 249 out: 240 250 if (err) { ··· 259 247 struct ovl_cattr *attr) 260 248 { 261 249 struct dentry *ret; 262 - ret = ovl_start_creating_temp(ofs, workdir); 250 + char name[OVL_TEMPNAME_SIZE]; 251 + 252 + ret = ovl_start_creating_temp(ofs, workdir, name); 263 253 if (IS_ERR(ret)) 264 254 return ret; 265 - ret = ovl_create_real(ofs, workdir, ret, attr); 255 + ret = ovl_create_real(ofs, workdir, ret, &QSTR(name), attr); 266 256 return end_creating_keep(ret); 267 257 } 268 258 ··· 364 350 struct ovl_fs *ofs = OVL_FS(dentry->d_sb); 365 351 struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); 366 352 struct dentry *newdentry; 353 + struct qstr qname = QSTR_LEN(dentry->d_name.name, 354 + dentry->d_name.len); 367 355 int err; 368 356 369 357 newdentry = ovl_start_creating_upper(ofs, upperdir, 370 - &QSTR_LEN(dentry->d_name.name, 371 - dentry->d_name.len)); 358 + &qname); 372 359 if (IS_ERR(newdentry)) 373 360 return PTR_ERR(newdentry); 374 - newdentry = ovl_create_real(ofs, upperdir, newdentry, attr); 361 + newdentry = ovl_create_real(ofs, upperdir, newdentry, &qname, attr); 375 362 if (IS_ERR(newdentry)) 376 363 return PTR_ERR(newdentry); 377 364
+37 -42
fs/overlayfs/export.c
··· 349 349 return NULL; 350 350 } 351 351 352 - /* 353 - * Lookup a child overlay dentry to get a connected overlay dentry whose real 354 - * dentry is @real. If @real is on upper layer, we lookup a child overlay 355 - * dentry with the same name as the real dentry. Otherwise, we need to consult 356 - * index for lookup. 352 + /** 353 + * ovl_lookup_real_one - Lookup a child overlay dentry to get an overlay dentry whose real dentry is given 354 + * @connected: parent overlay dentry 355 + * @real: given child real dentry 356 + * @layer: layer in which @real exists 357 + * 358 + * 359 + * Lookup a child overlay dentry in @connected with the same name as the @real 360 + * dentry. Then check that the parent of the result is the real dentry for 361 + * @connected, and @real is the real dentry for the result. 362 + * 363 + * Returns: 364 + * %-ECHILD if the parent of @real is no longer the real dentry for @connected. 365 + * %-ESTALE if @real is not the real dentry of the found dentry. 366 + * Otherwise the found dentry is returned. 357 367 */ 358 368 static struct dentry *ovl_lookup_real_one(struct dentry *connected, 359 369 struct dentry *real, 360 370 const struct ovl_layer *layer) 361 371 { 362 - struct inode *dir = d_inode(connected); 363 - struct dentry *this, *parent = NULL; 372 + struct dentry *this; 364 373 struct name_snapshot name; 365 374 int err; 366 375 367 376 /* 368 - * Lookup child overlay dentry by real name. The dir mutex protects us 369 - * from racing with overlay rename. If the overlay dentry that is above 370 - * real has already been moved to a parent that is not under the 371 - * connected overlay dir, we return -ECHILD and restart the lookup of 372 - * connected real path from the top. 373 - */ 374 - inode_lock_nested(dir, I_MUTEX_PARENT); 375 - err = -ECHILD; 376 - parent = dget_parent(real); 377 - if (ovl_dentry_real_at(connected, layer->idx) != parent) 378 - goto fail; 379 - 380 - /* 381 - * We also need to take a snapshot of real dentry name to protect us 377 + * We need to take a snapshot of real dentry name to protect us 382 378 * from racing with underlying layer rename. In this case, we don't 383 379 * care about returning ESTALE, only from dereferencing a free name 384 380 * pointer because we hold no lock on the real dentry. 385 381 */ 386 382 take_dentry_name_snapshot(&name, real); 387 - /* 388 - * No idmap handling here: it's an internal lookup. 389 - */ 390 - this = lookup_noperm(&name.name, connected); 383 + this = lookup_noperm_unlocked(&name.name, connected); 391 384 release_dentry_name_snapshot(&name); 392 - err = PTR_ERR(this); 393 - if (IS_ERR(this)) { 394 - goto fail; 395 - } else if (!this || !this->d_inode) { 396 - dput(this); 397 - err = -ENOENT; 398 - goto fail; 399 - } else if (ovl_dentry_real_at(this, layer->idx) != real) { 400 - dput(this); 401 - err = -ESTALE; 402 - goto fail; 403 - } 404 385 405 - out: 406 - dput(parent); 407 - inode_unlock(dir); 386 + err = -ECHILD; 387 + if (ovl_dentry_real_at(connected, layer->idx) != real->d_parent) 388 + goto fail; 389 + 390 + err = PTR_ERR(this); 391 + if (IS_ERR(this)) 392 + goto fail; 393 + 394 + err = -ENOENT; 395 + if (!this || !this->d_inode) 396 + goto fail; 397 + 398 + err = -ESTALE; 399 + if (ovl_dentry_real_at(this, layer->idx) != real) 400 + goto fail; 401 + 408 402 return this; 409 403 410 404 fail: 411 405 pr_warn_ratelimited("failed to lookup one by real (%pd2, layer=%d, connected=%pd2, err=%i)\n", 412 406 real, layer->idx, connected, err); 413 - this = ERR_PTR(err); 414 - goto out; 407 + if (!IS_ERR(this)) 408 + dput(this); 409 + return ERR_PTR(err); 415 410 } 416 411 417 412 static struct dentry *ovl_lookup_real(struct super_block *sb,
+1 -9
fs/overlayfs/overlayfs.h
··· 412 412 return file; 413 413 } 414 414 415 - static inline struct dentry *ovl_lookup_upper(struct ovl_fs *ofs, 416 - const char *name, 417 - struct dentry *base, int len) 418 - { 419 - return lookup_one(ovl_upper_mnt_idmap(ofs), &QSTR_LEN(name, len), base); 420 - } 421 - 422 415 static inline struct dentry *ovl_lookup_upper_unlocked(struct ovl_fs *ofs, 423 416 const char *name, 424 417 struct dentry *base, ··· 575 582 bool ovl_need_index(struct dentry *dentry); 576 583 int ovl_nlink_start(struct dentry *dentry); 577 584 void ovl_nlink_end(struct dentry *dentry); 578 - int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *work, 579 - struct dentry *upperdir, struct dentry *upper); 580 585 int ovl_check_metacopy_xattr(struct ovl_fs *ofs, const struct path *path, 581 586 struct ovl_metacopy *data); 582 587 int ovl_set_metacopy_xattr(struct ovl_fs *ofs, struct dentry *d, ··· 900 909 901 910 struct dentry *ovl_create_real(struct ovl_fs *ofs, 902 911 struct dentry *parent, struct dentry *newdentry, 912 + struct qstr *qname, 903 913 struct ovl_cattr *attr); 904 914 int ovl_cleanup(struct ovl_fs *ofs, struct dentry *workdir, struct dentry *dentry); 905 915 #define OVL_TEMPNAME_SIZE 20
+6 -10
fs/overlayfs/super.c
··· 451 451 return 0; 452 452 } 453 453 454 - /* Workdir should not be subdir of upperdir and vice versa */ 454 + /* 455 + * Workdir should not be subdir of upperdir and vice versa, and 456 + * they should not be the same. 457 + */ 455 458 static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir) 456 459 { 457 - bool ok = false; 458 - 459 - if (workdir != upperdir) { 460 - struct dentry *trap = lock_rename(workdir, upperdir); 461 - if (!IS_ERR(trap)) 462 - unlock_rename(workdir, upperdir); 463 - ok = (trap == NULL); 464 - } 465 - return ok; 460 + return !is_subdir(workdir, upperdir) && !is_subdir(upperdir, workdir); 466 461 } 467 462 468 463 static int ovl_setup_trap(struct super_block *sb, struct dentry *dir, ··· 629 634 if (!IS_ERR(child)) { 630 635 if (!child->d_inode) 631 636 child = ovl_create_real(ofs, parent, child, 637 + &QSTR(name), 632 638 OVL_CATTR(mode)); 633 639 end_creating_keep(child); 634 640 }
-25
fs/overlayfs/util.c
··· 1216 1216 ovl_inode_unlock(inode); 1217 1217 } 1218 1218 1219 - int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *work, 1220 - struct dentry *upperdir, struct dentry *upper) 1221 - { 1222 - struct dentry *trap; 1223 - 1224 - /* Workdir should not be subdir of upperdir and vice versa */ 1225 - trap = lock_rename(workdir, upperdir); 1226 - if (IS_ERR(trap)) 1227 - goto err; 1228 - if (trap) 1229 - goto err_unlock; 1230 - if (work && (work->d_parent != workdir || d_unhashed(work))) 1231 - goto err_unlock; 1232 - if (upper && (upper->d_parent != upperdir || d_unhashed(upper))) 1233 - goto err_unlock; 1234 - 1235 - return 0; 1236 - 1237 - err_unlock: 1238 - unlock_rename(workdir, upperdir); 1239 - err: 1240 - pr_err("failed to lock workdir+upperdir\n"); 1241 - return -EIO; 1242 - } 1243 - 1244 1219 /* 1245 1220 * err < 0, 0 if no metacopy xattr, metacopy data size if xattr found. 1246 1221 * an empty xattr returns OVL_METACOPY_MIN_SIZE to distinguish from no xattr value.
-3
fs/proc/self.c
··· 35 35 36 36 int proc_setup_self(struct super_block *s) 37 37 { 38 - struct inode *root_inode = d_inode(s->s_root); 39 38 struct dentry *self; 40 39 int ret = -ENOMEM; 41 40 42 - inode_lock(root_inode); 43 41 self = d_alloc_name(s->s_root, "self"); 44 42 if (self) { 45 43 struct inode *inode = new_inode(s); ··· 53 55 } 54 56 dput(self); 55 57 } 56 - inode_unlock(root_inode); 57 58 58 59 if (ret) 59 60 pr_err("proc_fill_super: can't allocate /proc/self\n");
-3
fs/proc/thread_self.c
··· 35 35 36 36 int proc_setup_thread_self(struct super_block *s) 37 37 { 38 - struct inode *root_inode = d_inode(s->s_root); 39 38 struct dentry *thread_self; 40 39 int ret = -ENOMEM; 41 40 42 - inode_lock(root_inode); 43 41 thread_self = d_alloc_name(s->s_root, "thread-self"); 44 42 if (thread_self) { 45 43 struct inode *inode = new_inode(s); ··· 53 55 } 54 56 dput(thread_self); 55 57 } 56 - inode_unlock(root_inode); 57 58 58 59 if (ret) 59 60 pr_err("proc_fill_super: can't allocate /proc/thread-self\n");
-6
include/linux/namei.h
··· 54 54 55 55 extern int user_path_at(int, const char __user *, unsigned, struct path *); 56 56 57 - struct dentry *lookup_one_qstr_excl(const struct qstr *name, 58 - struct dentry *base, 59 - unsigned int flags); 60 57 extern int kern_path(const char *, unsigned, struct path *); 61 58 struct dentry *kern_path_parent(const char *name, struct path *parent); 62 59 ··· 165 168 extern int follow_down(struct path *path, unsigned int flags); 166 169 extern int follow_up(struct path *); 167 170 168 - extern struct dentry *lock_rename(struct dentry *, struct dentry *); 169 - extern struct dentry *lock_rename_child(struct dentry *, struct dentry *); 170 - extern void unlock_rename(struct dentry *, struct dentry *); 171 171 int start_renaming(struct renamedata *rd, int lookup_flags, 172 172 struct qstr *old_last, struct qstr *new_last); 173 173 int start_renaming_dentry(struct renamedata *rd, int lookup_flags,
+8 -26
security/apparmor/apparmorfs.c
··· 351 351 352 352 dir = d_inode(parent); 353 353 354 - inode_lock(dir); 355 - dentry = lookup_noperm(&QSTR(name), parent); 354 + dentry = simple_start_creating(parent, name); 356 355 if (IS_ERR(dentry)) { 357 356 error = PTR_ERR(dentry); 358 - goto fail_lock; 359 - } 360 - 361 - if (d_really_is_positive(dentry)) { 362 - error = -EEXIST; 363 - goto fail_dentry; 357 + goto fail; 364 358 } 365 359 366 360 error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops); 361 + simple_done_creating(dentry); 367 362 if (error) 368 - goto fail_dentry; 369 - inode_unlock(dir); 363 + goto fail; 370 364 371 365 if (data) 372 366 aa_get_common_ref(data); 373 367 374 368 return dentry; 375 369 376 - fail_dentry: 377 - dput(dentry); 378 - 379 - fail_lock: 380 - inode_unlock(dir); 370 + fail: 381 371 simple_release_fs(&aafs_mnt, &aafs_count); 382 - 383 372 return ERR_PTR(error); 384 373 } 385 374 ··· 2617 2628 if (error) 2618 2629 return error; 2619 2630 2620 - inode_lock(d_inode(parent)); 2621 - dentry = lookup_noperm(&QSTR(NULL_FILE_NAME), parent); 2631 + dentry = simple_start_creating(parent, NULL_FILE_NAME); 2622 2632 if (IS_ERR(dentry)) { 2623 2633 error = PTR_ERR(dentry); 2624 2634 goto out; ··· 2625 2637 inode = new_inode(parent->d_inode->i_sb); 2626 2638 if (!inode) { 2627 2639 error = -ENOMEM; 2628 - goto out1; 2640 + goto out; 2629 2641 } 2630 2642 2631 2643 inode->i_ino = get_next_ino(); ··· 2637 2649 aa_null.dentry = dget(dentry); 2638 2650 aa_null.mnt = mntget(mount); 2639 2651 2640 - error = 0; 2641 - 2642 - out1: 2643 - dput(dentry); 2644 2652 out: 2645 - inode_unlock(d_inode(parent)); 2653 + simple_done_creating(dentry); 2646 2654 simple_release_fs(&mount, &count); 2647 2655 return error; 2648 2656 } 2649 - 2650 - 2651 2657 2652 2658 static const char *policy_get_link(struct dentry *dentry, 2653 2659 struct inode *inode,
+8 -9
security/selinux/selinuxfs.c
··· 1931 1931 static struct dentry *sel_make_swapover_dir(struct super_block *sb, 1932 1932 unsigned long *ino) 1933 1933 { 1934 - struct dentry *dentry = d_alloc_name(sb->s_root, ".swapover"); 1934 + struct dentry *dentry; 1935 1935 struct inode *inode; 1936 1936 1937 - if (!dentry) 1937 + inode = sel_make_inode(sb, S_IFDIR); 1938 + if (!inode) 1938 1939 return ERR_PTR(-ENOMEM); 1939 1940 1940 - inode = sel_make_inode(sb, S_IFDIR); 1941 - if (!inode) { 1942 - dput(dentry); 1943 - return ERR_PTR(-ENOMEM); 1941 + dentry = simple_start_creating(sb->s_root, ".swapover"); 1942 + if (IS_ERR(dentry)) { 1943 + iput(inode); 1944 + return dentry; 1944 1945 } 1945 1946 1946 1947 inode->i_op = &swapover_dir_inode_operations; 1947 1948 inode->i_ino = ++(*ino); 1948 1949 /* directory inodes start off with i_nlink == 2 (for "." entry) */ 1949 1950 inc_nlink(inode); 1950 - inode_lock(sb->s_root->d_inode); 1951 1951 d_make_persistent(dentry, inode); 1952 1952 inc_nlink(sb->s_root->d_inode); 1953 - inode_unlock(sb->s_root->d_inode); 1954 - dput(dentry); 1953 + simple_done_creating(dentry); 1955 1954 return dentry; // borrowed 1956 1955 } 1957 1956