From: claudio Date: Fri, 16 Apr 2021 14:37:06 +0000 (+0000) Subject: Implement a control message to get the state of iscsid. This is used X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=ea99aae698319411d0ceba71a85d96f5b73506a2;p=openbsd Implement a control message to get the state of iscsid. This is used by iscsictl to poll for completion after reload commands. With this slow session establishment should not cause mount errors during startup. Initial version from Dr Ashton Fagg ashton (at) fagg id au OK dlg@ deraadt@ --- diff --git a/usr.sbin/iscsid/Makefile b/usr.sbin/iscsid/Makefile index 7a62024e68b..2adb03aedbe 100644 --- a/usr.sbin/iscsid/Makefile +++ b/usr.sbin/iscsid/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.5 2019/11/25 22:52:13 kn Exp $ +# $OpenBSD: Makefile,v 1.6 2021/04/16 14:37:06 claudio Exp $ PROG= iscsid SRCS= connection.c control.c initiator.c iscsid.c log.c logmsg.c pdu.c \ - session.c task.c util.c vscsi.c + poll.c session.c task.c util.c vscsi.c MAN= iscsid.8 diff --git a/usr.sbin/iscsid/iscsid.c b/usr.sbin/iscsid/iscsid.c index d3526e96363..6815ad7a0fa 100644 --- a/usr.sbin/iscsid/iscsid.c +++ b/usr.sbin/iscsid/iscsid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iscsid.c,v 1.21 2021/01/27 07:21:54 deraadt Exp $ */ +/* $OpenBSD: iscsid.c,v 1.22 2021/04/16 14:37:06 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker @@ -211,6 +211,7 @@ iscsid_ctrl_dispatch(void *ch, struct pdu *pdu) struct initiator_config *ic; struct session_config *sc; struct session *s; + struct session_poll p = { 0 }; int *valp; cmh = pdu_getbuf(pdu, NULL, 0); @@ -304,6 +305,12 @@ iscsid_ctrl_dispatch(void *ch, struct pdu *pdu) control_compose(ch, CTRL_SUCCESS, NULL, 0); break; + case CTRL_SESS_POLL: + TAILQ_FOREACH(s, &initiator->sessions, entry) + poll_session(&p, s); + poll_finalize(&p); + control_compose(ch, CTRL_SESS_POLL, &p, sizeof(p)); + break; default: log_warnx("unknown control message type %d", cmh->type); control_compose(ch, CTRL_FAILURE, NULL, 0); diff --git a/usr.sbin/iscsid/iscsid.h b/usr.sbin/iscsid/iscsid.h index b43fb5dcd99..3ace3eee169 100644 --- a/usr.sbin/iscsid/iscsid.h +++ b/usr.sbin/iscsid/iscsid.h @@ -1,4 +1,4 @@ -/* $OpenBSD: iscsid.h,v 1.16 2016/09/02 16:22:31 benno Exp $ */ +/* $OpenBSD: iscsid.h,v 1.17 2021/04/16 14:37:06 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker @@ -67,7 +67,7 @@ struct ctrldata { #define CTRL_LOG_VERBOSE 6 #define CTRL_VSCSI_STATS 7 #define CTRL_SHOW_SUM 8 - +#define CTRL_SESS_POLL 9 TAILQ_HEAD(session_head, session); TAILQ_HEAD(connection_head, connection); @@ -75,10 +75,10 @@ TAILQ_HEAD(pduq, pdu); TAILQ_HEAD(taskq, task); /* as in tcp_seq.h */ -#define SEQ_LT(a,b) ((int)((a)-(b)) < 0) -#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) -#define SEQ_GT(a,b) ((int)((a)-(b)) > 0) -#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) +#define SEQ_LT(a,b) ((int)((a)-(b)) < 0) +#define SEQ_LEQ(a,b) ((int)((a)-(b)) <= 0) +#define SEQ_GT(a,b) ((int)((a)-(b)) > 0) +#define SEQ_GEQ(a,b) ((int)((a)-(b)) >= 0) #define SESS_INIT 0x0001 #define SESS_FREE 0x0002 @@ -251,6 +251,16 @@ struct session { int action; }; +struct session_poll { + int session_count; + int session_init_count; + int session_running_count; + int conn_logged_in_count; + int conn_failed_count; + int conn_waiting_count; + int sess_conn_status; +}; + struct connection { struct event ev; struct event wev; @@ -391,6 +401,10 @@ void vscsi_status(int, int, void *, size_t); void vscsi_event(unsigned long, u_int, u_int); struct vscsi_stats *vscsi_stats(void); +/* Session polling */ +void poll_session(struct session_poll *, struct session *); +void poll_finalize(struct session_poll *); + /* logmsg.c */ void log_hexdump(void *, size_t); void log_pdu(struct pdu *, int); diff --git a/usr.sbin/iscsid/poll.c b/usr.sbin/iscsid/poll.c new file mode 100644 index 00000000000..1442e2028eb --- /dev/null +++ b/usr.sbin/iscsid/poll.c @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2021 Dr Ashton Fagg + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "iscsid.h" +#include "log.h" + +void +poll_session(struct session_poll *p, struct session *s) +{ + if (!s) + fatal("poll_session failed: invalid session"); + + ++p->session_count; + + /* + * If SESS_RUNNING, the session has either been brought up + * successfully, or has failed. + */ + if (s->state & SESS_RUNNING) { + struct connection *c; + int is_logged_in = 0; + int is_failed = 0; + int is_waiting = 0; + + ++p->session_running_count; + + /* Next, check what state the connections are in. */ + TAILQ_FOREACH(c, &s->connections, entry) { + if (c->state & CONN_LOGGED_IN) + ++is_logged_in; + else if (c->state & CONN_FAILED) + ++is_failed; + else if (c->state & CONN_NEVER_LOGGED_IN) + ++is_waiting; + + } + + /* + * Potentially, we have multiple connections for each session. + * Handle this by saying that a single connection logging + * in takes precedent over a failed connection. Only say + * the session login has failed if none of the connections + * have logged in and nothing is in flight. + */ + + if (is_logged_in) + ++p->conn_logged_in_count; + if (is_failed) + ++p->conn_failed_count; + if (is_waiting) + ++p->conn_waiting_count; + + /* Sessions in SESS_INIT need to be waited on. */ + } else if (s->state & SESS_INIT) + ++p->session_init_count; + else + fatal("poll_session: unknown state."); +} + +/* + * Set session_poll sess_conn_status based on the number of sessions + * versus number of logged in or failed sessions. If the numbers are + * equal iscsictl can stop polling since all sessions reached a stable state. + */ +void +poll_finalize(struct session_poll *p) +{ + p->sess_conn_status = (p->session_count == p->conn_logged_in_count + + p->conn_failed_count); +}