Skip to content

Commit 69b85e1

Browse files
maurizio-lombardiChristoph Hellwig
authored andcommitted
nvmet-tcp: add an helper to free the cmd buffers
Makes the code easier to read and to debug. Sets the freed pointers to NULL, it will be useful when destroying the queues to understand if the commands' buffers have been released already or not. Signed-off-by: Maurizio Lombardi <[email protected]> Reviewed-by: Keith Busch <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: John Meneghini <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent a208fc5 commit 69b85e1

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

drivers/nvme/target/tcp.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ static struct workqueue_struct *nvmet_tcp_wq;
166166
static const struct nvmet_fabrics_ops nvmet_tcp_ops;
167167
static void nvmet_tcp_free_cmd(struct nvmet_tcp_cmd *c);
168168
static void nvmet_tcp_finish_cmd(struct nvmet_tcp_cmd *cmd);
169+
static void nvmet_tcp_free_cmd_buffers(struct nvmet_tcp_cmd *cmd);
170+
static void nvmet_tcp_unmap_pdu_iovec(struct nvmet_tcp_cmd *cmd);
169171

170172
static inline u16 nvmet_tcp_cmd_tag(struct nvmet_tcp_queue *queue,
171173
struct nvmet_tcp_cmd *cmd)
@@ -297,6 +299,16 @@ static int nvmet_tcp_check_ddgst(struct nvmet_tcp_queue *queue, void *pdu)
297299
return 0;
298300
}
299301

302+
static void nvmet_tcp_free_cmd_buffers(struct nvmet_tcp_cmd *cmd)
303+
{
304+
WARN_ON(unlikely(cmd->nr_mapped > 0));
305+
306+
kfree(cmd->iov);
307+
sgl_free(cmd->req.sg);
308+
cmd->iov = NULL;
309+
cmd->req.sg = NULL;
310+
}
311+
300312
static void nvmet_tcp_unmap_pdu_iovec(struct nvmet_tcp_cmd *cmd)
301313
{
302314
struct scatterlist *sg;
@@ -306,6 +318,8 @@ static void nvmet_tcp_unmap_pdu_iovec(struct nvmet_tcp_cmd *cmd)
306318

307319
for (i = 0; i < cmd->nr_mapped; i++)
308320
kunmap(sg_page(&sg[i]));
321+
322+
cmd->nr_mapped = 0;
309323
}
310324

311325
static void nvmet_tcp_map_pdu_iovec(struct nvmet_tcp_cmd *cmd)
@@ -387,7 +401,7 @@ static int nvmet_tcp_map_data(struct nvmet_tcp_cmd *cmd)
387401

388402
return 0;
389403
err:
390-
sgl_free(cmd->req.sg);
404+
nvmet_tcp_free_cmd_buffers(cmd);
391405
return NVME_SC_INTERNAL;
392406
}
393407

@@ -632,10 +646,8 @@ static int nvmet_try_send_data(struct nvmet_tcp_cmd *cmd, bool last_in_batch)
632646
}
633647
}
634648

635-
if (queue->nvme_sq.sqhd_disabled) {
636-
kfree(cmd->iov);
637-
sgl_free(cmd->req.sg);
638-
}
649+
if (queue->nvme_sq.sqhd_disabled)
650+
nvmet_tcp_free_cmd_buffers(cmd);
639651

640652
return 1;
641653

@@ -664,8 +676,7 @@ static int nvmet_try_send_response(struct nvmet_tcp_cmd *cmd,
664676
if (left)
665677
return -EAGAIN;
666678

667-
kfree(cmd->iov);
668-
sgl_free(cmd->req.sg);
679+
nvmet_tcp_free_cmd_buffers(cmd);
669680
cmd->queue->snd_cmd = NULL;
670681
nvmet_tcp_put_cmd(cmd);
671682
return 1;
@@ -1406,8 +1417,7 @@ static void nvmet_tcp_finish_cmd(struct nvmet_tcp_cmd *cmd)
14061417
{
14071418
nvmet_req_uninit(&cmd->req);
14081419
nvmet_tcp_unmap_pdu_iovec(cmd);
1409-
kfree(cmd->iov);
1410-
sgl_free(cmd->req.sg);
1420+
nvmet_tcp_free_cmd_buffers(cmd);
14111421
}
14121422

14131423
static void nvmet_tcp_uninit_data_in_cmds(struct nvmet_tcp_queue *queue)

0 commit comments

Comments
 (0)