diff options
Diffstat (limited to 'usr.sbin/iscsid')
-rw-r--r-- | usr.sbin/iscsid/Makefile | 6 | ||||
-rw-r--r-- | usr.sbin/iscsid/initiator.c | 109 | ||||
-rw-r--r-- | usr.sbin/iscsid/iscsid.h | 4 | ||||
-rw-r--r-- | usr.sbin/iscsid/session.c | 140 |
4 files changed, 147 insertions, 112 deletions
diff --git a/usr.sbin/iscsid/Makefile b/usr.sbin/iscsid/Makefile index 130beb0f1dc..ed5ec76e26a 100644 --- a/usr.sbin/iscsid/Makefile +++ b/usr.sbin/iscsid/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.2 2010/09/24 10:53:14 dlg Exp $ +# $OpenBSD: Makefile,v 1.3 2011/04/05 18:26:19 claudio Exp $ PROG= iscsid -SRCS= connection.c control.c initiator.c iscsid.c log.c pdu.c task.c \ - util.c vscsi.c +SRCS= connection.c control.c initiator.c iscsid.c log.c pdu.c session.c \ + task.c util.c vscsi.c MAN= iscsid.8 diff --git a/usr.sbin/iscsid/initiator.c b/usr.sbin/iscsid/initiator.c index 5e706cc82a7..9a65c73f94c 100644 --- a/usr.sbin/iscsid/initiator.c +++ b/usr.sbin/iscsid/initiator.c @@ -1,4 +1,4 @@ -/* $OpenBSD: initiator.c,v 1.4 2011/01/04 13:19:55 claudio Exp $ */ +/* $OpenBSD: initiator.c,v 1.5 2011/04/05 18:26:19 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -36,7 +36,6 @@ struct initiator *initiator; struct kvp *initiator_login_kvp(struct session *); -char *default_initiator_name(void); struct initiator * initiator_init(void) @@ -75,112 +74,6 @@ initiator_t2s(u_int target) return NULL; } -struct session * -session_find(struct initiator *i, char *name) -{ - struct session *s; - - TAILQ_FOREACH(s, &initiator->sessions, entry) { - if (strcmp(s->config.SessionName, name) == 0) - return s; - } - return NULL; -} - -struct session * -session_new(struct initiator *i, u_int8_t st) -{ - struct session *s; - - if (!(s = calloc(1, sizeof(*s)))) - return NULL; - - /* use the same qualifier unless there is a conflict */ - s->isid_base = i->config.isid_base; - s->isid_qual = i->config.isid_qual; - s->cmdseqnum = arc4random(); - s->itt = arc4random(); - s->initiator = i; - s->state = SESS_FREE; - - if (st == SESSION_TYPE_DISCOVERY) - s->target = 0; - else - s->target = s->initiator->target++; - - TAILQ_INSERT_HEAD(&i->sessions, s, entry); - TAILQ_INIT(&s->connections); - TAILQ_INIT(&s->tasks); - - return s; -} - -void -session_close(struct session *s) -{ - struct connection *c; - - while ((c = TAILQ_FIRST(&s->connections)) != NULL) - conn_free(c); - - free(s->config.TargetName); - free(s->config.InitiatorName); - free(s); -} - -void -session_config(struct session *s, struct session_config *sc) -{ - if (s->config.TargetName) - free(s->config.TargetName); - s->config.TargetName = NULL; - if (s->config.InitiatorName) - free(s->config.InitiatorName); - s->config.InitiatorName = NULL; - - s->config = *sc; - - if (sc->TargetName) { - s->config.TargetName = strdup(sc->TargetName); - if (s->config.TargetName == NULL) - fatal("strdup"); - } - if (sc->InitiatorName) { - s->config.InitiatorName = strdup(sc->InitiatorName); - if (s->config.InitiatorName == NULL) - fatal("strdup"); - } else - s->config.InitiatorName = default_initiator_name(); -} - -void -session_task_issue(struct session *s, struct task *t) -{ - TAILQ_INSERT_TAIL(&s->tasks, t, entry); - session_schedule(s); -} - -void -session_schedule(struct session *s) -{ - struct task *t = TAILQ_FIRST(&s->tasks); - struct connection *c; - - if (!t) - return; - - /* XXX IMMEDIATE TASK NEED SPECIAL HANDLING !!!! */ - - /* wake up a idle connection or a not busy one */ - /* XXX this needs more work as it makes the daemon go wrooOOOMM */ - TAILQ_REMOVE(&s->tasks, t, entry); - TAILQ_FOREACH(c, &s->connections, entry) - if (conn_task_issue(c, t)) - return; - /* all connections are busy readd task to the head */ - TAILQ_INSERT_HEAD(&s->tasks, t, entry); -} - struct task_login { struct task task; struct connection *c; diff --git a/usr.sbin/iscsid/iscsid.h b/usr.sbin/iscsid/iscsid.h index c5c19f4f00a..21d690a4cdc 100644 --- a/usr.sbin/iscsid/iscsid.h +++ b/usr.sbin/iscsid/iscsid.h @@ -1,4 +1,4 @@ -/* $OpenBSD: iscsid.h,v 1.4 2011/01/04 13:19:55 claudio Exp $ */ +/* $OpenBSD: iscsid.h,v 1.5 2011/04/05 18:26:19 claudio Exp $ */ /* * Copyright (c) 2009 Claudio Jeker <claudio@openbsd.org> @@ -67,6 +67,7 @@ TAILQ_HEAD(taskq, task); #define SESS_LOGGED_IN 0x0002 #define SESS_FAILED 0x0003 +#define CONN_DONE 0x0000 /* no real state just return value */ #define CONN_FREE 0x0001 #define CONN_XPT_WAIT 0x0002 #define CONN_XPT_UP 0x0004 @@ -243,6 +244,7 @@ struct session *initiator_t2s(u_int); void initiator_login(struct connection *); void initiator_discovery(struct session *); void initiator_nop_in_imm(struct connection *, struct pdu *); +char *default_initiator_name(void); int control_init(char *); void control_cleanup(char *); diff --git a/usr.sbin/iscsid/session.c b/usr.sbin/iscsid/session.c new file mode 100644 index 00000000000..5527f9a2668 --- /dev/null +++ b/usr.sbin/iscsid/session.c @@ -0,0 +1,140 @@ +/* $OpenBSD: session.c,v 1.1 2011/04/05 18:26:19 claudio Exp $ */ + +/* + * Copyright (c) 2011 Claudio Jeker <claudio@openbsd.org> + * + * 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 <sys/param.h> +#include <sys/types.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/uio.h> + +#include <scsi/iscsi.h> + +#include <event.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "iscsid.h" +#include "log.h" + +struct session * +session_find(struct initiator *i, char *name) +{ + struct session *s; + + TAILQ_FOREACH(s, &i->sessions, entry) { + if (strcmp(s->config.SessionName, name) == 0) + return s; + } + return NULL; +} + +struct session * +session_new(struct initiator *i, u_int8_t st) +{ + struct session *s; + + if (!(s = calloc(1, sizeof(*s)))) + return NULL; + + /* use the same qualifier unless there is a conflict */ + s->isid_base = i->config.isid_base; + s->isid_qual = i->config.isid_qual; + s->cmdseqnum = arc4random(); + s->itt = arc4random(); + s->initiator = i; + s->state = SESS_FREE; + + if (st == SESSION_TYPE_DISCOVERY) + s->target = 0; + else + s->target = s->initiator->target++; + + TAILQ_INSERT_HEAD(&i->sessions, s, entry); + TAILQ_INIT(&s->connections); + TAILQ_INIT(&s->tasks); + + return s; +} + +void +session_close(struct session *s) +{ + struct connection *c; + + while ((c = TAILQ_FIRST(&s->connections)) != NULL) + conn_free(c); + + free(s->config.TargetName); + free(s->config.InitiatorName); + free(s); +} + +void +session_config(struct session *s, struct session_config *sc) +{ + if (s->config.TargetName) + free(s->config.TargetName); + s->config.TargetName = NULL; + if (s->config.InitiatorName) + free(s->config.InitiatorName); + s->config.InitiatorName = NULL; + + s->config = *sc; + + if (sc->TargetName) { + s->config.TargetName = strdup(sc->TargetName); + if (s->config.TargetName == NULL) + fatal("strdup"); + } + if (sc->InitiatorName) { + s->config.InitiatorName = strdup(sc->InitiatorName); + if (s->config.InitiatorName == NULL) + fatal("strdup"); + } else + s->config.InitiatorName = default_initiator_name(); +} + +void +session_task_issue(struct session *s, struct task *t) +{ + TAILQ_INSERT_TAIL(&s->tasks, t, entry); + session_schedule(s); +} + +void +session_schedule(struct session *s) +{ + struct task *t = TAILQ_FIRST(&s->tasks); + struct connection *c; + + if (!t) + return; + + /* XXX IMMEDIATE TASK NEED SPECIAL HANDLING !!!! */ + + /* wake up a idle connection or a not busy one */ + /* XXX this needs more work as it makes the daemon go wrooOOOMM */ + TAILQ_REMOVE(&s->tasks, t, entry); + TAILQ_FOREACH(c, &s->connections, entry) + if (conn_task_issue(c, t)) + return; + /* all connections are busy readd task to the head */ + TAILQ_INSERT_HEAD(&s->tasks, t, entry); +} |