[PATCH 07/18] nvme/tcp: allocate socket file
Sagi Grimberg
sagi at grimberg.me
Tue Mar 21 06:52:36 PDT 2023
On 3/21/23 14:43, Hannes Reinecke wrote:
> When using the TLS upcall we need to allocate a socket file such
> that the userspace daemon is able to use the socket.
>
> Signed-off-by: Hannes Reinecke <hare at suse.de>
> ---
> drivers/nvme/host/tcp.c | 21 +++++++++++++++++++--
> 1 file changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c
> index 0512eb289dcf..0438d42f4179 100644
> --- a/drivers/nvme/host/tcp.c
> +++ b/drivers/nvme/host/tcp.c
> @@ -115,6 +115,7 @@ enum nvme_tcp_recv_state {
> struct nvme_tcp_ctrl;
> struct nvme_tcp_queue {
> struct socket *sock;
> + struct file *sock_file;
> struct work_struct io_work;
> int io_cpu;
>
> @@ -1330,7 +1331,12 @@ static void nvme_tcp_free_queue(struct nvme_ctrl *nctrl, int qid)
> }
>
> noreclaim_flag = memalloc_noreclaim_save();
> - sock_release(queue->sock);
> + if (queue->sock_file) {
> + fput(queue->sock_file);
> + queue->sock_file = NULL;
> + /* ->sock will be released by fput() */
> + } else
> + sock_release(queue->sock);
> memalloc_noreclaim_restore(noreclaim_flag);
>
> kfree(queue->pdu);
> @@ -1526,6 +1532,12 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid)
> goto err_destroy_mutex;
> }
>
> + queue->sock_file = sock_alloc_file(queue->sock, O_CLOEXEC, NULL);
> + if (IS_ERR(queue->sock_file)) {
> + ret = PTR_ERR(queue->sock_file);
> + queue->sock_file = NULL;
> + goto err_sock;
> + }
If a sock_file is always allocated, and fail the connection if
unsuccessful, why do you check on its existence when freeing the queue?
> nvme_tcp_reclassify_socket(queue->sock);
>
> /* Single syn retry */
> @@ -1647,7 +1659,12 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, int qid)
> if (queue->hdr_digest || queue->data_digest)
> nvme_tcp_free_crypto(queue);
> err_sock:
> - sock_release(queue->sock);
> + if (queue->sock_file) {
> + fput(queue->sock_file);
> + queue->sock_file = NULL;
> + /* ->sock will be released by fput() */
> + } else
> + sock_release(queue->sock);
> queue->sock = NULL;
> err_destroy_mutex:
> mutex_destroy(&queue->send_mutex);
More information about the Linux-nvme
mailing list