1 /*******************************************************************************
2 * This file contains the iSCSI Target specific utility functions.
4 * (c) Copyright 2007-2013 Datera, Inc.
6 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
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.
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 ******************************************************************************/
19 #include <linux/list.h>
20 #include <linux/percpu_ida.h>
21 #include <scsi/scsi_tcq.h>
22 #include <scsi/iscsi_proto.h>
23 #include <target/target_core_base.h>
24 #include <target/target_core_fabric.h>
25 #include <target/iscsi/iscsi_transport.h>
27 #include <target/iscsi/iscsi_target_core.h>
28 #include "iscsi_target_parameters.h"
29 #include "iscsi_target_seq_pdu_list.h"
30 #include "iscsi_target_datain_values.h"
31 #include "iscsi_target_erl0.h"
32 #include "iscsi_target_erl1.h"
33 #include "iscsi_target_erl2.h"
34 #include "iscsi_target_tpg.h"
35 #include "iscsi_target_util.h"
36 #include "iscsi_target.h"
38 #define PRINT_BUFF(buff, len) \
42 pr_debug("%d:\n", __LINE__); \
43 for (zzz = 0; zzz < len; zzz++) { \
44 if (zzz % 16 == 0) { \
47 pr_debug("%4i: ", zzz); \
49 pr_debug("%02x ", (unsigned char) (buff)[zzz]); \
55 extern struct list_head g_tiqn_list
;
56 extern spinlock_t tiqn_lock
;
59 * Called with cmd->r2t_lock held.
61 int iscsit_add_r2t_to_list(
62 struct iscsi_cmd
*cmd
,
68 struct iscsi_r2t
*r2t
;
70 r2t
= kmem_cache_zalloc(lio_r2t_cache
, GFP_ATOMIC
);
72 pr_err("Unable to allocate memory for struct iscsi_r2t.\n");
75 INIT_LIST_HEAD(&r2t
->r2t_list
);
77 r2t
->recovery_r2t
= recovery
;
78 r2t
->r2t_sn
= (!r2t_sn
) ? cmd
->r2t_sn
++ : r2t_sn
;
80 r2t
->xfer_len
= xfer_len
;
81 list_add_tail(&r2t
->r2t_list
, &cmd
->cmd_r2t_list
);
82 spin_unlock_bh(&cmd
->r2t_lock
);
84 iscsit_add_cmd_to_immediate_queue(cmd
, cmd
->conn
, ISTATE_SEND_R2T
);
86 spin_lock_bh(&cmd
->r2t_lock
);
90 struct iscsi_r2t
*iscsit_get_r2t_for_eos(
91 struct iscsi_cmd
*cmd
,
95 struct iscsi_r2t
*r2t
;
97 spin_lock_bh(&cmd
->r2t_lock
);
98 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
99 if ((r2t
->offset
<= offset
) &&
100 (r2t
->offset
+ r2t
->xfer_len
) >= (offset
+ length
)) {
101 spin_unlock_bh(&cmd
->r2t_lock
);
105 spin_unlock_bh(&cmd
->r2t_lock
);
107 pr_err("Unable to locate R2T for Offset: %u, Length:"
108 " %u\n", offset
, length
);
112 struct iscsi_r2t
*iscsit_get_r2t_from_list(struct iscsi_cmd
*cmd
)
114 struct iscsi_r2t
*r2t
;
116 spin_lock_bh(&cmd
->r2t_lock
);
117 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
118 if (!r2t
->sent_r2t
) {
119 spin_unlock_bh(&cmd
->r2t_lock
);
123 spin_unlock_bh(&cmd
->r2t_lock
);
125 pr_err("Unable to locate next R2T to send for ITT:"
126 " 0x%08x.\n", cmd
->init_task_tag
);
131 * Called with cmd->r2t_lock held.
133 void iscsit_free_r2t(struct iscsi_r2t
*r2t
, struct iscsi_cmd
*cmd
)
135 list_del(&r2t
->r2t_list
);
136 kmem_cache_free(lio_r2t_cache
, r2t
);
139 void iscsit_free_r2ts_from_list(struct iscsi_cmd
*cmd
)
141 struct iscsi_r2t
*r2t
, *r2t_tmp
;
143 spin_lock_bh(&cmd
->r2t_lock
);
144 list_for_each_entry_safe(r2t
, r2t_tmp
, &cmd
->cmd_r2t_list
, r2t_list
)
145 iscsit_free_r2t(r2t
, cmd
);
146 spin_unlock_bh(&cmd
->r2t_lock
);
150 * May be called from software interrupt (timer) context for allocating
153 struct iscsi_cmd
*iscsit_allocate_cmd(struct iscsi_conn
*conn
, int state
)
155 struct iscsi_cmd
*cmd
;
156 struct se_session
*se_sess
= conn
->sess
->se_sess
;
159 tag
= percpu_ida_alloc(&se_sess
->sess_tag_pool
, state
);
163 size
= sizeof(struct iscsi_cmd
) + conn
->conn_transport
->priv_size
;
164 cmd
= (struct iscsi_cmd
*)(se_sess
->sess_cmd_map
+ (tag
* size
));
165 memset(cmd
, 0, size
);
167 cmd
->se_cmd
.map_tag
= tag
;
169 INIT_LIST_HEAD(&cmd
->i_conn_node
);
170 INIT_LIST_HEAD(&cmd
->datain_list
);
171 INIT_LIST_HEAD(&cmd
->cmd_r2t_list
);
172 spin_lock_init(&cmd
->datain_lock
);
173 spin_lock_init(&cmd
->dataout_timeout_lock
);
174 spin_lock_init(&cmd
->istate_lock
);
175 spin_lock_init(&cmd
->error_lock
);
176 spin_lock_init(&cmd
->r2t_lock
);
180 EXPORT_SYMBOL(iscsit_allocate_cmd
);
182 struct iscsi_seq
*iscsit_get_seq_holder_for_datain(
183 struct iscsi_cmd
*cmd
,
188 for (i
= 0; i
< cmd
->seq_count
; i
++)
189 if (cmd
->seq_list
[i
].seq_send_order
== seq_send_order
)
190 return &cmd
->seq_list
[i
];
195 struct iscsi_seq
*iscsit_get_seq_holder_for_r2t(struct iscsi_cmd
*cmd
)
199 if (!cmd
->seq_list
) {
200 pr_err("struct iscsi_cmd->seq_list is NULL!\n");
204 for (i
= 0; i
< cmd
->seq_count
; i
++) {
205 if (cmd
->seq_list
[i
].type
!= SEQTYPE_NORMAL
)
207 if (cmd
->seq_list
[i
].seq_send_order
== cmd
->seq_send_order
) {
208 cmd
->seq_send_order
++;
209 return &cmd
->seq_list
[i
];
216 struct iscsi_r2t
*iscsit_get_holder_for_r2tsn(
217 struct iscsi_cmd
*cmd
,
220 struct iscsi_r2t
*r2t
;
222 spin_lock_bh(&cmd
->r2t_lock
);
223 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
224 if (r2t
->r2t_sn
== r2t_sn
) {
225 spin_unlock_bh(&cmd
->r2t_lock
);
229 spin_unlock_bh(&cmd
->r2t_lock
);
234 static inline int iscsit_check_received_cmdsn(struct iscsi_session
*sess
, u32 cmdsn
)
239 * This is the proper method of checking received CmdSN against
240 * ExpCmdSN and MaxCmdSN values, as well as accounting for out
241 * or order CmdSNs due to multiple connection sessions and/or
244 if (iscsi_sna_gt(cmdsn
, sess
->max_cmd_sn
)) {
245 pr_err("Received CmdSN: 0x%08x is greater than"
246 " MaxCmdSN: 0x%08x, ignoring.\n", cmdsn
,
248 ret
= CMDSN_MAXCMDSN_OVERRUN
;
250 } else if (cmdsn
== sess
->exp_cmd_sn
) {
252 pr_debug("Received CmdSN matches ExpCmdSN,"
253 " incremented ExpCmdSN to: 0x%08x\n",
255 ret
= CMDSN_NORMAL_OPERATION
;
257 } else if (iscsi_sna_gt(cmdsn
, sess
->exp_cmd_sn
)) {
258 pr_debug("Received CmdSN: 0x%08x is greater"
259 " than ExpCmdSN: 0x%08x, not acknowledging.\n",
260 cmdsn
, sess
->exp_cmd_sn
);
261 ret
= CMDSN_HIGHER_THAN_EXP
;
264 pr_err("Received CmdSN: 0x%08x is less than"
265 " ExpCmdSN: 0x%08x, ignoring.\n", cmdsn
,
267 ret
= CMDSN_LOWER_THAN_EXP
;
274 * Commands may be received out of order if MC/S is in use.
275 * Ensure they are executed in CmdSN order.
277 int iscsit_sequence_cmd(struct iscsi_conn
*conn
, struct iscsi_cmd
*cmd
,
278 unsigned char *buf
, __be32 cmdsn
)
282 u8 reason
= ISCSI_REASON_BOOKMARK_NO_RESOURCES
;
284 mutex_lock(&conn
->sess
->cmdsn_mutex
);
286 cmdsn_ret
= iscsit_check_received_cmdsn(conn
->sess
, be32_to_cpu(cmdsn
));
288 case CMDSN_NORMAL_OPERATION
:
289 ret
= iscsit_execute_cmd(cmd
, 0);
290 if ((ret
>= 0) && !list_empty(&conn
->sess
->sess_ooo_cmdsn_list
))
291 iscsit_execute_ooo_cmdsns(conn
->sess
);
294 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
297 case CMDSN_HIGHER_THAN_EXP
:
298 ret
= iscsit_handle_ooo_cmdsn(conn
->sess
, cmd
, be32_to_cpu(cmdsn
));
301 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
304 ret
= CMDSN_HIGHER_THAN_EXP
;
306 case CMDSN_LOWER_THAN_EXP
:
307 case CMDSN_MAXCMDSN_OVERRUN
:
309 cmd
->i_state
= ISTATE_REMOVE
;
310 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, cmd
->i_state
);
312 * Existing callers for iscsit_sequence_cmd() will silently
313 * ignore commands with CMDSN_LOWER_THAN_EXP, so force this
314 * return for CMDSN_MAXCMDSN_OVERRUN as well..
316 ret
= CMDSN_LOWER_THAN_EXP
;
319 mutex_unlock(&conn
->sess
->cmdsn_mutex
);
322 iscsit_reject_cmd(cmd
, reason
, buf
);
326 EXPORT_SYMBOL(iscsit_sequence_cmd
);
328 int iscsit_check_unsolicited_dataout(struct iscsi_cmd
*cmd
, unsigned char *buf
)
330 struct iscsi_conn
*conn
= cmd
->conn
;
331 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
332 struct iscsi_data
*hdr
= (struct iscsi_data
*) buf
;
333 u32 payload_length
= ntoh24(hdr
->dlength
);
335 if (conn
->sess
->sess_ops
->InitialR2T
) {
336 pr_err("Received unexpected unsolicited data"
337 " while InitialR2T=Yes, protocol error.\n");
338 transport_send_check_condition_and_sense(se_cmd
,
339 TCM_UNEXPECTED_UNSOLICITED_DATA
, 0);
343 if ((cmd
->first_burst_len
+ payload_length
) >
344 conn
->sess
->sess_ops
->FirstBurstLength
) {
345 pr_err("Total %u bytes exceeds FirstBurstLength: %u"
346 " for this Unsolicited DataOut Burst.\n",
347 (cmd
->first_burst_len
+ payload_length
),
348 conn
->sess
->sess_ops
->FirstBurstLength
);
349 transport_send_check_condition_and_sense(se_cmd
,
350 TCM_INCORRECT_AMOUNT_OF_DATA
, 0);
354 if (!(hdr
->flags
& ISCSI_FLAG_CMD_FINAL
))
357 if (((cmd
->first_burst_len
+ payload_length
) != cmd
->se_cmd
.data_length
) &&
358 ((cmd
->first_burst_len
+ payload_length
) !=
359 conn
->sess
->sess_ops
->FirstBurstLength
)) {
360 pr_err("Unsolicited non-immediate data received %u"
361 " does not equal FirstBurstLength: %u, and does"
362 " not equal ExpXferLen %u.\n",
363 (cmd
->first_burst_len
+ payload_length
),
364 conn
->sess
->sess_ops
->FirstBurstLength
, cmd
->se_cmd
.data_length
);
365 transport_send_check_condition_and_sense(se_cmd
,
366 TCM_INCORRECT_AMOUNT_OF_DATA
, 0);
372 struct iscsi_cmd
*iscsit_find_cmd_from_itt(
373 struct iscsi_conn
*conn
,
376 struct iscsi_cmd
*cmd
;
378 spin_lock_bh(&conn
->cmd_lock
);
379 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
380 if (cmd
->init_task_tag
== init_task_tag
) {
381 spin_unlock_bh(&conn
->cmd_lock
);
385 spin_unlock_bh(&conn
->cmd_lock
);
387 pr_err("Unable to locate ITT: 0x%08x on CID: %hu",
388 init_task_tag
, conn
->cid
);
391 EXPORT_SYMBOL(iscsit_find_cmd_from_itt
);
393 struct iscsi_cmd
*iscsit_find_cmd_from_itt_or_dump(
394 struct iscsi_conn
*conn
,
398 struct iscsi_cmd
*cmd
;
400 spin_lock_bh(&conn
->cmd_lock
);
401 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
402 if (cmd
->cmd_flags
& ICF_GOT_LAST_DATAOUT
)
404 if (cmd
->init_task_tag
== init_task_tag
) {
405 spin_unlock_bh(&conn
->cmd_lock
);
409 spin_unlock_bh(&conn
->cmd_lock
);
411 pr_err("Unable to locate ITT: 0x%08x on CID: %hu,"
412 " dumping payload\n", init_task_tag
, conn
->cid
);
414 iscsit_dump_data_payload(conn
, length
, 1);
419 struct iscsi_cmd
*iscsit_find_cmd_from_ttt(
420 struct iscsi_conn
*conn
,
423 struct iscsi_cmd
*cmd
= NULL
;
425 spin_lock_bh(&conn
->cmd_lock
);
426 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
427 if (cmd
->targ_xfer_tag
== targ_xfer_tag
) {
428 spin_unlock_bh(&conn
->cmd_lock
);
432 spin_unlock_bh(&conn
->cmd_lock
);
434 pr_err("Unable to locate TTT: 0x%08x on CID: %hu\n",
435 targ_xfer_tag
, conn
->cid
);
439 int iscsit_find_cmd_for_recovery(
440 struct iscsi_session
*sess
,
441 struct iscsi_cmd
**cmd_ptr
,
442 struct iscsi_conn_recovery
**cr_ptr
,
445 struct iscsi_cmd
*cmd
= NULL
;
446 struct iscsi_conn_recovery
*cr
;
448 * Scan through the inactive connection recovery list's command list.
449 * If init_task_tag matches the command is still alligent.
451 spin_lock(&sess
->cr_i_lock
);
452 list_for_each_entry(cr
, &sess
->cr_inactive_list
, cr_list
) {
453 spin_lock(&cr
->conn_recovery_cmd_lock
);
454 list_for_each_entry(cmd
, &cr
->conn_recovery_cmd_list
, i_conn_node
) {
455 if (cmd
->init_task_tag
== init_task_tag
) {
456 spin_unlock(&cr
->conn_recovery_cmd_lock
);
457 spin_unlock(&sess
->cr_i_lock
);
464 spin_unlock(&cr
->conn_recovery_cmd_lock
);
466 spin_unlock(&sess
->cr_i_lock
);
468 * Scan through the active connection recovery list's command list.
469 * If init_task_tag matches the command is ready to be reassigned.
471 spin_lock(&sess
->cr_a_lock
);
472 list_for_each_entry(cr
, &sess
->cr_active_list
, cr_list
) {
473 spin_lock(&cr
->conn_recovery_cmd_lock
);
474 list_for_each_entry(cmd
, &cr
->conn_recovery_cmd_list
, i_conn_node
) {
475 if (cmd
->init_task_tag
== init_task_tag
) {
476 spin_unlock(&cr
->conn_recovery_cmd_lock
);
477 spin_unlock(&sess
->cr_a_lock
);
484 spin_unlock(&cr
->conn_recovery_cmd_lock
);
486 spin_unlock(&sess
->cr_a_lock
);
491 void iscsit_add_cmd_to_immediate_queue(
492 struct iscsi_cmd
*cmd
,
493 struct iscsi_conn
*conn
,
496 struct iscsi_queue_req
*qr
;
498 qr
= kmem_cache_zalloc(lio_qr_cache
, GFP_ATOMIC
);
500 pr_err("Unable to allocate memory for"
501 " struct iscsi_queue_req\n");
504 INIT_LIST_HEAD(&qr
->qr_list
);
508 spin_lock_bh(&conn
->immed_queue_lock
);
509 list_add_tail(&qr
->qr_list
, &conn
->immed_queue_list
);
510 atomic_inc(&cmd
->immed_queue_count
);
511 atomic_set(&conn
->check_immediate_queue
, 1);
512 spin_unlock_bh(&conn
->immed_queue_lock
);
514 wake_up(&conn
->queues_wq
);
517 struct iscsi_queue_req
*iscsit_get_cmd_from_immediate_queue(struct iscsi_conn
*conn
)
519 struct iscsi_queue_req
*qr
;
521 spin_lock_bh(&conn
->immed_queue_lock
);
522 if (list_empty(&conn
->immed_queue_list
)) {
523 spin_unlock_bh(&conn
->immed_queue_lock
);
526 qr
= list_first_entry(&conn
->immed_queue_list
,
527 struct iscsi_queue_req
, qr_list
);
529 list_del(&qr
->qr_list
);
531 atomic_dec(&qr
->cmd
->immed_queue_count
);
532 spin_unlock_bh(&conn
->immed_queue_lock
);
537 static void iscsit_remove_cmd_from_immediate_queue(
538 struct iscsi_cmd
*cmd
,
539 struct iscsi_conn
*conn
)
541 struct iscsi_queue_req
*qr
, *qr_tmp
;
543 spin_lock_bh(&conn
->immed_queue_lock
);
544 if (!atomic_read(&cmd
->immed_queue_count
)) {
545 spin_unlock_bh(&conn
->immed_queue_lock
);
549 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->immed_queue_list
, qr_list
) {
553 atomic_dec(&qr
->cmd
->immed_queue_count
);
554 list_del(&qr
->qr_list
);
555 kmem_cache_free(lio_qr_cache
, qr
);
557 spin_unlock_bh(&conn
->immed_queue_lock
);
559 if (atomic_read(&cmd
->immed_queue_count
)) {
560 pr_err("ITT: 0x%08x immed_queue_count: %d\n",
562 atomic_read(&cmd
->immed_queue_count
));
566 void iscsit_add_cmd_to_response_queue(
567 struct iscsi_cmd
*cmd
,
568 struct iscsi_conn
*conn
,
571 struct iscsi_queue_req
*qr
;
573 qr
= kmem_cache_zalloc(lio_qr_cache
, GFP_ATOMIC
);
575 pr_err("Unable to allocate memory for"
576 " struct iscsi_queue_req\n");
579 INIT_LIST_HEAD(&qr
->qr_list
);
583 spin_lock_bh(&conn
->response_queue_lock
);
584 list_add_tail(&qr
->qr_list
, &conn
->response_queue_list
);
585 atomic_inc(&cmd
->response_queue_count
);
586 spin_unlock_bh(&conn
->response_queue_lock
);
588 wake_up(&conn
->queues_wq
);
591 struct iscsi_queue_req
*iscsit_get_cmd_from_response_queue(struct iscsi_conn
*conn
)
593 struct iscsi_queue_req
*qr
;
595 spin_lock_bh(&conn
->response_queue_lock
);
596 if (list_empty(&conn
->response_queue_list
)) {
597 spin_unlock_bh(&conn
->response_queue_lock
);
601 qr
= list_first_entry(&conn
->response_queue_list
,
602 struct iscsi_queue_req
, qr_list
);
604 list_del(&qr
->qr_list
);
606 atomic_dec(&qr
->cmd
->response_queue_count
);
607 spin_unlock_bh(&conn
->response_queue_lock
);
612 static void iscsit_remove_cmd_from_response_queue(
613 struct iscsi_cmd
*cmd
,
614 struct iscsi_conn
*conn
)
616 struct iscsi_queue_req
*qr
, *qr_tmp
;
618 spin_lock_bh(&conn
->response_queue_lock
);
619 if (!atomic_read(&cmd
->response_queue_count
)) {
620 spin_unlock_bh(&conn
->response_queue_lock
);
624 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->response_queue_list
,
629 atomic_dec(&qr
->cmd
->response_queue_count
);
630 list_del(&qr
->qr_list
);
631 kmem_cache_free(lio_qr_cache
, qr
);
633 spin_unlock_bh(&conn
->response_queue_lock
);
635 if (atomic_read(&cmd
->response_queue_count
)) {
636 pr_err("ITT: 0x%08x response_queue_count: %d\n",
638 atomic_read(&cmd
->response_queue_count
));
642 bool iscsit_conn_all_queues_empty(struct iscsi_conn
*conn
)
646 spin_lock_bh(&conn
->immed_queue_lock
);
647 empty
= list_empty(&conn
->immed_queue_list
);
648 spin_unlock_bh(&conn
->immed_queue_lock
);
653 spin_lock_bh(&conn
->response_queue_lock
);
654 empty
= list_empty(&conn
->response_queue_list
);
655 spin_unlock_bh(&conn
->response_queue_lock
);
660 void iscsit_free_queue_reqs_for_conn(struct iscsi_conn
*conn
)
662 struct iscsi_queue_req
*qr
, *qr_tmp
;
664 spin_lock_bh(&conn
->immed_queue_lock
);
665 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->immed_queue_list
, qr_list
) {
666 list_del(&qr
->qr_list
);
668 atomic_dec(&qr
->cmd
->immed_queue_count
);
670 kmem_cache_free(lio_qr_cache
, qr
);
672 spin_unlock_bh(&conn
->immed_queue_lock
);
674 spin_lock_bh(&conn
->response_queue_lock
);
675 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->response_queue_list
,
677 list_del(&qr
->qr_list
);
679 atomic_dec(&qr
->cmd
->response_queue_count
);
681 kmem_cache_free(lio_qr_cache
, qr
);
683 spin_unlock_bh(&conn
->response_queue_lock
);
686 void iscsit_release_cmd(struct iscsi_cmd
*cmd
)
688 struct iscsi_session
*sess
;
689 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
692 sess
= cmd
->conn
->sess
;
696 BUG_ON(!sess
|| !sess
->se_sess
);
699 kfree(cmd
->pdu_list
);
700 kfree(cmd
->seq_list
);
702 kfree(cmd
->iov_data
);
703 kfree(cmd
->text_in_ptr
);
705 percpu_ida_free(&sess
->se_sess
->sess_tag_pool
, se_cmd
->map_tag
);
707 EXPORT_SYMBOL(iscsit_release_cmd
);
709 void __iscsit_free_cmd(struct iscsi_cmd
*cmd
, bool scsi_cmd
,
712 struct iscsi_conn
*conn
= cmd
->conn
;
715 if (cmd
->data_direction
== DMA_TO_DEVICE
) {
716 iscsit_stop_dataout_timer(cmd
);
717 iscsit_free_r2ts_from_list(cmd
);
719 if (cmd
->data_direction
== DMA_FROM_DEVICE
)
720 iscsit_free_all_datain_reqs(cmd
);
723 if (conn
&& check_queues
) {
724 iscsit_remove_cmd_from_immediate_queue(cmd
, conn
);
725 iscsit_remove_cmd_from_response_queue(cmd
, conn
);
729 void iscsit_free_cmd(struct iscsi_cmd
*cmd
, bool shutdown
)
731 struct se_cmd
*se_cmd
= NULL
;
734 * Determine if a struct se_cmd is associated with
735 * this struct iscsi_cmd.
737 switch (cmd
->iscsi_opcode
) {
738 case ISCSI_OP_SCSI_CMD
:
739 se_cmd
= &cmd
->se_cmd
;
740 __iscsit_free_cmd(cmd
, true, shutdown
);
744 case ISCSI_OP_SCSI_TMFUNC
:
745 rc
= transport_generic_free_cmd(&cmd
->se_cmd
, shutdown
);
746 if (!rc
&& shutdown
&& se_cmd
&& se_cmd
->se_sess
) {
747 __iscsit_free_cmd(cmd
, true, shutdown
);
748 target_put_sess_cmd(se_cmd
);
751 case ISCSI_OP_REJECT
:
753 * Handle special case for REJECT when iscsi_add_reject*() has
754 * overwritten the original iscsi_opcode assignment, and the
755 * associated cmd->se_cmd needs to be released.
757 if (cmd
->se_cmd
.se_tfo
!= NULL
) {
758 se_cmd
= &cmd
->se_cmd
;
759 __iscsit_free_cmd(cmd
, true, shutdown
);
761 rc
= transport_generic_free_cmd(&cmd
->se_cmd
, shutdown
);
762 if (!rc
&& shutdown
&& se_cmd
->se_sess
) {
763 __iscsit_free_cmd(cmd
, true, shutdown
);
764 target_put_sess_cmd(se_cmd
);
770 __iscsit_free_cmd(cmd
, false, shutdown
);
771 iscsit_release_cmd(cmd
);
776 int iscsit_check_session_usage_count(struct iscsi_session
*sess
)
778 spin_lock_bh(&sess
->session_usage_lock
);
779 if (sess
->session_usage_count
!= 0) {
780 sess
->session_waiting_on_uc
= 1;
781 spin_unlock_bh(&sess
->session_usage_lock
);
785 wait_for_completion(&sess
->session_waiting_on_uc_comp
);
788 spin_unlock_bh(&sess
->session_usage_lock
);
793 void iscsit_dec_session_usage_count(struct iscsi_session
*sess
)
795 spin_lock_bh(&sess
->session_usage_lock
);
796 sess
->session_usage_count
--;
798 if (!sess
->session_usage_count
&& sess
->session_waiting_on_uc
)
799 complete(&sess
->session_waiting_on_uc_comp
);
801 spin_unlock_bh(&sess
->session_usage_lock
);
804 void iscsit_inc_session_usage_count(struct iscsi_session
*sess
)
806 spin_lock_bh(&sess
->session_usage_lock
);
807 sess
->session_usage_count
++;
808 spin_unlock_bh(&sess
->session_usage_lock
);
811 struct iscsi_conn
*iscsit_get_conn_from_cid(struct iscsi_session
*sess
, u16 cid
)
813 struct iscsi_conn
*conn
;
815 spin_lock_bh(&sess
->conn_lock
);
816 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
817 if ((conn
->cid
== cid
) &&
818 (conn
->conn_state
== TARG_CONN_STATE_LOGGED_IN
)) {
819 iscsit_inc_conn_usage_count(conn
);
820 spin_unlock_bh(&sess
->conn_lock
);
824 spin_unlock_bh(&sess
->conn_lock
);
829 struct iscsi_conn
*iscsit_get_conn_from_cid_rcfr(struct iscsi_session
*sess
, u16 cid
)
831 struct iscsi_conn
*conn
;
833 spin_lock_bh(&sess
->conn_lock
);
834 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
835 if (conn
->cid
== cid
) {
836 iscsit_inc_conn_usage_count(conn
);
837 spin_lock(&conn
->state_lock
);
838 atomic_set(&conn
->connection_wait_rcfr
, 1);
839 spin_unlock(&conn
->state_lock
);
840 spin_unlock_bh(&sess
->conn_lock
);
844 spin_unlock_bh(&sess
->conn_lock
);
849 void iscsit_check_conn_usage_count(struct iscsi_conn
*conn
)
851 spin_lock_bh(&conn
->conn_usage_lock
);
852 if (conn
->conn_usage_count
!= 0) {
853 conn
->conn_waiting_on_uc
= 1;
854 spin_unlock_bh(&conn
->conn_usage_lock
);
856 wait_for_completion(&conn
->conn_waiting_on_uc_comp
);
859 spin_unlock_bh(&conn
->conn_usage_lock
);
862 void iscsit_dec_conn_usage_count(struct iscsi_conn
*conn
)
864 spin_lock_bh(&conn
->conn_usage_lock
);
865 conn
->conn_usage_count
--;
867 if (!conn
->conn_usage_count
&& conn
->conn_waiting_on_uc
)
868 complete(&conn
->conn_waiting_on_uc_comp
);
870 spin_unlock_bh(&conn
->conn_usage_lock
);
873 void iscsit_inc_conn_usage_count(struct iscsi_conn
*conn
)
875 spin_lock_bh(&conn
->conn_usage_lock
);
876 conn
->conn_usage_count
++;
877 spin_unlock_bh(&conn
->conn_usage_lock
);
880 static int iscsit_add_nopin(struct iscsi_conn
*conn
, int want_response
)
883 struct iscsi_cmd
*cmd
;
885 cmd
= iscsit_allocate_cmd(conn
, TASK_RUNNING
);
889 cmd
->iscsi_opcode
= ISCSI_OP_NOOP_IN
;
890 state
= (want_response
) ? ISTATE_SEND_NOPIN_WANT_RESPONSE
:
891 ISTATE_SEND_NOPIN_NO_RESPONSE
;
892 cmd
->init_task_tag
= RESERVED_ITT
;
893 cmd
->targ_xfer_tag
= (want_response
) ?
894 session_get_next_ttt(conn
->sess
) : 0xFFFFFFFF;
895 spin_lock_bh(&conn
->cmd_lock
);
896 list_add_tail(&cmd
->i_conn_node
, &conn
->conn_cmd_list
);
897 spin_unlock_bh(&conn
->cmd_lock
);
900 iscsit_start_nopin_response_timer(conn
);
901 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, state
);
906 static void iscsit_handle_nopin_response_timeout(unsigned long data
)
908 struct iscsi_conn
*conn
= (struct iscsi_conn
*) data
;
910 iscsit_inc_conn_usage_count(conn
);
912 spin_lock_bh(&conn
->nopin_timer_lock
);
913 if (conn
->nopin_response_timer_flags
& ISCSI_TF_STOP
) {
914 spin_unlock_bh(&conn
->nopin_timer_lock
);
915 iscsit_dec_conn_usage_count(conn
);
919 pr_debug("Did not receive response to NOPIN on CID: %hu on"
920 " SID: %u, failing connection.\n", conn
->cid
,
922 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_RUNNING
;
923 spin_unlock_bh(&conn
->nopin_timer_lock
);
926 struct iscsi_portal_group
*tpg
= conn
->sess
->tpg
;
927 struct iscsi_tiqn
*tiqn
= tpg
->tpg_tiqn
;
930 spin_lock_bh(&tiqn
->sess_err_stats
.lock
);
931 strcpy(tiqn
->sess_err_stats
.last_sess_fail_rem_name
,
932 conn
->sess
->sess_ops
->InitiatorName
);
933 tiqn
->sess_err_stats
.last_sess_failure_type
=
934 ISCSI_SESS_ERR_CXN_TIMEOUT
;
935 tiqn
->sess_err_stats
.cxn_timeout_errors
++;
936 atomic_long_inc(&conn
->sess
->conn_timeout_errors
);
937 spin_unlock_bh(&tiqn
->sess_err_stats
.lock
);
941 iscsit_cause_connection_reinstatement(conn
, 0);
942 iscsit_dec_conn_usage_count(conn
);
945 void iscsit_mod_nopin_response_timer(struct iscsi_conn
*conn
)
947 struct iscsi_session
*sess
= conn
->sess
;
948 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
950 spin_lock_bh(&conn
->nopin_timer_lock
);
951 if (!(conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
)) {
952 spin_unlock_bh(&conn
->nopin_timer_lock
);
956 mod_timer(&conn
->nopin_response_timer
,
957 (get_jiffies_64() + na
->nopin_response_timeout
* HZ
));
958 spin_unlock_bh(&conn
->nopin_timer_lock
);
962 * Called with conn->nopin_timer_lock held.
964 void iscsit_start_nopin_response_timer(struct iscsi_conn
*conn
)
966 struct iscsi_session
*sess
= conn
->sess
;
967 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
969 spin_lock_bh(&conn
->nopin_timer_lock
);
970 if (conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
) {
971 spin_unlock_bh(&conn
->nopin_timer_lock
);
975 init_timer(&conn
->nopin_response_timer
);
976 conn
->nopin_response_timer
.expires
=
977 (get_jiffies_64() + na
->nopin_response_timeout
* HZ
);
978 conn
->nopin_response_timer
.data
= (unsigned long)conn
;
979 conn
->nopin_response_timer
.function
= iscsit_handle_nopin_response_timeout
;
980 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_STOP
;
981 conn
->nopin_response_timer_flags
|= ISCSI_TF_RUNNING
;
982 add_timer(&conn
->nopin_response_timer
);
984 pr_debug("Started NOPIN Response Timer on CID: %d to %u"
985 " seconds\n", conn
->cid
, na
->nopin_response_timeout
);
986 spin_unlock_bh(&conn
->nopin_timer_lock
);
989 void iscsit_stop_nopin_response_timer(struct iscsi_conn
*conn
)
991 spin_lock_bh(&conn
->nopin_timer_lock
);
992 if (!(conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
)) {
993 spin_unlock_bh(&conn
->nopin_timer_lock
);
996 conn
->nopin_response_timer_flags
|= ISCSI_TF_STOP
;
997 spin_unlock_bh(&conn
->nopin_timer_lock
);
999 del_timer_sync(&conn
->nopin_response_timer
);
1001 spin_lock_bh(&conn
->nopin_timer_lock
);
1002 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_RUNNING
;
1003 spin_unlock_bh(&conn
->nopin_timer_lock
);
1006 static void iscsit_handle_nopin_timeout(unsigned long data
)
1008 struct iscsi_conn
*conn
= (struct iscsi_conn
*) data
;
1010 iscsit_inc_conn_usage_count(conn
);
1012 spin_lock_bh(&conn
->nopin_timer_lock
);
1013 if (conn
->nopin_timer_flags
& ISCSI_TF_STOP
) {
1014 spin_unlock_bh(&conn
->nopin_timer_lock
);
1015 iscsit_dec_conn_usage_count(conn
);
1018 conn
->nopin_timer_flags
&= ~ISCSI_TF_RUNNING
;
1019 spin_unlock_bh(&conn
->nopin_timer_lock
);
1021 iscsit_add_nopin(conn
, 1);
1022 iscsit_dec_conn_usage_count(conn
);
1026 * Called with conn->nopin_timer_lock held.
1028 void __iscsit_start_nopin_timer(struct iscsi_conn
*conn
)
1030 struct iscsi_session
*sess
= conn
->sess
;
1031 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1033 * NOPIN timeout is disabled.
1035 if (!na
->nopin_timeout
)
1038 if (conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
)
1041 init_timer(&conn
->nopin_timer
);
1042 conn
->nopin_timer
.expires
= (get_jiffies_64() + na
->nopin_timeout
* HZ
);
1043 conn
->nopin_timer
.data
= (unsigned long)conn
;
1044 conn
->nopin_timer
.function
= iscsit_handle_nopin_timeout
;
1045 conn
->nopin_timer_flags
&= ~ISCSI_TF_STOP
;
1046 conn
->nopin_timer_flags
|= ISCSI_TF_RUNNING
;
1047 add_timer(&conn
->nopin_timer
);
1049 pr_debug("Started NOPIN Timer on CID: %d at %u second"
1050 " interval\n", conn
->cid
, na
->nopin_timeout
);
1053 void iscsit_start_nopin_timer(struct iscsi_conn
*conn
)
1055 struct iscsi_session
*sess
= conn
->sess
;
1056 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1058 * NOPIN timeout is disabled..
1060 if (!na
->nopin_timeout
)
1063 spin_lock_bh(&conn
->nopin_timer_lock
);
1064 if (conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
) {
1065 spin_unlock_bh(&conn
->nopin_timer_lock
);
1069 init_timer(&conn
->nopin_timer
);
1070 conn
->nopin_timer
.expires
= (get_jiffies_64() + na
->nopin_timeout
* HZ
);
1071 conn
->nopin_timer
.data
= (unsigned long)conn
;
1072 conn
->nopin_timer
.function
= iscsit_handle_nopin_timeout
;
1073 conn
->nopin_timer_flags
&= ~ISCSI_TF_STOP
;
1074 conn
->nopin_timer_flags
|= ISCSI_TF_RUNNING
;
1075 add_timer(&conn
->nopin_timer
);
1077 pr_debug("Started NOPIN Timer on CID: %d at %u second"
1078 " interval\n", conn
->cid
, na
->nopin_timeout
);
1079 spin_unlock_bh(&conn
->nopin_timer_lock
);
1082 void iscsit_stop_nopin_timer(struct iscsi_conn
*conn
)
1084 spin_lock_bh(&conn
->nopin_timer_lock
);
1085 if (!(conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
)) {
1086 spin_unlock_bh(&conn
->nopin_timer_lock
);
1089 conn
->nopin_timer_flags
|= ISCSI_TF_STOP
;
1090 spin_unlock_bh(&conn
->nopin_timer_lock
);
1092 del_timer_sync(&conn
->nopin_timer
);
1094 spin_lock_bh(&conn
->nopin_timer_lock
);
1095 conn
->nopin_timer_flags
&= ~ISCSI_TF_RUNNING
;
1096 spin_unlock_bh(&conn
->nopin_timer_lock
);
1099 int iscsit_send_tx_data(
1100 struct iscsi_cmd
*cmd
,
1101 struct iscsi_conn
*conn
,
1104 int tx_sent
, tx_size
;
1109 tx_size
= cmd
->tx_size
;
1112 iov
= &cmd
->iov_data
[0];
1113 iov_count
= cmd
->iov_data_count
;
1115 iov
= &cmd
->iov_misc
[0];
1116 iov_count
= cmd
->iov_misc_count
;
1119 tx_sent
= tx_data(conn
, &iov
[0], iov_count
, tx_size
);
1120 if (tx_size
!= tx_sent
) {
1121 if (tx_sent
== -EAGAIN
) {
1122 pr_err("tx_data() returned -EAGAIN\n");
1132 int iscsit_fe_sendpage_sg(
1133 struct iscsi_cmd
*cmd
,
1134 struct iscsi_conn
*conn
)
1136 struct scatterlist
*sg
= cmd
->first_data_sg
;
1138 u32 tx_hdr_size
, data_len
;
1139 u32 offset
= cmd
->first_data_sg_off
;
1140 int tx_sent
, iov_off
;
1143 tx_hdr_size
= ISCSI_HDR_LEN
;
1144 if (conn
->conn_ops
->HeaderDigest
)
1145 tx_hdr_size
+= ISCSI_CRC_LEN
;
1147 iov
.iov_base
= cmd
->pdu
;
1148 iov
.iov_len
= tx_hdr_size
;
1150 tx_sent
= tx_data(conn
, &iov
, 1, tx_hdr_size
);
1151 if (tx_hdr_size
!= tx_sent
) {
1152 if (tx_sent
== -EAGAIN
) {
1153 pr_err("tx_data() returned -EAGAIN\n");
1159 data_len
= cmd
->tx_size
- tx_hdr_size
- cmd
->padding
;
1161 * Set iov_off used by padding and data digest tx_data() calls below
1162 * in order to determine proper offset into cmd->iov_data[]
1164 if (conn
->conn_ops
->DataDigest
) {
1165 data_len
-= ISCSI_CRC_LEN
;
1167 iov_off
= (cmd
->iov_data_count
- 2);
1169 iov_off
= (cmd
->iov_data_count
- 1);
1171 iov_off
= (cmd
->iov_data_count
- 1);
1174 * Perform sendpage() for each page in the scatterlist
1177 u32 space
= (sg
->length
- offset
);
1178 u32 sub_len
= min_t(u32
, data_len
, space
);
1180 tx_sent
= conn
->sock
->ops
->sendpage(conn
->sock
,
1181 sg_page(sg
), sg
->offset
+ offset
, sub_len
, 0);
1182 if (tx_sent
!= sub_len
) {
1183 if (tx_sent
== -EAGAIN
) {
1184 pr_err("tcp_sendpage() returned"
1189 pr_err("tcp_sendpage() failure: %d\n",
1194 data_len
-= sub_len
;
1201 struct kvec
*iov_p
= &cmd
->iov_data
[iov_off
++];
1203 tx_sent
= tx_data(conn
, iov_p
, 1, cmd
->padding
);
1204 if (cmd
->padding
!= tx_sent
) {
1205 if (tx_sent
== -EAGAIN
) {
1206 pr_err("tx_data() returned -EAGAIN\n");
1214 if (conn
->conn_ops
->DataDigest
) {
1215 struct kvec
*iov_d
= &cmd
->iov_data
[iov_off
];
1217 tx_sent
= tx_data(conn
, iov_d
, 1, ISCSI_CRC_LEN
);
1218 if (ISCSI_CRC_LEN
!= tx_sent
) {
1219 if (tx_sent
== -EAGAIN
) {
1220 pr_err("tx_data() returned -EAGAIN\n");
1231 * This function is used for mainly sending a ISCSI_TARG_LOGIN_RSP PDU
1232 * back to the Initiator when an expection condition occurs with the
1233 * errors set in status_class and status_detail.
1235 * Parameters: iSCSI Connection, Status Class, Status Detail.
1236 * Returns: 0 on success, -1 on error.
1238 int iscsit_tx_login_rsp(struct iscsi_conn
*conn
, u8 status_class
, u8 status_detail
)
1240 struct iscsi_login_rsp
*hdr
;
1241 struct iscsi_login
*login
= conn
->conn_login
;
1243 login
->login_failed
= 1;
1244 iscsit_collect_login_stats(conn
, status_class
, status_detail
);
1246 memset(&login
->rsp
[0], 0, ISCSI_HDR_LEN
);
1248 hdr
= (struct iscsi_login_rsp
*)&login
->rsp
[0];
1249 hdr
->opcode
= ISCSI_OP_LOGIN_RSP
;
1250 hdr
->status_class
= status_class
;
1251 hdr
->status_detail
= status_detail
;
1252 hdr
->itt
= conn
->login_itt
;
1254 return conn
->conn_transport
->iscsit_put_login_tx(conn
, login
, 0);
1257 void iscsit_print_session_params(struct iscsi_session
*sess
)
1259 struct iscsi_conn
*conn
;
1261 pr_debug("-----------------------------[Session Params for"
1262 " SID: %u]-----------------------------\n", sess
->sid
);
1263 spin_lock_bh(&sess
->conn_lock
);
1264 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
)
1265 iscsi_dump_conn_ops(conn
->conn_ops
);
1266 spin_unlock_bh(&sess
->conn_lock
);
1268 iscsi_dump_sess_ops(sess
->sess_ops
);
1271 static int iscsit_do_rx_data(
1272 struct iscsi_conn
*conn
,
1273 struct iscsi_data_count
*count
)
1275 int data
= count
->data_length
, rx_loop
= 0, total_rx
= 0;
1278 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1281 memset(&msg
, 0, sizeof(struct msghdr
));
1282 iov_iter_kvec(&msg
.msg_iter
, READ
| ITER_KVEC
,
1283 count
->iov
, count
->iov_count
, data
);
1285 while (total_rx
< data
) {
1286 rx_loop
= sock_recvmsg(conn
->sock
, &msg
,
1287 (data
- total_rx
), MSG_WAITALL
);
1289 pr_debug("rx_loop: %d total_rx: %d\n",
1293 total_rx
+= rx_loop
;
1294 pr_debug("rx_loop: %d, total_rx: %d, data: %d\n",
1295 rx_loop
, total_rx
, data
);
1301 static int iscsit_do_tx_data(
1302 struct iscsi_conn
*conn
,
1303 struct iscsi_data_count
*count
)
1309 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1312 if (count
->data_length
<= 0) {
1313 pr_err("Data length is: %d\n", count
->data_length
);
1317 memset(&msg
, 0, sizeof(struct msghdr
));
1320 iov_len
= count
->iov_count
;
1322 ret
= kernel_sendmsg(conn
->sock
, &msg
, iov_p
, iov_len
,
1323 count
->data_length
);
1324 if (ret
!= count
->data_length
) {
1325 pr_err("Unexpected ret: %d send data %d\n",
1326 ret
, count
->data_length
);
1329 pr_debug("ret: %d, sent data: %d\n", ret
, count
->data_length
);
1335 struct iscsi_conn
*conn
,
1340 struct iscsi_data_count c
;
1342 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1345 memset(&c
, 0, sizeof(struct iscsi_data_count
));
1347 c
.iov_count
= iov_count
;
1348 c
.data_length
= data
;
1349 c
.type
= ISCSI_RX_DATA
;
1351 return iscsit_do_rx_data(conn
, &c
);
1355 struct iscsi_conn
*conn
,
1360 struct iscsi_data_count c
;
1362 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1365 memset(&c
, 0, sizeof(struct iscsi_data_count
));
1367 c
.iov_count
= iov_count
;
1368 c
.data_length
= data
;
1369 c
.type
= ISCSI_TX_DATA
;
1371 return iscsit_do_tx_data(conn
, &c
);
1374 void iscsit_collect_login_stats(
1375 struct iscsi_conn
*conn
,
1379 struct iscsi_param
*intrname
= NULL
;
1380 struct iscsi_tiqn
*tiqn
;
1381 struct iscsi_login_stats
*ls
;
1383 tiqn
= iscsit_snmp_get_tiqn(conn
);
1387 ls
= &tiqn
->login_stats
;
1389 spin_lock(&ls
->lock
);
1390 if (!strcmp(conn
->login_ip
, ls
->last_intr_fail_ip_addr
) &&
1391 ((get_jiffies_64() - ls
->last_fail_time
) < 10)) {
1392 /* We already have the failure info for this login */
1393 spin_unlock(&ls
->lock
);
1397 if (status_class
== ISCSI_STATUS_CLS_SUCCESS
)
1399 else if (status_class
== ISCSI_STATUS_CLS_REDIRECT
) {
1401 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_REDIRECT
;
1402 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1403 (status_detail
== ISCSI_LOGIN_STATUS_AUTH_FAILED
)) {
1404 ls
->authenticate_fails
++;
1405 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_AUTHENTICATE
;
1406 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1407 (status_detail
== ISCSI_LOGIN_STATUS_TGT_FORBIDDEN
)) {
1408 ls
->authorize_fails
++;
1409 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_AUTHORIZE
;
1410 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1411 (status_detail
== ISCSI_LOGIN_STATUS_INIT_ERR
)) {
1412 ls
->negotiate_fails
++;
1413 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_NEGOTIATE
;
1416 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_OTHER
;
1419 /* Save initiator name, ip address and time, if it is a failed login */
1420 if (status_class
!= ISCSI_STATUS_CLS_SUCCESS
) {
1421 if (conn
->param_list
)
1422 intrname
= iscsi_find_param_from_key(INITIATORNAME
,
1424 strlcpy(ls
->last_intr_fail_name
,
1425 (intrname
? intrname
->value
: "Unknown"),
1426 sizeof(ls
->last_intr_fail_name
));
1428 ls
->last_intr_fail_ip_family
= conn
->login_family
;
1430 snprintf(ls
->last_intr_fail_ip_addr
, IPV6_ADDRESS_SPACE
,
1431 "%s", conn
->login_ip
);
1432 ls
->last_fail_time
= get_jiffies_64();
1435 spin_unlock(&ls
->lock
);
1438 struct iscsi_tiqn
*iscsit_snmp_get_tiqn(struct iscsi_conn
*conn
)
1440 struct iscsi_portal_group
*tpg
;
1442 if (!conn
|| !conn
->sess
)
1445 tpg
= conn
->sess
->tpg
;
1452 return tpg
->tpg_tiqn
;