Skip to content

Commit 5dddf04

Browse files
metze-sambasmfrench
authored andcommitted
smb: client: make use of struct smbdirect_recv_io
This is the shared structure that will be used in the server too and will allow us to move helper functions into common code soon. Cc: Steve French <[email protected]> Cc: Tom Talpey <[email protected]> Cc: Long Li <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Stefan Metzmacher <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 60812d2 commit 5dddf04

File tree

2 files changed

+41
-54
lines changed

2 files changed

+41
-54
lines changed

fs/smb/client/smbdirect.c

Lines changed: 41 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
#include "cifsproto.h"
1414
#include "smb2proto.h"
1515

16-
static struct smbd_response *get_receive_buffer(
16+
static struct smbdirect_recv_io *get_receive_buffer(
1717
struct smbd_connection *info);
1818
static void put_receive_buffer(
1919
struct smbd_connection *info,
20-
struct smbd_response *response);
20+
struct smbdirect_recv_io *response);
2121
static int allocate_receive_buffers(struct smbd_connection *info, int num_buf);
2222
static void destroy_receive_buffers(struct smbd_connection *info);
2323

2424
static void enqueue_reassembly(
2525
struct smbd_connection *info,
26-
struct smbd_response *response, int data_length);
27-
static struct smbd_response *_get_first_reassembly(
26+
struct smbdirect_recv_io *response, int data_length);
27+
static struct smbdirect_recv_io *_get_first_reassembly(
2828
struct smbd_connection *info);
2929

3030
static int smbd_post_recv(
3131
struct smbd_connection *info,
32-
struct smbd_response *response);
32+
struct smbdirect_recv_io *response);
3333

3434
static int smbd_post_send_empty(struct smbd_connection *info);
3535

@@ -260,7 +260,7 @@ static inline void *smbd_request_payload(struct smbd_request *request)
260260
return (void *)request->packet;
261261
}
262262

263-
static inline void *smbd_response_payload(struct smbd_response *response)
263+
static inline void *smbdirect_recv_io_payload(struct smbdirect_recv_io *response)
264264
{
265265
return (void *)response->packet;
266266
}
@@ -315,12 +315,13 @@ static void dump_smbdirect_negotiate_resp(struct smbdirect_negotiate_resp *resp)
315315
* return value: true if negotiation is a success, false if failed
316316
*/
317317
static bool process_negotiation_response(
318-
struct smbd_response *response, int packet_length)
318+
struct smbdirect_recv_io *response, int packet_length)
319319
{
320-
struct smbd_connection *info = response->info;
321-
struct smbdirect_socket *sc = &info->socket;
320+
struct smbdirect_socket *sc = response->socket;
321+
struct smbd_connection *info =
322+
container_of(sc, struct smbd_connection, socket);
322323
struct smbdirect_socket_parameters *sp = &sc->parameters;
323-
struct smbdirect_negotiate_resp *packet = smbd_response_payload(response);
324+
struct smbdirect_negotiate_resp *packet = smbdirect_recv_io_payload(response);
324325

325326
if (packet_length < sizeof(struct smbdirect_negotiate_resp)) {
326327
log_rdma_event(ERR,
@@ -391,7 +392,7 @@ static void smbd_post_send_credits(struct work_struct *work)
391392
{
392393
int ret = 0;
393394
int rc;
394-
struct smbd_response *response;
395+
struct smbdirect_recv_io *response;
395396
struct smbd_connection *info =
396397
container_of(work, struct smbd_connection,
397398
post_send_credits_work);
@@ -442,10 +443,11 @@ static void smbd_post_send_credits(struct work_struct *work)
442443
static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
443444
{
444445
struct smbdirect_data_transfer *data_transfer;
445-
struct smbd_response *response =
446-
container_of(wc->wr_cqe, struct smbd_response, cqe);
447-
struct smbd_connection *info = response->info;
448-
struct smbdirect_socket *sc = &info->socket;
446+
struct smbdirect_recv_io *response =
447+
container_of(wc->wr_cqe, struct smbdirect_recv_io, cqe);
448+
struct smbdirect_socket *sc = response->socket;
449+
struct smbd_connection *info =
450+
container_of(sc, struct smbd_connection, socket);
449451
int data_length = 0;
450452

451453
log_rdma_recv(INFO, "response=0x%p type=%d wc status=%d wc opcode %d byte_len=%d pkey_index=%u\n",
@@ -467,7 +469,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
467469
switch (sc->recv_io.expected) {
468470
/* SMBD negotiation response */
469471
case SMBDIRECT_EXPECT_NEGOTIATE_REP:
470-
dump_smbdirect_negotiate_resp(smbd_response_payload(response));
472+
dump_smbdirect_negotiate_resp(smbdirect_recv_io_payload(response));
471473
info->full_packet_received = true;
472474
info->negotiate_done =
473475
process_negotiation_response(response, wc->byte_len);
@@ -477,7 +479,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
477479

478480
/* SMBD data transfer packet */
479481
case SMBDIRECT_EXPECT_DATA_TRANSFER:
480-
data_transfer = smbd_response_payload(response);
482+
data_transfer = smbdirect_recv_io_payload(response);
481483
data_length = le32_to_cpu(data_transfer->data_length);
482484

483485
if (data_length) {
@@ -1034,7 +1036,7 @@ static int smbd_post_send_full_iter(struct smbd_connection *info,
10341036
* The interaction is controlled by send/receive credit system
10351037
*/
10361038
static int smbd_post_recv(
1037-
struct smbd_connection *info, struct smbd_response *response)
1039+
struct smbd_connection *info, struct smbdirect_recv_io *response)
10381040
{
10391041
struct smbdirect_socket *sc = &info->socket;
10401042
struct smbdirect_socket_parameters *sp = &sc->parameters;
@@ -1074,7 +1076,7 @@ static int smbd_negotiate(struct smbd_connection *info)
10741076
{
10751077
struct smbdirect_socket *sc = &info->socket;
10761078
int rc;
1077-
struct smbd_response *response = get_receive_buffer(info);
1079+
struct smbdirect_recv_io *response = get_receive_buffer(info);
10781080

10791081
sc->recv_io.expected = SMBDIRECT_EXPECT_NEGOTIATE_REP;
10801082
rc = smbd_post_recv(info, response);
@@ -1119,7 +1121,7 @@ static int smbd_negotiate(struct smbd_connection *info)
11191121
*/
11201122
static void enqueue_reassembly(
11211123
struct smbd_connection *info,
1122-
struct smbd_response *response,
1124+
struct smbdirect_recv_io *response,
11231125
int data_length)
11241126
{
11251127
spin_lock(&info->reassembly_queue_lock);
@@ -1143,14 +1145,14 @@ static void enqueue_reassembly(
11431145
* Caller is responsible for locking
11441146
* return value: the first entry if any, NULL if queue is empty
11451147
*/
1146-
static struct smbd_response *_get_first_reassembly(struct smbd_connection *info)
1148+
static struct smbdirect_recv_io *_get_first_reassembly(struct smbd_connection *info)
11471149
{
1148-
struct smbd_response *ret = NULL;
1150+
struct smbdirect_recv_io *ret = NULL;
11491151

11501152
if (!list_empty(&info->reassembly_queue)) {
11511153
ret = list_first_entry(
11521154
&info->reassembly_queue,
1153-
struct smbd_response, list);
1155+
struct smbdirect_recv_io, list);
11541156
}
11551157
return ret;
11561158
}
@@ -1161,16 +1163,16 @@ static struct smbd_response *_get_first_reassembly(struct smbd_connection *info)
11611163
* pre-allocated in advance.
11621164
* return value: the receive buffer, NULL if none is available
11631165
*/
1164-
static struct smbd_response *get_receive_buffer(struct smbd_connection *info)
1166+
static struct smbdirect_recv_io *get_receive_buffer(struct smbd_connection *info)
11651167
{
1166-
struct smbd_response *ret = NULL;
1168+
struct smbdirect_recv_io *ret = NULL;
11671169
unsigned long flags;
11681170

11691171
spin_lock_irqsave(&info->receive_queue_lock, flags);
11701172
if (!list_empty(&info->receive_queue)) {
11711173
ret = list_first_entry(
11721174
&info->receive_queue,
1173-
struct smbd_response, list);
1175+
struct smbdirect_recv_io, list);
11741176
list_del(&ret->list);
11751177
info->count_receive_queue--;
11761178
info->count_get_receive_buffer++;
@@ -1187,7 +1189,7 @@ static struct smbd_response *get_receive_buffer(struct smbd_connection *info)
11871189
* receive buffer is returned.
11881190
*/
11891191
static void put_receive_buffer(
1190-
struct smbd_connection *info, struct smbd_response *response)
1192+
struct smbd_connection *info, struct smbdirect_recv_io *response)
11911193
{
11921194
struct smbdirect_socket *sc = &info->socket;
11931195
unsigned long flags;
@@ -1212,8 +1214,9 @@ static void put_receive_buffer(
12121214
/* Preallocate all receive buffer on transport establishment */
12131215
static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12141216
{
1217+
struct smbdirect_socket *sc = &info->socket;
1218+
struct smbdirect_recv_io *response;
12151219
int i;
1216-
struct smbd_response *response;
12171220

12181221
INIT_LIST_HEAD(&info->reassembly_queue);
12191222
spin_lock_init(&info->reassembly_queue_lock);
@@ -1231,7 +1234,7 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12311234
if (!response)
12321235
goto allocate_failed;
12331236

1234-
response->info = info;
1237+
response->socket = sc;
12351238
response->sge.length = 0;
12361239
list_add_tail(&response->list, &info->receive_queue);
12371240
info->count_receive_queue++;
@@ -1243,7 +1246,7 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12431246
while (!list_empty(&info->receive_queue)) {
12441247
response = list_first_entry(
12451248
&info->receive_queue,
1246-
struct smbd_response, list);
1249+
struct smbdirect_recv_io, list);
12471250
list_del(&response->list);
12481251
info->count_receive_queue--;
12491252

@@ -1254,7 +1257,7 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12541257

12551258
static void destroy_receive_buffers(struct smbd_connection *info)
12561259
{
1257-
struct smbd_response *response;
1260+
struct smbdirect_recv_io *response;
12581261

12591262
while ((response = get_receive_buffer(info)))
12601263
mempool_free(response, info->response_mempool);
@@ -1295,7 +1298,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
12951298
struct smbd_connection *info = server->smbd_conn;
12961299
struct smbdirect_socket *sc;
12971300
struct smbdirect_socket_parameters *sp;
1298-
struct smbd_response *response;
1301+
struct smbdirect_recv_io *response;
12991302
unsigned long flags;
13001303

13011304
if (!info) {
@@ -1456,17 +1459,17 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
14561459
if (!info->request_mempool)
14571460
goto out1;
14581461

1459-
scnprintf(name, MAX_NAME_LEN, "smbd_response_%p", info);
1462+
scnprintf(name, MAX_NAME_LEN, "smbdirect_recv_io_%p", info);
14601463

14611464
struct kmem_cache_args response_args = {
1462-
.align = __alignof__(struct smbd_response),
1463-
.useroffset = (offsetof(struct smbd_response, packet) +
1465+
.align = __alignof__(struct smbdirect_recv_io),
1466+
.useroffset = (offsetof(struct smbdirect_recv_io, packet) +
14641467
sizeof(struct smbdirect_data_transfer)),
14651468
.usersize = sp->max_recv_size - sizeof(struct smbdirect_data_transfer),
14661469
};
14671470
info->response_cache =
14681471
kmem_cache_create(name,
1469-
sizeof(struct smbd_response) + sp->max_recv_size,
1472+
sizeof(struct smbdirect_recv_io) + sp->max_recv_size,
14701473
&response_args, SLAB_HWCACHE_ALIGN);
14711474
if (!info->response_cache)
14721475
goto out2;
@@ -1756,7 +1759,7 @@ struct smbd_connection *smbd_get_connection(
17561759
int smbd_recv(struct smbd_connection *info, struct msghdr *msg)
17571760
{
17581761
struct smbdirect_socket *sc = &info->socket;
1759-
struct smbd_response *response;
1762+
struct smbdirect_recv_io *response;
17601763
struct smbdirect_data_transfer *data_transfer;
17611764
size_t size = iov_iter_count(&msg->msg_iter);
17621765
int to_copy, to_read, data_read, offset;
@@ -1792,7 +1795,7 @@ int smbd_recv(struct smbd_connection *info, struct msghdr *msg)
17921795
offset = info->first_entry_offset;
17931796
while (data_read < size) {
17941797
response = _get_first_reassembly(info);
1795-
data_transfer = smbd_response_payload(response);
1798+
data_transfer = smbdirect_recv_io_payload(response);
17961799
data_length = le32_to_cpu(data_transfer->data_length);
17971800
remaining_data_length =
17981801
le32_to_cpu(

fs/smb/client/smbdirect.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,6 @@ struct smbd_request {
175175
/* Maximum number of SGEs used by smbdirect.c in any receive work request */
176176
#define SMBDIRECT_MAX_RECV_SGE 1
177177

178-
/* The context for a SMBD response */
179-
struct smbd_response {
180-
struct smbd_connection *info;
181-
struct ib_cqe cqe;
182-
struct ib_sge sge;
183-
184-
/* Link to receive queue or reassembly queue */
185-
struct list_head list;
186-
187-
/* Indicate if this is the 1st packet of a payload */
188-
bool first_segment;
189-
190-
/* SMBD packet header and payload follows this structure */
191-
u8 packet[];
192-
};
193-
194178
/* Create a SMBDirect session */
195179
struct smbd_connection *smbd_get_connection(
196180
struct TCP_Server_Info *server, struct sockaddr *dstaddr);

0 commit comments

Comments
 (0)