Skip to content

Commit b685757

Browse files
Dawei Lismfrench
authored andcommitted
ksmbd: Implements sess->rpc_handle_list as xarray
For some ops on rpc handle: 1. ksmbd_session_rpc_method(), possibly on high frequency. 2. ksmbd_session_rpc_close(). id is used as indexing key to lookup channel, in that case, linear search based on list may suffer a bit for performance. Implements sess->rpc_handle_list as xarray. Signed-off-by: Dawei Li <set_pte_at@outlook.com> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 1d9c417 commit b685757

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

fs/ksmbd/mgmt/user_session.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ static DECLARE_RWSEM(sessions_table_lock);
2525
struct ksmbd_session_rpc {
2626
int id;
2727
unsigned int method;
28-
struct list_head list;
2928
};
3029

3130
static void free_channel_list(struct ksmbd_session *sess)
@@ -58,15 +57,14 @@ static void __session_rpc_close(struct ksmbd_session *sess,
5857
static 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

7270
static 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;
119117
free_id:
118+
xa_erase(&sess->rpc_handle_list, entry->id);
120119
ksmbd_rpc_id_free(entry->id);
121120
free_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

140134
int 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

151142
void ksmbd_session_destroy(struct ksmbd_session *sess)
@@ -327,7 +318,7 @@ static struct ksmbd_session *__session_create(int protocol)
327318
set_session_flag(sess, protocol);
328319
xa_init(&sess->tree_conns);
329320
xa_init(&sess->ksmbd_chann_list);
330-
INIT_LIST_HEAD(&sess->rpc_handle_list);
321+
xa_init(&sess->rpc_handle_list);
331322
sess->sequence_number = 1;
332323

333324
ret = __init_smb2_session(sess);

fs/ksmbd/mgmt/user_session.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct ksmbd_session {
5252
struct xarray ksmbd_chann_list;
5353
struct xarray tree_conns;
5454
struct ida tree_conn_ida;
55-
struct list_head rpc_handle_list;
55+
struct xarray rpc_handle_list;
5656

5757
__u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];
5858
__u8 smb3decryptionkey[SMB3_ENC_DEC_KEY_SIZE];

0 commit comments

Comments
 (0)