Merge branch 'for-3.5' of git://linux-nfs.org/~bfields/linux
authorLinus Torvalds <torvalds@linux-foundation.org>
Fri, 1 Jun 2012 15:32:58 +0000 (08:32 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 1 Jun 2012 15:32:58 +0000 (08:32 -0700)
Pull the rest of the nfsd commits from Bruce Fields:
 "... and then I cherry-picked the remainder of the patches from the
  head of my previous branch"

This is the rest of the original nfsd branch, rebased without the
delegation stuff that I thought really needed to be redone.

I don't like rebasing things like this in general, but in this situation
this was the lesser of two evils.

* 'for-3.5' of git://linux-nfs.org/~bfields/linux: (50 commits)
  nfsd4: fix, consolidate client_has_state
  nfsd4: don't remove rebooted client record until confirmation
  nfsd4: remove some dprintk's and a comment
  nfsd4: return "real" sequence id in confirmed case
  nfsd4: fix exchange_id to return confirm flag
  nfsd4: clarify that renewing expired client is a bug
  nfsd4: simpler ordering of setclientid_confirm checks
  nfsd4: setclientid: remove pointless assignment
  nfsd4: fix error return in non-matching-creds case
  nfsd4: fix setclientid_confirm same_cred check
  nfsd4: merge 3 setclientid cases to 2
  nfsd4: pull out common code from setclientid cases
  nfsd4: merge last two setclientid cases
  nfsd4: setclientid/confirm comment cleanup
  nfsd4: setclientid remove unnecessary terms from a logical expression
  nfsd4: move rq_flavor into svc_cred
  nfsd4: stricter cred comparison for setclientid/exchange_id
  nfsd4: move principal name into svc_cred
  nfsd4: allow removing clients not holding state
  nfsd4: rearrange exchange_id logic to simplify
  ...

1  2 
fs/nfsd/auth.c
fs/nfsd/nfs4recover.c
fs/nfsd/nfs4state.c
fs/nfsd/nfs4xdr.c
net/sunrpc/auth_gss/svcauth_gss.c
net/sunrpc/rpcb_clnt.c
net/sunrpc/svc.c
net/sunrpc/svc_xprt.c
net/sunrpc/svcauth_unix.c

diff --combined fs/nfsd/auth.c
index 204438cc914ea522b83907aaf618bb0dbcfa4068,b42eaf3aac160faedaf207863b2501393c702761..34a10d78b839f4c73b3d851e19820bc712129f36
@@@ -1,7 -1,6 +1,7 @@@
  /* Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> */
  
  #include <linux/sched.h>
 +#include <linux/user_namespace.h>
  #include "nfsd.h"
  #include "auth.h"
  
@@@ -11,7 -10,7 +11,7 @@@ int nfsexp_flags(struct svc_rqst *rqstp
        struct exp_flavor_info *end = exp->ex_flavors + exp->ex_nflavors;
  
        for (f = exp->ex_flavors; f < end; f++) {
-               if (f->pseudoflavor == rqstp->rq_flavor)
+               if (f->pseudoflavor == rqstp->rq_cred.cr_flavor)
                        return f->flags;
        }
        return exp->ex_flags;
@@@ -57,8 -56,8 +57,8 @@@ int nfsd_setuser(struct svc_rqst *rqstp
                        goto oom;
  
                for (i = 0; i < rqgi->ngroups; i++) {
 -                      if (!GROUP_AT(rqgi, i))
 -                              GROUP_AT(gi, i) = exp->ex_anon_gid;
 +                      if (gid_eq(GLOBAL_ROOT_GID, GROUP_AT(rqgi, i)))
 +                              GROUP_AT(gi, i) = make_kgid(&init_user_ns, exp->ex_anon_gid);
                        else
                                GROUP_AT(gi, i) = GROUP_AT(rqgi, i);
                }
diff --combined fs/nfsd/nfs4recover.c
index ed3f9206a0ee87c914f133492f1f6011775bdef8,260d8c8f691b8a99c0674b0d148384996fde1399..5ff0b7b9fc08f22f39cc1f2d83062baceb773bdc
@@@ -570,14 -570,14 +570,14 @@@ static ssize_
  cld_pipe_downcall(struct file *filp, const char __user *src, size_t mlen)
  {
        struct cld_upcall *tmp, *cup;
-       struct cld_msg *cmsg = (struct cld_msg *)src;
+       struct cld_msg __user *cmsg = (struct cld_msg __user *)src;
        uint32_t xid;
        struct nfsd_net *nn = net_generic(filp->f_dentry->d_sb->s_fs_info,
                                                nfsd_net_id);
        struct cld_net *cn = nn->cld_net;
  
        if (mlen != sizeof(*cmsg)) {
 -              dprintk("%s: got %lu bytes, expected %lu\n", __func__, mlen,
 +              dprintk("%s: got %zu bytes, expected %zu\n", __func__, mlen,
                        sizeof(*cmsg));
                return -EINVAL;
        }
@@@ -1029,7 -1029,7 +1029,7 @@@ rpc_pipefs_event(struct notifier_block 
        return ret;
  }
  
- struct notifier_block nfsd4_cld_block = {
+ static struct notifier_block nfsd4_cld_block = {
        .notifier_call = rpc_pipefs_event,
  };
  
diff --combined fs/nfsd/nfs4state.c
index 03f82c0bc35d725b7b460a9ef0ef93fd80409e38,0a6901d453499e09cc2201fd6da909d5bed3ffb9..8fdc9ec5c5d359f8defb2766e710eb35fc08c3b0
@@@ -42,6 -42,7 +42,7 @@@
  #include <linux/sunrpc/clnt.h>
  #include "xdr4.h"
  #include "vfs.h"
+ #include "current_stateid.h"
  
  #define NFSDDBG_FACILITY                NFSDDBG_PROC
  
@@@ -447,37 -448,69 +448,69 @@@ static struct list_head close_lru
   *
   * which we should reject.
   */
- static void
set_access(unsigned int *access, unsigned long bmap) {
+ static unsigned int
bmap_to_share_mode(unsigned long bmap) {
        int i;
+       unsigned int access = 0;
  
-       *access = 0;
        for (i = 1; i < 4; i++) {
                if (test_bit(i, &bmap))
-                       *access |= i;
+                       access |= i;
        }
+       return access;
  }
  
- static void
- set_deny(unsigned int *deny, unsigned long bmap) {
-       int i;
-       *deny = 0;
-       for (i = 0; i < 4; i++) {
-               if (test_bit(i, &bmap))
-                       *deny |= i ;
-       }
- }
- static int
+ static bool
  test_share(struct nfs4_ol_stateid *stp, struct nfsd4_open *open) {
        unsigned int access, deny;
  
-       set_access(&access, stp->st_access_bmap);
-       set_deny(&deny, stp->st_deny_bmap);
+       access = bmap_to_share_mode(stp->st_access_bmap);
+       deny = bmap_to_share_mode(stp->st_deny_bmap);
        if ((access & open->op_share_deny) || (deny & open->op_share_access))
-               return 0;
-       return 1;
+               return false;
+       return true;
+ }
+ /* set share access for a given stateid */
+ static inline void
+ set_access(u32 access, struct nfs4_ol_stateid *stp)
+ {
+       __set_bit(access, &stp->st_access_bmap);
+ }
+ /* clear share access for a given stateid */
+ static inline void
+ clear_access(u32 access, struct nfs4_ol_stateid *stp)
+ {
+       __clear_bit(access, &stp->st_access_bmap);
+ }
+ /* test whether a given stateid has access */
+ static inline bool
+ test_access(u32 access, struct nfs4_ol_stateid *stp)
+ {
+       return test_bit(access, &stp->st_access_bmap);
+ }
+ /* set share deny for a given stateid */
+ static inline void
+ set_deny(u32 access, struct nfs4_ol_stateid *stp)
+ {
+       __set_bit(access, &stp->st_deny_bmap);
+ }
+ /* clear share deny for a given stateid */
+ static inline void
+ clear_deny(u32 access, struct nfs4_ol_stateid *stp)
+ {
+       __clear_bit(access, &stp->st_deny_bmap);
+ }
+ /* test whether a given stateid is denying specific access */
+ static inline bool
+ test_deny(u32 access, struct nfs4_ol_stateid *stp)
+ {
+       return test_bit(access, &stp->st_deny_bmap);
  }
  
  static int nfs4_access_to_omode(u32 access)
        BUG();
  }
  
+ /* release all access and file references for a given stateid */
+ static void
+ release_all_access(struct nfs4_ol_stateid *stp)
+ {
+       int i;
+       for (i = 1; i < 4; i++) {
+               if (test_access(i, stp))
+                       nfs4_file_put_access(stp->st_file,
+                                            nfs4_access_to_omode(i));
+               clear_access(i, stp);
+       }
+ }
  static void unhash_generic_stateid(struct nfs4_ol_stateid *stp)
  {
        list_del(&stp->st_perfile);
  
  static void close_generic_stateid(struct nfs4_ol_stateid *stp)
  {
-       int i;
-       if (stp->st_access_bmap) {
-               for (i = 1; i < 4; i++) {
-                       if (test_bit(i, &stp->st_access_bmap))
-                               nfs4_file_put_access(stp->st_file,
-                                               nfs4_access_to_omode(i));
-                       __clear_bit(i, &stp->st_access_bmap);
-               }
-       }
+       release_all_access(stp);
        put_nfs4_file(stp->st_file);
        stp->st_file = NULL;
  }
@@@ -885,7 -923,7 +923,7 @@@ static struct nfsd4_session *alloc_init
        struct nfsd4_session *new;
        struct nfsd4_channel_attrs *fchan = &cses->fore_channel;
        int numslots, slotsize;
-       int status;
+       __be32 status;
        int idx;
  
        /*
@@@ -984,7 -1022,8 +1022,8 @@@ static inline voi
  renew_client_locked(struct nfs4_client *clp)
  {
        if (is_client_expired(clp)) {
-               dprintk("%s: client (clientid %08x/%08x) already expired\n",
+               WARN_ON(1);
+               printk("%s: client (clientid %08x/%08x) already expired\n",
                        __func__,
                        clp->cl_clientid.cl_boot,
                        clp->cl_clientid.cl_id);
@@@ -1049,9 -1088,7 +1088,7 @@@ free_client(struct nfs4_client *clp
                list_del(&ses->se_perclnt);
                nfsd4_put_session_locked(ses);
        }
-       if (clp->cl_cred.cr_group_info)
-               put_group_info(clp->cl_cred.cr_group_info);
-       kfree(clp->cl_principal);
+       free_svc_cred(&clp->cl_cred);
        kfree(clp->cl_name.data);
        kfree(clp);
  }
@@@ -1132,12 -1169,21 +1169,21 @@@ static void copy_clid(struct nfs4_clien
        target->cl_clientid.cl_id = source->cl_clientid.cl_id; 
  }
  
- static void copy_cred(struct svc_cred *target, struct svc_cred *source)
+ static int copy_cred(struct svc_cred *target, struct svc_cred *source)
  {
+       if (source->cr_principal) {
+               target->cr_principal =
+                               kstrdup(source->cr_principal, GFP_KERNEL);
+               if (target->cr_principal == NULL)
+                       return -ENOMEM;
+       } else
+               target->cr_principal = NULL;
+       target->cr_flavor = source->cr_flavor;
        target->cr_uid = source->cr_uid;
        target->cr_gid = source->cr_gid;
        target->cr_group_info = source->cr_group_info;
        get_group_info(target->cr_group_info);
+       return 0;
  }
  
  static int same_name(const char *n1, const char *n2)
@@@ -1157,11 -1203,31 +1203,31 @@@ same_clid(clientid_t *cl1, clientid_t *
        return (cl1->cl_boot == cl2->cl_boot) && (cl1->cl_id == cl2->cl_id);
  }
  
- /* XXX what about NGROUP */
+ static bool groups_equal(struct group_info *g1, struct group_info *g2)
+ {
+       int i;
+       if (g1->ngroups != g2->ngroups)
+               return false;
+       for (i=0; i<g1->ngroups; i++)
+               if (GROUP_AT(g1, i) != GROUP_AT(g2, i))
+                       return false;
+       return true;
+ }
  static int
  same_creds(struct svc_cred *cr1, struct svc_cred *cr2)
  {
-       return cr1->cr_uid == cr2->cr_uid;
+       if ((cr1->cr_flavor != cr2->cr_flavor)
+               || (cr1->cr_uid != cr2->cr_uid)
+               || (cr1->cr_gid != cr2->cr_gid)
+               || !groups_equal(cr1->cr_group_info, cr2->cr_group_info))
+               return false;
+       if (cr1->cr_principal == cr2->cr_principal)
+               return true;
+       if (!cr1->cr_principal || !cr2->cr_principal)
+               return false;
+       return 0 == strcmp(cr1->cr_principal, cr1->cr_principal);
  }
  
  static void gen_clid(struct nfs4_client *clp)
@@@ -1204,25 -1270,20 +1270,20 @@@ static struct nfs4_client *create_clien
  {
        struct nfs4_client *clp;
        struct sockaddr *sa = svc_addr(rqstp);
-       char *princ;
+       int ret;
  
        clp = alloc_client(name);
        if (clp == NULL)
                return NULL;
  
        INIT_LIST_HEAD(&clp->cl_sessions);
-       princ = svc_gss_principal(rqstp);
-       if (princ) {
-               clp->cl_principal = kstrdup(princ, GFP_KERNEL);
-               if (clp->cl_principal == NULL) {
-                       spin_lock(&client_lock);
-                       free_client(clp);
-                       spin_unlock(&client_lock);
-                       return NULL;
-               }
+       ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred);
+       if (ret) {
+               spin_lock(&client_lock);
+               free_client(clp);
+               spin_unlock(&client_lock);
+               return NULL;
        }
        idr_init(&clp->cl_stateids);
        memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
        atomic_set(&clp->cl_refcount, 0);
        rpc_init_wait_queue(&clp->cl_cb_waitq, "Backchannel slot table");
        copy_verf(clp, verf);
        rpc_copy_addr((struct sockaddr *) &clp->cl_addr, sa);
-       clp->cl_flavor = rqstp->rq_flavor;
-       copy_cred(&clp->cl_cred, &rqstp->rq_cred);
        gen_confirm(clp);
        clp->cl_cb_session = NULL;
        return clp;
@@@ -1470,18 -1529,32 +1529,32 @@@ nfsd4_set_ex_flags(struct nfs4_client *
        clid->flags = new->cl_exchange_flags;
  }
  
+ static bool client_has_state(struct nfs4_client *clp)
+ {
+       /*
+        * Note clp->cl_openowners check isn't quite right: there's no
+        * need to count owners without stateid's.
+        *
+        * Also note we should probably be using this in 4.0 case too.
+        */
+       return !list_empty(&clp->cl_openowners)
+               || !list_empty(&clp->cl_delegations)
+               || !list_empty(&clp->cl_sessions);
+ }
  __be32
  nfsd4_exchange_id(struct svc_rqst *rqstp,
                  struct nfsd4_compound_state *cstate,
                  struct nfsd4_exchange_id *exid)
  {
        struct nfs4_client *unconf, *conf, *new;
-       int status;
+       __be32 status;
        unsigned int            strhashval;
        char                    dname[HEXDIR_LEN];
        char                    addr_str[INET6_ADDRSTRLEN];
        nfs4_verifier           verf = exid->verifier;
        struct sockaddr         *sa = svc_addr(rqstp);
+       bool    update = exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A;
  
        rpc_ntop(sa, addr_str, sizeof(addr_str));
        dprintk("%s rqstp=%p exid=%p clname.len=%u clname.data=%p "
        status = nfs4_make_rec_clidname(dname, &exid->clname);
  
        if (status)
-               goto error;
+               return status;
  
        strhashval = clientstr_hashval(dname);
  
+       /* Cases below refer to rfc 5661 section 18.35.4: */
        nfs4_lock_state();
-       status = nfs_ok;
        conf = find_confirmed_client_by_str(dname, strhashval);
        if (conf) {
-               if (!clp_used_exchangeid(conf)) {
-                       status = nfserr_clid_inuse; /* XXX: ? */
-                       goto out;
-               }
-               if (!same_verf(&verf, &conf->cl_verifier)) {
-                       /* 18.35.4 case 8 */
-                       if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) {
+               bool creds_match = same_creds(&conf->cl_cred, &rqstp->rq_cred);
+               bool verfs_match = same_verf(&verf, &conf->cl_verifier);
+               if (update) {
+                       if (!clp_used_exchangeid(conf)) { /* buggy client */
+                               status = nfserr_inval;
+                               goto out;
+                       }
+                       if (!creds_match) { /* case 9 */
+                               status = nfserr_perm;
+                               goto out;
+                       }
+                       if (!verfs_match) { /* case 8 */
                                status = nfserr_not_same;
                                goto out;
                        }
-                       /* Client reboot: destroy old state */
-                       expire_client(conf);
-                       goto out_new;
+                       /* case 6 */
+                       exid->flags |= EXCHGID4_FLAG_CONFIRMED_R;
+                       new = conf;
+                       goto out_copy;
                }
-               if (!same_creds(&conf->cl_cred, &rqstp->rq_cred)) {
-                       /* 18.35.4 case 9 */
-                       if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) {
-                               status = nfserr_perm;
+               if (!creds_match) { /* case 3 */
+                       if (client_has_state(conf)) {
+                               status = nfserr_clid_inuse;
                                goto out;
                        }
                        expire_client(conf);
                        goto out_new;
                }
-               /*
-                * Set bit when the owner id and verifier map to an already
-                * confirmed client id (18.35.3).
-                */
-               exid->flags |= EXCHGID4_FLAG_CONFIRMED_R;
-               /*
-                * Falling into 18.35.4 case 2, possible router replay.
-                * Leave confirmed record intact and return same result.
-                */
-               copy_verf(conf, &verf);
-               new = conf;
-               goto out_copy;
+               if (verfs_match) { /* case 2 */
+                       conf->cl_exchange_flags |= EXCHGID4_FLAG_CONFIRMED_R;
+                       new = conf;
+                       goto out_copy;
+               }
+               /* case 5, client reboot */
+               goto out_new;
        }
  
-       /* 18.35.4 case 7 */
-       if (exid->flags & EXCHGID4_FLAG_UPD_CONFIRMED_REC_A) {
+       if (update) { /* case 7 */
                status = nfserr_noent;
                goto out;
        }
  
        unconf  = find_unconfirmed_client_by_str(dname, strhashval);
-       if (unconf) {
-               /*
-                * Possible retry or client restart.  Per 18.35.4 case 4,
-                * a new unconfirmed record should be generated regardless
-                * of whether any properties have changed.
-                */
+       if (unconf) /* case 4, possible retry or client restart */
                expire_client(unconf);
-       }
  
+       /* case 1 (normal case) */
  out_new:
-       /* Normal case */
        new = create_client(exid->clname, dname, rqstp, &verf);
        if (new == NULL) {
                status = nfserr_jukebox;
@@@ -1584,7 -1649,7 +1649,7 @@@ out_copy
        exid->clientid.cl_boot = new->cl_clientid.cl_boot;
        exid->clientid.cl_id = new->cl_clientid.cl_id;
  
-       exid->seqid = 1;
+       exid->seqid = new->cl_cs_slot.sl_seqid + 1;
        nfsd4_set_ex_flags(new, exid);
  
        dprintk("nfsd4_exchange_id seqid %d flags %x\n",
  
  out:
        nfs4_unlock_state();
- error:
-       dprintk("nfsd4_exchange_id returns %d\n", ntohl(status));
        return status;
  }
  
- static int
+ static __be32
  check_slot_seqid(u32 seqid, u32 slot_seqid, int slot_inuse)
  {
        dprintk("%s enter. seqid %d slot_seqid %d\n", __func__, seqid,
   */
  static void
  nfsd4_cache_create_session(struct nfsd4_create_session *cr_ses,
-                          struct nfsd4_clid_slot *slot, int nfserr)
+                          struct nfsd4_clid_slot *slot, __be32 nfserr)
  {
        slot->sl_status = nfserr;
        memcpy(&slot->sl_cr_ses, cr_ses, sizeof(*cr_ses));
@@@ -1657,7 -1720,7 +1720,7 @@@ nfsd4_replay_create_session(struct nfsd
                                /* seqid, slotID, slotID, slotID, status */ \
                        5 ) * sizeof(__be32))
  
- static __be32 check_forechannel_attrs(struct nfsd4_channel_attrs fchannel)
+ static bool check_forechannel_attrs(struct nfsd4_channel_attrs fchannel)
  {
        return fchannel.maxreq_sz < NFSD_MIN_REQ_HDR_SEQ_SZ
                || fchannel.maxresp_sz < NFSD_MIN_RESP_HDR_SEQ_SZ;
@@@ -1673,7 -1736,7 +1736,7 @@@ nfsd4_create_session(struct svc_rqst *r
        struct nfsd4_session *new;
        struct nfsd4_clid_slot *cs_slot = NULL;
        bool confirm_me = false;
-       int status = 0;
+       __be32 status = 0;
  
        if (cr_ses->flags & ~SESSION4_FLAG_MASK_A)
                return nfserr_inval;
                cs_slot = &conf->cl_cs_slot;
                status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0);
                if (status == nfserr_replay_cache) {
-                       dprintk("Got a create_session replay! seqid= %d\n",
-                               cs_slot->sl_seqid);
-                       /* Return the cached reply status */
                        status = nfsd4_replay_create_session(cr_ses, cs_slot);
                        goto out;
                } else if (cr_ses->seqid != cs_slot->sl_seqid + 1) {
                        status = nfserr_seq_misordered;
-                       dprintk("Sequence misordered!\n");
-                       dprintk("Expected seqid= %d but got seqid= %d\n",
-                               cs_slot->sl_seqid, cr_ses->seqid);
                        goto out;
                }
        } else if (unconf) {
                        status = nfserr_clid_inuse;
                        goto out;
                }
                cs_slot = &unconf->cl_cs_slot;
                status = check_slot_seqid(cr_ses->seqid, cs_slot->sl_seqid, 0);
                if (status) {
                        status = nfserr_seq_misordered;
                        goto out;
                }
                confirm_me = true;
                conf = unconf;
        } else {
  
        /* cache solo and embedded create sessions under the state lock */
        nfsd4_cache_create_session(cr_ses, cs_slot, status);
-       if (confirm_me)
+       if (confirm_me) {
+               unsigned int hash = clientstr_hashval(unconf->cl_recdir);
+               struct nfs4_client *old =
+                       find_confirmed_client_by_str(conf->cl_recdir, hash);
+               if (old)
+                       expire_client(old);
                move_to_confirmed(conf);
+       }
  out:
        nfs4_unlock_state();
        dprintk("%s returns %d\n", __func__, ntohl(status));
@@@ -1818,7 -1879,7 +1879,7 @@@ nfsd4_destroy_session(struct svc_rqst *
                      struct nfsd4_destroy_session *sessionid)
  {
        struct nfsd4_session *ses;
-       u32 status = nfserr_badsession;
+       __be32 status = nfserr_badsession;
  
        /* Notes:
         * - The confirmed nfs4_client->cl_sessionid holds destroyed sessinid
@@@ -1914,7 -1975,7 +1975,7 @@@ nfsd4_sequence(struct svc_rqst *rqstp
        struct nfsd4_session *session;
        struct nfsd4_slot *slot;
        struct nfsd4_conn *conn;
-       int status;
+       __be32 status;
  
        if (resp->opcnt != 1)
                return nfserr_sequence_pos;
        return status;
  }
  
- static inline bool has_resources(struct nfs4_client *clp)
- {
-       return !list_empty(&clp->cl_openowners)
-               || !list_empty(&clp->cl_delegations)
-               || !list_empty(&clp->cl_sessions);
- }
  __be32
  nfsd4_destroy_clientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_destroy_clientid *dc)
  {
        struct nfs4_client *conf, *unconf, *clp;
-       int status = 0;
+       __be32 status = 0;
  
        nfs4_lock_state();
        unconf = find_unconfirmed_client(&dc->clientid);
        if (conf) {
                clp = conf;
  
-               if (!is_client_expired(conf) && has_resources(conf)) {
+               if (!is_client_expired(conf) && client_has_state(conf)) {
                        status = nfserr_clientid_busy;
                        goto out;
                }
@@@ -2055,7 -2109,7 +2109,7 @@@ out
  __be32
  nfsd4_reclaim_complete(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_reclaim_complete *rc)
  {
-       int status = 0;
+       __be32 status = 0;
  
        if (rc->rca_one_fs) {
                if (!cstate->current_fh.fh_dentry)
@@@ -2106,17 -2160,13 +2160,13 @@@ nfsd4_setclientid(struct svc_rqst *rqst
        if (status)
                return status;
  
-       /* 
-        * XXX The Duplicate Request Cache (DRC) has been checked (??)
-        * We get here on a DRC miss.
-        */
        strhashval = clientstr_hashval(dname);
  
+       /* Cases below refer to rfc 3530 section 14.2.33: */
        nfs4_lock_state();
        conf = find_confirmed_client_by_str(dname, strhashval);
        if (conf) {
-               /* RFC 3530 14.2.33 CASE 0: */
+               /* case 0: */
                status = nfserr_clid_inuse;
                if (clp_used_exchangeid(conf))
                        goto out;
                        goto out;
                }
        }
-       /*
-        * section 14.2.33 of RFC 3530 (under the heading "IMPLEMENTATION")
-        * has a description of SETCLIENTID request processing consisting
-        * of 5 bullet points, labeled as CASE0 - CASE4 below.
-        */
        unconf = find_unconfirmed_client_by_str(dname, strhashval);
+       if (unconf)
+               expire_client(unconf);
        status = nfserr_jukebox;
-       if (!conf) {
-               /*
-                * RFC 3530 14.2.33 CASE 4:
-                * placed first, because it is the normal case
-                */
-               if (unconf)
-                       expire_client(unconf);
-               new = create_client(clname, dname, rqstp, &clverifier);
-               if (new == NULL)
-                       goto out;
-               gen_clid(new);
-       } else if (same_verf(&conf->cl_verifier, &clverifier)) {
-               /*
-                * RFC 3530 14.2.33 CASE 1:
-                * probable callback update
-                */
-               if (unconf) {
-                       /* Note this is removing unconfirmed {*x***},
-                        * which is stronger than RFC recommended {vxc**}.
-                        * This has the advantage that there is at most
-                        * one {*x***} in either list at any time.
-                        */
-                       expire_client(unconf);
-               }
-               new = create_client(clname, dname, rqstp, &clverifier);
-               if (new == NULL)
-                       goto out;
+       new = create_client(clname, dname, rqstp, &clverifier);
+       if (new == NULL)
+               goto out;
+       if (conf && same_verf(&conf->cl_verifier, &clverifier))
+               /* case 1: probable callback update */
                copy_clid(new, conf);
-       } else if (!unconf) {
-               /*
-                * RFC 3530 14.2.33 CASE 2:
-                * probable client reboot; state will be removed if
-                * confirmed.
-                */
-               new = create_client(clname, dname, rqstp, &clverifier);
-               if (new == NULL)
-                       goto out;
+       else /* case 4 (new client) or cases 2, 3 (client reboot): */
                gen_clid(new);
-       } else {
-               /*
-                * RFC 3530 14.2.33 CASE 3:
-                * probable client reboot; state will be removed if
-                * confirmed.
-                */
-               expire_client(unconf);
-               new = create_client(clname, dname, rqstp, &clverifier);
-               if (new == NULL)
-                       goto out;
-               gen_clid(new);
-       }
        /*
         * XXX: we should probably set this at creation time, and check
         * for consistent minorversion use throughout:
  }
  
  
- /*
-  * Section 14.2.34 of RFC 3530 (under the heading "IMPLEMENTATION") has
-  * a description of SETCLIENTID_CONFIRM request processing consisting of 4
-  * bullets, labeled as CASE1 - CASE4 below.
-  */
  __be32
  nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
                         struct nfsd4_compound_state *cstate,
                         struct nfsd4_setclientid_confirm *setclientid_confirm)
  {
-       struct sockaddr *sa = svc_addr(rqstp);
        struct nfs4_client *conf, *unconf;
        nfs4_verifier confirm = setclientid_confirm->sc_confirm; 
        clientid_t * clid = &setclientid_confirm->sc_clientid;
  
        if (STALE_CLIENTID(clid))
                return nfserr_stale_clientid;
-       /* 
-        * XXX The Duplicate Request Cache (DRC) has been checked (??)
-        * We get here on a DRC miss.
-        */
        nfs4_lock_state();
  
        conf = find_confirmed_client(clid);
        unconf = find_unconfirmed_client(clid);
-       status = nfserr_clid_inuse;
-       if (conf && !rpc_cmp_addr((struct sockaddr *) &conf->cl_addr, sa))
-               goto out;
-       if (unconf && !rpc_cmp_addr((struct sockaddr *) &unconf->cl_addr, sa))
-               goto out;
        /*
-        * section 14.2.34 of RFC 3530 has a description of
-        * SETCLIENTID_CONFIRM request processing consisting
-        * of 4 bullet points, labeled as CASE1 - CASE4 below.
+        * We try hard to give out unique clientid's, so if we get an
+        * attempt to confirm the same clientid with a different cred,
+        * there's a bug somewhere.  Let's charitably assume it's our
+        * bug.
         */
-       if (conf && unconf && same_verf(&confirm, &unconf->cl_confirm)) {
-               /*
-                * RFC 3530 14.2.34 CASE 1:
-                * callback update
-                */
-               if (!same_creds(&conf->cl_cred, &unconf->cl_cred))
-                       status = nfserr_clid_inuse;
-               else {
-                       nfsd4_change_callback(conf, &unconf->cl_cb_conn);
-                       nfsd4_probe_callback(conf);
-                       expire_client(unconf);
+       status = nfserr_serverfault;
+       if (unconf && !same_creds(&unconf->cl_cred, &rqstp->rq_cred))
+               goto out;
+       if (conf && !same_creds(&conf->cl_cred, &rqstp->rq_cred))
+               goto out;
+       /* cases below refer to rfc 3530 section 14.2.34: */
+       if (!unconf || !same_verf(&confirm, &unconf->cl_confirm)) {
+               if (conf && !unconf) /* case 2: probable retransmit */
                        status = nfs_ok;
+               else /* case 4: client hasn't noticed we rebooted yet? */
+                       status = nfserr_stale_clientid;
+               goto out;
+       }
+       status = nfs_ok;
+       if (conf) { /* case 1: callback update */
+               nfsd4_change_callback(conf, &unconf->cl_cb_conn);
+               nfsd4_probe_callback(conf);
+               expire_client(unconf);
+       } else { /* case 3: normal case; new or rebooted client */
+               unsigned int hash = clientstr_hashval(unconf->cl_recdir);
  
+               conf = find_confirmed_client_by_str(unconf->cl_recdir, hash);
+               if (conf) {
+                       nfsd4_client_record_remove(conf);
+                       expire_client(conf);
                }
-       } else if (conf && !unconf) {
-               /*
-                * RFC 3530 14.2.34 CASE 2:
-                * probable retransmitted request; play it safe and
-                * do nothing.
-                */
-               if (!same_creds(&conf->cl_cred, &rqstp->rq_cred))
-                       status = nfserr_clid_inuse;
-               else
-                       status = nfs_ok;
-       } else if (!conf && unconf
-                       && same_verf(&unconf->cl_confirm, &confirm)) {
-               /*
-                * RFC 3530 14.2.34 CASE 3:
-                * Normal case; new or rebooted client:
-                */
-               if (!same_creds(&unconf->cl_cred, &rqstp->rq_cred)) {
-                       status = nfserr_clid_inuse;
-               } else {
-                       unsigned int hash =
-                               clientstr_hashval(unconf->cl_recdir);
-                       conf = find_confirmed_client_by_str(unconf->cl_recdir,
-                                                           hash);
-                       if (conf) {
-                               nfsd4_client_record_remove(conf);
-                               expire_client(conf);
-                       }
-                       move_to_confirmed(unconf);
-                       conf = unconf;
-                       nfsd4_probe_callback(conf);
-                       status = nfs_ok;
-               }
-       } else if ((!conf || (conf && !same_verf(&conf->cl_confirm, &confirm)))
-           && (!unconf || (unconf && !same_verf(&unconf->cl_confirm,
-                                                               &confirm)))) {
-               /*
-                * RFC 3530 14.2.34 CASE 4:
-                * Client probably hasn't noticed that we rebooted yet.
-                */
-               status = nfserr_stale_clientid;
-       } else {
-               /* check that we have hit one of the cases...*/
-               status = nfserr_clid_inuse;
+               move_to_confirmed(unconf);
+               nfsd4_probe_callback(unconf);
        }
  out:
        nfs4_unlock_state();
@@@ -2454,8 -2413,8 +2413,8 @@@ static void init_open_stateid(struct nf
        stp->st_file = fp;
        stp->st_access_bmap = 0;
        stp->st_deny_bmap = 0;
-       __set_bit(open->op_share_access, &stp->st_access_bmap);
-       __set_bit(open->op_share_deny, &stp->st_deny_bmap);
+       set_access(open->op_share_access, stp);
+       set_deny(open->op_share_deny, stp);
        stp->st_openstp = NULL;
  }
  
@@@ -2534,8 -2493,8 +2493,8 @@@ nfs4_share_conflict(struct svc_fh *curr
        ret = nfserr_locked;
        /* Search for conflicting share reservations */
        list_for_each_entry(stp, &fp->fi_stateids, st_perfile) {
-               if (test_bit(deny_type, &stp->st_deny_bmap) ||
-                   test_bit(NFS4_SHARE_DENY_BOTH, &stp->st_deny_bmap))
+               if (test_deny(deny_type, stp) ||
+                   test_deny(NFS4_SHARE_DENY_BOTH, stp))
                        goto out;
        }
        ret = nfs_ok;
@@@ -2791,7 -2750,7 +2750,7 @@@ nfs4_upgrade_open(struct svc_rqst *rqst
        bool new_access;
        __be32 status;
  
-       new_access = !test_bit(op_share_access, &stp->st_access_bmap);
+       new_access = !test_access(op_share_access, stp);
        if (new_access) {
                status = nfs4_get_vfs_file(rqstp, fp, cur_fh, open);
                if (status)
                return status;
        }
        /* remember the open */
-       __set_bit(op_share_access, &stp->st_access_bmap);
-       __set_bit(open->op_share_deny, &stp->st_deny_bmap);
+       set_access(op_share_access, stp);
+       set_deny(open->op_share_deny, stp);
  
        return nfs_ok;
  }
@@@ -3282,18 -3241,18 +3241,18 @@@ STALE_STATEID(stateid_t *stateid
  }
  
  static inline int
- access_permit_read(unsigned long access_bmap)
+ access_permit_read(struct nfs4_ol_stateid *stp)
  {
-       return test_bit(NFS4_SHARE_ACCESS_READ, &access_bmap) ||
-               test_bit(NFS4_SHARE_ACCESS_BOTH, &access_bmap) ||
-               test_bit(NFS4_SHARE_ACCESS_WRITE, &access_bmap);
+       return test_access(NFS4_SHARE_ACCESS_READ, stp) ||
+               test_access(NFS4_SHARE_ACCESS_BOTH, stp) ||
+               test_access(NFS4_SHARE_ACCESS_WRITE, stp);
  }
  
  static inline int
- access_permit_write(unsigned long access_bmap)
+ access_permit_write(struct nfs4_ol_stateid *stp)
  {
-       return test_bit(NFS4_SHARE_ACCESS_WRITE, &access_bmap) ||
-               test_bit(NFS4_SHARE_ACCESS_BOTH, &access_bmap);
+       return test_access(NFS4_SHARE_ACCESS_WRITE, stp) ||
+               test_access(NFS4_SHARE_ACCESS_BOTH, stp);
  }
  
  static
@@@ -3304,9 -3263,9 +3263,9 @@@ __be32 nfs4_check_openmode(struct nfs4_
        /* For lock stateid's, we test the parent open, not the lock: */
        if (stp->st_openstp)
                stp = stp->st_openstp;
-       if ((flags & WR_STATE) && (!access_permit_write(stp->st_access_bmap)))
+       if ((flags & WR_STATE) && !access_permit_write(stp))
                  goto out;
-       if ((flags & RD_STATE) && (!access_permit_read(stp->st_access_bmap)))
+       if ((flags & RD_STATE) && !access_permit_read(stp))
                  goto out;
        status = nfs_ok;
  out:
@@@ -3346,7 -3305,7 +3305,7 @@@ static bool stateid_generation_after(st
        return (s32)a->si_generation - (s32)b->si_generation > 0;
  }
  
- static int check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)
+ static __be32 check_stateid_generation(stateid_t *in, stateid_t *ref, bool has_session)
  {
        /*
         * When sessions are used the stateid generation number is ignored
  
  static inline void nfs4_stateid_downgrade_bit(struct nfs4_ol_stateid *stp, u32 access)
  {
-       if (!test_bit(access, &stp->st_access_bmap))
+       if (!test_access(access, stp))
                return;
        nfs4_file_put_access(stp->st_file, nfs4_access_to_omode(access));
-       __clear_bit(access, &stp->st_access_bmap);
+       clear_access(access, stp);
  }
  
  static inline void nfs4_stateid_downgrade(struct nfs4_ol_stateid *stp, u32 to_access)
  }
  
  static void
- reset_union_bmap_deny(unsigned long deny, unsigned long *bmap)
+ reset_union_bmap_deny(unsigned long deny, struct nfs4_ol_stateid *stp)
  {
        int i;
        for (i = 0; i < 4; i++) {
                if ((i & deny) != i)
-                       __clear_bit(i, bmap);
+                       clear_deny(i, stp);
        }
  }
  
@@@ -3712,19 -3671,19 +3671,19 @@@ nfsd4_open_downgrade(struct svc_rqst *r
        if (status)
                goto out; 
        status = nfserr_inval;
-       if (!test_bit(od->od_share_access, &stp->st_access_bmap)) {
-               dprintk("NFSD:access not a subset current bitmap: 0x%lx, input access=%08x\n",
+       if (!test_access(od->od_share_access, stp)) {
+               dprintk("NFSD: access not a subset current bitmap: 0x%lx, input access=%08x\n",
                        stp->st_access_bmap, od->od_share_access);
                goto out;
        }
-       if (!test_bit(od->od_share_deny, &stp->st_deny_bmap)) {
+       if (!test_deny(od->od_share_deny, stp)) {
                dprintk("NFSD:deny not a subset current bitmap: 0x%lx, input deny=%08x\n",
                        stp->st_deny_bmap, od->od_share_deny);
                goto out;
        }
        nfs4_stateid_downgrade(stp, od->od_share_access);
  
-       reset_union_bmap_deny(od->od_share_deny, &stp->st_deny_bmap);
+       reset_union_bmap_deny(od->od_share_deny, stp);
  
        update_stateid(&stp->st_stid.sc_stateid);
        memcpy(&od->od_stateid, &stp->st_stid.sc_stateid, sizeof(stateid_t));
@@@ -4014,13 -3973,13 +3973,13 @@@ static void get_lock_access(struct nfs4
        struct nfs4_file *fp = lock_stp->st_file;
        int oflag = nfs4_access_to_omode(access);
  
-       if (test_bit(access, &lock_stp->st_access_bmap))
+       if (test_access(access, lock_stp))
                return;
        nfs4_file_get_access(fp, oflag);
-       __set_bit(access, &lock_stp->st_access_bmap);
+       set_access(access, lock_stp);
  }
  
- __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *ost, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new)
static __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, struct nfs4_ol_stateid *ost, struct nfsd4_lock *lock, struct nfs4_ol_stateid **lst, bool *new)
  {
        struct nfs4_file *fi = ost->st_file;
        struct nfs4_openowner *oo = openowner(ost->st_stateowner);
   * vfs_test_lock.  (Arguably perhaps test_lock should be done with an
   * inode operation.)
   */
 -static int nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
 +static __be32 nfsd_test_lock(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file_lock *lock)
  {
        struct file *file;
 -      int err;
 -
 -      err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file);
 -      if (err)
 -              return err;
 -      err = vfs_test_lock(file, lock);
 -      nfsd_close(file);
 +      __be32 err = nfsd_open(rqstp, fhp, S_IFREG, NFSD_MAY_READ, &file);
 +      if (!err) {
 +              err = nfserrno(vfs_test_lock(file, lock));
 +              nfsd_close(file);
 +      }
        return err;
  }
  
@@@ -4236,6 -4197,7 +4195,6 @@@ nfsd4_lockt(struct svc_rqst *rqstp, str
        struct inode *inode;
        struct file_lock file_lock;
        struct nfs4_lockowner *lo;
 -      int error;
        __be32 status;
  
        if (locks_in_grace())
  
        nfs4_transform_lock_offset(&file_lock);
  
 -      status = nfs_ok;
 -      error = nfsd_test_lock(rqstp, &cstate->current_fh, &file_lock);
 -      if (error) {
 -              status = nfserrno(error);
 +      status = nfsd_test_lock(rqstp, &cstate->current_fh, &file_lock);
 +      if (status)
                goto out;
 -      }
 +
        if (file_lock.fl_type != F_UNLCK) {
                status = nfserr_denied;
                nfs4_set_lock_denied(&file_lock, &lockt->lt_denied);
diff --combined fs/nfsd/nfs4xdr.c
index 74c00bc92b9af6b01e95e55c119b90d61fbf9d34,30817e9f1bb7af374a5c0baf8fddbdf2e70f9aae..4949667c84ea0c3d687a46faf0a455c410c39b6f
@@@ -1392,7 -1392,7 +1392,7 @@@ nfsd4_decode_test_stateid(struct nfsd4_
        for (i = 0; i < test_stateid->ts_num_ids; i++) {
                stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);
                if (!stateid) {
 -                      status = PTR_ERR(stateid);
 +                      status = nfserrno(-ENOMEM);
                        goto out;
                }
  
@@@ -1674,12 -1674,12 +1674,12 @@@ nfsd4_decode_compound(struct nfsd4_comp
  
  static void write32(__be32 **p, u32 n)
  {
-       *(*p)++ = n;
+       *(*p)++ = htonl(n);
  }
  
  static void write64(__be32 **p, u64 n)
  {
-       write32(p, (u32)(n >> 32));
+       write32(p, (n >> 32));
        write32(p, (u32)n);
  }
  
@@@ -1744,15 -1744,16 +1744,16 @@@ static void encode_seqid_op_tail(struc
  }
  
  /* Encode as an array of strings the string given with components
-  * separated @sep.
+  * separated @sep, escaped with esc_enter and esc_exit.
   */
- static __be32 nfsd4_encode_components(char sep, char *components,
-                                  __be32 **pp, int *buflen)
+ static __be32 nfsd4_encode_components_esc(char sep, char *components,
+                                  __be32 **pp, int *buflen,
+                                  char esc_enter, char esc_exit)
  {
        __be32 *p = *pp;
        __be32 *countp = p;
        int strlen, count=0;
-       char *str, *end;
+       char *str, *end, *next;
  
        dprintk("nfsd4_encode_components(%s)\n", components);
        if ((*buflen -= 4) < 0)
        WRITE32(0); /* We will fill this in with @count later */
        end = str = components;
        while (*end) {
-               for (; *end && (*end != sep); end++)
-                       ; /* Point to end of component */
+               bool found_esc = false;
+               /* try to parse as esc_start, ..., esc_end, sep */
+               if (*str == esc_enter) {
+                       for (; *end && (*end != esc_exit); end++)
+                               /* find esc_exit or end of string */;
+                       next = end + 1;
+                       if (*end && (!*next || *next == sep)) {
+                               str++;
+                               found_esc = true;
+                       }
+               }
+               if (!found_esc)
+                       for (; *end && (*end != sep); end++)
+                               /* find sep or end of string */;
                strlen = end - str;
                if (strlen) {
                        if ((*buflen -= ((XDR_QUADLEN(strlen) << 2) + 4)) < 0)
        return 0;
  }
  
+ /* Encode as an array of strings the string given with components
+  * separated @sep.
+  */
+ static __be32 nfsd4_encode_components(char sep, char *components,
+                                  __be32 **pp, int *buflen)
+ {
+       return nfsd4_encode_components_esc(sep, components, pp, buflen, 0, 0);
+ }
  /*
   * encode a location element of a fs_locations structure
   */
@@@ -1789,7 -1814,8 +1814,8 @@@ static __be32 nfsd4_encode_fs_location4
        __be32 status;
        __be32 *p = *pp;
  
-       status = nfsd4_encode_components(':', location->hosts, &p, buflen);
+       status = nfsd4_encode_components_esc(':', location->hosts, &p, buflen,
+                                               '[', ']');
        if (status)
                return status;
        status = nfsd4_encode_components('/', location->path, &p, buflen);
@@@ -3251,7 -3277,7 +3277,7 @@@ nfsd4_encode_write(struct nfsd4_compoun
  }
  
  static __be32
- nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, int nfserr,
+ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
                         struct nfsd4_exchange_id *exid)
  {
        __be32 *p;
  }
  
  static __be32
- nfsd4_encode_create_session(struct nfsd4_compoundres *resp, int nfserr,
+ nfsd4_encode_create_session(struct nfsd4_compoundres *resp, __be32 nfserr,
                            struct nfsd4_create_session *sess)
  {
        __be32 *p;
  }
  
  static __be32
- nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, int nfserr,
+ nfsd4_encode_destroy_session(struct nfsd4_compoundres *resp, __be32 nfserr,
                             struct nfsd4_destroy_session *destroy_session)
  {
        return nfserr;
  }
  
  static __be32
- nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, int nfserr,
+ nfsd4_encode_free_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
                          struct nfsd4_free_stateid *free_stateid)
  {
        __be32 *p;
                return nfserr;
  
        RESERVE_SPACE(4);
-       WRITE32(nfserr);
+       *p++ = nfserr;
        ADJUST_ARGS();
        return nfserr;
  }
  
  static __be32
- nfsd4_encode_sequence(struct nfsd4_compoundres *resp, int nfserr,
+ nfsd4_encode_sequence(struct nfsd4_compoundres *resp, __be32 nfserr,
                      struct nfsd4_sequence *seq)
  {
        __be32 *p;
        return 0;
  }
  
- __be32
- nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, int nfserr,
static __be32
+ nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, __be32 nfserr,
                          struct nfsd4_test_stateid *test_stateid)
  {
        struct nfsd4_test_stateid_id *stateid, *next;
        *p++ = htonl(test_stateid->ts_num_ids);
  
        list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
 -              *p++ = htonl(stateid->ts_id_status);
 +              *p++ = stateid->ts_id_status;
        }
  
        ADJUST_ARGS();
@@@ -3503,7 -3529,7 +3529,7 @@@ static nfsd4_enc nfsd4_enc_ops[] = 
   * Our se_fmaxresp_cached will always be a multiple of PAGE_SIZE, and so
   * will be at least a page and will therefore hold the xdr_buf head.
   */
int nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
__be32 nfsd4_check_resp_size(struct nfsd4_compoundres *resp, u32 pad)
  {
        struct xdr_buf *xb = &resp->rqstp->rq_res;
        struct nfsd4_session *session = NULL;
index 3089de37c433157cd45cff21974e0a242743c715,bcb773781ec08cbf0a2f00a4034126bfffc7e1cb..73e95738660042e7a9d4e7cb252143ec74078265
@@@ -41,7 -41,6 +41,7 @@@
  #include <linux/types.h>
  #include <linux/module.h>
  #include <linux/pagemap.h>
 +#include <linux/user_namespace.h>
  
  #include <linux/sunrpc/auth_gss.h>
  #include <linux/sunrpc/gss_err.h>
@@@ -336,7 -335,6 +336,6 @@@ struct rsc 
        struct svc_cred         cred;
        struct gss_svc_seq_data seqdata;
        struct gss_ctx          *mechctx;
-       char                    *client_name;
  };
  
  static struct rsc *rsc_update(struct cache_detail *cd, struct rsc *new, struct rsc *old);
@@@ -347,9 -345,7 +346,7 @@@ static void rsc_free(struct rsc *rsci
        kfree(rsci->handle.data);
        if (rsci->mechctx)
                gss_delete_sec_context(&rsci->mechctx);
-       if (rsci->cred.cr_group_info)
-               put_group_info(rsci->cred.cr_group_info);
-       kfree(rsci->client_name);
+       free_svc_cred(&rsci->cred);
  }
  
  static void rsc_put(struct kref *ref)
@@@ -387,7 -383,7 +384,7 @@@ rsc_init(struct cache_head *cnew, struc
        tmp->handle.data = NULL;
        new->mechctx = NULL;
        new->cred.cr_group_info = NULL;
-       new->client_name = NULL;
+       new->cred.cr_principal = NULL;
  }
  
  static void
@@@ -402,8 -398,8 +399,8 @@@ update_rsc(struct cache_head *cnew, str
        spin_lock_init(&new->seqdata.sd_lock);
        new->cred = tmp->cred;
        tmp->cred.cr_group_info = NULL;
-       new->client_name = tmp->client_name;
-       tmp->client_name = NULL;
+       new->cred.cr_principal = tmp->cred.cr_principal;
+       tmp->cred.cr_principal = NULL;
  }
  
  static struct cache_head *
@@@ -471,13 -467,9 +468,13 @@@ static int rsc_parse(struct cache_detai
                status = -EINVAL;
                for (i=0; i<N; i++) {
                        gid_t gid;
 +                      kgid_t kgid;
                        if (get_int(&mesg, &gid))
                                goto out;
 -                      GROUP_AT(rsci.cred.cr_group_info, i) = gid;
 +                      kgid = make_kgid(&init_user_ns, gid);
 +                      if (!gid_valid(kgid))
 +                              goto out;
 +                      GROUP_AT(rsci.cred.cr_group_info, i) = kgid;
                }
  
                /* mech name */
                /* get client name */
                len = qword_get(&mesg, buf, mlen);
                if (len > 0) {
-                       rsci.client_name = kstrdup(buf, GFP_KERNEL);
-                       if (!rsci.client_name)
+                       rsci.cred.cr_principal = kstrdup(buf, GFP_KERNEL);
+                       if (!rsci.cred.cr_principal)
                                goto out;
                }
  
@@@ -932,16 -924,6 +929,6 @@@ struct gss_svc_data 
        struct rsc                      *rsci;
  };
  
- char *svc_gss_principal(struct svc_rqst *rqstp)
- {
-       struct gss_svc_data *gd = (struct gss_svc_data *)rqstp->rq_auth_data;
-       if (gd && gd->rsci)
-               return gd->rsci->client_name;
-       return NULL;
- }
- EXPORT_SYMBOL_GPL(svc_gss_principal);
  static int
  svcauth_gss_set_client(struct svc_rqst *rqstp)
  {
@@@ -1220,7 -1202,7 +1207,7 @@@ svcauth_gss_accept(struct svc_rqst *rqs
                }
                svcdata->rsci = rsci;
                cache_get(&rsci->h);
-               rqstp->rq_flavor = gss_svc_to_pseudoflavor(
+               rqstp->rq_cred.cr_flavor = gss_svc_to_pseudoflavor(
                                        rsci->mechctx->mech_type, gc->gc_svc);
                ret = SVC_OK;
                goto out;
diff --combined net/sunrpc/rpcb_clnt.c
index 3c0653439f3dc398031301d53819c3b6e78bc4ef,4c38b33ab8a8969fe1f9aef626ddd230a4b1eb29..92509ffe15fcacce5de331cbb205a84c4f718a86
@@@ -180,14 -180,16 +180,16 @@@ void rpcb_put_local(struct net *net
        struct sunrpc_net *sn = net_generic(net, sunrpc_net_id);
        struct rpc_clnt *clnt = sn->rpcb_local_clnt;
        struct rpc_clnt *clnt4 = sn->rpcb_local_clnt4;
-       int shutdown;
+       int shutdown = 0;
  
        spin_lock(&sn->rpcb_clnt_lock);
-       if (--sn->rpcb_users == 0) {
-               sn->rpcb_local_clnt = NULL;
-               sn->rpcb_local_clnt4 = NULL;
+       if (sn->rpcb_users) {
+               if (--sn->rpcb_users == 0) {
+                       sn->rpcb_local_clnt = NULL;
+                       sn->rpcb_local_clnt4 = NULL;
+               }
+               shutdown = !sn->rpcb_users;
        }
-       shutdown = !sn->rpcb_users;
        spin_unlock(&sn->rpcb_clnt_lock);
  
        if (shutdown) {
@@@ -394,7 -396,6 +396,7 @@@ static int rpcb_register_call(struct rp
  
  /**
   * rpcb_register - set or unset a port registration with the local rpcbind svc
 + * @net: target network namespace
   * @prog: RPC program number to bind
   * @vers: RPC version number to bind
   * @prot: transport protocol to register
@@@ -522,7 -523,6 +524,7 @@@ static int rpcb_unregister_all_protofam
  
  /**
   * rpcb_v4_register - set or unset a port registration with the local rpcbind
 + * @net: target network namespace
   * @program: RPC program number of service to (un)register
   * @version: RPC version number of service to (un)register
   * @address: address family, IP address, and port to (un)register
diff --combined net/sunrpc/svc.c
index 017c0117d1543a784dfe5130396c74f80879131a,b7210f5cc8934fd35dfa302134a86098b8f78dbf..7e9baaa1e543e55878dcb0d9bd0378a0e51754e0
@@@ -407,6 -407,14 +407,14 @@@ static int svc_uses_rpcbind(struct svc_
        return 0;
  }
  
+ int svc_bind(struct svc_serv *serv, struct net *net)
+ {
+       if (!svc_uses_rpcbind(serv))
+               return 0;
+       return svc_rpcb_setup(serv, net);
+ }
+ EXPORT_SYMBOL_GPL(svc_bind);
  /*
   * Create an RPC service
   */
@@@ -471,15 -479,8 +479,8 @@@ __svc_create(struct svc_program *prog, 
                spin_lock_init(&pool->sp_lock);
        }
  
-       if (svc_uses_rpcbind(serv)) {
-               if (svc_rpcb_setup(serv, current->nsproxy->net_ns) < 0) {
-                       kfree(serv->sv_pools);
-                       kfree(serv);
-                       return NULL;
-               }
-               if (!serv->sv_shutdown)
-                       serv->sv_shutdown = svc_rpcb_cleanup;
-       }
+       if (svc_uses_rpcbind(serv) && (!serv->sv_shutdown))
+               serv->sv_shutdown = svc_rpcb_cleanup;
  
        return serv;
  }
@@@ -536,8 -537,6 +537,6 @@@ EXPORT_SYMBOL_GPL(svc_shutdown_net)
  void
  svc_destroy(struct svc_serv *serv)
  {
-       struct net *net = current->nsproxy->net_ns;
        dprintk("svc: svc_destroy(%s, %d)\n",
                                serv->sv_program->pg_name,
                                serv->sv_nrthreads);
  
        del_timer_sync(&serv->sv_temptimer);
  
-       svc_shutdown_net(serv, net);
        /*
         * The last user is gone and thus all sockets have to be destroyed to
         * the point. Check this.
@@@ -1041,21 -1038,23 +1038,21 @@@ static void svc_unregister(const struc
   * Printk the given error with the address of the client that caused it.
   */
  static __printf(2, 3)
 -int svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
 +void svc_printk(struct svc_rqst *rqstp, const char *fmt, ...)
  {
 +      struct va_format vaf;
        va_list args;
 -      int     r;
        char    buf[RPC_MAX_ADDRBUFLEN];
  
 -      if (!net_ratelimit())
 -              return 0;
 +      va_start(args, fmt);
  
 -      printk(KERN_WARNING "svc: %s: ",
 -              svc_print_addr(rqstp, buf, sizeof(buf)));
 +      vaf.fmt = fmt;
 +      vaf.va = &args;
  
 -      va_start(args, fmt);
 -      r = vprintk(fmt, args);
 -      va_end(args);
 +      net_warn_ratelimited("svc: %s: %pV",
 +                           svc_print_addr(rqstp, buf, sizeof(buf)), &vaf);
  
 -      return r;
 +      va_end(args);
  }
  
  /*
diff --combined net/sunrpc/svc_xprt.c
index b98ee35149121602b42ace9365bfd5f21e84767a,37a1f664d108a37898a3a9d1aefad4b7ed2061e9..88f2bf671960d444e73d3d9eba2998f75ac2885b
@@@ -544,11 -544,14 +544,11 @@@ static void svc_check_conn_limits(struc
                struct svc_xprt *xprt = NULL;
                spin_lock_bh(&serv->sv_lock);
                if (!list_empty(&serv->sv_tempsocks)) {
 -                      if (net_ratelimit()) {
 -                              /* Try to help the admin */
 -                              printk(KERN_NOTICE "%s: too many open  "
 -                                     "connections, consider increasing %s\n",
 -                                     serv->sv_name, serv->sv_maxconn ?
 -                                     "the max number of connections." :
 -                                     "the number of threads.");
 -                      }
 +                      /* Try to help the admin */
 +                      net_notice_ratelimited("%s: too many open connections, consider increasing the %s\n",
 +                                             serv->sv_name, serv->sv_maxconn ?
 +                                             "max number of connections" :
 +                                             "number of threads");
                        /*
                         * Always select the oldest connection. It's not fair,
                         * but so is life
@@@ -598,6 -601,7 +598,7 @@@ int svc_recv(struct svc_rqst *rqstp, lo
  
        /* now allocate needed pages.  If we get a failure, sleep briefly */
        pages = (serv->sv_max_mesg + PAGE_SIZE) / PAGE_SIZE;
+       BUG_ON(pages >= RPCSVC_MAXPAGES);
        for (i = 0; i < pages ; i++)
                while (rqstp->rq_pages[i] == NULL) {
                        struct page *p = alloc_page(GFP_KERNEL);
                        rqstp->rq_pages[i] = p;
                }
        rqstp->rq_pages[i++] = NULL; /* this might be seen in nfs_read_actor */
-       BUG_ON(pages >= RPCSVC_MAXPAGES);
  
        /* Make arg->head point to first page and arg->pages point to rest */
        arg = &rqstp->rq_arg;
@@@ -973,7 -976,7 +973,7 @@@ void svc_close_net(struct svc_serv *ser
        svc_clear_pools(serv, net);
        /*
         * At this point the sp_sockets lists will stay empty, since
-        * svc_enqueue will not add new entries without taking the
+        * svc_xprt_enqueue will not add new entries without taking the
         * sp_lock and checking XPT_BUSY.
         */
        svc_clear_list(&serv->sv_tempsocks, net);
index 6138c925923d00715cb8695ebd2cfbb719287699,88962cf343774a8c7f8e723ce944f60c62eac060..2777fa896645de3f063aa5ad67cb054bbb75a894
@@@ -14,7 -14,6 +14,7 @@@
  #include <net/sock.h>
  #include <net/ipv6.h>
  #include <linux/kernel.h>
 +#include <linux/user_namespace.h>
  #define RPCDBG_FACILITY       RPCDBG_AUTH
  
  #include <linux/sunrpc/clnt.h>
@@@ -526,15 -525,11 +526,15 @@@ static int unix_gid_parse(struct cache_
  
        for (i = 0 ; i < gids ; i++) {
                int gid;
 +              kgid_t kgid;
                rv = get_int(&mesg, &gid);
                err = -EINVAL;
                if (rv)
                        goto out;
 -              GROUP_AT(ug.gi, i) = gid;
 +              kgid = make_kgid(&init_user_ns, gid);
 +              if (!gid_valid(kgid))
 +                      goto out;
 +              GROUP_AT(ug.gi, i) = kgid;
        }
  
        ugp = unix_gid_lookup(cd, uid);
@@@ -563,7 -558,6 +563,7 @@@ static int unix_gid_show(struct seq_fil
                         struct cache_detail *cd,
                         struct cache_head *h)
  {
 +      struct user_namespace *user_ns = current_user_ns();
        struct unix_gid *ug;
        int i;
        int glen;
  
        seq_printf(m, "%u %d:", ug->uid, glen);
        for (i = 0; i < glen; i++)
 -              seq_printf(m, " %d", GROUP_AT(ug->gi, i));
 +              seq_printf(m, " %d", from_kgid_munged(user_ns, GROUP_AT(ug->gi, i)));
        seq_printf(m, "\n");
        return 0;
  }
@@@ -746,6 -740,7 +746,7 @@@ svcauth_null_accept(struct svc_rqst *rq
        struct svc_cred *cred = &rqstp->rq_cred;
  
        cred->cr_group_info = NULL;
+       cred->cr_principal = NULL;
        rqstp->rq_client = NULL;
  
        if (argv->iov_len < 3*4)
        svc_putnl(resv, RPC_AUTH_NULL);
        svc_putnl(resv, 0);
  
-       rqstp->rq_flavor = RPC_AUTH_NULL;
+       rqstp->rq_cred.cr_flavor = RPC_AUTH_NULL;
        return SVC_OK;
  }
  
@@@ -811,6 -806,7 +812,7 @@@ svcauth_unix_accept(struct svc_rqst *rq
        int             len   = argv->iov_len;
  
        cred->cr_group_info = NULL;
+       cred->cr_principal = NULL;
        rqstp->rq_client = NULL;
  
        if ((len -= 3*4) < 0)
        cred->cr_group_info = groups_alloc(slen);
        if (cred->cr_group_info == NULL)
                return SVC_CLOSE;
 -      for (i = 0; i < slen; i++)
 -              GROUP_AT(cred->cr_group_info, i) = svc_getnl(argv);
 +      for (i = 0; i < slen; i++) {
 +              kgid_t kgid = make_kgid(&init_user_ns, svc_getnl(argv));
 +              if (!gid_valid(kgid))
 +                      goto badcred;
 +              GROUP_AT(cred->cr_group_info, i) = kgid;
 +      }
        if (svc_getu32(argv) != htonl(RPC_AUTH_NULL) || svc_getu32(argv) != 0) {
                *authp = rpc_autherr_badverf;
                return SVC_DENIED;
        svc_putnl(resv, RPC_AUTH_NULL);
        svc_putnl(resv, 0);
  
-       rqstp->rq_flavor = RPC_AUTH_UNIX;
+       rqstp->rq_cred.cr_flavor = RPC_AUTH_UNIX;
        return SVC_OK;
  
  badcred: