aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin/iscsid
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2014-04-16 18:23:36 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2014-04-16 18:23:36 +0000
commit57a4f20b8dcfe1335f08c558d5da0ea72d3780ed (patch)
treea89f54c57099111ecedd3707d9ca5ea5cb03a477 /usr.sbin/iscsid
parenta67051e9f6d9298f9aa4852d8f58071d89405cf5 (diff)
downloadsrc-57a4f20b8dcfe1335f08c558d5da0ea72d3780ed.tar.gz
src-57a4f20b8dcfe1335f08c558d5da0ea72d3780ed.zip
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
Notes
Notes: svn path=/head/; revision=264549
Diffstat (limited to 'usr.sbin/iscsid')
-rw-r--r--usr.sbin/iscsid/iscsid.c48
-rw-r--r--usr.sbin/iscsid/iscsid.h2
-rw-r--r--usr.sbin/iscsid/pdu.c30
3 files changed, 46 insertions, 34 deletions
diff --git a/usr.sbin/iscsid/iscsid.c b/usr.sbin/iscsid/iscsid.c
index 25588dc7ed9f..cea996de6c3e 100644
--- a/usr.sbin/iscsid/iscsid.c
+++ b/usr.sbin/iscsid/iscsid.c
@@ -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;
- }
- 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: ISCSIDCONNECT", to_addr);
+ }
- 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);
+ return (conn);
}
-
-#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));
diff --git a/usr.sbin/iscsid/iscsid.h b/usr.sbin/iscsid/iscsid.h
index ec9f33bba51e..b19542d24250 100644
--- a/usr.sbin/iscsid/iscsid.h
+++ b/usr.sbin/iscsid/iscsid.h
@@ -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];
diff --git a/usr.sbin/iscsid/pdu.c b/usr.sbin/iscsid/pdu.c
index 24b63d794540..6b5630e8d90c 100644
--- a/usr.sbin/iscsid/pdu.c
+++ b/usr.sbin/iscsid/pdu.c
@@ -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)
{