Commit 7d1f193d authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] autofs4: readdir fixes

From: Ian Kent <raven@themaw.net>

a. Implement readdir and friends for directory lookup for late mounting.
   This is done largely by replacing a catch all condition in
   try_to_fill_dentry with appropriate cases.

b. Add path calc.  function in waitq.c to get extended path to return to
   daemon (for direct mounts).

c. Add revalidate calls to sys_chdir and sys_chroot so that pwd lookups
   work correctly.

d. Add ioctl to retrieve minor version for automount daemon (and me) to
   recognise module fix level.  Bumped minor version to 5.

From: Hugh Dickins <hugh@veritas.com>

  After chdir (or chroot) to non-existent directory on 2.6.5-mm5, you can no
  longer unmount filesystem holding working directory (or root).
parent 8b22c0c5
......@@ -95,6 +95,7 @@ struct autofs_sb_info {
pid_t oz_pgrp;
int catatonic;
int version;
int sub_version;
unsigned long exp_timeout;
struct super_block *sb;
struct autofs_wait_queue *queues; /* Wait queue pointer */
......@@ -127,6 +128,12 @@ static inline int autofs4_ispending(struct dentry *dentry)
(inf != NULL && inf->flags & AUTOFS_INF_EXPIRING);
}
static inline void autofs4_copy_atime(struct file *src, struct file *dst)
{
dst->f_dentry->d_inode->i_atime = src->f_dentry->d_inode->i_atime;
return;
}
struct inode *autofs4_get_inode(struct super_block *, struct autofs_info *);
struct autofs_info *autofs4_init_inf(struct autofs_sb_info *, mode_t mode);
void autofs4_free_ino(struct autofs_info *);
......@@ -143,6 +150,7 @@ int autofs4_expire_multi(struct super_block *, struct vfsmount *,
extern struct inode_operations autofs4_symlink_inode_operations;
extern struct inode_operations autofs4_dir_inode_operations;
extern struct inode_operations autofs4_root_inode_operations;
extern struct file_operations autofs4_dir_operations;
extern struct file_operations autofs4_root_operations;
/* Initializing function */
......@@ -159,7 +167,7 @@ enum autofs_notify
NFY_EXPIRE
};
int autofs4_wait(struct autofs_sb_info *,struct qstr *, enum autofs_notify);
int autofs4_wait(struct autofs_sb_info *,struct dentry *, enum autofs_notify);
int autofs4_wait_release(struct autofs_sb_info *,autofs_wqt_t,int);
void autofs4_catatonic_mode(struct autofs_sb_info *);
......
......@@ -348,7 +348,7 @@ int autofs4_expire_multi(struct super_block *sb, struct vfsmount *mnt,
/* This is synchronous because it makes the daemon a
little easier */
de_info->flags |= AUTOFS_INF_EXPIRING;
ret = autofs4_wait(sbi, &dentry->d_name, NFY_EXPIRE);
ret = autofs4_wait(sbi, dentry, NFY_EXPIRE);
de_info->flags &= ~AUTOFS_INF_EXPIRING;
dput(dentry);
}
......
......@@ -312,7 +312,7 @@ struct inode *autofs4_get_inode(struct super_block *sb,
if (S_ISDIR(inf->mode)) {
inode->i_nlink = 2;
inode->i_op = &autofs4_dir_inode_operations;
inode->i_fop = &simple_dir_operations;
inode->i_fop = &autofs4_dir_operations;
} else if (S_ISLNK(inf->mode)) {
inode->i_size = inf->size;
inode->i_op = &autofs4_symlink_inode_operations;
......
This diff is collapsed.
......@@ -3,6 +3,7 @@
* linux/fs/autofs/waitq.c
*
* Copyright 1997-1998 Transmeta Corporation -- All Rights Reserved
* Copyright 2001-2003 Ian Kent <raven@themaw.net>
*
* This file is part of the Linux kernel and is made available under
* the terms of the GNU General Public License, version 2, or at your
......@@ -126,25 +127,64 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
autofs4_catatonic_mode(sbi);
}
int autofs4_wait(struct autofs_sb_info *sbi, struct qstr *name,
static int autofs4_getpath(struct autofs_sb_info *sbi,
struct dentry *dentry, char **name)
{
struct dentry *root = sbi->sb->s_root;
struct dentry *tmp;
char *buf = *name;
char *p;
int len = 0;
spin_lock(&dcache_lock);
for (tmp = dentry ; tmp != root ; tmp = tmp->d_parent)
len += tmp->d_name.len + 1;
if (--len > NAME_MAX) {
spin_unlock(&dcache_lock);
return 0;
}
*(buf + len) = '\0';
p = buf + len - dentry->d_name.len;
strncpy(p, dentry->d_name.name, dentry->d_name.len);
for (tmp = dentry->d_parent; tmp != root ; tmp = tmp->d_parent) {
*(--p) = '/';
p -= tmp->d_name.len;
strncpy(p, tmp->d_name.name, tmp->d_name.len);
}
spin_unlock(&dcache_lock);
return len;
}
int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
enum autofs_notify notify)
{
struct autofs_wait_queue *wq;
int status;
char *name;
int len, status;
/* In catatonic mode, we don't wait for nobody */
if ( sbi->catatonic )
return -ENOENT;
/* We shouldn't be able to get here, but just in case */
if ( name->len > NAME_MAX )
name = kmalloc(NAME_MAX + 1, GFP_KERNEL);
if (!name)
return -ENOMEM;
len = autofs4_getpath(sbi, dentry, &name);
if (!len) {
kfree(name);
return -ENOENT;
}
spin_lock(&waitq_lock);
for ( wq = sbi->queues ; wq ; wq = wq->next ) {
if ( wq->hash == name->hash &&
wq->len == name->len &&
wq->name && !memcmp(wq->name,name->name,name->len) )
for (wq = sbi->queues ; wq ; wq = wq->next) {
if (wq->hash == dentry->d_name.hash &&
wq->len == len &&
wq->name && !memcmp(wq->name, name, len))
break;
}
spin_unlock(&waitq_lock);
......@@ -152,12 +192,8 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct qstr *name,
if ( !wq ) {
/* Create a new wait queue */
wq = kmalloc(sizeof(struct autofs_wait_queue),GFP_KERNEL);
if ( !wq )
return -ENOMEM;
wq->name = kmalloc(name->len,GFP_KERNEL);
if ( !wq->name ) {
kfree(wq);
if ( !wq ) {
kfree(name);
return -ENOMEM;
}
......@@ -169,10 +205,10 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct qstr *name,
sbi->queues = wq;
spin_unlock(&waitq_lock);
init_waitqueue_head(&wq->queue);
wq->hash = name->hash;
wq->len = name->len;
wq->hash = dentry->d_name.hash;
wq->name = name;
wq->len = len;
wq->status = -EINTR; /* Status return if interrupted */
memcpy(wq->name, name->name, name->len);
DPRINTK(("autofs4_wait: new wait id = 0x%08lx, name = %.*s, nfy=%d\n",
(unsigned long) wq->wait_queue_token, wq->len, wq->name, notify));
......
......@@ -517,18 +517,43 @@ asmlinkage long sys_chdir(const char __user * filename)
{
struct nameidata nd;
int error;
struct vfsmount *old_mnt;
struct dentry *old_dentry;
error = __user_walk(filename, LOOKUP_FOLLOW|LOOKUP_DIRECTORY, &nd);
if (error)
goto out;
old_mnt = mntget(current->fs->pwdmnt);
old_dentry = dget(current->fs->pwd);
error = permission(nd.dentry->d_inode,MAY_EXEC,&nd);
if (error)
goto dput_and_out;
set_fs_pwd(current->fs, nd.mnt, nd.dentry);
/*
* if we chdir to an autofs4 mount point we must get in early
* for subsequent path_walks to work properly.
*/
if (nd.dentry->d_op && nd.dentry->d_op->d_revalidate) {
int res;
res = nd.dentry->d_op->d_revalidate(nd.dentry, &nd);
if (res) {
error = permission(current->fs->pwd->d_inode, MAY_EXEC, &nd);
if (!error)
goto dput_and_out;
} else
error = -ENOENT;
set_fs_pwd(current->fs, old_mnt, old_dentry);
}
dput_and_out:
mntput(old_mnt);
dput(old_dentry);
path_release(&nd);
out:
return error;
......@@ -568,11 +593,16 @@ asmlinkage long sys_chroot(const char __user * filename)
{
struct nameidata nd;
int error;
struct vfsmount *old_mnt;
struct dentry *old_dentry;
error = __user_walk(filename, LOOKUP_FOLLOW | LOOKUP_DIRECTORY | LOOKUP_NOALT, &nd);
if (error)
goto out;
old_mnt = mntget(current->fs->pwdmnt);
old_dentry = dget(current->fs->pwd);
error = permission(nd.dentry->d_inode,MAY_EXEC,&nd);
if (error)
goto dput_and_out;
......@@ -582,9 +612,31 @@ asmlinkage long sys_chroot(const char __user * filename)
goto dput_and_out;
set_fs_root(current->fs, nd.mnt, nd.dentry);
/*
* if we chroot to an autofs4 mount point we must get in early
* for subsequent path_walks to work properly.
*/
if (nd.dentry->d_op && nd.dentry->d_op->d_revalidate) {
int res;
res = nd.dentry->d_op->d_revalidate(nd.dentry, &nd);
if (res) {
error = permission(current->fs->pwd->d_inode, MAY_EXEC, &nd);
if (!error)
goto valid;
} else
error = -ENOENT;
set_fs_root(current->fs, old_mnt, old_dentry);
goto dput_and_out;
}
valid:
set_fs_altroot();
error = 0;
dput_and_out:
mntput(old_mnt);
dput(old_dentry);
path_release(&nd);
out:
return error;
......
......@@ -23,6 +23,8 @@
#define AUTOFS_MIN_PROTO_VERSION 3
#define AUTOFS_MAX_PROTO_VERSION 4
#define AUTOFS_PROTO_SUBVERSION 5
/* Mask for expire behaviour */
#define AUTOFS_EXP_IMMEDIATE 1
#define AUTOFS_EXP_LEAVES 2
......@@ -46,6 +48,7 @@ union autofs_packet_union {
};
#define AUTOFS_IOC_EXPIRE_MULTI _IOW(0x93,0x66,int)
#define AUTOFS_IOC_PROTOSUBVER _IOR(0x93,0x67,int)
#endif /* _LINUX_AUTO_FS4_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment