Add an array that deswcribes which opcodes are supported by the RDWR backend. Opcodes that are supported are flagged with 1, and opcodes that are not supported are flagged with 0. This allows backends to specify which opcodes it is prepared to process and which commands should fail with invalid op code This is most useful for block devices where we have several different backends and where some backends only support a subset of the commands. Signed-off-by: Ronnie Sahlberg <ronniesahlberg@xxxxxxxxx> --- usr/bs_rdwr.c | 20 ++++++++++++++++++++ usr/scsi.c | 6 ++++++ usr/tgtd.h | 1 + 3 files changed, 27 insertions(+), 0 deletions(-) diff --git a/usr/bs_rdwr.c b/usr/bs_rdwr.c index 47d2d99..b65fa6a 100644 --- a/usr/bs_rdwr.c +++ b/usr/bs_rdwr.c @@ -412,6 +412,25 @@ static void bs_rdwr_exit(struct scsi_lu *lu) bs_thread_close(info); } +static const char bs_ops_supported[256] = { +/* 0x00-0x0F */ 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, +/* 0x10-0x1F */ 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, +/* 0x20-0x2F */ 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, +/* 0x30-0x3F */ 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0x40-0x4F */ 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0x50-0x5F */ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, +/* 0x60-0x6F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0x70-0x7F */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0x80-0x8F */ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, +/* 0x90-0x9F */ 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, +/* 0xA0-0xAF */ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, +/* 0xB0-0xBF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0xC0-0xCF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0xD0-0xDF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0xE0-0xEF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +/* 0xF0-0xFF */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + static struct backingstore_template rdwr_bst = { .bs_name = "rdwr", .bs_datasize = sizeof(struct bs_thread_info), @@ -421,6 +440,7 @@ static struct backingstore_template rdwr_bst = { .bs_exit = bs_rdwr_exit, .bs_cmd_submit = bs_thread_cmd_submit, .bs_oflags_supported = O_SYNC | O_DIRECT, + .bs_ops_supported = bs_ops_supported, }; __attribute__((constructor)) static void bs_rdwr_constructor(void) diff --git a/usr/scsi.c b/usr/scsi.c index 2636a5c..991974d 100644 --- a/usr/scsi.c +++ b/usr/scsi.c @@ -492,6 +492,12 @@ int scsi_cmd_perform(int host_no, struct scsi_cmd *cmd) if (spc_access_check(cmd)) return SAM_STAT_RESERVATION_CONFLICT; + if (cmd->dev->bst->bs_ops_supported + && !cmd->dev->bst->bs_ops_supported[op]) { + sense_data_build(cmd, ILLEGAL_REQUEST, ASC_INVALID_OP_CODE); + return SAM_STAT_CHECK_CONDITION; + } + return cmd->dev->dev_type_template.ops[op].cmd_perform(host_no, cmd); } diff --git a/usr/tgtd.h b/usr/tgtd.h index 484e6e9..70f6306 100644 --- a/usr/tgtd.h +++ b/usr/tgtd.h @@ -165,6 +165,7 @@ struct backingstore_template { void (*bs_exit)(struct scsi_lu *dev); int (*bs_cmd_submit)(struct scsi_cmd *cmd); int bs_oflags_supported; + const char *bs_ops_supported; struct list_head backingstore_siblings; }; -- 1.7.3.1 -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html