Skip to contentSkip to conversation

nvme: Add type of service (TOS) configuration

PATCH Superseded Israel Rukshin 4 participants 13 messages Aug 14, 2019 – Aug 15, 2019

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v3 cover nvme: Add type of service (TOS) configuration

Hi All,

This series adds TOS configuration for TCP and RDMA transports. It provides clients the ability to segregate traffic flows for different type of data.
One of the TOS usage is bandwidth management which allows setting bandwidth limits for QoS classes, e.g. 80% bandwidth to controllers at QoS class A and 20% to controllers at QoS class B.

Changes from v2:
- Clamping tos to 255

Changes from v1:
- Add TCP TOS configuration

Israel Rukshin (5):
nvme-fabrics: Add type of service (TOS) configuration
nvme-rdma: Add TOS for rdma transport
nvme-tcp: Use struct nvme_ctrl directly
nvme-tcp: Add TOS for tcp transport
nvmet-tcp: Add TOS for tcp transport

 drivers/nvme/host/fabrics.c | 20 +++++++++++++++++++-
 drivers/nvme/host/fabrics.h |  3 +++
 drivers/nvme/host/rdma.c    |  6 ++++--
 drivers/nvme/host/tcp.c     | 32 ++++++++++++++++++++++----------
 drivers/nvme/target/tcp.c   | 11 +++++++++++
 5 files changed, 59 insertions(+), 13 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/1 nvme-cli/fabrics: Add tos param to connect cmd

Added 'tos' to 'connect' command so users can specify the type of service.

usage examples:
nvme connect --tos=0 --transport=rdma --traddr=10.0.1.1 --nqn=test-nvme nvme connect -T 0 -t rdma -a 10.0.1.1 -n test_nvme

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
---
 fabrics.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)
fabrics.c +24 -9
index 333669f..f952722 100644
@@ -60,6 +60,7 @@ static struct config {
 	int  keep_alive_tmo;
 	int  reconnect_delay;
 	int  ctrl_loss_tmo;
+	int  tos;
 	char *raw;
 	char *device;
 	int  duplicate_connect;
@@ -576,11 +577,12 @@ add_bool_argument(char **argstr, int *max_len, char *arg_str, bool arg)
 }
 
 static int
-add_int_argument(char **argstr, int *max_len, char *arg_str, int arg)
+add_int_argument(char **argstr, int *max_len, char *arg_str, int arg,
+		 bool allow_zero)
 {
 	int len;
 
-	if (arg) {
+	if ((arg && !allow_zero) || (arg != -1 && allow_zero)) {
 		len = snprintf(*argstr, *max_len, ",%s=%d", arg_str, arg);
 		if (len < 0)
 			return -EINVAL;
@@ -640,21 +642,23 @@ static int build_options(char *argstr, int max_len, bool discover)
 		    add_argument(&argstr, &max_len, "hostid", cfg.hostid)) ||
 	    (!discover &&
 	      add_int_argument(&argstr, &max_len, "nr_io_queues",
-				cfg.nr_io_queues)) ||
+				cfg.nr_io_queues, false)) ||
 	    add_int_argument(&argstr, &max_len, "nr_write_queues",
-				cfg.nr_write_queues) ||
+				cfg.nr_write_queues, false) ||
 	    add_int_argument(&argstr, &max_len, "nr_poll_queues",
-				cfg.nr_poll_queues) ||
+				cfg.nr_poll_queues, false) ||
 	    (!discover &&
 	      add_int_argument(&argstr, &max_len, "queue_size",
-				cfg.queue_size)) ||
+				cfg.queue_size, false)) ||
 	    (!discover &&
 	      add_int_argument(&argstr, &max_len, "keep_alive_tmo",
-				cfg.keep_alive_tmo)) ||
+				cfg.keep_alive_tmo, false)) ||
 	    add_int_argument(&argstr, &max_len, "reconnect_delay",
-				cfg.reconnect_delay) ||
+				cfg.reconnect_delay, false) ||
 	    add_int_argument(&argstr, &max_len, "ctrl_loss_tmo",
-				cfg.ctrl_loss_tmo) ||
+				cfg.ctrl_loss_tmo, false) ||
+	    add_int_argument(&argstr, &max_len, "tos",
+				cfg.tos, true) ||
 	    add_bool_argument(&argstr, &max_len, "duplicate_connect",
 				cfg.duplicate_connect) ||
 	    add_bool_argument(&argstr, &max_len, "disable_sqflow",
@@ -749,6 +753,13 @@ retry:
 		p += len;
 	}
 
+	if (cfg.tos != -1) {
+		len = sprintf(p, ",tos=%d", cfg.tos);
+		if (len < 0)
+			return -EINVAL;
+		p += len;
+	}
+
 	if (cfg.keep_alive_tmo && !discover) {
 		len = sprintf(p, ",keep_alive_tmo=%d", cfg.keep_alive_tmo);
 		if (len < 0)
@@ -1065,6 +1076,7 @@ int discover(const char *desc, int argc, char **argv, bool connect)
 		{"keep-alive-tmo",  'k', "LIST", CFG_INT, &cfg.keep_alive_tmo,  required_argument, "keep alive timeout period in seconds" },
 		{"reconnect-delay", 'c', "LIST", CFG_INT, &cfg.reconnect_delay, required_argument, "reconnect timeout period in seconds" },
 		{"ctrl-loss-tmo",   'l', "LIST", CFG_INT, &cfg.ctrl_loss_tmo,   required_argument, "controller loss timeout period in seconds" },
+		{"tos",             'T', "LIST", CFG_INT, &cfg.tos,             required_argument, "type of service" },
 		{"hdr_digest", 'g', "", CFG_NONE, &cfg.hdr_digest, no_argument, "enable transport protocol header digest (TCP transport)" },
 		{"data_digest", 'G', "", CFG_NONE, &cfg.data_digest, no_argument, "enable transport protocol data digest (TCP transport)" },
 		{"nr-io-queues",    'i', "LIST", CFG_INT, &cfg.nr_io_queues,    required_argument, "number of io queues to use (default is core count)" },
@@ -1076,6 +1088,7 @@ int discover(const char *desc, int argc, char **argv, bool connect)
 		{NULL},
 	};
 
+	cfg.tos = -1;
 	ret = argconfig_parse(argc, argv, desc, command_line_options, &cfg,
 			sizeof(cfg));
 	if (ret)
@@ -1122,6 +1135,7 @@ int connect(const char *desc, int argc, char **argv)
 		{"keep-alive-tmo",  'k', "LIST", CFG_INT, &cfg.keep_alive_tmo,  required_argument, "keep alive timeout period in seconds" },
 		{"reconnect-delay", 'c', "LIST", CFG_INT, &cfg.reconnect_delay, required_argument, "reconnect timeout period in seconds" },
 		{"ctrl-loss-tmo",   'l', "LIST", CFG_INT, &cfg.ctrl_loss_tmo,   required_argument, "controller loss timeout period in seconds" },
+		{"tos",             'T', "LIST", CFG_INT, &cfg.tos,             required_argument, "type of service" },
 		{"duplicate_connect", 'D', "", CFG_NONE, &cfg.duplicate_connect, no_argument, "allow duplicate connections between same transport host and subsystem port" },
 		{"disable_sqflow", 'd', "", CFG_NONE, &cfg.disable_sqflow, no_argument, "disable controller sq flow control (default false)" },
 		{"hdr_digest", 'g', "", CFG_NONE, &cfg.hdr_digest, no_argument, "enable transport protocol header digest (TCP transport)" },
@@ -1129,6 +1143,7 @@ int connect(const char *desc, int argc, char **argv)
 		{NULL},
 	};
 
+	cfg.tos = -1;
 	ret = argconfig_parse(argc, argv, desc, command_line_options, &cfg,
 			sizeof(cfg));
 	if (ret)
Signature · 1 line
1.8.3.1
maintainer
#2 lore raw

PATCH 1/1 nvme-cli/fabrics: Add tos param to connect cmd

Quoted 6 lines

Added 'tos' to 'connect' command so users can specify the type of service.

usage examples:
nvme connect --tos=0 --transport=rdma --traddr=10.0.1.1 --nqn=test-nvme nvme connect -T 0 -t rdma -a 10.0.1.1 -n test_nvme

Still don't see how this is handled if the kernel does not support tos yet.

#3 lore raw

PATCH 1/1 nvme-cli/fabrics: Add tos param to connect cmd

Quoted 10 lines · Sagi Grimberg
Quoted 7 lines

Added 'tos' to 'connect' command so users can specify the type of service.

usage examples:
nvme connect --tos=0 --transport=rdma --traddr=10.0.1.1 --nqn=test-nvme nvme connect -T 0 -t rdma -a 10.0.1.1 -n test_nvme

Still don't see how this is handled if the kernel does not support tos yet.

how any other feature we added to connect command will act with old kernel ? (e.g. queue_size/nr_queues)

it will fail to get token "token = match_token(p, opt_tokens, args);" and return? -EINVAL.

Israel checked that.

#4 lore raw

PATCH 1/1 nvme-cli/fabrics: Add tos param to connect cmd

Quoted 13 lines · Max Gurtovoy
Quoted 10 lines · Sagi Grimberg
Quoted 7 lines

Added 'tos' to 'connect' command so users can specify the type of service.

usage examples:
nvme connect --tos=0 --transport=rdma --traddr=10.0.1.1 --nqn=test-nvme nvme connect -T 0 -t rdma -a 10.0.1.1 -n test_nvme

Still don't see how this is handled if the kernel does not support tos yet.

Quoted 7 lines

how any other feature we added to connect command will act with old kernel ? (e.g. queue_size/nr_queues)

it will fail to get token "token = match_token(p, opt_tokens, args);" and return? -EINVAL.

Israel checked that.

I think what Sagi's getting at is: it would be really nice to not fail the whole connect request if an argument can't be parsed. E.g. a newer cli, used on an older kernel, should be functional with or without the tos argument.

If so- as I doubt the cli knows what was invalid or which argument was invalid and it would be really odd (especially over time) to back out arguments and try again - we need to update the kernel to warn that an argument was not parsed and was ignored, but attempt to use what it does recognize and not return failure to the cli.? Sagi ?

-- james

maintainer
#5 lore raw

PATCH 1/1 nvme-cli/fabrics: Add tos param to connect cmd

Quoted 24 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Added 'tos' to 'connect' command so users can specify the type of service.

usage examples:
nvme connect --tos=0 --transport=rdma --traddr=10.0.1.1 --nqn=test-nvme nvme connect -T 0 -t rdma -a 10.0.1.1 -n test_nvme

Still don't see how this is handled if the kernel does not support tos yet.

Quoted 7 lines

how any other feature we added to connect command will act with old kernel ? (e.g. queue_size/nr_queues)

it will fail to get token "token = match_token(p, opt_tokens, args);" and return? -EINVAL.

Israel checked that.

I think what Sagi's getting at is: it would be really nice to not fail the whole connect request if an argument can't be parsed. E.g. a newer cli, used on an older kernel, should be functional with or without the tos argument.

Quoted 5 lines

If so- as I doubt the cli knows what was invalid or which argument was invalid and it would be really odd (especially over time) to back out arguments and try again - we need to update the kernel to warn that an argument was not parsed and was ignored, but attempt to use what it does recognize and not return failure to the cli.? Sagi ?

Actually, I think its fine. I got it confused with another case where nvme-cli generates this argument on its own from the discovery log page (like the sqflow_disable thing).

I think we're fine here, we can ignore my comment...

#6 lore raw

PATCH v3 1/5 nvme-fabrics: Add type of service (TOS) configuration

In reply to Israel Rukshin

TOS is user-defined and needs to be configured via nvme-cli. It must be set before initiating any traffic and once set the TOS cannot be changed.

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
---
 drivers/nvme/host/fabrics.c | 20 +++++++++++++++++++-
 drivers/nvme/host/fabrics.h |  3 +++
 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/nvme/host/fabrics.c +19 -1
index 1994d5b..d343c22 100644
@@ -611,6 +611,7 @@ bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
 	{ NVMF_OPT_DATA_DIGEST,		"data_digest"		},
 	{ NVMF_OPT_NR_WRITE_QUEUES,	"nr_write_queues=%d"	},
 	{ NVMF_OPT_NR_POLL_QUEUES,	"nr_poll_queues=%d"	},
+	{ NVMF_OPT_TOS,			"tos=%d"		},
 	{ NVMF_OPT_ERR,			NULL			}
 };
 
@@ -632,6 +633,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
 	opts->duplicate_connect = false;
 	opts->hdr_digest = false;
 	opts->data_digest = false;
+	opts->tos = -1; /* < 0 == use transport default */
 
 	options = o = kstrdup(buf, GFP_KERNEL);
 	if (!options)
@@ -856,6 +858,22 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
 			}
 			opts->nr_poll_queues = token;
 			break;
+		case NVMF_OPT_TOS:
+			if (match_int(args, &token)) {
+				ret = -EINVAL;
+				goto out;
+			}
+			if (token < 0) {
+				pr_err("Invalid type of service %d\n", token);
+				ret = -EINVAL;
+				goto out;
+			}
+			if (token > 255) {
+				pr_warn("Clamping type of service to 255\n");
+				token = 255;
+			}
+			opts->tos = token;
+			break;
 		default:
 			pr_warn("unknown parameter or missing value '%s' in ctrl creation request\n",
 				p);
@@ -975,7 +993,7 @@ void nvmf_free_options(struct nvmf_ctrl_options *opts)
 #define NVMF_ALLOWED_OPTS	(NVMF_OPT_QUEUE_SIZE | NVMF_OPT_NR_IO_QUEUES | \
 				 NVMF_OPT_KATO | NVMF_OPT_HOSTNQN | \
 				 NVMF_OPT_HOST_ID | NVMF_OPT_DUP_CONNECT |\
-				 NVMF_OPT_DISABLE_SQFLOW)
+				 NVMF_OPT_DISABLE_SQFLOW | NVMF_OPT_TOS)
 
 static struct nvme_ctrl *
 nvmf_create_ctrl(struct device *dev, const char *buf)
drivers/nvme/host/fabrics.h +3 -0
index 3044d8b..93f08d7 100644
@@ -55,6 +55,7 @@ enum {
 	NVMF_OPT_DATA_DIGEST	= 1 << 16,
 	NVMF_OPT_NR_WRITE_QUEUES = 1 << 17,
 	NVMF_OPT_NR_POLL_QUEUES = 1 << 18,
+	NVMF_OPT_TOS		= 1 << 19,
 };
 
 /**
@@ -87,6 +88,7 @@ enum {
  * @data_digest: generate/verify data digest (TCP)
  * @nr_write_queues: number of queues for write I/O
  * @nr_poll_queues: number of queues for polling I/O
+ * @tos: type of service
  */
 struct nvmf_ctrl_options {
 	unsigned		mask;
@@ -108,6 +110,7 @@ struct nvmf_ctrl_options {
 	bool			data_digest;
 	unsigned int		nr_write_queues;
 	unsigned int		nr_poll_queues;
+	int			tos;
 };
 
 /*
Signature · 1 line
1.8.3.1
maintainer
#7 lore raw

PATCH 1/5 nvme-fabrics: Add type of service (TOS) configuration

Quoted 39 lines · Israel Rukshin

TOS is user-defined and needs to be configured via nvme-cli. It must be set before initiating any traffic and once set the TOS cannot be changed.

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
---
  drivers/nvme/host/fabrics.c | 20 +++++++++++++++++++-
  drivers/nvme/host/fabrics.h |  3 +++
  2 files changed, 22 insertions(+), 1 deletion(-)
drivers/nvme/host/fabrics.c +6 -0
index 1994d5b..d343c22 100644
@@ -611,6 +611,7 @@ bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
  	{ NVMF_OPT_DATA_DIGEST,		"data_digest"		},
  	{ NVMF_OPT_NR_WRITE_QUEUES,	"nr_write_queues=%d"	},
  	{ NVMF_OPT_NR_POLL_QUEUES,	"nr_poll_queues=%d"	},
+	{ NVMF_OPT_TOS,			"tos=%d"		},
  	{ NVMF_OPT_ERR,			NULL			}
  };
 
@@ -632,6 +633,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
  	opts->duplicate_connect = false;
  	opts->hdr_digest = false;
  	opts->data_digest = false;
+	opts->tos = -1; /* < 0 == use transport default */
 
  	options = o = kstrdup(buf, GFP_KERNEL);
  	if (!options)
@@ -856,6 +858,22 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
  			}
  			opts->nr_poll_queues = token;
  			break;
+		case NVMF_OPT_TOS:
+			if (match_int(args, &token)) {
+				ret = -EINVAL;
+				goto out;

drivers/nvme/host/fabrics.c static int nvmf_parse_options(struct nvmf_ctrl_options *opts, · line 874

Quoted 10 lines
drivers/nvme/host/fabrics.c +10 -0
+			}
+			if (token < 0) {
+				pr_err("Invalid type of service %d\n", token);
+				ret = -EINVAL;
+				goto out;
+			}
+			if (token > 255) {
+				pr_warn("Clamping type of service to 255\n");
+				token = 255;
+			}

Again, if tos is an abstract opaque, this needs to happen in the individual transports, not in the generic part.

#8 lore raw

PATCH 1/5 nvme-fabrics: Add type of service (TOS) configuration

Quoted 48 lines · Sagi Grimberg
Quoted 45 lines · Israel Rukshin

TOS is user-defined and needs to be configured via nvme-cli. It must be set before initiating any traffic and once set the TOS cannot be changed.

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>

---
? drivers/nvme/host/fabrics.c | 20 +++++++++++++++++++- ? drivers/nvme/host/fabrics.h |? 3 +++
? 2 files changed, 22 insertions(+), 1 deletion(-)

drivers/nvme/host/fabrics.c +1 -0
index 1994d5b..d343c22 100644
@@ -611,6 +611,7 @@ bool __nvmf_check_ready(struct nvme_ctrl *ctrl, 
 struct request *rq,
 ????? { NVMF_OPT_DATA_DIGEST,??????? "data_digest"??????? },
 ????? { NVMF_OPT_NR_WRITE_QUEUES,??? "nr_write_queues=%d"??? },
 ????? { NVMF_OPT_NR_POLL_QUEUES,??? "nr_poll_queues=%d"??? },
+??? { NVMF_OPT_TOS,??????????? "tos=%d"??????? },
 ????? { NVMF_OPT_ERR,??????????? NULL??????????? }
 ? };

? @@ -632,6 +633,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
????? opts->duplicate_connect = false;
????? opts->hdr_digest = false;
????? opts->data_digest = false;
+??? opts->tos = -1; /* < 0 == use transport default */ ? ????? options = o = kstrdup(buf, GFP_KERNEL); ????? if (!options)

drivers/nvme/host/fabrics.c +9 -0
@@ -856,6 +858,22 @@ static int nvmf_parse_options(struct 
 nvmf_ctrl_options *opts,
 ????????????? }
 ????????????? opts->nr_poll_queues = token;
 ????????????? break;
+??????? case NVMF_OPT_TOS:
+??????????? if (match_int(args, &token)) {
+??????????????? ret = -EINVAL;
+??????????????? goto out;
+??????????? }
+??????????? if (token < 0) {
+??????????????? pr_err("Invalid type of service %d\n", token);
+??????????????? ret = -EINVAL;
+??????????????? goto out;
Quoted 8 lines

drivers/nvme/host/fabrics.c static int nvmf_parse_options(struct · line 875

Quoted 5 lines
drivers/nvme/host/fabrics.c +5 -0
+??????????? }
+??????????? if (token > 255) {
+??????????????? pr_warn("Clamping type of service to 255\n");
+??????????????? token = 255;
+??????????? }

Again, if tos is an abstract opaque, this needs to happen in the individual transports, not in the generic part.

right, we'll add it to .allowed_opts in the rdma.c and tcp.c and remove from NVMF_ALLOWED_OPTS in V4.

We'll leave the parsing in the common code.

-Max.

#9 lore raw

PATCH v3 2/5 nvme-rdma: Add TOS for rdma transport

In reply to Israel Rukshin

For RDMA transports, TOS is an extension of IB QoS to provide clients the ability to segregate traffic flows for different type of data. RDMA CM abstract it for ULPs using rdma_set_service_type(). Internally, each traffic flow is represented by a connection with all of its independent resources like that of a normal connection, and is differentiated by service type. In other words, there can be multiple qp connections between an IP pair and each supports a unique service type.

One of the TOS usage is bandwidth management which allows setting bandwidth limits for QoS classes, e.g. 80% bandwidth to controllers at QoS class A and 20% to controllers at QoS class B.

Note: In addition to the TOS configuration, QOS must be configured on the relevant HCA on the target (send RDMA commands) and initiator to effect the traffic.

usage example:
nvme connect --tos=0 --transport=rdma --traddr=10.0.1.1 --nqn=test-nvme

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
Reviewed-by Sagi Grimberg <sagi at grimberg.me>
---
 drivers/nvme/host/rdma.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/nvme/host/rdma.c +4 -2
index a249db5..9fd3d33 100644
@@ -1541,16 +1541,18 @@ static int nvme_rdma_conn_rejected(struct nvme_rdma_queue *queue,
 
 static int nvme_rdma_addr_resolved(struct nvme_rdma_queue *queue)
 {
+	struct nvme_ctrl *ctrl = &queue->ctrl->ctrl;
 	int ret;
 
 	ret = nvme_rdma_create_queue_ib(queue);
 	if (ret)
 		return ret;
 
+	if (ctrl->opts->tos >= 0)
+		rdma_set_service_type(queue->cm_id, ctrl->opts->tos);
 	ret = rdma_resolve_route(queue->cm_id, NVME_RDMA_CONNECT_TIMEOUT_MS);
 	if (ret) {
-		dev_err(queue->ctrl->ctrl.device,
-			"rdma_resolve_route failed (%d).\n",
+		dev_err(ctrl->device, "rdma_resolve_route failed (%d).\n",
 			queue->cm_error);
 		goto out_destroy_queue;
 	}
Signature · 1 line
1.8.3.1
#10 lore raw

PATCH v3 3/5 nvme-tcp: Use struct nvme_ctrl directly

In reply to Israel Rukshin

This patch doesn't change any functionality.

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
Reviewed-by Sagi Grimberg <sagi at grimberg.me>
---
 drivers/nvme/host/tcp.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/nvme/host/tcp.c +10 -10
index 606b13d..feed0dc 100644
@@ -1255,7 +1255,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	queue->queue_size = queue_size;
 
 	if (qid > 0)
-		queue->cmnd_capsule_len = ctrl->ctrl.ioccsz * 16;
+		queue->cmnd_capsule_len = nctrl->ioccsz * 16;
 	else
 		queue->cmnd_capsule_len = sizeof(struct nvme_command) +
 						NVME_TCP_ADMIN_CCSZ;
@@ -1263,7 +1263,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	ret = sock_create(ctrl->addr.ss_family, SOCK_STREAM,
 			IPPROTO_TCP, &queue->sock);
 	if (ret) {
-		dev_err(ctrl->ctrl.device,
+		dev_err(nctrl->device,
 			"failed to create socket: %d\n", ret);
 		return ret;
 	}
@@ -1273,7 +1273,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	ret = kernel_setsockopt(queue->sock, IPPROTO_TCP, TCP_SYNCNT,
 			(char *)&opt, sizeof(opt));
 	if (ret) {
-		dev_err(ctrl->ctrl.device,
+		dev_err(nctrl->device,
 			"failed to set TCP_SYNCNT sock opt %d\n", ret);
 		goto err_sock;
 	}
@@ -1283,7 +1283,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	ret = kernel_setsockopt(queue->sock, IPPROTO_TCP,
 			TCP_NODELAY, (char *)&opt, sizeof(opt));
 	if (ret) {
-		dev_err(ctrl->ctrl.device,
+		dev_err(nctrl->device,
 			"failed to set TCP_NODELAY sock opt %d\n", ret);
 		goto err_sock;
 	}
@@ -1296,7 +1296,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	ret = kernel_setsockopt(queue->sock, SOL_SOCKET, SO_LINGER,
 			(char *)&sol, sizeof(sol));
 	if (ret) {
-		dev_err(ctrl->ctrl.device,
+		dev_err(nctrl->device,
 			"failed to set SO_LINGER sock opt %d\n", ret);
 		goto err_sock;
 	}
@@ -1314,11 +1314,11 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	queue->pdu_offset = 0;
 	sk_set_memalloc(queue->sock->sk);
 
-	if (ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR) {
+	if (nctrl->opts->mask & NVMF_OPT_HOST_TRADDR) {
 		ret = kernel_bind(queue->sock, (struct sockaddr *)&ctrl->src_addr,
 			sizeof(ctrl->src_addr));
 		if (ret) {
-			dev_err(ctrl->ctrl.device,
+			dev_err(nctrl->device,
 				"failed to bind queue %d socket %d\n",
 				qid, ret);
 			goto err_sock;
@@ -1330,7 +1330,7 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 	if (queue->hdr_digest || queue->data_digest) {
 		ret = nvme_tcp_alloc_crypto(queue);
 		if (ret) {
-			dev_err(ctrl->ctrl.device,
+			dev_err(nctrl->device,
 				"failed to allocate queue %d crypto\n", qid);
 			goto err_sock;
 		}
@@ -1344,13 +1344,13 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 		goto err_crypto;
 	}
 
-	dev_dbg(ctrl->ctrl.device, "connecting queue %d\n",
+	dev_dbg(nctrl->device, "connecting queue %d\n",
 			nvme_tcp_queue_id(queue));
 
 	ret = kernel_connect(queue->sock, (struct sockaddr *)&ctrl->addr,
 		sizeof(ctrl->addr), 0);
 	if (ret) {
-		dev_err(ctrl->ctrl.device,
+		dev_err(nctrl->device,
 			"failed to connect socket: %d\n", ret);
 		goto err_rcv_pdu;
 	}
Signature · 1 line
1.8.3.1
#11 lore raw

PATCH v3 4/5 nvme-tcp: Add TOS for tcp transport

In reply to Israel Rukshin

TOS provide clients the ability to segregate traffic flows for different type of data.
One of the TOS usage is bandwidth management which allows setting bandwidth limits for QoS classes, e.g. 80% bandwidth to controllers at QoS class A and 20% to controllers at QoS class B.

usage example:
nvme connect --tos=0 --transport=tcp --traddr=10.0.1.1 --nqn=test-nvme

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
Reviewed-by Sagi Grimberg <sagi at grimberg.me>
---
 drivers/nvme/host/tcp.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/nvme/host/tcp.c +12 -0
index feed0dc..229017f 100644
@@ -1301,6 +1301,18 @@ static int nvme_tcp_alloc_queue(struct nvme_ctrl *nctrl,
 		goto err_sock;
 	}
 
+	/* Set socket type of service */
+	if (nctrl->opts->tos >= 0) {
+		opt = nctrl->opts->tos;
+		ret = kernel_setsockopt(queue->sock, SOL_IP, IP_TOS,
+				(char *)&opt, sizeof(opt));
+		if (ret) {
+			dev_err(nctrl->device,
+				"failed to set IP_TOS sock opt %d\n", ret);
+			goto err_sock;
+		}
+	}
+
 	queue->sock->sk->sk_allocation = GFP_ATOMIC;
 	if (!qid)
 		n = 0;
Signature · 1 line
1.8.3.1
#12 lore raw

PATCH v3 5/5 nvmet-tcp: Add TOS for tcp transport

In reply to Israel Rukshin

Set the outgoing packets type of service (TOS) according to the receiving TOS.

Signed-off-by Israel Rukshin <israelr at mellanox.com>
Suggested-by Sagi Grimberg <sagi at grimberg.me>
Reviewed-by Max Gurtovoy <maxg at mellanox.com>
Reviewed-by Sagi Grimberg <sagi at grimberg.me>
---
 drivers/nvme/target/tcp.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/nvme/target/tcp.c +11 -0
index 69b83fa..fdf10ee 100644
@@ -1410,6 +1410,7 @@ static void nvmet_tcp_state_change(struct sock *sk)
 static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)
 {
 	struct socket *sock = queue->sock;
+	struct inet_sock *inet = inet_sk(sock->sk);
 	struct linger sol = { .l_onoff = 1, .l_linger = 0 };
 	int ret;
 
@@ -1433,6 +1434,16 @@ static int nvmet_tcp_set_queue_sock(struct nvmet_tcp_queue *queue)
 	if (ret)
 		return ret;
 
+	/* Set socket type of service */
+	if (inet->rcv_tos > 0) {
+		int tos = inet->rcv_tos;
+
+		ret = kernel_setsockopt(sock, SOL_IP, IP_TOS,
+				(char *)&tos, sizeof(tos));
+		if (ret)
+			return ret;
+	}
+
 	write_lock_bh(&sock->sk->sk_callback_lock);
 	sock->sk->sk_user_data = queue;
 	queue->data_ready = sock->sk->sk_data_ready;
Signature · 1 line
1.8.3.1