Skip to content

Commit

Permalink
[PATCH] switch nfsd to kern_path()
Browse files Browse the repository at this point in the history
Signed-off-by: Al Viro <[email protected]>
  • Loading branch information
Al Viro committed Oct 23, 2008
1 parent c1a2a47 commit a63bb99
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 58 deletions.
48 changes: 23 additions & 25 deletions fs/nfsd/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,18 @@ static int expkey_parse(struct cache_detail *cd, char *mesg, int mlen)
cache_put(&ek->h, &svc_expkey_cache);
else err = -ENOMEM;
} else {
struct nameidata nd;
err = path_lookup(buf, 0, &nd);
err = kern_path(buf, 0, &key.ek_path);
if (err)
goto out;

dprintk("Found the path %s\n", buf);
key.ek_path = nd.path;

ek = svc_expkey_update(&key, ek);
if (ek)
cache_put(&ek->h, &svc_expkey_cache);
else
err = -ENOMEM;
path_put(&nd.path);
path_put(&key.ek_path);
}
cache_flush();
out:
Expand Down Expand Up @@ -991,7 +989,7 @@ exp_export(struct nfsctl_export *nxp)
struct svc_export *exp = NULL;
struct svc_export new;
struct svc_expkey *fsid_key = NULL;
struct nameidata nd;
struct path path;
int err;

/* Consistency check */
Expand All @@ -1014,21 +1012,21 @@ exp_export(struct nfsctl_export *nxp)


/* Look up the dentry */
err = path_lookup(nxp->ex_path, 0, &nd);
err = kern_path(nxp->ex_path, 0, &path);
if (err)
goto out_put_clp;
err = -EINVAL;

exp = exp_get_by_name(clp, nd.path.mnt, nd.path.dentry, NULL);
exp = exp_get_by_name(clp, path.mnt, path.dentry, NULL);

memset(&new, 0, sizeof(new));

/* must make sure there won't be an ex_fsid clash */
if ((nxp->ex_flags & NFSEXP_FSID) &&
(!IS_ERR(fsid_key = exp_get_fsid_key(clp, nxp->ex_dev))) &&
fsid_key->ek_path.mnt &&
(fsid_key->ek_path.mnt != nd.path.mnt ||
fsid_key->ek_path.dentry != nd.path.dentry))
(fsid_key->ek_path.mnt != path.mnt ||
fsid_key->ek_path.dentry != path.dentry))
goto finish;

if (!IS_ERR(exp)) {
Expand All @@ -1044,7 +1042,7 @@ exp_export(struct nfsctl_export *nxp)
goto finish;
}

err = check_export(nd.path.dentry->d_inode, nxp->ex_flags, NULL);
err = check_export(path.dentry->d_inode, nxp->ex_flags, NULL);
if (err) goto finish;

err = -ENOMEM;
Expand All @@ -1057,7 +1055,7 @@ exp_export(struct nfsctl_export *nxp)
if (!new.ex_pathname)
goto finish;
new.ex_client = clp;
new.ex_path = nd.path;
new.ex_path = path;
new.ex_flags = nxp->ex_flags;
new.ex_anon_uid = nxp->ex_anon_uid;
new.ex_anon_gid = nxp->ex_anon_gid;
Expand All @@ -1083,7 +1081,7 @@ exp_export(struct nfsctl_export *nxp)
exp_put(exp);
if (fsid_key && !IS_ERR(fsid_key))
cache_put(&fsid_key->h, &svc_expkey_cache);
path_put(&nd.path);
path_put(&path);
out_put_clp:
auth_domain_put(clp);
out_unlock:
Expand Down Expand Up @@ -1114,7 +1112,7 @@ exp_unexport(struct nfsctl_export *nxp)
{
struct auth_domain *dom;
svc_export *exp;
struct nameidata nd;
struct path path;
int err;

/* Consistency check */
Expand All @@ -1131,13 +1129,13 @@ exp_unexport(struct nfsctl_export *nxp)
goto out_unlock;
}

err = path_lookup(nxp->ex_path, 0, &nd);
err = kern_path(nxp->ex_path, 0, &path);
if (err)
goto out_domain;

err = -EINVAL;
exp = exp_get_by_name(dom, nd.path.mnt, nd.path.dentry, NULL);
path_put(&nd.path);
exp = exp_get_by_name(dom, path.mnt, path.dentry, NULL);
path_put(&path);
if (IS_ERR(exp))
goto out_domain;

Expand All @@ -1159,26 +1157,26 @@ exp_unexport(struct nfsctl_export *nxp)
* since its harder to fool a kernel module than a user space program.
*/
int
exp_rootfh(svc_client *clp, char *path, struct knfsd_fh *f, int maxsize)
exp_rootfh(svc_client *clp, char *name, struct knfsd_fh *f, int maxsize)
{
struct svc_export *exp;
struct nameidata nd;
struct path path;
struct inode *inode;
struct svc_fh fh;
int err;

err = -EPERM;
/* NB: we probably ought to check that it's NUL-terminated */
if (path_lookup(path, 0, &nd)) {
printk("nfsd: exp_rootfh path not found %s", path);
if (kern_path(name, 0, &path)) {
printk("nfsd: exp_rootfh path not found %s", name);
return err;
}
inode = nd.path.dentry->d_inode;
inode = path.dentry->d_inode;

dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
path, nd.path.dentry, clp->name,
name, path.dentry, clp->name,
inode->i_sb->s_id, inode->i_ino);
exp = exp_parent(clp, nd.path.mnt, nd.path.dentry, NULL);
exp = exp_parent(clp, path.mnt, path.dentry, NULL);
if (IS_ERR(exp)) {
err = PTR_ERR(exp);
goto out;
Expand All @@ -1188,15 +1186,15 @@ exp_rootfh(svc_client *clp, char *path, struct knfsd_fh *f, int maxsize)
* fh must be initialized before calling fh_compose
*/
fh_init(&fh, maxsize);
if (fh_compose(&fh, exp, nd.path.dentry, NULL))
if (fh_compose(&fh, exp, path.dentry, NULL))
err = -EINVAL;
else
err = 0;
memcpy(f, &fh.fh_handle, sizeof(struct knfsd_fh));
fh_put(&fh);
exp_put(exp);
out:
path_put(&nd.path);
path_put(&path);
return err;
}

Expand Down
50 changes: 25 additions & 25 deletions fs/nfsd/nfs4recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#define NFSDDBG_FACILITY NFSDDBG_PROC

/* Globals */
static struct nameidata rec_dir;
static struct path rec_dir;
static int rec_dir_init = 0;

static void
Expand Down Expand Up @@ -121,9 +121,9 @@ nfs4_make_rec_clidname(char *dname, struct xdr_netobj *clname)
static void
nfsd4_sync_rec_dir(void)
{
mutex_lock(&rec_dir.path.dentry->d_inode->i_mutex);
nfsd_sync_dir(rec_dir.path.dentry);
mutex_unlock(&rec_dir.path.dentry->d_inode->i_mutex);
mutex_lock(&rec_dir.dentry->d_inode->i_mutex);
nfsd_sync_dir(rec_dir.dentry);
mutex_unlock(&rec_dir.dentry->d_inode->i_mutex);
}

int
Expand All @@ -143,9 +143,9 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
nfs4_save_user(&uid, &gid);

/* lock the parent */
mutex_lock(&rec_dir.path.dentry->d_inode->i_mutex);
mutex_lock(&rec_dir.dentry->d_inode->i_mutex);

dentry = lookup_one_len(dname, rec_dir.path.dentry, HEXDIR_LEN-1);
dentry = lookup_one_len(dname, rec_dir.dentry, HEXDIR_LEN-1);
if (IS_ERR(dentry)) {
status = PTR_ERR(dentry);
goto out_unlock;
Expand All @@ -155,15 +155,15 @@ nfsd4_create_clid_dir(struct nfs4_client *clp)
dprintk("NFSD: nfsd4_create_clid_dir: DIRECTORY EXISTS\n");
goto out_put;
}
status = mnt_want_write(rec_dir.path.mnt);
status = mnt_want_write(rec_dir.mnt);
if (status)
goto out_put;
status = vfs_mkdir(rec_dir.path.dentry->d_inode, dentry, S_IRWXU);
mnt_drop_write(rec_dir.path.mnt);
status = vfs_mkdir(rec_dir.dentry->d_inode, dentry, S_IRWXU);
mnt_drop_write(rec_dir.mnt);
out_put:
dput(dentry);
out_unlock:
mutex_unlock(&rec_dir.path.dentry->d_inode->i_mutex);
mutex_unlock(&rec_dir.dentry->d_inode->i_mutex);
if (status == 0) {
clp->cl_firststate = 1;
nfsd4_sync_rec_dir();
Expand Down Expand Up @@ -226,7 +226,7 @@ nfsd4_list_rec_dir(struct dentry *dir, recdir_func *f)

nfs4_save_user(&uid, &gid);

filp = dentry_open(dget(dir), mntget(rec_dir.path.mnt), O_RDONLY);
filp = dentry_open(dget(dir), mntget(rec_dir.mnt), O_RDONLY);
status = PTR_ERR(filp);
if (IS_ERR(filp))
goto out;
Expand Down Expand Up @@ -291,9 +291,9 @@ nfsd4_unlink_clid_dir(char *name, int namlen)

dprintk("NFSD: nfsd4_unlink_clid_dir. name %.*s\n", namlen, name);

mutex_lock(&rec_dir.path.dentry->d_inode->i_mutex);
dentry = lookup_one_len(name, rec_dir.path.dentry, namlen);
mutex_unlock(&rec_dir.path.dentry->d_inode->i_mutex);
mutex_lock(&rec_dir.dentry->d_inode->i_mutex);
dentry = lookup_one_len(name, rec_dir.dentry, namlen);
mutex_unlock(&rec_dir.dentry->d_inode->i_mutex);
if (IS_ERR(dentry)) {
status = PTR_ERR(dentry);
return status;
Expand All @@ -302,7 +302,7 @@ nfsd4_unlink_clid_dir(char *name, int namlen)
if (!dentry->d_inode)
goto out;

status = nfsd4_clear_clid_dir(rec_dir.path.dentry, dentry);
status = nfsd4_clear_clid_dir(rec_dir.dentry, dentry);
out:
dput(dentry);
return status;
Expand All @@ -318,7 +318,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
if (!rec_dir_init || !clp->cl_firststate)
return;

status = mnt_want_write(rec_dir.path.mnt);
status = mnt_want_write(rec_dir.mnt);
if (status)
goto out;
clp->cl_firststate = 0;
Expand All @@ -327,7 +327,7 @@ nfsd4_remove_clid_dir(struct nfs4_client *clp)
nfs4_reset_user(uid, gid);
if (status == 0)
nfsd4_sync_rec_dir();
mnt_drop_write(rec_dir.path.mnt);
mnt_drop_write(rec_dir.mnt);
out:
if (status)
printk("NFSD: Failed to remove expired client state directory"
Expand Down Expand Up @@ -357,17 +357,17 @@ nfsd4_recdir_purge_old(void) {

if (!rec_dir_init)
return;
status = mnt_want_write(rec_dir.path.mnt);
status = mnt_want_write(rec_dir.mnt);
if (status)
goto out;
status = nfsd4_list_rec_dir(rec_dir.path.dentry, purge_old);
status = nfsd4_list_rec_dir(rec_dir.dentry, purge_old);
if (status == 0)
nfsd4_sync_rec_dir();
mnt_drop_write(rec_dir.path.mnt);
mnt_drop_write(rec_dir.mnt);
out:
if (status)
printk("nfsd4: failed to purge old clients from recovery"
" directory %s\n", rec_dir.path.dentry->d_name.name);
" directory %s\n", rec_dir.dentry->d_name.name);
}

static int
Expand All @@ -387,10 +387,10 @@ int
nfsd4_recdir_load(void) {
int status;

status = nfsd4_list_rec_dir(rec_dir.path.dentry, load_recdir);
status = nfsd4_list_rec_dir(rec_dir.dentry, load_recdir);
if (status)
printk("nfsd4: failed loading clients from recovery"
" directory %s\n", rec_dir.path.dentry->d_name.name);
" directory %s\n", rec_dir.dentry->d_name.name);
return status;
}

Expand All @@ -412,7 +412,7 @@ nfsd4_init_recdir(char *rec_dirname)

nfs4_save_user(&uid, &gid);

status = path_lookup(rec_dirname, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
status = kern_path(rec_dirname, LOOKUP_FOLLOW | LOOKUP_DIRECTORY,
&rec_dir);
if (status)
printk("NFSD: unable to find recovery directory %s\n",
Expand All @@ -429,5 +429,5 @@ nfsd4_shutdown_recdir(void)
if (!rec_dir_init)
return;
rec_dir_init = 0;
path_put(&rec_dir.path);
path_put(&rec_dir);
}
8 changes: 4 additions & 4 deletions fs/nfsd/nfs4state.c
Original file line number Diff line number Diff line change
Expand Up @@ -3284,17 +3284,17 @@ int
nfs4_reset_recoverydir(char *recdir)
{
int status;
struct nameidata nd;
struct path path;

status = path_lookup(recdir, LOOKUP_FOLLOW, &nd);
status = kern_path(recdir, LOOKUP_FOLLOW, &path);
if (status)
return status;
status = -ENOTDIR;
if (S_ISDIR(nd.path.dentry->d_inode->i_mode)) {
if (S_ISDIR(path.dentry->d_inode->i_mode)) {
nfs4_set_recdir(recdir);
status = 0;
}
path_put(&nd.path);
path_put(&path);
return status;
}

Expand Down
8 changes: 4 additions & 4 deletions fs/nfsd/nfsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ static ssize_t failover_unlock_ip(struct file *file, char *buf, size_t size)

static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size)
{
struct nameidata nd;
struct path path;
char *fo_path;
int error;

Expand All @@ -356,13 +356,13 @@ static ssize_t failover_unlock_fs(struct file *file, char *buf, size_t size)
if (qword_get(&buf, fo_path, size) < 0)
return -EINVAL;

error = path_lookup(fo_path, 0, &nd);
error = kern_path(fo_path, 0, &path);
if (error)
return error;

error = nlmsvc_unlock_all_by_sb(nd.path.mnt->mnt_sb);
error = nlmsvc_unlock_all_by_sb(path.mnt->mnt_sb);

path_put(&nd.path);
path_put(&path);
return error;
}

Expand Down

0 comments on commit a63bb99

Please sign in to comment.