[RHEL7,COMMIT] ms/target: reject COMPARE_AND_WRITE if emulate_caw is not set

Submitted by Konstantin Khorenko on April 2, 2018, 2:28 p.m.

Details

Message ID 201804021428.w32ESKRx023722@finist_ce7.work
State New
Series "target: backport bug fixes from the upstream kernel"
Headers show

Commit Message

Konstantin Khorenko April 2, 2018, 2:28 p.m.
The commit is pushed to "branch-rh7-3.10.0-693.21.1.vz7.46.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-693.21.1.vz7.46.2
------>
commit a5eccba2193d16ddfce4b110fd31300b6dae22b4
Author: Jiang Yi <jiangyilism@gmail.com>
Date:   Mon Apr 2 17:28:19 2018 +0300

    ms/target: reject COMPARE_AND_WRITE if emulate_caw is not set
    
    ML: 12f66e4a0f7b5624901ba4301210e026c9ddf78d
    
    In struct se_dev_attrib, there is a field emulate_caw exposed
    as a /sys/kernel/config/target/core/$HBA/$DEV/attrib/.
    
    If this field is set zero, it means the corresponding struct se_device
    does not support the scsi cmd COMPARE_AND_WRITE
    
    In function sbc_parse_cdb(), go ahead and reject scsi COMPARE_AND_WRITE
    if emulate_caw is not set, because it has been explicitly disabled
    from user-space.
    
    (Make pr_err ratelimited - nab)
    
    Signed-off-by: Jiang Yi <jiangyilism@gmail.com>
    Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
    Signed-off-by: Andrei Vagin <avagin@openvz.org>
---
 drivers/target/target_core_sbc.c | 6 ++++++
 1 file changed, 6 insertions(+)

Patch hide | download patch | download mbox

diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index 8a799a8860b7..17889bd68a78 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -913,6 +913,12 @@  sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
 		break;
 	}
 	case COMPARE_AND_WRITE:
+		if (!dev->dev_attrib.emulate_caw) {
+			pr_err_ratelimited("se_device %s/%s (vpd_unit_serial %s) reject"
+				" COMPARE_AND_WRITE\n", dev->transport->name,
+				dev->dev_group.cg_item.ci_name, dev->t10_wwn.unit_serial);
+			return TCM_UNSUPPORTED_SCSI_OPCODE;
+		}
 		sectors = cdb[13];
 		/*
 		 * Currently enforce COMPARE_AND_WRITE for a single sector