stgt.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
To: stgt@vger.kernel.org
Cc: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
Subject: [PATCH] iscsi: fix leak of task for delayed management request
Date: Tue, 18 Mar 2014 11:19:58 +0900	[thread overview]
Message-ID: <1395109198-15307-1-git-send-email-konishi.ryusuke@lab.ntt.co.jp> (raw)

Fix the following crash of tgtd which occured when removing a target
with --force option:

  conn_close(90) already closed 0x2058598 1
  iscsi_target_destroy(416) bug still have sessions 91

This crash happens if a task remains after the following calls of
conn_close() function for every connection on the target.

  list_for_each_entry_safe(session, stmp, &target->sessions_list, slist) {
          list_for_each_entry_safe(conn, ctmp, &session->conn_list, clist) {
                  conn_close(conn);
          }
  }

The leaked task turned out to be a task for handling ABORT_TASK
management request which was delayed due to a flying io.  The delayed
management request is attached to cmd->mreq of the io command and is
completed by iscsi_tm_done() function.  However, this function fails
with the following error and leaks the task if associated connection
(task->conn) is already closed:

 tgt_event_modify(245) Cannot find event 25
 iscsi_event_modify(560) tgt_event_modify failed

This fixes the issue by freeing task in iscsi_tm_done() if state of
the connection is STATE_CLOSE.

Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
---
 usr/iscsi/iscsid.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/usr/iscsi/iscsid.c b/usr/iscsi/iscsid.c
index 30bd13f..f0abe39 100644
--- a/usr/iscsi/iscsid.c
+++ b/usr/iscsi/iscsid.c
@@ -1428,6 +1428,11 @@ static int iscsi_tm_done(struct mgmt_req *mreq)
 		task->result = ISCSI_TMF_RSP_REJECTED;
 		break;
 	}
+
+	if (task->conn->state == STATE_CLOSE) {
+		iscsi_free_task(task);
+		return 0;
+	}
 	list_add_tail(&task->c_list, &task->conn->tx_clist);
 	task->conn->tp->ep_event_modify(task->conn, EPOLLIN | EPOLLOUT);
 	return 0;
-- 
1.7.9.3

             reply	other threads:[~2014-03-18  2:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-18  2:19 Ryusuke Konishi [this message]
2014-03-22 11:57 ` [PATCH] iscsi: fix leak of task for delayed management request FUJITA Tomonori

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1395109198-15307-1-git-send-email-konishi.ryusuke@lab.ntt.co.jp \
    --to=konishi.ryusuke@lab.ntt.co.jp \
    --cc=stgt@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).