Skip to content

Commit bef82d5

Browse files
metze-sambasmfrench
authored andcommitted
smb: client: make use of smbdirect_socket.{send,recv}_io.mem.{cache,pool}
This will allow common helper functions to be created later. 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 5ef8278 commit bef82d5

File tree

2 files changed

+34
-40
lines changed

2 files changed

+34
-40
lines changed

fs/smb/client/smbdirect.c

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
287287
if (wc->status != IB_WC_SUCCESS || wc->opcode != IB_WC_SEND) {
288288
log_rdma_send(ERR, "wc->status=%d wc->opcode=%d\n",
289289
wc->status, wc->opcode);
290-
mempool_free(request, info->request_mempool);
290+
mempool_free(request, sc->send_io.mem.pool);
291291
smbd_disconnect_rdma_connection(info);
292292
return;
293293
}
@@ -297,7 +297,7 @@ static void send_done(struct ib_cq *cq, struct ib_wc *wc)
297297

298298
wake_up(&info->wait_post_send);
299299

300-
mempool_free(request, info->request_mempool);
300+
mempool_free(request, sc->send_io.mem.pool);
301301
}
302302

303303
static void dump_smbdirect_negotiate_resp(struct smbdirect_negotiate_resp *resp)
@@ -692,7 +692,7 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
692692
struct smbdirect_send_io *request;
693693
struct smbdirect_negotiate_req *packet;
694694

695-
request = mempool_alloc(info->request_mempool, GFP_KERNEL);
695+
request = mempool_alloc(sc->send_io.mem.pool, GFP_KERNEL);
696696
if (!request)
697697
return rc;
698698

@@ -751,7 +751,7 @@ static int smbd_post_send_negotiate_req(struct smbd_connection *info)
751751
smbd_disconnect_rdma_connection(info);
752752

753753
dma_mapping_failed:
754-
mempool_free(request, info->request_mempool);
754+
mempool_free(request, sc->send_io.mem.pool);
755755
return rc;
756756
}
757757

@@ -883,7 +883,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
883883
goto wait_send_queue;
884884
}
885885

886-
request = mempool_alloc(info->request_mempool, GFP_KERNEL);
886+
request = mempool_alloc(sc->send_io.mem.pool, GFP_KERNEL);
887887
if (!request) {
888888
rc = -ENOMEM;
889889
goto err_alloc;
@@ -977,7 +977,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
977977
request->sge[i].addr,
978978
request->sge[i].length,
979979
DMA_TO_DEVICE);
980-
mempool_free(request, info->request_mempool);
980+
mempool_free(request, sc->send_io.mem.pool);
981981

982982
/* roll back receive credits and credits to be offered */
983983
spin_lock(&info->lock_new_credits_offered);
@@ -1235,7 +1235,7 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12351235
init_waitqueue_head(&info->wait_receive_queues);
12361236

12371237
for (i = 0; i < num_buf; i++) {
1238-
response = mempool_alloc(info->response_mempool, GFP_KERNEL);
1238+
response = mempool_alloc(sc->recv_io.mem.pool, GFP_KERNEL);
12391239
if (!response)
12401240
goto allocate_failed;
12411241

@@ -1255,17 +1255,18 @@ static int allocate_receive_buffers(struct smbd_connection *info, int num_buf)
12551255
list_del(&response->list);
12561256
info->count_receive_queue--;
12571257

1258-
mempool_free(response, info->response_mempool);
1258+
mempool_free(response, sc->recv_io.mem.pool);
12591259
}
12601260
return -ENOMEM;
12611261
}
12621262

12631263
static void destroy_receive_buffers(struct smbd_connection *info)
12641264
{
1265+
struct smbdirect_socket *sc = &info->socket;
12651266
struct smbdirect_recv_io *response;
12661267

12671268
while ((response = get_receive_buffer(info)))
1268-
mempool_free(response, info->response_mempool);
1269+
mempool_free(response, sc->recv_io.mem.pool);
12691270
}
12701271

12711272
/* Implement idle connection timer [MS-SMBD] 3.1.6.2 */
@@ -1377,11 +1378,11 @@ void smbd_destroy(struct TCP_Server_Info *server)
13771378
rdma_destroy_id(sc->rdma.cm_id);
13781379

13791380
/* free mempools */
1380-
mempool_destroy(info->request_mempool);
1381-
kmem_cache_destroy(info->request_cache);
1381+
mempool_destroy(sc->send_io.mem.pool);
1382+
kmem_cache_destroy(sc->send_io.mem.cache);
13821383

1383-
mempool_destroy(info->response_mempool);
1384-
kmem_cache_destroy(info->response_cache);
1384+
mempool_destroy(sc->recv_io.mem.pool);
1385+
kmem_cache_destroy(sc->recv_io.mem.cache);
13851386

13861387
sc->status = SMBDIRECT_SOCKET_DESTROYED;
13871388

@@ -1429,12 +1430,14 @@ int smbd_reconnect(struct TCP_Server_Info *server)
14291430

14301431
static void destroy_caches_and_workqueue(struct smbd_connection *info)
14311432
{
1433+
struct smbdirect_socket *sc = &info->socket;
1434+
14321435
destroy_receive_buffers(info);
14331436
destroy_workqueue(info->workqueue);
1434-
mempool_destroy(info->response_mempool);
1435-
kmem_cache_destroy(info->response_cache);
1436-
mempool_destroy(info->request_mempool);
1437-
kmem_cache_destroy(info->request_cache);
1437+
mempool_destroy(sc->recv_io.mem.pool);
1438+
kmem_cache_destroy(sc->recv_io.mem.cache);
1439+
mempool_destroy(sc->send_io.mem.pool);
1440+
kmem_cache_destroy(sc->send_io.mem.cache);
14381441
}
14391442

14401443
#define MAX_NAME_LEN 80
@@ -1449,19 +1452,19 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
14491452
return -ENOMEM;
14501453

14511454
scnprintf(name, MAX_NAME_LEN, "smbdirect_send_io_%p", info);
1452-
info->request_cache =
1455+
sc->send_io.mem.cache =
14531456
kmem_cache_create(
14541457
name,
14551458
sizeof(struct smbdirect_send_io) +
14561459
sizeof(struct smbdirect_data_transfer),
14571460
0, SLAB_HWCACHE_ALIGN, NULL);
1458-
if (!info->request_cache)
1461+
if (!sc->send_io.mem.cache)
14591462
return -ENOMEM;
14601463

1461-
info->request_mempool =
1464+
sc->send_io.mem.pool =
14621465
mempool_create(sp->send_credit_target, mempool_alloc_slab,
1463-
mempool_free_slab, info->request_cache);
1464-
if (!info->request_mempool)
1466+
mempool_free_slab, sc->send_io.mem.cache);
1467+
if (!sc->send_io.mem.pool)
14651468
goto out1;
14661469

14671470
scnprintf(name, MAX_NAME_LEN, "smbdirect_recv_io_%p", info);
@@ -1472,17 +1475,17 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
14721475
sizeof(struct smbdirect_data_transfer)),
14731476
.usersize = sp->max_recv_size - sizeof(struct smbdirect_data_transfer),
14741477
};
1475-
info->response_cache =
1478+
sc->recv_io.mem.cache =
14761479
kmem_cache_create(name,
14771480
sizeof(struct smbdirect_recv_io) + sp->max_recv_size,
14781481
&response_args, SLAB_HWCACHE_ALIGN);
1479-
if (!info->response_cache)
1482+
if (!sc->recv_io.mem.cache)
14801483
goto out2;
14811484

1482-
info->response_mempool =
1485+
sc->recv_io.mem.pool =
14831486
mempool_create(sp->recv_credit_max, mempool_alloc_slab,
1484-
mempool_free_slab, info->response_cache);
1485-
if (!info->response_mempool)
1487+
mempool_free_slab, sc->recv_io.mem.cache);
1488+
if (!sc->recv_io.mem.pool)
14861489
goto out3;
14871490

14881491
scnprintf(name, MAX_NAME_LEN, "smbd_%p", info);
@@ -1501,13 +1504,13 @@ static int allocate_caches_and_workqueue(struct smbd_connection *info)
15011504
out5:
15021505
destroy_workqueue(info->workqueue);
15031506
out4:
1504-
mempool_destroy(info->response_mempool);
1507+
mempool_destroy(sc->recv_io.mem.pool);
15051508
out3:
1506-
kmem_cache_destroy(info->response_cache);
1509+
kmem_cache_destroy(sc->recv_io.mem.cache);
15071510
out2:
1508-
mempool_destroy(info->request_mempool);
1511+
mempool_destroy(sc->send_io.mem.pool);
15091512
out1:
1510-
kmem_cache_destroy(info->request_cache);
1513+
kmem_cache_destroy(sc->send_io.mem.cache);
15111514
return -ENOMEM;
15121515
}
15131516

fs/smb/client/smbdirect.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,6 @@ struct smbd_connection {
105105
struct workqueue_struct *workqueue;
106106
struct delayed_work idle_timer_work;
107107

108-
/* Memory pool for preallocating buffers */
109-
/* request pool for RDMA send */
110-
struct kmem_cache *request_cache;
111-
mempool_t *request_mempool;
112-
113-
/* response pool for RDMA receive */
114-
struct kmem_cache *response_cache;
115-
mempool_t *response_mempool;
116-
117108
/* for debug purposes */
118109
unsigned int count_get_receive_buffer;
119110
unsigned int count_put_receive_buffer;

0 commit comments

Comments
 (0)