Commit 88455ec4 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nicholas Bellinger

target: split parsing of SPC commands into a separate helper

(nab: Add EXPORT_SYMBOL usage for spc_parse_cdb)
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 9b3b8041
...@@ -10,6 +10,7 @@ target_core_mod-y := target_core_configfs.o \ ...@@ -10,6 +10,7 @@ target_core_mod-y := target_core_configfs.o \
target_core_tpg.o \ target_core_tpg.o \
target_core_transport.o \ target_core_transport.o \
target_core_cdb.o \ target_core_cdb.o \
target_core_spc.o \
target_core_ua.o \ target_core_ua.o \
target_core_rd.o \ target_core_rd.o \
target_core_stat.o target_core_stat.o
......
...@@ -96,6 +96,9 @@ int core_tpg_post_addlun(struct se_portal_group *, struct se_lun *, ...@@ -96,6 +96,9 @@ int core_tpg_post_addlun(struct se_portal_group *, struct se_lun *,
struct se_lun *core_tpg_pre_dellun(struct se_portal_group *, u32 unpacked_lun); struct se_lun *core_tpg_pre_dellun(struct se_portal_group *, u32 unpacked_lun);
int core_tpg_post_dellun(struct se_portal_group *, struct se_lun *); int core_tpg_post_dellun(struct se_portal_group *, struct se_lun *);
/* target_core_spc.c */
int spc_parse_cdb(struct se_cmd *cmd, unsigned int *size, bool passthrough);
/* target_core_transport.c */ /* target_core_transport.c */
extern struct kmem_cache *se_tmr_req_cache; extern struct kmem_cache *se_tmr_req_cache;
......
/*
* SCSI Primary Commands (SPC) parsing and emulation.
*
* Copyright (c) 2002, 2003, 2004, 2005 PyX Technologies, Inc.
* Copyright (c) 2005, 2006, 2007 SBE, Inc.
* Copyright (c) 2007-2010 Rising Tide Systems
* Copyright (c) 2008-2010 Linux-iSCSI.org
*
* Nicholas A. Bellinger <nab@kernel.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h>
#include <scsi/scsi_tcq.h>
#include <target/target_core_base.h>
#include <target/target_core_backend.h>
#include <target/target_core_fabric.h>
#include "target_core_internal.h"
#include "target_core_pr.h"
#include "target_core_ua.h"
int spc_parse_cdb(struct se_cmd *cmd, unsigned int *size, bool passthrough)
{
struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
unsigned char *cdb = cmd->t_task_cdb;
switch (cdb[0]) {
case MODE_SELECT:
*size = cdb[4];
break;
case MODE_SELECT_10:
*size = (cdb[7] << 8) + cdb[8];
break;
case MODE_SENSE:
*size = cdb[4];
if (!passthrough)
cmd->execute_cmd = target_emulate_modesense;
break;
case MODE_SENSE_10:
*size = (cdb[7] << 8) + cdb[8];
if (!passthrough)
cmd->execute_cmd = target_emulate_modesense;
break;
case LOG_SELECT:
case LOG_SENSE:
*size = (cdb[7] << 8) + cdb[8];
break;
case PERSISTENT_RESERVE_IN:
if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
cmd->execute_cmd = target_scsi3_emulate_pr_in;
*size = (cdb[7] << 8) + cdb[8];
break;
case PERSISTENT_RESERVE_OUT:
if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
cmd->execute_cmd = target_scsi3_emulate_pr_out;
*size = (cdb[7] << 8) + cdb[8];
break;
case RELEASE:
case RELEASE_10:
if (cdb[0] == RELEASE_10)
*size = (cdb[7] << 8) | cdb[8];
else
*size = cmd->data_length;
if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
cmd->execute_cmd = target_scsi2_reservation_release;
break;
case RESERVE:
case RESERVE_10:
/*
* The SPC-2 RESERVE does not contain a size in the SCSI CDB.
* Assume the passthrough or $FABRIC_MOD will tell us about it.
*/
if (cdb[0] == RESERVE_10)
*size = (cdb[7] << 8) | cdb[8];
else
*size = cmd->data_length;
/*
* Setup the legacy emulated handler for SPC-2 and
* >= SPC-3 compatible reservation handling (CRH=1)
* Otherwise, we assume the underlying SCSI logic is
* is running in SPC_PASSTHROUGH, and wants reservations
* emulation disabled.
*/
if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
cmd->execute_cmd = target_scsi2_reservation_reserve;
break;
case REQUEST_SENSE:
*size = cdb[4];
if (!passthrough)
cmd->execute_cmd = target_emulate_request_sense;
break;
case INQUIRY:
*size = (cdb[3] << 8) + cdb[4];
/*
* Do implict HEAD_OF_QUEUE processing for INQUIRY.
* See spc4r17 section 5.3
*/
if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
cmd->sam_task_attr = MSG_HEAD_TAG;
if (!passthrough)
cmd->execute_cmd = target_emulate_inquiry;
break;
case SECURITY_PROTOCOL_IN:
case SECURITY_PROTOCOL_OUT:
*size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
break;
case EXTENDED_COPY:
case READ_ATTRIBUTE:
case RECEIVE_COPY_RESULTS:
case WRITE_ATTRIBUTE:
*size = (cdb[10] << 24) | (cdb[11] << 16) |
(cdb[12] << 8) | cdb[13];
break;
case RECEIVE_DIAGNOSTIC:
case SEND_DIAGNOSTIC:
*size = (cdb[3] << 8) | cdb[4];
break;
case WRITE_BUFFER:
*size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
break;
case REPORT_LUNS:
cmd->execute_cmd = target_report_luns;
*size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
/*
* Do implict HEAD_OF_QUEUE processing for REPORT_LUNS
* See spc4r17 section 5.3
*/
if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
cmd->sam_task_attr = MSG_HEAD_TAG;
break;
case TEST_UNIT_READY:
if (!passthrough)
cmd->execute_cmd = target_emulate_noop;
break;
default:
pr_warn("TARGET_CORE[%s]: Unsupported SCSI Opcode"
" 0x%02x, sending CHECK_CONDITION.\n",
cmd->se_tfo->get_fabric_name(), cdb[0]);
cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION;
cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
return -EINVAL;
}
return 0;
}
EXPORT_SYMBOL(spc_parse_cdb);
...@@ -2658,26 +2658,8 @@ static int transport_generic_cmd_sequencer( ...@@ -2658,26 +2658,8 @@ static int transport_generic_cmd_sequencer(
size = (cdb[8] << 8) + cdb[9]; size = (cdb[8] << 8) + cdb[9];
} }
break; break;
case MODE_SELECT:
size = cdb[4];
break;
case MODE_SELECT_10:
size = (cdb[7] << 8) + cdb[8];
break;
case MODE_SENSE:
size = cdb[4];
if (!passthrough)
cmd->execute_cmd = target_emulate_modesense;
break;
case MODE_SENSE_10:
size = (cdb[7] << 8) + cdb[8];
if (!passthrough)
cmd->execute_cmd = target_emulate_modesense;
break;
case GPCMD_READ_BUFFER_CAPACITY: case GPCMD_READ_BUFFER_CAPACITY:
case GPCMD_SEND_OPC: case GPCMD_SEND_OPC:
case LOG_SELECT:
case LOG_SENSE:
size = (cdb[7] << 8) + cdb[8]; size = (cdb[7] << 8) + cdb[8];
break; break;
case READ_BLOCK_LIMITS: case READ_BLOCK_LIMITS:
...@@ -2689,16 +2671,6 @@ static int transport_generic_cmd_sequencer( ...@@ -2689,16 +2671,6 @@ static int transport_generic_cmd_sequencer(
case GPCMD_READ_TRACK_RZONE_INFO: case GPCMD_READ_TRACK_RZONE_INFO:
size = (cdb[7] << 8) + cdb[8]; size = (cdb[7] << 8) + cdb[8];
break; break;
case PERSISTENT_RESERVE_IN:
if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
cmd->execute_cmd = target_scsi3_emulate_pr_in;
size = (cdb[7] << 8) + cdb[8];
break;
case PERSISTENT_RESERVE_OUT:
if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
cmd->execute_cmd = target_scsi3_emulate_pr_out;
size = (cdb[7] << 8) + cdb[8];
break;
case GPCMD_MECHANISM_STATUS: case GPCMD_MECHANISM_STATUS:
case GPCMD_READ_DVD_STRUCTURE: case GPCMD_READ_DVD_STRUCTURE:
size = (cdb[8] << 8) + cdb[9]; size = (cdb[8] << 8) + cdb[9];
...@@ -2725,17 +2697,6 @@ static int transport_generic_cmd_sequencer( ...@@ -2725,17 +2697,6 @@ static int transport_generic_cmd_sequencer(
size = (cdb[8] << 8) + cdb[9]; size = (cdb[8] << 8) + cdb[9];
} }
break; break;
case INQUIRY:
size = (cdb[3] << 8) + cdb[4];
/*
* Do implict HEAD_OF_QUEUE processing for INQUIRY.
* See spc4r17 section 5.3
*/
if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
cmd->sam_task_attr = MSG_HEAD_TAG;
if (!passthrough)
cmd->execute_cmd = target_emulate_inquiry;
break;
case READ_BUFFER: case READ_BUFFER:
size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
break; break;
...@@ -2745,10 +2706,6 @@ static int transport_generic_cmd_sequencer( ...@@ -2745,10 +2706,6 @@ static int transport_generic_cmd_sequencer(
cmd->execute_cmd = target_emulate_readcapacity; cmd->execute_cmd = target_emulate_readcapacity;
break; break;
case READ_MEDIA_SERIAL_NUMBER: case READ_MEDIA_SERIAL_NUMBER:
case SECURITY_PROTOCOL_IN:
case SECURITY_PROTOCOL_OUT:
size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
break;
case SERVICE_ACTION_IN: case SERVICE_ACTION_IN:
switch (cmd->t_task_cdb[1] & 0x1f) { switch (cmd->t_task_cdb[1] & 0x1f) {
case SAI_READ_CAPACITY_16: case SAI_READ_CAPACITY_16:
...@@ -2767,17 +2724,9 @@ static int transport_generic_cmd_sequencer( ...@@ -2767,17 +2724,9 @@ static int transport_generic_cmd_sequencer(
/*FALLTHROUGH*/ /*FALLTHROUGH*/
case ACCESS_CONTROL_IN: case ACCESS_CONTROL_IN:
case ACCESS_CONTROL_OUT: case ACCESS_CONTROL_OUT:
case EXTENDED_COPY:
case READ_ATTRIBUTE:
case RECEIVE_COPY_RESULTS:
case WRITE_ATTRIBUTE:
size = (cdb[10] << 24) | (cdb[11] << 16) | size = (cdb[10] << 24) | (cdb[11] << 16) |
(cdb[12] << 8) | cdb[13]; (cdb[12] << 8) | cdb[13];
break; break;
case RECEIVE_DIAGNOSTIC:
case SEND_DIAGNOSTIC:
size = (cdb[3] << 8) | cdb[4];
break;
/* #warning FIXME: Figure out correct GPCMD_READ_CD blocksize. */ /* #warning FIXME: Figure out correct GPCMD_READ_CD blocksize. */
#if 0 #if 0
case GPCMD_READ_CD: case GPCMD_READ_CD:
...@@ -2788,52 +2737,9 @@ static int transport_generic_cmd_sequencer( ...@@ -2788,52 +2737,9 @@ static int transport_generic_cmd_sequencer(
case READ_TOC: case READ_TOC:
size = cdb[8]; size = cdb[8];
break; break;
case REQUEST_SENSE:
size = cdb[4];
if (!passthrough)
cmd->execute_cmd = target_emulate_request_sense;
break;
case READ_ELEMENT_STATUS: case READ_ELEMENT_STATUS:
size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9]; size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9];
break; break;
case WRITE_BUFFER:
size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
break;
case RESERVE:
case RESERVE_10:
/*
* The SPC-2 RESERVE does not contain a size in the SCSI CDB.
* Assume the passthrough or $FABRIC_MOD will tell us about it.
*/
if (cdb[0] == RESERVE_10)
size = (cdb[7] << 8) | cdb[8];
else
size = cmd->data_length;
/*
* Setup the legacy emulated handler for SPC-2 and
* >= SPC-3 compatible reservation handling (CRH=1)
* Otherwise, we assume the underlying SCSI logic is
* is running in SPC_PASSTHROUGH, and wants reservations
* emulation disabled.
*/
if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
cmd->execute_cmd = target_scsi2_reservation_reserve;
break;
case RELEASE:
case RELEASE_10:
/*
* The SPC-2 RELEASE does not contain a size in the SCSI CDB.
* Assume the passthrough or $FABRIC_MOD will tell us about it.
*/
if (cdb[0] == RELEASE_10)
size = (cdb[7] << 8) | cdb[8];
else
size = cmd->data_length;
if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
cmd->execute_cmd = target_scsi2_reservation_release;
break;
case SYNCHRONIZE_CACHE: case SYNCHRONIZE_CACHE:
case SYNCHRONIZE_CACHE_16: case SYNCHRONIZE_CACHE_16:
/* /*
...@@ -2916,7 +2822,6 @@ static int transport_generic_cmd_sequencer( ...@@ -2916,7 +2822,6 @@ static int transport_generic_cmd_sequencer(
case SEEK_10: case SEEK_10:
case SPACE: case SPACE:
case START_STOP: case START_STOP:
case TEST_UNIT_READY:
case VERIFY: case VERIFY:
case WRITE_FILEMARKS: case WRITE_FILEMARKS:
if (!passthrough) if (!passthrough)
...@@ -2928,16 +2833,6 @@ static int transport_generic_cmd_sequencer( ...@@ -2928,16 +2833,6 @@ static int transport_generic_cmd_sequencer(
case GPCMD_SET_SPEED: case GPCMD_SET_SPEED:
case MOVE_MEDIUM: case MOVE_MEDIUM:
break; break;
case REPORT_LUNS:
cmd->execute_cmd = target_report_luns;
size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
/*
* Do implict HEAD_OF_QUEUE processing for REPORT_LUNS
* See spc4r17 section 5.3
*/
if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
cmd->sam_task_attr = MSG_HEAD_TAG;
break;
case GET_EVENT_STATUS_NOTIFICATION: case GET_EVENT_STATUS_NOTIFICATION:
size = (cdb[7] << 8) | cdb[8]; size = (cdb[7] << 8) | cdb[8];
break; break;
...@@ -2973,10 +2868,9 @@ static int transport_generic_cmd_sequencer( ...@@ -2973,10 +2868,9 @@ static int transport_generic_cmd_sequencer(
} }
break; break;
default: default:
pr_warn("TARGET_CORE[%s]: Unsupported SCSI Opcode" ret = spc_parse_cdb(cmd, &size, passthrough);
" 0x%02x, sending CHECK_CONDITION.\n", if (ret)
cmd->se_tfo->get_fabric_name(), cdb[0]); return ret;
goto out_unsupported_cdb;
} }
ret = target_cmd_size_check(cmd, size); ret = target_cmd_size_check(cmd, size);
......
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