From: Robert Love <robert.w.love@intel.com>
To: linux-scsi@vger.kernel.org
Cc: Kiran Patil <kiran.patil@intel.com>
Subject: [PATCH v2 10/12] tcm_fc: Fixing reference counting problem which was causing ft_sess to be deleted.
Date: Mon, 20 Jun 2011 16:59:41 -0700 [thread overview]
Message-ID: <20110620235941.1777.89859.stgit@localhost6.localdomain6> (raw)
In-Reply-To: <20110620235848.1777.5168.stgit@localhost6.localdomain6>
From: Kiran Patil <kiran.patil@intel.com>
Problem: After fixing the issue in TCM core w.r.t LUN Reset (Task Management request)
, ran into issue where during the completing of this LUN Reset command, reference
count of "ft_sess" drops to zero which caused "sess" to be deleted.
Fix: As part of handling task management request (e.g. LUN Reset), TCM core function
"transport_generic_do_tmr" ends up calling ft_free_cmd which in turn calls "ft_sess_put"
(which drops session's reference count by 1) and then frees ft_cmd. Then function
"transport_generic_do_tmr" calls "transport_cmd_check_stop" which in turn also calls
ft_free_cmd (which calls ft_sess_put - which drops reference count of sess by 1, hence
reference count of sess becomes zero and session gets deleted). Fix is to just send
response in case of tmr from function "ft_queue_resp_code" and not delete "ft_cmd"
(means don't call ft_free_cmd). Earlier code was to send the response code and also
free ft_cmd. ft_free_cmd will be freed later after sending response code as a result of
"transport_cmd_check_stop" (which calls ft_release_cmd -> ft_free_cmd) being called
from "transport_generic_do_tmr" after sening TMR response code.
Notes/Dependencies: This bug was found after fixing NULL pointer access issue in TCM
core (in LUN Reset codepath)
Signed-off-by: Kiran Patil <kiran.patil@intel.com>
Signed-off-by: Robert Love <robert.w.love@intel.com>
---
drivers/target/tcm_fc/tfc_cmd.c | 21 ++++++++++++++++-----
1 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index cdbcb6c..2b60eee 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -380,12 +380,23 @@ static void ft_send_resp_status(struct fc_lport *lport,
/*
* Send error or task management response.
- * Always frees the cmd and associated state.
*/
-static void ft_send_resp_code(struct ft_cmd *cmd, enum fcp_resp_rsp_codes code)
+static void ft_send_resp_code(struct ft_cmd *cmd,
+ enum fcp_resp_rsp_codes code)
{
ft_send_resp_status(cmd->sess->tport->lport,
cmd->req_frame, SAM_STAT_GOOD, code);
+}
+
+
+/*
+ * Send error or task management response.
+ * Always frees the cmd and associated state.
+ */
+static void ft_send_resp_code_and_free(struct ft_cmd *cmd,
+ enum fcp_resp_rsp_codes code)
+{
+ ft_send_resp_code(cmd, code);
ft_free_cmd(cmd);
}
@@ -422,7 +433,7 @@ static void ft_send_tm(struct ft_cmd *cmd)
* tm_flags set is invalid.
*/
FT_TM_DBG("invalid FCP tm_flags %x\n", fcp->fc_tm_flags);
- ft_send_resp_code(cmd, FCP_CMND_FIELDS_INVALID);
+ ft_send_resp_code_and_free(cmd, FCP_CMND_FIELDS_INVALID);
return;
}
@@ -430,7 +441,7 @@ static void ft_send_tm(struct ft_cmd *cmd)
tmr = core_tmr_alloc_req(&cmd->se_cmd, cmd, tm_func);
if (!tmr) {
FT_TM_DBG("alloc failed\n");
- ft_send_resp_code(cmd, FCP_TMF_FAILED);
+ ft_send_resp_code_and_free(cmd, FCP_TMF_FAILED);
return;
}
cmd->se_cmd.se_tmr_req = tmr;
@@ -668,7 +679,7 @@ static void ft_send_cmd(struct ft_cmd *cmd)
return;
err:
- ft_send_resp_code(cmd, FCP_CMND_FIELDS_INVALID);
+ ft_send_resp_code_and_free(cmd, FCP_CMND_FIELDS_INVALID);
return;
}
next prev parent reply other threads:[~2011-06-20 23:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-20 23:58 [PATCH v2 00/12] libfc, libfcoe and fcoe updates for scsi-misc Robert Love
2011-06-20 23:58 ` [PATCH v2 01/12] tcm_fc: Fix warning in file tfc_io Robert Love
2011-06-20 23:58 ` [PATCH v2 02/12] libfc: Enhancement to RPORT state machine applicable only for VN2VN mode Robert Love
2011-06-20 23:59 ` [PATCH v2 03/12] libfc, tcm_fc: add ddp_targ() to libfc function template to supprot FCoE DDP in target mode Robert Love
2011-06-20 23:59 ` [PATCH v2 04/12] fcoe: support ndo_fcoe_ddp_target() for DDP in FCoE targe Robert Love
2011-06-20 23:59 ` [PATCH v2 05/12] fcoe: Unable to select the exchangeID from offload pool for storage targets Robert Love
2011-06-20 23:59 ` [PATCH v2 06/12] fcoe: Round-robin based selection of CPU for post-processing of incoming commands Robert Love
2011-06-20 23:59 ` [PATCH v2 07/12] fcoe: Amends previous patch, Round-robin based selection of CPU for post processing of incoming request for FCoE target Robert Love
2011-06-20 23:59 ` [PATCH v2 08/12] libfc:Fix for exchange/seq loopup failure when FCoE stack is used as target and connected to windows initaitor Robert Love
2011-06-20 23:59 ` [PATCH v2 09/12] tcm_fc: Fix ft_send_tm-bug and drop ft_get_lun_for_cmd usage Robert Love
2011-06-22 18:37 ` Nicholas A. Bellinger
2011-06-22 21:38 ` Kiran Patil
2011-06-22 23:30 ` [PATCH] " Kiran Patil
2011-06-23 2:47 ` Nicholas A. Bellinger
2011-06-20 23:59 ` Robert Love [this message]
2011-06-20 23:59 ` [PATCH v2 11/12] libfc: post reset event on lport reset Robert Love
2011-06-20 23:59 ` [PATCH v2 12/12] fcoe: Rearrange fcoe port and NPIV port cleanup Robert Love
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=20110620235941.1777.89859.stgit@localhost6.localdomain6 \
--to=robert.w.love@intel.com \
--cc=kiran.patil@intel.com \
--cc=linux-scsi@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