Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

David Disseldorp and committed by
Martin K. Petersen
1bf630fd 87310c9f

+30 -11
+3 -1
drivers/target/target_core_configfs.c
··· 684 684 if (ret < 0) 685 685 return ret; 686 686 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) { 688 690 pr_err("Illegal value %d\n", val); 689 691 return -EINVAL; 690 692 }
+1 -1
drivers/target/target_core_device.c
··· 767 767 dev->dev_attrib.emulate_fua_write = 1; 768 768 dev->dev_attrib.emulate_fua_read = 1; 769 769 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; 771 771 dev->dev_attrib.emulate_tas = DA_EMULATE_TAS; 772 772 dev->dev_attrib.emulate_tpu = DA_EMULATE_TPU; 773 773 dev->dev_attrib.emulate_tpws = DA_EMULATE_TPWS;
+11 -2
drivers/target/target_core_spc.c
··· 847 847 * for a BUSY, TASK SET FULL, or RESERVATION CONFLICT status regardless 848 848 * to the number of commands completed with one of those status codes. 849 849 */ 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 + } 852 861 /* 853 862 * From spc4r17, section 7.4.6 Control mode Page 854 863 *
+2 -1
drivers/target/target_core_transport.c
··· 1879 1879 * See spc4r17, section 7.4.6 Control Mode Page, Table 349 1880 1880 */ 1881 1881 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) { 1883 1884 target_ua_allocate_lun(cmd->se_sess->se_node_acl, 1884 1885 cmd->orig_fe_lun, 0x2C, 1885 1886 ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS);
+5 -3
drivers/target/target_core_ua.c
··· 199 199 struct se_node_acl *nacl; 200 200 struct se_ua *ua = NULL, *ua_p; 201 201 int head = 1; 202 + bool dev_ua_intlck_clear = (dev->dev_attrib.emulate_ua_intlck_ctrl 203 + == TARGET_UA_INTLCK_CTRL_CLEAR); 202 204 203 205 if (WARN_ON_ONCE(!sess)) 204 206 return false; ··· 231 229 * highest priority UNIT_ATTENTION and ASC/ASCQ without 232 230 * clearing it. 233 231 */ 234 - if (dev->dev_attrib.emulate_ua_intlck_ctrl != 0) { 232 + if (!dev_ua_intlck_clear) { 235 233 *asc = ua->ua_asc; 236 234 *ascq = ua->ua_ascq; 237 235 break; ··· 256 254 " INTLCK_CTRL: %d, mapped LUN: %llu, got CDB: 0x%02x" 257 255 " reported ASC: 0x%02x, ASCQ: 0x%02x\n", 258 256 nacl->se_tpg->se_tpg_tfo->fabric_name, 259 - (dev->dev_attrib.emulate_ua_intlck_ctrl != 0) ? "Reporting" : 260 - "Releasing", dev->dev_attrib.emulate_ua_intlck_ctrl, 257 + dev_ua_intlck_clear ? "Releasing" : "Reporting", 258 + dev->dev_attrib.emulate_ua_intlck_ctrl, 261 259 cmd->orig_fe_lun, cmd->t_task_cdb[0], *asc, *ascq); 262 260 263 261 return head == 0;
+8 -3
include/target/target_core_base.h
··· 74 74 #define DA_EMULATE_MODEL_ALIAS 0 75 75 /* Emulation for WriteCache and SYNCHRONIZE_CACHE */ 76 76 #define DA_EMULATE_WRITE_CACHE 0 77 - /* Emulation for UNIT ATTENTION Interlock Control */ 78 - #define DA_EMULATE_UA_INTLLCK_CTRL 0 79 77 /* Emulation for TASK_ABORTED status (TAS) by default */ 80 78 #define DA_EMULATE_TAS 1 81 79 /* Emulation for Thin Provisioning UNMAP using block/blk-lib.c:blkdev_issue_discard() */ ··· 431 433 TARGET_DIF_TYPE3_PROT, 432 434 }; 433 435 436 + /* Emulation for UNIT ATTENTION Interlock Control */ 437 + enum target_ua_intlck_ctrl { 438 + TARGET_UA_INTLCK_CTRL_CLEAR = 0, 439 + TARGET_UA_INTLCK_CTRL_NO_CLEAR = 1, 440 + TARGET_UA_INTLCK_CTRL_ESTABLISH_UA = 2, 441 + }; 442 + 434 443 enum target_core_dif_check { 435 444 TARGET_DIF_CHECK_GUARD = 0x1 << 0, 436 445 TARGET_DIF_CHECK_APPTAG = 0x1 << 1, ··· 673 668 bool emulate_fua_write; 674 669 bool emulate_fua_read; /* deprecated */ 675 670 bool emulate_write_cache; 676 - int emulate_ua_intlck_ctrl; 671 + enum target_ua_intlck_ctrl emulate_ua_intlck_ctrl; 677 672 bool emulate_tas; 678 673 bool emulate_tpu; 679 674 bool emulate_tpws;