From: Andy Grover <agrover@xxxxxxxxxx> According to sbc3r27, WRITE SAME with sectors=0 either writes to the end of the lun, or returns an error, depending on if WSNZ was set to 0 or 1 in the block limits VPD (0xB0). This patch sets that bit, and returns the error. Previously we used the block size, I don't know why, but it seems wrong. Signed-off-by: Andy Grover <agrover@xxxxxxxxxx> Signed-off-by: Nicholas Bellinger <nab@xxxxxxxxxxxxxxx> --- drivers/target/target_core_cdb.c | 3 +++ drivers/target/target_core_transport.c | 17 +++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c index 1867db7..d03eebc 100644 --- a/drivers/target/target_core_cdb.c +++ b/drivers/target/target_core_cdb.c @@ -491,6 +491,9 @@ target_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf) buf[0] = dev->transport->get_device_type(dev); buf[3] = have_tp ? 0x3c : 0x10; + /* Set WSNZ to 1 */ + buf[4] = 0x01; + /* * Set OPTIMAL TRANSFER LENGTH GRANULARITY */ diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 6a93a58..ef64052 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -3066,10 +3066,13 @@ static int transport_generic_cmd_sequencer( if (sector_ret) goto out_unsupported_cdb; - if (sectors != 0) + if (sectors) size = transport_get_size(sectors, cdb, cmd); - else - size = dev->se_sub_dev->se_dev_attrib.block_size; + else { + pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not" + " supported\n"); + goto out_invalid_cdb_field; + } cmd->t_task_lba = get_unaligned_be64(&cdb[12]); cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; @@ -3343,10 +3346,12 @@ static int transport_generic_cmd_sequencer( if (sector_ret) goto out_unsupported_cdb; - if (sectors != 0) + if (sectors) size = transport_get_size(sectors, cdb, cmd); - else - size = dev->se_sub_dev->se_dev_attrib.block_size; + else { + pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n"); + goto out_invalid_cdb_field; + } cmd->t_task_lba = get_unaligned_be16(&cdb[2]); passthrough = (dev->transport->transport_type == -- 1.7.6 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html