From owner-svn-src-stable@freebsd.org Fri Nov 27 15:19:38 2015 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 026A6A3ABC5; Fri, 27 Nov 2015 15:19:38 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id B39331372; Fri, 27 Nov 2015 15:19:37 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tARFJaAo067327; Fri, 27 Nov 2015 15:19:36 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tARFJafn067322; Fri, 27 Nov 2015 15:19:36 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201511271519.tARFJafn067322@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Fri, 27 Nov 2015 15:19:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r291387 - stable/10/usr.sbin/ctld X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Nov 2015 15:19:38 -0000 Author: mav Date: Fri Nov 27 15:19:36 2015 New Revision: 291387 URL: https://svnweb.freebsd.org/changeset/base/291387 Log: MFC r290615: Introduce portal group options in ctl.conf. While CTL has concept of port options, used at least for iSCSI ports now, before this change it was impossible to set them manually. There still no user-configurable port options now, but I am planning to change that. Modified: stable/10/usr.sbin/ctld/ctl.conf.5 stable/10/usr.sbin/ctld/ctld.c stable/10/usr.sbin/ctld/ctld.h stable/10/usr.sbin/ctld/kernel.c stable/10/usr.sbin/ctld/parse.y Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/ctld/ctl.conf.5 ============================================================================== --- stable/10/usr.sbin/ctld/ctl.conf.5 Fri Nov 27 14:40:59 2015 (r291386) +++ stable/10/usr.sbin/ctld/ctl.conf.5 Fri Nov 27 15:19:36 2015 (r291387) @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 27, 2015 +.Dd November 9, 2015 .Dt CTL.CONF 5 .Os .Sh NAME @@ -229,7 +229,9 @@ An IPv4 or IPv6 address and port to list .\".It Ic listen-iser Ar address .\"An IPv4 or IPv6 address and port to listen on for incoming connections .\"using iSER (iSCSI over RDMA) protocol. -.It Ic redirect Aq Ar address +.It Ic option Ar name Ar value +The CTL-specific port options passed to the kernel. +.It Ic redirect Ar address IPv4 or IPv6 address to redirect initiators to. When configured, all initiators attempting to connect to portal belonging to this Modified: stable/10/usr.sbin/ctld/ctld.c ============================================================================== --- stable/10/usr.sbin/ctld/ctld.c Fri Nov 27 14:40:59 2015 (r291386) +++ stable/10/usr.sbin/ctld/ctld.c Fri Nov 27 15:19:36 2015 (r291387) @@ -615,6 +615,7 @@ portal_group_new(struct conf *conf, cons if (pg == NULL) log_err(1, "calloc"); pg->pg_name = checked_strdup(name); + TAILQ_INIT(&pg->pg_options); TAILQ_INIT(&pg->pg_portals); TAILQ_INIT(&pg->pg_ports); pg->pg_conf = conf; @@ -629,6 +630,7 @@ portal_group_delete(struct portal_group { struct portal *portal, *tmp; struct port *port, *tport; + struct option *o, *otmp; TAILQ_FOREACH_SAFE(port, &pg->pg_ports, p_pgs, tport) port_delete(port); @@ -636,6 +638,8 @@ portal_group_delete(struct portal_group TAILQ_FOREACH_SAFE(portal, &pg->pg_portals, p_next, tmp) portal_delete(portal); + TAILQ_FOREACH_SAFE(o, &pg->pg_options, o_next, otmp) + option_delete(&pg->pg_options, o); free(pg->pg_name); free(pg->pg_redirection); free(pg); @@ -1389,7 +1393,7 @@ void lun_delete(struct lun *lun) { struct target *targ; - struct lun_option *lo, *tmp; + struct option *o, *tmp; int i; TAILQ_FOREACH(targ, &lun->l_conf->conf_targets, t_next) { @@ -1400,8 +1404,8 @@ lun_delete(struct lun *lun) } TAILQ_REMOVE(&lun->l_conf->conf_luns, lun, l_next); - TAILQ_FOREACH_SAFE(lo, &lun->l_options, lo_next, tmp) - lun_option_delete(lo); + TAILQ_FOREACH_SAFE(o, &lun->l_options, o_next, tmp) + option_delete(&lun->l_options, o); free(lun->l_name); free(lun->l_backend); free(lun->l_device_id); @@ -1487,59 +1491,56 @@ lun_set_ctl_lun(struct lun *lun, uint32_ lun->l_ctl_lun = value; } -struct lun_option * -lun_option_new(struct lun *lun, const char *name, const char *value) +struct option * +option_new(struct options *options, const char *name, const char *value) { - struct lun_option *lo; + struct option *o; - lo = lun_option_find(lun, name); - if (lo != NULL) { - log_warnx("duplicated lun option \"%s\" for lun \"%s\"", - name, lun->l_name); + o = option_find(options, name); + if (o != NULL) { + log_warnx("duplicated option \"%s\"", name); return (NULL); } - lo = calloc(1, sizeof(*lo)); - if (lo == NULL) + o = calloc(1, sizeof(*o)); + if (o == NULL) log_err(1, "calloc"); - lo->lo_name = checked_strdup(name); - lo->lo_value = checked_strdup(value); - lo->lo_lun = lun; - TAILQ_INSERT_TAIL(&lun->l_options, lo, lo_next); + o->o_name = checked_strdup(name); + o->o_value = checked_strdup(value); + TAILQ_INSERT_TAIL(options, o, o_next); - return (lo); + return (o); } void -lun_option_delete(struct lun_option *lo) +option_delete(struct options *options, struct option *o) { - TAILQ_REMOVE(&lo->lo_lun->l_options, lo, lo_next); - - free(lo->lo_name); - free(lo->lo_value); - free(lo); + TAILQ_REMOVE(options, o, o_next); + free(o->o_name); + free(o->o_value); + free(o); } -struct lun_option * -lun_option_find(const struct lun *lun, const char *name) +struct option * +option_find(const struct options *options, const char *name) { - struct lun_option *lo; + struct option *o; - TAILQ_FOREACH(lo, &lun->l_options, lo_next) { - if (strcmp(lo->lo_name, name) == 0) - return (lo); + TAILQ_FOREACH(o, options, o_next) { + if (strcmp(o->o_name, name) == 0) + return (o); } return (NULL); } void -lun_option_set(struct lun_option *lo, const char *value) +option_set(struct option *o, const char *value) { - free(lo->lo_value); - lo->lo_value = checked_strdup(value); + free(o->o_value); + o->o_value = checked_strdup(value); } static struct connection * @@ -1578,7 +1579,7 @@ conf_print(struct conf *conf) struct portal *portal; struct target *targ; struct lun *lun; - struct lun_option *lo; + struct option *o; TAILQ_FOREACH(ag, &conf->conf_auth_groups, ag_next) { fprintf(stderr, "auth-group %s {\n", ag->ag_name); @@ -1603,9 +1604,9 @@ conf_print(struct conf *conf) TAILQ_FOREACH(lun, &conf->conf_luns, l_next) { fprintf(stderr, "\tlun %s {\n", lun->l_name); fprintf(stderr, "\t\tpath %s\n", lun->l_path); - TAILQ_FOREACH(lo, &lun->l_options, lo_next) + TAILQ_FOREACH(o, &lun->l_options, o_next) fprintf(stderr, "\t\toption %s %s\n", - lo->lo_name, lo->lo_value); + lo->o_name, lo->o_value); fprintf(stderr, "\t}\n"); } TAILQ_FOREACH(targ, &conf->conf_targets, t_next) { Modified: stable/10/usr.sbin/ctld/ctld.h ============================================================================== --- stable/10/usr.sbin/ctld/ctld.h Fri Nov 27 14:40:59 2015 (r291386) +++ stable/10/usr.sbin/ctld/ctld.h Fri Nov 27 15:19:36 2015 (r291387) @@ -105,6 +105,8 @@ struct portal { int p_socket; }; +TAILQ_HEAD(options, option); + #define PG_FILTER_UNKNOWN 0 #define PG_FILTER_NONE 1 #define PG_FILTER_PORTAL 2 @@ -114,6 +116,7 @@ struct portal { struct portal_group { TAILQ_ENTRY(portal_group) pg_next; struct conf *pg_conf; + struct options pg_options; char *pg_name; struct auth_group *pg_discovery_auth_group; int pg_discovery_filter; @@ -151,17 +154,16 @@ struct port { uint32_t p_ctl_port; }; -struct lun_option { - TAILQ_ENTRY(lun_option) lo_next; - struct lun *lo_lun; - char *lo_name; - char *lo_value; +struct option { + TAILQ_ENTRY(option) o_next; + char *o_name; + char *o_value; }; struct lun { TAILQ_ENTRY(lun) l_next; struct conf *l_conf; - TAILQ_HEAD(, lun_option) l_options; + struct options l_options; char *l_name; char *l_backend; uint8_t l_device_type; @@ -382,13 +384,11 @@ void lun_set_serial(struct lun *lun, c void lun_set_size(struct lun *lun, size_t value); void lun_set_ctl_lun(struct lun *lun, uint32_t value); -struct lun_option *lun_option_new(struct lun *lun, +struct option *option_new(struct options *os, const char *name, const char *value); -void lun_option_delete(struct lun_option *clo); -struct lun_option *lun_option_find(const struct lun *lun, - const char *name); -void lun_option_set(struct lun_option *clo, - const char *value); +void option_delete(struct options *os, struct option *co); +struct option *option_find(const struct options *os, const char *name); +void option_set(struct option *o, const char *value); void kernel_init(void); int kernel_lun_add(struct lun *lun); Modified: stable/10/usr.sbin/ctld/kernel.c ============================================================================== --- stable/10/usr.sbin/ctld/kernel.c Fri Nov 27 14:40:59 2015 (r291386) +++ stable/10/usr.sbin/ctld/kernel.c Fri Nov 27 15:19:36 2015 (r291387) @@ -396,7 +396,7 @@ conf_new_from_kernel(void) struct pport *pp; struct port *cp; struct lun *cl; - struct lun_option *lo; + struct option *o; struct ctl_lun_list list; struct cctl_devlist_data devlist; struct cctl_lun *lun; @@ -626,8 +626,8 @@ retry_port: lun_set_path(cl, nv->value); continue; } - lo = lun_option_new(cl, nv->name, nv->value); - if (lo == NULL) + o = option_new(&cl->l_options, nv->name, nv->value); + if (o == NULL) log_warnx("unable to add CTL lun option %s " "for CTL lun %ju \"%s\"", nv->name, (uintmax_t) lun->lun_id, @@ -652,7 +652,7 @@ str_arg(struct ctl_be_arg *arg, const ch int kernel_lun_add(struct lun *lun) { - struct lun_option *lo; + struct option *o; struct ctl_lun_req req; int error, i, num_options; @@ -687,31 +687,31 @@ kernel_lun_add(struct lun *lun) } if (lun->l_path != NULL) { - lo = lun_option_find(lun, "file"); - if (lo != NULL) { - lun_option_set(lo, lun->l_path); + o = option_find(&lun->l_options, "file"); + if (o != NULL) { + option_set(o, lun->l_path); } else { - lo = lun_option_new(lun, "file", lun->l_path); - assert(lo != NULL); + o = option_new(&lun->l_options, "file", lun->l_path); + assert(o != NULL); } } - lo = lun_option_find(lun, "ctld_name"); - if (lo != NULL) { - lun_option_set(lo, lun->l_name); + o = option_find(&lun->l_options, "ctld_name"); + if (o != NULL) { + option_set(o, lun->l_name); } else { - lo = lun_option_new(lun, "ctld_name", lun->l_name); - assert(lo != NULL); + o = option_new(&lun->l_options, "ctld_name", lun->l_name); + assert(o != NULL); } - lo = lun_option_find(lun, "scsiname"); - if (lo == NULL && lun->l_scsiname != NULL) { - lo = lun_option_new(lun, "scsiname", lun->l_scsiname); - assert(lo != NULL); + o = option_find(&lun->l_options, "scsiname"); + if (o == NULL && lun->l_scsiname != NULL) { + o = option_new(&lun->l_options, "scsiname", lun->l_scsiname); + assert(o != NULL); } num_options = 0; - TAILQ_FOREACH(lo, &lun->l_options, lo_next) + TAILQ_FOREACH(o, &lun->l_options, o_next) num_options++; req.num_be_args = num_options; @@ -724,8 +724,8 @@ kernel_lun_add(struct lun *lun) } i = 0; - TAILQ_FOREACH(lo, &lun->l_options, lo_next) { - str_arg(&req.be_args[i], lo->lo_name, lo->lo_value); + TAILQ_FOREACH(o, &lun->l_options, o_next) { + str_arg(&req.be_args[i], o->o_name, o->o_value); i++; } assert(i == num_options); @@ -760,7 +760,7 @@ kernel_lun_add(struct lun *lun) int kernel_lun_modify(struct lun *lun) { - struct lun_option *lo; + struct option *o; struct ctl_lun_req req; int error, i, num_options; @@ -773,7 +773,7 @@ kernel_lun_modify(struct lun *lun) req.reqdata.modify.lun_size_bytes = lun->l_size; num_options = 0; - TAILQ_FOREACH(lo, &lun->l_options, lo_next) + TAILQ_FOREACH(o, &lun->l_options, o_next) num_options++; req.num_be_args = num_options; @@ -786,8 +786,8 @@ kernel_lun_modify(struct lun *lun) } i = 0; - TAILQ_FOREACH(lo, &lun->l_options, lo_next) { - str_arg(&req.be_args[i], lo->lo_name, lo->lo_value); + TAILQ_FOREACH(o, &lun->l_options, o_next) { + str_arg(&req.be_args[i], o->o_name, o->o_value); i++; } assert(i == num_options); @@ -907,6 +907,7 @@ kernel_handoff(struct connection *conn) int kernel_port_add(struct port *port) { + struct option *o; struct ctl_port_entry entry; struct ctl_req req; struct ctl_lun_map lm; @@ -921,6 +922,8 @@ kernel_port_add(struct port *port) strlcpy(req.driver, "iscsi", sizeof(req.driver)); req.reqtype = CTL_REQ_CREATE; req.num_args = 5; + TAILQ_FOREACH(o, &pg->pg_options, o_next) + req.num_args++; req.args = malloc(req.num_args * sizeof(*req.args)); if (req.args == NULL) log_err(1, "malloc"); @@ -936,6 +939,8 @@ kernel_port_add(struct port *port) if (targ->t_alias) str_arg(&req.args[n++], "cfiscsi_target_alias", targ->t_alias); str_arg(&req.args[n++], "ctld_portal_group_name", pg->pg_name); + TAILQ_FOREACH(o, &pg->pg_options, o_next) + str_arg(&req.args[n++], o->o_name, o->o_value); req.num_args = n; error = ioctl(ctl_fd, CTL_PORT_REQ, &req); free(req.args); Modified: stable/10/usr.sbin/ctld/parse.y ============================================================================== --- stable/10/usr.sbin/ctld/parse.y Fri Nov 27 14:40:59 2015 (r291386) +++ stable/10/usr.sbin/ctld/parse.y Fri Nov 27 15:19:36 2015 (r291387) @@ -344,6 +344,8 @@ portal_group_entry: | portal_group_listen_iser | + portal_group_option + | portal_group_redirect | portal_group_tag @@ -409,6 +411,18 @@ portal_group_listen_iser: LISTEN_ISER ST } ; +portal_group_option: OPTION STR STR + { + struct option *o; + + o = option_new(&portal_group->pg_options, $2, $3); + free($2); + free($3); + if (o == NULL) + return (1); + } + ; + portal_group_redirect: REDIRECT STR { int error; @@ -950,12 +964,12 @@ lun_ctl_lun: CTL_LUN STR lun_option: OPTION STR STR { - struct lun_option *clo; + struct option *o; - clo = lun_option_new(lun, $2, $3); + o = option_new(&lun->l_options, $2, $3); free($2); free($3); - if (clo == NULL) + if (o == NULL) return (1); } ;