Skip to content

Commit

Permalink
target: move transport_generic_prepare_cdb into pscsi
Browse files Browse the repository at this point in the history
The virtual drivers don't need to clear cdb fields they never look at, so move
this code into the pscsi backend.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
  • Loading branch information
Christoph Hellwig authored and Nicholas Bellinger committed Jul 17, 2012
1 parent 1fd032e commit 3d6d720
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
26 changes: 26 additions & 0 deletions drivers/target/target_core_pscsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,30 @@ static int pscsi_map_sg(struct se_cmd *cmd, struct scatterlist *sgl,
return -ENOMEM;
}

/*
* Clear a lun set in the cdb if the initiator talking to use spoke
* and old standards version, as we can't assume the underlying device
* won't choke up on it.
*/
static inline void pscsi_clear_cdb_lun(unsigned char *cdb)
{
switch (cdb[0]) {
case READ_10: /* SBC - RDProtect */
case READ_12: /* SBC - RDProtect */
case READ_16: /* SBC - RDProtect */
case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
case VERIFY: /* SBC - VRProtect */
case VERIFY_16: /* SBC - VRProtect */
case WRITE_VERIFY: /* SBC - VRProtect */
case WRITE_VERIFY_12: /* SBC - VRProtect */
case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
break;
default:
cdb[1] &= 0x1f; /* clear logical unit number */
break;
}
}

static int pscsi_parse_cdb(struct se_cmd *cmd)
{
unsigned char *cdb = cmd->t_task_cdb;
Expand All @@ -1034,6 +1058,8 @@ static int pscsi_parse_cdb(struct se_cmd *cmd)
return -EINVAL;
}

pscsi_clear_cdb_lun(cdb);

/*
* For REPORT LUNS we always need to emulate the respone, and for everything
* related to persistent reservations and ALUA we might optionally use our
Expand Down
29 changes: 0 additions & 29 deletions drivers/target/target_core_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,34 +1315,6 @@ struct se_device *transport_add_device_to_core_hba(
}
EXPORT_SYMBOL(transport_add_device_to_core_hba);

/* transport_generic_prepare_cdb():
*
* Since the Initiator sees iSCSI devices as LUNs, the SCSI CDB will
* contain the iSCSI LUN in bits 7-5 of byte 1 as per SAM-2.
* The point of this is since we are mapping iSCSI LUNs to
* SCSI Target IDs having a non-zero LUN in the CDB will throw the
* devices and HBAs for a loop.
*/
static inline void transport_generic_prepare_cdb(
unsigned char *cdb)
{
switch (cdb[0]) {
case READ_10: /* SBC - RDProtect */
case READ_12: /* SBC - RDProtect */
case READ_16: /* SBC - RDProtect */
case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
case VERIFY: /* SBC - VRProtect */
case VERIFY_16: /* SBC - VRProtect */
case WRITE_VERIFY: /* SBC - VRProtect */
case WRITE_VERIFY_12: /* SBC - VRProtect */
case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
break;
default:
cdb[1] &= 0x1f; /* clear logical unit number */
break;
}
}

int target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
{
struct se_device *dev = cmd->se_dev;
Expand Down Expand Up @@ -1471,7 +1443,6 @@ int target_setup_cmd_from_cdb(
unsigned long flags;
int ret;

transport_generic_prepare_cdb(cdb);
/*
* Ensure that the received CDB is less than the max (252 + 8) bytes
* for VARIABLE_LENGTH_CMD
Expand Down

0 comments on commit 3d6d720

Please sign in to comment.