tcm: Add support for CDBs greater than TCM_MAX_COMMAND_SIZE bytes
Subsystems (2)
PATCH 1/1 tcm: Add support for CDBs greater than TCM_MAX_COMMAND_SIZE bytes
From: Nicholas Bellinger <[email protected]>
Greetings all,
This patch allows TCM Core to process CDBs containing a received scsi_command_size() larger than the hardcoded default of TCM_MAX_COMMAND_SIZE (32-bytes). This patch first converts the hardcoded per struct se_cmd -> struct se_transport_task->t_task_cdb[] to ->__t_task_cdb[TCM_MAX_COMMAND_SIZE], and turns ->t_task_cdb into a pointer used to reference ->__t_task_cdb or an extended CDB buffer setup in transport_generic_allocate_tasks().
It next adds a new struct se_subsystem_api->get_max_cdb_len() API caller that is used by TCM subsystem plugins to report their individual CDB size limits. Next transport_generic_cmd_sequencer() has been changed to use ->get_max_cdb_len() for VARIABLE_LENGTH_CMD to determine if the backstore can support the received
Quoted 1 line
TCM_MAX_COMMAND_SIZEsized CDB, or to fail the I/O with exception status.
The extended CDB buffer is setup in transport_generic_allocate_tasks() when necessary, and a new SCF_ECDB_ALLOCATION flag is then set. The release of the extended CDB buffer happens in transport_free_se_cmd() in the normal struct se_cmd release path.
This patch also updates TCM/pSCSI to handle extended CDBs up to PSCSI_MAX_CDB_SIZE=240 (maximum current OSD CDB size) and sets up the extra struct pscsi_plugin_task->pscsi_cdb allocation in struct se_task context in order to complete the > TCM_MAX_COMMAND_SIZE=32 request. The IBLOCK, FILEIO, RAMDISK, and STGT subsystem plugins have been updated to enforce the TCM_MAX_COMMAND_SIZE=32 limit via struct se_subsystem_api->get_max_cdb_len().
So far this code been tested with 'sgv4_xdwriteread -e' into a TCM_Loop -> TCM/pSCSI -> scsi_debug backstore with a TCM_MAX_COMMAND_SIZE=16 to force the extended CDB allocations. This was done due to the lack of an easy method to test > 32-byte CDBs w/o an TCM/OSD fabric module.
Many thanks to Boaz Harrosh for his help in this area!
--- drivers/target/target_core_file.c | 6 +++++ drivers/target/target_core_iblock.c | 6 +++++ drivers/target/target_core_pscsi.c | 39 ++++++++++++++++++++++++++++++++ drivers/target/target_core_pscsi.h | 6 ++++- drivers/target/target_core_rd.c | 6 +++++ drivers/target/target_core_stgt.c | 6 +++++ drivers/target/target_core_transport.c | 34 +++++++++++++++++++++++---- include/target/target_core_base.h | 6 +++- include/target/target_core_transport.h | 5 ++++ 9 files changed, 106 insertions(+), 8 deletions(-)
drivers/target/target_core_file.c +6 -0
@@ -1125,6 +1125,11 @@ static unsigned char *fd_get_cdb(struct se_task *task)return req->fd_scsi_cdb; } +static u32 fd_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* fd_get_blocksize(): (Part of se_subsystem_api_t template) * *
@@ -1224,6 +1229,7 @@ static struct se_subsystem_api fileio_template = { .check_lba = fd_check_lba, .check_for_SG = fd_check_for_SG, .get_cdb = fd_get_cdb, + .get_max_cdb_len = fd_get_max_cdb_len, .get_blocksize = fd_get_blocksize, .get_device_rev = fd_get_device_rev, .get_device_type = fd_get_device_type,
drivers/target/target_core_iblock.c +6 -0
@@ -1059,6 +1059,11 @@ static unsigned char *iblock_get_cdb(struct se_task *task)return req->ib_scsi_cdb; } +static u32 iblock_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +static u32 iblock_get_blocksize (struct se_device *dev) {struct iblock_dev *ibd = dev->dev_ptr;
@@ -1167,6 +1172,7 @@ static struct se_subsystem_api iblock_template = { .check_lba = iblock_check_lba, .check_for_SG = iblock_check_for_SG, .get_cdb = iblock_get_cdb, + .get_max_cdb_len = iblock_get_max_cdb_len, .get_blocksize = iblock_get_blocksize, .get_device_rev = iblock_get_device_rev, .get_device_type = iblock_get_device_type,
drivers/target/target_core_pscsi.c +39 -0
@@ -714,13 +714,40 @@ static void *pscsi_allocate_request(struct se_task *task, struct se_device *dev) { + struct se_cmd *cmd = task->task_se_cmd;struct pscsi_plugin_task *pt; +unsigned char *cdb =T_TASK (cmd)->t_task_cdb; pt =kzalloc (sizeof (struct pscsi_plugin_task ),GFP_KERNEL );if (!(pt)) {printk (KERN_ERR "Unable to allocate struct pscsi_plugin_task\n" );return NULL ; } +/* +* If TCM Core is signaling a > TCM_MAX_COMMAND_SIZE allocation, +* allocate the extended CDB buffer for per struct se_task context +* pt->pscsi_cdb now. +*/ +if (cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) { +/* +* PSCSI_MAX_CDB_SIZE is currently set to 240 bytes which +* allows the largest OSD CDB sizes again. +*/ +if (scsi_command_size (cdb) >PSCSI_MAX_CDB_SIZE ) { +printk (KERN_ERR "pSCSI: Received CDB of size: %u larger" +" than PSCSI_MAX_CDB_SIZE: %u\n" , +scsi_command_size (cdb),PSCSI_MAX_CDB_SIZE ); +return NULL ; + } + + pt->pscsi_cdb =kzalloc (scsi_command_size (cdb),GFP_KERNEL ); +if (!(pt->pscsi_cdb)) { +printk (KERN_ERR "pSCSI: Unable to allocate extended" +" pt->pscsi_cdb\n" ); +return NULL ; + } + }else + pt->pscsi_cdb = &pt->__pscsi_cdb[0 ];return pt; }
@@ -818,6 +845,12 @@ static void pscsi_free_task(struct se_task *task) {struct pscsi_plugin_task *pt = task->transport_req;/* +* Release the extended CDB allocation from pscsi_allocate_request() +* if one exists. +*/ +if (task->task_se_cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) +kfree (pt->pscsi_cdb); +/* * We do not release the bio(s) here associated with this task, as * this is handled by bio_put() and pscsi_bi_endio(). */
@@ -1366,6 +1399,11 @@ static unsigned char *pscsi_get_cdb(struct se_task *task)return pt->pscsi_cdb; } +static u32 pscsi_get_max_cdb_len (struct se_device *dev) +{ +return PSCSI_MAX_CDB_SIZE ; +} +/* pscsi_get_sense_buffer(): * *
@@ -1533,6 +1571,7 @@ static struct se_subsystem_api pscsi_template = { .check_lba = pscsi_check_lba, .check_for_SG = pscsi_check_for_SG, .get_cdb = pscsi_get_cdb, + .get_max_cdb_len = pscsi_get_max_cdb_len, .get_sense_buffer = pscsi_get_sense_buffer, .get_blocksize = pscsi_get_blocksize, .get_device_rev = pscsi_get_device_rev,
drivers/target/target_core_pscsi.h +5 -1
@@ -9,6 +9,9 @@#define INQUIRY_DATA_SIZE 0x24#endif +/* Maximum extended CDB size for handling OSD passthrough */ +#define PSCSI_MAX_CDB_SIZE 240 +/* used in pscsi_add_device_to_list() */ #define PSCSI_DEFAULT_QUEUEDEPTH 1
@@ -28,7 +31,8 @@ extern int linux_blockdevice_check(int, int);#include <linux/kobject.h> struct pscsi_plugin_task { -unsigned char pscsi_cdb[TCM_MAX_COMMAND_SIZE ]; +unsigned char *pscsi_cdb; +unsigned char __pscsi_cdb[TCM_MAX_COMMAND_SIZE ];unsigned char pscsi_sense[SCSI_SENSE_BUFFERSIZE ];int pscsi_direction;int pscsi_result;
drivers/target/target_core_rd.c +6 -0
@@ -1392,6 +1392,11 @@ static unsigned char *rd_get_cdb(struct se_task *task)return req->rd_scsi_cdb; } +static u32 rd_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* rd_get_blocksize(): (Part of se_subsystem_api_t template) * *
@@ -1475,6 +1480,7 @@ static struct se_subsystem_api rd_dr_template = { .check_lba = rd_DIRECT_check_lba, .check_for_SG = rd_check_for_SG, .get_cdb = rd_get_cdb, + .get_max_cdb_len = rd_get_max_cdb_len, .get_blocksize = rd_get_blocksize, .get_device_rev = rd_get_device_rev, .get_device_type = rd_get_device_type,
drivers/target/target_core_stgt.c +6 -0
@@ -751,6 +751,11 @@ static unsigned char *stgt_get_cdb(struct se_task *task)return pt->stgt_cdb; } +static u32 stgt_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* stgt_get_sense_buffer(): * *
@@ -931,6 +936,7 @@ static struct se_subsystem_api stgt_template = { .check_lba = stgt_check_lba, .check_for_SG = stgt_check_for_SG, .get_cdb = stgt_get_cdb, + .get_max_cdb_len = stgt_get_max_cdb_len, .get_sense_buffer = stgt_get_sense_buffer, .get_blocksize = stgt_get_blocksize, .get_device_rev = stgt_get_device_rev,
drivers/target/target_core_transport.c +29 -5
@@ -2860,6 +2860,11 @@ void transport_free_se_cmd(if (se_cmd->se_tmr_req)core_tmr_release_req (se_cmd->se_tmr_req);/* +* Check and free any extended CDB buffer that was allocated +*/ +if (se_cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) +kfree (T_TASK (se_cmd)->t_task_cdb); +/* * Release any optional TCM fabric dependent iovecs allocated by * transport_allocate_iovecs_for_cmd() */
@@ -2903,6 +2908,23 @@ int transport_generic_allocate_tasks(if (non_data_cdb <0 )return -1 ;/* +* If the received CDB is larger than TCM_MAX_COMMAND_SIZE, +* allocate the additional extended CDB buffer now.. Otherwise +* setup the pointer from __t_task_cdb to t_task_cdb. +*/ +if (scsi_command_size (cdb) >TCM_MAX_COMMAND_SIZE ) { +T_TASK (cmd)->t_task_cdb =kzalloc (scsi_command_size (cdb), +GFP_KERNEL ); +if (!(T_TASK (cmd)->t_task_cdb)) { +printk (KERN_ERR "Unable to allocate T_TASK(cmd)->t_task_cdb" +" %u > TCM_MAX_COMMAND_SIZE ops\n" , +scsi_command_size (cdb)); +return -1 ; + } + cmd->se_cmd_flags |=SCF_ECDB_ALLOCATION ; + }else +T_TASK (cmd)->t_task_cdb = &T_TASK (cmd)->__t_task_cdb[0 ]; +/* * Copy the original CDB into T_TASK(cmd). */ memcpy (T_TASK (cmd)->t_task_cdb, cdb,scsi_command_size (cdb));
@@ -5746,13 +5768,15 @@ static int transport_generic_cmd_sequencer( service_action =get_unaligned_be16 (&cdb[8 ]);/* * Check the additional CDB length (+ 8 bytes for header) does -* not exceed our TCM_MAX_COMMAND_SIZE. +* not exceed our backsores ->get_max_cdb_len() */ -if (scsi_varlen_cdb_length (&cdb[0 ]) >TCM_MAX_COMMAND_SIZE ) { +if (scsi_varlen_cdb_length (&cdb[0 ]) > +TRANSPORT (dev)->get_max_cdb_len (dev)) {printk (KERN_INFO "Only %u-byte extended CDBs currently" -" supported for VARIABLE_LENGTH_CMD, received:" -" %d for service action: 0x%04x\n" , -TCM_MAX_COMMAND_SIZE , +" supported for VARIABLE_LENGTH_CMD backstore %s," +" received: %d for service action: 0x%04x\n" , +TRANSPORT (dev)->get_max_cdb_len (dev), +TRANSPORT (dev)->name,scsi_varlen_cdb_length (&cdb[0 ]), service_action);return TGCS_INVALID_CDB_FIELD ; }
include/target/target_core_base.h +4 -2
@@ -137,7 +137,8 @@ enum se_cmd_flags_table {SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC =0x00800000 ,SCF_EMULATE_SYNC_CACHE =0x01000000 ,SCF_EMULATE_CDB_ASYNC =0x02000000 , - SCF_EMULATE_SYNC_UNMAP = 0x04000000 +SCF_EMULATE_SYNC_UNMAP =0x04000000 , + SCF_ECDB_ALLOCATION = 0x08000000 };/* struct se_device->type for known subsystem plugins */
@@ -424,7 +425,8 @@ struct se_queue_obj {* drivers/target/target_core_transport.c:__transport_alloc_se_cmd() */ struct se_transport_task { -unsigned char t_task_cdb[MAX_COMMAND_SIZE ]; +unsigned char *t_task_cdb; +unsigned char __t_task_cdb[MAX_COMMAND_SIZE ];unsigned long long t_task_lba;int t_tasks_failed;int t_tasks_fua;
include/target/target_core_transport.h +5 -0
@@ -519,6 +519,11 @@ struct se_subsystem_api {*/ unsigned char *(*get_cdb)(struct se_task *);/* +* get_max_cdb_len(): Used by subsystems backstoers to signal the +* maximum receivable SCSI CDB size. +*/ +u32 (*get_max_cdb_len)(struct se_device *); +/* * get_blocksize(): */ u32 (*get_blocksize)(struct se_device *);
Signature · 1 line
1.5.6.5
Quoted 10 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
Greetings all,
This patch allows TCM Core to process CDBs containing a received
scsi_command_size()larger than the hardcoded default ofTCM_MAX_COMMAND_SIZE(32-bytes). This patch first converts the hardcoded per structse_cmd-> struct se_transport_task->t_task_cdb[] to ->__t_task_cdb[TCM_MAX_COMMAND_SIZE], and turns ->t_task_cdb into a pointer used to reference ->__t_task_cdb or an extended CDB buffer setup intransport_generic_allocate_tasks().
Quoted 5 lines
It next adds a new struct
se_subsystem_api->get_max_cdb_len()API caller that is used by TCM subsystem plugins to report their individual CDB size limits. Nexttransport_generic_cmd_sequencer()has been changed to use ->get_max_cdb_len() forVARIABLE_LENGTH_CMDto determine if the backstore can support the receivedQuoted 1 line
TCM_MAX_COMMAND_SIZEsized CDB, or to fail the I/O with exception status.
^^ ==> ->get_max_cdb_len()
Quoted 1 line
I'm commenting on the change log here. Comments on actual code is below.
First: there are bigger then ->get_max_cdb_len() which are not VARIABLE_LENGTH_CMD, and there are VARIABLE_LENGTH_CMD which are smaller then 16 bytes. So the VARIABLE_LENGTH_CMD has nothing to do with it. It's all a matter of scsi_command_size(cmnd);
Second: I don't like that ->get_max_cdb_len(), it means nothing. The fact that the size check passed, does not mean the actual SCSI-COMMAND is supported. So plugins should be ready to receive unsupported commands and properly return the correct error. If an FILEIO does not support OSD_ACT_CREATE it's because it's an OSD command and not because it is big. Maintaining the proper ->get_max_cdb_len() as code evolves is just a maintenance headache that buys you nothing!
Note that in pSCSI passthrough plugin the request will fail soon enough and the proper error handling should be in place, already.
Quoted 3 lines
The extended CDB buffer is setup in
transport_generic_allocate_tasks()when necessary, and a newSCF_ECDB_ALLOCATIONflag is then set. The release of the extended CDB buffer happens intransport_free_se_cmd()in the normal structse_cmdrelease path.
You have a magic size number which is sizeof(->__t_task_cdb) bigger then "that" alloc. Then also bigger then "that" free. No need for a flag.
But I'd even do more. if (->t_task_cdb != ->__t_task_cdb) free
Quoted 3 lines
This patch also updates TCM/pSCSI to handle extended CDBs up to PSCSI_MAX_CDB_SIZE=240 (maximum current OSD CDB size) and sets up the extra struct
pscsi_plugin_task->pscsi_cdb
No! the max CDB size is SCSI_MAX_VARLEN_CDB_SIZE (260) defined in scsi/scsi.h. Including the varlen_cdb 8 bytes header. This is do to the fact that the header has a single byte to denote payload size and must be 4 bytes aligned so 252 + 8 bytes header. See "struct scsi_varlen_cdb_hdr" in scsi.h
Quoted 85 lines
allocation in struct
se_taskcontext in order to complete the > TCM_MAX_COMMAND_SIZE=32 request. The IBLOCK, FILEIO, RAMDISK, and STGT subsystem plugins have been updated to enforce the TCM_MAX_COMMAND_SIZE=32 limit via structse_subsystem_api->get_max_cdb_len().So far this code been tested with '
sgv4_xdwriteread-e' into aTCM_Loop-> TCM/pSCSI ->scsi_debugbackstore with a TCM_MAX_COMMAND_SIZE=16 to force the extended CDB allocations. This was done due to the lack of an easy method to test > 32-byte CDBs w/o an TCM/OSD fabric module.Many thanks to Boaz Harrosh for his help in this area!
Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/target_core_file.c | 6 +++++ drivers/target/target_core_iblock.c | 6 +++++ drivers/target/target_core_pscsi.c | 39 ++++++++++++++++++++++++++++++++ drivers/target/target_core_pscsi.h | 6 ++++- drivers/target/target_core_rd.c | 6 +++++ drivers/target/target_core_stgt.c | 6 +++++ drivers/target/target_core_transport.c | 34 +++++++++++++++++++++++---- include/target/target_core_base.h | 6 +++- include/target/target_core_transport.h | 5 ++++ 9 files changed, 106 insertions(+), 8 deletions(-)drivers/target/target_core_file.c +6
-0@@ -1125,6 +1125,11 @@ static unsigned char *fd_get_cdb(struct se_task *task)return req->fd_scsi_cdb; } +static u32 fd_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* fd_get_blocksize(): (Part of se_subsystem_api_t template) * * @@ -1224,6 +1229,7 @@ static struct se_subsystem_api fileio_template = { .check_lba = fd_check_lba, .check_for_SG = fd_check_for_SG, .get_cdb = fd_get_cdb, + .get_max_cdb_len = fd_get_max_cdb_len, .get_blocksize = fd_get_blocksize, .get_device_rev = fd_get_device_rev, .get_device_type = fd_get_device_type,drivers/target/target_core_iblock.c +6
-0@@ -1059,6 +1059,11 @@ static unsigned char *iblock_get_cdb(struct se_task *task)return req->ib_scsi_cdb; } +static u32 iblock_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +static u32 iblock_get_blocksize (struct se_device *dev) {struct iblock_dev *ibd = dev->dev_ptr;@@ -1167,6 +1172,7 @@ static struct se_subsystem_api iblock_template = { .check_lba = iblock_check_lba, .check_for_SG = iblock_check_for_SG, .get_cdb = iblock_get_cdb, + .get_max_cdb_len = iblock_get_max_cdb_len, .get_blocksize = iblock_get_blocksize, .get_device_rev = iblock_get_device_rev, .get_device_type = iblock_get_device_type,drivers/target/target_core_pscsi.c +2
-0@@ -714,13 +714,40 @@ static void *pscsi_allocate_request(struct se_task *task, struct se_device *dev) { + struct se_cmd *cmd = task->task_se_cmd;struct pscsi_plugin_task *pt; +unsigned char *cdb =T_TASK (cmd)->t_task_cdb; pt =kzalloc (sizeof (struct pscsi_plugin_task ),GFP_KERNEL );
drivers/target/target_core_pscsi.c static void *pscsi_allocate_request( · line 731
Quoted 10 lines
drivers/target/target_core_pscsi.c +6
-0if (!(pt)) {printk (KERN_ERR "Unable to allocate struct pscsi_plugin_task\n" );return NULL ; } +/* +* If TCM Core is signaling a > TCM_MAX_COMMAND_SIZE allocation, +* allocate the extended CDB buffer for per struct se_task context +* pt->pscsi_cdb now. +*/ +if (cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) {
Just check the size here, Why do you need the flag.
Quoted 9 lines
drivers/target/target_core_pscsi.c +9
-0+/* +* PSCSI_MAX_CDB_SIZE is currently set to 240 bytes which +* allows the largest OSD CDB sizes again. +*/ +if (scsi_command_size (cdb) >PSCSI_MAX_CDB_SIZE ) { +printk (KERN_ERR "pSCSI: Received CDB of size: %u larger" +" than PSCSI_MAX_CDB_SIZE: %u\n" , +scsi_command_size (cdb),PSCSI_MAX_CDB_SIZE ); +return NULL ;
drivers/target/target_core_pscsi.c static void *pscsi_allocate_request( · line 750
Quoted 10 lines
drivers/target/target_core_pscsi.c +10
-0+ } + + pt->pscsi_cdb =kzalloc (scsi_command_size (cdb),GFP_KERNEL ); +if (!(pt->pscsi_cdb)) { +printk (KERN_ERR "pSCSI: Unable to allocate extended" +" pt->pscsi_cdb\n" ); +return NULL ; + } + }else + pt->pscsi_cdb = &pt->__pscsi_cdb[0 ];
What? another copy and another pointer. Why? Why can't you just pass to block layer the command from T_TASK(cmd)->t_task_cdb. Don't you keep the T_TASK(cmd) associated with the pscsi_plugin_task up until completion. (The complete hunk looks pointless)
drivers/target/target_core_pscsi.c static void pscsi_free_task(struct se_task *task) · line 853
Quoted 13 lines
drivers/target/target_core_pscsi.c +6
-0return pt; }@@ -818,6 +845,12 @@ static void pscsi_free_task(struct se_task *task) {struct pscsi_plugin_task *pt = task->transport_req;/* +* Release the extended CDB allocation from pscsi_allocate_request() +* if one exists. +*/ +if (task->task_se_cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) +kfree (pt->pscsi_cdb); +/*
Here! you have the struct se_task up to the end. pt->pscsi_cdb is totally redundant.
drivers/target/target_core_pscsi.c static unsigned char *pscsi_get_cdb(struct se_task *task) · line 1406
Quoted 12 lines
drivers/target/target_core_pscsi.c +5
-0* We do not release the bio(s) here associated with this task, as * this is handled by bio_put() and pscsi_bi_endio(). */ @@ -1366,6 +1399,11 @@ static unsigned char *pscsi_get_cdb(struct se_task *task)return pt->pscsi_cdb; } +static u32 pscsi_get_max_cdb_len (struct se_device *dev) +{ +return PSCSI_MAX_CDB_SIZE ; +} +
I don't think you need that, but if you do why not return the scsi_host->max_cmd_len ?
Quoted 16 lines
drivers/target/target_core_pscsi.c +1
-0/* pscsi_get_sense_buffer(): * * @@ -1533,6 +1571,7 @@ static struct se_subsystem_api pscsi_template = { .check_lba = pscsi_check_lba, .check_for_SG = pscsi_check_for_SG, .get_cdb = pscsi_get_cdb, + .get_max_cdb_len = pscsi_get_max_cdb_len, .get_sense_buffer = pscsi_get_sense_buffer, .get_blocksize = pscsi_get_blocksize, .get_device_rev = pscsi_get_device_rev,drivers/target/target_core_pscsi.h +0
-0
drivers/target/target_core_pscsi.h line 14
Quoted 6 lines
drivers/target/target_core_pscsi.h +3
-0@@ -9,6 +9,9 @@#define INQUIRY_DATA_SIZE 0x24#endif +/* Maximum extended CDB size for handling OSD passthrough */ +#define PSCSI_MAX_CDB_SIZE 240 +
Wrong and redundant use SCSI_MAX_VARLEN_CDB_SIZE
drivers/target/target_core_pscsi.h extern int linux_blockdevice_check(int, int); · line 35
Quoted 10 lines
drivers/target/target_core_pscsi.h +2
-1/* used in pscsi_add_device_to_list() */ #define PSCSI_DEFAULT_QUEUEDEPTH 1@@ -28,7 +31,8 @@ extern int linux_blockdevice_check(int, int);#include <linux/kobject.h> struct pscsi_plugin_task { -unsigned char pscsi_cdb[TCM_MAX_COMMAND_SIZE ]; +unsigned char *pscsi_cdb; +unsigned char __pscsi_cdb[TCM_MAX_COMMAND_SIZE ];
As said above just drop it.
Quoted 32 lines
drivers/target/target_core_pscsi.h +0
-0unsigned char pscsi_sense[SCSI_SENSE_BUFFERSIZE ];int pscsi_direction;int pscsi_result;drivers/target/target_core_rd.c +6
-0@@ -1392,6 +1392,11 @@ static unsigned char *rd_get_cdb(struct se_task *task)return req->rd_scsi_cdb; } +static u32 rd_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* rd_get_blocksize(): (Part of se_subsystem_api_t template) * * @@ -1475,6 +1480,7 @@ static struct se_subsystem_api rd_dr_template = { .check_lba = rd_DIRECT_check_lba, .check_for_SG = rd_check_for_SG, .get_cdb = rd_get_cdb, + .get_max_cdb_len = rd_get_max_cdb_len, .get_blocksize = rd_get_blocksize, .get_device_rev = rd_get_device_rev, .get_device_type = rd_get_device_type,drivers/target/target_core_stgt.c +0
-0
drivers/target/target_core_stgt.c static unsigned char *stgt_get_cdb(struct se_task *task) · line 758
Quoted 8 lines
drivers/target/target_core_stgt.c +5
-0@@ -751,6 +751,11 @@ static unsigned char *stgt_get_cdb(struct se_task *task)return pt->stgt_cdb; } +static u32 stgt_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +
Surely not maximum for stgt. Or I missed the meaning of this completely.
Quoted 16 lines
drivers/target/target_core_stgt.c +1
-0/* stgt_get_sense_buffer(): * * @@ -931,6 +936,7 @@ static struct se_subsystem_api stgt_template = { .check_lba = stgt_check_lba, .check_for_SG = stgt_check_for_SG, .get_cdb = stgt_get_cdb, + .get_max_cdb_len = stgt_get_max_cdb_len, .get_sense_buffer = stgt_get_sense_buffer, .get_blocksize = stgt_get_blocksize, .get_device_rev = stgt_get_device_rev,drivers/target/target_core_transport.c +0
-0
drivers/target/target_core_transport.c void transport_free_se_cmd( · line 2866
Quoted 7 lines
drivers/target/target_core_transport.c +4
-0@@ -2860,6 +2860,11 @@ void transport_free_se_cmd(if (se_cmd->se_tmr_req)core_tmr_release_req (se_cmd->se_tmr_req);/* +* Check and free any extended CDB buffer that was allocated +*/ +if (se_cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) +kfree (T_TASK (se_cmd)->t_task_cdb);
What about if (T_TASK(se_cmd)->t_task_cdb != T_TASK(se_cmd)->__t_task_cdb)
drivers/target/target_core_transport.c int transport_generic_allocate_tasks( · line 2915
Quoted 13 lines
drivers/target/target_core_transport.c +6
-0+/* * Release any optional TCM fabric dependent iovecs allocated by * transport_allocate_iovecs_for_cmd() */ @@ -2903,6 +2908,23 @@ int transport_generic_allocate_tasks(if (non_data_cdb <0 )return -1 ;/* +* If the received CDB is larger than TCM_MAX_COMMAND_SIZE, +* allocate the additional extended CDB buffer now.. Otherwise +* setup the pointer from __t_task_cdb to t_task_cdb. +*/ +if (scsi_command_size (cdb) >TCM_MAX_COMMAND_SIZE ) {
^^ sizeof(T_TASK(cmd)->__t_task_cdb)
drivers/target/target_core_transport.c int transport_generic_allocate_tasks( · line 2926
Quoted 11 lines
drivers/target/target_core_transport.c +11
-0+T_TASK (cmd)->t_task_cdb =kzalloc (scsi_command_size (cdb), +GFP_KERNEL ); +if (!(T_TASK (cmd)->t_task_cdb)) { +printk (KERN_ERR "Unable to allocate T_TASK(cmd)->t_task_cdb" +" %u > TCM_MAX_COMMAND_SIZE ops\n" , +scsi_command_size (cdb)); +return -1 ; + } + cmd->se_cmd_flags |=SCF_ECDB_ALLOCATION ; + }else +T_TASK (cmd)->t_task_cdb = &T_TASK (cmd)->__t_task_cdb[0 ];
T_TASK(cmd)->t_task_cdb = T_TASK(cmd)->__t_task_cdb;
Quoted 5 lines
drivers/target/target_core_transport.c +1
-0+/* * Copy the original CDB into T_TASK(cmd). */ memcpy (T_TASK (cmd)->t_task_cdb, cdb,scsi_command_size (cdb));
drivers/target/target_core_transport.c static int transport_generic_cmd_sequencer( · line 5774
Quoted 9 lines
drivers/target/target_core_transport.c +3
-2@@ -5746,13 +5768,15 @@ static int transport_generic_cmd_sequencer( service_action =get_unaligned_be16 (&cdb[8 ]);/* * Check the additional CDB length (+ 8 bytes for header) does -* not exceed our TCM_MAX_COMMAND_SIZE. +* not exceed our backsores ->get_max_cdb_len() */ -if (scsi_varlen_cdb_length (&cdb[0 ]) >TCM_MAX_COMMAND_SIZE ) { +if (scsi_varlen_cdb_length (&cdb[0 ]) > +TRANSPORT (dev)->get_max_cdb_len (dev)) {
Again VARIABLE_LENGTH_CMD can be small as well as none-VARIABLE_LENGTH_CMD can be big. The check should be more generic and against scsi_command_size(cdb).
BUT!! Please just drop that ->get_max_cdb_len(dev) it's useless.
Quoted 41 lines
drivers/target/target_core_transport.c +4
-3printk (KERN_INFO "Only %u-byte extended CDBs currently" -" supported for VARIABLE_LENGTH_CMD, received:" -" %d for service action: 0x%04x\n" , -TCM_MAX_COMMAND_SIZE , +" supported for VARIABLE_LENGTH_CMD backstore %s," +" received: %d for service action: 0x%04x\n" , +TRANSPORT (dev)->get_max_cdb_len (dev), +TRANSPORT (dev)->name,scsi_varlen_cdb_length (&cdb[0 ]), service_action);return TGCS_INVALID_CDB_FIELD ; }include/target/target_core_base.h +4
-2@@ -137,7 +137,8 @@ enum se_cmd_flags_table {SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC =0x00800000 ,SCF_EMULATE_SYNC_CACHE =0x01000000 ,SCF_EMULATE_CDB_ASYNC =0x02000000 , - SCF_EMULATE_SYNC_UNMAP = 0x04000000 +SCF_EMULATE_SYNC_UNMAP =0x04000000 , + SCF_ECDB_ALLOCATION = 0x08000000 };/* struct se_device->type for known subsystem plugins */ @@ -424,7 +425,8 @@ struct se_queue_obj {* drivers/target/target_core_transport.c:__transport_alloc_se_cmd() */ struct se_transport_task { -unsigned char t_task_cdb[MAX_COMMAND_SIZE ]; +unsigned char *t_task_cdb; +unsigned char __t_task_cdb[MAX_COMMAND_SIZE ];unsigned long long t_task_lba;int t_tasks_failed;int t_tasks_fua;include/target/target_core_transport.h +0
-0@@ -519,6 +519,11 @@ struct se_subsystem_api {*/
include/target/target_core_transport.h struct se_subsystem_api { · line 529
Quoted 10 lines
include/target/target_core_transport.h +5
-0unsigned char *(*get_cdb)(struct se_task *);/* +* get_max_cdb_len(): Used by subsystems backstoers to signal the +* maximum receivable SCSI CDB size. +*/ +u32 (*get_max_cdb_len)(struct se_device *); +/* * get_blocksize(): */ u32 (*get_blocksize)(struct se_device *);
Thanks
Boaz
<Following up on some review from Boaz from last week that was dropped on my part..>
Quoted 32 lines · Boaz Harrosh
Quoted 10 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
Greetings all,
This patch allows TCM Core to process CDBs containing a received
scsi_command_size()larger than the hardcoded default ofTCM_MAX_COMMAND_SIZE(32-bytes). This patch first converts the hardcoded per structse_cmd-> struct se_transport_task->t_task_cdb[] to ->__t_task_cdb[TCM_MAX_COMMAND_SIZE], and turns ->t_task_cdb into a pointer used to reference ->__t_task_cdb or an extended CDB buffer setup intransport_generic_allocate_tasks().Quoted 5 lines
It next adds a new struct
se_subsystem_api->get_max_cdb_len()API caller that is used by TCM subsystem plugins to report their individual CDB size limits. Nexttransport_generic_cmd_sequencer()has been changed to use ->get_max_cdb_len() forVARIABLE_LENGTH_CMDto determine if the backstore can support the receivedQuoted 1 line
TCM_MAX_COMMAND_SIZEsized CDB, or to fail the I/O with exception status.^^ ==> ->get_max_cdb_len()Quoted 1 line
I'm commenting on the change log here. Comments on actual code is below.
First: there are bigger then ->get_max_cdb_len() which are not
VARIABLE_LENGTH_CMD, and there areVARIABLE_LENGTH_CMDwhich are smaller then 16 bytes. So theVARIABLE_LENGTH_CMDhas nothing to do with it. It's all a matter ofscsi_command_size(cmnd);Second: I don't like that ->get_max_cdb_len(), it means nothing. The fact that the size check passed, does not mean the actual SCSI-COMMAND is supported. So plugins should be ready to receive unsupported commands and properly return the correct error. If an FILEIO does not support
OSD_ACT_CREATEit's because it's an OSD command and not because it is big. Maintaining the proper ->get_max_cdb_len() as code evolves is just a maintenance headache that buys you nothing!
Quoted 3 lines
Note that in pSCSI passthrough plugin the request will fail soon enough and the proper error handling should be in place, already.
Since you had a chance to look at this code, the ->get_max_cdb_len() caller has been dropped from the backend struct se_subsystem_api in favor of struct se_dev_limits->max_cdb_len setup during subsystem plugin registration. But point well taken that a cdb_len check for backstores is really unnecessary in the current context. I will go ahead and drop these handful of checks...
Quoted 8 lines
Quoted 3 lines
The extended CDB buffer is setup in
transport_generic_allocate_tasks()when necessary, and a newSCF_ECDB_ALLOCATIONflag is then set. The release of the extended CDB buffer happens intransport_free_se_cmd()in the normal structse_cmdrelease path.You have a magic size number which is
sizeof(->__t_task_cdb)bigger then "that" alloc. Then also bigger then "that" free. No need for a flag.
But I'd even do more. if (->t_task_cdb != ->__t_task_cdb) free
OK, dropping SCF_ECDB_ALLOCATION flag in favor of this condition in transport_free_se_cmd().
Quoted 9 lines
Quoted 3 lines
This patch also updates TCM/pSCSI to handle extended CDBs up to PSCSI_MAX_CDB_SIZE=240 (maximum current OSD CDB size) and sets up the extra struct
pscsi_plugin_task->pscsi_cdbNo! the max CDB size is
SCSI_MAX_VARLEN_CDB_SIZE(260) defined inscsi/scsi.h. Including thevarlen_cdb8 bytes header. This is do to the fact that the header has a single byte to denote payload size and must be 4 bytes aligned so 252 + 8 bytes header. See "structscsi_varlen_cdb_hdr" inscsi.h
Ok, many thanks for the clarification on this one.
Quoted 84 lines
Quoted 84 lines
allocation in struct
se_taskcontext in order to complete the > TCM_MAX_COMMAND_SIZE=32 request. The IBLOCK, FILEIO, RAMDISK, and STGT subsystem plugins have been updated to enforce the TCM_MAX_COMMAND_SIZE=32 limit via structse_subsystem_api->get_max_cdb_len().So far this code been tested with '
sgv4_xdwriteread-e' into aTCM_Loop-> TCM/pSCSI ->scsi_debugbackstore with a TCM_MAX_COMMAND_SIZE=16 to force the extended CDB allocations. This was done due to the lack of an easy method to test > 32-byte CDBs w/o an TCM/OSD fabric module.Many thanks to Boaz Harrosh for his help in this area!
Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/target_core_file.c | 6 +++++ drivers/target/target_core_iblock.c | 6 +++++ drivers/target/target_core_pscsi.c | 39 ++++++++++++++++++++++++++++++++ drivers/target/target_core_pscsi.h | 6 ++++- drivers/target/target_core_rd.c | 6 +++++ drivers/target/target_core_stgt.c | 6 +++++ drivers/target/target_core_transport.c | 34 +++++++++++++++++++++++---- include/target/target_core_base.h | 6 +++- include/target/target_core_transport.h | 5 ++++ 9 files changed, 106 insertions(+), 8 deletions(-)drivers/target/target_core_file.c +6
-0@@ -1125,6 +1125,11 @@ static unsigned char *fd_get_cdb(struct se_task *task)return req->fd_scsi_cdb; } +static u32 fd_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* fd_get_blocksize(): (Part of se_subsystem_api_t template) * * @@ -1224,6 +1229,7 @@ static struct se_subsystem_api fileio_template = { .check_lba = fd_check_lba, .check_for_SG = fd_check_for_SG, .get_cdb = fd_get_cdb, + .get_max_cdb_len = fd_get_max_cdb_len, .get_blocksize = fd_get_blocksize, .get_device_rev = fd_get_device_rev, .get_device_type = fd_get_device_type,drivers/target/target_core_iblock.c +6
-0@@ -1059,6 +1059,11 @@ static unsigned char *iblock_get_cdb(struct se_task *task)return req->ib_scsi_cdb; } +static u32 iblock_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +static u32 iblock_get_blocksize (struct se_device *dev) {struct iblock_dev *ibd = dev->dev_ptr;@@ -1167,6 +1172,7 @@ static struct se_subsystem_api iblock_template = { .check_lba = iblock_check_lba, .check_for_SG = iblock_check_for_SG, .get_cdb = iblock_get_cdb, + .get_max_cdb_len = iblock_get_max_cdb_len, .get_blocksize = iblock_get_blocksize, .get_device_rev = iblock_get_device_rev, .get_device_type = iblock_get_device_type,drivers/target/target_core_pscsi.c +2
-0@@ -714,13 +714,40 @@ static void *pscsi_allocate_request(struct se_task *task, struct se_device *dev) { + struct se_cmd *cmd = task->task_se_cmd;struct pscsi_plugin_task *pt; +unsigned char *cdb =T_TASK (cmd)->t_task_cdb;
Quoted 14 lines
drivers/target/target_core_pscsi.c static void *pscsi_allocate_request( · line 731
Quoted 11 lines
drivers/target/target_core_pscsi.c +6
-0pt =kzalloc (sizeof (struct pscsi_plugin_task ),GFP_KERNEL );if (!(pt)) {printk (KERN_ERR "Unable to allocate struct pscsi_plugin_task\n" );return NULL ; } +/* +* If TCM Core is signaling a > TCM_MAX_COMMAND_SIZE allocation, +* allocate the extended CDB buffer for per struct se_task context +* pt->pscsi_cdb now. +*/ +if (cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) {Just check the size here, Why do you need the flag.
Fixed
Quoted 16 lines
Quoted 16 lines
drivers/target/target_core_pscsi.c +16
-0+/* +* PSCSI_MAX_CDB_SIZE is currently set to 240 bytes which +* allows the largest OSD CDB sizes again. +*/ +if (scsi_command_size (cdb) >PSCSI_MAX_CDB_SIZE ) { +printk (KERN_ERR "pSCSI: Received CDB of size: %u larger" +" than PSCSI_MAX_CDB_SIZE: %u\n" , +scsi_command_size (cdb),PSCSI_MAX_CDB_SIZE ); +return NULL ; + } + + pt->pscsi_cdb =kzalloc (scsi_command_size (cdb),GFP_KERNEL ); +if (!(pt->pscsi_cdb)) { +printk (KERN_ERR "pSCSI: Unable to allocate extended" +" pt->pscsi_cdb\n" ); +return NULL ;
Quoted 8 lines
drivers/target/target_core_pscsi.c static void *pscsi_allocate_request( · line 750
Quoted 3 lines
drivers/target/target_core_pscsi.c +3
-0+ } + }else + pt->pscsi_cdb = &pt->__pscsi_cdb[0 ];What? another copy and another pointer. Why? Why can't you just pass to block layer the command from T_TASK(cmd)->t_task_cdb. Don't you keep the
T_TASK(cmd)associated with thepscsi_plugin_taskup until completion. (The complete hunk looks pointless)
Not exactly correct. This is the case for all control CDBs of type SG and non SG that will never be split into multiple struct se_tasks for dispatch to backend code due to ->max_sectors limitiations. However for the primary SCF_SCSI_DATA_SG_IO_CDB bulk data I/O code path the CDB memory does in fact live in the subsystem backstore specific per struct se_task data structure.
Quoted 25 lines
Quoted 5 lines
drivers/target/target_core_pscsi.c +0
-0return pt; }drivers/target/target_core_pscsi.c static void pscsi_free_task(struct se_task *task) · line 853
Quoted 9 lines
drivers/target/target_core_pscsi.c +6
-0@@ -818,6 +845,12 @@ static void pscsi_free_task(struct se_task *task) {struct pscsi_plugin_task *pt = task->transport_req;/* +* Release the extended CDB allocation from pscsi_allocate_request() +* if one exists. +*/ +if (task->task_se_cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) +kfree (pt->pscsi_cdb); +/* Here! you have the struct
se_taskup to the end.pt->pscsi_cdbis totally redundant.Quoted 7 lines
drivers/target/target_core_pscsi.c +0
-0* We do not release the bio(s) here associated with this task, as * this is handled by bio_put() and pscsi_bi_endio(). */ @@ -1366,6 +1399,11 @@ static unsigned char *pscsi_get_cdb(struct se_task *task)return pt->pscsi_cdb; }
Quoted 8 lines
drivers/target/target_core_pscsi.c static unsigned char *pscsi_get_cdb(struct se_task *task) · line 1406
Quoted 5 lines
drivers/target/target_core_pscsi.c +5
-0+static u32 pscsi_get_max_cdb_len (struct se_device *dev) +{ +return PSCSI_MAX_CDB_SIZE ; +} +I don't think you need that, but if you do why not return the
scsi_host->max_cmd_len?
<nod> dropping the current equivlient of this in pSCSI.
Quoted 19 lines
Quoted 19 lines
drivers/target/target_core_pscsi.c +1
-0/* pscsi_get_sense_buffer(): * * @@ -1533,6 +1571,7 @@ static struct se_subsystem_api pscsi_template = { .check_lba = pscsi_check_lba, .check_for_SG = pscsi_check_for_SG, .get_cdb = pscsi_get_cdb, + .get_max_cdb_len = pscsi_get_max_cdb_len, .get_sense_buffer = pscsi_get_sense_buffer, .get_blocksize = pscsi_get_blocksize, .get_device_rev = pscsi_get_device_rev,drivers/target/target_core_pscsi.h +0
-0@@ -9,6 +9,9 @@#define INQUIRY_DATA_SIZE 0x24#endif
Quoted 5 lines
drivers/target/target_core_pscsi.h line 14
Quoted 3 lines
drivers/target/target_core_pscsi.h +3
-0+/* Maximum extended CDB size for handling OSD passthrough */ +#define PSCSI_MAX_CDB_SIZE 240 +Wrong and redundant use
SCSI_MAX_VARLEN_CDB_SIZE
Dropping
Quoted 49 lines
drivers/target/target_core_pscsi.h extern int linux_blockdevice_check(int, int); · line 35
Quoted 11 lines
drivers/target/target_core_pscsi.h +2
-1/* used in pscsi_add_device_to_list() */ #define PSCSI_DEFAULT_QUEUEDEPTH 1@@ -28,7 +31,8 @@ extern int linux_blockdevice_check(int, int);#include <linux/kobject.h> struct pscsi_plugin_task { -unsigned char pscsi_cdb[TCM_MAX_COMMAND_SIZE ]; +unsigned char *pscsi_cdb; +unsigned char __pscsi_cdb[TCM_MAX_COMMAND_SIZE ];As said above just drop it.
Quoted 35 lines
drivers/target/target_core_pscsi.h +0
-0unsigned char pscsi_sense[SCSI_SENSE_BUFFERSIZE ];int pscsi_direction;int pscsi_result;drivers/target/target_core_rd.c +6
-0@@ -1392,6 +1392,11 @@ static unsigned char *rd_get_cdb(struct se_task *task)return req->rd_scsi_cdb; } +static u32 rd_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +/* rd_get_blocksize(): (Part of se_subsystem_api_t template) * * @@ -1475,6 +1480,7 @@ static struct se_subsystem_api rd_dr_template = { .check_lba = rd_DIRECT_check_lba, .check_for_SG = rd_check_for_SG, .get_cdb = rd_get_cdb, + .get_max_cdb_len = rd_get_max_cdb_len, .get_blocksize = rd_get_blocksize, .get_device_rev = rd_get_device_rev, .get_device_type = rd_get_device_type,drivers/target/target_core_stgt.c +0
-0@@ -751,6 +751,11 @@ static unsigned char *stgt_get_cdb(struct se_task *task)return pt->stgt_cdb; }
Quoted 8 lines
drivers/target/target_core_stgt.c static unsigned char *stgt_get_cdb(struct se_task *task) · line 758
Quoted 5 lines
drivers/target/target_core_stgt.c +5
-0+static u32 stgt_get_max_cdb_len (struct se_device *dev) +{ +return TCM_MAX_COMMAND_SIZE ; +} +Surely not maximum for stgt. Or I missed the meaning of this completely.
Yes, this one has already been dropped for STGT.
Quoted 17 lines
Quoted 17 lines
drivers/target/target_core_stgt.c +1
-0/* stgt_get_sense_buffer(): * * @@ -931,6 +936,7 @@ static struct se_subsystem_api stgt_template = { .check_lba = stgt_check_lba, .check_for_SG = stgt_check_for_SG, .get_cdb = stgt_get_cdb, + .get_max_cdb_len = stgt_get_max_cdb_len, .get_sense_buffer = stgt_get_sense_buffer, .get_blocksize = stgt_get_blocksize, .get_device_rev = stgt_get_device_rev,drivers/target/target_core_transport.c +0
-0@@ -2860,6 +2860,11 @@ void transport_free_se_cmd(if (se_cmd->se_tmr_req)
Quoted 8 lines
drivers/target/target_core_transport.c void transport_free_se_cmd( · line 2866
Quoted 6 lines
drivers/target/target_core_transport.c +4
-0core_tmr_release_req (se_cmd->se_tmr_req);/* +* Check and free any extended CDB buffer that was allocated +*/ +if (se_cmd->se_cmd_flags &SCF_ECDB_ALLOCATION ) +kfree (T_TASK (se_cmd)->t_task_cdb);What about if (T_TASK(se_cmd)->t_task_cdb != T_TASK(se_cmd)->__t_task_cdb)
Fixed
Quoted 17 lines
Quoted 6 lines
drivers/target/target_core_transport.c +1
-0+/* * Release any optional TCM fabric dependent iovecs allocated by * transport_allocate_iovecs_for_cmd() */ drivers/target/target_core_transport.c int transport_generic_allocate_tasks( · line 2915
Quoted 8 lines
drivers/target/target_core_transport.c +5
-0@@ -2903,6 +2908,23 @@ int transport_generic_allocate_tasks(if (non_data_cdb <0 )return -1 ;/* +* If the received CDB is larger than TCM_MAX_COMMAND_SIZE, +* allocate the additional extended CDB buffer now.. Otherwise +* setup the pointer from __t_task_cdb to t_task_cdb. +*/ +if (scsi_command_size (cdb) >TCM_MAX_COMMAND_SIZE ) {^^ sizeof(T_TASK(cmd)->__t_task_cdb)
Fixed
Quoted 32 lines
drivers/target/target_core_transport.c int transport_generic_allocate_tasks( · line 2926
Quoted 11 lines
drivers/target/target_core_transport.c +11
-0+T_TASK (cmd)->t_task_cdb =kzalloc (scsi_command_size (cdb), +GFP_KERNEL ); +if (!(T_TASK (cmd)->t_task_cdb)) { +printk (KERN_ERR "Unable to allocate T_TASK(cmd)->t_task_cdb" +" %u > TCM_MAX_COMMAND_SIZE ops\n" , +scsi_command_size (cdb)); +return -1 ; + } + cmd->se_cmd_flags |=SCF_ECDB_ALLOCATION ; + }else +T_TASK (cmd)->t_task_cdb = &T_TASK (cmd)->__t_task_cdb[0 ];T_TASK(cmd)->t_task_cdb = T_TASK(cmd)->__t_task_cdb;Quoted 5 lines
drivers/target/target_core_transport.c +1
-0+/* * Copy the original CDB into T_TASK(cmd). */ memcpy (T_TASK (cmd)->t_task_cdb, cdb,scsi_command_size (cdb));drivers/target/target_core_transport.c static int transport_generic_cmd_sequencer( · line 5774
Quoted 9 lines
drivers/target/target_core_transport.c +3
-2@@ -5746,13 +5768,15 @@ static int transport_generic_cmd_sequencer( service_action =get_unaligned_be16 (&cdb[8 ]);/* * Check the additional CDB length (+ 8 bytes for header) does -* not exceed our TCM_MAX_COMMAND_SIZE. +* not exceed our backsores ->get_max_cdb_len() */ -if (scsi_varlen_cdb_length (&cdb[0 ]) >TCM_MAX_COMMAND_SIZE ) { +if (scsi_varlen_cdb_length (&cdb[0 ]) > +TRANSPORT (dev)->get_max_cdb_len (dev)) {Again
VARIABLE_LENGTH_CMDcan be small as well as none-VARIABLE_LENGTH_CMD can be big. The check should be more generic and againstscsi_command_size(cdb).
Quoted 1 line
BUT!! Please just drop that ->get_max_cdb_len(dev) it's useless.
Done!
Sending out a patch shortly against the latest lio-core-2.6.git/lio-4.0 for your review.
Thanks for your comments Boaz!