1 /*******************************************************************************
2 * This file contains the iSCSI Target specific utility functions.
4 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
6 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 ******************************************************************************/
21 #include <linux/list.h>
22 #include <scsi/scsi_tcq.h>
23 #include <scsi/iscsi_proto.h>
24 #include <target/target_core_base.h>
25 #include <target/target_core_fabric.h>
26 #include <target/target_core_configfs.h>
27 #include <target/iscsi/iscsi_transport.h>
29 #include "iscsi_target_core.h"
30 #include "iscsi_target_parameters.h"
31 #include "iscsi_target_seq_pdu_list.h"
32 #include "iscsi_target_datain_values.h"
33 #include "iscsi_target_erl0.h"
34 #include "iscsi_target_erl1.h"
35 #include "iscsi_target_erl2.h"
36 #include "iscsi_target_tpg.h"
37 #include "iscsi_target_tq.h"
38 #include "iscsi_target_util.h"
39 #include "iscsi_target.h"
41 #define PRINT_BUFF(buff, len) \
45 pr_debug("%d:\n", __LINE__); \
46 for (zzz = 0; zzz < len; zzz++) { \
47 if (zzz % 16 == 0) { \
50 pr_debug("%4i: ", zzz); \
52 pr_debug("%02x ", (unsigned char) (buff)[zzz]); \
58 extern struct list_head g_tiqn_list
;
59 extern spinlock_t tiqn_lock
;
62 * Called with cmd->r2t_lock held.
64 int iscsit_add_r2t_to_list(
65 struct iscsi_cmd
*cmd
,
71 struct iscsi_r2t
*r2t
;
73 r2t
= kmem_cache_zalloc(lio_r2t_cache
, GFP_ATOMIC
);
75 pr_err("Unable to allocate memory for struct iscsi_r2t.\n");
78 INIT_LIST_HEAD(&r2t
->r2t_list
);
80 r2t
->recovery_r2t
= recovery
;
81 r2t
->r2t_sn
= (!r2t_sn
) ? cmd
->r2t_sn
++ : r2t_sn
;
83 r2t
->xfer_len
= xfer_len
;
84 list_add_tail(&r2t
->r2t_list
, &cmd
->cmd_r2t_list
);
85 spin_unlock_bh(&cmd
->r2t_lock
);
87 iscsit_add_cmd_to_immediate_queue(cmd
, cmd
->conn
, ISTATE_SEND_R2T
);
89 spin_lock_bh(&cmd
->r2t_lock
);
93 struct iscsi_r2t
*iscsit_get_r2t_for_eos(
94 struct iscsi_cmd
*cmd
,
98 struct iscsi_r2t
*r2t
;
100 spin_lock_bh(&cmd
->r2t_lock
);
101 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
102 if ((r2t
->offset
<= offset
) &&
103 (r2t
->offset
+ r2t
->xfer_len
) >= (offset
+ length
)) {
104 spin_unlock_bh(&cmd
->r2t_lock
);
108 spin_unlock_bh(&cmd
->r2t_lock
);
110 pr_err("Unable to locate R2T for Offset: %u, Length:"
111 " %u\n", offset
, length
);
115 struct iscsi_r2t
*iscsit_get_r2t_from_list(struct iscsi_cmd
*cmd
)
117 struct iscsi_r2t
*r2t
;
119 spin_lock_bh(&cmd
->r2t_lock
);
120 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
121 if (!r2t
->sent_r2t
) {
122 spin_unlock_bh(&cmd
->r2t_lock
);
126 spin_unlock_bh(&cmd
->r2t_lock
);
128 pr_err("Unable to locate next R2T to send for ITT:"
129 " 0x%08x.\n", cmd
->init_task_tag
);
134 * Called with cmd->r2t_lock held.
136 void iscsit_free_r2t(struct iscsi_r2t
*r2t
, struct iscsi_cmd
*cmd
)
138 list_del(&r2t
->r2t_list
);
139 kmem_cache_free(lio_r2t_cache
, r2t
);
142 void iscsit_free_r2ts_from_list(struct iscsi_cmd
*cmd
)
144 struct iscsi_r2t
*r2t
, *r2t_tmp
;
146 spin_lock_bh(&cmd
->r2t_lock
);
147 list_for_each_entry_safe(r2t
, r2t_tmp
, &cmd
->cmd_r2t_list
, r2t_list
)
148 iscsit_free_r2t(r2t
, cmd
);
149 spin_unlock_bh(&cmd
->r2t_lock
);
153 * May be called from software interrupt (timer) context for allocating
156 struct iscsi_cmd
*iscsit_allocate_cmd(struct iscsi_conn
*conn
, gfp_t gfp_mask
)
158 struct iscsi_cmd
*cmd
;
159 int priv_size
= conn
->conn_transport
->priv_size
;
161 cmd
= kzalloc(sizeof(struct iscsi_cmd
) + priv_size
, gfp_mask
);
163 pr_err("Unable to allocate memory for struct iscsi_cmd.\n");
167 INIT_LIST_HEAD(&cmd
->i_conn_node
);
168 INIT_LIST_HEAD(&cmd
->datain_list
);
169 INIT_LIST_HEAD(&cmd
->cmd_r2t_list
);
170 spin_lock_init(&cmd
->datain_lock
);
171 spin_lock_init(&cmd
->dataout_timeout_lock
);
172 spin_lock_init(&cmd
->istate_lock
);
173 spin_lock_init(&cmd
->error_lock
);
174 spin_lock_init(&cmd
->r2t_lock
);
178 EXPORT_SYMBOL(iscsit_allocate_cmd
);
180 struct iscsi_seq
*iscsit_get_seq_holder_for_datain(
181 struct iscsi_cmd
*cmd
,
186 for (i
= 0; i
< cmd
->seq_count
; i
++)
187 if (cmd
->seq_list
[i
].seq_send_order
== seq_send_order
)
188 return &cmd
->seq_list
[i
];
193 struct iscsi_seq
*iscsit_get_seq_holder_for_r2t(struct iscsi_cmd
*cmd
)
197 if (!cmd
->seq_list
) {
198 pr_err("struct iscsi_cmd->seq_list is NULL!\n");
202 for (i
= 0; i
< cmd
->seq_count
; i
++) {
203 if (cmd
->seq_list
[i
].type
!= SEQTYPE_NORMAL
)
205 if (cmd
->seq_list
[i
].seq_send_order
== cmd
->seq_send_order
) {
206 cmd
->seq_send_order
++;
207 return &cmd
->seq_list
[i
];
214 struct iscsi_r2t
*iscsit_get_holder_for_r2tsn(
215 struct iscsi_cmd
*cmd
,
218 struct iscsi_r2t
*r2t
;
220 spin_lock_bh(&cmd
->r2t_lock
);
221 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
222 if (r2t
->r2t_sn
== r2t_sn
) {
223 spin_unlock_bh(&cmd
->r2t_lock
);
227 spin_unlock_bh(&cmd
->r2t_lock
);
232 static inline int iscsit_check_received_cmdsn(struct iscsi_session
*sess
, u32 cmdsn
)
237 * This is the proper method of checking received CmdSN against
238 * ExpCmdSN and MaxCmdSN values, as well as accounting for out
239 * or order CmdSNs due to multiple connection sessions and/or
242 if (iscsi_sna_gt(cmdsn
, sess
->max_cmd_sn
)) {
243 pr_err("Received CmdSN: 0x%08x is greater than"
244 " MaxCmdSN: 0x%08x, protocol error.\n", cmdsn
,
246 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
248 } else if (cmdsn
== sess
->exp_cmd_sn
) {
250 pr_debug("Received CmdSN matches ExpCmdSN,"
251 " incremented ExpCmdSN to: 0x%08x\n",
253 ret
= CMDSN_NORMAL_OPERATION
;
255 } else if (iscsi_sna_gt(cmdsn
, sess
->exp_cmd_sn
)) {
256 pr_debug("Received CmdSN: 0x%08x is greater"
257 " than ExpCmdSN: 0x%08x, not acknowledging.\n",
258 cmdsn
, sess
->exp_cmd_sn
);
259 ret
= CMDSN_HIGHER_THAN_EXP
;
262 pr_err("Received CmdSN: 0x%08x is less than"
263 " ExpCmdSN: 0x%08x, ignoring.\n", cmdsn
,
265 ret
= CMDSN_LOWER_THAN_EXP
;
272 * Commands may be received out of order if MC/S is in use.
273 * Ensure they are executed in CmdSN order.
275 int iscsit_sequence_cmd(struct iscsi_conn
*conn
, struct iscsi_cmd
*cmd
,
276 unsigned char *buf
, __be32 cmdsn
)
280 u8 reason
= ISCSI_REASON_BOOKMARK_NO_RESOURCES
;
282 mutex_lock(&conn
->sess
->cmdsn_mutex
);
284 cmdsn_ret
= iscsit_check_received_cmdsn(conn
->sess
, be32_to_cpu(cmdsn
));
286 case CMDSN_NORMAL_OPERATION
:
287 ret
= iscsit_execute_cmd(cmd
, 0);
288 if ((ret
>= 0) && !list_empty(&conn
->sess
->sess_ooo_cmdsn_list
))
289 iscsit_execute_ooo_cmdsns(conn
->sess
);
292 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
295 case CMDSN_HIGHER_THAN_EXP
:
296 ret
= iscsit_handle_ooo_cmdsn(conn
->sess
, cmd
, be32_to_cpu(cmdsn
));
299 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
302 ret
= CMDSN_HIGHER_THAN_EXP
;
304 case CMDSN_LOWER_THAN_EXP
:
305 cmd
->i_state
= ISTATE_REMOVE
;
306 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, cmd
->i_state
);
310 reason
= ISCSI_REASON_PROTOCOL_ERROR
;
315 mutex_unlock(&conn
->sess
->cmdsn_mutex
);
318 iscsit_reject_cmd(cmd
, reason
, buf
);
322 EXPORT_SYMBOL(iscsit_sequence_cmd
);
324 int iscsit_check_unsolicited_dataout(struct iscsi_cmd
*cmd
, unsigned char *buf
)
326 struct iscsi_conn
*conn
= cmd
->conn
;
327 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
328 struct iscsi_data
*hdr
= (struct iscsi_data
*) buf
;
329 u32 payload_length
= ntoh24(hdr
->dlength
);
331 if (conn
->sess
->sess_ops
->InitialR2T
) {
332 pr_err("Received unexpected unsolicited data"
333 " while InitialR2T=Yes, protocol error.\n");
334 transport_send_check_condition_and_sense(se_cmd
,
335 TCM_UNEXPECTED_UNSOLICITED_DATA
, 0);
339 if ((cmd
->first_burst_len
+ payload_length
) >
340 conn
->sess
->sess_ops
->FirstBurstLength
) {
341 pr_err("Total %u bytes exceeds FirstBurstLength: %u"
342 " for this Unsolicited DataOut Burst.\n",
343 (cmd
->first_burst_len
+ payload_length
),
344 conn
->sess
->sess_ops
->FirstBurstLength
);
345 transport_send_check_condition_and_sense(se_cmd
,
346 TCM_INCORRECT_AMOUNT_OF_DATA
, 0);
350 if (!(hdr
->flags
& ISCSI_FLAG_CMD_FINAL
))
353 if (((cmd
->first_burst_len
+ payload_length
) != cmd
->se_cmd
.data_length
) &&
354 ((cmd
->first_burst_len
+ payload_length
) !=
355 conn
->sess
->sess_ops
->FirstBurstLength
)) {
356 pr_err("Unsolicited non-immediate data received %u"
357 " does not equal FirstBurstLength: %u, and does"
358 " not equal ExpXferLen %u.\n",
359 (cmd
->first_burst_len
+ payload_length
),
360 conn
->sess
->sess_ops
->FirstBurstLength
, cmd
->se_cmd
.data_length
);
361 transport_send_check_condition_and_sense(se_cmd
,
362 TCM_INCORRECT_AMOUNT_OF_DATA
, 0);
368 struct iscsi_cmd
*iscsit_find_cmd_from_itt(
369 struct iscsi_conn
*conn
,
372 struct iscsi_cmd
*cmd
;
374 spin_lock_bh(&conn
->cmd_lock
);
375 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
376 if (cmd
->init_task_tag
== init_task_tag
) {
377 spin_unlock_bh(&conn
->cmd_lock
);
381 spin_unlock_bh(&conn
->cmd_lock
);
383 pr_err("Unable to locate ITT: 0x%08x on CID: %hu",
384 init_task_tag
, conn
->cid
);
388 struct iscsi_cmd
*iscsit_find_cmd_from_itt_or_dump(
389 struct iscsi_conn
*conn
,
393 struct iscsi_cmd
*cmd
;
395 spin_lock_bh(&conn
->cmd_lock
);
396 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
397 if (cmd
->init_task_tag
== init_task_tag
) {
398 spin_unlock_bh(&conn
->cmd_lock
);
402 spin_unlock_bh(&conn
->cmd_lock
);
404 pr_err("Unable to locate ITT: 0x%08x on CID: %hu,"
405 " dumping payload\n", init_task_tag
, conn
->cid
);
407 iscsit_dump_data_payload(conn
, length
, 1);
412 struct iscsi_cmd
*iscsit_find_cmd_from_ttt(
413 struct iscsi_conn
*conn
,
416 struct iscsi_cmd
*cmd
= NULL
;
418 spin_lock_bh(&conn
->cmd_lock
);
419 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
420 if (cmd
->targ_xfer_tag
== targ_xfer_tag
) {
421 spin_unlock_bh(&conn
->cmd_lock
);
425 spin_unlock_bh(&conn
->cmd_lock
);
427 pr_err("Unable to locate TTT: 0x%08x on CID: %hu\n",
428 targ_xfer_tag
, conn
->cid
);
432 int iscsit_find_cmd_for_recovery(
433 struct iscsi_session
*sess
,
434 struct iscsi_cmd
**cmd_ptr
,
435 struct iscsi_conn_recovery
**cr_ptr
,
438 struct iscsi_cmd
*cmd
= NULL
;
439 struct iscsi_conn_recovery
*cr
;
441 * Scan through the inactive connection recovery list's command list.
442 * If init_task_tag matches the command is still alligent.
444 spin_lock(&sess
->cr_i_lock
);
445 list_for_each_entry(cr
, &sess
->cr_inactive_list
, cr_list
) {
446 spin_lock(&cr
->conn_recovery_cmd_lock
);
447 list_for_each_entry(cmd
, &cr
->conn_recovery_cmd_list
, i_conn_node
) {
448 if (cmd
->init_task_tag
== init_task_tag
) {
449 spin_unlock(&cr
->conn_recovery_cmd_lock
);
450 spin_unlock(&sess
->cr_i_lock
);
457 spin_unlock(&cr
->conn_recovery_cmd_lock
);
459 spin_unlock(&sess
->cr_i_lock
);
461 * Scan through the active connection recovery list's command list.
462 * If init_task_tag matches the command is ready to be reassigned.
464 spin_lock(&sess
->cr_a_lock
);
465 list_for_each_entry(cr
, &sess
->cr_active_list
, cr_list
) {
466 spin_lock(&cr
->conn_recovery_cmd_lock
);
467 list_for_each_entry(cmd
, &cr
->conn_recovery_cmd_list
, i_conn_node
) {
468 if (cmd
->init_task_tag
== init_task_tag
) {
469 spin_unlock(&cr
->conn_recovery_cmd_lock
);
470 spin_unlock(&sess
->cr_a_lock
);
477 spin_unlock(&cr
->conn_recovery_cmd_lock
);
479 spin_unlock(&sess
->cr_a_lock
);
484 void iscsit_add_cmd_to_immediate_queue(
485 struct iscsi_cmd
*cmd
,
486 struct iscsi_conn
*conn
,
489 struct iscsi_queue_req
*qr
;
491 qr
= kmem_cache_zalloc(lio_qr_cache
, GFP_ATOMIC
);
493 pr_err("Unable to allocate memory for"
494 " struct iscsi_queue_req\n");
497 INIT_LIST_HEAD(&qr
->qr_list
);
501 spin_lock_bh(&conn
->immed_queue_lock
);
502 list_add_tail(&qr
->qr_list
, &conn
->immed_queue_list
);
503 atomic_inc(&cmd
->immed_queue_count
);
504 atomic_set(&conn
->check_immediate_queue
, 1);
505 spin_unlock_bh(&conn
->immed_queue_lock
);
507 wake_up(&conn
->queues_wq
);
510 struct iscsi_queue_req
*iscsit_get_cmd_from_immediate_queue(struct iscsi_conn
*conn
)
512 struct iscsi_queue_req
*qr
;
514 spin_lock_bh(&conn
->immed_queue_lock
);
515 if (list_empty(&conn
->immed_queue_list
)) {
516 spin_unlock_bh(&conn
->immed_queue_lock
);
519 qr
= list_first_entry(&conn
->immed_queue_list
,
520 struct iscsi_queue_req
, qr_list
);
522 list_del(&qr
->qr_list
);
524 atomic_dec(&qr
->cmd
->immed_queue_count
);
525 spin_unlock_bh(&conn
->immed_queue_lock
);
530 static void iscsit_remove_cmd_from_immediate_queue(
531 struct iscsi_cmd
*cmd
,
532 struct iscsi_conn
*conn
)
534 struct iscsi_queue_req
*qr
, *qr_tmp
;
536 spin_lock_bh(&conn
->immed_queue_lock
);
537 if (!atomic_read(&cmd
->immed_queue_count
)) {
538 spin_unlock_bh(&conn
->immed_queue_lock
);
542 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->immed_queue_list
, qr_list
) {
546 atomic_dec(&qr
->cmd
->immed_queue_count
);
547 list_del(&qr
->qr_list
);
548 kmem_cache_free(lio_qr_cache
, qr
);
550 spin_unlock_bh(&conn
->immed_queue_lock
);
552 if (atomic_read(&cmd
->immed_queue_count
)) {
553 pr_err("ITT: 0x%08x immed_queue_count: %d\n",
555 atomic_read(&cmd
->immed_queue_count
));
559 void iscsit_add_cmd_to_response_queue(
560 struct iscsi_cmd
*cmd
,
561 struct iscsi_conn
*conn
,
564 struct iscsi_queue_req
*qr
;
566 qr
= kmem_cache_zalloc(lio_qr_cache
, GFP_ATOMIC
);
568 pr_err("Unable to allocate memory for"
569 " struct iscsi_queue_req\n");
572 INIT_LIST_HEAD(&qr
->qr_list
);
576 spin_lock_bh(&conn
->response_queue_lock
);
577 list_add_tail(&qr
->qr_list
, &conn
->response_queue_list
);
578 atomic_inc(&cmd
->response_queue_count
);
579 spin_unlock_bh(&conn
->response_queue_lock
);
581 wake_up(&conn
->queues_wq
);
584 struct iscsi_queue_req
*iscsit_get_cmd_from_response_queue(struct iscsi_conn
*conn
)
586 struct iscsi_queue_req
*qr
;
588 spin_lock_bh(&conn
->response_queue_lock
);
589 if (list_empty(&conn
->response_queue_list
)) {
590 spin_unlock_bh(&conn
->response_queue_lock
);
594 qr
= list_first_entry(&conn
->response_queue_list
,
595 struct iscsi_queue_req
, qr_list
);
597 list_del(&qr
->qr_list
);
599 atomic_dec(&qr
->cmd
->response_queue_count
);
600 spin_unlock_bh(&conn
->response_queue_lock
);
605 static void iscsit_remove_cmd_from_response_queue(
606 struct iscsi_cmd
*cmd
,
607 struct iscsi_conn
*conn
)
609 struct iscsi_queue_req
*qr
, *qr_tmp
;
611 spin_lock_bh(&conn
->response_queue_lock
);
612 if (!atomic_read(&cmd
->response_queue_count
)) {
613 spin_unlock_bh(&conn
->response_queue_lock
);
617 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->response_queue_list
,
622 atomic_dec(&qr
->cmd
->response_queue_count
);
623 list_del(&qr
->qr_list
);
624 kmem_cache_free(lio_qr_cache
, qr
);
626 spin_unlock_bh(&conn
->response_queue_lock
);
628 if (atomic_read(&cmd
->response_queue_count
)) {
629 pr_err("ITT: 0x%08x response_queue_count: %d\n",
631 atomic_read(&cmd
->response_queue_count
));
635 bool iscsit_conn_all_queues_empty(struct iscsi_conn
*conn
)
639 spin_lock_bh(&conn
->immed_queue_lock
);
640 empty
= list_empty(&conn
->immed_queue_list
);
641 spin_unlock_bh(&conn
->immed_queue_lock
);
646 spin_lock_bh(&conn
->response_queue_lock
);
647 empty
= list_empty(&conn
->response_queue_list
);
648 spin_unlock_bh(&conn
->response_queue_lock
);
653 void iscsit_free_queue_reqs_for_conn(struct iscsi_conn
*conn
)
655 struct iscsi_queue_req
*qr
, *qr_tmp
;
657 spin_lock_bh(&conn
->immed_queue_lock
);
658 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->immed_queue_list
, qr_list
) {
659 list_del(&qr
->qr_list
);
661 atomic_dec(&qr
->cmd
->immed_queue_count
);
663 kmem_cache_free(lio_qr_cache
, qr
);
665 spin_unlock_bh(&conn
->immed_queue_lock
);
667 spin_lock_bh(&conn
->response_queue_lock
);
668 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->response_queue_list
,
670 list_del(&qr
->qr_list
);
672 atomic_dec(&qr
->cmd
->response_queue_count
);
674 kmem_cache_free(lio_qr_cache
, qr
);
676 spin_unlock_bh(&conn
->response_queue_lock
);
679 void iscsit_release_cmd(struct iscsi_cmd
*cmd
)
682 kfree(cmd
->pdu_list
);
683 kfree(cmd
->seq_list
);
685 kfree(cmd
->iov_data
);
686 kfree(cmd
->text_in_ptr
);
690 EXPORT_SYMBOL(iscsit_release_cmd
);
692 static void __iscsit_free_cmd(struct iscsi_cmd
*cmd
, bool scsi_cmd
,
695 struct iscsi_conn
*conn
= cmd
->conn
;
698 if (cmd
->data_direction
== DMA_TO_DEVICE
) {
699 iscsit_stop_dataout_timer(cmd
);
700 iscsit_free_r2ts_from_list(cmd
);
702 if (cmd
->data_direction
== DMA_FROM_DEVICE
)
703 iscsit_free_all_datain_reqs(cmd
);
706 if (conn
&& check_queues
) {
707 iscsit_remove_cmd_from_immediate_queue(cmd
, conn
);
708 iscsit_remove_cmd_from_response_queue(cmd
, conn
);
712 void iscsit_free_cmd(struct iscsi_cmd
*cmd
, bool shutdown
)
714 struct se_cmd
*se_cmd
= NULL
;
717 * Determine if a struct se_cmd is associated with
718 * this struct iscsi_cmd.
720 switch (cmd
->iscsi_opcode
) {
721 case ISCSI_OP_SCSI_CMD
:
722 se_cmd
= &cmd
->se_cmd
;
723 __iscsit_free_cmd(cmd
, true, shutdown
);
727 case ISCSI_OP_SCSI_TMFUNC
:
728 rc
= transport_generic_free_cmd(&cmd
->se_cmd
, 1);
729 if (!rc
&& shutdown
&& se_cmd
&& se_cmd
->se_sess
) {
730 __iscsit_free_cmd(cmd
, true, shutdown
);
731 target_put_sess_cmd(se_cmd
->se_sess
, se_cmd
);
734 case ISCSI_OP_REJECT
:
736 * Handle special case for REJECT when iscsi_add_reject*() has
737 * overwritten the original iscsi_opcode assignment, and the
738 * associated cmd->se_cmd needs to be released.
740 if (cmd
->se_cmd
.se_tfo
!= NULL
) {
741 se_cmd
= &cmd
->se_cmd
;
742 __iscsit_free_cmd(cmd
, true, shutdown
);
744 rc
= transport_generic_free_cmd(&cmd
->se_cmd
, 1);
745 if (!rc
&& shutdown
&& se_cmd
->se_sess
) {
746 __iscsit_free_cmd(cmd
, true, shutdown
);
747 target_put_sess_cmd(se_cmd
->se_sess
, se_cmd
);
753 __iscsit_free_cmd(cmd
, false, shutdown
);
754 iscsit_release_cmd(cmd
);
759 int iscsit_check_session_usage_count(struct iscsi_session
*sess
)
761 spin_lock_bh(&sess
->session_usage_lock
);
762 if (sess
->session_usage_count
!= 0) {
763 sess
->session_waiting_on_uc
= 1;
764 spin_unlock_bh(&sess
->session_usage_lock
);
768 wait_for_completion(&sess
->session_waiting_on_uc_comp
);
771 spin_unlock_bh(&sess
->session_usage_lock
);
776 void iscsit_dec_session_usage_count(struct iscsi_session
*sess
)
778 spin_lock_bh(&sess
->session_usage_lock
);
779 sess
->session_usage_count
--;
781 if (!sess
->session_usage_count
&& sess
->session_waiting_on_uc
)
782 complete(&sess
->session_waiting_on_uc_comp
);
784 spin_unlock_bh(&sess
->session_usage_lock
);
787 void iscsit_inc_session_usage_count(struct iscsi_session
*sess
)
789 spin_lock_bh(&sess
->session_usage_lock
);
790 sess
->session_usage_count
++;
791 spin_unlock_bh(&sess
->session_usage_lock
);
795 * Setup conn->if_marker and conn->of_marker values based upon
796 * the initial marker-less interval. (see iSCSI v19 A.2)
798 int iscsit_set_sync_and_steering_values(struct iscsi_conn
*conn
)
800 int login_ifmarker_count
= 0, login_ofmarker_count
= 0, next_marker
= 0;
802 * IFMarkInt and OFMarkInt are negotiated as 32-bit words.
804 u32 IFMarkInt
= (conn
->conn_ops
->IFMarkInt
* 4);
805 u32 OFMarkInt
= (conn
->conn_ops
->OFMarkInt
* 4);
807 if (conn
->conn_ops
->OFMarker
) {
809 * Account for the first Login Command received not
810 * via iscsi_recv_msg().
812 conn
->of_marker
+= ISCSI_HDR_LEN
;
813 if (conn
->of_marker
<= OFMarkInt
) {
814 conn
->of_marker
= (OFMarkInt
- conn
->of_marker
);
816 login_ofmarker_count
= (conn
->of_marker
/ OFMarkInt
);
817 next_marker
= (OFMarkInt
* (login_ofmarker_count
+ 1)) +
818 (login_ofmarker_count
* MARKER_SIZE
);
819 conn
->of_marker
= (next_marker
- conn
->of_marker
);
821 conn
->of_marker_offset
= 0;
822 pr_debug("Setting OFMarker value to %u based on Initial"
823 " Markerless Interval.\n", conn
->of_marker
);
826 if (conn
->conn_ops
->IFMarker
) {
827 if (conn
->if_marker
<= IFMarkInt
) {
828 conn
->if_marker
= (IFMarkInt
- conn
->if_marker
);
830 login_ifmarker_count
= (conn
->if_marker
/ IFMarkInt
);
831 next_marker
= (IFMarkInt
* (login_ifmarker_count
+ 1)) +
832 (login_ifmarker_count
* MARKER_SIZE
);
833 conn
->if_marker
= (next_marker
- conn
->if_marker
);
835 pr_debug("Setting IFMarker value to %u based on Initial"
836 " Markerless Interval.\n", conn
->if_marker
);
842 struct iscsi_conn
*iscsit_get_conn_from_cid(struct iscsi_session
*sess
, u16 cid
)
844 struct iscsi_conn
*conn
;
846 spin_lock_bh(&sess
->conn_lock
);
847 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
848 if ((conn
->cid
== cid
) &&
849 (conn
->conn_state
== TARG_CONN_STATE_LOGGED_IN
)) {
850 iscsit_inc_conn_usage_count(conn
);
851 spin_unlock_bh(&sess
->conn_lock
);
855 spin_unlock_bh(&sess
->conn_lock
);
860 struct iscsi_conn
*iscsit_get_conn_from_cid_rcfr(struct iscsi_session
*sess
, u16 cid
)
862 struct iscsi_conn
*conn
;
864 spin_lock_bh(&sess
->conn_lock
);
865 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
866 if (conn
->cid
== cid
) {
867 iscsit_inc_conn_usage_count(conn
);
868 spin_lock(&conn
->state_lock
);
869 atomic_set(&conn
->connection_wait_rcfr
, 1);
870 spin_unlock(&conn
->state_lock
);
871 spin_unlock_bh(&sess
->conn_lock
);
875 spin_unlock_bh(&sess
->conn_lock
);
880 void iscsit_check_conn_usage_count(struct iscsi_conn
*conn
)
882 spin_lock_bh(&conn
->conn_usage_lock
);
883 if (conn
->conn_usage_count
!= 0) {
884 conn
->conn_waiting_on_uc
= 1;
885 spin_unlock_bh(&conn
->conn_usage_lock
);
887 wait_for_completion(&conn
->conn_waiting_on_uc_comp
);
890 spin_unlock_bh(&conn
->conn_usage_lock
);
893 void iscsit_dec_conn_usage_count(struct iscsi_conn
*conn
)
895 spin_lock_bh(&conn
->conn_usage_lock
);
896 conn
->conn_usage_count
--;
898 if (!conn
->conn_usage_count
&& conn
->conn_waiting_on_uc
)
899 complete(&conn
->conn_waiting_on_uc_comp
);
901 spin_unlock_bh(&conn
->conn_usage_lock
);
904 void iscsit_inc_conn_usage_count(struct iscsi_conn
*conn
)
906 spin_lock_bh(&conn
->conn_usage_lock
);
907 conn
->conn_usage_count
++;
908 spin_unlock_bh(&conn
->conn_usage_lock
);
911 static int iscsit_add_nopin(struct iscsi_conn
*conn
, int want_response
)
914 struct iscsi_cmd
*cmd
;
916 cmd
= iscsit_allocate_cmd(conn
, GFP_ATOMIC
);
920 cmd
->iscsi_opcode
= ISCSI_OP_NOOP_IN
;
921 state
= (want_response
) ? ISTATE_SEND_NOPIN_WANT_RESPONSE
:
922 ISTATE_SEND_NOPIN_NO_RESPONSE
;
923 cmd
->init_task_tag
= RESERVED_ITT
;
924 spin_lock_bh(&conn
->sess
->ttt_lock
);
925 cmd
->targ_xfer_tag
= (want_response
) ? conn
->sess
->targ_xfer_tag
++ :
927 if (want_response
&& (cmd
->targ_xfer_tag
== 0xFFFFFFFF))
928 cmd
->targ_xfer_tag
= conn
->sess
->targ_xfer_tag
++;
929 spin_unlock_bh(&conn
->sess
->ttt_lock
);
931 spin_lock_bh(&conn
->cmd_lock
);
932 list_add_tail(&cmd
->i_conn_node
, &conn
->conn_cmd_list
);
933 spin_unlock_bh(&conn
->cmd_lock
);
936 iscsit_start_nopin_response_timer(conn
);
937 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, state
);
942 static void iscsit_handle_nopin_response_timeout(unsigned long data
)
944 struct iscsi_conn
*conn
= (struct iscsi_conn
*) data
;
946 iscsit_inc_conn_usage_count(conn
);
948 spin_lock_bh(&conn
->nopin_timer_lock
);
949 if (conn
->nopin_response_timer_flags
& ISCSI_TF_STOP
) {
950 spin_unlock_bh(&conn
->nopin_timer_lock
);
951 iscsit_dec_conn_usage_count(conn
);
955 pr_debug("Did not receive response to NOPIN on CID: %hu on"
956 " SID: %u, failing connection.\n", conn
->cid
,
958 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_RUNNING
;
959 spin_unlock_bh(&conn
->nopin_timer_lock
);
962 struct iscsi_portal_group
*tpg
= conn
->sess
->tpg
;
963 struct iscsi_tiqn
*tiqn
= tpg
->tpg_tiqn
;
966 spin_lock_bh(&tiqn
->sess_err_stats
.lock
);
967 strcpy(tiqn
->sess_err_stats
.last_sess_fail_rem_name
,
968 conn
->sess
->sess_ops
->InitiatorName
);
969 tiqn
->sess_err_stats
.last_sess_failure_type
=
970 ISCSI_SESS_ERR_CXN_TIMEOUT
;
971 tiqn
->sess_err_stats
.cxn_timeout_errors
++;
972 conn
->sess
->conn_timeout_errors
++;
973 spin_unlock_bh(&tiqn
->sess_err_stats
.lock
);
977 iscsit_cause_connection_reinstatement(conn
, 0);
978 iscsit_dec_conn_usage_count(conn
);
981 void iscsit_mod_nopin_response_timer(struct iscsi_conn
*conn
)
983 struct iscsi_session
*sess
= conn
->sess
;
984 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
986 spin_lock_bh(&conn
->nopin_timer_lock
);
987 if (!(conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
)) {
988 spin_unlock_bh(&conn
->nopin_timer_lock
);
992 mod_timer(&conn
->nopin_response_timer
,
993 (get_jiffies_64() + na
->nopin_response_timeout
* HZ
));
994 spin_unlock_bh(&conn
->nopin_timer_lock
);
998 * Called with conn->nopin_timer_lock held.
1000 void iscsit_start_nopin_response_timer(struct iscsi_conn
*conn
)
1002 struct iscsi_session
*sess
= conn
->sess
;
1003 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1005 spin_lock_bh(&conn
->nopin_timer_lock
);
1006 if (conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
) {
1007 spin_unlock_bh(&conn
->nopin_timer_lock
);
1011 init_timer(&conn
->nopin_response_timer
);
1012 conn
->nopin_response_timer
.expires
=
1013 (get_jiffies_64() + na
->nopin_response_timeout
* HZ
);
1014 conn
->nopin_response_timer
.data
= (unsigned long)conn
;
1015 conn
->nopin_response_timer
.function
= iscsit_handle_nopin_response_timeout
;
1016 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_STOP
;
1017 conn
->nopin_response_timer_flags
|= ISCSI_TF_RUNNING
;
1018 add_timer(&conn
->nopin_response_timer
);
1020 pr_debug("Started NOPIN Response Timer on CID: %d to %u"
1021 " seconds\n", conn
->cid
, na
->nopin_response_timeout
);
1022 spin_unlock_bh(&conn
->nopin_timer_lock
);
1025 void iscsit_stop_nopin_response_timer(struct iscsi_conn
*conn
)
1027 spin_lock_bh(&conn
->nopin_timer_lock
);
1028 if (!(conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
)) {
1029 spin_unlock_bh(&conn
->nopin_timer_lock
);
1032 conn
->nopin_response_timer_flags
|= ISCSI_TF_STOP
;
1033 spin_unlock_bh(&conn
->nopin_timer_lock
);
1035 del_timer_sync(&conn
->nopin_response_timer
);
1037 spin_lock_bh(&conn
->nopin_timer_lock
);
1038 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_RUNNING
;
1039 spin_unlock_bh(&conn
->nopin_timer_lock
);
1042 static void iscsit_handle_nopin_timeout(unsigned long data
)
1044 struct iscsi_conn
*conn
= (struct iscsi_conn
*) data
;
1046 iscsit_inc_conn_usage_count(conn
);
1048 spin_lock_bh(&conn
->nopin_timer_lock
);
1049 if (conn
->nopin_timer_flags
& ISCSI_TF_STOP
) {
1050 spin_unlock_bh(&conn
->nopin_timer_lock
);
1051 iscsit_dec_conn_usage_count(conn
);
1054 conn
->nopin_timer_flags
&= ~ISCSI_TF_RUNNING
;
1055 spin_unlock_bh(&conn
->nopin_timer_lock
);
1057 iscsit_add_nopin(conn
, 1);
1058 iscsit_dec_conn_usage_count(conn
);
1062 * Called with conn->nopin_timer_lock held.
1064 void __iscsit_start_nopin_timer(struct iscsi_conn
*conn
)
1066 struct iscsi_session
*sess
= conn
->sess
;
1067 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1069 * NOPIN timeout is disabled.
1071 if (!na
->nopin_timeout
)
1074 if (conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
)
1077 init_timer(&conn
->nopin_timer
);
1078 conn
->nopin_timer
.expires
= (get_jiffies_64() + na
->nopin_timeout
* HZ
);
1079 conn
->nopin_timer
.data
= (unsigned long)conn
;
1080 conn
->nopin_timer
.function
= iscsit_handle_nopin_timeout
;
1081 conn
->nopin_timer_flags
&= ~ISCSI_TF_STOP
;
1082 conn
->nopin_timer_flags
|= ISCSI_TF_RUNNING
;
1083 add_timer(&conn
->nopin_timer
);
1085 pr_debug("Started NOPIN Timer on CID: %d at %u second"
1086 " interval\n", conn
->cid
, na
->nopin_timeout
);
1089 void iscsit_start_nopin_timer(struct iscsi_conn
*conn
)
1091 struct iscsi_session
*sess
= conn
->sess
;
1092 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1094 * NOPIN timeout is disabled..
1096 if (!na
->nopin_timeout
)
1099 spin_lock_bh(&conn
->nopin_timer_lock
);
1100 if (conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
) {
1101 spin_unlock_bh(&conn
->nopin_timer_lock
);
1105 init_timer(&conn
->nopin_timer
);
1106 conn
->nopin_timer
.expires
= (get_jiffies_64() + na
->nopin_timeout
* HZ
);
1107 conn
->nopin_timer
.data
= (unsigned long)conn
;
1108 conn
->nopin_timer
.function
= iscsit_handle_nopin_timeout
;
1109 conn
->nopin_timer_flags
&= ~ISCSI_TF_STOP
;
1110 conn
->nopin_timer_flags
|= ISCSI_TF_RUNNING
;
1111 add_timer(&conn
->nopin_timer
);
1113 pr_debug("Started NOPIN Timer on CID: %d at %u second"
1114 " interval\n", conn
->cid
, na
->nopin_timeout
);
1115 spin_unlock_bh(&conn
->nopin_timer_lock
);
1118 void iscsit_stop_nopin_timer(struct iscsi_conn
*conn
)
1120 spin_lock_bh(&conn
->nopin_timer_lock
);
1121 if (!(conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
)) {
1122 spin_unlock_bh(&conn
->nopin_timer_lock
);
1125 conn
->nopin_timer_flags
|= ISCSI_TF_STOP
;
1126 spin_unlock_bh(&conn
->nopin_timer_lock
);
1128 del_timer_sync(&conn
->nopin_timer
);
1130 spin_lock_bh(&conn
->nopin_timer_lock
);
1131 conn
->nopin_timer_flags
&= ~ISCSI_TF_RUNNING
;
1132 spin_unlock_bh(&conn
->nopin_timer_lock
);
1135 int iscsit_send_tx_data(
1136 struct iscsi_cmd
*cmd
,
1137 struct iscsi_conn
*conn
,
1140 int tx_sent
, tx_size
;
1145 tx_size
= cmd
->tx_size
;
1148 iov
= &cmd
->iov_data
[0];
1149 iov_count
= cmd
->iov_data_count
;
1151 iov
= &cmd
->iov_misc
[0];
1152 iov_count
= cmd
->iov_misc_count
;
1155 tx_sent
= tx_data(conn
, &iov
[0], iov_count
, tx_size
);
1156 if (tx_size
!= tx_sent
) {
1157 if (tx_sent
== -EAGAIN
) {
1158 pr_err("tx_data() returned -EAGAIN\n");
1168 int iscsit_fe_sendpage_sg(
1169 struct iscsi_cmd
*cmd
,
1170 struct iscsi_conn
*conn
)
1172 struct scatterlist
*sg
= cmd
->first_data_sg
;
1174 u32 tx_hdr_size
, data_len
;
1175 u32 offset
= cmd
->first_data_sg_off
;
1176 int tx_sent
, iov_off
;
1179 tx_hdr_size
= ISCSI_HDR_LEN
;
1180 if (conn
->conn_ops
->HeaderDigest
)
1181 tx_hdr_size
+= ISCSI_CRC_LEN
;
1183 iov
.iov_base
= cmd
->pdu
;
1184 iov
.iov_len
= tx_hdr_size
;
1186 tx_sent
= tx_data(conn
, &iov
, 1, tx_hdr_size
);
1187 if (tx_hdr_size
!= tx_sent
) {
1188 if (tx_sent
== -EAGAIN
) {
1189 pr_err("tx_data() returned -EAGAIN\n");
1195 data_len
= cmd
->tx_size
- tx_hdr_size
- cmd
->padding
;
1197 * Set iov_off used by padding and data digest tx_data() calls below
1198 * in order to determine proper offset into cmd->iov_data[]
1200 if (conn
->conn_ops
->DataDigest
) {
1201 data_len
-= ISCSI_CRC_LEN
;
1203 iov_off
= (cmd
->iov_data_count
- 2);
1205 iov_off
= (cmd
->iov_data_count
- 1);
1207 iov_off
= (cmd
->iov_data_count
- 1);
1210 * Perform sendpage() for each page in the scatterlist
1213 u32 space
= (sg
->length
- offset
);
1214 u32 sub_len
= min_t(u32
, data_len
, space
);
1216 tx_sent
= conn
->sock
->ops
->sendpage(conn
->sock
,
1217 sg_page(sg
), sg
->offset
+ offset
, sub_len
, 0);
1218 if (tx_sent
!= sub_len
) {
1219 if (tx_sent
== -EAGAIN
) {
1220 pr_err("tcp_sendpage() returned"
1225 pr_err("tcp_sendpage() failure: %d\n",
1230 data_len
-= sub_len
;
1237 struct kvec
*iov_p
= &cmd
->iov_data
[iov_off
++];
1239 tx_sent
= tx_data(conn
, iov_p
, 1, cmd
->padding
);
1240 if (cmd
->padding
!= tx_sent
) {
1241 if (tx_sent
== -EAGAIN
) {
1242 pr_err("tx_data() returned -EAGAIN\n");
1250 if (conn
->conn_ops
->DataDigest
) {
1251 struct kvec
*iov_d
= &cmd
->iov_data
[iov_off
];
1253 tx_sent
= tx_data(conn
, iov_d
, 1, ISCSI_CRC_LEN
);
1254 if (ISCSI_CRC_LEN
!= tx_sent
) {
1255 if (tx_sent
== -EAGAIN
) {
1256 pr_err("tx_data() returned -EAGAIN\n");
1267 * This function is used for mainly sending a ISCSI_TARG_LOGIN_RSP PDU
1268 * back to the Initiator when an expection condition occurs with the
1269 * errors set in status_class and status_detail.
1271 * Parameters: iSCSI Connection, Status Class, Status Detail.
1272 * Returns: 0 on success, -1 on error.
1274 int iscsit_tx_login_rsp(struct iscsi_conn
*conn
, u8 status_class
, u8 status_detail
)
1276 struct iscsi_login_rsp
*hdr
;
1277 struct iscsi_login
*login
= conn
->conn_login
;
1279 login
->login_failed
= 1;
1280 iscsit_collect_login_stats(conn
, status_class
, status_detail
);
1282 hdr
= (struct iscsi_login_rsp
*)&login
->rsp
[0];
1283 hdr
->opcode
= ISCSI_OP_LOGIN_RSP
;
1284 hdr
->status_class
= status_class
;
1285 hdr
->status_detail
= status_detail
;
1286 hdr
->itt
= conn
->login_itt
;
1288 return conn
->conn_transport
->iscsit_put_login_tx(conn
, login
, 0);
1291 void iscsit_print_session_params(struct iscsi_session
*sess
)
1293 struct iscsi_conn
*conn
;
1295 pr_debug("-----------------------------[Session Params for"
1296 " SID: %u]-----------------------------\n", sess
->sid
);
1297 spin_lock_bh(&sess
->conn_lock
);
1298 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
)
1299 iscsi_dump_conn_ops(conn
->conn_ops
);
1300 spin_unlock_bh(&sess
->conn_lock
);
1302 iscsi_dump_sess_ops(sess
->sess_ops
);
1305 static int iscsit_do_rx_data(
1306 struct iscsi_conn
*conn
,
1307 struct iscsi_data_count
*count
)
1309 int data
= count
->data_length
, rx_loop
= 0, total_rx
= 0, iov_len
;
1313 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1316 memset(&msg
, 0, sizeof(struct msghdr
));
1319 iov_len
= count
->iov_count
;
1321 while (total_rx
< data
) {
1322 rx_loop
= kernel_recvmsg(conn
->sock
, &msg
, iov_p
, iov_len
,
1323 (data
- total_rx
), MSG_WAITALL
);
1325 pr_debug("rx_loop: %d total_rx: %d\n",
1329 total_rx
+= rx_loop
;
1330 pr_debug("rx_loop: %d, total_rx: %d, data: %d\n",
1331 rx_loop
, total_rx
, data
);
1337 static int iscsit_do_tx_data(
1338 struct iscsi_conn
*conn
,
1339 struct iscsi_data_count
*count
)
1341 int data
= count
->data_length
, total_tx
= 0, tx_loop
= 0, iov_len
;
1345 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1349 pr_err("Data length is: %d\n", data
);
1353 memset(&msg
, 0, sizeof(struct msghdr
));
1356 iov_len
= count
->iov_count
;
1358 while (total_tx
< data
) {
1359 tx_loop
= kernel_sendmsg(conn
->sock
, &msg
, iov_p
, iov_len
,
1362 pr_debug("tx_loop: %d total_tx %d\n",
1366 total_tx
+= tx_loop
;
1367 pr_debug("tx_loop: %d, total_tx: %d, data: %d\n",
1368 tx_loop
, total_tx
, data
);
1375 struct iscsi_conn
*conn
,
1380 struct iscsi_data_count c
;
1382 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1385 memset(&c
, 0, sizeof(struct iscsi_data_count
));
1387 c
.iov_count
= iov_count
;
1388 c
.data_length
= data
;
1389 c
.type
= ISCSI_RX_DATA
;
1391 return iscsit_do_rx_data(conn
, &c
);
1395 struct iscsi_conn
*conn
,
1400 struct iscsi_data_count c
;
1402 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1405 memset(&c
, 0, sizeof(struct iscsi_data_count
));
1407 c
.iov_count
= iov_count
;
1408 c
.data_length
= data
;
1409 c
.type
= ISCSI_TX_DATA
;
1411 return iscsit_do_tx_data(conn
, &c
);
1414 void iscsit_collect_login_stats(
1415 struct iscsi_conn
*conn
,
1419 struct iscsi_param
*intrname
= NULL
;
1420 struct iscsi_tiqn
*tiqn
;
1421 struct iscsi_login_stats
*ls
;
1423 tiqn
= iscsit_snmp_get_tiqn(conn
);
1427 ls
= &tiqn
->login_stats
;
1429 spin_lock(&ls
->lock
);
1430 if (!strcmp(conn
->login_ip
, ls
->last_intr_fail_ip_addr
) &&
1431 ((get_jiffies_64() - ls
->last_fail_time
) < 10)) {
1432 /* We already have the failure info for this login */
1433 spin_unlock(&ls
->lock
);
1437 if (status_class
== ISCSI_STATUS_CLS_SUCCESS
)
1439 else if (status_class
== ISCSI_STATUS_CLS_REDIRECT
) {
1441 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_REDIRECT
;
1442 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1443 (status_detail
== ISCSI_LOGIN_STATUS_AUTH_FAILED
)) {
1444 ls
->authenticate_fails
++;
1445 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_AUTHENTICATE
;
1446 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1447 (status_detail
== ISCSI_LOGIN_STATUS_TGT_FORBIDDEN
)) {
1448 ls
->authorize_fails
++;
1449 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_AUTHORIZE
;
1450 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1451 (status_detail
== ISCSI_LOGIN_STATUS_INIT_ERR
)) {
1452 ls
->negotiate_fails
++;
1453 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_NEGOTIATE
;
1456 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_OTHER
;
1459 /* Save initiator name, ip address and time, if it is a failed login */
1460 if (status_class
!= ISCSI_STATUS_CLS_SUCCESS
) {
1461 if (conn
->param_list
)
1462 intrname
= iscsi_find_param_from_key(INITIATORNAME
,
1464 strcpy(ls
->last_intr_fail_name
,
1465 (intrname
? intrname
->value
: "Unknown"));
1467 ls
->last_intr_fail_ip_family
= conn
->login_family
;
1469 snprintf(ls
->last_intr_fail_ip_addr
, IPV6_ADDRESS_SPACE
,
1470 "%s", conn
->login_ip
);
1471 ls
->last_fail_time
= get_jiffies_64();
1474 spin_unlock(&ls
->lock
);
1477 struct iscsi_tiqn
*iscsit_snmp_get_tiqn(struct iscsi_conn
*conn
)
1479 struct iscsi_portal_group
*tpg
;
1481 if (!conn
|| !conn
->sess
)
1484 tpg
= conn
->sess
->tpg
;
1491 return tpg
->tpg_tiqn
;