Skip to content

Commit 1bf630f

Browse files
ddissmartinkpetersen
authored andcommitted
scsi: target: use an enum to track emulate_ua_intlck_ctrl
The emulate_ua_intlck_ctrl device attribute accepts values of 0, 1 or 2 via ConfigFS, which map to unit attention interlocks control codes in the MODE SENSE control Mode Page. Use an enum to track these values so that it's clear that, unlike the remaining emulate_X attributes, emulate_ua_intlck_ctrl isn't boolean. Link: https://marc.info/?l=target-devel&m=158227825428798 Suggested-by: Bart Van Assche <bvanassche@acm.org> Signed-off-by: David Disseldorp <ddiss@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 87310c9 commit 1bf630f

6 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎drivers/target/target_core_configfs.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,9 @@ static ssize_t emulate_ua_intlck_ctrl_store(struct config_item *item,
684684
if (ret < 0)
685685
return ret;
686686

687-
if (val != 0 && val != 1 && val != 2) {
687+
if (val != TARGET_UA_INTLCK_CTRL_CLEAR
688+
&& val != TARGET_UA_INTLCK_CTRL_NO_CLEAR
689+
&& val != TARGET_UA_INTLCK_CTRL_ESTABLISH_UA) {
688690
pr_err("Illegal value %d\n", val);
689691
return -EINVAL;
690692
}

‎drivers/target/target_core_device.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
767767
dev->dev_attrib.emulate_fua_write = 1;
768768
dev->dev_attrib.emulate_fua_read = 1;
769769
dev->dev_attrib.emulate_write_cache = DA_EMULATE_WRITE_CACHE;
770-
dev->dev_attrib.emulate_ua_intlck_ctrl = DA_EMULATE_UA_INTLLCK_CTRL;
770+
dev->dev_attrib.emulate_ua_intlck_ctrl = TARGET_UA_INTLCK_CTRL_CLEAR;
771771
dev->dev_attrib.emulate_tas = DA_EMULATE_TAS;
772772
dev->dev_attrib.emulate_tpu = DA_EMULATE_TPU;
773773
dev->dev_attrib.emulate_tpws = DA_EMULATE_TPWS;

‎drivers/target/target_core_spc.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,17 @@ static int spc_modesense_control(struct se_cmd *cmd, u8 pc, u8 *p)
847847
* for a BUSY, TASK SET FULL, or RESERVATION CONFLICT status regardless
848848
* to the number of commands completed with one of those status codes.
849849
*/
850-
p[4] = (dev->dev_attrib.emulate_ua_intlck_ctrl == 2) ? 0x30 :
851-
(dev->dev_attrib.emulate_ua_intlck_ctrl == 1) ? 0x20 : 0x00;
850+
switch (dev->dev_attrib.emulate_ua_intlck_ctrl) {
851+
case TARGET_UA_INTLCK_CTRL_ESTABLISH_UA:
852+
p[4] = 0x30;
853+
break;
854+
case TARGET_UA_INTLCK_CTRL_NO_CLEAR:
855+
p[4] = 0x20;
856+
break;
857+
default: /* TARGET_UA_INTLCK_CTRL_CLEAR */
858+
p[4] = 0x00;
859+
break;
860+
}
852861
/*
853862
* From spc4r17, section 7.4.6 Control mode Page
854863
*

‎drivers/target/target_core_transport.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1879,7 +1879,8 @@ void transport_generic_request_failure(struct se_cmd *cmd,
18791879
* See spc4r17, section 7.4.6 Control Mode Page, Table 349
18801880
*/
18811881
if (cmd->se_sess &&
1882-
cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl == 2) {
1882+
cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl
1883+
== TARGET_UA_INTLCK_CTRL_ESTABLISH_UA) {
18831884
target_ua_allocate_lun(cmd->se_sess->se_node_acl,
18841885
cmd->orig_fe_lun, 0x2C,
18851886
ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS);

‎drivers/target/target_core_ua.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ bool core_scsi3_ua_for_check_condition(struct se_cmd *cmd, u8 *key, u8 *asc,
199199
struct se_node_acl *nacl;
200200
struct se_ua *ua = NULL, *ua_p;
201201
int head = 1;
202+
bool dev_ua_intlck_clear = (dev->dev_attrib.emulate_ua_intlck_ctrl
203+
== TARGET_UA_INTLCK_CTRL_CLEAR);
202204

203205
if (WARN_ON_ONCE(!sess))
204206
return false;
@@ -229,7 +231,7 @@ bool core_scsi3_ua_for_check_condition(struct se_cmd *cmd, u8 *key, u8 *asc,
229231
* highest priority UNIT_ATTENTION and ASC/ASCQ without
230232
* clearing it.
231233
*/
232-
if (dev->dev_attrib.emulate_ua_intlck_ctrl != 0) {
234+
if (!dev_ua_intlck_clear) {
233235
*asc = ua->ua_asc;
234236
*ascq = ua->ua_ascq;
235237
break;
@@ -254,8 +256,8 @@ bool core_scsi3_ua_for_check_condition(struct se_cmd *cmd, u8 *key, u8 *asc,
254256
" INTLCK_CTRL: %d, mapped LUN: %llu, got CDB: 0x%02x"
255257
" reported ASC: 0x%02x, ASCQ: 0x%02x\n",
256258
nacl->se_tpg->se_tpg_tfo->fabric_name,
257-
(dev->dev_attrib.emulate_ua_intlck_ctrl != 0) ? "Reporting" :
258-
"Releasing", dev->dev_attrib.emulate_ua_intlck_ctrl,
259+
dev_ua_intlck_clear ? "Releasing" : "Reporting",
260+
dev->dev_attrib.emulate_ua_intlck_ctrl,
259261
cmd->orig_fe_lun, cmd->t_task_cdb[0], *asc, *ascq);
260262

261263
return head == 0;

‎include/target/target_core_base.h‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@
7474
#define DA_EMULATE_MODEL_ALIAS 0
7575
/* Emulation for WriteCache and SYNCHRONIZE_CACHE */
7676
#define DA_EMULATE_WRITE_CACHE 0
77-
/* Emulation for UNIT ATTENTION Interlock Control */
78-
#define DA_EMULATE_UA_INTLLCK_CTRL 0
7977
/* Emulation for TASK_ABORTED status (TAS) by default */
8078
#define DA_EMULATE_TAS 1
8179
/* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */
@@ -433,6 +431,13 @@ enum target_prot_type {
433431
TARGET_DIF_TYPE3_PROT,
434432
};
435433

434+
/* Emulation for UNIT ATTENTION Interlock Control */
435+
enum target_ua_intlck_ctrl {
436+
TARGET_UA_INTLCK_CTRL_CLEAR = 0,
437+
TARGET_UA_INTLCK_CTRL_NO_CLEAR = 1,
438+
TARGET_UA_INTLCK_CTRL_ESTABLISH_UA = 2,
439+
};
440+
436441
enum target_core_dif_check {
437442
TARGET_DIF_CHECK_GUARD = 0x1 << 0,
438443
TARGET_DIF_CHECK_APPTAG = 0x1 << 1,
@@ -668,7 +673,7 @@ struct se_dev_attrib {
668673
bool emulate_fua_write;
669674
bool emulate_fua_read; /* deprecated */
670675
bool emulate_write_cache;
671-
int emulate_ua_intlck_ctrl;
676+
enum target_ua_intlck_ctrl emulate_ua_intlck_ctrl;
672677
bool emulate_tas;
673678
bool emulate_tpu;
674679
bool emulate_tpws;

0 commit comments

Comments
 (0)