1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * This file contains the login functions used by the iSCSI Target driver.
5 * (c) Copyright 2007-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 ******************************************************************************/
11 #include <crypto/hash.h>
12 #include <linux/module.h>
13 #include <linux/string.h>
14 #include <linux/kthread.h>
15 #include <linux/sched/signal.h>
16 #include <linux/idr.h>
17 #include <linux/tcp.h> /* TCP_NODELAY */
18 #include <net/ipv6.h> /* ipv6_addr_v4mapped() */
19 #include <scsi/iscsi_proto.h>
20 #include <target/target_core_base.h>
21 #include <target/target_core_fabric.h>
23 #include <target/iscsi/iscsi_target_core.h>
24 #include <target/iscsi/iscsi_target_stat.h>
25 #include "iscsi_target_device.h"
26 #include "iscsi_target_nego.h"
27 #include "iscsi_target_erl0.h"
28 #include "iscsi_target_erl2.h"
29 #include "iscsi_target_login.h"
30 #include "iscsi_target_tpg.h"
31 #include "iscsi_target_util.h"
32 #include "iscsi_target.h"
33 #include "iscsi_target_parameters.h"
35 #include <target/iscsi/iscsi_transport.h>
37 static struct iscsi_login
*iscsi_login_init_conn(struct iscsi_conn
*conn
)
39 struct iscsi_login
*login
;
41 login
= kzalloc(sizeof(struct iscsi_login
), GFP_KERNEL
);
43 pr_err("Unable to allocate memory for struct iscsi_login.\n");
48 login
->first_request
= 1;
50 login
->req_buf
= kzalloc(MAX_KEY_VALUE_PAIRS
, GFP_KERNEL
);
51 if (!login
->req_buf
) {
52 pr_err("Unable to allocate memory for response buffer.\n");
56 login
->rsp_buf
= kzalloc(MAX_KEY_VALUE_PAIRS
, GFP_KERNEL
);
57 if (!login
->rsp_buf
) {
58 pr_err("Unable to allocate memory for request buffer.\n");
62 conn
->conn_login
= login
;
67 kfree(login
->req_buf
);
74 * Used by iscsi_target_nego.c:iscsi_target_locate_portal() to setup
75 * per struct iscsi_conn libcrypto contexts for crc32c and crc32-intel
77 int iscsi_login_setup_crypto(struct iscsi_conn
*conn
)
79 struct crypto_ahash
*tfm
;
82 * Setup slicing by CRC32C algorithm for RX and TX libcrypto contexts
83 * which will default to crc32c_intel.ko for cpu_has_xmm4_2, or fallback
84 * to software 1x8 byte slicing from crc32c.ko
86 tfm
= crypto_alloc_ahash("crc32c", 0, CRYPTO_ALG_ASYNC
);
88 pr_err("crypto_alloc_ahash() failed\n");
92 conn
->conn_rx_hash
= ahash_request_alloc(tfm
, GFP_KERNEL
);
93 if (!conn
->conn_rx_hash
) {
94 pr_err("ahash_request_alloc() failed for conn_rx_hash\n");
95 crypto_free_ahash(tfm
);
98 ahash_request_set_callback(conn
->conn_rx_hash
, 0, NULL
, NULL
);
100 conn
->conn_tx_hash
= ahash_request_alloc(tfm
, GFP_KERNEL
);
101 if (!conn
->conn_tx_hash
) {
102 pr_err("ahash_request_alloc() failed for conn_tx_hash\n");
103 ahash_request_free(conn
->conn_rx_hash
);
104 conn
->conn_rx_hash
= NULL
;
105 crypto_free_ahash(tfm
);
108 ahash_request_set_callback(conn
->conn_tx_hash
, 0, NULL
, NULL
);
113 static int iscsi_login_check_initiator_version(
114 struct iscsi_conn
*conn
,
118 if ((version_max
!= 0x00) || (version_min
!= 0x00)) {
119 pr_err("Unsupported iSCSI IETF Pre-RFC Revision,"
120 " version Min/Max 0x%02x/0x%02x, rejecting login.\n",
121 version_min
, version_max
);
122 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_INITIATOR_ERR
,
123 ISCSI_LOGIN_STATUS_NO_VERSION
);
130 int iscsi_check_for_session_reinstatement(struct iscsi_conn
*conn
)
133 struct iscsi_param
*initiatorname_param
= NULL
, *sessiontype_param
= NULL
;
134 struct iscsi_portal_group
*tpg
= conn
->tpg
;
135 struct iscsi_session
*sess
= NULL
, *sess_p
= NULL
;
136 struct se_portal_group
*se_tpg
= &tpg
->tpg_se_tpg
;
137 struct se_session
*se_sess
, *se_sess_tmp
;
139 initiatorname_param
= iscsi_find_param_from_key(
140 INITIATORNAME
, conn
->param_list
);
141 sessiontype_param
= iscsi_find_param_from_key(
142 SESSIONTYPE
, conn
->param_list
);
143 if (!initiatorname_param
|| !sessiontype_param
) {
144 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_INITIATOR_ERR
,
145 ISCSI_LOGIN_STATUS_MISSING_FIELDS
);
149 sessiontype
= (strncmp(sessiontype_param
->value
, NORMAL
, 6)) ? 1 : 0;
151 spin_lock_bh(&se_tpg
->session_lock
);
152 list_for_each_entry_safe(se_sess
, se_sess_tmp
, &se_tpg
->tpg_sess_list
,
155 sess_p
= se_sess
->fabric_sess_ptr
;
156 spin_lock(&sess_p
->conn_lock
);
157 if (atomic_read(&sess_p
->session_fall_back_to_erl0
) ||
158 atomic_read(&sess_p
->session_logout
) ||
159 (sess_p
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
)) {
160 spin_unlock(&sess_p
->conn_lock
);
163 if (!memcmp(sess_p
->isid
, conn
->sess
->isid
, 6) &&
164 (!strcmp(sess_p
->sess_ops
->InitiatorName
,
165 initiatorname_param
->value
) &&
166 (sess_p
->sess_ops
->SessionType
== sessiontype
))) {
167 atomic_set(&sess_p
->session_reinstatement
, 1);
168 atomic_set(&sess_p
->session_fall_back_to_erl0
, 1);
169 spin_unlock(&sess_p
->conn_lock
);
170 iscsit_inc_session_usage_count(sess_p
);
171 iscsit_stop_time2retain_timer(sess_p
);
175 spin_unlock(&sess_p
->conn_lock
);
177 spin_unlock_bh(&se_tpg
->session_lock
);
179 * If the Time2Retain handler has expired, the session is already gone.
184 pr_debug("%s iSCSI Session SID %u is still active for %s,"
185 " performing session reinstatement.\n", (sessiontype
) ?
186 "Discovery" : "Normal", sess
->sid
,
187 sess
->sess_ops
->InitiatorName
);
189 spin_lock_bh(&sess
->conn_lock
);
190 if (sess
->session_state
== TARG_SESS_STATE_FAILED
) {
191 spin_unlock_bh(&sess
->conn_lock
);
192 iscsit_dec_session_usage_count(sess
);
193 iscsit_close_session(sess
);
196 spin_unlock_bh(&sess
->conn_lock
);
198 iscsit_stop_session(sess
, 1, 1);
199 iscsit_dec_session_usage_count(sess
);
201 iscsit_close_session(sess
);
205 static int iscsi_login_set_conn_values(
206 struct iscsi_session
*sess
,
207 struct iscsi_conn
*conn
,
212 conn
->cid
= be16_to_cpu(cid
);
214 * Generate a random Status sequence number (statsn) for the new
217 ret
= get_random_bytes_wait(&conn
->stat_sn
, sizeof(u32
));
221 mutex_lock(&auth_id_lock
);
222 conn
->auth_id
= iscsit_global
->auth_id
++;
223 mutex_unlock(&auth_id_lock
);
227 __printf(2, 3) int iscsi_change_param_sprintf(
228 struct iscsi_conn
*conn
,
229 const char *fmt
, ...)
232 unsigned char buf
[64];
234 memset(buf
, 0, sizeof buf
);
237 vsnprintf(buf
, sizeof buf
, fmt
, args
);
240 if (iscsi_change_param_value(buf
, conn
->param_list
, 0) < 0) {
241 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
242 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
248 EXPORT_SYMBOL(iscsi_change_param_sprintf
);
251 * This is the leading connection of a new session,
252 * or session reinstatement.
254 static int iscsi_login_zero_tsih_s1(
255 struct iscsi_conn
*conn
,
258 struct iscsi_session
*sess
= NULL
;
259 struct iscsi_login_req
*pdu
= (struct iscsi_login_req
*)buf
;
262 sess
= kzalloc(sizeof(struct iscsi_session
), GFP_KERNEL
);
264 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
265 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
266 pr_err("Could not allocate memory for session\n");
270 if (iscsi_login_set_conn_values(sess
, conn
, pdu
->cid
))
273 sess
->init_task_tag
= pdu
->itt
;
274 memcpy(&sess
->isid
, pdu
->isid
, 6);
275 sess
->exp_cmd_sn
= be32_to_cpu(pdu
->cmdsn
);
276 INIT_LIST_HEAD(&sess
->sess_conn_list
);
277 INIT_LIST_HEAD(&sess
->sess_ooo_cmdsn_list
);
278 INIT_LIST_HEAD(&sess
->cr_active_list
);
279 INIT_LIST_HEAD(&sess
->cr_inactive_list
);
280 init_completion(&sess
->async_msg_comp
);
281 init_completion(&sess
->reinstatement_comp
);
282 init_completion(&sess
->session_wait_comp
);
283 init_completion(&sess
->session_waiting_on_uc_comp
);
284 mutex_init(&sess
->cmdsn_mutex
);
285 spin_lock_init(&sess
->conn_lock
);
286 spin_lock_init(&sess
->cr_a_lock
);
287 spin_lock_init(&sess
->cr_i_lock
);
288 spin_lock_init(&sess
->session_usage_lock
);
289 spin_lock_init(&sess
->ttt_lock
);
291 timer_setup(&sess
->time2retain_timer
,
292 iscsit_handle_time2retain_timeout
, 0);
294 ret
= ida_alloc(&sess_ida
, GFP_KERNEL
);
296 pr_err("Session ID allocation failed %d\n", ret
);
297 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
298 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
302 sess
->session_index
= ret
;
303 sess
->creation_time
= get_jiffies_64();
305 * The FFP CmdSN window values will be allocated from the TPG's
306 * Initiator Node's ACL once the login has been successfully completed.
308 atomic_set(&sess
->max_cmd_sn
, be32_to_cpu(pdu
->cmdsn
));
310 sess
->sess_ops
= kzalloc(sizeof(struct iscsi_sess_ops
), GFP_KERNEL
);
311 if (!sess
->sess_ops
) {
312 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
313 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
314 pr_err("Unable to allocate memory for"
315 " struct iscsi_sess_ops.\n");
319 sess
->se_sess
= transport_alloc_session(TARGET_PROT_NORMAL
);
320 if (IS_ERR(sess
->se_sess
)) {
321 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
322 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
329 kfree(sess
->sess_ops
);
331 ida_free(&sess_ida
, sess
->session_index
);
338 static int iscsi_login_zero_tsih_s2(
339 struct iscsi_conn
*conn
)
341 struct iscsi_node_attrib
*na
;
342 struct iscsi_session
*sess
= conn
->sess
;
345 sess
->tpg
= conn
->tpg
;
348 * Assign a new TPG Session Handle. Note this is protected with
349 * struct iscsi_portal_group->np_login_sem from iscsit_access_np().
351 sess
->tsih
= ++sess
->tpg
->ntsih
;
353 sess
->tsih
= ++sess
->tpg
->ntsih
;
356 * Create the default params from user defined values..
358 if (iscsi_copy_param_list(&conn
->param_list
,
359 conn
->tpg
->param_list
, 1) < 0) {
360 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
361 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
365 if (conn
->conn_transport
->transport_type
== ISCSI_INFINIBAND
)
368 iscsi_set_keys_to_negotiate(conn
->param_list
, iser
);
370 if (sess
->sess_ops
->SessionType
)
371 return iscsi_set_keys_irrelevant_for_discovery(
374 na
= iscsit_tpg_get_node_attrib(sess
);
377 * Need to send TargetPortalGroupTag back in first login response
378 * on any iSCSI connection where the Initiator provides TargetName.
379 * See 5.3.1. Login Phase Start
381 * In our case, we have already located the struct iscsi_tiqn at this point.
383 if (iscsi_change_param_sprintf(conn
, "TargetPortalGroupTag=%hu", sess
->tpg
->tpgt
))
387 * Workaround for Initiators that have broken connection recovery logic.
389 * "We would really like to get rid of this." Linux-iSCSI.org team
391 if (iscsi_change_param_sprintf(conn
, "ErrorRecoveryLevel=%d", na
->default_erl
))
395 * Set RDMAExtensions=Yes by default for iSER enabled network portals
398 struct iscsi_param
*param
;
399 unsigned long mrdsl
, off
;
402 if (iscsi_change_param_sprintf(conn
, "RDMAExtensions=Yes"))
406 * Make MaxRecvDataSegmentLength PAGE_SIZE aligned for
407 * Immediate Data + Unsolicited Data-OUT if necessary..
409 param
= iscsi_find_param_from_key("MaxRecvDataSegmentLength",
412 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
413 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
416 rc
= kstrtoul(param
->value
, 0, &mrdsl
);
418 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
419 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
422 off
= mrdsl
% PAGE_SIZE
;
426 if (mrdsl
< PAGE_SIZE
)
431 pr_warn("Aligning ISER MaxRecvDataSegmentLength: %lu down"
432 " to PAGE_SIZE\n", mrdsl
);
434 if (iscsi_change_param_sprintf(conn
, "MaxRecvDataSegmentLength=%lu\n", mrdsl
))
437 * ISER currently requires that ImmediateData + Unsolicited
438 * Data be disabled when protection / signature MRs are enabled.
441 if (sess
->se_sess
->sup_prot_ops
&
442 (TARGET_PROT_DOUT_STRIP
| TARGET_PROT_DOUT_PASS
|
443 TARGET_PROT_DOUT_INSERT
)) {
445 if (iscsi_change_param_sprintf(conn
, "ImmediateData=No"))
448 if (iscsi_change_param_sprintf(conn
, "InitialR2T=Yes"))
451 pr_debug("Forcing ImmediateData=No + InitialR2T=Yes for"
452 " T10-PI enabled ISER session\n");
459 static int iscsi_login_non_zero_tsih_s1(
460 struct iscsi_conn
*conn
,
463 struct iscsi_login_req
*pdu
= (struct iscsi_login_req
*)buf
;
465 return iscsi_login_set_conn_values(NULL
, conn
, pdu
->cid
);
469 * Add a new connection to an existing session.
471 static int iscsi_login_non_zero_tsih_s2(
472 struct iscsi_conn
*conn
,
475 struct iscsi_portal_group
*tpg
= conn
->tpg
;
476 struct iscsi_session
*sess
= NULL
, *sess_p
= NULL
;
477 struct se_portal_group
*se_tpg
= &tpg
->tpg_se_tpg
;
478 struct se_session
*se_sess
, *se_sess_tmp
;
479 struct iscsi_login_req
*pdu
= (struct iscsi_login_req
*)buf
;
482 spin_lock_bh(&se_tpg
->session_lock
);
483 list_for_each_entry_safe(se_sess
, se_sess_tmp
, &se_tpg
->tpg_sess_list
,
486 sess_p
= (struct iscsi_session
*)se_sess
->fabric_sess_ptr
;
487 if (atomic_read(&sess_p
->session_fall_back_to_erl0
) ||
488 atomic_read(&sess_p
->session_logout
) ||
489 (sess_p
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
))
491 if (!memcmp(sess_p
->isid
, pdu
->isid
, 6) &&
492 (sess_p
->tsih
== be16_to_cpu(pdu
->tsih
))) {
493 iscsit_inc_session_usage_count(sess_p
);
494 iscsit_stop_time2retain_timer(sess_p
);
499 spin_unlock_bh(&se_tpg
->session_lock
);
502 * If the Time2Retain handler has expired, the session is already gone.
505 pr_err("Initiator attempting to add a connection to"
506 " a non-existent session, rejecting iSCSI Login.\n");
507 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_INITIATOR_ERR
,
508 ISCSI_LOGIN_STATUS_NO_SESSION
);
513 * Stop the Time2Retain timer if this is a failed session, we restart
514 * the timer if the login is not successful.
516 spin_lock_bh(&sess
->conn_lock
);
517 if (sess
->session_state
== TARG_SESS_STATE_FAILED
)
518 atomic_set(&sess
->session_continuation
, 1);
519 spin_unlock_bh(&sess
->conn_lock
);
521 if (iscsi_login_set_conn_values(sess
, conn
, pdu
->cid
) < 0 ||
522 iscsi_copy_param_list(&conn
->param_list
,
523 conn
->tpg
->param_list
, 0) < 0) {
524 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
525 ISCSI_LOGIN_STATUS_NO_RESOURCES
);
529 if (conn
->conn_transport
->transport_type
== ISCSI_INFINIBAND
)
532 iscsi_set_keys_to_negotiate(conn
->param_list
, iser
);
534 * Need to send TargetPortalGroupTag back in first login response
535 * on any iSCSI connection where the Initiator provides TargetName.
536 * See 5.3.1. Login Phase Start
538 * In our case, we have already located the struct iscsi_tiqn at this point.
540 if (iscsi_change_param_sprintf(conn
, "TargetPortalGroupTag=%hu", sess
->tpg
->tpgt
))
546 int iscsi_login_post_auth_non_zero_tsih(
547 struct iscsi_conn
*conn
,
551 struct iscsi_conn
*conn_ptr
= NULL
;
552 struct iscsi_conn_recovery
*cr
= NULL
;
553 struct iscsi_session
*sess
= conn
->sess
;
556 * By following item 5 in the login table, if we have found
557 * an existing ISID and a valid/existing TSIH and an existing
558 * CID we do connection reinstatement. Currently we dont not
559 * support it so we send back an non-zero status class to the
560 * initiator and release the new connection.
562 conn_ptr
= iscsit_get_conn_from_cid_rcfr(sess
, cid
);
564 pr_err("Connection exists with CID %hu for %s,"
565 " performing connection reinstatement.\n",
566 conn_ptr
->cid
, sess
->sess_ops
->InitiatorName
);
568 iscsit_connection_reinstatement_rcfr(conn_ptr
);
569 iscsit_dec_conn_usage_count(conn_ptr
);
573 * Check for any connection recovery entries containing CID.
574 * We use the original ExpStatSN sent in the first login request
575 * to acknowledge commands for the failed connection.
577 * Also note that an explict logout may have already been sent,
578 * but the response may not be sent due to additional connection
581 if (sess
->sess_ops
->ErrorRecoveryLevel
== 2) {
582 cr
= iscsit_get_inactive_connection_recovery_entry(
585 pr_debug("Performing implicit logout"
586 " for connection recovery on CID: %hu\n",
588 iscsit_discard_cr_cmds_by_expstatsn(cr
, exp_statsn
);
593 * Else we follow item 4 from the login table in that we have
594 * found an existing ISID and a valid/existing TSIH and a new
595 * CID we go ahead and continue to add a new connection to the
598 pr_debug("Adding CID %hu to existing session for %s.\n",
599 cid
, sess
->sess_ops
->InitiatorName
);
601 if ((atomic_read(&sess
->nconn
) + 1) > sess
->sess_ops
->MaxConnections
) {
602 pr_err("Adding additional connection to this session"
603 " would exceed MaxConnections %d, login failed.\n",
604 sess
->sess_ops
->MaxConnections
);
605 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_INITIATOR_ERR
,
606 ISCSI_LOGIN_STATUS_ISID_ERROR
);
613 static void iscsi_post_login_start_timers(struct iscsi_conn
*conn
)
615 struct iscsi_session
*sess
= conn
->sess
;
617 * FIXME: Unsolicited NopIN support for ISER
619 if (conn
->conn_transport
->transport_type
== ISCSI_INFINIBAND
)
622 if (!sess
->sess_ops
->SessionType
)
623 iscsit_start_nopin_timer(conn
);
626 int iscsit_start_kthreads(struct iscsi_conn
*conn
)
630 spin_lock(&iscsit_global
->ts_bitmap_lock
);
631 conn
->bitmap_id
= bitmap_find_free_region(iscsit_global
->ts_bitmap
,
632 ISCSIT_BITMAP_BITS
, get_order(1));
633 spin_unlock(&iscsit_global
->ts_bitmap_lock
);
635 if (conn
->bitmap_id
< 0) {
636 pr_err("bitmap_find_free_region() failed for"
637 " iscsit_start_kthreads()\n");
641 conn
->tx_thread
= kthread_run(iscsi_target_tx_thread
, conn
,
642 "%s", ISCSI_TX_THREAD_NAME
);
643 if (IS_ERR(conn
->tx_thread
)) {
644 pr_err("Unable to start iscsi_target_tx_thread\n");
645 ret
= PTR_ERR(conn
->tx_thread
);
648 conn
->tx_thread_active
= true;
650 conn
->rx_thread
= kthread_run(iscsi_target_rx_thread
, conn
,
651 "%s", ISCSI_RX_THREAD_NAME
);
652 if (IS_ERR(conn
->rx_thread
)) {
653 pr_err("Unable to start iscsi_target_rx_thread\n");
654 ret
= PTR_ERR(conn
->rx_thread
);
657 conn
->rx_thread_active
= true;
661 send_sig(SIGINT
, conn
->tx_thread
, 1);
662 kthread_stop(conn
->tx_thread
);
663 conn
->tx_thread_active
= false;
665 spin_lock(&iscsit_global
->ts_bitmap_lock
);
666 bitmap_release_region(iscsit_global
->ts_bitmap
, conn
->bitmap_id
,
668 spin_unlock(&iscsit_global
->ts_bitmap_lock
);
672 void iscsi_post_login_handler(
674 struct iscsi_conn
*conn
,
678 struct iscsi_session
*sess
= conn
->sess
;
679 struct se_session
*se_sess
= sess
->se_sess
;
680 struct iscsi_portal_group
*tpg
= sess
->tpg
;
681 struct se_portal_group
*se_tpg
= &tpg
->tpg_se_tpg
;
683 iscsit_inc_conn_usage_count(conn
);
685 iscsit_collect_login_stats(conn
, ISCSI_STATUS_CLS_SUCCESS
,
686 ISCSI_LOGIN_STATUS_ACCEPT
);
688 pr_debug("Moving to TARG_CONN_STATE_LOGGED_IN.\n");
689 conn
->conn_state
= TARG_CONN_STATE_LOGGED_IN
;
691 iscsi_set_connection_parameters(conn
->conn_ops
, conn
->param_list
);
693 * SCSI Initiator -> SCSI Target Port Mapping
696 iscsi_set_session_parameters(sess
->sess_ops
,
697 conn
->param_list
, 0);
698 iscsi_release_param_list(conn
->param_list
);
699 conn
->param_list
= NULL
;
701 spin_lock_bh(&sess
->conn_lock
);
702 atomic_set(&sess
->session_continuation
, 0);
703 if (sess
->session_state
== TARG_SESS_STATE_FAILED
) {
705 " TARG_SESS_STATE_LOGGED_IN.\n");
706 sess
->session_state
= TARG_SESS_STATE_LOGGED_IN
;
710 pr_debug("iSCSI Login successful on CID: %hu from %pISpc to"
711 " %pISpc,%hu\n", conn
->cid
, &conn
->login_sockaddr
,
712 &conn
->local_sockaddr
, tpg
->tpgt
);
714 list_add_tail(&conn
->conn_list
, &sess
->sess_conn_list
);
715 atomic_inc(&sess
->nconn
);
716 pr_debug("Incremented iSCSI Connection count to %hu"
717 " from node: %s\n", atomic_read(&sess
->nconn
),
718 sess
->sess_ops
->InitiatorName
);
719 spin_unlock_bh(&sess
->conn_lock
);
721 iscsi_post_login_start_timers(conn
);
723 * Determine CPU mask to ensure connection's RX and TX kthreads
724 * are scheduled on the same CPU.
726 iscsit_thread_get_cpumask(conn
);
727 conn
->conn_rx_reset_cpumask
= 1;
728 conn
->conn_tx_reset_cpumask
= 1;
730 * Wakeup the sleeping iscsi_target_rx_thread() now that
731 * iscsi_conn is in TARG_CONN_STATE_LOGGED_IN state.
733 complete(&conn
->rx_login_comp
);
734 iscsit_dec_conn_usage_count(conn
);
737 spin_lock_bh(&se_tpg
->session_lock
);
738 iscsit_stop_time2retain_timer(sess
);
739 spin_unlock_bh(&se_tpg
->session_lock
);
741 iscsit_dec_session_usage_count(sess
);
745 iscsi_set_session_parameters(sess
->sess_ops
, conn
->param_list
, 1);
746 iscsi_release_param_list(conn
->param_list
);
747 conn
->param_list
= NULL
;
749 iscsit_determine_maxcmdsn(sess
);
751 spin_lock_bh(&se_tpg
->session_lock
);
752 __transport_register_session(&sess
->tpg
->tpg_se_tpg
,
753 se_sess
->se_node_acl
, se_sess
, sess
);
754 pr_debug("Moving to TARG_SESS_STATE_LOGGED_IN.\n");
755 sess
->session_state
= TARG_SESS_STATE_LOGGED_IN
;
757 pr_debug("iSCSI Login successful on CID: %hu from %pISpc to %pISpc,%hu\n",
758 conn
->cid
, &conn
->login_sockaddr
, &conn
->local_sockaddr
,
761 spin_lock_bh(&sess
->conn_lock
);
762 list_add_tail(&conn
->conn_list
, &sess
->sess_conn_list
);
763 atomic_inc(&sess
->nconn
);
764 pr_debug("Incremented iSCSI Connection count to %hu from node:"
765 " %s\n", atomic_read(&sess
->nconn
),
766 sess
->sess_ops
->InitiatorName
);
767 spin_unlock_bh(&sess
->conn_lock
);
769 sess
->sid
= tpg
->sid
++;
771 sess
->sid
= tpg
->sid
++;
772 pr_debug("Established iSCSI session from node: %s\n",
773 sess
->sess_ops
->InitiatorName
);
777 tpg
->tpg_tiqn
->tiqn_nsessions
++;
779 pr_debug("Incremented number of active iSCSI sessions to %u on"
780 " iSCSI Target Portal Group: %hu\n", tpg
->nsessions
, tpg
->tpgt
);
781 spin_unlock_bh(&se_tpg
->session_lock
);
783 iscsi_post_login_start_timers(conn
);
785 * Determine CPU mask to ensure connection's RX and TX kthreads
786 * are scheduled on the same CPU.
788 iscsit_thread_get_cpumask(conn
);
789 conn
->conn_rx_reset_cpumask
= 1;
790 conn
->conn_tx_reset_cpumask
= 1;
792 * Wakeup the sleeping iscsi_target_rx_thread() now that
793 * iscsi_conn is in TARG_CONN_STATE_LOGGED_IN state.
795 complete(&conn
->rx_login_comp
);
796 iscsit_dec_conn_usage_count(conn
);
799 void iscsi_handle_login_thread_timeout(struct timer_list
*t
)
801 struct iscsi_np
*np
= from_timer(np
, t
, np_login_timer
);
803 spin_lock_bh(&np
->np_thread_lock
);
804 pr_err("iSCSI Login timeout on Network Portal %pISpc\n",
807 if (np
->np_login_timer_flags
& ISCSI_TF_STOP
) {
808 spin_unlock_bh(&np
->np_thread_lock
);
813 send_sig(SIGINT
, np
->np_thread
, 1);
815 np
->np_login_timer_flags
&= ~ISCSI_TF_RUNNING
;
816 spin_unlock_bh(&np
->np_thread_lock
);
819 static void iscsi_start_login_thread_timer(struct iscsi_np
*np
)
822 * This used the TA_LOGIN_TIMEOUT constant because at this
823 * point we do not have access to ISCSI_TPG_ATTRIB(tpg)->login_timeout
825 spin_lock_bh(&np
->np_thread_lock
);
826 np
->np_login_timer_flags
&= ~ISCSI_TF_STOP
;
827 np
->np_login_timer_flags
|= ISCSI_TF_RUNNING
;
828 mod_timer(&np
->np_login_timer
, jiffies
+ TA_LOGIN_TIMEOUT
* HZ
);
830 pr_debug("Added timeout timer to iSCSI login request for"
831 " %u seconds.\n", TA_LOGIN_TIMEOUT
);
832 spin_unlock_bh(&np
->np_thread_lock
);
835 static void iscsi_stop_login_thread_timer(struct iscsi_np
*np
)
837 spin_lock_bh(&np
->np_thread_lock
);
838 if (!(np
->np_login_timer_flags
& ISCSI_TF_RUNNING
)) {
839 spin_unlock_bh(&np
->np_thread_lock
);
842 np
->np_login_timer_flags
|= ISCSI_TF_STOP
;
843 spin_unlock_bh(&np
->np_thread_lock
);
845 del_timer_sync(&np
->np_login_timer
);
847 spin_lock_bh(&np
->np_thread_lock
);
848 np
->np_login_timer_flags
&= ~ISCSI_TF_RUNNING
;
849 spin_unlock_bh(&np
->np_thread_lock
);
854 struct sockaddr_storage
*sockaddr
)
856 struct socket
*sock
= NULL
;
857 int backlog
= ISCSIT_TCP_BACKLOG
, ret
, opt
= 0, len
;
859 switch (np
->np_network_transport
) {
861 np
->np_ip_proto
= IPPROTO_TCP
;
862 np
->np_sock_type
= SOCK_STREAM
;
865 np
->np_ip_proto
= IPPROTO_SCTP
;
866 np
->np_sock_type
= SOCK_STREAM
;
869 np
->np_ip_proto
= IPPROTO_SCTP
;
870 np
->np_sock_type
= SOCK_SEQPACKET
;
873 pr_err("Unsupported network_transport: %d\n",
874 np
->np_network_transport
);
878 ret
= sock_create(sockaddr
->ss_family
, np
->np_sock_type
,
879 np
->np_ip_proto
, &sock
);
881 pr_err("sock_create() failed.\n");
884 np
->np_socket
= sock
;
886 * Setup the np->np_sockaddr from the passed sockaddr setup
887 * in iscsi_target_configfs.c code..
889 memcpy(&np
->np_sockaddr
, sockaddr
,
890 sizeof(struct sockaddr_storage
));
892 if (sockaddr
->ss_family
== AF_INET6
)
893 len
= sizeof(struct sockaddr_in6
);
895 len
= sizeof(struct sockaddr_in
);
897 * Set SO_REUSEADDR, and disable Nagel Algorithm with TCP_NODELAY.
899 /* FIXME: Someone please explain why this is endian-safe */
901 if (np
->np_network_transport
== ISCSI_TCP
) {
902 ret
= kernel_setsockopt(sock
, IPPROTO_TCP
, TCP_NODELAY
,
903 (char *)&opt
, sizeof(opt
));
905 pr_err("kernel_setsockopt() for TCP_NODELAY"
906 " failed: %d\n", ret
);
911 /* FIXME: Someone please explain why this is endian-safe */
912 ret
= kernel_setsockopt(sock
, SOL_SOCKET
, SO_REUSEADDR
,
913 (char *)&opt
, sizeof(opt
));
915 pr_err("kernel_setsockopt() for SO_REUSEADDR"
920 ret
= kernel_setsockopt(sock
, IPPROTO_IP
, IP_FREEBIND
,
921 (char *)&opt
, sizeof(opt
));
923 pr_err("kernel_setsockopt() for IP_FREEBIND"
928 ret
= kernel_bind(sock
, (struct sockaddr
*)&np
->np_sockaddr
, len
);
930 pr_err("kernel_bind() failed: %d\n", ret
);
934 ret
= kernel_listen(sock
, backlog
);
936 pr_err("kernel_listen() failed: %d\n", ret
);
942 np
->np_socket
= NULL
;
947 int iscsi_target_setup_login_socket(
949 struct sockaddr_storage
*sockaddr
)
951 struct iscsit_transport
*t
;
954 t
= iscsit_get_transport(np
->np_network_transport
);
958 rc
= t
->iscsit_setup_np(np
, sockaddr
);
960 iscsit_put_transport(t
);
964 np
->np_transport
= t
;
969 int iscsit_accept_np(struct iscsi_np
*np
, struct iscsi_conn
*conn
)
971 struct socket
*new_sock
, *sock
= np
->np_socket
;
972 struct sockaddr_in sock_in
;
973 struct sockaddr_in6 sock_in6
;
976 rc
= kernel_accept(sock
, &new_sock
, 0);
980 conn
->sock
= new_sock
;
981 conn
->login_family
= np
->np_sockaddr
.ss_family
;
983 if (np
->np_sockaddr
.ss_family
== AF_INET6
) {
984 memset(&sock_in6
, 0, sizeof(struct sockaddr_in6
));
986 rc
= conn
->sock
->ops
->getname(conn
->sock
,
987 (struct sockaddr
*)&sock_in6
, 1);
989 if (!ipv6_addr_v4mapped(&sock_in6
.sin6_addr
)) {
990 memcpy(&conn
->login_sockaddr
, &sock_in6
, sizeof(sock_in6
));
992 /* Pretend to be an ipv4 socket */
993 sock_in
.sin_family
= AF_INET
;
994 sock_in
.sin_port
= sock_in6
.sin6_port
;
995 memcpy(&sock_in
.sin_addr
, &sock_in6
.sin6_addr
.s6_addr32
[3], 4);
996 memcpy(&conn
->login_sockaddr
, &sock_in
, sizeof(sock_in
));
1000 rc
= conn
->sock
->ops
->getname(conn
->sock
,
1001 (struct sockaddr
*)&sock_in6
, 0);
1003 if (!ipv6_addr_v4mapped(&sock_in6
.sin6_addr
)) {
1004 memcpy(&conn
->local_sockaddr
, &sock_in6
, sizeof(sock_in6
));
1006 /* Pretend to be an ipv4 socket */
1007 sock_in
.sin_family
= AF_INET
;
1008 sock_in
.sin_port
= sock_in6
.sin6_port
;
1009 memcpy(&sock_in
.sin_addr
, &sock_in6
.sin6_addr
.s6_addr32
[3], 4);
1010 memcpy(&conn
->local_sockaddr
, &sock_in
, sizeof(sock_in
));
1014 memset(&sock_in
, 0, sizeof(struct sockaddr_in
));
1016 rc
= conn
->sock
->ops
->getname(conn
->sock
,
1017 (struct sockaddr
*)&sock_in
, 1);
1019 memcpy(&conn
->login_sockaddr
, &sock_in
, sizeof(sock_in
));
1021 rc
= conn
->sock
->ops
->getname(conn
->sock
,
1022 (struct sockaddr
*)&sock_in
, 0);
1024 memcpy(&conn
->local_sockaddr
, &sock_in
, sizeof(sock_in
));
1030 int iscsit_get_login_rx(struct iscsi_conn
*conn
, struct iscsi_login
*login
)
1032 struct iscsi_login_req
*login_req
;
1033 u32 padding
= 0, payload_length
;
1035 if (iscsi_login_rx_data(conn
, login
->req
, ISCSI_HDR_LEN
) < 0)
1038 login_req
= (struct iscsi_login_req
*)login
->req
;
1039 payload_length
= ntoh24(login_req
->dlength
);
1040 padding
= ((-payload_length
) & 3);
1042 pr_debug("Got Login Command, Flags 0x%02x, ITT: 0x%08x,"
1043 " CmdSN: 0x%08x, ExpStatSN: 0x%08x, CID: %hu, Length: %u\n",
1044 login_req
->flags
, login_req
->itt
, login_req
->cmdsn
,
1045 login_req
->exp_statsn
, login_req
->cid
, payload_length
);
1047 * Setup the initial iscsi_login values from the leading
1048 * login request PDU.
1050 if (login
->first_request
) {
1051 login_req
= (struct iscsi_login_req
*)login
->req
;
1052 login
->leading_connection
= (!login_req
->tsih
) ? 1 : 0;
1053 login
->current_stage
= ISCSI_LOGIN_CURRENT_STAGE(login_req
->flags
);
1054 login
->version_min
= login_req
->min_version
;
1055 login
->version_max
= login_req
->max_version
;
1056 memcpy(login
->isid
, login_req
->isid
, 6);
1057 login
->cmd_sn
= be32_to_cpu(login_req
->cmdsn
);
1058 login
->init_task_tag
= login_req
->itt
;
1059 login
->initial_exp_statsn
= be32_to_cpu(login_req
->exp_statsn
);
1060 login
->cid
= be16_to_cpu(login_req
->cid
);
1061 login
->tsih
= be16_to_cpu(login_req
->tsih
);
1064 if (iscsi_target_check_login_request(conn
, login
) < 0)
1067 memset(login
->req_buf
, 0, MAX_KEY_VALUE_PAIRS
);
1068 if (iscsi_login_rx_data(conn
, login
->req_buf
,
1069 payload_length
+ padding
) < 0)
1075 int iscsit_put_login_tx(struct iscsi_conn
*conn
, struct iscsi_login
*login
,
1078 if (iscsi_login_tx_data(conn
, login
->rsp
, login
->rsp_buf
, length
) < 0)
1085 iscsit_conn_set_transport(struct iscsi_conn
*conn
, struct iscsit_transport
*t
)
1090 conn
->conn_transport
= t
;
1094 rc
= try_module_get(t
->owner
);
1096 pr_err("try_module_get() failed for %s\n", t
->name
);
1100 conn
->conn_transport
= t
;
1104 static struct iscsi_conn
*iscsit_alloc_conn(struct iscsi_np
*np
)
1106 struct iscsi_conn
*conn
;
1108 conn
= kzalloc(sizeof(struct iscsi_conn
), GFP_KERNEL
);
1110 pr_err("Could not allocate memory for new connection\n");
1113 pr_debug("Moving to TARG_CONN_STATE_FREE.\n");
1114 conn
->conn_state
= TARG_CONN_STATE_FREE
;
1116 init_waitqueue_head(&conn
->queues_wq
);
1117 INIT_LIST_HEAD(&conn
->conn_list
);
1118 INIT_LIST_HEAD(&conn
->conn_cmd_list
);
1119 INIT_LIST_HEAD(&conn
->immed_queue_list
);
1120 INIT_LIST_HEAD(&conn
->response_queue_list
);
1121 init_completion(&conn
->conn_post_wait_comp
);
1122 init_completion(&conn
->conn_wait_comp
);
1123 init_completion(&conn
->conn_wait_rcfr_comp
);
1124 init_completion(&conn
->conn_waiting_on_uc_comp
);
1125 init_completion(&conn
->conn_logout_comp
);
1126 init_completion(&conn
->rx_half_close_comp
);
1127 init_completion(&conn
->tx_half_close_comp
);
1128 init_completion(&conn
->rx_login_comp
);
1129 spin_lock_init(&conn
->cmd_lock
);
1130 spin_lock_init(&conn
->conn_usage_lock
);
1131 spin_lock_init(&conn
->immed_queue_lock
);
1132 spin_lock_init(&conn
->nopin_timer_lock
);
1133 spin_lock_init(&conn
->response_queue_lock
);
1134 spin_lock_init(&conn
->state_lock
);
1136 timer_setup(&conn
->nopin_response_timer
,
1137 iscsit_handle_nopin_response_timeout
, 0);
1138 timer_setup(&conn
->nopin_timer
, iscsit_handle_nopin_timeout
, 0);
1140 if (iscsit_conn_set_transport(conn
, np
->np_transport
) < 0)
1143 conn
->conn_ops
= kzalloc(sizeof(struct iscsi_conn_ops
), GFP_KERNEL
);
1144 if (!conn
->conn_ops
) {
1145 pr_err("Unable to allocate memory for struct iscsi_conn_ops.\n");
1149 if (!zalloc_cpumask_var(&conn
->conn_cpumask
, GFP_KERNEL
)) {
1150 pr_err("Unable to allocate conn->conn_cpumask\n");
1157 kfree(conn
->conn_ops
);
1159 iscsit_put_transport(conn
->conn_transport
);
1165 void iscsit_free_conn(struct iscsi_conn
*conn
)
1167 free_cpumask_var(conn
->conn_cpumask
);
1168 kfree(conn
->conn_ops
);
1169 iscsit_put_transport(conn
->conn_transport
);
1173 void iscsi_target_login_sess_out(struct iscsi_conn
*conn
,
1174 struct iscsi_np
*np
, bool zero_tsih
, bool new_sess
)
1179 pr_err("iSCSI Login negotiation failed.\n");
1180 iscsit_collect_login_stats(conn
, ISCSI_STATUS_CLS_INITIATOR_ERR
,
1181 ISCSI_LOGIN_STATUS_INIT_ERR
);
1182 if (!zero_tsih
|| !conn
->sess
)
1185 transport_free_session(conn
->sess
->se_sess
);
1186 ida_free(&sess_ida
, conn
->sess
->session_index
);
1187 kfree(conn
->sess
->sess_ops
);
1192 iscsi_stop_login_thread_timer(np
);
1194 * If login negotiation fails check if the Time2Retain timer
1195 * needs to be restarted.
1197 if (!zero_tsih
&& conn
->sess
) {
1198 spin_lock_bh(&conn
->sess
->conn_lock
);
1199 if (conn
->sess
->session_state
== TARG_SESS_STATE_FAILED
) {
1200 struct se_portal_group
*se_tpg
=
1201 &conn
->tpg
->tpg_se_tpg
;
1203 atomic_set(&conn
->sess
->session_continuation
, 0);
1204 spin_unlock_bh(&conn
->sess
->conn_lock
);
1205 spin_lock_bh(&se_tpg
->session_lock
);
1206 iscsit_start_time2retain_handler(conn
->sess
);
1207 spin_unlock_bh(&se_tpg
->session_lock
);
1209 spin_unlock_bh(&conn
->sess
->conn_lock
);
1210 iscsit_dec_session_usage_count(conn
->sess
);
1213 ahash_request_free(conn
->conn_tx_hash
);
1214 if (conn
->conn_rx_hash
) {
1215 struct crypto_ahash
*tfm
;
1217 tfm
= crypto_ahash_reqtfm(conn
->conn_rx_hash
);
1218 ahash_request_free(conn
->conn_rx_hash
);
1219 crypto_free_ahash(tfm
);
1222 if (conn
->param_list
) {
1223 iscsi_release_param_list(conn
->param_list
);
1224 conn
->param_list
= NULL
;
1226 iscsi_target_nego_release(conn
);
1229 sock_release(conn
->sock
);
1233 if (conn
->conn_transport
->iscsit_wait_conn
)
1234 conn
->conn_transport
->iscsit_wait_conn(conn
);
1236 if (conn
->conn_transport
->iscsit_free_conn
)
1237 conn
->conn_transport
->iscsit_free_conn(conn
);
1239 iscsit_free_conn(conn
);
1242 static int __iscsi_target_login_thread(struct iscsi_np
*np
)
1244 u8
*buffer
, zero_tsih
= 0;
1246 struct iscsi_conn
*conn
= NULL
;
1247 struct iscsi_login
*login
;
1248 struct iscsi_portal_group
*tpg
= NULL
;
1249 struct iscsi_login_req
*pdu
;
1250 struct iscsi_tpg_np
*tpg_np
;
1251 bool new_sess
= false;
1253 flush_signals(current
);
1255 spin_lock_bh(&np
->np_thread_lock
);
1256 if (atomic_dec_if_positive(&np
->np_reset_count
) >= 0) {
1257 np
->np_thread_state
= ISCSI_NP_THREAD_ACTIVE
;
1258 spin_unlock_bh(&np
->np_thread_lock
);
1259 complete(&np
->np_restart_comp
);
1261 } else if (np
->np_thread_state
== ISCSI_NP_THREAD_SHUTDOWN
) {
1262 spin_unlock_bh(&np
->np_thread_lock
);
1265 np
->np_thread_state
= ISCSI_NP_THREAD_ACTIVE
;
1267 spin_unlock_bh(&np
->np_thread_lock
);
1269 conn
= iscsit_alloc_conn(np
);
1271 /* Get another socket */
1275 rc
= np
->np_transport
->iscsit_accept_np(np
, conn
);
1276 if (rc
== -ENOSYS
) {
1277 complete(&np
->np_restart_comp
);
1278 iscsit_free_conn(conn
);
1280 } else if (rc
< 0) {
1281 spin_lock_bh(&np
->np_thread_lock
);
1282 if (atomic_dec_if_positive(&np
->np_reset_count
) >= 0) {
1283 np
->np_thread_state
= ISCSI_NP_THREAD_ACTIVE
;
1284 spin_unlock_bh(&np
->np_thread_lock
);
1285 complete(&np
->np_restart_comp
);
1286 iscsit_free_conn(conn
);
1287 /* Get another socket */
1290 spin_unlock_bh(&np
->np_thread_lock
);
1291 iscsit_free_conn(conn
);
1295 * Perform the remaining iSCSI connection initialization items..
1297 login
= iscsi_login_init_conn(conn
);
1302 iscsi_start_login_thread_timer(np
);
1304 pr_debug("Moving to TARG_CONN_STATE_XPT_UP.\n");
1305 conn
->conn_state
= TARG_CONN_STATE_XPT_UP
;
1307 * This will process the first login request + payload..
1309 rc
= np
->np_transport
->iscsit_get_login_rx(conn
, login
);
1315 buffer
= &login
->req
[0];
1316 pdu
= (struct iscsi_login_req
*)buffer
;
1318 * Used by iscsit_tx_login_rsp() for Login Resonses PDUs
1319 * when Status-Class != 0.
1321 conn
->login_itt
= pdu
->itt
;
1323 spin_lock_bh(&np
->np_thread_lock
);
1324 if (np
->np_thread_state
!= ISCSI_NP_THREAD_ACTIVE
) {
1325 spin_unlock_bh(&np
->np_thread_lock
);
1326 pr_err("iSCSI Network Portal on %pISpc currently not"
1327 " active.\n", &np
->np_sockaddr
);
1328 iscsit_tx_login_rsp(conn
, ISCSI_STATUS_CLS_TARGET_ERR
,
1329 ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE
);
1332 spin_unlock_bh(&np
->np_thread_lock
);
1334 conn
->network_transport
= np
->np_network_transport
;
1336 pr_debug("Received iSCSI login request from %pISpc on %s Network"
1337 " Portal %pISpc\n", &conn
->login_sockaddr
, np
->np_transport
->name
,
1338 &conn
->local_sockaddr
);
1340 pr_debug("Moving to TARG_CONN_STATE_IN_LOGIN.\n");
1341 conn
->conn_state
= TARG_CONN_STATE_IN_LOGIN
;
1343 if (iscsi_login_check_initiator_version(conn
, pdu
->max_version
,
1344 pdu
->min_version
) < 0)
1347 zero_tsih
= (pdu
->tsih
== 0x0000);
1350 * This is the leading connection of a new session.
1351 * We wait until after authentication to check for
1352 * session reinstatement.
1354 if (iscsi_login_zero_tsih_s1(conn
, buffer
) < 0)
1358 * Add a new connection to an existing session.
1359 * We check for a non-existant session in
1360 * iscsi_login_non_zero_tsih_s2() below based
1361 * on ISID/TSIH, but wait until after authentication
1362 * to check for connection reinstatement, etc.
1364 if (iscsi_login_non_zero_tsih_s1(conn
, buffer
) < 0)
1368 * SessionType: Discovery
1370 * Locates Default Portal
1372 * SessionType: Normal
1374 * Locates Target Portal from NP -> Target IQN
1376 rc
= iscsi_target_locate_portal(np
, conn
, login
);
1381 login
->zero_tsih
= zero_tsih
;
1384 conn
->sess
->se_sess
->sup_prot_ops
=
1385 conn
->conn_transport
->iscsit_get_sup_prot_ops(conn
);
1389 pr_err("Unable to locate struct iscsi_conn->tpg\n");
1394 if (iscsi_login_zero_tsih_s2(conn
) < 0)
1397 if (iscsi_login_non_zero_tsih_s2(conn
, buffer
) < 0)
1401 if (conn
->conn_transport
->iscsit_validate_params
) {
1402 ret
= conn
->conn_transport
->iscsit_validate_params(conn
);
1411 ret
= iscsi_target_start_negotiation(login
, conn
);
1415 iscsi_stop_login_thread_timer(np
);
1418 tpg_np
= conn
->tpg_np
;
1420 iscsi_post_login_handler(np
, conn
, zero_tsih
);
1421 iscsit_deaccess_np(np
, tpg
, tpg_np
);
1426 /* Get another socket */
1432 tpg_np
= conn
->tpg_np
;
1433 iscsi_target_login_sess_out(conn
, np
, zero_tsih
, new_sess
);
1437 iscsit_deaccess_np(np
, tpg
, tpg_np
);
1445 iscsi_stop_login_thread_timer(np
);
1446 spin_lock_bh(&np
->np_thread_lock
);
1447 np
->np_thread_state
= ISCSI_NP_THREAD_EXIT
;
1448 spin_unlock_bh(&np
->np_thread_lock
);
1453 int iscsi_target_login_thread(void *arg
)
1455 struct iscsi_np
*np
= arg
;
1458 allow_signal(SIGINT
);
1461 ret
= __iscsi_target_login_thread(np
);
1463 * We break and exit here unless another sock_accept() call
1470 while (!kthread_should_stop()) {