Skip to content

Commit 5f57cbc

Browse files
author
Nick Piggin
committed
fs: dcache remove d_mounted
Rather than keep a d_mounted count in the dentry, set a dentry flag instead. The flag can be cleared by checking the hash table to see if there are any mounts left, which is not time critical because it is performed at detach time. The mounted state of a dentry is only used to speculatively take a look in the mount hash table if it is set -- before following the mount, vfsmount lock is taken and mount re-checked without races. This saves 4 bytes on 32-bit, nothing on 64-bit but it does provide a hole I might use later (and some configs have larger than 32-bit spinlocks which might make use of the hole). Autofs4 conversion and changelog by Ian Kent <raven@themaw.net>: In autofs4, when expring direct (or offset) mounts we need to ensure that we block user path walks into the autofs mount, which is covered by another mount. To do this we clear the mounted status so that follows stop before walking into the mount and are essentially blocked until the expire is completed. The automount daemon still finds the correct dentry for the umount due to the follow mount logic in fs/autofs4/root.c:autofs4_follow_link(), which is set as an inode operation for direct and offset mounts only and is called following the lookup that stopped at the covered mount. At the end of the expire the covering mount probably has gone away so the mounted status need not be restored. But we need to check this and only restore the mounted status if the expire failed. XXX: autofs may not work right if we have other mounts go over the top of it? Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent c28cc36 commit 5f57cbc

4 files changed

Lines changed: 58 additions & 27 deletions

File tree

‎fs/autofs4/expire.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@ struct dentry *autofs4_expire_direct(struct super_block *sb,
295295
struct autofs_info *ino = autofs4_dentry_ino(root);
296296
if (d_mountpoint(root)) {
297297
ino->flags |= AUTOFS_INF_MOUNTPOINT;
298-
root->d_mounted--;
298+
spin_lock(&root->d_lock);
299+
root->d_flags &= ~DCACHE_MOUNTED;
300+
spin_unlock(&root->d_lock);
299301
}
300302
ino->flags |= AUTOFS_INF_EXPIRING;
301303
init_completion(&ino->expire_complete);
@@ -503,7 +505,14 @@ int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt,
503505

504506
spin_lock(&sbi->fs_lock);
505507
if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
506-
sb->s_root->d_mounted++;
508+
spin_lock(&sb->s_root->d_lock);
509+
/*
510+
* If we haven't been expired away, then reset
511+
* mounted status.
512+
*/
513+
if (mnt->mnt_parent != mnt)
514+
sb->s_root->d_flags |= DCACHE_MOUNTED;
515+
spin_unlock(&sb->s_root->d_lock);
507516
ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
508517
}
509518
ino->flags &= ~AUTOFS_INF_EXPIRING;

‎fs/dcache.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,6 @@ struct dentry *d_alloc(struct dentry * parent, const struct qstr *name)
12651265
dentry->d_sb = NULL;
12661266
dentry->d_op = NULL;
12671267
dentry->d_fsdata = NULL;
1268-
dentry->d_mounted = 0;
12691268
INIT_HLIST_NODE(&dentry->d_hash);
12701269
INIT_LIST_HEAD(&dentry->d_lru);
12711270
INIT_LIST_HEAD(&dentry->d_subdirs);

‎fs/namespace.c‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,27 @@ static void __touch_mnt_namespace(struct mnt_namespace *ns)
491491
}
492492
}
493493

494+
/*
495+
* Clear dentry's mounted state if it has no remaining mounts.
496+
* vfsmount_lock must be held for write.
497+
*/
498+
static void dentry_reset_mounted(struct vfsmount *mnt, struct dentry *dentry)
499+
{
500+
unsigned u;
501+
502+
for (u = 0; u < HASH_SIZE; u++) {
503+
struct vfsmount *p;
504+
505+
list_for_each_entry(p, &mount_hashtable[u], mnt_hash) {
506+
if (p->mnt_mountpoint == dentry)
507+
return;
508+
}
509+
}
510+
spin_lock(&dentry->d_lock);
511+
dentry->d_flags &= ~DCACHE_MOUNTED;
512+
spin_unlock(&dentry->d_lock);
513+
}
514+
494515
/*
495516
* vfsmount lock must be held for write
496517
*/
@@ -502,7 +523,7 @@ static void detach_mnt(struct vfsmount *mnt, struct path *old_path)
502523
mnt->mnt_mountpoint = mnt->mnt_root;
503524
list_del_init(&mnt->mnt_child);
504525
list_del_init(&mnt->mnt_hash);
505-
old_path->dentry->d_mounted--;
526+
dentry_reset_mounted(old_path->mnt, old_path->dentry);
506527
}
507528

508529
/*
@@ -513,7 +534,9 @@ void mnt_set_mountpoint(struct vfsmount *mnt, struct dentry *dentry,
513534
{
514535
child_mnt->mnt_parent = mntget(mnt);
515536
child_mnt->mnt_mountpoint = dget(dentry);
516-
dentry->d_mounted++;
537+
spin_lock(&dentry->d_lock);
538+
dentry->d_flags |= DCACHE_MOUNTED;
539+
spin_unlock(&dentry->d_lock);
517540
}
518541

519542
/*
@@ -1073,7 +1096,7 @@ void umount_tree(struct vfsmount *mnt, int propagate, struct list_head *kill)
10731096
list_del_init(&p->mnt_child);
10741097
if (p->mnt_parent != p) {
10751098
p->mnt_parent->mnt_ghosts++;
1076-
p->mnt_mountpoint->d_mounted--;
1099+
dentry_reset_mounted(p->mnt_parent, p->mnt_mountpoint);
10771100
}
10781101
change_mnt_propagation(p, MS_PRIVATE);
10791102
}

‎include/linux/dcache.h‎

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ struct dentry {
9292
unsigned int d_flags; /* protected by d_lock */
9393
spinlock_t d_lock; /* per dentry lock */
9494
seqcount_t d_seq; /* per dentry seqlock */
95-
int d_mounted;
9695
struct inode *d_inode; /* Where the name belongs to - NULL is
9796
* negative */
9897
/*
@@ -156,33 +155,34 @@ struct dentry_operations {
156155

157156
/* d_flags entries */
158157
#define DCACHE_AUTOFS_PENDING 0x0001 /* autofs: "under construction" */
159-
#define DCACHE_NFSFS_RENAMED 0x0002 /* this dentry has been "silly
160-
* renamed" and has to be
161-
* deleted on the last dput()
162-
*/
163-
#define DCACHE_DISCONNECTED 0x0004
164-
/* This dentry is possibly not currently connected to the dcache tree,
165-
* in which case its parent will either be itself, or will have this
166-
* flag as well. nfsd will not use a dentry with this bit set, but will
167-
* first endeavour to clear the bit either by discovering that it is
168-
* connected, or by performing lookup operations. Any filesystem which
169-
* supports nfsd_operations MUST have a lookup function which, if it finds
170-
* a directory inode with a DCACHE_DISCONNECTED dentry, will d_move
171-
* that dentry into place and return that dentry rather than the passed one,
172-
* typically using d_splice_alias.
173-
*/
158+
#define DCACHE_NFSFS_RENAMED 0x0002
159+
/* this dentry has been "silly renamed" and has to be deleted on the last
160+
* dput() */
161+
162+
#define DCACHE_DISCONNECTED 0x0004
163+
/* This dentry is possibly not currently connected to the dcache tree, in
164+
* which case its parent will either be itself, or will have this flag as
165+
* well. nfsd will not use a dentry with this bit set, but will first
166+
* endeavour to clear the bit either by discovering that it is connected,
167+
* or by performing lookup operations. Any filesystem which supports
168+
* nfsd_operations MUST have a lookup function which, if it finds a
169+
* directory inode with a DCACHE_DISCONNECTED dentry, will d_move that
170+
* dentry into place and return that dentry rather than the passed one,
171+
* typically using d_splice_alias. */
174172

175173
#define DCACHE_REFERENCED 0x0008 /* Recently used, don't discard. */
176174
#define DCACHE_UNHASHED 0x0010
177-
178-
#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020 /* Parent inode is watched by inotify */
175+
#define DCACHE_INOTIFY_PARENT_WATCHED 0x0020
176+
/* Parent inode is watched by inotify */
179177

180178
#define DCACHE_COOKIE 0x0040 /* For use by dcookie subsystem */
181-
182-
#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080 /* Parent inode is watched by some fsnotify listener */
179+
#define DCACHE_FSNOTIFY_PARENT_WATCHED 0x0080
180+
/* Parent inode is watched by some fsnotify listener */
183181

184182
#define DCACHE_CANT_MOUNT 0x0100
185183
#define DCACHE_GENOCIDE 0x0200
184+
#define DCACHE_MOUNTED 0x0400 /* is a mountpoint */
185+
186186

187187
extern spinlock_t dcache_inode_lock;
188188
extern seqlock_t rename_lock;
@@ -372,7 +372,7 @@ extern void dput(struct dentry *);
372372

373373
static inline int d_mountpoint(struct dentry *dentry)
374374
{
375-
return dentry->d_mounted;
375+
return dentry->d_flags & DCACHE_MOUNTED;
376376
}
377377

378378
extern struct vfsmount *lookup_mnt(struct path *);

0 commit comments

Comments
 (0)