Commit 1bf630fd authored by David Disseldorp's avatar David Disseldorp Committed by Martin K. Petersen
Browse files

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: default avatarBart Van Assche <bvanassche@acm.org>
Signed-off-by: default avatarDavid Disseldorp <ddiss@suse.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 87310c9f
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -684,7 +684,9 @@ static ssize_t emulate_ua_intlck_ctrl_store(struct config_item *item,
	if (ret < 0)
		return ret;

	if (val != 0 && val != 1 && val != 2) {
	if (val != TARGET_UA_INTLCK_CTRL_CLEAR
	 && val != TARGET_UA_INTLCK_CTRL_NO_CLEAR
	 && val != TARGET_UA_INTLCK_CTRL_ESTABLISH_UA) {
		pr_err("Illegal value %d\n", val);
		return -EINVAL;
	}
+1 −1
Original line number Diff line number Diff line
@@ -767,7 +767,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
	dev->dev_attrib.emulate_fua_write = 1;
	dev->dev_attrib.emulate_fua_read = 1;
	dev->dev_attrib.emulate_write_cache = DA_EMULATE_WRITE_CACHE;
	dev->dev_attrib.emulate_ua_intlck_ctrl = DA_EMULATE_UA_INTLLCK_CTRL;
	dev->dev_attrib.emulate_ua_intlck_ctrl = TARGET_UA_INTLCK_CTRL_CLEAR;
	dev->dev_attrib.emulate_tas = DA_EMULATE_TAS;
	dev->dev_attrib.emulate_tpu = DA_EMULATE_TPU;
	dev->dev_attrib.emulate_tpws = DA_EMULATE_TPWS;
+11 −2
Original line number Diff line number Diff line
@@ -847,8 +847,17 @@ static int spc_modesense_control(struct se_cmd *cmd, u8 pc, u8 *p)
	 * for a BUSY, TASK SET FULL, or RESERVATION CONFLICT status regardless
	 * to the number of commands completed with one of those status codes.
	 */
	p[4] = (dev->dev_attrib.emulate_ua_intlck_ctrl == 2) ? 0x30 :
	       (dev->dev_attrib.emulate_ua_intlck_ctrl == 1) ? 0x20 : 0x00;
	switch (dev->dev_attrib.emulate_ua_intlck_ctrl) {
	case TARGET_UA_INTLCK_CTRL_ESTABLISH_UA:
		p[4] = 0x30;
		break;
	case TARGET_UA_INTLCK_CTRL_NO_CLEAR:
		p[4] = 0x20;
		break;
	default:	/* TARGET_UA_INTLCK_CTRL_CLEAR */
		p[4] = 0x00;
		break;
	}
	/*
	 * From spc4r17, section 7.4.6 Control mode Page
	 *
+2 −1
Original line number Diff line number Diff line
@@ -1879,7 +1879,8 @@ void transport_generic_request_failure(struct se_cmd *cmd,
		 * See spc4r17, section 7.4.6 Control Mode Page, Table 349
		 */
		if (cmd->se_sess &&
		    cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl == 2) {
		    cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl
					== TARGET_UA_INTLCK_CTRL_ESTABLISH_UA) {
			target_ua_allocate_lun(cmd->se_sess->se_node_acl,
					       cmd->orig_fe_lun, 0x2C,
					ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS);
+5 −3
Original line number Diff line number Diff line
@@ -199,6 +199,8 @@ bool core_scsi3_ua_for_check_condition(struct se_cmd *cmd, u8 *key, u8 *asc,
	struct se_node_acl *nacl;
	struct se_ua *ua = NULL, *ua_p;
	int head = 1;
	bool dev_ua_intlck_clear = (dev->dev_attrib.emulate_ua_intlck_ctrl
						== TARGET_UA_INTLCK_CTRL_CLEAR);

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

	return head == 0;
Loading