Add -w flag to iscsictl(8) utility, to make it wait for successfull
session establishment. Scripting is kind of hard without it. Reviewed by: mav@ MFC after: 1 month Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D3872
This commit is contained in:
parent
defd502f1f
commit
1dba27c1bf
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=289453
@ -27,7 +27,7 @@
|
|||||||
.\"
|
.\"
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd September 12, 2014
|
.Dd October 17, 2015
|
||||||
.Dt ISCSICTL 8
|
.Dt ISCSICTL 8
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -36,7 +36,9 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Fl A
|
.Fl A
|
||||||
.Fl p Ar portal Fl t Ar target Op Fl u Ar user Fl s Ar secret
|
.Fl p Ar portal Fl t Ar target
|
||||||
|
.Op Fl u Ar user Fl s Ar secret
|
||||||
|
.Op Fl w Ar timeout
|
||||||
.Nm
|
.Nm
|
||||||
.Fl A
|
.Fl A
|
||||||
.Fl d Ar discovery-host Op Fl u Ar user Fl s Ar secret
|
.Fl d Ar discovery-host Op Fl u Ar user Fl s Ar secret
|
||||||
@ -70,6 +72,7 @@
|
|||||||
.Nm
|
.Nm
|
||||||
.Fl L
|
.Fl L
|
||||||
.Op Fl v
|
.Op Fl v
|
||||||
|
.Op Fl w Ar timeout
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
.Nm
|
.Nm
|
||||||
@ -113,6 +116,10 @@ Target name.
|
|||||||
CHAP login.
|
CHAP login.
|
||||||
.It Fl v
|
.It Fl v
|
||||||
Verbose mode.
|
Verbose mode.
|
||||||
|
.It Fl w
|
||||||
|
Instead of returning immediately, wait up to
|
||||||
|
.Ar timeout
|
||||||
|
seconds until all configured sessions are successfully established.
|
||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
Certain parameters are necessary when adding a session.
|
Certain parameters are necessary when adding a session.
|
||||||
@ -132,9 +139,11 @@ via configuration file.
|
|||||||
.Pp
|
.Pp
|
||||||
Since connecting to the target is performed in background, non-zero
|
Since connecting to the target is performed in background, non-zero
|
||||||
exit status does not mean that the session was successfully established.
|
exit status does not mean that the session was successfully established.
|
||||||
Use
|
Use either
|
||||||
.Nm Fl L
|
.Nm Fl L
|
||||||
to check the connection status.
|
to check the connection status, or the
|
||||||
|
.Fl w
|
||||||
|
flag to wait for session establishment.
|
||||||
.Pp
|
.Pp
|
||||||
Note that in order for the iSCSI initiator to be able to connect to a target,
|
Note that in order for the iSCSI initiator to be able to connect to a target,
|
||||||
the
|
the
|
||||||
|
@ -592,12 +592,70 @@ kernel_list(int iscsi_fd, const struct target *targ __unused,
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
kernel_wait(int iscsi_fd, int timeout)
|
||||||
|
{
|
||||||
|
struct iscsi_session_state *states = NULL;
|
||||||
|
const struct iscsi_session_state *state;
|
||||||
|
const struct iscsi_session_conf *conf;
|
||||||
|
struct iscsi_session_list isl;
|
||||||
|
unsigned int i, nentries = 1;
|
||||||
|
bool all_connected;
|
||||||
|
int error;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
for (;;) {
|
||||||
|
states = realloc(states,
|
||||||
|
nentries * sizeof(struct iscsi_session_state));
|
||||||
|
if (states == NULL)
|
||||||
|
xo_err(1, "realloc");
|
||||||
|
|
||||||
|
memset(&isl, 0, sizeof(isl));
|
||||||
|
isl.isl_nentries = nentries;
|
||||||
|
isl.isl_pstates = states;
|
||||||
|
|
||||||
|
error = ioctl(iscsi_fd, ISCSISLIST, &isl);
|
||||||
|
if (error != 0 && errno == EMSGSIZE) {
|
||||||
|
nentries *= 4;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (error != 0) {
|
||||||
|
xo_warn("ISCSISLIST");
|
||||||
|
return (error);
|
||||||
|
}
|
||||||
|
|
||||||
|
all_connected = true;
|
||||||
|
for (i = 0; i < isl.isl_nentries; i++) {
|
||||||
|
state = &states[i];
|
||||||
|
conf = &state->iss_conf;
|
||||||
|
|
||||||
|
if (!state->iss_connected) {
|
||||||
|
all_connected = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (all_connected)
|
||||||
|
return (0);
|
||||||
|
|
||||||
|
sleep(1);
|
||||||
|
|
||||||
|
if (timeout > 0) {
|
||||||
|
timeout--;
|
||||||
|
if (timeout == 0)
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
fprintf(stderr, "usage: iscsictl -A -p portal -t target "
|
fprintf(stderr, "usage: iscsictl -A -p portal -t target "
|
||||||
"[-u user -s secret]\n");
|
"[-u user -s secret] [-w timeout]\n");
|
||||||
fprintf(stderr, " iscsictl -A -d discovery-host "
|
fprintf(stderr, " iscsictl -A -d discovery-host "
|
||||||
"[-u user -s secret]\n");
|
"[-u user -s secret]\n");
|
||||||
fprintf(stderr, " iscsictl -A -a [-c path]\n");
|
fprintf(stderr, " iscsictl -A -a [-c path]\n");
|
||||||
@ -609,7 +667,7 @@ usage(void)
|
|||||||
fprintf(stderr, " iscsictl -R [-p portal] [-t target]\n");
|
fprintf(stderr, " iscsictl -R [-p portal] [-t target]\n");
|
||||||
fprintf(stderr, " iscsictl -R -a\n");
|
fprintf(stderr, " iscsictl -R -a\n");
|
||||||
fprintf(stderr, " iscsictl -R -n nickname [-c path]\n");
|
fprintf(stderr, " iscsictl -R -n nickname [-c path]\n");
|
||||||
fprintf(stderr, " iscsictl -L [-v]\n");
|
fprintf(stderr, " iscsictl -L [-v] [-w timeout]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -631,6 +689,7 @@ main(int argc, char **argv)
|
|||||||
const char *conf_path = DEFAULT_CONFIG_PATH;
|
const char *conf_path = DEFAULT_CONFIG_PATH;
|
||||||
char *nickname = NULL, *discovery_host = NULL, *portal = NULL,
|
char *nickname = NULL, *discovery_host = NULL, *portal = NULL,
|
||||||
*target = NULL, *user = NULL, *secret = NULL;
|
*target = NULL, *user = NULL, *secret = NULL;
|
||||||
|
int timeout = -1;
|
||||||
long long session_id = -1;
|
long long session_id = -1;
|
||||||
char *end;
|
char *end;
|
||||||
int ch, error, iscsi_fd, retval, saved_errno;
|
int ch, error, iscsi_fd, retval, saved_errno;
|
||||||
@ -641,7 +700,7 @@ main(int argc, char **argv)
|
|||||||
argc = xo_parse_args(argc, argv);
|
argc = xo_parse_args(argc, argv);
|
||||||
xo_open_container("iscsictl");
|
xo_open_container("iscsictl");
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "AMRLac:d:i:n:p:t:u:s:v")) != -1) {
|
while ((ch = getopt(argc, argv, "AMRLac:d:i:n:p:t:u:s:vw:")) != -1) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'A':
|
case 'A':
|
||||||
Aflag = 1;
|
Aflag = 1;
|
||||||
@ -692,6 +751,13 @@ main(int argc, char **argv)
|
|||||||
case 'v':
|
case 'v':
|
||||||
vflag = 1;
|
vflag = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'w':
|
||||||
|
timeout = strtol(optarg, &end, 10);
|
||||||
|
if ((size_t)(end - optarg) != strlen(optarg))
|
||||||
|
xo_errx(1, "trailing characters after timeout");
|
||||||
|
if (timeout < 0)
|
||||||
|
xo_errx(1, "timeout cannot be negative");
|
||||||
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
@ -782,6 +848,8 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if (vflag != 0)
|
if (vflag != 0)
|
||||||
xo_errx(1, "-v cannot be used with -M");
|
xo_errx(1, "-v cannot be used with -M");
|
||||||
|
if (timeout != -1)
|
||||||
|
xo_errx(1, "-w cannot be used with -M");
|
||||||
|
|
||||||
} else if (Rflag != 0) {
|
} else if (Rflag != 0) {
|
||||||
if (user != NULL)
|
if (user != NULL)
|
||||||
@ -811,6 +879,8 @@ main(int argc, char **argv)
|
|||||||
xo_errx(1, "-i cannot be used with -R");
|
xo_errx(1, "-i cannot be used with -R");
|
||||||
if (vflag != 0)
|
if (vflag != 0)
|
||||||
xo_errx(1, "-v cannot be used with -R");
|
xo_errx(1, "-v cannot be used with -R");
|
||||||
|
if (timeout != -1)
|
||||||
|
xo_errx(1, "-w cannot be used with -R");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
assert(Lflag != 0);
|
assert(Lflag != 0);
|
||||||
@ -896,6 +966,9 @@ main(int argc, char **argv)
|
|||||||
failed += kernel_list(iscsi_fd, targ, vflag);
|
failed += kernel_list(iscsi_fd, targ, vflag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (timeout != -1)
|
||||||
|
failed += kernel_wait(iscsi_fd, timeout);
|
||||||
|
|
||||||
error = close(iscsi_fd);
|
error = close(iscsi_fd);
|
||||||
if (error != 0)
|
if (error != 0)
|
||||||
xo_err(1, "close");
|
xo_err(1, "close");
|
||||||
|
Loading…
Reference in New Issue
Block a user