Skip to content

Commit

Permalink
ksmbd: work 2
Browse files Browse the repository at this point in the history
Signed-off-by: Namjae Jeon <[email protected]>
  • Loading branch information
namjaejeon committed Aug 16, 2024
1 parent ebaf264 commit 30e4cc0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
25 changes: 24 additions & 1 deletion connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,34 @@ void ksmbd_all_conn_set_status(u64 sess_id, u32 status)
up_read(&conn_list_lock);
}

void ksmbd_conn_wait_idle(struct ksmbd_conn *conn, u64 sess_id)
void ksmbd_conn_wait_idle(struct ksmbd_conn *conn)
{
wait_event(conn->req_running_q, atomic_read(&conn->req_running) < 2);
}

void ksmbd_conn_wait_idle_sess_id(u64 sess_id)
{
struct ksmbd_conn *conn;
int rc;

retry_idle:
down_read(&conn_list_lock);
list_for_each_entry(conn, &conn_list, conns_list) {
if (conn->binding || xa_load(&conn->sessions, sess_id)) {
if (atomic_read(&conn->req_running) != 0) {
rc = wait_event_timeout(conn->req_running_q,
atomic_read(&conn->req_running) == 0,
__msecs_to_jiffies(1000));
if (!rc) {
up_read(&conn_list_lock);
goto retry_idle;
}
}
}
}
up_read(&conn_list_lock);
}

int ksmbd_conn_write(struct ksmbd_work *work)
{
struct ksmbd_conn *conn = work->conn;
Expand Down
3 changes: 2 additions & 1 deletion connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ extern struct list_head conn_list;
extern struct rw_semaphore conn_list_lock;

bool ksmbd_conn_alive(struct ksmbd_conn *conn);
void ksmbd_conn_wait_idle(struct ksmbd_conn *conn, u64 sess_id);
void ksmbd_conn_wait_idle(struct ksmbd_conn *conn);
void ksmbd_conn_wait_idle_sess_id(u64 sess_id);
struct ksmbd_conn *ksmbd_conn_alloc(void);
void ksmbd_conn_free(struct ksmbd_conn *conn);
bool ksmbd_conn_lookup_dialect(struct ksmbd_conn *c);
Expand Down
6 changes: 3 additions & 3 deletions mgmt/user_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ void destroy_previous_session(struct ksmbd_conn *conn,
memcmp(user->passkey, prev_user->passkey, user->passkey_sz))
goto out;

ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_RECONNECT);
ksmbd_conn_wait_idle(conn, sess_id);
ksmbd_all_conn_set_status(id, KSMBD_SESS_NEED_RECONNECT);
ksmbd_conn_wait_idle_sess_id(id);

ksmbd_destroy_file_table(&prev_sess->file_table);
prev_sess->state = SMB2_SESSION_EXPIRED;
ksmbd_all_conn_set_status(sess_id, KSMBD_SESS_NEED_NEGOTIATE);
ksmbd_all_conn_set_status(id, KSMBD_SESS_NEED_NEGOTIATE);
ksmbd_launch_ksmbd_durable_scavenger();
out:
up_write(&conn->session_lock);
Expand Down
6 changes: 2 additions & 4 deletions smb2pdu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ int smb2_sess_setup(struct ksmbd_work *work)
unsigned int negblob_len, negblob_off;
int rc = 0;

pr_err("Received request for session setup\n");
ksmbd_debug(SMB, "Received request for session setup\n");

WORK_BUFFERS(work, req, rsp);

Expand Down Expand Up @@ -2228,7 +2228,7 @@ int smb2_session_logoff(struct ksmbd_work *work)
ksmbd_conn_unlock(conn);

ksmbd_close_session_fds(work);
ksmbd_conn_wait_idle(conn, sess_id);
ksmbd_conn_wait_idle(conn);

/*
* Re-lookup session to validate if session is deleted
Expand Down Expand Up @@ -2939,8 +2939,6 @@ int smb2_open(struct ksmbd_work *work)

WORK_BUFFERS(work, req, rsp);

msleep(1000 *5 );

if (req->hdr.NextCommand && !work->next_smb2_rcv_hdr_off &&
(req->hdr.Flags & SMB2_FLAGS_RELATED_OPERATIONS)) {
ksmbd_debug(SMB, "invalid flag in chained command\n");
Expand Down
1 change: 0 additions & 1 deletion vfs_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,6 @@ void ksmbd_destroy_file_table(struct ksmbd_file_table *ft)
__close_file_table_ids(ft, NULL, session_fd_check);
idr_destroy(ft->idr);
kfree(ft->idr);
msleep(1000 * 100);
ft->idr = NULL;
}

Expand Down

0 comments on commit 30e4cc0

Please sign in to comment.