···124124 * it.125125 */126126 spin_lock(&sbi->lookup_lock);127127- spin_lock(&dentry->d_lock);128128- if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) {129129- spin_unlock(&dentry->d_lock);127127+ if (!d_mountpoint(dentry) && simple_empty(dentry)) {130128 spin_unlock(&sbi->lookup_lock);131129 return -ENOENT;132130 }133133- spin_unlock(&dentry->d_lock);134131 spin_unlock(&sbi->lookup_lock);135132136133out:···352355 status = autofs4_mount_wait(dentry);353356 if (status)354357 return ERR_PTR(status);355355- spin_lock(&sbi->fs_lock);356358 goto done;357359 }358360···360364 * having d_mountpoint() true, so there's no need to call back361365 * to the daemon.362366 */363363- if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode))367367+ if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)) {368368+ spin_unlock(&sbi->fs_lock);364369 goto done;370370+ }371371+365372 if (!d_mountpoint(dentry)) {366373 /*367374 * It's possible that user space hasn't removed directories···378379 * require user space behave.379380 */380381 if (sbi->version > 4) {381381- if (have_submounts(dentry))382382- goto done;383383- } else {384384- spin_lock(&dentry->d_lock);385385- if (!list_empty(&dentry->d_subdirs)) {386386- spin_unlock(&dentry->d_lock);382382+ if (have_submounts(dentry)) {383383+ spin_unlock(&sbi->fs_lock);387384 goto done;388385 }389389- spin_unlock(&dentry->d_lock);386386+ } else {387387+ if (!simple_empty(dentry))388388+ goto done;390389 }391390 ino->flags |= AUTOFS_INF_PENDING;392391 spin_unlock(&sbi->fs_lock);···396399 return ERR_PTR(status);397400 }398401 }399399-done:400400- if (!(ino->flags & AUTOFS_INF_EXPIRING)) {401401- /*402402- * Any needed mounting has been completed and the path403403- * updated so clear DCACHE_NEED_AUTOMOUNT so we don't404404- * call ->d_automount() on rootless multi-mounts since405405- * it can lead to an incorrect ELOOP error return.406406- *407407- * Only clear DMANAGED_AUTOMOUNT for rootless multi-mounts and408408- * symlinks as in all other cases the dentry will be covered by409409- * an actual mount so ->d_automount() won't be called during410410- * the follow.411411- */412412- spin_lock(&dentry->d_lock);413413- if ((!d_mountpoint(dentry) &&414414- !list_empty(&dentry->d_subdirs)) ||415415- (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)))416416- __managed_dentry_clear_automount(dentry);417417- spin_unlock(&dentry->d_lock);418418- }419402 spin_unlock(&sbi->fs_lock);420420-403403+done:421404 /* Mount succeeded, check if we ended up with a new dentry */422405 dentry = autofs4_mountpoint_changed(path);423406 if (!dentry)···409432int autofs4_d_manage(struct dentry *dentry, bool rcu_walk)410433{411434 struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);435435+ struct autofs_info *ino = autofs4_dentry_ino(dentry);436436+ int status;412437413438 DPRINTK("dentry=%p %.*s",414439 dentry, dentry->d_name.len, dentry->d_name.name);···435456 * This dentry may be under construction so wait on mount436457 * completion.437458 */438438- return autofs4_mount_wait(dentry);459459+ status = autofs4_mount_wait(dentry);460460+ if (status)461461+ return status;462462+463463+ spin_lock(&sbi->fs_lock);464464+ /*465465+ * If the dentry has been selected for expire while we slept466466+ * on the lock then it might go away. We'll deal with that in467467+ * ->d_automount() and wait on a new mount if the expire468468+ * succeeds or return here if it doesn't (since there's no469469+ * mount to follow with a rootless multi-mount).470470+ */471471+ if (!(ino->flags & AUTOFS_INF_EXPIRING)) {472472+ /*473473+ * Any needed mounting has been completed and the path474474+ * updated so check if this is a rootless multi-mount so475475+ * we can avoid needless calls ->d_automount() and avoid476476+ * an incorrect ELOOP error return.477477+ */478478+ if ((!d_mountpoint(dentry) && !simple_empty(dentry)) ||479479+ (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)))480480+ status = -EISDIR;481481+ }482482+ spin_unlock(&sbi->fs_lock);483483+484484+ return status;439485}440486441487/* Lookups in the root directory */···603599604600 spin_lock(&sbi->lookup_lock);605601 __autofs4_add_expiring(dentry);606606- spin_lock(&dentry->d_lock);607607- __d_drop(dentry);608608- spin_unlock(&dentry->d_lock);602602+ d_drop(dentry);609603 spin_unlock(&sbi->lookup_lock);610604611605 return 0;···674672 return -EACCES;675673676674 spin_lock(&sbi->lookup_lock);677677- spin_lock(&dentry->d_lock);678678- if (!list_empty(&dentry->d_subdirs)) {679679- spin_unlock(&dentry->d_lock);675675+ if (!simple_empty(dentry)) {680676 spin_unlock(&sbi->lookup_lock);681677 return -ENOTEMPTY;682678 }683679 __autofs4_add_expiring(dentry);684684- __d_drop(dentry);685685- spin_unlock(&dentry->d_lock);680680+ d_drop(dentry);686681 spin_unlock(&sbi->lookup_lock);687682688683 if (sbi->version < 5)