From e0750f86962a1183d0fb87d8bb7c6a75e43f66dd Mon Sep 17 00:00:00 2001 From: mav Date: Mon, 5 Oct 2015 09:22:31 +0000 Subject: [PATCH] MFC r287823: Add ctl-lun config option for consistency in HA setups. git-svn-id: svn://svn.freebsd.org/base/stable/10@288760 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- usr.sbin/ctld/ctl.conf.5 | 6 +++++- usr.sbin/ctld/ctld.c | 1 + usr.sbin/ctld/kernel.c | 5 +++++ usr.sbin/ctld/parse.y | 26 ++++++++++++++++++++++++-- usr.sbin/ctld/token.l | 1 + 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/usr.sbin/ctld/ctl.conf.5 b/usr.sbin/ctld/ctl.conf.5 index 9e8ac67e3..a05f89df5 100644 --- a/usr.sbin/ctld/ctl.conf.5 +++ b/usr.sbin/ctld/ctl.conf.5 @@ -28,7 +28,7 @@ .\" .\" $FreeBSD$ .\" -.Dd September 7, 2015 +.Dd September 15, 2015 .Dt CTL.CONF 5 .Os .Sh NAME @@ -365,6 +365,10 @@ The default backend is block. .It Ic blocksize Ar size The blocksize visible to the initiator. The default blocksize is 512. +.It Ic ctl-lun Ar lun_id +Global numeric identifier to use for a given LUN inside CTL. +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 option Ar name Ar value diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index 114deb1d1..8b13bce4c 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -1380,6 +1380,7 @@ lun_new(struct conf *conf, const char *name) lun->l_name = checked_strdup(name); TAILQ_INIT(&lun->l_options); TAILQ_INSERT_TAIL(&conf->conf_luns, lun, l_next); + lun->l_ctl_lun = -1; return (lun); } diff --git a/usr.sbin/ctld/kernel.c b/usr.sbin/ctld/kernel.c index 4ed9a410c..12f622c30 100644 --- a/usr.sbin/ctld/kernel.c +++ b/usr.sbin/ctld/kernel.c @@ -656,6 +656,11 @@ kernel_lun_add(struct lun *lun) if (lun->l_size != 0) req.reqdata.create.lun_size_bytes = lun->l_size; + if (lun->l_ctl_lun >= 0) { + req.reqdata.create.req_lun_id = lun->l_ctl_lun; + req.reqdata.create.flags |= CTL_LUN_FLAG_ID_REQ; + } + req.reqdata.create.flags |= CTL_LUN_FLAG_DEV_TYPE; req.reqdata.create.device_type = T_DIRECT; diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y index dda130b77..92d4d3edb 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 DEBUG DEVICE_ID DISCOVERY_AUTH_GROUP DISCOVERY_FILTER -%token FOREIGN +%token CLOSING_BRACKET CTL_LUN DEBUG DEVICE_ID DISCOVERY_AUTH_GROUP +%token DISCOVERY_FILTER FOREIGN %token INITIATOR_NAME INITIATOR_PORTAL ISNS_SERVER ISNS_PERIOD ISNS_TIMEOUT %token LISTEN LISTEN_ISER LUN MAXPROC OPENING_BRACKET OPTION %token PATH PIDFILE PORT PORTAL_GROUP REDIRECT SEMICOLON SERIAL SIZE STR @@ -842,6 +842,8 @@ lun_entry: | lun_device_id | + lun_ctl_lun + | lun_option | lun_path @@ -899,6 +901,26 @@ lun_device_id: DEVICE_ID STR } ; +lun_ctl_lun: CTL_LUN STR + { + uint64_t tmp; + + if (expand_number($2, &tmp) != 0) { + yyerror("invalid numeric value"); + free($2); + return (1); + } + + if (lun->l_ctl_lun >= 0) { + log_warnx("ctl_lun for lun \"%s\" " + "specified more than once", + lun->l_name); + return (1); + } + lun_set_ctl_lun(lun, tmp); + } + ; + lun_option: OPTION STR STR { struct lun_option *clo; diff --git a/usr.sbin/ctld/token.l b/usr.sbin/ctld/token.l index 979949c00..ce95e62ac 100644 --- a/usr.sbin/ctld/token.l +++ b/usr.sbin/ctld/token.l @@ -54,6 +54,7 @@ backend { return BACKEND; } blocksize { return BLOCKSIZE; } chap { return CHAP; } chap-mutual { return CHAP_MUTUAL; } +ctl-lun { return CTL_LUN; } debug { return DEBUG; } device-id { return DEVICE_ID; } discovery-auth-group { return DISCOVERY_AUTH_GROUP; } -- 2.45.0