NFSD: Finish refactoring __write_ports()
[safe/jmp/linux-2.6] / fs / nfsd / nfsproc.c
index 757f9d2..e298e26 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/unistd.h>
 #include <linux/slab.h>
 
+#include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/svc.h>
 #include <linux/nfsd/nfsd.h>
 #include <linux/nfsd/cache.h>
@@ -30,40 +31,61 @@ typedef struct svc_buf      svc_buf;
 #define NFSDDBG_FACILITY               NFSDDBG_PROC
 
 
-static int
+static __be32
 nfsd_proc_null(struct svc_rqst *rqstp, void *argp, void *resp)
 {
        return nfs_ok;
 }
 
+static __be32
+nfsd_return_attrs(__be32 err, struct nfsd_attrstat *resp)
+{
+       if (err) return err;
+       return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt,
+                                   resp->fh.fh_dentry,
+                                   &resp->stat));
+}
+static __be32
+nfsd_return_dirop(__be32 err, struct nfsd_diropres *resp)
+{
+       if (err) return err;
+       return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt,
+                                   resp->fh.fh_dentry,
+                                   &resp->stat));
+}
 /*
  * Get a file's attributes
  * N.B. After this call resp->fh needs an fh_put
  */
-static int
+static __be32
 nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle  *argp,
                                          struct nfsd_attrstat *resp)
 {
+       __be32 nfserr;
        dprintk("nfsd: GETATTR  %s\n", SVCFH_fmt(&argp->fh));
 
        fh_copy(&resp->fh, &argp->fh);
-       return fh_verify(rqstp, &resp->fh, 0, MAY_NOP);
+       nfserr = fh_verify(rqstp, &resp->fh, 0,
+                       NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
+       return nfsd_return_attrs(nfserr, resp);
 }
 
 /*
  * Set a file's attributes
  * N.B. After this call resp->fh needs an fh_put
  */
-static int
+static __be32
 nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp,
                                          struct nfsd_attrstat  *resp)
 {
+       __be32 nfserr;
        dprintk("nfsd: SETATTR  %s, valid=%x, size=%ld\n",
                SVCFH_fmt(&argp->fh),
                argp->attrs.ia_valid, (long) argp->attrs.ia_size);
 
        fh_copy(&resp->fh, &argp->fh);
-       return nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0);
+       nfserr = nfsd_setattr(rqstp, &resp->fh, &argp->attrs,0, (time_t)0);
+       return nfsd_return_attrs(nfserr, resp);
 }
 
 /*
@@ -72,11 +94,11 @@ nfsd_proc_setattr(struct svc_rqst *rqstp, struct nfsd_sattrargs *argp,
  * doesn't exist yet.
  * N.B. After this call resp->fh needs an fh_put
  */
-static int
+static __be32
 nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
                                         struct nfsd_diropres  *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: LOOKUP   %s %.*s\n",
                SVCFH_fmt(&argp->fh), argp->len, argp->name);
@@ -86,17 +108,17 @@ nfsd_proc_lookup(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
                                 &resp->fh);
 
        fh_put(&argp->fh);
-       return nfserr;
+       return nfsd_return_dirop(nfserr, resp);
 }
 
 /*
  * Read a symlink.
  */
-static int
+static __be32
 nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp,
                                           struct nfsd_readlinkres *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: READLINK %s\n", SVCFH_fmt(&argp->fh));
 
@@ -112,11 +134,11 @@ nfsd_proc_readlink(struct svc_rqst *rqstp, struct nfsd_readlinkargs *argp,
  * Read a portion of a file.
  * N.B. After this call resp->fh needs an fh_put
  */
-static int
+static __be32
 nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
                                       struct nfsd_readres  *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: READ    %s %d bytes at %d\n",
                SVCFH_fmt(&argp->fh),
@@ -126,35 +148,39 @@ nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
         * status, 17 words for fattr, and 1 word for the byte count.
         */
 
-       if (NFSSVC_MAXBLKSIZE < argp->count) {
+       if (NFSSVC_MAXBLKSIZE_V2 < argp->count) {
+               char buf[RPC_MAX_ADDRBUFLEN];
                printk(KERN_NOTICE
-                       "oversized read request from %u.%u.%u.%u:%d (%d bytes)\n",
-                               NIPQUAD(rqstp->rq_addr.sin_addr.s_addr),
-                               ntohs(rqstp->rq_addr.sin_port),
+                       "oversized read request from %s (%d bytes)\n",
+                               svc_print_addr(rqstp, buf, sizeof(buf)),
                                argp->count);
-               argp->count = NFSSVC_MAXBLKSIZE;
+               argp->count = NFSSVC_MAXBLKSIZE_V2;
        }
-       svc_reserve(rqstp, (19<<2) + argp->count + 4);
+       svc_reserve_auth(rqstp, (19<<2) + argp->count + 4);
 
        resp->count = argp->count;
        nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
                                  argp->offset,
-                                 argp->vec, argp->vlen,
+                                 rqstp->rq_vec, argp->vlen,
                                  &resp->count);
 
-       return nfserr;
+       if (nfserr) return nfserr;
+       return nfserrno(vfs_getattr(resp->fh.fh_export->ex_path.mnt,
+                                   resp->fh.fh_dentry,
+                                   &resp->stat));
 }
 
 /*
  * Write data to a file
  * N.B. After this call resp->fh needs an fh_put
  */
-static int
+static __be32
 nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
                                        struct nfsd_attrstat  *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
        int     stable = 1;
+       unsigned long cnt = argp->len;
 
        dprintk("nfsd: WRITE    %s %d bytes at %d\n",
                SVCFH_fmt(&argp->fh),
@@ -162,10 +188,10 @@ nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
 
        nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
                                   argp->offset,
-                                  argp->vec, argp->vlen,
-                                  argp->len,
+                                  rqstp->rq_vec, argp->vlen,
+                                  &cnt,
                                   &stable);
-       return nfserr;
+       return nfsd_return_attrs(nfserr, resp);
 }
 
 /*
@@ -174,7 +200,7 @@ nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
  * and the actual create() call in compliance with VFS protocols.
  * N.B. After this call _both_ argp->fh and resp->fh need an fh_put
  */
-static int
+static __be32
 nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
                                         struct nfsd_diropres   *resp)
 {
@@ -183,18 +209,19 @@ nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
        struct iattr    *attr = &argp->attrs;
        struct inode    *inode;
        struct dentry   *dchild;
-       int             nfserr, type, mode;
+       int             type, mode;
+       __be32          nfserr;
        dev_t           rdev = 0, wanted = new_decode_dev(attr->ia_size);
 
        dprintk("nfsd: CREATE   %s %.*s\n",
                SVCFH_fmt(dirfhp), argp->len, argp->name);
 
        /* First verify the parent file handle */
-       nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, MAY_EXEC);
+       nfserr = fh_verify(rqstp, dirfhp, S_IFDIR, NFSD_MAY_EXEC);
        if (nfserr)
                goto done; /* must fh_put dirfhp even on error */
 
-       /* Check for MAY_WRITE in nfsd_create if necessary */
+       /* Check for NFSD_MAY_WRITE in nfsd_create if necessary */
 
        nfserr = nfserr_acces;
        if (!argp->len)
@@ -202,7 +229,7 @@ nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
        nfserr = nfserr_exist;
        if (isdotent(argp->name, argp->len))
                goto done;
-       fh_lock(dirfhp);
+       fh_lock_nested(dirfhp, I_MUTEX_PARENT);
        dchild = lookup_one_len(argp->name, dirfhp->fh_dentry, argp->len);
        if (IS_ERR(dchild)) {
                nfserr = nfserrno(PTR_ERR(dchild));
@@ -253,9 +280,10 @@ nfsd_proc_create(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
                                         *   echo thing > device-special-file-or-pipe
                                         * by doing a CREATE with type==0
                                         */
-                                       nfserr = nfsd_permission(newfhp->fh_export,
+                                       nfserr = nfsd_permission(rqstp,
+                                                                newfhp->fh_export,
                                                                 newfhp->fh_dentry,
-                                                                MAY_WRITE|MAY_LOCAL_ACCESS);
+                                                                NFSD_MAY_WRITE|NFSD_MAY_LOCAL_ACCESS);
                                        if (nfserr && nfserr != nfserr_rofs)
                                                goto out_unlock;
                                }
@@ -322,14 +350,14 @@ out_unlock:
 
 done:
        fh_put(dirfhp);
-       return nfserr;
+       return nfsd_return_dirop(nfserr, resp);
 }
 
-static int
+static __be32
 nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
                                         void                  *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: REMOVE   %s %.*s\n", SVCFH_fmt(&argp->fh),
                argp->len, argp->name);
@@ -340,11 +368,11 @@ nfsd_proc_remove(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
        return nfserr;
 }
 
-static int
+static __be32
 nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp,
                                         void                   *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: RENAME   %s %.*s -> \n",
                SVCFH_fmt(&argp->ffh), argp->flen, argp->fname);
@@ -358,11 +386,11 @@ nfsd_proc_rename(struct svc_rqst *rqstp, struct nfsd_renameargs *argp,
        return nfserr;
 }
 
-static int
+static __be32
 nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp,
                                void                        *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: LINK     %s ->\n",
                SVCFH_fmt(&argp->ffh));
@@ -378,12 +406,12 @@ nfsd_proc_link(struct svc_rqst *rqstp, struct nfsd_linkargs *argp,
        return nfserr;
 }
 
-static int
+static __be32
 nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp,
                                          void                    *resp)
 {
        struct svc_fh   newfh;
-       int             nfserr;
+       __be32          nfserr;
 
        dprintk("nfsd: SYMLINK  %s %.*s -> %.*s\n",
                SVCFH_fmt(&argp->ffh), argp->flen, argp->fname,
@@ -407,11 +435,11 @@ nfsd_proc_symlink(struct svc_rqst *rqstp, struct nfsd_symlinkargs *argp,
  * Make directory. This operation is not idempotent.
  * N.B. After this call resp->fh needs an fh_put
  */
-static int
+static __be32
 nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
                                        struct nfsd_diropres   *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: MKDIR    %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
 
@@ -425,17 +453,17 @@ nfsd_proc_mkdir(struct svc_rqst *rqstp, struct nfsd_createargs *argp,
        nfserr = nfsd_create(rqstp, &argp->fh, argp->name, argp->len,
                                    &argp->attrs, S_IFDIR, 0, &resp->fh);
        fh_put(&argp->fh);
-       return nfserr;
+       return nfsd_return_dirop(nfserr, resp);
 }
 
 /*
  * Remove a directory
  */
-static int
+static __be32
 nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
                                        void                  *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: RMDIR    %s %.*s\n", SVCFH_fmt(&argp->fh), argp->len, argp->name);
 
@@ -447,11 +475,12 @@ nfsd_proc_rmdir(struct svc_rqst *rqstp, struct nfsd_diropargs *argp,
 /*
  * Read a portion of a directory.
  */
-static int
+static __be32
 nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
                                          struct nfsd_readdirres  *resp)
 {
-       int             nfserr, count;
+       int             count;
+       __be32          nfserr;
        loff_t          offset;
 
        dprintk("nfsd: READDIR  %s %d bytes at %d\n",
@@ -486,15 +515,16 @@ nfsd_proc_readdir(struct svc_rqst *rqstp, struct nfsd_readdirargs *argp,
 /*
  * Get file system info
  */
-static int
+static __be32
 nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle   *argp,
                                          struct nfsd_statfsres *resp)
 {
-       int     nfserr;
+       __be32  nfserr;
 
        dprintk("nfsd: STATFS   %s\n", SVCFH_fmt(&argp->fh));
 
-       nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats);
+       nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
+                       NFSD_MAY_BYPASS_GSS_ON_ROOT);
        fh_put(&argp->fh);
        return nfserr;
 }
@@ -530,7 +560,7 @@ static struct svc_procedure         nfsd_procedures2[18] = {
   PROC(none,    void,          void,           none,           RC_NOCACHE, ST),
   PROC(lookup,  diropargs,     diropres,       fhandle,        RC_NOCACHE, ST+FH+AT),
   PROC(readlink, readlinkargs, readlinkres,    none,           RC_NOCACHE, ST+1+NFS_MAXPATHLEN/4),
-  PROC(read,    readargs,      readres,        fhandle,        RC_NOCACHE, ST+AT+1+NFSSVC_MAXBLKSIZE),
+  PROC(read,    readargs,      readres,        fhandle,        RC_NOCACHE, ST+AT+1+NFSSVC_MAXBLKSIZE_V2/4),
   PROC(none,    void,          void,           none,           RC_NOCACHE, ST),
   PROC(write,   writeargs,     attrstat,       fhandle,        RC_REPLBUFF, ST+AT),
   PROC(create,  createargs,    diropres,       fhandle,        RC_REPLBUFF, ST+FH+AT),
@@ -556,11 +586,11 @@ struct svc_version        nfsd_version2 = {
 /*
  * Map errnos to NFS errnos.
  */
-int
+__be32
 nfserrno (int errno)
 {
        static struct {
-               int     nfserr;
+               __be32  nfserr;
                int     syserr;
        } nfs_errtbl[] = {
                { nfs_ok, 0 },
@@ -587,15 +617,17 @@ nfserrno (int errno)
 #endif
                { nfserr_stale, -ESTALE },
                { nfserr_jukebox, -ETIMEDOUT },
+               { nfserr_jukebox, -ERESTARTSYS },
                { nfserr_dropit, -EAGAIN },
                { nfserr_dropit, -ENOMEM },
                { nfserr_badname, -ESRCH },
                { nfserr_io, -ETXTBSY },
-               { -1, -EIO }
+               { nfserr_notsupp, -EOPNOTSUPP },
+               { nfserr_toosmall, -ETOOSMALL },
        };
        int     i;
 
-       for (i = 0; nfs_errtbl[i].nfserr != -1; i++) {
+       for (i = 0; i < ARRAY_SIZE(nfs_errtbl); i++) {
                if (nfs_errtbl[i].syserr == errno)
                        return nfs_errtbl[i].nfserr;
        }