summaryrefslogtreecommitdiffstats
path: root/usr.sbin
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-02-19 14:31:16 +0000
committermav <mav@FreeBSD.org>2015-02-19 14:31:16 +0000
commitaa6a7df89f1b4850d6005220f912240b8daeece7 (patch)
tree282042eb15012260f41a76a3f6a645a80bd3d224 /usr.sbin
parent31fb601bdcf989b8cbedd19f0fb14b8e56eb253c (diff)
downloadFreeBSD-src-aa6a7df89f1b4850d6005220f912240b8daeece7.zip
FreeBSD-src-aa6a7df89f1b4850d6005220f912240b8daeece7.tar.gz
MFC r278037: CTL LUN mapping rewrite.
Replace iSCSI-specific LUN mapping mechanism with new one, working for any ports. By default all ports are created without LUN mapping, exposing all CTL LUNs as before. But, if needed, LUN mapping can be manually set on per-port basis via ctladm. For its iSCSI ports ctld does it via ioctl(2). The next step will be to teach ctld to work with FibreChannel ports also. Respecting additional flexibility of the new mechanism, ctl.conf now allows alternative syntax for LUN definition. LUNs can now be defined in global context, and then referenced from targets by unique name, as needed. It allows same LUN to be exposed several times via multiple targets. While there, increase limit for LUNs per target in ctld from 256 to 1024. Some initiators do not support LUNs above 255, but that is not our problem. Relnotes: yes Sponsored by: iXsystems, Inc.
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ctladm/ctladm.837
-rw-r--r--usr.sbin/ctladm/ctladm.c78
-rw-r--r--usr.sbin/ctld/ctl.conf.529
-rw-r--r--usr.sbin/ctld/ctld.c410
-rw-r--r--usr.sbin/ctld/ctld.h19
-rw-r--r--usr.sbin/ctld/kernel.c133
-rw-r--r--usr.sbin/ctld/parse.y72
7 files changed, 466 insertions, 312 deletions
diff --git a/usr.sbin/ctladm/ctladm.8 b/usr.sbin/ctladm/ctladm.8
index a22a61c..b0e7154 100644
--- a/usr.sbin/ctladm/ctladm.8
+++ b/usr.sbin/ctladm/ctladm.8
@@ -34,7 +34,7 @@
.\" $Id: //depot/users/kenm/FreeBSD-test2/usr.sbin/ctladm/ctladm.8#3 $
.\" $FreeBSD$
.\"
-.Dd December 17, 2014
+.Dd February 1, 2015
.Dt CTLADM 8
.Os
.Sh NAME
@@ -196,11 +196,17 @@
.Ic portlist
.Op Fl f Ar frontend
.Op Fl i
+.Op Fl l
.Op Fl p Ar targ_port
.Op Fl q
.Op Fl v
.Op Fl x
.Nm
+.Ic lunmap
+.Aq Fl p Ar targ_port
+.Op Fl l Ar pLUN
+.Op Fl L Ar cLUN
+.Nm
.Ic dumpooa
.Nm
.Ic dumpstructs
@@ -782,7 +788,9 @@ List CTL frontend ports.
.It Fl f Ar frontend
Specify the frontend type.
.It Fl i
-Report target and connected initiators addresses
+Report target and connected initiators addresses.
+.It Fl l
+Report LUN mapping.
.It Fl p Ar targ_port
Specify the frontend port number.
.It Fl q
@@ -792,6 +800,31 @@ Enable verbose output (report all port options).
.It Fl x
Output the port list in XML format.
.El
+.It Ic lunmap
+Change LUN mapping for specified port.
+If both
+.Ar pLUN
+and
+.Ar cLUN
+are specified -- LUN will be mapped.
+If
+.Ar pLUN
+is specified, but
+.Ar cLUN
+is not -- LUN will be unmapped.
+If neither
+.Ar pLUN
+nor
+.Ar cLUN
+are specified -- LUN mapping will be disabled, exposing all CTL LUNs.
+.Bl -tag -width 12n
+.It Fl p Ar targ_port
+Specify the frontend port number.
+.It Fl l Ar pLUN
+LUN number visible by specified port.
+.It Fl L Ar cLUN
+CTL LUN number.
+.El
.It Ic dumpooa
Dump the OOA (Order Of Arrival) queue for each LUN registered with CTL.
.It Ic dumpstructs
diff --git a/usr.sbin/ctladm/ctladm.c b/usr.sbin/ctladm/ctladm.c
index 9f72c83..3351e3c 100644
--- a/usr.sbin/ctladm/ctladm.c
+++ b/usr.sbin/ctladm/ctladm.c
@@ -121,7 +121,8 @@ typedef enum {
CTLADM_CMD_MODIFY,
CTLADM_CMD_ISLIST,
CTLADM_CMD_ISLOGOUT,
- CTLADM_CMD_ISTERMINATE
+ CTLADM_CMD_ISTERMINATE,
+ CTLADM_CMD_LUNMAP
} ctladm_cmdfunction;
typedef enum {
@@ -188,10 +189,11 @@ static struct ctladm_opts option_table[] = {
{"islogout", CTLADM_CMD_ISLOGOUT, CTLADM_ARG_NONE, "ac:i:p:"},
{"isterminate", CTLADM_CMD_ISTERMINATE, CTLADM_ARG_NONE, "ac:i:p:"},
{"lunlist", CTLADM_CMD_LUNLIST, CTLADM_ARG_NONE, NULL},
+ {"lunmap", CTLADM_CMD_LUNMAP, CTLADM_ARG_NONE, "p:l:L:"},
{"modesense", CTLADM_CMD_MODESENSE, CTLADM_ARG_NEED_TL, "P:S:dlm:c:"},
{"modify", CTLADM_CMD_MODIFY, CTLADM_ARG_NONE, "b:l:s:"},
{"port", CTLADM_CMD_PORT, CTLADM_ARG_NONE, "lo:p:qt:w:W:x"},
- {"portlist", CTLADM_CMD_PORTLIST, CTLADM_ARG_NONE, "f:ip:qvx"},
+ {"portlist", CTLADM_CMD_PORTLIST, CTLADM_ARG_NONE, "f:ilp:qvx"},
{"prin", CTLADM_CMD_PRES_IN, CTLADM_ARG_NEED_TL, "a:"},
{"prout", CTLADM_CMD_PRES_OUT, CTLADM_ARG_NEED_TL, "a:k:r:s:"},
{"read", CTLADM_CMD_READ, CTLADM_ARG_NEED_TL, rw_opts},
@@ -4106,8 +4108,9 @@ struct cctl_port {
char *frontend_type;
char *name;
int pp, vp;
- char *target, *port;
+ char *target, *port, *lun_map;
STAILQ_HEAD(,cctl_lun_nv) init_list;
+ STAILQ_HEAD(,cctl_lun_nv) lun_list;
STAILQ_HEAD(,cctl_lun_nv) attr_list;
STAILQ_ENTRY(cctl_port) links;
};
@@ -4161,6 +4164,7 @@ cctl_start_pelement(void *user_data, const char *name, const char **attr)
portlist->cur_port = cur_port;
STAILQ_INIT(&cur_port->init_list);
+ STAILQ_INIT(&cur_port->lun_list);
STAILQ_INIT(&cur_port->attr_list);
cur_port->port_id = portlist->cur_id;
STAILQ_INSERT_TAIL(&portlist->port_list, cur_port, links);
@@ -4220,6 +4224,9 @@ cctl_end_pelement(void *user_data, const char *name)
} else if (strcmp(name, "port") == 0) {
cur_port->port = str;
str = NULL;
+ } else if (strcmp(name, "lun_map") == 0) {
+ cur_port->lun_map = str;
+ str = NULL;
} else if (strcmp(name, "targ_port") == 0) {
portlist->cur_port = NULL;
} else if (strcmp(name, "ctlportlist") == 0) {
@@ -4232,7 +4239,8 @@ cctl_end_pelement(void *user_data, const char *name)
err(1, "%s: can't allocate %zd bytes for nv pair",
__func__, sizeof(*nv));
- if (strcmp(name, "initiator") == 0)
+ if (strcmp(name, "initiator") == 0 ||
+ strcmp(name, "lun") == 0)
asprintf(&nv->name, "%ju", portlist->cur_id);
else
nv->name = strdup(name);
@@ -4244,6 +4252,8 @@ cctl_end_pelement(void *user_data, const char *name)
str = NULL;
if (strcmp(name, "initiator") == 0)
STAILQ_INSERT_TAIL(&cur_port->init_list, nv, links);
+ else if (strcmp(name, "lun") == 0)
+ STAILQ_INSERT_TAIL(&cur_port->lun_list, nv, links);
else
STAILQ_INSERT_TAIL(&cur_port->attr_list, nv, links);
}
@@ -4274,7 +4284,7 @@ cctl_portlist(int fd, int argc, char **argv, char *combinedopt)
int retval, c;
char *frontend = NULL;
uint64_t portarg = UINT64_MAX;
- int verbose = 0, init = 0, quiet = 0;
+ int verbose = 0, init = 0, lun = 0, quiet = 0;
retval = 0;
port_len = 4096;
@@ -4290,6 +4300,9 @@ cctl_portlist(int fd, int argc, char **argv, char *combinedopt)
case 'i':
init++;
break;
+ case 'l':
+ lun++;
+ break;
case 'p':
portarg = strtoll(optarg, NULL, 0);
break;
@@ -4381,6 +4394,17 @@ retry:
}
}
+ if (lun || verbose) {
+ if (port->lun_map) {
+ STAILQ_FOREACH(nv, &port->lun_list, links)
+ printf(" LUN %s: %s\n",
+ nv->name, nv->value);
+ if (STAILQ_EMPTY(&port->lun_list))
+ printf(" No LUNs mapped\n");
+ } else
+ printf(" All LUNs mapped\n");
+ }
+
if (verbose) {
STAILQ_FOREACH(nv, &port->attr_list, links) {
printf(" %s=%s\n", nv->name, nv->value);
@@ -4393,6 +4417,41 @@ bailout:
return (retval);
}
+static int
+cctl_lunmap(int fd, int argc, char **argv, char *combinedopt)
+{
+ struct ctl_lun_map lm;
+ int retval = 0, c;
+
+ retval = 0;
+ lm.port = UINT32_MAX;
+ lm.plun = UINT32_MAX;
+ lm.lun = UINT32_MAX;
+
+ while ((c = getopt(argc, argv, combinedopt)) != -1) {
+ switch (c) {
+ case 'p':
+ lm.port = strtoll(optarg, NULL, 0);
+ break;
+ case 'l':
+ lm.plun = strtoll(optarg, NULL, 0);
+ break;
+ case 'L':
+ lm.lun = strtoll(optarg, NULL, 0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (ioctl(fd, CTL_LUN_MAP, &lm) == -1) {
+ warn("%s: error issuing CTL_LUN_MAP ioctl", __func__);
+ retval = 1;
+ }
+
+ return (retval);
+}
+
void
usage(int error)
{
@@ -4430,6 +4489,7 @@ usage(int error)
" ctladm hardstop\n"
" ctladm hardstart\n"
" ctladm lunlist\n"
+" ctladm lunmap -p targ_port [-l pLUN] [-L cLUN]\n"
" ctladm bbrread [dev_id] <-l lba> <-d datalen>\n"
" ctladm delay [dev_id] <-l datamove|done> [-T oneshot|cont]\n"
" [-t secs]\n"
@@ -4529,10 +4589,15 @@ usage(int error)
"portlist options:\n"
"-f fronetnd : specify frontend type\n"
"-i : report target and initiators addresses\n"
+"-l : report LUN mapping\n"
"-p targ_port : specify target port number\n"
"-q : omit header in list output\n"
"-v : verbose output (report all port options)\n"
"-x : output port list in XML format\n"
+"lunmap options:\n"
+"-p targ_port : specify target port number\n"
+"-L pLUN : specify port-visible LUN\n"
+"-L cLUN : specify CTL LUN\n"
"bbrread options:\n"
"-l lba : starting LBA\n"
"-d datalen : length, in bytes, to read\n",
@@ -4760,6 +4825,9 @@ main(int argc, char **argv)
case CTLADM_CMD_PORTLIST:
retval = cctl_portlist(fd, argc, argv, combinedopt);
break;
+ case CTLADM_CMD_LUNMAP:
+ retval = cctl_lunmap(fd, argc, argv, combinedopt);
+ break;
case CTLADM_CMD_READCAPACITY:
retval = cctl_read_capacity(fd, target, lun, initid, retries,
argc, argv, combinedopt);
diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5
index 1074fd4..29a0acb 100644
--- a/usr.sbin/ctld/ctl.conf.5
+++ b/usr.sbin/ctld/ctl.conf.5
@@ -27,7 +27,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 24, 2014
+.Dd February 1, 2015
.Dt CTL.CONF 5
.Os
.Sh NAME
@@ -60,9 +60,14 @@ file is:
.Dl ...
}
+.No lun Ar name No {
+.Dl path Ar path
+}
+
.No target Ar name {
.Dl auth-group Ar name
.Dl portal-group Ar name
+.Dl lun Ar number Ar name
.Dl lun Ar number No {
.Dl path Ar path
.Dl }
@@ -95,6 +100,10 @@ Create a
configuration context,
defining a new portal-group,
which can then be assigned to any number of targets.
+.It Ic lun Ar name
+Create a
+.Sy lun
+configuration context, defining a LUN to be exported by some target(s).
.It Ic target Ar name
Create a
.Sy target
@@ -312,6 +321,10 @@ IPv4 or IPv6 address to redirect initiators to.
When configured, all initiators attempting to connect to this target
will get redirected using "Target moved temporarily" login response.
Redirection happens after successful authentication.
+.It Ic lun Ar number Ar name
+Export previously defined
+.Sy lun
+by the parent target.
.It Ic lun Ar number
Create a
.Sy lun
@@ -386,21 +399,21 @@ target iqn.2012-06.com.example:target0 {
}
}
+lun example_1 {
+ path /dev/zvol/tank/example_1
+}
+
target iqn.2012-06.com.example:target1 {
chap chapuser chapsecret
- lun 0 {
- path /dev/zvol/tank/example_1
- }
+ lun 0 example_1
}
target iqn.2012-06.com.example:target2 {
auth-group ag0
portal-group pg0
- lun 0 {
- path /dev/zvol/tank/example2_0
- }
+ lun 0 example_1
lun 1 {
- path /dev/zvol/tank/example2_1
+ path /dev/zvol/tank/example_2
option foo bar
}
}
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c
index 21e6030..08e2905 100644
--- a/usr.sbin/ctld/ctld.c
+++ b/usr.sbin/ctld/ctld.c
@@ -87,6 +87,7 @@ conf_new(void)
conf = calloc(1, sizeof(*conf));
if (conf == NULL)
log_err(1, "calloc");
+ TAILQ_INIT(&conf->conf_luns);
TAILQ_INIT(&conf->conf_targets);
TAILQ_INIT(&conf->conf_auth_groups);
TAILQ_INIT(&conf->conf_portal_groups);
@@ -104,6 +105,7 @@ conf_new(void)
void
conf_delete(struct conf *conf)
{
+ struct lun *lun, *ltmp;
struct target *targ, *tmp;
struct auth_group *ag, *cagtmp;
struct portal_group *pg, *cpgtmp;
@@ -111,6 +113,8 @@ conf_delete(struct conf *conf)
assert(conf->conf_pidfh == NULL);
+ TAILQ_FOREACH_SAFE(lun, &conf->conf_luns, l_next, ltmp)
+ lun_delete(lun);
TAILQ_FOREACH_SAFE(targ, &conf->conf_targets, t_next, tmp)
target_delete(targ);
TAILQ_FOREACH_SAFE(ag, &conf->conf_auth_groups, ag_next, cagtmp)
@@ -1146,7 +1150,6 @@ target_new(struct conf *conf, const char *name)
for (i = 0; i < len; i++)
targ->t_name[i] = tolower(targ->t_name[i]);
- TAILQ_INIT(&targ->t_luns);
targ->t_conf = conf;
TAILQ_INSERT_TAIL(&conf->conf_targets, targ, t_next);
@@ -1156,12 +1159,9 @@ target_new(struct conf *conf, const char *name)
void
target_delete(struct target *targ)
{
- struct lun *lun, *tmp;
TAILQ_REMOVE(&targ->t_conf->conf_targets, targ, t_next);
- TAILQ_FOREACH_SAFE(lun, &targ->t_luns, l_next, tmp)
- lun_delete(lun);
free(targ->t_name);
free(targ->t_redirection);
free(targ);
@@ -1196,25 +1196,31 @@ target_set_redirection(struct target *target, const char *addr)
return (0);
}
+void
+target_set_ctl_port(struct target *target, uint32_t value)
+{
+
+ target->t_ctl_port = value;
+}
+
struct lun *
-lun_new(struct target *targ, int lun_id)
+lun_new(struct conf *conf, const char *name)
{
struct lun *lun;
- lun = lun_find(targ, lun_id);
+ lun = lun_find(conf, name);
if (lun != NULL) {
- log_warnx("duplicated lun %d for target \"%s\"",
- lun_id, targ->t_name);
+ log_warnx("duplicated lun \"%s\"", name);
return (NULL);
}
lun = calloc(1, sizeof(*lun));
if (lun == NULL)
log_err(1, "calloc");
- lun->l_lun = lun_id;
+ lun->l_conf = conf;
+ lun->l_name = checked_strdup(name);
TAILQ_INIT(&lun->l_options);
- lun->l_target = targ;
- TAILQ_INSERT_TAIL(&targ->t_luns, lun, l_next);
+ TAILQ_INSERT_TAIL(&conf->conf_luns, lun, l_next);
return (lun);
}
@@ -1222,26 +1228,36 @@ lun_new(struct target *targ, int lun_id)
void
lun_delete(struct lun *lun)
{
+ struct target *targ;
struct lun_option *lo, *tmp;
+ int i;
- TAILQ_REMOVE(&lun->l_target->t_luns, lun, l_next);
+ TAILQ_FOREACH(targ, &lun->l_conf->conf_targets, t_next) {
+ for (i = 0; i < MAX_LUNS; i++) {
+ if (targ->t_luns[i] == lun)
+ targ->t_luns[i] = NULL;
+ }
+ }
+ TAILQ_REMOVE(&lun->l_conf->conf_luns, lun, l_next);
TAILQ_FOREACH_SAFE(lo, &lun->l_options, lo_next, tmp)
lun_option_delete(lo);
+ free(lun->l_name);
free(lun->l_backend);
free(lun->l_device_id);
free(lun->l_path);
+ free(lun->l_scsiname);
free(lun->l_serial);
free(lun);
}
struct lun *
-lun_find(const struct target *targ, int lun_id)
+lun_find(const struct conf *conf, const char *name)
{
struct lun *lun;
- TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
- if (lun->l_lun == lun_id)
+ TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
+ if (strcmp(lun->l_name, name) == 0)
return (lun);
}
@@ -1277,6 +1293,13 @@ lun_set_path(struct lun *lun, const char *value)
}
void
+lun_set_scsiname(struct lun *lun, const char *value)
+{
+ free(lun->l_scsiname);
+ lun->l_scsiname = checked_strdup(value);
+}
+
+void
lun_set_serial(struct lun *lun, const char *value)
{
free(lun->l_serial);
@@ -1304,8 +1327,8 @@ lun_option_new(struct lun *lun, const char *name, const char *value)
lo = lun_option_find(lun, name);
if (lo != NULL) {
- log_warnx("duplicated lun option %s for lun %d, target \"%s\"",
- name, lun->l_lun, lun->l_target->t_name);
+ log_warnx("duplicated lun option \"%s\" for lun \"%s\"",
+ name, lun->l_name);
return (NULL);
}
@@ -1410,18 +1433,18 @@ conf_print(struct conf *conf)
fprintf(stderr, "\t listen %s\n", portal->p_listen);
fprintf(stderr, "}\n");
}
+ 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)
+ fprintf(stderr, "\t\toption %s %s\n",
+ lo->lo_name, lo->lo_value);
+ fprintf(stderr, "\t}\n");
+ }
TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
fprintf(stderr, "target %s {\n", targ->t_name);
if (targ->t_alias != NULL)
fprintf(stderr, "\t alias %s\n", targ->t_alias);
- TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
- fprintf(stderr, "\tlun %d {\n", lun->l_lun);
- fprintf(stderr, "\t\tpath %s\n", lun->l_path);
- TAILQ_FOREACH(lo, &lun->l_options, lo_next)
- fprintf(stderr, "\t\toption %s %s\n",
- lo->lo_name, lo->lo_value);
- fprintf(stderr, "\t}\n");
- }
fprintf(stderr, "}\n");
}
}
@@ -1431,60 +1454,49 @@ static int
conf_verify_lun(struct lun *lun)
{
const struct lun *lun2;
- const struct target *targ2;
if (lun->l_backend == NULL)
lun_set_backend(lun, "block");
if (strcmp(lun->l_backend, "block") == 0) {
if (lun->l_path == NULL) {
- log_warnx("missing path for lun %d, target \"%s\"",
- lun->l_lun, lun->l_target->t_name);
+ log_warnx("missing path for lun \"%s\"",
+ lun->l_name);
return (1);
}
} else if (strcmp(lun->l_backend, "ramdisk") == 0) {
if (lun->l_size == 0) {
- log_warnx("missing size for ramdisk-backed lun %d, "
- "target \"%s\"", lun->l_lun, lun->l_target->t_name);
+ log_warnx("missing size for ramdisk-backed lun \"%s\"",
+ lun->l_name);
return (1);
}
if (lun->l_path != NULL) {
log_warnx("path must not be specified "
- "for ramdisk-backed lun %d, target \"%s\"",
- lun->l_lun, lun->l_target->t_name);
+ "for ramdisk-backed lun \"%s\"",
+ lun->l_name);
return (1);
}
}
- if (lun->l_lun < 0 || lun->l_lun > 255) {
- log_warnx("invalid lun number for lun %d, target \"%s\"; "
- "must be between 0 and 255", lun->l_lun,
- lun->l_target->t_name);
- return (1);
- }
if (lun->l_blocksize == 0) {
lun_set_blocksize(lun, DEFAULT_BLOCKSIZE);
} else if (lun->l_blocksize < 0) {
- log_warnx("invalid blocksize for lun %d, target \"%s\"; "
- "must be larger than 0", lun->l_lun, lun->l_target->t_name);
+ log_warnx("invalid blocksize for lun \"%s\"; "
+ "must be larger than 0", lun->l_name);
return (1);
}
if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) {
- log_warnx("invalid size for lun %d, target \"%s\"; "
- "must be multiple of blocksize", lun->l_lun,
- lun->l_target->t_name);
+ log_warnx("invalid size for lun \"%s\"; "
+ "must be multiple of blocksize", lun->l_name);
return (1);
}
- TAILQ_FOREACH(targ2, &lun->l_target->t_conf->conf_targets, t_next) {
- TAILQ_FOREACH(lun2, &targ2->t_luns, l_next) {
- if (lun == lun2)
- continue;
- if (lun->l_path != NULL && lun2->l_path != NULL &&
- strcmp(lun->l_path, lun2->l_path) == 0) {
- log_debugx("WARNING: path \"%s\" duplicated "
- "between lun %d, target \"%s\", and "
- "lun %d, target \"%s\"", lun->l_path,
- lun->l_lun, lun->l_target->t_name,
- lun2->l_lun, lun2->l_target->t_name);
- }
+ TAILQ_FOREACH(lun2, &lun->l_conf->conf_luns, l_next) {
+ if (lun == lun2)
+ continue;
+ if (lun->l_path != NULL && lun2->l_path != NULL &&
+ strcmp(lun->l_path, lun2->l_path) == 0) {
+ log_debugx("WARNING: path \"%s\" duplicated "
+ "between lun \"%s\", and "
+ "lun \"%s\"", lun->l_path,
+ lun->l_name, lun2->l_name);
}
}
@@ -1499,11 +1511,16 @@ conf_verify(struct conf *conf)
struct target *targ;
struct lun *lun;
bool found;
- int error;
+ int error, i;
if (conf->conf_pidfile_path == NULL)
conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE);
+ TAILQ_FOREACH(lun, &conf->conf_luns, l_next) {
+ error = conf_verify_lun(lun);
+ if (error != 0)
+ return (error);
+ }
TAILQ_FOREACH(targ, &conf->conf_targets, t_next) {
if (targ->t_auth_group == NULL) {
targ->t_auth_group = auth_group_find(conf,
@@ -1516,11 +1533,9 @@ conf_verify(struct conf *conf)
assert(targ->t_portal_group != NULL);
}
found = false;
- TAILQ_FOREACH(lun, &targ->t_luns, l_next) {
- error = conf_verify_lun(lun);
- if (error != 0)
- return (error);
- found = true;
+ for (i = 0; i < MAX_LUNS; i++) {
+ if (targ->t_luns[i] != NULL)
+ found = true;
}
if (!found && targ->t_redirection == NULL) {
log_warnx("no LUNs defined for target \"%s\"",
@@ -1657,126 +1672,128 @@ conf_apply(struct conf *oldconf, struct conf *newconf)
* be somewhat hairy, though, and lun deletion failures don't
* really happen, so leave it as it is for now.
*/
+ /*
+ * First, remove any targets present in the old configuration
+ * and missing in the new one.
+ */
TAILQ_FOREACH_SAFE(oldtarg, &oldconf->conf_targets, t_next, tmptarg) {
- /*
- * First, remove any targets present in the old configuration
- * and missing in the new one.
- */
newtarg = target_find(newconf, oldtarg->t_name);
- if (newtarg == NULL) {
- error = kernel_port_remove(oldtarg);
+ if (newtarg != NULL)
+ continue;
+ error = kernel_port_remove(oldtarg);
+ if (error != 0) {
+ log_warnx("failed to remove target %s",
+ oldtarg->t_name);
+ /*
+ * XXX: Uncomment after fixing the root cause.
+ *
+ * cumulated_error++;
+ */
+ }
+ }
+
+ /*
+ * Second, remove any LUNs present in the old configuration
+ * and missing in the new one.
+ */
+ TAILQ_FOREACH_SAFE(oldlun, &oldconf->conf_luns, l_next, tmplun) {
+ newlun = lun_find(newconf, oldlun->l_name);
+ if (newlun == NULL) {
+ log_debugx("lun \"%s\", CTL lun %d "
+ "not found in new configuration; "
+ "removing", oldlun->l_name, oldlun->l_ctl_lun);
+ error = kernel_lun_remove(oldlun);
if (error != 0) {
- log_warnx("failed to remove target %s",
- oldtarg->t_name);
- /*
- * XXX: Uncomment after fixing the root cause.
- *
- * cumulated_error++;
- */
- }
- TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next,
- tmplun) {
- log_debugx("target %s not found in new "
- "configuration; removing its lun %d, "
- "backed by CTL lun %d",
- oldtarg->t_name, oldlun->l_lun,
- oldlun->l_ctl_lun);
- error = kernel_lun_remove(oldlun);
- if (error != 0) {
- log_warnx("failed to remove lun %d, "
- "target %s, CTL lun %d",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- cumulated_error++;
- }
+ log_warnx("failed to remove lun \"%s\", "
+ "CTL lun %d",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ cumulated_error++;
}
continue;
}
/*
- * Second, remove any LUNs present in the old target
- * and missing in the new one.
+ * Also remove the LUNs changed by more than size.
*/
- TAILQ_FOREACH_SAFE(oldlun, &oldtarg->t_luns, l_next, tmplun) {
- newlun = lun_find(newtarg, oldlun->l_lun);
- if (newlun == NULL) {
- log_debugx("lun %d, target %s, CTL lun %d "
- "not found in new configuration; "
- "removing", oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- error = kernel_lun_remove(oldlun);
- if (error != 0) {
- log_warnx("failed to remove lun %d, "
- "target %s, CTL lun %d",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- cumulated_error++;
- }
- continue;
+ changed = 0;
+ assert(oldlun->l_backend != NULL);
+ assert(newlun->l_backend != NULL);
+ if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
+ log_debugx("backend for lun \"%s\", "
+ "CTL lun %d changed; removing",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ changed = 1;
+ }
+ if (oldlun->l_blocksize != newlun->l_blocksize) {
+ log_debugx("blocksize for lun \"%s\", "
+ "CTL lun %d changed; removing",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ changed = 1;
+ }
+ if (newlun->l_device_id != NULL &&
+ (oldlun->l_device_id == NULL ||
+ strcmp(oldlun->l_device_id, newlun->l_device_id) !=
+ 0)) {
+ log_debugx("device-id for lun \"%s\", "
+ "CTL lun %d changed; removing",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ changed = 1;
+ }
+ if (newlun->l_path != NULL &&
+ (oldlun->l_path == NULL ||
+ strcmp(oldlun->l_path, newlun->l_path) != 0)) {
+ log_debugx("path for lun \"%s\", "
+ "CTL lun %d, changed; removing",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ changed = 1;
+ }
+ if (newlun->l_serial != NULL &&
+ (oldlun->l_serial == NULL ||
+ strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
+ log_debugx("serial for lun \"%s\", "
+ "CTL lun %d changed; removing",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ changed = 1;
+ }
+ if (changed) {
+ error = kernel_lun_remove(oldlun);
+ if (error != 0) {
+ log_warnx("failed to remove lun \"%s\", "
+ "CTL lun %d",
+ oldlun->l_name, oldlun->l_ctl_lun);
+ cumulated_error++;
}
+ lun_delete(oldlun);
+ continue;
+ }
- /*
- * Also remove the LUNs changed by more than size.
- */
- changed = 0;
- assert(oldlun->l_backend != NULL);
- assert(newlun->l_backend != NULL);
- if (strcmp(newlun->l_backend, oldlun->l_backend) != 0) {
- log_debugx("backend for lun %d, target %s, "
- "CTL lun %d changed; removing",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- changed = 1;
- }
- if (oldlun->l_blocksize != newlun->l_blocksize) {
- log_debugx("blocksize for lun %d, target %s, "
- "CTL lun %d changed; removing",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- changed = 1;
- }
- if (newlun->l_device_id != NULL &&
- (oldlun->l_device_id == NULL ||
- strcmp(oldlun->l_device_id, newlun->l_device_id) !=
- 0)) {
- log_debugx("device-id for lun %d, target %s, "
- "CTL lun %d changed; removing",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- changed = 1;
- }
- if (newlun->l_path != NULL &&
- (oldlun->l_path == NULL ||
- strcmp(oldlun->l_path, newlun->l_path) != 0)) {
- log_debugx("path for lun %d, target %s, "
- "CTL lun %d, changed; removing",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- changed = 1;
- }
- if (newlun->l_serial != NULL &&
- (oldlun->l_serial == NULL ||
- strcmp(oldlun->l_serial, newlun->l_serial) != 0)) {
- log_debugx("serial for lun %d, target %s, "
- "CTL lun %d changed; removing",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
- changed = 1;
- }
- if (changed) {
- error = kernel_lun_remove(oldlun);
+ lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
+ }
+
+ TAILQ_FOREACH_SAFE(newlun, &newconf->conf_luns, l_next, tmplun) {
+ oldlun = lun_find(oldconf, newlun->l_name);
+ if (oldlun != NULL) {
+ if (newlun->l_size != oldlun->l_size ||
+ newlun->l_size == 0) {
+ log_debugx("resizing lun \"%s\", CTL lun %d",
+ newlun->l_name, newlun->l_ctl_lun);
+ error = kernel_lun_resize(newlun);
if (error != 0) {
- log_warnx("failed to remove lun %d, "
- "target %s, CTL lun %d",
- oldlun->l_lun, oldtarg->t_name,
- oldlun->l_ctl_lun);
+ log_warnx("failed to "
+ "resize lun \"%s\", CTL lun %d",
+ newlun->l_name,
+ newlun->l_ctl_lun);
cumulated_error++;
}
- lun_delete(oldlun);
- continue;
}
-
- lun_set_ctl_lun(newlun, oldlun->l_ctl_lun);
+ continue;
+ }
+ log_debugx("adding lun \"%s\"", newlun->l_name);
+ error = kernel_lun_add(newlun);
+ if (error != 0) {
+ log_warnx("failed to add lun \"%s\"", newlun->l_name);
+ lun_delete(newlun);
+ cumulated_error++;
}
}
@@ -1786,54 +1803,21 @@ conf_apply(struct conf *oldconf, struct conf *newconf)
TAILQ_FOREACH(newtarg, &newconf->conf_targets, t_next) {
oldtarg = target_find(oldconf, newtarg->t_name);
- TAILQ_FOREACH_SAFE(newlun, &newtarg->t_luns, l_next, tmplun) {
- if (oldtarg != NULL) {
- oldlun = lun_find(oldtarg, newlun->l_lun);
- if (oldlun != NULL) {
- if (newlun->l_size != oldlun->l_size ||
- newlun->l_size == 0) {
- log_debugx("resizing lun %d, "
- "target %s, CTL lun %d",
- newlun->l_lun,
- newtarg->t_name,
- newlun->l_ctl_lun);
- error =
- kernel_lun_resize(newlun);
- if (error != 0) {
- log_warnx("failed to "
- "resize lun %d, "
- "target %s, "
- "CTL lun %d",
- newlun->l_lun,
- newtarg->t_name,
- newlun->l_lun);
- cumulated_error++;
- }
- }
- continue;
- }
- }
- log_debugx("adding lun %d, target %s",
- newlun->l_lun, newtarg->t_name);
- error = kernel_lun_add(newlun);
- if (error != 0) {
- log_warnx("failed to add lun %d, target %s",
- newlun->l_lun, newtarg->t_name);
- lun_delete(newlun);
- cumulated_error++;
- }
- }
- if (oldtarg == NULL) {
+ if (oldtarg == NULL)
error = kernel_port_add(newtarg);
- if (error != 0) {
- log_warnx("failed to add target %s",
- newtarg->t_name);
- /*
- * XXX: Uncomment after fixing the root cause.
- *
- * cumulated_error++;
- */
- }
+ else {
+ target_set_ctl_port(newtarg, oldtarg->t_ctl_port);
+ error = kernel_port_update(newtarg);
+ }
+ if (error != 0) {
+ log_warnx("failed to %s target %s",
+ (oldtarg == NULL) ? "add" : "update",
+ newtarg->t_name);
+ /*
+ * XXX: Uncomment after fixing the root cause.
+ *
+ * cumulated_error++;
+ */
}
}
diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h
index 34c0891..e082a41 100644
--- a/usr.sbin/ctld/ctld.h
+++ b/usr.sbin/ctld/ctld.h
@@ -45,6 +45,7 @@
#define DEFAULT_PIDFILE "/var/run/ctld.pid"
#define DEFAULT_BLOCKSIZE 512
+#define MAX_LUNS 1024
#define MAX_NAME_LEN 223
#define MAX_DATA_SEGMENT_LENGTH (128 * 1024)
#define MAX_BURST_LENGTH 16776192
@@ -132,13 +133,14 @@ struct lun_option {
struct lun {
TAILQ_ENTRY(lun) l_next;
+ struct conf *l_conf;
TAILQ_HEAD(, lun_option) l_options;
- struct target *l_target;
- int l_lun;
+ char *l_name;
char *l_backend;
int l_blocksize;
char *l_device_id;
char *l_path;
+ char *l_scsiname;
char *l_serial;
int64_t l_size;
@@ -147,13 +149,15 @@ struct lun {
struct target {
TAILQ_ENTRY(target) t_next;
- TAILQ_HEAD(, lun) t_luns;
struct conf *t_conf;
+ struct lun *t_luns[MAX_LUNS];
struct auth_group *t_auth_group;
struct portal_group *t_portal_group;
char *t_name;
char *t_alias;
char *t_redirection;
+
+ uint32_t t_ctl_port;
};
struct isns {
@@ -165,6 +169,7 @@ struct isns {
struct conf {
char *conf_pidfile_path;
+ TAILQ_HEAD(, lun) conf_luns;
TAILQ_HEAD(, target) conf_targets;
TAILQ_HEAD(, auth_group) conf_auth_groups;
TAILQ_HEAD(, portal_group) conf_portal_groups;
@@ -319,14 +324,17 @@ struct target *target_find(struct conf *conf,
const char *name);
int target_set_redirection(struct target *target,
const char *addr);
+void target_set_ctl_port(struct target *target,
+ uint32_t value);
-struct lun *lun_new(struct target *target, int lun_id);
+struct lun *lun_new(struct conf *conf, const char *name);
void lun_delete(struct lun *lun);
-struct lun *lun_find(const struct target *target, int lun_id);
+struct lun *lun_find(const struct conf *conf, const char *name);
void lun_set_backend(struct lun *lun, const char *value);
void lun_set_blocksize(struct lun *lun, size_t value);
void lun_set_device_id(struct lun *lun, const char *value);
void lun_set_path(struct lun *lun, const char *value);
+void lun_set_scsiname(struct lun *lun, const char *value);
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);
@@ -345,6 +353,7 @@ int kernel_lun_resize(struct lun *lun);
int kernel_lun_remove(struct lun *lun);
void kernel_handoff(struct connection *conn);
int kernel_port_add(struct target *targ);
+int kernel_port_update(struct target *targ);
int kernel_port_remove(struct target *targ);
void kernel_capsicate(void);
diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c
index c375990..890bb2b 100644
--- a/usr.sbin/ctld/kernel.c
+++ b/usr.sbin/ctld/kernel.c
@@ -114,8 +114,7 @@ struct cctl_lun {
uint32_t blocksize;
char *serial_number;
char *device_id;
- char *cfiscsi_target;
- int cfiscsi_lun;
+ char *ctld_name;
STAILQ_HEAD(,cctl_lun_nv) attr_list;
STAILQ_ENTRY(cctl_lun) links;
};
@@ -229,11 +228,9 @@ cctl_end_element(void *user_data, const char *name)
} else if (strcmp(name, "device_id") == 0) {
cur_lun->device_id = str;
str = NULL;
- } else if (strcmp(name, "cfiscsi_target") == 0) {
- cur_lun->cfiscsi_target = str;
+ } else if (strcmp(name, "ctld_name") == 0) {
+ cur_lun->ctld_name = str;
str = NULL;
- } else if (strcmp(name, "cfiscsi_lun") == 0) {
- cur_lun->cfiscsi_lun = strtoul(str, NULL, 0);
} else if (strcmp(name, "lun") == 0) {
devlist->cur_lun = NULL;
} else if (strcmp(name, "ctllunlist") == 0) {
@@ -522,38 +519,25 @@ retry_port:
STAILQ_FOREACH(lun, &devlist.lun_list, links) {
struct cctl_lun_nv *nv;
- if (lun->cfiscsi_target == NULL) {
+ if (lun->ctld_name == NULL) {
log_debugx("CTL lun %ju wasn't managed by ctld; "
"ignoring", (uintmax_t)lun->lun_id);
continue;
}
- targ = target_find(conf, lun->cfiscsi_target);
- if (targ == NULL) {
-#if 0
- log_debugx("found new kernel target %s for CTL lun %ld",
- lun->cfiscsi_target, lun->lun_id);
-#endif
- targ = target_new(conf, lun->cfiscsi_target);
- if (targ == NULL) {
- log_warnx("target_new failed");
- continue;
- }
- }
-
- cl = lun_find(targ, lun->cfiscsi_lun);
+ cl = lun_find(conf, lun->ctld_name);
if (cl != NULL) {
- log_warnx("found CTL lun %ju, backing lun %d, target "
- "%s, also backed by CTL lun %d; ignoring",
- (uintmax_t) lun->lun_id, cl->l_lun,
- cl->l_target->t_name, cl->l_ctl_lun);
+ log_warnx("found CTL lun %ju \"%s\", "
+ "also backed by CTL lun %d; ignoring",
+ (uintmax_t)lun->lun_id, lun->ctld_name,
+ cl->l_ctl_lun);
continue;
}
- log_debugx("found CTL lun %ju, backing lun %d, target %s",
- (uintmax_t)lun->lun_id, lun->cfiscsi_lun, lun->cfiscsi_target);
+ log_debugx("found CTL lun %ju \"%s\"",
+ (uintmax_t)lun->lun_id, lun->ctld_name);
- cl = lun_new(targ, lun->cfiscsi_lun);
+ cl = lun_new(conf, lun->ctld_name);
if (cl == NULL) {
log_warnx("lun_new failed");
continue;
@@ -574,9 +558,9 @@ retry_port:
lo = lun_option_new(cl, nv->name, nv->value);
if (lo == NULL)
log_warnx("unable to add CTL lun option %s "
- "for CTL lun %ju for lun %d, target %s",
+ "for CTL lun %ju \"%s\"",
nv->name, (uintmax_t) lun->lun_id,
- cl->l_lun, cl->l_target->t_name);
+ cl->l_name);
}
}
@@ -599,7 +583,6 @@ kernel_lun_add(struct lun *lun)
{
struct lun_option *lo;
struct ctl_lun_req req;
- char *tmp;
int error, i, num_options;
bzero(&req, sizeof(req));
@@ -637,38 +620,17 @@ kernel_lun_add(struct lun *lun)
}
}
- lo = lun_option_find(lun, "cfiscsi_target");
- if (lo != NULL) {
- lun_option_set(lo, lun->l_target->t_name);
- } else {
- lo = lun_option_new(lun, "cfiscsi_target",
- lun->l_target->t_name);
- assert(lo != NULL);
- }
-
- asprintf(&tmp, "%d", lun->l_lun);
- if (tmp == NULL)
- log_errx(1, "asprintf");
- lo = lun_option_find(lun, "cfiscsi_lun");
+ lo = lun_option_find(lun, "ctld_name");
if (lo != NULL) {
- lun_option_set(lo, tmp);
- free(tmp);
+ lun_option_set(lo, lun->l_name);
} else {
- lo = lun_option_new(lun, "cfiscsi_lun", tmp);
- free(tmp);
+ lo = lun_option_new(lun, "ctld_name", lun->l_name);
assert(lo != NULL);
}
- asprintf(&tmp, "%s,lun,%d", lun->l_target->t_name, lun->l_lun);
- if (tmp == NULL)
- log_errx(1, "asprintf");
lo = lun_option_find(lun, "scsiname");
- if (lo != NULL) {
- lun_option_set(lo, tmp);
- free(tmp);
- } else {
- lo = lun_option_new(lun, "scsiname", tmp);
- free(tmp);
+ if (lo == NULL && lun->l_scsiname != NULL) {
+ lo = lun_option_new(lun, "scsiname", lun->l_scsiname);
assert(lo != NULL);
}
@@ -846,10 +808,11 @@ kernel_port_add(struct target *targ)
{
struct ctl_port_entry entry;
struct ctl_req req;
+ struct ctl_lun_map lm;
char tagstr[16];
- int error;
- uint32_t port_id = -1;
+ int error, i;
+ /* Create iSCSI port. */
bzero(&req, sizeof(req));
strlcpy(req.driver, "iscsi", sizeof(req.driver));
req.reqtype = CTL_REQ_CREATE;
@@ -857,8 +820,8 @@ kernel_port_add(struct target *targ)
req.args = malloc(req.num_args * sizeof(*req.args));
req.args[0].namelen = sizeof("port_id");
req.args[0].name = __DECONST(char *, "port_id");
- req.args[0].vallen = sizeof(port_id);
- req.args[0].value = &port_id;
+ req.args[0].vallen = sizeof(targ->t_ctl_port);
+ req.args[0].value = &targ->t_ctl_port;
req.args[0].flags = CTL_BEARG_WR;
str_arg(&req.args[1], "cfiscsi_target", targ->t_name);
snprintf(tagstr, sizeof(tagstr), "%d", targ->t_portal_group->pg_tag);
@@ -867,29 +830,46 @@ kernel_port_add(struct target *targ)
str_arg(&req.args[3], "cfiscsi_target_alias", targ->t_alias);
else
req.num_args--;
-
error = ioctl(ctl_fd, CTL_PORT_REQ, &req);
free(req.args);
if (error != 0) {
log_warn("error issuing CTL_PORT_REQ ioctl");
return (1);
}
-
if (req.status == CTL_LUN_ERROR) {
log_warnx("error returned from port creation request: %s",
req.error_str);
return (1);
}
-
if (req.status != CTL_LUN_OK) {
log_warnx("unknown port creation request status %d",
req.status);
return (1);
}
- bzero(&entry, sizeof(entry));
- entry.targ_port = port_id;
+ /* Explicitly enable mapping to block any access except allowed. */
+ lm.port = targ->t_ctl_port;
+ lm.plun = UINT32_MAX;
+ lm.lun = 0;
+ error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
+ if (error != 0)
+ log_warn("CTL_LUN_MAP ioctl failed");
+
+ /* Map configured LUNs */
+ for (i = 0; i < MAX_LUNS; i++) {
+ if (targ->t_luns[i] == NULL)
+ continue;
+ lm.port = targ->t_ctl_port;
+ lm.plun = i;
+ lm.lun = targ->t_luns[i]->l_ctl_lun;
+ error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
+ if (error != 0)
+ log_warn("CTL_LUN_MAP ioctl failed");
+ }
+ /* Enable port */
+ bzero(&entry, sizeof(entry));
+ entry.targ_port = targ->t_ctl_port;
error = ioctl(ctl_fd, CTL_ENABLE_PORT, &entry);
if (error != 0) {
log_warn("CTL_ENABLE_PORT ioctl failed");
@@ -900,6 +880,27 @@ kernel_port_add(struct target *targ)
}
int
+kernel_port_update(struct target *targ)
+{
+ struct ctl_lun_map lm;
+ int error, i;
+
+ /* Map configured LUNs and unmap others */
+ for (i = 0; i < MAX_LUNS; i++) {
+ lm.port = targ->t_ctl_port;
+ lm.plun = i;
+ if (targ->t_luns[i] == NULL)
+ lm.lun = UINT32_MAX;
+ else
+ lm.lun = targ->t_luns[i]->l_ctl_lun;
+ error = ioctl(ctl_fd, CTL_LUN_MAP, &lm);
+ if (error != 0)
+ log_warn("CTL_LUN_MAP ioctl failed");
+ }
+ return (0);
+}
+
+int
kernel_port_remove(struct target *targ)
{
struct ctl_req req;
diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y
index a6519dd..fead2ea 100644
--- a/usr.sbin/ctld/parse.y
+++ b/usr.sbin/ctld/parse.y
@@ -99,6 +99,8 @@ statement:
|
portal_group
|
+ lun
+ |
target
;
@@ -407,6 +409,22 @@ portal_group_redirect: REDIRECT STR
}
;
+lun: LUN lun_name
+ OPENING_BRACKET lun_entries CLOSING_BRACKET
+ {
+ lun = NULL;
+ }
+ ;
+
+lun_name: STR
+ {
+ lun = lun_new(conf, $1);
+ free($1);
+ if (lun == NULL)
+ return (1);
+ }
+ ;
+
target: TARGET target_name
OPENING_BRACKET target_entries CLOSING_BRACKET
{
@@ -450,6 +468,8 @@ target_entry:
target_redirect
|
target_lun
+ |
+ target_lun_ref
;
target_alias: ALIAS STR
@@ -672,6 +692,7 @@ target_lun: LUN lun_number
lun_number: STR
{
uint64_t tmp;
+ char *name;
if (expand_number($1, &tmp) != 0) {
yyerror("invalid numeric value");
@@ -679,9 +700,34 @@ lun_number: STR
return (1);
}
- lun = lun_new(target, tmp);
+ asprintf(&name, "%s,lun,%ju", target->t_name, tmp);
+ lun = lun_new(conf, name);
if (lun == NULL)
return (1);
+
+ lun_set_scsiname(lun, name);
+ target->t_luns[tmp] = lun;
+ }
+ ;
+
+target_lun_ref: LUN STR STR
+ {
+ uint64_t tmp;
+
+ if (expand_number($2, &tmp) != 0) {
+ yyerror("invalid numeric value");
+ free($2);
+ free($3);
+ return (1);
+ }
+ free($2);
+
+ lun = lun_find(conf, $3);
+ free($3);
+ if (lun == NULL)
+ return (1);
+
+ target->t_luns[tmp] = lun;
}
;
@@ -711,9 +757,9 @@ lun_entry:
lun_backend: BACKEND STR
{
if (lun->l_backend != NULL) {
- log_warnx("backend for lun %d, target \"%s\" "
+ log_warnx("backend for lun \"%s\" "
"specified more than once",
- lun->l_lun, target->t_name);
+ lun->l_name);
free($2);
return (1);
}
@@ -733,9 +779,9 @@ lun_blocksize: BLOCKSIZE STR
}
if (lun->l_blocksize != 0) {
- log_warnx("blocksize for lun %d, target \"%s\" "
+ log_warnx("blocksize for lun \"%s\" "
"specified more than once",
- lun->l_lun, target->t_name);
+ lun->l_name);
return (1);
}
lun_set_blocksize(lun, tmp);
@@ -745,9 +791,9 @@ lun_blocksize: BLOCKSIZE STR
lun_device_id: DEVICE_ID STR
{
if (lun->l_device_id != NULL) {
- log_warnx("device_id for lun %d, target \"%s\" "
+ log_warnx("device_id for lun \"%s\" "
"specified more than once",
- lun->l_lun, target->t_name);
+ lun->l_name);
free($2);
return (1);
}
@@ -771,9 +817,9 @@ lun_option: OPTION STR STR
lun_path: PATH STR
{
if (lun->l_path != NULL) {
- log_warnx("path for lun %d, target \"%s\" "
+ log_warnx("path for lun \"%s\" "
"specified more than once",
- lun->l_lun, target->t_name);
+ lun->l_name);
free($2);
return (1);
}
@@ -785,9 +831,9 @@ lun_path: PATH STR
lun_serial: SERIAL STR
{
if (lun->l_serial != NULL) {
- log_warnx("serial for lun %d, target \"%s\" "
+ log_warnx("serial for lun \"%s\" "
"specified more than once",
- lun->l_lun, target->t_name);
+ lun->l_name);
free($2);
return (1);
}
@@ -807,9 +853,9 @@ lun_size: SIZE STR
}
if (lun->l_size != 0) {
- log_warnx("size for lun %d, target \"%s\" "
+ log_warnx("size for lun \"%s\" "
"specified more than once",
- lun->l_lun, target->t_name);
+ lun->l_name);
return (1);
}
lun_set_size(lun, tmp);
OpenPOWER on IntegriCloud