@@ -1269,7 +1269,6 @@ static struct srpt_send_ioctx *srpt_get_send_ioctx(struct srpt_rdma_ch *ch)
12691269 return ioctx ;
12701270
12711271 BUG_ON (ioctx -> ch != ch );
1272- kref_init (& ioctx -> kref );
12731272 spin_lock_init (& ioctx -> spinlock );
12741273 ioctx -> state = SRPT_STATE_NEW ;
12751274 ioctx -> n_rbuf = 0 ;
@@ -1290,39 +1289,6 @@ static struct srpt_send_ioctx *srpt_get_send_ioctx(struct srpt_rdma_ch *ch)
12901289 return ioctx ;
12911290}
12921291
1293- /**
1294- * srpt_put_send_ioctx() - Free up resources.
1295- */
1296- static void srpt_put_send_ioctx (struct srpt_send_ioctx * ioctx )
1297- {
1298- struct srpt_rdma_ch * ch ;
1299- unsigned long flags ;
1300-
1301- BUG_ON (!ioctx );
1302- ch = ioctx -> ch ;
1303- BUG_ON (!ch );
1304-
1305- WARN_ON (srpt_get_cmd_state (ioctx ) != SRPT_STATE_DONE );
1306-
1307- srpt_unmap_sg_to_ib_sge (ioctx -> ch , ioctx );
1308- transport_generic_free_cmd (& ioctx -> cmd , 0 );
1309-
1310- if (ioctx -> n_rbuf > 1 ) {
1311- kfree (ioctx -> rbufs );
1312- ioctx -> rbufs = NULL ;
1313- ioctx -> n_rbuf = 0 ;
1314- }
1315-
1316- spin_lock_irqsave (& ch -> spinlock , flags );
1317- list_add (& ioctx -> free_list , & ch -> free_list );
1318- spin_unlock_irqrestore (& ch -> spinlock , flags );
1319- }
1320-
1321- static void srpt_put_send_ioctx_kref (struct kref * kref )
1322- {
1323- srpt_put_send_ioctx (container_of (kref , struct srpt_send_ioctx , kref ));
1324- }
1325-
13261292/**
13271293 * srpt_abort_cmd() - Abort a SCSI command.
13281294 * @ioctx: I/O context associated with the SCSI command.
@@ -1359,8 +1325,14 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
13591325 }
13601326 spin_unlock_irqrestore (& ioctx -> spinlock , flags );
13611327
1362- if (state == SRPT_STATE_DONE )
1328+ if (state == SRPT_STATE_DONE ) {
1329+ struct srpt_rdma_ch * ch = ioctx -> ch ;
1330+
1331+ BUG_ON (ch -> sess == NULL );
1332+
1333+ target_put_sess_cmd (ch -> sess , & ioctx -> cmd );
13631334 goto out ;
1335+ }
13641336
13651337 pr_debug ("Aborting cmd with state %d and tag %lld\n" , state ,
13661338 ioctx -> tag );
@@ -1395,11 +1367,11 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
13951367 spin_lock_irqsave (& ioctx -> cmd .t_state_lock , flags );
13961368 ioctx -> cmd .transport_state |= CMD_T_LUN_STOP ;
13971369 spin_unlock_irqrestore (& ioctx -> cmd .t_state_lock , flags );
1398- kref_put ( & ioctx -> kref , srpt_put_send_ioctx_kref );
1370+ target_put_sess_cmd ( ioctx -> ch -> sess , & ioctx -> cmd );
13991371 break ;
14001372 case SRPT_STATE_MGMT_RSP_SENT :
14011373 srpt_set_cmd_state (ioctx , SRPT_STATE_DONE );
1402- kref_put ( & ioctx -> kref , srpt_put_send_ioctx_kref );
1374+ target_put_sess_cmd ( ioctx -> ch -> sess , & ioctx -> cmd );
14031375 break ;
14041376 default :
14051377 WARN_ON ("ERROR: unexpected command state" );
@@ -1457,11 +1429,13 @@ static void srpt_handle_send_comp(struct srpt_rdma_ch *ch,
14571429 && state != SRPT_STATE_DONE ))
14581430 pr_debug ("state = %d\n" , state );
14591431
1460- if (state != SRPT_STATE_DONE )
1461- kref_put (& ioctx -> kref , srpt_put_send_ioctx_kref );
1462- else
1432+ if (state != SRPT_STATE_DONE ) {
1433+ srpt_unmap_sg_to_ib_sge (ch , ioctx );
1434+ transport_generic_free_cmd (& ioctx -> cmd , 0 );
1435+ } else {
14631436 printk (KERN_ERR "IB completion has been received too late for"
14641437 " wr_id = %u.\n" , ioctx -> ioctx .index );
1438+ }
14651439}
14661440
14671441/**
@@ -1712,10 +1686,10 @@ static uint64_t srpt_unpack_lun(const uint8_t *lun, int len)
17121686
17131687static int srpt_check_stop_free (struct se_cmd * cmd )
17141688{
1715- struct srpt_send_ioctx * ioctx ;
1689+ struct srpt_send_ioctx * ioctx = container_of (cmd ,
1690+ struct srpt_send_ioctx , cmd );
17161691
1717- ioctx = container_of (cmd , struct srpt_send_ioctx , cmd );
1718- return kref_put (& ioctx -> kref , srpt_put_send_ioctx_kref );
1692+ return target_put_sess_cmd (ioctx -> ch -> sess , & ioctx -> cmd );
17191693}
17201694
17211695/**
@@ -1731,11 +1705,11 @@ static int srpt_handle_cmd(struct srpt_rdma_ch *ch,
17311705 u64 data_len ;
17321706 enum dma_data_direction dir ;
17331707 sense_reason_t ret ;
1708+ int rc ;
17341709
17351710 BUG_ON (!send_ioctx );
17361711
17371712 srp_cmd = recv_ioctx -> ioctx .buf ;
1738- kref_get (& send_ioctx -> kref );
17391713 cmd = & send_ioctx -> cmd ;
17401714 send_ioctx -> tag = srp_cmd -> tag ;
17411715
@@ -1759,30 +1733,18 @@ static int srpt_handle_cmd(struct srpt_rdma_ch *ch,
17591733 printk (KERN_ERR "0x%llx: parsing SRP descriptor table failed.\n" ,
17601734 srp_cmd -> tag );
17611735 ret = TCM_INVALID_CDB_FIELD ;
1762- kref_put (& send_ioctx -> kref , srpt_put_send_ioctx_kref );
17631736 goto send_sense ;
17641737 }
17651738
1766- cmd -> data_length = data_len ;
1767- cmd -> data_direction = dir ;
17681739 unpacked_lun = srpt_unpack_lun ((uint8_t * )& srp_cmd -> lun ,
17691740 sizeof (srp_cmd -> lun ));
1770- ret = transport_lookup_cmd_lun (cmd , unpacked_lun );
1771- if (ret ) {
1772- kref_put (& send_ioctx -> kref , srpt_put_send_ioctx_kref );
1741+ rc = target_submit_cmd (cmd , ch -> sess , srp_cmd -> cdb ,
1742+ & send_ioctx -> sense_data [0 ], unpacked_lun , data_len ,
1743+ MSG_SIMPLE_TAG , dir , TARGET_SCF_ACK_KREF );
1744+ if (rc != 0 ) {
1745+ ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE ;
17731746 goto send_sense ;
17741747 }
1775- ret = target_setup_cmd_from_cdb (cmd , srp_cmd -> cdb );
1776- if (ret ) {
1777- kref_put (& send_ioctx -> kref , srpt_put_send_ioctx_kref );
1778- if (ret == TCM_RESERVATION_CONFLICT ) {
1779- srpt_queue_status (cmd );
1780- return 0 ;
1781- }
1782- goto send_sense ;
1783- }
1784-
1785- transport_handle_cdb_direct (cmd );
17861748 return 0 ;
17871749
17881750send_sense :
@@ -1884,6 +1846,9 @@ static void srpt_handle_tsk_mgmt(struct srpt_rdma_ch *ch,
18841846 TMR_TASK_MGMT_FUNCTION_NOT_SUPPORTED ;
18851847 goto fail ;
18861848 }
1849+ transport_init_se_cmd (& send_ioctx -> cmd , & srpt_target -> tf_ops , ch -> sess ,
1850+ 0 , DMA_NONE , MSG_SIMPLE_TAG , send_ioctx -> sense_data );
1851+
18871852 res = core_tmr_alloc_req (cmd , NULL , tcm_tmr , GFP_KERNEL );
18881853 if (res < 0 ) {
18891854 send_ioctx -> cmd .se_tmr_req -> response = TMR_FUNCTION_REJECTED ;
@@ -1902,11 +1867,9 @@ static void srpt_handle_tsk_mgmt(struct srpt_rdma_ch *ch,
19021867 if (srp_tsk -> tsk_mgmt_func == SRP_TSK_ABORT_TASK )
19031868 srpt_rx_mgmt_fn_tag (send_ioctx , srp_tsk -> task_tag );
19041869
1905- kref_get (& send_ioctx -> kref );
19061870 transport_generic_handle_tmr (& send_ioctx -> cmd );
19071871 return ;
19081872fail :
1909- kref_get (& send_ioctx -> kref );
19101873 transport_send_check_condition_and_sense (cmd , 0 , 0 ); // XXX:
19111874}
19121875
@@ -1949,10 +1912,6 @@ static void srpt_handle_new_iu(struct srpt_rdma_ch *ch,
19491912 }
19501913 }
19511914
1952- transport_init_se_cmd (& send_ioctx -> cmd , & srpt_target -> tf_ops , ch -> sess ,
1953- 0 , DMA_NONE , MSG_SIMPLE_TAG ,
1954- send_ioctx -> sense_data );
1955-
19561915 switch (srp_cmd -> opcode ) {
19571916 case SRP_CMD :
19581917 srpt_handle_cmd (ch , recv_ioctx , send_ioctx );
@@ -2358,6 +2317,7 @@ static void srpt_release_channel_work(struct work_struct *w)
23582317{
23592318 struct srpt_rdma_ch * ch ;
23602319 struct srpt_device * sdev ;
2320+ struct se_session * se_sess ;
23612321
23622322 ch = container_of (w , struct srpt_rdma_ch , release_work );
23632323 pr_debug ("ch = %p; ch->sess = %p; release_done = %p\n" , ch , ch -> sess ,
@@ -2366,8 +2326,13 @@ static void srpt_release_channel_work(struct work_struct *w)
23662326 sdev = ch -> sport -> sdev ;
23672327 BUG_ON (!sdev );
23682328
2369- transport_deregister_session_configfs (ch -> sess );
2370- transport_deregister_session (ch -> sess );
2329+ se_sess = ch -> sess ;
2330+ BUG_ON (!se_sess );
2331+
2332+ target_wait_for_sess_cmds (se_sess , 0 );
2333+
2334+ transport_deregister_session_configfs (se_sess );
2335+ transport_deregister_session (se_sess );
23712336 ch -> sess = NULL ;
23722337
23732338 srpt_destroy_ch_ib (ch );
@@ -3092,7 +3057,7 @@ static int srpt_queue_response(struct se_cmd *cmd)
30923057 ioctx -> tag );
30933058 srpt_unmap_sg_to_ib_sge (ch , ioctx );
30943059 srpt_set_cmd_state (ioctx , SRPT_STATE_DONE );
3095- kref_put ( & ioctx -> kref , srpt_put_send_ioctx_kref );
3060+ target_put_sess_cmd ( ioctx -> ch -> sess , & ioctx -> cmd );
30963061 }
30973062
30983063out :
@@ -3483,6 +3448,23 @@ static u32 srpt_tpg_get_inst_index(struct se_portal_group *se_tpg)
34833448
34843449static void srpt_release_cmd (struct se_cmd * se_cmd )
34853450{
3451+ struct srpt_send_ioctx * ioctx = container_of (se_cmd ,
3452+ struct srpt_send_ioctx , cmd );
3453+ struct srpt_rdma_ch * ch = ioctx -> ch ;
3454+ unsigned long flags ;
3455+
3456+ WARN_ON (ioctx -> state != SRPT_STATE_DONE );
3457+ WARN_ON (ioctx -> mapped_sg_count != 0 );
3458+
3459+ if (ioctx -> n_rbuf > 1 ) {
3460+ kfree (ioctx -> rbufs );
3461+ ioctx -> rbufs = NULL ;
3462+ ioctx -> n_rbuf = 0 ;
3463+ }
3464+
3465+ spin_lock_irqsave (& ch -> spinlock , flags );
3466+ list_add (& ioctx -> free_list , & ch -> free_list );
3467+ spin_unlock_irqrestore (& ch -> spinlock , flags );
34863468}
34873469
34883470/**
0 commit comments