aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target/target_core_pr.c
diff options
context:
space:
mode:
authorNicholas Bellinger <nab@linux-iscsi.org>2012-03-14 00:29:06 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-03-14 00:43:43 -0400
commit087a03b3ea1c8d6e2d5743a8d1c6d571058caa04 (patch)
tree52cb057d9c2f01f8772de66f1cce7086c9e8b7c5 /drivers/target/target_core_pr.c
parent67236c44741e250199ccd77f1115568e68cf8848 (diff)
target: Fix compatible reservation handling (CRH=1) with legacy RESERVE/RELEASE
This patch addresses a bug with target_check_scsi2_reservation_conflict() return checking in target_scsi2_reservation_[reserve,release]() that was preventing CRH=1 operation from silently succeeding in the two special cases defined by SPC-3, and not failing with reservation conflict status when dealing with legacy RESERVE/RELEASE + active SPC-3 PR logic. Also explictly set cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT during the early non reservation holder failure from pr_ops->t10_seq_non_holder() check in transport_generic_cmd_sequencer() for fabrics that already expect it to be set. This bug was originally introduced in mainline commit: commit eacac00ce5bfde8086cd0615fb53c986f7f970fe Author: Christoph Hellwig <hch@infradead.org> Date: Thu Nov 3 17:50:40 2011 -0400 target: split core_scsi2_emulate_crh Reported-by: Martin Svec <martin.svec@zoner.cz> Cc: Martin Svec <martin.svec@zoner.cz> Cc: Christoph Hellwig <hch@lst.de> Cc: stable@vger.kernel.org Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target/target_core_pr.c')
-rw-r--r--drivers/target/target_core_pr.c34
1 files changed, 22 insertions, 12 deletions
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index b7c779389eea..63e703bb6ac9 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -117,7 +117,7 @@ static struct t10_pr_registration *core_scsi3_locate_pr_reg(struct se_device *,
117 struct se_node_acl *, struct se_session *); 117 struct se_node_acl *, struct se_session *);
118static void core_scsi3_put_pr_reg(struct t10_pr_registration *); 118static void core_scsi3_put_pr_reg(struct t10_pr_registration *);
119 119
120static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret) 120static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd)
121{ 121{
122 struct se_session *se_sess = cmd->se_sess; 122 struct se_session *se_sess = cmd->se_sess;
123 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev; 123 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
@@ -127,7 +127,7 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
127 int conflict = 0; 127 int conflict = 0;
128 128
129 if (!crh) 129 if (!crh)
130 return false; 130 return -EINVAL;
131 131
132 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, 132 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
133 se_sess); 133 se_sess);
@@ -155,16 +155,14 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
155 */ 155 */
156 if (pr_reg->pr_res_holder) { 156 if (pr_reg->pr_res_holder) {
157 core_scsi3_put_pr_reg(pr_reg); 157 core_scsi3_put_pr_reg(pr_reg);
158 *ret = 0; 158 return 1;
159 return false;
160 } 159 }
161 if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) || 160 if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) ||
162 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) || 161 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) ||
163 (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || 162 (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) ||
164 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) { 163 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) {
165 core_scsi3_put_pr_reg(pr_reg); 164 core_scsi3_put_pr_reg(pr_reg);
166 *ret = 0; 165 return 1;
167 return true;
168 } 166 }
169 core_scsi3_put_pr_reg(pr_reg); 167 core_scsi3_put_pr_reg(pr_reg);
170 conflict = 1; 168 conflict = 1;
@@ -189,10 +187,10 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
189 " while active SPC-3 registrations exist," 187 " while active SPC-3 registrations exist,"
190 " returning RESERVATION_CONFLICT\n"); 188 " returning RESERVATION_CONFLICT\n");
191 cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT; 189 cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
192 return true; 190 return -EBUSY;
193 } 191 }
194 192
195 return false; 193 return 0;
196} 194}
197 195
198int target_scsi2_reservation_release(struct se_task *task) 196int target_scsi2_reservation_release(struct se_task *task)
@@ -201,12 +199,18 @@ int target_scsi2_reservation_release(struct se_task *task)
201 struct se_device *dev = cmd->se_dev; 199 struct se_device *dev = cmd->se_dev;
202 struct se_session *sess = cmd->se_sess; 200 struct se_session *sess = cmd->se_sess;
203 struct se_portal_group *tpg = sess->se_tpg; 201 struct se_portal_group *tpg = sess->se_tpg;
204 int ret = 0; 202 int ret = 0, rc;
205 203
206 if (!sess || !tpg) 204 if (!sess || !tpg)
207 goto out; 205 goto out;
208 if (target_check_scsi2_reservation_conflict(cmd, &ret)) 206 rc = target_check_scsi2_reservation_conflict(cmd);
207 if (rc == 1)
208 goto out;
209 else if (rc < 0) {
210 cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
211 ret = -EINVAL;
209 goto out; 212 goto out;
213 }
210 214
211 ret = 0; 215 ret = 0;
212 spin_lock(&dev->dev_reservation_lock); 216 spin_lock(&dev->dev_reservation_lock);
@@ -243,7 +247,7 @@ int target_scsi2_reservation_reserve(struct se_task *task)
243 struct se_device *dev = cmd->se_dev; 247 struct se_device *dev = cmd->se_dev;
244 struct se_session *sess = cmd->se_sess; 248 struct se_session *sess = cmd->se_sess;
245 struct se_portal_group *tpg = sess->se_tpg; 249 struct se_portal_group *tpg = sess->se_tpg;
246 int ret = 0; 250 int ret = 0, rc;
247 251
248 if ((cmd->t_task_cdb[1] & 0x01) && 252 if ((cmd->t_task_cdb[1] & 0x01) &&
249 (cmd->t_task_cdb[1] & 0x02)) { 253 (cmd->t_task_cdb[1] & 0x02)) {
@@ -259,8 +263,14 @@ int target_scsi2_reservation_reserve(struct se_task *task)
259 */ 263 */
260 if (!sess || !tpg) 264 if (!sess || !tpg)
261 goto out; 265 goto out;
262 if (target_check_scsi2_reservation_conflict(cmd, &ret)) 266 rc = target_check_scsi2_reservation_conflict(cmd);
267 if (rc == 1)
263 goto out; 268 goto out;
269 else if (rc < 0) {
270 cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
271 ret = -EINVAL;
272 goto out;
273 }
264 274
265 ret = 0; 275 ret = 0;
266 spin_lock(&dev->dev_reservation_lock); 276 spin_lock(&dev->dev_reservation_lock);