Make it possible for the initiator side to operate in both proxy

and normal mode; this makes it possible to compile with the former
by default, but use it only when neccessary.  That's especially
important for the userland part.

Sponsored by:	The FreeBSD Foundation
This commit is contained in:
Edward Tomasz Napierala 2014-04-16 18:23:36 +00:00
parent a67051e9f6
commit 57a4f20b8d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=264549
5 changed files with 71 additions and 47 deletions

View File

@ -1304,12 +1304,19 @@ iscsi_ioctl_daemon_handoff(struct iscsi_softc *sc,
ISCSI_SESSION_UNLOCK(is);
#ifndef ICL_KERNEL_PROXY
error = icl_conn_handoff(is->is_conn, handoff->idh_socket);
if (error != 0) {
sx_sunlock(&sc->sc_lock);
iscsi_session_terminate(is);
return (error);
#ifdef ICL_KERNEL_PROXY
if (handoff->idh_socket != 0) {
#endif
/*
* Handoff without using ICL proxy.
*/
error = icl_conn_handoff(is->is_conn, handoff->idh_socket);
if (error != 0) {
sx_sunlock(&sc->sc_lock);
iscsi_session_terminate(is);
return (error);
}
#ifdef ICL_KERNEL_PROXY
}
#endif
@ -1420,13 +1427,18 @@ iscsi_ioctl_daemon_connect(struct iscsi_softc *sc,
if (idc->idc_from_addrlen > 0) {
error = getsockaddr(&from_sa, (void *)idc->idc_from_addr, idc->idc_from_addrlen);
if (error != 0)
if (error != 0) {
ISCSI_SESSION_WARN(is,
"getsockaddr failed with error %d", error);
return (error);
}
} else {
from_sa = NULL;
}
error = getsockaddr(&to_sa, (void *)idc->idc_to_addr, idc->idc_to_addrlen);
if (error != 0) {
ISCSI_SESSION_WARN(is, "getsockaddr failed with error %d",
error);
free(from_sa, M_SONAME);
return (error);
}

View File

@ -129,9 +129,9 @@ struct iscsi_daemon_fail {
/*
* When ICL_KERNEL_PROXY is not defined, the iscsid(8) is responsible
* for creating the socket, connecting, performing Login Phase using
* socked in the usual userspace way, and then passing the socket file
* descriptor to the kernel part using ISCSIDHANDOFF.
* for creating the socket, connecting, and performing Login Phase using
* the socket in the usual userspace way, and then passing the socket
* file descriptor to the kernel part using ISCSIDHANDOFF.
*
* When ICL_KERNEL_PROXY is defined, the iscsid(8) creates the session
* using ISCSICONNECT, performs Login Phase using ISCSISEND/ISCSIRECEIVE
@ -162,7 +162,7 @@ struct iscsi_daemon_send {
void *ids_spare2;
size_t ids_data_segment_len;
void *ids_data_segment;
int ids_spare[4];
int ids_spare3[4];
};
struct iscsi_daemon_receive {
@ -172,7 +172,7 @@ struct iscsi_daemon_receive {
void *idr_spare2;
size_t idr_data_segment_len;
void *idr_data_segment;
int idr_spare[4];
int idr_spare3[4];
};
#define ISCSIDCONNECT _IOWR('I', 0x04, struct iscsi_daemon_connect)

View File

@ -194,30 +194,32 @@ connection_new(unsigned int session_id, const struct iscsi_session_conf *conf,
resolve_addr(conn, to_addr, &to_ai, false);
#ifdef ICL_KERNEL_PROXY
if (conn->conn_conf.isc_iser) {
memset(&idc, 0, sizeof(idc));
idc.idc_session_id = conn->conn_session_id;
if (conn->conn_conf.isc_iser)
idc.idc_iser = 1;
idc.idc_domain = to_ai->ai_family;
idc.idc_socktype = to_ai->ai_socktype;
idc.idc_protocol = to_ai->ai_protocol;
if (from_ai != NULL) {
idc.idc_from_addr = from_ai->ai_addr;
idc.idc_from_addrlen = from_ai->ai_addrlen;
}
idc.idc_to_addr = to_ai->ai_addr;
idc.idc_to_addrlen = to_ai->ai_addrlen;
memset(&idc, 0, sizeof(idc));
idc.idc_session_id = conn->conn_session_id;
if (conn->conn_conf.isc_iser)
idc.idc_iser = 1;
idc.idc_domain = to_ai->ai_family;
idc.idc_socktype = to_ai->ai_socktype;
idc.idc_protocol = to_ai->ai_protocol;
if (from_ai != NULL) {
idc.idc_from_addr = from_ai->ai_addr;
idc.idc_from_addrlen = from_ai->ai_addrlen;
log_debugx("connecting to %s using ICL kernel proxy", to_addr);
error = ioctl(iscsi_fd, ISCSIDCONNECT, &idc);
if (error != 0) {
fail(conn, strerror(errno));
log_err(1, "failed to connect to %s "
"using ICL kernel proxy: ISCSIDCONNECT", to_addr);
}
return (conn);
}
idc.idc_to_addr = to_ai->ai_addr;
idc.idc_to_addrlen = to_ai->ai_addrlen;
log_debugx("connecting to %s using ICL kernel proxy", to_addr);
error = ioctl(iscsi_fd, ISCSIDCONNECT, &idc);
if (error != 0) {
fail(conn, strerror(errno));
log_err(1, "failed to connect to %s using ICL kernel proxy",
to_addr);
}
#else /* !ICL_KERNEL_PROXY */
#endif /* ICL_KERNEL_PROXY */
if (conn->conn_conf.isc_iser) {
fail(conn, "iSER not supported");
@ -246,8 +248,6 @@ connection_new(unsigned int session_id, const struct iscsi_session_conf *conf,
log_err(1, "failed to connect to %s", to_addr);
}
#endif /* !ICL_KERNEL_PROXY */
return (conn);
}
@ -261,9 +261,7 @@ handoff(struct connection *conn)
memset(&idh, 0, sizeof(idh));
idh.idh_session_id = conn->conn_session_id;
#ifndef ICL_KERNEL_PROXY
idh.idh_socket = conn->conn_socket;
#endif
strlcpy(idh.idh_target_alias, conn->conn_target_alias,
sizeof(idh.idh_target_alias));
memcpy(idh.idh_isid, conn->conn_isid, sizeof(idh.idh_isid));

View File

@ -46,9 +46,7 @@
struct connection {
int conn_iscsi_fd;
#ifndef ICL_KERNEL_PROXY
int conn_socket;
#endif
unsigned int conn_session_id;
struct iscsi_session_conf conn_conf;
char conn_target_alias[ISCSI_ADDR_LEN];

View File

@ -101,13 +101,15 @@ pdu_new_response(struct pdu *request)
#ifdef ICL_KERNEL_PROXY
void
pdu_receive(struct pdu *pdu)
static void
pdu_receive_proxy(struct pdu *pdu)
{
struct iscsi_daemon_receive *idr;
size_t len;
int error;
assert(pdu->pdu_connection->conn_conf.isc_iser != 0);
pdu->pdu_data = malloc(ISCSI_MAX_DATA_SEGMENT_LENGTH);
if (pdu->pdu_data == NULL)
log_err(1, "malloc");
@ -136,12 +138,14 @@ pdu_receive(struct pdu *pdu)
free(idr);
}
void
pdu_send(struct pdu *pdu)
static void
pdu_send_proxy(struct pdu *pdu)
{
struct iscsi_daemon_send *ids;
int error;
assert(pdu->pdu_connection->conn_conf.isc_iser != 0);
pdu_set_data_segment_length(pdu, pdu->pdu_data_len);
ids = calloc(1, sizeof(*ids));
@ -160,7 +164,7 @@ pdu_send(struct pdu *pdu)
free(ids);
}
#else /* !ICL_KERNEL_PROXY */
#endif /* ICL_KERNEL_PROXY */
static size_t
pdu_padding(const struct pdu *pdu)
@ -196,6 +200,13 @@ pdu_receive(struct pdu *pdu)
size_t len, padding;
char dummy[4];
#ifdef ICL_KERNEL_PROXY
if (pdu->pdu_connection->conn_conf.isc_iser != 0)
return (pdu_receive_proxy(pdu));
#endif
assert(pdu->pdu_connection->conn_conf.isc_iser == 0);
pdu_read(pdu->pdu_connection->conn_socket,
(char *)pdu->pdu_bhs, sizeof(*pdu->pdu_bhs));
@ -237,6 +248,13 @@ pdu_send(struct pdu *pdu)
struct iovec iov[3];
int iovcnt;
#ifdef ICL_KERNEL_PROXY
if (pdu->pdu_connection->conn_conf.isc_iser != 0)
return (pdu_send_proxy(pdu));
#endif
assert(pdu->pdu_connection->conn_conf.isc_iser == 0);
pdu_set_data_segment_length(pdu, pdu->pdu_data_len);
iov[0].iov_base = pdu->pdu_bhs;
iov[0].iov_len = sizeof(*pdu->pdu_bhs);
@ -269,8 +287,6 @@ pdu_send(struct pdu *pdu)
log_errx(1, "short write");
}
#endif /* !ICL_KERNEL_PROXY */
void
pdu_delete(struct pdu *pdu)
{