Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6:
  autofs4: clean ->d_release() and autofs4_free_ino() up
  autofs4: split autofs4_init_ino()
  autofs4: mkdir and symlink always get a dentry that had passed lookup
  autofs4: autofs4_get_inode() doesn't need autofs_info * argument anymore
  autofs4: kill ->size in autofs_info
  autofs4: pass mode to autofs4_get_inode() explicitly
  autofs4: autofs4_mkroot() is not different from autofs4_init_ino()
  autofs4: keep symlink body in inode->i_private
  autofs4 - fix debug print in autofs4_lookup()
  vfs - fix dentry ref count in do_lookup()
  autofs4 - fix get_next_positive_dentry()
This commit is contained in:
Linus Torvalds 2011-01-18 07:58:36 -08:00
commit 8dec00059e
6 changed files with 66 additions and 121 deletions

View File

@ -88,14 +88,6 @@ struct autofs_info {
uid_t uid;
gid_t gid;
mode_t mode;
size_t size;
void (*free)(struct autofs_info *);
union {
const char *symlink;
} u;
};
#define AUTOFS_INF_EXPIRING (1<<0) /* dentry is in the process of expiring */
@ -175,7 +167,7 @@ static inline int autofs4_ispending(struct dentry *dentry)
return 0;
}
struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *);
struct inode *autofs4_get_inode(struct super_block *, mode_t);
void autofs4_free_ino(struct autofs_info *);
/* Expiration */
@ -285,7 +277,8 @@ static inline void managed_dentry_clear_managed(struct dentry *dentry)
/* Initializing function */
int autofs4_fill_super(struct super_block *, void *, int);
struct autofs_info *autofs4_init_ino(struct autofs_info *, struct autofs_sb_info *sbi, mode_t mode);
struct autofs_info *autofs4_new_ino(struct autofs_sb_info *);
void autofs4_clean_ino(struct autofs_info *);
/* Queue management functions */
@ -345,5 +338,4 @@ static inline void autofs4_del_expiring(struct dentry *dentry)
return;
}
void autofs4_dentry_release(struct dentry *);
extern void autofs4_kill_sb(struct super_block *);

View File

@ -96,7 +96,7 @@ static struct dentry *get_next_positive_dentry(struct dentry *prev,
struct dentry *p, *ret;
if (prev == NULL)
return dget(prev);
return dget(root);
spin_lock(&autofs4_lock);
relock:
@ -133,7 +133,7 @@ again:
spin_lock_nested(&ret->d_lock, DENTRY_D_LOCK_NESTED);
/* Negative dentry - try next */
if (!simple_positive(ret)) {
spin_unlock(&ret->d_lock);
spin_unlock(&p->d_lock);
p = ret;
goto again;
}

View File

@ -22,65 +22,27 @@
#include "autofs_i.h"
#include <linux/module.h>
static void ino_lnkfree(struct autofs_info *ino)
struct autofs_info *autofs4_new_ino(struct autofs_sb_info *sbi)
{
if (ino->u.symlink) {
kfree(ino->u.symlink);
ino->u.symlink = NULL;
struct autofs_info *ino = kzalloc(sizeof(*ino), GFP_KERNEL);
if (ino) {
INIT_LIST_HEAD(&ino->active);
INIT_LIST_HEAD(&ino->expiring);
ino->last_used = jiffies;
ino->sbi = sbi;
}
return ino;
}
struct autofs_info *autofs4_init_ino(struct autofs_info *ino,
struct autofs_sb_info *sbi, mode_t mode)
void autofs4_clean_ino(struct autofs_info *ino)
{
int reinit = 1;
if (ino == NULL) {
reinit = 0;
ino = kmalloc(sizeof(*ino), GFP_KERNEL);
}
if (ino == NULL)
return NULL;
if (!reinit) {
ino->flags = 0;
ino->dentry = NULL;
ino->size = 0;
INIT_LIST_HEAD(&ino->active);
ino->active_count = 0;
INIT_LIST_HEAD(&ino->expiring);
atomic_set(&ino->count, 0);
}
ino->uid = 0;
ino->gid = 0;
ino->mode = mode;
ino->last_used = jiffies;
ino->sbi = sbi;
if (reinit && ino->free)
(ino->free)(ino);
memset(&ino->u, 0, sizeof(ino->u));
ino->free = NULL;
if (S_ISLNK(mode))
ino->free = ino_lnkfree;
return ino;
}
void autofs4_free_ino(struct autofs_info *ino)
{
if (ino->dentry) {
ino->dentry->d_fsdata = NULL;
ino->dentry = NULL;
}
if (ino->free)
(ino->free)(ino);
kfree(ino);
}
@ -136,9 +98,16 @@ static int autofs4_show_options(struct seq_file *m, struct vfsmount *mnt)
return 0;
}
static void autofs4_evict_inode(struct inode *inode)
{
end_writeback(inode);
kfree(inode->i_private);
}
static const struct super_operations autofs4_sops = {
.statfs = simple_statfs,
.show_options = autofs4_show_options,
.evict_inode = autofs4_evict_inode,
};
enum {Opt_err, Opt_fd, Opt_uid, Opt_gid, Opt_pgrp, Opt_minproto, Opt_maxproto,
@ -228,17 +197,6 @@ static int parse_options(char *options, int *pipefd, uid_t *uid, gid_t *gid,
return (*pipefd < 0);
}
static struct autofs_info *autofs4_mkroot(struct autofs_sb_info *sbi)
{
struct autofs_info *ino;
ino = autofs4_init_ino(NULL, sbi, S_IFDIR | 0755);
if (!ino)
return NULL;
return ino;
}
int autofs4_fill_super(struct super_block *s, void *data, int silent)
{
struct inode * root_inode;
@ -282,10 +240,10 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
/*
* Get the root inode and dentry, but defer checking for errors.
*/
ino = autofs4_mkroot(sbi);
ino = autofs4_new_ino(sbi);
if (!ino)
goto fail_free;
root_inode = autofs4_get_inode(s, ino);
root_inode = autofs4_get_inode(s, S_IFDIR | 0755);
if (!root_inode)
goto fail_ino;
@ -368,15 +326,14 @@ fail_unlock:
return -EINVAL;
}
struct inode *autofs4_get_inode(struct super_block *sb,
struct autofs_info *inf)
struct inode *autofs4_get_inode(struct super_block *sb, mode_t mode)
{
struct inode *inode = new_inode(sb);
if (inode == NULL)
return NULL;
inode->i_mode = inf->mode;
inode->i_mode = mode;
if (sb->s_root) {
inode->i_uid = sb->s_root->d_inode->i_uid;
inode->i_gid = sb->s_root->d_inode->i_gid;
@ -384,12 +341,11 @@ struct inode *autofs4_get_inode(struct super_block *sb,
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
inode->i_ino = get_next_ino();
if (S_ISDIR(inf->mode)) {
if (S_ISDIR(mode)) {
inode->i_nlink = 2;
inode->i_op = &autofs4_dir_inode_operations;
inode->i_fop = &autofs4_dir_operations;
} else if (S_ISLNK(inf->mode)) {
inode->i_size = inf->size;
} else if (S_ISLNK(mode)) {
inode->i_op = &autofs4_symlink_inode_operations;
}

View File

@ -37,6 +37,7 @@ static int autofs4_dir_open(struct inode *inode, struct file *file);
static struct dentry *autofs4_lookup(struct inode *,struct dentry *, struct nameidata *);
static struct vfsmount *autofs4_d_automount(struct path *);
static int autofs4_d_manage(struct dentry *, bool, bool);
static void autofs4_dentry_release(struct dentry *);
const struct file_operations autofs4_root_operations = {
.open = dcache_dir_open,
@ -138,25 +139,26 @@ out:
return dcache_dir_open(inode, file);
}
void autofs4_dentry_release(struct dentry *de)
static void autofs4_dentry_release(struct dentry *de)
{
struct autofs_info *inf;
struct autofs_info *ino = autofs4_dentry_ino(de);
struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
DPRINTK("releasing %p", de);
inf = autofs4_dentry_ino(de);
if (inf) {
struct autofs_sb_info *sbi = autofs4_sbi(de->d_sb);
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);
}
autofs4_free_ino(inf);
if (!ino)
return;
if (sbi) {
spin_lock(&sbi->lookup_lock);
if (!list_empty(&ino->active))
list_del(&ino->active);
if (!list_empty(&ino->expiring))
list_del(&ino->expiring);
spin_unlock(&sbi->lookup_lock);
}
autofs4_free_ino(ino);
}
static struct dentry *autofs4_lookup_active(struct dentry *dentry)
@ -488,7 +490,8 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
sbi = autofs4_sbi(dir->i_sb);
DPRINTK("pid = %u, pgrp = %u, catatonic = %d, oz_mode = %d",
current->pid, task_pgrp_nr(current), sbi->catatonic, oz_mode);
current->pid, task_pgrp_nr(current), sbi->catatonic,
autofs4_oz_mode(sbi));
active = autofs4_lookup_active(dentry);
if (active) {
@ -507,7 +510,7 @@ static struct dentry *autofs4_lookup(struct inode *dir, struct dentry *dentry, s
if (autofs_type_indirect(sbi->type) && IS_ROOT(dentry->d_parent))
__managed_dentry_set_managed(dentry);
ino = autofs4_init_ino(NULL, sbi, 0555);
ino = autofs4_new_ino(sbi);
if (!ino)
return ERR_PTR(-ENOMEM);
@ -529,6 +532,7 @@ static int autofs4_dir_symlink(struct inode *dir,
struct autofs_info *ino = autofs4_dentry_ino(dentry);
struct autofs_info *p_ino;
struct inode *inode;
size_t size = strlen(symname);
char *cp;
DPRINTK("%s <- %.*s", symname,
@ -537,39 +541,35 @@ static int autofs4_dir_symlink(struct inode *dir,
if (!autofs4_oz_mode(sbi))
return -EACCES;
ino = autofs4_init_ino(ino, sbi, S_IFLNK | 0555);
if (!ino)
return -ENOMEM;
BUG_ON(!ino);
autofs4_clean_ino(ino);
autofs4_del_active(dentry);
ino->size = strlen(symname);
cp = kmalloc(ino->size + 1, GFP_KERNEL);
if (!cp) {
if (!dentry->d_fsdata)
kfree(ino);
cp = kmalloc(size + 1, GFP_KERNEL);
if (!cp)
return -ENOMEM;
}
strcpy(cp, symname);
inode = autofs4_get_inode(dir->i_sb, ino);
inode = autofs4_get_inode(dir->i_sb, S_IFLNK | 0555);
if (!inode) {
kfree(cp);
if (!dentry->d_fsdata)
kfree(ino);
return -ENOMEM;
}
inode->i_private = cp;
inode->i_size = size;
d_add(dentry, inode);
dentry->d_fsdata = ino;
ino->dentry = dget(dentry);
dget(dentry);
atomic_inc(&ino->count);
p_ino = autofs4_dentry_ino(dentry->d_parent);
if (p_ino && dentry->d_parent != dentry)
atomic_inc(&p_ino->count);
ino->u.symlink = cp;
dir->i_mtime = CURRENT_TIME;
return 0;
@ -732,25 +732,21 @@ static int autofs4_dir_mkdir(struct inode *dir, struct dentry *dentry, int mode)
DPRINTK("dentry %p, creating %.*s",
dentry, dentry->d_name.len, dentry->d_name.name);
ino = autofs4_init_ino(ino, sbi, S_IFDIR | 0555);
if (!ino)
return -ENOMEM;
BUG_ON(!ino);
autofs4_clean_ino(ino);
autofs4_del_active(dentry);
inode = autofs4_get_inode(dir->i_sb, ino);
if (!inode) {
if (!dentry->d_fsdata)
kfree(ino);
inode = autofs4_get_inode(dir->i_sb, S_IFDIR | 0555);
if (!inode)
return -ENOMEM;
}
d_add(dentry, inode);
if (sbi->version < 5)
autofs_set_leaf_automount_flags(dentry);
dentry->d_fsdata = ino;
ino->dentry = dget(dentry);
dget(dentry);
atomic_inc(&ino->count);
p_ino = autofs4_dentry_ino(dentry->d_parent);
if (p_ino && dentry->d_parent != dentry)

View File

@ -14,8 +14,7 @@
static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
{
struct autofs_info *ino = autofs4_dentry_ino(dentry);
nd_set_link(nd, (char *)ino->u.symlink);
nd_set_link(nd, dentry->d_inode->i_private);
return NULL;
}

View File

@ -1272,8 +1272,10 @@ done:
path->mnt = mnt;
path->dentry = dentry;
err = follow_managed(path, nd->flags);
if (unlikely(err < 0))
if (unlikely(err < 0)) {
path_put_conditional(path, nd);
return err;
}
*inode = path->dentry->d_inode;
return 0;