Author: mav
Date: Mon Nov  9 18:33:36 2015
New Revision: 290615
URL: https://svnweb.freebsd.org/changeset/base/290615

Log:
  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:
  head/usr.sbin/ctld/ctl.conf.5
  head/usr.sbin/ctld/ctld.c
  head/usr.sbin/ctld/ctld.h
  head/usr.sbin/ctld/kernel.c
  head/usr.sbin/ctld/parse.y

Modified: head/usr.sbin/ctld/ctl.conf.5
==============================================================================
--- head/usr.sbin/ctld/ctl.conf.5       Mon Nov  9 17:57:32 2015        
(r290614)
+++ head/usr.sbin/ctld/ctl.conf.5       Mon Nov  9 18:33:36 2015        
(r290615)
@@ -28,7 +28,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd September 27, 2015
+.Dd November 9, 2015
 .Dt CTL.CONF 5
 .Os
 .Sh NAME
@@ -226,6 +226,8 @@ An IPv4 or IPv6 address and port to list
 .It Ic offload Ar driver
 Define iSCSI hardware offload driver to use for this
 .Sy portal-group .
+.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

Modified: head/usr.sbin/ctld/ctld.c
==============================================================================
--- head/usr.sbin/ctld/ctld.c   Mon Nov  9 17:57:32 2015        (r290614)
+++ head/usr.sbin/ctld/ctld.c   Mon Nov  9 18:33:36 2015        (r290615)
@@ -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_offload);
        free(pg->pg_redirection);
@@ -1406,7 +1410,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) {
@@ -1417,8 +1421,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);
@@ -1504,59 +1508,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 *
@@ -1595,7 +1596,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);
@@ -1620,9 +1621,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: head/usr.sbin/ctld/ctld.h
==============================================================================
--- head/usr.sbin/ctld/ctld.h   Mon Nov  9 17:57:32 2015        (r290614)
+++ head/usr.sbin/ctld/ctld.h   Mon Nov  9 18:33:36 2015        (r290615)
@@ -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;
@@ -152,17 +155,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;
@@ -386,13 +388,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: head/usr.sbin/ctld/kernel.c
==============================================================================
--- head/usr.sbin/ctld/kernel.c Mon Nov  9 17:57:32 2015        (r290614)
+++ head/usr.sbin/ctld/kernel.c Mon Nov  9 18:33:36 2015        (r290615)
@@ -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);
@@ -945,6 +945,7 @@ kernel_limits(const char *offload, size_
 int
 kernel_port_add(struct port *port)
 {
+       struct option *o;
        struct ctl_port_entry entry;
        struct ctl_req req;
        struct ctl_lun_map lm;
@@ -959,6 +960,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");
@@ -974,6 +977,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: head/usr.sbin/ctld/parse.y
==============================================================================
--- head/usr.sbin/ctld/parse.y  Mon Nov  9 17:57:32 2015        (r290614)
+++ head/usr.sbin/ctld/parse.y  Mon Nov  9 18:33:36 2015        (r290615)
@@ -346,6 +346,8 @@ portal_group_entry:
        |
        portal_group_offload
        |
+       portal_group_option
+       |
        portal_group_redirect
        |
        portal_group_tag
@@ -422,6 +424,18 @@ portal_group_offload:      OFFLOAD STR
        }
        ;
 
+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;
@@ -963,12 +977,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);
        }
        ;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to