diff options
author | Sagi Grimberg <sagig@mellanox.com> | 2015-03-29 08:52:15 -0400 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2015-04-08 02:27:55 -0400 |
commit | ae9ea9ed38c9c8f6cf19c669d7b032cab3dadede (patch) | |
tree | b642d5aa8ecdb3b2f4cd91abb2beebb6f03825d8 | |
parent | cf8ae95823ae99186729834a630f24ff9e7b1501 (diff) |
iser-target: Split some logic in isert_connect_request to routines
Move login buffer alloc/free code to dedicated
routines and introduce isert_conn_init which
initializes the connection lists and locks.
Simplifies and cleans up the code a little bit.
Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r-- | drivers/infiniband/ulp/isert/ib_isert.c | 118 |
1 files changed, 70 insertions, 48 deletions
diff --git a/drivers/infiniband/ulp/isert/ib_isert.c b/drivers/infiniband/ulp/isert/ib_isert.c index d19271bb8de1..4fddc08f4ae5 100644 --- a/drivers/infiniband/ulp/isert/ib_isert.c +++ b/drivers/infiniband/ulp/isert/ib_isert.c | |||
@@ -636,32 +636,9 @@ err: | |||
636 | return ret; | 636 | return ret; |
637 | } | 637 | } |
638 | 638 | ||
639 | static int | 639 | static void |
640 | isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) | 640 | isert_init_conn(struct isert_conn *isert_conn) |
641 | { | 641 | { |
642 | struct isert_np *isert_np = cma_id->context; | ||
643 | struct iscsi_np *np = isert_np->np; | ||
644 | struct isert_conn *isert_conn; | ||
645 | struct isert_device *device; | ||
646 | struct ib_device *ib_dev = cma_id->device; | ||
647 | int ret = 0; | ||
648 | |||
649 | spin_lock_bh(&np->np_thread_lock); | ||
650 | if (!np->enabled) { | ||
651 | spin_unlock_bh(&np->np_thread_lock); | ||
652 | isert_dbg("iscsi_np is not enabled, reject connect request\n"); | ||
653 | return rdma_reject(cma_id, NULL, 0); | ||
654 | } | ||
655 | spin_unlock_bh(&np->np_thread_lock); | ||
656 | |||
657 | isert_dbg("cma_id: %p, portal: %p\n", | ||
658 | cma_id, cma_id->context); | ||
659 | |||
660 | isert_conn = kzalloc(sizeof(struct isert_conn), GFP_KERNEL); | ||
661 | if (!isert_conn) { | ||
662 | isert_err("Unable to allocate isert_conn\n"); | ||
663 | return -ENOMEM; | ||
664 | } | ||
665 | isert_conn->state = ISER_CONN_INIT; | 642 | isert_conn->state = ISER_CONN_INIT; |
666 | INIT_LIST_HEAD(&isert_conn->conn_accept_node); | 643 | INIT_LIST_HEAD(&isert_conn->conn_accept_node); |
667 | init_completion(&isert_conn->conn_login_comp); | 644 | init_completion(&isert_conn->conn_login_comp); |
@@ -671,20 +648,38 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) | |||
671 | mutex_init(&isert_conn->conn_mutex); | 648 | mutex_init(&isert_conn->conn_mutex); |
672 | spin_lock_init(&isert_conn->conn_lock); | 649 | spin_lock_init(&isert_conn->conn_lock); |
673 | INIT_LIST_HEAD(&isert_conn->conn_fr_pool); | 650 | INIT_LIST_HEAD(&isert_conn->conn_fr_pool); |
651 | } | ||
674 | 652 | ||
675 | isert_conn->conn_cm_id = cma_id; | 653 | static void |
654 | isert_free_login_buf(struct isert_conn *isert_conn) | ||
655 | { | ||
656 | struct ib_device *ib_dev = isert_conn->conn_device->ib_device; | ||
657 | |||
658 | ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma, | ||
659 | ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE); | ||
660 | ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma, | ||
661 | ISCSI_DEF_MAX_RECV_SEG_LEN, | ||
662 | DMA_FROM_DEVICE); | ||
663 | kfree(isert_conn->login_buf); | ||
664 | } | ||
665 | |||
666 | static int | ||
667 | isert_alloc_login_buf(struct isert_conn *isert_conn, | ||
668 | struct ib_device *ib_dev) | ||
669 | { | ||
670 | int ret; | ||
676 | 671 | ||
677 | isert_conn->login_buf = kzalloc(ISCSI_DEF_MAX_RECV_SEG_LEN + | 672 | isert_conn->login_buf = kzalloc(ISCSI_DEF_MAX_RECV_SEG_LEN + |
678 | ISER_RX_LOGIN_SIZE, GFP_KERNEL); | 673 | ISER_RX_LOGIN_SIZE, GFP_KERNEL); |
679 | if (!isert_conn->login_buf) { | 674 | if (!isert_conn->login_buf) { |
680 | isert_err("Unable to allocate isert_conn->login_buf\n"); | 675 | isert_err("Unable to allocate isert_conn->login_buf\n"); |
681 | ret = -ENOMEM; | 676 | return -ENOMEM; |
682 | goto out; | ||
683 | } | 677 | } |
684 | 678 | ||
685 | isert_conn->login_req_buf = isert_conn->login_buf; | 679 | isert_conn->login_req_buf = isert_conn->login_buf; |
686 | isert_conn->login_rsp_buf = isert_conn->login_buf + | 680 | isert_conn->login_rsp_buf = isert_conn->login_buf + |
687 | ISCSI_DEF_MAX_RECV_SEG_LEN; | 681 | ISCSI_DEF_MAX_RECV_SEG_LEN; |
682 | |||
688 | isert_dbg("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n", | 683 | isert_dbg("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n", |
689 | isert_conn->login_buf, isert_conn->login_req_buf, | 684 | isert_conn->login_buf, isert_conn->login_req_buf, |
690 | isert_conn->login_rsp_buf); | 685 | isert_conn->login_rsp_buf); |
@@ -695,8 +690,7 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) | |||
695 | 690 | ||
696 | ret = ib_dma_mapping_error(ib_dev, isert_conn->login_req_dma); | 691 | ret = ib_dma_mapping_error(ib_dev, isert_conn->login_req_dma); |
697 | if (ret) { | 692 | if (ret) { |
698 | isert_err("ib_dma_mapping_error failed for login_req_dma: %d\n", | 693 | isert_err("login_req_dma mapping error: %d\n", ret); |
699 | ret); | ||
700 | isert_conn->login_req_dma = 0; | 694 | isert_conn->login_req_dma = 0; |
701 | goto out_login_buf; | 695 | goto out_login_buf; |
702 | } | 696 | } |
@@ -707,12 +701,52 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) | |||
707 | 701 | ||
708 | ret = ib_dma_mapping_error(ib_dev, isert_conn->login_rsp_dma); | 702 | ret = ib_dma_mapping_error(ib_dev, isert_conn->login_rsp_dma); |
709 | if (ret) { | 703 | if (ret) { |
710 | isert_err("ib_dma_mapping_error failed for login_rsp_dma: %d\n", | 704 | isert_err("login_rsp_dma mapping error: %d\n", ret); |
711 | ret); | ||
712 | isert_conn->login_rsp_dma = 0; | 705 | isert_conn->login_rsp_dma = 0; |
713 | goto out_req_dma_map; | 706 | goto out_req_dma_map; |
714 | } | 707 | } |
715 | 708 | ||
709 | return 0; | ||
710 | |||
711 | out_req_dma_map: | ||
712 | ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma, | ||
713 | ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_FROM_DEVICE); | ||
714 | out_login_buf: | ||
715 | kfree(isert_conn->login_buf); | ||
716 | return ret; | ||
717 | } | ||
718 | |||
719 | static int | ||
720 | isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) | ||
721 | { | ||
722 | struct isert_np *isert_np = cma_id->context; | ||
723 | struct iscsi_np *np = isert_np->np; | ||
724 | struct isert_conn *isert_conn; | ||
725 | struct isert_device *device; | ||
726 | int ret = 0; | ||
727 | |||
728 | spin_lock_bh(&np->np_thread_lock); | ||
729 | if (!np->enabled) { | ||
730 | spin_unlock_bh(&np->np_thread_lock); | ||
731 | isert_dbg("iscsi_np is not enabled, reject connect request\n"); | ||
732 | return rdma_reject(cma_id, NULL, 0); | ||
733 | } | ||
734 | spin_unlock_bh(&np->np_thread_lock); | ||
735 | |||
736 | isert_dbg("cma_id: %p, portal: %p\n", | ||
737 | cma_id, cma_id->context); | ||
738 | |||
739 | isert_conn = kzalloc(sizeof(struct isert_conn), GFP_KERNEL); | ||
740 | if (!isert_conn) | ||
741 | return -ENOMEM; | ||
742 | |||
743 | isert_init_conn(isert_conn); | ||
744 | isert_conn->conn_cm_id = cma_id; | ||
745 | |||
746 | ret = isert_alloc_login_buf(isert_conn, cma_id->device); | ||
747 | if (ret) | ||
748 | goto out; | ||
749 | |||
716 | device = isert_device_get(cma_id); | 750 | device = isert_device_get(cma_id); |
717 | if (IS_ERR(device)) { | 751 | if (IS_ERR(device)) { |
718 | ret = PTR_ERR(device); | 752 | ret = PTR_ERR(device); |
@@ -749,13 +783,7 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event) | |||
749 | out_conn_dev: | 783 | out_conn_dev: |
750 | isert_device_put(device); | 784 | isert_device_put(device); |
751 | out_rsp_dma_map: | 785 | out_rsp_dma_map: |
752 | ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma, | 786 | isert_free_login_buf(isert_conn); |
753 | ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE); | ||
754 | out_req_dma_map: | ||
755 | ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma, | ||
756 | ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_FROM_DEVICE); | ||
757 | out_login_buf: | ||
758 | kfree(isert_conn->login_buf); | ||
759 | out: | 787 | out: |
760 | kfree(isert_conn); | 788 | kfree(isert_conn); |
761 | rdma_reject(cma_id, NULL, 0); | 789 | rdma_reject(cma_id, NULL, 0); |
@@ -766,7 +794,6 @@ static void | |||
766 | isert_connect_release(struct isert_conn *isert_conn) | 794 | isert_connect_release(struct isert_conn *isert_conn) |
767 | { | 795 | { |
768 | struct isert_device *device = isert_conn->conn_device; | 796 | struct isert_device *device = isert_conn->conn_device; |
769 | struct ib_device *ib_dev = device->ib_device; | ||
770 | 797 | ||
771 | isert_dbg("conn %p\n", isert_conn); | 798 | isert_dbg("conn %p\n", isert_conn); |
772 | 799 | ||
@@ -784,14 +811,9 @@ isert_connect_release(struct isert_conn *isert_conn) | |||
784 | ib_destroy_qp(isert_conn->conn_qp); | 811 | ib_destroy_qp(isert_conn->conn_qp); |
785 | } | 812 | } |
786 | 813 | ||
787 | if (isert_conn->login_buf) { | 814 | if (isert_conn->login_buf) |
788 | ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma, | 815 | isert_free_login_buf(isert_conn); |
789 | ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE); | 816 | |
790 | ib_dma_unmap_single(ib_dev, isert_conn->login_req_dma, | ||
791 | ISCSI_DEF_MAX_RECV_SEG_LEN, | ||
792 | DMA_FROM_DEVICE); | ||
793 | kfree(isert_conn->login_buf); | ||
794 | } | ||
795 | kfree(isert_conn); | 817 | kfree(isert_conn); |
796 | 818 | ||
797 | if (device) | 819 | if (device) |