Commit cd063bef authored by Nicholas Bellinger's avatar Nicholas Bellinger

target/sbc: Seperate WRITE_SAME based on UNMAP flag in sbc_ops

This patch adds a new sbc_ops->execute_write_same_unmap() caller for use
with WRITE_SAME w/ UNMAP=1, and performs the ->execute_cmd() setup based
this bit within sbc_setup_write_same() code.

Also, makes the changes in sbc_parse_cdb() to handle a sense_reason_t
return from sbc_setup_write_same() on error.
Reported-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 1920ed61
...@@ -235,26 +235,30 @@ static inline unsigned long long transport_lba_64_ext(unsigned char *cdb) ...@@ -235,26 +235,30 @@ static inline unsigned long long transport_lba_64_ext(unsigned char *cdb)
return ((unsigned long long)__v2) | (unsigned long long)__v1 << 32; return ((unsigned long long)__v2) | (unsigned long long)__v1 << 32;
} }
static int sbc_write_same_supported(struct se_device *dev, static sense_reason_t
unsigned char *flags) sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *ops)
{ {
if ((flags[0] & 0x04) || (flags[0] & 0x02)) { if ((flags[0] & 0x04) || (flags[0] & 0x02)) {
pr_err("WRITE_SAME PBDATA and LBDATA" pr_err("WRITE_SAME PBDATA and LBDATA"
" bits not supported for Block Discard" " bits not supported for Block Discard"
" Emulation\n"); " Emulation\n");
return -ENOSYS; return TCM_UNSUPPORTED_SCSI_OPCODE;
} }
/* /*
* Currently for the emulated case we only accept * Special case for WRITE_SAME w/ UNMAP=1 that ends up getting
* tpws with the UNMAP=1 bit set. * translated into block discard requests within backend code.
*/ */
if (!(flags[0] & 0x08)) { if (flags[0] & 0x08) {
pr_err("WRITE_SAME w/o UNMAP bit not" if (!ops->execute_write_same_unmap)
" supported for Block Discard Emulation\n"); return TCM_UNSUPPORTED_SCSI_OPCODE;
return -ENOSYS;
cmd->execute_cmd = ops->execute_write_same_unmap;
return 0;
} }
if (!ops->execute_write_same)
return TCM_UNSUPPORTED_SCSI_OPCODE;
cmd->execute_cmd = ops->execute_write_same;
return 0; return 0;
} }
...@@ -418,9 +422,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) ...@@ -418,9 +422,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
cmd->se_cmd_flags |= SCF_FUA; cmd->se_cmd_flags |= SCF_FUA;
break; break;
case WRITE_SAME_32: case WRITE_SAME_32:
if (!ops->execute_write_same)
return TCM_UNSUPPORTED_SCSI_OPCODE;
sectors = transport_get_sectors_32(cdb); sectors = transport_get_sectors_32(cdb);
if (!sectors) { if (!sectors) {
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not" pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not"
...@@ -431,9 +432,9 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) ...@@ -431,9 +432,9 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
size = sbc_get_size(cmd, 1); size = sbc_get_size(cmd, 1);
cmd->t_task_lba = get_unaligned_be64(&cdb[12]); cmd->t_task_lba = get_unaligned_be64(&cdb[12]);
if (sbc_write_same_supported(dev, &cdb[10]) < 0) ret = sbc_setup_write_same(cmd, &cdb[10], ops);
return TCM_UNSUPPORTED_SCSI_OPCODE; if (ret < 0)
cmd->execute_cmd = ops->execute_write_same; return ret;
break; break;
default: default:
pr_err("VARIABLE_LENGTH_CMD service action" pr_err("VARIABLE_LENGTH_CMD service action"
...@@ -495,9 +496,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) ...@@ -495,9 +496,6 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
cmd->execute_cmd = ops->execute_unmap; cmd->execute_cmd = ops->execute_unmap;
break; break;
case WRITE_SAME_16: case WRITE_SAME_16:
if (!ops->execute_write_same)
return TCM_UNSUPPORTED_SCSI_OPCODE;
sectors = transport_get_sectors_16(cdb); sectors = transport_get_sectors_16(cdb);
if (!sectors) { if (!sectors) {
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n"); pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
...@@ -507,14 +505,11 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) ...@@ -507,14 +505,11 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
size = sbc_get_size(cmd, 1); size = sbc_get_size(cmd, 1);
cmd->t_task_lba = get_unaligned_be64(&cdb[2]); cmd->t_task_lba = get_unaligned_be64(&cdb[2]);
if (sbc_write_same_supported(dev, &cdb[1]) < 0) ret = sbc_setup_write_same(cmd, &cdb[1], ops);
return TCM_UNSUPPORTED_SCSI_OPCODE; if (ret < 0)
cmd->execute_cmd = ops->execute_write_same; return ret;
break; break;
case WRITE_SAME: case WRITE_SAME:
if (!ops->execute_write_same)
return TCM_UNSUPPORTED_SCSI_OPCODE;
sectors = transport_get_sectors_10(cdb); sectors = transport_get_sectors_10(cdb);
if (!sectors) { if (!sectors) {
pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n"); pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
...@@ -528,9 +523,9 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops) ...@@ -528,9 +523,9 @@ sbc_parse_cdb(struct se_cmd *cmd, struct sbc_ops *ops)
* Follow sbcr26 with WRITE_SAME (10) and check for the existence * Follow sbcr26 with WRITE_SAME (10) and check for the existence
* of byte 1 bit 3 UNMAP instead of original reserved field * of byte 1 bit 3 UNMAP instead of original reserved field
*/ */
if (sbc_write_same_supported(dev, &cdb[1]) < 0) ret = sbc_setup_write_same(cmd, &cdb[1], ops);
return TCM_UNSUPPORTED_SCSI_OPCODE; if (ret < 0)
cmd->execute_cmd = ops->execute_write_same; return ret;
break; break;
case VERIFY: case VERIFY:
size = 0; size = 0;
......
...@@ -41,6 +41,7 @@ struct sbc_ops { ...@@ -41,6 +41,7 @@ struct sbc_ops {
sense_reason_t (*execute_rw)(struct se_cmd *cmd); sense_reason_t (*execute_rw)(struct se_cmd *cmd);
sense_reason_t (*execute_sync_cache)(struct se_cmd *cmd); sense_reason_t (*execute_sync_cache)(struct se_cmd *cmd);
sense_reason_t (*execute_write_same)(struct se_cmd *cmd); sense_reason_t (*execute_write_same)(struct se_cmd *cmd);
sense_reason_t (*execute_write_same_unmap)(struct se_cmd *cmd);
sense_reason_t (*execute_unmap)(struct se_cmd *cmd); sense_reason_t (*execute_unmap)(struct se_cmd *cmd);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment