diff options
author | trasz <trasz@FreeBSD.org> | 2016-05-31 11:32:07 +0000 |
---|---|---|
committer | trasz <trasz@FreeBSD.org> | 2016-05-31 11:32:07 +0000 |
commit | 57b120baca99da265a7c8c19f005889c18cc4ce9 (patch) | |
tree | f57ecea9678102f6e68e4e8d609716c155fee5e8 /usr.bin | |
parent | 911309521295b7118688ca73a76d7d0635123ba6 (diff) | |
download | FreeBSD-src-57b120baca99da265a7c8c19f005889c18cc4ce9.zip FreeBSD-src-57b120baca99da265a7c8c19f005889c18cc4ce9.tar.gz |
Add "iscsictl -e". Among other things, it makes it possible to perform
discovery without attaching to the targets ("iscsictl -Ad ... -e off"),
and then attach to selected ones ("iscsictl -Mi ... -e on").
PR: 204129
MFC after: 1 month
Relnotes: yes
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D6633
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/iscsictl/iscsi.conf.5 | 8 | ||||
-rw-r--r-- | usr.bin/iscsictl/iscsictl.8 | 13 | ||||
-rw-r--r-- | usr.bin/iscsictl/iscsictl.c | 61 | ||||
-rw-r--r-- | usr.bin/iscsictl/iscsictl.h | 6 | ||||
-rw-r--r-- | usr.bin/iscsictl/parse.y | 15 | ||||
-rw-r--r-- | usr.bin/iscsictl/token.l | 1 |
6 files changed, 94 insertions, 10 deletions
diff --git a/usr.bin/iscsictl/iscsi.conf.5 b/usr.bin/iscsictl/iscsi.conf.5 index be543e4..6d80392 100644 --- a/usr.bin/iscsictl/iscsi.conf.5 +++ b/usr.bin/iscsictl/iscsi.conf.5 @@ -125,6 +125,14 @@ must be defined. Discovery sessions result in the initiator connecting to all the targets returned by SendTargets iSCSI discovery with the defined .Sy TargetAddress . +.It Cm Enable +Enable or disable the session. +State can be either +.Qq Ar On , +or +.Qq Ar Off . +Default is +.Qq Ar On . .It Cm Offload Name of selected iSCSI hardware offload driver. Default is diff --git a/usr.bin/iscsictl/iscsictl.8 b/usr.bin/iscsictl/iscsictl.8 index 8c1b0ad..7360e6a 100644 --- a/usr.bin/iscsictl/iscsictl.8 +++ b/usr.bin/iscsictl/iscsictl.8 @@ -40,11 +40,13 @@ .Op Fl u Ar user Fl s Ar secret .Op Fl w Ar timeout .Op Fl r +.Op Fl e Cm on | off .Nm .Fl A .Fl d Ar discovery-host .Op Fl u Ar user Fl s Ar secret .Op Fl r +.Op Fl e Cm on | off .Nm .Fl A .Fl a Op Fl c Ar path @@ -58,6 +60,7 @@ .Op Fl t Ar target .Op Fl u Ar user .Op Fl s Ar secret +.Op Fl e Cm on | off .Nm .Fl M .Fl i Ar session-id @@ -110,6 +113,10 @@ Target host name or address used for SendTargets discovery. When used, it will add a temporary discovery session. After discovery is done, sessions will be added for each discovered target, and the temporary discovery session will be removed. +.It Fl e +Enable or disable the session. +This is ignored for discovery sessions, but gets passed down to normal +sessions they add. .It Fl i Session ID, as displayed by .Nm @@ -189,6 +196,12 @@ utility exits 0 on success, and >0 if an error occurs. Attach to target iqn.2012-06.com.example:target0, served by 192.168.1.1: .Dl Nm Fl A Fl t Ar iqn.2012-06.com.example:target0 Fl p Ar 192.168.1.1 .Pp +Perform discovery on 192.168.1.1, and add disabled sessions for each +discovered target; use +.Nm -M -e on +to connect them: +.Dl Nm Fl A Fl d Ar 192.168.1.1 Fl e Ar off +.Pp Disconnect all iSCSI sessions: .Dl Nm Fl Ra .Sh SEE ALSO diff --git a/usr.bin/iscsictl/iscsictl.c b/usr.bin/iscsictl/iscsictl.c index 5056886..fd05db3 100644 --- a/usr.bin/iscsictl/iscsictl.c +++ b/usr.bin/iscsictl/iscsictl.c @@ -98,7 +98,6 @@ target_delete(struct target *targ) free(targ); } - static char * default_initiator_name(void) { @@ -152,6 +151,23 @@ valid_hex(const char ch) } } +int +parse_enable(const char *enable) +{ + if (enable == NULL) + return (ENABLE_UNSPECIFIED); + + if (strcasecmp(enable, "on") == 0 || + strcasecmp(enable, "yes") == 0) + return (ENABLE_ON); + + if (strcasecmp(enable, "off") == 0 || + strcasecmp(enable, "no") == 0) + return (ENABLE_OFF); + + return (ENABLE_UNSPECIFIED); +} + bool valid_iscsi_name(const char *name) { @@ -325,6 +341,8 @@ conf_from_target(struct iscsi_session_conf *conf, sizeof(conf->isc_mutual_secret)); if (targ->t_session_type == SESSION_TYPE_DISCOVERY) conf->isc_discovery = 1; + if (targ->t_enable != ENABLE_OFF) + conf->isc_enable = 1; if (targ->t_protocol == PROTOCOL_ISER) conf->isc_iser = 1; if (targ->t_offload != NULL) @@ -371,7 +389,7 @@ kernel_modify(int iscsi_fd, unsigned int session_id, const struct target *targ) static void kernel_modify_some(int iscsi_fd, unsigned int session_id, const char *target, - const char *target_addr, const char *user, const char *secret) + const char *target_addr, const char *user, const char *secret, int enable) { struct iscsi_session_state *states = NULL; struct iscsi_session_state *state; @@ -421,6 +439,10 @@ kernel_modify_some(int iscsi_fd, unsigned int session_id, const char *target, strlcpy(conf->isc_user, user, sizeof(conf->isc_user)); if (secret != NULL) strlcpy(conf->isc_secret, secret, sizeof(conf->isc_secret)); + if (enable == ENABLE_ON) + conf->isc_enable = 1; + else if (enable == ENABLE_OFF) + conf->isc_enable = 0; memset(&ism, 0, sizeof(ism)); ism.ism_session_id = session_id; @@ -527,6 +549,9 @@ kernel_list(int iscsi_fd, const struct target *targ __unused, xo_emit("{L:/%-18s}{V:type/%s}\n", "Session type:", conf->isc_discovery ? "Discovery" : "Normal"); + xo_emit("{L:/%-18s}{V:enable/%s}\n", + "Enable:", + conf->isc_enable ? "Yes" : "No"); xo_emit("{L:/%-18s}{V:state/%s}\n", "Session state:", state->iss_connected ? "Connected" : "Disconnected"); @@ -575,6 +600,8 @@ kernel_list(int iscsi_fd, const struct target *targ __unused, } else { if (conf->isc_discovery) { xo_emit("{V:state}\n", "Discovery"); + } else if (conf->isc_enable == 0) { + xo_emit("{V:state}\n", "Disabled"); } else if (state->iss_connected) { xo_emit("{V:state}: ", "Connected"); print_periphs(state->iss_id); @@ -653,13 +680,13 @@ usage(void) { fprintf(stderr, "usage: iscsictl -A -p portal -t target " - "[-u user -s secret] [-w timeout]\n"); + "[-u user -s secret] [-w timeout] [-e on | off]\n"); fprintf(stderr, " iscsictl -A -d discovery-host " - "[-u user -s secret]\n"); + "[-u user -s secret] [-e on | off]\n"); fprintf(stderr, " iscsictl -A -a [-c path]\n"); fprintf(stderr, " iscsictl -A -n nickname [-c path]\n"); fprintf(stderr, " iscsictl -M -i session-id [-p portal] " - "[-t target] [-u user] [-s secret]\n"); + "[-t target] [-u user] [-s secret] [-e on | off]\n"); fprintf(stderr, " iscsictl -M -i session-id -n nickname " "[-c path]\n"); fprintf(stderr, " iscsictl -R [-p portal] [-t target]\n"); @@ -687,8 +714,8 @@ main(int argc, char **argv) rflag = 0, vflag = 0; const char *conf_path = DEFAULT_CONFIG_PATH; char *nickname = NULL, *discovery_host = NULL, *portal = NULL, - *target = NULL, *user = NULL, *secret = NULL; - int timeout = -1; + *target = NULL, *user = NULL, *secret = NULL; + int timeout = -1, enable = ENABLE_UNSPECIFIED; long long session_id = -1; char *end; int ch, error, iscsi_fd, retval, saved_errno; @@ -699,7 +726,7 @@ main(int argc, char **argv) argc = xo_parse_args(argc, argv); xo_open_container("iscsictl"); - while ((ch = getopt(argc, argv, "AMRLac:d:i:n:p:rt:u:s:vw:")) != -1) { + while ((ch = getopt(argc, argv, "AMRLac:d:e:i:n:p:rt:u:s:vw:")) != -1) { switch (ch) { case 'A': Aflag = 1; @@ -722,6 +749,13 @@ main(int argc, char **argv) case 'd': discovery_host = optarg; break; + case 'e': + enable = parse_enable(optarg); + if (enable == ENABLE_UNSPECIFIED) { + xo_errx(1, "invalid argument to -e, " + "must be either \"on\" or \"off\""); + } + break; case 'i': session_id = strtol(optarg, &end, 10); if ((size_t)(end - optarg) != strlen(optarg)) @@ -781,6 +815,8 @@ main(int argc, char **argv) */ if (Aflag != 0) { if (aflag != 0) { + if (enable != ENABLE_UNSPECIFIED) + xo_errx(1, "-a and -e and mutually exclusive"); if (portal != NULL) xo_errx(1, "-a and -p and mutually exclusive"); if (target != NULL) @@ -796,6 +832,8 @@ main(int argc, char **argv) if (rflag != 0) xo_errx(1, "-a and -r and mutually exclusive"); } else if (nickname != NULL) { + if (enable != ENABLE_UNSPECIFIED) + xo_errx(1, "-n and -e and mutually exclusive"); if (portal != NULL) xo_errx(1, "-n and -p and mutually exclusive"); if (target != NULL) @@ -838,6 +876,8 @@ main(int argc, char **argv) xo_errx(1, "-M requires -i"); if (nickname != NULL) { + if (enable != ENABLE_UNSPECIFIED) + xo_errx(1, "-n and -e and mutually exclusive"); if (portal != NULL) xo_errx(1, "-n and -p and mutually exclusive"); if (target != NULL) @@ -878,6 +918,8 @@ main(int argc, char **argv) if (discovery_host != NULL) xo_errx(1, "-d cannot be used with -R"); + if (enable != ENABLE_UNSPECIFIED) + xo_errx(1, "-e cannot be used with -R"); if (session_id != -1) xo_errx(1, "-i cannot be used with -R"); if (rflag != 0) @@ -946,7 +988,7 @@ main(int argc, char **argv) failed += kernel_list(iscsi_fd, targ, vflag); } else if (Mflag != 0) { kernel_modify_some(iscsi_fd, session_id, target, portal, - user, secret); + user, secret, enable); } else { if (Aflag != 0 && target != NULL) { if (valid_iscsi_name(target) == false) @@ -965,6 +1007,7 @@ main(int argc, char **argv) targ->t_session_type = SESSION_TYPE_NORMAL; targ->t_address = portal; } + targ->t_enable = enable; if (rflag != 0) targ->t_protocol = PROTOCOL_ISER; targ->t_user = user; diff --git a/usr.bin/iscsictl/iscsictl.h b/usr.bin/iscsictl/iscsictl.h index 727e8ae..18300a1 100644 --- a/usr.bin/iscsictl/iscsictl.h +++ b/usr.bin/iscsictl/iscsictl.h @@ -58,6 +58,10 @@ #define PROTOCOL_ISCSI 1 #define PROTOCOL_ISER 2 +#define ENABLE_UNSPECIFIED 0 +#define ENABLE_ON 1 +#define ENABLE_OFF 2 + struct target { TAILQ_ENTRY(target) t_next; struct conf *t_conf; @@ -71,6 +75,7 @@ struct target { int t_data_digest; int t_auth_method; int t_session_type; + int t_enable; int t_protocol; char *t_offload; char *t_user; @@ -113,5 +118,6 @@ void print_periphs(int session_id); char *checked_strdup(const char *); bool valid_iscsi_name(const char *name); +int parse_enable(const char *enable); #endif /* !ISCSICTL_H */ diff --git a/usr.bin/iscsictl/parse.y b/usr.bin/iscsictl/parse.y index 9941904..84c05b8 100644 --- a/usr.bin/iscsictl/parse.y +++ b/usr.bin/iscsictl/parse.y @@ -56,7 +56,7 @@ extern void yyrestart(FILE *); %} -%token AUTH_METHOD HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS +%token AUTH_METHOD ENABLE HEADER_DIGEST DATA_DIGEST TARGET_NAME TARGET_ADDRESS %token INITIATOR_NAME INITIATOR_ADDRESS INITIATOR_ALIAS USER SECRET %token MUTUAL_USER MUTUAL_SECRET SEMICOLON SESSION_TYPE PROTOCOL OFFLOAD %token IGNORED EQUALS OPENING_BRACKET CLOSING_BRACKET @@ -118,6 +118,8 @@ target_entry: | session_type | + enable + | offload | protocol @@ -253,6 +255,17 @@ session_type: SESSION_TYPE EQUALS STR } ; +enable: ENABLE EQUALS STR + { + if (target->t_enable != ENABLE_UNSPECIFIED) + xo_errx(1, "duplicated enable at line %d", lineno); + target->t_enable = parse_enable($3); + if (target->t_enable == ENABLE_UNSPECIFIED) + xo_errx(1, "invalid enable at line %d; " + "must be either \"on\" or \"off\"", lineno); + } + ; + offload: OFFLOAD EQUALS STR { if (target->t_offload != NULL) diff --git a/usr.bin/iscsictl/token.l b/usr.bin/iscsictl/token.l index 8cf2fec..c9e3e72 100644 --- a/usr.bin/iscsictl/token.l +++ b/usr.bin/iscsictl/token.l @@ -62,6 +62,7 @@ tgtChapName { return MUTUAL_USER; } tgtChapSecret { return MUTUAL_SECRET; } AuthMethod { return AUTH_METHOD; } SessionType { return SESSION_TYPE; } +enable { return ENABLE; } protocol { return PROTOCOL; } offload { return OFFLOAD; } port { return IGNORED; } |