[stgt] tgtd exits in iscsi_tx_handler during heavy I/Os

FUJITA Tomonori fujita.tomonori at lab.ntt.co.jp
Fri May 20 05:24:02 CEST 2011


On Fri, 20 May 2011 00:01:28 +0800
Kiefer Chang <zapchang at gmail.com> wrote:

> I've applied the patch and reproduce the symptom.
> The tgtd stop responding after doing some heavy I/Os. Maybe the
> new-added while loop can never exit?
> (I/O fail and tgt-admin -s command blocks)

Sorry about that. As you said, the patch is broken. Please try the patch that
I've attached. It still disable TMF but tgtd should continue to work after a
connection is closed.


> During fighting this issue we found the code to handle task management
> request seems pass the wrong tag.
> The referenced task tag (RTT) should be used instead of the initiator
> task tag (ITT). This causes the handler try to find the TMF itself.
> Please have a look at this:

Yeah, thanks for spotting this bug! Can you resend the patch with your
Signed-off-by?

Thanks!

diff --git a/usr/bs.c b/usr/bs.c
index d72d090..8f56aee 100644
--- a/usr/bs.c
+++ b/usr/bs.c
@@ -122,7 +122,7 @@ out:
 	pthread_exit(NULL);
 }
 
-static void bs_thread_request_done(int fd, int events, void *data)
+void bs_thread_request_done(int fd, int events, void *data)
 {
 	struct scsi_cmd *cmd;
 	int nr_events, ret;
@@ -230,6 +230,8 @@ static int bs_init_signalfd(void)
 	sigset_t mask;
 	int ret;
 
+	return 1;
+
 	pthread_mutex_init(&finished_lock, NULL);
 
 	sigemptyset(&mask);
@@ -270,6 +272,7 @@ static int bs_init_notify_thread(void)
 		goto close_command_fd;
 	}
 
+	set_non_blocking(done_fd[0]);
 	ret = tgt_event_add(done_fd[0], EPOLLIN, bs_thread_request_done, NULL);
 	if (ret) {
 		eprintf("failed to add epoll event\n");
diff --git a/usr/bs_thread.h b/usr/bs_thread.h
index d460032..14456a7 100644
--- a/usr/bs_thread.h
+++ b/usr/bs_thread.h
@@ -29,3 +29,4 @@ extern int bs_thread_open(struct bs_thread_info *info, request_func_t *rfn,
 extern void bs_thread_close(struct bs_thread_info *info);
 extern int bs_thread_cmd_submit(struct scsi_cmd *cmd);
 
+extern void bs_wait_one_completion(void);
diff --git a/usr/iscsi/conn.c b/usr/iscsi/conn.c
index 53e719e..928a8a1 100644
--- a/usr/iscsi/conn.c
+++ b/usr/iscsi/conn.c
@@ -115,14 +115,14 @@ void conn_close(struct iscsi_connection *conn)
 		if (task->conn != conn)
 			continue;
 
-		eprintf("Forcing release of pending task %p %" PRIx64 "\n",
-			task, task->tag);
+		eprintf("Forcing release of pending task %p %" PRIx64 " %u\n",
+			task, task->tag, conn->refcount);
 		list_del(&task->c_list);
 		iscsi_free_task(task);
 	}
 
 	if (conn->tx_task) {
-		dprintf("Add current tx task to the tx list for removal "
+		eprintf("Add current tx task to the tx list for removal "
 			"%p %" PRIx64 "\n",
 			conn->tx_task, conn->tx_task->tag);
 		list_add(&conn->tx_task->c_list, &conn->tx_clist);
@@ -134,8 +134,8 @@ void conn_close(struct iscsi_connection *conn)
 
 		op = task->req.opcode & ISCSI_OPCODE_MASK;
 
-		eprintf("Forcing release of tx task %p %" PRIx64 " %x\n",
-			task, task->tag, op);
+		eprintf("Forcing release of tx task %p %" PRIx64 " %x %u\n",
+			task, task->tag, op, conn->refcount);
 		switch (op) {
 		case ISCSI_OP_SCSI_CMD:
 			/*
@@ -155,14 +155,14 @@ void conn_close(struct iscsi_connection *conn)
 			iscsi_free_task(task);
 			break;
 		default:
-			eprintf("%x\n", op);
+			eprintf("unknow op %x\n", op);
 			break;
 		}
 	}
 
 	if (conn->rx_task) {
-		eprintf("Forcing release of rx task %p %" PRIx64 "\n",
-			conn->rx_task, conn->rx_task->tag);
+		eprintf("Forcing release of rx task %p %" PRIx64 " %u\n",
+			conn->rx_task, conn->rx_task->tag, conn->refcount);
 		iscsi_free_task(conn->rx_task);
 	}
 	conn->rx_task = NULL;
@@ -173,10 +173,24 @@ void conn_close(struct iscsi_connection *conn)
 		 * This task is in SCSI. We need to wait for I/O
 		 * completion.
 		 */
+		eprintf("release task %p %" PRIx64 " flag %lx, %u\n",
+			task, task->tag, task->flags, conn->refcount);
+
 		if (task_in_scsi(task))
 			continue;
 		iscsi_free_task(task);
 	}
+
+	eprintf("%p %u\n", conn, conn->refcount);
+
+	while (conn->refcount != 1) {
+		struct timeval t;
+		t.tv_sec = 1;
+		t.tv_usec = 0;
+		eprintf("%p %u\n", conn, conn->refcount);
+		bs_thread_request_done(0, 0, NULL);
+		select(0, NULL, NULL, NULL, &t);
+	}
 done:
 	conn_put(conn);
 }
diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c
index e87bbf1..977249c 100644
--- a/usr/iscsi/iscsi_tcp.c
+++ b/usr/iscsi/iscsi_tcp.c
@@ -164,7 +164,7 @@ static void iscsi_tcp_event_handler(int fd, int events, void *data)
 		iscsi_tx_handler(conn);
 
 	if (conn->state == STATE_CLOSE) {
-		dprintf("connection closed %p\n", conn);
+		eprintf("connection closed %p\n", conn);
 		conn_close(conn);
 	}
 }
@@ -306,7 +306,7 @@ static int iscsi_tcp_init(void)
 	   for ipv4 and ipv6
 	*/
 	if (list_empty(&iscsi_portals_list)) {
-		iscsi_add_portal("0::0", 0, 1, 0);
+		/* iscsi_add_portal("0::0", 0, 1, 0); */
 		iscsi_add_portal("0.0.0.0", 0, 1, 0);
 	}
 
diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 7666381..9528880 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1207,6 +1207,8 @@ static int iscsi_scsi_cmd_done(uint64_t nid, int result, struct scsi_cmd *scmd)
 	 * task got reassinged to another connection.
 	 */
 	if (task->conn->state == STATE_CLOSE) {
+		eprintf("finish a task on a closed conn, %p %u\n",
+			task, task->conn->refcount);
 		iscsi_free_cmd_task(task);
 		return 0;
 	}
@@ -1396,6 +1398,8 @@ static int iscsi_tm_execute(struct iscsi_task *task)
 	struct iscsi_tm *req = (struct iscsi_tm *) &task->req;
 	int fn = 0, err = 0;
 
+	eprintf("%x\n", req->flags & ISCSI_FLAG_TM_FUNC_MASK);
+
 	switch (req->flags & ISCSI_FLAG_TM_FUNC_MASK) {
 	case ISCSI_TM_FUNC_ABORT_TASK:
 		fn = ABORT_TASK;
@@ -1424,6 +1428,8 @@ static int iscsi_tm_execute(struct iscsi_task *task)
 			req->flags & ISCSI_FLAG_TM_FUNC_MASK);
 	}
 
+	err = ISCSI_TMF_RSP_NOT_SUPPORTED;
+
 	if (err)
 		task->result = err;
 	else {
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list