Message ID | 20220311030113.73384-3-sunmingbao@tom.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | NVMe/TCP: support specifying the congestion-control | expand |
On Fri, Mar 11, 2022 at 11:01:12AM +0800, Mingbao Sun wrote: > + case NVMF_OPT_TCP_CONGESTION: > + p = match_strdup(args); > + if (!p) { > + ret = -ENOMEM; > + goto out; > + } > + > + kfree(opts->tcp_congestion); > + opts->tcp_congestion = p; We'll need to check that the string is no loner than TCP_CA_NAME_MAX somewhere. > > + if (nctrl->opts->mask & NVMF_OPT_TCP_CONGESTION) { > + ret = tcp_set_congestion_control(queue->sock->sk, > + nctrl->opts->tcp_congestion, > + true, true); This needs to be called under lock_sock() protection. Maybe also add an assert to tcp_set_congestion_control to enforce that.
On Fri, 11 Mar 2022 08:15:18 +0100 Christoph Hellwig <hch@lst.de> wrote: > On Fri, Mar 11, 2022 at 11:01:12AM +0800, Mingbao Sun wrote: > > + case NVMF_OPT_TCP_CONGESTION: > > + p = match_strdup(args); > > + if (!p) { > > + ret = -ENOMEM; > > + goto out; > > + } > > + > > + kfree(opts->tcp_congestion); > > + opts->tcp_congestion = p; > > We'll need to check that the string is no loner than TCP_CA_NAME_MAX > somewhere. > accept. will do that in the next version. this would also be applied for the target side. > > > > + if (nctrl->opts->mask & NVMF_OPT_TCP_CONGESTION) { > > + ret = tcp_set_congestion_control(queue->sock->sk, > > + nctrl->opts->tcp_congestion, > > + true, true); > > This needs to be called under lock_sock() protection. Maybe also > add an assert to tcp_set_congestion_control to enforce that. accept. will handle it in the next version. this would also be applied for the target side. Many thanks for reminding. as for the assertion, I failed to find a conventional way to do that. would you like to give me a suggestion?
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c index ee79a6d639b4..79d5f0dbafd3 100644 --- a/drivers/nvme/host/fabrics.c +++ b/drivers/nvme/host/fabrics.c @@ -548,6 +548,7 @@ static const match_table_t opt_tokens = { { NVMF_OPT_TOS, "tos=%d" }, { NVMF_OPT_FAIL_FAST_TMO, "fast_io_fail_tmo=%d" }, { NVMF_OPT_DISCOVERY, "discovery" }, + { NVMF_OPT_TCP_CONGESTION, "tcp_congestion=%s" }, { NVMF_OPT_ERR, NULL } }; @@ -829,6 +830,16 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, case NVMF_OPT_DISCOVERY: opts->discovery_nqn = true; break; + case NVMF_OPT_TCP_CONGESTION: + p = match_strdup(args); + if (!p) { + ret = -ENOMEM; + goto out; + } + + kfree(opts->tcp_congestion); + opts->tcp_congestion = p; + break; default: pr_warn("unknown parameter or missing value '%s' in ctrl creation request\n", p); @@ -947,6 +958,7 @@ void nvmf_free_options(struct nvmf_ctrl_options *opts) kfree(opts->subsysnqn); kfree(opts->host_traddr); kfree(opts->host_iface); + kfree(opts->tcp_congestion); kfree(opts); } EXPORT_SYMBOL_GPL(nvmf_free_options); diff --git a/drivers/nvme/host/fabrics.h b/drivers/nvme/host/fabrics.h index c3203ff1c654..25fdc169949d 100644 --- a/drivers/nvme/host/fabrics.h +++ b/drivers/nvme/host/fabrics.h @@ -68,6 +68,7 @@ enum { NVMF_OPT_FAIL_FAST_TMO = 1 << 20, NVMF_OPT_HOST_IFACE = 1 << 21, NVMF_OPT_DISCOVERY = 1 << 22, + NVMF_OPT_TCP_CONGESTION = 1 << 23, }; /** @@ -117,6 +118,7 @@ struct nvmf_ctrl_options { unsigned int nr_io_queues; unsigned int reconnect_delay; bool discovery_nqn; + const char *tcp_congestion; bool duplicate_connect; unsigned int kato; struct nvmf_host *host; diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 10fc45d95b86..f2a6df35374a 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -1487,6 +1487,18 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl, if (nctrl->opts->tos >= 0) ip_sock_set_tos(queue->sock->sk, nctrl->opts->tos); + if (nctrl->opts->mask & NVMF_OPT_TCP_CONGESTION) { + ret = tcp_set_congestion_control(queue->sock->sk, + nctrl->opts->tcp_congestion, + true, true); + if (ret) { + dev_err(nctrl->device, + "failed to set TCP congestion to %s: %d\n", + nctrl->opts->tcp_congestion, ret); + goto err_sock; + } + } + /* Set 10 seconds timeout for icresp recvmsg */ queue->sock->sk->sk_rcvtimeo = 10 * HZ; @@ -2650,7 +2662,8 @@ static struct nvmf_transport_ops nvme_tcp_transport = { NVMF_OPT_HOST_TRADDR | NVMF_OPT_CTRL_LOSS_TMO | NVMF_OPT_HDR_DIGEST | NVMF_OPT_DATA_DIGEST | NVMF_OPT_NR_WRITE_QUEUES | NVMF_OPT_NR_POLL_QUEUES | - NVMF_OPT_TOS | NVMF_OPT_HOST_IFACE, + NVMF_OPT_TOS | NVMF_OPT_HOST_IFACE | + NVMF_OPT_TCP_CONGESTION, .create_ctrl = nvme_tcp_create_ctrl, };