summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ctld
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-09-27 13:47:28 +0000
committermav <mav@FreeBSD.org>2015-09-27 13:47:28 +0000
commitba6084f68972fe48de4abe069143177cfdf30dce (patch)
tree2a3d3e1da2b5b7f04f0cccf015c73fb8785f1fc7 /usr.sbin/ctld
parent9ee306217426e87108150ba032bf29b14893e7a0 (diff)
downloadFreeBSD-src-ba6084f68972fe48de4abe069143177cfdf30dce.zip
FreeBSD-src-ba6084f68972fe48de4abe069143177cfdf30dce.tar.gz
Add to CTL initial support for CDROMs and removable devices.
Relnotes: yes
Diffstat (limited to 'usr.sbin/ctld')
-rw-r--r--usr.sbin/ctld/ctl.conf.56
-rw-r--r--usr.sbin/ctld/ctld.c7
-rw-r--r--usr.sbin/ctld/ctld.h2
-rw-r--r--usr.sbin/ctld/kernel.c6
-rw-r--r--usr.sbin/ctld/parse.y31
-rw-r--r--usr.sbin/ctld/token.l1
6 files changed, 49 insertions, 4 deletions
diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5
index ea1d07a..24c4c85 100644
--- a/usr.sbin/ctld/ctl.conf.5
+++ b/usr.sbin/ctld/ctl.conf.5
@@ -28,7 +28,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd September 15, 2015
+.Dd September 27, 2015
.Dt CTL.CONF 5
.Os
.Sh NAME
@@ -394,6 +394,10 @@ By default CTL allocates those IDs dynamically, but explicit specification
may be needed for consistency in HA configurations.
.It Ic device-id Ar string
The SCSI Device Identification string presented to the initiator.
+.It Ic device-type Ar type
+Specify the SCSI device type to use when creating the LUN.
+Currently CTL supports Direct Access (type 0), Processor (type 3)
+and CD/DVD (type 5) LUNs.
.It Ic option Ar name Ar value
The CTL-specific options passed to the kernel.
All CTL-specific options are documented in the
diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c
index b43ffce..12474ea 100644
--- a/usr.sbin/ctld/ctld.c
+++ b/usr.sbin/ctld/ctld.c
@@ -1456,6 +1456,13 @@ lun_set_blocksize(struct lun *lun, size_t value)
}
void
+lun_set_device_type(struct lun *lun, uint8_t value)
+{
+
+ lun->l_device_type = value;
+}
+
+void
lun_set_device_id(struct lun *lun, const char *value)
{
free(lun->l_device_id);
diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h
index 782db15..6eb878c 100644
--- a/usr.sbin/ctld/ctld.h
+++ b/usr.sbin/ctld/ctld.h
@@ -164,6 +164,7 @@ struct lun {
TAILQ_HEAD(, lun_option) l_options;
char *l_name;
char *l_backend;
+ uint8_t l_device_type;
int l_blocksize;
char *l_device_id;
char *l_path;
@@ -375,6 +376,7 @@ struct lun *lun_new(struct conf *conf, const char *name);
void lun_delete(struct lun *lun);
struct lun *lun_find(const struct conf *conf, const char *name);
void lun_set_backend(struct lun *lun, const char *value);
+void lun_set_device_type(struct lun *lun, uint8_t 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);
diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c
index 3f21590..b9658b5 100644
--- a/usr.sbin/ctld/kernel.c
+++ b/usr.sbin/ctld/kernel.c
@@ -108,6 +108,7 @@ struct cctl_lun_nv {
struct cctl_lun {
uint64_t lun_id;
char *backend_type;
+ uint8_t device_type;
uint64_t size_blocks;
uint32_t blocksize;
char *serial_number;
@@ -221,6 +222,8 @@ cctl_end_element(void *user_data, const char *name)
if (strcmp(name, "backend_type") == 0) {
cur_lun->backend_type = str;
str = NULL;
+ } else if (strcmp(name, "lun_type") == 0) {
+ cur_lun->device_type = strtoull(str, NULL, 0);
} else if (strcmp(name, "size") == 0) {
cur_lun->size_blocks = strtoull(str, NULL, 0);
} else if (strcmp(name, "blocksize") == 0) {
@@ -610,6 +613,7 @@ retry_port:
continue;
}
lun_set_backend(cl, lun->backend_type);
+ lun_set_device_type(cl, lun->device_type);
lun_set_blocksize(cl, lun->blocksize);
lun_set_device_id(cl, lun->device_id);
lun_set_serial(cl, lun->serial_number);
@@ -668,7 +672,7 @@ kernel_lun_add(struct lun *lun)
}
req.reqdata.create.flags |= CTL_LUN_FLAG_DEV_TYPE;
- req.reqdata.create.device_type = T_DIRECT;
+ req.reqdata.create.device_type = lun->l_device_type;
if (lun->l_serial != NULL) {
strncpy(req.reqdata.create.serial_num, lun->l_serial,
diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y
index 6907b48..03a511f 100644
--- a/usr.sbin/ctld/parse.y
+++ b/usr.sbin/ctld/parse.y
@@ -57,8 +57,8 @@ extern void yyrestart(FILE *);
%}
%token ALIAS AUTH_GROUP AUTH_TYPE BACKEND BLOCKSIZE CHAP CHAP_MUTUAL
-%token CLOSING_BRACKET CTL_LUN DEBUG DEVICE_ID DISCOVERY_AUTH_GROUP
-%token DISCOVERY_FILTER FOREIGN
+%token CLOSING_BRACKET CTL_LUN DEBUG DEVICE_ID DEVICE_TYPE
+%token DISCOVERY_AUTH_GROUP DISCOVERY_FILTER 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
@@ -855,6 +855,8 @@ lun_entry:
|
lun_device_id
|
+ lun_device_type
+ |
lun_ctl_lun
|
lun_option
@@ -914,6 +916,31 @@ lun_device_id: DEVICE_ID STR
}
;
+lun_device_type: DEVICE_TYPE STR
+ {
+ uint64_t tmp;
+
+ if (strcasecmp($2, "disk") == 0 ||
+ strcasecmp($2, "direct") == 0)
+ tmp = 0;
+ else if (strcasecmp($2, "processor") == 0)
+ tmp = 3;
+ else if (strcasecmp($2, "cd") == 0 ||
+ strcasecmp($2, "cdrom") == 0 ||
+ strcasecmp($2, "dvd") == 0 ||
+ strcasecmp($2, "dvdrom") == 0)
+ tmp = 5;
+ else if (expand_number($2, &tmp) != 0 ||
+ tmp > 15) {
+ yyerror("invalid numeric value");
+ free($2);
+ return (1);
+ }
+
+ lun_set_device_type(lun, tmp);
+ }
+ ;
+
lun_ctl_lun: CTL_LUN STR
{
uint64_t tmp;
diff --git a/usr.sbin/ctld/token.l b/usr.sbin/ctld/token.l
index 37989ce..e8cbf3b 100644
--- a/usr.sbin/ctld/token.l
+++ b/usr.sbin/ctld/token.l
@@ -57,6 +57,7 @@ chap-mutual { return CHAP_MUTUAL; }
ctl-lun { return CTL_LUN; }
debug { return DEBUG; }
device-id { return DEVICE_ID; }
+device-type { return DEVICE_TYPE; }
discovery-auth-group { return DISCOVERY_AUTH_GROUP; }
discovery-filter { return DISCOVERY_FILTER; }
foreign { return FOREIGN; }
OpenPOWER on IntegriCloud