nfsd4.1: fix session memory use calculation
[safe/jmp/linux-2.6] / fs / nfsd / nfs4state.c
index 11db40c..c171371 100644 (file)
@@ -477,13 +477,14 @@ static int set_forechannel_drc_size(struct nfsd4_channel_attrs *fchan)
 
 /*
  * fchan holds the client values on input, and the server values on output
+ * sv_max_mesg is the maximum payload plus one page for overhead.
  */
 static int init_forechannel_attrs(struct svc_rqst *rqstp,
                                  struct nfsd4_channel_attrs *session_fchan,
                                  struct nfsd4_channel_attrs *fchan)
 {
        int status = 0;
-       __u32   maxcount = svc_max_payload(rqstp);
+       __u32   maxcount = nfsd_serv->sv_max_mesg;
 
        /* headerpadsz set to zero in encode routine */
 
@@ -628,10 +629,13 @@ void
 free_session(struct kref *kref)
 {
        struct nfsd4_session *ses;
+       int mem;
 
        ses = container_of(kref, struct nfsd4_session, se_ref);
        spin_lock(&nfsd_drc_lock);
-       nfsd_drc_mem_used -= ses->se_fchannel.maxreqs * NFSD_SLOT_CACHE_SIZE;
+       mem = ses->se_fchannel.maxreqs
+               * (ses->se_fchannel.maxresp_cached - NFSD_MIN_HDR_SEQ_SZ);
+       nfsd_drc_mem_used -= mem;
        spin_unlock(&nfsd_drc_lock);
        free_session_slots(ses);
        kfree(ses);
@@ -696,16 +700,14 @@ shutdown_callback_client(struct nfs4_client *clp)
                clp->cl_cb_conn.cb_client = NULL;
                rpc_shutdown_client(clnt);
        }
-       if (clp->cl_cb_conn.cb_cred) {
-               put_rpccred(clp->cl_cb_conn.cb_cred);
-               clp->cl_cb_conn.cb_cred = NULL;
-       }
 }
 
 static inline void
 free_client(struct nfs4_client *clp)
 {
        shutdown_callback_client(clp);
+       if (clp->cl_cb_xprt)
+               svc_xprt_put(clp->cl_cb_xprt);
        if (clp->cl_cred.cr_group_info)
                put_group_info(clp->cl_cred.cr_group_info);
        kfree(clp->cl_principal);
@@ -761,25 +763,6 @@ expire_client(struct nfs4_client *clp)
        put_nfs4_client(clp);
 }
 
-static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir)
-{
-       struct nfs4_client *clp;
-
-       clp = alloc_client(name);
-       if (clp == NULL)
-               return NULL;
-       memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
-       atomic_set(&clp->cl_count, 1);
-       atomic_set(&clp->cl_cb_conn.cb_set, 0);
-       INIT_LIST_HEAD(&clp->cl_idhash);
-       INIT_LIST_HEAD(&clp->cl_strhash);
-       INIT_LIST_HEAD(&clp->cl_openowners);
-       INIT_LIST_HEAD(&clp->cl_delegations);
-       INIT_LIST_HEAD(&clp->cl_sessions);
-       INIT_LIST_HEAD(&clp->cl_lru);
-       return clp;
-}
-
 static void copy_verf(struct nfs4_client *target, nfs4_verifier *source)
 {
        memcpy(target->cl_verifier.data, source->data,
@@ -842,6 +825,46 @@ static void gen_confirm(struct nfs4_client *clp)
        *p++ = i++;
 }
 
+static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
+               struct svc_rqst *rqstp, nfs4_verifier *verf)
+{
+       struct nfs4_client *clp;
+       struct sockaddr *sa = svc_addr(rqstp);
+       char *princ;
+
+       clp = alloc_client(name);
+       if (clp == NULL)
+               return NULL;
+
+       princ = svc_gss_principal(rqstp);
+       if (princ) {
+               clp->cl_principal = kstrdup(princ, GFP_KERNEL);
+               if (clp->cl_principal == NULL) {
+                       free_client(clp);
+                       return NULL;
+               }
+       }
+
+       memcpy(clp->cl_recdir, recdir, HEXDIR_LEN);
+       atomic_set(&clp->cl_count, 1);
+       atomic_set(&clp->cl_cb_conn.cb_set, 0);
+       INIT_LIST_HEAD(&clp->cl_idhash);
+       INIT_LIST_HEAD(&clp->cl_strhash);
+       INIT_LIST_HEAD(&clp->cl_openowners);
+       INIT_LIST_HEAD(&clp->cl_delegations);
+       INIT_LIST_HEAD(&clp->cl_sessions);
+       INIT_LIST_HEAD(&clp->cl_lru);
+       clear_bit(0, &clp->cl_cb_slot_busy);
+       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);
+
+       return clp;
+}
+
 static int check_name(struct xdr_netobj name)
 {
        if (name.len == 0) 
@@ -1189,17 +1212,13 @@ nfsd4_exchange_id(struct svc_rqst *rqstp,
 
 out_new:
        /* Normal case */
-       new = create_client(exid->clname, dname);
+       new = create_client(exid->clname, dname, rqstp, &verf);
        if (new == NULL) {
                status = nfserr_serverfault;
                goto out;
        }
 
-       copy_verf(new, &verf);
-       copy_cred(&new->cl_cred, &rqstp->rq_cred);
-       rpc_copy_addr((struct sockaddr *) &new->cl_addr, sa);
        gen_clid(new);
-       gen_confirm(new);
        add_to_unconfirmed(new, strhashval);
 out_copy:
        exid->clientid.cl_boot = new->cl_clientid.cl_boot;
@@ -1321,6 +1340,19 @@ nfsd4_create_session(struct svc_rqst *rqstp,
                cr_ses->flags &= ~SESSION4_PERSIST;
                cr_ses->flags &= ~SESSION4_RDMA;
 
+               if (cr_ses->flags & SESSION4_BACK_CHAN) {
+                       unconf->cl_cb_xprt = rqstp->rq_xprt;
+                       svc_xprt_get(unconf->cl_cb_xprt);
+                       rpc_copy_addr(
+                               (struct sockaddr *)&unconf->cl_cb_conn.cb_addr,
+                               sa);
+                       unconf->cl_cb_conn.cb_addrlen = svc_addr_len(sa);
+                       unconf->cl_cb_conn.cb_minorversion =
+                               cstate->minorversion;
+                       unconf->cl_cb_conn.cb_prog = cr_ses->callback_prog;
+                       unconf->cl_cb_seq_nr = 1;
+                       nfsd4_probe_callback(unconf);
+               }
                conf = unconf;
        } else {
                status = nfserr_stale_clientid;
@@ -1460,7 +1492,6 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        unsigned int            strhashval;
        struct nfs4_client      *conf, *unconf, *new;
        __be32                  status;
-       char                    *princ;
        char                    dname[HEXDIR_LEN];
        
        if (!check_name(clname))
@@ -1505,7 +1536,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                 */
                if (unconf)
                        expire_client(unconf);
-               new = create_client(clname, dname);
+               new = create_client(clname, dname, rqstp, &clverifier);
                if (new == NULL)
                        goto out;
                gen_clid(new);
@@ -1522,7 +1553,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                         */
                        expire_client(unconf);
                }
-               new = create_client(clname, dname);
+               new = create_client(clname, dname, rqstp, &clverifier);
                if (new == NULL)
                        goto out;
                copy_clid(new, conf);
@@ -1532,7 +1563,7 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                 * probable client reboot; state will be removed if
                 * confirmed.
                 */
-               new = create_client(clname, dname);
+               new = create_client(clname, dname, rqstp, &clverifier);
                if (new == NULL)
                        goto out;
                gen_clid(new);
@@ -1543,24 +1574,11 @@ nfsd4_setclientid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
                 * confirmed.
                 */
                expire_client(unconf);
-               new = create_client(clname, dname);
+               new = create_client(clname, dname, rqstp, &clverifier);
                if (new == NULL)
                        goto out;
                gen_clid(new);
        }
-       copy_verf(new, &clverifier);
-       rpc_copy_addr((struct sockaddr *) &new->cl_addr, sa);
-       new->cl_flavor = rqstp->rq_flavor;
-       princ = svc_gss_principal(rqstp);
-       if (princ) {
-               new->cl_principal = kstrdup(princ, GFP_KERNEL);
-               if (new->cl_principal == NULL) {
-                       free_client(new);
-                       goto out;
-               }
-       }
-       copy_cred(&new->cl_cred, &rqstp->rq_cred);
-       gen_confirm(new);
        gen_callback(new, setclid, rpc_get_scope_id(sa));
        add_to_unconfirmed(new, strhashval);
        setclid->se_clientid.cl_boot = new->cl_clientid.cl_boot;
@@ -2095,7 +2113,7 @@ int nfsd_change_deleg_cb(struct file_lock **onlist, int arg)
                return -EAGAIN;
 }
 
-static struct lock_manager_operations nfsd_lease_mng_ops = {
+static const struct lock_manager_operations nfsd_lease_mng_ops = {
        .fl_break = nfsd_break_deleg_cb,
        .fl_release_private = nfsd_release_deleg_cb,
        .fl_copy_lock = nfsd_copy_lock_deleg_cb,
@@ -3300,7 +3318,7 @@ nfs4_transform_lock_offset(struct file_lock *lock)
 
 /* Hack!: For now, we're defining this just so we can use a pointer to it
  * as a unique cookie to identify our (NFSv4's) posix locks. */
-static struct lock_manager_operations nfsd_posix_mng_ops  = {
+static const struct lock_manager_operations nfsd_posix_mng_ops  = {
 };
 
 static inline void
@@ -4020,7 +4038,7 @@ __nfs4_state_start(void)
                return -ENOMEM;
        queue_delayed_work(laundry_wq, &laundromat_work, grace_time);
        set_max_delegations();
-       return 0;
+       return set_callback_cred();
 }
 
 int