nfsd: make client_lock per net
[pandora-kernel.git] / fs / nfsd / nfs4state.c
index d40e57b..0e7e174 100644 (file)
@@ -176,8 +176,6 @@ static unsigned int ownerstr_hashval(u32 clientid, struct xdr_netobj *ownername)
        return ret & OWNER_HASH_MASK;
 }
 
-static struct list_head        ownerstr_hashtbl[OWNER_HASH_SIZE];
-
 /* hash table for nfs4_file */
 #define FILE_HASH_BITS                   8
 #define FILE_HASH_SIZE                  (1 << FILE_HASH_BITS)
@@ -192,7 +190,7 @@ static struct list_head file_hashtbl[FILE_HASH_SIZE];
 
 static void __nfs4_file_get_access(struct nfs4_file *fp, int oflag)
 {
-       BUG_ON(!(fp->fi_fds[oflag] || fp->fi_fds[O_RDWR]));
+       WARN_ON_ONCE(!(fp->fi_fds[oflag] || fp->fi_fds[O_RDWR]));
        atomic_inc(&fp->fi_access[oflag]);
 }
 
@@ -251,7 +249,7 @@ static inline int get_new_stid(struct nfs4_stid *stid)
         * preallocations that can exist at a time, but the state lock
         * prevents anyone from using ours before we get here:
         */
-       BUG_ON(error);
+       WARN_ON_ONCE(error);
        /*
         * It shouldn't be a problem to reuse an opaque stateid value.
         * I don't think it is for 4.1.  But with 4.0 I worry that, for
@@ -390,9 +388,6 @@ unhash_delegation(struct nfs4_delegation *dp)
  * SETCLIENTID state 
  */
 
-/* client_lock protects the client lru list and session hash table */
-static DEFINE_SPINLOCK(client_lock);
-
 static unsigned int clientid_hashval(u32 id)
 {
        return id & CLIENT_HASH_MASK;
@@ -403,23 +398,6 @@ static unsigned int clientstr_hashval(const char *name)
        return opaque_hashval(name, 8) & CLIENT_HASH_MASK;
 }
 
-/*
- * unconf_id_hashtbl[] and unconf_name_tree hold unconfirmed
- * setclientid info.
- *
- * client_lru holds client queue ordered by nfs4_client.cl_time
- * for lease renewal.
- *
- * close_lru holds (open) stateowner queue ordered by nfs4_stateowner.so_time
- * for last close replay.
- *
- * All of the above fields are protected by the client_mutex.
- */
-static struct list_head        unconf_id_hashtbl[CLIENT_HASH_SIZE];
-static struct rb_root unconf_name_tree;
-static struct list_head client_lru;
-static struct list_head close_lru;
-
 /*
  * We store the NONE, READ, WRITE, and BOTH bits separately in the
  * st_{access,deny}_bmap field of the stateid, in order to track not
@@ -513,7 +491,8 @@ static int nfs4_access_to_omode(u32 access)
        case NFS4_SHARE_ACCESS_BOTH:
                return O_RDWR;
        }
-       BUG();
+       WARN_ON_ONCE(1);
+       return O_RDONLY;
 }
 
 /* release all access and file references for a given stateid */
@@ -639,9 +618,6 @@ static void release_openowner(struct nfs4_openowner *oo)
        nfs4_free_openowner(oo);
 }
 
-#define SESSION_HASH_SIZE      512
-static struct list_head sessionid_hashtbl[SESSION_HASH_SIZE];
-
 static inline int
 hash_sessionid(struct nfs4_sessionid *sessionid)
 {
@@ -893,18 +869,23 @@ static void __free_session(struct nfsd4_session *ses)
 static void free_session(struct kref *kref)
 {
        struct nfsd4_session *ses;
+       struct nfsd_net *nn;
 
-       lockdep_assert_held(&client_lock);
        ses = container_of(kref, struct nfsd4_session, se_ref);
+       nn = net_generic(ses->se_client->net, nfsd_net_id);
+
+       lockdep_assert_held(&nn->client_lock);
        nfsd4_del_conns(ses);
        __free_session(ses);
 }
 
 void nfsd4_put_session(struct nfsd4_session *ses)
 {
-       spin_lock(&client_lock);
+       struct nfsd_net *nn = net_generic(ses->se_client->net, nfsd_net_id);
+
+       spin_lock(&nn->client_lock);
        nfsd4_put_session_locked(ses);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 }
 
 static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fchan)
@@ -935,6 +916,7 @@ static struct nfsd4_session *alloc_session(struct nfsd4_channel_attrs *fchan)
 static void init_session(struct svc_rqst *rqstp, struct nfsd4_session *new, struct nfs4_client *clp, struct nfsd4_create_session *cses)
 {
        int idx;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        new->se_client = clp;
        gen_sessionid(new);
@@ -947,12 +929,12 @@ static void init_session(struct svc_rqst *rqstp, struct nfsd4_session *new, stru
        new->se_cb_sec = cses->cb_sec;
        kref_init(&new->se_ref);
        idx = hash_sessionid(&new->se_sessionid);
-       spin_lock(&client_lock);
-       list_add(&new->se_hash, &sessionid_hashtbl[idx]);
+       spin_lock(&nn->client_lock);
+       list_add(&new->se_hash, &nn->sessionid_hashtbl[idx]);
        spin_lock(&clp->cl_lock);
        list_add(&new->se_perclnt, &clp->cl_sessions);
        spin_unlock(&clp->cl_lock);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 
        if (cses->flags & SESSION4_BACK_CHAN) {
                struct sockaddr *sa = svc_addr(rqstp);
@@ -970,15 +952,16 @@ static void init_session(struct svc_rqst *rqstp, struct nfsd4_session *new, stru
 
 /* caller must hold client_lock */
 static struct nfsd4_session *
-find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid)
+find_in_sessionid_hashtbl(struct nfs4_sessionid *sessionid, struct net *net)
 {
        struct nfsd4_session *elem;
        int idx;
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
        dump_sessionid(__func__, sessionid);
        idx = hash_sessionid(sessionid);
        /* Search in the appropriate list */
-       list_for_each_entry(elem, &sessionid_hashtbl[idx], se_hash) {
+       list_for_each_entry(elem, &nn->sessionid_hashtbl[idx], se_hash) {
                if (!memcmp(elem->se_sessionid.data, sessionid->data,
                            NFS4_MAX_SESSIONID_LEN)) {
                        return elem;
@@ -1003,6 +986,8 @@ unhash_session(struct nfsd4_session *ses)
 static inline void
 renew_client_locked(struct nfs4_client *clp)
 {
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
        if (is_client_expired(clp)) {
                WARN_ON(1);
                printk("%s: client (clientid %08x/%08x) already expired\n",
@@ -1015,16 +1000,18 @@ renew_client_locked(struct nfs4_client *clp)
        dprintk("renewing client (clientid %08x/%08x)\n", 
                        clp->cl_clientid.cl_boot, 
                        clp->cl_clientid.cl_id);
-       list_move_tail(&clp->cl_lru, &client_lru);
+       list_move_tail(&clp->cl_lru, &nn->client_lru);
        clp->cl_time = get_seconds();
 }
 
 static inline void
 renew_client(struct nfs4_client *clp)
 {
-       spin_lock(&client_lock);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+       spin_lock(&nn->client_lock);
        renew_client_locked(clp);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 }
 
 /* SETCLIENTID and SETCLIENTID_CONFIRM Helper functions */
@@ -1062,7 +1049,9 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
 static inline void
 free_client(struct nfs4_client *clp)
 {
-       lockdep_assert_held(&client_lock);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+       lockdep_assert_held(&nn->client_lock);
        while (!list_empty(&clp->cl_sessions)) {
                struct nfsd4_session *ses;
                ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
@@ -1079,15 +1068,16 @@ void
 release_session_client(struct nfsd4_session *session)
 {
        struct nfs4_client *clp = session->se_client;
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
 
-       if (!atomic_dec_and_lock(&clp->cl_refcount, &client_lock))
+       if (!atomic_dec_and_lock(&clp->cl_refcount, &nn->client_lock))
                return;
        if (is_client_expired(clp)) {
                free_client(clp);
                session->se_client = NULL;
        } else
                renew_client_locked(clp);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 }
 
 /* must be called under the client_lock */
@@ -1135,12 +1125,12 @@ destroy_client(struct nfs4_client *clp)
        if (test_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags))
                rb_erase(&clp->cl_namenode, &nn->conf_name_tree);
        else
-               rb_erase(&clp->cl_namenode, &unconf_name_tree);
-       spin_lock(&client_lock);
+               rb_erase(&clp->cl_namenode, &nn->unconf_name_tree);
+       spin_lock(&nn->client_lock);
        unhash_client_locked(clp);
        if (atomic_read(&clp->cl_refcount) == 0)
                free_client(clp);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 }
 
 static void expire_client(struct nfs4_client *clp)
@@ -1291,6 +1281,7 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
        struct sockaddr *sa = svc_addr(rqstp);
        int ret;
        struct net *net = SVC_NET(rqstp);
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
        clp = alloc_client(name);
        if (clp == NULL)
@@ -1299,9 +1290,9 @@ static struct nfs4_client *create_client(struct xdr_netobj name,
        INIT_LIST_HEAD(&clp->cl_sessions);
        ret = copy_cred(&clp->cl_cred, &rqstp->rq_cred);
        if (ret) {
-               spin_lock(&client_lock);
+               spin_lock(&nn->client_lock);
                free_client(clp);
-               spin_unlock(&client_lock);
+               spin_unlock(&nn->client_lock);
                return NULL;
        }
        idr_init(&clp->cl_stateids);
@@ -1369,11 +1360,12 @@ static void
 add_to_unconfirmed(struct nfs4_client *clp)
 {
        unsigned int idhashval;
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
 
        clear_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags);
-       add_clp_to_name_tree(clp, &unconf_name_tree);
+       add_clp_to_name_tree(clp, &nn->unconf_name_tree);
        idhashval = clientid_hashval(clp->cl_clientid.cl_id);
-       list_add(&clp->cl_idhash, &unconf_id_hashtbl[idhashval]);
+       list_add(&clp->cl_idhash, &nn->unconf_id_hashtbl[idhashval]);
        renew_client(clp);
 }
 
@@ -1385,7 +1377,7 @@ move_to_confirmed(struct nfs4_client *clp)
 
        dprintk("NFSD: move_to_confirm nfs4_client %p\n", clp);
        list_move(&clp->cl_idhash, &nn->conf_id_hashtbl[idhashval]);
-       rb_erase(&clp->cl_namenode, &unconf_name_tree);
+       rb_erase(&clp->cl_namenode, &nn->unconf_name_tree);
        add_clp_to_name_tree(clp, &nn->conf_name_tree);
        set_bit(NFSD4_CLIENT_CONFIRMED, &clp->cl_flags);
        renew_client(clp);
@@ -1409,12 +1401,12 @@ find_confirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn)
 }
 
 static struct nfs4_client *
-find_unconfirmed_client(clientid_t *clid, bool sessions)
+find_unconfirmed_client(clientid_t *clid, bool sessions, struct nfsd_net *nn)
 {
        struct nfs4_client *clp;
        unsigned int idhashval = clientid_hashval(clid->cl_id);
 
-       list_for_each_entry(clp, &unconf_id_hashtbl[idhashval], cl_idhash) {
+       list_for_each_entry(clp, &nn->unconf_id_hashtbl[idhashval], cl_idhash) {
                if (same_clid(&clp->cl_clientid, clid)) {
                        if ((bool)clp->cl_minorversion != sessions)
                                return NULL;
@@ -1436,9 +1428,9 @@ find_confirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn)
 }
 
 static struct nfs4_client *
-find_unconfirmed_client_by_name(struct xdr_netobj *name)
+find_unconfirmed_client_by_name(struct xdr_netobj *name, struct nfsd_net *nn)
 {
-       return find_clp_in_name_tree(name, &unconf_name_tree);
+       return find_clp_in_name_tree(name, &nn->unconf_name_tree);
 }
 
 static void
@@ -1622,10 +1614,9 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
        switch (exid->spa_how) {
        case SP4_NONE:
                break;
+       default:                                /* checked by xdr code */
+               WARN_ON_ONCE(1);
        case SP4_SSV:
-               return nfserr_serverfault;
-       default:
-               BUG();                          /* checked by xdr code */
        case SP4_MACH_CRED:
                return nfserr_serverfault;      /* no excuse :-/ */
        }
@@ -1677,7 +1668,7 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
                goto out;
        }
 
-       unconf  = find_unconfirmed_client_by_name(&exid->clname);
+       unconf  = find_unconfirmed_client_by_name(&exid->clname, nn);
        if (unconf) /* case 4, possible retry or client restart */
                expire_client(unconf);
 
@@ -1799,7 +1790,7 @@ nfsd4_create_session(struct svc_rqst *rqstp,
                goto out_free_session;
 
        nfs4_lock_state();
-       unconf = find_unconfirmed_client(&cr_ses->clientid, true);
+       unconf = find_unconfirmed_client(&cr_ses->clientid, true, nn);
        conf = find_confirmed_client(&cr_ses->clientid, true, nn);
 
        if (conf) {
@@ -1890,11 +1881,12 @@ static __be32 nfsd4_map_bcts_dir(u32 *dir)
 __be32 nfsd4_backchannel_ctl(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, struct nfsd4_backchannel_ctl *bc)
 {
        struct nfsd4_session *session = cstate->session;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
-       spin_lock(&client_lock);
+       spin_lock(&nn->client_lock);
        session->se_cb_prog = bc->bc_cb_program;
        session->se_cb_sec = bc->bc_cb_sec;
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 
        nfsd4_probe_callback(session->se_client);
 
@@ -1907,18 +1899,19 @@ __be32 nfsd4_bind_conn_to_session(struct svc_rqst *rqstp,
 {
        __be32 status;
        struct nfsd4_conn *conn;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        if (!nfsd4_last_compound_op(rqstp))
                return nfserr_not_only_op;
-       spin_lock(&client_lock);
-       cstate->session = find_in_sessionid_hashtbl(&bcts->sessionid);
+       spin_lock(&nn->client_lock);
+       cstate->session = find_in_sessionid_hashtbl(&bcts->sessionid, SVC_NET(rqstp));
        /* Sorta weird: we only need the refcnt'ing because new_conn acquires
         * client_lock iself: */
        if (cstate->session) {
                nfsd4_get_session(cstate->session);
                atomic_inc(&cstate->session->se_client->cl_refcount);
        }
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
        if (!cstate->session)
                return nfserr_badsession;
 
@@ -1946,6 +1939,7 @@ nfsd4_destroy_session(struct svc_rqst *r,
 {
        struct nfsd4_session *ses;
        __be32 status = nfserr_badsession;
+       struct nfsd_net *nn = net_generic(SVC_NET(r), nfsd_net_id);
 
        /* Notes:
         * - The confirmed nfs4_client->cl_sessionid holds destroyed sessinid
@@ -1959,24 +1953,24 @@ nfsd4_destroy_session(struct svc_rqst *r,
                        return nfserr_not_only_op;
        }
        dump_sessionid(__func__, &sessionid->sessionid);
-       spin_lock(&client_lock);
-       ses = find_in_sessionid_hashtbl(&sessionid->sessionid);
+       spin_lock(&nn->client_lock);
+       ses = find_in_sessionid_hashtbl(&sessionid->sessionid, SVC_NET(r));
        if (!ses) {
-               spin_unlock(&client_lock);
+               spin_unlock(&nn->client_lock);
                goto out;
        }
 
        unhash_session(ses);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
 
        nfs4_lock_state();
        nfsd4_probe_callback_sync(ses->se_client);
        nfs4_unlock_state();
 
-       spin_lock(&client_lock);
+       spin_lock(&nn->client_lock);
        nfsd4_del_conns(ses);
        nfsd4_put_session_locked(ses);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
        status = nfs_ok;
 out:
        dprintk("%s returns %d\n", __func__, ntohl(status));
@@ -2042,6 +2036,7 @@ nfsd4_sequence(struct svc_rqst *rqstp,
        struct nfsd4_slot *slot;
        struct nfsd4_conn *conn;
        __be32 status;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        if (resp->opcnt != 1)
                return nfserr_sequence_pos;
@@ -2054,9 +2049,9 @@ nfsd4_sequence(struct svc_rqst *rqstp,
        if (!conn)
                return nfserr_jukebox;
 
-       spin_lock(&client_lock);
+       spin_lock(&nn->client_lock);
        status = nfserr_badsession;
-       session = find_in_sessionid_hashtbl(&seq->sessionid);
+       session = find_in_sessionid_hashtbl(&seq->sessionid, SVC_NET(rqstp));
        if (!session)
                goto out;
 
@@ -2130,7 +2125,7 @@ out:
                }
        }
        kfree(conn);
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
        dprintk("%s: return %d\n", __func__, ntohl(status));
        return status;
 }
@@ -2143,7 +2138,7 @@ nfsd4_destroy_clientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *csta
        struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        nfs4_lock_state();
-       unconf = find_unconfirmed_client(&dc->clientid, true);
+       unconf = find_unconfirmed_client(&dc->clientid, true, nn);
        conf = find_confirmed_client(&dc->clientid, true, nn);
 
        if (conf) {
@@ -2239,7 +2234,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                        goto out;
                }
        }
-       unconf = find_unconfirmed_client_by_name(&clname);
+       unconf = find_unconfirmed_client_by_name(&clname, nn);
        if (unconf)
                expire_client(unconf);
        status = nfserr_jukebox;
@@ -2280,7 +2275,7 @@ nfsd4_setclientid_confirm(struct svc_rqst *rqstp,
        nfs4_lock_state();
 
        conf = find_confirmed_client(clid, false, nn);
-       unconf = find_unconfirmed_client(clid, false);
+       unconf = find_unconfirmed_client(clid, false, nn);
        /*
         * We try hard to give out unique clientid's, so if we get an
         * attempt to confirm the same clientid with a different cred,
@@ -2432,7 +2427,9 @@ static inline void *alloc_stateowner(struct kmem_cache *slab, struct xdr_netobj
 
 static void hash_openowner(struct nfs4_openowner *oo, struct nfs4_client *clp, unsigned int strhashval)
 {
-       list_add(&oo->oo_owner.so_strhash, &ownerstr_hashtbl[strhashval]);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
+
+       list_add(&oo->oo_owner.so_strhash, &nn->ownerstr_hashtbl[strhashval]);
        list_add(&oo->oo_perclient, &clp->cl_openowners);
 }
 
@@ -2472,11 +2469,13 @@ static void init_open_stateid(struct nfs4_ol_stateid *stp, struct nfs4_file *fp,
 }
 
 static void
-move_to_close_lru(struct nfs4_openowner *oo)
+move_to_close_lru(struct nfs4_openowner *oo, struct net *net)
 {
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+
        dprintk("NFSD: move_to_close_lru nfs4_openowner %p\n", oo);
 
-       list_move_tail(&oo->oo_close_lru, &close_lru);
+       list_move_tail(&oo->oo_close_lru, &nn->close_lru);
        oo->oo_time = get_seconds();
 }
 
@@ -2490,13 +2489,14 @@ same_owner_str(struct nfs4_stateowner *sop, struct xdr_netobj *owner,
 }
 
 static struct nfs4_openowner *
-find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open, bool sessions)
+find_openstateowner_str(unsigned int hashval, struct nfsd4_open *open,
+                       bool sessions, struct nfsd_net *nn)
 {
        struct nfs4_stateowner *so;
        struct nfs4_openowner *oo;
        struct nfs4_client *clp;
 
-       list_for_each_entry(so, &ownerstr_hashtbl[hashval], so_strhash) {
+       list_for_each_entry(so, &nn->ownerstr_hashtbl[hashval], so_strhash) {
                if (!so->so_is_open_owner)
                        continue;
                if (same_owner_str(so, &open->op_owner, &open->op_clientid)) {
@@ -2632,14 +2632,13 @@ static __be32 nfsd4_check_seqid(struct nfsd4_compound_state *cstate, struct nfs4
 
 __be32
 nfsd4_process_open1(struct nfsd4_compound_state *cstate,
-                   struct nfsd4_open *open)
+                   struct nfsd4_open *open, struct nfsd_net *nn)
 {
        clientid_t *clientid = &open->op_clientid;
        struct nfs4_client *clp = NULL;
        unsigned int strhashval;
        struct nfs4_openowner *oo = NULL;
        __be32 status;
-       struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
 
        if (STALE_CLIENTID(&open->op_clientid, nn))
                return nfserr_stale_clientid;
@@ -2652,7 +2651,7 @@ nfsd4_process_open1(struct nfsd4_compound_state *cstate,
                return nfserr_jukebox;
 
        strhashval = ownerstr_hashval(clientid->cl_id, &open->op_owner);
-       oo = find_openstateowner_str(strhashval, open, cstate->minorversion);
+       oo = find_openstateowner_str(strhashval, open, cstate->minorversion, nn);
        open->op_openowner = oo;
        if (!oo) {
                clp = find_confirmed_client(clientid, cstate->minorversion,
@@ -2925,7 +2924,7 @@ static void nfsd4_open_deleg_none_ext(struct nfsd4_open *open, int status)
                        open->op_why_no_deleg = WND4_CANCELLED;
                        break;
                case NFS4_SHARE_WANT_NO_DELEG:
-                       BUG();  /* not supposed to get here */
+                       WARN_ON_ONCE(1);
                }
        }
 }
@@ -3170,17 +3169,15 @@ out:
 }
 
 static void
-nfsd4_end_grace(struct net *net)
+nfsd4_end_grace(struct nfsd_net *nn)
 {
-       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
-
        /* do nothing if grace period already ended */
        if (nn->grace_ended)
                return;
 
        dprintk("NFSD: end of grace period\n");
        nn->grace_ended = true;
-       nfsd4_record_grace_done(net, nn->boot_time);
+       nfsd4_record_grace_done(nn, nn->boot_time);
        locks_end_grace(&nn->nfsd4_manager);
        /*
         * Now that every NFSv4 client has had the chance to recover and
@@ -3191,7 +3188,7 @@ nfsd4_end_grace(struct net *net)
 }
 
 static time_t
-nfs4_laundromat(void)
+nfs4_laundromat(struct nfsd_net *nn)
 {
        struct nfs4_client *clp;
        struct nfs4_openowner *oo;
@@ -3204,10 +3201,10 @@ nfs4_laundromat(void)
        nfs4_lock_state();
 
        dprintk("NFSD: laundromat service - starting\n");
-       nfsd4_end_grace(&init_net);
+       nfsd4_end_grace(nn);
        INIT_LIST_HEAD(&reaplist);
-       spin_lock(&client_lock);
-       list_for_each_safe(pos, next, &client_lru) {
+       spin_lock(&nn->client_lock);
+       list_for_each_safe(pos, next, &nn->client_lru) {
                clp = list_entry(pos, struct nfs4_client, cl_lru);
                if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) {
                        t = clp->cl_time - cutoff;
@@ -3223,7 +3220,7 @@ nfs4_laundromat(void)
                unhash_client_locked(clp);
                list_add(&clp->cl_lru, &reaplist);
        }
-       spin_unlock(&client_lock);
+       spin_unlock(&nn->client_lock);
        list_for_each_safe(pos, next, &reaplist) {
                clp = list_entry(pos, struct nfs4_client, cl_lru);
                dprintk("NFSD: purging unused client (clientid %08x)\n",
@@ -3247,7 +3244,7 @@ nfs4_laundromat(void)
                unhash_delegation(dp);
        }
        test_val = nfsd4_lease;
-       list_for_each_safe(pos, next, &close_lru) {
+       list_for_each_safe(pos, next, &nn->close_lru) {
                oo = container_of(pos, struct nfs4_openowner, oo_close_lru);
                if (time_after((unsigned long)oo->oo_time, (unsigned long)cutoff)) {
                        u = oo->oo_time - cutoff;
@@ -3265,16 +3262,19 @@ nfs4_laundromat(void)
 
 static struct workqueue_struct *laundry_wq;
 static void laundromat_main(struct work_struct *);
-static DECLARE_DELAYED_WORK(laundromat_work, laundromat_main);
 
 static void
-laundromat_main(struct work_struct *not_used)
+laundromat_main(struct work_struct *laundry)
 {
        time_t t;
+       struct delayed_work *dwork = container_of(laundry, struct delayed_work,
+                                                 work);
+       struct nfsd_net *nn = container_of(dwork, struct nfsd_net,
+                                          laundromat_work);
 
-       t = nfs4_laundromat();
+       t = nfs4_laundromat(nn);
        dprintk("NFSD: laundromat_main - sleeping for %ld seconds\n", t);
-       queue_delayed_work(laundry_wq, &laundromat_work, t*HZ);
+       queue_delayed_work(laundry_wq, &nn->laundromat_work, t*HZ);
 }
 
 static inline __be32 nfs4_check_fh(struct svc_fh *fhp, struct nfs4_ol_stateid *stp)
@@ -3419,10 +3419,11 @@ static __be32 nfsd4_validate_stateid(struct nfs4_client *cl, stateid_t *stateid)
        return nfs_ok;
 }
 
-static __be32 nfsd4_lookup_stateid(stateid_t *stateid, unsigned char typemask, struct nfs4_stid **s, bool sessions)
+static __be32 nfsd4_lookup_stateid(stateid_t *stateid, unsigned char typemask,
+                                  struct nfs4_stid **s, bool sessions,
+                                  struct nfsd_net *nn)
 {
        struct nfs4_client *cl;
-       struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
 
        if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
                return nfserr_bad_stateid;
@@ -3450,6 +3451,7 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
        struct nfs4_delegation *dp = NULL;
        struct svc_fh *current_fh = &cstate->current_fh;
        struct inode *ino = current_fh->fh_dentry->d_inode;
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
        __be32 status;
 
        if (filpp)
@@ -3461,7 +3463,8 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
        if (ZERO_STATEID(stateid) || ONE_STATEID(stateid))
                return check_special_stateids(net, current_fh, stateid, flags);
 
-       status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID, &s, cstate->minorversion);
+       status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID|NFS4_OPEN_STID|NFS4_LOCK_STID,
+                                     &s, cstate->minorversion, nn);
        if (status)
                return status;
        status = check_stateid_generation(stateid, &s->sc_stateid, nfsd4_has_session(cstate));
@@ -3475,7 +3478,11 @@ nfs4_preprocess_stateid_op(struct net *net, struct nfsd4_compound_state *cstate,
                        goto out;
                if (filpp) {
                        *filpp = dp->dl_file->fi_deleg_file;
-                       BUG_ON(!*filpp);
+                       if (!*filpp) {
+                               WARN_ON_ONCE(1);
+                               status = nfserr_serverfault;
+                               goto out;
+                       }
                }
                break;
        case NFS4_OPEN_STID:
@@ -3602,7 +3609,8 @@ static __be32 nfs4_seqid_op_checks(struct nfsd4_compound_state *cstate, stateid_
 static __be32
 nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
                         stateid_t *stateid, char typemask,
-                        struct nfs4_ol_stateid **stpp)
+                        struct nfs4_ol_stateid **stpp,
+                        struct nfsd_net *nn)
 {
        __be32 status;
        struct nfs4_stid *s;
@@ -3611,7 +3619,8 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
                seqid, STATEID_VAL(stateid));
 
        *stpp = NULL;
-       status = nfsd4_lookup_stateid(stateid, typemask, &s, cstate->minorversion);
+       status = nfsd4_lookup_stateid(stateid, typemask, &s,
+                                     cstate->minorversion, nn);
        if (status)
                return status;
        *stpp = openlockstateid(s);
@@ -3620,13 +3629,14 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
        return nfs4_seqid_op_checks(cstate, stateid, seqid, *stpp);
 }
 
-static __be32 nfs4_preprocess_confirmed_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid, stateid_t *stateid, struct nfs4_ol_stateid **stpp)
+static __be32 nfs4_preprocess_confirmed_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
+                                                stateid_t *stateid, struct nfs4_ol_stateid **stpp, struct nfsd_net *nn)
 {
        __be32 status;
        struct nfs4_openowner *oo;
 
        status = nfs4_preprocess_seqid_op(cstate, seqid, stateid,
-                                               NFS4_OPEN_STID, stpp);
+                                               NFS4_OPEN_STID, stpp, nn);
        if (status)
                return status;
        oo = openowner((*stpp)->st_stateowner);
@@ -3642,6 +3652,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        __be32 status;
        struct nfs4_openowner *oo;
        struct nfs4_ol_stateid *stp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        dprintk("NFSD: nfsd4_open_confirm on file %.*s\n",
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3655,7 +3666,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        status = nfs4_preprocess_seqid_op(cstate,
                                        oc->oc_seqid, &oc->oc_req_stateid,
-                                       NFS4_OPEN_STID, &stp);
+                                       NFS4_OPEN_STID, &stp, nn);
        if (status)
                goto out;
        oo = openowner(stp->st_stateowner);
@@ -3698,7 +3709,7 @@ static inline void nfs4_stateid_downgrade(struct nfs4_ol_stateid *stp, u32 to_ac
        case NFS4_SHARE_ACCESS_BOTH:
                break;
        default:
-               BUG();
+               WARN_ON_ONCE(1);
        }
 }
 
@@ -3719,6 +3730,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
 {
        __be32 status;
        struct nfs4_ol_stateid *stp;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        dprintk("NFSD: nfsd4_open_downgrade on file %.*s\n", 
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3731,7 +3743,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
 
        nfs4_lock_state();
        status = nfs4_preprocess_confirmed_seqid_op(cstate, od->od_seqid,
-                                       &od->od_stateid, &stp);
+                                       &od->od_stateid, &stp, nn);
        if (status)
                goto out; 
        status = nfserr_inval;
@@ -3794,6 +3806,8 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        __be32 status;
        struct nfs4_openowner *oo;
        struct nfs4_ol_stateid *stp;
+       struct net *net = SVC_NET(rqstp);
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
        dprintk("NFSD: nfsd4_close on file %.*s\n", 
                        (int)cstate->current_fh.fh_dentry->d_name.len,
@@ -3803,7 +3817,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        status = nfs4_preprocess_seqid_op(cstate, close->cl_seqid,
                                        &close->cl_stateid,
                                        NFS4_OPEN_STID|NFS4_CLOSED_STID,
-                                       &stp);
+                                       &stp, nn);
        if (status)
                goto out; 
        oo = openowner(stp->st_stateowner);
@@ -3825,7 +3839,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                         * little while to handle CLOSE replay.
                         */
                        if (list_empty(&oo->oo_owner.so_stateids))
-                               move_to_close_lru(oo);
+                               move_to_close_lru(oo, SVC_NET(rqstp));
                }
        }
 out:
@@ -3842,12 +3856,14 @@ nfsd4_delegreturn(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        stateid_t *stateid = &dr->dr_stateid;
        struct nfs4_stid *s;
        __be32 status;
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
 
        if ((status = fh_verify(rqstp, &cstate->current_fh, S_IFREG, 0)))
                return status;
 
        nfs4_lock_state();
-       status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID, &s, cstate->minorversion);
+       status = nfsd4_lookup_stateid(stateid, NFS4_DELEG_STID, &s,
+                                     cstate->minorversion, nn);
        if (status)
                goto out;
        dp = delegstateid(s);
@@ -3865,8 +3881,6 @@ out:
 
 #define LOFF_OVERFLOW(start, len)      ((u64)(len) > ~(u64)(start))
 
-#define LOCKOWNER_INO_HASH_BITS 8
-#define LOCKOWNER_INO_HASH_SIZE (1 << LOCKOWNER_INO_HASH_BITS)
 #define LOCKOWNER_INO_HASH_MASK (LOCKOWNER_INO_HASH_SIZE - 1)
 
 static inline u64
@@ -3884,7 +3898,7 @@ last_byte_offset(u64 start, u64 len)
 {
        u64 end;
 
-       BUG_ON(!len);
+       WARN_ON_ONCE(!len);
        end = start + len;
        return end > start ? end - 1: NFS4_MAX_UINT64;
 }
@@ -3896,8 +3910,6 @@ static unsigned int lockowner_ino_hashval(struct inode *inode, u32 cl_id, struct
                & LOCKOWNER_INO_HASH_MASK;
 }
 
-static struct list_head lockowner_ino_hashtbl[LOCKOWNER_INO_HASH_SIZE];
-
 /*
  * TODO: Linux file offsets are _signed_ 64-bit quantities, which means that
  * we can't properly handle lock requests that go beyond the (2^63 - 1)-th
@@ -3963,12 +3975,12 @@ static bool same_lockowner_ino(struct nfs4_lockowner *lo, struct inode *inode, c
 
 static struct nfs4_lockowner *
 find_lockowner_str(struct inode *inode, clientid_t *clid,
-               struct xdr_netobj *owner)
+                  struct xdr_netobj *owner, struct nfsd_net *nn)
 {
        unsigned int hashval = lockowner_ino_hashval(inode, clid->cl_id, owner);
        struct nfs4_lockowner *lo;
 
-       list_for_each_entry(lo, &lockowner_ino_hashtbl[hashval], lo_owner_ino_hash) {
+       list_for_each_entry(lo, &nn->lockowner_ino_hashtbl[hashval], lo_owner_ino_hash) {
                if (same_lockowner_ino(lo, inode, clid, owner))
                        return lo;
        }
@@ -3980,9 +3992,10 @@ static void hash_lockowner(struct nfs4_lockowner *lo, unsigned int strhashval, s
        struct inode *inode = open_stp->st_file->fi_inode;
        unsigned int inohash = lockowner_ino_hashval(inode,
                        clp->cl_clientid.cl_id, &lo->lo_owner.so_owner);
+       struct nfsd_net *nn = net_generic(clp->net, nfsd_net_id);
 
-       list_add(&lo->lo_owner.so_strhash, &ownerstr_hashtbl[strhashval]);
-       list_add(&lo->lo_owner_ino_hash, &lockowner_ino_hashtbl[inohash]);
+       list_add(&lo->lo_owner.so_strhash, &nn->ownerstr_hashtbl[strhashval]);
+       list_add(&lo->lo_owner_ino_hash, &nn->lockowner_ino_hashtbl[inohash]);
        list_add(&lo->lo_perstateid, &open_stp->st_lockowners);
 }
 
@@ -4056,8 +4069,10 @@ static __be32 lookup_or_create_lock_state(struct nfsd4_compound_state *cstate, s
        struct nfs4_client *cl = oo->oo_owner.so_client;
        struct nfs4_lockowner *lo;
        unsigned int strhashval;
+       struct nfsd_net *nn = net_generic(cl->net, nfsd_net_id);
 
-       lo = find_lockowner_str(fi->fi_inode, &cl->cl_clientid, &lock->v.new.owner);
+       lo = find_lockowner_str(fi->fi_inode, &cl->cl_clientid,
+                               &lock->v.new.owner, nn);
        if (lo) {
                if (!cstate->minorversion)
                        return nfserr_bad_seqid;
@@ -4097,7 +4112,8 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        bool new_state = false;
        int lkflg;
        int err;
-       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+       struct net *net = SVC_NET(rqstp);
+       struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
        dprintk("NFSD: nfsd4_lock: start=%Ld length=%Ld\n",
                (long long) lock->lk_offset,
@@ -4131,7 +4147,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                status = nfs4_preprocess_confirmed_seqid_op(cstate,
                                        lock->lk_new_open_seqid,
                                        &lock->lk_new_open_stateid,
-                                       &open_stp);
+                                       &open_stp, nn);
                if (status)
                        goto out;
                open_sop = openowner(open_stp->st_stateowner);
@@ -4145,7 +4161,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                status = nfs4_preprocess_seqid_op(cstate,
                                       lock->lk_old_lock_seqid,
                                       &lock->lk_old_lock_stateid,
-                                      NFS4_LOCK_STID, &lock_stp);
+                                      NFS4_LOCK_STID, &lock_stp, nn);
        if (status)
                goto out;
        lock_sop = lockowner(lock_stp->st_stateowner);
@@ -4156,10 +4172,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
 
        status = nfserr_grace;
-       if (locks_in_grace(SVC_NET(rqstp)) && !lock->lk_reclaim)
+       if (locks_in_grace(net) && !lock->lk_reclaim)
                goto out;
        status = nfserr_no_grace;
-       if (!locks_in_grace(SVC_NET(rqstp)) && lock->lk_reclaim)
+       if (!locks_in_grace(net) && lock->lk_reclaim)
                goto out;
 
        file_lock = locks_alloc_lock();
@@ -4310,7 +4326,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                goto out;
        }
 
-       lo = find_lockowner_str(inode, &lockt->lt_clientid, &lockt->lt_owner);
+       lo = find_lockowner_str(inode, &lockt->lt_clientid, &lockt->lt_owner, nn);
        if (lo)
                file_lock->fl_owner = (fl_owner_t)lo;
        file_lock->fl_pid = current->tgid;
@@ -4345,7 +4361,8 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        struct file_lock *file_lock = NULL;
        __be32 status;
        int err;
-                                                       
+       struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
+
        dprintk("NFSD: nfsd4_locku: start=%Ld length=%Ld\n",
                (long long) locku->lu_offset,
                (long long) locku->lu_length);
@@ -4356,7 +4373,8 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        nfs4_lock_state();
                                                                                
        status = nfs4_preprocess_seqid_op(cstate, locku->lu_seqid,
-                                       &locku->lu_stateid, NFS4_LOCK_STID, &stp);
+                                       &locku->lu_stateid, NFS4_LOCK_STID,
+                                       &stp, nn);
        if (status)
                goto out;
        filp = find_any_file(stp->st_file);
@@ -4462,7 +4480,7 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp,
        status = nfserr_locks_held;
        INIT_LIST_HEAD(&matches);
 
-       list_for_each_entry(sop, &ownerstr_hashtbl[hashval], so_strhash) {
+       list_for_each_entry(sop, &nn->ownerstr_hashtbl[hashval], so_strhash) {
                if (sop->so_is_open_owner)
                        continue;
                if (!same_owner_str(sop, owner, clid))
@@ -4550,7 +4568,7 @@ nfs4_release_reclaim(struct nfsd_net *nn)
                        nfs4_remove_reclaim_record(crp, nn);
                }
        }
-       BUG_ON(nn->reclaim_str_hashtbl_size);
+       WARN_ON_ONCE(nn->reclaim_str_hashtbl_size);
 }
 
 /*
@@ -4576,10 +4594,9 @@ nfsd4_find_reclaim_client(const char *recdir, struct nfsd_net *nn)
 * Called from OPEN. Look for clientid in reclaim list.
 */
 __be32
-nfs4_check_open_reclaim(clientid_t *clid, bool sessions)
+nfs4_check_open_reclaim(clientid_t *clid, bool sessions, struct nfsd_net *nn)
 {
        struct nfs4_client *clp;
-       struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
 
        /* find clientid in conf_id_hashtbl */
        clp = find_confirmed_client(clid, sessions, nn);
@@ -4595,9 +4612,10 @@ void nfsd_forget_clients(u64 num)
 {
        struct nfs4_client *clp, *next;
        int count = 0;
+       struct nfsd_net *nn = net_generic(current->nsproxy->net_ns, nfsd_net_id);
 
        nfs4_lock_state();
-       list_for_each_entry_safe(clp, next, &client_lru, cl_lru) {
+       list_for_each_entry_safe(clp, next, &nn->client_lru, cl_lru) {
                expire_client(clp);
                if (++count == num)
                        break;
@@ -4618,13 +4636,14 @@ static void release_openowner_sop(struct nfs4_stateowner *sop)
 }
 
 static int nfsd_release_n_owners(u64 num, bool is_open_owner,
-                               void (*release_sop)(struct nfs4_stateowner *))
+                               void (*release_sop)(struct nfs4_stateowner *),
+                               struct nfsd_net *nn)
 {
        int i, count = 0;
        struct nfs4_stateowner *sop, *next;
 
        for (i = 0; i < OWNER_HASH_SIZE; i++) {
-               list_for_each_entry_safe(sop, next, &ownerstr_hashtbl[i], so_strhash) {
+               list_for_each_entry_safe(sop, next, &nn->ownerstr_hashtbl[i], so_strhash) {
                        if (sop->so_is_open_owner != is_open_owner)
                                continue;
                        release_sop(sop);
@@ -4638,9 +4657,10 @@ static int nfsd_release_n_owners(u64 num, bool is_open_owner,
 void nfsd_forget_locks(u64 num)
 {
        int count;
+       struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
 
        nfs4_lock_state();
-       count = nfsd_release_n_owners(num, false, release_lockowner_sop);
+       count = nfsd_release_n_owners(num, false, release_lockowner_sop, nn);
        nfs4_unlock_state();
 
        printk(KERN_INFO "NFSD: Forgot %d locks", count);
@@ -4649,9 +4669,10 @@ void nfsd_forget_locks(u64 num)
 void nfsd_forget_openowners(u64 num)
 {
        int count;
+       struct nfsd_net *nn = net_generic(&init_net, nfsd_net_id);
 
        nfs4_lock_state();
-       count = nfsd_release_n_owners(num, true, release_openowner_sop);
+       count = nfsd_release_n_owners(num, true, release_openowner_sop, nn);
        nfs4_unlock_state();
 
        printk(KERN_INFO "NFSD: Forgot %d open owners", count);
@@ -4720,22 +4741,9 @@ nfs4_state_init(void)
 {
        int i;
 
-       for (i = 0; i < CLIENT_HASH_SIZE; i++) {
-               INIT_LIST_HEAD(&unconf_id_hashtbl[i]);
-       }
-       unconf_name_tree = RB_ROOT;
-       for (i = 0; i < SESSION_HASH_SIZE; i++)
-               INIT_LIST_HEAD(&sessionid_hashtbl[i]);
        for (i = 0; i < FILE_HASH_SIZE; i++) {
                INIT_LIST_HEAD(&file_hashtbl[i]);
        }
-       for (i = 0; i < OWNER_HASH_SIZE; i++) {
-               INIT_LIST_HEAD(&ownerstr_hashtbl[i]);
-       }
-       for (i = 0; i < LOCKOWNER_INO_HASH_SIZE; i++)
-               INIT_LIST_HEAD(&lockowner_ino_hashtbl[i]);
-       INIT_LIST_HEAD(&close_lru);
-       INIT_LIST_HEAD(&client_lru);
        INIT_LIST_HEAD(&del_recall_lru);
 }
 
@@ -4769,14 +4777,51 @@ static int nfs4_state_start_net(struct net *net)
                        CLIENT_HASH_SIZE, GFP_KERNEL);
        if (!nn->conf_id_hashtbl)
                goto err;
+       nn->unconf_id_hashtbl = kmalloc(sizeof(struct list_head) *
+                       CLIENT_HASH_SIZE, GFP_KERNEL);
+       if (!nn->unconf_id_hashtbl)
+               goto err_unconf_id;
+       nn->ownerstr_hashtbl = kmalloc(sizeof(struct list_head) *
+                       OWNER_HASH_SIZE, GFP_KERNEL);
+       if (!nn->ownerstr_hashtbl)
+               goto err_ownerstr;
+       nn->lockowner_ino_hashtbl = kmalloc(sizeof(struct list_head) *
+                       LOCKOWNER_INO_HASH_SIZE, GFP_KERNEL);
+       if (!nn->lockowner_ino_hashtbl)
+               goto err_lockowner_ino;
+       nn->sessionid_hashtbl = kmalloc(sizeof(struct list_head) *
+                       SESSION_HASH_SIZE, GFP_KERNEL);
+       if (!nn->sessionid_hashtbl)
+               goto err_sessionid;
 
        for (i = 0; i < CLIENT_HASH_SIZE; i++) {
                INIT_LIST_HEAD(&nn->conf_id_hashtbl[i]);
+               INIT_LIST_HEAD(&nn->unconf_id_hashtbl[i]);
        }
+       for (i = 0; i < OWNER_HASH_SIZE; i++)
+               INIT_LIST_HEAD(&nn->ownerstr_hashtbl[i]);
+       for (i = 0; i < LOCKOWNER_INO_HASH_SIZE; i++)
+               INIT_LIST_HEAD(&nn->lockowner_ino_hashtbl[i]);
+       for (i = 0; i < SESSION_HASH_SIZE; i++)
+               INIT_LIST_HEAD(&nn->sessionid_hashtbl[i]);
        nn->conf_name_tree = RB_ROOT;
+       nn->unconf_name_tree = RB_ROOT;
+       INIT_LIST_HEAD(&nn->client_lru);
+       INIT_LIST_HEAD(&nn->close_lru);
+       spin_lock_init(&nn->client_lock);
+
+       INIT_DELAYED_WORK(&nn->laundromat_work, laundromat_main);
 
        return 0;
 
+err_sessionid:
+       kfree(nn->lockowner_ino_hashtbl);
+err_lockowner_ino:
+       kfree(nn->ownerstr_hashtbl);
+err_ownerstr:
+       kfree(nn->unconf_id_hashtbl);
+err_unconf_id:
+       kfree(nn->conf_id_hashtbl);
 err:
        return -ENOMEM;
 }
@@ -4787,6 +4832,7 @@ __nfs4_state_shutdown_net(struct net *net)
        int i;
        struct nfs4_client *clp = NULL;
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
+       struct rb_node *node, *tmp;
 
        for (i = 0; i < CLIENT_HASH_SIZE; i++) {
                while (!list_empty(&nn->conf_id_hashtbl[i])) {
@@ -4794,6 +4840,20 @@ __nfs4_state_shutdown_net(struct net *net)
                        destroy_client(clp);
                }
        }
+
+       node = rb_first(&nn->unconf_name_tree);
+       while (node != NULL) {
+               tmp = node;
+               node = rb_next(tmp);
+               clp = rb_entry(tmp, struct nfs4_client, cl_namenode);
+               rb_erase(tmp, &nn->unconf_name_tree);
+               destroy_client(clp);
+       }
+
+       kfree(nn->sessionid_hashtbl);
+       kfree(nn->lockowner_ino_hashtbl);
+       kfree(nn->ownerstr_hashtbl);
+       kfree(nn->unconf_id_hashtbl);
        kfree(nn->conf_id_hashtbl);
 }
 
@@ -4836,7 +4896,8 @@ nfs4_state_start(void)
        ret = nfsd4_create_callback_queue();
        if (ret)
                goto out_free_laundry;
-       queue_delayed_work(laundry_wq, &laundromat_work, nfsd4_grace * HZ);
+
+       queue_delayed_work(laundry_wq, &nn->laundromat_work, nfsd4_grace * HZ);
        set_max_delegations();
        return 0;
 out_free_laundry:
@@ -4852,22 +4913,11 @@ out_recovery:
 static void
 __nfs4_state_shutdown(struct net *net)
 {
-       struct nfs4_client *clp = NULL;
        struct nfs4_delegation *dp = NULL;
        struct list_head *pos, *next, reaplist;
-       struct rb_node *node, *tmp;
 
        __nfs4_state_shutdown_net(net);
 
-       node = rb_first(&unconf_name_tree);
-       while (node != NULL) {
-               tmp = node;
-               node = rb_next(tmp);
-               clp = rb_entry(tmp, struct nfs4_client, cl_namenode);
-               rb_erase(tmp, &unconf_name_tree);
-               destroy_client(clp);
-       }
-
        INIT_LIST_HEAD(&reaplist);
        spin_lock(&recall_lock);
        list_for_each_safe(pos, next, &del_recall_lru) {
@@ -4880,8 +4930,8 @@ __nfs4_state_shutdown(struct net *net)
                unhash_delegation(dp);
        }
 
-       nfsd4_client_tracking_exit(&init_net);
-       put_net(&init_net);
+       nfsd4_client_tracking_exit(net);
+       put_net(net);
 }
 
 void
@@ -4890,12 +4940,10 @@ nfs4_state_shutdown(void)
        struct net *net = &init_net;
        struct nfsd_net *nn = net_generic(net, nfsd_net_id);
 
-       cancel_delayed_work_sync(&laundromat_work);
+       cancel_delayed_work_sync(&nn->laundromat_work);
        destroy_workqueue(laundry_wq);
        locks_end_grace(&nn->nfsd4_manager);
-       nfs4_lock_state();
        __nfs4_state_shutdown(net);
-       nfs4_unlock_state();
        nfsd4_destroy_callback_queue();
 }