iSCSI target v4.1.0-rc1 series for .39-rc1
Subsystems (7)
v3 cover iSCSI target v4.1.0-rc1 series for .39-rc1
From: Nicholas Bellinger <[email protected]>
Greetings folks,
This is the third RFC series of the RisingTide Systems iSCSI target fabric module compatible with mainline target core v4 -> for-39 target infrastructure.
More information about iscsi_target_mod is available here:
http://linux-iscsi.org/wiki/ISCSI/configFS
This series contains a number of cleanups and updates for modern mainline code based on feedback from Christoph Hellwig and Jesper Juhl that have gone into lio-core-2.6.git/lio-4.1 recently. A big thanks to them for their review!
The full RFC-v3 series for iscsi-target is available here:
git://git.kernel.org/pub/scm/linux/kernel/git/nab/scsi-post-merge-2.6.git for-39-iscsi-target-v3
The changes from RFC-v2 -> RFC-v3 include:
*) Remove dead tpg shutdown code
*) Remove dead struct iscsi_np_ex logic
*) Fix up network portal handling
*) Rename core_* prefixed functions to iscsit_* *) Convert semaphores to completion and mutex *) Convert iscsi_global members to global variables *) Cleanups for iscsi_target_login_thread logic *) Use SIGINT in iscsi_handle_login_thread_timeout() *) Cleanups for iscsi_thread_queue.c logic *) Drop MOD_TIMER and SETUP_TIMER macros
*) Convert iscsi_index_t to use idr.h
*) Remove CONN* and SESS* deference macros *) Update copyright and vendor
*) Fix up remaining struct semaphore callbacks *) Renaming renaming non iscsi_target_* source files
The changes from RFC-v1 -> RFC-v2 include:
*) Drop extra crc32c_intel libcrypto magic from iscsi_login_setup_crypto() *) Fix padded login response payload breakage from initial iscsi_proto.h
conversion
*) Cleanups for iscsi_target_core.h and conversion a number of definitions
to enums and inline defs
*) Removal of '__' prefix around u32 and friends
*) Other miscellanous checkpatch.pl cleanups
At this point the code should be ready for an initial merge for .39-rc1.
Please review and comment,
Thanks!
Nicholas Bellinger (12):
iscsi: Resolve iscsi_proto.h naming conflicts with
drivers/target/iscsi
iscsi-target: Add primary iSCSI request/response state machine logic
iscsi-target: Add TCM v4 compatiable ConfigFS control plane
iscsi-target: Add configfs fabric dependent statistics
iscsi-target: Add TPG and Device logic
iscsi-target: Add iSCSI Login Negotiation and Parameter logic
iscsi-target: Add CHAP Authentication support using libcrypto
iscsi-target: Add Sequence/PDU list + DataIN response logic
iscsi-target: Add iSCSI Error Recovery Hierarchy support
iscsi-target: Add support for task management operations
iscsi-target: Add misc utility and debug logic
iscsi-target: Add Makefile/Kconfig and update TCM top level
drivers/infiniband/ulp/iser/iser_initiator.c | 2 +- drivers/scsi/be2iscsi/be_main.h | 4 +- drivers/scsi/bnx2i/bnx2i_hwi.c | 8 +- drivers/scsi/bnx2i/bnx2i_iscsi.c | 2 +- drivers/scsi/libiscsi.c | 6 +- drivers/target/Kconfig | 1 + drivers/target/Makefile | 1 + drivers/target/iscsi/Kconfig | 17 + drivers/target/iscsi/Makefile | 20 + drivers/target/iscsi/iscsi_target.c | 5371 +++++++++++++++++++++ drivers/target/iscsi/iscsi_target.h | 45 + drivers/target/iscsi/iscsi_target_auth.c | 500 ++ drivers/target/iscsi/iscsi_target_auth.h | 33 + drivers/target/iscsi/iscsi_target_configfs.c | 1593 ++++++ drivers/target/iscsi/iscsi_target_configfs.h | 7 + drivers/target/iscsi/iscsi_target_core.h | 888 ++++ drivers/target/iscsi/iscsi_target_datain_values.c | 539 +++ drivers/target/iscsi/iscsi_target_datain_values.h | 15 + drivers/target/iscsi/iscsi_target_debug.h | 113 + drivers/target/iscsi/iscsi_target_device.c | 124 + drivers/target/iscsi/iscsi_target_device.h | 9 + drivers/target/iscsi/iscsi_target_erl0.c | 1080 +++++ drivers/target/iscsi/iscsi_target_erl0.h | 19 + drivers/target/iscsi/iscsi_target_erl1.c | 1378 ++++++ drivers/target/iscsi/iscsi_target_erl1.h | 35 + drivers/target/iscsi/iscsi_target_erl2.c | 529 ++ drivers/target/iscsi/iscsi_target_erl2.h | 20 + drivers/target/iscsi/iscsi_target_login.c | 1296 +++++ drivers/target/iscsi/iscsi_target_login.h | 13 + drivers/target/iscsi/iscsi_target_nego.c | 1069 ++++ drivers/target/iscsi/iscsi_target_nego.h | 19 + drivers/target/iscsi/iscsi_target_nodeattrib.c | 264 + drivers/target/iscsi/iscsi_target_nodeattrib.h | 14 + drivers/target/iscsi/iscsi_target_parameters.c | 2052 ++++++++ drivers/target/iscsi/iscsi_target_parameters.h | 271 ++ drivers/target/iscsi/iscsi_target_seq_pdu_list.c | 710 +++ drivers/target/iscsi/iscsi_target_seq_pdu_list.h | 88 + drivers/target/iscsi/iscsi_target_stat.c | 950 ++++ drivers/target/iscsi/iscsi_target_stat.h | 64 + drivers/target/iscsi/iscsi_target_tmr.c | 868 ++++ drivers/target/iscsi/iscsi_target_tmr.h | 16 + drivers/target/iscsi/iscsi_target_tpg.c | 999 ++++ drivers/target/iscsi/iscsi_target_tpg.h | 65 + drivers/target/iscsi/iscsi_target_tq.c | 640 +++ drivers/target/iscsi/iscsi_target_tq.h | 89 + drivers/target/iscsi/iscsi_target_util.c | 2611 ++++++++++ drivers/target/iscsi/iscsi_target_util.h | 127 + include/scsi/iscsi_proto.h | 30 +- 48 files changed, 24595 insertions(+), 19 deletions(-) create mode 100644 drivers/target/iscsi/Kconfig create mode 100644 drivers/target/iscsi/Makefile create mode 100644 drivers/target/iscsi/iscsi_target.c create mode 100644 drivers/target/iscsi/iscsi_target.h create mode 100644 drivers/target/iscsi/iscsi_target_auth.c create mode 100644 drivers/target/iscsi/iscsi_target_auth.h create mode 100644 drivers/target/iscsi/iscsi_target_configfs.c create mode 100644 drivers/target/iscsi/iscsi_target_configfs.h create mode 100644 drivers/target/iscsi/iscsi_target_core.h create mode 100644 drivers/target/iscsi/iscsi_target_datain_values.c create mode 100644 drivers/target/iscsi/iscsi_target_datain_values.h create mode 100644 drivers/target/iscsi/iscsi_target_debug.h create mode 100644 drivers/target/iscsi/iscsi_target_device.c create mode 100644 drivers/target/iscsi/iscsi_target_device.h create mode 100644 drivers/target/iscsi/iscsi_target_erl0.c create mode 100644 drivers/target/iscsi/iscsi_target_erl0.h create mode 100644 drivers/target/iscsi/iscsi_target_erl1.c create mode 100644 drivers/target/iscsi/iscsi_target_erl1.h create mode 100644 drivers/target/iscsi/iscsi_target_erl2.c create mode 100644 drivers/target/iscsi/iscsi_target_erl2.h create mode 100644 drivers/target/iscsi/iscsi_target_login.c create mode 100644 drivers/target/iscsi/iscsi_target_login.h create mode 100644 drivers/target/iscsi/iscsi_target_nego.c create mode 100644 drivers/target/iscsi/iscsi_target_nego.h create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.c create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.h create mode 100644 drivers/target/iscsi/iscsi_target_parameters.c create mode 100644 drivers/target/iscsi/iscsi_target_parameters.h create mode 100644 drivers/target/iscsi/iscsi_target_seq_pdu_list.c create mode 100644 drivers/target/iscsi/iscsi_target_seq_pdu_list.h create mode 100644 drivers/target/iscsi/iscsi_target_stat.c create mode 100644 drivers/target/iscsi/iscsi_target_stat.h create mode 100644 drivers/target/iscsi/iscsi_target_tmr.c create mode 100644 drivers/target/iscsi/iscsi_target_tmr.h create mode 100644 drivers/target/iscsi/iscsi_target_tpg.c create mode 100644 drivers/target/iscsi/iscsi_target_tpg.h create mode 100644 drivers/target/iscsi/iscsi_target_tq.c create mode 100644 drivers/target/iscsi/iscsi_target_tq.h create mode 100644 drivers/target/iscsi/iscsi_target_util.c create mode 100644 drivers/target/iscsi/iscsi_target_util.h
Signature · 1 line
1.7.4.1
RFC v3 1/12 iscsi: Resolve iscsi_proto.h naming conflicts with drivers/target/iscsi
From: Nicholas Bellinger <[email protected]>
This patch renames the following iscsi_proto.h structures to avoid namespace issues with drivers/target/iscsi/iscsi_target_core.h:
*) struct iscsi_cmd -> struct iscsi_scsi_req
*) struct iscsi_cmd_rsp -> struct iscsi_scsi_rsp
*) struct iscsi_login -> struct iscsi_login_req
This patch includes useful ISCSI_FLAG_LOGIN_[CURRENT,NEXT]_STAGE*, and ISCSI_FLAG_SNACK_TYPE_* definitions used by iscsi_target_mod, and fixes the incorrect definition of struct iscsi_snack to following RFC-3720 Section 10.16. SNACK Request.
Also, this patch updates libiscsi, iSER, be2iscsi, and bn2xi to use the updated structure definitions in a handful of locations.
--- drivers/infiniband/ulp/iser/iser_initiator.c | 2 +- drivers/scsi/be2iscsi/be_main.h | 4 +- drivers/scsi/bnx2i/bnx2i_hwi.c | 8 +++--- drivers/scsi/bnx2i/bnx2i_iscsi.c | 2 +- drivers/scsi/libiscsi.c | 6 ++-- include/scsi/iscsi_proto.h | 30 +++++++++++++++++++------- 6 files changed, 33 insertions(+), 19 deletions(-)
drivers/infiniband/ulp/iser/iser_initiator.c +1 -1
@@ -271,7 +271,7 @@ int iser_send_command(struct iscsi_conn *conn,unsigned long edtl;int err;struct iser_data_buf *data_buf; -struct iscsi_cmd *hdr = (struct iscsi_cmd *)task->hdr; +struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *)task->hdr;struct scsi_cmnd *sc = task->sc;struct iser_tx_desc *tx_desc = &iser_task->desc;
drivers/scsi/be2iscsi/be_main.h +2 -2
@@ -398,7 +398,7 @@ struct amap_pdu_data_out { };struct be_cmd_bhs { -struct iscsi_cmd iscsi_hdr; +struct iscsi_scsi_req iscsi_hdr;unsigned char pad1[16 ];struct pdu_data_out iscsi_data_pdu; unsigned char pad2[BE_SENSE_INFO_SIZE -
@@ -429,7 +429,7 @@ struct be_nonio_bhs { };struct be_status_bhs { -struct iscsi_cmd iscsi_hdr; +struct iscsi_scsi_req iscsi_hdr;unsigned char pad1[16 ];/** * The plus 2 below is to hold the sense info length that gets
drivers/scsi/bnx2i/bnx2i_hwi.c +4 -4
@@ -326,11 +326,11 @@ int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn, {struct bnx2i_cmd *bnx2i_cmd;struct bnx2i_login_request *login_wqe; -struct iscsi_login *login_hdr; +struct iscsi_login_req *login_hdr;u32 dword; bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data; - login_hdr = (struct iscsi_login *)task->hdr; + login_hdr = (struct iscsi_login_req *)task->hdr; login_wqe = (struct bnx2i_login_request *) bnx2i_conn->ep->qp.sq_prod_qe;
@@ -1288,7 +1288,7 @@ static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,struct bnx2i_cmd_response *resp_cqe;struct bnx2i_cmd *bnx2i_cmd;struct iscsi_task *task; -struct iscsi_cmd_rsp *hdr; +struct iscsi_scsi_rsp *hdr;u32 datalen =0 ; resp_cqe = (struct bnx2i_cmd_response *)cqe;
@@ -1315,7 +1315,7 @@ static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session, }bnx2i_iscsi_unmap_sg_list (bnx2i_cmd); - hdr = (struct iscsi_cmd_rsp *)task->hdr; + hdr = (struct iscsi_scsi_rsp *)task->hdr; resp_cqe = (struct bnx2i_cmd_response *)cqe; hdr->opcode = resp_cqe->op_code; hdr->max_cmdsn =cpu_to_be32 (resp_cqe->max_cmd_sn);
drivers/scsi/bnx2i/bnx2i_iscsi.c +1 -1
@@ -1203,7 +1203,7 @@ static int bnx2i_task_xmit(struct iscsi_task *task)struct bnx2i_conn *bnx2i_conn = conn->dd_data;struct scsi_cmnd *sc = task->sc;struct bnx2i_cmd *cmd = task->dd_data; -struct iscsi_cmd *hdr = (struct iscsi_cmd *) task->hdr; +struct iscsi_scsi_req *hdr = (struct iscsi_scsi_req *) task->hdr;/* * If there is no scsi_cmnd this must be a mgmt task
drivers/scsi/libiscsi.c +3 -3
@@ -360,7 +360,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)struct iscsi_conn *conn = task->conn;struct iscsi_session *session = conn->session;struct scsi_cmnd *sc = task->sc; -struct iscsi_cmd *hdr; +struct iscsi_scsi_req *hdr;unsigned hdrlength, cmd_len;itt_t itt;int rc;
@@ -374,7 +374,7 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task *task)if (rc)return rc; } - hdr = (struct iscsi_cmd *) task->hdr; + hdr = (struct iscsi_scsi_req *) task->hdr; itt = hdr->itt;memset (hdr,0 ,sizeof (*hdr));
@@ -830,7 +830,7 @@ static void iscsi_scsi_cmd_rsp(struct iscsi_conn *conn, struct iscsi_hdr *hdr, struct iscsi_task *task, char *data, int datalen) { - struct iscsi_cmd_rsp *rhdr = (struct iscsi_cmd_rsp *)hdr; + struct iscsi_scsi_rsp *rhdr = (struct iscsi_scsi_rsp *)hdr;struct iscsi_session *session = conn->session;struct scsi_cmnd *sc = task->sc;
include/scsi/iscsi_proto.h +22 -8
@@ -116,7 +116,7 @@ struct iscsi_ahs_hdr {#define ISCSI_CDB_SIZE 16/* iSCSI PDU Header */ -struct iscsi_cmd { +struct iscsi_scsi_req {uint8_t opcode;uint8_t flags;__be16 rsvd2;
@@ -161,7 +161,7 @@ struct iscsi_ecdb_ahdr { };/* SCSI Response Header */ -struct iscsi_cmd_rsp { +struct iscsi_scsi_rsp {uint8_t opcode;uint8_t flags;uint8_t response;
@@ -406,7 +406,7 @@ struct iscsi_text_rsp { };/* Login Header */ -struct iscsi_login { +struct iscsi_login_req {uint8_t opcode;uint8_t flags;uint8_t max_version;/* Max. version supported */
@@ -427,7 +427,13 @@ struct iscsi_login {#define ISCSI_FLAG_LOGIN_TRANSIT 0x80#define ISCSI_FLAG_LOGIN_CONTINUE 0x40#define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C/* 2 bits */ +#define ISCSI_FLAG_LOGIN_CURRENT_STAGE1 0x04 +#define ISCSI_FLAG_LOGIN_CURRENT_STAGE2 0x08 +#define ISCSI_FLAG_LOGIN_CURRENT_STAGE3 0x0C#define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03/* 2 bits */ +#define ISCSI_FLAG_LOGIN_NEXT_STAGE1 0x01 +#define ISCSI_FLAG_LOGIN_NEXT_STAGE2 0x02 +#define ISCSI_FLAG_LOGIN_NEXT_STAGE3 0x03#define ISCSI_LOGIN_CURRENT_STAGE (flags) \ ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
@@ -550,17 +556,25 @@ struct iscsi_logout_rsp {struct iscsi_snack {uint8_t opcode;uint8_t flags; -uint8_t rsvd2[14 ]; +uint8_t rsvd2[2 ]; +uint8_t hlength; +uint8_t dlength[3 ]; +uint8_t lun[8 ];itt_t itt; +__be32 ttt; +uint8_t rsvd3[4 ]; +__be32 exp_statsn; +uint8_t rsvd4[8 ];__be32 begrun;__be32 runlength; -__be32 exp_statsn; -__be32 rsvd3; -__be32 exp_datasn; -uint8_t rsvd6[8 ]; };/* SNACK PDU flags */ +#define ISCSI_FLAG_SNACK_TYPE_DATA 0 +#define ISCSI_FLAG_SNACK_TYPE_R2T 0 +#define ISCSI_FLAG_SNACK_TYPE_STATUS 1 +#define ISCSI_FLAG_SNACK_TYPE_DATA_ACK 2 +#define ISCSI_FLAG_SNACK_TYPE_RDATA 3#define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F/* 4 bits */ /* Reject Message Header */
Signature · 1 line
1.7.4.1
RFC v3 2/12 iscsi-target: Add primary iSCSI request/response state machine logic
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds iscsi_target.[c,h] containing the main iSCSI Request and Response PDU state machines and accompanying infrastructure code and base iscsi_target_core.h include for iscsi_target_mod. This includes support for all defined iSCSI operation codes from RFC-3720 Section 10.2.1.2 and primary state machines for per struct iscsi_conn RX/TX threads.
--- drivers/target/iscsi/iscsi_target.c | 5371 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target.h | 45 + drivers/target/iscsi/iscsi_target_core.h | 888 +++++ 3 files changed, 6304 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target.c create mode 100644 drivers/target/iscsi/iscsi_target.h create mode 100644 drivers/target/iscsi/iscsi_target_core.h
drivers/target/iscsi/iscsi_target.c new file +5371 -0
@@ -0,0 +1,5371 @@ +/******************************************************************************* +* This file contains main functions related to the iSCSI Target Core Driver. +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <linux/kthread.h> +#include <linux/crypto.h> +#include <linux/completion.h> +#include <asm/unaligned.h> +#include <scsi/iscsi_proto.h> +#include <target/target_core_base.h> +#include <target/target_core_tmr.h> +#include <target/target_core_transport.h> + +#include "iscsi_target_debug.h" +#include "iscsi_target_core.h" +#include "iscsi_target_parameters.h" +#include "iscsi_target_seq_pdu_list.h" +#include "iscsi_target_tq.h" +#include "iscsi_target_configfs.h" +#include "iscsi_target_datain_values.h" +#include "iscsi_target_erl0.h" +#include "iscsi_target_erl1.h" +#include "iscsi_target_erl2.h" +#include "iscsi_target_login.h" +#include "iscsi_target_tmr.h" +#include "iscsi_target_tpg.h" +#include "iscsi_target_util.h" +#include "iscsi_target.h" +#include "iscsi_target_device.h" +#include "iscsi_target_stat.h" + +LIST_HEAD (g_tiqn_list); +LIST_HEAD (g_np_list); +DEFINE_SPINLOCK (tiqn_lock); +DEFINE_SPINLOCK (np_lock); + +static struct idr tiqn_idr; +struct idr sess_idr; +struct mutex auth_id_lock; +spinlock_t sess_idr_lock; + +struct iscsi_global *iscsi_global; + +struct kmem_cache *lio_cmd_cache; +struct kmem_cache *lio_qr_cache; +struct kmem_cache *lio_dr_cache; +struct kmem_cache *lio_ooo_cache; +struct kmem_cache *lio_r2t_cache; + +static void iscsi_rx_thread_wait_for_tcp (struct iscsi_conn *); + +static int iscsi_handle_immediate_data (struct iscsi_cmd *, +unsigned char *buf,u32 ); +static inline int iscsi_send_data_in (struct iscsi_cmd *,struct iscsi_conn *, +struct se_unmap_sg *,int *); +static inline int iscsi_send_logout_response (struct iscsi_cmd *,struct iscsi_conn *); +static inline int iscsi_send_nopin_response (struct iscsi_cmd *,struct iscsi_conn *); +static inline int iscsi_send_status (struct iscsi_cmd *,struct iscsi_conn *); +static int iscsi_send_task_mgt_rsp (struct iscsi_cmd *,struct iscsi_conn *); +static int iscsi_send_text_rsp (struct iscsi_cmd *,struct iscsi_conn *); +static int iscsi_send_reject (struct iscsi_cmd *,struct iscsi_conn *); +static int iscsi_logout_post_handler (struct iscsi_cmd *,struct iscsi_conn *); + +struct iscsi_tiqn *iscsit_get_tiqn_for_login (unsigned char *buf) +{ +struct iscsi_tiqn *tiqn =NULL ; + +spin_lock (&tiqn_lock); +list_for_each_entry (tiqn, &g_tiqn_list, tiqn_list) { +if (!strcmp (tiqn->tiqn, buf)) { + +spin_lock (&tiqn->tiqn_state_lock); +if (tiqn->tiqn_state ==TIQN_STATE_ACTIVE ) { + tiqn->tiqn_access_count++; +spin_unlock (&tiqn->tiqn_state_lock); +spin_unlock (&tiqn_lock); +return tiqn; + } +spin_unlock (&tiqn->tiqn_state_lock); + } + } +spin_unlock (&tiqn_lock); + +return NULL ; +} + +static int iscsit_set_tiqn_shutdown (struct iscsi_tiqn *tiqn) +{ +spin_lock (&tiqn->tiqn_state_lock); +if (tiqn->tiqn_state ==TIQN_STATE_ACTIVE ) { + tiqn->tiqn_state =TIQN_STATE_SHUTDOWN ; +spin_unlock (&tiqn->tiqn_state_lock); +return 0 ; + } +spin_unlock (&tiqn->tiqn_state_lock); + +return -1 ; +} + +void iscsit_put_tiqn_for_login (struct iscsi_tiqn *tiqn) +{ +spin_lock (&tiqn->tiqn_state_lock); + tiqn->tiqn_access_count--; +spin_unlock (&tiqn->tiqn_state_lock); +} + +/* +* Note that IQN formatting is expected to be done in userspace, and +* no explict IQN format checks are done here. +*/ +struct iscsi_tiqn *iscsit_add_tiqn (unsigned char *buf,int *ret) +{ +struct iscsi_tiqn *tiqn =NULL ; + +if (strlen (buf) >ISCSI_IQN_LEN ) { +printk (KERN_ERR "Target IQN exceeds %d bytes\n" , +ISCSI_IQN_LEN ); + *ret =-1 ; +return NULL ; + } + +spin_lock (&tiqn_lock); +list_for_each_entry (tiqn, &g_tiqn_list, tiqn_list) { +if (!strcmp (tiqn->tiqn, buf)) { +printk (KERN_ERR "Target IQN: %s already exists in Core\n" , + tiqn->tiqn); +spin_unlock (&tiqn_lock); + *ret =-1 ; +return NULL ; + } + } +spin_unlock (&tiqn_lock); + + tiqn =kzalloc (sizeof (struct iscsi_tiqn ),GFP_KERNEL ); +if (!tiqn) { +printk (KERN_ERR "Unable to allocate struct iscsi_tiqn\n" ); + *ret =-1 ; +return NULL ; + } + +sprintf (tiqn->tiqn,"%s" , buf); +INIT_LIST_HEAD (&tiqn->tiqn_list); +INIT_LIST_HEAD (&tiqn->tiqn_tpg_list); +spin_lock_init (&tiqn->tiqn_state_lock); +spin_lock_init (&tiqn->tiqn_tpg_lock); +spin_lock_init (&tiqn->sess_err_stats.lock); +spin_lock_init (&tiqn->login_stats.lock); +spin_lock_init (&tiqn->logout_stats.lock); + +if (!idr_pre_get (&tiqn_idr,GFP_KERNEL )) { +printk (KERN_ERR "idr_pre_get() for tiqn_idr failed\n" ); +kfree (tiqn); + *ret =-1 ; +return NULL ; + } + tiqn->tiqn_state =TIQN_STATE_ACTIVE ; + +spin_lock (&tiqn_lock); +idr_get_new (&tiqn_idr,NULL , &tiqn->tiqn_index); +list_add_tail (&tiqn->tiqn_list, &g_tiqn_list); +spin_unlock (&tiqn_lock); + +printk (KERN_INFO "CORE[0] - Added iSCSI Target IQN: %s\n" , tiqn->tiqn); + +return tiqn; + +} + +void __iscsit_del_tiqn (struct iscsi_tiqn *tiqn) +{ +spin_lock (&tiqn_lock); +list_del (&tiqn->tiqn_list); +idr_remove (&tiqn_idr, tiqn->tiqn_index); +spin_unlock (&tiqn_lock); + +printk (KERN_INFO "CORE[0] - Deleted iSCSI Target IQN: %s\n" , + tiqn->tiqn); +kfree (tiqn); +} + +static void iscsit_wait_for_tiqn (struct iscsi_tiqn *tiqn) +{ +/* +* Wait for accesses to said struct iscsi_tiqn to end. +*/ +spin_lock (&tiqn->tiqn_state_lock); +while (tiqn->tiqn_access_count !=0 ) { +spin_unlock (&tiqn->tiqn_state_lock); +msleep (10 ); +spin_lock (&tiqn->tiqn_state_lock); + } +spin_unlock (&tiqn->tiqn_state_lock); +} + +void iscsit_del_tiqn (struct iscsi_tiqn *tiqn) +{ +/* +* iscsit_set_tiqn_shutdown sets tiqn->tiqn_state = TIQN_STATE_SHUTDOWN +* while holding tiqn->tiqn_state_lock. This means that all subsequent +* attempts to access this struct iscsi_tiqn will fail from both transport +* fabric and control code paths. +*/ +if (iscsit_set_tiqn_shutdown (tiqn) <0 ) { +printk (KERN_ERR "iscsit_set_tiqn_shutdown() failed\n" ); +return ; + } + +iscsit_wait_for_tiqn (tiqn); +__iscsit_del_tiqn (tiqn); +} + +int iscsit_access_np (struct iscsi_np *np,struct iscsi_portal_group *tpg) +{ +int ret; +/* +* Determine if the network portal is accepting storage traffic. +*/ +spin_lock_bh (&np->np_thread_lock); +if (np->np_thread_state !=ISCSI_NP_THREAD_ACTIVE ) { +spin_unlock_bh (&np->np_thread_lock); +return -1 ; + } +if (np->np_login_tpg) { +printk (KERN_ERR "np->np_login_tpg() is not NULL!\n" ); +spin_unlock_bh (&np->np_thread_lock); +return -1 ; + } +spin_unlock_bh (&np->np_thread_lock); +/* +* Determine if the portal group is accepting storage traffic. +*/ +spin_lock_bh (&tpg->tpg_state_lock); +if (tpg->tpg_state !=TPG_STATE_ACTIVE ) { +spin_unlock_bh (&tpg->tpg_state_lock); +return -1 ; + } +spin_unlock_bh (&tpg->tpg_state_lock); + +/* +* Here we serialize access across the TIQN+TPG Tuple. +*/ + ret =mutex_lock_interruptible (&tpg->np_login_lock); +if ((ret !=0 ) ||signal_pending (current)) +return -1 ; + +spin_lock_bh (&tpg->tpg_state_lock); +if (tpg->tpg_state !=TPG_STATE_ACTIVE ) { +spin_unlock_bh (&tpg->tpg_state_lock); +return -1 ; + } +spin_unlock_bh (&tpg->tpg_state_lock); + +spin_lock_bh (&np->np_thread_lock); + np->np_login_tpg = tpg; +spin_unlock_bh (&np->np_thread_lock); + +return 0 ; +} + +int iscsit_deaccess_np (struct iscsi_np *np,struct iscsi_portal_group *tpg) +{ +struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; + +spin_lock_bh (&np->np_thread_lock); + np->np_login_tpg =NULL ; +spin_unlock_bh (&np->np_thread_lock); + +mutex_unlock (&tpg->np_login_lock); + +if (tiqn) +iscsit_put_tiqn_for_login (tiqn); + +return 0 ; +} + +static struct iscsi_np *iscsit_get_np ( +unsigned char *ipv6, +u32 ipv4, +u16 port, +int network_transport) +{ +struct iscsi_np *np; +void *p, *ip; +int net_size; + +spin_lock (&np_lock); +list_for_each_entry (np, &g_np_list, np_list) { +spin_lock (&np->np_state_lock); +if (atomic_read (&np->np_shutdown)) { +spin_unlock (&np->np_state_lock); +continue ; + } +spin_unlock (&np->np_state_lock); + +if (ipv6 !=NULL ) { + p = (void *)&np->np_ipv6[0 ]; + ip = (void *)ipv6; + net_size =IPV6_ADDRESS_SPACE ; + }else { + p = (void *)&np->np_ipv4; + ip = (void *)&ipv4; + net_size =IPV4_ADDRESS_SPACE ; + } + +if (!memcmp (p, ip, net_size) && (np->np_port == port) && + (np->np_network_transport == network_transport)) { +spin_unlock (&np_lock); +return np; + } + } +spin_unlock (&np_lock); + +return NULL ; +} + +struct iscsi_np *iscsit_add_np ( +struct iscsi_np_addr *np_addr, +int network_transport) +{ +struct iscsi_np *np; +char *ip_buf =NULL , *ipv6 =NULL ; +unsigned char buf_ipv4[IPV4_BUF_SIZE ]; +u32 ipv4 =0 ; +int ret; + +if (np_addr->np_flags &NPF_NET_IPV6 ) { + ip_buf = &np_addr->np_ipv6[0 ]; + ipv6 = &np_addr->np_ipv6[0 ]; + }else { +memset (buf_ipv4,0 ,IPV4_BUF_SIZE ); +iscsi_ntoa2 (buf_ipv4, np_addr->np_ipv4); + ip_buf = &buf_ipv4[0 ]; + ipv4 = np_addr->np_ipv4; + } +/* +* Locate the existing struct iscsi_np if already active.. +*/ + np =iscsit_get_np (ipv6, ipv4, np_addr->np_port, network_transport); +if (np) +return np; + + np =kzalloc (sizeof (struct iscsi_np ),GFP_KERNEL ); +if (!np) { +printk (KERN_ERR "Unable to allocate memory for struct iscsi_np\n" ); +return ERR_PTR (-ENOMEM ); + } + + np->np_flags |=NPF_IP_NETWORK ; +if (np_addr->np_flags &NPF_NET_IPV6 ) { + np->np_flags |=NPF_NET_IPV6 ; +memcpy (np->np_ipv6, np_addr->np_ipv6,IPV6_ADDRESS_SPACE ); + }else { + np->np_flags |=NPF_NET_IPV4 ; + np->np_ipv4 = np_addr->np_ipv4; + } + np->np_port = np_addr->np_port; + np->np_network_transport = network_transport; +atomic_set (&np->np_shutdown,0 ); +spin_lock_init (&np->np_state_lock); +spin_lock_init (&np->np_thread_lock); +init_completion (&np->np_restart_comp); +INIT_LIST_HEAD (&np->np_list); + + ret =iscsi_target_setup_login_socket (np); +if (ret !=0 ) { +kfree (np); +return ERR_PTR (ret); + } + + np->np_thread =kthread_run (iscsi_target_login_thread, np,"iscsi_np" ); +if (IS_ERR (np->np_thread)) { +printk (KERN_ERR "Unable to create kthread: iscsi_np\n" ); + ret =PTR_ERR (np->np_thread); +kfree (np); +return ERR_PTR (ret); + } +spin_lock (&np_lock); +list_add_tail (&np->np_list, &g_np_list); +spin_unlock (&np_lock); + +printk (KERN_INFO "CORE[0] - Added Network Portal: %s:%hu on %s on" +" network device: %s\n" , ip_buf, np->np_port, + (np->np_network_transport ==ISCSI_TCP ) ? +"TCP" :"SCTP" , (strlen (np->np_net_dev)) ? + (char *)np->np_net_dev :"None" ); + +return np; +} + +int iscsit_reset_np_thread ( +struct iscsi_np *np, +struct iscsi_tpg_np *tpg_np, +struct iscsi_portal_group *tpg) +{ +spin_lock_bh (&np->np_thread_lock); +if (tpg && tpg_np) { +/* +* The reset operation need only be performed when the +* passed struct iscsi_portal_group has a login in progress +* to one of the network portals. +*/ +if (tpg_np->tpg_np->np_login_tpg != tpg) { +spin_unlock_bh (&np->np_thread_lock); +return 0 ; + } + } +if (np->np_thread_state ==ISCSI_NP_THREAD_INACTIVE ) { +spin_unlock_bh (&np->np_thread_lock); +return 0 ; + } + np->np_thread_state =ISCSI_NP_THREAD_RESET ; + +if (np->np_thread) { +spin_unlock_bh (&np->np_thread_lock); +send_sig (SIGINT , np->np_thread,1 ); +wait_for_completion (&np->np_restart_comp); +spin_lock_bh (&np->np_thread_lock); + } +spin_unlock_bh (&np->np_thread_lock); + +return 0 ; +} + +int iscsit_del_np_thread (struct iscsi_np *np) +{ +spin_lock_bh (&np->np_thread_lock); + np->np_thread_state =ISCSI_NP_THREAD_SHUTDOWN ; +atomic_set (&np->np_shutdown,1 ); +spin_unlock_bh (&np->np_thread_lock); + +if (np->np_thread) { +/* +* We need to send the signal to wakeup Linux/Net +* sock_accept().. +*/ +send_sig (SIGINT , np->np_thread,1 ); +kthread_stop (np->np_thread); + } + +return 0 ; +} + +int iscsit_del_np_comm (struct iscsi_np *np) +{ +if (!np->np_socket) +return 0 ; + +/* +* Some network transports allocate their own struct sock->file, +* see if we need to free any additional allocated resources. +*/ +if (np->np_flags &NPF_SCTP_STRUCT_FILE ) { +kfree (np->np_socket->file); + np->np_socket->file =NULL ; + } + +sock_release (np->np_socket); +return 0 ; +} + +int iscsit_del_np (struct iscsi_np *np) +{ +unsigned char *ip =NULL ; +unsigned char buf_ipv4[IPV4_BUF_SIZE ]; + +iscsit_del_np_thread (np); +iscsit_del_np_comm (np); + +spin_lock (&np_lock); +list_del (&np->np_list); +spin_unlock (&np_lock); + +if (np->np_flags &NPF_NET_IPV6 ) { + ip = &np->np_ipv6[0 ]; + }else { +memset (buf_ipv4,0 ,IPV4_BUF_SIZE ); +iscsi_ntoa2 (buf_ipv4, np->np_ipv4); + ip = &buf_ipv4[0 ]; + } + +printk (KERN_INFO "CORE[0] - Removed Network Portal: %s:%hu on %s on" +" network device: %s\n" , ip, np->np_port, + (np->np_network_transport ==ISCSI_TCP ) ? +"TCP" :"SCTP" , (strlen (np->np_net_dev)) ? + (char *)np->np_net_dev :"None" ); + +kfree (np); +return 0 ; +} + +static int __init iscsi_target_init_module (void ) +{ +int ret =0 ; + +printk (KERN_INFO "RisingTide Systems iSCSI-Target " ISCSI_VERSION "\n" ); + + iscsi_global =kzalloc (sizeof (struct iscsi_global ),GFP_KERNEL ); +if (!iscsi_global) { +printk (KERN_ERR "Unable to allocate memory for iscsi_global\n" ); +return -1 ; + } +mutex_init (&auth_id_lock); +spin_lock_init (&sess_idr_lock); +idr_init (&tiqn_idr); +idr_init (&sess_idr); + + ret =iscsi_target_register_configfs (); +if (ret <0 ) + goto out; + + ret =iscsi_thread_set_init (); +if (ret <0 ) + goto configfs_out; + +if (iscsi_allocate_thread_sets (TARGET_THREAD_SET_COUNT ) != +TARGET_THREAD_SET_COUNT ) { +printk (KERN_ERR "iscsi_allocate_thread_sets() returned" +" unexpected value!\n" ); + goto ts_out1; + } + + lio_cmd_cache =kmem_cache_create ("lio_cmd_cache" , +sizeof (struct iscsi_cmd ), __alignof__(struct iscsi_cmd ), +0 ,NULL ); +if (!lio_cmd_cache) { +printk (KERN_ERR "Unable to kmem_cache_create() for" +" lio_cmd_cache\n" ); + goto ts_out2; + } + + lio_qr_cache =kmem_cache_create ("lio_qr_cache" , +sizeof (struct iscsi_queue_req ), + __alignof__(struct iscsi_queue_req ),0 ,NULL ); +if (!lio_qr_cache) { +printk (KERN_ERR "nable to kmem_cache_create() for" +" lio_qr_cache\n" ); + goto cmd_out; + } + + lio_dr_cache =kmem_cache_create ("lio_dr_cache" , +sizeof (struct iscsi_datain_req ), + __alignof__(struct iscsi_datain_req ),0 ,NULL ); +if (!lio_dr_cache) { +printk (KERN_ERR "Unable to kmem_cache_create() for" +" lio_dr_cache\n" ); + goto qr_out; + } + + lio_ooo_cache =kmem_cache_create ("lio_ooo_cache" , +sizeof (struct iscsi_ooo_cmdsn ), + __alignof__(struct iscsi_ooo_cmdsn ),0 ,NULL ); +if (!lio_ooo_cache) { +printk (KERN_ERR "Unable to kmem_cache_create() for" +" lio_ooo_cache\n" ); + goto dr_out; + } + + lio_r2t_cache =kmem_cache_create ("lio_r2t_cache" , +sizeof (struct iscsi_r2t ), __alignof__(struct iscsi_r2t ), +0 ,NULL ); +if (!lio_r2t_cache) { +printk (KERN_ERR "Unable to kmem_cache_create() for" +" lio_r2t_cache\n" ); + goto ooo_out; + } + +if (iscsit_load_discovery_tpg () <0 ) + goto r2t_out; + +printk ("Loading Complete.\n" ); + +return ret; +r2t_out: +kmem_cache_destroy (lio_r2t_cache); +ooo_out: +kmem_cache_destroy (lio_ooo_cache); +dr_out: +kmem_cache_destroy (lio_dr_cache); +qr_out: +kmem_cache_destroy (lio_qr_cache); +cmd_out: +kmem_cache_destroy (lio_cmd_cache); +ts_out2: +iscsi_deallocate_thread_sets (); +ts_out1: +iscsi_thread_set_free (); +configfs_out: +iscsi_target_deregister_configfs (); +out: +kfree (iscsi_global); + iscsi_global =NULL ; + +return -1 ; +} + +static void __exit iscsi_target_cleanup_module(void) +{ +iscsi_deallocate_thread_sets (); +iscsi_thread_set_free (); +iscsit_release_discovery_tpg (); +kmem_cache_destroy (lio_cmd_cache); +kmem_cache_destroy (lio_qr_cache); +kmem_cache_destroy (lio_dr_cache); +kmem_cache_destroy (lio_ooo_cache); +kmem_cache_destroy (lio_r2t_cache); + +iscsi_target_deregister_configfs (); + +kfree (iscsi_global); +printk (KERN_INFO "Unloading Complete.\n" ); +} + +char *iscsi_get_fabric_name (void ) +{ +return "iSCSI" ; +} + +struct iscsi_cmd *iscsi_get_cmd (struct se_cmd *se_cmd) +{ + struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); + +return cmd; +} + +u32 iscsi_get_task_tag (struct se_cmd *se_cmd) +{ + struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); + +return cmd->init_task_tag; +} + +int iscsi_get_cmd_state (struct se_cmd *se_cmd) +{ + struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); + +return cmd->i_state; +} + +void iscsi_new_cmd_failure (struct se_cmd *se_cmd) +{ +struct iscsi_cmd *cmd =iscsi_get_cmd (se_cmd); + +if (cmd->immediate_data || cmd->unsolicited_data) +complete (&cmd->unsolicited_data_comp); +} + +int iscsi_is_state_remove (struct se_cmd *se_cmd) +{ +struct iscsi_cmd *cmd =iscsi_get_cmd (se_cmd); + +return (cmd->i_state ==ISTATE_REMOVE ); +} + +int lio_sess_logged_in (struct se_session *se_sess) +{ +struct iscsi_session *sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +int ret; + +/* +* Called with spin_lock_bh(&se_global->se_tpg_lock); and +* spin_lock(&se_tpg->session_lock); held. +*/ +spin_lock (&sess->conn_lock); + ret = (sess->session_state !=TARG_SESS_STATE_LOGGED_IN ); +spin_unlock (&sess->conn_lock); + +return ret; +} + +u32 lio_sess_get_index (struct se_session *se_sess) +{ +struct iscsi_session *sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; + +return sess->session_index; +} + +u32 lio_sess_get_initiator_sid ( +struct se_session *se_sess, +unsigned char *buf, +u32 size) +{ +struct iscsi_session *sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +/* +* iSCSI Initiator Session Identifier from RFC-3720. +*/ +return snprintf (buf, size,"%02x%02x%02x%02x%02x%02x" , + sess->isid[0 ], sess->isid[1 ], sess->isid[2 ], + sess->isid[3 ], sess->isid[4 ], sess->isid[5 ]); +} + +int iscsi_add_nopin ( +struct iscsi_conn *conn, +int want_response) +{ +u8 state; +struct iscsi_cmd *cmd; + + cmd =iscsi_allocate_cmd (conn); +if (!cmd) +return -1 ; + + cmd->iscsi_opcode =ISCSI_OP_NOOP_IN ; + state = (want_response) ?ISTATE_SEND_NOPIN_WANT_RESPONSE : +ISTATE_SEND_NOPIN_NO_RESPONSE ; + cmd->init_task_tag =0xFFFFFFFF ; +spin_lock_bh (&conn->sess->ttt_lock); + cmd->targ_xfer_tag = (want_response) ? conn->sess->targ_xfer_tag++ : +0xFFFFFFFF ; +if (want_response && (cmd->targ_xfer_tag ==0xFFFFFFFF )) + cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; +spin_unlock_bh (&conn->sess->ttt_lock); + +iscsi_attach_cmd_to_queue (conn, cmd); +if (want_response) +iscsi_start_nopin_response_timer (conn); +iscsi_add_cmd_to_immediate_queue (cmd, conn, state); + +return 0 ; +} + +int iscsi_add_reject ( +u8 reason, +int fail_conn, +unsigned char *buf, +struct iscsi_conn *conn) +{ +struct iscsi_cmd *cmd; +struct iscsi_reject *hdr; +int ret; + + cmd =iscsi_allocate_cmd (conn); +if (!cmd) +return -1 ; + + cmd->iscsi_opcode =ISCSI_OP_REJECT ; +if (fail_conn) + cmd->cmd_flags |=ICF_REJECT_FAIL_CONN ; + + hdr = (struct iscsi_reject *) cmd->pdu; + hdr->reason = reason; + + cmd->buf_ptr =kzalloc (ISCSI_HDR_LEN ,GFP_ATOMIC ); +if (!cmd->buf_ptr) { +printk (KERN_ERR "Unable to allocate memory for cmd->buf_ptr\n" ); +__iscsi_release_cmd_to_pool (cmd, conn->sess); +return -1 ; + } +memcpy (cmd->buf_ptr, buf,ISCSI_HDR_LEN ); + +iscsi_attach_cmd_to_queue (conn, cmd); + + cmd->i_state =ISTATE_SEND_REJECT ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); + + ret =wait_for_completion_interruptible (&cmd->reject_comp); +if (ret !=0 ) +return -1 ; + +return (!fail_conn) ?0 :-1 ; +} + +/* iscsi_add_reject_from_cmd(): +* +* +*/ +int iscsi_add_reject_from_cmd ( +u8 reason, +int fail_conn, +int add_to_conn, +unsigned char *buf, +struct iscsi_cmd *cmd) +{ +struct iscsi_conn *conn; +struct iscsi_reject *hdr; +int ret; + +if (!cmd->conn) { +printk (KERN_ERR "cmd->conn is NULL for ITT: 0x%08x\n" , + cmd->init_task_tag); +return -1 ; + } + conn = cmd->conn; + + cmd->iscsi_opcode =ISCSI_OP_REJECT ; +if (fail_conn) + cmd->cmd_flags |=ICF_REJECT_FAIL_CONN ; + + hdr = (struct iscsi_reject *) cmd->pdu; + hdr->reason = reason; + + cmd->buf_ptr =kzalloc (ISCSI_HDR_LEN ,GFP_ATOMIC ); +if (!cmd->buf_ptr) { +printk (KERN_ERR "Unable to allocate memory for cmd->buf_ptr\n" ); +__iscsi_release_cmd_to_pool (cmd, conn->sess); +return -1 ; + } +memcpy (cmd->buf_ptr, buf,ISCSI_HDR_LEN ); + +if (add_to_conn) +iscsi_attach_cmd_to_queue (conn, cmd); + + cmd->i_state =ISTATE_SEND_REJECT ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); + + ret =wait_for_completion_interruptible (&cmd->reject_comp); +if (ret !=0 ) +return -1 ; + +return (!fail_conn) ?0 :-1 ; +} + +/* #define iscsi_calculate_map_segment_DEBUG */ +#ifdef iscsi_calculate_map_segment_DEBUG +#define DEBUG_MAP_SEGMENTS(buf...) PYXPRINT(buf) +#else +#define DEBUG_MAP_SEGMENTS(buf...) +#endif + +static inline void iscsi_calculate_map_segment ( +u32 *data_length, +struct se_offset_map *lm) +{ +u32 sg_offset =0 ; +struct se_mem *se_mem = lm->map_se_mem; + +DEBUG_MAP_SEGMENTS (" START Mapping se_mem: %p, Length: %d" +" Remaining iSCSI Data: %u\n" , se_mem, se_mem->se_len, + *data_length); +/* +* Still working on pages in the current struct se_mem. +*/ +if (!lm->map_reset) { + lm->iovec_length = (lm->sg_length >PAGE_SIZE ) ? +PAGE_SIZE : lm->sg_length; +if (*data_length < lm->iovec_length) { +DEBUG_MAP_SEGMENTS ("LINUX_MAP: Reset lm->iovec_length" +" to %d\n" , *data_length); + + lm->iovec_length = *data_length; + } + lm->iovec_base =page_address (lm->sg_page) + sg_offset; + +DEBUG_MAP_SEGMENTS ("LINUX_MAP: Set lm->iovec_base to %p from" +" lm->sg_page: %p\n" , lm->iovec_base, lm->sg_page); +return ; + } + +/* +* First run of an iscsi_linux_map_t. +* +* OR: +* +* Mapped all of the pages in the current scatterlist, move +* on to the next one. +*/ + lm->map_reset =0 ; + sg_offset = se_mem->se_off; + lm->sg_page = se_mem->se_page; + lm->sg_length = se_mem->se_len; + +DEBUG_MAP_SEGMENTS ("LINUX_MAP1[%p]: Starting to se_mem->se_len: %u," +" se_mem->se_off: %u, se_mem->se_page: %p\n" , se_mem, + se_mem->se_len, se_mem->se_off, se_mem->se_page); +/* +* Get the base and length of the current page for use with the iovec. +*/ +recalc: + lm->iovec_length = (lm->sg_length > (PAGE_SIZE - sg_offset)) ? + (PAGE_SIZE - sg_offset) : lm->sg_length; + +DEBUG_MAP_SEGMENTS ("LINUX_MAP: lm->iovec_length: %u, lm->sg_length: %u," +" sg_offset: %u\n" , lm->iovec_length, lm->sg_length, sg_offset); +/* +* See if there is any iSCSI offset we need to deal with. +*/ +if (!lm->current_offset) { + lm->iovec_base =page_address (lm->sg_page) + sg_offset; + +if (*data_length < lm->iovec_length) { +DEBUG_MAP_SEGMENTS ("LINUX_MAP1[%p]: Reset" +" lm->iovec_length to %d\n" , se_mem, + *data_length); + lm->iovec_length = *data_length; + } + +DEBUG_MAP_SEGMENTS ("LINUX_MAP2[%p]: No current_offset," +" set iovec_base to %p and set Current Page to %p\n" , + se_mem, lm->iovec_base, lm->sg_page); + +return ; + } + +/* +* We know the iSCSI offset is in the next page of the current +* scatterlist. Increase the lm->sg_page pointer and try again. +*/ +if (lm->current_offset >= lm->iovec_length) { +DEBUG_MAP_SEGMENTS ("LINUX_MAP3[%p]: Next Page:" +" lm->current_offset: %u, iovec_length: %u" +" sg_offset: %u\n" , se_mem, lm->current_offset, + lm->iovec_length, sg_offset); + + lm->current_offset -= lm->iovec_length; + lm->sg_length -= lm->iovec_length; + lm->sg_page++; + sg_offset =0 ; + +DEBUG_MAP_SEGMENTS ("LINUX_MAP3[%p]: ** Skipping to Next Page," +" updated values: lm->current_offset: %u\n" , se_mem, + lm->current_offset); + + goto recalc; + } + +/* +* The iSCSI offset is in the current page, increment the iovec +* base and reduce iovec length. +*/ + lm->iovec_base =page_address (lm->sg_page); + +DEBUG_MAP_SEGMENTS ("LINUX_MAP4[%p]: Set lm->iovec_base to %p\n" , se_mem, + lm->iovec_base); + + lm->iovec_base += sg_offset; + lm->iovec_base += lm->current_offset; +DEBUG_MAP_SEGMENTS ("****** the OLD lm->iovec_length: %u lm->sg_length:" +" %u\n" , lm->iovec_length, lm->sg_length); + +if ((lm->iovec_length - lm->current_offset) < *data_length) + lm->iovec_length -= lm->current_offset; +else + lm->iovec_length = *data_length; + +if ((lm->sg_length - lm->current_offset) < *data_length) + lm->sg_length -= lm->current_offset; +else + lm->sg_length = *data_length; + + lm->current_offset =0 ; + +DEBUG_MAP_SEGMENTS ("****** the NEW lm->iovec_length %u lm->sg_length:" +" %u\n" , lm->iovec_length, lm->sg_length); +} + +/* #define iscsi_linux_get_iscsi_offset_DEBUG */ +#ifdef iscsi_linux_get_iscsi_offset_DEBUG +#define DEBUG_GET_ISCSI_OFFSET(buf...) PYXPRINT(buf) +#else +#define DEBUG_GET_ISCSI_OFFSET(buf...) +#endif + +static int get_iscsi_offset ( +struct se_offset_map *lmap, +struct se_unmap_sg *usg) +{ +u32 current_length =0 , current_iscsi_offset = lmap->iscsi_offset; +u32 total_offset =0 ; +struct se_cmd *cmd = usg->se_cmd; +struct se_mem *se_mem; + +list_for_each_entry (se_mem,T_TASK (cmd)->t_mem_list, se_list) +break ; + +if (!se_mem) { +printk (KERN_ERR "Unable to locate se_mem from" +" T_TASK(cmd)->t_mem_list\n" ); +return -1 ; + } + +/* +* Locate the current offset from the passed iSCSI Offset. +*/ +while (lmap->iscsi_offset != current_length) { +/* +* The iSCSI Offset is within the current struct se_mem. +* +* Or: +* +* The iSCSI Offset is outside of the current struct se_mem. +* Recalculate the values and obtain the next struct se_mem pointer. +*/ + total_offset += se_mem->se_len; + +DEBUG_GET_ISCSI_OFFSET ("ISCSI_OFFSET: current_length: %u," +" total_offset: %u, sg->length: %u\n" , + current_length, total_offset, se_mem->se_len); + +if (total_offset > lmap->iscsi_offset) { + current_length += current_iscsi_offset; + lmap->orig_offset = lmap->current_offset = + usg->t_offset = current_iscsi_offset; +DEBUG_GET_ISCSI_OFFSET ("ISCSI_OFFSET: Within Current" +" struct se_mem: %p, current_length incremented to" +" %u\n" , se_mem, current_length); + }else { + current_length += se_mem->se_len; + current_iscsi_offset -= se_mem->se_len; + +DEBUG_GET_ISCSI_OFFSET ("ISCSI_OFFSET: Outside of" +" Current se_mem: %p, current_length" +" incremented to %u and current_iscsi_offset" +" decremented to %u\n" , se_mem, current_length, + current_iscsi_offset); + +list_for_each_entry_continue (se_mem, +T_TASK (cmd)->t_mem_list, se_list) +break ; + +if (!se_mem) { +printk (KERN_ERR "Unable to locate struct se_mem\n" ); +return -1 ; + } + } + } + lmap->map_orig_se_mem = se_mem; + usg->cur_se_mem = se_mem; + +return 0 ; +} + +/* #define iscsi_OS_set_SG_iovec_ptrs_DEBUG */ +#ifdef iscsi_OS_set_SG_iovec_ptrs_DEBUG +#define DEBUG_IOVEC_SCATTERLISTS(buf...) PYXPRINT(buf) + +static void iscsi_check_iovec_map ( +u32 iovec_count, +u32 map_length, +struct se_map_sg *map_sg, +struct se_unmap_sg *unmap_sg) +{ +u32 i, iovec_map_length =0 ; +struct se_cmd *cmd = map_sg->se_cmd; +struct iovec *iov = map_sg->iov; +struct se_mem *se_mem; + +for (i =0 ; i < iovec_count; i++) + iovec_map_length += iov[i].iov_len; + +if (iovec_map_length == map_length) +return ; + +printk (KERN_INFO "Calculated iovec_map_length: %u does not match passed" +" map_length: %u\n" , iovec_map_length, map_length); +printk (KERN_INFO "ITT: 0x%08x data_length: %u data_direction %d\n" , +CMD_TFO (cmd)->get_task_tag (cmd), cmd->data_length, + cmd->data_direction); + + iovec_map_length =0 ; + +for (i =0 ; i < iovec_count; i++) { +printk (KERN_INFO "iov[%d].iov_[base,len]: %p / %u bytes------" +"-->\n" , i, iov[i].iov_base, iov[i].iov_len); + +printk (KERN_INFO "iovec_map_length from %u to %u\n" , + iovec_map_length, iovec_map_length + iov[i].iov_len); + iovec_map_length += iov[i].iov_len; + +printk (KERN_INFO "XXXX_map_length from %u to %u\n" , map_length, + (map_length - iov[i].iov_len)); + map_length -= iov[i].iov_len; + } + +list_for_each_entry (se_mem,T_TASK (cmd)->t_mem_list, se_list) { +printk (KERN_INFO "se_mem[%p]: offset: %u length: %u\n" , + se_mem, se_mem->se_off, se_mem->se_len); + } + +BUG (); +} + +#else +#define DEBUG_IOVEC_SCATTERLISTS(buf...) +#define iscsi_check_iovec_map (a, b, c, d) +#endif + +static int iscsi_set_iovec_ptrs ( +struct se_map_sg *map_sg, +struct se_unmap_sg *unmap_sg) +{ +u32 i =0 /* For iovecs */ , j =0 /* For scatterlists */ ; +#ifdef iscsi_OS_set_SG_iovec_ptrs_DEBUG +u32 orig_map_length = map_sg->data_length; +#endif +struct se_cmd *cmd = map_sg->se_cmd; + struct iscsi_cmd *i_cmd = container_of(cmd, struct iscsi_cmd, se_cmd); +struct se_offset_map *lmap = &unmap_sg->lmap; +struct iovec *iov = map_sg->iov; + +/* +* Used for non scatterlist operations, assume a single iovec. +*/ +if (!T_TASK (cmd)->t_tasks_se_num) { +DEBUG_IOVEC_SCATTERLISTS ("ITT: 0x%08x No struct se_mem elements" +" present\n" ,CMD_TFO (cmd)->get_task_tag (cmd)); + iov[0 ].iov_base = (unsigned char *)T_TASK (cmd)->t_task_buf + + map_sg->data_offset; + iov[0 ].iov_len = map_sg->data_length; +return 1 ; + } + +/* +* Set lmap->map_reset = 1 so the first call to +* iscsi_calculate_map_segment() sets up the initial +* values for struct se_offset_map. +*/ + lmap->map_reset =1 ; + +DEBUG_IOVEC_SCATTERLISTS ("[-------------------] ITT: 0x%08x OS" +" Independent Network POSIX defined iovectors to SE Memory" +" [-------------------]\n\n" ,CMD_TFO (cmd)->get_task_tag (cmd)); + +/* +* Get a pointer to the first used scatterlist based on the passed +* offset. Also set the rest of the needed values in iscsi_linux_map_t. +*/ + lmap->iscsi_offset = map_sg->data_offset; +if (map_sg->sg_kmap_active) { + unmap_sg->se_cmd = map_sg->se_cmd; +get_iscsi_offset (lmap, unmap_sg); + unmap_sg->data_length = map_sg->data_length; + }else { + lmap->current_offset = lmap->orig_offset; + } + lmap->map_se_mem = lmap->map_orig_se_mem; + +DEBUG_IOVEC_SCATTERLISTS ("OS_IOVEC: Total map_sg->data_length: %d," +" lmap->iscsi_offset: %d, i_cmd->orig_iov_data_count: %d\n" , + map_sg->data_length, lmap->iscsi_offset, + i_cmd->orig_iov_data_count); + +while (map_sg->data_length) { +/* +* Time to get the virtual address for use with iovec pointers. +* This function will return the expected iovec_base address +* and iovec_length. +*/ +iscsi_calculate_map_segment (&map_sg->data_length, lmap); + +/* +* Set the iov.iov_base and iov.iov_len from the current values +* in iscsi_linux_map_t. +*/ + iov[i].iov_base = lmap->iovec_base; + iov[i].iov_len = lmap->iovec_length; + +/* +* Subtract the final iovec length from the total length to be +* mapped, and the length of the current scatterlist. Also +* perform the paranoid check to make sure we are not going to +* overflow the iovecs allocated for this command in the next +* pass. +*/ + map_sg->data_length -= iov[i].iov_len; + lmap->sg_length -= iov[i].iov_len; + +DEBUG_IOVEC_SCATTERLISTS ("OS_IOVEC: iov[%u].iov_len: %u\n" , + i, iov[i].iov_len); +DEBUG_IOVEC_SCATTERLISTS ("OS_IOVEC: lmap->sg_length: from %u" +" to %u\n" , lmap->sg_length + iov[i].iov_len, + lmap->sg_length); +DEBUG_IOVEC_SCATTERLISTS ("OS_IOVEC: Changed total" +" map_sg->data_length from %u to %u\n" , + map_sg->data_length + iov[i].iov_len, + map_sg->data_length); + +if ((++i +1 ) > i_cmd->orig_iov_data_count) { +printk (KERN_ERR "Current iovec count %u is greater than" +" struct se_cmd->orig_data_iov_count %u, cannot" +" continue.\n" , i+1 , i_cmd->orig_iov_data_count); +return -1 ; + } + +/* +* All done mapping this scatterlist's pages, move on to +* the next scatterlist by setting lmap.map_reset = 1; +*/ +if (!lmap->sg_length || !map_sg->data_length) { +list_for_each_entry (lmap->map_se_mem, + &lmap->map_se_mem->se_list, se_list) +break ; + +if (!lmap->map_se_mem) { +printk (KERN_ERR "Unable to locate next" +" lmap->map_struct se_mem entry\n" ); +return -1 ; + } + j++; + + lmap->sg_page =NULL ; + lmap->map_reset =1 ; + +DEBUG_IOVEC_SCATTERLISTS ("OS_IOVEC: Done with current" +" scatterlist, incremented Generic scatterlist" +" Counter to %d and reset = 1\n" , j); + }else + lmap->sg_page++; + } + + unmap_sg->sg_count = j; + +iscsi_check_iovec_map (i, orig_map_length, map_sg, unmap_sg); + +return i; +} + +static void iscsi_map_SG_segments (struct se_unmap_sg *unmap_sg) +{ +u32 i =0 ; +struct se_cmd *cmd = unmap_sg->se_cmd; +struct se_mem *se_mem = unmap_sg->cur_se_mem; + +if (!T_TASK (cmd)->t_tasks_se_num) +return ; + +list_for_each_entry_continue (se_mem,T_TASK (cmd)->t_mem_list, se_list) { +kmap (se_mem->se_page); + +if (++i == unmap_sg->sg_count) +break ; + } +} + +static void iscsi_unmap_SG_segments (struct se_unmap_sg *unmap_sg) +{ +u32 i =0 ; +struct se_cmd *cmd = unmap_sg->se_cmd; +struct se_mem *se_mem = unmap_sg->cur_se_mem; + +if (!T_TASK (cmd)->t_tasks_se_num) +return ; + +list_for_each_entry_continue (se_mem,T_TASK (cmd)->t_mem_list, se_list) { +kunmap (se_mem->se_page); + +if (++i == unmap_sg->sg_count) +break ; + } +} + +static inline int iscsi_handle_scsi_cmd ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +int data_direction, cmdsn_ret =0 , immed_ret, ret, transport_ret; +int dump_immediate_data =0 , send_check_condition =0 , payload_length; +struct iscsi_cmd *cmd =NULL ; +struct iscsi_scsi_req *hdr; + +spin_lock_bh (&conn->sess->session_stats_lock); + conn->sess->cmd_pdus++; +if (conn->sess->se_sess->se_node_acl) { +spin_lock (&conn->sess->se_sess->se_node_acl->stats_lock); + conn->sess->se_sess->se_node_acl->num_cmds++; +spin_unlock (&conn->sess->se_sess->se_node_acl->stats_lock); + } +spin_unlock_bh (&conn->sess->session_stats_lock); + + hdr = (struct iscsi_scsi_req *) buf; + payload_length =ntoh24 (hdr->dlength); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->data_length =be32_to_cpu (hdr->data_length); + hdr->cmdsn =be32_to_cpu (hdr->cmdsn); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + +/* FIXME; Add checks for AdditionalHeaderSegment */ + +if (!(hdr->flags &ISCSI_FLAG_CMD_WRITE ) && + !(hdr->flags &ISCSI_FLAG_CMD_FINAL )) { +printk (KERN_ERR "ISCSI_FLAG_CMD_WRITE & ISCSI_FLAG_CMD_FINAL" +" not set. Bad iSCSI Initiator.\n" ); +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_INVALID ,1 , + buf, conn); + } + +if (((hdr->flags &ISCSI_FLAG_CMD_READ ) || + (hdr->flags &ISCSI_FLAG_CMD_WRITE )) && !hdr->data_length) { +/* +* Vmware ESX v3.0 uses a modified Cisco Initiator (v3.4.2) +* that adds support for RESERVE/RELEASE. There is a bug +* add with this new functionality that sets R/W bits when +* neither CDB carries any READ or WRITE datapayloads. +*/ +if ((hdr->cdb[0 ] ==0x16 ) || (hdr->cdb[0 ] ==0x17 )) { + hdr->flags &= ~ISCSI_FLAG_CMD_READ ; + hdr->flags &= ~ISCSI_FLAG_CMD_WRITE ; + goto done; + } + +printk (KERN_ERR "ISCSI_FLAG_CMD_READ or ISCSI_FLAG_CMD_WRITE" +" set when Expected Data Transfer Length is 0 for" +" CDB: 0x%02x. Bad iSCSI Initiator.\n" , hdr->cdb[0 ]); +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_INVALID ,1 , + buf, conn); + } +done: + +if (!(hdr->flags &ISCSI_FLAG_CMD_READ ) && + !(hdr->flags &ISCSI_FLAG_CMD_WRITE ) && (hdr->data_length !=0 )) { +printk (KERN_ERR "ISCSI_FLAG_CMD_READ and/or ISCSI_FLAG_CMD_WRITE" +" MUST be set if Expected Data Transfer Length is not 0." +" Bad iSCSI Initiator\n" ); +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_INVALID ,1 , + buf, conn); + } + +if ((hdr->flags &ISCSI_FLAG_CMD_READ ) && + (hdr->flags &ISCSI_FLAG_CMD_WRITE )) { +printk (KERN_ERR "Bidirectional operations not supported!\n" ); +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_INVALID ,1 , + buf, conn); + } + +if (hdr->opcode &ISCSI_OP_IMMEDIATE ) { +printk (KERN_ERR "Illegally set Immediate Bit in iSCSI Initiator" +" Scsi Command PDU.\n" ); +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_INVALID ,1 , + buf, conn); + } + +if (payload_length && !conn->sess->sess_ops->ImmediateData) { +printk (KERN_ERR "ImmediateData=No but DataSegmentLength=%u," +" protocol error.\n" , payload_length); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } +#if 0 +if (!(hdr->flags &ISCSI_FLAG_CMD_FINAL ) && + (hdr->flags &ISCSI_FLAG_CMD_WRITE ) && conn->sess->sess_ops->InitialR2T) { +printk (KERN_ERR "ISCSI_FLAG_CMD_FINAL is not Set and" +" ISCSI_FLAG_CMD_WRITE Bit and InitialR2T=Yes," +" protocol error\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } +#endif +if ((hdr->data_length == payload_length) && + (!(hdr->flags &ISCSI_FLAG_CMD_FINAL ))) { +printk (KERN_ERR "Expected Data Transfer Length and Length of" +" Immediate Data are the same, but ISCSI_FLAG_CMD_FINAL" +" bit is not set protocol error\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +if (payload_length > hdr->data_length) { +printk (KERN_ERR "DataSegmentLength: %u is greater than" +" EDTL: %u, protocol error.\n" , payload_length, + hdr->data_length); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +if (payload_length > conn->conn_ops->MaxRecvDataSegmentLength) { +printk (KERN_ERR "DataSegmentLength: %u is greater than" +" MaxRecvDataSegmentLength: %u, protocol error.\n" , + payload_length, conn->conn_ops->MaxRecvDataSegmentLength); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +if (payload_length > conn->sess->sess_ops->FirstBurstLength) { +printk (KERN_ERR "DataSegmentLength: %u is greater than" +" FirstBurstLength: %u, protocol error.\n" , + payload_length, conn->sess->sess_ops->FirstBurstLength); +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_INVALID ,1 , + buf, conn); + } + + data_direction = (hdr->flags &ISCSI_FLAG_CMD_WRITE ) ?DMA_TO_DEVICE : + (hdr->flags &ISCSI_FLAG_CMD_READ ) ?DMA_FROM_DEVICE : +DMA_NONE ; + + cmd =iscsi_allocate_se_cmd (conn, hdr->data_length, data_direction, + (hdr->flags &ISCSI_FLAG_CMD_ATTR_MASK )); +if (!cmd) +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_NO_RESOURCES ,1 , + buf, conn); + +TRACE (TRACE_ISCSI ,"Got SCSI Command, ITT: 0x%08x, CmdSN: 0x%08x," +" ExpXferLen: %u, Length: %u, CID: %hu\n" , hdr->itt, + hdr->cmdsn, hdr->data_length, payload_length, conn->cid); + + cmd->iscsi_opcode =ISCSI_OP_SCSI_CMD ; + cmd->i_state =ISTATE_NEW_CMD ; + cmd->immediate_cmd = ((hdr->opcode &ISCSI_OP_IMMEDIATE ) ?1 :0 ); + cmd->immediate_data = (payload_length) ?1 :0 ; + cmd->unsolicited_data = ((!(hdr->flags &ISCSI_FLAG_CMD_FINAL ) && + (hdr->flags &ISCSI_FLAG_CMD_WRITE )) ?1 :0 ); +if (cmd->unsolicited_data) + cmd->cmd_flags |=ICF_NON_IMMEDIATE_UNSOLICITED_DATA ; + + conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; +if (hdr->flags &ISCSI_FLAG_CMD_READ ) { +spin_lock_bh (&conn->sess->ttt_lock); + cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; +if (cmd->targ_xfer_tag ==0xFFFFFFFF ) + cmd->targ_xfer_tag = conn->sess->targ_xfer_tag++; +spin_unlock_bh (&conn->sess->ttt_lock); + }else if (hdr->flags &ISCSI_FLAG_CMD_WRITE ) + cmd->targ_xfer_tag =0xFFFFFFFF ; + cmd->cmd_sn = hdr->cmdsn; + cmd->exp_stat_sn = hdr->exp_statsn; + cmd->first_burst_len = payload_length; + +if (cmd->data_direction ==DMA_FROM_DEVICE ) { +struct iscsi_datain_req *dr; + + dr =iscsi_allocate_datain_req (); +if (!dr) +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 ,1 , buf, cmd); + +iscsi_attach_datain_req (cmd, dr); + } + +/* +* The CDB is going to an se_device_t. +*/ + ret =iscsi_get_lun_for_cmd (cmd, hdr->cdb, +get_unaligned_le64 (&hdr->lun[0 ])); +if (ret <0 ) { +if (SE_CMD (cmd)->scsi_sense_reason ==TCM_NON_EXISTENT_LUN ) { +TRACE (TRACE_VANITY ,"Responding to non-acl'ed," +" non-existent or non-exported iSCSI LUN:" +" 0x%016Lx\n" ,get_unaligned_le64 (&hdr->lun[0 ])); + } +if (ret ==PYX_TRANSPORT_OUT_OF_MEMORY_RESOURCES ) +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 ,1 , buf, cmd); + + send_check_condition =1 ; + goto attach_cmd; + } +/* +* The Initiator Node has access to the LUN (the addressing method +* is handled inside of iscsi_get_lun_for_cmd()). Now it's time to +* allocate 1->N transport tasks (depending on sector count and +* maximum request size the physical HBA(s) can handle. +*/ + transport_ret =transport_generic_allocate_tasks (SE_CMD (cmd), hdr->cdb); +if (!transport_ret) + goto build_list; + +if (transport_ret ==-1 ) { +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 ,1 , buf, cmd); + }else if (transport_ret ==-2 ) { +/* +* Unsupported SAM Opcode. CHECK_CONDITION will be sent +* in iscsi_execute_cmd() during the CmdSN OOO Execution +* Mechinism. +*/ + send_check_condition =1 ; + goto attach_cmd; + } + +build_list: +if (iscsi_decide_list_to_build (cmd, payload_length) <0 ) +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 ,1 , buf, cmd); +attach_cmd: +iscsi_attach_cmd_to_queue (conn, cmd); +/* +* Check if we need to delay processing because of ALUA +* Active/NonOptimized primary access state.. +*/ +core_alua_check_nonop_delay (SE_CMD (cmd)); +/* +* Check the CmdSN against ExpCmdSN/MaxCmdSN here if +* the Immediate Bit is not set, and no Immediate +* Data is attached. +* +* A PDU/CmdSN carrying Immediate Data can only +* be processed after the DataCRC has passed. +* If the DataCRC fails, the CmdSN MUST NOT +* be acknowledged. (See below) +*/ +if (!cmd->immediate_data) { + cmdsn_ret =iscsi_check_received_cmdsn (conn, + cmd, hdr->cmdsn); +if ((cmdsn_ret ==CMDSN_NORMAL_OPERATION ) || + (cmdsn_ret ==CMDSN_HIGHER_THAN_EXP )) +do {}while (0 ); +else if (cmdsn_ret ==CMDSN_LOWER_THAN_EXP ) { + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, + conn, cmd->i_state); +return 0 ; + }else {/* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + } + } +iscsi_ack_from_expstatsn (conn, hdr->exp_statsn); + +/* +* If no Immediate Data is attached, it's OK to return now. +*/ +if (!cmd->immediate_data) { +if (send_check_condition) +return 0 ; + +if (cmd->unsolicited_data) { +iscsi_set_dataout_sequence_values (cmd); + +spin_lock_bh (&cmd->dataout_timeout_lock); +iscsi_start_dataout_timer (cmd, cmd->conn); +spin_unlock_bh (&cmd->dataout_timeout_lock); + } + +return 0 ; + } + +/* +* Early CHECK_CONDITIONs never make it to the transport processing +* thread. They are processed in CmdSN order by +* iscsi_check_received_cmdsn() below. +*/ +if (send_check_condition) { + immed_ret =IMMEDIDATE_DATA_NORMAL_OPERATION ; + dump_immediate_data =1 ; + goto after_immediate_data; + } + +/* +* Immediate Data is present, send to the transport and block until +* the underlying transport plugin has allocated the buffer to +* receive the Immediate Write Data into. +*/ +transport_generic_handle_cdb (SE_CMD (cmd)); + +wait_for_completion (&cmd->unsolicited_data_comp); + +if (SE_CMD (cmd)->se_cmd_flags &SCF_SE_CMD_FAILED ) { + immed_ret =IMMEDIDATE_DATA_NORMAL_OPERATION ; + dump_immediate_data =1 ; + goto after_immediate_data; + } + + immed_ret =iscsi_handle_immediate_data (cmd, buf, payload_length); +after_immediate_data: +if (immed_ret ==IMMEDIDATE_DATA_NORMAL_OPERATION ) { +/* +* A PDU/CmdSN carrying Immediate Data passed +* DataCRC, check against ExpCmdSN/MaxCmdSN if +* Immediate Bit is not set. +*/ + cmdsn_ret =iscsi_check_received_cmdsn (conn, + cmd, hdr->cmdsn); +/* +* Special case for Unsupported SAM WRITE Opcodes +* and ImmediateData=Yes. +*/ +if (dump_immediate_data) { +if (iscsi_dump_data_payload (conn, payload_length,1 ) <0 ) +return -1 ; + }else if (cmd->unsolicited_data) { +iscsi_set_dataout_sequence_values (cmd); + +spin_lock_bh (&cmd->dataout_timeout_lock); +iscsi_start_dataout_timer (cmd, cmd->conn); +spin_unlock_bh (&cmd->dataout_timeout_lock); + } + +if (cmdsn_ret ==CMDSN_NORMAL_OPERATION ) +return 0 ; +else if (cmdsn_ret ==CMDSN_HIGHER_THAN_EXP ) +return 0 ; +else if (cmdsn_ret ==CMDSN_LOWER_THAN_EXP ) { + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, + conn, cmd->i_state); +return 0 ; + }else {/* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + } + }else if (immed_ret ==IMMEDIDATE_DATA_ERL1_CRC_FAILURE ) { +/* +* Immediate Data failed DataCRC and ERL>=1, +* silently drop this PDU and let the initiator +* plug the CmdSN gap. +* +* FIXME: Send Unsolicited NOPIN with reserved +* TTT here to help the initiator figure out +* the missing CmdSN, although they should be +* intelligent enough to determine the missing +* CmdSN and issue a retry to plug the sequence. +*/ + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, conn, cmd->i_state); + }else /* immed_ret == IMMEDIDATE_DATA_CANNOT_RECOVER */ +return -1 ; + +return 0 ; +} + +static inline int iscsi_handle_data_out (struct iscsi_conn *conn,unsigned char *buf) +{ +int iov_ret, ooo_cmdsn =0 , ret; +u8 data_crc_failed =0 , *pad_bytes[4 ]; +u32 checksum, iov_count =0 , padding =0 , rx_got =0 ; +u32 rx_size =0 , payload_length; +struct iscsi_cmd *cmd =NULL ; +struct se_cmd *se_cmd; +struct se_map_sg map_sg; +struct se_unmap_sg unmap_sg; +struct iscsi_data *hdr; +struct iovec *iov; +unsigned long flags; + + hdr = (struct iscsi_data *) buf; + payload_length =ntoh24 (hdr->dlength); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->ttt =be32_to_cpu (hdr->ttt); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + hdr->datasn =be32_to_cpu (hdr->datasn); + hdr->offset =be32_to_cpu (hdr->offset); + +if (!payload_length) { +printk (KERN_ERR "DataOUT payload is ZERO, protocol error.\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +/* iSCSI write */ +spin_lock_bh (&conn->sess->session_stats_lock); + conn->sess->rx_data_octets += payload_length; +if (conn->sess->se_sess->se_node_acl) { +spin_lock (&conn->sess->se_sess->se_node_acl->stats_lock); + conn->sess->se_sess->se_node_acl->write_bytes += payload_length; +spin_unlock (&conn->sess->se_sess->se_node_acl->stats_lock); + } +spin_unlock_bh (&conn->sess->session_stats_lock); + +if (payload_length > conn->conn_ops->MaxRecvDataSegmentLength) { +printk (KERN_ERR "DataSegmentLength: %u is greater than" +" MaxRecvDataSegmentLength: %u\n" , payload_length, + conn->conn_ops->MaxRecvDataSegmentLength); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + + cmd =iscsi_find_cmd_from_itt_or_dump (conn, hdr->itt, + payload_length); +if (!cmd) +return 0 ; + +TRACE (TRACE_ISCSI ,"Got DataOut ITT: 0x%08x, TTT: 0x%08x," +" DataSN: 0x%08x, Offset: %u, Length: %u, CID: %hu\n" , + hdr->itt, hdr->ttt, hdr->datasn, hdr->offset, + payload_length, conn->cid); + +if (cmd->cmd_flags &ICF_GOT_LAST_DATAOUT ) { +printk (KERN_ERR "Command ITT: 0x%08x received DataOUT after" +" last DataOUT received, dumping payload\n" , + cmd->init_task_tag); +return iscsi_dump_data_payload (conn, payload_length,1 ); + } + +if (cmd->data_direction !=DMA_TO_DEVICE ) { +printk (KERN_ERR "Command ITT: 0x%08x received DataOUT for a" +" NON-WRITE command.\n" , cmd->init_task_tag); +return iscsi_add_reject_from_cmd (ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + } + se_cmd =SE_CMD (cmd); +iscsi_mod_dataout_timer (cmd); + +if ((hdr->offset + payload_length) > cmd->data_length) { +printk (KERN_ERR "DataOut Offset: %u, Length %u greater than" +" iSCSI Command EDTL %u, protocol error.\n" , + hdr->offset, payload_length, cmd->data_length); +return iscsi_add_reject_from_cmd (ISCSI_REASON_BOOKMARK_INVALID , +1 ,0 , buf, cmd); + } + +/* +* Whenever a DataOUT or DataIN PDU contains a valid TTT, the +* iSCSI LUN field must be set. iSCSI v20 10.7.4. Of course, +* Cisco cannot figure this out. +*/ +#if 0 +if (hdr->ttt !=0xFFFFFFFF ) { +int lun =iscsi_unpack_lun (get_unaligned_le64 (&hdr->lun[0 ])); +if (lun !=SE_CMD (cmd)->orig_fe_lun) { +printk (KERN_ERR "Received LUN: %u does not match iSCSI" +" LUN: %u\n" , lun,SE_CMD (cmd)->orig_fe_lun); +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_BOOKMARK_INVALID , +1 ,0 , buf, cmd); + } + } +#endif +if (cmd->unsolicited_data) { +int dump_unsolicited_data =0 , wait_for_transport =0 ; + +if (conn->sess->sess_ops->InitialR2T) { +printk (KERN_ERR "Received unexpected unsolicited data" +" while InitialR2T=Yes, protocol error.\n" ); +transport_send_check_condition_and_sense (SE_CMD (cmd), +TCM_UNEXPECTED_UNSOLICITED_DATA ,0 ); +return -1 ; + } +/* +* Special case for dealing with Unsolicited DataOUT +* and Unsupported SAM WRITE Opcodes and SE resource allocation +* failures; +*/ +spin_lock_irqsave (&T_TASK (se_cmd)->t_state_lock, flags); +/* +* Handle cases where we do or do not want to sleep on +* unsolicited_data_comp +* +* First, if TRANSPORT_WRITE_PENDING state has not been reached, +* we need assume we need to wait and sleep.. +*/ + wait_for_transport = + (se_cmd->t_state !=TRANSPORT_WRITE_PENDING ); +/* +* For the ImmediateData=Yes cases, there will already be +* generic target memory allocated with the original +* ISCSI_OP_SCSI_CMD PDU, so do not sleep for that case. +* +* The last is a check for a delayed TASK_ABORTED status that +* means the data payload will be dropped because +* SCF_SE_CMD_FAILED has been set to indicate that an exception +* condition for this struct sse_cmd has occured in generic target +* code that requires us to drop payload. +*/ + wait_for_transport = + (se_cmd->t_state !=TRANSPORT_WRITE_PENDING ); +if ((cmd->immediate_data !=0 ) || + (atomic_read (&T_TASK (se_cmd)->t_transport_aborted) !=0 )) + wait_for_transport =0 ; +spin_unlock_irqrestore (&T_TASK (se_cmd)->t_state_lock, flags); + +if (wait_for_transport) +wait_for_completion (&cmd->unsolicited_data_comp); + +spin_lock_irqsave (&T_TASK (se_cmd)->t_state_lock, flags); +if (!(se_cmd->se_cmd_flags &SCF_SUPPORTED_SAM_OPCODE ) || + (se_cmd->se_cmd_flags &SCF_SE_CMD_FAILED )) + dump_unsolicited_data =1 ; +spin_unlock_irqrestore (&T_TASK (se_cmd)->t_state_lock, flags); + +if (dump_unsolicited_data) { +/* +* Check if a delayed TASK_ABORTED status needs to +* be sent now if the ISCSI_FLAG_CMD_FINAL has been +* received with the unsolicitied data out. +*/ +if (hdr->flags &ISCSI_FLAG_CMD_FINAL ) +iscsi_stop_dataout_timer (cmd); + +transport_check_aborted_status (se_cmd, + (hdr->flags &ISCSI_FLAG_CMD_FINAL )); +return iscsi_dump_data_payload (conn, payload_length,1 ); + } + }else { +/* +* For the normal solicited data path: +* +* Check for a delayed TASK_ABORTED status and dump any +* incoming data out payload if one exists. Also, when the +* ISCSI_FLAG_CMD_FINAL is set to denote the end of the current +* data out sequence, we decrement outstanding_r2ts. Once +* outstanding_r2ts reaches zero, go ahead and send the delayed +* TASK_ABORTED status. +*/ +if (atomic_read (&T_TASK (se_cmd)->t_transport_aborted) !=0 ) { +if (hdr->flags &ISCSI_FLAG_CMD_FINAL ) +if (--cmd->outstanding_r2ts <1 ) { +iscsi_stop_dataout_timer (cmd); +transport_check_aborted_status ( + se_cmd,1 ); + } + +return iscsi_dump_data_payload (conn, payload_length,1 ); + } + } +/* +* Preform DataSN, DataSequenceInOrder, DataPDUInOrder, and +* within-command recovery checks before receiving the payload. +*/ + ret =iscsi_check_pre_dataout (cmd, buf); +if (ret ==DATAOUT_WITHIN_COMMAND_RECOVERY ) +return 0 ; +else if (ret ==DATAOUT_CANNOT_RECOVER ) +return -1 ; + + rx_size += payload_length; + iov = &cmd->iov_data[0 ]; + +memset (&map_sg,0 ,sizeof (struct se_map_sg )); +memset (&unmap_sg,0 ,sizeof (struct se_unmap_sg )); + map_sg.fabric_cmd = (void *)cmd; + map_sg.se_cmd =SE_CMD (cmd); + map_sg.iov = iov; + map_sg.sg_kmap_active =1 ; + map_sg.data_length = payload_length; + map_sg.data_offset = hdr->offset; + unmap_sg.fabric_cmd = (void *)cmd; + unmap_sg.se_cmd =SE_CMD (cmd); + + iov_ret =iscsi_set_iovec_ptrs (&map_sg, &unmap_sg); +if (iov_ret <0 ) +return -1 ; + + iov_count += iov_ret; + + padding = ((-payload_length) &3 ); +if (padding !=0 ) { + iov[iov_count].iov_base = &pad_bytes; + iov[iov_count++].iov_len = padding; + rx_size += padding; +TRACE (TRACE_ISCSI ,"Receiving %u padding bytes.\n" , padding); + } + +if (conn->conn_ops->DataDigest) { + iov[iov_count].iov_base = &checksum; + iov[iov_count++].iov_len =CRC_LEN ; + rx_size +=CRC_LEN ; + } + +iscsi_map_SG_segments (&unmap_sg); + + rx_got =rx_data (conn, &cmd->iov_data[0 ], iov_count, rx_size); + +iscsi_unmap_SG_segments (&unmap_sg); + +if (rx_got != rx_size) +return -1 ; + +if (conn->conn_ops->DataDigest) { +u32 counter = payload_length, data_crc =0 ; +struct iovec *iov_ptr = &cmd->iov_data[0 ]; +struct scatterlist sg; +/* +* Thanks to the IP stack shitting on passed iovecs, we have to +* call set_iovec_data_ptrs() again in order to have a iMD/PSCSI +* agnostic way of doing datadigests computations. +*/ +memset (&map_sg,0 ,sizeof (struct se_map_sg )); + map_sg.fabric_cmd = (void *)cmd; + map_sg.se_cmd =SE_CMD (cmd); + map_sg.iov = iov_ptr; + map_sg.data_length = payload_length; + map_sg.data_offset = hdr->offset; + +if (iscsi_set_iovec_ptrs (&map_sg, &unmap_sg) <0 ) +return -1 ; + +crypto_hash_init (&conn->conn_rx_hash); + +while (counter >0 ) { +sg_init_one (&sg, iov_ptr->iov_base, + iov_ptr->iov_len); +crypto_hash_update (&conn->conn_rx_hash, &sg, + iov_ptr->iov_len); + +TRACE (TRACE_DIGEST ,"Computed CRC32C DataDigest %zu" +" bytes, CRC 0x%08x\n" , iov_ptr->iov_len, + data_crc); + counter -= iov_ptr->iov_len; + iov_ptr++; + } + +if (padding) { +sg_init_one (&sg, (u8 *)&pad_bytes, padding); +crypto_hash_update (&conn->conn_rx_hash, &sg, + padding); +TRACE (TRACE_DIGEST ,"Computed CRC32C DataDigest %d" +" bytes of padding, CRC 0x%08x\n" , + padding, data_crc); + } +crypto_hash_final (&conn->conn_rx_hash, (u8 *)&data_crc); + +if (checksum != data_crc) { +printk (KERN_ERR "ITT: 0x%08x, Offset: %u, Length: %u," +" DataSN: 0x%08x, CRC32C DataDigest 0x%08x" +" does not match computed 0x%08x\n" , + hdr->itt, hdr->offset, payload_length, + hdr->datasn, checksum, data_crc); + data_crc_failed =1 ; + }else { +TRACE (TRACE_DIGEST ,"Got CRC32C DataDigest 0x%08x for" +" %u bytes of Data Out\n" , checksum, + payload_length); + } + } +/* +* Increment post receive data and CRC values or perform +* within-command recovery. +*/ + ret =iscsi_check_post_dataout (cmd, buf, data_crc_failed); +if ((ret ==DATAOUT_NORMAL ) || (ret ==DATAOUT_WITHIN_COMMAND_RECOVERY )) +return 0 ; +else if (ret ==DATAOUT_SEND_R2T ) { +iscsi_set_dataout_sequence_values (cmd); +iscsi_build_r2ts_for_cmd (cmd, conn,0 ); + }else if (ret ==DATAOUT_SEND_TO_TRANSPORT ) { +/* +* Handle extra special case for out of order +* Unsolicited Data Out. +*/ +spin_lock_bh (&cmd->istate_lock); + ooo_cmdsn = (cmd->cmd_flags &ICF_OOO_CMDSN ); + cmd->cmd_flags |=ICF_GOT_LAST_DATAOUT ; + cmd->i_state =ISTATE_RECEIVED_LAST_DATAOUT ; +spin_unlock_bh (&cmd->istate_lock); + +iscsi_stop_dataout_timer (cmd); +return (!ooo_cmdsn) ?transport_generic_handle_data ( +SE_CMD (cmd)) :0 ; + }else /* DATAOUT_CANNOT_RECOVER */ +return -1 ; + +return 0 ; +} + +static inline int iscsi_handle_nop_out ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +unsigned char *ping_data =NULL ; +int cmdsn_ret, niov =0 , ret =0 , rx_got, rx_size; +u32 checksum, data_crc, padding =0 , payload_length; +u64 lun; +struct iscsi_cmd *cmd =NULL ; +struct iovec *iov =NULL ; +struct iscsi_nopout *hdr; +struct scatterlist sg; + + hdr = (struct iscsi_nopout *) buf; + payload_length =ntoh24 (hdr->dlength); + lun =get_unaligned_le64 (&hdr->lun[0 ]); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->ttt =be32_to_cpu (hdr->ttt); + hdr->cmdsn =be32_to_cpu (hdr->cmdsn); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + +if ((hdr->itt ==0xFFFFFFFF ) && !(hdr->opcode &ISCSI_OP_IMMEDIATE )) { +printk (KERN_ERR "NOPOUT ITT is reserved, but Immediate Bit is" +" not set, protocol error.\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +if (payload_length > conn->conn_ops->MaxRecvDataSegmentLength) { +printk (KERN_ERR "NOPOUT Ping Data DataSegmentLength: %u is" +" greater than MaxRecvDataSegmentLength: %u, protocol" +" error.\n" , payload_length, + conn->conn_ops->MaxRecvDataSegmentLength); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +TRACE (TRACE_ISCSI ,"Got NOPOUT Ping %s ITT: 0x%08x, TTT: 0x%09x," +" CmdSN: 0x%08x, ExpStatSN: 0x%08x, Length: %u\n" , + (hdr->itt ==0xFFFFFFFF ) ?"Response" :"Request" , + hdr->itt, hdr->ttt, hdr->cmdsn, hdr->exp_statsn, + payload_length); +/* +* This is not a response to a Unsolicited NopIN, which means +* it can either be a NOPOUT ping request (with a valid ITT), +* or a NOPOUT not requesting a NOPIN (with a reserved ITT). +* Either way, make sure we allocate an struct iscsi_cmd, as both +* can contain ping data. +*/ +if (hdr->ttt ==0xFFFFFFFF ) { + cmd =iscsi_allocate_cmd (conn); +if (!cmd) +return iscsi_add_reject ( +ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 , buf, conn); + + cmd->iscsi_opcode =ISCSI_OP_NOOP_OUT ; + cmd->i_state =ISTATE_SEND_NOPIN ; + cmd->immediate_cmd = ((hdr->opcode &ISCSI_OP_IMMEDIATE ) ? +1 :0 ); + conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; + cmd->targ_xfer_tag =0xFFFFFFFF ; + cmd->cmd_sn = hdr->cmdsn; + cmd->exp_stat_sn = hdr->exp_statsn; + cmd->data_direction =DMA_NONE ; + } + +if (payload_length && (hdr->ttt ==0xFFFFFFFF )) { + rx_size = payload_length; + ping_data =kzalloc (payload_length +1 ,GFP_KERNEL ); +if (!ping_data) { +printk (KERN_ERR "Unable to allocate memory for" +" NOPOUT ping data.\n" ); + ret =-1 ; + goto out; + } + + iov = &cmd->iov_misc[0 ]; + iov[niov].iov_base = ping_data; + iov[niov++].iov_len = payload_length; + + padding = ((-payload_length) &3 ); +if (padding !=0 ) { +TRACE (TRACE_ISCSI ,"Receiving %u additional bytes" +" for padding.\n" , padding); + iov[niov].iov_base = &cmd->pad_bytes; + iov[niov++].iov_len = padding; + rx_size += padding; + } +if (conn->conn_ops->DataDigest) { + iov[niov].iov_base = &checksum; + iov[niov++].iov_len =CRC_LEN ; + rx_size +=CRC_LEN ; + } + + rx_got =rx_data (conn, &cmd->iov_misc[0 ], niov, rx_size); +if (rx_got != rx_size) { + ret =-1 ; + goto out; + } + +if (conn->conn_ops->DataDigest) { +crypto_hash_init (&conn->conn_rx_hash); + +sg_init_one (&sg, (u8 *)ping_data, payload_length); +crypto_hash_update (&conn->conn_rx_hash, &sg, + payload_length); + +if (padding) { +sg_init_one (&sg, (u8 *)&cmd->pad_bytes, + padding); +crypto_hash_update (&conn->conn_rx_hash, &sg, + padding); + } +crypto_hash_final (&conn->conn_rx_hash, (u8 *)&data_crc); + +if (checksum != data_crc) { +printk (KERN_ERR "Ping data CRC32C DataDigest" +" 0x%08x does not match computed 0x%08x\n" , + checksum, data_crc); +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Unable to recover from" +" NOPOUT Ping DataCRC failure while in" +" ERL=0.\n" ); + ret =-1 ; + goto out; + }else { +/* +* Silently drop this PDU and let the +* initiator plug the CmdSN gap. +*/ +TRACE (TRACE_ERL1 ,"Dropping NOPOUT" +" Command CmdSN: 0x%08x due to" +" DataCRC error.\n" , hdr->cmdsn); + ret =0 ; + goto out; + } + }else { +TRACE (TRACE_DIGEST ,"Got CRC32C DataDigest" +" 0x%08x for %u bytes of ping data.\n" , + checksum, payload_length); + } + } + + ping_data[payload_length] ='\0' ; +/* +* Attach ping data to struct iscsi_cmd->buf_ptr. +*/ + cmd->buf_ptr = (void *)ping_data; + cmd->buf_ptr_size = payload_length; + +TRACE (TRACE_ISCSI ,"Got %u bytes of NOPOUT ping" +" data.\n" , payload_length); +TRACE (TRACE_ISCSI ,"Ping Data: \"%s\"\n" , ping_data); + } + +if (hdr->itt !=0xFFFFFFFF ) { +if (!cmd) { +printk (KERN_ERR "Checking CmdSN for NOPOUT," +" but cmd is NULL!\n" ); +return -1 ; + } + +/* +* Initiator is expecting a NopIN ping reply, +*/ +iscsi_attach_cmd_to_queue (conn, cmd); + +iscsi_ack_from_expstatsn (conn, hdr->exp_statsn); + +if (hdr->opcode &ISCSI_OP_IMMEDIATE ) { +iscsi_add_cmd_to_response_queue (cmd, conn, + cmd->i_state); +return 0 ; + } + + cmdsn_ret =iscsi_check_received_cmdsn (conn, cmd, hdr->cmdsn); +if ((cmdsn_ret ==CMDSN_NORMAL_OPERATION ) || + (cmdsn_ret ==CMDSN_HIGHER_THAN_EXP )) { +return 0 ; + }else if (cmdsn_ret ==CMDSN_LOWER_THAN_EXP ) { + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, conn, + cmd->i_state); + ret =0 ; + goto ping_out; + }else {/* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + ret =-1 ; + goto ping_out; + } + +return 0 ; + } + +if (hdr->ttt !=0xFFFFFFFF ) { +/* +* This was a response to a unsolicited NOPIN ping. +*/ + cmd =iscsi_find_cmd_from_ttt (conn, hdr->ttt); +if (!cmd) +return -1 ; + +iscsi_stop_nopin_response_timer (conn); + + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, conn, cmd->i_state); +iscsi_start_nopin_timer (conn); + }else { +/* +* Initiator is not expecting a NOPIN is response. +* Just ignore for now. +* +* iSCSI v19-91 10.18 +* "A NOP-OUT may also be used to confirm a changed +* ExpStatSN if another PDU will not be available +* for a long time." +*/ + ret =0 ; + goto out; + } + +return 0 ; +out: +if (cmd) +__iscsi_release_cmd_to_pool (cmd, conn->sess); +ping_out: +kfree (ping_data); +return ret; +} + +static inline int iscsi_handle_task_mgt_cmd ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +struct iscsi_cmd *cmd; +struct se_tmr_req *se_tmr; +struct iscsi_tmr_req *tmr_req; +struct iscsi_tm *hdr; +u32 payload_length; +int cmdsn_ret, out_of_order_cmdsn =0 , ret; +u8 function; + + hdr = (struct iscsi_tm *) buf; + payload_length =ntoh24 (hdr->dlength); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->rtt =be32_to_cpu (hdr->rtt); + hdr->cmdsn =be32_to_cpu (hdr->cmdsn); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + hdr->refcmdsn =be32_to_cpu (hdr->refcmdsn); + hdr->exp_datasn =be32_to_cpu (hdr->exp_datasn); + hdr->flags &= ~ISCSI_FLAG_CMD_FINAL ; + function = hdr->flags; + +TRACE (TRACE_ISCSI ,"Got Task Management Request ITT: 0x%08x, CmdSN:" +" 0x%08x, Function: 0x%02x, RefTaskTag: 0x%08x, RefCmdSN:" +" 0x%08x, CID: %hu\n" , hdr->itt, hdr->cmdsn, function, + hdr->rtt, hdr->refcmdsn, conn->cid); + +if ((function !=ISCSI_TM_FUNC_ABORT_TASK ) && + ((function !=ISCSI_TM_FUNC_TASK_REASSIGN ) && + (hdr->rtt !=ISCSI_RESERVED_TAG ))) { +printk (KERN_ERR "RefTaskTag should be set to 0xFFFFFFFF.\n" ); + hdr->rtt =ISCSI_RESERVED_TAG ; + } + +if ((function ==ISCSI_TM_FUNC_TASK_REASSIGN ) && + !(hdr->opcode &ISCSI_OP_IMMEDIATE )) { +printk (KERN_ERR "Task Management Request TASK_REASSIGN not" +" issued as immediate command, bad iSCSI Initiator" +"implementation\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } +if ((function !=ISCSI_TM_FUNC_ABORT_TASK ) && + (hdr->refcmdsn !=ISCSI_RESERVED_TAG )) + hdr->refcmdsn =ISCSI_RESERVED_TAG ; + + cmd =iscsi_allocate_se_cmd_for_tmr (conn, function); +if (!cmd) +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 , buf, conn); + + cmd->iscsi_opcode =ISCSI_OP_SCSI_TMFUNC ; + cmd->i_state =ISTATE_SEND_TASKMGTRSP ; + cmd->immediate_cmd = ((hdr->opcode &ISCSI_OP_IMMEDIATE ) ?1 :0 ); + cmd->init_task_tag = hdr->itt; + cmd->targ_xfer_tag =0xFFFFFFFF ; + cmd->cmd_sn = hdr->cmdsn; + cmd->exp_stat_sn = hdr->exp_statsn; + se_tmr =SE_CMD (cmd)->se_tmr_req; + tmr_req = cmd->tmr_req; +/* +* Locate the struct se_lun for all TMRs not related to ERL=2 TASK_REASSIGN +*/ +if (function !=ISCSI_TM_FUNC_TASK_REASSIGN ) { + ret =iscsi_get_lun_for_tmr (cmd, +get_unaligned_le64 (&hdr->lun[0 ])); +if (ret <0 ) { +SE_CMD (cmd)->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; + se_tmr->response =ISCSI_TMF_RSP_NO_LUN ; + goto attach; + } + } + +switch (function) { +case ISCSI_TM_FUNC_ABORT_TASK : + se_tmr->response =iscsi_tmr_abort_task (cmd, buf); +if (se_tmr->response !=ISCSI_TMF_RSP_COMPLETE ) { +SE_CMD (cmd)->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; + goto attach; + } +break ; +case ISCSI_TM_FUNC_ABORT_TASK_SET : +case ISCSI_TM_FUNC_CLEAR_ACA : +case ISCSI_TM_FUNC_CLEAR_TASK_SET : +case ISCSI_TM_FUNC_LOGICAL_UNIT_RESET : +break ; +case ISCSI_TM_FUNC_TARGET_WARM_RESET : +if (iscsi_tmr_task_warm_reset (conn, tmr_req, buf) <0 ) { +SE_CMD (cmd)->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; + se_tmr->response =ISCSI_TMF_RSP_AUTH_FAILED ; + goto attach; + } +break ; +case ISCSI_TM_FUNC_TARGET_COLD_RESET : +if (iscsi_tmr_task_cold_reset (conn, tmr_req, buf) <0 ) { +SE_CMD (cmd)->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; + se_tmr->response =ISCSI_TMF_RSP_AUTH_FAILED ; + goto attach; + } +break ; +case ISCSI_TM_FUNC_TASK_REASSIGN : + se_tmr->response =iscsi_tmr_task_reassign (cmd, buf); +/* +* Perform sanity checks on the ExpDataSN only if the +* TASK_REASSIGN was successful. +*/ +if (se_tmr->response !=ISCSI_TMF_RSP_COMPLETE ) +break ; + +if (iscsi_check_task_reassign_expdatasn (tmr_req, conn) <0 ) +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_BOOKMARK_INVALID ,1 ,1 , + buf, cmd); +break ; +default : +printk (KERN_ERR "Unknown TMR function: 0x%02x, protocol" +" error.\n" , function); +SE_CMD (cmd)->se_cmd_flags |=SCF_SCSI_CDB_EXCEPTION ; + se_tmr->response =ISCSI_TMF_RSP_NOT_SUPPORTED ; + goto attach; + } + +if ((function !=ISCSI_TM_FUNC_TASK_REASSIGN ) && + (se_tmr->response ==ISCSI_TMF_RSP_COMPLETE )) + se_tmr->call_transport =1 ; +attach: +iscsi_attach_cmd_to_queue (conn, cmd); + +if (!(hdr->opcode &ISCSI_OP_IMMEDIATE )) { + cmdsn_ret =iscsi_check_received_cmdsn (conn, + cmd, hdr->cmdsn); +if (cmdsn_ret ==CMDSN_NORMAL_OPERATION ) +do {}while (0 ); +else if (cmdsn_ret ==CMDSN_HIGHER_THAN_EXP ) + out_of_order_cmdsn =1 ; +else if (cmdsn_ret ==CMDSN_LOWER_THAN_EXP ) { + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, conn, + cmd->i_state); +return 0 ; + }else {/* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + } + } +iscsi_ack_from_expstatsn (conn, hdr->exp_statsn); + +if (out_of_order_cmdsn) +return 0 ; +/* +* Found the referenced task, send to transport for processing. +*/ +if (se_tmr->call_transport) +return transport_generic_handle_tmr (SE_CMD (cmd)); + +/* +* Could not find the referenced LUN, task, or Task Management +* command not authorized or supported. Change state and +* let the tx_thread send the response. +* +* For connection recovery, this is also the default action for +* TMR TASK_REASSIGN. +*/ +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; +} + +/* #warning FIXME: Support Text Command parameters besides SendTargets */ +static inline int iscsi_handle_text_cmd ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +char *text_ptr, *text_in; +int cmdsn_ret, niov =0 , rx_got, rx_size; +u32 checksum =0 , data_crc =0 , payload_length; +u32 padding =0 , pad_bytes =0 , text_length =0 ; +struct iscsi_cmd *cmd; +struct iovec iov[3 ]; +struct iscsi_text *hdr; +struct scatterlist sg; + + hdr = (struct iscsi_text *) buf; + payload_length =ntoh24 (hdr->dlength); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->ttt =be32_to_cpu (hdr->ttt); + hdr->cmdsn =be32_to_cpu (hdr->cmdsn); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + +if (payload_length > conn->conn_ops->MaxRecvDataSegmentLength) { +printk (KERN_ERR "Unable to accept text parameter length: %u" +"greater than MaxRecvDataSegmentLength %u.\n" , + payload_length, conn->conn_ops->MaxRecvDataSegmentLength); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +TRACE (TRACE_ISCSI ,"Got Text Request: ITT: 0x%08x, CmdSN: 0x%08x," +" ExpStatSN: 0x%08x, Length: %u\n" , hdr->itt, hdr->cmdsn, + hdr->exp_statsn, payload_length); + + rx_size = text_length = payload_length; +if (text_length) { + text_in =kzalloc (text_length,GFP_KERNEL ); +if (!text_in) { +printk (KERN_ERR "Unable to allocate memory for" +" incoming text parameters\n" ); +return -1 ; + } + +memset (iov,0 ,3 *sizeof (struct iovec )); + iov[niov].iov_base = text_in; + iov[niov++].iov_len = text_length; + + padding = ((-payload_length) &3 ); +if (padding !=0 ) { + iov[niov].iov_base = &pad_bytes; + iov[niov++].iov_len = padding; + rx_size += padding; +TRACE (TRACE_ISCSI ,"Receiving %u additional bytes" +" for padding.\n" , padding); + } +if (conn->conn_ops->DataDigest) { + iov[niov].iov_base = &checksum; + iov[niov++].iov_len =CRC_LEN ; + rx_size +=CRC_LEN ; + } + + rx_got =rx_data (conn, &iov[0 ], niov, rx_size); +if (rx_got != rx_size) { +kfree (text_in); +return -1 ; + } + +if (conn->conn_ops->DataDigest) { +crypto_hash_init (&conn->conn_rx_hash); + +sg_init_one (&sg, (u8 *)text_in, text_length); +crypto_hash_update (&conn->conn_rx_hash, &sg, + text_length); + +if (padding) { +sg_init_one (&sg, (u8 *)&pad_bytes, padding); +crypto_hash_update (&conn->conn_rx_hash, &sg, + padding); + } +crypto_hash_final (&conn->conn_rx_hash, (u8 *)&data_crc); + +if (checksum != data_crc) { +printk (KERN_ERR "Text data CRC32C DataDigest" +" 0x%08x does not match computed" +" 0x%08x\n" , checksum, data_crc); +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Unable to recover from" +" Text Data digest failure while in" +" ERL=0.\n" ); +kfree (text_in); +return -1 ; + }else { +/* +* Silently drop this PDU and let the +* initiator plug the CmdSN gap. +*/ +TRACE (TRACE_ERL1 ,"Dropping Text" +" Command CmdSN: 0x%08x due to" +" DataCRC error.\n" , hdr->cmdsn); +kfree (text_in); +return 0 ; + } + }else { +TRACE (TRACE_DIGEST ,"Got CRC32C DataDigest" +" 0x%08x for %u bytes of text data.\n" , + checksum, text_length); + } + } + text_in[text_length -1 ] ='\0' ; +TRACE (TRACE_ISCSI ,"Successfully read %d bytes of text" +" data.\n" , text_length); + +if (strncmp ("SendTargets" , text_in,11 ) !=0 ) { +printk (KERN_ERR "Received Text Data that is not" +" SendTargets, cannot continue.\n" ); +kfree (text_in); +return -1 ; + } + text_ptr =strchr (text_in,'=' ); +if (!text_ptr) { +printk (KERN_ERR "No \"=\" separator found in Text Data," +" cannot continue.\n" ); +kfree (text_in); +return -1 ; + } +if (strncmp ("=All" , text_ptr,4 ) !=0 ) { +printk (KERN_ERR "Unable to locate All value for" +" SendTargets key, cannot continue.\n" ); +kfree (text_in); +return -1 ; + } +/*#warning Support SendTargets=(iSCSI Target Name/Nothing) values. */ +kfree (text_in); + } + + cmd =iscsi_allocate_cmd (conn); +if (!cmd) +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_NO_RESOURCES , +1 , buf, conn); + + cmd->iscsi_opcode =ISCSI_OP_TEXT ; + cmd->i_state =ISTATE_SEND_TEXTRSP ; + cmd->immediate_cmd = ((hdr->opcode &ISCSI_OP_IMMEDIATE ) ?1 :0 ); + conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; + cmd->targ_xfer_tag =0xFFFFFFFF ; + cmd->cmd_sn = hdr->cmdsn; + cmd->exp_stat_sn = hdr->exp_statsn; + cmd->data_direction =DMA_NONE ; + +iscsi_attach_cmd_to_queue (conn, cmd); +iscsi_ack_from_expstatsn (conn, hdr->exp_statsn); + +if (!(hdr->opcode &ISCSI_OP_IMMEDIATE )) { + cmdsn_ret =iscsi_check_received_cmdsn (conn, cmd, hdr->cmdsn); +if ((cmdsn_ret ==CMDSN_NORMAL_OPERATION ) || + (cmdsn_ret ==CMDSN_HIGHER_THAN_EXP )) +return 0 ; +else if (cmdsn_ret ==CMDSN_LOWER_THAN_EXP ) { +iscsi_add_cmd_to_immediate_queue (cmd, conn, +ISTATE_REMOVE ); +return 0 ; + }else {/* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + } + +return 0 ; + } + +return iscsi_execute_cmd (cmd,0 ); +} + +/* iscsi_logout_closesession(): +* +* +*/ +int iscsi_logout_closesession (struct iscsi_cmd *cmd,struct iscsi_conn *conn) +{ +struct iscsi_conn *conn_p; +struct iscsi_session *sess = conn->sess; + +TRACE (TRACE_ISCSI ,"Received logout request CLOSESESSION on CID: %hu" +" for SID: %u.\n" , conn->cid, conn->sess->sid); + +atomic_set (&sess->session_logout,1 ); +atomic_set (&conn->conn_logout_remove,1 ); + conn->conn_logout_reason =ISCSI_LOGOUT_REASON_CLOSE_SESSION ; + +iscsi_inc_conn_usage_count (conn); +iscsi_inc_session_usage_count (sess); + +spin_lock_bh (&sess->conn_lock); +list_for_each_entry (conn_p, &sess->sess_conn_list, conn_list) { +if (conn_p->conn_state !=TARG_CONN_STATE_LOGGED_IN ) +continue ; + +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_IN_LOGOUT.\n" ); + conn_p->conn_state =TARG_CONN_STATE_IN_LOGOUT ; + } +spin_unlock_bh (&sess->conn_lock); + +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); + +return 0 ; +} + +int iscsi_logout_closeconnection (struct iscsi_cmd *cmd,struct iscsi_conn *conn) +{ +struct iscsi_conn *l_conn; +struct iscsi_session *sess = conn->sess; + +TRACE (TRACE_ISCSI ,"Received logout request CLOSECONNECTION for CID:" +" %hu on CID: %hu.\n" , cmd->logout_cid, conn->cid); + +/* +* A Logout Request with a CLOSECONNECTION reason code for a CID +* can arrive on a connection with a differing CID. +*/ +if (conn->cid == cmd->logout_cid) { +spin_lock_bh (&conn->state_lock); +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_IN_LOGOUT.\n" ); + conn->conn_state =TARG_CONN_STATE_IN_LOGOUT ; + +atomic_set (&conn->conn_logout_remove,1 ); + conn->conn_logout_reason =ISCSI_LOGOUT_REASON_CLOSE_CONNECTION ; +iscsi_inc_conn_usage_count (conn); + +spin_unlock_bh (&conn->state_lock); + }else { +/* +* Handle all different cid CLOSECONNECTION requests in +* iscsi_logout_post_handler_diffcid() as to give enough +* time for any non immediate command's CmdSN to be +* acknowledged on the connection in question. +* +* Here we simply make sure the CID is still around. +*/ + l_conn =iscsi_get_conn_from_cid (sess, + cmd->logout_cid); +if (!l_conn) { + cmd->logout_response =ISCSI_LOGOUT_CID_NOT_FOUND ; +iscsi_add_cmd_to_response_queue (cmd, conn, + cmd->i_state); +return 0 ; + } + +iscsi_dec_conn_usage_count (l_conn); + } + +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); + +return 0 ; +} + +int iscsi_logout_removeconnforrecovery (struct iscsi_cmd *cmd,struct iscsi_conn *conn) +{ +struct iscsi_session *sess = conn->sess; + +TRACE (TRACE_ERL2 ,"Received explicit REMOVECONNFORRECOVERY logout for" +" CID: %hu on CID: %hu.\n" , cmd->logout_cid, conn->cid); + +if (sess->sess_ops->ErrorRecoveryLevel !=2 ) { +printk (KERN_ERR "Received Logout Request REMOVECONNFORRECOVERY" +" while ERL!=2.\n" ); + cmd->logout_response =ISCSI_LOGOUT_RECOVERY_UNSUPPORTED ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; + } + +if (conn->cid == cmd->logout_cid) { +printk (KERN_ERR "Received Logout Request REMOVECONNFORRECOVERY" +" with CID: %hu on CID: %hu, implementation error.\n" , + cmd->logout_cid, conn->cid); + cmd->logout_response =ISCSI_LOGOUT_CLEANUP_FAILED ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; + } + +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); + +return 0 ; +} + +static inline int iscsi_handle_logout_cmd ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +int cmdsn_ret, logout_remove =0 ; +u8 reason_code =0 ; +struct iscsi_cmd *cmd; +struct iscsi_logout *hdr; +struct iscsi_tiqn *tiqn =iscsi_snmp_get_tiqn (conn); + + hdr = (struct iscsi_logout *) buf; + reason_code = (hdr->flags &0x7f ); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->cid =be16_to_cpu (hdr->cid); + hdr->cmdsn =be32_to_cpu (hdr->cmdsn); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + +if (tiqn) { +spin_lock (&tiqn->logout_stats.lock); +if (reason_code ==ISCSI_LOGOUT_REASON_CLOSE_SESSION ) + tiqn->logout_stats.normal_logouts++; +else + tiqn->logout_stats.abnormal_logouts++; +spin_unlock (&tiqn->logout_stats.lock); + } + +TRACE (TRACE_ISCSI ,"Got Logout Request ITT: 0x%08x CmdSN: 0x%08x" +" ExpStatSN: 0x%08x Reason: 0x%02x CID: %hu on CID: %hu\n" , + hdr->itt, hdr->cmdsn, hdr->exp_statsn, reason_code, + hdr->cid, conn->cid); + +if (conn->conn_state !=TARG_CONN_STATE_LOGGED_IN ) { +printk (KERN_ERR "Received logout request on connection that" +" is not in logged in state, ignoring request.\n" ); +return 0 ; + } + + cmd =iscsi_allocate_cmd (conn); +if (!cmd) +return iscsi_add_reject (ISCSI_REASON_BOOKMARK_NO_RESOURCES ,1 , + buf, conn); + + cmd->iscsi_opcode =ISCSI_OP_LOGOUT ; + cmd->i_state =ISTATE_SEND_LOGOUTRSP ; + cmd->immediate_cmd = ((hdr->opcode &ISCSI_OP_IMMEDIATE ) ?1 :0 ); + conn->sess->init_task_tag = cmd->init_task_tag = hdr->itt; + cmd->targ_xfer_tag =0xFFFFFFFF ; + cmd->cmd_sn = hdr->cmdsn; + cmd->exp_stat_sn = hdr->exp_statsn; + cmd->logout_cid = hdr->cid; + cmd->logout_reason = reason_code; + cmd->data_direction =DMA_NONE ; + +/* +* We need to sleep in these cases (by returning 1) until the Logout +* Response gets sent in the tx thread. +*/ +if ((reason_code ==ISCSI_LOGOUT_REASON_CLOSE_SESSION ) || + ((reason_code ==ISCSI_LOGOUT_REASON_CLOSE_CONNECTION ) && + (hdr->cid == conn->cid))) + logout_remove =1 ; + +iscsi_attach_cmd_to_queue (conn, cmd); + +if (reason_code !=ISCSI_LOGOUT_REASON_RECOVERY ) +iscsi_ack_from_expstatsn (conn, hdr->exp_statsn); + +/* +* Non-Immediate Logout Commands are executed in CmdSN order.. +*/ +if (!(hdr->opcode &ISCSI_OP_IMMEDIATE )) { + cmdsn_ret =iscsi_check_received_cmdsn (conn, cmd, hdr->cmdsn); +if ((cmdsn_ret ==CMDSN_NORMAL_OPERATION ) || + (cmdsn_ret ==CMDSN_HIGHER_THAN_EXP )) +return logout_remove; +else if (cmdsn_ret ==CMDSN_LOWER_THAN_EXP ) { + cmd->i_state =ISTATE_REMOVE ; +iscsi_add_cmd_to_immediate_queue (cmd, conn, + cmd->i_state); +return 0 ; + }else {/* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ +return iscsi_add_reject_from_cmd ( +ISCSI_REASON_PROTOCOL_ERROR , +1 ,0 , buf, cmd); + } + } +/* +* Immediate Logout Commands are executed, well, Immediately. +*/ +if (iscsi_execute_cmd (cmd,0 ) <0 ) +return -1 ; + +return logout_remove; +} + +static inline int iscsi_handle_snack ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +u32 debug_type, unpacked_lun; +u64 lun; +struct iscsi_snack *hdr; + + hdr = (struct iscsi_snack *) buf; + hdr->flags &= ~ISCSI_FLAG_CMD_FINAL ; + lun =get_unaligned_le64 (&hdr->lun[0 ]); + unpacked_lun =iscsi_unpack_lun ((unsigned char *)&lun); + hdr->itt =be32_to_cpu (hdr->itt); + hdr->ttt =be32_to_cpu (hdr->ttt); + hdr->exp_statsn =be32_to_cpu (hdr->exp_statsn); + hdr->begrun =be32_to_cpu (hdr->begrun); + hdr->runlength =be32_to_cpu (hdr->runlength); + + debug_type = (hdr->flags &0x02 ) ?TRACE_ISCSI :TRACE_ERL1 ; +TRACE (debug_type,"Got ISCSI_INIT_SNACK, ITT: 0x%08x, ExpStatSN:" +" 0x%08x, Type: 0x%02x, BegRun: 0x%08x, RunLength: 0x%08x," +" CID: %hu\n" , hdr->itt, hdr->exp_statsn, hdr->flags, + hdr->begrun, hdr->runlength, conn->cid); + +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Initiator sent SNACK request while in" +" ErrorRecoveryLevel=0.\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } +/* +* SNACK_DATA and SNACK_R2T are both 0, so check which function to +* call from inside iscsi_send_recovery_datain_or_r2t(). +*/ +switch (hdr->flags &ISCSI_FLAG_SNACK_TYPE_MASK ) { +case 0 : +return iscsi_handle_recovery_datain_or_r2t (conn, buf, + hdr->itt, hdr->ttt, hdr->begrun, hdr->runlength); +return 0 ; +case ISCSI_FLAG_SNACK_TYPE_STATUS : +return iscsi_handle_status_snack (conn, hdr->itt, hdr->ttt, + hdr->begrun, hdr->runlength); +case ISCSI_FLAG_SNACK_TYPE_DATA_ACK : +return iscsi_handle_data_ack (conn, hdr->ttt, hdr->begrun, + hdr->runlength); +case ISCSI_FLAG_SNACK_TYPE_RDATA : +/* FIXME: Support R-Data SNACK */ +printk (KERN_ERR "R-Data SNACK Not Supported.\n" ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); +default : +printk (KERN_ERR "Unknown SNACK type 0x%02x, protocol" +" error.\n" , hdr->flags &0x0f ); +return iscsi_add_reject (ISCSI_REASON_PROTOCOL_ERROR ,1 , + buf, conn); + } + +return 0 ; +} + +static int iscsi_handle_immediate_data ( +struct iscsi_cmd *cmd, +unsigned char *buf, +u32 length) +{ +int iov_ret, rx_got =0 , rx_size =0 ; +u32 checksum, iov_count =0 , padding =0 , pad_bytes =0 ; +struct iscsi_conn *conn = cmd->conn; +struct se_map_sg map_sg; +struct se_unmap_sg unmap_sg; +struct iovec *iov; + +memset (&map_sg,0 ,sizeof (struct se_map_sg )); +memset (&unmap_sg,0 ,sizeof (struct se_unmap_sg )); + map_sg.fabric_cmd = (void *)cmd; + map_sg.se_cmd =SE_CMD (cmd); + map_sg.sg_kmap_active =1 ; + map_sg.iov = &cmd->iov_data[0 ]; + map_sg.data_length = length; + map_sg.data_offset = cmd->write_data_done; + unmap_sg.fabric_cmd = (void *)cmd; + unmap_sg.se_cmd =SE_CMD (cmd); + + iov_ret =iscsi_set_iovec_ptrs (&map_sg, &unmap_sg); +if (iov_ret <0 ) +return IMMEDIDATE_DATA_CANNOT_RECOVER ; + + rx_size = length; + iov_count = iov_ret; + iov = &cmd->iov_data[0 ]; + + padding = ((-length) &3 ); +if (padding !=0 ) { + iov[iov_count].iov_base = &pad_bytes; + iov[iov_count++].iov_len = padding; + rx_size += padding; + } + +if (conn->conn_ops->DataDigest) { + iov[iov_count].iov_base = &checksum; + iov[iov_count++].iov_len =CRC_LEN ; + rx_size +=CRC_LEN ; + } + +iscsi_map_SG_segments (&unmap_sg); + + rx_got =rx_data (conn, &cmd->iov_data[0 ], iov_count, rx_size); + +iscsi_unmap_SG_segments (&unmap_sg); + +if (rx_got != rx_size) { +iscsi_rx_thread_wait_for_tcp (conn); +return IMMEDIDATE_DATA_CANNOT_RECOVER ; + } + +if (conn->conn_ops->DataDigest) { +u32 counter = length, data_crc; +struct iovec *iov_ptr = &cmd->iov_data[0 ]; +struct scatterlist sg; +/* +* Thanks to the IP stack shitting on passed iovecs, we have to +* call set_iovec_data_ptrs again in order to have a iMD/PSCSI +* agnostic way of doing datadigests computations. +*/ +memset (&map_sg,0 ,sizeof (struct se_map_sg )); + map_sg.fabric_cmd = (void *)cmd; + map_sg.se_cmd =SE_CMD (cmd); + map_sg.iov = iov_ptr; + map_sg.data_length = length; + map_sg.data_offset = cmd->write_data_done; + +if (iscsi_set_iovec_ptrs (&map_sg, &unmap_sg) <0 ) +return IMMEDIDATE_DATA_CANNOT_RECOVER ; + +crypto_hash_init (&conn->conn_rx_hash); + +while (counter >0 ) { +sg_init_one (&sg, iov_ptr->iov_base, + iov_ptr->iov_len); +crypto_hash_update (&conn->conn_rx_hash, &sg, + iov_ptr->iov_len); + +TRACE (TRACE_DIGEST ,"Computed CRC32C DataDigest %zu" +" bytes, CRC 0x%08x\n" , iov_ptr->iov_len, data_crc); + counter -= iov_ptr->iov_len; + iov_ptr++; + } + +if (padding) { +sg_init_one (&sg, (u8 *)&pad_bytes, padding); +crypto_hash_update (&conn->conn_rx_hash, &sg, + padding); +TRACE (TRACE_DIGEST ,"Computed CRC32C DataDigest %d" +" bytes of padding, CRC 0x%08x\n" , padding, data_crc); + } +crypto_hash_final (&conn->conn_rx_hash, (u8 *)&data_crc); + +if (checksum != data_crc) { +printk (KERN_ERR "ImmediateData CRC32C DataDigest 0x%08x" +" does not match computed 0x%08x\n" , checksum, + data_crc); + +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Unable to recover from" +" Immediate Data digest failure while" +" in ERL=0.\n" ); +iscsi_add_reject_from_cmd ( +ISCSI_REASON_DATA_DIGEST_ERROR , +1 ,0 , buf, cmd); +return IMMEDIDATE_DATA_CANNOT_RECOVER ; + }else { +iscsi_add_reject_from_cmd ( +ISCSI_REASON_DATA_DIGEST_ERROR , +0 ,0 , buf, cmd); +return IMMEDIDATE_DATA_ERL1_CRC_FAILURE ; + } + }else { +TRACE (TRACE_DIGEST ,"Got CRC32C DataDigest 0x%08x for" +" %u bytes of Immediate Data\n" , checksum, + length); + } + } + + cmd->write_data_done += length; + +if (cmd->write_data_done == cmd->data_length) { +spin_lock_bh (&cmd->istate_lock); + cmd->cmd_flags |=ICF_GOT_LAST_DATAOUT ; + cmd->i_state =ISTATE_RECEIVED_LAST_DATAOUT ; +spin_unlock_bh (&cmd->istate_lock); + } + +return IMMEDIDATE_DATA_NORMAL_OPERATION ; +} + +/* iscsi_send_async_msg(): +* +* FIXME: Support SCSI AEN. +*/ +int iscsi_send_async_msg ( +struct iscsi_conn *conn, +u16 cid, +u8 async_event, +u8 async_vcode) +{ +u8 iscsi_hdr[ISCSI_HDR_LEN +CRC_LEN ]; +u32 tx_send =ISCSI_HDR_LEN , tx_sent =0 ; +struct timer_list async_msg_timer; +struct iscsi_async *hdr; +struct iovec iov; +struct scatterlist sg; + +memset (&iov,0 ,sizeof (struct iovec )); +memset (&iscsi_hdr,0 ,ISCSI_HDR_LEN +CRC_LEN ); + + hdr = (struct iscsi_async *)&iscsi_hdr; + hdr->opcode =ISCSI_OP_ASYNC_EVENT ; + hdr->flags |=ISCSI_FLAG_CMD_FINAL ; +hton24 (hdr->dlength,0 ); +put_unaligned_le64 (0 , &hdr->lun[0 ]); +put_unaligned_be64 (0xffffffffffffffff , &hdr->rsvd4[0 ]); + hdr->statsn =cpu_to_be32 (conn->stat_sn++); +spin_lock (&conn->sess->cmdsn_lock); + hdr->exp_cmdsn =cpu_to_be32 (conn->sess->exp_cmd_sn); + hdr->max_cmdsn =cpu_to_be32 (conn->sess->max_cmd_sn); +spin_unlock (&conn->sess->cmdsn_lock); + hdr->async_event = async_event; + hdr->async_vcode = async_vcode; + +switch (async_event) { +case ISCSI_ASYNC_MSG_SCSI_EVENT : +printk (KERN_ERR "ISCSI_ASYNC_MSG_SCSI_EVENT: not supported yet.\n" ); +return -1 ; +case ISCSI_ASYNC_MSG_REQUEST_LOGOUT : +TRACE (TRACE_STATE ,"Moving to" +" TARG_CONN_STATE_LOGOUT_REQUESTED.\n" ); + conn->conn_state =TARG_CONN_STATE_LOGOUT_REQUESTED ; + hdr->param1 =0 ; + hdr->param2 =0 ; + hdr->param3 =cpu_to_be16 (SECONDS_FOR_ASYNC_LOGOUT ); +break ; +case ISCSI_ASYNC_MSG_DROPPING_CONNECTION : + hdr->param1 =cpu_to_be16 (cid); + hdr->param2 =cpu_to_be16 (conn->sess->sess_ops->DefaultTime2Wait); + hdr->param3 =cpu_to_be16 (conn->sess->sess_ops->DefaultTime2Retain); +break ; +case ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS : + hdr->param1 =0 ; + hdr->param2 =cpu_to_be16 (conn->sess->sess_ops->DefaultTime2Wait); + hdr->param3 =cpu_to_be16 (conn->sess->sess_ops->DefaultTime2Retain); +break ; +case ISCSI_ASYNC_MSG_PARAM_NEGOTIATION : + hdr->param1 =0 ; + hdr->param2 =0 ; + hdr->param3 =cpu_to_be16 (SECONDS_FOR_ASYNC_TEXT ); +break ; +case ISCSI_ASYNC_MSG_VENDOR_SPECIFIC : +printk (KERN_ERR "ISCSI_ASYNC_MSG_VENDOR_SPECIFIC not" +" supported yet.\n" ); +return -1 ; +default : +printk (KERN_ERR "Unknown AsycnEvent 0x%02x, protocol" +" error.\n" , async_event); +return -1 ; + } + + iov.iov_base = &iscsi_hdr; + iov.iov_len =ISCSI_HDR_LEN ; + +if (conn->conn_ops->HeaderDigest) { +u32 *header_digest = (u32 *)&iscsi_hdr[ISCSI_HDR_LEN ]; + +crypto_hash_init (&conn->conn_tx_hash); + +sg_init_one (&sg, (u8 *)&iscsi_hdr,ISCSI_HDR_LEN ); +crypto_hash_update (&conn->conn_tx_hash, &sg,ISCSI_HDR_LEN ); +
Lines of this file are not shown. View the raw message.
drivers/target/iscsi/iscsi_target.h new file +45 -0
45 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_core.h new file +888 -0
888 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Part of the diff is not shown here. View the raw message.
Re: [RFC-v3 02/12] iscsi-target: Add primary iSCSI request/response state machine logic
Quoted 26 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch adds iscsi_target.[c,h] containing the main iSCSI Request and Response PDU state machines and accompanying infrastructure code and base
iscsi_target_core.hinclude foriscsi_target_mod. This includes support for all defined iSCSI operation codes from RFC-3720 Section 10.2.1.2 and primary state machines for per structiscsi_connRX/TX threads.Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 5371 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target.h | 45 + drivers/target/iscsi/iscsi_target_core.h | 888 +++++ 3 files changed, 6304 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target.c create mode 100644 drivers/target/iscsi/iscsi_target.h create mode 100644 drivers/target/iscsi/iscsi_target_core.hdrivers/target/iscsi/iscsi_target.c new file +6
-0+static struct iscsi_np *iscsit_get_np ( +unsigned char *ipv6, +u32 ipv4, +u16 port, +int network_transport) + if (ipv6 != NULL) {
drivers/target/iscsi/iscsi_target.c line 321
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+ p = (void *)&np->np_ipv6[0 ]; + ip = (void *)ipv6; + net_size =IPV6_ADDRESS_SPACE ; + }else { + p = (void *)&np->np_ipv4; + ip = (void *)&ipv4; + net_size =IPV4_ADDRESS_SPACE ; + } + + if (!memcmp(p, ip, net_size) && (np->np_port == port) &&
All this opencoded handling of IPV4 vs IPV6 address is still quite a mess.
What's the problem with always passing around a struct sockaddr, and then have helpers that treat it like a sockaddr_in or sockaddr_in6 depending on the ->ss_family field? That's what at least the iSCSI initiator and NFS client and server do.
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c new file +5
-0+int iscsit_del_np_thread (struct iscsi_np *np) +{ +spin_lock_bh (&np->np_thread_lock); + np->np_thread_state =ISCSI_NP_THREAD_SHUTDOWN ; +atomic_set (&np->np_shutdown,1 );
drivers/target/iscsi/iscsi_target.c line 454
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+spin_unlock_bh (&np->np_thread_lock); + +if (np->np_thread) { +/* +* We need to send the signal to wakeup Linux/Net +* sock_accept().. +*/ +send_sig (SIGINT , np->np_thread,1 ); +kthread_stop (np->np_thread); + }
What's the point of np_shutdown and the thread_state?
kthread_should_stop() returns true if the thread should stop, so it can replace the shutdown check. You'll still need some indicator for the pure reset case, but except for that the kthread API alone should do it.
drivers/target/iscsi/iscsi_target.c line 737
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c new file +3
-0+u32 lio_sess_get_initiator_sid( +int iscsi_add_nopin( +int iscsi_add_reject(
Why are all these fabric ops method implementations in a different file from the code assigning them to the ops vector? Having all these static and just an ops vector or helper to assign it exposed gives much better visibility control.
drivers/target/iscsi/iscsi_target.c line 833
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+/* #define iscsi_calculate_map_segment_DEBUG */ +#ifdef iscsi_calculate_map_segment_DEBUG +#define DEBUG_MAP_SEGMENTS(buf...) PYXPRINT(buf) +#else +#define DEBUG_MAP_SEGMENTS(buf...) +#endif
Do we need to keep all this ad-hoc debugging code?
Quoted 4 lines
+/*
iscsi_logout_closesession():
+ *
+ *
+ */
As mentioned in a previous round please try to remove all comment which like this one don't provide any documentation value by just repeating the function name.
drivers/target/iscsi/iscsi_target.c line 3031
Quoted 4 lines
drivers/target/iscsi/iscsi_target.c new file +4
-0+ +add_timer (&async_msg_timer); +wait_for_completion (&conn->sess->async_msg_comp); +del_timer_sync (&async_msg_timer);
Just use wait_for_completion_timeout here.
Quoted 11 lines
drivers/target/iscsi/iscsi_target.c new file +11
-0+static void iscsi_tx_thread_TCP_timeout (unsigned long data) +{ +complete ((struct completion *)data); +} + +static void iscsi_tx_thread_wait_for_tcp (struct iscsi_conn *conn) +{ +struct timer_list tx_TCP_timer; +int ret; + + if ((conn->sock->sk->sk_shutdown & SEND_SHUTDOWN) ||
drivers/target/iscsi/iscsi_target.c line 4202
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+ (conn->sock->sk->sk_shutdown & RCV_SHUTDOWN)) { +init_timer (&tx_TCP_timer); + tx_TCP_timer.expires = + (get_jiffies_64 () +ISCSI_TX_THREAD_TCP_TIMEOUT *HZ ); + tx_TCP_timer.data = (unsigned long )&conn->tx_half_close_comp; + tx_TCP_timer.function = iscsi_tx_thread_TCP_timeout; + +add_timer (&tx_TCP_timer); + ret =wait_for_completion_interruptible (&conn->tx_half_close_comp); +del_timer_sync (&tx_TCP_timer);
and wait_for_completion_interruptible_timeout here, please.
Review
Quoted 1 line
(quoted diff) +1
-0+ set_user_nice(current, -20);
Messing with the nice level at least needs an explanation.
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c new file +5
-0+allow_signal (SIGINT ); + +restart: + conn =iscsi_tx_thread_pre_handler (ts); +if (!conn)
drivers/target/iscsi/iscsi_target.c line 4302
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+ goto out; + + eodr = map_sg = ret = sent_status = use_misc =0 ; + +while (!kthread_should_stop ()) { +/* +* Ensure that both TX and RX per connection kthreads +* are scheduled to run on the same CPU. +*/ +iscsi_thread_check_cpumask (conn, current,1 );
Would kthread_bind help with binding the threads to CPUs?
drivers/target/iscsi/iscsi_target.c line 4304
Quoted 1 line
drivers/target/iscsi/iscsi_target.c new file +1
-0+ ret =wait_for_completion_interruptible (&conn->tx_comp);
This looks like the functions to queue up work should just do a wake_up_process on the tast structure, and the thread itself should just do a schedule_timeout().
Quoted 11 lines
drivers/target/iscsi/iscsi_target.c new file +11
-0+static void iscsi_rx_thread_TCP_timeout (unsigned long data) +{ +complete ((struct completion *)data); +} + +static void iscsi_rx_thread_wait_for_tcp (struct iscsi_conn *conn) +{ +struct timer_list rx_TCP_timer; +int ret; + + if ((conn->sock->sk->sk_shutdown & SEND_SHUTDOWN) ||
drivers/target/iscsi/iscsi_target.c line 4607
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+ (conn->sock->sk->sk_shutdown & RCV_SHUTDOWN)) { +init_timer (&rx_TCP_timer); + rx_TCP_timer.expires = + (get_jiffies_64 () +ISCSI_RX_THREAD_TCP_TIMEOUT *HZ ); + rx_TCP_timer.data = (unsigned long )&conn->rx_half_close_comp; + rx_TCP_timer.function = iscsi_rx_thread_TCP_timeout; + +add_timer (&rx_TCP_timer); + ret =wait_for_completion_interruptible (&conn->rx_half_close_comp); +del_timer_sync (&rx_TCP_timer);
wait_for_completion_interruptible_timeout again, please.
Review
Quoted 1 line
(quoted diff) +1
-0+ set_user_nice(current, -20);
explanation, please.
drivers/target/iscsi/iscsi_target.c line 4781
Quoted 7 lines
drivers/target/iscsi/iscsi_target.c new file +7
-0+spin_lock_bh (&conn->cmd_lock); +list_for_each_entry_safe (cmd, cmd_tmp, &conn->conn_cmd_list, i_list) { +if (!(SE_CMD (cmd)) || + !(SE_CMD (cmd)->se_cmd_flags &SCF_SE_LUN_CMD )) { + +list_del (&cmd->i_list); +spin_unlock_bh (&conn->cmd_lock);
What gurantees the list hasn't been modified after the lock was released?
drivers/target/iscsi/iscsi_target.c line 4921
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+/* +* If connection reinstatement is being performed on this connection +* by receiving a REMOVECONNFORRECOVERY logout request, up the +* connection wait rcfr semaphore that is being blocked on +* an iscsi_connection_reinstatement_rcfr(). +*/ +if (atomic_read (&conn->connection_wait_rcfr)) { +spin_unlock_bh (&conn->state_lock); +complete (&conn->conn_wait_rcfr_comp); +wait_for_completion (&conn->conn_post_wait_comp);
I'm trying to understand what this (and the similar block next to it) is doing. You wake up another process in the ERL code, which does nothing but waking this code up again. Why do we have to wait here until the ERL code did it's run?
Quoted 1 line
+int
iscsi_close_session(struct iscsi_session *sess)
The code still seems to be undecided on iscsi_ vs iscsit_ as a prefix.
drivers/target/iscsi/iscsi_target.c line 5307
Quoted 12 lines
drivers/target/iscsi/iscsi_target.c new file +12
-0+spin_lock_bh (&sess->conn_lock); +if (session_sleep) +atomic_set (&sess->sleep_on_sess_wait_comp,1 ); + +if (connection_sleep) { +list_for_each_entry_safe (conn, conn_tmp, &sess->sess_conn_list, + conn_list) { +if (conn_count ==0 ) +break ; + +iscsi_inc_conn_usage_count (conn); +spin_unlock_bh (&sess->conn_lock);
What protects the next entry from going away after dropping the lock?
Re: [RFC-v3 02/12] iscsi-target: Add primary iSCSI request/response state machine logic
Quoted 40 lines · Christoph Hellwig
Quoted 26 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch adds iscsi_target.[c,h] containing the main iSCSI Request and Response PDU state machines and accompanying infrastructure code and base
iscsi_target_core.hinclude foriscsi_target_mod. This includes support for all defined iSCSI operation codes from RFC-3720 Section 10.2.1.2 and primary state machines for per structiscsi_connRX/TX threads.Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/iscsi/iscsi_target.c | 5371 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target.h | 45 + drivers/target/iscsi/iscsi_target_core.h | 888 +++++ 3 files changed, 6304 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target.c create mode 100644 drivers/target/iscsi/iscsi_target.h create mode 100644 drivers/target/iscsi/iscsi_target_core.hdrivers/target/iscsi/iscsi_target.c new file +6
-0+static struct iscsi_np *iscsit_get_np ( +unsigned char *ipv6, +u32 ipv4, +u16 port, +int network_transport) + if (ipv6 != NULL) {drivers/target/iscsi/iscsi_target.c line 321
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c new file +10
-0+ p = (void *)&np->np_ipv6[0 ]; + ip = (void *)ipv6; + net_size =IPV6_ADDRESS_SPACE ; + }else { + p = (void *)&np->np_ipv4; + ip = (void *)&ipv4; + net_size =IPV4_ADDRESS_SPACE ; + } + + if (!memcmp(p, ip, net_size) && (np->np_port == port) &&All this opencoded handling of IPV4 vs IPV6 address is still quite a mess.
Quoted 5 lines
What's the problem with always passing around a struct sockaddr, and then have helpers that treat it like a
sockaddr_inorsockaddr_in6depending on the ->ss_family field? That's what at least the iSCSI initiator and NFS client and server do.
<nod>, will get this converted over to follow existing code.
Quoted 9 lines
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c new file +9
-0+int iscsit_del_np_thread (struct iscsi_np *np) +{ +spin_lock_bh (&np->np_thread_lock); + np->np_thread_state =ISCSI_NP_THREAD_SHUTDOWN ; +atomic_set (&np->np_shutdown,1 ); +spin_unlock_bh (&np->np_thread_lock); + +if (np->np_thread) { +/*
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 454
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+* We need to send the signal to wakeup Linux/Net +* sock_accept().. +*/ +send_sig (SIGINT , np->np_thread,1 ); +kthread_stop (np->np_thread); + }What's the point of
np_shutdownand thethread_state?
np_shutdown is used in a handful of places external to iscsi_target_login_thread() context to skip processing of iscsi_np while the shutdown is happening.
Quoted 2 lines
kthread_should_stop()returns true if the thread should stop, so it can replace the shutdown check.
Ok, I will drop np_shutdown and just check thread_state for these handful of cases outside of iscsi_target_login_thread() context currently checking for iscsi_np->np_shutdown..
Quoted 4 lines
You'll still need some indicator
for the pure reset case, but except for that the kthread API alone should do it.
<nod>, keeping thread_state for this purpose..
Quoted 11 lines
drivers/target/iscsi/iscsi_target.c line 737
Quoted 5 lines
drivers/target/iscsi/iscsi_target.c new file +3
-0+u32 lio_sess_get_initiator_sid( +int iscsi_add_nopin( +int iscsi_add_reject(Why are all these fabric ops method implementations in a different file from the code assigning them to the ops vector? Having all these static and just an ops vector or helper to assign it exposed gives much better visibility control.
Only sess_get_initiator_sid is a fabric ops method btw, but point taken. I will take a look at iscsi_target_util.c and make everything possible statically defined.
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 833
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+/* #define iscsi_calculate_map_segment_DEBUG */ +#ifdef iscsi_calculate_map_segment_DEBUG +#define DEBUG_MAP_SEGMENTS(buf...) PYXPRINT(buf) +#else +#define DEBUG_MAP_SEGMENTS(buf...) +#endif Do we need to keep all this ad-hoc debugging code?
Dropping all of these now..
Quoted 9 lines
Quoted 4 lines
+/*
iscsi_logout_closesession():
+ *
+ *
+ */As mentioned in a previous round please try to remove all comment which like this one don't provide any documentation value by just repeating the function name.
Ugh, sorry, will get all of these removed
Quoted 7 lines
drivers/target/iscsi/iscsi_target.c line 3031
Quoted 4 lines
drivers/target/iscsi/iscsi_target.c new file +4
-0+ +add_timer (&async_msg_timer); +wait_for_completion (&conn->sess->async_msg_comp); +del_timer_sync (&async_msg_timer);Just use
wait_for_completion_timeouthere.
Converted
Quoted 15 lines
Quoted 15 lines
drivers/target/iscsi/iscsi_target.c new file +15
-0+static void iscsi_tx_thread_TCP_timeout (unsigned long data) +{ +complete ((struct completion *)data); +} + +static void iscsi_tx_thread_wait_for_tcp (struct iscsi_conn *conn) +{ +struct timer_list tx_TCP_timer; +int ret; + +if ((conn->sock->sk->sk_shutdown &SEND_SHUTDOWN ) || + (conn->sock->sk->sk_shutdown &RCV_SHUTDOWN )) { +init_timer (&tx_TCP_timer); + tx_TCP_timer.expires = + (get_jiffies_64 () +ISCSI_TX_THREAD_TCP_TIMEOUT *HZ );
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 4202
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+ tx_TCP_timer.data = (unsigned long )&conn->tx_half_close_comp; + tx_TCP_timer.function = iscsi_tx_thread_TCP_timeout; + +add_timer (&tx_TCP_timer); + ret =wait_for_completion_interruptible (&conn->tx_half_close_comp); +del_timer_sync (&tx_TCP_timer);and
wait_for_completion_interruptible_timeouthere, please.
Converted
Quoted 4 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ set_user_nice(current, -20);Messing with the nice level at least needs an explanation.
I think this was originally from iSCSI Initiator code and/or NDB (which still uses it btw), and several other mainline software fabric users do it as well; drivers/scsi/fcoe/fcoe.c:fcoe_percpu_receive_thread()
Adding a comments here..
Quoted 9 lines
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c new file +9
-0+allow_signal (SIGINT ); + +restart: + conn =iscsi_tx_thread_pre_handler (ts); +if (!conn) + goto out; + + eodr = map_sg = ret = sent_status = use_misc =0 ; +
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 4302
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+while (!kthread_should_stop ()) { +/* +* Ensure that both TX and RX per connection kthreads +* are scheduled to run on the same CPU. +*/ +iscsi_thread_check_cpumask (conn, current,1 );Would
kthread_bindhelp with binding the threads to CPUs?
Hmmm, need to have a deeper look at this.
Converting this would mean that the RX/TX thread pairs would only be calling kthread_bind() once when the threads are created, instead of checking per each RX/TX loop iteration w/ iscsi_thread_check_cpumask().
I think being able to re-bind these to different CPUs after the fact would still be useful though.. If we are using kthread_bind() during initial thread creation, how would re-binding work once the thread is running..?
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c line 4304
Quoted 1 line
drivers/target/iscsi/iscsi_target.c new file +1
-0+ ret =wait_for_completion_interruptible (&conn->tx_comp);This looks like the functions to queue up work should just do a
wake_up_processon the tast structure, and the thread itself should just do aschedule_timeout().
OK, converting iscsi_target_tx_thread() to use wake_up_process() and schedule_timeout().
Quoted 15 lines
Quoted 15 lines
drivers/target/iscsi/iscsi_target.c new file +15
-0+static void iscsi_rx_thread_TCP_timeout (unsigned long data) +{ +complete ((struct completion *)data); +} + +static void iscsi_rx_thread_wait_for_tcp (struct iscsi_conn *conn) +{ +struct timer_list rx_TCP_timer; +int ret; + +if ((conn->sock->sk->sk_shutdown &SEND_SHUTDOWN ) || + (conn->sock->sk->sk_shutdown &RCV_SHUTDOWN )) { +init_timer (&rx_TCP_timer); + rx_TCP_timer.expires = + (get_jiffies_64 () +ISCSI_RX_THREAD_TCP_TIMEOUT *HZ );
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 4607
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+ rx_TCP_timer.data = (unsigned long )&conn->rx_half_close_comp; + rx_TCP_timer.function = iscsi_rx_thread_TCP_timeout; + +add_timer (&rx_TCP_timer); + ret =wait_for_completion_interruptible (&conn->rx_half_close_comp); +del_timer_sync (&rx_TCP_timer);
wait_for_completion_interruptible_timeoutagain, please.
Converted
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +1
-0+ set_user_nice(current, -20);explanation, please.
Quoted 10 lines
drivers/target/iscsi/iscsi_target.c line 4781
Quoted 7 lines
drivers/target/iscsi/iscsi_target.c new file +7
-0+spin_lock_bh (&conn->cmd_lock); +list_for_each_entry_safe (cmd, cmd_tmp, &conn->conn_cmd_list, i_list) { +if (!(SE_CMD (cmd)) || + !(SE_CMD (cmd)->se_cmd_flags &SCF_SE_LUN_CMD )) { + +list_del (&cmd->i_list); +spin_unlock_bh (&conn->cmd_lock);What gurantees the list hasn't been modified after the lock was released?
At this point for a RX/TX connection pair during a connection logout or failure event, only one of the two threads can ever call:
iscsi_take_action_for_connection_exit() -> iscsi_handle_connection_cleanup() -> iscsi_close_connection() -> iscsi_release_commands_from_conn()
The other will return back to sleeping in iscsi_[r,t]x_thread_pre_handler() waiting for the iSCSI connection to be shutdown.
Quoted 7 lines
Quoted 7 lines
drivers/target/iscsi/iscsi_target.c new file +7
-0+/* +* If connection reinstatement is being performed on this connection +* by receiving a REMOVECONNFORRECOVERY logout request, up the +* connection wait rcfr semaphore that is being blocked on +* an iscsi_connection_reinstatement_rcfr(). +*/ +if (atomic_read (&conn->connection_wait_rcfr)) {
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 4921
Quoted 3 lines
drivers/target/iscsi/iscsi_target.c new file +3
-0+spin_unlock_bh (&conn->state_lock); +complete (&conn->conn_wait_rcfr_comp); +wait_for_completion (&conn->conn_post_wait_comp);I'm trying to understand what this (and the similar block next to it) is doing. You wake up another process in the ERL code, which does nothing but waking this code up again. Why do we have to wait here until the ERL code did it's run?
These are two special cases where iscsi_target_login_thread() context may already be initiating recovery for an struct iscsi_conn, and then iSCSI connection failure or logout toccurs from within the active RX/TX thread pair context.
Quoted 5 lines
Quoted 2 lines
+int
iscsi_close_session(struct iscsi_session *sess)The code still seems to be undecided on
iscsi_vsiscsit_as a prefix.
Yes, the first name conversion was specifically for the core_* prefix code in iscsi_target.c. I will go ahead and convert this specifically for the main iscsi_target.c file, but I would prefer to avoid doing this for stuff outside of iscsi_target.c
Quoted 6 lines
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+spin_lock_bh (&sess->conn_lock); +if (session_sleep) +atomic_set (&sess->sleep_on_sess_wait_comp,1 ); + +if (connection_sleep) { + list_for_each_entry_safe(conn, conn_tmp, &sess->sess_conn_list,
Quoted 9 lines
drivers/target/iscsi/iscsi_target.c line 5270
Quoted 6 lines
drivers/target/iscsi/iscsi_target.c new file +6
-0+ conn_list) { +if (conn_count ==0 ) +break ; + +iscsi_inc_conn_usage_count (conn); +spin_unlock_bh (&sess->conn_lock);What protects the next entry from going away after dropping the lock?
Good catch. Fixing this now by adding a conn_usage reference to conn_tmp when non NULL..
I will get these items fixed up and tested in lio-4.1 and will send out
an updated patch over the weekend. Please let me know if you have any
other comments and I will try to get them addressed ASAP.
Thanks,
--nab
RFC v3 3/12 iscsi-target: Add TCM v4 compatiable ConfigFS control plane
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds support for /sys/kernel/config/target/iscsi using TCM v4.0 compatiable calls following target_core_fabric_configfs.c
This includes a number of iSCSI fabric dependent attributes upon target_core_fabric_configfs.c provided struct config_item_types from include/target/target_core_configfs.hstruct target_fabric_configfs_template
It also includes iscsi_target_nodeattrib.[c,h] for handling the lio_target_nacl_attrib_attrs[] store/show for iSCSI fabric dependent attributes.
--- drivers/target/iscsi/iscsi_target_configfs.c | 1593 ++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_configfs.h | 7 + drivers/target/iscsi/iscsi_target_nodeattrib.c | 264 ++++ drivers/target/iscsi/iscsi_target_nodeattrib.h | 14 + 4 files changed, 1878 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_configfs.c create mode 100644 drivers/target/iscsi/iscsi_target_configfs.h create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.c create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.h
drivers/target/iscsi/iscsi_target_configfs.c new file +1593 -0
@@ -0,0 +1,1593 @@ +/******************************************************************************* +* This file contains the configfs implementation for iSCSI Target mode +* from the LIO-Target Project. +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +****************************************************************************/ + +#include <linux/configfs.h> +#include <target/target_core_base.h> +#include <target/target_core_transport.h> +#include <target/target_core_fabric_ops.h> +#include <target/target_core_fabric_configfs.h> +#include <target/target_core_fabric_lib.h> +#include <target/target_core_device.h> +#include <target/target_core_tpg.h> +#include <target/target_core_configfs.h> +#include <target/configfs_macros.h> + +#include "iscsi_target_core.h" +#include "iscsi_target_parameters.h" +#include "iscsi_target_device.h" +#include "iscsi_target_erl0.h" +#include "iscsi_target_nodeattrib.h" +#include "iscsi_target_tpg.h" +#include "iscsi_target_util.h" +#include "iscsi_target.h" +#include "iscsi_target_stat.h" +#include "iscsi_target_configfs.h" + +struct target_fabric_configfs *lio_target_fabric_configfs; + +struct lio_target_configfs_attribute { +struct configfs_attribute attr; +ssize_t (*show)(void *,char *); +ssize_t (*store)(void *,const char *,size_t ); +}; + +struct iscsi_portal_group *lio_get_tpg_from_tpg_item ( +struct config_item *item, +struct iscsi_tiqn **tiqn_out) +{ +struct se_portal_group *se_tpg =container_of (to_config_group (item), + struct se_portal_group, tpg_group); +struct iscsi_portal_group *tpg = + (struct iscsi_portal_group *)se_tpg->se_tpg_fabric_ptr; +int ret; + +if (!tpg) { +printk (KERN_ERR "Unable to locate struct iscsi_portal_group " +"pointer\n" ); +return NULL ; + } + ret =iscsi_get_tpg (tpg); +if (ret <0 ) +return NULL ; + + *tiqn_out = tpg->tpg_tiqn; +return tpg; +} + +/* Start items for lio_target_portal_cit */ + +static ssize_t lio_target_np_show_sctp ( +struct se_tpg_np *se_tpg_np, +char *page) +{ +struct iscsi_tpg_np *tpg_np =container_of (se_tpg_np, + struct iscsi_tpg_np, se_tpg_np); +struct iscsi_tpg_np *tpg_np_sctp; +ssize_t rb; + + tpg_np_sctp =iscsi_tpg_locate_child_np (tpg_np,ISCSI_SCTP_TCP ); +if (tpg_np_sctp) + rb =sprintf (page,"1\n" ); +else + rb =sprintf (page,"0\n" ); + +return rb; +} + +static ssize_t lio_target_np_store_sctp ( +struct se_tpg_np *se_tpg_np, +const char *page, +size_t count) +{ +struct iscsi_np *np; +struct iscsi_portal_group *tpg; +struct iscsi_tpg_np *tpg_np =container_of (se_tpg_np, + struct iscsi_tpg_np, se_tpg_np); +struct iscsi_tpg_np *tpg_np_sctp =NULL ; +struct iscsi_np_addr np_addr; +char *endptr; +u32 op; +int ret; + + op =simple_strtoul (page, &endptr,0 ); +if ((op !=1 ) && (op !=0 )) { +printk (KERN_ERR "Illegal value for tpg_enable: %u\n" , op); +return -EINVAL ; + } + np = tpg_np->tpg_np; +if (!np) { +printk (KERN_ERR "Unable to locate struct iscsi_np from" +" struct iscsi_tpg_np\n" ); +return -EINVAL ; + } + + tpg = tpg_np->tpg; +if (iscsi_get_tpg (tpg) <0 ) +return -EINVAL ; + +if (op) { +memset (&np_addr,0 ,sizeof (struct iscsi_np_addr )); +if (np->np_flags &NPF_NET_IPV6 ) +snprintf (np_addr.np_ipv6,IPV6_ADDRESS_SPACE , +"%s" , np->np_ipv6); +else + np_addr.np_ipv4 = np->np_ipv4; + np_addr.np_flags = np->np_flags; + np_addr.np_port = np->np_port; + + tpg_np_sctp =iscsi_tpg_add_network_portal (tpg, &np_addr, + tpg_np,ISCSI_SCTP_TCP ); +if (!tpg_np_sctp ||IS_ERR (tpg_np_sctp)) + goto out; + }else { + tpg_np_sctp =iscsi_tpg_locate_child_np (tpg_np,ISCSI_SCTP_TCP ); +if (!tpg_np_sctp) + goto out; + + ret =iscsi_tpg_del_network_portal (tpg, tpg_np_sctp); +if (ret <0 ) + goto out; + } + +iscsi_put_tpg (tpg); +return count; +out: +iscsi_put_tpg (tpg); +return -EINVAL ; +} + +TF_NP_BASE_ATTR (lio_target, sctp,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_portal_attrs[] = { + &lio_target_np_sctp.attr, +NULL , +}; + +/* Stop items for lio_target_portal_cit */ + +/* Start items for lio_target_np_cit */ + +#define MAX_PORTAL_LEN 256 + +struct se_tpg_np *lio_target_call_addnptotpg ( +struct se_portal_group *se_tpg, +struct config_group *group, +const char *name) +{ +struct iscsi_portal_group *tpg; +struct iscsi_tpg_np *tpg_np; +char *str, *str2, *end_ptr, *ip_str, *port_str; +struct iscsi_np_addr np_addr; +u32 ipv4 =0 ; +int ret; +char buf[MAX_PORTAL_LEN +1 ]; + +if (strlen (name) >MAX_PORTAL_LEN ) { +printk (KERN_ERR "strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n" , + (int )strlen (name),MAX_PORTAL_LEN ); +return ERR_PTR (-EOVERFLOW ); + } +memset (buf,0 ,MAX_PORTAL_LEN ); +snprintf (buf,MAX_PORTAL_LEN ,"%s" , name); + +memset (&np_addr,0 ,sizeof (struct iscsi_np_addr )); + + str =strstr (buf,"[" ); +if (str) { + str2 =strstr (str,"]" ); +if (!str2) { +printk (KERN_ERR "Unable to locate trailing \"]\"" +" in IPv6 iSCSI network portal address\n" ); +return ERR_PTR (-EINVAL ); + } + str++;/* Skip over leading "[" */ + *str2 ='\0' ;/* Terminate the IPv6 address */ + str2++;/* Skip over the "]" */ + port_str =strstr (str2,":" ); +if (!port_str) { +printk (KERN_ERR "Unable to locate \":port\"" +" in IPv6 iSCSI network portal address\n" ); +return ERR_PTR (-EINVAL ); + } + *port_str ='\0' ;/* Terminate string for IP */ + port_str++;/* Skip over ":" */ + np_addr.np_port =simple_strtoul (port_str, &end_ptr,0 ); + +snprintf (np_addr.np_ipv6,IPV6_ADDRESS_SPACE ,"%s" , str); + np_addr.np_flags |=NPF_NET_IPV6 ; + }else { + ip_str = &buf[0 ]; + port_str =strstr (ip_str,":" ); +if (!port_str) { +printk (KERN_ERR "Unable to locate \":port\"" +" in IPv4 iSCSI network portal address\n" ); +return ERR_PTR (-EINVAL ); + } + *port_str ='\0' ;/* Terminate string for IP */ + port_str++;/* Skip over ":" */ + np_addr.np_port =simple_strtoul (port_str, &end_ptr,0 ); + + ipv4 =in_aton (ip_str); + np_addr.np_ipv4 =htonl (ipv4); + np_addr.np_flags |=NPF_NET_IPV4 ; + } + tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); + ret =iscsi_get_tpg (tpg); +if (ret <0 ) +return ERR_PTR (-EINVAL ); + +printk (KERN_INFO "LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" +" PORTAL: %s\n" , +config_item_name (&se_tpg->se_tpg_wwn->wwn_group.cg_item), + tpg->tpgt, name); +/* +* Assume ISCSI_TCP by default. Other network portals for other +* iSCSI fabrics: +* +* Traditional iSCSI over SCTP (initial support) +* iSER/TCP (TODO, hardware available) +* iSER/SCTP (TODO, software emulation with osc-iwarp) +* iSER/IB (TODO, hardware available) +* +* can be enabled with atributes under +* sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ +* +*/ + tpg_np =iscsi_tpg_add_network_portal (tpg, &np_addr,NULL ,ISCSI_TCP ); +if (IS_ERR (tpg_np)) { +iscsi_put_tpg (tpg); +return ERR_PTR (PTR_ERR (tpg_np)); + } +printk (KERN_INFO "LIO_Target_ConfigFS: addnptotpg done!\n" ); + +iscsi_put_tpg (tpg); +return &tpg_np->se_tpg_np; +} + +static void lio_target_call_delnpfromtpg ( +struct se_tpg_np *se_tpg_np) +{ +struct iscsi_portal_group *tpg; +struct iscsi_tpg_np *tpg_np; +struct se_portal_group *se_tpg; +int ret; + + tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); + tpg = tpg_np->tpg; + ret =iscsi_get_tpg (tpg); +if (ret <0 ) +return ; + + se_tpg = &tpg->tpg_se_tpg; +printk (KERN_INFO "LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" +" PORTAL: %s\n" ,config_item_name (&se_tpg->se_tpg_wwn->wwn_group.cg_item), + tpg->tpgt,config_item_name (&se_tpg_np->tpg_np_group.cg_item)); + + ret =iscsi_tpg_del_network_portal (tpg, tpg_np); +if (ret <0 ) + goto out; + +printk (KERN_INFO "LIO_Target_ConfigFS: delnpfromtpg done!\n" ); +out: +iscsi_put_tpg (tpg); +} + +/* End items for lio_target_np_cit */ + +/* Start items for lio_target_nacl_attrib_cit */ + +#define DEF_NACL_ATTRIB (name) \ +static ssize_t iscsi_nacl_attrib_show_##name( \ + struct se_node_acl *se_nacl, \ + char *page) \ +{ \ + struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ + se_node_acl); \ + ssize_t rb; \ + \ + rb = sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \ + return rb; \ +} \ + \ +static ssize_t iscsi_nacl_attrib_store_##name( \ + struct se_node_acl *se_nacl, \ + const char *page, \ + size_t count) \ +{ \ + struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ + se_node_acl); \ + char *endptr; \ + u32 val; \ + int ret; \ + \ + val = simple_strtoul(page, &endptr, 0); \ + ret = iscsi_na_##name(nacl, val); \ + if (ret < 0) \ + return ret; \ + \ + return count; \ +} + +#define NACL_ATTR (_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode); +/* +* Define iscsi_node_attrib_s_dataout_timeout +*/ +DEF_NACL_ATTRIB (dataout_timeout); +NACL_ATTR (dataout_timeout,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_dataout_timeout_retries +*/ +DEF_NACL_ATTRIB (dataout_timeout_retries); +NACL_ATTR (dataout_timeout_retries,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_default_erl +*/ +DEF_NACL_ATTRIB (default_erl); +NACL_ATTR (default_erl,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_nopin_timeout +*/ +DEF_NACL_ATTRIB (nopin_timeout); +NACL_ATTR (nopin_timeout,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_nopin_response_timeout +*/ +DEF_NACL_ATTRIB (nopin_response_timeout); +NACL_ATTR (nopin_response_timeout,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_random_datain_pdu_offsets +*/ +DEF_NACL_ATTRIB (random_datain_pdu_offsets); +NACL_ATTR (random_datain_pdu_offsets,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_random_datain_seq_offsets +*/ +DEF_NACL_ATTRIB (random_datain_seq_offsets); +NACL_ATTR (random_datain_seq_offsets,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_node_attrib_s_random_r2t_offsets +*/ +DEF_NACL_ATTRIB (random_r2t_offsets); +NACL_ATTR (random_r2t_offsets,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { + &iscsi_nacl_attrib_dataout_timeout.attr, + &iscsi_nacl_attrib_dataout_timeout_retries.attr, + &iscsi_nacl_attrib_default_erl.attr, + &iscsi_nacl_attrib_nopin_timeout.attr, + &iscsi_nacl_attrib_nopin_response_timeout.attr, + &iscsi_nacl_attrib_random_datain_pdu_offsets.attr, + &iscsi_nacl_attrib_random_datain_seq_offsets.attr, + &iscsi_nacl_attrib_random_r2t_offsets.attr, +NULL , +}; + +/* End items for lio_target_nacl_attrib_cit */ + +/* Start items for lio_target_nacl_auth_cit */ + +#define __DEF_NACL_AUTH_STR (prefix, name, flags) \ +static ssize_t __iscsi_##prefix##_show_##name( \ + struct iscsi_node_acl *nacl, \ + char *page) \ +{ \ + struct iscsi_node_auth *auth = &nacl->node_auth; \ + ssize_t rb; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + rb = snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ + return rb; \ +} \ + \ +static ssize_t __iscsi_##prefix##_store_##name( \ + struct iscsi_node_acl *nacl, \ + const char *page, \ + size_t count) \ +{ \ + struct iscsi_node_auth *auth = &nacl->node_auth; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + \ + snprintf(auth->name, PAGE_SIZE, "%s", page); \ + if (!strncmp("NULL", auth->name, 4)) \ + auth->naf_flags &= ~flags; \ + else \ + auth->naf_flags |= flags; \ + \ + if ((auth->naf_flags & NAF_USERID_IN_SET) && \ + (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ + auth->authenticate_target = 1; \ + else \ + auth->authenticate_target = 0; \ + \ + return count; \ +} + +#define __DEF_NACL_AUTH_INT (prefix, name) \ +static ssize_t __iscsi_##prefix##_show_##name( \ + struct iscsi_node_acl *nacl, \ + char *page) \ +{ \ + struct iscsi_node_auth *auth = &nacl->node_auth; \ + ssize_t rb; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + \ + rb = snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ + return rb; \ +} + +#define DEF_NACL_AUTH_STR (name, flags) \ + __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ +static ssize_t iscsi_nacl_auth_show_##name( \ + struct se_node_acl *nacl, \ + char *page) \ +{ \ + return __iscsi_nacl_auth_show_##name(container_of(nacl, \ + struct iscsi_node_acl, se_node_acl), page); \ +} \ +static ssize_t iscsi_nacl_auth_store_##name( \ + struct se_node_acl *nacl, \ + const char *page, \ + size_t count) \ +{ \ + return __iscsi_nacl_auth_store_##name(container_of(nacl, \ + struct iscsi_node_acl, se_node_acl), page, count); \ +} + +#define DEF_NACL_AUTH_INT (name) \ + __DEF_NACL_AUTH_INT(nacl_auth, name) \ +static ssize_t iscsi_nacl_auth_show_##name( \ + struct se_node_acl *nacl, \ + char *page) \ +{ \ + return __iscsi_nacl_auth_show_##name(container_of(nacl, \ + struct iscsi_node_acl, se_node_acl), page); \ +} + +#define AUTH_ATTR (_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); +#define AUTH_ATTR_RO (_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); + +/* +* One-way authentication userid +*/ +DEF_NACL_AUTH_STR (userid,NAF_USERID_SET ); +AUTH_ATTR (userid,S_IRUGO |S_IWUSR ); +/* +* One-way authentication password +*/ +DEF_NACL_AUTH_STR (password,NAF_PASSWORD_SET ); +AUTH_ATTR (password,S_IRUGO |S_IWUSR ); +/* +* Enforce mutual authentication +*/ +DEF_NACL_AUTH_INT (authenticate_target); +AUTH_ATTR_RO (authenticate_target); +/* +* Mutual authentication userid +*/ +DEF_NACL_AUTH_STR (userid_mutual,NAF_USERID_IN_SET ); +AUTH_ATTR (userid_mutual,S_IRUGO |S_IWUSR ); +/* +* Mutual authentication password +*/ +DEF_NACL_AUTH_STR (password_mutual,NAF_PASSWORD_IN_SET ); +AUTH_ATTR (password_mutual,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { + &iscsi_nacl_auth_userid.attr, + &iscsi_nacl_auth_password.attr, + &iscsi_nacl_auth_authenticate_target.attr, + &iscsi_nacl_auth_userid_mutual.attr, + &iscsi_nacl_auth_password_mutual.attr, +NULL , +}; + +/* End items for lio_target_nacl_auth_cit */ + +/* Start items for lio_target_nacl_param_cit */ + +#define DEF_NACL_PARAM (name) \ +static ssize_t iscsi_nacl_param_show_##name( \ + struct se_node_acl *se_nacl, \ + char *page) \ +{ \ + struct iscsi_session *sess; \ + struct se_session *se_sess; \ + ssize_t rb; \ + \ + spin_lock_bh(&se_nacl->nacl_sess_lock); \ + se_sess = se_nacl->nacl_sess; \ + if (!se_sess) { \ + rb = snprintf(page, PAGE_SIZE, \ + "No Active iSCSI Session\n"); \ + } else { \ + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; \ + rb = snprintf(page, PAGE_SIZE, "%u\n", \ + (u32)sess->sess_ops->name); \ + } \ + spin_unlock_bh(&se_nacl->nacl_sess_lock); \ + \ + return rb; \ +} + +#define NACL_PARAM_ATTR (_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name); + +DEF_NACL_PARAM (MaxConnections); +NACL_PARAM_ATTR (MaxConnections); + +DEF_NACL_PARAM (InitialR2T); +NACL_PARAM_ATTR (InitialR2T); + +DEF_NACL_PARAM (ImmediateData); +NACL_PARAM_ATTR (ImmediateData); + +DEF_NACL_PARAM (MaxBurstLength); +NACL_PARAM_ATTR (MaxBurstLength); + +DEF_NACL_PARAM (FirstBurstLength); +NACL_PARAM_ATTR (FirstBurstLength); + +DEF_NACL_PARAM (DefaultTime2Wait); +NACL_PARAM_ATTR (DefaultTime2Wait); + +DEF_NACL_PARAM (DefaultTime2Retain); +NACL_PARAM_ATTR (DefaultTime2Retain); + +DEF_NACL_PARAM (MaxOutstandingR2T); +NACL_PARAM_ATTR (MaxOutstandingR2T); + +DEF_NACL_PARAM (DataPDUInOrder); +NACL_PARAM_ATTR (DataPDUInOrder); + +DEF_NACL_PARAM (DataSequenceInOrder); +NACL_PARAM_ATTR (DataSequenceInOrder); + +DEF_NACL_PARAM (ErrorRecoveryLevel); +NACL_PARAM_ATTR (ErrorRecoveryLevel); + +static struct configfs_attribute *lio_target_nacl_param_attrs[] = { + &iscsi_nacl_param_MaxConnections.attr, + &iscsi_nacl_param_InitialR2T.attr, + &iscsi_nacl_param_ImmediateData.attr, + &iscsi_nacl_param_MaxBurstLength.attr, + &iscsi_nacl_param_FirstBurstLength.attr, + &iscsi_nacl_param_DefaultTime2Wait.attr, + &iscsi_nacl_param_DefaultTime2Retain.attr, + &iscsi_nacl_param_MaxOutstandingR2T.attr, + &iscsi_nacl_param_DataPDUInOrder.attr, + &iscsi_nacl_param_DataSequenceInOrder.attr, + &iscsi_nacl_param_ErrorRecoveryLevel.attr, +NULL , +}; + +/* End items for lio_target_nacl_param_cit */ + +/* Start items for lio_target_acl_cit */ + +static ssize_t lio_target_nacl_show_info ( +struct se_node_acl *se_nacl, +char *page) +{ +struct iscsi_session *sess; +struct iscsi_conn *conn; +struct se_session *se_sess; +unsigned char *ip, buf_ipv4[IPV4_BUF_SIZE ]; +ssize_t rb =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (!se_sess) { + rb +=sprintf (page+rb,"No active iSCSI Session for Initiator" +" Endpoint: %s\n" , se_nacl->initiatorname); + }else { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; + +if (sess->sess_ops->InitiatorName) + rb +=sprintf (page+rb,"InitiatorName: %s\n" , + sess->sess_ops->InitiatorName); +if (sess->sess_ops->InitiatorAlias) + rb +=sprintf (page+rb,"InitiatorAlias: %s\n" , + sess->sess_ops->InitiatorAlias); + + rb +=sprintf (page+rb,"LIO Session ID: %u " +"ISID: 0x%02x %02x %02x %02x %02x %02x " +"TSIH: %hu " , sess->sid, + sess->isid[0 ], sess->isid[1 ], sess->isid[2 ], + sess->isid[3 ], sess->isid[4 ], sess->isid[5 ], + sess->tsih); + rb +=sprintf (page+rb,"SessionType: %s\n" , + (sess->sess_ops->SessionType) ? +"Discovery" :"Normal" ); + rb +=sprintf (page+rb,"Session State: " ); +switch (sess->session_state) { +case TARG_SESS_STATE_FREE : + rb +=sprintf (page+rb,"TARG_SESS_FREE\n" ); +break ; +case TARG_SESS_STATE_ACTIVE : + rb +=sprintf (page+rb,"TARG_SESS_STATE_ACTIVE\n" ); +break ; +case TARG_SESS_STATE_LOGGED_IN : + rb +=sprintf (page+rb,"TARG_SESS_STATE_LOGGED_IN\n" ); +break ; +case TARG_SESS_STATE_FAILED : + rb +=sprintf (page+rb,"TARG_SESS_STATE_FAILED\n" ); +break ; +case TARG_SESS_STATE_IN_CONTINUE : + rb +=sprintf (page+rb,"TARG_SESS_STATE_IN_CONTINUE\n" ); +break ; +default : + rb +=sprintf (page+rb,"ERROR: Unknown Session" +" State!\n" ); +break ; + } + + rb +=sprintf (page+rb,"---------------------[iSCSI Session" +" Values]-----------------------\n" ); + rb +=sprintf (page+rb," CmdSN/WR : CmdSN/WC : ExpCmdSN" +" : MaxCmdSN : ITT : TTT\n" ); + rb +=sprintf (page+rb," 0x%08x 0x%08x 0x%08x 0x%08x" +" 0x%08x 0x%08x\n" , + sess->cmdsn_window, + (sess->max_cmd_sn - sess->exp_cmd_sn) +1 , + sess->exp_cmd_sn, sess->max_cmd_sn, + sess->init_task_tag, sess->targ_xfer_tag); + rb +=sprintf (page+rb,"----------------------[iSCSI" +" Connections]-------------------------\n" ); + +spin_lock (&sess->conn_lock); +list_for_each_entry (conn, &sess->sess_conn_list, conn_list) { + rb +=sprintf (page+rb,"CID: %hu Connection" +" State: " , conn->cid); +switch (conn->conn_state) { +case TARG_CONN_STATE_FREE : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_FREE\n" ); +break ; +case TARG_CONN_STATE_XPT_UP : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_XPT_UP\n" ); +break ; +case TARG_CONN_STATE_IN_LOGIN : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_IN_LOGIN\n" ); +break ; +case TARG_CONN_STATE_LOGGED_IN : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_LOGGED_IN\n" ); +break ; +case TARG_CONN_STATE_IN_LOGOUT : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_IN_LOGOUT\n" ); +break ; +case TARG_CONN_STATE_LOGOUT_REQUESTED : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_LOGOUT_REQUESTED\n" ); +break ; +case TARG_CONN_STATE_CLEANUP_WAIT : + rb +=sprintf (page+rb, +"TARG_CONN_STATE_CLEANUP_WAIT\n" ); +break ; +default : + rb +=sprintf (page+rb, +"ERROR: Unknown Connection State!\n" ); +break ; + } + +if (conn->net_size ==IPV6_ADDRESS_SPACE ) { + ip = &conn->ipv6_login_ip[0 ]; + }else { +iscsi_ntoa2 (buf_ipv4, conn->login_ip); + ip = &buf_ipv4[0 ]; + } + rb +=sprintf (page+rb," Address %s %s" , ip, + (conn->network_transport ==ISCSI_TCP ) ? +"TCP" :"SCTP" ); + rb +=sprintf (page+rb," StatSN: 0x%08x\n" , + conn->stat_sn); + } +spin_unlock (&sess->conn_lock); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return rb; +} + +TF_NACL_BASE_ATTR_RO (lio_target, info); + +static ssize_t lio_target_nacl_show_cmdsn_depth ( +struct se_node_acl *se_nacl, +char *page) +{ +return sprintf (page,"%u\n" , se_nacl->queue_depth); +} + +static ssize_t lio_target_nacl_store_cmdsn_depth ( +struct se_node_acl *se_nacl, +const char *page, +size_t count) +{ +struct se_portal_group *se_tpg = se_nacl->se_tpg; +struct iscsi_portal_group *tpg =container_of (se_tpg, + struct iscsi_portal_group, tpg_se_tpg); +struct config_item *acl_ci, *tpg_ci, *wwn_ci; +char *endptr; +u32 cmdsn_depth =0 ; +int ret; + + cmdsn_depth =simple_strtoul (page, &endptr,0 ); +if (cmdsn_depth >TA_DEFAULT_CMDSN_DEPTH_MAX ) { +printk (KERN_ERR "Passed cmdsn_depth: %u exceeds" +" TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n" , cmdsn_depth, +TA_DEFAULT_CMDSN_DEPTH_MAX ); +return -EINVAL ; + } + acl_ci = &se_nacl->acl_group.cg_item; +if (!acl_ci) { +printk (KERN_ERR "Unable to locatel acl_ci\n" ); +return -EINVAL ; + } + tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; +if (!tpg_ci) { +printk (KERN_ERR "Unable to locate tpg_ci\n" ); +return -EINVAL ; + } + wwn_ci = &tpg_ci->ci_group->cg_item; +if (!wwn_ci) { +printk (KERN_ERR "Unable to locate config_item wwn_ci\n" ); +return -EINVAL ; + } + +if (iscsi_get_tpg (tpg) <0 ) +return -EINVAL ; +/* +* iscsi_tpg_set_initiator_node_queue_depth() assumes force=1 +*/ + ret =iscsi_tpg_set_initiator_node_queue_depth (tpg, +config_item_name (acl_ci), cmdsn_depth,1 ); + +printk (KERN_INFO "LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" +"InitiatorName: %s\n" ,config_item_name (wwn_ci), +config_item_name (tpg_ci), cmdsn_depth, +config_item_name (acl_ci)); + +iscsi_put_tpg (tpg); +return (!ret) ? count : (ssize_t )ret; +} + +TF_NACL_BASE_ATTR (lio_target, cmdsn_depth,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_initiator_attrs[] = { + &lio_target_nacl_info.attr, + &lio_target_nacl_cmdsn_depth.attr, +NULL , +}; + +static struct se_node_acl *lio_target_make_nodeacl ( +struct se_portal_group *se_tpg, +struct config_group *group, +const char *name) +{ +struct config_group *stats_cg; +struct iscsi_node_acl *acl; +struct se_node_acl *se_nacl_new, *se_nacl; +struct iscsi_portal_group *tpg =container_of (se_tpg, + struct iscsi_portal_group, tpg_se_tpg); +u32 cmdsn_depth; + + se_nacl_new =lio_tpg_alloc_fabric_acl (se_tpg); + + acl = container_of(se_nacl_new, struct iscsi_node_acl, + se_node_acl); + + cmdsn_depth =ISCSI_TPG_ATTRIB (tpg)->default_cmdsn_depth; +/* +* se_nacl_new may be released by core_tpg_add_initiator_node_acl() +* when converting a NdoeACL from demo mode -> explict +*/ + se_nacl =core_tpg_add_initiator_node_acl (se_tpg, se_nacl_new, + name, cmdsn_depth); +if (IS_ERR (se_nacl)) +return ERR_PTR (PTR_ERR (se_nacl)); + + stats_cg = &acl->se_node_acl.acl_fabric_stat_group; + + stats_cg->default_groups =kzalloc (sizeof (struct config_group ) *2 , +GFP_KERNEL ); +if (!stats_cg->default_groups) { +printk (KERN_ERR "Unable to allocate memory for" +" stats_cg->default_groups\n" ); +core_tpg_del_initiator_node_acl (se_tpg, se_nacl,1 ); +kfree (acl); +return ERR_PTR (-ENOMEM ); + } + + stats_cg->default_groups[0 ] = &NODE_STAT_GRPS (acl)->iscsi_sess_stats_group; + stats_cg->default_groups[1 ] =NULL ; +config_group_init_type_name (&NODE_STAT_GRPS (acl)->iscsi_sess_stats_group, +"iscsi_sess_stats" , &iscsi_stat_sess_cit); + +return se_nacl; +} + +static void lio_target_drop_nodeacl ( +struct se_node_acl *se_nacl) +{ +struct se_portal_group *se_tpg = se_nacl->se_tpg; +struct iscsi_node_acl *acl =container_of (se_nacl, + struct iscsi_node_acl, se_node_acl); +struct config_item *df_item; +struct config_group *stats_cg; +int i; + + stats_cg = &acl->se_node_acl.acl_fabric_stat_group; +for (i =0 ; stats_cg->default_groups[i]; i++) { + df_item = &stats_cg->default_groups[i]->cg_item; + stats_cg->default_groups[i] =NULL ; +config_item_put (df_item); + } +kfree (stats_cg->default_groups); + +core_tpg_del_initiator_node_acl (se_tpg, se_nacl,1 ); +kfree (acl); +} + +/* End items for lio_target_acl_cit */ + +/* Start items for lio_target_tpg_attrib_cit */ + +#define DEF_TPG_ATTRIB (name) \ + \ +static ssize_t iscsi_tpg_attrib_show_##name( \ + struct se_portal_group *se_tpg, \ + char *page) \ +{ \ + struct iscsi_portal_group *tpg = container_of(se_tpg, \ + struct iscsi_portal_group, tpg_se_tpg); \ + ssize_t rb; \ + \ + if (iscsi_get_tpg(tpg) < 0) \ + return -EINVAL; \ + \ + rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \ + iscsi_put_tpg(tpg); \ + return rb; \ +} \ + \ +static ssize_t iscsi_tpg_attrib_store_##name( \ + struct se_portal_group *se_tpg, \ + const char *page, \ + size_t count) \ +{ \ + struct iscsi_portal_group *tpg = container_of(se_tpg, \ + struct iscsi_portal_group, tpg_se_tpg); \ + char *endptr; \ + u32 val; \ + int ret; \ + \ + if (iscsi_get_tpg(tpg) < 0) \ + return -EINVAL; \ + \ + val = simple_strtoul(page, &endptr, 0); \ + ret = iscsi_ta_##name(tpg, val); \ + if (ret < 0) \ + goto out; \ + \ + iscsi_put_tpg(tpg); \ + return count; \ +out: \ + iscsi_put_tpg(tpg); \ + return ret; \ +} + +#define TPG_ATTR (_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode); + +/* +* Define iscsi_tpg_attrib_s_authentication +*/ +DEF_TPG_ATTRIB (authentication); +TPG_ATTR (authentication,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_tpg_attrib_s_login_timeout +*/ +DEF_TPG_ATTRIB (login_timeout); +TPG_ATTR (login_timeout,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_tpg_attrib_s_netif_timeout +*/ +DEF_TPG_ATTRIB (netif_timeout); +TPG_ATTR (netif_timeout,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_tpg_attrib_s_generate_node_acls +*/ +DEF_TPG_ATTRIB (generate_node_acls); +TPG_ATTR (generate_node_acls,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_tpg_attrib_s_default_cmdsn_depth +*/ +DEF_TPG_ATTRIB (default_cmdsn_depth); +TPG_ATTR (default_cmdsn_depth,S_IRUGO |S_IWUSR ); +/* +Define iscsi_tpg_attrib_s_cache_dynamic_acls +*/ +DEF_TPG_ATTRIB (cache_dynamic_acls); +TPG_ATTR (cache_dynamic_acls,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_tpg_attrib_s_demo_mode_write_protect +*/ +DEF_TPG_ATTRIB (demo_mode_write_protect); +TPG_ATTR (demo_mode_write_protect,S_IRUGO |S_IWUSR ); +/* +* Define iscsi_tpg_attrib_s_prod_mode_write_protect +*/ +DEF_TPG_ATTRIB (prod_mode_write_protect); +TPG_ATTR (prod_mode_write_protect,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { + &iscsi_tpg_attrib_authentication.attr, + &iscsi_tpg_attrib_login_timeout.attr, + &iscsi_tpg_attrib_netif_timeout.attr, + &iscsi_tpg_attrib_generate_node_acls.attr, + &iscsi_tpg_attrib_default_cmdsn_depth.attr, + &iscsi_tpg_attrib_cache_dynamic_acls.attr, + &iscsi_tpg_attrib_demo_mode_write_protect.attr, + &iscsi_tpg_attrib_prod_mode_write_protect.attr, +NULL , +}; + +/* End items for lio_target_tpg_attrib_cit */ + +/* Start items for lio_target_tpg_param_cit */ + +#define DEF_TPG_PARAM (name) \ +static ssize_t iscsi_tpg_param_show_##name( \ + struct se_portal_group *se_tpg, \ + char *page) \ +{ \ + struct iscsi_portal_group *tpg = container_of(se_tpg, \ + struct iscsi_portal_group, tpg_se_tpg); \ + struct iscsi_param *param; \ + ssize_t rb; \ + \ + if (iscsi_get_tpg(tpg) < 0) \ + return -EINVAL; \ + \ + param = iscsi_find_param_from_key(__stringify(name), \ + tpg->param_list); \ + if (!param) { \ + iscsi_put_tpg(tpg); \ + return -EINVAL; \ + } \ + rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ + \ + iscsi_put_tpg(tpg); \ + return rb; \ +} \ +static ssize_t iscsi_tpg_param_store_##name( \ + struct se_portal_group *se_tpg, \ + const char *page, \ + size_t count) \ +{ \ + struct iscsi_portal_group *tpg = container_of(se_tpg, \ + struct iscsi_portal_group, tpg_se_tpg); \ + char *buf; \ + int ret; \ + \ + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ + if (!buf) \ + return -ENOMEM; \ + snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ + buf[strlen(buf)-1] = '\0';/* Kill newline */ \ + \ +if (iscsi_get_tpg (tpg) <0 ) \ +return -EINVAL ; \ + \ + ret =iscsi_change_param_value (buf, tpg->param_list,1 ); \ +if (ret <0 ) \ + goto out; \ + \ +kfree (buf); \ +iscsi_put_tpg (tpg); \ +return count; \ +out: \ +kfree (buf); \ +iscsi_put_tpg (tpg); \ +return -EINVAL ; \ +} + +#define TPG_PARAM_ATTR (_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode); + +DEF_TPG_PARAM (AuthMethod); +TPG_PARAM_ATTR (AuthMethod,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (HeaderDigest); +TPG_PARAM_ATTR (HeaderDigest,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (DataDigest); +TPG_PARAM_ATTR (DataDigest,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (MaxConnections); +TPG_PARAM_ATTR (MaxConnections,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (TargetAlias); +TPG_PARAM_ATTR (TargetAlias,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (InitialR2T); +TPG_PARAM_ATTR (InitialR2T,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (ImmediateData); +TPG_PARAM_ATTR (ImmediateData,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (MaxRecvDataSegmentLength); +TPG_PARAM_ATTR (MaxRecvDataSegmentLength,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (MaxBurstLength); +TPG_PARAM_ATTR (MaxBurstLength,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (FirstBurstLength); +TPG_PARAM_ATTR (FirstBurstLength,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (DefaultTime2Wait); +TPG_PARAM_ATTR (DefaultTime2Wait,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (DefaultTime2Retain); +TPG_PARAM_ATTR (DefaultTime2Retain,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (MaxOutstandingR2T); +TPG_PARAM_ATTR (MaxOutstandingR2T,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (DataPDUInOrder); +TPG_PARAM_ATTR (DataPDUInOrder,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (DataSequenceInOrder); +TPG_PARAM_ATTR (DataSequenceInOrder,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (ErrorRecoveryLevel); +TPG_PARAM_ATTR (ErrorRecoveryLevel,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (IFMarker); +TPG_PARAM_ATTR (IFMarker,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (OFMarker); +TPG_PARAM_ATTR (OFMarker,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (IFMarkInt); +TPG_PARAM_ATTR (IFMarkInt,S_IRUGO |S_IWUSR ); + +DEF_TPG_PARAM (OFMarkInt); +TPG_PARAM_ATTR (OFMarkInt,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_tpg_param_attrs[] = { + &iscsi_tpg_param_AuthMethod.attr, + &iscsi_tpg_param_HeaderDigest.attr, + &iscsi_tpg_param_DataDigest.attr, + &iscsi_tpg_param_MaxConnections.attr, + &iscsi_tpg_param_TargetAlias.attr, + &iscsi_tpg_param_InitialR2T.attr, + &iscsi_tpg_param_ImmediateData.attr, + &iscsi_tpg_param_MaxRecvDataSegmentLength.attr, + &iscsi_tpg_param_MaxBurstLength.attr, + &iscsi_tpg_param_FirstBurstLength.attr, + &iscsi_tpg_param_DefaultTime2Wait.attr, + &iscsi_tpg_param_DefaultTime2Retain.attr, + &iscsi_tpg_param_MaxOutstandingR2T.attr, + &iscsi_tpg_param_DataPDUInOrder.attr, + &iscsi_tpg_param_DataSequenceInOrder.attr, + &iscsi_tpg_param_ErrorRecoveryLevel.attr, + &iscsi_tpg_param_IFMarker.attr, + &iscsi_tpg_param_OFMarker.attr, + &iscsi_tpg_param_IFMarkInt.attr, + &iscsi_tpg_param_OFMarkInt.attr, +NULL , +}; + +/* End items for lio_target_tpg_param_cit */ + +/* Start items for lio_target_tpg_cit */ + +static ssize_t lio_target_tpg_show_enable ( +struct se_portal_group *se_tpg, +char *page) +{ +struct iscsi_portal_group *tpg =container_of (se_tpg, + struct iscsi_portal_group, tpg_se_tpg); +ssize_t len; + +spin_lock (&tpg->tpg_state_lock); + len =sprintf (page,"%d\n" , + (tpg->tpg_state ==TPG_STATE_ACTIVE ) ?1 :0 ); +spin_unlock (&tpg->tpg_state_lock); + +return len; +} + +static ssize_t lio_target_tpg_store_enable ( +struct se_portal_group *se_tpg, +const char *page, +size_t count) +{ +struct iscsi_portal_group *tpg =container_of (se_tpg, + struct iscsi_portal_group, tpg_se_tpg); +char *endptr; +u32 op; +int ret =0 ; + + op =simple_strtoul (page, &endptr,0 ); +if ((op !=1 ) && (op !=0 )) { +printk (KERN_ERR "Illegal value for tpg_enable: %u\n" , op); +return -EINVAL ; + } + + ret =iscsi_get_tpg (tpg); +if (ret <0 ) +return -EINVAL ; + +if (op) { + ret =iscsi_tpg_enable_portal_group (tpg); +if (ret <0 ) + goto out; + }else { +/* +* iscsi_tpg_disable_portal_group() assumes force=1 +*/ + ret =iscsi_tpg_disable_portal_group (tpg,1 ); +if (ret <0 ) + goto out; + } + +iscsi_put_tpg (tpg); +return count; +out: +iscsi_put_tpg (tpg); +return -EINVAL ; +} + +TF_TPG_BASE_ATTR (lio_target, enable,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_tpg_attrs[] = { + &lio_target_tpg_enable.attr, +NULL , +}; + +/* End items for lio_target_tpg_cit */ + +/* Start items for lio_target_tiqn_cit */ + +struct se_portal_group *lio_target_tiqn_addtpg ( +struct se_wwn *wwn, +struct config_group *group, +const char *name) +{ +struct iscsi_portal_group *tpg; +struct iscsi_tiqn *tiqn; +char *tpgt_str, *end_ptr; +int ret =0 ; +unsigned short int tpgt; + + tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); +/* +* Only tpgt_# directory groups can be created below +* target/iscsi/iqn.superturodiskarry/ +*/ + tpgt_str =strstr (name,"tpgt_" ); +if (!tpgt_str) { +printk (KERN_ERR "Unable to locate \"tpgt_#\" directory" +" group\n" ); +return NULL ; + } + tpgt_str +=5 ;/* Skip ahead of "tpgt_" */ + tpgt = (unsigned short int )simple_strtoul (tpgt_str, &end_ptr,0 ); + + tpg =iscsit_alloc_portal_group (tiqn, tpgt); +if (!tpg) +return NULL ; + + ret =core_tpg_register ( + &lio_target_fabric_configfs->tf_ops, + wwn, &tpg->tpg_se_tpg, (void *)tpg, +TRANSPORT_TPG_TYPE_NORMAL ); +if (ret <0 ) +return NULL ; + + ret =iscsi_tpg_add_portal_group (tiqn, tpg); +if (ret !=0 ) + goto out; + +printk (KERN_INFO "LIO_Target_ConfigFS: REGISTER -> %s\n" , tiqn->tiqn); +printk (KERN_INFO "LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n" , + name); +return &tpg->tpg_se_tpg; +out: +core_tpg_deregister (&tpg->tpg_se_tpg); +kfree (tpg); +return NULL ; +} + +void lio_target_tiqn_deltpg (struct se_portal_group *se_tpg) +{ +struct iscsi_portal_group *tpg; +struct iscsi_tiqn *tiqn; + + tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); + tiqn = tpg->tpg_tiqn; +/* +* iscsi_tpg_del_portal_group() assumes force=1 +*/ +printk (KERN_INFO "LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n" ); +iscsi_tpg_del_portal_group (tiqn, tpg,1 ); +} + +/* End items for lio_target_tiqn_cit */ + +/* Start LIO-Target TIQN struct contig_item lio_target_cit */ + +static ssize_t lio_target_wwn_show_attr_lio_version ( +struct target_fabric_configfs *tf, +char *page) +{ +return sprintf (page,"RisingTide Systems Linux-iSCSI Target " ISCSI_VERSION "\n" ); +} + +TF_WWN_ATTR_RO (lio_target, lio_version); + +static struct configfs_attribute *lio_target_wwn_attrs[] = { + &lio_target_wwn_lio_version.attr, +NULL , +}; + +struct se_wwn *lio_target_call_coreaddtiqn ( +struct target_fabric_configfs *tf, +struct config_group *group, +const char *name) +{ +struct config_group *stats_cg; +struct iscsi_tiqn *tiqn; +int ret =0 ; + + tiqn =iscsit_add_tiqn ((unsigned char *)name, &ret); +if (!tiqn) +return NULL ; +/* +* Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. +*/ + stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; + + stats_cg->default_groups =kzalloc (sizeof (struct config_group ) *6 , +GFP_KERNEL ); +if (!stats_cg->default_groups) { +printk (KERN_ERR "Unable to allocate memory for" +" stats_cg->default_groups\n" ); +iscsit_del_tiqn (tiqn); +return ERR_PTR (-ENOMEM ); + } + + stats_cg->default_groups[0 ] = &WWN_STAT_GRPS (tiqn)->iscsi_instance_group; + stats_cg->default_groups[1 ] = &WWN_STAT_GRPS (tiqn)->iscsi_sess_err_group; + stats_cg->default_groups[2 ] = &WWN_STAT_GRPS (tiqn)->iscsi_tgt_attr_group; + stats_cg->default_groups[3 ] = &WWN_STAT_GRPS (tiqn)->iscsi_login_stats_group; + stats_cg->default_groups[4 ] = &WWN_STAT_GRPS (tiqn)->iscsi_logout_stats_group; + stats_cg->default_groups[5 ] =NULL ; +config_group_init_type_name (&WWN_STAT_GRPS (tiqn)->iscsi_instance_group, +"iscsi_instance" , &iscsi_stat_instance_cit); +config_group_init_type_name (&WWN_STAT_GRPS (tiqn)->iscsi_sess_err_group, +"iscsi_sess_err" , &iscsi_stat_sess_err_cit); +config_group_init_type_name (&WWN_STAT_GRPS (tiqn)->iscsi_tgt_attr_group, +"iscsi_tgt_attr" , &iscsi_stat_tgt_attr_cit); +config_group_init_type_name (&WWN_STAT_GRPS (tiqn)->iscsi_login_stats_group, +"iscsi_login_stats" , &iscsi_stat_login_cit); +config_group_init_type_name (&WWN_STAT_GRPS (tiqn)->iscsi_logout_stats_group, +"iscsi_logout_stats" , &iscsi_stat_logout_cit); + +printk (KERN_INFO "LIO_Target_ConfigFS: REGISTER -> %s\n" , tiqn->tiqn); +printk (KERN_INFO "LIO_Target_ConfigFS: REGISTER -> Allocated Node:" +" %s\n" , name); +return &tiqn->tiqn_wwn; +} + +void lio_target_call_coredeltiqn ( +struct se_wwn *wwn) +{ + struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); +struct config_item *df_item; +struct config_group *stats_cg; +int i; + + stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; +for (i =0 ; stats_cg->default_groups[i]; i++) { + df_item = &stats_cg->default_groups[i]->cg_item; + stats_cg->default_groups[i] =NULL ; +config_item_put (df_item); + } +kfree (stats_cg->default_groups); + +printk (KERN_INFO "LIO_Target_ConfigFS: DEREGISTER -> %s\n" , + tiqn->tiqn); +iscsit_del_tiqn (tiqn); +} + +/* End LIO-Target TIQN struct contig_lio_target_cit */ + +/* Start lio_target_discovery_auth_cit */ + +#define DEF_DISC_AUTH_STR (name, flags) \ + __DEF_NACL_AUTH_STR(disc, name, flags) \ +static ssize_t iscsi_disc_show_##name( \ + struct target_fabric_configfs *tf, \ + char *page) \ +{ \ + return __iscsi_disc_show_##name(&iscsi_global->discovery_acl, \ + page); \ +} \ +static ssize_t iscsi_disc_store_##name( \ + struct target_fabric_configfs *tf, \ + const char *page, \ + size_t count) \ +{ \ + return __iscsi_disc_store_##name(&iscsi_global->discovery_acl, \ + page, count); \ +} + +#define DEF_DISC_AUTH_INT (name) \ + __DEF_NACL_AUTH_INT(disc, name) \ +static ssize_t iscsi_disc_show_##name( \ + struct target_fabric_configfs *tf, \ + char *page) \ +{ \ + return __iscsi_disc_show_##name(&iscsi_global->discovery_acl, \ + page); \ +} + +#define DISC_AUTH_ATTR (_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode) +#define DISC_AUTH_ATTR_RO (_name) TF_DISC_ATTR_RO(iscsi, _name) + +/* +* One-way authentication userid +*/ +DEF_DISC_AUTH_STR (userid,NAF_USERID_SET ); +DISC_AUTH_ATTR (userid,S_IRUGO |S_IWUSR ); +/* +* One-way authentication password +*/ +DEF_DISC_AUTH_STR (password,NAF_PASSWORD_SET ); +DISC_AUTH_ATTR (password,S_IRUGO |S_IWUSR ); +/* +* Enforce mutual authentication +*/ +DEF_DISC_AUTH_INT (authenticate_target); +DISC_AUTH_ATTR_RO (authenticate_target); +/* +* Mutual authentication userid +*/ +DEF_DISC_AUTH_STR (userid_mutual,NAF_USERID_IN_SET ); +DISC_AUTH_ATTR (userid_mutual,S_IRUGO |S_IWUSR ); +/* +* Mutual authentication password +*/ +DEF_DISC_AUTH_STR (password_mutual,NAF_PASSWORD_IN_SET ); +DISC_AUTH_ATTR (password_mutual,S_IRUGO |S_IWUSR ); + +/* +* enforce_discovery_auth +*/ +static ssize_t iscsi_disc_show_enforce_discovery_auth ( +struct target_fabric_configfs *tf, +char *page) +{ +struct iscsi_node_auth *discovery_auth = &iscsi_global->discovery_acl.node_auth; + +return sprintf (page,"%d\n" , discovery_auth->enforce_discovery_auth); +} + +static ssize_t iscsi_disc_store_enforce_discovery_auth ( +struct target_fabric_configfs *tf, +const char *page, +size_t count) +{ +struct iscsi_param *param; +struct iscsi_portal_group *discovery_tpg = iscsi_global->discovery_tpg; +char *endptr; +u32 op; + + op =simple_strtoul (page, &endptr,0 ); +if ((op !=1 ) && (op !=0 )) { +printk (KERN_ERR "Illegal value for enforce_discovery_auth:" +" %u\n" , op); +return -EINVAL ; + } + +if (!discovery_tpg) { +printk (KERN_ERR "iscsi_global->discovery_tpg is NULL\n" ); +return -EINVAL ; + } + + param =iscsi_find_param_from_key (AUTHMETHOD , + discovery_tpg->param_list); +if (!param) +return -EINVAL ; + +if (op) { +/* +* Reset the AuthMethod key to CHAP. +*/ +if (iscsi_update_param_value (param,CHAP ) <0 ) +return -EINVAL ; + + discovery_tpg->tpg_attrib.authentication =1 ; + iscsi_global->discovery_acl.node_auth.enforce_discovery_auth =1 ; +printk (KERN_INFO "LIO-CORE[0] Successfully enabled" +" authentication enforcement for iSCSI" +" Discovery TPG\n" ); + }else { +/* +* Reset the AuthMethod key to CHAP,None +*/ +if (iscsi_update_param_value (param,"CHAP,None" ) <0 ) +return -EINVAL ; + + discovery_tpg->tpg_attrib.authentication =0 ; + iscsi_global->discovery_acl.node_auth.enforce_discovery_auth =0 ; +printk (KERN_INFO "LIO-CORE[0] Successfully disabled" +" authentication enforcement for iSCSI" +" Discovery TPG\n" ); + } + +return count; +} + +DISC_AUTH_ATTR (enforce_discovery_auth,S_IRUGO |S_IWUSR ); + +static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { + &iscsi_disc_userid.attr, + &iscsi_disc_password.attr, + &iscsi_disc_authenticate_target.attr, + &iscsi_disc_userid_mutual.attr, + &iscsi_disc_password_mutual.attr, + &iscsi_disc_enforce_discovery_auth.attr, +NULL , +}; + +/* End lio_target_discovery_auth_cit */ + +int iscsi_target_register_configfs (void ) +{ +struct target_fabric_configfs *fabric; +int ret; + + lio_target_fabric_configfs =NULL ; + fabric =target_fabric_configfs_init (THIS_MODULE ,"iscsi" ); +if (!fabric) { +printk (KERN_ERR "target_fabric_configfs_init() for" +" LIO-Target failed!\n" ); +return -1 ; + } +/* +* Setup the fabric API of function pointers used by target_core_mod.. +*/ + fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name; + fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident; + fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn; + fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag; + fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth; + fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id; + fabric->tf_ops.tpg_get_pr_transport_id_len = + &iscsi_get_pr_transport_id_len; + fabric->tf_ops.tpg_parse_pr_out_transport_id = + &iscsi_parse_pr_out_transport_id; + fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode; + fabric->tf_ops.tpg_check_demo_mode_cache = + &lio_tpg_check_demo_mode_cache; + fabric->tf_ops.tpg_check_demo_mode_write_protect = + &lio_tpg_check_demo_mode_write_protect; + fabric->tf_ops.tpg_check_prod_mode_write_protect = + &lio_tpg_check_prod_mode_write_protect; + fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl; + fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl; + fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index; +/* +* Use our local iscsi_allocate_iovecs_for_cmd() for the extra +* callback in transport_generic_new_cmd() to allocate +* iscsi_cmd->iov_data[] for Linux/Net kernel sockets operations. +*/ + fabric->tf_ops.alloc_cmd_iovecs = &iscsi_allocate_iovecs_for_cmd; + fabric->tf_ops.release_cmd_to_pool = &lio_release_cmd_to_pool; + fabric->tf_ops.release_cmd_direct = &lio_release_cmd_direct; + fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session; + fabric->tf_ops.close_session = &lio_tpg_close_session; + fabric->tf_ops.stop_session = &lio_tpg_stop_session; + fabric->tf_ops.fall_back_to_erl0 = &lio_tpg_fall_back_to_erl0; + fabric->tf_ops.sess_logged_in = &lio_sess_logged_in; + fabric->tf_ops.sess_get_index = &lio_sess_get_index; + fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid; + fabric->tf_ops.write_pending = &lio_write_pending; + fabric->tf_ops.write_pending_status = &lio_write_pending_status; + fabric->tf_ops.set_default_node_attributes = + &lio_set_default_node_attributes; + fabric->tf_ops.get_task_tag = &iscsi_get_task_tag; + fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state; + fabric->tf_ops.new_cmd_failure = &iscsi_new_cmd_failure; + fabric->tf_ops.queue_data_in = &lio_queue_data_in; + fabric->tf_ops.queue_status = &lio_queue_status; + fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp; + fabric->tf_ops.set_fabric_sense_len = &lio_set_fabric_sense_len; + fabric->tf_ops.get_fabric_sense_len = &lio_get_fabric_sense_len; + fabric->tf_ops.is_state_remove = &iscsi_is_state_remove; + fabric->tf_ops.pack_lun = &iscsi_pack_lun; +/* +* Setup function pointers for generic logic in target_core_fabric_configfs.c +*/ + fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn; + fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn; + fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg; + fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg; + fabric->tf_ops.fabric_post_link =NULL ; + fabric->tf_ops.fabric_pre_unlink =NULL ; + fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg; + fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg; + fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl; + fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl; +/* +* Setup default attribute lists for various fabric->tf_cit_tmpl +* sturct config_item_type's +*/ +TF_CIT_TMPL (fabric)->tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs; +TF_CIT_TMPL (fabric)->tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs; +TF_CIT_TMPL (fabric)->tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs; + + ret =target_fabric_configfs_register (fabric); +if (ret <0 ) { +printk (KERN_ERR "target_fabric_configfs_register() for" +" LIO-Target failed!\n" ); +target_fabric_configfs_free (fabric); +return -1 ; + } + + lio_target_fabric_configfs = fabric; +printk (KERN_INFO "LIO_TARGET[0] - Set fabric ->" +" lio_target_fabric_configfs\n" ); +return 0 ; +} + + +void iscsi_target_deregister_configfs (void ) +{ +if (!lio_target_fabric_configfs) +return ; +/* +* Shutdown discovery sessions and disable discovery TPG +*/ +if (iscsi_global->discovery_tpg) +iscsi_tpg_disable_portal_group (iscsi_global->discovery_tpg,1 ); + +target_fabric_configfs_deregister (lio_target_fabric_configfs); + lio_target_fabric_configfs =NULL ; +printk (KERN_INFO "LIO_TARGET[0] - Cleared" +" lio_target_fabric_configfs\n" ); +}
drivers/target/iscsi/iscsi_target_configfs.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef ISCSI_TARGET_CONFIGFS_H +#define ISCSI_TARGET_CONFIGFS_H + +extern int iscsi_target_register_configfs (void ); +extern void iscsi_target_deregister_configfs (void ); + +#endif /* ISCSI_TARGET_CONFIGFS_H */
drivers/target/iscsi/iscsi_target_nodeattrib.c new file +264 -0
264 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_nodeattrib.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef ISCSI_TARGET_NODEATTRIB_H +#define ISCSI_TARGET_NODEATTRIB_H + +extern void iscsi_set_default_node_attribues (struct iscsi_node_acl *); +extern int iscsi_na_dataout_timeout (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_dataout_timeout_retries (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_nopin_timeout (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_nopin_response_timeout (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_random_datain_pdu_offsets (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_random_datain_seq_offsets (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_random_r2t_offsets (struct iscsi_node_acl *,u32 ); +extern int iscsi_na_default_erl (struct iscsi_node_acl *,u32 ); + +#endif /* ISCSI_TARGET_NODEATTRIB_H */
Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC-v3 03/12] iscsi-target: Add TCM v4 compatiable ConfigFS control plane
Quoted 31 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch adds support for
/sys/kernel/config/target/iscsiusing TCM v4.0 compatiable calls followingtarget_core_fabric_configfs.cThis includes a number of iSCSI fabric dependent attributes upon
target_core_fabric_configfs.cprovided structconfig_item_typesfrominclude/target/target_core_configfs.hstructtarget_fabric_configfs_templateIt also includes iscsi_target_nodeattrib.[c,h] for handling the lio_target_nacl_attrib_attrs[] store/show for iSCSI fabric dependent attributes.
Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/iscsi/iscsi_target_configfs.c | 1593 ++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_configfs.h | 7 + drivers/target/iscsi/iscsi_target_nodeattrib.c | 264 ++++ drivers/target/iscsi/iscsi_target_nodeattrib.h | 14 + 4 files changed, 1878 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_configfs.c create mode 100644 drivers/target/iscsi/iscsi_target_configfs.h create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.c create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.hdrivers/target/iscsi/iscsi_target_configfs.c new file +0
-0
drivers/target/iscsi/iscsi_target_configfs.c line 5
Quoted 5 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +5
-0@@ -0,0 +1,1593 @@ +/******************************************************************************* +* This file contains the configfs implementation for iSCSI Target mode +* from the LIO-Target Project. +* +* ?? Copyright 2007-2011 RisingTide Systems LLC.
"??" ?
You have this in other files as well - what's the point of those two question marks?
Quoted 9 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +9
-0+struct se_tpg_np *lio_target_call_addnptotpg ( +struct se_portal_group *se_tpg, +struct config_group *group, +const char *name) +{ +struct iscsi_portal_group *tpg; +struct iscsi_tpg_np *tpg_np; +char *str, *str2, *end_ptr, *ip_str, *port_str; +struct iscsi_np_addr np_addr;
drivers/target/iscsi/iscsi_target_configfs.c line 188
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +10
-0+u32 ipv4 =0 ; +int ret; +char buf[MAX_PORTAL_LEN +1 ]; + +if (strlen (name) >MAX_PORTAL_LEN ) { +printk (KERN_ERR "strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n" , + (int )strlen (name),MAX_PORTAL_LEN ); +return ERR_PTR (-EOVERFLOW ); + } +memset (buf,0 ,MAX_PORTAL_LEN );
memset(buf, 0, MAX_PORTAL_LEN + 1);
drivers/target/iscsi/iscsi_target_configfs.c line 307
Quoted 11 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +11
-0+#define DEF_NACL_ATTRIB (name) \ +static ssize_t iscsi_nacl_attrib_show_##name( \ + struct se_node_acl *se_nacl, \ + char *page) \ +{ \ + struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ + se_node_acl); \ + ssize_t rb; \ + \ + rb = sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \ + return rb; \
Why the 'rb' variable? Why not just
return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name);
?
drivers/target/iscsi/iscsi_target_configfs.c line 398
Quoted 12 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +12
-0+#define __DEF_NACL_AUTH_STR (prefix, name, flags) \ +static ssize_t __iscsi_##prefix##_show_##name( \ + struct iscsi_node_acl *nacl, \ + char *page) \ +{ \ + struct iscsi_node_auth *auth = &nacl->node_auth; \ + ssize_t rb; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + rb = snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ + return rb; \
Kill 'rb' and just
return snprintf(page, PAGE_SIZE, "%s\n", auth->name);
I'd say.
drivers/target/iscsi/iscsi_target_configfs.c line 438
Quoted 13 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +13
-0+#define __DEF_NACL_AUTH_INT (prefix, name) \ +static ssize_t __iscsi_##prefix##_show_##name( \ + struct iscsi_node_acl *nacl, \ + char *page) \ +{ \ + struct iscsi_node_auth *auth = &nacl->node_auth; \ + ssize_t rb; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + \ + rb = snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ + return rb; \
Just kill that pointless 'rb' variable..
Quoted 8 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +8
-0+static ssize_t lio_target_nacl_show_info ( +struct se_node_acl *se_nacl, +char *page) +{ +struct iscsi_session *sess; +struct iscsi_conn *conn; +struct se_session *se_sess; +unsigned char *ip, buf_ipv4[IPV4_BUF_SIZE ];
drivers/target/iscsi/iscsi_target_configfs.c line 606
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +10
-0+ssize_t rb =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (!se_sess) { + rb +=sprintf (page+rb,"No active iSCSI Session for Initiator" +" Endpoint: %s\n" , se_nacl->initiatorname); + }else { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +
Is this cast needed?
Quoted 8 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +8
-0+static ssize_t iscsi_tpg_param_store_##name( \ + struct se_portal_group *se_tpg, \ + const char *page, \ + size_t count) \ +{ \ + struct iscsi_portal_group *tpg = container_of(se_tpg, \ + struct iscsi_portal_group, tpg_se_tpg); \ + char *buf; \
drivers/target/iscsi/iscsi_target_configfs.c line 1004
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +10
-0+int ret; \ + \ + buf =kzalloc (PAGE_SIZE ,GFP_KERNEL ); \ +if (!buf) \ +return -ENOMEM ; \ +snprintf (buf,PAGE_SIZE ,"%s=%s" ,__stringify (name), page); \ + buf[strlen (buf)-1 ] ='\0' ;/* Kill newline */ \ + \ +if (iscsi_get_tpg (tpg) <0 ) \ +return -EINVAL ; \
You just leaked "buf".
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
Re: [RFC-v3 03/12] iscsi-target: Add TCM v4 compatiable ConfigFS control plane
Quoted 27 lines · Jesper Juhl
Quoted 25 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
This patch adds support for
/sys/kernel/config/target/iscsiusing TCM v4.0 compatiable calls followingtarget_core_fabric_configfs.cThis includes a number of iSCSI fabric dependent attributes upon
target_core_fabric_configfs.cprovided structconfig_item_typesfrominclude/target/target_core_configfs.hstructtarget_fabric_configfs_templateIt also includes iscsi_target_nodeattrib.[c,h] for handling the lio_target_nacl_attrib_attrs[] store/show for iSCSI fabric dependent attributes.
Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/iscsi/iscsi_target_configfs.c | 1593 ++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_configfs.h | 7 + drivers/target/iscsi/iscsi_target_nodeattrib.c | 264 ++++ drivers/target/iscsi/iscsi_target_nodeattrib.h | 14 + 4 files changed, 1878 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_configfs.c create mode 100644 drivers/target/iscsi/iscsi_target_configfs.h create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.c create mode 100644 drivers/target/iscsi/iscsi_target_nodeattrib.h
Quoted 17 lines
drivers/target/iscsi/iscsi_target_configfs.c line 5
Quoted 11 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +5
-0@@ -0,0 +1,1593 @@ +/******************************************************************************* +* This file contains the configfs implementation for iSCSI Target mode +* from the LIO-Target Project. +* +* ?? Copyright 2007-2011 RisingTide Systems LLC. "??" ?
You have this in other files as well - what's the point of those two question marks?
Mmm, this looks like an email encoding issue. The actual code is using the copyright symbol (c) -> ©
Quoted 13 lines
Quoted 13 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +13
-0+struct se_tpg_np *lio_target_call_addnptotpg ( +struct se_portal_group *se_tpg, +struct config_group *group, +const char *name) +{ +struct iscsi_portal_group *tpg; +struct iscsi_tpg_np *tpg_np; +char *str, *str2, *end_ptr, *ip_str, *port_str; +struct iscsi_np_addr np_addr; +u32 ipv4 =0 ; +int ret; +char buf[MAX_PORTAL_LEN +1 ]; +
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c line 188
Quoted 6 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +6
-0+if (strlen (name) >MAX_PORTAL_LEN ) { +printk (KERN_ERR "strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n" , + (int )strlen (name),MAX_PORTAL_LEN ); +return ERR_PTR (-EOVERFLOW ); + } +memset (buf,0 ,MAX_PORTAL_LEN );
memset(buf, 0, MAX_PORTAL_LEN + 1);
Fixed
Quoted 14 lines
drivers/target/iscsi/iscsi_target_configfs.c line 307
Quoted 11 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +11
-0+#define DEF_NACL_ATTRIB (name) \ +static ssize_t iscsi_nacl_attrib_show_##name( \ + struct se_node_acl *se_nacl, \ + char *page) \ +{ \ + struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ + se_node_acl); \ + ssize_t rb; \ + \ + rb = sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \ + return rb; \Why the 'rb' variable? Why not just
Quoted 5 lines
return
sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name);?
Fixed
Quoted 15 lines
drivers/target/iscsi/iscsi_target_configfs.c line 398
Quoted 12 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +12
-0+#define __DEF_NACL_AUTH_STR (prefix, name, flags) \ +static ssize_t __iscsi_##prefix##_show_##name( \ + struct iscsi_node_acl *nacl, \ + char *page) \ +{ \ + struct iscsi_node_auth *auth = &nacl->node_auth; \ + ssize_t rb; \ + \ + if (!capable(CAP_SYS_ADMIN)) \ + return -EPERM; \ + rb = snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ + return rb; \Kill 'rb' and just
Quoted 4 lines
return snprintf(page, PAGE_SIZE, "%s\n", auth->name);I'd say.
Fixed
Quoted 18 lines
Quoted 4 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +3
-0+#define __DEF_NACL_AUTH_INT (prefix, name) \ +static ssize_t __iscsi_##prefix##_show_##name( \ + struct iscsi_node_acl *nacl, \drivers/target/iscsi/iscsi_target_configfs.c line 438
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +10
-0+ char *page) \ +{ \ +struct iscsi_node_auth *auth = &nacl->node_auth; \ +ssize_t rb; \ + \ +if (!capable (CAP_SYS_ADMIN )) \ +return -EPERM ; \ + \ + rb =snprintf (page,PAGE_SIZE ,"%d\n" , auth->name); \ +return rb; \Just kill that pointless 'rb' variable..
Fixed
Quoted 12 lines
Quoted 12 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +12
-0+static ssize_t lio_target_nacl_show_info ( +struct se_node_acl *se_nacl, +char *page) +{ +struct iscsi_session *sess; +struct iscsi_conn *conn; +struct se_session *se_sess; +unsigned char *ip, buf_ipv4[IPV4_BUF_SIZE ]; +ssize_t rb =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess;
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c line 606
Quoted 6 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +6
-0+if (!se_sess) { + rb +=sprintf (page+rb,"No active iSCSI Session for Initiator" +" Endpoint: %s\n" , se_nacl->initiatorname); + }else { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +Is this cast needed?
Removed
Quoted 12 lines
Quoted 12 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +12
-0+static ssize_t iscsi_tpg_param_store_##name( \ + struct se_portal_group *se_tpg, \ + const char *page, \ + size_t count) \ +{ \ + struct iscsi_portal_group *tpg = container_of(se_tpg, \ + struct iscsi_portal_group, tpg_se_tpg); \ + char *buf; \ + int ret; \ + \ + buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ + if (!buf) \
Quoted 10 lines
drivers/target/iscsi/iscsi_target_configfs.c line 1004
Quoted 6 lines
drivers/target/iscsi/iscsi_target_configfs.c new file +6
-0+return -ENOMEM ; \ +snprintf (buf,PAGE_SIZE ,"%s=%s" ,__stringify (name), page); \ + buf[strlen (buf)-1 ] ='\0' ;/* Kill newline */ \ + \ +if (iscsi_get_tpg (tpg) <0 ) \ +return -EINVAL ; \You just leaked "buf".
Fixed. Thanks for your review Jesper!
--nab
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v3 4/12 iscsi-target: Add configfs fabric dependent statistics
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds support for iSCSI fabric dependent configfs statistics using TCM v4 default statistics groups.
--- drivers/target/iscsi/iscsi_target_stat.c | 950 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_stat.h | 64 ++ 2 files changed, 1014 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_stat.c create mode 100644 drivers/target/iscsi/iscsi_target_stat.h
drivers/target/iscsi/iscsi_target_stat.c new file +950 -0
@@ -0,0 +1,950 @@ +/******************************************************************************* +* Modern ConfigFS group context specific iSCSI statistics based on original +* iscsi_target_mib.c code +* +* Copyright (c) 2011 Rising Tide Systems +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <linux/configfs.h> +#include <scsi/iscsi_proto.h> +#include <target/target_core_base.h> +#include <target/target_core_transport.h> +#include <target/configfs_macros.h> + +#include "iscsi_target_core.h" +#include "iscsi_target_parameters.h" +#include "iscsi_target_device.h" +#include "iscsi_target_tpg.h" +#include "iscsi_target_util.h" +#include "iscsi_target_stat.h" + +#ifndef INITIAL_JIFFIES +#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ)) +#endif + +/* Instance Attributes Table */ +#define ISCSI_INST_NUM_NODES 1 +#define ISCSI_INST_DESCR "Storage Engine Target" +#define ISCSI_INST_LAST_FAILURE_TYPE 0 +#define ISCSI_DISCONTINUITY_TIME 0 + +#define ISCSI_NODE_INDEX 1 + +#define ISPRINT (a) ((a >= ' ') && (a <= '~')) + +/**************************************************************************** +* iSCSI MIB Tables +****************************************************************************/ +/* +* Instance Attributes Table +*/ +CONFIGFS_EATTR_STRUCT (iscsi_stat_instance, iscsi_wwn_stat_grps); +#define ISCSI_STAT_INSTANCE_ATTR (_name, _mode) \ +static struct iscsi_stat_instance_attribute \ + iscsi_stat_instance_##_name = \ + __CONFIGFS_EATTR(_name, _mode, \ + iscsi_stat_instance_show_attr_##_name, \ + iscsi_stat_instance_store_attr_##_name); + +#define ISCSI_STAT_INSTANCE_ATTR_RO (_name) \ +static struct iscsi_stat_instance_attribute \ + iscsi_stat_instance_##_name = \ + __CONFIGFS_EATTR_RO(_name, \ + iscsi_stat_instance_show_attr_##_name); + +static ssize_t iscsi_stat_instance_show_attr_inst ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_index); +} +ISCSI_STAT_INSTANCE_ATTR_RO (inst); + +static ssize_t iscsi_stat_instance_show_attr_min_ver ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_DRAFT20_VERSION ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (min_ver); + +static ssize_t iscsi_stat_instance_show_attr_max_ver ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_DRAFT20_VERSION ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (max_ver); + +static ssize_t iscsi_stat_instance_show_attr_portals ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_num_tpg_nps); +} +ISCSI_STAT_INSTANCE_ATTR_RO (portals); + +static ssize_t iscsi_stat_instance_show_attr_nodes ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_INST_NUM_NODES ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (nodes); + +static ssize_t iscsi_stat_instance_show_attr_sessions ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_nsessions); +} +ISCSI_STAT_INSTANCE_ATTR_RO (sessions); + +static ssize_t iscsi_stat_instance_show_attr_fail_sess ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; +u32 sess_err_count; + +spin_lock_bh (&sess_err->lock); + sess_err_count = (sess_err->digest_errors + + sess_err->cxn_timeout_errors + + sess_err->pdu_format_errors); +spin_unlock_bh (&sess_err->lock); + +return snprintf (page,PAGE_SIZE ,"%u\n" , sess_err_count); +} +ISCSI_STAT_INSTANCE_ATTR_RO (fail_sess); + +static ssize_t iscsi_stat_instance_show_attr_fail_type ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; + +return snprintf (page,PAGE_SIZE ,"%u\n" , + sess_err->last_sess_failure_type); +} +ISCSI_STAT_INSTANCE_ATTR_RO (fail_type); + +static ssize_t iscsi_stat_instance_show_attr_fail_rem_name ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; + +return snprintf (page,PAGE_SIZE ,"%s\n" , + sess_err->last_sess_fail_rem_name[0 ] ? + sess_err->last_sess_fail_rem_name :NONE ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (fail_rem_name); + +static ssize_t iscsi_stat_instance_show_attr_disc_time ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_DISCONTINUITY_TIME ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (disc_time); + +static ssize_t iscsi_stat_instance_show_attr_description ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%s\n" ,ISCSI_INST_DESCR ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (description); + +static ssize_t iscsi_stat_instance_show_attr_vendor ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"RisingTide Systems iSCSI-Target\n" ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (vendor); + +static ssize_t iscsi_stat_instance_show_attr_version ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%s\n" ,ISCSI_VERSION ); +} +ISCSI_STAT_INSTANCE_ATTR_RO (version); + +CONFIGFS_EATTR_OPS (iscsi_stat_instance, iscsi_wwn_stat_grps, + iscsi_instance_group); + +static struct configfs_attribute *iscsi_stat_instance_attrs[] = { + &iscsi_stat_instance_inst.attr, + &iscsi_stat_instance_min_ver.attr, + &iscsi_stat_instance_max_ver.attr, + &iscsi_stat_instance_portals.attr, + &iscsi_stat_instance_nodes.attr, + &iscsi_stat_instance_sessions.attr, + &iscsi_stat_instance_fail_sess.attr, + &iscsi_stat_instance_fail_type.attr, + &iscsi_stat_instance_fail_rem_name.attr, + &iscsi_stat_instance_disc_time.attr, + &iscsi_stat_instance_description.attr, + &iscsi_stat_instance_vendor.attr, + &iscsi_stat_instance_version.attr, +NULL , +}; + +static struct configfs_item_operations iscsi_stat_instance_item_ops = { + .show_attribute = iscsi_stat_instance_attr_show, + .store_attribute = iscsi_stat_instance_attr_store, +}; + +struct config_item_type iscsi_stat_instance_cit = { + .ct_item_ops = &iscsi_stat_instance_item_ops, + .ct_attrs = iscsi_stat_instance_attrs, + .ct_owner =THIS_MODULE , +}; + +/* +* Instance Session Failure Stats Table +*/ +CONFIGFS_EATTR_STRUCT (iscsi_stat_sess_err, iscsi_wwn_stat_grps); +#define ISCSI_STAT_SESS_ERR_ATTR (_name, _mode) \ +static struct iscsi_stat_sess_err_attribute \ + iscsi_stat_sess_err_##_name = \ + __CONFIGFS_EATTR(_name, _mode, \ + iscsi_stat_sess_err_show_attr_##_name, \ + iscsi_stat_sess_err_store_attr_##_name); + +#define ISCSI_STAT_SESS_ERR_ATTR_RO (_name) \ +static struct iscsi_stat_sess_err_attribute \ + iscsi_stat_sess_err_##_name = \ + __CONFIGFS_EATTR_RO(_name, \ + iscsi_stat_sess_err_show_attr_##_name); + +static ssize_t iscsi_stat_sess_err_show_attr_inst ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_index); +} +ISCSI_STAT_SESS_ERR_ATTR_RO (inst); + +static ssize_t iscsi_stat_sess_err_show_attr_digest_errors ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; + +return snprintf (page,PAGE_SIZE ,"%u\n" , sess_err->digest_errors); +} +ISCSI_STAT_SESS_ERR_ATTR_RO (digest_errors); + +static ssize_t iscsi_stat_sess_err_show_attr_cxn_errors ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; + +return snprintf (page,PAGE_SIZE ,"%u\n" , sess_err->cxn_timeout_errors); +} +ISCSI_STAT_SESS_ERR_ATTR_RO (cxn_errors); + +static ssize_t iscsi_stat_sess_err_show_attr_format_errors ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; + +return snprintf (page,PAGE_SIZE ,"%u\n" , sess_err->pdu_format_errors); +} +ISCSI_STAT_SESS_ERR_ATTR_RO (format_errors); + +CONFIGFS_EATTR_OPS (iscsi_stat_sess_err, iscsi_wwn_stat_grps, + iscsi_sess_err_group); + +static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = { + &iscsi_stat_sess_err_inst.attr, + &iscsi_stat_sess_err_digest_errors.attr, + &iscsi_stat_sess_err_cxn_errors.attr, + &iscsi_stat_sess_err_format_errors.attr, +NULL , +}; + +static struct configfs_item_operations iscsi_stat_sess_err_item_ops = { + .show_attribute = iscsi_stat_sess_err_attr_show, + .store_attribute = iscsi_stat_sess_err_attr_store, +}; + +struct config_item_type iscsi_stat_sess_err_cit = { + .ct_item_ops = &iscsi_stat_sess_err_item_ops, + .ct_attrs = iscsi_stat_sess_err_attrs, + .ct_owner =THIS_MODULE , +}; + +/* +* Target Attributes Table +*/ +CONFIGFS_EATTR_STRUCT (iscsi_stat_tgt_attr, iscsi_wwn_stat_grps); +#define ISCSI_STAT_TGT_ATTR (_name, _mode) \ +static struct iscsi_stat_tgt_attr_attribute \ + iscsi_stat_tgt_attr_##_name = \ + __CONFIGFS_EATTR(_name, _mode, \ + iscsi_stat_tgt-attr_show_attr_##_name, \ + iscsi_stat_tgt_attr_store_attr_##_name); + +#define ISCSI_STAT_TGT_ATTR_RO (_name) \ +static struct iscsi_stat_tgt_attr_attribute \ + iscsi_stat_tgt_attr_##_name = \ + __CONFIGFS_EATTR_RO(_name, \ + iscsi_stat_tgt_attr_show_attr_##_name); + +static ssize_t iscsi_stat_tgt_attr_show_attr_inst ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_index); +} +ISCSI_STAT_TGT_ATTR_RO (inst); + +static ssize_t iscsi_stat_tgt_attr_show_attr_indx ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_NODE_INDEX ); +} +ISCSI_STAT_TGT_ATTR_RO (indx); + +static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +u32 fail_count; + +spin_lock (&lstat->lock); + fail_count = (lstat->redirects + lstat->authorize_fails + + lstat->authenticate_fails + lstat->negotiate_fails + + lstat->other_fails); +spin_unlock (&lstat->lock); + +return snprintf (page,PAGE_SIZE ,"%u\n" , fail_count); +} +ISCSI_STAT_TGT_ATTR_RO (login_fails); + +static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +u32 last_fail_time; + +spin_lock (&lstat->lock); + last_fail_time = lstat->last_fail_time ? + (u32)(((u32 )lstat->last_fail_time - +INITIAL_JIFFIES ) *100 /HZ ) :0 ; +spin_unlock (&lstat->lock); + +return snprintf (page,PAGE_SIZE ,"%u\n" , last_fail_time); +} +ISCSI_STAT_TGT_ATTR_RO (last_fail_time); + +static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +u32 last_fail_type; + +spin_lock (&lstat->lock); + last_fail_type = lstat->last_fail_type; +spin_unlock (&lstat->lock); + +return snprintf (page,PAGE_SIZE ,"%u\n" , last_fail_type); +} +ISCSI_STAT_TGT_ATTR_RO (last_fail_type); + +static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +unsigned char buf[224 ]; + +spin_lock (&lstat->lock); +snprintf (buf,224 ,"%s" , lstat->last_intr_fail_name[0 ] ? + lstat->last_intr_fail_name :NONE ); +spin_unlock (&lstat->lock); + +return snprintf (page,PAGE_SIZE ,"%s\n" , buf); +} +ISCSI_STAT_TGT_ATTR_RO (fail_intr_name); + +static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +unsigned char buf[8 ]; + +spin_lock (&lstat->lock); +snprintf (buf,8 ,"%s" , (lstat->last_intr_fail_ip6_addr !=NULL ) ? +"ipv6" :"ipv4" ); +spin_unlock (&lstat->lock); + +return snprintf (page,PAGE_SIZE ,"%s\n" , buf); +} +ISCSI_STAT_TGT_ATTR_RO (fail_intr_addr_type); + +static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +unsigned char buf[32 ]; + +spin_lock (&lstat->lock); +if (lstat->last_intr_fail_ip6_addr !=NULL ) +snprintf (buf,32 ,"[%s]" , lstat->last_intr_fail_ip6_addr); +else +snprintf (buf,32 ,"%08X" , lstat->last_intr_fail_addr); +spin_unlock (&lstat->lock); + +return snprintf (page,PAGE_SIZE ,"%s\n" , buf); +} +ISCSI_STAT_TGT_ATTR_RO (fail_intr_addr); + +CONFIGFS_EATTR_OPS (iscsi_stat_tgt_attr, iscsi_wwn_stat_grps, + iscsi_tgt_attr_group); + +static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = { + &iscsi_stat_tgt_attr_inst.attr, + &iscsi_stat_tgt_attr_indx.attr, + &iscsi_stat_tgt_attr_login_fails.attr, + &iscsi_stat_tgt_attr_last_fail_time.attr, + &iscsi_stat_tgt_attr_last_fail_type.attr, + &iscsi_stat_tgt_attr_fail_intr_name.attr, + &iscsi_stat_tgt_attr_fail_intr_addr_type.attr, + &iscsi_stat_tgt_attr_fail_intr_addr.attr, +NULL , +}; + +static struct configfs_item_operations iscsi_stat_tgt_attr_item_ops = { + .show_attribute = iscsi_stat_tgt_attr_attr_show, + .store_attribute = iscsi_stat_tgt_attr_attr_store, +}; + +struct config_item_type iscsi_stat_tgt_attr_cit = { + .ct_item_ops = &iscsi_stat_tgt_attr_item_ops, + .ct_attrs = iscsi_stat_tgt_attr_attrs, + .ct_owner =THIS_MODULE , +}; + +/* +* Target Login Stats Table +*/ +CONFIGFS_EATTR_STRUCT (iscsi_stat_login, iscsi_wwn_stat_grps); +#define ISCSI_STAT_LOGIN (_name, _mode) \ +static struct iscsi_stat_login_attribute \ + iscsi_stat_login_##_name = \ + __CONFIGFS_EATTR(_name, _mode, \ + iscsi_stat_login_show_attr_##_name, \ + iscsi_stat_login_store_attr_##_name); + +#define ISCSI_STAT_LOGIN_RO (_name) \ +static struct iscsi_stat_login_attribute \ + iscsi_stat_login_##_name = \ + __CONFIGFS_EATTR_RO(_name, \ + iscsi_stat_login_show_attr_##_name); + +static ssize_t iscsi_stat_login_show_attr_inst ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_index); +} +ISCSI_STAT_LOGIN_RO (inst); + +static ssize_t iscsi_stat_login_show_attr_indx ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_NODE_INDEX ); +} +ISCSI_STAT_LOGIN_RO (indx); + +static ssize_t iscsi_stat_login_show_attr_accepts ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +ssize_t ret; + +spin_lock (&lstat->lock); + ret =snprintf (page,PAGE_SIZE ,"%u\n" , lstat->accepts); +spin_unlock (&lstat->lock); + +return ret; +} +ISCSI_STAT_LOGIN_RO (accepts); + +static ssize_t iscsi_stat_login_show_attr_other_fails ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +ssize_t ret; + +spin_lock (&lstat->lock); + ret =snprintf (page,PAGE_SIZE ,"%u\n" , lstat->other_fails); +spin_unlock (&lstat->lock); + +return ret; +} +ISCSI_STAT_LOGIN_RO (other_fails); + +static ssize_t iscsi_stat_login_show_attr_redirects ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +ssize_t ret; + +spin_lock (&lstat->lock); + ret =snprintf (page,PAGE_SIZE ,"%u\n" , lstat->redirects); +spin_unlock (&lstat->lock); + +return ret; +} +ISCSI_STAT_LOGIN_RO (redirects); + +static ssize_t iscsi_stat_login_show_attr_authorize_fails ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +ssize_t ret; + +spin_lock (&lstat->lock); + ret =snprintf (page,PAGE_SIZE ,"%u\n" , lstat->authorize_fails); +spin_unlock (&lstat->lock); + +return ret; +} +ISCSI_STAT_LOGIN_RO (authorize_fails); + +static ssize_t iscsi_stat_login_show_attr_authenticate_fails ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +ssize_t ret; + +spin_lock (&lstat->lock); + ret =snprintf (page,PAGE_SIZE ,"%u\n" , lstat->authenticate_fails); +spin_unlock (&lstat->lock); + +return ret; +} +ISCSI_STAT_LOGIN_RO (authenticate_fails); + +static ssize_t iscsi_stat_login_show_attr_negotiate_fails ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_login_stats *lstat = &tiqn->login_stats; +ssize_t ret; + +spin_lock (&lstat->lock); + ret =snprintf (page,PAGE_SIZE ,"%u\n" , lstat->negotiate_fails); +spin_unlock (&lstat->lock); + +return ret; +} +ISCSI_STAT_LOGIN_RO (negotiate_fails); + +CONFIGFS_EATTR_OPS (iscsi_stat_login, iscsi_wwn_stat_grps, + iscsi_login_stats_group); + +static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = { + &iscsi_stat_login_inst.attr, + &iscsi_stat_login_indx.attr, + &iscsi_stat_login_accepts.attr, + &iscsi_stat_login_other_fails.attr, + &iscsi_stat_login_redirects.attr, + &iscsi_stat_login_authorize_fails.attr, + &iscsi_stat_login_authenticate_fails.attr, + &iscsi_stat_login_negotiate_fails.attr, +NULL , +}; + +static struct configfs_item_operations iscsi_stat_login_stats_item_ops = { + .show_attribute = iscsi_stat_login_attr_show, + .store_attribute = iscsi_stat_login_attr_store, +}; + +struct config_item_type iscsi_stat_login_cit = { + .ct_item_ops = &iscsi_stat_login_stats_item_ops, + .ct_attrs = iscsi_stat_login_stats_attrs, + .ct_owner =THIS_MODULE , +}; + +/* +* Target Logout Stats Table +*/ + +CONFIGFS_EATTR_STRUCT (iscsi_stat_logout, iscsi_wwn_stat_grps); +#define ISCSI_STAT_LOGOUT (_name, _mode) \ +static struct iscsi_stat_logout_attribute \ + iscsi_stat_logout_##_name = \ + __CONFIGFS_EATTR(_name, _mode, \ + iscsi_stat_logout_show_attr_##_name, \ + iscsi_stat_logout_store_attr_##_name); + +#define ISCSI_STAT_LOGOUT_RO (_name) \ +static struct iscsi_stat_logout_attribute \ + iscsi_stat_logout_##_name = \ + __CONFIGFS_EATTR_RO(_name, \ + iscsi_stat_logout_show_attr_##_name); + +static ssize_t iscsi_stat_logout_show_attr_inst ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_index); +} +ISCSI_STAT_LOGOUT_RO (inst); + +static ssize_t iscsi_stat_logout_show_attr_indx ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +return snprintf (page,PAGE_SIZE ,"%u\n" ,ISCSI_NODE_INDEX ); +} +ISCSI_STAT_LOGOUT_RO (indx); + +static ssize_t iscsi_stat_logout_show_attr_normal_logouts ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_logout_stats *lstats = &tiqn->logout_stats; + +return snprintf (page,PAGE_SIZE ,"%u\n" , lstats->normal_logouts); +} +ISCSI_STAT_LOGOUT_RO (normal_logouts); + +static ssize_t iscsi_stat_logout_show_attr_abnormal_logouts ( +struct iscsi_wwn_stat_grps *igrps,char *page) +{ +struct iscsi_tiqn *tiqn =container_of (igrps, + struct iscsi_tiqn, tiqn_stat_grps); +struct iscsi_logout_stats *lstats = &tiqn->logout_stats; + +return snprintf (page,PAGE_SIZE ,"%u\n" , lstats->abnormal_logouts); +} +ISCSI_STAT_LOGOUT_RO (abnormal_logouts); + +CONFIGFS_EATTR_OPS (iscsi_stat_logout, iscsi_wwn_stat_grps, + iscsi_logout_stats_group); + +static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = { + &iscsi_stat_logout_inst.attr, + &iscsi_stat_logout_indx.attr, + &iscsi_stat_logout_normal_logouts.attr, + &iscsi_stat_logout_abnormal_logouts.attr, +NULL , +}; + +static struct configfs_item_operations iscsi_stat_logout_stats_item_ops = { + .show_attribute = iscsi_stat_logout_attr_show, + .store_attribute = iscsi_stat_logout_attr_store, +}; + +struct config_item_type iscsi_stat_logout_cit = { + .ct_item_ops = &iscsi_stat_logout_stats_item_ops, + .ct_attrs = iscsi_stat_logout_stats_attrs, + .ct_owner =THIS_MODULE , +}; + +/* +* Session Stats Table +*/ + +CONFIGFS_EATTR_STRUCT (iscsi_stat_sess, iscsi_node_stat_grps); +#define ISCSI_STAT_SESS (_name, _mode) \ +static struct iscsi_stat_sess_attribute \ + iscsi_stat_sess_##_name = \ + __CONFIGFS_EATTR(_name, _mode, \ + iscsi_stat_sess_show_attr_##_name, \ + iscsi_stat_sess_store_attr_##_name); + +#define ISCSI_STAT_SESS_RO (_name) \ +static struct iscsi_stat_sess_attribute \ + iscsi_stat_sess_##_name = \ + __CONFIGFS_EATTR_RO(_name, \ + iscsi_stat_sess_show_attr_##_name); + +static ssize_t iscsi_stat_sess_show_attr_inst ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn; +struct iscsi_tiqn *tiqn =container_of (wwn, + struct iscsi_tiqn, tiqn_wwn); + +return snprintf (page,PAGE_SIZE ,"%u\n" , tiqn->tiqn_index); +} +ISCSI_STAT_SESS_RO (inst); + +static ssize_t iscsi_stat_sess_show_attr_node ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%u\n" , + sess->sess_ops->SessionType ?0 :ISCSI_NODE_INDEX ); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (node); + +static ssize_t iscsi_stat_sess_show_attr_indx ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%u\n" , + sess->session_index); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (indx); + +static ssize_t iscsi_stat_sess_show_attr_cmd_pdus ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%u\n" , sess->cmd_pdus); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (cmd_pdus); + +static ssize_t iscsi_stat_sess_show_attr_rsp_pdus ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%u\n" , sess->rsp_pdus); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (rsp_pdus); + +static ssize_t iscsi_stat_sess_show_attr_txdata_octs ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%llu\n" , + (unsigned long long )sess->tx_data_octets); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (txdata_octs); + +static ssize_t iscsi_stat_sess_show_attr_rxdata_octs ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%llu\n" , + (unsigned long long )sess->rx_data_octets); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (rxdata_octs); + +static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%u\n" , + sess->conn_digest_errors); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (conn_digest_errors); + +static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors ( +struct iscsi_node_stat_grps *igrps,char *page) +{ +struct iscsi_node_acl *acl =container_of (igrps, + struct iscsi_node_acl, node_stat_grps); +struct se_node_acl *se_nacl = &acl->se_node_acl; +struct iscsi_session *sess; +struct se_session *se_sess; +ssize_t ret =0 ; + +spin_lock_bh (&se_nacl->nacl_sess_lock); + se_sess = se_nacl->nacl_sess; +if (se_sess) { + sess = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (sess) + ret =snprintf (page,PAGE_SIZE ,"%u\n" , + sess->conn_timeout_errors); + } +spin_unlock_bh (&se_nacl->nacl_sess_lock); + +return ret; +} +ISCSI_STAT_SESS_RO (conn_timeout_errors); + +CONFIGFS_EATTR_OPS (iscsi_stat_sess, iscsi_node_stat_grps, + iscsi_sess_stats_group); + +static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = { + &iscsi_stat_sess_inst.attr, + &iscsi_stat_sess_node.attr, + &iscsi_stat_sess_indx.attr, + &iscsi_stat_sess_cmd_pdus.attr, + &iscsi_stat_sess_rsp_pdus.attr, + &iscsi_stat_sess_txdata_octs.attr, + &iscsi_stat_sess_rxdata_octs.attr, + &iscsi_stat_sess_conn_digest_errors.attr, + &iscsi_stat_sess_conn_timeout_errors.attr, +NULL , +}; + +static struct configfs_item_operations iscsi_stat_sess_stats_item_ops = { + .show_attribute = iscsi_stat_sess_attr_show, + .store_attribute = iscsi_stat_sess_attr_store, +}; + +struct config_item_type iscsi_stat_sess_cit = { + .ct_item_ops = &iscsi_stat_sess_stats_item_ops, + .ct_attrs = iscsi_stat_sess_stats_attrs, + .ct_owner =THIS_MODULE , +};
drivers/target/iscsi/iscsi_target_stat.h new file +64 -0
64 lines not on this page · raw message
Signature · 1 line
1.7.4.1
RFC v3 5/12 iscsi-target: Add TPG and Device logic
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds TPG and device logiced using for mapping iscsi-target abstractions on top of TCM v4 struct se_portal_group and struct se_device abstractions.
--- drivers/target/iscsi/iscsi_target_device.c | 124 ++++ drivers/target/iscsi/iscsi_target_device.h | 9 + drivers/target/iscsi/iscsi_target_tpg.c | 999 ++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_tpg.h | 65 ++ 4 files changed, 1197 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_device.c create mode 100644 drivers/target/iscsi/iscsi_target_device.h create mode 100644 drivers/target/iscsi/iscsi_target_tpg.c create mode 100644 drivers/target/iscsi/iscsi_target_tpg.h
drivers/target/iscsi/iscsi_target_device.c new file +124 -0
@@ -0,0 +1,124 @@ +/******************************************************************************* +* This file contains the iSCSI Virtual Device and Disk Transport +* agnostic related functions. +* +© Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <target/target_core_base.h> +#include <target/target_core_device.h> +#include <target/target_core_transport.h> + +#include "iscsi_target_debug.h" +#include "iscsi_target_core.h" +#include "iscsi_target_device.h" +#include "iscsi_target_tpg.h" +#include "iscsi_target_util.h" + +/* iscsi_get_lun(): +* +* +*/ +int iscsi_get_lun_for_tmr ( +struct iscsi_cmd *cmd, +u64 lun) +{ +struct iscsi_conn *conn = cmd->conn; +struct iscsi_portal_group *tpg =ISCSI_TPG_C (conn); +u32 unpacked_lun; + + unpacked_lun =iscsi_unpack_lun ((unsigned char *)&lun); +if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG -1 )) { +printk (KERN_ERR "iSCSI LUN: %u exceeds TRANSPORT_MAX_LUNS_PER_TPG" +"-1: %u for Target Portal Group: %hu\n" , unpacked_lun, +TRANSPORT_MAX_LUNS_PER_TPG -1 , tpg->tpgt); +return -1 ; + } + +return transport_get_lun_for_tmr (SE_CMD (cmd), unpacked_lun); +} + +/* iscsi_get_lun_for_cmd(): +* +* Returns (0) on success +* Returns (< 0) on failure +*/ +int iscsi_get_lun_for_cmd ( +struct iscsi_cmd *cmd, +unsigned char *cdb, +u64 lun) +{ +struct iscsi_conn *conn = cmd->conn; +struct iscsi_portal_group *tpg =ISCSI_TPG_C (conn); +u32 unpacked_lun; + + unpacked_lun =iscsi_unpack_lun ((unsigned char *)&lun); +if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG -1 )) { +printk (KERN_ERR "iSCSI LUN: %u exceeds TRANSPORT_MAX_LUNS_PER_TPG" +"-1: %u for Target Portal Group: %hu\n" , unpacked_lun, +TRANSPORT_MAX_LUNS_PER_TPG -1 , tpg->tpgt); +return -1 ; + } + +return transport_get_lun_for_cmd (SE_CMD (cmd), cdb, unpacked_lun); +} + +/* iscsi_determine_maxcmdsn(): +* +* +*/ +void iscsi_determine_maxcmdsn (struct iscsi_session *sess) +{ +struct se_node_acl *se_nacl; + +/* +* This is a discovery session, the single queue slot was already +* assigned in iscsi_login_zero_tsih(). Since only Logout and +* Text Opcodes are allowed during discovery we do not have to worry +* about the HBA's queue depth here. +*/ +if (sess->sess_ops->SessionType) +return ; + + se_nacl = sess->se_sess->se_node_acl; + +/* +* This is a normal session, set the Session's CmdSN window to the +* struct se_node_acl->queue_depth. The value in struct se_node_acl->queue_depth +* has already been validated as a legal value in +* core_set_queue_depth_for_node(). +*/ + sess->cmdsn_window = se_nacl->queue_depth; + sess->max_cmd_sn = (sess->max_cmd_sn + se_nacl->queue_depth) -1 ; +} + +/* iscsi_increment_maxcmdsn(); +* +* +*/ +void iscsi_increment_maxcmdsn (struct iscsi_cmd *cmd,struct iscsi_session *sess) +{ +if (cmd->immediate_cmd || cmd->maxcmdsn_inc) +return ; + + cmd->maxcmdsn_inc =1 ; + +spin_lock (&sess->cmdsn_lock); + sess->max_cmd_sn +=1 ; +TRACE (TRACE_ISCSI ,"Updated MaxCmdSN to 0x%08x\n" , sess->max_cmd_sn); +spin_unlock (&sess->cmdsn_lock); +}
drivers/target/iscsi/iscsi_target_device.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef ISCSI_TARGET_DEVICE_H +#define ISCSI_TARGET_DEVICE_H + +extern int iscsi_get_lun_for_tmr (struct iscsi_cmd *,u64 ); +extern int iscsi_get_lun_for_cmd (struct iscsi_cmd *,unsigned char *,u64 ); +extern void iscsi_determine_maxcmdsn (struct iscsi_session *); +extern void iscsi_increment_maxcmdsn (struct iscsi_cmd *,struct iscsi_session *); + +#endif /* ISCSI_TARGET_DEVICE_H */
drivers/target/iscsi/iscsi_target_tpg.c new file +999 -0
999 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_tpg.h new file +65 -0
65 lines not on this page · raw message
Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v3 6/12 iscsi-target: Add iSCSI Login Negotiation and Parameter logic
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds the princple RFC-3720 compatiable iSCSI Login phase negotiation for iscsi_target_mod. This also includes the target RX/TX thread queue logic which is called directly from iSCSI login associated code.
--- drivers/target/iscsi/iscsi_target_login.c | 1296 +++++++++++++++ drivers/target/iscsi/iscsi_target_login.h | 13 + drivers/target/iscsi/iscsi_target_nego.c | 1069 ++++++++++++ drivers/target/iscsi/iscsi_target_nego.h | 19 + drivers/target/iscsi/iscsi_target_parameters.c | 2052 ++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_parameters.h | 271 ++++ drivers/target/iscsi/iscsi_target_tq.c | 640 ++++++++ drivers/target/iscsi/iscsi_target_tq.h | 89 + 8 files changed, 5449 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_login.c create mode 100644 drivers/target/iscsi/iscsi_target_login.h create mode 100644 drivers/target/iscsi/iscsi_target_nego.c create mode 100644 drivers/target/iscsi/iscsi_target_nego.h create mode 100644 drivers/target/iscsi/iscsi_target_parameters.c create mode 100644 drivers/target/iscsi/iscsi_target_parameters.h create mode 100644 drivers/target/iscsi/iscsi_target_tq.c create mode 100644 drivers/target/iscsi/iscsi_target_tq.h
drivers/target/iscsi/iscsi_target_login.c new file +1296 -0
@@ -0,0 +1,1296 @@ +/******************************************************************************* +* This file contains the login functions used by the iSCSI Target driver. +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <linux/kthread.h> +#include <linux/crypto.h> +#include <scsi/iscsi_proto.h> +#include <target/target_core_base.h> +#include <target/target_core_transport.h> + +#include "iscsi_target_debug.h" +#include "iscsi_target_core.h" +#include "iscsi_target_tq.h" +#include "iscsi_target_device.h" +#include "iscsi_target_nego.h" +#include "iscsi_target_erl0.h" +#include "iscsi_target_erl2.h" +#include "iscsi_target_login.h" +#include "iscsi_target_stat.h" +#include "iscsi_target_tpg.h" +#include "iscsi_target_util.h" +#include "iscsi_target.h" +#include "iscsi_target_parameters.h" + +extern struct idr sess_idr; +extern struct mutex auth_id_lock; +extern spinlock_t sess_idr_lock; + +static int iscsi_login_init_conn (struct iscsi_conn *conn) +{ +INIT_LIST_HEAD (&conn->conn_list); +INIT_LIST_HEAD (&conn->conn_cmd_list); +INIT_LIST_HEAD (&conn->immed_queue_list); +INIT_LIST_HEAD (&conn->response_queue_list); +init_completion (&conn->conn_post_wait_comp); +init_completion (&conn->conn_wait_comp); +init_completion (&conn->conn_wait_rcfr_comp); +init_completion (&conn->conn_waiting_on_uc_comp); +init_completion (&conn->conn_logout_comp); +init_completion (&conn->rx_half_close_comp); +init_completion (&conn->tx_half_close_comp); +init_completion (&conn->tx_comp); +spin_lock_init (&conn->cmd_lock); +spin_lock_init (&conn->conn_usage_lock); +spin_lock_init (&conn->immed_queue_lock); +spin_lock_init (&conn->netif_lock); +spin_lock_init (&conn->nopin_timer_lock); +spin_lock_init (&conn->response_queue_lock); +spin_lock_init (&conn->state_lock); + +if (!(zalloc_cpumask_var (&conn->conn_cpumask,GFP_KERNEL ))) { +printk (KERN_ERR "Unable to allocate conn->conn_cpumask\n" ); +return -ENOMEM ; + } + +return 0 ; +} + +/* +* Used by iscsi_target_nego.c:iscsi_target_locate_portal() to setup +* per struct iscsi_conn libcrypto contexts for crc32c and crc32-intel +*/ +int iscsi_login_setup_crypto (struct iscsi_conn *conn) +{ +/* +* Setup slicing by CRC32C algorithm for RX and TX libcrypto contexts +* which will default to crc32c_intel.ko for cpu_has_xmm4_2, or fallback +* to software 1x8 byte slicing from crc32c.ko +*/ + conn->conn_rx_hash.flags =0 ; + conn->conn_rx_hash.tfm =crypto_alloc_hash ("crc32c" ,0 , +CRYPTO_ALG_ASYNC ); +if (IS_ERR (conn->conn_rx_hash.tfm)) { +printk (KERN_ERR "crypto_alloc_hash() failed for conn_rx_tfm\n" ); +return -ENOMEM ; + } + + conn->conn_tx_hash.flags =0 ; + conn->conn_tx_hash.tfm =crypto_alloc_hash ("crc32c" ,0 , +CRYPTO_ALG_ASYNC ); +if (IS_ERR (conn->conn_tx_hash.tfm)) { +printk (KERN_ERR "crypto_alloc_hash() failed for conn_tx_tfm\n" ); +crypto_free_hash (conn->conn_rx_hash.tfm); +return -ENOMEM ; + } + +return 0 ; +} + +static int iscsi_login_check_initiator_version ( +struct iscsi_conn *conn, +u8 version_max, +u8 version_min) +{ +if ((version_max !=0x00 ) || (version_min !=0x00 )) { +printk (KERN_ERR "Unsupported iSCSI IETF Pre-RFC Revision," +" version Min/Max 0x%02x/0x%02x, rejecting login.\n" , + version_min, version_max); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_INITIATOR_ERR , +ISCSI_LOGIN_STATUS_NO_VERSION ); +return -1 ; + } + +return 0 ; +} + +int iscsi_check_for_session_reinstatement (struct iscsi_conn *conn) +{ +int sessiontype; +struct iscsi_param *initiatorname_param =NULL , *sessiontype_param =NULL ; +struct iscsi_portal_group *tpg = conn->tpg; +struct iscsi_session *sess =NULL , *sess_p =NULL ; +struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; +struct se_session *se_sess, *se_sess_tmp; + + initiatorname_param =iscsi_find_param_from_key ( +INITIATORNAME , conn->param_list); +if (!initiatorname_param) +return -1 ; + + sessiontype_param =iscsi_find_param_from_key ( +SESSIONTYPE , conn->param_list); +if (!sessiontype_param) +return -1 ; + + sessiontype = (strncmp (sessiontype_param->value,NORMAL ,6 )) ?1 :0 ; + +spin_lock_bh (&se_tpg->session_lock); +list_for_each_entry_safe (se_sess, se_sess_tmp, &se_tpg->tpg_sess_list, + sess_list) { + + sess_p = (struct iscsi_session *)se_sess->fabric_sess_ptr; +spin_lock (&sess_p->conn_lock); +if (atomic_read (&sess_p->session_fall_back_to_erl0) || +atomic_read (&sess_p->session_logout) || + (sess_p->time2retain_timer_flags &ISCSI_TF_EXPIRED )) { +spin_unlock (&sess_p->conn_lock); +continue ; + } +if (!memcmp ((void *)sess_p->isid, (void *)conn->sess->isid,6 ) && + (!strcmp ((void *)sess_p->sess_ops->InitiatorName, + (void *)initiatorname_param->value) && + (sess_p->sess_ops->SessionType == sessiontype))) { +atomic_set (&sess_p->session_reinstatement,1 ); +spin_unlock (&sess_p->conn_lock); +iscsi_inc_session_usage_count (sess_p); +iscsi_stop_time2retain_timer (sess_p); + sess = sess_p; +break ; + } +spin_unlock (&sess_p->conn_lock); + } +spin_unlock_bh (&se_tpg->session_lock); +/* +* If the Time2Retain handler has expired, the session is already gone. +*/ +if (!sess) +return 0 ; + +TRACE (TRACE_ERL0 ,"%s iSCSI Session SID %u is still active for %s," +" preforming session reinstatement.\n" , (sessiontype) ? +"Discovery" :"Normal" , sess->sid, + sess->sess_ops->InitiatorName); + +spin_lock_bh (&sess->conn_lock); +if (sess->session_state ==TARG_SESS_STATE_FAILED ) { +spin_unlock_bh (&sess->conn_lock); +iscsi_dec_session_usage_count (sess); +return iscsi_close_session (sess); + } +spin_unlock_bh (&sess->conn_lock); + +iscsi_stop_session (sess,1 ,1 ); +iscsi_dec_session_usage_count (sess); + +return iscsi_close_session (sess); +} + +static void iscsi_login_set_conn_values ( +struct iscsi_session *sess, +struct iscsi_conn *conn, +u16 cid) +{ + conn->sess = sess; + conn->cid = cid; +/* +* Generate a random Status sequence number (statsn) for the new +* iSCSI connection. +*/ +get_random_bytes (&conn->stat_sn,sizeof (u32)); + +mutex_lock (&auth_id_lock); + conn->auth_id = iscsi_global->auth_id++; +mutex_unlock (&auth_id_lock); +} + +/* iscsi_login_zero_tsih(): +* +* This is the leading connection of a new session, +* or session reinstatement. +*/ +static int iscsi_login_zero_tsih_s1 ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +struct iscsi_session *sess =NULL ; +struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; + + sess =kzalloc (sizeof (struct iscsi_session ),GFP_KERNEL ); +if (!sess) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +printk (KERN_ERR "Could not allocate memory for session\n" ); +return -1 ; + } + +iscsi_login_set_conn_values (sess, conn, pdu->cid); + sess->init_task_tag = pdu->itt; +memcpy ((void *)&sess->isid, (void *)pdu->isid,6 ); + sess->exp_cmd_sn = pdu->cmdsn; +INIT_LIST_HEAD (&sess->sess_conn_list); +INIT_LIST_HEAD (&sess->sess_ooo_cmdsn_list); +INIT_LIST_HEAD (&sess->cr_active_list); +INIT_LIST_HEAD (&sess->cr_inactive_list); +init_completion (&sess->async_msg_comp); +init_completion (&sess->reinstatement_comp); +init_completion (&sess->session_wait_comp); +spin_lock_init (&sess->cmdsn_lock); +spin_lock_init (&sess->conn_lock); +spin_lock_init (&sess->cr_a_lock); +spin_lock_init (&sess->cr_i_lock); +spin_lock_init (&sess->session_usage_lock); +spin_lock_init (&sess->ttt_lock); + +if (!idr_pre_get (&sess_idr,GFP_KERNEL )) { +printk (KERN_ERR "idr_pre_get() for sess_idr failed\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } +spin_lock (&sess_idr_lock); +idr_get_new (&sess_idr,NULL , &sess->session_index); +spin_unlock (&sess_idr_lock); + + sess->creation_time =get_jiffies_64 (); +spin_lock_init (&sess->session_stats_lock); +/* +* The FFP CmdSN window values will be allocated from the TPG's +* Initiator Node's ACL once the login has been successfully completed. +*/ + sess->max_cmd_sn = pdu->cmdsn; + + sess->sess_ops =kzalloc (sizeof (struct iscsi_sess_ops ),GFP_KERNEL ); +if (!sess->sess_ops) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +printk (KERN_ERR "Unable to allocate memory for" +" struct iscsi_sess_ops.\n" ); +return -1 ; + } + + sess->se_sess =transport_init_session (); +if (!sess->se_sess) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + +return 0 ; +} + +static int iscsi_login_zero_tsih_s2 ( +struct iscsi_conn *conn) +{ +struct iscsi_node_attrib *na; +struct iscsi_session *sess = conn->sess; +unsigned char buf[32 ]; + + sess->tpg = conn->tpg; + +/* +* Assign a new TPG Session Handle. Note this is protected with +* struct iscsi_portal_group->np_login_sem from iscsit_access_np(). +*/ + sess->tsih = ++ISCSI_TPG_S (sess)->ntsih; +if (!sess->tsih) + sess->tsih = ++ISCSI_TPG_S (sess)->ntsih; + +/* +* Create the default params from user defined values.. +*/ +if (iscsi_copy_param_list (&conn->param_list, +ISCSI_TPG_C (conn)->param_list,1 ) <0 ) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + +iscsi_set_keys_to_negotiate (0 , conn->param_list); + +if (sess->sess_ops->SessionType) +return iscsi_set_keys_irrelevant_for_discovery ( + conn->param_list); + + na =iscsi_tpg_get_node_attrib (sess); + +/* +* Need to send TargetPortalGroupTag back in first login response +* on any iSCSI connection where the Initiator provides TargetName. +* See 5.3.1. Login Phase Start +* +* In our case, we have already located the struct iscsi_tiqn at this point. +*/ +memset (buf,0 ,32 ); +sprintf (buf,"TargetPortalGroupTag=%hu" ,ISCSI_TPG_S (sess)->tpgt); +if (iscsi_change_param_value (buf, conn->param_list,0 ) <0 ) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + +/* +* Workaround for Initiators that have broken connection recovery logic. +* +* "We would really like to get rid of this." Linux-iSCSI.org team +*/ +memset (buf,0 ,32 ); +sprintf (buf,"ErrorRecoveryLevel=%d" , na->default_erl); +if (iscsi_change_param_value (buf, conn->param_list,0 ) <0 ) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + +if (iscsi_login_disable_FIM_keys (conn->param_list, conn) <0 ) +return -1 ; + +return 0 ; +} + +/* +* Remove PSTATE_NEGOTIATE for the four FIM related keys. +* The Initiator node will be able to enable FIM by proposing them itself. +*/ +int iscsi_login_disable_FIM_keys ( +struct iscsi_param_list *param_list, +struct iscsi_conn *conn) +{ +struct iscsi_param *param; + + param =iscsi_find_param_from_key ("OFMarker" , param_list); +if (!param) { +printk (KERN_ERR "iscsi_find_param_from_key() for" +" OFMarker failed\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + param->state &= ~PSTATE_NEGOTIATE ; + + param =iscsi_find_param_from_key ("OFMarkInt" , param_list); +if (!param) { +printk (KERN_ERR "iscsi_find_param_from_key() for" +" IFMarker failed\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + param->state &= ~PSTATE_NEGOTIATE ; + + param =iscsi_find_param_from_key ("IFMarker" , param_list); +if (!param) { +printk (KERN_ERR "iscsi_find_param_from_key() for" +" IFMarker failed\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + param->state &= ~PSTATE_NEGOTIATE ; + + param =iscsi_find_param_from_key ("IFMarkInt" , param_list); +if (!param) { +printk (KERN_ERR "iscsi_find_param_from_key() for" +" IFMarker failed\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + param->state &= ~PSTATE_NEGOTIATE ; + +return 0 ; +} + +static int iscsi_login_non_zero_tsih_s1 ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; + +iscsi_login_set_conn_values (NULL , conn, pdu->cid); +return 0 ; +} + +/* iscsi_login_non_zero_tsih_s2(): +* +* Add a new connection to an existing session. +*/ +static int iscsi_login_non_zero_tsih_s2 ( +struct iscsi_conn *conn, +unsigned char *buf) +{ +struct iscsi_portal_group *tpg = conn->tpg; +struct iscsi_session *sess =NULL , *sess_p =NULL ; +struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; +struct se_session *se_sess, *se_sess_tmp; +struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; + +spin_lock_bh (&se_tpg->session_lock); +list_for_each_entry_safe (se_sess, se_sess_tmp, &se_tpg->tpg_sess_list, + sess_list) { + + sess_p = (struct iscsi_session *)se_sess->fabric_sess_ptr; +if (atomic_read (&sess_p->session_fall_back_to_erl0) || +atomic_read (&sess_p->session_logout) || + (sess_p->time2retain_timer_flags &ISCSI_TF_EXPIRED )) +continue ; +if (!(memcmp ((const void *)sess_p->isid, + (const void *)pdu->isid,6 )) && + (sess_p->tsih == pdu->tsih)) { +iscsi_inc_session_usage_count (sess_p); +iscsi_stop_time2retain_timer (sess_p); + sess = sess_p; +break ; + } + } +spin_unlock_bh (&se_tpg->session_lock); + +/* +* If the Time2Retain handler has expired, the session is already gone. +*/ +if (!sess) { +printk (KERN_ERR "Initiator attempting to add a connection to" +" a non-existent session, rejecting iSCSI Login.\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_INITIATOR_ERR , +ISCSI_LOGIN_STATUS_NO_SESSION ); +return -1 ; + } + +/* +* Stop the Time2Retain timer if this is a failed session, we restart +* the timer if the login is not successful. +*/ +spin_lock_bh (&sess->conn_lock); +if (sess->session_state ==TARG_SESS_STATE_FAILED ) +atomic_set (&sess->session_continuation,1 ); +spin_unlock_bh (&sess->conn_lock); + +iscsi_login_set_conn_values (sess, conn, pdu->cid); + +if (iscsi_copy_param_list (&conn->param_list, +ISCSI_TPG_C (conn)->param_list,0 ) <0 ) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + +iscsi_set_keys_to_negotiate (0 , conn->param_list); +/* +* Need to send TargetPortalGroupTag back in first login response +* on any iSCSI connection where the Initiator provides TargetName. +* See 5.3.1. Login Phase Start +* +* In our case, we have already located the struct iscsi_tiqn at this point. +*/ +memset (buf,0 ,32 ); +sprintf (buf,"TargetPortalGroupTag=%hu" ,ISCSI_TPG_S (sess)->tpgt); +if (iscsi_change_param_value (buf, conn->param_list,0 ) <0 ) { +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_NO_RESOURCES ); +return -1 ; + } + +return iscsi_login_disable_FIM_keys (conn->param_list, conn); +} + +int iscsi_login_post_auth_non_zero_tsih ( +struct iscsi_conn *conn, +u16 cid, +u32 exp_statsn) +{ +struct iscsi_conn *conn_ptr =NULL ; +struct iscsi_conn_recovery *cr =NULL ; +struct iscsi_session *sess = conn->sess; + +/* +* By following item 5 in the login table, if we have found +* an existing ISID and a valid/existing TSIH and an existing +* CID we do connection reinstatement. Currently we dont not +* support it so we send back an non-zero status class to the +* initiator and release the new connection. +*/ + conn_ptr =iscsi_get_conn_from_cid_rcfr (sess, cid); +if ((conn_ptr)) { +printk (KERN_ERR "Connection exists with CID %hu for %s," +" performing connection reinstatement.\n" , + conn_ptr->cid, sess->sess_ops->InitiatorName); + +iscsi_connection_reinstatement_rcfr (conn_ptr); +iscsi_dec_conn_usage_count (conn_ptr); + } + +/* +* Check for any connection recovery entires containing CID. +* We use the original ExpStatSN sent in the first login request +* to acknowledge commands for the failed connection. +* +* Also note that an explict logout may have already been sent, +* but the response may not be sent due to additional connection +* loss. +*/ +if (sess->sess_ops->ErrorRecoveryLevel ==2 ) { + cr =iscsi_get_inactive_connection_recovery_entry ( + sess, cid); +if ((cr)) { +TRACE (TRACE_ERL2 ,"Performing implicit logout" +" for connection recovery on CID: %hu\n" , + conn->cid); +iscsi_discard_cr_cmds_by_expstatsn (cr, exp_statsn); + } + } + +/* +* Else we follow item 4 from the login table in that we have +* found an existing ISID and a valid/existing TSIH and a new +* CID we go ahead and continue to add a new connection to the +* session. +*/ +TRACE (TRACE_LOGIN ,"Adding CID %hu to existing session for %s.\n" , + cid, sess->sess_ops->InitiatorName); + +if ((atomic_read (&sess->nconn) +1 ) > sess->sess_ops->MaxConnections) { +printk (KERN_ERR "Adding additional connection to this session" +" would exceed MaxConnections %d, login failed.\n" , + sess->sess_ops->MaxConnections); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_INITIATOR_ERR , +ISCSI_LOGIN_STATUS_ISID_ERROR ); +return -1 ; + } + +return 0 ; +} + +static void iscsi_post_login_start_timers (struct iscsi_conn *conn) +{ +struct iscsi_session *sess = conn->sess; + +/* #warning PHY timer is disabled */ +#if 0 +iscsi_get_network_interface_from_conn (conn); + +spin_lock_bh (&conn->netif_lock); +iscsi_start_netif_timer (conn); +spin_unlock_bh (&conn->netif_lock); +#endif +if (!sess->sess_ops->SessionType) +iscsi_start_nopin_timer (conn); +} + +static int iscsi_post_login_handler ( +struct iscsi_np *np, +struct iscsi_conn *conn, +u8 zero_tsih) +{ +int stop_timer =0 ; +unsigned char buf_ipv4[IPV4_BUF_SIZE ], buf1_ipv4[IPV4_BUF_SIZE ]; +unsigned char *ip, *ip_np; +struct iscsi_session *sess = conn->sess; +struct se_session *se_sess = sess->se_sess; +struct iscsi_portal_group *tpg =ISCSI_TPG_S (sess); +struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; +struct iscsi_thread_set *ts; + +iscsi_inc_conn_usage_count (conn); + +iscsi_collect_login_stats (conn,ISCSI_STATUS_CLS_SUCCESS , +ISCSI_LOGIN_STATUS_ACCEPT ); + +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_LOGGED_IN.\n" ); + conn->conn_state =TARG_CONN_STATE_LOGGED_IN ; + +iscsi_set_connection_parameters (conn->conn_ops, conn->param_list); +iscsi_set_sync_and_steering_values (conn); + +if (np->np_flags &NPF_NET_IPV6 ) { + ip = &conn->ipv6_login_ip[0 ]; + ip_np = &np->np_ipv6[0 ]; + }else { +memset (buf_ipv4,0 ,IPV4_BUF_SIZE ); +memset (buf1_ipv4,0 ,IPV4_BUF_SIZE ); +iscsi_ntoa2 (buf_ipv4, conn->login_ip); +iscsi_ntoa2 (buf1_ipv4, np->np_ipv4); + ip = &buf_ipv4[0 ]; + ip_np = &buf1_ipv4[0 ]; + } + +/* +* SCSI Initiator -> SCSI Target Port Mapping +*/ + ts =iscsi_get_thread_set (); +if (!zero_tsih) { +iscsi_set_session_parameters (sess->sess_ops, + conn->param_list,0 ); +iscsi_release_param_list (conn->param_list); + conn->param_list =NULL ; + +spin_lock_bh (&sess->conn_lock); +atomic_set (&sess->session_continuation,0 ); +if (sess->session_state ==TARG_SESS_STATE_FAILED ) { +TRACE (TRACE_STATE ,"Moving to" +" TARG_SESS_STATE_LOGGED_IN.\n" ); + sess->session_state =TARG_SESS_STATE_LOGGED_IN ; + stop_timer =1 ; + } + +printk (KERN_INFO "iSCSI Login successful on CID: %hu from %s to" +" %s:%hu,%hu\n" , conn->cid, ip, ip_np, + np->np_port, tpg->tpgt); + +list_add_tail (&conn->conn_list, &sess->sess_conn_list); +atomic_inc (&sess->nconn); +printk (KERN_INFO "Incremented iSCSI Connection count to %hu" +" from node: %s\n" ,atomic_read (&sess->nconn), + sess->sess_ops->InitiatorName); +spin_unlock_bh (&sess->conn_lock); + +iscsi_post_login_start_timers (conn); +iscsi_activate_thread_set (conn, ts); +/* +* Determine CPU mask to ensure connection's RX and TX kthreads +* are scheduled on the same CPU. +*/ +iscsi_thread_get_cpumask (conn); + conn->conn_rx_reset_cpumask =1 ; + conn->conn_tx_reset_cpumask =1 ; + +iscsi_dec_conn_usage_count (conn); +if (stop_timer) { +spin_lock_bh (&se_tpg->session_lock); +iscsi_stop_time2retain_timer (sess); +spin_unlock_bh (&se_tpg->session_lock); + } +iscsi_dec_session_usage_count (sess); +return 0 ; + } + +iscsi_set_session_parameters (sess->sess_ops, conn->param_list,1 ); +iscsi_release_param_list (conn->param_list); + conn->param_list =NULL ; + +iscsi_determine_maxcmdsn (sess); + +spin_lock_bh (&se_tpg->session_lock); +__transport_register_session (&sess->tpg->tpg_se_tpg, + se_sess->se_node_acl, se_sess, (void *)sess); +TRACE (TRACE_STATE ,"Moving to TARG_SESS_STATE_LOGGED_IN.\n" ); + sess->session_state =TARG_SESS_STATE_LOGGED_IN ; + +printk (KERN_INFO "iSCSI Login successful on CID: %hu from %s to %s:%hu,%hu\n" , + conn->cid, ip, ip_np, np->np_port, tpg->tpgt); + +spin_lock_bh (&sess->conn_lock); +list_add_tail (&conn->conn_list, &sess->sess_conn_list); +atomic_inc (&sess->nconn); +printk (KERN_INFO "Incremented iSCSI Connection count to %hu from node:" +" %s\n" ,atomic_read (&sess->nconn), + sess->sess_ops->InitiatorName); +spin_unlock_bh (&sess->conn_lock); + + sess->sid = tpg->sid++; +if (!sess->sid) + sess->sid = tpg->sid++; +printk (KERN_INFO "Established iSCSI session from node: %s\n" , + sess->sess_ops->InitiatorName); + + tpg->nsessions++; +if (tpg->tpg_tiqn) + tpg->tpg_tiqn->tiqn_nsessions++; + +printk (KERN_INFO "Incremented number of active iSCSI sessions to %u on" +" iSCSI Target Portal Group: %hu\n" , tpg->nsessions, tpg->tpgt); +spin_unlock_bh (&se_tpg->session_lock); + +iscsi_post_login_start_timers (conn); +iscsi_activate_thread_set (conn, ts); +/* +* Determine CPU mask to ensure connection's RX and TX kthreads +* are scheduled on the same CPU. +*/ +iscsi_thread_get_cpumask (conn); + conn->conn_rx_reset_cpumask =1 ; + conn->conn_tx_reset_cpumask =1 ; + +iscsi_dec_conn_usage_count (conn); + +return 0 ; +} + +static void iscsi_handle_login_thread_timeout (unsigned long data) +{ +unsigned char buf_ipv4[IPV4_BUF_SIZE ]; +struct iscsi_np *np = (struct iscsi_np *) data; + +memset (buf_ipv4,0 ,IPV4_BUF_SIZE ); +spin_lock_bh (&np->np_thread_lock); +iscsi_ntoa2 (buf_ipv4, np->np_ipv4); + +printk (KERN_ERR "iSCSI Login timeout on Network Portal %s:%hu\n" , + buf_ipv4, np->np_port); + +if (np->np_login_timer_flags &ISCSI_TF_STOP ) { +spin_unlock_bh (&np->np_thread_lock); +return ; + } + +if (np->np_thread) +send_sig (SIGINT , np->np_thread,1 ); + + np->np_login_timer_flags &= ~ISCSI_TF_RUNNING ; +spin_unlock_bh (&np->np_thread_lock); +} + +static void iscsi_start_login_thread_timer (struct iscsi_np *np) +{ +/* +* This used the TA_LOGIN_TIMEOUT constant because at this +* point we do not have access to ISCSI_TPG_ATTRIB(tpg)->login_timeout +*/ +spin_lock_bh (&np->np_thread_lock); +init_timer (&np->np_login_timer); + np->np_login_timer.expires = (get_jiffies_64 () +TA_LOGIN_TIMEOUT *HZ ); + np->np_login_timer.data = (unsigned long )np; + np->np_login_timer.function = iscsi_handle_login_thread_timeout; + np->np_login_timer_flags &= ~ISCSI_TF_STOP ; + np->np_login_timer_flags |=ISCSI_TF_RUNNING ; +add_timer (&np->np_login_timer); + +TRACE (TRACE_LOGIN ,"Added timeout timer to iSCSI login request for" +" %u seconds.\n" ,TA_LOGIN_TIMEOUT ); +spin_unlock_bh (&np->np_thread_lock); +} + +static void iscsi_stop_login_thread_timer (struct iscsi_np *np) +{ +spin_lock_bh (&np->np_thread_lock); +if (!(np->np_login_timer_flags &ISCSI_TF_RUNNING )) { +spin_unlock_bh (&np->np_thread_lock); +return ; + } + np->np_login_timer_flags |=ISCSI_TF_STOP ; +spin_unlock_bh (&np->np_thread_lock); + +del_timer_sync (&np->np_login_timer); + +spin_lock_bh (&np->np_thread_lock); + np->np_login_timer_flags &= ~ISCSI_TF_RUNNING ; +spin_unlock_bh (&np->np_thread_lock); +} + +int iscsi_target_setup_login_socket (struct iscsi_np *np) +{ +const char *end; +struct socket *sock; +int backlog =5 , ret, opt =0 ; +struct sockaddr_in sock_in; +struct sockaddr_in6 sock_in6; + +switch (np->np_network_transport) { +case ISCSI_TCP : + np->np_ip_proto =IPPROTO_TCP ; + np->np_sock_type =SOCK_STREAM ; +break ; +case ISCSI_SCTP_TCP : + np->np_ip_proto =IPPROTO_SCTP ; + np->np_sock_type =SOCK_STREAM ; +break ; +case ISCSI_SCTP_UDP : + np->np_ip_proto =IPPROTO_SCTP ; + np->np_sock_type =SOCK_SEQPACKET ; +break ; +case ISCSI_IWARP_TCP : +case ISCSI_IWARP_SCTP : +case ISCSI_INFINIBAND : +default : +printk (KERN_ERR "Unsupported network_transport: %d\n" , + np->np_network_transport); +return -EINVAL ; + } + + ret =sock_create ((np->np_flags &NPF_NET_IPV6 ) ?AF_INET6 :AF_INET , + np->np_sock_type, np->np_ip_proto, &sock); +if (ret <0 ) { +printk (KERN_ERR "sock_create() failed.\n" ); +return ret; + } + np->np_socket = sock; + +/* +* The SCTP stack needs struct socket->file. +*/ +if ((np->np_network_transport ==ISCSI_SCTP_TCP ) || + (np->np_network_transport ==ISCSI_SCTP_UDP )) { +if (!sock->file) { + sock->file =kzalloc (sizeof (struct file ),GFP_KERNEL ); +if (!sock->file) { +printk (KERN_ERR "Unable to allocate struct" +" file for SCTP\n" ); + ret = -ENOMEM ; + goto fail; + } + np->np_flags |=NPF_SCTP_STRUCT_FILE ; + } + } + +if (np->np_flags &NPF_NET_IPV6 ) { +memset (&sock_in6,0 ,sizeof (struct sockaddr_in6 )); + sock_in6.sin6_family =AF_INET6 ; + sock_in6.sin6_port =htons (np->np_port); + + ret =in6_pton (&np->np_ipv6[0 ],IPV6_ADDRESS_SPACE , + (void *)&sock_in6.sin6_addr.in6_u,-1 , &end); +if (ret <=0 ) { +printk (KERN_ERR "in6_pton returned: %d\n" , ret); + ret = -EINVAL ; + goto fail; + } + }else { +memset (&sock_in,0 ,sizeof (struct sockaddr_in )); + sock_in.sin_family =AF_INET ; + sock_in.sin_port =htons (np->np_port); + sock_in.sin_addr.s_addr =htonl (np->np_ipv4); + } + +/* +* Set SO_REUSEADDR, and disable Nagel Algorithm with TCP_NODELAY. +*/ + opt =1 ; +if (np->np_network_transport ==ISCSI_TCP ) { + ret =kernel_setsockopt (sock,IPPROTO_TCP ,TCP_NODELAY , + (char *)&opt,sizeof (opt)); +if (ret <0 ) { +printk (KERN_ERR "kernel_setsockopt() for TCP_NODELAY" +" failed: %d\n" , ret); + goto fail; + } + } + ret =kernel_setsockopt (sock,SOL_SOCKET ,SO_REUSEADDR , + (char *)&opt,sizeof (opt)); +if (ret <0 ) { +printk (KERN_ERR "kernel_setsockopt() for SO_REUSEADDR" +" failed\n" ); + goto fail; + } + +if (np->np_flags &NPF_NET_IPV6 ) { + ret =kernel_bind (sock, (struct sockaddr *)&sock_in6, +sizeof (struct sockaddr_in6 )); +if (ret <0 ) { +printk (KERN_ERR "kernel_bind() failed: %d\n" , ret); + goto fail; + } + }else { + ret =kernel_bind (sock, (struct sockaddr *)&sock_in, +sizeof (struct sockaddr )); +if (ret <0 ) { +printk (KERN_ERR "kernel_bind() failed: %d\n" , ret); + goto fail; + } + } + + ret =kernel_listen (sock, backlog); +if (ret !=0 ) { +printk (KERN_ERR "kernel_listen() failed: %d\n" , ret); + goto fail; + } + +return 0 ; + +fail: + np->np_socket =NULL ; +if (sock) { +if (np->np_flags &NPF_SCTP_STRUCT_FILE ) { +kfree (sock->file); + sock->file =NULL ; + } + +sock_release (sock); + } +return ret; +} + +static int __iscsi_target_login_thread (struct iscsi_np *np) +{ +u8 buffer[ISCSI_HDR_LEN ], iscsi_opcode, zero_tsih =0 ; +unsigned char *ip =NULL , *ip_init_buf =NULL ; +unsigned char buf_ipv4[IPV4_BUF_SIZE ], buf1_ipv4[IPV4_BUF_SIZE ]; +int err, ret =0 , ip_proto, sock_type, set_sctp_conn_flag; +struct iscsi_conn *conn =NULL ; +struct iscsi_login *login; +struct iscsi_portal_group *tpg =NULL ; +struct socket *new_sock, *sock; +struct iovec iov; +struct iscsi_login_req *pdu; +struct sockaddr_in sock_in; +struct sockaddr_in6 sock_in6; + +flush_signals (current); + set_sctp_conn_flag =0 ; + sock = np->np_socket; + ip_proto = np->np_ip_proto; + sock_type = np->np_sock_type; + +spin_lock_bh (&np->np_thread_lock); +if (np->np_thread_state ==ISCSI_NP_THREAD_RESET ) { + np->np_thread_state =ISCSI_NP_THREAD_ACTIVE ; +complete (&np->np_restart_comp); + }else { + np->np_thread_state =ISCSI_NP_THREAD_ACTIVE ; + } +spin_unlock_bh (&np->np_thread_lock); + +if (kernel_accept (sock, &new_sock,0 ) <0 ) { +spin_lock_bh (&np->np_thread_lock); +if (np->np_thread_state ==ISCSI_NP_THREAD_RESET ) { +spin_unlock_bh (&np->np_thread_lock); +complete (&np->np_restart_comp); +/* Get another socket */ +return 1 ; + } +spin_unlock_bh (&np->np_thread_lock); + goto out; + } +/* +* The SCTP stack needs struct socket->file. +*/ +if ((np->np_network_transport ==ISCSI_SCTP_TCP ) || + (np->np_network_transport ==ISCSI_SCTP_UDP )) { +if (!new_sock->file) { + new_sock->file =kzalloc ( +sizeof (struct file ),GFP_KERNEL ); +if (!new_sock->file) { +printk (KERN_ERR "Unable to allocate struct" +" file for SCTP\n" ); +sock_release (new_sock); +/* Get another socket */ +return 1 ; + } + set_sctp_conn_flag =1 ; + } + } + +iscsi_start_login_thread_timer (np); + + conn =kzalloc (sizeof (struct iscsi_conn ),GFP_KERNEL ); +if (!conn) { +printk (KERN_ERR "Could not allocate memory for" +" new connection\n" ); +if (set_sctp_conn_flag) { +kfree (new_sock->file); + new_sock->file =NULL ; + } +sock_release (new_sock); +/* Get another socket */ +return 1 ; + } + +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_FREE.\n" ); + conn->conn_state =TARG_CONN_STATE_FREE ; + conn->sock = new_sock; + +if (set_sctp_conn_flag) + conn->conn_flags |=CONNFLAG_SCTP_STRUCT_FILE ; + +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_XPT_UP.\n" ); + conn->conn_state =TARG_CONN_STATE_XPT_UP ; + +/* +* Allocate conn->conn_ops early as a failure calling +* iscsi_tx_login_rsp() below will call tx_data(). +*/ + conn->conn_ops =kzalloc (sizeof (struct iscsi_conn_ops ),GFP_KERNEL ); +if (!conn->conn_ops) { +printk (KERN_ERR "Unable to allocate memory for" +" struct iscsi_conn_ops.\n" ); + goto new_sess_out; + } +/* +* Perform the remaining iSCSI connection initialization items.. +*/ +if (iscsi_login_init_conn (conn) <0 ) + goto new_sess_out; + +memset (buffer,0 ,ISCSI_HDR_LEN ); +memset (&iov,0 ,sizeof (struct iovec )); + iov.iov_base = buffer; + iov.iov_len =ISCSI_HDR_LEN ; + +if (rx_data (conn, &iov,1 ,ISCSI_HDR_LEN ) <=0 ) { +printk (KERN_ERR "rx_data() returned an error.\n" ); + goto new_sess_out; + } + + iscsi_opcode = (buffer[0 ] &ISCSI_OPCODE_MASK ); +if (!(iscsi_opcode &ISCSI_OP_LOGIN )) { +printk (KERN_ERR "First opcode is not login request," +" failing login request.\n" ); + goto new_sess_out; + } + + pdu = (struct iscsi_login_req *) buffer; + pdu->cid =be16_to_cpu (pdu->cid); + pdu->tsih =be16_to_cpu (pdu->tsih); + pdu->itt =be32_to_cpu (pdu->itt); + pdu->cmdsn =be32_to_cpu (pdu->cmdsn); + pdu->exp_statsn =be32_to_cpu (pdu->exp_statsn); +/* +* Used by iscsi_tx_login_rsp() for Login Resonses PDUs +* when Status-Class != 0. +*/ + conn->login_itt = pdu->itt; + +if (np->np_flags &NPF_NET_IPV6 ) { + ip = &np->np_ipv6[0 ]; + }else { +memset (buf_ipv4,0 ,IPV4_BUF_SIZE ); +iscsi_ntoa2 (buf_ipv4, np->np_ipv4); + ip = &buf_ipv4[0 ]; + } + +spin_lock_bh (&np->np_thread_lock); +if ((atomic_read (&np->np_shutdown)) || + (np->np_thread_state !=ISCSI_NP_THREAD_ACTIVE )) { +spin_unlock_bh (&np->np_thread_lock); +printk (KERN_ERR "iSCSI Network Portal on %s:%hu currently not" +" active.\n" , ip, np->np_port); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE ); + goto new_sess_out; + } +spin_unlock_bh (&np->np_thread_lock); + +if (np->np_flags &NPF_NET_IPV6 ) { +memset (&sock_in6,0 ,sizeof (struct sockaddr_in6 )); + +if (conn->sock->ops->getname (conn->sock, + (struct sockaddr *)&sock_in6, &err,1 ) <0 ) { +printk (KERN_ERR "sock_ops->getname() failed.\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_TARGET_ERROR ); + goto new_sess_out; + } +#if 0 +if (!(iscsi_ntop6 ((const unsigned char *) + &sock_in6.sin6_addr.in6_u, + (char *)&conn->ipv6_login_ip[0 ], +IPV6_ADDRESS_SPACE ))) { +printk (KERN_ERR "iscsi_ntop6() failed\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_TARGET_ERROR ); + goto new_sess_out; + } +#else +printk (KERN_INFO "Skipping iscsi_ntop6()\n" ); +#endif + ip_init_buf = &conn->ipv6_login_ip[0 ]; + }else { +memset (&sock_in,0 ,sizeof (struct sockaddr_in )); + +if (conn->sock->ops->getname (conn->sock, + (struct sockaddr *)&sock_in, &err,1 ) <0 ) { +printk (KERN_ERR "sock_ops->getname() failed.\n" ); +iscsi_tx_login_rsp (conn,ISCSI_STATUS_CLS_TARGET_ERR , +ISCSI_LOGIN_STATUS_TARGET_ERROR ); + goto new_sess_out; + } +memset (buf1_ipv4,0 ,IPV4_BUF_SIZE ); + conn->login_ip =ntohl (sock_in.sin_addr.s_addr); + conn->login_port =ntohs (sock_in.sin_port); +iscsi_ntoa2 (buf1_ipv4, conn->login_ip); + ip_init_buf = &buf1_ipv4[0 ]; + } + + conn->network_transport = np->np_network_transport; +snprintf (conn->net_dev,ISCSI_NETDEV_NAME_SIZE ,"%s" , np->np_net_dev); + + conn->local_ip = np->np_ipv4; + conn->local_port = np->np_port; + +printk (KERN_INFO "Received iSCSI login request from %s on %s Network" +" Portal %s:%hu\n" , ip_init_buf, + (conn->network_transport ==ISCSI_TCP ) ?"TCP" :"SCTP" , + ip, np->np_port); + +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_IN_LOGIN.\n" ); + conn->conn_state =TARG_CONN_STATE_IN_LOGIN ; + +if (iscsi_login_check_initiator_version (conn, pdu->max_version, + pdu->min_version) <0 ) + goto new_sess_out; + + zero_tsih = (pdu->tsih ==0x0000 ); +if ((zero_tsih)) { +/* +* This is the leading connection of a new session. +* We wait until after authentication to check for +* session reinstatement. +*/ +if (iscsi_login_zero_tsih_s1 (conn, buffer) <0 ) + goto new_sess_out; + }else { +/* +* Add a new connection to an existing session. +* We check for a non-existant session in +* iscsi_login_non_zero_tsih_s2() below based +* on ISID/TSIH, but wait until after authentication +* to check for connection reinstatement, etc. +*/ +if (iscsi_login_non_zero_tsih_s1 (conn, buffer) <0 ) + goto new_sess_out; + } + +/* +* This will process the first login request, and call +* iscsi_target_locate_portal(), and return a valid struct iscsi_login. +*/ + login =iscsi_target_init_negotiation (np, conn, buffer); +if (!login) { + tpg = conn->tpg; + goto new_sess_out; + } + + tpg = conn->tpg; +if (!tpg) { +printk (KERN_ERR "Unable to locate struct iscsi_conn->tpg\n" ); + goto new_sess_out; + } + +if (zero_tsih) { +if (iscsi_login_zero_tsih_s2 (conn) <0 ) { +iscsi_target_nego_release (login, conn); + goto new_sess_out; + } + }else { +if (iscsi_login_non_zero_tsih_s2 (conn, buffer) <0 ) { +iscsi_target_nego_release (login, conn); + goto old_sess_out; + } + } + +if (iscsi_target_start_negotiation (login, conn) <0 ) + goto new_sess_out; + +if (!conn->sess) { +printk (KERN_ERR "struct iscsi_conn session pointer is NULL!\n" ); + goto new_sess_out; + } + +iscsi_stop_login_thread_timer (np); + +if (signal_pending (current)) + goto new_sess_out; + + ret =iscsi_post_login_handler (np, conn, zero_tsih); + +if (ret <0 ) + goto new_sess_out; + +iscsit_deaccess_np (np, tpg); + tpg =NULL ; +/* Get another socket */ +return 1 ; + +new_sess_out: +printk (KERN_ERR "iSCSI Login negotiation failed.\n" ); +iscsi_collect_login_stats (conn,ISCSI_STATUS_CLS_INITIATOR_ERR , +ISCSI_LOGIN_STATUS_INIT_ERR ); +if (!zero_tsih || !conn->sess) + goto old_sess_out; +if (conn->sess->se_sess) +transport_free_session (conn->sess->se_sess); +if (conn->sess->session_index !=0 ) { +spin_lock_bh (&sess_idr_lock); +idr_remove (&sess_idr, conn->sess->session_index); +spin_unlock_bh (&sess_idr_lock); + } +if (conn->sess->sess_ops) +kfree (conn->sess->sess_ops); +if (conn->sess) +kfree (conn->sess); +old_sess_out: +iscsi_stop_login_thread_timer (np); +/* +* If login negotiation fails check if the Time2Retain timer +* needs to be restarted. +*/ +if (!zero_tsih && conn->sess) { +spin_lock_bh (&conn->sess->conn_lock); +if (conn->sess->session_state ==TARG_SESS_STATE_FAILED ) { +struct se_portal_group *se_tpg = + &ISCSI_TPG_C (conn)->tpg_se_tpg; + +atomic_set (&conn->sess->session_continuation,0 ); +spin_unlock_bh (&conn->sess->conn_lock); +spin_lock_bh (&se_tpg->session_lock); +iscsi_start_time2retain_handler (conn->sess); +spin_unlock_bh (&se_tpg->session_lock); + }else +spin_unlock_bh (&conn->sess->conn_lock); +iscsi_dec_session_usage_count (conn->sess); + } + +if (!IS_ERR (conn->conn_rx_hash.tfm)) +crypto_free_hash (conn->conn_rx_hash.tfm); +if (!IS_ERR (conn->conn_tx_hash.tfm)) +crypto_free_hash (conn->conn_tx_hash.tfm); + +if (conn->conn_cpumask) +free_cpumask_var (conn->conn_cpumask); + +kfree (conn->conn_ops); + +if (conn->param_list) { +iscsi_release_param_list (conn->param_list); + conn->param_list =NULL ; + } +if (conn->sock) { +if (conn->conn_flags &CONNFLAG_SCTP_STRUCT_FILE ) { +kfree (conn->sock->file); + conn->sock->file =NULL ; + } +sock_release (conn->sock); + } +kfree (conn); + +if (tpg) { +iscsit_deaccess_np (np, tpg); + tpg =NULL ; + } + +out: +/* Wait for another socket.. */ +if (!signal_pending (current) || !kthread_should_stop ()) +return 1 ; + +iscsi_stop_login_thread_timer (np); +spin_lock_bh (&np->np_thread_lock); + np->np_thread_state =ISCSI_NP_THREAD_EXIT ; +spin_unlock_bh (&np->np_thread_lock); +return 0 ; +} + +int iscsi_target_login_thread (void *arg) +{ +struct iscsi_np *np = (struct iscsi_np *)arg; +int ret; + +set_user_nice (current,-20 ); +allow_signal (SIGINT ); + +while (!kthread_should_stop ()) { + ret =__iscsi_target_login_thread (np); +/* +* We break and exit here unless another sock_accept() call +* is expected. +*/ +if (ret !=1 ) +break ; + } + +return 0 ; +}
drivers/target/iscsi/iscsi_target_login.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef ISCSI_TARGET_LOGIN_H +#define ISCSI_TARGET_LOGIN_H + +extern int iscsi_login_setup_crypto (struct iscsi_conn *); +extern int iscsi_check_for_session_reinstatement (struct iscsi_conn *); +extern int iscsi_login_post_auth_non_zero_tsih (struct iscsi_conn *,u16 ,u32 ); +extern int iscsi_target_setup_login_socket (struct iscsi_np *); +extern int iscsi_target_login_thread (void *); +extern int iscsi_login_disable_FIM_keys (struct iscsi_param_list *,struct iscsi_conn *); + +extern struct iscsi_global *iscsi_global; + +#endif /*** ISCSI_TARGET_LOGIN_H ***/
drivers/target/iscsi/iscsi_target_nego.c new file +1069 -0
1,069 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_nego.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef ISCSI_TARGET_NEGO_H +#define ISCSI_TARGET_NEGO_H + +#define DECIMAL 0 +#define HEX 1 + +extern void convert_null_to_semi (char *,int ); +extern int extract_param (const char *,const char *,unsigned int ,char *, +unsigned char *); +extern struct iscsi_login *iscsi_target_init_negotiation ( +struct iscsi_np *,struct iscsi_conn *,char *); +extern int iscsi_target_start_negotiation ( +struct iscsi_login *,struct iscsi_conn *); +extern void iscsi_target_nego_release ( +struct iscsi_login *,struct iscsi_conn *); + +extern struct iscsi_global *iscsi_global; + +#endif /* ISCSI_TARGET_NEGO_H */
drivers/target/iscsi/iscsi_target_parameters.c new file +2052 -0
603 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_parameters.h new file +271 -0
271 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_tq.c new file +640 -0
640 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_tq.h new file +89 -0
89 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.7.4.1
Part of the diff is not shown here. View the raw message.
RFC v3 7/12 iscsi-target: Add CHAP Authentication support using libcrypto
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds support for libcrypto md5 based iSCSI CHAP authentication support for iscsi_target_mod. This includes support for mutual and one-way NodeACL authentication for SessionType=Normal and SessionType=Discovery via /sys/kernel/config/target/iscsi.
--- drivers/target/iscsi/iscsi_target_auth.c | 500 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_auth.h | 33 ++ 2 files changed, 533 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_auth.c create mode 100644 drivers/target/iscsi/iscsi_target_auth.h
drivers/target/iscsi/iscsi_target_auth.c new file +500 -0
@@ -0,0 +1,500 @@ +/******************************************************************************* +* This file houses the main functions for the iSCSI CHAP support +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <linux/string.h> +#include <linux/crypto.h> +#include <linux/err.h> +#include <linux/scatterlist.h> + +#include "iscsi_target_core.h" +#include "iscsi_target_nego.h" +#include "iscsi_target_auth.h" + +#ifdef DEBUG_CHAP +#define PRINT(x...) printk(KERN_INFO x) +#else +#define PRINT(x...) +#endif + +unsigned char chap_asciihex_to_binaryhex (unsigned char val[2 ]) +{ +unsigned char result =0 ; +/* +* MSB +*/ +if ((val[0 ] >='a' ) && (val[0 ] <='f' )) + result = ((val[0 ] -'a' +10 ) &0xf ) <<4 ; +else +if ((val[0 ] >='A' ) && (val[0 ] <='F' )) + result = ((val[0 ] -'A' +10 ) &0xf ) <<4 ; +else /* digit */ + result = ((val[0 ] -'0' ) &0xf ) <<4 ; +/* +* LSB +*/ +if ((val[1 ] >='a' ) && (val[1 ] <='f' )) + result |= ((val[1 ] -'a' +10 ) &0xf ); +else +if ((val[1 ] >='A' ) && (val[1 ] <='F' )) + result |= ((val[1 ] -'A' +10 ) &0xf ); +else /* digit */ + result |= ((val[1 ] -'0' ) &0xf ); + +return result; +} + +int chap_string_to_hex (unsigned char *dst,unsigned char *src,int len) +{ +int i =0 , j =0 ; + +for (i =0 ; i < len; i +=2 ) + dst[j++] = (unsigned char )chap_asciihex_to_binaryhex (&src[i]); + + dst[j] ='\0' ; +return j; +} + +void chap_binaryhex_to_asciihex (char *dst,char *src,int src_len) +{ +int i; + +for (i =0 ; i < src_len; i++) +sprintf (&dst[i*2 ],"%02x" , (int ) src[i] &0xff ); +} + +void chap_set_random (char *data,int length) +{ +long r; +unsigned n; + +while (length >0 ) { + +get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>4 ); + n = r &0x7 ; + +get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>5 ); + n = (n <<3 ) | (r &0x7 ); + +get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>5 ); + n = (n <<2 ) | (r &0x3 ); + + *data++ = n; + length--; + } +} + +static struct iscsi_chap *chap_server_open ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +const char *A_str, +char *AIC_str, +unsigned int *AIC_len) +{ +struct iscsi_chap *chap; +int ret; + +if (!(auth->naf_flags &NAF_USERID_SET ) || + !(auth->naf_flags &NAF_PASSWORD_SET )) { +printk (KERN_ERR "CHAP user or password not set for" +" Initiator ACL\n" ); +return NULL ; + } + + conn->auth_protocol =kzalloc (sizeof (struct iscsi_chap ),GFP_KERNEL ); +if (!(conn->auth_protocol)) +return NULL ; + + chap = (struct iscsi_chap *) conn->auth_protocol; +/* +* We only support MD5 MDA presently. +*/ +if (strncmp (A_str,"CHAP_A=5" ,8 )) { +printk (KERN_ERR "CHAP_A is not MD5.\n" ); +return NULL ; + } +"[server] Got CHAP_A=5\n" ); +/* +* Send back CHAP_A set to MD5. +*/ + *AIC_len =sprintf (AIC_str,"CHAP_A=5" ); + *AIC_len +=1 ; + chap->digest_type =CHAP_DIGEST_MD5 ; +"[server] Sending CHAP_A=%d\n" , chap->digest_type); +/* +* Set Identifier. +*/ + chap->id =ISCSI_TPG_C (conn)->tpg_chap_id++; + *AIC_len +=sprintf (AIC_str + *AIC_len,"CHAP_I=%d" , chap->id); + *AIC_len +=1 ; +"[server] Sending CHAP_I=%d\n" , chap->id); +/* +* Generate Challenge. +*/ + ret =chap_gen_challenge (conn,1 , AIC_str, AIC_len); +if (ret <0 ) +return NULL ; + +return chap; +} + +void chap_close (struct iscsi_conn *conn) +{ +kfree (conn->auth_protocol); + conn->auth_protocol =NULL ; +} + +int chap_gen_challenge ( +struct iscsi_conn *conn, +int caller, +char *C_str, +unsigned int *C_len) +{ +unsigned char challenge_asciihex[CHAP_CHALLENGE_LENGTH *2 +1 ]; +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +memset (challenge_asciihex,0 ,CHAP_CHALLENGE_LENGTH *2 +1 ); + +chap_set_random (chap->challenge,CHAP_CHALLENGE_LENGTH ); +chap_binaryhex_to_asciihex (challenge_asciihex, chap->challenge, +CHAP_CHALLENGE_LENGTH ); +/* +* Set CHAP_C, and copy the generated challenge into C_str. +*/ + *C_len +=sprintf (C_str + *C_len,"CHAP_C=0x%s" , challenge_asciihex); + *C_len +=1 ; + +"[%s] Sending CHAP_C=0x%s\n\n" , (caller) ?"server" :"client" , + challenge_asciihex); +return 0 ; +} + +int chap_server_compute_md5 ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +char *endptr; +unsigned char id, digest[MD5_SIGNATURE_SIZE ]; +unsigned char type, response[MD5_SIGNATURE_SIZE *2 +2 ]; +unsigned char identifier[10 ], *challenge, *challenge_binhex; +unsigned char client_digest[MD5_SIGNATURE_SIZE ]; +unsigned char server_digest[MD5_SIGNATURE_SIZE ]; +unsigned char chap_n[MAX_CHAP_N_SIZE ], chap_r[MAX_RESPONSE_LENGTH ]; +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; +struct crypto_hash *tfm; +struct hash_desc desc; +struct scatterlist sg; +int auth_ret =-1 , ret, challenge_len; + +memset (identifier,0 ,10 ); +memset (chap_n,0 ,MAX_CHAP_N_SIZE ); +memset (chap_r,0 ,MAX_RESPONSE_LENGTH ); +memset (digest,0 ,MD5_SIGNATURE_SIZE ); +memset (response,0 ,MD5_SIGNATURE_SIZE *2 +2 ); +memset (client_digest,0 ,MD5_SIGNATURE_SIZE ); +memset (server_digest,0 ,MD5_SIGNATURE_SIZE ); + + challenge =kzalloc (CHAP_CHALLENGE_STR_LEN ,GFP_KERNEL ); +if (!(challenge)) { +printk (KERN_ERR "Unable to allocate challenge buffer\n" ); +return -1 ; + } + + challenge_binhex =kzalloc (CHAP_CHALLENGE_STR_LEN ,GFP_KERNEL ); +if (!(challenge_binhex)) { +printk (KERN_ERR "Unable to allocate challenge_binhex buffer\n" ); +kfree (challenge); +return -1 ; + } +/* +* Extract CHAP_N. +*/ +if (extract_param (NR_in_ptr,"CHAP_N" ,MAX_CHAP_N_SIZE , chap_n, + &type) <0 ) { +printk (KERN_ERR "Could not find CHAP_N.\n" ); + goto out; + } +if (type ==HEX ) { +printk (KERN_ERR "Could not find CHAP_N.\n" ); + goto out; + } + +if (memcmp (chap_n, auth->userid,strlen (auth->userid)) !=0 ) { +printk (KERN_ERR "CHAP_N values do not match!\n" ); + goto out; + } +"[server] Got CHAP_N=%s\n" , chap_n); +/* +* Extract CHAP_R. +*/ +if (extract_param (NR_in_ptr,"CHAP_R" ,MAX_RESPONSE_LENGTH , chap_r, + &type) <0 ) { +printk (KERN_ERR "Could not find CHAP_R.\n" ); + goto out; + } +if (type !=HEX ) { +printk (KERN_ERR "Could not find CHAP_R.\n" ); + goto out; + } + +"[server] Got CHAP_R=%s\n" , chap_r); +chap_string_to_hex (client_digest, chap_r,strlen (chap_r)); + + tfm =crypto_alloc_hash ("md5" ,0 ,CRYPTO_ALG_ASYNC ); +if (IS_ERR (tfm)) { +printk (KERN_ERR "Unable to allocate struct crypto_hash\n" ); + goto out; + } + desc.tfm = tfm; + desc.flags =0 ; + + ret =crypto_hash_init (&desc); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_init() failed\n" ); +crypto_free_hash (tfm); + goto out; + } + +sg_init_one (&sg, (void *)&chap->id,1 ); + ret =crypto_hash_update (&desc, &sg,1 ); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_update() failed for id\n" ); +crypto_free_hash (tfm); + goto out; + } + +sg_init_one (&sg, (void *)&auth->password,strlen (auth->password)); + ret =crypto_hash_update (&desc, &sg,strlen (auth->password)); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_update() failed for password\n" ); +crypto_free_hash (tfm); + goto out; + } + +sg_init_one (&sg, (void *)chap->challenge,strlen (chap->challenge)); + ret =crypto_hash_update (&desc, &sg,strlen (chap->challenge)); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_update() failed for challenge\n" ); +crypto_free_hash (tfm); + goto out; + } + + ret =crypto_hash_final (&desc, server_digest); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_final() failed for server digest\n" ); +crypto_free_hash (tfm); + goto out; + } +crypto_free_hash (tfm); + +chap_binaryhex_to_asciihex (response, server_digest,MD5_SIGNATURE_SIZE ); +"[server] MD5 Server Digest: %s\n" , response); + +if (memcmp (server_digest, client_digest,MD5_SIGNATURE_SIZE ) !=0 ) { +"[server] MD5 Digests do not match!\n\n" ); + goto out; + }else +"[server] MD5 Digests match, CHAP connetication" +" successful.\n\n" ); +/* +* One way authentication has succeeded, return now if mutual +* authentication is not enabled. +*/ +if (!auth->authenticate_target) { +kfree (challenge); +kfree (challenge_binhex); +return 0 ; + } +/* +* Get CHAP_I. +*/ +if (extract_param (NR_in_ptr,"CHAP_I" ,10 , identifier, &type) <0 ) { +printk (KERN_ERR "Could not find CHAP_I.\n" ); + goto out; + } + +if (type ==HEX ) + id = (unsigned char )simple_strtoul ((char *)&identifier[2 ], + &endptr,0 ); +else + id = (unsigned char )simple_strtoul (identifier, &endptr,0 ); +/* +* RFC 1994 says Identifier is no more than octet (8 bits). +*/ +"[server] Got CHAP_I=%d\n" , id); +/* +* Get CHAP_C. +*/ +if (extract_param (NR_in_ptr,"CHAP_C" ,CHAP_CHALLENGE_STR_LEN , + challenge, &type) <0 ) { +printk (KERN_ERR "Could not find CHAP_C.\n" ); + goto out; + } + +if (type !=HEX ) { +printk (KERN_ERR "Could not find CHAP_C.\n" ); + goto out; + } +"[server] Got CHAP_C=%s\n" , challenge); + challenge_len =chap_string_to_hex (challenge_binhex, challenge, +strlen (challenge)); +if (!(challenge_len)) { +printk (KERN_ERR "Unable to convert incoming challenge\n" ); + goto out; + } +/* +* Generate CHAP_N and CHAP_R for mutual authentication. +*/ + tfm =crypto_alloc_hash ("md5" ,0 ,CRYPTO_ALG_ASYNC ); +if (IS_ERR (tfm)) { +printk (KERN_ERR "Unable to allocate struct crypto_hash\n" ); + goto out; + } + desc.tfm = tfm; + desc.flags =0 ; + + ret =crypto_hash_init (&desc); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_init() failed\n" ); +crypto_free_hash (tfm); + goto out; + } + +sg_init_one (&sg, (void *)&id,1 ); + ret =crypto_hash_update (&desc, &sg,1 ); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_update() failed for id\n" ); +crypto_free_hash (tfm); + goto out; + } + +sg_init_one (&sg, (void *)auth->password_mutual, +strlen (auth->password_mutual)); + ret =crypto_hash_update (&desc, &sg,strlen (auth->password_mutual)); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_update() failed for" +" password_mutual\n" ); +crypto_free_hash (tfm); + goto out; + } +/* +* Convert received challenge to binary hex. +*/ +sg_init_one (&sg, (void *)challenge_binhex, challenge_len); + ret =crypto_hash_update (&desc, &sg, challenge_len); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_update() failed for ma challenge\n" ); +crypto_free_hash (tfm); + goto out; + } + + ret =crypto_hash_final (&desc, digest); +if (ret <0 ) { +printk (KERN_ERR "crypto_hash_final() failed for ma digest\n" ); +crypto_free_hash (tfm); + goto out; + } +crypto_free_hash (tfm); +/* +* Generate CHAP_N and CHAP_R. +*/ + *NR_out_len =sprintf (NR_out_ptr,"CHAP_N=%s" , auth->userid_mutual); + *NR_out_len +=1 ; +"[server] Sending CHAP_N=%s\n" , auth->userid_mutual); +/* +* Convert response from binary hex to ascii hext. +*/ +chap_binaryhex_to_asciihex (response, digest,MD5_SIGNATURE_SIZE ); + *NR_out_len +=sprintf (NR_out_ptr + *NR_out_len,"CHAP_R=0x%s" , + response); + *NR_out_len +=1 ; +"[server] Sending CHAP_R=0x%s\n" , response); + auth_ret =0 ; +out: +kfree (challenge); +kfree (challenge_binhex); +return auth_ret; +} + +int chap_got_response ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +switch (chap->digest_type) { +case CHAP_DIGEST_MD5 : +if (chap_server_compute_md5 (conn, auth, NR_in_ptr, + NR_out_ptr, NR_out_len) <0 ) +return -1 ; +break ; +default : +printk (KERN_ERR "Unknown CHAP digest type %d!\n" , + chap->digest_type); +return -1 ; + } + +return 0 ; +} + +u32 chap_main_loop ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *in_text, +char *out_text, +int *in_len, +int *out_len) +{ +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +if (!(chap)) { + chap =chap_server_open (conn, auth, in_text, out_text, out_len); +if (!(chap)) +return 2 ; + chap->chap_state =CHAP_STAGE_SERVER_AIC ; +return 0 ; + }else if (chap->chap_state ==CHAP_STAGE_SERVER_AIC ) { +convert_null_to_semi (in_text, *in_len); +if (chap_got_response (conn, auth, in_text, out_text, + out_len) <0 ) { +chap_close (conn); +return 2 ; + } +if (auth->authenticate_target) + chap->chap_state =CHAP_STAGE_SERVER_NR ; +else + *out_len =0 ; +chap_close (conn); +return 1 ; + } + +return 2 ; +}
drivers/target/iscsi/iscsi_target_auth.h new file +33 -0
@@ -0,0 +1,33 @@ +#ifndef _ISCSI_CHAP_H_ +#define _ISCSI_CHAP_H_ + +#define CHAP_DIGEST_MD5 5 +#define CHAP_DIGEST_SHA 6 + +#define CHAP_CHALLENGE_LENGTH 16 +#define CHAP_CHALLENGE_STR_LEN 4096 +#define MAX_RESPONSE_LENGTH 64/* sufficient for MD5 */ +#define MAX_CHAP_N_SIZE 512 + +#define MD5_SIGNATURE_SIZE 16/* 16 bytes in a MD5 message digest */ + +#define CHAP_STAGE_CLIENT_A 1 +#define CHAP_STAGE_SERVER_AIC 2 +#define CHAP_STAGE_CLIENT_NR 3 +#define CHAP_STAGE_CLIENT_NRIC 4 +#define CHAP_STAGE_SERVER_NR 5 + +extern int chap_gen_challenge (struct iscsi_conn *,int ,char *,unsigned int *); +extern u32 chap_main_loop (struct iscsi_conn *,struct iscsi_node_auth *,char *,char *, +int *,int *); + +struct iscsi_chap { +unsigned char digest_type; +unsigned char id; +unsigned char challenge[CHAP_CHALLENGE_LENGTH ]; +unsigned int challenge_len; +unsigned int authenticate_target; +unsigned int chap_state; +}____cacheline_aligned ; + +#endif /*** _ISCSI_CHAP_H_ ***/
Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [RFC-v3 07/12] iscsi-target: Add CHAP Authentication support using libcrypto
Quoted 2 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
Minor nitpicks below.
Quoted 19 lines
This patch adds support for libcrypto md5 based iSCSI CHAP authentication support for
iscsi_target_mod. This includes support for mutual and one-way NodeACL authentication for SessionType=Normal and SessionType=Discovery via/sys/kernel/config/target/iscsi.Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/iscsi/iscsi_target_auth.c | 500 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_auth.h | 33 ++ 2 files changed, 533 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_auth.c create mode 100644 drivers/target/iscsi/iscsi_target_auth.hdrivers/target/iscsi/iscsi_target_auth.c new file +0
-0
drivers/target/iscsi/iscsi_target_auth.c line 4
Quoted 4 lines
drivers/target/iscsi/iscsi_target_auth.c new file +4
-0@@ -0,0 +1,500 @@ +/******************************************************************************* +* This file houses the main functions for the iSCSI CHAP support +* +* ?? Copyright 2007-2011 RisingTide Systems LLC.
"??" ?
drivers/target/iscsi/iscsi_target_auth.c line 67
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+int chap_string_to_hex (unsigned char *dst,unsigned char *src,int len) +{ +int i =0 , j =0 ; + +for (i =0 ; i < len; i +=2 )
Initializing 'i' to zero twice is a little needless.
drivers/target/iscsi/iscsi_target_auth.c line 78
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+void chap_binaryhex_to_asciihex (char *dst,char *src,int src_len) +{ +int i; + +for (i =0 ; i < src_len; i++)
Do we still support compiler versions that don't understand 'for-scope'?
for (int i = 0; ...
drivers/target/iscsi/iscsi_target_auth.c line 88
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+void chap_set_random (char *data,int length) +{ +long r; +unsigned n; + +while (length >0 ) { +
Pointless newline IMHO.
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>4 ); + n = r &0x7 ; + +get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 );
drivers/target/iscsi/iscsi_target_auth.c line 105
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c new file +10
-0+ r = r ^ (r >>5 ); + n = (n <<3 ) | (r &0x7 ); + +get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>5 ); + n = (n <<2 ) | (r &0x3 ); + + *data++ = n; + length--;
Mixing space and tab in indentation here.
Quoted 13 lines
drivers/target/iscsi/iscsi_target_auth.c new file +13
-0+int chap_gen_challenge ( +struct iscsi_conn *conn, +int caller, +char *C_str, +unsigned int *C_len) +{ +unsigned char challenge_asciihex[CHAP_CHALLENGE_LENGTH *2 +1 ]; +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +memset (challenge_asciihex,0 ,CHAP_CHALLENGE_LENGTH *2 +1 ); + +chap_set_random (chap->challenge,CHAP_CHALLENGE_LENGTH ); + chap_binaryhex_to_asciihex(challenge_asciihex, chap->challenge,
drivers/target/iscsi/iscsi_target_auth.c line 191
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c new file +10
-0+ CHAP_CHALLENGE_LENGTH); +/* +* Set CHAP_C, and copy the generated challenge into C_str. +*/ + *C_len +=sprintf (C_str + *C_len,"CHAP_C=0x%s" , challenge_asciihex); + *C_len +=1 ; + +"[%s] Sending CHAP_C=0x%s\n\n" , (caller) ?"server" :"client" , + challenge_asciihex); +return 0 ;
You only ever return '0', so why couldn't this function just return 'void'? - sorry, didn't bother to actually check how its used :-/
drivers/target/iscsi/iscsi_target_auth.c line 204
Quoted 11 lines
drivers/target/iscsi/iscsi_target_auth.c new file +11
-0+int chap_server_compute_md5 ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +char *endptr; +unsigned char id, digest[MD5_SIGNATURE_SIZE ]; +unsigned char type, response[MD5_SIGNATURE_SIZE *2 +2 ]; +unsigned char identifier[10 ], *challenge, *challenge_binhex;
If you changed the above line to
unsigned char identifier[10], *challenge; unsigned char *challenge_binhex = 0;
Quoted 11 lines
drivers/target/iscsi/iscsi_target_auth.c new file +11
-0+unsigned char client_digest[MD5_SIGNATURE_SIZE ]; +unsigned char server_digest[MD5_SIGNATURE_SIZE ]; +unsigned char chap_n[MAX_CHAP_N_SIZE ], chap_r[MAX_RESPONSE_LENGTH ]; +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; +struct crypto_hash *tfm; +struct hash_desc desc; +struct scatterlist sg; +int auth_ret =-1 , ret, challenge_len; + +memset (identifier,0 ,10 ); +memset (chap_n,0 ,MAX_CHAP_N_SIZE );
drivers/target/iscsi/iscsi_target_auth.c line 225
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c new file +10
-0+memset (chap_r,0 ,MAX_RESPONSE_LENGTH ); +memset (digest,0 ,MD5_SIGNATURE_SIZE ); +memset (response,0 ,MD5_SIGNATURE_SIZE *2 +2 ); +memset (client_digest,0 ,MD5_SIGNATURE_SIZE ); +memset (server_digest,0 ,MD5_SIGNATURE_SIZE ); + + challenge =kzalloc (CHAP_CHALLENGE_STR_LEN ,GFP_KERNEL ); +if (!(challenge)) { +printk (KERN_ERR "Unable to allocate challenge buffer\n" ); +return -1 ;
this could become "goto out;"
drivers/target/iscsi/iscsi_target_auth.c line 232
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+ } + + challenge_binhex =kzalloc (CHAP_CHALLENGE_STR_LEN ,GFP_KERNEL ); +if (!(challenge_binhex)) { +printk (KERN_ERR "Unable to allocate challenge_binhex buffer\n" ); +kfree (challenge); +return -1 ;
and here the kfree() call could go away and the return be converted to "goto out;".
kfree(0) is a no-op.
...
drivers/target/iscsi/iscsi_target_auth.c line 331
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+* One way authentication has succeeded, return now if mutual +* authentication is not enabled. +*/ +if (!auth->authenticate_target) { +kfree (challenge); +kfree (challenge_binhex); +return 0 ;
and here the two kfree() calls would also go away and "return 0" would be replaced with
auth_ret = 0; goto out;
...
drivers/target/iscsi/iscsi_target_auth.c line 442
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+out: +kfree (challenge); +kfree (challenge_binhex); +return auth_ret; +}
That would nicely consolidate *all* exits from the function in one place.
Quoted 13 lines
drivers/target/iscsi/iscsi_target_auth.c new file +13
-0+ +int chap_got_response ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +switch (chap->digest_type) { +case CHAP_DIGEST_MD5 : + if (chap_server_compute_md5(conn, auth, NR_in_ptr,
drivers/target/iscsi/iscsi_target_auth.c line 465
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c new file +10
-0+ NR_out_ptr, NR_out_len) < 0) +return -1 ; +break ; +default : +printk (KERN_ERR "Unknown CHAP digest type %d!\n" , + chap->digest_type); +return -1 ; + } + +return 0 ;
You could kill the 'return 0' and replace the 'break' above with 'return 0'. No difference in behaviour, but you'd save a few lines and it would be just as readable IMHO.
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/~esr/jargon/html/T/top-post.html Plain text mails only, please.
Re: [RFC-v3 07/12] iscsi-target: Add CHAP Authentication support using libcrypto
Quoted 8 lines · Jesper Juhl
Quoted 2 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
Minor nitpicks below.
...
Quoted 15 lines
drivers/target/iscsi/iscsi_target_auth.c line 204
Quoted 12 lines
drivers/target/iscsi/iscsi_target_auth.c new file +11
-0+int chap_server_compute_md5 ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +char *endptr; +unsigned char id, digest[MD5_SIGNATURE_SIZE ]; +unsigned char type, response[MD5_SIGNATURE_SIZE *2 +2 ]; +unsigned char identifier[10 ], *challenge, *challenge_binhex;If you changed the above line to
Quoted 3 lines
unsigned char identifier[10], *challenge; unsigned char *challenge_binhex = 0;
Actually, to be pedantic, that should probably be
unsigned char *challenge_binhex = NULL;
Signature · 3 lines
Jesper Juhl <[email protected]> http://www.chaosbits.net/ Don't top-post http://www.catb.org/jargon/html/T/top-post.html Plain text mails only, please.
Re: [RFC-v3 07/12] iscsi-target: Add CHAP Authentication support using libcrypto
In reply to Jesper JuhlQuoted 35 lines · Jesper Juhl
Quoted 2 lines · Nicholas A. Bellinger
From: Nicholas Bellinger <[email protected]>
Minor nitpicks below.
Quoted 19 lines
This patch adds support for libcrypto md5 based iSCSI CHAP authentication support for
iscsi_target_mod. This includes support for mutual and one-way NodeACL authentication for SessionType=Normal and SessionType=Discovery via/sys/kernel/config/target/iscsi.Signed-off-by Nicholas A. Bellinger <[email protected]>--- drivers/target/iscsi/iscsi_target_auth.c | 500 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_auth.h | 33 ++ 2 files changed, 533 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_auth.c create mode 100644 drivers/target/iscsi/iscsi_target_auth.hdrivers/target/iscsi/iscsi_target_auth.c new file +0
-0drivers/target/iscsi/iscsi_target_auth.c line 4
Quoted 4 lines
drivers/target/iscsi/iscsi_target_auth.c new file +4
-0@@ -0,0 +1,500 @@ +/******************************************************************************* +* This file houses the main functions for the iSCSI CHAP support +* +* ?? Copyright 2007-2011 RisingTide Systems LLC. "??" ?
Quoted 9 lines
drivers/target/iscsi/iscsi_target_auth.c line 67
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+int chap_string_to_hex (unsigned char *dst,unsigned char *src,int len) +{ +int i =0 , j =0 ; + +for (i =0 ; i < len; i +=2 )Initializing 'i' to zero twice is a little needless.
Fixed
Quoted 11 lines
drivers/target/iscsi/iscsi_target_auth.c line 78
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+void chap_binaryhex_to_asciihex (char *dst,char *src,int src_len) +{ +int i; + +for (i =0 ; i < src_len; i++)Do we still support compiler versions that don't understand 'for-scope'?
for (int i = 0; ...
Mmmm, not sure. Adding far (...) {} usage here to be safe
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c line 88
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+void chap_set_random (char *data,int length) +{ +long r; +unsigned n; + +while (length >0 ) { +Pointless newline IMHO.
Removed
Quoted 11 lines
Quoted 11 lines
drivers/target/iscsi/iscsi_target_auth.c new file +11
-0+get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>4 ); + n = r &0x7 ; + +get_random_bytes (&r,sizeof (long )); + r = r ^ (r >>8 ); + r = r ^ (r >>5 ); + n = (n <<3 ) | (r &0x7 ); + +get_random_bytes (&r,sizeof (long ));
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c line 105
Quoted 6 lines
drivers/target/iscsi/iscsi_target_auth.c new file +6
-0+ r = r ^ (r >>8 ); + r = r ^ (r >>5 ); + n = (n <<2 ) | (r &0x3 ); + + *data++ = n; + length--;Mixing space and tab in indentation here.
Fixing up now..
Quoted 18 lines
Quoted 18 lines
drivers/target/iscsi/iscsi_target_auth.c new file +18
-0+int chap_gen_challenge ( +struct iscsi_conn *conn, +int caller, +char *C_str, +unsigned int *C_len) +{ +unsigned char challenge_asciihex[CHAP_CHALLENGE_LENGTH *2 +1 ]; +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +memset (challenge_asciihex,0 ,CHAP_CHALLENGE_LENGTH *2 +1 ); + +chap_set_random (chap->challenge,CHAP_CHALLENGE_LENGTH ); +chap_binaryhex_to_asciihex (challenge_asciihex, chap->challenge, +CHAP_CHALLENGE_LENGTH ); +/* +* Set CHAP_C, and copy the generated challenge into C_str. +*/ + *C_len +=sprintf (C_str + *C_len,"CHAP_C=0x%s" , challenge_asciihex);
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c line 191
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+ *C_len +=1 ; + +"[%s] Sending CHAP_C=0x%s\n\n" , (caller) ?"server" :"client" , + challenge_asciihex); +return 0 ;You only ever return '0', so why couldn't this function just return 'void'? - sorry, didn't bother to actually check how its used :-/
Making this function return void and declaring static as well..
Quoted 32 lines
drivers/target/iscsi/iscsi_target_auth.c line 204
Quoted 11 lines
drivers/target/iscsi/iscsi_target_auth.c new file +11
-0+int chap_server_compute_md5 ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +char *endptr; +unsigned char id, digest[MD5_SIGNATURE_SIZE ]; +unsigned char type, response[MD5_SIGNATURE_SIZE *2 +2 ]; +unsigned char identifier[10 ], *challenge, *challenge_binhex;If you changed the above line to
unsigned char identifier[10], *challenge; unsigned char *challenge_binhex = 0;Quoted 15 lines
drivers/target/iscsi/iscsi_target_auth.c new file +15
-0+unsigned char client_digest[MD5_SIGNATURE_SIZE ]; +unsigned char server_digest[MD5_SIGNATURE_SIZE ]; +unsigned char chap_n[MAX_CHAP_N_SIZE ], chap_r[MAX_RESPONSE_LENGTH ]; +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; +struct crypto_hash *tfm; +struct hash_desc desc; +struct scatterlist sg; +int auth_ret =-1 , ret, challenge_len; + +memset (identifier,0 ,10 ); +memset (chap_n,0 ,MAX_CHAP_N_SIZE ); +memset (chap_r,0 ,MAX_RESPONSE_LENGTH ); +memset (digest,0 ,MD5_SIGNATURE_SIZE ); +memset (response,0 ,MD5_SIGNATURE_SIZE *2 +2 ); +memset (client_digest,0 ,MD5_SIGNATURE_SIZE );
Quoted 9 lines
drivers/target/iscsi/iscsi_target_auth.c line 225
Quoted 6 lines
drivers/target/iscsi/iscsi_target_auth.c new file +6
-0+memset (server_digest,0 ,MD5_SIGNATURE_SIZE ); + + challenge =kzalloc (CHAP_CHALLENGE_STR_LEN ,GFP_KERNEL ); +if (!(challenge)) { +printk (KERN_ERR "Unable to allocate challenge buffer\n" ); +return -1 ;this could become "goto out;"
Fixed
Quoted 12 lines
drivers/target/iscsi/iscsi_target_auth.c line 232
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+ } + + challenge_binhex =kzalloc (CHAP_CHALLENGE_STR_LEN ,GFP_KERNEL ); +if (!(challenge_binhex)) { +printk (KERN_ERR "Unable to allocate challenge_binhex buffer\n" ); +kfree (challenge); +return -1 ;and here the
kfree()call could go away and the return be converted to "goto out;".
kfree(0) is a no-op.
Fixed.
Quoted 16 lines
...
drivers/target/iscsi/iscsi_target_auth.c line 331
Quoted 7 lines
drivers/target/iscsi/iscsi_target_auth.c new file +7
-0+* One way authentication has succeeded, return now if mutual +* authentication is not enabled. +*/ +if (!auth->authenticate_target) { +kfree (challenge); +kfree (challenge_binhex); +return 0 ;and here the two
kfree()calls would also go away and "return 0" would be replaced withauth_ret = 0; goto out;...
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c line 442
Quoted 5 lines
drivers/target/iscsi/iscsi_target_auth.c new file +5
-0+out: +kfree (challenge); +kfree (challenge_binhex); +return auth_ret; +}That would nicely consolidate *all* exits from the function in one place.
Done.
Quoted 20 lines
Quoted 20 lines
drivers/target/iscsi/iscsi_target_auth.c new file +19
-0+ +int chap_got_response ( +struct iscsi_conn *conn, +struct iscsi_node_auth *auth, +char *NR_in_ptr, +char *NR_out_ptr, +unsigned int *NR_out_len) +{ +struct iscsi_chap *chap = (struct iscsi_chap *) conn->auth_protocol; + +switch (chap->digest_type) { +case CHAP_DIGEST_MD5 : +if (chap_server_compute_md5 (conn, auth, NR_in_ptr, + NR_out_ptr, NR_out_len) <0 ) +return -1 ; +break ; +default : +printk (KERN_ERR "Unknown CHAP digest type %d!\n" , + chap->digest_type);
Quoted 10 lines
drivers/target/iscsi/iscsi_target_auth.c line 465
Quoted 4 lines
drivers/target/iscsi/iscsi_target_auth.c new file +4
-0+return -1 ; + } + +return 0 ;You could kill the 'return 0' and replace the 'break' above with 'return 0'. No difference in behaviour, but you'd save a few lines and it would be just as readable IMHO.
Fixed.
Also fixing a handful of 'if (!(foo))' usage and made everything aside from chap_main_loop() defined as static.
Thanks Jesper!
--nab
RFC v3 8/12 iscsi-target: Add Sequence/PDU list + DataIN response logic
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds Sequence/PDU list logic used by RFC-3720 for DataSequenceInOrder=[Yes,No] and DataPDUInOrder=[Yes,No]. It also includes support for these modes of support for generating iSCSI DataIN response data from iscsi_target.c:iscsi_send_data_in().
--- drivers/target/iscsi/iscsi_target_datain_values.c | 539 ++++++++++++++++ drivers/target/iscsi/iscsi_target_datain_values.h | 15 + drivers/target/iscsi/iscsi_target_seq_pdu_list.c | 710 +++++++++++++++++++++ drivers/target/iscsi/iscsi_target_seq_pdu_list.h | 88 +++ 4 files changed, 1352 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_datain_values.c create mode 100644 drivers/target/iscsi/iscsi_target_datain_values.h create mode 100644 drivers/target/iscsi/iscsi_target_seq_pdu_list.c create mode 100644 drivers/target/iscsi/iscsi_target_seq_pdu_list.h
drivers/target/iscsi/iscsi_target_datain_values.c new file +539 -0
@@ -0,0 +1,539 @@ +/******************************************************************************* +* This file contains the iSCSI Target DataIN value generation functions. +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <scsi/iscsi_proto.h> + +#include "iscsi_target_debug.h" +#include "iscsi_target_core.h" +#include "iscsi_target_seq_pdu_list.h" +#include "iscsi_target_erl1.h" +#include "iscsi_target_util.h" +#include "iscsi_target_datain_values.h" + +struct iscsi_datain_req *iscsi_allocate_datain_req (void ) +{ +struct iscsi_datain_req *dr; + + dr =kmem_cache_zalloc (lio_dr_cache,GFP_ATOMIC ); +if (!dr) { +printk (KERN_ERR "Unable to allocate memory for" +" struct iscsi_datain_req\n" ); +return NULL ; + } +INIT_LIST_HEAD (&dr->dr_list); + +return dr; +} + +void iscsi_attach_datain_req (struct iscsi_cmd *cmd,struct iscsi_datain_req *dr) +{ +spin_lock (&cmd->datain_lock); +list_add_tail (&dr->dr_list, &cmd->datain_list); +spin_unlock (&cmd->datain_lock); +} + +void iscsi_free_datain_req (struct iscsi_cmd *cmd,struct iscsi_datain_req *dr) +{ +spin_lock (&cmd->datain_lock); +list_del (&dr->dr_list); +spin_unlock (&cmd->datain_lock); + +kmem_cache_free (lio_dr_cache, dr); +} + +void iscsi_free_all_datain_reqs (struct iscsi_cmd *cmd) +{ +struct iscsi_datain_req *dr, *dr_tmp; + +spin_lock (&cmd->datain_lock); +list_for_each_entry_safe (dr, dr_tmp, &cmd->datain_list, dr_list) { +list_del (&dr->dr_list); +kmem_cache_free (lio_dr_cache, dr); + } +spin_unlock (&cmd->datain_lock); +} + +struct iscsi_datain_req *iscsi_get_datain_req (struct iscsi_cmd *cmd) +{ +struct iscsi_datain_req *dr; + +if (list_empty (&cmd->datain_list)) { +printk (KERN_ERR "cmd->datain_list is empty for ITT:" +" 0x%08x\n" , cmd->init_task_tag); +return NULL ; + } +list_for_each_entry (dr, &cmd->datain_list, dr_list) +break ; + +return dr; +} + +/* iscsi_set_datain_values_yes_and_yes(): +* +* For Normal and Recovery DataSequenceInOrder=Yes and DataPDUInOrder=Yes. +*/ +static inline struct iscsi_datain_req *iscsi_set_datain_values_yes_and_yes ( +struct iscsi_cmd *cmd, +struct iscsi_datain *datain) +{ +u32 next_burst_len, read_data_done, read_data_left; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_datain_req *dr; + + dr =iscsi_get_datain_req (cmd); +if (!dr) +return NULL ; + +if (dr->recovery && dr->generate_recovery_values) { +if (iscsi_create_recovery_datain_values_datasequenceinorder_yes ( + cmd, dr) <0 ) +return NULL ; + + dr->generate_recovery_values =0 ; + } + + next_burst_len = (!dr->recovery) ? + cmd->next_burst_len : dr->next_burst_len; + read_data_done = (!dr->recovery) ? + cmd->read_data_done : dr->read_data_done; + + read_data_left = (cmd->data_length - read_data_done); +if (!read_data_left) { +printk (KERN_ERR "ITT: 0x%08x read_data_left is zero!\n" , + cmd->init_task_tag); +return NULL ; + } + +if ((read_data_left <= conn->conn_ops->MaxRecvDataSegmentLength) && + (read_data_left <= (conn->sess->sess_ops->MaxBurstLength - + next_burst_len))) { + datain->length = read_data_left; + + datain->flags |= (ISCSI_FLAG_CMD_FINAL |ISCSI_FLAG_DATA_STATUS ); +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + datain->flags |=ISCSI_FLAG_DATA_ACK ; + }else { +if ((next_burst_len + + conn->conn_ops->MaxRecvDataSegmentLength) < + conn->sess->sess_ops->MaxBurstLength) { + datain->length = + conn->conn_ops->MaxRecvDataSegmentLength; + next_burst_len += datain->length; + }else { + datain->length = (conn->sess->sess_ops->MaxBurstLength - + next_burst_len); + next_burst_len =0 ; + + datain->flags |=ISCSI_FLAG_CMD_FINAL ; +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + datain->flags |=ISCSI_FLAG_DATA_ACK ; + } + } + + datain->data_sn = (!dr->recovery) ? cmd->data_sn++ : dr->data_sn++; + datain->offset = read_data_done; + +if (!dr->recovery) { + cmd->next_burst_len = next_burst_len; + cmd->read_data_done += datain->length; + }else { + dr->next_burst_len = next_burst_len; + dr->read_data_done += datain->length; + } + +if (!dr->recovery) { +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) + dr->dr_complete =DATAIN_COMPLETE_NORMAL ; + +return dr; + } + +if (!dr->runlength) { +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + }else { +if ((dr->begrun + dr->runlength) == dr->data_sn) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + } + +return dr; +} + +/* iscsi_set_datain_values_no_and_yes(): +* +* For Normal and Recovery DataSequenceInOrder=No and DataPDUInOrder=Yes. +*/ +static inline struct iscsi_datain_req *iscsi_set_datain_values_no_and_yes ( +struct iscsi_cmd *cmd, +struct iscsi_datain *datain) +{ +u32 offset, read_data_done, read_data_left, seq_send_order; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_datain_req *dr; +struct iscsi_seq *seq; + + dr =iscsi_get_datain_req (cmd); +if (!dr) +return NULL ; + +if (dr->recovery && dr->generate_recovery_values) { +if (iscsi_create_recovery_datain_values_datasequenceinorder_no ( + cmd, dr) <0 ) +return NULL ; + + dr->generate_recovery_values =0 ; + } + + read_data_done = (!dr->recovery) ? + cmd->read_data_done : dr->read_data_done; + seq_send_order = (!dr->recovery) ? + cmd->seq_send_order : dr->seq_send_order; + + read_data_left = (cmd->data_length - read_data_done); +if (!read_data_left) { +printk (KERN_ERR "ITT: 0x%08x read_data_left is zero!\n" , + cmd->init_task_tag); +return NULL ; + } + + seq =iscsi_get_seq_holder_for_datain (cmd, seq_send_order); +if (!seq) +return NULL ; + + seq->sent =1 ; + +if (!dr->recovery && !seq->next_burst_len) + seq->first_datasn = cmd->data_sn; + + offset = (seq->offset + seq->next_burst_len); + +if ((offset + conn->conn_ops->MaxRecvDataSegmentLength) >= + cmd->data_length) { + datain->length = (cmd->data_length - offset); + datain->offset = offset; + + datain->flags |=ISCSI_FLAG_CMD_FINAL ; +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + datain->flags |=ISCSI_FLAG_DATA_ACK ; + + seq->next_burst_len =0 ; + seq_send_order++; + }else { +if ((seq->next_burst_len + + conn->conn_ops->MaxRecvDataSegmentLength) < + conn->sess->sess_ops->MaxBurstLength) { + datain->length = + conn->conn_ops->MaxRecvDataSegmentLength; + datain->offset = (seq->offset + seq->next_burst_len); + + seq->next_burst_len += datain->length; + }else { + datain->length = (conn->sess->sess_ops->MaxBurstLength - + seq->next_burst_len); + datain->offset = (seq->offset + seq->next_burst_len); + + datain->flags |=ISCSI_FLAG_CMD_FINAL ; +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + datain->flags |=ISCSI_FLAG_DATA_ACK ; + + seq->next_burst_len =0 ; + seq_send_order++; + } + } + +if ((read_data_done + datain->length) == cmd->data_length) + datain->flags |=ISCSI_FLAG_DATA_STATUS ; + + datain->data_sn = (!dr->recovery) ? cmd->data_sn++ : dr->data_sn++; +if (!dr->recovery) { + cmd->seq_send_order = seq_send_order; + cmd->read_data_done += datain->length; + }else { + dr->seq_send_order = seq_send_order; + dr->read_data_done += datain->length; + } + +if (!dr->recovery) { +if (datain->flags &ISCSI_FLAG_CMD_FINAL ) + seq->last_datasn = datain->data_sn; +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) + dr->dr_complete =DATAIN_COMPLETE_NORMAL ; + +return dr; + } + +if (!dr->runlength) { +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + }else { +if ((dr->begrun + dr->runlength) == dr->data_sn) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + } + +return dr; +} + +/* iscsi_set_datain_values_yes_and_no(): +* +* For Normal and Recovery DataSequenceInOrder=Yes and DataPDUInOrder=No. +*/ +static inline struct iscsi_datain_req *iscsi_set_datain_values_yes_and_no ( +struct iscsi_cmd *cmd, +struct iscsi_datain *datain) +{ +u32 next_burst_len, read_data_done, read_data_left; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_datain_req *dr; +struct iscsi_pdu *pdu; + + dr =iscsi_get_datain_req (cmd); +if (!dr) +return NULL ; + +if (dr->recovery && dr->generate_recovery_values) { +if (iscsi_create_recovery_datain_values_datasequenceinorder_yes ( + cmd, dr) <0 ) +return NULL ; + + dr->generate_recovery_values =0 ; + } + + next_burst_len = (!dr->recovery) ? + cmd->next_burst_len : dr->next_burst_len; + read_data_done = (!dr->recovery) ? + cmd->read_data_done : dr->read_data_done; + + read_data_left = (cmd->data_length - read_data_done); +if (!read_data_left) { +printk (KERN_ERR "ITT: 0x%08x read_data_left is zero!\n" , + cmd->init_task_tag); +return dr; + } + + pdu =iscsi_get_pdu_holder_for_seq (cmd,NULL ); +if (!pdu) +return dr; + +if ((read_data_done + pdu->length) == cmd->data_length) { + pdu->flags |= (ISCSI_FLAG_CMD_FINAL |ISCSI_FLAG_DATA_STATUS ); +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + pdu->flags |=ISCSI_FLAG_DATA_ACK ; + + next_burst_len =0 ; + }else { +if ((next_burst_len + conn->conn_ops->MaxRecvDataSegmentLength) < + conn->sess->sess_ops->MaxBurstLength) + next_burst_len += pdu->length; +else { + pdu->flags |=ISCSI_FLAG_CMD_FINAL ; +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + pdu->flags |=ISCSI_FLAG_DATA_ACK ; + + next_burst_len =0 ; + } + } + + pdu->data_sn = (!dr->recovery) ? cmd->data_sn++ : dr->data_sn++; +if (!dr->recovery) { + cmd->next_burst_len = next_burst_len; + cmd->read_data_done += pdu->length; + }else { + dr->next_burst_len = next_burst_len; + dr->read_data_done += pdu->length; + } + + datain->flags = pdu->flags; + datain->length = pdu->length; + datain->offset = pdu->offset; + datain->data_sn = pdu->data_sn; + +if (!dr->recovery) { +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) + dr->dr_complete =DATAIN_COMPLETE_NORMAL ; + +return dr; + } + +if (!dr->runlength) { +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + }else { +if ((dr->begrun + dr->runlength) == dr->data_sn) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + } + +return dr; +} + +/* iscsi_set_datain_values_no_and_no(): +* +* For Normal and Recovery DataSequenceInOrder=No and DataPDUInOrder=No. +*/ +static inline struct iscsi_datain_req *iscsi_set_datain_values_no_and_no ( +struct iscsi_cmd *cmd, +struct iscsi_datain *datain) +{ +u32 read_data_done, read_data_left, seq_send_order; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_datain_req *dr; +struct iscsi_pdu *pdu; +struct iscsi_seq *seq =NULL ; + + dr =iscsi_get_datain_req (cmd); +if (!dr) +return NULL ; + +if (dr->recovery && dr->generate_recovery_values) { +if (iscsi_create_recovery_datain_values_datasequenceinorder_no ( + cmd, dr) <0 ) +return NULL ; + + dr->generate_recovery_values =0 ; + } + + read_data_done = (!dr->recovery) ? + cmd->read_data_done : dr->read_data_done; + seq_send_order = (!dr->recovery) ? + cmd->seq_send_order : dr->seq_send_order; + + read_data_left = (cmd->data_length - read_data_done); +if (!read_data_left) { +printk (KERN_ERR "ITT: 0x%08x read_data_left is zero!\n" , + cmd->init_task_tag); +return NULL ; + } + + seq =iscsi_get_seq_holder_for_datain (cmd, seq_send_order); +if (!seq) +return NULL ; + + seq->sent =1 ; + +if (!dr->recovery && !seq->next_burst_len) + seq->first_datasn = cmd->data_sn; + + pdu =iscsi_get_pdu_holder_for_seq (cmd, seq); +if (!pdu) +return NULL ; + +if (seq->pdu_send_order == seq->pdu_count) { + pdu->flags |=ISCSI_FLAG_CMD_FINAL ; +if (conn->sess->sess_ops->ErrorRecoveryLevel >0 ) + pdu->flags |=ISCSI_FLAG_DATA_ACK ; + + seq->next_burst_len =0 ; + seq_send_order++; + }else + seq->next_burst_len += pdu->length; + +if ((read_data_done + pdu->length) == cmd->data_length) + pdu->flags |=ISCSI_FLAG_DATA_STATUS ; + + pdu->data_sn = (!dr->recovery) ? cmd->data_sn++ : dr->data_sn++; +if (!dr->recovery) { + cmd->seq_send_order = seq_send_order; + cmd->read_data_done += pdu->length; + }else { + dr->seq_send_order = seq_send_order; + dr->read_data_done += pdu->length; + } + + datain->flags = pdu->flags; + datain->length = pdu->length; + datain->offset = pdu->offset; + datain->data_sn = pdu->data_sn; + +if (!dr->recovery) { +if (datain->flags &ISCSI_FLAG_CMD_FINAL ) + seq->last_datasn = datain->data_sn; +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) + dr->dr_complete =DATAIN_COMPLETE_NORMAL ; + +return dr; + } + +if (!dr->runlength) { +if (datain->flags &ISCSI_FLAG_DATA_STATUS ) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + }else { +if ((dr->begrun + dr->runlength) == dr->data_sn) { + dr->dr_complete = + (dr->recovery ==DATAIN_WITHIN_COMMAND_RECOVERY ) ? +DATAIN_COMPLETE_WITHIN_COMMAND_RECOVERY : +DATAIN_COMPLETE_CONNECTION_RECOVERY ; + } + } + +return dr; +} + +/* iscsi_get_datain_values(): +* +* +*/ +struct iscsi_datain_req *iscsi_get_datain_values ( +struct iscsi_cmd *cmd, +struct iscsi_datain *datain) +{ +struct iscsi_conn *conn = cmd->conn; + +if (conn->sess->sess_ops->DataSequenceInOrder && + conn->sess->sess_ops->DataPDUInOrder) +return iscsi_set_datain_values_yes_and_yes (cmd, datain); +else if (!conn->sess->sess_ops->DataSequenceInOrder && + conn->sess->sess_ops->DataPDUInOrder) +return iscsi_set_datain_values_no_and_yes (cmd, datain); +else if (conn->sess->sess_ops->DataSequenceInOrder && + !conn->sess->sess_ops->DataPDUInOrder) +return iscsi_set_datain_values_yes_and_no (cmd, datain); +else if (!conn->sess->sess_ops->DataSequenceInOrder && + !conn->sess->sess_ops->DataPDUInOrder) +return iscsi_set_datain_values_no_and_no (cmd, datain); + +return NULL ; +}
drivers/target/iscsi/iscsi_target_datain_values.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef ISCSI_TARGET_DATAIN_VALUES_H +#define ISCSI_TARGET_DATAIN_VALUES_H + +extern struct iscsi_datain_req *iscsi_allocate_datain_req (void ); +extern void iscsi_attach_datain_req (struct iscsi_cmd *,struct iscsi_datain_req *); +extern void iscsi_free_datain_req (struct iscsi_cmd *,struct iscsi_datain_req *); +extern void iscsi_free_all_datain_reqs (struct iscsi_cmd *); +extern struct iscsi_datain_req *iscsi_get_datain_req (struct iscsi_cmd *); +extern struct iscsi_datain_req *iscsi_get_datain_values (struct iscsi_cmd *, +struct iscsi_datain *); + +extern struct iscsi_global *iscsi_global; +extern struct kmem_cache *lio_dr_cache; + +#endif /*** ISCSI_TARGET_DATAIN_VALUES_H ***/
drivers/target/iscsi/iscsi_target_seq_pdu_list.c new file +710 -0
710 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_seq_pdu_list.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.7.4.1
RFC v3 9/12 iscsi-target: Add iSCSI Error Recovery Hierarchy support
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds support for RFC-3720 compatiable ErrorRecoveryLevel support as defined in Section 6.1.5. Error Recovery Hierarchy.
This includes support for iSCSI session reinstatement, iSCSI within command and within connection recovery, and explict/implict connection recovery (CSM-E and CSM-I) from state machines in Section 7 of RFC-3720.
These functions are called from iscsi_target.c to handle processing based on the negotiated session-wide ErrorRecoveryLevel parameter.
--- drivers/target/iscsi/iscsi_target_erl0.c | 1080 +++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_erl0.h | 19 + drivers/target/iscsi/iscsi_target_erl1.c | 1378 ++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_erl1.h | 35 + drivers/target/iscsi/iscsi_target_erl2.c | 529 ++++++++++++ drivers/target/iscsi/iscsi_target_erl2.h | 20 + 6 files changed, 3061 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_erl0.c create mode 100644 drivers/target/iscsi/iscsi_target_erl0.h create mode 100644 drivers/target/iscsi/iscsi_target_erl1.c create mode 100644 drivers/target/iscsi/iscsi_target_erl1.h create mode 100644 drivers/target/iscsi/iscsi_target_erl2.c create mode 100644 drivers/target/iscsi/iscsi_target_erl2.h
drivers/target/iscsi/iscsi_target_erl0.c new file +1080 -0
@@ -0,0 +1,1080 @@ +/****************************************************************************** +* This file contains error recovery level zero functions used by +* the iSCSI Target driver. +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <scsi/iscsi_proto.h> +#include <target/target_core_base.h> +#include <target/target_core_transport.h> + +#include "iscsi_target_debug.h" +#include "iscsi_target_core.h" +#include "iscsi_target_seq_pdu_list.h" +#include "iscsi_target_tq.h" +#include "iscsi_target_erl0.h" +#include "iscsi_target_erl1.h" +#include "iscsi_target_erl2.h" +#include "iscsi_target_util.h" +#include "iscsi_target.h" + +/* iscsi_set_dataout_sequence_values(): +* +* Used to set values in struct iscsi_cmd that iscsi_dataout_check_sequence() +* checks against to determine a PDU's Offset+Length is within the current +* DataOUT Sequence. Used for DataSequenceInOrder=Yes only. +*/ +void iscsi_set_dataout_sequence_values ( +struct iscsi_cmd *cmd) +{ +struct iscsi_conn *conn = cmd->conn; +/* +* Still set seq_start_offset and seq_end_offset for Unsolicited +* DataOUT, even if DataSequenceInOrder=No. +*/ +if (cmd->unsolicited_data) { + cmd->seq_start_offset = cmd->write_data_done; + cmd->seq_end_offset = (cmd->write_data_done + + (cmd->data_length > + conn->sess->sess_ops->FirstBurstLength) ? + conn->sess->sess_ops->FirstBurstLength : cmd->data_length); +return ; + } + +if (!conn->sess->sess_ops->DataSequenceInOrder) +return ; + +if (!cmd->seq_start_offset && !cmd->seq_end_offset) { + cmd->seq_start_offset = cmd->write_data_done; + cmd->seq_end_offset = (cmd->data_length > + conn->sess->sess_ops->MaxBurstLength) ? + (cmd->write_data_done + + conn->sess->sess_ops->MaxBurstLength) : cmd->data_length; + }else { + cmd->seq_start_offset = cmd->seq_end_offset; + cmd->seq_end_offset = ((cmd->seq_end_offset + + conn->sess->sess_ops->MaxBurstLength) >= + cmd->data_length) ? cmd->data_length : + (cmd->seq_end_offset + + conn->sess->sess_ops->MaxBurstLength); + } +} + +/* iscsi_dataout_within_command_recovery_check(): +* +* +*/ +static inline int iscsi_dataout_within_command_recovery_check ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +struct iscsi_conn *conn = cmd->conn; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + +/* +* We do the within-command recovery checks here as it is +* the first function called in iscsi_check_pre_dataout(). +* Basically, if we are in within-command recovery and +* the PDU does not contain the offset the sequence needs, +* dump the payload. +* +* This only applies to DataPDUInOrder=Yes, for +* DataPDUInOrder=No we only re-request the failed PDU +* and check that all PDUs in a sequence are received +* upon end of sequence. +*/ +if (conn->sess->sess_ops->DataSequenceInOrder) { +if ((cmd->cmd_flags &ICF_WITHIN_COMMAND_RECOVERY ) && + (cmd->write_data_done != hdr->offset)) + goto dump; + + cmd->cmd_flags &= ~ICF_WITHIN_COMMAND_RECOVERY ; + }else { +struct iscsi_seq *seq; + + seq =iscsi_get_seq_holder (cmd, hdr->offset, payload_length); +if (!seq) +return DATAOUT_CANNOT_RECOVER ; +/* +* Set the struct iscsi_seq pointer to reuse later. +*/ + cmd->seq_ptr = seq; + +if (conn->sess->sess_ops->DataPDUInOrder) { +if ((seq->status == +DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY ) && + ((seq->offset != hdr->offset) || + (seq->data_sn != hdr->datasn))) + goto dump; + }else { +if ((seq->status == +DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY ) && + (seq->data_sn != hdr->datasn)) + goto dump; + } + +if (seq->status ==DATAOUT_SEQUENCE_COMPLETE ) + goto dump; + +if (seq->status !=DATAOUT_SEQUENCE_COMPLETE ) + seq->status =0 ; + } + +return DATAOUT_NORMAL ; + +dump: +printk (KERN_ERR "Dumping DataOUT PDU Offset: %u Length: %d DataSN:" +" 0x%08x\n" , hdr->offset, payload_length, hdr->datasn); +return iscsi_dump_data_payload (conn, payload_length,1 ); +} + +/* iscsi_dataout_check_unsolicited_sequence(): +* +* +*/ +static inline int iscsi_dataout_check_unsolicited_sequence ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +u32 first_burst_len; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + + +if ((hdr->offset < cmd->seq_start_offset) || + ((hdr->offset + payload_length) > cmd->seq_end_offset)) { +printk (KERN_ERR "Command ITT: 0x%08x with Offset: %u," +" Length: %u outside of Unsolicited Sequence %u:%u while" +" DataSequenceInOrder=Yes.\n" , cmd->init_task_tag, + hdr->offset, payload_length, cmd->seq_start_offset, + cmd->seq_end_offset); +return DATAOUT_CANNOT_RECOVER ; + } + + first_burst_len = (cmd->first_burst_len + payload_length); + +if (first_burst_len > conn->sess->sess_ops->FirstBurstLength) { +printk (KERN_ERR "Total %u bytes exceeds FirstBurstLength: %u" +" for this Unsolicited DataOut Burst.\n" , + first_burst_len, conn->sess->sess_ops->FirstBurstLength); +transport_send_check_condition_and_sense (SE_CMD (cmd), +TCM_INCORRECT_AMOUNT_OF_DATA ,0 ); +return DATAOUT_CANNOT_RECOVER ; + } + +/* +* Perform various MaxBurstLength and ISCSI_FLAG_CMD_FINAL sanity +* checks for the current Unsolicited DataOUT Sequence. +*/ +if (hdr->flags &ISCSI_FLAG_CMD_FINAL ) { +/* +* Ignore ISCSI_FLAG_CMD_FINAL checks while DataPDUInOrder=No, end of +* sequence checks are handled in +* iscsi_dataout_datapduinorder_no_fbit(). +*/ +if (!conn->sess->sess_ops->DataPDUInOrder) + goto out; + +if ((first_burst_len != cmd->data_length) && + (first_burst_len != conn->sess->sess_ops->FirstBurstLength)) { +printk (KERN_ERR "Unsolicited non-immediate data" +" received %u does not equal FirstBurstLength: %u, and" +" does not equal ExpXferLen %u.\n" , first_burst_len, + conn->sess->sess_ops->FirstBurstLength, + cmd->data_length); +transport_send_check_condition_and_sense (SE_CMD (cmd), +TCM_INCORRECT_AMOUNT_OF_DATA ,0 ); +return DATAOUT_CANNOT_RECOVER ; + } + }else { +if (first_burst_len == conn->sess->sess_ops->FirstBurstLength) { +printk (KERN_ERR "Command ITT: 0x%08x reached" +" FirstBurstLength: %u, but ISCSI_FLAG_CMD_FINAL is not set. protocol" +" error.\n" , cmd->init_task_tag, + conn->sess->sess_ops->FirstBurstLength); +return DATAOUT_CANNOT_RECOVER ; + } +if (first_burst_len == cmd->data_length) { +printk (KERN_ERR "Command ITT: 0x%08x reached" +" ExpXferLen: %u, but ISCSI_FLAG_CMD_FINAL is not set. protocol" +" error.\n" , cmd->init_task_tag, cmd->data_length); +return DATAOUT_CANNOT_RECOVER ; + } + } + +out: +return DATAOUT_NORMAL ; +} + +/* iscsi_dataout_check_sequence(): +* +* +*/ +static inline int iscsi_dataout_check_sequence ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +u32 next_burst_len; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_seq *seq =NULL ; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + +/* +* For DataSequenceInOrder=Yes: Check that the offset and offset+length +* is within range as defined by iscsi_set_dataout_sequence_values(). +* +* For DataSequenceInOrder=No: Check that an struct iscsi_seq exists for +* offset+length tuple. +*/ +if (conn->sess->sess_ops->DataSequenceInOrder) { +/* +* Due to possibility of recovery DataOUT sent by the initiator +* fullfilling an Recovery R2T, it's best to just dump the +* payload here, instead of erroring out. +*/ +if ((hdr->offset < cmd->seq_start_offset) || + ((hdr->offset + payload_length) > cmd->seq_end_offset)) { +printk (KERN_ERR "Command ITT: 0x%08x with Offset: %u," +" Length: %u outside of Sequence %u:%u while" +" DataSequenceInOrder=Yes.\n" , cmd->init_task_tag, + hdr->offset, payload_length, cmd->seq_start_offset, + cmd->seq_end_offset); + +if (iscsi_dump_data_payload (conn, payload_length,1 ) <0 ) +return DATAOUT_CANNOT_RECOVER ; +return DATAOUT_WITHIN_COMMAND_RECOVERY ; + } + + next_burst_len = (cmd->next_burst_len + payload_length); + }else { + seq =iscsi_get_seq_holder (cmd, hdr->offset, payload_length); +if (!seq) +return DATAOUT_CANNOT_RECOVER ; +/* +* Set the struct iscsi_seq pointer to reuse later. +*/ + cmd->seq_ptr = seq; + +if (seq->status ==DATAOUT_SEQUENCE_COMPLETE ) { +if (iscsi_dump_data_payload (conn, payload_length,1 ) <0 ) +return DATAOUT_CANNOT_RECOVER ; +return DATAOUT_WITHIN_COMMAND_RECOVERY ; + } + + next_burst_len = (seq->next_burst_len + payload_length); + } + +if (next_burst_len > conn->sess->sess_ops->MaxBurstLength) { +printk (KERN_ERR "Command ITT: 0x%08x, NextBurstLength: %u and" +" Length: %u exceeds MaxBurstLength: %u. protocol" +" error.\n" , cmd->init_task_tag, + (next_burst_len - payload_length), + payload_length, conn->sess->sess_ops->MaxBurstLength); +return DATAOUT_CANNOT_RECOVER ; + } + +/* +* Perform various MaxBurstLength and ISCSI_FLAG_CMD_FINAL sanity +* checks for the current DataOUT Sequence. +*/ +if (hdr->flags &ISCSI_FLAG_CMD_FINAL ) { +/* +* Ignore ISCSI_FLAG_CMD_FINAL checks while DataPDUInOrder=No, end of +* sequence checks are handled in +* iscsi_dataout_datapduinorder_no_fbit(). +*/ +if (!conn->sess->sess_ops->DataPDUInOrder) + goto out; + +if (conn->sess->sess_ops->DataSequenceInOrder) { +if ((next_burst_len < + conn->sess->sess_ops->MaxBurstLength) && + ((cmd->write_data_done + payload_length) < + cmd->data_length)) { +printk (KERN_ERR "Command ITT: 0x%08x set ISCSI_FLAG_CMD_FINAL" +" before end of DataOUT sequence, protocol" +" error.\n" , cmd->init_task_tag); +return DATAOUT_CANNOT_RECOVER ; + } + }else { +if (next_burst_len < seq->xfer_len) { +printk (KERN_ERR "Command ITT: 0x%08x set ISCSI_FLAG_CMD_FINAL" +" before end of DataOUT sequence, protocol" +" error.\n" , cmd->init_task_tag); +return DATAOUT_CANNOT_RECOVER ; + } + } + }else { +if (conn->sess->sess_ops->DataSequenceInOrder) { +if (next_burst_len == + conn->sess->sess_ops->MaxBurstLength) { +printk (KERN_ERR "Command ITT: 0x%08x reached" +" MaxBurstLength: %u, but ISCSI_FLAG_CMD_FINAL is" +" not set, protocol error." , cmd->init_task_tag, + conn->sess->sess_ops->MaxBurstLength); +return DATAOUT_CANNOT_RECOVER ; + } +if ((cmd->write_data_done + payload_length) == + cmd->data_length) { +printk (KERN_ERR "Command ITT: 0x%08x reached" +" last DataOUT PDU in sequence but ISCSI_FLAG_" +"CMD_FINAL is not set, protocol error.\n" , + cmd->init_task_tag); +return DATAOUT_CANNOT_RECOVER ; + } + }else { +if (next_burst_len == seq->xfer_len) { +printk (KERN_ERR "Command ITT: 0x%08x reached" +" last DataOUT PDU in sequence but ISCSI_FLAG_" +"CMD_FINAL is not set, protocol error.\n" , + cmd->init_task_tag); +return DATAOUT_CANNOT_RECOVER ; + } + } + } + +out: +return DATAOUT_NORMAL ; +} + +/* iscsi_dataout_check_datasn(): +* +* Called from: iscsi_check_pre_dataout() +*/ +static inline int iscsi_dataout_check_datasn ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +int dump =0 , recovery =0 ; +u32 data_sn =0 ; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + +/* +* Considering the target has no method of re-requesting DataOUT +* by DataSN, if we receieve a greater DataSN than expected we +* assume the functions for DataPDUInOrder=[Yes,No] below will +* handle it. +* +* If the DataSN is less than expected, dump the payload. +*/ +if (conn->sess->sess_ops->DataSequenceInOrder) + data_sn = cmd->data_sn; +else { +struct iscsi_seq *seq = cmd->seq_ptr; + data_sn = seq->data_sn; + } + +if (hdr->datasn > data_sn) { +printk (KERN_ERR "Command ITT: 0x%08x, received DataSN: 0x%08x" +" higher than expected 0x%08x.\n" , cmd->init_task_tag, + hdr->datasn, data_sn); + recovery =1 ; + goto recover; + }else if (hdr->datasn < data_sn) { +printk (KERN_ERR "Command ITT: 0x%08x, received DataSN: 0x%08x" +" lower than expected 0x%08x, discarding payload.\n" , + cmd->init_task_tag, hdr->datasn, data_sn); + dump =1 ; + goto dump; + } + +return DATAOUT_NORMAL ; + +recover: +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Unable to perform within-command recovery" +" while ERL=0.\n" ); +return DATAOUT_CANNOT_RECOVER ; + } +dump: +if (iscsi_dump_data_payload (conn, payload_length,1 ) <0 ) +return DATAOUT_CANNOT_RECOVER ; + +return (recovery || dump) ?DATAOUT_WITHIN_COMMAND_RECOVERY : +DATAOUT_NORMAL ; +} + +/* iscsi_dataout_pre_datapduinorder_yes(): +* +* +*/ +static inline int iscsi_dataout_pre_datapduinorder_yes ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +int dump =0 , recovery =0 ; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + +/* +* For DataSequenceInOrder=Yes: If the offset is greater than the global +* DataPDUInOrder=Yes offset counter in struct iscsi_cmd a protcol error has +* occured and fail the connection. +* +* For DataSequenceInOrder=No: If the offset is greater than the per +* sequence DataPDUInOrder=Yes offset counter in struct iscsi_seq a protocol +* error has occured and fail the connection. +*/ +if (conn->sess->sess_ops->DataSequenceInOrder) { +if (hdr->offset != cmd->write_data_done) { +printk (KERN_ERR "Command ITT: 0x%08x, received offset" +" %u different than expected %u.\n" , cmd->init_task_tag, + hdr->offset, cmd->write_data_done); + recovery =1 ; + goto recover; + } + }else { +struct iscsi_seq *seq = cmd->seq_ptr; + +if (hdr->offset > seq->offset) { +printk (KERN_ERR "Command ITT: 0x%08x, received offset" +" %u greater than expected %u.\n" , cmd->init_task_tag, + hdr->offset, seq->offset); + recovery =1 ; + goto recover; + }else if (hdr->offset < seq->offset) { +printk (KERN_ERR "Command ITT: 0x%08x, received offset" +" %u less than expected %u, discarding payload.\n" , + cmd->init_task_tag, hdr->offset, seq->offset); + dump =1 ; + goto dump; + } + } + +return DATAOUT_NORMAL ; + +recover: +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Unable to perform within-command recovery" +" while ERL=0.\n" ); +return DATAOUT_CANNOT_RECOVER ; + } +dump: +if (iscsi_dump_data_payload (conn, payload_length,1 ) <0 ) +return DATAOUT_CANNOT_RECOVER ; + +return (recovery) ?iscsi_recover_dataout_sequence (cmd, + hdr->offset, payload_length) : + (dump) ?DATAOUT_WITHIN_COMMAND_RECOVERY :DATAOUT_NORMAL ; +} + +/* iscsi_dataout_pre_datapduinorder_no(): +* +* Called from: iscsi_check_pre_dataout() +*/ +static inline int iscsi_dataout_pre_datapduinorder_no ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +struct iscsi_pdu *pdu; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + + pdu =iscsi_get_pdu_holder (cmd, hdr->offset, payload_length); +if (!pdu) +return DATAOUT_CANNOT_RECOVER ; + + cmd->pdu_ptr = pdu; + +switch (pdu->status) { +case ISCSI_PDU_NOT_RECEIVED : +case ISCSI_PDU_CRC_FAILED : +case ISCSI_PDU_TIMED_OUT : +break ; +case ISCSI_PDU_RECEIVED_OK : +printk (KERN_ERR "Command ITT: 0x%08x received already gotten" +" Offset: %u, Length: %u\n" , cmd->init_task_tag, + hdr->offset, payload_length); +return iscsi_dump_data_payload (cmd->conn, payload_length,1 ); +default : +return DATAOUT_CANNOT_RECOVER ; + } + +return DATAOUT_NORMAL ; +} + +/* iscsi_dataout_update_r2t(): +* +* +*/ +static int iscsi_dataout_update_r2t (struct iscsi_cmd *cmd,u32 offset,u32 length) +{ +struct iscsi_r2t *r2t; + +if (cmd->unsolicited_data) +return 0 ; + + r2t =iscsi_get_r2t_for_eos (cmd, offset, length); +if (!r2t) +return -1 ; + +spin_lock_bh (&cmd->r2t_lock); + r2t->seq_complete =1 ; + cmd->outstanding_r2ts--; +spin_unlock_bh (&cmd->r2t_lock); + +return 0 ; +} + +/* iscsi_dataout_update_datapduinorder_no(): +* +* +*/ +static int iscsi_dataout_update_datapduinorder_no ( +struct iscsi_cmd *cmd, +u32 data_sn, +int f_bit) +{ +int ret =0 ; +struct iscsi_pdu *pdu = cmd->pdu_ptr; + + pdu->data_sn = data_sn; + +switch (pdu->status) { +case ISCSI_PDU_NOT_RECEIVED : + pdu->status =ISCSI_PDU_RECEIVED_OK ; +break ; +case ISCSI_PDU_CRC_FAILED : + pdu->status =ISCSI_PDU_RECEIVED_OK ; +break ; +case ISCSI_PDU_TIMED_OUT : + pdu->status =ISCSI_PDU_RECEIVED_OK ; +break ; +default : +return DATAOUT_CANNOT_RECOVER ; + } + +if (f_bit) { + ret =iscsi_dataout_datapduinorder_no_fbit (cmd, pdu); +if (ret ==DATAOUT_CANNOT_RECOVER ) +return ret; + } + +return DATAOUT_NORMAL ; +} + +/* iscsi_dataout_post_crc_passed(): +* +* Called from: iscsi_check_post_dataout() +*/ +static inline int iscsi_dataout_post_crc_passed ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +int ret, send_r2t =0 ; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_seq *seq =NULL ; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + +if (cmd->unsolicited_data) { +if ((cmd->first_burst_len + payload_length) == + conn->sess->sess_ops->FirstBurstLength) { +if (iscsi_dataout_update_r2t (cmd, hdr->offset, + payload_length) <0 ) +return DATAOUT_CANNOT_RECOVER ; + send_r2t =1 ; + } + +if (!conn->sess->sess_ops->DataPDUInOrder) { + ret =iscsi_dataout_update_datapduinorder_no (cmd, + hdr->datasn, (hdr->flags &ISCSI_FLAG_CMD_FINAL )); +if (ret ==DATAOUT_CANNOT_RECOVER ) +return ret; + } + + cmd->first_burst_len += payload_length; + +if (conn->sess->sess_ops->DataSequenceInOrder) + cmd->data_sn++; +else { + seq = cmd->seq_ptr; + seq->data_sn++; + seq->offset += payload_length; + } + +if (send_r2t) { +if (seq) + seq->status =DATAOUT_SEQUENCE_COMPLETE ; + cmd->first_burst_len =0 ; + cmd->unsolicited_data =0 ; + } + }else { +if (conn->sess->sess_ops->DataSequenceInOrder) { +if ((cmd->next_burst_len + payload_length) == + conn->sess->sess_ops->MaxBurstLength) { +if (iscsi_dataout_update_r2t (cmd, hdr->offset, + payload_length) <0 ) +return DATAOUT_CANNOT_RECOVER ; + send_r2t =1 ; + } + +if (!conn->sess->sess_ops->DataPDUInOrder) { + ret =iscsi_dataout_update_datapduinorder_no ( + cmd, hdr->datasn, + (hdr->flags &ISCSI_FLAG_CMD_FINAL )); +if (ret ==DATAOUT_CANNOT_RECOVER ) +return ret; + } + + cmd->next_burst_len += payload_length; + cmd->data_sn++; + +if (send_r2t) + cmd->next_burst_len =0 ; + }else { + seq = cmd->seq_ptr; + +if ((seq->next_burst_len + payload_length) == + seq->xfer_len) { +if (iscsi_dataout_update_r2t (cmd, hdr->offset, + payload_length) <0 ) +return DATAOUT_CANNOT_RECOVER ; + send_r2t =1 ; + } + +if (!conn->sess->sess_ops->DataPDUInOrder) { + ret =iscsi_dataout_update_datapduinorder_no ( + cmd, hdr->datasn, + (hdr->flags &ISCSI_FLAG_CMD_FINAL )); +if (ret ==DATAOUT_CANNOT_RECOVER ) +return ret; + } + + seq->data_sn++; + seq->offset += payload_length; + seq->next_burst_len += payload_length; + +if (send_r2t) { + seq->next_burst_len =0 ; + seq->status =DATAOUT_SEQUENCE_COMPLETE ; + } + } + } + +if (send_r2t && conn->sess->sess_ops->DataSequenceInOrder) + cmd->data_sn =0 ; + + cmd->write_data_done += payload_length; + +return (cmd->write_data_done == cmd->data_length) ? +DATAOUT_SEND_TO_TRANSPORT : (send_r2t) ? +DATAOUT_SEND_R2T :DATAOUT_NORMAL ; +} + +/* iscsi_dataout_post_crc_failed(): +* +* Called from: iscsi_check_post_dataout() +*/ +static inline int iscsi_dataout_post_crc_failed ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +struct iscsi_conn *conn = cmd->conn; +struct iscsi_pdu *pdu; +struct iscsi_data *hdr = (struct iscsi_data *) buf; +u32 payload_length =ntoh24 (hdr->dlength); + +if (conn->sess->sess_ops->DataPDUInOrder) + goto recover; + +/* +* The rest of this function is only called when DataPDUInOrder=No. +*/ + pdu = cmd->pdu_ptr; + +switch (pdu->status) { +case ISCSI_PDU_NOT_RECEIVED : + pdu->status =ISCSI_PDU_CRC_FAILED ; +break ; +case ISCSI_PDU_CRC_FAILED : +break ; +case ISCSI_PDU_TIMED_OUT : + pdu->status =ISCSI_PDU_CRC_FAILED ; +break ; +default : +return DATAOUT_CANNOT_RECOVER ; + } + +recover: +return iscsi_recover_dataout_sequence (cmd, hdr->offset, payload_length); +} + +/* iscsi_check_pre_dataout(): +* +* Called from iscsi_handle_data_out() before DataOUT Payload is received +* and CRC computed. +*/ +extern int iscsi_check_pre_dataout ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +int ret; +struct iscsi_conn *conn = cmd->conn; + + ret =iscsi_dataout_within_command_recovery_check (cmd, buf); +if ((ret ==DATAOUT_WITHIN_COMMAND_RECOVERY ) || + (ret ==DATAOUT_CANNOT_RECOVER )) +return ret; + + ret =iscsi_dataout_check_datasn (cmd, buf); +if ((ret ==DATAOUT_WITHIN_COMMAND_RECOVERY ) || + (ret ==DATAOUT_CANNOT_RECOVER )) +return ret; + +if (cmd->unsolicited_data) { + ret =iscsi_dataout_check_unsolicited_sequence (cmd, buf); +if ((ret ==DATAOUT_WITHIN_COMMAND_RECOVERY ) || + (ret ==DATAOUT_CANNOT_RECOVER )) +return ret; + }else { + ret =iscsi_dataout_check_sequence (cmd, buf); +if ((ret ==DATAOUT_WITHIN_COMMAND_RECOVERY ) || + (ret ==DATAOUT_CANNOT_RECOVER )) +return ret; + } + +return (conn->sess->sess_ops->DataPDUInOrder) ? +iscsi_dataout_pre_datapduinorder_yes (cmd, buf) : +iscsi_dataout_pre_datapduinorder_no (cmd, buf); +} + +/* iscsi_check_post_dataout(): +* +* Called from iscsi_handle_data_out() after DataOUT Payload is received +* and CRC computed. +*/ +int iscsi_check_post_dataout ( +struct iscsi_cmd *cmd, +unsigned char *buf, +u8 data_crc_failed) +{ +struct iscsi_conn *conn = cmd->conn; + + cmd->dataout_timeout_retries =0 ; + +if (!data_crc_failed) +return iscsi_dataout_post_crc_passed (cmd, buf); +else { +if (!conn->sess->sess_ops->ErrorRecoveryLevel) { +printk (KERN_ERR "Unable to recover from DataOUT CRC" +" failure while ERL=0, closing session.\n" ); +iscsi_add_reject_from_cmd (ISCSI_REASON_DATA_DIGEST_ERROR , +1 ,0 , buf, cmd); +return DATAOUT_CANNOT_RECOVER ; + } + +iscsi_add_reject_from_cmd (ISCSI_REASON_DATA_DIGEST_ERROR , +0 ,0 , buf, cmd); +return iscsi_dataout_post_crc_failed (cmd, buf); + } +} + +/* iscsi_handle_time2retain_timeout(): +* +* +*/ +static void iscsi_handle_time2retain_timeout (unsigned long data) +{ +struct iscsi_session *sess = (struct iscsi_session *) data; +struct iscsi_portal_group *tpg =ISCSI_TPG_S (sess); +struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; + +spin_lock_bh (&se_tpg->session_lock); +if (sess->time2retain_timer_flags &ISCSI_TF_STOP ) { +spin_unlock_bh (&se_tpg->session_lock); +return ; + } +if (atomic_read (&sess->session_reinstatement)) { +printk (KERN_ERR "Exiting Time2Retain handler because" +" session_reinstatement=1\n" ); +spin_unlock_bh (&se_tpg->session_lock); +return ; + } + sess->time2retain_timer_flags |=ISCSI_TF_EXPIRED ; + +printk (KERN_ERR "Time2Retain timer expired for SID: %u, cleaning up" +" iSCSI session.\n" , sess->sid); + { +struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; + +if (tiqn) { +spin_lock (&tiqn->sess_err_stats.lock); +strcpy (tiqn->sess_err_stats.last_sess_fail_rem_name, + (void *)sess->sess_ops->InitiatorName); + tiqn->sess_err_stats.last_sess_failure_type = +ISCSI_SESS_ERR_CXN_TIMEOUT ; + tiqn->sess_err_stats.cxn_timeout_errors++; + sess->conn_timeout_errors++; +spin_unlock (&tiqn->sess_err_stats.lock); + } + } + +spin_unlock_bh (&se_tpg->session_lock); +iscsi_close_session (sess); +} + +/* iscsi_start_session_cleanup_handler(): +* +* +*/ +extern void iscsi_start_time2retain_handler (struct iscsi_session *sess) +{ +int tpg_active; + +/* +* Only start Time2Retain timer when the assoicated TPG is still in +* an ACTIVE (eg: not disabled or shutdown) state. +*/ +spin_lock (&ISCSI_TPG_S (sess)->tpg_state_lock); + tpg_active = (ISCSI_TPG_S (sess)->tpg_state ==TPG_STATE_ACTIVE ); +spin_unlock (&ISCSI_TPG_S (sess)->tpg_state_lock); + +if (!tpg_active) +return ; + +if (sess->time2retain_timer_flags &ISCSI_TF_RUNNING ) +return ; + +TRACE (TRACE_TIMER ,"Starting Time2Retain timer for %u seconds on" +" SID: %u\n" , sess->sess_ops->DefaultTime2Retain, sess->sid); + +init_timer (&sess->time2retain_timer); + sess->time2retain_timer.expires = + (get_jiffies_64 () + sess->sess_ops->DefaultTime2Retain *HZ ); + sess->time2retain_timer.data = (unsigned long )sess; + sess->time2retain_timer.function = iscsi_handle_time2retain_timeout; + sess->time2retain_timer_flags &= ~ISCSI_TF_STOP ; + sess->time2retain_timer_flags |=ISCSI_TF_RUNNING ; +add_timer (&sess->time2retain_timer); +} + +/* iscsi_stop_time2retain_timer(): +* +* Called with spin_lock_bh(&struct se_portal_group->session_lock) held +*/ +extern int iscsi_stop_time2retain_timer (struct iscsi_session *sess) +{ +struct iscsi_portal_group *tpg =ISCSI_TPG_S (sess); +struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; + +if (sess->time2retain_timer_flags &ISCSI_TF_EXPIRED ) +return -1 ; + +if (!(sess->time2retain_timer_flags &ISCSI_TF_RUNNING )) +return 0 ; + + sess->time2retain_timer_flags |=ISCSI_TF_STOP ; +spin_unlock_bh (&se_tpg->session_lock); + +del_timer_sync (&sess->time2retain_timer); + +spin_lock_bh (&se_tpg->session_lock); + sess->time2retain_timer_flags &= ~ISCSI_TF_RUNNING ; +TRACE (TRACE_TIMER ,"Stopped Time2Retain Timer for SID: %u\n" , + sess->sid); +return 0 ; +} + +/* iscsi_connection_reinstatement_rcfr(): +* +* +*/ +void iscsi_connection_reinstatement_rcfr (struct iscsi_conn *conn) +{ +spin_lock_bh (&conn->state_lock); +if (atomic_read (&conn->connection_exit)) { +spin_unlock_bh (&conn->state_lock); + goto sleep; + } + +if (atomic_read (&conn->transport_failed)) { +spin_unlock_bh (&conn->state_lock); + goto sleep; + } +spin_unlock_bh (&conn->state_lock); + +iscsi_thread_set_force_reinstatement (conn); + +sleep: +wait_for_completion (&conn->conn_wait_rcfr_comp); +complete (&conn->conn_post_wait_comp); +} + +/* iscsi_cause_connection_reinstatement(): +* +* +*/ +void iscsi_cause_connection_reinstatement (struct iscsi_conn *conn,int sleep) +{ +spin_lock_bh (&conn->state_lock); +if (atomic_read (&conn->connection_exit)) { +spin_unlock_bh (&conn->state_lock); +return ; + } + +if (atomic_read (&conn->transport_failed)) { +spin_unlock_bh (&conn->state_lock); +return ; + } + +if (atomic_read (&conn->connection_reinstatement)) { +spin_unlock_bh (&conn->state_lock); +return ; + } + +if (iscsi_thread_set_force_reinstatement (conn) <0 ) { +spin_unlock_bh (&conn->state_lock); +return ; + } + +atomic_set (&conn->connection_reinstatement,1 ); +if (!sleep) { +spin_unlock_bh (&conn->state_lock); +return ; + } + +atomic_set (&conn->sleep_on_conn_wait_comp,1 ); +spin_unlock_bh (&conn->state_lock); + +wait_for_completion (&conn->conn_wait_comp); +complete (&conn->conn_post_wait_comp); +} + +/* iscsi_fall_back_to_erl0(): +* +* +*/ +void iscsi_fall_back_to_erl0 (struct iscsi_session *sess) +{ +TRACE (TRACE_ERL0 ,"Falling back to ErrorRecoveryLevel=0 for SID:" +" %u\n" , sess->sid); + +atomic_set (&sess->session_fall_back_to_erl0,1 ); +} + +/* iscsi_handle_connection_cleanup(): +* +* +*/ +static void iscsi_handle_connection_cleanup (struct iscsi_conn *conn) +{ +struct iscsi_session *sess = conn->sess; + +if ((sess->sess_ops->ErrorRecoveryLevel ==2 ) && + !atomic_read (&sess->session_reinstatement) && + !atomic_read (&sess->session_fall_back_to_erl0)) +iscsi_connection_recovery_transport_reset (conn); +else { +TRACE (TRACE_ERL0 ,"Performing cleanup for failed iSCSI" +" Connection ID: %hu from %s\n" , conn->cid, + sess->sess_ops->InitiatorName); +iscsi_close_connection (conn); + } +} + +/* iscsi_take_action_for_connection_exit(): +* +* +*/ +extern void iscsi_take_action_for_connection_exit (struct iscsi_conn *conn) +{ +spin_lock_bh (&conn->state_lock); +if (atomic_read (&conn->connection_exit)) { +spin_unlock_bh (&conn->state_lock); +return ; + } +atomic_set (&conn->connection_exit,1 ); + +if (conn->conn_state ==TARG_CONN_STATE_IN_LOGOUT ) { +spin_unlock_bh (&conn->state_lock); +iscsi_close_connection (conn); +return ; + } + +if (conn->conn_state ==TARG_CONN_STATE_CLEANUP_WAIT ) { +spin_unlock_bh (&conn->state_lock); +return ; + } + +TRACE (TRACE_STATE ,"Moving to TARG_CONN_STATE_CLEANUP_WAIT.\n" ); + conn->conn_state =TARG_CONN_STATE_CLEANUP_WAIT ; +spin_unlock_bh (&conn->state_lock); + +iscsi_handle_connection_cleanup (conn); +} + +/* iscsi_recover_from_unknown_opcode(): +* +* This is the simple function that makes the magic of +* sync and steering happen in the follow paradoxical order: +* +* 0) Receive conn->of_marker (bytes left until next OFMarker) +* bytes into an offload buffer. When we pass the exact number +* of bytes in conn->of_marker, iscsi_dump_data_payload() and hence +* rx_data() will automatically receive the identical u32 marker +* values and store it in conn->of_marker_offset; +* 1) Now conn->of_marker_offset will contain the offset to the start +* of the next iSCSI PDU. Dump these remaining bytes into another +* offload buffer. +* 2) We are done! +* Next byte in the TCP stream will contain the next iSCSI PDU! +* Cool Huh?! +*/ +int iscsi_recover_from_unknown_opcode (struct iscsi_conn *conn) +{ +/* +* Make sure the remaining bytes to next maker is a sane value. +*/ +if (conn->of_marker > (conn->conn_ops->OFMarkInt *4 )) { +printk (KERN_ERR "Remaining bytes to OFMarker: %u exceeds" +" OFMarkInt bytes: %u.\n" , conn->of_marker, + conn->conn_ops->OFMarkInt *4 ); +return -1 ; + } + +TRACE (TRACE_ERL1 ,"Advancing %u bytes in TCP stream to get to the" +" next OFMarker.\n" , conn->of_marker); + +if (iscsi_dump_data_payload (conn, conn->of_marker,0 ) <0 ) +return -1 ; + +/* +* Make sure the offset marker we retrived is a valid value. +*/ +if (conn->of_marker_offset > (ISCSI_HDR_LEN + (CRC_LEN *2 ) + + conn->conn_ops->MaxRecvDataSegmentLength)) { +printk (KERN_ERR "OfMarker offset value: %u exceeds limit.\n" , + conn->of_marker_offset); +return -1 ; + } + +TRACE (TRACE_ERL1 ,"Discarding %u bytes of TCP stream to get to the" +" next iSCSI Opcode.\n" , conn->of_marker_offset); + +if (iscsi_dump_data_payload (conn, conn->of_marker_offset,0 ) <0 ) +return -1 ; + +return 0 ; +}
drivers/target/iscsi/iscsi_target_erl0.h new file +19 -0
@@ -0,0 +1,19 @@ +#ifndef ISCSI_TARGET_ERL0_H +#define ISCSI_TARGET_ERL0_H + +extern void iscsi_set_dataout_sequence_values (struct iscsi_cmd *); +extern int iscsi_check_pre_dataout (struct iscsi_cmd *,unsigned char *); +extern int iscsi_check_post_dataout (struct iscsi_cmd *,unsigned char *,u8 ); +extern void iscsi_start_time2retain_handler (struct iscsi_session *); +extern int iscsi_stop_time2retain_timer (struct iscsi_session *); +extern void iscsi_connection_reinstatement_rcfr (struct iscsi_conn *); +extern void iscsi_cause_connection_reinstatement (struct iscsi_conn *,int ); +extern void iscsi_fall_back_to_erl0 (struct iscsi_session *); +extern void iscsi_take_action_for_connection_exit (struct iscsi_conn *); +extern int iscsi_recover_from_unknown_opcode (struct iscsi_conn *); + +extern struct iscsi_global *iscsi_global; +extern int iscsi_add_reject_from_cmd (u8 ,int ,int ,unsigned char *, +struct iscsi_cmd *); + +#endif /*** ISCSI_TARGET_ERL0_H ***/
drivers/target/iscsi/iscsi_target_erl1.c new file +1378 -0
1,378 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_erl1.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef ISCSI_TARGET_ERL1_H +#define ISCSI_TARGET_ERL1_H + +extern int iscsi_dump_data_payload (struct iscsi_conn *,u32 ,int ); +extern int iscsi_create_recovery_datain_values_datasequenceinorder_yes ( +struct iscsi_cmd *,struct iscsi_datain_req *); +extern int iscsi_create_recovery_datain_values_datasequenceinorder_no ( +struct iscsi_cmd *,struct iscsi_datain_req *); +extern int iscsi_handle_recovery_datain_or_r2t (struct iscsi_conn *,unsigned char *, +u32 ,u32 ,u32 ,u32 ); +extern int iscsi_handle_status_snack (struct iscsi_conn *,u32 ,u32 , +u32 ,u32 ); +extern int iscsi_handle_data_ack (struct iscsi_conn *,u32 ,u32 ,u32 ); +extern int iscsi_dataout_datapduinorder_no_fbit (struct iscsi_cmd *,struct iscsi_pdu *); +extern int iscsi_recover_dataout_sequence (struct iscsi_cmd *,u32 ,u32 ); +extern void iscsi_clear_ooo_cmdsns_for_conn (struct iscsi_conn *); +extern void iscsi_free_all_ooo_cmdsns (struct iscsi_session *); +extern int iscsi_execute_ooo_cmdsns (struct iscsi_session *); +extern int iscsi_execute_cmd (struct iscsi_cmd *,int ); +extern int iscsi_handle_ooo_cmdsn (struct iscsi_session *,struct iscsi_cmd *,u32 ); +extern void iscsi_remove_ooo_cmdsn (struct iscsi_session *,struct iscsi_ooo_cmdsn *); +extern void iscsi_mod_dataout_timer (struct iscsi_cmd *); +extern void iscsi_start_dataout_timer (struct iscsi_cmd *,struct iscsi_conn *); +extern void iscsi_stop_dataout_timer (struct iscsi_cmd *); + +extern struct kmem_cache *lio_ooo_cache; + +extern int iscsi_add_reject_from_cmd (u8 ,int ,int ,unsigned char *, +struct iscsi_cmd *); +extern int iscsi_build_r2ts_for_cmd (struct iscsi_cmd *,struct iscsi_conn *,int ); +extern int iscsi_logout_closesession (struct iscsi_cmd *,struct iscsi_conn *); +extern int iscsi_logout_closeconnection (struct iscsi_cmd *,struct iscsi_conn *); +extern int iscsi_logout_removeconnforrecovery (struct iscsi_cmd *,struct iscsi_conn *); + +#endif /* ISCSI_TARGET_ERL1_H */
drivers/target/iscsi/iscsi_target_erl2.c new file +529 -0
488 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_erl2.h new file +20 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Part of the diff is not shown here. View the raw message.
RFC v3 10/12 iscsi-target: Add support for task management operations
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This patch adds support for iSCSI task management operations called directly from iscsi_target.c TMR request/response PDU logic, and interfaces struct se_lun -> struct se_device for assoication of TMRs to TCM backend devices.
--- drivers/target/iscsi/iscsi_target_tmr.c | 868 +++++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_tmr.h | 16 + 2 files changed, 884 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_tmr.c create mode 100644 drivers/target/iscsi/iscsi_target_tmr.h
drivers/target/iscsi/iscsi_target_tmr.c new file +868 -0
@@ -0,0 +1,868 @@ +/******************************************************************************* +* This file contains the iSCSI Target specific Task Management functions. +* +* © Copyright 2007-2011 RisingTide Systems LLC. +* +* Licensed to the Linux Foundation under the General Public License (GPL) version 2. +* +* Author: Nicholas A. Bellinger <[email protected]> +* +* 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. +******************************************************************************/ + +#include <asm/unaligned.h> +#include <scsi/iscsi_proto.h> +#include <target/target_core_base.h> +#include <target/target_core_transport.h> + +#include "iscsi_target_debug.h" +#include "iscsi_target_core.h" +#include "iscsi_target_seq_pdu_list.h" +#include "iscsi_target_datain_values.h" +#include "iscsi_target_device.h" +#include "iscsi_target_erl0.h" +#include "iscsi_target_erl1.h" +#include "iscsi_target_erl2.h" +#include "iscsi_target_tmr.h" +#include "iscsi_target_tpg.h" +#include "iscsi_target_util.h" + +/* iscsi_tmr_abort_task(): +* +* Called from iscsi_handle_task_mgt_cmd(). +*/ +u8 iscsi_tmr_abort_task ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +struct iscsi_cmd *ref_cmd; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_tmr_req *tmr_req = cmd->tmr_req; +struct se_tmr_req *se_tmr =SE_CMD (cmd)->se_tmr_req; +struct iscsi_tm *hdr = (struct iscsi_tm *) buf; + + ref_cmd =iscsi_find_cmd_from_itt (conn, hdr->rtt); +if (!ref_cmd) { +printk (KERN_ERR "Unable to locate RefTaskTag: 0x%08x on CID:" +" %hu.\n" , hdr->rtt, conn->cid); +return ((hdr->refcmdsn >= conn->sess->exp_cmd_sn) && + (hdr->refcmdsn <= conn->sess->max_cmd_sn)) ? +ISCSI_TMF_RSP_COMPLETE :ISCSI_TMF_RSP_NO_TASK ; + } +if (ref_cmd->cmd_sn != hdr->refcmdsn) { +printk (KERN_ERR "RefCmdSN 0x%08x does not equal" +" task's CmdSN 0x%08x. Rejecting ABORT_TASK.\n" , + hdr->refcmdsn, ref_cmd->cmd_sn); +return ISCSI_TMF_RSP_REJECTED ; + } + + se_tmr->ref_task_tag = hdr->rtt; + se_tmr->ref_cmd = &ref_cmd->se_cmd; + tmr_req->ref_cmd_sn = hdr->refcmdsn; + tmr_req->exp_data_sn = hdr->exp_datasn; + +return ISCSI_TMF_RSP_COMPLETE ; +} + +/* iscsi_tmr_task_warm_reset(): +* +* Called from iscsi_handle_task_mgt_cmd(). +*/ +int iscsi_tmr_task_warm_reset ( +struct iscsi_conn *conn, +struct iscsi_tmr_req *tmr_req, +unsigned char *buf) +{ +struct iscsi_session *sess = conn->sess; +struct iscsi_node_attrib *na =iscsi_tpg_get_node_attrib (sess); +#if 0 +struct iscsi_init_task_mgt_cmnd *hdr = + (struct iscsi_init_task_mgt_cmnd *) buf; +#endif +if (!na->tmr_warm_reset) { +printk (KERN_ERR "TMR Opcode TARGET_WARM_RESET authorization" +" failed for Initiator Node: %s\n" , + sess->se_sess->se_node_acl->initiatorname); +return -1 ; + } +/* +* Do the real work in transport_generic_do_tmr(). +*/ +return 0 ; +} + +/* iscsi_tmr_task_cold_reset(): +* +* Called from iscsi_handle_task_mgt_cmd(). +*/ +int iscsi_tmr_task_cold_reset ( +struct iscsi_conn *conn, +struct iscsi_tmr_req *tmr_req, +unsigned char *buf) +{ +struct iscsi_session *sess = conn->sess; +struct iscsi_node_attrib *na =iscsi_tpg_get_node_attrib (sess); + +if (!na->tmr_cold_reset) { +printk (KERN_ERR "TMR Opcode TARGET_COLD_RESET authorization" +" failed for Initiator Node: %s\n" , + sess->se_sess->se_node_acl->initiatorname); +return -1 ; + } +/* +* Do the real work in transport_generic_do_tmr(). +*/ +return 0 ; +} + +/* iscsi_tmr_task_reassign(): +* +* Called from iscsi_handle_task_mgt_cmd(). +*/ +u8 iscsi_tmr_task_reassign ( +struct iscsi_cmd *cmd, +unsigned char *buf) +{ +struct iscsi_cmd *ref_cmd =NULL ; +struct iscsi_conn *conn = cmd->conn; +struct iscsi_conn_recovery *cr =NULL ; +struct iscsi_tmr_req *tmr_req = cmd->tmr_req; +struct se_tmr_req *se_tmr =SE_CMD (cmd)->se_tmr_req; +struct iscsi_tm *hdr = (struct iscsi_tm *) buf; +int ret; + +TRACE (TRACE_ERL2 ,"Got TASK_REASSIGN TMR ITT: 0x%08x," +" RefTaskTag: 0x%08x, ExpDataSN: 0x%08x, CID: %hu\n" , + hdr->itt, hdr->rtt, hdr->exp_datasn, conn->cid); + +if (conn->sess->sess_ops->ErrorRecoveryLevel !=2 ) { +printk (KERN_ERR "TMR TASK_REASSIGN not supported in ERL<2," +" ignoring request.\n" ); +return ISCSI_TMF_RSP_NOT_SUPPORTED ; + } + + ret =iscsi_find_cmd_for_recovery (conn->sess, &ref_cmd, &cr, hdr->rtt); +if (ret ==-2 ) { +printk (KERN_ERR "Command ITT: 0x%08x is still alligent to CID:" +" %hu\n" , ref_cmd->init_task_tag, cr->cid); +return ISCSI_TMF_RSP_TASK_ALLEGIANT ; + }else if (ret ==-1 ) { +printk (KERN_ERR "Unable to locate RefTaskTag: 0x%08x in" +" connection recovery command list.\n" , hdr->rtt); +return ISCSI_TMF_RSP_NO_TASK ; + } +/* +* Temporary check to prevent connection recovery for +* connections with a differing MaxRecvDataSegmentLength. +*/ +if (cr->maxrecvdatasegmentlength != + conn->conn_ops->MaxRecvDataSegmentLength) { +printk (KERN_ERR "Unable to perform connection recovery for" +" differing MaxRecvDataSegmentLength, rejecting" +" TMR TASK_REASSIGN.\n" ); +return ISCSI_TMF_RSP_REJECTED ; + } + + se_tmr->ref_task_tag = hdr->rtt; + se_tmr->ref_cmd = &ref_cmd->se_cmd; + se_tmr->ref_task_lun =get_unaligned_le64 (&hdr->lun[0 ]); + tmr_req->ref_cmd_sn = hdr->refcmdsn; + tmr_req->exp_data_sn = hdr->exp_datasn; + tmr_req->conn_recovery = cr; + tmr_req->task_reassign =1 ; +/* +* Command can now be reassigned to a new connection. +* The task management response must be sent before the +* reassignment actually happens. See iscsi_tmr_post_handler(). +*/ +return ISCSI_TMF_RSP_COMPLETE ; +} + +static void iscsi_task_reassign_remove_cmd ( +struct iscsi_cmd *cmd, +struct iscsi_conn_recovery *cr, +struct iscsi_session *sess) +{ +int ret; + +spin_lock (&cr->conn_recovery_cmd_lock); + ret =iscsi_remove_cmd_from_connection_recovery (cmd, sess); +spin_unlock (&cr->conn_recovery_cmd_lock); +if (!ret) { +printk (KERN_INFO "iSCSI connection recovery successful for CID:" +" %hu on SID: %u\n" , cr->cid, sess->sid); +iscsi_remove_active_connection_recovery_entry (cr, sess); + } + +return ; +} + +static int iscsi_task_reassign_complete_nop_out ( +struct iscsi_tmr_req *tmr_req, +struct iscsi_conn *conn) +{ +struct se_tmr_req *se_tmr = tmr_req->se_tmr_req; +struct se_cmd *se_cmd = se_tmr->ref_cmd; + struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); +struct iscsi_conn_recovery *cr; + +if (!cmd->cr) { +printk (KERN_ERR "struct iscsi_conn_recovery pointer for ITT: 0x%08x" +" is NULL!\n" , cmd->init_task_tag); +return -1 ; + } + cr = cmd->cr; + +/* +* Reset the StatSN so a new one for this commands new connection +* will be assigned. +* Reset the ExpStatSN as well so we may receive Status SNACKs. +*/ + cmd->stat_sn = cmd->exp_stat_sn =0 ; + +iscsi_task_reassign_remove_cmd (cmd, cr, conn->sess); + +iscsi_attach_cmd_to_queue (conn, cmd); + + cmd->i_state =ISTATE_SEND_NOPIN ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; +} + +static int iscsi_task_reassign_complete_write ( +struct iscsi_cmd *cmd, +struct iscsi_tmr_req *tmr_req) +{ +int no_build_r2ts =0 ; +u32 length =0 , offset =0 ; +struct iscsi_conn *conn = cmd->conn; +struct se_cmd *se_cmd =SE_CMD (cmd); +/* +* The Initiator must not send a R2T SNACK with a Begrun less than +* the TMR TASK_REASSIGN's ExpDataSN. +*/ +if (!tmr_req->exp_data_sn) { + cmd->cmd_flags &= ~ICF_GOT_DATACK_SNACK ; + cmd->acked_data_sn =0 ; + }else { + cmd->cmd_flags |=ICF_GOT_DATACK_SNACK ; + cmd->acked_data_sn = (tmr_req->exp_data_sn -1 ); + } + +/* +* The TMR TASK_REASSIGN's ExpDataSN contains the next R2TSN the +* Initiator is expecting. The Target controls all WRITE operations +* so if we have received all DataOUT we can safety ignore Initiator. +*/ +if (cmd->cmd_flags &ICF_GOT_LAST_DATAOUT ) { +if (!atomic_read (&cmd->transport_sent)) { +TRACE (TRACE_ERL2 ,"WRITE ITT: 0x%08x: t_state: %d" +" never sent to transport\n" , + cmd->init_task_tag, cmd->se_cmd.t_state); +return transport_generic_handle_data (se_cmd); + } + + cmd->i_state =ISTATE_SEND_STATUS ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; + } + +/* +* Special case to deal with DataSequenceInOrder=No and Non-Immeidate +* Unsolicited DataOut. +*/ +if (cmd->unsolicited_data) { + cmd->unsolicited_data =0 ; + + offset = cmd->next_burst_len = cmd->write_data_done; + +if ((conn->sess->sess_ops->FirstBurstLength - offset) >= + cmd->data_length) { + no_build_r2ts =1 ; + length = (cmd->data_length - offset); + }else + length = (conn->sess->sess_ops->FirstBurstLength - offset); + +spin_lock_bh (&cmd->r2t_lock); +if (iscsi_add_r2t_to_list (cmd, offset, length,0 ,0 ) <0 ) { +spin_unlock_bh (&cmd->r2t_lock); +return -1 ; + } + cmd->outstanding_r2ts++; +spin_unlock_bh (&cmd->r2t_lock); + +if (no_build_r2ts) +return 0 ; + } +/* +* iscsi_build_r2ts_for_cmd() can handle the rest from here. +*/ +return iscsi_build_r2ts_for_cmd (cmd, conn,2 ); +} + +static int iscsi_task_reassign_complete_read ( +struct iscsi_cmd *cmd, +struct iscsi_tmr_req *tmr_req) +{ +struct iscsi_conn *conn = cmd->conn; +struct iscsi_datain_req *dr; +struct se_cmd *se_cmd =SE_CMD (cmd); +/* +* The Initiator must not send a Data SNACK with a BegRun less than +* the TMR TASK_REASSIGN's ExpDataSN. +*/ +if (!tmr_req->exp_data_sn) { + cmd->cmd_flags &= ~ICF_GOT_DATACK_SNACK ; + cmd->acked_data_sn =0 ; + }else { + cmd->cmd_flags |=ICF_GOT_DATACK_SNACK ; + cmd->acked_data_sn = (tmr_req->exp_data_sn -1 ); + } + +if (!atomic_read (&cmd->transport_sent)) { +printk (KERN_INFO "READ ITT: 0x%08x: t_state: %d never sent to" +" transport\n" , cmd->init_task_tag, +SE_CMD (cmd)->t_state); +transport_generic_handle_cdb (se_cmd); +return 0 ; + } + +if (!atomic_read (&T_TASK (se_cmd)->t_transport_complete)) { +printk (KERN_ERR "READ ITT: 0x%08x: t_state: %d, never returned" +" from transport\n" , cmd->init_task_tag, +SE_CMD (cmd)->t_state); +return -1 ; + } + + dr =iscsi_allocate_datain_req (); +if (!dr) +return -1 ; +/* +* The TMR TASK_REASSIGN's ExpDataSN contains the next DataSN the +* Initiator is expecting. +*/ + dr->data_sn = dr->begrun = tmr_req->exp_data_sn; + dr->runlength =0 ; + dr->generate_recovery_values =1 ; + dr->recovery =DATAIN_CONNECTION_RECOVERY ; + +iscsi_attach_datain_req (cmd, dr); + + cmd->i_state =ISTATE_SEND_DATAIN ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; +} + +static int iscsi_task_reassign_complete_none ( +struct iscsi_cmd *cmd, +struct iscsi_tmr_req *tmr_req) +{ +struct iscsi_conn *conn = cmd->conn; + + cmd->i_state =ISTATE_SEND_STATUS ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; +} + +static int iscsi_task_reassign_complete_scsi_cmnd ( +struct iscsi_tmr_req *tmr_req, +struct iscsi_conn *conn) +{ +struct se_tmr_req *se_tmr = tmr_req->se_tmr_req; +struct se_cmd *se_cmd = se_tmr->ref_cmd; + struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); +struct iscsi_conn_recovery *cr; + +if (!cmd->cr) { +printk (KERN_ERR "struct iscsi_conn_recovery pointer for ITT: 0x%08x" +" is NULL!\n" , cmd->init_task_tag); +return -1 ; + } + cr = cmd->cr; + +/* +* Reset the StatSN so a new one for this commands new connection +* will be assigned. +* Reset the ExpStatSN as well so we may receive Status SNACKs. +*/ + cmd->stat_sn = cmd->exp_stat_sn =0 ; + +iscsi_task_reassign_remove_cmd (cmd, cr, conn->sess); +iscsi_attach_cmd_to_queue (conn, cmd); + +if (se_cmd->se_cmd_flags &SCF_SENT_CHECK_CONDITION ) { + cmd->i_state =ISTATE_SEND_STATUS ; +iscsi_add_cmd_to_response_queue (cmd, conn, cmd->i_state); +return 0 ; + } + +switch (cmd->data_direction) { +case DMA_TO_DEVICE : +return iscsi_task_reassign_complete_write (cmd, tmr_req); +case DMA_FROM_DEVICE : +return iscsi_task_reassign_complete_read (cmd, tmr_req); +case DMA_NONE : +return iscsi_task_reassign_complete_none (cmd, tmr_req); +default : +printk (KERN_ERR "Unknown cmd->data_direction: 0x%02x\n" , + cmd->data_direction); +return -1 ; + } + +return 0 ; +} + +/* iscsi_task_reassign_complete(): +* +* Called from iscsi_tmr_post_handler(). +*/ +static int iscsi_task_reassign_complete ( +struct iscsi_tmr_req *tmr_req, +struct iscsi_conn *conn) +{ +struct se_tmr_req *se_tmr = tmr_req->se_tmr_req; +struct se_cmd *se_cmd; +struct iscsi_cmd *cmd; +int ret =0 ; + +if (!se_tmr->ref_cmd) { +printk (KERN_ERR "TMR Request is missing a RefCmd struct iscsi_cmd.\n" ); +return -1 ; + } + se_cmd = se_tmr->ref_cmd; + cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); + + cmd->conn = conn; + +switch (cmd->iscsi_opcode) { +case ISCSI_OP_NOOP_OUT : + ret =iscsi_task_reassign_complete_nop_out (tmr_req, conn); +break ; +case ISCSI_OP_SCSI_CMD : + ret =iscsi_task_reassign_complete_scsi_cmnd (tmr_req, conn); +break ; +default : +printk (KERN_ERR "Illegal iSCSI Opcode 0x%02x during" +" command realligence\n" , cmd->iscsi_opcode); +return -1 ; + } + +if (ret !=0 ) +return ret; + +TRACE (TRACE_ERL2 ,"Completed connection realligence for Opcode: 0x%02x," +" ITT: 0x%08x to CID: %hu.\n" , cmd->iscsi_opcode, + cmd->init_task_tag, conn->cid); + +return 0 ; +} + +/* iscsi_tmr_post_handler(): +* +* Handles special after-the-fact actions related to TMRs. +* Right now the only one that its really needed for is +* connection recovery releated TASK_REASSIGN. +*/ +extern int iscsi_tmr_post_handler (struct iscsi_cmd *cmd,struct iscsi_conn *conn) +{ +struct iscsi_tmr_req *tmr_req = cmd->tmr_req; +struct se_tmr_req *se_tmr =SE_CMD (cmd)->se_tmr_req; + +if (tmr_req->task_reassign && + (se_tmr->response ==ISCSI_TMF_RSP_COMPLETE )) +return iscsi_task_reassign_complete (tmr_req, conn); + +return 0 ; +} + +/* iscsi_task_reassign_prepare_read(): +* +* Nothing to do here, but leave it for good measure. :-) +*/ +int iscsi_task_reassign_prepare_read ( +struct iscsi_tmr_req *tmr_req, +struct iscsi_conn *conn) +{ +return 0 ; +} + +static void iscsi_task_reassign_prepare_unsolicited_dataout ( +struct iscsi_cmd *cmd, +struct iscsi_conn *conn) +{ +int i, j; +struct iscsi_pdu *pdu =NULL ; +struct iscsi_seq *seq =NULL ; + +if (conn->sess->sess_ops->DataSequenceInOrder) { + cmd->data_sn =0 ; + +if (cmd->immediate_data) + cmd->r2t_offset += (cmd->first_burst_len - + cmd->seq_start_offset); + +if (conn->sess->sess_ops->DataPDUInOrder) { + cmd->write_data_done -= (cmd->immediate_data) ? + (cmd->first_burst_len - + cmd->seq_start_offset) : + cmd->first_burst_len; + cmd->first_burst_len =0 ; +return ; + } + +for (i =0 ; i < cmd->pdu_count; i++) { + pdu = &cmd->pdu_list[i]; + +if (pdu->status !=ISCSI_PDU_RECEIVED_OK ) +continue ; + +if ((pdu->offset >= cmd->seq_start_offset) && + ((pdu->offset + pdu->length) <= + cmd->seq_end_offset)) { + cmd->first_burst_len -= pdu->length; + cmd->write_data_done -= pdu->length; + pdu->status =ISCSI_PDU_NOT_RECEIVED ; + } + } + }else { +for (i =0 ; i < cmd->seq_count; i++) { + seq = &cmd->seq_list[i]; + +if (seq->type !=SEQTYPE_UNSOLICITED ) +continue ; + + cmd->write_data_done -= + (seq->offset - seq->orig_offset); + cmd->first_burst_len =0 ; + seq->data_sn =0 ; + seq->offset = seq->orig_offset; + seq->next_burst_len =0 ; + seq->status =DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY ; + +if (conn->sess->sess_ops->DataPDUInOrder) +continue ; + +for (j =0 ; j < seq->pdu_count; j++) { + pdu = &cmd->pdu_list[j+seq->pdu_start]; + +if (pdu->status !=ISCSI_PDU_RECEIVED_OK ) +continue ; + + pdu->status =ISCSI_PDU_NOT_RECEIVED ; + } + } + } + +return ; +} + +int iscsi_task_reassign_prepare_write ( +struct iscsi_tmr_req *tmr_req, +struct iscsi_conn *conn) +{ +struct se_tmr_req *se_tmr = tmr_req->se_tmr_req; +struct se_cmd *se_cmd = se_tmr->ref_cmd; + struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); +struct iscsi_pdu *pdu =NULL ; +struct iscsi_r2t *r2t =NULL , *r2t_tmp; +int first_incomplete_r2t =1 , i =0 ; + +/* +* The command was in the process of receiving Unsolicited DataOUT when +* the connection failed. +*/ +if (cmd->unsolicited_data) +iscsi_task_reassign_prepare_unsolicited_dataout (cmd, conn); + +/* +* The Initiator is requesting R2Ts starting from zero, skip +* checking acknowledged R2Ts and start checking struct iscsi_r2ts +* greater than zero. +*/ +if (!tmr_req->exp_data_sn) + goto drop_unacknowledged_r2ts; + +/* +* We now check that the PDUs in DataOUT sequences below +* the TMR TASK_REASSIGN ExpDataSN (R2TSN the Initiator is +* expecting next) have all the DataOUT they require to complete +* the DataOUT sequence. First scan from R2TSN 0 to TMR +* TASK_REASSIGN ExpDataSN-1. +* +* If we have not received all DataOUT in question, we must +* make sure to make the appropriate changes to values in +* struct iscsi_cmd (and elsewhere depending on session parameters) +* so iscsi_build_r2ts_for_cmd() in iscsi_task_reassign_complete_write() +* will resend a new R2T for the DataOUT sequences in question. +*/ +spin_lock_bh (&cmd->r2t_lock); +if (list_empty (&cmd->cmd_r2t_list)) { +spin_unlock_bh (&cmd->r2t_lock); +return -1 ; + } + +list_for_each_entry (r2t, &cmd->cmd_r2t_list, r2t_list) { + +if (r2t->r2t_sn >= tmr_req->exp_data_sn) +continue ; +/* +* Safely ignore Recovery R2Ts and R2Ts that have completed +* DataOUT sequences. +*/ +if (r2t->seq_complete) +continue ; + +if (r2t->recovery_r2t) +continue ; + +/* +* DataSequenceInOrder=Yes: +* +* Taking into account the iSCSI implementation requirement of +* MaxOutstandingR2T=1 while ErrorRecoveryLevel>0 and +* DataSequenceInOrder=Yes, we must take into consideration +* the following: +* +* DataSequenceInOrder=No: +* +* Taking into account that the Initiator controls the (possibly +* random) PDU Order in (possibly random) Sequence Order of +* DataOUT the target requests with R2Ts, we must take into +* consideration the following: +* +* DataPDUInOrder=Yes for DataSequenceInOrder=[Yes,No]: +* +* While processing non-complete R2T DataOUT sequence requests +* the Target will re-request only the total sequence length +* minus current received offset. This is because we must +* assume the initiator will continue sending DataOUT from the +* last PDU before the connection failed. +* +* DataPDUInOrder=No for DataSequenceInOrder=[Yes,No]: +* +* While processing non-complete R2T DataOUT sequence requests +* the Target will re-request the entire DataOUT sequence if +* any single PDU is missing from the sequence. This is because +* we have no logical method to determine the next PDU offset, +* and we must assume the Initiator will be sending any random +* PDU offset in the current sequence after TASK_REASSIGN +* has completed. +*/ +if (conn->sess->sess_ops->DataSequenceInOrder) { +if (!first_incomplete_r2t) { + cmd->r2t_offset -= r2t->xfer_len; + goto next; + } + +if (conn->sess->sess_ops->DataPDUInOrder) { + cmd->data_sn =0 ; + cmd->r2t_offset -= (r2t->xfer_len - + cmd->next_burst_len); + first_incomplete_r2t =0 ; + goto next; + } + + cmd->data_sn =0 ; + cmd->r2t_offset -= r2t->xfer_len; + +for (i =0 ; i < cmd->pdu_count; i++) { + pdu = &cmd->pdu_list[i]; + +if (pdu->status !=ISCSI_PDU_RECEIVED_OK ) +continue ; + +if ((pdu->offset >= r2t->offset) && + (pdu->offset < (r2t->offset + + r2t->xfer_len))) { + cmd->next_burst_len -= pdu->length; + cmd->write_data_done -= pdu->length; + pdu->status =ISCSI_PDU_NOT_RECEIVED ; + } + } + + first_incomplete_r2t =0 ; + }else { +struct iscsi_seq *seq; + + seq =iscsi_get_seq_holder (cmd, r2t->offset, + r2t->xfer_len); +if (!seq) { +spin_unlock_bh (&cmd->r2t_lock); +return -1 ; + } + + cmd->write_data_done -= + (seq->offset - seq->orig_offset); + seq->data_sn =0 ; + seq->offset = seq->orig_offset; + seq->next_burst_len =0 ; + seq->status =DATAOUT_SEQUENCE_WITHIN_COMMAND_RECOVERY ; + + cmd->seq_send_order--; + +if (conn->sess->sess_ops->DataPDUInOrder) + goto next; + +for (i =0 ; i < seq->pdu_count; i++) { + pdu = &cmd->pdu_list[i+seq->pdu_start]; + +if (pdu->status !=ISCSI_PDU_RECEIVED_OK ) +continue ; + + pdu->status =ISCSI_PDU_NOT_RECEIVED ; + } + } + +next: + cmd->outstanding_r2ts--; + } +spin_unlock_bh (&cmd->r2t_lock); + +/* +* We now drop all unacknowledged R2Ts, ie: ExpDataSN from TMR +* TASK_REASSIGN to the last R2T in the list.. We are also careful +* to check that the Initiator is not requesting R2Ts for DataOUT +* sequences it has already completed. +* +* Free each R2T in question and adjust values in struct iscsi_cmd +* accordingly so iscsi_build_r2ts_for_cmd() do the rest of +* the work after the TMR TASK_REASSIGN Response is sent. +*/ +drop_unacknowledged_r2ts: + + cmd->cmd_flags &= ~ICF_SENT_LAST_R2T ; + cmd->r2t_sn = tmr_req->exp_data_sn; + +spin_lock_bh (&cmd->r2t_lock); +list_for_each_entry_safe (r2t, r2t_tmp, &cmd->cmd_r2t_list, r2t_list) { +/* +* Skip up to the R2T Sequence number provided by the +* iSCSI TASK_REASSIGN TMR +*/ +if (r2t->r2t_sn < tmr_req->exp_data_sn) +continue ; + +if (r2t->seq_complete) { +printk (KERN_ERR "Initiator is requesting R2Ts from" +" R2TSN: 0x%08x, but R2TSN: 0x%08x, Offset: %u," +" Length: %u is already complete." +" BAD INITIATOR ERL=2 IMPLEMENTATION!\n" , + tmr_req->exp_data_sn, r2t->r2t_sn, + r2t->offset, r2t->xfer_len); +spin_unlock_bh (&cmd->r2t_lock); +return -1 ; + } + +if (r2t->recovery_r2t) { +iscsi_free_r2t (r2t, cmd); +continue ; + } + +/* DataSequenceInOrder=Yes: +* +* Taking into account the iSCSI implementation requirement of +* MaxOutstandingR2T=1 while ErrorRecoveryLevel>0 and +* DataSequenceInOrder=Yes, it's safe to subtract the R2Ts +* entire transfer length from the commands R2T offset marker. +* +* DataSequenceInOrder=No: +* +* We subtract the difference from struct iscsi_seq between the +* current offset and original offset from cmd->write_data_done +* for account for DataOUT PDUs already received. Then reset +* the current offset to the original and zero out the current +* burst length, to make sure we re-request the entire DataOUT +* sequence. +*/ +if (conn->sess->sess_ops->DataSequenceInOrder) + cmd->r2t_offset -= r2t->xfer_len; +else + cmd->seq_send_order--; + + cmd->outstanding_r2ts--; +iscsi_free_r2t (r2t, cmd); + } +spin_unlock_bh (&cmd->r2t_lock); + +return 0 ; +} + +/* iscsi_check_task_reassign_expdatasn(): +* +* Performs sanity checks TMR TASK_REASSIGN's ExpDataSN for +* a given struct iscsi_cmd. +*/ +int iscsi_check_task_reassign_expdatasn ( +struct iscsi_tmr_req *tmr_req, +struct iscsi_conn *conn) +{ +struct se_tmr_req *se_tmr = tmr_req->se_tmr_req; +struct se_cmd *se_cmd = se_tmr->ref_cmd; + struct iscsi_cmd *ref_cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); + +if (ref_cmd->iscsi_opcode !=ISCSI_OP_SCSI_CMD ) +return 0 ; + +if (se_cmd->se_cmd_flags &SCF_SENT_CHECK_CONDITION ) +return 0 ; + +if (ref_cmd->data_direction ==DMA_NONE ) +return 0 ; + +/* +* For READs the TMR TASK_REASSIGNs ExpDataSN contains the next DataSN +* of DataIN the Initiator is expecting. +* +* Also check that the Initiator is not re-requesting DataIN that has +* already been acknowledged with a DataAck SNACK. +*/ +if (ref_cmd->data_direction ==DMA_FROM_DEVICE ) { +if (tmr_req->exp_data_sn > ref_cmd->data_sn) { +printk (KERN_ERR "Received ExpDataSN: 0x%08x for READ" +" in TMR TASK_REASSIGN greater than command's" +" DataSN: 0x%08x.\n" , tmr_req->exp_data_sn, + ref_cmd->data_sn); +return -1 ; + } +if ((ref_cmd->cmd_flags &ICF_GOT_DATACK_SNACK ) && + (tmr_req->exp_data_sn <= ref_cmd->acked_data_sn)) { +printk (KERN_ERR "Received ExpDataSN: 0x%08x for READ" +" in TMR TASK_REASSIGN for previously" +" acknowledged DataIN: 0x%08x," +" protocol error\n" , tmr_req->exp_data_sn, + ref_cmd->acked_data_sn); +return -1 ; + } +return iscsi_task_reassign_prepare_read (tmr_req, conn); + } + +/* +* For WRITEs the TMR TASK_REASSIGNs ExpDataSN contains the next R2TSN +* for R2Ts the Initiator is expecting. +* +* Do the magic in iscsi_task_reassign_prepare_write(). +*/ +if (ref_cmd->data_direction ==DMA_TO_DEVICE ) { +if (tmr_req->exp_data_sn > ref_cmd->r2t_sn) { +printk (KERN_ERR "Received ExpDataSN: 0x%08x for WRITE" +" in TMR TASK_REASSIGN greater than command's" +" R2TSN: 0x%08x.\n" , tmr_req->exp_data_sn, + ref_cmd->r2t_sn); +return -1 ; + } +return iscsi_task_reassign_prepare_write (tmr_req, conn); + } + +printk (KERN_ERR "Unknown iSCSI data_direction: 0x%02x\n" , + ref_cmd->data_direction); + +return -1 ; +}
drivers/target/iscsi/iscsi_target_tmr.h new file +16 -0
@@ -0,0 +1,16 @@ +#ifndef ISCSI_TARGET_TMR_H +#define ISCSI_TARGET_TMR_H + +extern u8 iscsi_tmr_abort_task (struct iscsi_cmd *,unsigned char *); +extern int iscsi_tmr_task_warm_reset (struct iscsi_conn *,struct iscsi_tmr_req *, +unsigned char *); +extern int iscsi_tmr_task_cold_reset (struct iscsi_conn *,struct iscsi_tmr_req *, +unsigned char *); +extern u8 iscsi_tmr_task_reassign (struct iscsi_cmd *,unsigned char *); +extern int iscsi_tmr_post_handler (struct iscsi_cmd *,struct iscsi_conn *); +extern int iscsi_check_task_reassign_expdatasn (struct iscsi_tmr_req *, +struct iscsi_conn *); + +extern int iscsi_build_r2ts_for_cmd (struct iscsi_cmd *,struct iscsi_conn *,int ); + +#endif /* ISCSI_TARGET_TMR_H */
Signature · 6 lines
1.7.4.1 -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
RFC v3 11/12 iscsi-target: Add misc utility and debug logic
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
This file adds iscsi_target_util.[c,h] code containing a number of miscellaneous utility functions for iscsi_target_mod including the following:
*) wrappers to TCM logic from iscsi_target.c for struct iscsi_cmd allocation
*) received iSCSI Command Sequence Number (CmdSN) processing *) Code for immediate / TX queues
*) Nopin Response + Response Timeout handlers
*) Primary sock_sendmsg() and sock_recvmsg() calls into Linux/Net *) iSCSI SendTargets
It also contains iscsi_debug.h macros for CONFIG_ISCSI_TARGET_DEBUG
--- drivers/target/iscsi/iscsi_target_debug.h | 113 ++ drivers/target/iscsi/iscsi_target_util.c | 2611 +++++++++++++++++++++++++++++ drivers/target/iscsi/iscsi_target_util.h | 127 ++ 3 files changed, 2851 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/iscsi_target_debug.h create mode 100644 drivers/target/iscsi/iscsi_target_util.c create mode 100644 drivers/target/iscsi/iscsi_target_util.h
drivers/target/iscsi/iscsi_target_debug.h new file +113 -0
@@ -0,0 +1,113 @@ +#ifndef ISCSI_DEBUG_H +#define ISCSI_DEBUG_H + +/* +* Debugging Support +*/ + +#define TRACE_DEBUG 0x00000001/* Verbose debugging */ +#define TRACE_SCSI 0x00000002/* Stuff related to SCSI Mid-layer */ +#define TRACE_ISCSI 0x00000004/* Stuff related to iSCSI */ +#define TRACE_NET 0x00000008/* Stuff related to network code */ +#define TRACE_BUFF 0x00000010/* For dumping raw data */ +#define TRACE_FILE 0x00000020/* Used for __FILE__ */ +#define TRACE_LINE 0x00000040/* Used for __LINE__ */ +#define TRACE_FUNCTION 0x00000080/* Used for __FUNCTION__ */ +#define TRACE_SEM 0x00000100/* Stuff related to semaphores */ +#define TRACE_ENTER_LEAVE 0x00000200/* For entering/leaving functions */ +#define TRACE_DIGEST 0x00000400/* For Header/Data Digests */ +#define TRACE_PARAM 0x00000800/* For parameters in parameters.c */ +#define TRACE_LOGIN 0x00001000/* For login related code */ +#define TRACE_STATE 0x00002000/* For conn/sess/cleanup states */ +#define TRACE_ERL0 0x00004000/* For ErrorRecoveryLevel=0 */ +#define TRACE_ERL1 0x00008000/* For ErrorRecoveryLevel=1 */ +#define TRACE_ERL2 0x00010000/* For ErrorRecoveryLevel=2 */ +#define TRACE_TIMER 0x00020000/* For various ERL timers */ +#define TRACE_R2T 0x00040000/* For R2T callers */ +#define TRACE_SPINDLE 0x00080000/* For Spindle callers */ +#define TRACE_SSLR 0x00100000/* For SyncNSteering RX */ +#define TRACE_SSLT 0x00200000/* For SyncNSteering TX */ +#define TRACE_CHANNEL 0x00400000/* For SCSI Channels */ +#define TRACE_CMDSN 0x00800000/* For Out of Order CmdSN execution */ +#define TRACE_NODEATTRIB 0x01000000/* For Initiator Nodes */ + +#define TRACE_VANITY 0x80000000/* For all Vanity Noise */ +#define TRACE_ALL 0xffffffff/* Turn on all flags */ +#define TRACE_ENDING 0x00000000/* foo */ + +#ifdef CONFIG_ISCSI_TARGET_DEBUG +/* +* TRACE_VANITY, is always last! +*/ +static unsigned int iscsi_trace = +/* TRACE_DEBUG | */ +/* TRACE_SCSI | */ +/* TRACE_ISCSI | */ +/* TRACE_NET | */ +/* TRACE_BUFF | */ +/* TRACE_FILE | */ +/* TRACE_LINE | */ +/* TRACE_FUNCTION | */ +/* TRACE_SEM | */ + +/* TRACE_DIGEST | */ +/* TRACE_PARAM | */ +/* TRACE_LOGIN | */ +/* TRACE_STATE | */ +TRACE_ERL0 | +TRACE_ERL1 | +TRACE_ERL2 | +/* TRACE_TIMER | */ +/* TRACE_R2T | */ +/* TRACE_SPINDLE | */ +/* TRACE_SSLR | */ +/* TRACE_SSLT | */ +/* TRACE_CHANNEL | */ +/* TRACE_CMDSN | */ +/* TRACE_NODEATTRIB | */ +TRACE_VANITY | +TRACE_ENDING ; + +#define TRACE(trace, args...) \ +{ \ +static char iscsi_trace_buff[256]; \ + \ +if (iscsi_trace & trace) { \ + sprintf(iscsi_trace_buff, args); \ + if (iscsi_trace & TRACE_FUNCTION) { \ + printk(KERN_INFO "%s:%d: %s", __func__, __LINE__, \ + iscsi_trace_buff); \ + } else if (iscsi_trace&TRACE_FILE) { \ + printk(KERN_INFO "%s::%d: %s", __FILE__, __LINE__, \ + iscsi_trace_buff); \ + } else if (iscsi_trace & TRACE_LINE) { \ + printk(KERN_INFO "%d: %s", __LINE__, iscsi_trace_buff); \ + } else { \ + printk(KERN_INFO "%s", iscsi_trace_buff); \ + } \ +} \ +} + +#define PRINT_BUFF (buff, len) \ +if (iscsi_trace & TRACE_BUFF) { \ + int zzz; \ + \ + printk(KERN_INFO "%d:\n", __LINE__); \ + for (zzz = 0; zzz < len; zzz++) { \ + if (zzz % 16 == 0) { \ + if (zzz) \ + printk(KERN_INFO "\n"); \ + printk(KERN_INFO "%4i: ", zzz); \ + } \ + printk(KERN_INFO "%02x ", (unsigned char) (buff)[zzz]); \ + } \ + if ((len + 1) % 16) \ + printk(KERN_INFO "\n"); \ +} + +#else /* !CONFIG_ISCSI_TARGET_DEBUG */ +#define TRACE(trace, args...) +#define PRINT_BUFF (buff, len) +#endif /* CONFIG_ISCSI_TARGET_DEBUG */ + +#endif /*** ISCSI_DEBUG_H ***/
drivers/target/iscsi/iscsi_target_util.c new file +2611 -0
2,611 lines not on this page · raw message
drivers/target/iscsi/iscsi_target_util.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
1.7.4.1
RFC v3 12/12 iscsi-target: Add Makefile/Kconfig and update TCM top level
In reply to Nicholas A. BellingerFrom: Nicholas Bellinger <[email protected]>
Add Makefile/Kconfig and update drivers/target/[Makefile,Kconfig] to include the fabric module.
--- drivers/target/Kconfig | 1 + drivers/target/Makefile | 1 + drivers/target/iscsi/Kconfig | 17 +++++++++++++++++ drivers/target/iscsi/Makefile | 20 ++++++++++++++++++++ 4 files changed, 39 insertions(+), 0 deletions(-) create mode 100644 drivers/target/iscsi/Kconfig create mode 100644 drivers/target/iscsi/Makefile
drivers/target/Kconfig +1 -0
@@ -30,5 +30,6 @@ config TCM_PSCSI passthrough access to Linux/SCSI device source "drivers/target/loopback/Kconfig" +source "drivers/target/iscsi/Kconfig" endif
drivers/target/Makefile +1 -0
@@ -24,3 +24,4 @@ obj-$(CONFIG_TCM_PSCSI) += target_core_pscsi.o # Fabric modules obj-$(CONFIG_LOOPBACK_TARGET) += loopback/ +obj-$(CONFIG_ISCSI_TARGET) += iscsi/
drivers/target/iscsi/Kconfig new file +17 -0
@@ -0,0 +1,17 @@ +config ISCSI_TARGET + tristate "Linux-iSCSI.org iSCSI Target Mode Stack" + select CRYPTO + select CRYPTO_CRC32C + select CRYPTO_CRC32C_INTEL if X86 + help + Say Y here to enable the ConfigFS enabled Linux-iSCSI.org iSCSI + Target Mode Stack. + +if ISCSI_TARGET + +config ISCSI_TARGET_DEBUG + bool "LIO-Target iscsi_debug.h ring buffer messages" + help + Say Y here to enable the legacy DEBUG_ISCSI macros in iscsi_debug.h + +endif
drivers/target/iscsi/Makefile new file +20 -0
@@ -0,0 +1,20 @@ +iscsi_target_mod-y += iscsi_target_parameters.o \ + iscsi_target_seq_pdu_list.o \ + iscsi_target_tq.o \ + iscsi_target_auth.o \ + iscsi_target_datain_values.o \ + iscsi_target_device.o \ + iscsi_target_erl0.o \ + iscsi_target_erl1.o \ + iscsi_target_erl2.o \ + iscsi_target_login.o \ + iscsi_target_nego.o \ + iscsi_target_nodeattrib.o \ + iscsi_target_tmr.o \ + iscsi_target_tpg.o \ + iscsi_target_util.o \ + iscsi_target.o \ + iscsi_target_configfs.o \ + iscsi_target_stat.o + +obj-$(CONFIG_ISCSI_TARGET) += iscsi_target_mod.o
Signature · 1 line
1.7.4.1