nfsd: move most of nfsfh.h to fs/nfsd
[safe/jmp/linux-2.6] / fs / nfsd / export.c
index 6eb9181..b26a364 100644 (file)
  * Copyright (C) 1995, 1996 Olaf Kirch, <okir@monad.swb.de>
  */
 
-#include <linux/unistd.h>
-#include <linux/slab.h>
-#include <linux/stat.h>
-#include <linux/in.h>
-#include <linux/seq_file.h>
-#include <linux/syscalls.h>
-#include <linux/rwsem.h>
-#include <linux/dcache.h>
 #include <linux/namei.h>
-#include <linux/mount.h>
-#include <linux/hash.h>
 #include <linux/module.h>
 #include <linux/exportfs.h>
 
-#include <linux/sunrpc/svc.h>
-#include <linux/nfsd/nfsd.h>
-#include <linux/nfsd/nfsfh.h>
 #include <linux/nfsd/syscall.h>
-#include <linux/lockd/bind.h>
-#include <linux/sunrpc/msg_prot.h>
-#include <linux/sunrpc/gss_api.h>
 #include <net/ipv6.h>
 
+#include "nfsd.h"
+#include "nfsfh.h"
+
 #define NFSDDBG_FACILITY       NFSDDBG_EXPORT
 
 typedef struct auth_domain     svc_client;
@@ -85,6 +72,11 @@ static void expkey_request(struct cache_detail *cd,
        (*bpp)[-1] = '\n';
 }
 
+static int expkey_upcall(struct cache_detail *cd, struct cache_head *h)
+{
+       return sunrpc_cache_pipe_upcall(cd, h, expkey_request);
+}
+
 static struct svc_expkey *svc_expkey_update(struct svc_expkey *new, struct svc_expkey *old);
 static struct svc_expkey *svc_expkey_lookup(struct svc_expkey *);
 static struct cache_detail svc_expkey_cache;
@@ -259,7 +251,7 @@ static struct cache_detail svc_expkey_cache = {
        .hash_table     = expkey_table,
        .name           = "nfsd.fh",
        .cache_put      = expkey_put,
-       .cache_request  = expkey_request,
+       .cache_upcall   = expkey_upcall,
        .cache_parse    = expkey_parse,
        .cache_show     = expkey_show,
        .match          = expkey_match,
@@ -355,20 +347,34 @@ static void svc_export_request(struct cache_detail *cd,
        (*bpp)[-1] = '\n';
 }
 
+static int svc_export_upcall(struct cache_detail *cd, struct cache_head *h)
+{
+       return sunrpc_cache_pipe_upcall(cd, h, svc_export_request);
+}
+
 static struct svc_export *svc_export_update(struct svc_export *new,
                                            struct svc_export *old);
 static struct svc_export *svc_export_lookup(struct svc_export *);
 
-static int check_export(struct inode *inode, int flags, unsigned char *uuid)
+static int check_export(struct inode *inode, int *flags, unsigned char *uuid)
 {
 
-       /* We currently export only dirs and regular files.
-        * This is what umountd does.
+       /*
+        * We currently export only dirs, regular files, and (for v4
+        * pseudoroot) symlinks.
         */
        if (!S_ISDIR(inode->i_mode) &&
+           !S_ISLNK(inode->i_mode) &&
            !S_ISREG(inode->i_mode))
                return -ENOTDIR;
 
+       /*
+        * Mountd should never pass down a writeable V4ROOT export, but,
+        * just to make sure:
+        */
+       if (*flags & NFSEXP_V4ROOT)
+               *flags |= NFSEXP_READONLY;
+
        /* There are two requirements on a filesystem to be exportable.
         * 1:  We must be able to identify the filesystem from a number.
         *       either a device number (so FS_REQUIRES_DEV needed)
@@ -377,7 +383,7 @@ static int check_export(struct inode *inode, int flags, unsigned char *uuid)
         *       This means that s_export_op must be set.
         */
        if (!(inode->i_sb->s_type->fs_flags & FS_REQUIRES_DEV) &&
-           !(flags & NFSEXP_FSID) &&
+           !(*flags & NFSEXP_FSID) &&
            uuid == NULL) {
                dprintk("exp_export: export of non-dev fs without fsid\n");
                return -EINVAL;
@@ -592,7 +598,7 @@ static int svc_export_parse(struct cache_detail *cd, char *mesg, int mlen)
                                goto out4;
                }
 
-               err = check_export(exp.ex_path.dentry->d_inode, exp.ex_flags,
+               err = check_export(exp.ex_path.dentry->d_inode, &exp.ex_flags,
                                   exp.ex_uuid);
                if (err)
                        goto out4;
@@ -724,7 +730,7 @@ struct cache_detail svc_export_cache = {
        .hash_table     = export_table,
        .name           = "nfsd.export",
        .cache_put      = svc_export_put,
-       .cache_request  = svc_export_request,
+       .cache_upcall   = svc_export_upcall,
        .cache_parse    = svc_export_parse,
        .cache_show     = svc_export_show,
        .match          = svc_export_match,
@@ -842,9 +848,8 @@ exp_get_fsid_key(svc_client *clp, int fsid)
        return exp_find_key(clp, FSID_NUM, fsidv, NULL);
 }
 
-static svc_export *exp_get_by_name(svc_client *clp, struct vfsmount *mnt,
-                                  struct dentry *dentry,
-                                  struct cache_req *reqp)
+static svc_export *exp_get_by_name(svc_client *clp, const struct path *path,
+                                    struct cache_req *reqp)
 {
        struct svc_export *exp, key;
        int err;
@@ -853,8 +858,7 @@ static svc_export *exp_get_by_name(svc_client *clp, struct vfsmount *mnt,
                return ERR_PTR(-ENOENT);
 
        key.ex_client = clp;
-       key.ex_path.mnt = mnt;
-       key.ex_path.dentry = dentry;
+       key.ex_path = *path;
 
        exp = svc_export_lookup(&key);
        if (exp == NULL)
@@ -868,24 +872,19 @@ static svc_export *exp_get_by_name(svc_client *clp, struct vfsmount *mnt,
 /*
  * Find the export entry for a given dentry.
  */
-static struct svc_export *exp_parent(svc_client *clp, struct vfsmount *mnt,
-                                    struct dentry *dentry,
-                                    struct cache_req *reqp)
+static struct svc_export *exp_parent(svc_client *clp, struct path *path)
 {
-       svc_export *exp;
-
-       dget(dentry);
-       exp = exp_get_by_name(clp, mnt, dentry, reqp);
-
-       while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(dentry)) {
-               struct dentry *parent;
-
-               parent = dget_parent(dentry);
-               dput(dentry);
-               dentry = parent;
-               exp = exp_get_by_name(clp, mnt, dentry, reqp);
+       struct dentry *saved = dget(path->dentry);
+       svc_export *exp = exp_get_by_name(clp, path, NULL);
+
+       while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
+               struct dentry *parent = dget_parent(path->dentry);
+               dput(path->dentry);
+               path->dentry = parent;
+               exp = exp_get_by_name(clp, path, NULL);
        }
-       dput(dentry);
+       dput(path->dentry);
+       path->dentry = saved;
        return exp;
 }
 
@@ -1013,7 +1012,7 @@ exp_export(struct nfsctl_export *nxp)
                goto out_put_clp;
        err = -EINVAL;
 
-       exp = exp_get_by_name(clp, path.mnt, path.dentry, NULL);
+       exp = exp_get_by_name(clp, &path, NULL);
 
        memset(&new, 0, sizeof(new));
 
@@ -1038,7 +1037,7 @@ exp_export(struct nfsctl_export *nxp)
                goto finish;
        }
 
-       err = check_export(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;
@@ -1130,7 +1129,7 @@ exp_unexport(struct nfsctl_export *nxp)
                goto out_domain;
 
        err = -EINVAL;
-       exp = exp_get_by_name(dom, path.mnt, path.dentry, NULL);
+       exp = exp_get_by_name(dom, &path, NULL);
        path_put(&path);
        if (IS_ERR(exp))
                goto out_domain;
@@ -1172,7 +1171,7 @@ exp_rootfh(svc_client *clp, char *name, struct knfsd_fh *f, int maxsize)
        dprintk("nfsd: exp_rootfh(%s [%p] %s:%s/%ld)\n",
                 name, path.dentry, clp->name,
                 inode->i_sb->s_id, inode->i_ino);
-       exp = exp_parent(clp, path.mnt, path.dentry, NULL);
+       exp = exp_parent(clp, &path);
        if (IS_ERR(exp)) {
                err = PTR_ERR(exp);
                goto out;
@@ -1202,7 +1201,7 @@ static struct svc_export *exp_find(struct auth_domain *clp, int fsid_type,
        if (IS_ERR(ek))
                return ERR_CAST(ek);
 
-       exp = exp_get_by_name(clp, ek->ek_path.mnt, ek->ek_path.dentry, reqp);
+       exp = exp_get_by_name(clp, &ek->ek_path, reqp);
        cache_put(&ek->h, &svc_expkey_cache);
 
        if (IS_ERR(exp))
@@ -1242,8 +1241,7 @@ __be32 check_nfsd_access(struct svc_export *exp, struct svc_rqst *rqstp)
  * use exp_get_by_name() or exp_find().
  */
 struct svc_export *
-rqst_exp_get_by_name(struct svc_rqst *rqstp, struct vfsmount *mnt,
-               struct dentry *dentry)
+rqst_exp_get_by_name(struct svc_rqst *rqstp, struct path *path)
 {
        struct svc_export *gssexp, *exp = ERR_PTR(-ENOENT);
 
@@ -1251,8 +1249,7 @@ rqst_exp_get_by_name(struct svc_rqst *rqstp, struct vfsmount *mnt,
                goto gss;
 
        /* First try the auth_unix client: */
-       exp = exp_get_by_name(rqstp->rq_client, mnt, dentry,
-                                               &rqstp->rq_chandle);
+       exp = exp_get_by_name(rqstp->rq_client, path, &rqstp->rq_chandle);
        if (PTR_ERR(exp) == -ENOENT)
                goto gss;
        if (IS_ERR(exp))
@@ -1264,8 +1261,7 @@ gss:
        /* Otherwise, try falling back on gss client */
        if (rqstp->rq_gssclient == NULL)
                return exp;
-       gssexp = exp_get_by_name(rqstp->rq_gssclient, mnt, dentry,
-                                               &rqstp->rq_chandle);
+       gssexp = exp_get_by_name(rqstp->rq_gssclient, path, &rqstp->rq_chandle);
        if (PTR_ERR(gssexp) == -ENOENT)
                return exp;
        if (!IS_ERR(exp))
@@ -1304,23 +1300,36 @@ gss:
 }
 
 struct svc_export *
-rqst_exp_parent(struct svc_rqst *rqstp, struct vfsmount *mnt,
-               struct dentry *dentry)
+rqst_exp_parent(struct svc_rqst *rqstp, struct path *path)
 {
-       struct svc_export *exp;
+       struct dentry *saved = dget(path->dentry);
+       struct svc_export *exp = rqst_exp_get_by_name(rqstp, path);
+
+       while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(path->dentry)) {
+               struct dentry *parent = dget_parent(path->dentry);
+               dput(path->dentry);
+               path->dentry = parent;
+               exp = rqst_exp_get_by_name(rqstp, path);
+       }
+       dput(path->dentry);
+       path->dentry = saved;
+       return exp;
+}
 
-       dget(dentry);
-       exp = rqst_exp_get_by_name(rqstp, mnt, dentry);
+static struct svc_export *find_fsidzero_export(struct svc_rqst *rqstp)
+{
+       struct svc_export *exp;
+       u32 fsidv[2];
 
-       while (PTR_ERR(exp) == -ENOENT && !IS_ROOT(dentry)) {
-               struct dentry *parent;
+       mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
 
-               parent = dget_parent(dentry);
-               dput(dentry);
-               dentry = parent;
-               exp = rqst_exp_get_by_name(rqstp, mnt, dentry);
-       }
-       dput(dentry);
+       exp = rqst_exp_find(rqstp, FSID_NUM, fsidv);
+       /*
+        * We shouldn't have accepting an nfsv4 request at all if we
+        * don't have a pseudoexport!:
+        */
+       if (IS_ERR(exp) && PTR_ERR(exp) == -ENOENT)
+               exp = ERR_PTR(-ESERVERFAULT);
        return exp;
 }
 
@@ -1334,17 +1343,16 @@ exp_pseudoroot(struct svc_rqst *rqstp, struct svc_fh *fhp)
 {
        struct svc_export *exp;
        __be32 rv;
-       u32 fsidv[2];
 
-       mk_fsid(FSID_NUM, fsidv, 0, 0, 0, NULL);
-
-       exp = rqst_exp_find(rqstp, FSID_NUM, fsidv);
+       exp = find_fsidzero_export(rqstp);
        if (IS_ERR(exp))
                return nfserrno(PTR_ERR(exp));
        rv = fh_compose(fhp, exp, exp->ex_path.dentry, NULL);
        if (rv)
                goto out;
        rv = check_nfsd_access(exp, rqstp);
+       if (rv)
+               fh_put(fhp);
 out:
        exp_put(exp);
        return rv;
@@ -1427,6 +1435,7 @@ static struct flags {
        { NFSEXP_CROSSMOUNT, {"crossmnt", ""}},
        { NFSEXP_NOSUBTREECHECK, {"no_subtree_check", ""}},
        { NFSEXP_NOAUTHNLM, {"insecure_locks", ""}},
+       { NFSEXP_V4ROOT, {"v4root", ""}},
 #ifdef MSNFS
        { NFSEXP_MSNFS, {"msnfs", ""}},
 #endif
@@ -1519,7 +1528,7 @@ static int e_show(struct seq_file *m, void *p)
        return svc_export_show(m, &svc_export_cache, cp);
 }
 
-struct seq_operations nfs_exports_op = {
+const struct seq_operations nfs_exports_op = {
        .start  = e_start,
        .next   = e_next,
        .stop   = e_stop,