From 7b4deef5d9a1fa74ccfbd07b4cfe795ee18fceca Mon Sep 17 00:00:00 2001 From: Nicholas Bellinger Date: Sun, 6 May 2012 12:59:45 -0700 Subject: [PATCH] target: Enforce hw_max_sectors for SCF_SCSI_DATA_SG_IO_CDB Instead of depending upon a max_sectors value that may be set via configfs based upon original HW queue limitations, go ahead and convert to using the hw_max_sectors reported by the backend device in order to determine when to reject an I/O's who's sector count exceeds what is supported by the backend with a single se_cmd descriptor. It addresses a potential case where se_dev_attrib.max_sectors for IBLOCK backends has already been set via queue_max_sectors() to something small like max_sectors=32 (LVM, DRBD may do this), resulting typically sized SCF_SCSI_DATA_SG_IO_CDB to be incorrectly rejected with invalid_cdb_field in transport_generic_cmd_sequencer(). Reviewed-by: Christoph Hellwig Cc: Roland Dreier Cc: Andy Grover Signed-off-by: Nicholas Bellinger --- drivers/target/target_core_transport.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 5c06b87..a10d784 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -2973,12 +2973,21 @@ static int transport_generic_cmd_sequencer( cmd->data_length = size; } - if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB && - (sectors > dev->se_sub_dev->se_dev_attrib.fabric_max_sectors || - sectors > dev->se_sub_dev->se_dev_attrib.max_sectors)) { - printk_ratelimited(KERN_ERR "SCSI OP %02xh with too big sectors %u\n", - cdb[0], sectors); - goto out_invalid_cdb_field; + if (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB) { + if (sectors > su_dev->se_dev_attrib.fabric_max_sectors) { + printk_ratelimited(KERN_ERR "SCSI OP %02xh with too" + " big sectors %u exceeds fabric_max_sectors:" + " %u\n", cdb[0], sectors, + su_dev->se_dev_attrib.fabric_max_sectors); + goto out_invalid_cdb_field; + } + if (sectors > su_dev->se_dev_attrib.hw_max_sectors) { + printk_ratelimited(KERN_ERR "SCSI OP %02xh with too" + " big sectors %u exceeds backend hw_max_sectors:" + " %u\n", cdb[0], sectors, + su_dev->se_dev_attrib.hw_max_sectors); + goto out_invalid_cdb_field; + } } /* reject any command that we don't have a handler for */ -- 2.7.4