Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 231515
b: refs/heads/master
c: b5b8017
h: refs/heads/master
i:
  231513: bae4879
  231511: 75ee47b
v: v3
  • Loading branch information
Ian Kent authored and Al Viro committed Jan 16, 2011
1 parent 98f4511 commit a25b548
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 41 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 10584211e48036182212b598cc53331776406d60
refs/heads/master: b5b801779d59165c4ecf1009009109545bd1f642
50 changes: 49 additions & 1 deletion trunk/fs/autofs4/autofs_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ struct autofs_info {
};

#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
#define AUTOFS_INF_MOUNTPOINT (1<<1) /* mountpoint status for direct expire */
#define AUTOFS_INF_PENDING (1<<2) /* dentry pending mount */

struct autofs_wait_queue {
Expand Down Expand Up @@ -221,6 +220,7 @@ extern const struct file_operations autofs4_root_operations;
/* Operations methods */

struct vfsmount *autofs4_d_automount(struct path *);
int autofs4_d_manage(struct dentry *, bool);

/* VFS automount flags management functions */

Expand Down Expand Up @@ -248,6 +248,54 @@ static inline void managed_dentry_clear_automount(struct dentry *dentry)
spin_unlock(&dentry->d_lock);
}

static inline void __managed_dentry_set_transit(struct dentry *dentry)
{
dentry->d_flags |= DCACHE_MANAGE_TRANSIT;
}

static inline void managed_dentry_set_transit(struct dentry *dentry)
{
spin_lock(&dentry->d_lock);
__managed_dentry_set_transit(dentry);
spin_unlock(&dentry->d_lock);
}

static inline void __managed_dentry_clear_transit(struct dentry *dentry)
{
dentry->d_flags &= ~DCACHE_MANAGE_TRANSIT;
}

static inline void managed_dentry_clear_transit(struct dentry *dentry)
{
spin_lock(&dentry->d_lock);
__managed_dentry_clear_transit(dentry);
spin_unlock(&dentry->d_lock);
}

static inline void __managed_dentry_set_managed(struct dentry *dentry)
{
dentry->d_flags |= (DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT);
}

static inline void managed_dentry_set_managed(struct dentry *dentry)
{
spin_lock(&dentry->d_lock);
__managed_dentry_set_managed(dentry);
spin_unlock(&dentry->d_lock);
}

static inline void __managed_dentry_clear_managed(struct dentry *dentry)
{
dentry->d_flags &= ~(DCACHE_NEED_AUTOMOUNT|DCACHE_MANAGE_TRANSIT);
}

static inline void managed_dentry_clear_managed(struct dentry *dentry)
{
spin_lock(&dentry->d_lock);
__managed_dentry_clear_managed(dentry);
spin_unlock(&dentry->d_lock);
}

/* Initializing function */

int autofs4_fill_super(struct super_block *, void *, int);
Expand Down
51 changes: 26 additions & 25 deletions trunk/fs/autofs4/expire.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ static inline int autofs4_can_expire(struct dentry *dentry,
if (ino == NULL)
return 0;

/* No point expiring a pending mount */
if (ino->flags & AUTOFS_INF_PENDING)
return 0;

if (!do_now) {
/* Too young to die */
if (!timeout || time_after(ino->last_used + timeout, now))
Expand Down Expand Up @@ -283,6 +279,7 @@ struct dentry *autofs4_expire_direct(struct super_block *sb,
unsigned long timeout;
struct dentry *root = dget(sb->s_root);
int do_now = how & AUTOFS_EXP_IMMEDIATE;
struct autofs_info *ino;

if (!root)
return NULL;
Expand All @@ -291,20 +288,21 @@ struct dentry *autofs4_expire_direct(struct super_block *sb,
timeout = sbi->exp_timeout;

spin_lock(&sbi->fs_lock);
ino = autofs4_dentry_ino(root);
/* No point expiring a pending mount */
if (ino->flags & AUTOFS_INF_PENDING) {
spin_unlock(&sbi->fs_lock);
return NULL;
}
managed_dentry_set_transit(root);
if (!autofs4_direct_busy(mnt, root, timeout, do_now)) {
struct autofs_info *ino = autofs4_dentry_ino(root);
if (d_mountpoint(root)) {
ino->flags |= AUTOFS_INF_MOUNTPOINT;
spin_lock(&root->d_lock);
root->d_flags &= ~DCACHE_MOUNTED;
spin_unlock(&root->d_lock);
}
ino->flags |= AUTOFS_INF_EXPIRING;
managed_dentry_set_automount(root);
init_completion(&ino->expire_complete);
spin_unlock(&sbi->fs_lock);
return root;
}
managed_dentry_clear_transit(root);
spin_unlock(&sbi->fs_lock);
dput(root);

Expand Down Expand Up @@ -341,6 +339,10 @@ struct dentry *autofs4_expire_indirect(struct super_block *sb,
while ((dentry = get_next_positive_dentry(dentry, root))) {
spin_lock(&sbi->fs_lock);
ino = autofs4_dentry_ino(dentry);
/* No point expiring a pending mount */
if (ino->flags & AUTOFS_INF_PENDING)
goto cont;
managed_dentry_set_transit(dentry);

/*
* Case 1: (i) indirect mount or top level pseudo direct mount
Expand Down Expand Up @@ -400,6 +402,8 @@ struct dentry *autofs4_expire_indirect(struct super_block *sb,
}
}
next:
managed_dentry_clear_transit(dentry);
cont:
spin_unlock(&sbi->fs_lock);
}
return NULL;
Expand All @@ -409,7 +413,6 @@ struct dentry *autofs4_expire_indirect(struct super_block *sb,
expired, (int)expired->d_name.len, expired->d_name.name);
ino = autofs4_dentry_ino(expired);
ino->flags |= AUTOFS_INF_EXPIRING;
managed_dentry_set_automount(expired);
init_completion(&ino->expire_complete);
spin_unlock(&sbi->fs_lock);
spin_lock(&autofs4_lock);
Expand Down Expand Up @@ -482,7 +485,7 @@ int autofs4_expire_run(struct super_block *sb,
ino = autofs4_dentry_ino(dentry);
ino->flags &= ~AUTOFS_INF_EXPIRING;
if (!d_unhashed(dentry))
managed_dentry_clear_automount(dentry);
managed_dentry_clear_transit(dentry);
complete_all(&ino->expire_complete);
spin_unlock(&sbi->fs_lock);

Expand All @@ -508,20 +511,18 @@ int autofs4_do_expire_multi(struct super_block *sb, struct vfsmount *mnt,
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);

spin_lock(&sbi->fs_lock);
if (ino->flags & AUTOFS_INF_MOUNTPOINT) {
spin_lock(&sb->s_root->d_lock);
/*
* If we haven't been expired away, then reset
* mounted status.
*/
if (mnt->mnt_parent != mnt)
sb->s_root->d_flags |= DCACHE_MOUNTED;
spin_unlock(&sb->s_root->d_lock);
ino->flags &= ~AUTOFS_INF_MOUNTPOINT;
}
ino->flags &= ~AUTOFS_INF_EXPIRING;
spin_lock(&dentry->d_lock);
if (ret)
managed_dentry_clear_automount(dentry);
__managed_dentry_clear_transit(dentry);
else {
if ((IS_ROOT(dentry) ||
(autofs_type_indirect(sbi->type) &&
IS_ROOT(dentry->d_parent))) &&
!(dentry->d_flags & DCACHE_NEED_AUTOMOUNT))
__managed_dentry_set_automount(dentry);
}
spin_unlock(&dentry->d_lock);
complete_all(&ino->expire_complete);
spin_unlock(&sbi->fs_lock);
dput(dentry);
Expand Down
3 changes: 2 additions & 1 deletion trunk/fs/autofs4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)

static const struct dentry_operations autofs4_sb_dentry_operations = {
.d_automount = autofs4_d_automount,
.d_manage = autofs4_d_manage,
.d_release = autofs4_dentry_release,
};

Expand Down Expand Up @@ -322,7 +323,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
}

if (autofs_type_trigger(sbi->type))
__managed_dentry_set_automount(root);
__managed_dentry_set_managed(root);

root_inode->i_fop = &autofs4_root_operations;
root_inode->i_op = autofs_type_trigger(sbi->type) ?
Expand Down
95 changes: 82 additions & 13 deletions trunk/fs/autofs4/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ static const struct dentry_operations autofs4_root_dentry_operations = {
/* For other dentries */
static const struct dentry_operations autofs4_dentry_operations = {
.d_automount = autofs4_d_automount,
.d_manage = autofs4_d_manage,
.d_release = autofs4_dentry_release,
};

Expand Down Expand Up @@ -604,6 +605,18 @@ struct vfsmount *autofs4_d_automount(struct path *path)
DPRINTK("dentry=%p %.*s",
dentry, dentry->d_name.len, dentry->d_name.name);

/*
* Someone may have manually umounted this or it was a submount
* that has gone away.
*/
spin_lock(&dentry->d_lock);
if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) {
if (!(dentry->d_flags & DCACHE_MANAGE_TRANSIT) &&
(dentry->d_flags & DCACHE_NEED_AUTOMOUNT))
__managed_dentry_set_transit(path->dentry);
}
spin_unlock(&dentry->d_lock);

/* The daemon never triggers a mount. */
if (autofs4_oz_mode(sbi))
return NULL;
Expand Down Expand Up @@ -633,31 +646,63 @@ struct vfsmount *autofs4_d_automount(struct path *path)

/*
* If the dentry is a symlink it's equivalent to a directory
* having d_mounted() true, so there's no need to call back
* having d_mountpoint() true, so there's no need to call back
* to the daemon.
*/
if (dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode))
goto done;
spin_lock(&dentry->d_lock);
if (!d_mountpoint(dentry) && list_empty(&dentry->d_subdirs)) {
if (!d_mountpoint(dentry)) {
/*
* It's possible that user space hasn't removed directories
* after umounting a rootless multi-mount, although it
* should. For v5 have_submounts() is sufficient to handle
* this because the leaves of the directory tree under the
* mount never trigger mounts themselves (they have an autofs
* trigger mount mounted on them). But v4 pseudo direct mounts
* do need the leaves to to trigger mounts. In this case we
* have no choice but to use the list_empty() check and
* require user space behave.
*/
if (sbi->version > 4) {
if (have_submounts(dentry))
goto done;
} else {
spin_lock(&dentry->d_lock);
if (!list_empty(&dentry->d_subdirs)) {
spin_unlock(&dentry->d_lock);
goto done;
}
spin_unlock(&dentry->d_lock);
}
ino->flags |= AUTOFS_INF_PENDING;
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->fs_lock);
status = autofs4_mount_wait(dentry);
if (status)
return ERR_PTR(status);
spin_lock(&sbi->fs_lock);
ino->flags &= ~AUTOFS_INF_PENDING;
goto done;
}
spin_unlock(&dentry->d_lock);
done:
/*
* Any needed mounting has been completed and the path updated
* so turn this into a normal dentry so we don't continually
* call ->d_automount().
*/
managed_dentry_clear_automount(dentry);
if (!(ino->flags & AUTOFS_INF_EXPIRING)) {
/*
* Any needed mounting has been completed and the path updated
* so turn this into a normal dentry so we don't continually
* call ->d_automount() and ->d_manage().
*/
spin_lock(&dentry->d_lock);
__managed_dentry_clear_transit(dentry);
/*
* Only clear DMANAGED_AUTOMOUNT for rootless multi-mounts and
* symlinks as in all other cases the dentry will be covered by
* an actual mount so ->d_automount() won't be called during
* the follow.
*/
if ((!d_mountpoint(dentry) &&
!list_empty(&dentry->d_subdirs)) ||
(dentry->d_inode && S_ISLNK(dentry->d_inode->i_mode)))
__managed_dentry_clear_automount(dentry);
spin_unlock(&dentry->d_lock);
}
spin_unlock(&sbi->fs_lock);

/* Mount succeeded, check if we ended up with a new dentry */
Expand All @@ -668,6 +713,30 @@ struct vfsmount *autofs4_d_automount(struct path *path)
return NULL;
}

int autofs4_d_manage(struct dentry *dentry, bool mounting_here)
{
struct autofs_sb_info *sbi = autofs4_sbi(dentry->d_sb);

DPRINTK("dentry=%p %.*s",
dentry, dentry->d_name.len, dentry->d_name.name);

/* The daemon never waits. */
if (autofs4_oz_mode(sbi) || mounting_here) {
if (!d_mountpoint(dentry))
return -EISDIR;
return 0;
}

/* Wait for pending expires */
do_expire_wait(dentry);

/*
* This dentry may be under construction so wait on mount
* completion.
*/
return autofs4_mount_wait(dentry);
}

/* Lookups in the root directory */
static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
{
Expand Down Expand Up @@ -704,7 +773,7 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
/* Mark entries in the root as mount triggers */
if (autofs_type_indirect(sbi->type) && IS_ROOT(dentry->d_parent)) {
d_set_d_op(dentry, &autofs4_dentry_operations);
managed_dentry_set_automount(dentry);
__managed_dentry_set_managed(dentry);
}

ino = autofs4_init_ino(NULL, sbi, 0555);
Expand Down

0 comments on commit a25b548

Please sign in to comment.