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
);
152 struct iscsi_cmd
*iscsit_alloc_cmd(struct iscsi_conn
*conn
, gfp_t gfp_mask
)
154 struct iscsi_cmd
*cmd
;
156 cmd
= kmem_cache_zalloc(lio_cmd_cache
, gfp_mask
);
160 cmd
->release_cmd
= &iscsit_release_cmd
;
165 * May be called from software interrupt (timer) context for allocating
168 struct iscsi_cmd
*iscsit_allocate_cmd(struct iscsi_conn
*conn
, gfp_t gfp_mask
)
170 struct iscsi_cmd
*cmd
;
172 cmd
= conn
->conn_transport
->iscsit_alloc_cmd(conn
, gfp_mask
);
174 pr_err("Unable to allocate memory for struct iscsi_cmd.\n");
178 INIT_LIST_HEAD(&cmd
->i_conn_node
);
179 INIT_LIST_HEAD(&cmd
->datain_list
);
180 INIT_LIST_HEAD(&cmd
->cmd_r2t_list
);
181 spin_lock_init(&cmd
->datain_lock
);
182 spin_lock_init(&cmd
->dataout_timeout_lock
);
183 spin_lock_init(&cmd
->istate_lock
);
184 spin_lock_init(&cmd
->error_lock
);
185 spin_lock_init(&cmd
->r2t_lock
);
189 EXPORT_SYMBOL(iscsit_allocate_cmd
);
191 struct iscsi_seq
*iscsit_get_seq_holder_for_datain(
192 struct iscsi_cmd
*cmd
,
197 for (i
= 0; i
< cmd
->seq_count
; i
++)
198 if (cmd
->seq_list
[i
].seq_send_order
== seq_send_order
)
199 return &cmd
->seq_list
[i
];
204 struct iscsi_seq
*iscsit_get_seq_holder_for_r2t(struct iscsi_cmd
*cmd
)
208 if (!cmd
->seq_list
) {
209 pr_err("struct iscsi_cmd->seq_list is NULL!\n");
213 for (i
= 0; i
< cmd
->seq_count
; i
++) {
214 if (cmd
->seq_list
[i
].type
!= SEQTYPE_NORMAL
)
216 if (cmd
->seq_list
[i
].seq_send_order
== cmd
->seq_send_order
) {
217 cmd
->seq_send_order
++;
218 return &cmd
->seq_list
[i
];
225 struct iscsi_r2t
*iscsit_get_holder_for_r2tsn(
226 struct iscsi_cmd
*cmd
,
229 struct iscsi_r2t
*r2t
;
231 spin_lock_bh(&cmd
->r2t_lock
);
232 list_for_each_entry(r2t
, &cmd
->cmd_r2t_list
, r2t_list
) {
233 if (r2t
->r2t_sn
== r2t_sn
) {
234 spin_unlock_bh(&cmd
->r2t_lock
);
238 spin_unlock_bh(&cmd
->r2t_lock
);
243 static inline int iscsit_check_received_cmdsn(struct iscsi_session
*sess
, u32 cmdsn
)
248 * This is the proper method of checking received CmdSN against
249 * ExpCmdSN and MaxCmdSN values, as well as accounting for out
250 * or order CmdSNs due to multiple connection sessions and/or
253 if (iscsi_sna_gt(cmdsn
, sess
->max_cmd_sn
)) {
254 pr_err("Received CmdSN: 0x%08x is greater than"
255 " MaxCmdSN: 0x%08x, protocol error.\n", cmdsn
,
257 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
259 } else if (cmdsn
== sess
->exp_cmd_sn
) {
261 pr_debug("Received CmdSN matches ExpCmdSN,"
262 " incremented ExpCmdSN to: 0x%08x\n",
264 ret
= CMDSN_NORMAL_OPERATION
;
266 } else if (iscsi_sna_gt(cmdsn
, sess
->exp_cmd_sn
)) {
267 pr_debug("Received CmdSN: 0x%08x is greater"
268 " than ExpCmdSN: 0x%08x, not acknowledging.\n",
269 cmdsn
, sess
->exp_cmd_sn
);
270 ret
= CMDSN_HIGHER_THAN_EXP
;
273 pr_err("Received CmdSN: 0x%08x is less than"
274 " ExpCmdSN: 0x%08x, ignoring.\n", cmdsn
,
276 ret
= CMDSN_LOWER_THAN_EXP
;
283 * Commands may be received out of order if MC/S is in use.
284 * Ensure they are executed in CmdSN order.
286 int iscsit_sequence_cmd(struct iscsi_conn
*conn
, struct iscsi_cmd
*cmd
,
287 unsigned char *buf
, __be32 cmdsn
)
291 u8 reason
= ISCSI_REASON_BOOKMARK_NO_RESOURCES
;
293 mutex_lock(&conn
->sess
->cmdsn_mutex
);
295 cmdsn_ret
= iscsit_check_received_cmdsn(conn
->sess
, be32_to_cpu(cmdsn
));
297 case CMDSN_NORMAL_OPERATION
:
298 ret
= iscsit_execute_cmd(cmd
, 0);
299 if ((ret
>= 0) && !list_empty(&conn
->sess
->sess_ooo_cmdsn_list
))
300 iscsit_execute_ooo_cmdsns(conn
->sess
);
303 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
306 case CMDSN_HIGHER_THAN_EXP
:
307 ret
= iscsit_handle_ooo_cmdsn(conn
->sess
, cmd
, be32_to_cpu(cmdsn
));
310 ret
= CMDSN_ERROR_CANNOT_RECOVER
;
313 ret
= CMDSN_HIGHER_THAN_EXP
;
315 case CMDSN_LOWER_THAN_EXP
:
316 cmd
->i_state
= ISTATE_REMOVE
;
317 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, cmd
->i_state
);
321 reason
= ISCSI_REASON_PROTOCOL_ERROR
;
326 mutex_unlock(&conn
->sess
->cmdsn_mutex
);
329 iscsit_reject_cmd(cmd
, reason
, buf
);
333 EXPORT_SYMBOL(iscsit_sequence_cmd
);
335 int iscsit_check_unsolicited_dataout(struct iscsi_cmd
*cmd
, unsigned char *buf
)
337 struct iscsi_conn
*conn
= cmd
->conn
;
338 struct se_cmd
*se_cmd
= &cmd
->se_cmd
;
339 struct iscsi_data
*hdr
= (struct iscsi_data
*) buf
;
340 u32 payload_length
= ntoh24(hdr
->dlength
);
342 if (conn
->sess
->sess_ops
->InitialR2T
) {
343 pr_err("Received unexpected unsolicited data"
344 " while InitialR2T=Yes, protocol error.\n");
345 transport_send_check_condition_and_sense(se_cmd
,
346 TCM_UNEXPECTED_UNSOLICITED_DATA
, 0);
350 if ((cmd
->first_burst_len
+ payload_length
) >
351 conn
->sess
->sess_ops
->FirstBurstLength
) {
352 pr_err("Total %u bytes exceeds FirstBurstLength: %u"
353 " for this Unsolicited DataOut Burst.\n",
354 (cmd
->first_burst_len
+ payload_length
),
355 conn
->sess
->sess_ops
->FirstBurstLength
);
356 transport_send_check_condition_and_sense(se_cmd
,
357 TCM_INCORRECT_AMOUNT_OF_DATA
, 0);
361 if (!(hdr
->flags
& ISCSI_FLAG_CMD_FINAL
))
364 if (((cmd
->first_burst_len
+ payload_length
) != cmd
->se_cmd
.data_length
) &&
365 ((cmd
->first_burst_len
+ payload_length
) !=
366 conn
->sess
->sess_ops
->FirstBurstLength
)) {
367 pr_err("Unsolicited non-immediate data received %u"
368 " does not equal FirstBurstLength: %u, and does"
369 " not equal ExpXferLen %u.\n",
370 (cmd
->first_burst_len
+ payload_length
),
371 conn
->sess
->sess_ops
->FirstBurstLength
, cmd
->se_cmd
.data_length
);
372 transport_send_check_condition_and_sense(se_cmd
,
373 TCM_INCORRECT_AMOUNT_OF_DATA
, 0);
379 struct iscsi_cmd
*iscsit_find_cmd_from_itt(
380 struct iscsi_conn
*conn
,
383 struct iscsi_cmd
*cmd
;
385 spin_lock_bh(&conn
->cmd_lock
);
386 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
387 if (cmd
->init_task_tag
== init_task_tag
) {
388 spin_unlock_bh(&conn
->cmd_lock
);
392 spin_unlock_bh(&conn
->cmd_lock
);
394 pr_err("Unable to locate ITT: 0x%08x on CID: %hu",
395 init_task_tag
, conn
->cid
);
399 struct iscsi_cmd
*iscsit_find_cmd_from_itt_or_dump(
400 struct iscsi_conn
*conn
,
404 struct iscsi_cmd
*cmd
;
406 spin_lock_bh(&conn
->cmd_lock
);
407 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
408 if (cmd
->init_task_tag
== init_task_tag
) {
409 spin_unlock_bh(&conn
->cmd_lock
);
413 spin_unlock_bh(&conn
->cmd_lock
);
415 pr_err("Unable to locate ITT: 0x%08x on CID: %hu,"
416 " dumping payload\n", init_task_tag
, conn
->cid
);
418 iscsit_dump_data_payload(conn
, length
, 1);
423 struct iscsi_cmd
*iscsit_find_cmd_from_ttt(
424 struct iscsi_conn
*conn
,
427 struct iscsi_cmd
*cmd
= NULL
;
429 spin_lock_bh(&conn
->cmd_lock
);
430 list_for_each_entry(cmd
, &conn
->conn_cmd_list
, i_conn_node
) {
431 if (cmd
->targ_xfer_tag
== targ_xfer_tag
) {
432 spin_unlock_bh(&conn
->cmd_lock
);
436 spin_unlock_bh(&conn
->cmd_lock
);
438 pr_err("Unable to locate TTT: 0x%08x on CID: %hu\n",
439 targ_xfer_tag
, conn
->cid
);
443 int iscsit_find_cmd_for_recovery(
444 struct iscsi_session
*sess
,
445 struct iscsi_cmd
**cmd_ptr
,
446 struct iscsi_conn_recovery
**cr_ptr
,
449 struct iscsi_cmd
*cmd
= NULL
;
450 struct iscsi_conn_recovery
*cr
;
452 * Scan through the inactive connection recovery list's command list.
453 * If init_task_tag matches the command is still alligent.
455 spin_lock(&sess
->cr_i_lock
);
456 list_for_each_entry(cr
, &sess
->cr_inactive_list
, cr_list
) {
457 spin_lock(&cr
->conn_recovery_cmd_lock
);
458 list_for_each_entry(cmd
, &cr
->conn_recovery_cmd_list
, i_conn_node
) {
459 if (cmd
->init_task_tag
== init_task_tag
) {
460 spin_unlock(&cr
->conn_recovery_cmd_lock
);
461 spin_unlock(&sess
->cr_i_lock
);
468 spin_unlock(&cr
->conn_recovery_cmd_lock
);
470 spin_unlock(&sess
->cr_i_lock
);
472 * Scan through the active connection recovery list's command list.
473 * If init_task_tag matches the command is ready to be reassigned.
475 spin_lock(&sess
->cr_a_lock
);
476 list_for_each_entry(cr
, &sess
->cr_active_list
, cr_list
) {
477 spin_lock(&cr
->conn_recovery_cmd_lock
);
478 list_for_each_entry(cmd
, &cr
->conn_recovery_cmd_list
, i_conn_node
) {
479 if (cmd
->init_task_tag
== init_task_tag
) {
480 spin_unlock(&cr
->conn_recovery_cmd_lock
);
481 spin_unlock(&sess
->cr_a_lock
);
488 spin_unlock(&cr
->conn_recovery_cmd_lock
);
490 spin_unlock(&sess
->cr_a_lock
);
495 void iscsit_add_cmd_to_immediate_queue(
496 struct iscsi_cmd
*cmd
,
497 struct iscsi_conn
*conn
,
500 struct iscsi_queue_req
*qr
;
502 qr
= kmem_cache_zalloc(lio_qr_cache
, GFP_ATOMIC
);
504 pr_err("Unable to allocate memory for"
505 " struct iscsi_queue_req\n");
508 INIT_LIST_HEAD(&qr
->qr_list
);
512 spin_lock_bh(&conn
->immed_queue_lock
);
513 list_add_tail(&qr
->qr_list
, &conn
->immed_queue_list
);
514 atomic_inc(&cmd
->immed_queue_count
);
515 atomic_set(&conn
->check_immediate_queue
, 1);
516 spin_unlock_bh(&conn
->immed_queue_lock
);
518 wake_up(&conn
->queues_wq
);
521 struct iscsi_queue_req
*iscsit_get_cmd_from_immediate_queue(struct iscsi_conn
*conn
)
523 struct iscsi_queue_req
*qr
;
525 spin_lock_bh(&conn
->immed_queue_lock
);
526 if (list_empty(&conn
->immed_queue_list
)) {
527 spin_unlock_bh(&conn
->immed_queue_lock
);
530 qr
= list_first_entry(&conn
->immed_queue_list
,
531 struct iscsi_queue_req
, qr_list
);
533 list_del(&qr
->qr_list
);
535 atomic_dec(&qr
->cmd
->immed_queue_count
);
536 spin_unlock_bh(&conn
->immed_queue_lock
);
541 static void iscsit_remove_cmd_from_immediate_queue(
542 struct iscsi_cmd
*cmd
,
543 struct iscsi_conn
*conn
)
545 struct iscsi_queue_req
*qr
, *qr_tmp
;
547 spin_lock_bh(&conn
->immed_queue_lock
);
548 if (!atomic_read(&cmd
->immed_queue_count
)) {
549 spin_unlock_bh(&conn
->immed_queue_lock
);
553 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->immed_queue_list
, qr_list
) {
557 atomic_dec(&qr
->cmd
->immed_queue_count
);
558 list_del(&qr
->qr_list
);
559 kmem_cache_free(lio_qr_cache
, qr
);
561 spin_unlock_bh(&conn
->immed_queue_lock
);
563 if (atomic_read(&cmd
->immed_queue_count
)) {
564 pr_err("ITT: 0x%08x immed_queue_count: %d\n",
566 atomic_read(&cmd
->immed_queue_count
));
570 void iscsit_add_cmd_to_response_queue(
571 struct iscsi_cmd
*cmd
,
572 struct iscsi_conn
*conn
,
575 struct iscsi_queue_req
*qr
;
577 qr
= kmem_cache_zalloc(lio_qr_cache
, GFP_ATOMIC
);
579 pr_err("Unable to allocate memory for"
580 " struct iscsi_queue_req\n");
583 INIT_LIST_HEAD(&qr
->qr_list
);
587 spin_lock_bh(&conn
->response_queue_lock
);
588 list_add_tail(&qr
->qr_list
, &conn
->response_queue_list
);
589 atomic_inc(&cmd
->response_queue_count
);
590 spin_unlock_bh(&conn
->response_queue_lock
);
592 wake_up(&conn
->queues_wq
);
595 struct iscsi_queue_req
*iscsit_get_cmd_from_response_queue(struct iscsi_conn
*conn
)
597 struct iscsi_queue_req
*qr
;
599 spin_lock_bh(&conn
->response_queue_lock
);
600 if (list_empty(&conn
->response_queue_list
)) {
601 spin_unlock_bh(&conn
->response_queue_lock
);
605 qr
= list_first_entry(&conn
->response_queue_list
,
606 struct iscsi_queue_req
, qr_list
);
608 list_del(&qr
->qr_list
);
610 atomic_dec(&qr
->cmd
->response_queue_count
);
611 spin_unlock_bh(&conn
->response_queue_lock
);
616 static void iscsit_remove_cmd_from_response_queue(
617 struct iscsi_cmd
*cmd
,
618 struct iscsi_conn
*conn
)
620 struct iscsi_queue_req
*qr
, *qr_tmp
;
622 spin_lock_bh(&conn
->response_queue_lock
);
623 if (!atomic_read(&cmd
->response_queue_count
)) {
624 spin_unlock_bh(&conn
->response_queue_lock
);
628 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->response_queue_list
,
633 atomic_dec(&qr
->cmd
->response_queue_count
);
634 list_del(&qr
->qr_list
);
635 kmem_cache_free(lio_qr_cache
, qr
);
637 spin_unlock_bh(&conn
->response_queue_lock
);
639 if (atomic_read(&cmd
->response_queue_count
)) {
640 pr_err("ITT: 0x%08x response_queue_count: %d\n",
642 atomic_read(&cmd
->response_queue_count
));
646 bool iscsit_conn_all_queues_empty(struct iscsi_conn
*conn
)
650 spin_lock_bh(&conn
->immed_queue_lock
);
651 empty
= list_empty(&conn
->immed_queue_list
);
652 spin_unlock_bh(&conn
->immed_queue_lock
);
657 spin_lock_bh(&conn
->response_queue_lock
);
658 empty
= list_empty(&conn
->response_queue_list
);
659 spin_unlock_bh(&conn
->response_queue_lock
);
664 void iscsit_free_queue_reqs_for_conn(struct iscsi_conn
*conn
)
666 struct iscsi_queue_req
*qr
, *qr_tmp
;
668 spin_lock_bh(&conn
->immed_queue_lock
);
669 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->immed_queue_list
, qr_list
) {
670 list_del(&qr
->qr_list
);
672 atomic_dec(&qr
->cmd
->immed_queue_count
);
674 kmem_cache_free(lio_qr_cache
, qr
);
676 spin_unlock_bh(&conn
->immed_queue_lock
);
678 spin_lock_bh(&conn
->response_queue_lock
);
679 list_for_each_entry_safe(qr
, qr_tmp
, &conn
->response_queue_list
,
681 list_del(&qr
->qr_list
);
683 atomic_dec(&qr
->cmd
->response_queue_count
);
685 kmem_cache_free(lio_qr_cache
, qr
);
687 spin_unlock_bh(&conn
->response_queue_lock
);
690 void iscsit_release_cmd(struct iscsi_cmd
*cmd
)
693 kfree(cmd
->pdu_list
);
694 kfree(cmd
->seq_list
);
696 kfree(cmd
->iov_data
);
697 kfree(cmd
->text_in_ptr
);
699 kmem_cache_free(lio_cmd_cache
, cmd
);
702 static void __iscsit_free_cmd(struct iscsi_cmd
*cmd
, bool scsi_cmd
,
705 struct iscsi_conn
*conn
= cmd
->conn
;
708 if (cmd
->data_direction
== DMA_TO_DEVICE
) {
709 iscsit_stop_dataout_timer(cmd
);
710 iscsit_free_r2ts_from_list(cmd
);
712 if (cmd
->data_direction
== DMA_FROM_DEVICE
)
713 iscsit_free_all_datain_reqs(cmd
);
716 if (conn
&& check_queues
) {
717 iscsit_remove_cmd_from_immediate_queue(cmd
, conn
);
718 iscsit_remove_cmd_from_response_queue(cmd
, conn
);
722 void iscsit_free_cmd(struct iscsi_cmd
*cmd
, bool shutdown
)
724 struct se_cmd
*se_cmd
= NULL
;
727 * Determine if a struct se_cmd is associated with
728 * this struct iscsi_cmd.
730 switch (cmd
->iscsi_opcode
) {
731 case ISCSI_OP_SCSI_CMD
:
732 se_cmd
= &cmd
->se_cmd
;
733 __iscsit_free_cmd(cmd
, true, shutdown
);
737 case ISCSI_OP_SCSI_TMFUNC
:
738 rc
= transport_generic_free_cmd(&cmd
->se_cmd
, 1);
739 if (!rc
&& shutdown
&& se_cmd
&& se_cmd
->se_sess
) {
740 __iscsit_free_cmd(cmd
, true, shutdown
);
741 target_put_sess_cmd(se_cmd
->se_sess
, se_cmd
);
744 case ISCSI_OP_REJECT
:
746 * Handle special case for REJECT when iscsi_add_reject*() has
747 * overwritten the original iscsi_opcode assignment, and the
748 * associated cmd->se_cmd needs to be released.
750 if (cmd
->se_cmd
.se_tfo
!= NULL
) {
751 se_cmd
= &cmd
->se_cmd
;
752 __iscsit_free_cmd(cmd
, true, shutdown
);
754 rc
= transport_generic_free_cmd(&cmd
->se_cmd
, 1);
755 if (!rc
&& shutdown
&& se_cmd
->se_sess
) {
756 __iscsit_free_cmd(cmd
, true, shutdown
);
757 target_put_sess_cmd(se_cmd
->se_sess
, se_cmd
);
763 __iscsit_free_cmd(cmd
, false, shutdown
);
764 cmd
->release_cmd(cmd
);
769 int iscsit_check_session_usage_count(struct iscsi_session
*sess
)
771 spin_lock_bh(&sess
->session_usage_lock
);
772 if (sess
->session_usage_count
!= 0) {
773 sess
->session_waiting_on_uc
= 1;
774 spin_unlock_bh(&sess
->session_usage_lock
);
778 wait_for_completion(&sess
->session_waiting_on_uc_comp
);
781 spin_unlock_bh(&sess
->session_usage_lock
);
786 void iscsit_dec_session_usage_count(struct iscsi_session
*sess
)
788 spin_lock_bh(&sess
->session_usage_lock
);
789 sess
->session_usage_count
--;
791 if (!sess
->session_usage_count
&& sess
->session_waiting_on_uc
)
792 complete(&sess
->session_waiting_on_uc_comp
);
794 spin_unlock_bh(&sess
->session_usage_lock
);
797 void iscsit_inc_session_usage_count(struct iscsi_session
*sess
)
799 spin_lock_bh(&sess
->session_usage_lock
);
800 sess
->session_usage_count
++;
801 spin_unlock_bh(&sess
->session_usage_lock
);
805 * Setup conn->if_marker and conn->of_marker values based upon
806 * the initial marker-less interval. (see iSCSI v19 A.2)
808 int iscsit_set_sync_and_steering_values(struct iscsi_conn
*conn
)
810 int login_ifmarker_count
= 0, login_ofmarker_count
= 0, next_marker
= 0;
812 * IFMarkInt and OFMarkInt are negotiated as 32-bit words.
814 u32 IFMarkInt
= (conn
->conn_ops
->IFMarkInt
* 4);
815 u32 OFMarkInt
= (conn
->conn_ops
->OFMarkInt
* 4);
817 if (conn
->conn_ops
->OFMarker
) {
819 * Account for the first Login Command received not
820 * via iscsi_recv_msg().
822 conn
->of_marker
+= ISCSI_HDR_LEN
;
823 if (conn
->of_marker
<= OFMarkInt
) {
824 conn
->of_marker
= (OFMarkInt
- conn
->of_marker
);
826 login_ofmarker_count
= (conn
->of_marker
/ OFMarkInt
);
827 next_marker
= (OFMarkInt
* (login_ofmarker_count
+ 1)) +
828 (login_ofmarker_count
* MARKER_SIZE
);
829 conn
->of_marker
= (next_marker
- conn
->of_marker
);
831 conn
->of_marker_offset
= 0;
832 pr_debug("Setting OFMarker value to %u based on Initial"
833 " Markerless Interval.\n", conn
->of_marker
);
836 if (conn
->conn_ops
->IFMarker
) {
837 if (conn
->if_marker
<= IFMarkInt
) {
838 conn
->if_marker
= (IFMarkInt
- conn
->if_marker
);
840 login_ifmarker_count
= (conn
->if_marker
/ IFMarkInt
);
841 next_marker
= (IFMarkInt
* (login_ifmarker_count
+ 1)) +
842 (login_ifmarker_count
* MARKER_SIZE
);
843 conn
->if_marker
= (next_marker
- conn
->if_marker
);
845 pr_debug("Setting IFMarker value to %u based on Initial"
846 " Markerless Interval.\n", conn
->if_marker
);
852 struct iscsi_conn
*iscsit_get_conn_from_cid(struct iscsi_session
*sess
, u16 cid
)
854 struct iscsi_conn
*conn
;
856 spin_lock_bh(&sess
->conn_lock
);
857 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
858 if ((conn
->cid
== cid
) &&
859 (conn
->conn_state
== TARG_CONN_STATE_LOGGED_IN
)) {
860 iscsit_inc_conn_usage_count(conn
);
861 spin_unlock_bh(&sess
->conn_lock
);
865 spin_unlock_bh(&sess
->conn_lock
);
870 struct iscsi_conn
*iscsit_get_conn_from_cid_rcfr(struct iscsi_session
*sess
, u16 cid
)
872 struct iscsi_conn
*conn
;
874 spin_lock_bh(&sess
->conn_lock
);
875 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
876 if (conn
->cid
== cid
) {
877 iscsit_inc_conn_usage_count(conn
);
878 spin_lock(&conn
->state_lock
);
879 atomic_set(&conn
->connection_wait_rcfr
, 1);
880 spin_unlock(&conn
->state_lock
);
881 spin_unlock_bh(&sess
->conn_lock
);
885 spin_unlock_bh(&sess
->conn_lock
);
890 void iscsit_check_conn_usage_count(struct iscsi_conn
*conn
)
892 spin_lock_bh(&conn
->conn_usage_lock
);
893 if (conn
->conn_usage_count
!= 0) {
894 conn
->conn_waiting_on_uc
= 1;
895 spin_unlock_bh(&conn
->conn_usage_lock
);
897 wait_for_completion(&conn
->conn_waiting_on_uc_comp
);
900 spin_unlock_bh(&conn
->conn_usage_lock
);
903 void iscsit_dec_conn_usage_count(struct iscsi_conn
*conn
)
905 spin_lock_bh(&conn
->conn_usage_lock
);
906 conn
->conn_usage_count
--;
908 if (!conn
->conn_usage_count
&& conn
->conn_waiting_on_uc
)
909 complete(&conn
->conn_waiting_on_uc_comp
);
911 spin_unlock_bh(&conn
->conn_usage_lock
);
914 void iscsit_inc_conn_usage_count(struct iscsi_conn
*conn
)
916 spin_lock_bh(&conn
->conn_usage_lock
);
917 conn
->conn_usage_count
++;
918 spin_unlock_bh(&conn
->conn_usage_lock
);
921 static int iscsit_add_nopin(struct iscsi_conn
*conn
, int want_response
)
924 struct iscsi_cmd
*cmd
;
926 cmd
= iscsit_allocate_cmd(conn
, GFP_ATOMIC
);
930 cmd
->iscsi_opcode
= ISCSI_OP_NOOP_IN
;
931 state
= (want_response
) ? ISTATE_SEND_NOPIN_WANT_RESPONSE
:
932 ISTATE_SEND_NOPIN_NO_RESPONSE
;
933 cmd
->init_task_tag
= RESERVED_ITT
;
934 spin_lock_bh(&conn
->sess
->ttt_lock
);
935 cmd
->targ_xfer_tag
= (want_response
) ? conn
->sess
->targ_xfer_tag
++ :
937 if (want_response
&& (cmd
->targ_xfer_tag
== 0xFFFFFFFF))
938 cmd
->targ_xfer_tag
= conn
->sess
->targ_xfer_tag
++;
939 spin_unlock_bh(&conn
->sess
->ttt_lock
);
941 spin_lock_bh(&conn
->cmd_lock
);
942 list_add_tail(&cmd
->i_conn_node
, &conn
->conn_cmd_list
);
943 spin_unlock_bh(&conn
->cmd_lock
);
946 iscsit_start_nopin_response_timer(conn
);
947 iscsit_add_cmd_to_immediate_queue(cmd
, conn
, state
);
952 static void iscsit_handle_nopin_response_timeout(unsigned long data
)
954 struct iscsi_conn
*conn
= (struct iscsi_conn
*) data
;
956 iscsit_inc_conn_usage_count(conn
);
958 spin_lock_bh(&conn
->nopin_timer_lock
);
959 if (conn
->nopin_response_timer_flags
& ISCSI_TF_STOP
) {
960 spin_unlock_bh(&conn
->nopin_timer_lock
);
961 iscsit_dec_conn_usage_count(conn
);
965 pr_debug("Did not receive response to NOPIN on CID: %hu on"
966 " SID: %u, failing connection.\n", conn
->cid
,
968 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_RUNNING
;
969 spin_unlock_bh(&conn
->nopin_timer_lock
);
972 struct iscsi_portal_group
*tpg
= conn
->sess
->tpg
;
973 struct iscsi_tiqn
*tiqn
= tpg
->tpg_tiqn
;
976 spin_lock_bh(&tiqn
->sess_err_stats
.lock
);
977 strcpy(tiqn
->sess_err_stats
.last_sess_fail_rem_name
,
978 conn
->sess
->sess_ops
->InitiatorName
);
979 tiqn
->sess_err_stats
.last_sess_failure_type
=
980 ISCSI_SESS_ERR_CXN_TIMEOUT
;
981 tiqn
->sess_err_stats
.cxn_timeout_errors
++;
982 conn
->sess
->conn_timeout_errors
++;
983 spin_unlock_bh(&tiqn
->sess_err_stats
.lock
);
987 iscsit_cause_connection_reinstatement(conn
, 0);
988 iscsit_dec_conn_usage_count(conn
);
991 void iscsit_mod_nopin_response_timer(struct iscsi_conn
*conn
)
993 struct iscsi_session
*sess
= conn
->sess
;
994 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
996 spin_lock_bh(&conn
->nopin_timer_lock
);
997 if (!(conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
)) {
998 spin_unlock_bh(&conn
->nopin_timer_lock
);
1002 mod_timer(&conn
->nopin_response_timer
,
1003 (get_jiffies_64() + na
->nopin_response_timeout
* HZ
));
1004 spin_unlock_bh(&conn
->nopin_timer_lock
);
1008 * Called with conn->nopin_timer_lock held.
1010 void iscsit_start_nopin_response_timer(struct iscsi_conn
*conn
)
1012 struct iscsi_session
*sess
= conn
->sess
;
1013 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1015 spin_lock_bh(&conn
->nopin_timer_lock
);
1016 if (conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
) {
1017 spin_unlock_bh(&conn
->nopin_timer_lock
);
1021 init_timer(&conn
->nopin_response_timer
);
1022 conn
->nopin_response_timer
.expires
=
1023 (get_jiffies_64() + na
->nopin_response_timeout
* HZ
);
1024 conn
->nopin_response_timer
.data
= (unsigned long)conn
;
1025 conn
->nopin_response_timer
.function
= iscsit_handle_nopin_response_timeout
;
1026 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_STOP
;
1027 conn
->nopin_response_timer_flags
|= ISCSI_TF_RUNNING
;
1028 add_timer(&conn
->nopin_response_timer
);
1030 pr_debug("Started NOPIN Response Timer on CID: %d to %u"
1031 " seconds\n", conn
->cid
, na
->nopin_response_timeout
);
1032 spin_unlock_bh(&conn
->nopin_timer_lock
);
1035 void iscsit_stop_nopin_response_timer(struct iscsi_conn
*conn
)
1037 spin_lock_bh(&conn
->nopin_timer_lock
);
1038 if (!(conn
->nopin_response_timer_flags
& ISCSI_TF_RUNNING
)) {
1039 spin_unlock_bh(&conn
->nopin_timer_lock
);
1042 conn
->nopin_response_timer_flags
|= ISCSI_TF_STOP
;
1043 spin_unlock_bh(&conn
->nopin_timer_lock
);
1045 del_timer_sync(&conn
->nopin_response_timer
);
1047 spin_lock_bh(&conn
->nopin_timer_lock
);
1048 conn
->nopin_response_timer_flags
&= ~ISCSI_TF_RUNNING
;
1049 spin_unlock_bh(&conn
->nopin_timer_lock
);
1052 static void iscsit_handle_nopin_timeout(unsigned long data
)
1054 struct iscsi_conn
*conn
= (struct iscsi_conn
*) data
;
1056 iscsit_inc_conn_usage_count(conn
);
1058 spin_lock_bh(&conn
->nopin_timer_lock
);
1059 if (conn
->nopin_timer_flags
& ISCSI_TF_STOP
) {
1060 spin_unlock_bh(&conn
->nopin_timer_lock
);
1061 iscsit_dec_conn_usage_count(conn
);
1064 conn
->nopin_timer_flags
&= ~ISCSI_TF_RUNNING
;
1065 spin_unlock_bh(&conn
->nopin_timer_lock
);
1067 iscsit_add_nopin(conn
, 1);
1068 iscsit_dec_conn_usage_count(conn
);
1072 * Called with conn->nopin_timer_lock held.
1074 void __iscsit_start_nopin_timer(struct iscsi_conn
*conn
)
1076 struct iscsi_session
*sess
= conn
->sess
;
1077 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1079 * NOPIN timeout is disabled.
1081 if (!na
->nopin_timeout
)
1084 if (conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
)
1087 init_timer(&conn
->nopin_timer
);
1088 conn
->nopin_timer
.expires
= (get_jiffies_64() + na
->nopin_timeout
* HZ
);
1089 conn
->nopin_timer
.data
= (unsigned long)conn
;
1090 conn
->nopin_timer
.function
= iscsit_handle_nopin_timeout
;
1091 conn
->nopin_timer_flags
&= ~ISCSI_TF_STOP
;
1092 conn
->nopin_timer_flags
|= ISCSI_TF_RUNNING
;
1093 add_timer(&conn
->nopin_timer
);
1095 pr_debug("Started NOPIN Timer on CID: %d at %u second"
1096 " interval\n", conn
->cid
, na
->nopin_timeout
);
1099 void iscsit_start_nopin_timer(struct iscsi_conn
*conn
)
1101 struct iscsi_session
*sess
= conn
->sess
;
1102 struct iscsi_node_attrib
*na
= iscsit_tpg_get_node_attrib(sess
);
1104 * NOPIN timeout is disabled..
1106 if (!na
->nopin_timeout
)
1109 spin_lock_bh(&conn
->nopin_timer_lock
);
1110 if (conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
) {
1111 spin_unlock_bh(&conn
->nopin_timer_lock
);
1115 init_timer(&conn
->nopin_timer
);
1116 conn
->nopin_timer
.expires
= (get_jiffies_64() + na
->nopin_timeout
* HZ
);
1117 conn
->nopin_timer
.data
= (unsigned long)conn
;
1118 conn
->nopin_timer
.function
= iscsit_handle_nopin_timeout
;
1119 conn
->nopin_timer_flags
&= ~ISCSI_TF_STOP
;
1120 conn
->nopin_timer_flags
|= ISCSI_TF_RUNNING
;
1121 add_timer(&conn
->nopin_timer
);
1123 pr_debug("Started NOPIN Timer on CID: %d at %u second"
1124 " interval\n", conn
->cid
, na
->nopin_timeout
);
1125 spin_unlock_bh(&conn
->nopin_timer_lock
);
1128 void iscsit_stop_nopin_timer(struct iscsi_conn
*conn
)
1130 spin_lock_bh(&conn
->nopin_timer_lock
);
1131 if (!(conn
->nopin_timer_flags
& ISCSI_TF_RUNNING
)) {
1132 spin_unlock_bh(&conn
->nopin_timer_lock
);
1135 conn
->nopin_timer_flags
|= ISCSI_TF_STOP
;
1136 spin_unlock_bh(&conn
->nopin_timer_lock
);
1138 del_timer_sync(&conn
->nopin_timer
);
1140 spin_lock_bh(&conn
->nopin_timer_lock
);
1141 conn
->nopin_timer_flags
&= ~ISCSI_TF_RUNNING
;
1142 spin_unlock_bh(&conn
->nopin_timer_lock
);
1145 int iscsit_send_tx_data(
1146 struct iscsi_cmd
*cmd
,
1147 struct iscsi_conn
*conn
,
1150 int tx_sent
, tx_size
;
1155 tx_size
= cmd
->tx_size
;
1158 iov
= &cmd
->iov_data
[0];
1159 iov_count
= cmd
->iov_data_count
;
1161 iov
= &cmd
->iov_misc
[0];
1162 iov_count
= cmd
->iov_misc_count
;
1165 tx_sent
= tx_data(conn
, &iov
[0], iov_count
, tx_size
);
1166 if (tx_size
!= tx_sent
) {
1167 if (tx_sent
== -EAGAIN
) {
1168 pr_err("tx_data() returned -EAGAIN\n");
1178 int iscsit_fe_sendpage_sg(
1179 struct iscsi_cmd
*cmd
,
1180 struct iscsi_conn
*conn
)
1182 struct scatterlist
*sg
= cmd
->first_data_sg
;
1184 u32 tx_hdr_size
, data_len
;
1185 u32 offset
= cmd
->first_data_sg_off
;
1186 int tx_sent
, iov_off
;
1189 tx_hdr_size
= ISCSI_HDR_LEN
;
1190 if (conn
->conn_ops
->HeaderDigest
)
1191 tx_hdr_size
+= ISCSI_CRC_LEN
;
1193 iov
.iov_base
= cmd
->pdu
;
1194 iov
.iov_len
= tx_hdr_size
;
1196 tx_sent
= tx_data(conn
, &iov
, 1, tx_hdr_size
);
1197 if (tx_hdr_size
!= tx_sent
) {
1198 if (tx_sent
== -EAGAIN
) {
1199 pr_err("tx_data() returned -EAGAIN\n");
1205 data_len
= cmd
->tx_size
- tx_hdr_size
- cmd
->padding
;
1207 * Set iov_off used by padding and data digest tx_data() calls below
1208 * in order to determine proper offset into cmd->iov_data[]
1210 if (conn
->conn_ops
->DataDigest
) {
1211 data_len
-= ISCSI_CRC_LEN
;
1213 iov_off
= (cmd
->iov_data_count
- 2);
1215 iov_off
= (cmd
->iov_data_count
- 1);
1217 iov_off
= (cmd
->iov_data_count
- 1);
1220 * Perform sendpage() for each page in the scatterlist
1223 u32 space
= (sg
->length
- offset
);
1224 u32 sub_len
= min_t(u32
, data_len
, space
);
1226 tx_sent
= conn
->sock
->ops
->sendpage(conn
->sock
,
1227 sg_page(sg
), sg
->offset
+ offset
, sub_len
, 0);
1228 if (tx_sent
!= sub_len
) {
1229 if (tx_sent
== -EAGAIN
) {
1230 pr_err("tcp_sendpage() returned"
1235 pr_err("tcp_sendpage() failure: %d\n",
1240 data_len
-= sub_len
;
1247 struct kvec
*iov_p
= &cmd
->iov_data
[iov_off
++];
1249 tx_sent
= tx_data(conn
, iov_p
, 1, cmd
->padding
);
1250 if (cmd
->padding
!= tx_sent
) {
1251 if (tx_sent
== -EAGAIN
) {
1252 pr_err("tx_data() returned -EAGAIN\n");
1260 if (conn
->conn_ops
->DataDigest
) {
1261 struct kvec
*iov_d
= &cmd
->iov_data
[iov_off
];
1263 tx_sent
= tx_data(conn
, iov_d
, 1, ISCSI_CRC_LEN
);
1264 if (ISCSI_CRC_LEN
!= tx_sent
) {
1265 if (tx_sent
== -EAGAIN
) {
1266 pr_err("tx_data() returned -EAGAIN\n");
1277 * This function is used for mainly sending a ISCSI_TARG_LOGIN_RSP PDU
1278 * back to the Initiator when an expection condition occurs with the
1279 * errors set in status_class and status_detail.
1281 * Parameters: iSCSI Connection, Status Class, Status Detail.
1282 * Returns: 0 on success, -1 on error.
1284 int iscsit_tx_login_rsp(struct iscsi_conn
*conn
, u8 status_class
, u8 status_detail
)
1286 struct iscsi_login_rsp
*hdr
;
1287 struct iscsi_login
*login
= conn
->conn_login
;
1289 login
->login_failed
= 1;
1290 iscsit_collect_login_stats(conn
, status_class
, status_detail
);
1292 hdr
= (struct iscsi_login_rsp
*)&login
->rsp
[0];
1293 hdr
->opcode
= ISCSI_OP_LOGIN_RSP
;
1294 hdr
->status_class
= status_class
;
1295 hdr
->status_detail
= status_detail
;
1296 hdr
->itt
= conn
->login_itt
;
1298 return conn
->conn_transport
->iscsit_put_login_tx(conn
, login
, 0);
1301 void iscsit_print_session_params(struct iscsi_session
*sess
)
1303 struct iscsi_conn
*conn
;
1305 pr_debug("-----------------------------[Session Params for"
1306 " SID: %u]-----------------------------\n", sess
->sid
);
1307 spin_lock_bh(&sess
->conn_lock
);
1308 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
)
1309 iscsi_dump_conn_ops(conn
->conn_ops
);
1310 spin_unlock_bh(&sess
->conn_lock
);
1312 iscsi_dump_sess_ops(sess
->sess_ops
);
1315 static int iscsit_do_rx_data(
1316 struct iscsi_conn
*conn
,
1317 struct iscsi_data_count
*count
)
1319 int data
= count
->data_length
, rx_loop
= 0, total_rx
= 0, iov_len
;
1323 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1326 memset(&msg
, 0, sizeof(struct msghdr
));
1329 iov_len
= count
->iov_count
;
1331 while (total_rx
< data
) {
1332 rx_loop
= kernel_recvmsg(conn
->sock
, &msg
, iov_p
, iov_len
,
1333 (data
- total_rx
), MSG_WAITALL
);
1335 pr_debug("rx_loop: %d total_rx: %d\n",
1339 total_rx
+= rx_loop
;
1340 pr_debug("rx_loop: %d, total_rx: %d, data: %d\n",
1341 rx_loop
, total_rx
, data
);
1347 static int iscsit_do_tx_data(
1348 struct iscsi_conn
*conn
,
1349 struct iscsi_data_count
*count
)
1351 int data
= count
->data_length
, total_tx
= 0, tx_loop
= 0, iov_len
;
1355 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1359 pr_err("Data length is: %d\n", data
);
1363 memset(&msg
, 0, sizeof(struct msghdr
));
1366 iov_len
= count
->iov_count
;
1368 while (total_tx
< data
) {
1369 tx_loop
= kernel_sendmsg(conn
->sock
, &msg
, iov_p
, iov_len
,
1372 pr_debug("tx_loop: %d total_tx %d\n",
1376 total_tx
+= tx_loop
;
1377 pr_debug("tx_loop: %d, total_tx: %d, data: %d\n",
1378 tx_loop
, total_tx
, data
);
1385 struct iscsi_conn
*conn
,
1390 struct iscsi_data_count c
;
1392 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1395 memset(&c
, 0, sizeof(struct iscsi_data_count
));
1397 c
.iov_count
= iov_count
;
1398 c
.data_length
= data
;
1399 c
.type
= ISCSI_RX_DATA
;
1401 return iscsit_do_rx_data(conn
, &c
);
1405 struct iscsi_conn
*conn
,
1410 struct iscsi_data_count c
;
1412 if (!conn
|| !conn
->sock
|| !conn
->conn_ops
)
1415 memset(&c
, 0, sizeof(struct iscsi_data_count
));
1417 c
.iov_count
= iov_count
;
1418 c
.data_length
= data
;
1419 c
.type
= ISCSI_TX_DATA
;
1421 return iscsit_do_tx_data(conn
, &c
);
1424 void iscsit_collect_login_stats(
1425 struct iscsi_conn
*conn
,
1429 struct iscsi_param
*intrname
= NULL
;
1430 struct iscsi_tiqn
*tiqn
;
1431 struct iscsi_login_stats
*ls
;
1433 tiqn
= iscsit_snmp_get_tiqn(conn
);
1437 ls
= &tiqn
->login_stats
;
1439 spin_lock(&ls
->lock
);
1440 if (!strcmp(conn
->login_ip
, ls
->last_intr_fail_ip_addr
) &&
1441 ((get_jiffies_64() - ls
->last_fail_time
) < 10)) {
1442 /* We already have the failure info for this login */
1443 spin_unlock(&ls
->lock
);
1447 if (status_class
== ISCSI_STATUS_CLS_SUCCESS
)
1449 else if (status_class
== ISCSI_STATUS_CLS_REDIRECT
) {
1451 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_REDIRECT
;
1452 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1453 (status_detail
== ISCSI_LOGIN_STATUS_AUTH_FAILED
)) {
1454 ls
->authenticate_fails
++;
1455 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_AUTHENTICATE
;
1456 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1457 (status_detail
== ISCSI_LOGIN_STATUS_TGT_FORBIDDEN
)) {
1458 ls
->authorize_fails
++;
1459 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_AUTHORIZE
;
1460 } else if ((status_class
== ISCSI_STATUS_CLS_INITIATOR_ERR
) &&
1461 (status_detail
== ISCSI_LOGIN_STATUS_INIT_ERR
)) {
1462 ls
->negotiate_fails
++;
1463 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_NEGOTIATE
;
1466 ls
->last_fail_type
= ISCSI_LOGIN_FAIL_OTHER
;
1469 /* Save initiator name, ip address and time, if it is a failed login */
1470 if (status_class
!= ISCSI_STATUS_CLS_SUCCESS
) {
1471 if (conn
->param_list
)
1472 intrname
= iscsi_find_param_from_key(INITIATORNAME
,
1474 strcpy(ls
->last_intr_fail_name
,
1475 (intrname
? intrname
->value
: "Unknown"));
1477 ls
->last_intr_fail_ip_family
= conn
->login_family
;
1479 snprintf(ls
->last_intr_fail_ip_addr
, IPV6_ADDRESS_SPACE
,
1480 "%s", conn
->login_ip
);
1481 ls
->last_fail_time
= get_jiffies_64();
1484 spin_unlock(&ls
->lock
);
1487 struct iscsi_tiqn
*iscsit_snmp_get_tiqn(struct iscsi_conn
*conn
)
1489 struct iscsi_portal_group
*tpg
;
1491 if (!conn
|| !conn
->sess
)
1494 tpg
= conn
->sess
->tpg
;
1501 return tpg
->tpg_tiqn
;