Skip to content

Commit

Permalink
ksmbd: update tree disconnect race update
Browse files Browse the repository at this point in the history
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Oct 3, 2023
1 parent edc8910 commit 11d3bf6
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mgmt/tree_connect.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ ksmbd_tree_conn_connect(struct ksmbd_conn *conn, struct ksmbd_session *sess,
tree_conn->share_conf = sc;
tree_conn->t_state = TREE_NEW;
status.tree_conn = tree_conn;
atomic_set(&tree_conn->refcount, 1);
init_waitqueue_head(&tree_conn->refcount_q);

ret = xa_err(xa_store(&sess->tree_conns, tree_conn->id, tree_conn,
Expand Down Expand Up @@ -117,7 +118,7 @@ int ksmbd_tree_conn_disconnect(struct ksmbd_session *sess,
xa_erase(&sess->tree_conns, tree_conn->id);
write_unlock(&sess->tree_conns_lock);

if (atomic_read(&tree_conn->refcount))
if (!atomic_dec_and_test(&tree_conn->refcount))
wait_event(tree_conn->refcount_q,
atomic_read(&tree_conn->refcount) == 0);

Expand All @@ -138,8 +139,8 @@ struct ksmbd_tree_connect *ksmbd_tree_conn_lookup(struct ksmbd_session *sess,
if (tcon) {
if (tcon->t_state != TREE_CONNECTED)
tcon = NULL;
else
atomic_inc(&tcon->refcount);
else if (!atomic_inc_not_zero(&tcon->refcount))
tcon = NULL;
}
read_unlock(&sess->tree_conns_lock);

Expand Down

0 comments on commit 11d3bf6

Please sign in to comment.