Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / fs / lockd / xdr.c
index a76c496..f22a376 100644 (file)
@@ -44,7 +44,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 u32 *nlm_decode_cookie(u32 *p, struct nlm_cookie *c)
 {
        unsigned int    len;
 
@@ -55,16 +55,16 @@ static inline u32 *nlm_decode_cookie(u32 *p, struct nlm_cookie *c)
                c->len=4;
                memset(c->data, 0, 4);  /* hockeypux brain damage */
        }
-       else if(len<=8)
+       else if(len<=NLM_MAXCOOKIELEN)
        {
                c->len=len;
                memcpy(c->data, p, len);
-               p+=(len+3)>>2;
+               p+=XDR_QUADLEN(len);
        }
        else 
        {
                printk(KERN_NOTICE
-                       "lockd: bad cookie size %d (only cookies under 8 bytes are supported.)\n", len);
+                       "lockd: bad cookie size %d (only cookies under %d bytes are supported.)\n", len, NLM_MAXCOOKIELEN);
                return NULL;
        }
        return p;
@@ -75,18 +75,18 @@ nlm_encode_cookie(u32 *p, struct nlm_cookie *c)
 {
        *p++ = htonl(c->len);
        memcpy(p, c->data, c->len);
-       p+=(c->len+3)>>2;
+       p+=XDR_QUADLEN(c->len);
        return p;
 }
 
-static inline u32 *
+static u32 *
 nlm_decode_fh(u32 *p, struct nfs_fh *f)
 {
        unsigned int    len;
 
        if ((len = ntohl(*p++)) != NFS2_FHSIZE) {
                printk(KERN_NOTICE
-                       "lockd: bad fhandle size %x (should be %d)\n",
+                       "lockd: bad fhandle size %d (should be %d)\n",
                        len, NFS2_FHSIZE);
                return NULL;
        }
@@ -119,7 +119,7 @@ nlm_encode_oh(u32 *p, struct xdr_netobj *oh)
        return xdr_encode_netobj(p, oh);
 }
 
-static inline u32 *
+static u32 *
 nlm_decode_lock(u32 *p, struct nlm_lock *lock)
 {
        struct file_lock        *fl = &lock->fl;
@@ -131,10 +131,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++);
@@ -174,7 +175,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);
 
@@ -197,7 +198,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)))
@@ -298,7 +299,8 @@ nlmsvc_decode_shareargs(struct svc_rqst *rqstp, u32 *p, nlm_args *argp)
 
        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,
@@ -415,7 +417,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;
 
@@ -512,11 +515,11 @@ nlmclt_decode_res(struct rpc_rqst *req, u32 *p, struct nlm_res *resp)
  * Buffer requirements for NLM
  */
 #define NLM_void_sz            0
-#define NLM_cookie_sz          3       /* 1 len , 2 data */
-#define NLM_caller_sz          1+QUADLEN(sizeof(system_utsname.nodename))
-#define NLM_netobj_sz          1+QUADLEN(XDR_MAX_NETOBJ)
-/* #define NLM_owner_sz                1+QUADLEN(NLM_MAXOWNER) */
-#define NLM_fhandle_sz         1+QUADLEN(NFS2_FHSIZE)
+#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_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
 
@@ -543,7 +546,9 @@ 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_bufsiz    = MAX(NLM_##argtype##_sz, NLM_##restype##_sz) << 2,        \
+       .p_statidx   = NLMPROC_##proc,                                  \
+       .p_name      = #proc,                                           \
        }
 
 static struct rpc_procinfo     nlm_procedures[] = {
@@ -599,8 +604,37 @@ 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,
 };
 
+#ifdef RPC_DEBUG
+const char *nlmdbg_cookie2a(const struct nlm_cookie *cookie)
+{
+       /*
+        * We can get away with a static buffer because we're only
+        * called with BKL held.
+        */
+       static char buf[2*NLM_MAXCOOKIELEN+1];
+       int i;
+       int len = sizeof(buf);
+       char *p = buf;
+
+       len--;  /* allow for trailing \0 */
+       if (len < 3)
+               return "???";
+       for (i = 0 ; i < cookie->len ; i++) {
+               if (len < 2) {
+                       strcpy(p-3, "...");
+                       break;
+               }
+               sprintf(p, "%02x", cookie->data[i]);
+               p += 2;
+               len -= 2;
+       }
+       *p = '\0';
+
+       return buf;
+}
+#endif