Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * This file contains the login functions used by the iSCSI Target driver. |
| 3 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 4 | * (c) Copyright 2007-2013 Datera, Inc. |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 5 | * |
| 6 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | ******************************************************************************/ |
| 18 | |
| 19 | #include <linux/string.h> |
| 20 | #include <linux/kthread.h> |
| 21 | #include <linux/crypto.h> |
Al Viro | 4040153 | 2012-02-13 03:58:52 +0000 | [diff] [blame] | 22 | #include <linux/idr.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 23 | #include <scsi/iscsi_proto.h> |
| 24 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 25 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 26 | |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 27 | #include <target/iscsi/iscsi_target_core.h> |
| 28 | #include <target/iscsi/iscsi_target_stat.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 29 | #include "iscsi_target_device.h" |
| 30 | #include "iscsi_target_nego.h" |
| 31 | #include "iscsi_target_erl0.h" |
| 32 | #include "iscsi_target_erl2.h" |
| 33 | #include "iscsi_target_login.h" |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 34 | #include "iscsi_target_tpg.h" |
| 35 | #include "iscsi_target_util.h" |
| 36 | #include "iscsi_target.h" |
| 37 | #include "iscsi_target_parameters.h" |
| 38 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 39 | #include <target/iscsi/iscsi_transport.h> |
| 40 | |
| 41 | static struct iscsi_login *iscsi_login_init_conn(struct iscsi_conn *conn) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 42 | { |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 43 | struct iscsi_login *login; |
| 44 | |
| 45 | login = kzalloc(sizeof(struct iscsi_login), GFP_KERNEL); |
| 46 | if (!login) { |
| 47 | pr_err("Unable to allocate memory for struct iscsi_login.\n"); |
| 48 | return NULL; |
| 49 | } |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 50 | conn->login = login; |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 51 | login->conn = conn; |
| 52 | login->first_request = 1; |
| 53 | |
| 54 | login->req_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL); |
| 55 | if (!login->req_buf) { |
| 56 | pr_err("Unable to allocate memory for response buffer.\n"); |
| 57 | goto out_login; |
| 58 | } |
| 59 | |
| 60 | login->rsp_buf = kzalloc(MAX_KEY_VALUE_PAIRS, GFP_KERNEL); |
| 61 | if (!login->rsp_buf) { |
| 62 | pr_err("Unable to allocate memory for request buffer.\n"); |
| 63 | goto out_req_buf; |
| 64 | } |
| 65 | |
| 66 | conn->conn_ops = kzalloc(sizeof(struct iscsi_conn_ops), GFP_KERNEL); |
| 67 | if (!conn->conn_ops) { |
| 68 | pr_err("Unable to allocate memory for" |
| 69 | " struct iscsi_conn_ops.\n"); |
| 70 | goto out_rsp_buf; |
| 71 | } |
| 72 | |
Roland Dreier | d5627ac | 2012-10-31 09:16:46 -0700 | [diff] [blame] | 73 | init_waitqueue_head(&conn->queues_wq); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 74 | INIT_LIST_HEAD(&conn->conn_list); |
| 75 | INIT_LIST_HEAD(&conn->conn_cmd_list); |
| 76 | INIT_LIST_HEAD(&conn->immed_queue_list); |
| 77 | INIT_LIST_HEAD(&conn->response_queue_list); |
| 78 | init_completion(&conn->conn_post_wait_comp); |
| 79 | init_completion(&conn->conn_wait_comp); |
| 80 | init_completion(&conn->conn_wait_rcfr_comp); |
| 81 | init_completion(&conn->conn_waiting_on_uc_comp); |
| 82 | init_completion(&conn->conn_logout_comp); |
| 83 | init_completion(&conn->rx_half_close_comp); |
| 84 | init_completion(&conn->tx_half_close_comp); |
| 85 | spin_lock_init(&conn->cmd_lock); |
| 86 | spin_lock_init(&conn->conn_usage_lock); |
| 87 | spin_lock_init(&conn->immed_queue_lock); |
| 88 | spin_lock_init(&conn->nopin_timer_lock); |
| 89 | spin_lock_init(&conn->response_queue_lock); |
| 90 | spin_lock_init(&conn->state_lock); |
| 91 | |
| 92 | if (!zalloc_cpumask_var(&conn->conn_cpumask, GFP_KERNEL)) { |
| 93 | pr_err("Unable to allocate conn->conn_cpumask\n"); |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 94 | goto out_conn_ops; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 95 | } |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 96 | conn->conn_login = login; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 97 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 98 | return login; |
| 99 | |
| 100 | out_conn_ops: |
| 101 | kfree(conn->conn_ops); |
| 102 | out_rsp_buf: |
| 103 | kfree(login->rsp_buf); |
| 104 | out_req_buf: |
| 105 | kfree(login->req_buf); |
| 106 | out_login: |
| 107 | kfree(login); |
| 108 | return NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Used by iscsi_target_nego.c:iscsi_target_locate_portal() to setup |
| 113 | * per struct iscsi_conn libcrypto contexts for crc32c and crc32-intel |
| 114 | */ |
| 115 | int iscsi_login_setup_crypto(struct iscsi_conn *conn) |
| 116 | { |
| 117 | /* |
| 118 | * Setup slicing by CRC32C algorithm for RX and TX libcrypto contexts |
| 119 | * which will default to crc32c_intel.ko for cpu_has_xmm4_2, or fallback |
| 120 | * to software 1x8 byte slicing from crc32c.ko |
| 121 | */ |
| 122 | conn->conn_rx_hash.flags = 0; |
| 123 | conn->conn_rx_hash.tfm = crypto_alloc_hash("crc32c", 0, |
| 124 | CRYPTO_ALG_ASYNC); |
| 125 | if (IS_ERR(conn->conn_rx_hash.tfm)) { |
| 126 | pr_err("crypto_alloc_hash() failed for conn_rx_tfm\n"); |
| 127 | return -ENOMEM; |
| 128 | } |
| 129 | |
| 130 | conn->conn_tx_hash.flags = 0; |
| 131 | conn->conn_tx_hash.tfm = crypto_alloc_hash("crc32c", 0, |
| 132 | CRYPTO_ALG_ASYNC); |
| 133 | if (IS_ERR(conn->conn_tx_hash.tfm)) { |
| 134 | pr_err("crypto_alloc_hash() failed for conn_tx_tfm\n"); |
| 135 | crypto_free_hash(conn->conn_rx_hash.tfm); |
| 136 | return -ENOMEM; |
| 137 | } |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | static int iscsi_login_check_initiator_version( |
| 143 | struct iscsi_conn *conn, |
| 144 | u8 version_max, |
| 145 | u8 version_min) |
| 146 | { |
| 147 | if ((version_max != 0x00) || (version_min != 0x00)) { |
| 148 | pr_err("Unsupported iSCSI IETF Pre-RFC Revision," |
| 149 | " version Min/Max 0x%02x/0x%02x, rejecting login.\n", |
| 150 | version_min, version_max); |
| 151 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, |
| 152 | ISCSI_LOGIN_STATUS_NO_VERSION); |
| 153 | return -1; |
| 154 | } |
| 155 | |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | int iscsi_check_for_session_reinstatement(struct iscsi_conn *conn) |
| 160 | { |
| 161 | int sessiontype; |
| 162 | struct iscsi_param *initiatorname_param = NULL, *sessiontype_param = NULL; |
| 163 | struct iscsi_portal_group *tpg = conn->tpg; |
| 164 | struct iscsi_session *sess = NULL, *sess_p = NULL; |
| 165 | struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; |
| 166 | struct se_session *se_sess, *se_sess_tmp; |
| 167 | |
| 168 | initiatorname_param = iscsi_find_param_from_key( |
| 169 | INITIATORNAME, conn->param_list); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 170 | sessiontype_param = iscsi_find_param_from_key( |
| 171 | SESSIONTYPE, conn->param_list); |
Roland Dreier | 1c5c12c | 2012-11-05 18:02:42 -0800 | [diff] [blame] | 172 | if (!initiatorname_param || !sessiontype_param) { |
| 173 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, |
| 174 | ISCSI_LOGIN_STATUS_MISSING_FIELDS); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 175 | return -1; |
Roland Dreier | 1c5c12c | 2012-11-05 18:02:42 -0800 | [diff] [blame] | 176 | } |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 177 | |
| 178 | sessiontype = (strncmp(sessiontype_param->value, NORMAL, 6)) ? 1 : 0; |
| 179 | |
| 180 | spin_lock_bh(&se_tpg->session_lock); |
| 181 | list_for_each_entry_safe(se_sess, se_sess_tmp, &se_tpg->tpg_sess_list, |
| 182 | sess_list) { |
| 183 | |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 184 | sess_p = se_sess->fabric_sess_ptr; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 185 | spin_lock(&sess_p->conn_lock); |
| 186 | if (atomic_read(&sess_p->session_fall_back_to_erl0) || |
| 187 | atomic_read(&sess_p->session_logout) || |
| 188 | (sess_p->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { |
| 189 | spin_unlock(&sess_p->conn_lock); |
| 190 | continue; |
| 191 | } |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 192 | if (!memcmp(sess_p->isid, conn->sess->isid, 6) && |
| 193 | (!strcmp(sess_p->sess_ops->InitiatorName, |
| 194 | initiatorname_param->value) && |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 195 | (sess_p->sess_ops->SessionType == sessiontype))) { |
| 196 | atomic_set(&sess_p->session_reinstatement, 1); |
| 197 | spin_unlock(&sess_p->conn_lock); |
| 198 | iscsit_inc_session_usage_count(sess_p); |
| 199 | iscsit_stop_time2retain_timer(sess_p); |
| 200 | sess = sess_p; |
| 201 | break; |
| 202 | } |
| 203 | spin_unlock(&sess_p->conn_lock); |
| 204 | } |
| 205 | spin_unlock_bh(&se_tpg->session_lock); |
| 206 | /* |
| 207 | * If the Time2Retain handler has expired, the session is already gone. |
| 208 | */ |
| 209 | if (!sess) |
| 210 | return 0; |
| 211 | |
| 212 | pr_debug("%s iSCSI Session SID %u is still active for %s," |
| 213 | " preforming session reinstatement.\n", (sessiontype) ? |
| 214 | "Discovery" : "Normal", sess->sid, |
| 215 | sess->sess_ops->InitiatorName); |
| 216 | |
| 217 | spin_lock_bh(&sess->conn_lock); |
| 218 | if (sess->session_state == TARG_SESS_STATE_FAILED) { |
| 219 | spin_unlock_bh(&sess->conn_lock); |
| 220 | iscsit_dec_session_usage_count(sess); |
Nicholas Bellinger | 99367f0 | 2012-02-27 01:43:32 -0800 | [diff] [blame] | 221 | target_put_session(sess->se_sess); |
| 222 | return 0; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 223 | } |
| 224 | spin_unlock_bh(&sess->conn_lock); |
| 225 | |
| 226 | iscsit_stop_session(sess, 1, 1); |
| 227 | iscsit_dec_session_usage_count(sess); |
| 228 | |
Nicholas Bellinger | 99367f0 | 2012-02-27 01:43:32 -0800 | [diff] [blame] | 229 | target_put_session(sess->se_sess); |
| 230 | return 0; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static void iscsi_login_set_conn_values( |
| 234 | struct iscsi_session *sess, |
| 235 | struct iscsi_conn *conn, |
Christoph Hellwig | 50e5c87 | 2012-09-26 08:00:40 -0400 | [diff] [blame] | 236 | __be16 cid) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 237 | { |
| 238 | conn->sess = sess; |
Christoph Hellwig | 50e5c87 | 2012-09-26 08:00:40 -0400 | [diff] [blame] | 239 | conn->cid = be16_to_cpu(cid); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 240 | /* |
| 241 | * Generate a random Status sequence number (statsn) for the new |
| 242 | * iSCSI connection. |
| 243 | */ |
| 244 | get_random_bytes(&conn->stat_sn, sizeof(u32)); |
| 245 | |
| 246 | mutex_lock(&auth_id_lock); |
| 247 | conn->auth_id = iscsit_global->auth_id++; |
| 248 | mutex_unlock(&auth_id_lock); |
| 249 | } |
| 250 | |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 251 | static __printf(2, 3) int iscsi_change_param_sprintf( |
| 252 | struct iscsi_conn *conn, |
| 253 | const char *fmt, ...) |
| 254 | { |
| 255 | va_list args; |
| 256 | unsigned char buf[64]; |
| 257 | |
| 258 | memset(buf, 0, sizeof buf); |
| 259 | |
| 260 | va_start(args, fmt); |
| 261 | vsnprintf(buf, sizeof buf, fmt, args); |
| 262 | va_end(args); |
| 263 | |
| 264 | if (iscsi_change_param_value(buf, conn->param_list, 0) < 0) { |
| 265 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 266 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 267 | return -1; |
| 268 | } |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 273 | /* |
| 274 | * This is the leading connection of a new session, |
| 275 | * or session reinstatement. |
| 276 | */ |
| 277 | static int iscsi_login_zero_tsih_s1( |
| 278 | struct iscsi_conn *conn, |
| 279 | unsigned char *buf) |
| 280 | { |
| 281 | struct iscsi_session *sess = NULL; |
| 282 | struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; |
Benjamin Wang | 13b5533 | 2012-08-26 18:04:10 +0800 | [diff] [blame] | 283 | int ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 284 | |
| 285 | sess = kzalloc(sizeof(struct iscsi_session), GFP_KERNEL); |
| 286 | if (!sess) { |
| 287 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 288 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 289 | pr_err("Could not allocate memory for session\n"); |
Nicholas Bellinger | 0957627 | 2011-11-04 11:36:38 -0700 | [diff] [blame] | 290 | return -ENOMEM; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | iscsi_login_set_conn_values(sess, conn, pdu->cid); |
| 294 | sess->init_task_tag = pdu->itt; |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 295 | memcpy(&sess->isid, pdu->isid, 6); |
Christoph Hellwig | 50e5c87 | 2012-09-26 08:00:40 -0400 | [diff] [blame] | 296 | sess->exp_cmd_sn = be32_to_cpu(pdu->cmdsn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 297 | INIT_LIST_HEAD(&sess->sess_conn_list); |
| 298 | INIT_LIST_HEAD(&sess->sess_ooo_cmdsn_list); |
| 299 | INIT_LIST_HEAD(&sess->cr_active_list); |
| 300 | INIT_LIST_HEAD(&sess->cr_inactive_list); |
| 301 | init_completion(&sess->async_msg_comp); |
| 302 | init_completion(&sess->reinstatement_comp); |
| 303 | init_completion(&sess->session_wait_comp); |
| 304 | init_completion(&sess->session_waiting_on_uc_comp); |
| 305 | mutex_init(&sess->cmdsn_mutex); |
| 306 | spin_lock_init(&sess->conn_lock); |
| 307 | spin_lock_init(&sess->cr_a_lock); |
| 308 | spin_lock_init(&sess->cr_i_lock); |
| 309 | spin_lock_init(&sess->session_usage_lock); |
| 310 | spin_lock_init(&sess->ttt_lock); |
| 311 | |
Tejun Heo | c9365bd | 2013-02-27 17:04:43 -0800 | [diff] [blame] | 312 | idr_preload(GFP_KERNEL); |
Roland Dreier | 998866b | 2012-11-05 18:02:40 -0800 | [diff] [blame] | 313 | spin_lock_bh(&sess_idr_lock); |
Tejun Heo | c9365bd | 2013-02-27 17:04:43 -0800 | [diff] [blame] | 314 | ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT); |
| 315 | if (ret >= 0) |
| 316 | sess->session_index = ret; |
Roland Dreier | 998866b | 2012-11-05 18:02:40 -0800 | [diff] [blame] | 317 | spin_unlock_bh(&sess_idr_lock); |
Tejun Heo | c9365bd | 2013-02-27 17:04:43 -0800 | [diff] [blame] | 318 | idr_preload_end(); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 319 | |
Benjamin Wang | 13b5533 | 2012-08-26 18:04:10 +0800 | [diff] [blame] | 320 | if (ret < 0) { |
Tejun Heo | c9365bd | 2013-02-27 17:04:43 -0800 | [diff] [blame] | 321 | pr_err("idr_alloc() for sess_idr failed\n"); |
Benjamin Wang | 13b5533 | 2012-08-26 18:04:10 +0800 | [diff] [blame] | 322 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 323 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 324 | kfree(sess); |
| 325 | return -ENOMEM; |
| 326 | } |
| 327 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 328 | sess->creation_time = get_jiffies_64(); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 329 | /* |
| 330 | * The FFP CmdSN window values will be allocated from the TPG's |
| 331 | * Initiator Node's ACL once the login has been successfully completed. |
| 332 | */ |
Christoph Hellwig | 50e5c87 | 2012-09-26 08:00:40 -0400 | [diff] [blame] | 333 | sess->max_cmd_sn = be32_to_cpu(pdu->cmdsn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 334 | |
| 335 | sess->sess_ops = kzalloc(sizeof(struct iscsi_sess_ops), GFP_KERNEL); |
| 336 | if (!sess->sess_ops) { |
| 337 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 338 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 339 | pr_err("Unable to allocate memory for" |
| 340 | " struct iscsi_sess_ops.\n"); |
Nicholas Bellinger | 0957627 | 2011-11-04 11:36:38 -0700 | [diff] [blame] | 341 | kfree(sess); |
| 342 | return -ENOMEM; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Sagi Grimberg | 23a548e | 2014-12-02 16:57:35 +0200 | [diff] [blame] | 345 | sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); |
Nicholas Bellinger | 0957627 | 2011-11-04 11:36:38 -0700 | [diff] [blame] | 346 | if (IS_ERR(sess->se_sess)) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 347 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 348 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
Evgenii Lepikhin | a928d28 | 2015-04-21 15:49:57 +0300 | [diff] [blame] | 349 | kfree(sess->sess_ops); |
Nicholas Bellinger | 0957627 | 2011-11-04 11:36:38 -0700 | [diff] [blame] | 350 | kfree(sess); |
| 351 | return -ENOMEM; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static int iscsi_login_zero_tsih_s2( |
| 358 | struct iscsi_conn *conn) |
| 359 | { |
| 360 | struct iscsi_node_attrib *na; |
| 361 | struct iscsi_session *sess = conn->sess; |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 362 | bool iser = false; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 363 | |
| 364 | sess->tpg = conn->tpg; |
| 365 | |
| 366 | /* |
| 367 | * Assign a new TPG Session Handle. Note this is protected with |
| 368 | * struct iscsi_portal_group->np_login_sem from iscsit_access_np(). |
| 369 | */ |
Andy Grover | 60bfcf8 | 2013-10-09 11:05:58 -0700 | [diff] [blame] | 370 | sess->tsih = ++sess->tpg->ntsih; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 371 | if (!sess->tsih) |
Andy Grover | 60bfcf8 | 2013-10-09 11:05:58 -0700 | [diff] [blame] | 372 | sess->tsih = ++sess->tpg->ntsih; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * Create the default params from user defined values.. |
| 376 | */ |
| 377 | if (iscsi_copy_param_list(&conn->param_list, |
Andy Grover | 60bfcf8 | 2013-10-09 11:05:58 -0700 | [diff] [blame] | 378 | conn->tpg->param_list, 1) < 0) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 379 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 380 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 381 | return -1; |
| 382 | } |
| 383 | |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 384 | if (conn->conn_transport->transport_type == ISCSI_INFINIBAND) |
| 385 | iser = true; |
| 386 | |
| 387 | iscsi_set_keys_to_negotiate(conn->param_list, iser); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 388 | |
| 389 | if (sess->sess_ops->SessionType) |
| 390 | return iscsi_set_keys_irrelevant_for_discovery( |
| 391 | conn->param_list); |
| 392 | |
| 393 | na = iscsit_tpg_get_node_attrib(sess); |
| 394 | |
| 395 | /* |
| 396 | * Need to send TargetPortalGroupTag back in first login response |
| 397 | * on any iSCSI connection where the Initiator provides TargetName. |
| 398 | * See 5.3.1. Login Phase Start |
| 399 | * |
| 400 | * In our case, we have already located the struct iscsi_tiqn at this point. |
| 401 | */ |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 402 | if (iscsi_change_param_sprintf(conn, "TargetPortalGroupTag=%hu", sess->tpg->tpgt)) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 403 | return -1; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 404 | |
| 405 | /* |
| 406 | * Workaround for Initiators that have broken connection recovery logic. |
| 407 | * |
| 408 | * "We would really like to get rid of this." Linux-iSCSI.org team |
| 409 | */ |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 410 | if (iscsi_change_param_sprintf(conn, "ErrorRecoveryLevel=%d", na->default_erl)) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 411 | return -1; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 412 | |
| 413 | if (iscsi_login_disable_FIM_keys(conn->param_list, conn) < 0) |
| 414 | return -1; |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 415 | /* |
| 416 | * Set RDMAExtensions=Yes by default for iSER enabled network portals |
| 417 | */ |
| 418 | if (iser) { |
| 419 | struct iscsi_param *param; |
| 420 | unsigned long mrdsl, off; |
| 421 | int rc; |
| 422 | |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 423 | if (iscsi_change_param_sprintf(conn, "RDMAExtensions=Yes")) |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 424 | return -1; |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 425 | |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 426 | /* |
| 427 | * Make MaxRecvDataSegmentLength PAGE_SIZE aligned for |
| 428 | * Immediate Data + Unsolicitied Data-OUT if necessary.. |
| 429 | */ |
| 430 | param = iscsi_find_param_from_key("MaxRecvDataSegmentLength", |
| 431 | conn->param_list); |
| 432 | if (!param) { |
| 433 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 434 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 435 | return -1; |
| 436 | } |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 437 | rc = kstrtoul(param->value, 0, &mrdsl); |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 438 | if (rc < 0) { |
| 439 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 440 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 441 | return -1; |
| 442 | } |
| 443 | off = mrdsl % PAGE_SIZE; |
| 444 | if (!off) |
Nicholas Bellinger | 52d0aa7 | 2014-05-14 20:54:26 +0000 | [diff] [blame] | 445 | goto check_prot; |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 446 | |
| 447 | if (mrdsl < PAGE_SIZE) |
| 448 | mrdsl = PAGE_SIZE; |
| 449 | else |
| 450 | mrdsl -= off; |
| 451 | |
| 452 | pr_warn("Aligning ISER MaxRecvDataSegmentLength: %lu down" |
| 453 | " to PAGE_SIZE\n", mrdsl); |
| 454 | |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 455 | if (iscsi_change_param_sprintf(conn, "MaxRecvDataSegmentLength=%lu\n", mrdsl)) |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 456 | return -1; |
Nicholas Bellinger | 52d0aa7 | 2014-05-14 20:54:26 +0000 | [diff] [blame] | 457 | /* |
| 458 | * ISER currently requires that ImmediateData + Unsolicited |
| 459 | * Data be disabled when protection / signature MRs are enabled. |
| 460 | */ |
| 461 | check_prot: |
| 462 | if (sess->se_sess->sup_prot_ops & |
| 463 | (TARGET_PROT_DOUT_STRIP | TARGET_PROT_DOUT_PASS | |
| 464 | TARGET_PROT_DOUT_INSERT)) { |
| 465 | |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 466 | if (iscsi_change_param_sprintf(conn, "ImmediateData=No")) |
Nicholas Bellinger | 52d0aa7 | 2014-05-14 20:54:26 +0000 | [diff] [blame] | 467 | return -1; |
Nicholas Bellinger | 52d0aa7 | 2014-05-14 20:54:26 +0000 | [diff] [blame] | 468 | |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 469 | if (iscsi_change_param_sprintf(conn, "InitialR2T=Yes")) |
Nicholas Bellinger | 52d0aa7 | 2014-05-14 20:54:26 +0000 | [diff] [blame] | 470 | return -1; |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 471 | |
Nicholas Bellinger | 52d0aa7 | 2014-05-14 20:54:26 +0000 | [diff] [blame] | 472 | pr_debug("Forcing ImmediateData=No + InitialR2T=Yes for" |
| 473 | " T10-PI enabled ISER session\n"); |
| 474 | } |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 475 | } |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | /* |
| 481 | * Remove PSTATE_NEGOTIATE for the four FIM related keys. |
| 482 | * The Initiator node will be able to enable FIM by proposing them itself. |
| 483 | */ |
| 484 | int iscsi_login_disable_FIM_keys( |
| 485 | struct iscsi_param_list *param_list, |
| 486 | struct iscsi_conn *conn) |
| 487 | { |
| 488 | struct iscsi_param *param; |
| 489 | |
| 490 | param = iscsi_find_param_from_key("OFMarker", param_list); |
| 491 | if (!param) { |
| 492 | pr_err("iscsi_find_param_from_key() for" |
| 493 | " OFMarker failed\n"); |
| 494 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 495 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 496 | return -1; |
| 497 | } |
| 498 | param->state &= ~PSTATE_NEGOTIATE; |
| 499 | |
| 500 | param = iscsi_find_param_from_key("OFMarkInt", param_list); |
| 501 | if (!param) { |
| 502 | pr_err("iscsi_find_param_from_key() for" |
| 503 | " IFMarker failed\n"); |
| 504 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 505 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 506 | return -1; |
| 507 | } |
| 508 | param->state &= ~PSTATE_NEGOTIATE; |
| 509 | |
| 510 | param = iscsi_find_param_from_key("IFMarker", param_list); |
| 511 | if (!param) { |
| 512 | pr_err("iscsi_find_param_from_key() for" |
| 513 | " IFMarker failed\n"); |
| 514 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 515 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 516 | return -1; |
| 517 | } |
| 518 | param->state &= ~PSTATE_NEGOTIATE; |
| 519 | |
| 520 | param = iscsi_find_param_from_key("IFMarkInt", param_list); |
| 521 | if (!param) { |
| 522 | pr_err("iscsi_find_param_from_key() for" |
| 523 | " IFMarker failed\n"); |
| 524 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 525 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 526 | return -1; |
| 527 | } |
| 528 | param->state &= ~PSTATE_NEGOTIATE; |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static int iscsi_login_non_zero_tsih_s1( |
| 534 | struct iscsi_conn *conn, |
| 535 | unsigned char *buf) |
| 536 | { |
| 537 | struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; |
| 538 | |
| 539 | iscsi_login_set_conn_values(NULL, conn, pdu->cid); |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | /* |
| 544 | * Add a new connection to an existing session. |
| 545 | */ |
| 546 | static int iscsi_login_non_zero_tsih_s2( |
| 547 | struct iscsi_conn *conn, |
| 548 | unsigned char *buf) |
| 549 | { |
| 550 | struct iscsi_portal_group *tpg = conn->tpg; |
| 551 | struct iscsi_session *sess = NULL, *sess_p = NULL; |
| 552 | struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; |
| 553 | struct se_session *se_sess, *se_sess_tmp; |
| 554 | struct iscsi_login_req *pdu = (struct iscsi_login_req *)buf; |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 555 | bool iser = false; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 556 | |
| 557 | spin_lock_bh(&se_tpg->session_lock); |
| 558 | list_for_each_entry_safe(se_sess, se_sess_tmp, &se_tpg->tpg_sess_list, |
| 559 | sess_list) { |
| 560 | |
| 561 | sess_p = (struct iscsi_session *)se_sess->fabric_sess_ptr; |
| 562 | if (atomic_read(&sess_p->session_fall_back_to_erl0) || |
| 563 | atomic_read(&sess_p->session_logout) || |
| 564 | (sess_p->time2retain_timer_flags & ISCSI_TF_EXPIRED)) |
| 565 | continue; |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 566 | if (!memcmp(sess_p->isid, pdu->isid, 6) && |
Christoph Hellwig | 50e5c87 | 2012-09-26 08:00:40 -0400 | [diff] [blame] | 567 | (sess_p->tsih == be16_to_cpu(pdu->tsih))) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 568 | iscsit_inc_session_usage_count(sess_p); |
| 569 | iscsit_stop_time2retain_timer(sess_p); |
| 570 | sess = sess_p; |
| 571 | break; |
| 572 | } |
| 573 | } |
| 574 | spin_unlock_bh(&se_tpg->session_lock); |
| 575 | |
| 576 | /* |
| 577 | * If the Time2Retain handler has expired, the session is already gone. |
| 578 | */ |
| 579 | if (!sess) { |
| 580 | pr_err("Initiator attempting to add a connection to" |
| 581 | " a non-existent session, rejecting iSCSI Login.\n"); |
| 582 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, |
| 583 | ISCSI_LOGIN_STATUS_NO_SESSION); |
| 584 | return -1; |
| 585 | } |
| 586 | |
| 587 | /* |
| 588 | * Stop the Time2Retain timer if this is a failed session, we restart |
| 589 | * the timer if the login is not successful. |
| 590 | */ |
| 591 | spin_lock_bh(&sess->conn_lock); |
| 592 | if (sess->session_state == TARG_SESS_STATE_FAILED) |
| 593 | atomic_set(&sess->session_continuation, 1); |
| 594 | spin_unlock_bh(&sess->conn_lock); |
| 595 | |
| 596 | iscsi_login_set_conn_values(sess, conn, pdu->cid); |
| 597 | |
| 598 | if (iscsi_copy_param_list(&conn->param_list, |
Andy Grover | 60bfcf8 | 2013-10-09 11:05:58 -0700 | [diff] [blame] | 599 | conn->tpg->param_list, 0) < 0) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 600 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 601 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
| 602 | return -1; |
| 603 | } |
| 604 | |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 605 | if (conn->conn_transport->transport_type == ISCSI_INFINIBAND) |
| 606 | iser = true; |
| 607 | |
| 608 | iscsi_set_keys_to_negotiate(conn->param_list, iser); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 609 | /* |
| 610 | * Need to send TargetPortalGroupTag back in first login response |
| 611 | * on any iSCSI connection where the Initiator provides TargetName. |
| 612 | * See 5.3.1. Login Phase Start |
| 613 | * |
| 614 | * In our case, we have already located the struct iscsi_tiqn at this point. |
| 615 | */ |
Roland Dreier | 79d59d0 | 2014-05-29 13:32:30 -0700 | [diff] [blame] | 616 | if (iscsi_change_param_sprintf(conn, "TargetPortalGroupTag=%hu", sess->tpg->tpgt)) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 617 | return -1; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 618 | |
| 619 | return iscsi_login_disable_FIM_keys(conn->param_list, conn); |
| 620 | } |
| 621 | |
| 622 | int iscsi_login_post_auth_non_zero_tsih( |
| 623 | struct iscsi_conn *conn, |
| 624 | u16 cid, |
| 625 | u32 exp_statsn) |
| 626 | { |
| 627 | struct iscsi_conn *conn_ptr = NULL; |
| 628 | struct iscsi_conn_recovery *cr = NULL; |
| 629 | struct iscsi_session *sess = conn->sess; |
| 630 | |
| 631 | /* |
| 632 | * By following item 5 in the login table, if we have found |
| 633 | * an existing ISID and a valid/existing TSIH and an existing |
| 634 | * CID we do connection reinstatement. Currently we dont not |
| 635 | * support it so we send back an non-zero status class to the |
| 636 | * initiator and release the new connection. |
| 637 | */ |
| 638 | conn_ptr = iscsit_get_conn_from_cid_rcfr(sess, cid); |
Andy Grover | ee1b1b9 | 2012-07-12 17:34:54 -0700 | [diff] [blame] | 639 | if (conn_ptr) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 640 | pr_err("Connection exists with CID %hu for %s," |
| 641 | " performing connection reinstatement.\n", |
| 642 | conn_ptr->cid, sess->sess_ops->InitiatorName); |
| 643 | |
| 644 | iscsit_connection_reinstatement_rcfr(conn_ptr); |
| 645 | iscsit_dec_conn_usage_count(conn_ptr); |
| 646 | } |
| 647 | |
| 648 | /* |
| 649 | * Check for any connection recovery entires containing CID. |
| 650 | * We use the original ExpStatSN sent in the first login request |
| 651 | * to acknowledge commands for the failed connection. |
| 652 | * |
| 653 | * Also note that an explict logout may have already been sent, |
| 654 | * but the response may not be sent due to additional connection |
| 655 | * loss. |
| 656 | */ |
| 657 | if (sess->sess_ops->ErrorRecoveryLevel == 2) { |
| 658 | cr = iscsit_get_inactive_connection_recovery_entry( |
| 659 | sess, cid); |
Andy Grover | ee1b1b9 | 2012-07-12 17:34:54 -0700 | [diff] [blame] | 660 | if (cr) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 661 | pr_debug("Performing implicit logout" |
| 662 | " for connection recovery on CID: %hu\n", |
| 663 | conn->cid); |
| 664 | iscsit_discard_cr_cmds_by_expstatsn(cr, exp_statsn); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * Else we follow item 4 from the login table in that we have |
| 670 | * found an existing ISID and a valid/existing TSIH and a new |
| 671 | * CID we go ahead and continue to add a new connection to the |
| 672 | * session. |
| 673 | */ |
| 674 | pr_debug("Adding CID %hu to existing session for %s.\n", |
| 675 | cid, sess->sess_ops->InitiatorName); |
| 676 | |
| 677 | if ((atomic_read(&sess->nconn) + 1) > sess->sess_ops->MaxConnections) { |
| 678 | pr_err("Adding additional connection to this session" |
| 679 | " would exceed MaxConnections %d, login failed.\n", |
| 680 | sess->sess_ops->MaxConnections); |
| 681 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, |
| 682 | ISCSI_LOGIN_STATUS_ISID_ERROR); |
| 683 | return -1; |
| 684 | } |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | static void iscsi_post_login_start_timers(struct iscsi_conn *conn) |
| 690 | { |
| 691 | struct iscsi_session *sess = conn->sess; |
Nicholas Bellinger | 03aa207 | 2013-03-06 21:54:38 -0800 | [diff] [blame] | 692 | /* |
| 693 | * FIXME: Unsolicitied NopIN support for ISER |
| 694 | */ |
| 695 | if (conn->conn_transport->transport_type == ISCSI_INFINIBAND) |
| 696 | return; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 697 | |
| 698 | if (!sess->sess_ops->SessionType) |
| 699 | iscsit_start_nopin_timer(conn); |
| 700 | } |
| 701 | |
Christoph Hellwig | 9649491 | 2015-03-26 12:27:33 +0100 | [diff] [blame] | 702 | static int iscsit_start_kthreads(struct iscsi_conn *conn) |
Nicholas Bellinger | 88dcd2d | 2015-02-26 22:19:15 -0800 | [diff] [blame] | 703 | { |
| 704 | int ret = 0; |
| 705 | |
| 706 | spin_lock(&iscsit_global->ts_bitmap_lock); |
| 707 | conn->bitmap_id = bitmap_find_free_region(iscsit_global->ts_bitmap, |
| 708 | ISCSIT_BITMAP_BITS, get_order(1)); |
| 709 | spin_unlock(&iscsit_global->ts_bitmap_lock); |
| 710 | |
| 711 | if (conn->bitmap_id < 0) { |
| 712 | pr_err("bitmap_find_free_region() failed for" |
| 713 | " iscsit_start_kthreads()\n"); |
| 714 | return -ENOMEM; |
| 715 | } |
| 716 | |
| 717 | conn->tx_thread = kthread_run(iscsi_target_tx_thread, conn, |
| 718 | "%s", ISCSI_TX_THREAD_NAME); |
| 719 | if (IS_ERR(conn->tx_thread)) { |
| 720 | pr_err("Unable to start iscsi_target_tx_thread\n"); |
| 721 | ret = PTR_ERR(conn->tx_thread); |
| 722 | goto out_bitmap; |
| 723 | } |
| 724 | conn->tx_thread_active = true; |
| 725 | |
| 726 | conn->rx_thread = kthread_run(iscsi_target_rx_thread, conn, |
| 727 | "%s", ISCSI_RX_THREAD_NAME); |
| 728 | if (IS_ERR(conn->rx_thread)) { |
| 729 | pr_err("Unable to start iscsi_target_rx_thread\n"); |
| 730 | ret = PTR_ERR(conn->rx_thread); |
| 731 | goto out_tx; |
| 732 | } |
| 733 | conn->rx_thread_active = true; |
| 734 | |
| 735 | return 0; |
| 736 | out_tx: |
| 737 | kthread_stop(conn->tx_thread); |
| 738 | conn->tx_thread_active = false; |
| 739 | out_bitmap: |
| 740 | spin_lock(&iscsit_global->ts_bitmap_lock); |
| 741 | bitmap_release_region(iscsit_global->ts_bitmap, conn->bitmap_id, |
| 742 | get_order(1)); |
| 743 | spin_unlock(&iscsit_global->ts_bitmap_lock); |
| 744 | return ret; |
| 745 | } |
| 746 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 747 | int iscsi_post_login_handler( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 748 | struct iscsi_np *np, |
| 749 | struct iscsi_conn *conn, |
| 750 | u8 zero_tsih) |
| 751 | { |
| 752 | int stop_timer = 0; |
| 753 | struct iscsi_session *sess = conn->sess; |
| 754 | struct se_session *se_sess = sess->se_sess; |
Andy Grover | 60bfcf8 | 2013-10-09 11:05:58 -0700 | [diff] [blame] | 755 | struct iscsi_portal_group *tpg = sess->tpg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 756 | struct se_portal_group *se_tpg = &tpg->tpg_se_tpg; |
Nicholas Bellinger | 88dcd2d | 2015-02-26 22:19:15 -0800 | [diff] [blame] | 757 | int rc; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 758 | |
| 759 | iscsit_inc_conn_usage_count(conn); |
| 760 | |
| 761 | iscsit_collect_login_stats(conn, ISCSI_STATUS_CLS_SUCCESS, |
| 762 | ISCSI_LOGIN_STATUS_ACCEPT); |
| 763 | |
| 764 | pr_debug("Moving to TARG_CONN_STATE_LOGGED_IN.\n"); |
| 765 | conn->conn_state = TARG_CONN_STATE_LOGGED_IN; |
| 766 | |
| 767 | iscsi_set_connection_parameters(conn->conn_ops, conn->param_list); |
| 768 | iscsit_set_sync_and_steering_values(conn); |
| 769 | /* |
| 770 | * SCSI Initiator -> SCSI Target Port Mapping |
| 771 | */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 772 | if (!zero_tsih) { |
| 773 | iscsi_set_session_parameters(sess->sess_ops, |
| 774 | conn->param_list, 0); |
| 775 | iscsi_release_param_list(conn->param_list); |
| 776 | conn->param_list = NULL; |
| 777 | |
| 778 | spin_lock_bh(&sess->conn_lock); |
| 779 | atomic_set(&sess->session_continuation, 0); |
| 780 | if (sess->session_state == TARG_SESS_STATE_FAILED) { |
| 781 | pr_debug("Moving to" |
| 782 | " TARG_SESS_STATE_LOGGED_IN.\n"); |
| 783 | sess->session_state = TARG_SESS_STATE_LOGGED_IN; |
| 784 | stop_timer = 1; |
| 785 | } |
| 786 | |
| 787 | pr_debug("iSCSI Login successful on CID: %hu from %s to" |
Nicholas Bellinger | 2f9bc89 | 2012-01-16 23:33:48 -0800 | [diff] [blame] | 788 | " %s:%hu,%hu\n", conn->cid, conn->login_ip, |
| 789 | conn->local_ip, conn->local_port, tpg->tpgt); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 790 | |
| 791 | list_add_tail(&conn->conn_list, &sess->sess_conn_list); |
| 792 | atomic_inc(&sess->nconn); |
| 793 | pr_debug("Incremented iSCSI Connection count to %hu" |
| 794 | " from node: %s\n", atomic_read(&sess->nconn), |
| 795 | sess->sess_ops->InitiatorName); |
| 796 | spin_unlock_bh(&sess->conn_lock); |
| 797 | |
Nicholas Bellinger | 88dcd2d | 2015-02-26 22:19:15 -0800 | [diff] [blame] | 798 | rc = iscsit_start_kthreads(conn); |
| 799 | if (rc) |
| 800 | return rc; |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 801 | |
Nicholas Bellinger | 88dcd2d | 2015-02-26 22:19:15 -0800 | [diff] [blame] | 802 | iscsi_post_login_start_timers(conn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 803 | /* |
| 804 | * Determine CPU mask to ensure connection's RX and TX kthreads |
| 805 | * are scheduled on the same CPU. |
| 806 | */ |
| 807 | iscsit_thread_get_cpumask(conn); |
| 808 | conn->conn_rx_reset_cpumask = 1; |
| 809 | conn->conn_tx_reset_cpumask = 1; |
| 810 | |
| 811 | iscsit_dec_conn_usage_count(conn); |
| 812 | if (stop_timer) { |
| 813 | spin_lock_bh(&se_tpg->session_lock); |
| 814 | iscsit_stop_time2retain_timer(sess); |
| 815 | spin_unlock_bh(&se_tpg->session_lock); |
| 816 | } |
| 817 | iscsit_dec_session_usage_count(sess); |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | iscsi_set_session_parameters(sess->sess_ops, conn->param_list, 1); |
| 822 | iscsi_release_param_list(conn->param_list); |
| 823 | conn->param_list = NULL; |
| 824 | |
| 825 | iscsit_determine_maxcmdsn(sess); |
| 826 | |
| 827 | spin_lock_bh(&se_tpg->session_lock); |
| 828 | __transport_register_session(&sess->tpg->tpg_se_tpg, |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 829 | se_sess->se_node_acl, se_sess, sess); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 830 | pr_debug("Moving to TARG_SESS_STATE_LOGGED_IN.\n"); |
| 831 | sess->session_state = TARG_SESS_STATE_LOGGED_IN; |
| 832 | |
| 833 | pr_debug("iSCSI Login successful on CID: %hu from %s to %s:%hu,%hu\n", |
Nicholas Bellinger | 2f9bc89 | 2012-01-16 23:33:48 -0800 | [diff] [blame] | 834 | conn->cid, conn->login_ip, conn->local_ip, conn->local_port, |
| 835 | tpg->tpgt); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 836 | |
| 837 | spin_lock_bh(&sess->conn_lock); |
| 838 | list_add_tail(&conn->conn_list, &sess->sess_conn_list); |
| 839 | atomic_inc(&sess->nconn); |
| 840 | pr_debug("Incremented iSCSI Connection count to %hu from node:" |
| 841 | " %s\n", atomic_read(&sess->nconn), |
| 842 | sess->sess_ops->InitiatorName); |
| 843 | spin_unlock_bh(&sess->conn_lock); |
| 844 | |
| 845 | sess->sid = tpg->sid++; |
| 846 | if (!sess->sid) |
| 847 | sess->sid = tpg->sid++; |
| 848 | pr_debug("Established iSCSI session from node: %s\n", |
| 849 | sess->sess_ops->InitiatorName); |
| 850 | |
| 851 | tpg->nsessions++; |
| 852 | if (tpg->tpg_tiqn) |
| 853 | tpg->tpg_tiqn->tiqn_nsessions++; |
| 854 | |
| 855 | pr_debug("Incremented number of active iSCSI sessions to %u on" |
| 856 | " iSCSI Target Portal Group: %hu\n", tpg->nsessions, tpg->tpgt); |
| 857 | spin_unlock_bh(&se_tpg->session_lock); |
| 858 | |
Nicholas Bellinger | 88dcd2d | 2015-02-26 22:19:15 -0800 | [diff] [blame] | 859 | rc = iscsit_start_kthreads(conn); |
| 860 | if (rc) |
| 861 | return rc; |
| 862 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 863 | iscsi_post_login_start_timers(conn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 864 | /* |
| 865 | * Determine CPU mask to ensure connection's RX and TX kthreads |
| 866 | * are scheduled on the same CPU. |
| 867 | */ |
| 868 | iscsit_thread_get_cpumask(conn); |
| 869 | conn->conn_rx_reset_cpumask = 1; |
| 870 | conn->conn_tx_reset_cpumask = 1; |
| 871 | |
| 872 | iscsit_dec_conn_usage_count(conn); |
| 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | static void iscsi_handle_login_thread_timeout(unsigned long data) |
| 878 | { |
| 879 | struct iscsi_np *np = (struct iscsi_np *) data; |
| 880 | |
| 881 | spin_lock_bh(&np->np_thread_lock); |
| 882 | pr_err("iSCSI Login timeout on Network Portal %s:%hu\n", |
| 883 | np->np_ip, np->np_port); |
| 884 | |
| 885 | if (np->np_login_timer_flags & ISCSI_TF_STOP) { |
| 886 | spin_unlock_bh(&np->np_thread_lock); |
| 887 | return; |
| 888 | } |
| 889 | |
| 890 | if (np->np_thread) |
| 891 | send_sig(SIGINT, np->np_thread, 1); |
| 892 | |
| 893 | np->np_login_timer_flags &= ~ISCSI_TF_RUNNING; |
| 894 | spin_unlock_bh(&np->np_thread_lock); |
| 895 | } |
| 896 | |
| 897 | static void iscsi_start_login_thread_timer(struct iscsi_np *np) |
| 898 | { |
| 899 | /* |
| 900 | * This used the TA_LOGIN_TIMEOUT constant because at this |
| 901 | * point we do not have access to ISCSI_TPG_ATTRIB(tpg)->login_timeout |
| 902 | */ |
| 903 | spin_lock_bh(&np->np_thread_lock); |
| 904 | init_timer(&np->np_login_timer); |
| 905 | np->np_login_timer.expires = (get_jiffies_64() + TA_LOGIN_TIMEOUT * HZ); |
| 906 | np->np_login_timer.data = (unsigned long)np; |
| 907 | np->np_login_timer.function = iscsi_handle_login_thread_timeout; |
| 908 | np->np_login_timer_flags &= ~ISCSI_TF_STOP; |
| 909 | np->np_login_timer_flags |= ISCSI_TF_RUNNING; |
| 910 | add_timer(&np->np_login_timer); |
| 911 | |
| 912 | pr_debug("Added timeout timer to iSCSI login request for" |
| 913 | " %u seconds.\n", TA_LOGIN_TIMEOUT); |
| 914 | spin_unlock_bh(&np->np_thread_lock); |
| 915 | } |
| 916 | |
| 917 | static void iscsi_stop_login_thread_timer(struct iscsi_np *np) |
| 918 | { |
| 919 | spin_lock_bh(&np->np_thread_lock); |
| 920 | if (!(np->np_login_timer_flags & ISCSI_TF_RUNNING)) { |
| 921 | spin_unlock_bh(&np->np_thread_lock); |
| 922 | return; |
| 923 | } |
| 924 | np->np_login_timer_flags |= ISCSI_TF_STOP; |
| 925 | spin_unlock_bh(&np->np_thread_lock); |
| 926 | |
| 927 | del_timer_sync(&np->np_login_timer); |
| 928 | |
| 929 | spin_lock_bh(&np->np_thread_lock); |
| 930 | np->np_login_timer_flags &= ~ISCSI_TF_RUNNING; |
| 931 | spin_unlock_bh(&np->np_thread_lock); |
| 932 | } |
| 933 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 934 | int iscsit_setup_np( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 935 | struct iscsi_np *np, |
| 936 | struct __kernel_sockaddr_storage *sockaddr) |
| 937 | { |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 938 | struct socket *sock = NULL; |
Nicholas Bellinger | 837f645 | 2013-09-09 16:24:46 -0700 | [diff] [blame] | 939 | int backlog = ISCSIT_TCP_BACKLOG, ret, opt = 0, len; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 940 | |
| 941 | switch (np->np_network_transport) { |
| 942 | case ISCSI_TCP: |
| 943 | np->np_ip_proto = IPPROTO_TCP; |
| 944 | np->np_sock_type = SOCK_STREAM; |
| 945 | break; |
| 946 | case ISCSI_SCTP_TCP: |
| 947 | np->np_ip_proto = IPPROTO_SCTP; |
| 948 | np->np_sock_type = SOCK_STREAM; |
| 949 | break; |
| 950 | case ISCSI_SCTP_UDP: |
| 951 | np->np_ip_proto = IPPROTO_SCTP; |
| 952 | np->np_sock_type = SOCK_SEQPACKET; |
| 953 | break; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 954 | default: |
| 955 | pr_err("Unsupported network_transport: %d\n", |
| 956 | np->np_network_transport); |
| 957 | return -EINVAL; |
| 958 | } |
| 959 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 960 | np->np_ip_proto = IPPROTO_TCP; |
| 961 | np->np_sock_type = SOCK_STREAM; |
| 962 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 963 | ret = sock_create(sockaddr->ss_family, np->np_sock_type, |
| 964 | np->np_ip_proto, &sock); |
| 965 | if (ret < 0) { |
| 966 | pr_err("sock_create() failed.\n"); |
| 967 | return ret; |
| 968 | } |
| 969 | np->np_socket = sock; |
| 970 | /* |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 971 | * Setup the np->np_sockaddr from the passed sockaddr setup |
| 972 | * in iscsi_target_configfs.c code.. |
| 973 | */ |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 974 | memcpy(&np->np_sockaddr, sockaddr, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 975 | sizeof(struct __kernel_sockaddr_storage)); |
| 976 | |
| 977 | if (sockaddr->ss_family == AF_INET6) |
| 978 | len = sizeof(struct sockaddr_in6); |
| 979 | else |
| 980 | len = sizeof(struct sockaddr_in); |
| 981 | /* |
| 982 | * Set SO_REUSEADDR, and disable Nagel Algorithm with TCP_NODELAY. |
| 983 | */ |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 984 | /* FIXME: Someone please explain why this is endian-safe */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 985 | opt = 1; |
| 986 | if (np->np_network_transport == ISCSI_TCP) { |
| 987 | ret = kernel_setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, |
| 988 | (char *)&opt, sizeof(opt)); |
| 989 | if (ret < 0) { |
| 990 | pr_err("kernel_setsockopt() for TCP_NODELAY" |
| 991 | " failed: %d\n", ret); |
| 992 | goto fail; |
| 993 | } |
| 994 | } |
| 995 | |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 996 | /* FIXME: Someone please explain why this is endian-safe */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 997 | ret = kernel_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, |
| 998 | (char *)&opt, sizeof(opt)); |
| 999 | if (ret < 0) { |
| 1000 | pr_err("kernel_setsockopt() for SO_REUSEADDR" |
| 1001 | " failed\n"); |
| 1002 | goto fail; |
| 1003 | } |
| 1004 | |
Dax Kelson | 9f9ef6d | 2012-02-03 23:40:25 -0700 | [diff] [blame] | 1005 | ret = kernel_setsockopt(sock, IPPROTO_IP, IP_FREEBIND, |
| 1006 | (char *)&opt, sizeof(opt)); |
| 1007 | if (ret < 0) { |
| 1008 | pr_err("kernel_setsockopt() for IP_FREEBIND" |
| 1009 | " failed\n"); |
| 1010 | goto fail; |
| 1011 | } |
| 1012 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1013 | ret = kernel_bind(sock, (struct sockaddr *)&np->np_sockaddr, len); |
| 1014 | if (ret < 0) { |
| 1015 | pr_err("kernel_bind() failed: %d\n", ret); |
| 1016 | goto fail; |
| 1017 | } |
| 1018 | |
| 1019 | ret = kernel_listen(sock, backlog); |
| 1020 | if (ret != 0) { |
| 1021 | pr_err("kernel_listen() failed: %d\n", ret); |
| 1022 | goto fail; |
| 1023 | } |
| 1024 | |
| 1025 | return 0; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1026 | fail: |
| 1027 | np->np_socket = NULL; |
Joern Engel | 94e16e9 | 2014-09-02 17:49:53 -0400 | [diff] [blame] | 1028 | sock_release(sock); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1029 | return ret; |
| 1030 | } |
| 1031 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1032 | int iscsi_target_setup_login_socket( |
| 1033 | struct iscsi_np *np, |
| 1034 | struct __kernel_sockaddr_storage *sockaddr) |
| 1035 | { |
| 1036 | struct iscsit_transport *t; |
| 1037 | int rc; |
| 1038 | |
| 1039 | t = iscsit_get_transport(np->np_network_transport); |
| 1040 | if (!t) |
| 1041 | return -EINVAL; |
| 1042 | |
| 1043 | rc = t->iscsit_setup_np(np, sockaddr); |
| 1044 | if (rc < 0) { |
| 1045 | iscsit_put_transport(t); |
| 1046 | return rc; |
| 1047 | } |
| 1048 | |
| 1049 | np->np_transport = t; |
Sagi Grimberg | 14f4b54 | 2014-04-29 13:13:47 +0300 | [diff] [blame] | 1050 | np->enabled = true; |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | int iscsit_accept_np(struct iscsi_np *np, struct iscsi_conn *conn) |
| 1055 | { |
| 1056 | struct socket *new_sock, *sock = np->np_socket; |
| 1057 | struct sockaddr_in sock_in; |
| 1058 | struct sockaddr_in6 sock_in6; |
| 1059 | int rc, err; |
| 1060 | |
| 1061 | rc = kernel_accept(sock, &new_sock, 0); |
| 1062 | if (rc < 0) |
| 1063 | return rc; |
| 1064 | |
| 1065 | conn->sock = new_sock; |
| 1066 | conn->login_family = np->np_sockaddr.ss_family; |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1067 | |
| 1068 | if (np->np_sockaddr.ss_family == AF_INET6) { |
| 1069 | memset(&sock_in6, 0, sizeof(struct sockaddr_in6)); |
| 1070 | |
| 1071 | rc = conn->sock->ops->getname(conn->sock, |
| 1072 | (struct sockaddr *)&sock_in6, &err, 1); |
| 1073 | if (!rc) { |
Chris Leech | dfecf61 | 2013-08-12 11:26:28 -0700 | [diff] [blame] | 1074 | if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) |
| 1075 | snprintf(conn->login_ip, sizeof(conn->login_ip), "[%pI6c]", |
| 1076 | &sock_in6.sin6_addr.in6_u); |
| 1077 | else |
| 1078 | snprintf(conn->login_ip, sizeof(conn->login_ip), "%pI4", |
| 1079 | &sock_in6.sin6_addr.s6_addr32[3]); |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1080 | conn->login_port = ntohs(sock_in6.sin6_port); |
| 1081 | } |
| 1082 | |
| 1083 | rc = conn->sock->ops->getname(conn->sock, |
| 1084 | (struct sockaddr *)&sock_in6, &err, 0); |
| 1085 | if (!rc) { |
Chris Leech | dfecf61 | 2013-08-12 11:26:28 -0700 | [diff] [blame] | 1086 | if (!ipv6_addr_v4mapped(&sock_in6.sin6_addr)) |
| 1087 | snprintf(conn->local_ip, sizeof(conn->local_ip), "[%pI6c]", |
| 1088 | &sock_in6.sin6_addr.in6_u); |
| 1089 | else |
| 1090 | snprintf(conn->local_ip, sizeof(conn->local_ip), "%pI4", |
| 1091 | &sock_in6.sin6_addr.s6_addr32[3]); |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1092 | conn->local_port = ntohs(sock_in6.sin6_port); |
| 1093 | } |
| 1094 | } else { |
| 1095 | memset(&sock_in, 0, sizeof(struct sockaddr_in)); |
| 1096 | |
| 1097 | rc = conn->sock->ops->getname(conn->sock, |
| 1098 | (struct sockaddr *)&sock_in, &err, 1); |
| 1099 | if (!rc) { |
| 1100 | sprintf(conn->login_ip, "%pI4", |
| 1101 | &sock_in.sin_addr.s_addr); |
| 1102 | conn->login_port = ntohs(sock_in.sin_port); |
| 1103 | } |
| 1104 | |
| 1105 | rc = conn->sock->ops->getname(conn->sock, |
| 1106 | (struct sockaddr *)&sock_in, &err, 0); |
| 1107 | if (!rc) { |
| 1108 | sprintf(conn->local_ip, "%pI4", |
| 1109 | &sock_in.sin_addr.s_addr); |
| 1110 | conn->local_port = ntohs(sock_in.sin_port); |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
| 1117 | int iscsit_get_login_rx(struct iscsi_conn *conn, struct iscsi_login *login) |
| 1118 | { |
| 1119 | struct iscsi_login_req *login_req; |
| 1120 | u32 padding = 0, payload_length; |
| 1121 | |
| 1122 | if (iscsi_login_rx_data(conn, login->req, ISCSI_HDR_LEN) < 0) |
| 1123 | return -1; |
| 1124 | |
| 1125 | login_req = (struct iscsi_login_req *)login->req; |
| 1126 | payload_length = ntoh24(login_req->dlength); |
| 1127 | padding = ((-payload_length) & 3); |
| 1128 | |
| 1129 | pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x," |
| 1130 | " CmdSN: 0x%08x, ExpStatSN: 0x%08x, CID: %hu, Length: %u\n", |
| 1131 | login_req->flags, login_req->itt, login_req->cmdsn, |
| 1132 | login_req->exp_statsn, login_req->cid, payload_length); |
| 1133 | /* |
| 1134 | * Setup the initial iscsi_login values from the leading |
| 1135 | * login request PDU. |
| 1136 | */ |
| 1137 | if (login->first_request) { |
| 1138 | login_req = (struct iscsi_login_req *)login->req; |
| 1139 | login->leading_connection = (!login_req->tsih) ? 1 : 0; |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1140 | login->current_stage = ISCSI_LOGIN_CURRENT_STAGE(login_req->flags); |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1141 | login->version_min = login_req->min_version; |
| 1142 | login->version_max = login_req->max_version; |
| 1143 | memcpy(login->isid, login_req->isid, 6); |
| 1144 | login->cmd_sn = be32_to_cpu(login_req->cmdsn); |
| 1145 | login->init_task_tag = login_req->itt; |
| 1146 | login->initial_exp_statsn = be32_to_cpu(login_req->exp_statsn); |
| 1147 | login->cid = be16_to_cpu(login_req->cid); |
| 1148 | login->tsih = be16_to_cpu(login_req->tsih); |
| 1149 | } |
| 1150 | |
| 1151 | if (iscsi_target_check_login_request(conn, login) < 0) |
| 1152 | return -1; |
| 1153 | |
| 1154 | memset(login->req_buf, 0, MAX_KEY_VALUE_PAIRS); |
| 1155 | if (iscsi_login_rx_data(conn, login->req_buf, |
| 1156 | payload_length + padding) < 0) |
| 1157 | return -1; |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | int iscsit_put_login_tx(struct iscsi_conn *conn, struct iscsi_login *login, |
| 1163 | u32 length) |
| 1164 | { |
| 1165 | if (iscsi_login_tx_data(conn, login->rsp, login->rsp_buf, length) < 0) |
| 1166 | return -1; |
| 1167 | |
| 1168 | return 0; |
| 1169 | } |
| 1170 | |
| 1171 | static int |
| 1172 | iscsit_conn_set_transport(struct iscsi_conn *conn, struct iscsit_transport *t) |
| 1173 | { |
| 1174 | int rc; |
| 1175 | |
| 1176 | if (!t->owner) { |
| 1177 | conn->conn_transport = t; |
| 1178 | return 0; |
| 1179 | } |
| 1180 | |
| 1181 | rc = try_module_get(t->owner); |
| 1182 | if (!rc) { |
| 1183 | pr_err("try_module_get() failed for %s\n", t->name); |
| 1184 | return -EINVAL; |
| 1185 | } |
| 1186 | |
| 1187 | conn->conn_transport = t; |
| 1188 | return 0; |
| 1189 | } |
| 1190 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1191 | void iscsi_target_login_sess_out(struct iscsi_conn *conn, |
| 1192 | struct iscsi_np *np, bool zero_tsih, bool new_sess) |
| 1193 | { |
Christophe Vu-Brugier | 0bcc297 | 2014-06-06 17:15:16 +0200 | [diff] [blame] | 1194 | if (!new_sess) |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1195 | goto old_sess_out; |
| 1196 | |
| 1197 | pr_err("iSCSI Login negotiation failed.\n"); |
| 1198 | iscsit_collect_login_stats(conn, ISCSI_STATUS_CLS_INITIATOR_ERR, |
| 1199 | ISCSI_LOGIN_STATUS_INIT_ERR); |
| 1200 | if (!zero_tsih || !conn->sess) |
| 1201 | goto old_sess_out; |
| 1202 | if (conn->sess->se_sess) |
| 1203 | transport_free_session(conn->sess->se_sess); |
| 1204 | if (conn->sess->session_index != 0) { |
| 1205 | spin_lock_bh(&sess_idr_lock); |
| 1206 | idr_remove(&sess_idr, conn->sess->session_index); |
| 1207 | spin_unlock_bh(&sess_idr_lock); |
| 1208 | } |
| 1209 | kfree(conn->sess->sess_ops); |
| 1210 | kfree(conn->sess); |
Sagi Grimberg | a0b3b9b | 2014-12-15 15:08:54 +0200 | [diff] [blame] | 1211 | conn->sess = NULL; |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1212 | |
| 1213 | old_sess_out: |
| 1214 | iscsi_stop_login_thread_timer(np); |
| 1215 | /* |
| 1216 | * If login negotiation fails check if the Time2Retain timer |
| 1217 | * needs to be restarted. |
| 1218 | */ |
| 1219 | if (!zero_tsih && conn->sess) { |
| 1220 | spin_lock_bh(&conn->sess->conn_lock); |
| 1221 | if (conn->sess->session_state == TARG_SESS_STATE_FAILED) { |
| 1222 | struct se_portal_group *se_tpg = |
Andy Grover | 60bfcf8 | 2013-10-09 11:05:58 -0700 | [diff] [blame] | 1223 | &conn->tpg->tpg_se_tpg; |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1224 | |
| 1225 | atomic_set(&conn->sess->session_continuation, 0); |
| 1226 | spin_unlock_bh(&conn->sess->conn_lock); |
| 1227 | spin_lock_bh(&se_tpg->session_lock); |
| 1228 | iscsit_start_time2retain_handler(conn->sess); |
| 1229 | spin_unlock_bh(&se_tpg->session_lock); |
| 1230 | } else |
| 1231 | spin_unlock_bh(&conn->sess->conn_lock); |
| 1232 | iscsit_dec_session_usage_count(conn->sess); |
| 1233 | } |
| 1234 | |
| 1235 | if (!IS_ERR(conn->conn_rx_hash.tfm)) |
| 1236 | crypto_free_hash(conn->conn_rx_hash.tfm); |
| 1237 | if (!IS_ERR(conn->conn_tx_hash.tfm)) |
| 1238 | crypto_free_hash(conn->conn_tx_hash.tfm); |
| 1239 | |
Joern Engel | fbecb65 | 2014-09-02 17:49:47 -0400 | [diff] [blame] | 1240 | free_cpumask_var(conn->conn_cpumask); |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1241 | |
| 1242 | kfree(conn->conn_ops); |
| 1243 | |
| 1244 | if (conn->param_list) { |
| 1245 | iscsi_release_param_list(conn->param_list); |
| 1246 | conn->param_list = NULL; |
| 1247 | } |
| 1248 | iscsi_target_nego_release(conn); |
| 1249 | |
| 1250 | if (conn->sock) { |
| 1251 | sock_release(conn->sock); |
| 1252 | conn->sock = NULL; |
| 1253 | } |
| 1254 | |
Sagi Grimberg | 954f237 | 2014-12-02 16:57:17 +0200 | [diff] [blame] | 1255 | if (conn->conn_transport->iscsit_wait_conn) |
| 1256 | conn->conn_transport->iscsit_wait_conn(conn); |
| 1257 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1258 | if (conn->conn_transport->iscsit_free_conn) |
| 1259 | conn->conn_transport->iscsit_free_conn(conn); |
| 1260 | |
| 1261 | iscsit_put_transport(conn->conn_transport); |
| 1262 | kfree(conn); |
| 1263 | } |
| 1264 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1265 | static int __iscsi_target_login_thread(struct iscsi_np *np) |
| 1266 | { |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1267 | u8 *buffer, zero_tsih = 0; |
Mikulas Patocka | 81a9c5e | 2014-06-23 13:42:37 -0400 | [diff] [blame] | 1268 | int ret = 0, rc; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1269 | struct iscsi_conn *conn = NULL; |
| 1270 | struct iscsi_login *login; |
| 1271 | struct iscsi_portal_group *tpg = NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1272 | struct iscsi_login_req *pdu; |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1273 | struct iscsi_tpg_np *tpg_np; |
| 1274 | bool new_sess = false; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1275 | |
| 1276 | flush_signals(current); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1277 | |
| 1278 | spin_lock_bh(&np->np_thread_lock); |
| 1279 | if (np->np_thread_state == ISCSI_NP_THREAD_RESET) { |
| 1280 | np->np_thread_state = ISCSI_NP_THREAD_ACTIVE; |
| 1281 | complete(&np->np_restart_comp); |
Mikulas Patocka | 81a9c5e | 2014-06-23 13:42:37 -0400 | [diff] [blame] | 1282 | } else if (np->np_thread_state == ISCSI_NP_THREAD_SHUTDOWN) { |
| 1283 | spin_unlock_bh(&np->np_thread_lock); |
| 1284 | goto exit; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1285 | } else { |
| 1286 | np->np_thread_state = ISCSI_NP_THREAD_ACTIVE; |
| 1287 | } |
| 1288 | spin_unlock_bh(&np->np_thread_lock); |
| 1289 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1290 | conn = kzalloc(sizeof(struct iscsi_conn), GFP_KERNEL); |
| 1291 | if (!conn) { |
| 1292 | pr_err("Could not allocate memory for" |
| 1293 | " new connection\n"); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1294 | /* Get another socket */ |
| 1295 | return 1; |
| 1296 | } |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1297 | pr_debug("Moving to TARG_CONN_STATE_FREE.\n"); |
| 1298 | conn->conn_state = TARG_CONN_STATE_FREE; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1299 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1300 | if (iscsit_conn_set_transport(conn, np->np_transport) < 0) { |
| 1301 | kfree(conn); |
| 1302 | return 1; |
| 1303 | } |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1304 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1305 | rc = np->np_transport->iscsit_accept_np(np, conn); |
| 1306 | if (rc == -ENOSYS) { |
| 1307 | complete(&np->np_restart_comp); |
| 1308 | iscsit_put_transport(conn->conn_transport); |
| 1309 | kfree(conn); |
| 1310 | conn = NULL; |
| 1311 | goto exit; |
| 1312 | } else if (rc < 0) { |
| 1313 | spin_lock_bh(&np->np_thread_lock); |
| 1314 | if (np->np_thread_state == ISCSI_NP_THREAD_RESET) { |
| 1315 | spin_unlock_bh(&np->np_thread_lock); |
| 1316 | complete(&np->np_restart_comp); |
Nicholas Bellinger | c9a03c1 | 2013-08-18 15:07:44 -0700 | [diff] [blame] | 1317 | iscsit_put_transport(conn->conn_transport); |
| 1318 | kfree(conn); |
| 1319 | conn = NULL; |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1320 | /* Get another socket */ |
| 1321 | return 1; |
| 1322 | } |
| 1323 | spin_unlock_bh(&np->np_thread_lock); |
| 1324 | iscsit_put_transport(conn->conn_transport); |
| 1325 | kfree(conn); |
| 1326 | conn = NULL; |
| 1327 | goto out; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1328 | } |
| 1329 | /* |
| 1330 | * Perform the remaining iSCSI connection initialization items.. |
| 1331 | */ |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1332 | login = iscsi_login_init_conn(conn); |
| 1333 | if (!login) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1334 | goto new_sess_out; |
| 1335 | } |
| 1336 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1337 | iscsi_start_login_thread_timer(np); |
| 1338 | |
| 1339 | pr_debug("Moving to TARG_CONN_STATE_XPT_UP.\n"); |
| 1340 | conn->conn_state = TARG_CONN_STATE_XPT_UP; |
| 1341 | /* |
| 1342 | * This will process the first login request + payload.. |
| 1343 | */ |
| 1344 | rc = np->np_transport->iscsit_get_login_rx(conn, login); |
| 1345 | if (rc == 1) |
| 1346 | return 1; |
| 1347 | else if (rc < 0) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1348 | goto new_sess_out; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1349 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1350 | buffer = &login->req[0]; |
| 1351 | pdu = (struct iscsi_login_req *)buffer; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1352 | /* |
| 1353 | * Used by iscsit_tx_login_rsp() for Login Resonses PDUs |
| 1354 | * when Status-Class != 0. |
| 1355 | */ |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1356 | conn->login_itt = pdu->itt; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1357 | |
| 1358 | spin_lock_bh(&np->np_thread_lock); |
| 1359 | if (np->np_thread_state != ISCSI_NP_THREAD_ACTIVE) { |
| 1360 | spin_unlock_bh(&np->np_thread_lock); |
| 1361 | pr_err("iSCSI Network Portal on %s:%hu currently not" |
| 1362 | " active.\n", np->np_ip, np->np_port); |
| 1363 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
| 1364 | ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE); |
| 1365 | goto new_sess_out; |
| 1366 | } |
| 1367 | spin_unlock_bh(&np->np_thread_lock); |
| 1368 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1369 | conn->network_transport = np->np_network_transport; |
| 1370 | |
| 1371 | pr_debug("Received iSCSI login request from %s on %s Network" |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1372 | " Portal %s:%hu\n", conn->login_ip, np->np_transport->name, |
| 1373 | conn->local_ip, conn->local_port); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1374 | |
| 1375 | pr_debug("Moving to TARG_CONN_STATE_IN_LOGIN.\n"); |
| 1376 | conn->conn_state = TARG_CONN_STATE_IN_LOGIN; |
| 1377 | |
| 1378 | if (iscsi_login_check_initiator_version(conn, pdu->max_version, |
| 1379 | pdu->min_version) < 0) |
| 1380 | goto new_sess_out; |
| 1381 | |
| 1382 | zero_tsih = (pdu->tsih == 0x0000); |
Andy Grover | ee1b1b9 | 2012-07-12 17:34:54 -0700 | [diff] [blame] | 1383 | if (zero_tsih) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1384 | /* |
| 1385 | * This is the leading connection of a new session. |
| 1386 | * We wait until after authentication to check for |
| 1387 | * session reinstatement. |
| 1388 | */ |
| 1389 | if (iscsi_login_zero_tsih_s1(conn, buffer) < 0) |
| 1390 | goto new_sess_out; |
| 1391 | } else { |
| 1392 | /* |
| 1393 | * Add a new connection to an existing session. |
| 1394 | * We check for a non-existant session in |
| 1395 | * iscsi_login_non_zero_tsih_s2() below based |
| 1396 | * on ISID/TSIH, but wait until after authentication |
| 1397 | * to check for connection reinstatement, etc. |
| 1398 | */ |
| 1399 | if (iscsi_login_non_zero_tsih_s1(conn, buffer) < 0) |
| 1400 | goto new_sess_out; |
| 1401 | } |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1402 | /* |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1403 | * SessionType: Discovery |
| 1404 | * |
| 1405 | * Locates Default Portal |
| 1406 | * |
| 1407 | * SessionType: Normal |
| 1408 | * |
| 1409 | * Locates Target Portal from NP -> Target IQN |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1410 | */ |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1411 | rc = iscsi_target_locate_portal(np, conn, login); |
| 1412 | if (rc < 0) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1413 | tpg = conn->tpg; |
| 1414 | goto new_sess_out; |
| 1415 | } |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1416 | login->zero_tsih = zero_tsih; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1417 | |
Sagi Grimberg | 23a548e | 2014-12-02 16:57:35 +0200 | [diff] [blame] | 1418 | conn->sess->se_sess->sup_prot_ops = |
| 1419 | conn->conn_transport->iscsit_get_sup_prot_ops(conn); |
| 1420 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1421 | tpg = conn->tpg; |
| 1422 | if (!tpg) { |
| 1423 | pr_err("Unable to locate struct iscsi_conn->tpg\n"); |
| 1424 | goto new_sess_out; |
| 1425 | } |
| 1426 | |
| 1427 | if (zero_tsih) { |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1428 | if (iscsi_login_zero_tsih_s2(conn) < 0) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1429 | goto new_sess_out; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1430 | } else { |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1431 | if (iscsi_login_non_zero_tsih_s2(conn, buffer) < 0) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1432 | goto old_sess_out; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1435 | ret = iscsi_target_start_negotiation(login, conn); |
| 1436 | if (ret < 0) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1437 | goto new_sess_out; |
| 1438 | |
| 1439 | if (!conn->sess) { |
| 1440 | pr_err("struct iscsi_conn session pointer is NULL!\n"); |
| 1441 | goto new_sess_out; |
| 1442 | } |
| 1443 | |
| 1444 | iscsi_stop_login_thread_timer(np); |
| 1445 | |
| 1446 | if (signal_pending(current)) |
| 1447 | goto new_sess_out; |
| 1448 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1449 | if (ret == 1) { |
| 1450 | tpg_np = conn->tpg_np; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1451 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1452 | ret = iscsi_post_login_handler(np, conn, zero_tsih); |
| 1453 | if (ret < 0) |
| 1454 | goto new_sess_out; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1455 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1456 | iscsit_deaccess_np(np, tpg, tpg_np); |
| 1457 | } |
| 1458 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1459 | tpg = NULL; |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1460 | tpg_np = NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1461 | /* Get another socket */ |
| 1462 | return 1; |
| 1463 | |
| 1464 | new_sess_out: |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1465 | new_sess = true; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1466 | old_sess_out: |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1467 | tpg_np = conn->tpg_np; |
| 1468 | iscsi_target_login_sess_out(conn, np, zero_tsih, new_sess); |
| 1469 | new_sess = false; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1470 | |
| 1471 | if (tpg) { |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1472 | iscsit_deaccess_np(np, tpg, tpg_np); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1473 | tpg = NULL; |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 1474 | tpg_np = NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | out: |
Mikulas Patocka | 81a9c5e | 2014-06-23 13:42:37 -0400 | [diff] [blame] | 1478 | return 1; |
| 1479 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1480 | exit: |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1481 | iscsi_stop_login_thread_timer(np); |
| 1482 | spin_lock_bh(&np->np_thread_lock); |
| 1483 | np->np_thread_state = ISCSI_NP_THREAD_EXIT; |
| 1484 | spin_unlock_bh(&np->np_thread_lock); |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 1485 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | int iscsi_target_login_thread(void *arg) |
| 1490 | { |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 1491 | struct iscsi_np *np = arg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1492 | int ret; |
| 1493 | |
| 1494 | allow_signal(SIGINT); |
| 1495 | |
Mikulas Patocka | 81a9c5e | 2014-06-23 13:42:37 -0400 | [diff] [blame] | 1496 | while (1) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1497 | ret = __iscsi_target_login_thread(np); |
| 1498 | /* |
| 1499 | * We break and exit here unless another sock_accept() call |
| 1500 | * is expected. |
| 1501 | */ |
| 1502 | if (ret != 1) |
| 1503 | break; |
| 1504 | } |
| 1505 | |
| 1506 | return 0; |
| 1507 | } |