[Stgt-devel] [PATCH 09/18] iser event handler to tcp

Pete Wyckoff pw
Tue Sep 4 22:09:32 CEST 2007


Move iscsi_event_handler to iscsi_tcp.c as it is TCP-specific.  RDMA will
have its own event handler.  Both will call into iscsi_tx_handler and
iscsi_rx_handler, which are now exported, along with iscsi_scsi_cmd_execute
that will be needed when an RDMA read collects all the write data.

Signed-off-by: Pete Wyckoff <pw at osc.edu>
---
 usr/iscsi/iscsi_tcp.c |   23 ++++++++++++++++++++++-
 usr/iscsi/iscsid.c    |   25 +++----------------------
 usr/iscsi/iscsid.h    |    4 +++-
 3 files changed, 28 insertions(+), 24 deletions(-)

diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index 0d189c7..7e0ab90 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -40,6 +40,8 @@
 #define LISTEN_MAX		4
 #define INCOMING_MAX		32
 
+static void iscsi_tcp_event_handler(int fd, int events, void *data);
+
 static int set_keepalive(int fd)
 {
 	int ret, opt;
@@ -97,7 +99,7 @@ static void accept_connection(int afd, int events, void *data)
 	conn_read_pdu(conn);
 	set_non_blocking(fd);
 
-	err = tgt_event_add(fd, EPOLLIN, iscsi_event_handler, conn);
+	err = tgt_event_add(fd, EPOLLIN, iscsi_tcp_event_handler, conn);
 	if (err)
 		goto free_conn;
 
@@ -109,6 +111,25 @@ out:
 	return;
 }
 
+static void iscsi_tcp_event_handler(int fd, int events, void *data)
+{
+	struct iscsi_connection *conn = (struct iscsi_connection *) data;
+
+	if (events & EPOLLIN)
+		iscsi_rx_handler(fd, conn);
+
+	if (conn->state == STATE_CLOSE)
+		dprintf("connection closed\n");
+
+	if (conn->state != STATE_CLOSE && events & EPOLLOUT)
+		iscsi_tx_handler(fd, conn);
+
+	if (conn->state == STATE_CLOSE) {
+		conn_close(conn, fd);
+		dprintf("connection closed\n");
+	}
+}
+
 static int iscsi_tcp_init(void)
 {
 	struct addrinfo hints, *res, *res0;
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 2d96930..0701c69 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1155,7 +1155,7 @@ static int iscsi_target_cmd_queue(struct iscsi_task *task)
 	return target_cmd_queue(conn->session->target->tid, scmd);
 }
 
-static int iscsi_scsi_cmd_execute(struct iscsi_task *task)
+int iscsi_scsi_cmd_execute(struct iscsi_task *task)
 {
 	struct iscsi_connection *conn = task->conn;
 	struct iscsi_cmd *req = (struct iscsi_cmd *) &task->req;
@@ -1750,7 +1750,7 @@ static int do_recv(int fd, struct iscsi_connection *conn, int next_state)
 	return ret;
 }
 
-static void iscsi_rx_handler(int fd, struct iscsi_connection *conn)
+void iscsi_rx_handler(int fd, struct iscsi_connection *conn)
 {
 	int ret = 0, hdigest, ddigest;
 	uint32_t crc;
@@ -1917,7 +1917,7 @@ again:
 	return 0;
 }
 
-static void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
+void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
 {
 	int ret = 0, hdigest, ddigest;
 	uint32_t crc;
@@ -2047,25 +2047,6 @@ static void iscsi_tx_handler(int fd, struct iscsi_connection *conn)
 	}
 }
 
-void iscsi_event_handler(int fd, int events, void *data)
-{
-	struct iscsi_connection *conn = (struct iscsi_connection *) data;
-
-	if (events & EPOLLIN)
-		iscsi_rx_handler(fd, conn);
-
-	if (conn->state == STATE_CLOSE)
-		dprintf("connection closed\n");
-
-	if (conn->state != STATE_CLOSE && events & EPOLLOUT)
-		iscsi_tx_handler(fd, conn);
-
-	if (conn->state == STATE_CLOSE) {
-		conn_close(conn, fd);
-		dprintf("connection closed\n");
-	}
-}
-
 struct tgt_driver iscsi = {
 	.name			= "iscsi",
 	.use_kernel		= 0,
diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h
index 42b1b5c..d6bc0a9 100644
--- a/usr/iscsi/iscsid.h
+++ b/usr/iscsi/iscsid.h
@@ -260,10 +260,12 @@ extern int conn_take_fd(struct iscsi_connection *conn, int fd);
 extern void conn_add_to_session(struct iscsi_connection *conn, struct iscsi_session *session);
 
 /* iscsid.c */
-extern void iscsi_event_handler(int fd, int events, void *data);
 extern char *text_key_find(struct iscsi_connection *conn, char *searchKey);
 extern void text_key_add(struct iscsi_connection *conn, char *key, char *value);
 extern void conn_read_pdu(struct iscsi_connection *conn);
+extern void iscsi_tx_handler(int fd, struct iscsi_connection *conn);
+extern void iscsi_rx_handler(int fd, struct iscsi_connection *conn);
+extern int iscsi_scsi_cmd_execute(struct iscsi_task *task);
 
 /* iscsid.c iscsi_task */
 extern void iscsi_free_task(struct iscsi_task *task);
-- 
1.5.2.5




More information about the stgt mailing list