Implement redirection handling in initiator.
Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
9975d0a2a6
commit
49d8d5028f
@ -1589,6 +1589,33 @@ iscsi_sanitize_session_conf(struct iscsi_session_conf *isc)
|
||||
isc->isc_mutual_secret[ISCSI_SECRET_LEN - 1] = '\0';
|
||||
}
|
||||
|
||||
static bool
|
||||
iscsi_valid_session_conf(const struct iscsi_session_conf *isc)
|
||||
{
|
||||
|
||||
if (isc->isc_initiator[0] == '\0') {
|
||||
ISCSI_DEBUG("empty isc_initiator");
|
||||
return (false);
|
||||
}
|
||||
|
||||
if (isc->isc_target_addr[0] == '\0') {
|
||||
ISCSI_DEBUG("empty isc_target_addr");
|
||||
return (false);
|
||||
}
|
||||
|
||||
if (isc->isc_discovery != 0 && isc->isc_target[0] != 0) {
|
||||
ISCSI_DEBUG("non-empty isc_target for discovery session");
|
||||
return (false);
|
||||
}
|
||||
|
||||
if (isc->isc_discovery == 0 && isc->isc_target[0] == 0) {
|
||||
ISCSI_DEBUG("empty isc_target for non-discovery session");
|
||||
return (false);
|
||||
}
|
||||
|
||||
return (true);
|
||||
}
|
||||
|
||||
static int
|
||||
iscsi_ioctl_session_add(struct iscsi_softc *sc, struct iscsi_session_add *isa)
|
||||
{
|
||||
@ -1597,22 +1624,12 @@ iscsi_ioctl_session_add(struct iscsi_softc *sc, struct iscsi_session_add *isa)
|
||||
int error;
|
||||
|
||||
iscsi_sanitize_session_conf(&isa->isa_conf);
|
||||
if (iscsi_valid_session_conf(&isa->isa_conf) == false)
|
||||
return (EINVAL);
|
||||
|
||||
is = malloc(sizeof(*is), M_ISCSI, M_ZERO | M_WAITOK);
|
||||
memcpy(&is->is_conf, &isa->isa_conf, sizeof(is->is_conf));
|
||||
|
||||
if (is->is_conf.isc_initiator[0] == '\0' ||
|
||||
is->is_conf.isc_target_addr[0] == '\0') {
|
||||
free(is, M_ISCSI);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
if ((is->is_conf.isc_discovery != 0 && is->is_conf.isc_target[0] != 0) ||
|
||||
(is->is_conf.isc_discovery == 0 && is->is_conf.isc_target[0] == 0)) {
|
||||
free(is, M_ISCSI);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
sx_xlock(&sc->sc_lock);
|
||||
|
||||
/*
|
||||
@ -1769,7 +1786,38 @@ iscsi_ioctl_session_list(struct iscsi_softc *sc, struct iscsi_session_list *isl)
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
iscsi_ioctl_session_modify(struct iscsi_softc *sc,
|
||||
struct iscsi_session_modify *ism)
|
||||
{
|
||||
struct iscsi_session *is;
|
||||
|
||||
iscsi_sanitize_session_conf(&ism->ism_conf);
|
||||
if (iscsi_valid_session_conf(&ism->ism_conf) == false)
|
||||
return (EINVAL);
|
||||
|
||||
sx_xlock(&sc->sc_lock);
|
||||
TAILQ_FOREACH(is, &sc->sc_sessions, is_next) {
|
||||
ISCSI_SESSION_LOCK(is);
|
||||
if (is->is_id == ism->ism_session_id)
|
||||
break;
|
||||
ISCSI_SESSION_UNLOCK(is);
|
||||
}
|
||||
if (is == NULL) {
|
||||
sx_xunlock(&sc->sc_lock);
|
||||
return (ESRCH);
|
||||
}
|
||||
sx_xunlock(&sc->sc_lock);
|
||||
|
||||
memcpy(&is->is_conf, &ism->ism_conf, sizeof(is->is_conf));
|
||||
ISCSI_SESSION_UNLOCK(is);
|
||||
|
||||
iscsi_session_reconnect(is);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode,
|
||||
struct thread *td)
|
||||
@ -1808,6 +1856,9 @@ iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode,
|
||||
case ISCSISLIST:
|
||||
return (iscsi_ioctl_session_list(sc,
|
||||
(struct iscsi_session_list *)arg));
|
||||
case ISCSISMODIFY:
|
||||
return (iscsi_ioctl_session_modify(sc,
|
||||
(struct iscsi_session_modify *)arg));
|
||||
default:
|
||||
return (EINVAL);
|
||||
}
|
||||
|
@ -202,8 +202,15 @@ struct iscsi_session_list {
|
||||
int isl_spare[4];
|
||||
};
|
||||
|
||||
struct iscsi_session_modify {
|
||||
unsigned int ism_session_id;
|
||||
struct iscsi_session_conf ism_conf;
|
||||
int ism_spare[4];
|
||||
};
|
||||
|
||||
#define ISCSISADD _IOW('I', 0x11, struct iscsi_session_add)
|
||||
#define ISCSISREMOVE _IOW('I', 0x12, struct iscsi_session_remove)
|
||||
#define ISCSISLIST _IOWR('I', 0x13, struct iscsi_session_list)
|
||||
#define ISCSISMODIFY _IOWR('I', 0x14, struct iscsi_session_modify)
|
||||
|
||||
#endif /* !ISCSI_IOCTL_H */
|
||||
|
@ -304,10 +304,10 @@ capsicate(struct connection *conn)
|
||||
cap_rights_t rights;
|
||||
#ifdef ICL_KERNEL_PROXY
|
||||
const unsigned long cmds[] = { ISCSIDCONNECT, ISCSIDSEND, ISCSIDRECEIVE,
|
||||
ISCSIDHANDOFF, ISCSIDFAIL, ISCSISADD, ISCSISREMOVE };
|
||||
ISCSIDHANDOFF, ISCSIDFAIL, ISCSISADD, ISCSISREMOVE, ISCSISMODIFY };
|
||||
#else
|
||||
const unsigned long cmds[] = { ISCSIDHANDOFF, ISCSIDFAIL, ISCSISADD,
|
||||
ISCSISREMOVE };
|
||||
ISCSISREMOVE, ISCSISMODIFY };
|
||||
#endif
|
||||
|
||||
cap_rights_init(&rights, CAP_IOCTL);
|
||||
|
@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
@ -158,6 +159,60 @@ login_target_error_str(int class, int detail)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
kernel_modify(const struct connection *conn, const char *target_address)
|
||||
{
|
||||
struct iscsi_session_modify ism;
|
||||
int error;
|
||||
|
||||
memset(&ism, 0, sizeof(ism));
|
||||
ism.ism_session_id = conn->conn_session_id;
|
||||
memcpy(&ism.ism_conf, &conn->conn_conf, sizeof(ism.ism_conf));
|
||||
strlcpy(ism.ism_conf.isc_target_addr, target_address,
|
||||
sizeof(ism.ism_conf.isc_target));
|
||||
error = ioctl(conn->conn_iscsi_fd, ISCSISMODIFY, &ism);
|
||||
if (error != 0) {
|
||||
log_err(1, "failed to redirect to %s: ISCSISMODIFY",
|
||||
target_address);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX: The way it works is suboptimal; what should happen is described
|
||||
* in draft-gilligan-iscsi-fault-tolerance-00. That, however, would
|
||||
* be much more complicated: we would need to keep "dependencies"
|
||||
* for sessions, so that, in case described in draft and using draft
|
||||
* terminology, we would have three sessions: one for discovery,
|
||||
* one for initial target portal, and one for redirect portal.
|
||||
* This would allow us to "backtrack" on connection failure,
|
||||
* as described in draft.
|
||||
*/
|
||||
static void
|
||||
login_handle_redirection(struct connection *conn, struct pdu *response)
|
||||
{
|
||||
struct iscsi_bhs_login_response *bhslr;
|
||||
struct keys *response_keys;
|
||||
const char *target_address;
|
||||
|
||||
bhslr = (struct iscsi_bhs_login_response *)response->pdu_bhs;
|
||||
assert (bhslr->bhslr_status_class == 1);
|
||||
|
||||
response_keys = keys_new();
|
||||
keys_load(response_keys, response);
|
||||
|
||||
target_address = keys_find(response_keys, "TargetAddress");
|
||||
if (target_address == NULL)
|
||||
log_errx(1, "received redirection without TargetAddress");
|
||||
if (target_address[0] == '\0')
|
||||
log_errx(1, "received redirection with empty TargetAddress");
|
||||
if (strlen(target_address) >=
|
||||
sizeof(conn->conn_conf.isc_target_addr) - 1)
|
||||
log_errx(1, "received TargetAddress is too long");
|
||||
|
||||
log_debugx("received redirection to \"%s\"", target_address);
|
||||
kernel_modify(conn, target_address);
|
||||
}
|
||||
|
||||
static struct pdu *
|
||||
login_receive(struct connection *conn)
|
||||
{
|
||||
@ -184,6 +239,11 @@ login_receive(struct connection *conn)
|
||||
if (bhslr->bhslr_version_active != 0x00)
|
||||
log_errx(1, "received Login PDU with unsupported "
|
||||
"Version-active 0x%x", bhslr->bhslr_version_active);
|
||||
if (bhslr->bhslr_status_class == 1) {
|
||||
login_handle_redirection(conn, response);
|
||||
log_debugx("redirection handled; exiting");
|
||||
exit(0);
|
||||
}
|
||||
if (bhslr->bhslr_status_class != 0) {
|
||||
errorstr = login_target_error_str(bhslr->bhslr_status_class,
|
||||
bhslr->bhslr_status_detail);
|
||||
|
Loading…
x
Reference in New Issue
Block a user