aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/nfsd/nfs4state.c35
-rw-r--r--fs/nfsd/state.h13
2 files changed, 32 insertions, 16 deletions
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 97dd2c75f322..867086357f6c 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -95,6 +95,19 @@ nfs4_lock_state(void)
95 mutex_lock(&client_mutex); 95 mutex_lock(&client_mutex);
96} 96}
97 97
98static void free_session(struct kref *);
99
100/* Must be called under the client_lock */
101static void nfsd4_put_session_locked(struct nfsd4_session *ses)
102{
103 kref_put(&ses->se_ref, free_session);
104}
105
106static void nfsd4_get_session(struct nfsd4_session *ses)
107{
108 kref_get(&ses->se_ref);
109}
110
98void 111void
99nfs4_unlock_state(void) 112nfs4_unlock_state(void)
100{ 113{
@@ -836,11 +849,12 @@ static void nfsd4_del_conns(struct nfsd4_session *s)
836 spin_unlock(&clp->cl_lock); 849 spin_unlock(&clp->cl_lock);
837} 850}
838 851
839void free_session(struct kref *kref) 852static void free_session(struct kref *kref)
840{ 853{
841 struct nfsd4_session *ses; 854 struct nfsd4_session *ses;
842 int mem; 855 int mem;
843 856
857 BUG_ON(!spin_is_locked(&client_lock));
844 ses = container_of(kref, struct nfsd4_session, se_ref); 858 ses = container_of(kref, struct nfsd4_session, se_ref);
845 nfsd4_del_conns(ses); 859 nfsd4_del_conns(ses);
846 spin_lock(&nfsd_drc_lock); 860 spin_lock(&nfsd_drc_lock);
@@ -851,6 +865,13 @@ void free_session(struct kref *kref)
851 kfree(ses); 865 kfree(ses);
852} 866}
853 867
868void nfsd4_put_session(struct nfsd4_session *ses)
869{
870 spin_lock(&client_lock);
871 nfsd4_put_session_locked(ses);
872 spin_unlock(&client_lock);
873}
874
854static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, struct nfsd4_create_session *cses) 875static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct nfs4_client *clp, struct nfsd4_create_session *cses)
855{ 876{
856 struct nfsd4_session *new; 877 struct nfsd4_session *new;
@@ -898,7 +919,9 @@ static struct nfsd4_session *alloc_init_session(struct svc_rqst *rqstp, struct n
898 status = nfsd4_new_conn_from_crses(rqstp, new); 919 status = nfsd4_new_conn_from_crses(rqstp, new);
899 /* whoops: benny points out, status is ignored! (err, or bogus) */ 920 /* whoops: benny points out, status is ignored! (err, or bogus) */
900 if (status) { 921 if (status) {
922 spin_lock(&client_lock);
901 free_session(&new->se_ref); 923 free_session(&new->se_ref);
924 spin_unlock(&client_lock);
902 return NULL; 925 return NULL;
903 } 926 }
904 if (cses->flags & SESSION4_BACK_CHAN) { 927 if (cses->flags & SESSION4_BACK_CHAN) {
@@ -1010,12 +1033,13 @@ static struct nfs4_client *alloc_client(struct xdr_netobj name)
1010static inline void 1033static inline void
1011free_client(struct nfs4_client *clp) 1034free_client(struct nfs4_client *clp)
1012{ 1035{
1036 BUG_ON(!spin_is_locked(&client_lock));
1013 while (!list_empty(&clp->cl_sessions)) { 1037 while (!list_empty(&clp->cl_sessions)) {
1014 struct nfsd4_session *ses; 1038 struct nfsd4_session *ses;
1015 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session, 1039 ses = list_entry(clp->cl_sessions.next, struct nfsd4_session,
1016 se_perclnt); 1040 se_perclnt);
1017 list_del(&ses->se_perclnt); 1041 list_del(&ses->se_perclnt);
1018 nfsd4_put_session(ses); 1042 nfsd4_put_session_locked(ses);
1019 } 1043 }
1020 if (clp->cl_cred.cr_group_info) 1044 if (clp->cl_cred.cr_group_info)
1021 put_group_info(clp->cl_cred.cr_group_info); 1045 put_group_info(clp->cl_cred.cr_group_info);
@@ -1184,7 +1208,9 @@ static struct nfs4_client *create_client(struct xdr_netobj name, char *recdir,
1184 if (princ) { 1208 if (princ) {
1185 clp->cl_principal = kstrdup(princ, GFP_KERNEL); 1209 clp->cl_principal = kstrdup(princ, GFP_KERNEL);
1186 if (clp->cl_principal == NULL) { 1210 if (clp->cl_principal == NULL) {
1211 spin_lock(&client_lock);
1187 free_client(clp); 1212 free_client(clp);
1213 spin_unlock(&client_lock);
1188 return NULL; 1214 return NULL;
1189 } 1215 }
1190 } 1216 }
@@ -1812,9 +1838,10 @@ nfsd4_destroy_session(struct svc_rqst *r,
1812 nfsd4_probe_callback_sync(ses->se_client); 1838 nfsd4_probe_callback_sync(ses->se_client);
1813 nfs4_unlock_state(); 1839 nfs4_unlock_state();
1814 1840
1841 spin_lock(&client_lock);
1815 nfsd4_del_conns(ses); 1842 nfsd4_del_conns(ses);
1816 1843 nfsd4_put_session_locked(ses);
1817 nfsd4_put_session(ses); 1844 spin_unlock(&client_lock);
1818 status = nfs_ok; 1845 status = nfs_ok;
1819out: 1846out:
1820 dprintk("%s returns %d\n", __func__, ntohl(status)); 1847 dprintk("%s returns %d\n", __func__, ntohl(status));
diff --git a/fs/nfsd/state.h b/fs/nfsd/state.h
index d8f52a0f4988..1e2b582bc9dc 100644
--- a/fs/nfsd/state.h
+++ b/fs/nfsd/state.h
@@ -198,18 +198,7 @@ struct nfsd4_session {
198 struct nfsd4_slot *se_slots[]; /* forward channel slots */ 198 struct nfsd4_slot *se_slots[]; /* forward channel slots */
199}; 199};
200 200
201static inline void 201extern void nfsd4_put_session(struct nfsd4_session *ses);
202nfsd4_put_session(struct nfsd4_session *ses)
203{
204 extern void free_session(struct kref *kref);
205 kref_put(&ses->se_ref, free_session);
206}
207
208static inline void
209nfsd4_get_session(struct nfsd4_session *ses)
210{
211 kref_get(&ses->se_ref);
212}
213 202
214/* formatted contents of nfs4_sessionid */ 203/* formatted contents of nfs4_sessionid */
215struct nfsd4_sessionid { 204struct nfsd4_sessionid {