@@ -25,20 +25,19 @@ static DECLARE_RWSEM(sessions_table_lock);
2525struct ksmbd_session_rpc {
2626 int id ;
2727 unsigned int method ;
28- struct list_head list ;
2928};
3029
3130static void free_channel_list (struct ksmbd_session * sess )
3231{
33- struct channel * chann , * tmp ;
32+ struct channel * chann ;
33+ unsigned long index ;
3434
35- write_lock (& sess -> chann_lock );
36- list_for_each_entry_safe (chann , tmp , & sess -> ksmbd_chann_list ,
37- chann_list ) {
38- list_del (& chann -> chann_list );
35+ xa_for_each (& sess -> ksmbd_chann_list , index , chann ) {
36+ xa_erase (& sess -> ksmbd_chann_list , index );
3937 kfree (chann );
4038 }
41- write_unlock (& sess -> chann_lock );
39+
40+ xa_destroy (& sess -> ksmbd_chann_list );
4241}
4342
4443static void __session_rpc_close (struct ksmbd_session * sess ,
@@ -58,15 +57,14 @@ static void __session_rpc_close(struct ksmbd_session *sess,
5857static void ksmbd_session_rpc_clear_list (struct ksmbd_session * sess )
5958{
6059 struct ksmbd_session_rpc * entry ;
60+ long index ;
6161
62- while (!list_empty (& sess -> rpc_handle_list )) {
63- entry = list_entry (sess -> rpc_handle_list .next ,
64- struct ksmbd_session_rpc ,
65- list );
66-
67- list_del (& entry -> list );
62+ xa_for_each (& sess -> rpc_handle_list , index , entry ) {
63+ xa_erase (& sess -> rpc_handle_list , index );
6864 __session_rpc_close (sess , entry );
6965 }
66+
67+ xa_destroy (& sess -> rpc_handle_list );
7068}
7169
7270static int __rpc_method (char * rpc_name )
@@ -102,13 +100,13 @@ int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name)
102100
103101 entry = kzalloc (sizeof (struct ksmbd_session_rpc ), GFP_KERNEL );
104102 if (!entry )
105- return - EINVAL ;
103+ return - ENOMEM ;
106104
107- list_add (& entry -> list , & sess -> rpc_handle_list );
108105 entry -> method = method ;
109106 entry -> id = ksmbd_ipc_id_alloc ();
110107 if (entry -> id < 0 )
111108 goto free_entry ;
109+ xa_store (& sess -> rpc_handle_list , entry -> id , entry , GFP_KERNEL );
112110
113111 resp = ksmbd_rpc_open (sess , entry -> id );
114112 if (!resp )
@@ -117,9 +115,9 @@ int ksmbd_session_rpc_open(struct ksmbd_session *sess, char *rpc_name)
117115 kvfree (resp );
118116 return entry -> id ;
119117free_id :
118+ xa_erase (& sess -> rpc_handle_list , entry -> id );
120119 ksmbd_rpc_id_free (entry -> id );
121120free_entry :
122- list_del (& entry -> list );
123121 kfree (entry );
124122 return - EINVAL ;
125123}
@@ -128,24 +126,17 @@ void ksmbd_session_rpc_close(struct ksmbd_session *sess, int id)
128126{
129127 struct ksmbd_session_rpc * entry ;
130128
131- list_for_each_entry (entry , & sess -> rpc_handle_list , list ) {
132- if (entry -> id == id ) {
133- list_del (& entry -> list );
134- __session_rpc_close (sess , entry );
135- break ;
136- }
137- }
129+ entry = xa_erase (& sess -> rpc_handle_list , id );
130+ if (entry )
131+ __session_rpc_close (sess , entry );
138132}
139133
140134int ksmbd_session_rpc_method (struct ksmbd_session * sess , int id )
141135{
142136 struct ksmbd_session_rpc * entry ;
143137
144- list_for_each_entry (entry , & sess -> rpc_handle_list , list ) {
145- if (entry -> id == id )
146- return entry -> method ;
147- }
148- return 0 ;
138+ entry = xa_load (& sess -> rpc_handle_list , id );
139+ return entry ? entry -> method : 0 ;
149140}
150141
151142void ksmbd_session_destroy (struct ksmbd_session * sess )
@@ -190,21 +181,15 @@ int ksmbd_session_register(struct ksmbd_conn *conn,
190181
191182static int ksmbd_chann_del (struct ksmbd_conn * conn , struct ksmbd_session * sess )
192183{
193- struct channel * chann , * tmp ;
194-
195- write_lock (& sess -> chann_lock );
196- list_for_each_entry_safe (chann , tmp , & sess -> ksmbd_chann_list ,
197- chann_list ) {
198- if (chann -> conn == conn ) {
199- list_del (& chann -> chann_list );
200- kfree (chann );
201- write_unlock (& sess -> chann_lock );
202- return 0 ;
203- }
204- }
205- write_unlock (& sess -> chann_lock );
184+ struct channel * chann ;
185+
186+ chann = xa_erase (& sess -> ksmbd_chann_list , (long )conn );
187+ if (!chann )
188+ return - ENOENT ;
206189
207- return - ENOENT ;
190+ kfree (chann );
191+
192+ return 0 ;
208193}
209194
210195void ksmbd_sessions_deregister (struct ksmbd_conn * conn )
@@ -234,7 +219,7 @@ void ksmbd_sessions_deregister(struct ksmbd_conn *conn)
234219 return ;
235220
236221sess_destroy :
237- if (list_empty (& sess -> ksmbd_chann_list )) {
222+ if (xa_empty (& sess -> ksmbd_chann_list )) {
238223 xa_erase (& conn -> sessions , sess -> id );
239224 ksmbd_session_destroy (sess );
240225 }
@@ -320,6 +305,9 @@ static struct ksmbd_session *__session_create(int protocol)
320305 struct ksmbd_session * sess ;
321306 int ret ;
322307
308+ if (protocol != CIFDS_SESSION_FLAG_SMB2 )
309+ return NULL ;
310+
323311 sess = kzalloc (sizeof (struct ksmbd_session ), GFP_KERNEL );
324312 if (!sess )
325313 return NULL ;
@@ -329,30 +317,20 @@ static struct ksmbd_session *__session_create(int protocol)
329317
330318 set_session_flag (sess , protocol );
331319 xa_init (& sess -> tree_conns );
332- INIT_LIST_HEAD (& sess -> ksmbd_chann_list );
333- INIT_LIST_HEAD (& sess -> rpc_handle_list );
320+ xa_init (& sess -> ksmbd_chann_list );
321+ xa_init (& sess -> rpc_handle_list );
334322 sess -> sequence_number = 1 ;
335- rwlock_init (& sess -> chann_lock );
336-
337- switch (protocol ) {
338- case CIFDS_SESSION_FLAG_SMB2 :
339- ret = __init_smb2_session (sess );
340- break ;
341- default :
342- ret = - EINVAL ;
343- break ;
344- }
345323
324+ ret = __init_smb2_session (sess );
346325 if (ret )
347326 goto error ;
348327
349328 ida_init (& sess -> tree_conn_ida );
350329
351- if (protocol == CIFDS_SESSION_FLAG_SMB2 ) {
352- down_write (& sessions_table_lock );
353- hash_add (sessions_table , & sess -> hlist , sess -> id );
354- up_write (& sessions_table_lock );
355- }
330+ down_write (& sessions_table_lock );
331+ hash_add (sessions_table , & sess -> hlist , sess -> id );
332+ up_write (& sessions_table_lock );
333+
356334 return sess ;
357335
358336error :
0 commit comments