summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--usr.sbin/ctld/ctl.conf.56
-rw-r--r--usr.sbin/ctld/ctld.c71
-rw-r--r--usr.sbin/ctld/ctld.h24
-rw-r--r--usr.sbin/ctld/kernel.c55
-rw-r--r--usr.sbin/ctld/parse.y20
5 files changed, 99 insertions, 77 deletions
diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5
index 2fcc908..3ddd370 100644
--- a/usr.sbin/ctld/ctl.conf.5
+++ b/usr.sbin/ctld/ctl.conf.5
@@ -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 listen on for incoming connections.
.\".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
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c
index 90c7db8..55a2603 100644
--- a/usr.sbin/ctld/ctld.c
+++ b/usr.sbin/ctld/ctld.c
@@ -615,6 +615,7 @@ portal_group_new(struct conf *conf, const char *name)
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 *pg)
{
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 *pg)
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_t value)
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) {
diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h
index ef85e43..7c7c3ba 100644
--- a/usr.sbin/ctld/ctld.h
+++ b/usr.sbin/ctld/ctld.h
@@ -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, const char *value);
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);
diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c
index dea1917..ef0534f 100644
--- a/usr.sbin/ctld/kernel.c
+++ b/usr.sbin/ctld/kernel.c
@@ -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 char *name, const char *value)
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);
diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y
index 1e40dd8..1de1e88 100644
--- a/usr.sbin/ctld/parse.y
+++ b/usr.sbin/ctld/parse.y
@@ -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 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;
@@ -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);
}
;
OpenPOWER on IntegriCloud