Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 105457
b: refs/heads/master
c: 2576737
h: refs/heads/master
i:
  105455: 42df4ee
v: v3
  • Loading branch information
Ian Kent authored and Linus Torvalds committed Jul 24, 2008
1 parent 48f4ce2 commit 2f6b3c6
Show file tree
Hide file tree
Showing 4 changed files with 157 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: caf7da3d5d4d9dd873eb52d025d8cc63b89f1fdb
refs/heads/master: 2576737873dc1d9ea461a5955a5f6779b569a350
2 changes: 2 additions & 0 deletions trunk/fs/autofs4/autofs_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct autofs_info {

int flags;

struct list_head active;
struct list_head expiring;

struct autofs_sb_info *sbi;
Expand Down Expand Up @@ -113,6 +114,7 @@ struct autofs_sb_info {
spinlock_t fs_lock;
struct autofs_wait_queue *queues; /* Wait queue pointer */
spinlock_t lookup_lock;
struct list_head active_list;
struct list_head expiring_list;
};

Expand Down
25 changes: 15 additions & 10 deletions trunk/fs/autofs4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@

static void ino_lnkfree(struct autofs_info *ino)
{
kfree(ino->u.symlink);
ino->u.symlink = NULL;
if (ino->u.symlink) {
kfree(ino->u.symlink);
ino->u.symlink = NULL;
}
}

struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
Expand All @@ -41,16 +43,18 @@ struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
if (ino == NULL)
return NULL;

ino->flags = 0;
ino->mode = mode;
ino->inode = NULL;
ino->dentry = NULL;
ino->size = 0;

INIT_LIST_HEAD(&ino->expiring);
if (!reinit) {
ino->flags = 0;
ino->inode = NULL;
ino->dentry = NULL;
ino->size = 0;
INIT_LIST_HEAD(&ino->active);
INIT_LIST_HEAD(&ino->expiring);
atomic_set(&ino->count, 0);
}

ino->mode = mode;
ino->last_used = jiffies;
atomic_set(&ino->count, 0);

ino->sbi = sbi;

Expand Down Expand Up @@ -339,6 +343,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
spin_lock_init(&sbi->fs_lock);
sbi->queues = NULL;
spin_lock_init(&sbi->lookup_lock);
INIT_LIST_HEAD(&sbi->active_list);
INIT_LIST_HEAD(&sbi->expiring_list);
s->s_blocksize = 1024;
s->s_blocksize_bits = 10;
Expand Down
169 changes: 139 additions & 30 deletions trunk/fs/autofs4/root.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ void autofs4_dentry_release(struct dentry *de)

if (sbi) {
spin_lock(&sbi->lookup_lock);
if (!list_empty(&inf->active))
list_del(&inf->active);
if (!list_empty(&inf->expiring))
list_del(&inf->expiring);
spin_unlock(&sbi->lookup_lock);
Expand All @@ -497,6 +499,58 @@ static struct dentry_operations autofs4_dentry_operations = {
.d_release = autofs4_dentry_release,
};

static struct dentry *autofs4_lookup_active(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
{
unsigned int len = name->len;
unsigned int hash = name->hash;
const unsigned char *str = name->name;
struct list_head *p, *head;

spin_lock(&dcache_lock);
spin_lock(&sbi->lookup_lock);
head = &sbi->active_list;
list_for_each(p, head) {
struct autofs_info *ino;
struct dentry *dentry;
struct qstr *qstr;

ino = list_entry(p, struct autofs_info, active);
dentry = ino->dentry;

spin_lock(&dentry->d_lock);

/* Already gone? */
if (atomic_read(&dentry->d_count) == 0)
goto next;

qstr = &dentry->d_name;

if (dentry->d_name.hash != hash)
goto next;
if (dentry->d_parent != parent)
goto next;

if (qstr->len != len)
goto next;
if (memcmp(qstr->name, str, len))
goto next;

if (d_unhashed(dentry)) {
dget(dentry);
spin_unlock(&dentry->d_lock);
spin_unlock(&sbi->lookup_lock);
spin_unlock(&dcache_lock);
return dentry;
}
next:
spin_unlock(&dentry->d_lock);
}
spin_unlock(&sbi->lookup_lock);
spin_unlock(&dcache_lock);

return NULL;
}

static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct dentry *parent, struct qstr *name)
{
unsigned int len = name->len;
Expand Down Expand Up @@ -553,7 +607,8 @@ static struct dentry *autofs4_lookup_expiring(struct autofs_sb_info *sbi, struct
static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
{
struct autofs_sb_info *sbi;
struct dentry *expiring;
struct autofs_info *ino;
struct dentry *expiring, *unhashed;
int oz_mode;

DPRINTK("name = %.*s",
Expand All @@ -571,12 +626,12 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s

expiring = autofs4_lookup_expiring(sbi, dentry->d_parent, &dentry->d_name);
if (expiring) {
struct autofs_info *ino = autofs4_dentry_ino(expiring);
/*
* If we are racing with expire the request might not
* be quite complete but the directory has been removed
* so it must have been successful, so just wait for it.
*/
ino = autofs4_dentry_ino(expiring);
while (ino && (ino->flags & AUTOFS_INF_EXPIRING)) {
DPRINTK("wait for incomplete expire %p name=%.*s",
expiring, expiring->d_name.len,
Expand All @@ -591,21 +646,41 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
dput(expiring);
}

/*
* Mark the dentry incomplete but don't hash it. We do this
* to serialize our inode creation operations (symlink and
* mkdir) which prevents deadlock during the callback to
* the daemon. Subsequent user space lookups for the same
* dentry are placed on the wait queue while the daemon
* itself is allowed passage unresticted so the create
* operation itself can then hash the dentry. Finally,
* we check for the hashed dentry and return the newly
* hashed dentry.
*/
dentry->d_op = &autofs4_root_dentry_operations;
unhashed = autofs4_lookup_active(sbi, dentry->d_parent, &dentry->d_name);
if (unhashed)
dentry = unhashed;
else {
/*
* Mark the dentry incomplete but don't hash it. We do this
* to serialize our inode creation operations (symlink and
* mkdir) which prevents deadlock during the callback to
* the daemon. Subsequent user space lookups for the same
* dentry are placed on the wait queue while the daemon
* itself is allowed passage unresticted so the create
* operation itself can then hash the dentry. Finally,
* we check for the hashed dentry and return the newly
* hashed dentry.
*/
dentry->d_op = &autofs4_root_dentry_operations;

/*
* And we need to ensure that the same dentry is used for
* all following lookup calls until it is hashed so that
* the dentry flags are persistent throughout the request.
*/
ino = autofs4_init_ino(NULL, sbi, 0555);
if (!ino)
return ERR_PTR(-ENOMEM);

dentry->d_fsdata = ino;
ino->dentry = dentry;

spin_lock(&sbi->lookup_lock);
list_add(&ino->active, &sbi->active_list);
spin_unlock(&sbi->lookup_lock);

dentry->d_fsdata = NULL;
d_instantiate(dentry, NULL);
d_instantiate(dentry, NULL);
}

if (!oz_mode) {
spin_lock(&dentry->d_lock);
Expand All @@ -630,12 +705,16 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
if (sigismember (sigset, SIGKILL) ||
sigismember (sigset, SIGQUIT) ||
sigismember (sigset, SIGINT)) {
if (unhashed)
dput(unhashed);
return ERR_PTR(-ERESTARTNOINTR);
}
}
spin_lock(&dentry->d_lock);
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
spin_unlock(&dentry->d_lock);
if (!oz_mode) {
spin_lock(&dentry->d_lock);
dentry->d_flags &= ~DCACHE_AUTOFS_PENDING;
spin_unlock(&dentry->d_lock);
}
}

/*
Expand All @@ -659,9 +738,15 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
else
dentry = ERR_PTR(-ENOENT);

if (unhashed)
dput(unhashed);

return dentry;
}

if (unhashed)
return unhashed;

return NULL;
}

Expand All @@ -682,20 +767,30 @@ static int autofs4_dir_symlink(struct inode *dir,
return -EACCES;

ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
if (ino == NULL)
return -ENOSPC;
if (!ino)
return -ENOMEM;

ino->size = strlen(symname);
ino->u.symlink = cp = kmalloc(ino->size + 1, GFP_KERNEL);
spin_lock(&sbi->lookup_lock);
if (!list_empty(&ino->active))
list_del_init(&ino->active);
spin_unlock(&sbi->lookup_lock);

if (cp == NULL) {
kfree(ino);
return -ENOSPC;
cp = kmalloc(ino->size + 1, GFP_KERNEL);
if (!cp) {
if (!dentry->d_fsdata)
kfree(ino);
return -ENOMEM;
}

strcpy(cp, symname);

inode = autofs4_get_inode(dir->i_sb, ino);
if (!inode) {
kfree(cp);
if (!dentry->d_fsdata)
kfree(ino);
return -ENOMEM;
}
d_add(dentry, inode);

if (dir == dir->i_sb->s_root->d_inode)
Expand All @@ -711,6 +806,8 @@ static int autofs4_dir_symlink(struct inode *dir,
atomic_inc(&p_ino->count);
ino->inode = inode;

ino->size = strlen(symname);
ino->u.symlink = cp;
dir->i_mtime = CURRENT_TIME;

return 0;
Expand Down Expand Up @@ -755,7 +852,8 @@ static int autofs4_dir_unlink(struct inode *dir, struct dentry *dentry)

spin_lock(&dcache_lock);
spin_lock(&sbi->lookup_lock);
list_add(&ino->expiring, &sbi->expiring_list);
if (list_empty(&ino->expiring))
list_add(&ino->expiring, &sbi->expiring_list);
spin_unlock(&sbi->lookup_lock);
spin_lock(&dentry->d_lock);
__d_drop(dentry);
Expand Down Expand Up @@ -783,7 +881,8 @@ static int autofs4_dir_rmdir(struct inode *dir, struct dentry *dentry)
return -ENOTEMPTY;
}
spin_lock(&sbi->lookup_lock);
list_add(&ino->expiring, &sbi->expiring_list);
if (list_empty(&ino->expiring))
list_add(&ino->expiring, &sbi->expiring_list);
spin_unlock(&sbi->lookup_lock);
spin_lock(&dentry->d_lock);
__d_drop(dentry);
Expand Down Expand Up @@ -819,10 +918,20 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
dentry, dentry->d_name.len, dentry->d_name.name);

ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
if (ino == NULL)
return -ENOSPC;
if (!ino)
return -ENOMEM;

spin_lock(&sbi->lookup_lock);
if (!list_empty(&ino->active))
list_del_init(&ino->active);
spin_unlock(&sbi->lookup_lock);

inode = autofs4_get_inode(dir->i_sb, ino);
if (!inode) {
if (!dentry->d_fsdata)
kfree(ino);
return -ENOMEM;
}
d_add(dentry, inode);

if (dir == dir->i_sb->s_root->d_inode)
Expand Down

0 comments on commit 2f6b3c6

Please sign in to comment.