Skip to content

Commit b527fd1

Browse files
Nicholas Bellingergregkh
authored andcommitted
target: Fix compatible reservation handling (CRH=1) with legacy RESERVE/RELEASE
commit 087a03b upstream. 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 eacac00 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> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 980b16e commit b527fd1

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

‎drivers/target/target_core_pr.c‎

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static struct t10_pr_registration *core_scsi3_locate_pr_reg(struct se_device *,
120120
struct se_node_acl *, struct se_session *);
121121
static void core_scsi3_put_pr_reg(struct t10_pr_registration *);
122122

123-
static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
123+
static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd)
124124
{
125125
struct se_session *se_sess = cmd->se_sess;
126126
struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
@@ -130,7 +130,7 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
130130
int conflict = 0;
131131

132132
if (!crh)
133-
return false;
133+
return -EINVAL;
134134

135135
pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
136136
se_sess);
@@ -158,16 +158,14 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
158158
*/
159159
if (pr_reg->pr_res_holder) {
160160
core_scsi3_put_pr_reg(pr_reg);
161-
*ret = 0;
162-
return false;
161+
return 1;
163162
}
164163
if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) ||
165164
(pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) ||
166165
(pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) ||
167166
(pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) {
168167
core_scsi3_put_pr_reg(pr_reg);
169-
*ret = 0;
170-
return true;
168+
return 1;
171169
}
172170
core_scsi3_put_pr_reg(pr_reg);
173171
conflict = 1;
@@ -192,10 +190,10 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
192190
" while active SPC-3 registrations exist,"
193191
" returning RESERVATION_CONFLICT\n");
194192
cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
195-
return true;
193+
return -EBUSY;
196194
}
197195

198-
return false;
196+
return 0;
199197
}
200198

201199
int target_scsi2_reservation_release(struct se_task *task)
@@ -204,12 +202,18 @@ int target_scsi2_reservation_release(struct se_task *task)
204202
struct se_device *dev = cmd->se_dev;
205203
struct se_session *sess = cmd->se_sess;
206204
struct se_portal_group *tpg = sess->se_tpg;
207-
int ret = 0;
205+
int ret = 0, rc;
208206

209207
if (!sess || !tpg)
210208
goto out;
211-
if (target_check_scsi2_reservation_conflict(cmd, &ret))
209+
rc = target_check_scsi2_reservation_conflict(cmd);
210+
if (rc == 1)
211+
goto out;
212+
else if (rc < 0) {
213+
cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
214+
ret = -EINVAL;
212215
goto out;
216+
}
213217

214218
ret = 0;
215219
spin_lock(&dev->dev_reservation_lock);
@@ -246,7 +250,7 @@ int target_scsi2_reservation_reserve(struct se_task *task)
246250
struct se_device *dev = cmd->se_dev;
247251
struct se_session *sess = cmd->se_sess;
248252
struct se_portal_group *tpg = sess->se_tpg;
249-
int ret = 0;
253+
int ret = 0, rc;
250254

251255
if ((cmd->t_task_cdb[1] & 0x01) &&
252256
(cmd->t_task_cdb[1] & 0x02)) {
@@ -262,8 +266,14 @@ int target_scsi2_reservation_reserve(struct se_task *task)
262266
*/
263267
if (!sess || !tpg)
264268
goto out;
265-
if (target_check_scsi2_reservation_conflict(cmd, &ret))
269+
rc = target_check_scsi2_reservation_conflict(cmd);
270+
if (rc == 1)
266271
goto out;
272+
else if (rc < 0) {
273+
cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
274+
ret = -EINVAL;
275+
goto out;
276+
}
267277

268278
ret = 0;
269279
spin_lock(&dev->dev_reservation_lock);

‎drivers/target/target_core_transport.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2507,6 +2507,7 @@ static int transport_generic_cmd_sequencer(
25072507
cmd, cdb, pr_reg_type) != 0) {
25082508
cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
25092509
cmd->se_cmd_flags |= SCF_SCSI_RESERVATION_CONFLICT;
2510+
cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT;
25102511
cmd->scsi_sense_reason = TCM_RESERVATION_CONFLICT;
25112512
return -EBUSY;
25122513
}

0 commit comments

Comments
 (0)