Skip to content

Commit ae9ea9e

Browse files
Sagi GrimbergNicholas Bellinger
authored andcommitted
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>
1 parent cf8ae95 commit ae9ea9e

1 file changed

Lines changed: 70 additions & 48 deletions

File tree

‎drivers/infiniband/ulp/isert/ib_isert.c‎

Lines changed: 70 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -636,32 +636,9 @@ isert_conn_create_fastreg_pool(struct isert_conn *isert_conn)
636636
return ret;
637637
}
638638

639-
static int
640-
isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
639+
static void
640+
isert_init_conn(struct isert_conn *isert_conn)
641641
{
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-
}
665642
isert_conn->state = ISER_CONN_INIT;
666643
INIT_LIST_HEAD(&isert_conn->conn_accept_node);
667644
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)
671648
mutex_init(&isert_conn->conn_mutex);
672649
spin_lock_init(&isert_conn->conn_lock);
673650
INIT_LIST_HEAD(&isert_conn->conn_fr_pool);
651+
}
674652

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;
676671

677672
isert_conn->login_buf = kzalloc(ISCSI_DEF_MAX_RECV_SEG_LEN +
678673
ISER_RX_LOGIN_SIZE, GFP_KERNEL);
679674
if (!isert_conn->login_buf) {
680675
isert_err("Unable to allocate isert_conn->login_buf\n");
681-
ret = -ENOMEM;
682-
goto out;
676+
return -ENOMEM;
683677
}
684678

685679
isert_conn->login_req_buf = isert_conn->login_buf;
686680
isert_conn->login_rsp_buf = isert_conn->login_buf +
687681
ISCSI_DEF_MAX_RECV_SEG_LEN;
682+
688683
isert_dbg("Set login_buf: %p login_req_buf: %p login_rsp_buf: %p\n",
689684
isert_conn->login_buf, isert_conn->login_req_buf,
690685
isert_conn->login_rsp_buf);
@@ -695,8 +690,7 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
695690

696691
ret = ib_dma_mapping_error(ib_dev, isert_conn->login_req_dma);
697692
if (ret) {
698-
isert_err("ib_dma_mapping_error failed for login_req_dma: %d\n",
699-
ret);
693+
isert_err("login_req_dma mapping error: %d\n", ret);
700694
isert_conn->login_req_dma = 0;
701695
goto out_login_buf;
702696
}
@@ -707,12 +701,52 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
707701

708702
ret = ib_dma_mapping_error(ib_dev, isert_conn->login_rsp_dma);
709703
if (ret) {
710-
isert_err("ib_dma_mapping_error failed for login_rsp_dma: %d\n",
711-
ret);
704+
isert_err("login_rsp_dma mapping error: %d\n", ret);
712705
isert_conn->login_rsp_dma = 0;
713706
goto out_req_dma_map;
714707
}
715708

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+
716750
device = isert_device_get(cma_id);
717751
if (IS_ERR(device)) {
718752
ret = PTR_ERR(device);
@@ -749,13 +783,7 @@ isert_connect_request(struct rdma_cm_id *cma_id, struct rdma_cm_event *event)
749783
out_conn_dev:
750784
isert_device_put(device);
751785
out_rsp_dma_map:
752-
ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma,
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);
786+
isert_free_login_buf(isert_conn);
759787
out:
760788
kfree(isert_conn);
761789
rdma_reject(cma_id, NULL, 0);
@@ -766,7 +794,6 @@ static void
766794
isert_connect_release(struct isert_conn *isert_conn)
767795
{
768796
struct isert_device *device = isert_conn->conn_device;
769-
struct ib_device *ib_dev = device->ib_device;
770797

771798
isert_dbg("conn %p\n", isert_conn);
772799

@@ -784,14 +811,9 @@ isert_connect_release(struct isert_conn *isert_conn)
784811
ib_destroy_qp(isert_conn->conn_qp);
785812
}
786813

787-
if (isert_conn->login_buf) {
788-
ib_dma_unmap_single(ib_dev, isert_conn->login_rsp_dma,
789-
ISER_RX_LOGIN_SIZE, DMA_TO_DEVICE);
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-
}
814+
if (isert_conn->login_buf)
815+
isert_free_login_buf(isert_conn);
816+
795817
kfree(isert_conn);
796818

797819
if (device)

0 commit comments

Comments
 (0)