Skip to content

Commit 850d71a

Browse files
author
Al Viro
committed
autofs: don't bother with atomics for ino->count
All writers are serialized on inode->i_rwsem. So are the readers outside of expire.c. And the readers in expire.c are in the code that really doesn't care about narrow races - it's looking for expiry candidates and its callers have to cope with the possibility of a good candidate becoming busy right under them. No point bothering with atomic operations - just use int and mark the non-serialized readers with READ_ONCE(). Signed-off-by: Al Viro <[email protected]>
1 parent c3aed16 commit 850d71a

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

fs/autofs/autofs_i.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct autofs_info {
6363

6464
struct autofs_sb_info *sbi;
6565
unsigned long last_used;
66-
atomic_t count;
66+
int count;
6767

6868
kuid_t uid;
6969
kgid_t gid;

fs/autofs/expire.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ static int autofs_tree_busy(struct vfsmount *mnt,
211211
}
212212
} else {
213213
struct autofs_info *ino = autofs_dentry_ino(p);
214-
unsigned int ino_count = atomic_read(&ino->count);
214+
unsigned int ino_count = READ_ONCE(ino->count);
215215

216216
/* allow for dget above and top is already dgot */
217217
if (p == top)
@@ -379,7 +379,7 @@ static struct dentry *should_expire(struct dentry *dentry,
379379
/* Not a forced expire? */
380380
if (!(how & AUTOFS_EXP_FORCED)) {
381381
/* ref-walk currently on this dentry? */
382-
ino_count = atomic_read(&ino->count) + 1;
382+
ino_count = READ_ONCE(ino->count) + 1;
383383
if (d_count(dentry) > ino_count)
384384
return NULL;
385385
}
@@ -396,7 +396,7 @@ static struct dentry *should_expire(struct dentry *dentry,
396396
/* Not a forced expire? */
397397
if (!(how & AUTOFS_EXP_FORCED)) {
398398
/* ref-walk currently on this dentry? */
399-
ino_count = atomic_read(&ino->count) + 1;
399+
ino_count = READ_ONCE(ino->count) + 1;
400400
if (d_count(dentry) > ino_count)
401401
return NULL;
402402
}

fs/autofs/root.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -569,9 +569,9 @@ static int autofs_dir_symlink(struct inode *dir,
569569
d_add(dentry, inode);
570570

571571
dget(dentry);
572-
atomic_inc(&ino->count);
572+
ino->count++;
573573
p_ino = autofs_dentry_ino(dentry->d_parent);
574-
atomic_inc(&p_ino->count);
574+
p_ino->count++;
575575

576576
dir->i_mtime = current_time(dir);
577577

@@ -609,9 +609,9 @@ static int autofs_dir_unlink(struct inode *dir, struct dentry *dentry)
609609
if (sbi->flags & AUTOFS_SBI_CATATONIC)
610610
return -EACCES;
611611

612-
atomic_dec(&ino->count);
612+
ino->count--;
613613
p_ino = autofs_dentry_ino(dentry->d_parent);
614-
atomic_dec(&p_ino->count);
614+
p_ino->count--;
615615
dput(ino->dentry);
616616

617617
d_inode(dentry)->i_size = 0;
@@ -669,7 +669,7 @@ static void autofs_clear_leaf_automount_flags(struct dentry *dentry)
669669
/* only consider parents below dentrys in the root */
670670
if (IS_ROOT(parent->d_parent))
671671
return;
672-
if (atomic_read(&autofs_dentry_ino(parent)->count) == 2)
672+
if (autofs_dentry_ino(parent)->count == 2)
673673
managed_dentry_set_managed(parent);
674674
}
675675

@@ -691,7 +691,7 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
691691
if (sbi->flags & AUTOFS_SBI_CATATONIC)
692692
return -EACCES;
693693

694-
if (atomic_read(&ino->count) != 1)
694+
if (ino->count != 1)
695695
return -ENOTEMPTY;
696696

697697
spin_lock(&sbi->lookup_lock);
@@ -702,9 +702,9 @@ static int autofs_dir_rmdir(struct inode *dir, struct dentry *dentry)
702702
if (sbi->version < 5)
703703
autofs_clear_leaf_automount_flags(dentry);
704704

705-
atomic_dec(&ino->count);
705+
ino->count--;
706706
p_ino = autofs_dentry_ino(dentry->d_parent);
707-
atomic_dec(&p_ino->count);
707+
p_ino->count--;
708708
dput(ino->dentry);
709709
d_inode(dentry)->i_size = 0;
710710
clear_nlink(d_inode(dentry));
@@ -750,9 +750,9 @@ static int autofs_dir_mkdir(struct inode *dir,
750750
autofs_set_leaf_automount_flags(dentry);
751751

752752
dget(dentry);
753-
atomic_inc(&ino->count);
753+
ino->count++;
754754
p_ino = autofs_dentry_ino(dentry->d_parent);
755-
atomic_inc(&p_ino->count);
755+
p_ino->count++;
756756
inc_nlink(dir);
757757
dir->i_mtime = current_time(dir);
758758

0 commit comments

Comments
 (0)