From ea8f1280a206a662b8afb343522adf5cc34e4569 Mon Sep 17 00:00:00 2001 From: Richard Scheffenegger Date: Sat, 24 Oct 2020 21:10:53 +0000 Subject: [PATCH] Add network QoS support for PCP to iscsi target. Mak the Ethernet PCP codepoint configurable for L2 local traffic, to allow lower latency for iSCSI block IO. This addresses the target side only. Reviewed by: mav, trasz, bcr Sponsored by: NetApp, Inc. Differential Revision: https://reviews.freebsd.org/D26740 --- usr.sbin/ctld/ctl.conf.5 | 7 +++++++ usr.sbin/ctld/ctld.c | 27 +++++++++++++++++++++++++++ usr.sbin/ctld/ctld.h | 1 + usr.sbin/ctld/parse.y | 24 ++++++++++++++++++++++-- usr.sbin/ctld/token.l | 1 + usr.sbin/ctld/uclparse.c | 13 +++++++++++++ 6 files changed, 71 insertions(+), 2 deletions(-) diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5 index 68766af3ae60..f4827d042ac1 100644 --- a/usr.sbin/ctld/ctl.conf.5 +++ b/usr.sbin/ctld/ctl.conf.5 @@ -258,6 +258,13 @@ well-defined and .Qq Ar AFxx codepoints. +.It Ic pcp Ar value +The 802.1Q Priority CodePoint used for sending packets. +The PCP can be set to a value in the range between +.Qq Ar 0 +to +.Qq Ar 7 . +When omitted, the default for the outgoing interface is used. .El .Ss target Context .Bl -tag -width indent diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index 76f5ffc6c801..978680eb93f6 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -626,6 +626,7 @@ portal_group_new(struct conf *conf, const char *name) pg->pg_conf = conf; pg->pg_tag = 0; /* Assigned later in conf_apply(). */ pg->pg_dscp = -1; + pg->pg_pcp = -1; TAILQ_INSERT_TAIL(&conf->conf_portal_groups, pg, pg_next); return (pg); @@ -2214,6 +2215,32 @@ conf_apply(struct conf *oldconf, struct conf *newconf) newp->p_listen); } } + if (newpg->pg_pcp != -1) { + struct sockaddr sa; + int len = sizeof(sa); + getsockname(newp->p_socket, &sa, &len); + /* + * Only allow the 6-bit DSCP + * field to be modified + */ + int pcp = newpg->pg_pcp; + if (sa.sa_family == AF_INET) { + if (setsockopt(newp->p_socket, + IPPROTO_IP, IP_VLAN_PCP, + &pcp, sizeof(pcp)) == -1) + log_warn("setsockopt(IP_VLAN_PCP) " + "failed for %s", + newp->p_listen); + } else + if (sa.sa_family == AF_INET6) { + if (setsockopt(newp->p_socket, + IPPROTO_IPV6, IPV6_VLAN_PCP, + &pcp, sizeof(pcp)) == -1) + log_warn("setsockopt(IPV6_VLAN_PCP) " + "failed for %s", + newp->p_listen); + } + } error = bind(newp->p_socket, newp->p_ai->ai_addr, newp->p_ai->ai_addrlen); if (error != 0) { diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h index 317fd0c33040..212e35cbb4be 100644 --- a/usr.sbin/ctld/ctld.h +++ b/usr.sbin/ctld/ctld.h @@ -128,6 +128,7 @@ struct portal_group { char *pg_offload; char *pg_redirection; int pg_dscp; + int pg_pcp; uint16_t pg_tag; }; diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y index b6903890210b..7ef6cb7c2e5c 100644 --- a/usr.sbin/ctld/parse.y +++ b/usr.sbin/ctld/parse.y @@ -65,8 +65,8 @@ extern void yyrestart(FILE *); %token DISCOVERY_AUTH_GROUP DISCOVERY_FILTER DSCP FOREIGN %token INITIATOR_NAME INITIATOR_PORTAL ISNS_SERVER ISNS_PERIOD ISNS_TIMEOUT %token LISTEN LISTEN_ISER LUN MAXPROC OFFLOAD OPENING_BRACKET OPTION -%token PATH PIDFILE PORT PORTAL_GROUP REDIRECT SEMICOLON SERIAL SIZE STR -%token TAG TARGET TIMEOUT +%token PATH PCP PIDFILE PORT PORTAL_GROUP REDIRECT SEMICOLON SERIAL +%token SIZE STR TAG TARGET TIMEOUT %token AF11 AF12 AF13 AF21 AF22 AF23 AF31 AF32 AF33 AF41 AF42 AF43 %token BE EF CS0 CS1 CS2 CS3 CS4 CS5 CS6 CS7 @@ -359,6 +359,8 @@ portal_group_entry: portal_group_tag | portal_group_dscp + | + portal_group_pcp ; portal_group_discovery_auth_group: DISCOVERY_AUTH_GROUP STR @@ -512,6 +514,24 @@ portal_group_dscp | DSCP AF43 { portal_group->pg_dscp = IPTOS_DSCP_AF43 >> 2 ; } ; +portal_group_pcp: PCP STR + { + uint64_t tmp; + + if (expand_number($2, &tmp) != 0) { + yyerror("invalid numeric value"); + free($2); + return (1); + } + if (!((tmp >= 0) && (tmp <= 7))) { + yyerror("invalid pcp value"); + free($2); + return (1); + } + + portal_group->pg_pcp = tmp; + } + ; lun: LUN lun_name OPENING_BRACKET lun_entries CLOSING_BRACKET diff --git a/usr.sbin/ctld/token.l b/usr.sbin/ctld/token.l index 30b7d770e691..7b8db415e410 100644 --- a/usr.sbin/ctld/token.l +++ b/usr.sbin/ctld/token.l @@ -64,6 +64,7 @@ device-type { return DEVICE_TYPE; } discovery-auth-group { return DISCOVERY_AUTH_GROUP; } discovery-filter { return DISCOVERY_FILTER; } dscp { return DSCP; } +pcp { return PCP; } foreign { return FOREIGN; } initiator-name { return INITIATOR_NAME; } initiator-portal { return INITIATOR_PORTAL; } diff --git a/usr.sbin/ctld/uclparse.c b/usr.sbin/ctld/uclparse.c index caf4d25bb6df..b73e6b48b2f6 100644 --- a/usr.sbin/ctld/uclparse.c +++ b/usr.sbin/ctld/uclparse.c @@ -672,6 +672,19 @@ uclparse_portal_group(const char *name, const ucl_object_t *top) } } } + + if (!strcmp(key, "pcp")) { + if (obj->type != UCL_INT) { + log_warnx("\"pcp\" property of portal group " + "\"%s\" is not an integer", portal_group->pg_name); + return(1); + } + portal_group->pg_pcp = ucl_object_toint(obj); + if (!((portal_group->pg_pcp >= 0) && (portal_group->pg_pcp <= 7))) { + log_warnx("invalid \"pcp\" value %d, using default", portal_group->pg_pcp); + portal_group->pg_pcp = -1; + } + } } return (0);