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

autofs: use dentry info count instead of simple_empty()

The dentry info. field count is used to check if a dentry is in use
during expire. But, to be used for this the count field must account for
the presence of child dentries in a directory dentry.

Therefore it can also be used to check for an empty directory dentry which
can be done without having to to take an additional lock or account for
the presence of a readdir cursor dentry as is done by simple_empty().

Link: https://lkml.kernel.org/r/165724459238.30914.1504611159945950108.stgit@donald.themaw.net
Signed-off-by: Ian Kent <raven@themaw.net>
Cc: Al Viro <viro@ZenIV.linux.org.uk>
Cc: David Howells <dhowells@redhat.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Ian Kent and committed by
akpm
a4a87303 9ccbac76

+14 -11
+5
fs/autofs/autofs_i.h
··· 148 148 task_pgrp(current) == sbi->oz_pgrp); 149 149 } 150 150 151 + static inline bool autofs_empty(struct autofs_info *ino) 152 + { 153 + return ino->count < 2; 154 + } 155 + 151 156 struct inode *autofs_get_inode(struct super_block *, umode_t); 152 157 void autofs_free_ino(struct autofs_info *); 153 158
+1 -1
fs/autofs/expire.c
··· 371 371 return NULL; 372 372 } 373 373 374 - if (simple_empty(dentry)) 374 + if (autofs_empty(ino)) 375 375 return NULL; 376 376 377 377 /* Case 2: tree mount, expire iff entire tree is not busy */
+8 -10
fs/autofs/root.c
··· 79 79 { 80 80 struct dentry *dentry = file->f_path.dentry; 81 81 struct autofs_sb_info *sbi = autofs_sbi(dentry->d_sb); 82 + struct autofs_info *ino = autofs_dentry_ino(dentry); 82 83 83 84 pr_debug("file=%p dentry=%p %pd\n", file, dentry, dentry); 84 85 ··· 96 95 * it. 97 96 */ 98 97 spin_lock(&sbi->lookup_lock); 99 - if (!path_is_mountpoint(&file->f_path) && simple_empty(dentry)) { 98 + if (!path_is_mountpoint(&file->f_path) && autofs_empty(ino)) { 100 99 spin_unlock(&sbi->lookup_lock); 101 100 return -ENOENT; 102 101 } ··· 365 364 * the mount never trigger mounts themselves (they have an 366 365 * autofs trigger mount mounted on them). But v4 pseudo direct 367 366 * mounts do need the leaves to trigger mounts. In this case 368 - * we have no choice but to use the list_empty() check and 367 + * we have no choice but to use the autofs_empty() check and 369 368 * require user space behave. 370 369 */ 371 370 if (sbi->version > 4) { ··· 374 373 goto done; 375 374 } 376 375 } else { 377 - if (!simple_empty(dentry)) { 376 + if (!autofs_empty(ino)) { 378 377 spin_unlock(&sbi->fs_lock); 379 378 goto done; 380 379 } ··· 429 428 430 429 if (rcu_walk) { 431 430 /* We don't need fs_lock in rcu_walk mode, 432 - * just testing 'AUTOFS_INFO_NO_RCU' is enough. 433 - * simple_empty() takes a spinlock, so leave it 434 - * to last. 431 + * just testing 'AUTOFS_INF_WANT_EXPIRE' is enough. 432 + * 435 433 * We only return -EISDIR when certain this isn't 436 434 * a mount-trap. 437 435 */ ··· 443 443 inode = d_inode_rcu(dentry); 444 444 if (inode && S_ISLNK(inode->i_mode)) 445 445 return -EISDIR; 446 - if (list_empty(&dentry->d_subdirs)) 447 - return 0; 448 - if (!simple_empty(dentry)) 446 + if (!autofs_empty(ino)) 449 447 return -EISDIR; 450 448 return 0; 451 449 } ··· 463 465 * we can avoid needless calls ->d_automount() and avoid 464 466 * an incorrect ELOOP error return. 465 467 */ 466 - if ((!path_is_mountpoint(path) && !simple_empty(dentry)) || 468 + if ((!path_is_mountpoint(path) && !autofs_empty(ino)) || 467 469 (d_really_is_positive(dentry) && d_is_symlink(dentry))) 468 470 status = -EISDIR; 469 471 }