@@ -80,8 +80,10 @@ ksmbd_tree_conn_connect(struct ksmbd_work *work, const char *share_name)
8080 status .tree_conn = tree_conn ;
8181 atomic_set (& tree_conn -> refcount , 1 );
8282
83+ down_write (& sess -> tree_conns_lock );
8384 ret = xa_err (xa_store (& sess -> tree_conns , tree_conn -> id , tree_conn ,
8485 KSMBD_DEFAULT_GFP ));
86+ up_write (& sess -> tree_conns_lock );
8587 if (ret ) {
8688 status .ret = - ENOMEM ;
8789 goto out_error ;
@@ -105,15 +107,11 @@ void ksmbd_tree_connect_put(struct ksmbd_tree_connect *tcon)
105107 kfree (tcon );
106108}
107109
108- int ksmbd_tree_conn_disconnect (struct ksmbd_session * sess ,
109- struct ksmbd_tree_connect * tree_conn )
110+ static int __ksmbd_tree_conn_disconnect (struct ksmbd_session * sess ,
111+ struct ksmbd_tree_connect * tree_conn )
110112{
111113 int ret ;
112114
113- write_lock (& sess -> tree_conns_lock );
114- xa_erase (& sess -> tree_conns , tree_conn -> id );
115- write_unlock (& sess -> tree_conns_lock );
116-
117115 ret = ksmbd_ipc_tree_disconnect_request (sess -> id , tree_conn -> id );
118116 ksmbd_release_tree_conn_id (sess , tree_conn -> id );
119117 ksmbd_share_config_put (tree_conn -> share_conf );
@@ -123,20 +121,30 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
123121 return ret ;
124122}
125123
124+ int ksmbd_tree_conn_disconnect (struct ksmbd_session * sess ,
125+ struct ksmbd_tree_connect * tree_conn )
126+ {
127+ down_write (& sess -> tree_conns_lock );
128+ xa_erase (& sess -> tree_conns , tree_conn -> id );
129+ up_write (& sess -> tree_conns_lock );
130+
131+ return __ksmbd_tree_conn_disconnect (sess , tree_conn );
132+ }
133+
126134struct ksmbd_tree_connect * ksmbd_tree_conn_lookup (struct ksmbd_session * sess ,
127135 unsigned int id )
128136{
129137 struct ksmbd_tree_connect * tcon ;
130138
131- read_lock (& sess -> tree_conns_lock );
139+ down_read (& sess -> tree_conns_lock );
132140 tcon = xa_load (& sess -> tree_conns , id );
133141 if (tcon ) {
134142 if (tcon -> t_state != TREE_CONNECTED )
135143 tcon = NULL ;
136144 else if (!atomic_inc_not_zero (& tcon -> refcount ))
137145 tcon = NULL ;
138146 }
139- read_unlock (& sess -> tree_conns_lock );
147+ up_read (& sess -> tree_conns_lock );
140148
141149 return tcon ;
142150}
@@ -150,18 +158,19 @@ int ksmbd_tree_conn_session_logoff(struct ksmbd_session *sess)
150158 if (!sess )
151159 return - EINVAL ;
152160
161+ down_write (& sess -> tree_conns_lock );
153162 xa_for_each (& sess -> tree_conns , id , tc ) {
154- write_lock (& sess -> tree_conns_lock );
155163 if (tc -> t_state == TREE_DISCONNECTED ) {
156- write_unlock (& sess -> tree_conns_lock );
157164 ret = - ENOENT ;
158165 continue ;
159166 }
160167 tc -> t_state = TREE_DISCONNECTED ;
161- write_unlock (& sess -> tree_conns_lock );
162168
163- ret |= ksmbd_tree_conn_disconnect (sess , tc );
169+ xa_erase (& sess -> tree_conns , tc -> id );
170+ ret |= __ksmbd_tree_conn_disconnect (sess , tc );
164171 }
165172 xa_destroy (& sess -> tree_conns );
173+ up_write (& sess -> tree_conns_lock );
174+
166175 return ret ;
167176}
0 commit comments