diff options
Diffstat (limited to 'drivers/target/iscsi/iscsi_target_util.c')
-rw-r--r-- | drivers/target/iscsi/iscsi_target_util.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/drivers/target/iscsi/iscsi_target_util.c b/drivers/target/iscsi/iscsi_target_util.c index 2cc6c9a3ffb8..08a3bacef0c5 100644 --- a/drivers/target/iscsi/iscsi_target_util.c +++ b/drivers/target/iscsi/iscsi_target_util.c | |||
@@ -676,40 +676,56 @@ void iscsit_free_queue_reqs_for_conn(struct iscsi_conn *conn) | |||
676 | 676 | ||
677 | void iscsit_release_cmd(struct iscsi_cmd *cmd) | 677 | void iscsit_release_cmd(struct iscsi_cmd *cmd) |
678 | { | 678 | { |
679 | struct iscsi_conn *conn = cmd->conn; | ||
680 | |||
681 | iscsit_free_r2ts_from_list(cmd); | ||
682 | iscsit_free_all_datain_reqs(cmd); | ||
683 | |||
684 | kfree(cmd->buf_ptr); | 679 | kfree(cmd->buf_ptr); |
685 | kfree(cmd->pdu_list); | 680 | kfree(cmd->pdu_list); |
686 | kfree(cmd->seq_list); | 681 | kfree(cmd->seq_list); |
687 | kfree(cmd->tmr_req); | 682 | kfree(cmd->tmr_req); |
688 | kfree(cmd->iov_data); | 683 | kfree(cmd->iov_data); |
689 | 684 | ||
690 | if (conn) { | 685 | kmem_cache_free(lio_cmd_cache, cmd); |
686 | } | ||
687 | |||
688 | static void __iscsit_free_cmd(struct iscsi_cmd *cmd, bool scsi_cmd, | ||
689 | bool check_queues) | ||
690 | { | ||
691 | struct iscsi_conn *conn = cmd->conn; | ||
692 | |||
693 | if (scsi_cmd) { | ||
694 | if (cmd->data_direction == DMA_TO_DEVICE) { | ||
695 | iscsit_stop_dataout_timer(cmd); | ||
696 | iscsit_free_r2ts_from_list(cmd); | ||
697 | } | ||
698 | if (cmd->data_direction == DMA_FROM_DEVICE) | ||
699 | iscsit_free_all_datain_reqs(cmd); | ||
700 | } | ||
701 | |||
702 | if (conn && check_queues) { | ||
691 | iscsit_remove_cmd_from_immediate_queue(cmd, conn); | 703 | iscsit_remove_cmd_from_immediate_queue(cmd, conn); |
692 | iscsit_remove_cmd_from_response_queue(cmd, conn); | 704 | iscsit_remove_cmd_from_response_queue(cmd, conn); |
693 | } | 705 | } |
694 | |||
695 | kmem_cache_free(lio_cmd_cache, cmd); | ||
696 | } | 706 | } |
697 | 707 | ||
698 | void iscsit_free_cmd(struct iscsi_cmd *cmd) | 708 | void iscsit_free_cmd(struct iscsi_cmd *cmd, bool shutdown) |
699 | { | 709 | { |
710 | struct se_cmd *se_cmd = NULL; | ||
711 | int rc; | ||
700 | /* | 712 | /* |
701 | * Determine if a struct se_cmd is associated with | 713 | * Determine if a struct se_cmd is associated with |
702 | * this struct iscsi_cmd. | 714 | * this struct iscsi_cmd. |
703 | */ | 715 | */ |
704 | switch (cmd->iscsi_opcode) { | 716 | switch (cmd->iscsi_opcode) { |
705 | case ISCSI_OP_SCSI_CMD: | 717 | case ISCSI_OP_SCSI_CMD: |
706 | if (cmd->data_direction == DMA_TO_DEVICE) | 718 | se_cmd = &cmd->se_cmd; |
707 | iscsit_stop_dataout_timer(cmd); | 719 | __iscsit_free_cmd(cmd, true, shutdown); |
708 | /* | 720 | /* |
709 | * Fallthrough | 721 | * Fallthrough |
710 | */ | 722 | */ |
711 | case ISCSI_OP_SCSI_TMFUNC: | 723 | case ISCSI_OP_SCSI_TMFUNC: |
712 | transport_generic_free_cmd(&cmd->se_cmd, 1); | 724 | rc = transport_generic_free_cmd(&cmd->se_cmd, 1); |
725 | if (!rc && shutdown && se_cmd && se_cmd->se_sess) { | ||
726 | __iscsit_free_cmd(cmd, true, shutdown); | ||
727 | target_put_sess_cmd(se_cmd->se_sess, se_cmd); | ||
728 | } | ||
713 | break; | 729 | break; |
714 | case ISCSI_OP_REJECT: | 730 | case ISCSI_OP_REJECT: |
715 | /* | 731 | /* |
@@ -718,11 +734,19 @@ void iscsit_free_cmd(struct iscsi_cmd *cmd) | |||
718 | * associated cmd->se_cmd needs to be released. | 734 | * associated cmd->se_cmd needs to be released. |
719 | */ | 735 | */ |
720 | if (cmd->se_cmd.se_tfo != NULL) { | 736 | if (cmd->se_cmd.se_tfo != NULL) { |
721 | transport_generic_free_cmd(&cmd->se_cmd, 1); | 737 | se_cmd = &cmd->se_cmd; |
738 | __iscsit_free_cmd(cmd, true, shutdown); | ||
739 | |||
740 | rc = transport_generic_free_cmd(&cmd->se_cmd, 1); | ||
741 | if (!rc && shutdown && se_cmd->se_sess) { | ||
742 | __iscsit_free_cmd(cmd, true, shutdown); | ||
743 | target_put_sess_cmd(se_cmd->se_sess, se_cmd); | ||
744 | } | ||
722 | break; | 745 | break; |
723 | } | 746 | } |
724 | /* Fall-through */ | 747 | /* Fall-through */ |
725 | default: | 748 | default: |
749 | __iscsit_free_cmd(cmd, false, shutdown); | ||
726 | cmd->release_cmd(cmd); | 750 | cmd->release_cmd(cmd); |
727 | break; | 751 | break; |
728 | } | 752 | } |