mirror of
https://github.com/armbian/linux.git
synced 2026-01-06 10:13:00 -08:00
iscsi-target: Add iSCSI fabric support for target v4.1
The Linux-iSCSI.org target module is a full featured in-kernel software implementation of iSCSI target mode (RFC-3720) for the current WIP mainline target v4.1 infrastructure code for the v3.1 kernel. More information can be found here: http://linux-iscsi.org/wiki/ISCSI This includes support for: * RFC-3720 defined request / response state machines and support for all defined iSCSI operation codes from Section 10.2.1.2 using libiscsi include/scsi/iscsi_proto.h PDU definitions * Target v4.1 compatible control plane using the generic layout in target_core_fabric_configfs.c and fabric dependent attributes within /sys/kernel/config/target/iscsi/ subdirectories. * Target v4.1 compatible iSCSI statistics based on RFC-4544 (iSCSI MIBS) * Support for IPv6 and IPv4 network portals in M:N mapping to TPGs * iSCSI Error Recovery Hierarchy support * Per iSCSI connection RX/TX thread pair scheduling affinity * crc32c + crc32c_intel SSEv4 instruction offload support using libcrypto * CHAP Authentication support using libcrypto * Conversion to use internal SGl allocation with iscsit_alloc_buffs() -> transport_generic_map_mem_to_cmd() (nab: Fix iscsi_proto.h struct scsi_lun usage from linux-next in commit: iscsi: Use struct scsi_lun in iscsi structs instead of u8[8]) (nab: Fix 32-bit compile warnings) Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Andy Grover <agrover@redhat.com> Acked-by: Roland Dreier <roland@kernel.org> Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
This commit is contained in:
@@ -31,5 +31,6 @@ config TCM_PSCSI
|
||||
|
||||
source "drivers/target/loopback/Kconfig"
|
||||
source "drivers/target/tcm_fc/Kconfig"
|
||||
source "drivers/target/iscsi/Kconfig"
|
||||
|
||||
endif
|
||||
|
||||
@@ -24,5 +24,5 @@ obj-$(CONFIG_TCM_PSCSI) += target_core_pscsi.o
|
||||
|
||||
# Fabric modules
|
||||
obj-$(CONFIG_LOOPBACK_TARGET) += loopback/
|
||||
|
||||
obj-$(CONFIG_TCM_FC) += tcm_fc/
|
||||
obj-$(CONFIG_ISCSI_TARGET) += iscsi/
|
||||
|
||||
8
drivers/target/iscsi/Kconfig
Normal file
8
drivers/target/iscsi/Kconfig
Normal file
@@ -0,0 +1,8 @@
|
||||
config ISCSI_TARGET
|
||||
tristate "Linux-iSCSI.org iSCSI Target Mode Stack"
|
||||
select CRYPTO
|
||||
select CRYPTO_CRC32C
|
||||
select CRYPTO_CRC32C_INTEL if X86
|
||||
help
|
||||
Say M here to enable the ConfigFS enabled Linux-iSCSI.org iSCSI
|
||||
Target Mode Stack.
|
||||
20
drivers/target/iscsi/Makefile
Normal file
20
drivers/target/iscsi/Makefile
Normal file
@@ -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
|
||||
4559
drivers/target/iscsi/iscsi_target.c
Normal file
4559
drivers/target/iscsi/iscsi_target.c
Normal file
File diff suppressed because it is too large
Load Diff
42
drivers/target/iscsi/iscsi_target.h
Normal file
42
drivers/target/iscsi/iscsi_target.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#ifndef ISCSI_TARGET_H
|
||||
#define ISCSI_TARGET_H
|
||||
|
||||
extern struct iscsi_tiqn *iscsit_get_tiqn_for_login(unsigned char *);
|
||||
extern struct iscsi_tiqn *iscsit_get_tiqn(unsigned char *, int);
|
||||
extern void iscsit_put_tiqn_for_login(struct iscsi_tiqn *);
|
||||
extern struct iscsi_tiqn *iscsit_add_tiqn(unsigned char *);
|
||||
extern void iscsit_del_tiqn(struct iscsi_tiqn *);
|
||||
extern int iscsit_access_np(struct iscsi_np *, struct iscsi_portal_group *);
|
||||
extern int iscsit_deaccess_np(struct iscsi_np *, struct iscsi_portal_group *);
|
||||
extern struct iscsi_np *iscsit_add_np(struct __kernel_sockaddr_storage *,
|
||||
char *, int);
|
||||
extern int iscsit_reset_np_thread(struct iscsi_np *, struct iscsi_tpg_np *,
|
||||
struct iscsi_portal_group *);
|
||||
extern int iscsit_del_np(struct iscsi_np *);
|
||||
extern int iscsit_add_reject_from_cmd(u8, int, int, unsigned char *, struct iscsi_cmd *);
|
||||
extern int iscsit_logout_closesession(struct iscsi_cmd *, struct iscsi_conn *);
|
||||
extern int iscsit_logout_closeconnection(struct iscsi_cmd *, struct iscsi_conn *);
|
||||
extern int iscsit_logout_removeconnforrecovery(struct iscsi_cmd *, struct iscsi_conn *);
|
||||
extern int iscsit_send_async_msg(struct iscsi_conn *, u16, u8, u8);
|
||||
extern int iscsit_send_r2t(struct iscsi_cmd *, struct iscsi_conn *);
|
||||
extern int iscsit_build_r2ts_for_cmd(struct iscsi_cmd *, struct iscsi_conn *, int);
|
||||
extern void iscsit_thread_get_cpumask(struct iscsi_conn *);
|
||||
extern int iscsi_target_tx_thread(void *);
|
||||
extern int iscsi_target_rx_thread(void *);
|
||||
extern int iscsit_close_connection(struct iscsi_conn *);
|
||||
extern int iscsit_close_session(struct iscsi_session *);
|
||||
extern void iscsit_fail_session(struct iscsi_session *);
|
||||
extern int iscsit_free_session(struct iscsi_session *);
|
||||
extern void iscsit_stop_session(struct iscsi_session *, int, int);
|
||||
extern int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *, int);
|
||||
|
||||
extern struct iscsit_global *iscsit_global;
|
||||
extern struct target_fabric_configfs *lio_target_fabric_configfs;
|
||||
|
||||
extern struct kmem_cache *lio_dr_cache;
|
||||
extern struct kmem_cache *lio_ooo_cache;
|
||||
extern struct kmem_cache *lio_cmd_cache;
|
||||
extern struct kmem_cache *lio_qr_cache;
|
||||
extern struct kmem_cache *lio_r2t_cache;
|
||||
|
||||
#endif /*** ISCSI_TARGET_H ***/
|
||||
490
drivers/target/iscsi/iscsi_target_auth.c
Normal file
490
drivers/target/iscsi/iscsi_target_auth.c
Normal file
@@ -0,0 +1,490 @@
|
||||
/*******************************************************************************
|
||||
* This file houses the main functions for the iSCSI CHAP support
|
||||
*
|
||||
* \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
|
||||
*
|
||||
* Licensed to the Linux Foundation under the General Public License (GPL) version 2.
|
||||
*
|
||||
* Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
******************************************************************************/
|
||||
|
||||
#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"
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
static int chap_string_to_hex(unsigned char *dst, unsigned char *src, int len)
|
||||
{
|
||||
int i, j = 0;
|
||||
|
||||
for (i = 0; i < len; i += 2) {
|
||||
dst[j++] = (unsigned char) chap_asciihex_to_binaryhex(&src[i]);
|
||||
}
|
||||
|
||||
dst[j] = '\0';
|
||||
return j;
|
||||
}
|
||||
|
||||
static 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);
|
||||
}
|
||||
}
|
||||
|
||||
static 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 void 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;
|
||||
|
||||
pr_debug("[%s] Sending CHAP_C=0x%s\n\n", (caller) ? "server" : "client",
|
||||
challenge_asciihex);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if (!(auth->naf_flags & NAF_USERID_SET) ||
|
||||
!(auth->naf_flags & NAF_PASSWORD_SET)) {
|
||||
pr_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)) {
|
||||
pr_err("CHAP_A is not MD5.\n");
|
||||
return NULL;
|
||||
}
|
||||
pr_debug("[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;
|
||||
pr_debug("[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;
|
||||
pr_debug("[server] Sending CHAP_I=%d\n", chap->id);
|
||||
/*
|
||||
* Generate Challenge.
|
||||
*/
|
||||
chap_gen_challenge(conn, 1, aic_str, aic_len);
|
||||
|
||||
return chap;
|
||||
}
|
||||
|
||||
static void chap_close(struct iscsi_conn *conn)
|
||||
{
|
||||
kfree(conn->auth_protocol);
|
||||
conn->auth_protocol = NULL;
|
||||
}
|
||||
|
||||
static 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 = NULL;
|
||||
unsigned char *challenge_binhex = NULL;
|
||||
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) {
|
||||
pr_err("Unable to allocate challenge buffer\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
challenge_binhex = kzalloc(CHAP_CHALLENGE_STR_LEN, GFP_KERNEL);
|
||||
if (!challenge_binhex) {
|
||||
pr_err("Unable to allocate challenge_binhex buffer\n");
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Extract CHAP_N.
|
||||
*/
|
||||
if (extract_param(nr_in_ptr, "CHAP_N", MAX_CHAP_N_SIZE, chap_n,
|
||||
&type) < 0) {
|
||||
pr_err("Could not find CHAP_N.\n");
|
||||
goto out;
|
||||
}
|
||||
if (type == HEX) {
|
||||
pr_err("Could not find CHAP_N.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (memcmp(chap_n, auth->userid, strlen(auth->userid)) != 0) {
|
||||
pr_err("CHAP_N values do not match!\n");
|
||||
goto out;
|
||||
}
|
||||
pr_debug("[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) {
|
||||
pr_err("Could not find CHAP_R.\n");
|
||||
goto out;
|
||||
}
|
||||
if (type != HEX) {
|
||||
pr_err("Could not find CHAP_R.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
pr_debug("[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)) {
|
||||
pr_err("Unable to allocate struct crypto_hash\n");
|
||||
goto out;
|
||||
}
|
||||
desc.tfm = tfm;
|
||||
desc.flags = 0;
|
||||
|
||||
ret = crypto_hash_init(&desc);
|
||||
if (ret < 0) {
|
||||
pr_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) {
|
||||
pr_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) {
|
||||
pr_err("crypto_hash_update() failed for password\n");
|
||||
crypto_free_hash(tfm);
|
||||
goto out;
|
||||
}
|
||||
|
||||
sg_init_one(&sg, (void *)chap->challenge, CHAP_CHALLENGE_LENGTH);
|
||||
ret = crypto_hash_update(&desc, &sg, CHAP_CHALLENGE_LENGTH);
|
||||
if (ret < 0) {
|
||||
pr_err("crypto_hash_update() failed for challenge\n");
|
||||
crypto_free_hash(tfm);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = crypto_hash_final(&desc, server_digest);
|
||||
if (ret < 0) {
|
||||
pr_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);
|
||||
pr_debug("[server] MD5 Server Digest: %s\n", response);
|
||||
|
||||
if (memcmp(server_digest, client_digest, MD5_SIGNATURE_SIZE) != 0) {
|
||||
pr_debug("[server] MD5 Digests do not match!\n\n");
|
||||
goto out;
|
||||
} else
|
||||
pr_debug("[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) {
|
||||
pr_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).
|
||||
*/
|
||||
pr_debug("[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) {
|
||||
pr_err("Could not find CHAP_C.\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (type != HEX) {
|
||||
pr_err("Could not find CHAP_C.\n");
|
||||
goto out;
|
||||
}
|
||||
pr_debug("[server] Got CHAP_C=%s\n", challenge);
|
||||
challenge_len = chap_string_to_hex(challenge_binhex, challenge,
|
||||
strlen(challenge));
|
||||
if (!challenge_len) {
|
||||
pr_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)) {
|
||||
pr_err("Unable to allocate struct crypto_hash\n");
|
||||
goto out;
|
||||
}
|
||||
desc.tfm = tfm;
|
||||
desc.flags = 0;
|
||||
|
||||
ret = crypto_hash_init(&desc);
|
||||
if (ret < 0) {
|
||||
pr_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) {
|
||||
pr_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) {
|
||||
pr_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) {
|
||||
pr_err("crypto_hash_update() failed for ma challenge\n");
|
||||
crypto_free_hash(tfm);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = crypto_hash_final(&desc, digest);
|
||||
if (ret < 0) {
|
||||
pr_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;
|
||||
pr_debug("[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;
|
||||
pr_debug("[server] Sending CHAP_R=0x%s\n", response);
|
||||
auth_ret = 0;
|
||||
out:
|
||||
kfree(challenge);
|
||||
kfree(challenge_binhex);
|
||||
return auth_ret;
|
||||
}
|
||||
|
||||
static 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;
|
||||
return 0;
|
||||
default:
|
||||
pr_err("Unknown CHAP digest type %d!\n",
|
||||
chap->digest_type);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
31
drivers/target/iscsi/iscsi_target_auth.h
Normal file
31
drivers/target/iscsi/iscsi_target_auth.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#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 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 authenticate_target;
|
||||
unsigned int chap_state;
|
||||
} ____cacheline_aligned;
|
||||
|
||||
#endif /*** _ISCSI_CHAP_H_ ***/
|
||||
1882
drivers/target/iscsi/iscsi_target_configfs.c
Normal file
1882
drivers/target/iscsi/iscsi_target_configfs.c
Normal file
File diff suppressed because it is too large
Load Diff
7
drivers/target/iscsi/iscsi_target_configfs.h
Normal file
7
drivers/target/iscsi/iscsi_target_configfs.h
Normal file
@@ -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 */
|
||||
859
drivers/target/iscsi/iscsi_target_core.h
Normal file
859
drivers/target/iscsi/iscsi_target_core.h
Normal file
File diff suppressed because it is too large
Load Diff
531
drivers/target/iscsi/iscsi_target_datain_values.c
Normal file
531
drivers/target/iscsi/iscsi_target_datain_values.c
Normal file
File diff suppressed because it is too large
Load Diff
12
drivers/target/iscsi/iscsi_target_datain_values.h
Normal file
12
drivers/target/iscsi/iscsi_target_datain_values.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef ISCSI_TARGET_DATAIN_VALUES_H
|
||||
#define ISCSI_TARGET_DATAIN_VALUES_H
|
||||
|
||||
extern struct iscsi_datain_req *iscsit_allocate_datain_req(void);
|
||||
extern void iscsit_attach_datain_req(struct iscsi_cmd *, struct iscsi_datain_req *);
|
||||
extern void iscsit_free_datain_req(struct iscsi_cmd *, struct iscsi_datain_req *);
|
||||
extern void iscsit_free_all_datain_reqs(struct iscsi_cmd *);
|
||||
extern struct iscsi_datain_req *iscsit_get_datain_req(struct iscsi_cmd *);
|
||||
extern struct iscsi_datain_req *iscsit_get_datain_values(struct iscsi_cmd *,
|
||||
struct iscsi_datain *);
|
||||
|
||||
#endif /*** ISCSI_TARGET_DATAIN_VALUES_H ***/
|
||||
87
drivers/target/iscsi/iscsi_target_device.c
Normal file
87
drivers/target/iscsi/iscsi_target_device.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*******************************************************************************
|
||||
* This file contains the iSCSI Virtual Device and Disk Transport
|
||||
* agnostic related functions.
|
||||
*
|
||||
\u00a9 Copyright 2007-2011 RisingTide Systems LLC.
|
||||
*
|
||||
* Licensed to the Linux Foundation under the General Public License (GPL) version 2.
|
||||
*
|
||||
* Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
******************************************************************************/
|
||||
|
||||
#include <scsi/scsi_device.h>
|
||||
#include <target/target_core_base.h>
|
||||
#include <target/target_core_device.h>
|
||||
#include <target/target_core_transport.h>
|
||||
|
||||
#include "iscsi_target_core.h"
|
||||
#include "iscsi_target_device.h"
|
||||
#include "iscsi_target_tpg.h"
|
||||
#include "iscsi_target_util.h"
|
||||
|
||||
int iscsit_get_lun_for_tmr(
|
||||
struct iscsi_cmd *cmd,
|
||||
u64 lun)
|
||||
{
|
||||
u32 unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun);
|
||||
|
||||
return transport_lookup_tmr_lun(&cmd->se_cmd, unpacked_lun);
|
||||
}
|
||||
|
||||
int iscsit_get_lun_for_cmd(
|
||||
struct iscsi_cmd *cmd,
|
||||
unsigned char *cdb,
|
||||
u64 lun)
|
||||
{
|
||||
u32 unpacked_lun = scsilun_to_int((struct scsi_lun *)&lun);
|
||||
|
||||
return transport_lookup_cmd_lun(&cmd->se_cmd, unpacked_lun);
|
||||
}
|
||||
|
||||
void iscsit_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;
|
||||
}
|
||||
|
||||
void iscsit_increment_maxcmdsn(struct iscsi_cmd *cmd, struct iscsi_session *sess)
|
||||
{
|
||||
if (cmd->immediate_cmd || cmd->maxcmdsn_inc)
|
||||
return;
|
||||
|
||||
cmd->maxcmdsn_inc = 1;
|
||||
|
||||
mutex_lock(&sess->cmdsn_mutex);
|
||||
sess->max_cmd_sn += 1;
|
||||
pr_debug("Updated MaxCmdSN to 0x%08x\n", sess->max_cmd_sn);
|
||||
mutex_unlock(&sess->cmdsn_mutex);
|
||||
}
|
||||
9
drivers/target/iscsi/iscsi_target_device.h
Normal file
9
drivers/target/iscsi/iscsi_target_device.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef ISCSI_TARGET_DEVICE_H
|
||||
#define ISCSI_TARGET_DEVICE_H
|
||||
|
||||
extern int iscsit_get_lun_for_tmr(struct iscsi_cmd *, u64);
|
||||
extern int iscsit_get_lun_for_cmd(struct iscsi_cmd *, unsigned char *, u64);
|
||||
extern void iscsit_determine_maxcmdsn(struct iscsi_session *);
|
||||
extern void iscsit_increment_maxcmdsn(struct iscsi_cmd *, struct iscsi_session *);
|
||||
|
||||
#endif /* ISCSI_TARGET_DEVICE_H */
|
||||
1004
drivers/target/iscsi/iscsi_target_erl0.c
Normal file
1004
drivers/target/iscsi/iscsi_target_erl0.c
Normal file
File diff suppressed because it is too large
Load Diff
15
drivers/target/iscsi/iscsi_target_erl0.h
Normal file
15
drivers/target/iscsi/iscsi_target_erl0.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef ISCSI_TARGET_ERL0_H
|
||||
#define ISCSI_TARGET_ERL0_H
|
||||
|
||||
extern void iscsit_set_dataout_sequence_values(struct iscsi_cmd *);
|
||||
extern int iscsit_check_pre_dataout(struct iscsi_cmd *, unsigned char *);
|
||||
extern int iscsit_check_post_dataout(struct iscsi_cmd *, unsigned char *, u8);
|
||||
extern void iscsit_start_time2retain_handler(struct iscsi_session *);
|
||||
extern int iscsit_stop_time2retain_timer(struct iscsi_session *);
|
||||
extern void iscsit_connection_reinstatement_rcfr(struct iscsi_conn *);
|
||||
extern void iscsit_cause_connection_reinstatement(struct iscsi_conn *, int);
|
||||
extern void iscsit_fall_back_to_erl0(struct iscsi_session *);
|
||||
extern void iscsit_take_action_for_connection_exit(struct iscsi_conn *);
|
||||
extern int iscsit_recover_from_unknown_opcode(struct iscsi_conn *);
|
||||
|
||||
#endif /*** ISCSI_TARGET_ERL0_H ***/
|
||||
1299
drivers/target/iscsi/iscsi_target_erl1.c
Normal file
1299
drivers/target/iscsi/iscsi_target_erl1.c
Normal file
File diff suppressed because it is too large
Load Diff
26
drivers/target/iscsi/iscsi_target_erl1.h
Normal file
26
drivers/target/iscsi/iscsi_target_erl1.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef ISCSI_TARGET_ERL1_H
|
||||
#define ISCSI_TARGET_ERL1_H
|
||||
|
||||
extern int iscsit_dump_data_payload(struct iscsi_conn *, u32, int);
|
||||
extern int iscsit_create_recovery_datain_values_datasequenceinorder_yes(
|
||||
struct iscsi_cmd *, struct iscsi_datain_req *);
|
||||
extern int iscsit_create_recovery_datain_values_datasequenceinorder_no(
|
||||
struct iscsi_cmd *, struct iscsi_datain_req *);
|
||||
extern int iscsit_handle_recovery_datain_or_r2t(struct iscsi_conn *, unsigned char *,
|
||||
u32, u32, u32, u32);
|
||||
extern int iscsit_handle_status_snack(struct iscsi_conn *, u32, u32,
|
||||
u32, u32);
|
||||
extern int iscsit_handle_data_ack(struct iscsi_conn *, u32, u32, u32);
|
||||
extern int iscsit_dataout_datapduinorder_no_fbit(struct iscsi_cmd *, struct iscsi_pdu *);
|
||||
extern int iscsit_recover_dataout_sequence(struct iscsi_cmd *, u32, u32);
|
||||
extern void iscsit_clear_ooo_cmdsns_for_conn(struct iscsi_conn *);
|
||||
extern void iscsit_free_all_ooo_cmdsns(struct iscsi_session *);
|
||||
extern int iscsit_execute_ooo_cmdsns(struct iscsi_session *);
|
||||
extern int iscsit_execute_cmd(struct iscsi_cmd *, int);
|
||||
extern int iscsit_handle_ooo_cmdsn(struct iscsi_session *, struct iscsi_cmd *, u32);
|
||||
extern void iscsit_remove_ooo_cmdsn(struct iscsi_session *, struct iscsi_ooo_cmdsn *);
|
||||
extern void iscsit_mod_dataout_timer(struct iscsi_cmd *);
|
||||
extern void iscsit_start_dataout_timer(struct iscsi_cmd *, struct iscsi_conn *);
|
||||
extern void iscsit_stop_dataout_timer(struct iscsi_cmd *);
|
||||
|
||||
#endif /* ISCSI_TARGET_ERL1_H */
|
||||
474
drivers/target/iscsi/iscsi_target_erl2.c
Normal file
474
drivers/target/iscsi/iscsi_target_erl2.c
Normal file
@@ -0,0 +1,474 @@
|
||||
/*******************************************************************************
|
||||
* This file contains error recovery level two functions used by
|
||||
* the iSCSI Target driver.
|
||||
*
|
||||
* \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
|
||||
*
|
||||
* Licensed to the Linux Foundation under the General Public License (GPL) version 2.
|
||||
*
|
||||
* Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
******************************************************************************/
|
||||
|
||||
#include <scsi/iscsi_proto.h>
|
||||
#include <target/target_core_base.h>
|
||||
#include <target/target_core_transport.h>
|
||||
|
||||
#include "iscsi_target_core.h"
|
||||
#include "iscsi_target_datain_values.h"
|
||||
#include "iscsi_target_util.h"
|
||||
#include "iscsi_target_erl0.h"
|
||||
#include "iscsi_target_erl1.h"
|
||||
#include "iscsi_target_erl2.h"
|
||||
#include "iscsi_target.h"
|
||||
|
||||
/*
|
||||
* FIXME: Does RData SNACK apply here as well?
|
||||
*/
|
||||
void iscsit_create_conn_recovery_datain_values(
|
||||
struct iscsi_cmd *cmd,
|
||||
u32 exp_data_sn)
|
||||
{
|
||||
u32 data_sn = 0;
|
||||
struct iscsi_conn *conn = cmd->conn;
|
||||
|
||||
cmd->next_burst_len = 0;
|
||||
cmd->read_data_done = 0;
|
||||
|
||||
while (exp_data_sn > data_sn) {
|
||||
if ((cmd->next_burst_len +
|
||||
conn->conn_ops->MaxRecvDataSegmentLength) <
|
||||
conn->sess->sess_ops->MaxBurstLength) {
|
||||
cmd->read_data_done +=
|
||||
conn->conn_ops->MaxRecvDataSegmentLength;
|
||||
cmd->next_burst_len +=
|
||||
conn->conn_ops->MaxRecvDataSegmentLength;
|
||||
} else {
|
||||
cmd->read_data_done +=
|
||||
(conn->sess->sess_ops->MaxBurstLength -
|
||||
cmd->next_burst_len);
|
||||
cmd->next_burst_len = 0;
|
||||
}
|
||||
data_sn++;
|
||||
}
|
||||
}
|
||||
|
||||
void iscsit_create_conn_recovery_dataout_values(
|
||||
struct iscsi_cmd *cmd)
|
||||
{
|
||||
u32 write_data_done = 0;
|
||||
struct iscsi_conn *conn = cmd->conn;
|
||||
|
||||
cmd->data_sn = 0;
|
||||
cmd->next_burst_len = 0;
|
||||
|
||||
while (cmd->write_data_done > write_data_done) {
|
||||
if ((write_data_done + conn->sess->sess_ops->MaxBurstLength) <=
|
||||
cmd->write_data_done)
|
||||
write_data_done += conn->sess->sess_ops->MaxBurstLength;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
cmd->write_data_done = write_data_done;
|
||||
}
|
||||
|
||||
static int iscsit_attach_active_connection_recovery_entry(
|
||||
struct iscsi_session *sess,
|
||||
struct iscsi_conn_recovery *cr)
|
||||
{
|
||||
spin_lock(&sess->cr_a_lock);
|
||||
list_add_tail(&cr->cr_list, &sess->cr_active_list);
|
||||
spin_unlock(&sess->cr_a_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iscsit_attach_inactive_connection_recovery_entry(
|
||||
struct iscsi_session *sess,
|
||||
struct iscsi_conn_recovery *cr)
|
||||
{
|
||||
spin_lock(&sess->cr_i_lock);
|
||||
list_add_tail(&cr->cr_list, &sess->cr_inactive_list);
|
||||
|
||||
sess->conn_recovery_count++;
|
||||
pr_debug("Incremented connection recovery count to %u for"
|
||||
" SID: %u\n", sess->conn_recovery_count, sess->sid);
|
||||
spin_unlock(&sess->cr_i_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct iscsi_conn_recovery *iscsit_get_inactive_connection_recovery_entry(
|
||||
struct iscsi_session *sess,
|
||||
u16 cid)
|
||||
{
|
||||
struct iscsi_conn_recovery *cr;
|
||||
|
||||
spin_lock(&sess->cr_i_lock);
|
||||
list_for_each_entry(cr, &sess->cr_inactive_list, cr_list) {
|
||||
if (cr->cid == cid) {
|
||||
spin_unlock(&sess->cr_i_lock);
|
||||
return cr;
|
||||
}
|
||||
}
|
||||
spin_unlock(&sess->cr_i_lock);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void iscsit_free_connection_recovery_entires(struct iscsi_session *sess)
|
||||
{
|
||||
struct iscsi_cmd *cmd, *cmd_tmp;
|
||||
struct iscsi_conn_recovery *cr, *cr_tmp;
|
||||
|
||||
spin_lock(&sess->cr_a_lock);
|
||||
list_for_each_entry_safe(cr, cr_tmp, &sess->cr_active_list, cr_list) {
|
||||
list_del(&cr->cr_list);
|
||||
spin_unlock(&sess->cr_a_lock);
|
||||
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
list_for_each_entry_safe(cmd, cmd_tmp,
|
||||
&cr->conn_recovery_cmd_list, i_list) {
|
||||
|
||||
list_del(&cmd->i_list);
|
||||
cmd->conn = NULL;
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) ||
|
||||
!(cmd->se_cmd.transport_wait_for_tasks))
|
||||
iscsit_release_cmd(cmd);
|
||||
else
|
||||
cmd->se_cmd.transport_wait_for_tasks(
|
||||
&cmd->se_cmd, 1, 1);
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
}
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
spin_lock(&sess->cr_a_lock);
|
||||
|
||||
kfree(cr);
|
||||
}
|
||||
spin_unlock(&sess->cr_a_lock);
|
||||
|
||||
spin_lock(&sess->cr_i_lock);
|
||||
list_for_each_entry_safe(cr, cr_tmp, &sess->cr_inactive_list, cr_list) {
|
||||
list_del(&cr->cr_list);
|
||||
spin_unlock(&sess->cr_i_lock);
|
||||
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
list_for_each_entry_safe(cmd, cmd_tmp,
|
||||
&cr->conn_recovery_cmd_list, i_list) {
|
||||
|
||||
list_del(&cmd->i_list);
|
||||
cmd->conn = NULL;
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) ||
|
||||
!(cmd->se_cmd.transport_wait_for_tasks))
|
||||
iscsit_release_cmd(cmd);
|
||||
else
|
||||
cmd->se_cmd.transport_wait_for_tasks(
|
||||
&cmd->se_cmd, 1, 1);
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
}
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
spin_lock(&sess->cr_i_lock);
|
||||
|
||||
kfree(cr);
|
||||
}
|
||||
spin_unlock(&sess->cr_i_lock);
|
||||
}
|
||||
|
||||
int iscsit_remove_active_connection_recovery_entry(
|
||||
struct iscsi_conn_recovery *cr,
|
||||
struct iscsi_session *sess)
|
||||
{
|
||||
spin_lock(&sess->cr_a_lock);
|
||||
list_del(&cr->cr_list);
|
||||
|
||||
sess->conn_recovery_count--;
|
||||
pr_debug("Decremented connection recovery count to %u for"
|
||||
" SID: %u\n", sess->conn_recovery_count, sess->sid);
|
||||
spin_unlock(&sess->cr_a_lock);
|
||||
|
||||
kfree(cr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iscsit_remove_inactive_connection_recovery_entry(
|
||||
struct iscsi_conn_recovery *cr,
|
||||
struct iscsi_session *sess)
|
||||
{
|
||||
spin_lock(&sess->cr_i_lock);
|
||||
list_del(&cr->cr_list);
|
||||
spin_unlock(&sess->cr_i_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called with cr->conn_recovery_cmd_lock help.
|
||||
*/
|
||||
int iscsit_remove_cmd_from_connection_recovery(
|
||||
struct iscsi_cmd *cmd,
|
||||
struct iscsi_session *sess)
|
||||
{
|
||||
struct iscsi_conn_recovery *cr;
|
||||
|
||||
if (!cmd->cr) {
|
||||
pr_err("struct iscsi_conn_recovery pointer for ITT: 0x%08x"
|
||||
" is NULL!\n", cmd->init_task_tag);
|
||||
BUG();
|
||||
}
|
||||
cr = cmd->cr;
|
||||
|
||||
list_del(&cmd->i_list);
|
||||
return --cr->cmd_count;
|
||||
}
|
||||
|
||||
void iscsit_discard_cr_cmds_by_expstatsn(
|
||||
struct iscsi_conn_recovery *cr,
|
||||
u32 exp_statsn)
|
||||
{
|
||||
u32 dropped_count = 0;
|
||||
struct iscsi_cmd *cmd, *cmd_tmp;
|
||||
struct iscsi_session *sess = cr->sess;
|
||||
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
list_for_each_entry_safe(cmd, cmd_tmp,
|
||||
&cr->conn_recovery_cmd_list, i_list) {
|
||||
|
||||
if (((cmd->deferred_i_state != ISTATE_SENT_STATUS) &&
|
||||
(cmd->deferred_i_state != ISTATE_REMOVE)) ||
|
||||
(cmd->stat_sn >= exp_statsn)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
dropped_count++;
|
||||
pr_debug("Dropping Acknowledged ITT: 0x%08x, StatSN:"
|
||||
" 0x%08x, CID: %hu.\n", cmd->init_task_tag,
|
||||
cmd->stat_sn, cr->cid);
|
||||
|
||||
iscsit_remove_cmd_from_connection_recovery(cmd, sess);
|
||||
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) ||
|
||||
!(cmd->se_cmd.transport_wait_for_tasks))
|
||||
iscsit_release_cmd(cmd);
|
||||
else
|
||||
cmd->se_cmd.transport_wait_for_tasks(
|
||||
&cmd->se_cmd, 1, 0);
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
}
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
|
||||
pr_debug("Dropped %u total acknowledged commands on"
|
||||
" CID: %hu less than old ExpStatSN: 0x%08x\n",
|
||||
dropped_count, cr->cid, exp_statsn);
|
||||
|
||||
if (!cr->cmd_count) {
|
||||
pr_debug("No commands to be reassigned for failed"
|
||||
" connection CID: %hu on SID: %u\n",
|
||||
cr->cid, sess->sid);
|
||||
iscsit_remove_inactive_connection_recovery_entry(cr, sess);
|
||||
iscsit_attach_active_connection_recovery_entry(sess, cr);
|
||||
pr_debug("iSCSI connection recovery successful for CID:"
|
||||
" %hu on SID: %u\n", cr->cid, sess->sid);
|
||||
iscsit_remove_active_connection_recovery_entry(cr, sess);
|
||||
} else {
|
||||
iscsit_remove_inactive_connection_recovery_entry(cr, sess);
|
||||
iscsit_attach_active_connection_recovery_entry(sess, cr);
|
||||
}
|
||||
}
|
||||
|
||||
int iscsit_discard_unacknowledged_ooo_cmdsns_for_conn(struct iscsi_conn *conn)
|
||||
{
|
||||
u32 dropped_count = 0;
|
||||
struct iscsi_cmd *cmd, *cmd_tmp;
|
||||
struct iscsi_ooo_cmdsn *ooo_cmdsn, *ooo_cmdsn_tmp;
|
||||
struct iscsi_session *sess = conn->sess;
|
||||
|
||||
mutex_lock(&sess->cmdsn_mutex);
|
||||
list_for_each_entry_safe(ooo_cmdsn, ooo_cmdsn_tmp,
|
||||
&sess->sess_ooo_cmdsn_list, ooo_list) {
|
||||
|
||||
if (ooo_cmdsn->cid != conn->cid)
|
||||
continue;
|
||||
|
||||
dropped_count++;
|
||||
pr_debug("Dropping unacknowledged CmdSN:"
|
||||
" 0x%08x during connection recovery on CID: %hu\n",
|
||||
ooo_cmdsn->cmdsn, conn->cid);
|
||||
iscsit_remove_ooo_cmdsn(sess, ooo_cmdsn);
|
||||
}
|
||||
mutex_unlock(&sess->cmdsn_mutex);
|
||||
|
||||
spin_lock_bh(&conn->cmd_lock);
|
||||
list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_list) {
|
||||
if (!(cmd->cmd_flags & ICF_OOO_CMDSN))
|
||||
continue;
|
||||
|
||||
list_del(&cmd->i_list);
|
||||
|
||||
spin_unlock_bh(&conn->cmd_lock);
|
||||
if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) ||
|
||||
!(cmd->se_cmd.transport_wait_for_tasks))
|
||||
iscsit_release_cmd(cmd);
|
||||
else
|
||||
cmd->se_cmd.transport_wait_for_tasks(
|
||||
&cmd->se_cmd, 1, 1);
|
||||
spin_lock_bh(&conn->cmd_lock);
|
||||
}
|
||||
spin_unlock_bh(&conn->cmd_lock);
|
||||
|
||||
pr_debug("Dropped %u total unacknowledged commands on CID:"
|
||||
" %hu for ExpCmdSN: 0x%08x.\n", dropped_count, conn->cid,
|
||||
sess->exp_cmd_sn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iscsit_prepare_cmds_for_realligance(struct iscsi_conn *conn)
|
||||
{
|
||||
u32 cmd_count = 0;
|
||||
struct iscsi_cmd *cmd, *cmd_tmp;
|
||||
struct iscsi_conn_recovery *cr;
|
||||
|
||||
/*
|
||||
* Allocate an struct iscsi_conn_recovery for this connection.
|
||||
* Each struct iscsi_cmd contains an struct iscsi_conn_recovery pointer
|
||||
* (struct iscsi_cmd->cr) so we need to allocate this before preparing the
|
||||
* connection's command list for connection recovery.
|
||||
*/
|
||||
cr = kzalloc(sizeof(struct iscsi_conn_recovery), GFP_KERNEL);
|
||||
if (!cr) {
|
||||
pr_err("Unable to allocate memory for"
|
||||
" struct iscsi_conn_recovery.\n");
|
||||
return -1;
|
||||
}
|
||||
INIT_LIST_HEAD(&cr->cr_list);
|
||||
INIT_LIST_HEAD(&cr->conn_recovery_cmd_list);
|
||||
spin_lock_init(&cr->conn_recovery_cmd_lock);
|
||||
/*
|
||||
* Only perform connection recovery on ISCSI_OP_SCSI_CMD or
|
||||
* ISCSI_OP_NOOP_OUT opcodes. For all other opcodes call
|
||||
* list_del(&cmd->i_list); to release the command to the
|
||||
* session pool and remove it from the connection's list.
|
||||
*
|
||||
* Also stop the DataOUT timer, which will be restarted after
|
||||
* sending the TMR response.
|
||||
*/
|
||||
spin_lock_bh(&conn->cmd_lock);
|
||||
list_for_each_entry_safe(cmd, cmd_tmp, &conn->conn_cmd_list, i_list) {
|
||||
|
||||
if ((cmd->iscsi_opcode != ISCSI_OP_SCSI_CMD) &&
|
||||
(cmd->iscsi_opcode != ISCSI_OP_NOOP_OUT)) {
|
||||
pr_debug("Not performing realligence on"
|
||||
" Opcode: 0x%02x, ITT: 0x%08x, CmdSN: 0x%08x,"
|
||||
" CID: %hu\n", cmd->iscsi_opcode,
|
||||
cmd->init_task_tag, cmd->cmd_sn, conn->cid);
|
||||
|
||||
list_del(&cmd->i_list);
|
||||
spin_unlock_bh(&conn->cmd_lock);
|
||||
|
||||
if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) ||
|
||||
!(cmd->se_cmd.transport_wait_for_tasks))
|
||||
iscsit_release_cmd(cmd);
|
||||
else
|
||||
cmd->se_cmd.transport_wait_for_tasks(
|
||||
&cmd->se_cmd, 1, 0);
|
||||
spin_lock_bh(&conn->cmd_lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* Special case where commands greater than or equal to
|
||||
* the session's ExpCmdSN are attached to the connection
|
||||
* list but not to the out of order CmdSN list. The one
|
||||
* obvious case is when a command with immediate data
|
||||
* attached must only check the CmdSN against ExpCmdSN
|
||||
* after the data is received. The special case below
|
||||
* is when the connection fails before data is received,
|
||||
* but also may apply to other PDUs, so it has been
|
||||
* made generic here.
|
||||
*/
|
||||
if (!(cmd->cmd_flags & ICF_OOO_CMDSN) && !cmd->immediate_cmd &&
|
||||
(cmd->cmd_sn >= conn->sess->exp_cmd_sn)) {
|
||||
list_del(&cmd->i_list);
|
||||
spin_unlock_bh(&conn->cmd_lock);
|
||||
|
||||
if (!(cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) ||
|
||||
!(cmd->se_cmd.transport_wait_for_tasks))
|
||||
iscsit_release_cmd(cmd);
|
||||
else
|
||||
cmd->se_cmd.transport_wait_for_tasks(
|
||||
&cmd->se_cmd, 1, 1);
|
||||
spin_lock_bh(&conn->cmd_lock);
|
||||
continue;
|
||||
}
|
||||
|
||||
cmd_count++;
|
||||
pr_debug("Preparing Opcode: 0x%02x, ITT: 0x%08x,"
|
||||
" CmdSN: 0x%08x, StatSN: 0x%08x, CID: %hu for"
|
||||
" realligence.\n", cmd->iscsi_opcode,
|
||||
cmd->init_task_tag, cmd->cmd_sn, cmd->stat_sn,
|
||||
conn->cid);
|
||||
|
||||
cmd->deferred_i_state = cmd->i_state;
|
||||
cmd->i_state = ISTATE_IN_CONNECTION_RECOVERY;
|
||||
|
||||
if (cmd->data_direction == DMA_TO_DEVICE)
|
||||
iscsit_stop_dataout_timer(cmd);
|
||||
|
||||
cmd->sess = conn->sess;
|
||||
|
||||
list_del(&cmd->i_list);
|
||||
spin_unlock_bh(&conn->cmd_lock);
|
||||
|
||||
iscsit_free_all_datain_reqs(cmd);
|
||||
|
||||
if ((cmd->se_cmd.se_cmd_flags & SCF_SE_LUN_CMD) &&
|
||||
cmd->se_cmd.transport_wait_for_tasks)
|
||||
cmd->se_cmd.transport_wait_for_tasks(&cmd->se_cmd,
|
||||
0, 0);
|
||||
/*
|
||||
* Add the struct iscsi_cmd to the connection recovery cmd list
|
||||
*/
|
||||
spin_lock(&cr->conn_recovery_cmd_lock);
|
||||
list_add_tail(&cmd->i_list, &cr->conn_recovery_cmd_list);
|
||||
spin_unlock(&cr->conn_recovery_cmd_lock);
|
||||
|
||||
spin_lock_bh(&conn->cmd_lock);
|
||||
cmd->cr = cr;
|
||||
cmd->conn = NULL;
|
||||
}
|
||||
spin_unlock_bh(&conn->cmd_lock);
|
||||
/*
|
||||
* Fill in the various values in the preallocated struct iscsi_conn_recovery.
|
||||
*/
|
||||
cr->cid = conn->cid;
|
||||
cr->cmd_count = cmd_count;
|
||||
cr->maxrecvdatasegmentlength = conn->conn_ops->MaxRecvDataSegmentLength;
|
||||
cr->sess = conn->sess;
|
||||
|
||||
iscsit_attach_inactive_connection_recovery_entry(conn->sess, cr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int iscsit_connection_recovery_transport_reset(struct iscsi_conn *conn)
|
||||
{
|
||||
atomic_set(&conn->connection_recovery, 1);
|
||||
|
||||
if (iscsit_close_connection(conn) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user