Index: head/sys/dev/iscsi/iscsi.c =================================================================== --- head/sys/dev/iscsi/iscsi.c +++ head/sys/dev/iscsi/iscsi.c @@ -406,6 +406,11 @@ KASSERT(STAILQ_EMPTY(&is->is_postponed), ("destroying session with postponed PDUs")); + if (is->is_conf.isc_enable == 0 && is->is_conf.isc_discovery == 0) { + ISCSI_SESSION_UNLOCK(is); + return; + } + /* * Request immediate reconnection from iscsid(8). */ @@ -549,6 +554,9 @@ callout_schedule(&is->is_callout, 1 * hz); + if (is->is_conf.isc_enable == 0) + goto out; + is->is_timeout++; if (is->is_waiting_for_iscsid) { @@ -1311,6 +1319,11 @@ for (;;) { TAILQ_FOREACH(is, &sc->sc_sessions, is_next) { ISCSI_SESSION_LOCK(is); + if (is->is_conf.isc_enable == 0 && + is->is_conf.isc_discovery == 0) { + ISCSI_SESSION_UNLOCK(is); + continue; + } if (is->is_waiting_for_iscsid) break; ISCSI_SESSION_UNLOCK(is); @@ -1826,17 +1839,22 @@ callout_reset(&is->is_callout, 1 * hz, iscsi_callout, is); TAILQ_INSERT_TAIL(&sc->sc_sessions, is, is_next); + ISCSI_SESSION_LOCK(is); /* - * Trigger immediate reconnection. + * Don't notify iscsid(8) if the session is disabled and it's not + * a discovery session, */ - ISCSI_SESSION_LOCK(is); + if (is->is_conf.isc_enable == 0 && is->is_conf.isc_discovery == 0) { + ISCSI_SESSION_UNLOCK(is); + sx_xunlock(&sc->sc_lock); + return (0); + } + is->is_waiting_for_iscsid = true; strlcpy(is->is_reason, "Waiting for iscsid(8)", sizeof(is->is_reason)); ISCSI_SESSION_UNLOCK(is); cv_signal(&sc->sc_cv); - sx_xunlock(&sc->sc_lock); - return (0); } Index: head/sys/dev/iscsi/iscsi_ioctl.h =================================================================== --- head/sys/dev/iscsi/iscsi_ioctl.h +++ head/sys/dev/iscsi/iscsi_ioctl.h @@ -67,7 +67,8 @@ int isc_data_digest; int isc_iser; char isc_offload[ISCSI_OFFLOAD_LEN]; - int isc_spare[2]; + int isc_enable; + int isc_spare[1]; }; /* Index: head/usr.bin/iscsictl/iscsi.conf.5 =================================================================== --- head/usr.bin/iscsictl/iscsi.conf.5 +++ head/usr.bin/iscsictl/iscsi.conf.5 @@ -125,6 +125,14 @@ 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 Index: head/usr.bin/iscsictl/iscsictl.h =================================================================== --- head/usr.bin/iscsictl/iscsictl.h +++ head/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 @@ 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 @@ char *checked_strdup(const char *); bool valid_iscsi_name(const char *name); +int parse_enable(const char *enable); #endif /* !ISCSICTL_H */ Index: head/usr.bin/iscsictl/iscsictl.8 =================================================================== --- head/usr.bin/iscsictl/iscsictl.8 +++ head/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 @@ 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 @@ 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 Index: head/usr.bin/iscsictl/iscsictl.c =================================================================== --- head/usr.bin/iscsictl/iscsictl.c +++ head/usr.bin/iscsictl/iscsictl.c @@ -98,7 +98,6 @@ free(targ); } - static char * default_initiator_name(void) { @@ -152,6 +151,23 @@ } } +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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ { 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 @@ 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 @@ 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 @@ 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 @@ */ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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; Index: head/usr.bin/iscsictl/parse.y =================================================================== --- head/usr.bin/iscsictl/parse.y +++ head/usr.bin/iscsictl/parse.y @@ -56,7 +56,7 @@ %} -%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 @@ | session_type | + enable + | offload | protocol @@ -253,6 +255,17 @@ } ; +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) Index: head/usr.bin/iscsictl/token.l =================================================================== --- head/usr.bin/iscsictl/token.l +++ head/usr.bin/iscsictl/token.l @@ -62,6 +62,7 @@ tgtChapSecret { return MUTUAL_SECRET; } AuthMethod { return AUTH_METHOD; } SessionType { return SESSION_TYPE; } +enable { return ENABLE; } protocol { return PROTOCOL; } offload { return OFFLOAD; } port { return IGNORED; }