nfsd4: use common rpc_cred for all callbacks
[safe/jmp/linux-2.6] / fs / lockd / xdr.c
index f01e9c0..0336f2b 100644 (file)
@@ -6,7 +6,6 @@
  * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
  */
 
-#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/sched.h>
 #include <linux/utsname.h>
@@ -17,7 +16,6 @@
 #include <linux/sunrpc/svc.h>
 #include <linux/sunrpc/stats.h>
 #include <linux/lockd/lockd.h>
-#include <linux/lockd/sm_inter.h>
 
 #define NLMDBG_FACILITY                NLMDBG_XDR
 
@@ -44,7 +42,7 @@ loff_t_to_s32(loff_t offset)
 /*
  * XDR functions for basic NLM types
  */
-static inline u32 *nlm_decode_cookie(u32 *p, struct nlm_cookie *c)
+static __be32 *nlm_decode_cookie(__be32 *p, struct nlm_cookie *c)
 {
        unsigned int    len;
 
@@ -63,15 +61,16 @@ static inline u32 *nlm_decode_cookie(u32 *p, struct nlm_cookie *c)
        }
        else 
        {
-               printk(KERN_NOTICE
-                       "lockd: bad cookie size %d (only cookies under %d bytes are supported.)\n", len, NLM_MAXCOOKIELEN);
+               dprintk("lockd: bad cookie size %d (only cookies under "
+                       "%d bytes are supported.)\n",
+                               len, NLM_MAXCOOKIELEN);
                return NULL;
        }
        return p;
 }
 
-static inline u32 *
-nlm_encode_cookie(u32 *p, struct nlm_cookie *c)
+static inline __be32 *
+nlm_encode_cookie(__be32 *p, struct nlm_cookie *c)
 {
        *p++ = htonl(c->len);
        memcpy(p, c->data, c->len);
@@ -79,14 +78,13 @@ nlm_encode_cookie(u32 *p, struct nlm_cookie *c)
        return p;
 }
 
-static inline u32 *
-nlm_decode_fh(u32 *p, struct nfs_fh *f)
+static __be32 *
+nlm_decode_fh(__be32 *p, struct nfs_fh *f)
 {
        unsigned int    len;
 
        if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
-               printk(KERN_NOTICE
-                       "lockd: bad fhandle size %d (should be %d)\n",
+               dprintk("lockd: bad fhandle size %d (should be %d)\n",
                        len, NFS2_FHSIZE);
                return NULL;
        }
@@ -96,8 +94,8 @@ nlm_decode_fh(u32 *p, struct nfs_fh *f)
        return p + XDR_QUADLEN(NFS2_FHSIZE);
 }
 
-static inline u32 *
-nlm_encode_fh(u32 *p, struct nfs_fh *f)
+static inline __be32 *
+nlm_encode_fh(__be32 *p, struct nfs_fh *f)
 {
        *p++ = htonl(NFS2_FHSIZE);
        memcpy(p, f->data, NFS2_FHSIZE);
@@ -107,20 +105,20 @@ nlm_encode_fh(u32 *p, struct nfs_fh *f)
 /*
  * Encode and decode owner handle
  */
-static inline u32 *
-nlm_decode_oh(u32 *p, struct xdr_netobj *oh)
+static inline __be32 *
+nlm_decode_oh(__be32 *p, struct xdr_netobj *oh)
 {
        return xdr_decode_netobj(p, oh);
 }
 
-static inline u32 *
-nlm_encode_oh(u32 *p, struct xdr_netobj *oh)
+static inline __be32 *
+nlm_encode_oh(__be32 *p, struct xdr_netobj *oh)
 {
        return xdr_encode_netobj(p, oh);
 }
 
-static inline u32 *
-nlm_decode_lock(u32 *p, struct nlm_lock *lock)
+static __be32 *
+nlm_decode_lock(__be32 *p, struct nlm_lock *lock)
 {
        struct file_lock        *fl = &lock->fl;
        s32                     start, len, end;
@@ -131,10 +129,11 @@ nlm_decode_lock(u32 *p, struct nlm_lock *lock)
         || !(p = nlm_decode_fh(p, &lock->fh))
         || !(p = nlm_decode_oh(p, &lock->oh)))
                return NULL;
+       lock->svid  = ntohl(*p++);
 
        locks_init_lock(fl);
        fl->fl_owner = current->files;
-       fl->fl_pid   = ntohl(*p++);
+       fl->fl_pid   = (pid_t)lock->svid;
        fl->fl_flags = FL_POSIX;
        fl->fl_type  = F_RDLCK;         /* as good as anything else */
        start = ntohl(*p++);
@@ -153,8 +152,8 @@ nlm_decode_lock(u32 *p, struct nlm_lock *lock)
 /*
  * Encode a lock as part of an NLM call
  */
-static u32 *
-nlm_encode_lock(u32 *p, struct nlm_lock *lock)
+static __be32 *
+nlm_encode_lock(__be32 *p, struct nlm_lock *lock)
 {
        struct file_lock        *fl = &lock->fl;
        __s32                   start, len;
@@ -174,7 +173,7 @@ nlm_encode_lock(u32 *p, struct nlm_lock *lock)
        else
                len = loff_t_to_s32(fl->fl_end - fl->fl_start + 1);
 
-       *p++ = htonl(fl->fl_pid);
+       *p++ = htonl(lock->svid);
        *p++ = htonl(start);
        *p++ = htonl(len);
 
@@ -184,8 +183,8 @@ nlm_encode_lock(u32 *p, struct nlm_lock *lock)
 /*
  * Encode result of a TEST/TEST_MSG call
  */
-static u32 *
-nlm_encode_testres(u32 *p, struct nlm_res *resp)
+static __be32 *
+nlm_encode_testres(__be32 *p, struct nlm_res *resp)
 {
        s32             start, len;
 
@@ -197,7 +196,7 @@ nlm_encode_testres(u32 *p, struct nlm_res *resp)
                struct file_lock        *fl = &resp->lock.fl;
 
                *p++ = (fl->fl_type == F_RDLCK)? xdr_zero : xdr_one;
-               *p++ = htonl(fl->fl_pid);
+               *p++ = htonl(resp->lock.svid);
 
                /* Encode owner handle. */
                if (!(p = xdr_encode_netobj(p, &resp->lock.oh)))
@@ -221,7 +220,7 @@ nlm_encode_testres(u32 *p, struct nlm_res *resp)
  * First, the server side XDR functions
  */
 int
-nlmsvc_decode_testargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
+nlmsvc_decode_testargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
 {
        u32     exclusive;
 
@@ -238,7 +237,7 @@ nlmsvc_decode_testargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 }
 
 int
-nlmsvc_encode_testres(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
+nlmsvc_encode_testres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_encode_testres(p, resp)))
                return 0;
@@ -246,7 +245,7 @@ nlmsvc_encode_testres(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
 }
 
 int
-nlmsvc_decode_lockargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
+nlmsvc_decode_lockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
 {
        u32     exclusive;
 
@@ -266,7 +265,7 @@ nlmsvc_decode_lockargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 }
 
 int
-nlmsvc_decode_cancargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
+nlmsvc_decode_cancargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
 {
        u32     exclusive;
 
@@ -282,7 +281,7 @@ nlmsvc_decode_cancargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 }
 
 int
-nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
+nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
 {
        if (!(p = nlm_decode_cookie(p, &argp->cookie))
         || !(p = nlm_decode_lock(p, &argp->lock)))
@@ -292,13 +291,14 @@ nlmsvc_decode_unlockargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 }
 
 int
-nlmsvc_decode_shareargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
+nlmsvc_decode_shareargs(struct svc_rqst *rqstp, __be32 *p, nlm_args *argp)
 {
        struct nlm_lock *lock = &argp->lock;
 
        memset(lock, 0, sizeof(*lock));
        locks_init_lock(&lock->fl);
-       lock->fl.fl_pid = ~(u32) 0;
+       lock->svid = ~(u32) 0;
+       lock->fl.fl_pid = (pid_t)lock->svid;
 
        if (!(p = nlm_decode_cookie(p, &argp->cookie))
         || !(p = xdr_decode_string_inplace(p, &lock->caller,
@@ -312,7 +312,7 @@ nlmsvc_decode_shareargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 }
 
 int
-nlmsvc_encode_shareres(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
+nlmsvc_encode_shareres(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_encode_cookie(p, &resp->cookie)))
                return 0;
@@ -322,7 +322,7 @@ nlmsvc_encode_shareres(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
 }
 
 int
-nlmsvc_encode_res(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
+nlmsvc_encode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_encode_cookie(p, &resp->cookie)))
                return 0;
@@ -331,7 +331,7 @@ nlmsvc_encode_res(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
 }
 
 int
-nlmsvc_decode_notify(struct svc_rqst *rqstp, u32 *p, struct nlm_args *argp)
+nlmsvc_decode_notify(struct svc_rqst *rqstp, __be32 *p, struct nlm_args *argp)
 {
        struct nlm_lock *lock = &argp->lock;
 
@@ -343,35 +343,33 @@ nlmsvc_decode_notify(struct svc_rqst *rqstp, u32 *p, struct nlm_args *argp)
 }
 
 int
-nlmsvc_decode_reboot(struct svc_rqst *rqstp, u32 *p, struct nlm_reboot *argp)
+nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp)
 {
        if (!(p = xdr_decode_string_inplace(p, &argp->mon, &argp->len, SM_MAXSTRLEN)))
                return 0;
        argp->state = ntohl(*p++);
-       /* Preserve the address in network byte order */
-       argp->addr = *p++;
-       argp->vers = *p++;
-       argp->proto = *p++;
+       memcpy(&argp->priv.data, p, sizeof(argp->priv.data));
+       p += XDR_QUADLEN(SM_PRIV_SIZE);
        return xdr_argsize_check(rqstp, p);
 }
 
 int
-nlmsvc_decode_res(struct svc_rqst *rqstp, u32 *p, struct nlm_res *resp)
+nlmsvc_decode_res(struct svc_rqst *rqstp, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_decode_cookie(p, &resp->cookie)))
                return 0;
-       resp->status = ntohl(*p++);
+       resp->status = *p++;
        return xdr_argsize_check(rqstp, p);
 }
 
 int
-nlmsvc_decode_void(struct svc_rqst *rqstp, u32 *p, void *dummy)
+nlmsvc_decode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
 {
        return xdr_argsize_check(rqstp, p);
 }
 
 int
-nlmsvc_encode_void(struct svc_rqst *rqstp, u32 *p, void *dummy)
+nlmsvc_encode_void(struct svc_rqst *rqstp, __be32 *p, void *dummy)
 {
        return xdr_ressize_check(rqstp, p);
 }
@@ -388,7 +386,7 @@ nlmclt_decode_void(struct rpc_rqst *req, u32 *p, void *ptr)
 #endif
 
 static int
-nlmclt_encode_testargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
+nlmclt_encode_testargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
 {
        struct nlm_lock *lock = &argp->lock;
 
@@ -402,12 +400,12 @@ nlmclt_encode_testargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
 }
 
 static int
-nlmclt_decode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
+nlmclt_decode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_decode_cookie(p, &resp->cookie)))
                return -EIO;
-       resp->status = ntohl(*p++);
-       if (resp->status == NLM_LCK_DENIED) {
+       resp->status = *p++;
+       if (resp->status == nlm_lck_denied) {
                struct file_lock        *fl = &resp->lock.fl;
                u32                     excl;
                s32                     start, len, end;
@@ -415,7 +413,8 @@ nlmclt_decode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
                memset(&resp->lock, 0, sizeof(resp->lock));
                locks_init_lock(fl);
                excl = ntohl(*p++);
-               fl->fl_pid = ntohl(*p++);
+               resp->lock.svid = ntohl(*p++);
+               fl->fl_pid = (pid_t)resp->lock.svid;
                if (!(p = nlm_decode_oh(p, &resp->lock.oh)))
                        return -EIO;
 
@@ -436,7 +435,7 @@ nlmclt_decode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
 
 
 static int
-nlmclt_encode_lockargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
+nlmclt_encode_lockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
 {
        struct nlm_lock *lock = &argp->lock;
 
@@ -453,7 +452,7 @@ nlmclt_encode_lockargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
 }
 
 static int
-nlmclt_encode_cancargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
+nlmclt_encode_cancargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
 {
        struct nlm_lock *lock = &argp->lock;
 
@@ -468,7 +467,7 @@ nlmclt_encode_cancargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
 }
 
 static int
-nlmclt_encode_unlockargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
+nlmclt_encode_unlockargs(struct rpc_rqst *req, __be32 *p, nlm_args *argp)
 {
        struct nlm_lock *lock = &argp->lock;
 
@@ -481,7 +480,7 @@ nlmclt_encode_unlockargs(struct rpc_rqst *req, u32 *p, nlm_args *argp)
 }
 
 static int
-nlmclt_encode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
+nlmclt_encode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_encode_cookie(p, &resp->cookie)))
                return -EIO;
@@ -491,7 +490,7 @@ nlmclt_encode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
 }
 
 static int
-nlmclt_encode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
+nlmclt_encode_testres(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_encode_testres(p, resp)))
                return -EIO;
@@ -500,25 +499,28 @@ nlmclt_encode_testres(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
 }
 
 static int
-nlmclt_decode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
+nlmclt_decode_res(struct rpc_rqst *req, __be32 *p, struct nlm_res *resp)
 {
        if (!(p = nlm_decode_cookie(p, &resp->cookie)))
                return -EIO;
-       resp->status = ntohl(*p++);
+       resp->status = *p++;
        return 0;
 }
 
+#if (NLMCLNT_OHSIZE > XDR_MAX_NETOBJ)
+#  error "NLM host name cannot be larger than XDR_MAX_NETOBJ!"
+#endif
+
 /*
  * Buffer requirements for NLM
  */
 #define NLM_void_sz            0
 #define NLM_cookie_sz          1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
-#define NLM_caller_sz          1+XDR_QUADLEN(sizeof(system_utsname.nodename))
-#define NLM_netobj_sz          1+XDR_QUADLEN(XDR_MAX_NETOBJ)
-/* #define NLM_owner_sz                1+XDR_QUADLEN(NLM_MAXOWNER) */
+#define NLM_caller_sz          1+XDR_QUADLEN(NLMCLNT_OHSIZE)
+#define NLM_owner_sz           1+XDR_QUADLEN(NLMCLNT_OHSIZE)
 #define NLM_fhandle_sz         1+XDR_QUADLEN(NFS2_FHSIZE)
-#define NLM_lock_sz            3+NLM_caller_sz+NLM_netobj_sz+NLM_fhandle_sz
-#define NLM_holder_sz          4+NLM_netobj_sz
+#define NLM_lock_sz            3+NLM_caller_sz+NLM_owner_sz+NLM_fhandle_sz
+#define NLM_holder_sz          4+NLM_owner_sz
 
 #define NLM_testargs_sz                NLM_cookie_sz+1+NLM_lock_sz
 #define NLM_lockargs_sz                NLM_cookie_sz+4+NLM_lock_sz
@@ -529,10 +531,6 @@ nlmclt_decode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
 #define NLM_res_sz             NLM_cookie_sz+1
 #define NLM_norep_sz           0
 
-#ifndef MAX
-# define MAX(a, b)             (((a) > (b))? (a) : (b))
-#endif
-
 /*
  * For NLM, a void procedure really returns nothing
  */
@@ -543,7 +541,10 @@ nlmclt_decode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
        .p_proc      = NLMPROC_##proc,                                  \
        .p_encode    = (kxdrproc_t) nlmclt_encode_##argtype,            \
        .p_decode    = (kxdrproc_t) nlmclt_decode_##restype,            \
-       .p_bufsiz    = MAX(NLM_##argtype##_sz, NLM_##restype##_sz) << 2 \
+       .p_arglen    = NLM_##argtype##_sz,                              \
+       .p_replen    = NLM_##restype##_sz,                              \
+       .p_statidx   = NLMPROC_##proc,                                  \
+       .p_name      = #proc,                                           \
        }
 
 static struct rpc_procinfo     nlm_procedures[] = {
@@ -582,10 +583,6 @@ static struct rpc_version  nlm_version3 = {
                .procs          = nlm_procedures,
 };
 
-#ifdef         CONFIG_LOCKD_V4
-extern struct rpc_version nlm_version4;
-#endif
-
 static struct rpc_version *    nlm_versions[] = {
        [1] = &nlm_version1,
        [3] = &nlm_version3,
@@ -599,7 +596,7 @@ static struct rpc_stat              nlm_stats;
 struct rpc_program             nlm_program = {
                .name           = "lockd",
                .number         = NLM_PROGRAM,
-               .nrvers         = sizeof(nlm_versions) / sizeof(nlm_versions[0]),
+               .nrvers         = ARRAY_SIZE(nlm_versions),
                .version        = nlm_versions,
                .stats          = &nlm_stats,
 };
@@ -612,8 +609,7 @@ const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
         * called with BKL held.
         */
        static char buf[2*NLM_MAXCOOKIELEN+1];
-       int i;
-       int len = sizeof(buf);
+       unsigned int i, len = sizeof(buf);
        char *p = buf;
 
        len--;  /* allow for trailing \0 */