@@ -1847,13 +1847,13 @@ static int srpt_disconnect_ch(struct srpt_rdma_ch *ch)
1847
1847
return ret ;
1848
1848
}
1849
1849
1850
- static bool srpt_ch_closed (struct srpt_device * sdev , struct srpt_rdma_ch * ch )
1850
+ static bool srpt_ch_closed (struct srpt_port * sport , struct srpt_rdma_ch * ch )
1851
1851
{
1852
1852
struct srpt_rdma_ch * ch2 ;
1853
1853
bool res = true;
1854
1854
1855
1855
rcu_read_lock ();
1856
- list_for_each_entry (ch2 , & sdev -> rch_list , list ) {
1856
+ list_for_each_entry (ch2 , & sport -> rch_list , list ) {
1857
1857
if (ch2 == ch ) {
1858
1858
res = false;
1859
1859
break ;
@@ -1871,33 +1871,32 @@ static bool srpt_ch_closed(struct srpt_device *sdev, struct srpt_rdma_ch *ch)
1871
1871
static bool srpt_disconnect_ch_sync (struct srpt_rdma_ch * ch )
1872
1872
__must_hold (& sdev - > mutex )
1873
1873
{
1874
- struct srpt_device * sdev = ch -> sport -> sdev ;
1874
+ struct srpt_port * sport = ch -> sport ;
1875
1875
int ret ;
1876
1876
1877
- lockdep_assert_held (& sdev -> mutex );
1877
+ lockdep_assert_held (& sport -> mutex );
1878
1878
1879
1879
pr_debug ("ch %s-%d state %d\n" , ch -> sess_name , ch -> qp -> qp_num ,
1880
1880
ch -> state );
1881
1881
1882
1882
ret = srpt_disconnect_ch (ch );
1883
- mutex_unlock (& sdev -> mutex );
1883
+ mutex_unlock (& sport -> mutex );
1884
1884
1885
- while (wait_event_timeout (sdev -> ch_releaseQ , srpt_ch_closed (sdev , ch ),
1885
+ while (wait_event_timeout (sport -> ch_releaseQ , srpt_ch_closed (sport , ch ),
1886
1886
5 * HZ ) == 0 )
1887
1887
pr_info ("%s(%s-%d state %d): still waiting ...\n" , __func__ ,
1888
1888
ch -> sess_name , ch -> qp -> qp_num , ch -> state );
1889
1889
1890
- mutex_lock (& sdev -> mutex );
1890
+ mutex_lock (& sport -> mutex );
1891
1891
return ret == 0 ;
1892
1892
}
1893
1893
1894
1894
static void srpt_set_enabled (struct srpt_port * sport , bool enabled )
1895
- __must_hold (& sdev - > mutex )
1895
+ __must_hold (& sport - > mutex )
1896
1896
{
1897
- struct srpt_device * sdev = sport -> sdev ;
1898
1897
struct srpt_rdma_ch * ch ;
1899
1898
1900
- lockdep_assert_held (& sdev -> mutex );
1899
+ lockdep_assert_held (& sport -> mutex );
1901
1900
1902
1901
if (sport -> enabled == enabled )
1903
1902
return ;
@@ -1906,10 +1905,10 @@ static void srpt_set_enabled(struct srpt_port *sport, bool enabled)
1906
1905
return ;
1907
1906
1908
1907
again :
1909
- list_for_each_entry (ch , & sdev -> rch_list , list ) {
1908
+ list_for_each_entry (ch , & sport -> rch_list , list ) {
1910
1909
if (ch -> sport == sport ) {
1911
1910
pr_info ("%s: closing channel %s-%d\n" ,
1912
- sdev -> device -> name , ch -> sess_name ,
1911
+ sport -> sdev -> device -> name , ch -> sess_name ,
1913
1912
ch -> qp -> qp_num );
1914
1913
if (srpt_disconnect_ch_sync (ch ))
1915
1914
goto again ;
@@ -1929,6 +1928,7 @@ static void srpt_release_channel_work(struct work_struct *w)
1929
1928
{
1930
1929
struct srpt_rdma_ch * ch ;
1931
1930
struct srpt_device * sdev ;
1931
+ struct srpt_port * sport ;
1932
1932
struct se_session * se_sess ;
1933
1933
1934
1934
ch = container_of (w , struct srpt_rdma_ch , release_work );
@@ -1959,11 +1959,12 @@ static void srpt_release_channel_work(struct work_struct *w)
1959
1959
sdev , ch -> rq_size ,
1960
1960
srp_max_req_size , DMA_FROM_DEVICE );
1961
1961
1962
- mutex_lock (& sdev -> mutex );
1962
+ sport = ch -> sport ;
1963
+ mutex_lock (& sport -> mutex );
1963
1964
list_del_rcu (& ch -> list );
1964
- mutex_unlock (& sdev -> mutex );
1965
+ mutex_unlock (& sport -> mutex );
1965
1966
1966
- wake_up (& sdev -> ch_releaseQ );
1967
+ wake_up (& sport -> ch_releaseQ );
1967
1968
1968
1969
kref_put (& ch -> kref , srpt_free_ch );
1969
1970
}
@@ -2036,9 +2037,9 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
2036
2037
if ((req -> req_flags & SRP_MTCH_ACTION ) == SRP_MULTICHAN_SINGLE ) {
2037
2038
rsp -> rsp_flags = SRP_LOGIN_RSP_MULTICHAN_NO_CHAN ;
2038
2039
2039
- mutex_lock (& sdev -> mutex );
2040
+ mutex_lock (& sport -> mutex );
2040
2041
2041
- list_for_each_entry_safe (ch , tmp_ch , & sdev -> rch_list , list ) {
2042
+ list_for_each_entry_safe (ch , tmp_ch , & sport -> rch_list , list ) {
2042
2043
if (!memcmp (ch -> i_port_id , req -> initiator_port_id , 16 )
2043
2044
&& !memcmp (ch -> t_port_id , req -> target_port_id , 16 )
2044
2045
&& param -> port == ch -> sport -> port
@@ -2053,7 +2054,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
2053
2054
}
2054
2055
}
2055
2056
2056
- mutex_unlock (& sdev -> mutex );
2057
+ mutex_unlock (& sport -> mutex );
2057
2058
2058
2059
} else
2059
2060
rsp -> rsp_flags = SRP_LOGIN_RSP_MULTICHAN_MAINTAINED ;
@@ -2205,9 +2206,9 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
2205
2206
goto release_channel ;
2206
2207
}
2207
2208
2208
- mutex_lock (& sdev -> mutex );
2209
- list_add_tail_rcu (& ch -> list , & sdev -> rch_list );
2210
- mutex_unlock (& sdev -> mutex );
2209
+ mutex_lock (& sport -> mutex );
2210
+ list_add_tail_rcu (& ch -> list , & sport -> rch_list );
2211
+ mutex_unlock (& sport -> mutex );
2211
2212
2212
2213
goto out ;
2213
2214
@@ -2559,24 +2560,21 @@ static void srpt_refresh_port_work(struct work_struct *work)
2559
2560
}
2560
2561
2561
2562
/**
2562
- * srpt_release_sdev - disable login and wait for associated channels
2563
- * @sdev : SRPT HCA pointer .
2563
+ * srpt_release_sport - disable login and wait for associated channels
2564
+ * @sport : SRPT HCA port .
2564
2565
*/
2565
- static int srpt_release_sdev (struct srpt_device * sdev )
2566
+ static int srpt_release_sport (struct srpt_port * sport )
2566
2567
{
2567
- int i , res ;
2568
+ int res ;
2568
2569
2569
2570
WARN_ON_ONCE (irqs_disabled ());
2570
2571
2571
- BUG_ON (!sdev );
2572
-
2573
- mutex_lock (& sdev -> mutex );
2574
- for (i = 0 ; i < ARRAY_SIZE (sdev -> port ); i ++ )
2575
- srpt_set_enabled (& sdev -> port [i ], false);
2576
- mutex_unlock (& sdev -> mutex );
2572
+ mutex_lock (& sport -> mutex );
2573
+ srpt_set_enabled (sport , false);
2574
+ mutex_unlock (& sport -> mutex );
2577
2575
2578
- res = wait_event_interruptible (sdev -> ch_releaseQ ,
2579
- list_empty_careful (& sdev -> rch_list ));
2576
+ res = wait_event_interruptible (sport -> ch_releaseQ ,
2577
+ list_empty_careful (& sport -> rch_list ));
2580
2578
if (res )
2581
2579
pr_err ("%s: interrupted.\n" , __func__ );
2582
2580
@@ -2704,9 +2702,7 @@ static void srpt_add_one(struct ib_device *device)
2704
2702
goto err ;
2705
2703
2706
2704
sdev -> device = device ;
2707
- INIT_LIST_HEAD (& sdev -> rch_list );
2708
- init_waitqueue_head (& sdev -> ch_releaseQ );
2709
- mutex_init (& sdev -> mutex );
2705
+ mutex_init (& sdev -> sdev_mutex );
2710
2706
2711
2707
sdev -> pd = ib_alloc_pd (device , 0 );
2712
2708
if (IS_ERR (sdev -> pd ))
@@ -2747,6 +2743,9 @@ static void srpt_add_one(struct ib_device *device)
2747
2743
2748
2744
for (i = 1 ; i <= sdev -> device -> phys_port_cnt ; i ++ ) {
2749
2745
sport = & sdev -> port [i - 1 ];
2746
+ INIT_LIST_HEAD (& sport -> rch_list );
2747
+ init_waitqueue_head (& sport -> ch_releaseQ );
2748
+ mutex_init (& sport -> mutex );
2750
2749
sport -> sdev = sdev ;
2751
2750
sport -> port = i ;
2752
2751
sport -> port_attrib .srp_max_rdma_size = DEFAULT_MAX_RDMA_SIZE ;
@@ -2819,7 +2818,9 @@ static void srpt_remove_one(struct ib_device *device, void *client_data)
2819
2818
spin_lock (& srpt_dev_lock );
2820
2819
list_del (& sdev -> list );
2821
2820
spin_unlock (& srpt_dev_lock );
2822
- srpt_release_sdev (sdev );
2821
+
2822
+ for (i = 0 ; i < sdev -> device -> phys_port_cnt ; i ++ )
2823
+ srpt_release_sport (& sdev -> port [i ]);
2823
2824
2824
2825
srpt_free_srq (sdev );
2825
2826
@@ -2905,11 +2906,11 @@ static void srpt_release_cmd(struct se_cmd *se_cmd)
2905
2906
static void srpt_close_session (struct se_session * se_sess )
2906
2907
{
2907
2908
struct srpt_rdma_ch * ch = se_sess -> fabric_sess_ptr ;
2908
- struct srpt_device * sdev = ch -> sport -> sdev ;
2909
+ struct srpt_port * sport = ch -> sport ;
2909
2910
2910
- mutex_lock (& sdev -> mutex );
2911
+ mutex_lock (& sport -> mutex );
2911
2912
srpt_disconnect_ch_sync (ch );
2912
- mutex_unlock (& sdev -> mutex );
2913
+ mutex_unlock (& sport -> mutex );
2913
2914
}
2914
2915
2915
2916
/**
@@ -3134,18 +3135,24 @@ static ssize_t srpt_tpg_attrib_use_srq_store(struct config_item *item,
3134
3135
if (val != !!val )
3135
3136
return - EINVAL ;
3136
3137
3137
- ret = mutex_lock_interruptible (& sdev -> mutex );
3138
+ ret = mutex_lock_interruptible (& sdev -> sdev_mutex );
3138
3139
if (ret < 0 )
3139
3140
return ret ;
3141
+ ret = mutex_lock_interruptible (& sport -> mutex );
3142
+ if (ret < 0 )
3143
+ goto unlock_sdev ;
3140
3144
enabled = sport -> enabled ;
3141
3145
/* Log out all initiator systems before changing 'use_srq'. */
3142
3146
srpt_set_enabled (sport , false);
3143
3147
sport -> port_attrib .use_srq = val ;
3144
3148
srpt_use_srq (sdev , sport -> port_attrib .use_srq );
3145
3149
srpt_set_enabled (sport , enabled );
3146
- mutex_unlock (& sdev -> mutex );
3150
+ ret = count ;
3151
+ mutex_unlock (& sport -> mutex );
3152
+ unlock_sdev :
3153
+ mutex_unlock (& sdev -> sdev_mutex );
3147
3154
3148
- return count ;
3155
+ return ret ;
3149
3156
}
3150
3157
3151
3158
CONFIGFS_ATTR (srpt_tpg_attrib_ , srp_max_rdma_size );
@@ -3174,7 +3181,6 @@ static ssize_t srpt_tpg_enable_store(struct config_item *item,
3174
3181
{
3175
3182
struct se_portal_group * se_tpg = to_tpg (item );
3176
3183
struct srpt_port * sport = srpt_tpg_to_sport (se_tpg );
3177
- struct srpt_device * sdev = sport -> sdev ;
3178
3184
unsigned long tmp ;
3179
3185
int ret ;
3180
3186
@@ -3189,9 +3195,9 @@ static ssize_t srpt_tpg_enable_store(struct config_item *item,
3189
3195
return - EINVAL ;
3190
3196
}
3191
3197
3192
- mutex_lock (& sdev -> mutex );
3198
+ mutex_lock (& sport -> mutex );
3193
3199
srpt_set_enabled (sport , tmp );
3194
- mutex_unlock (& sdev -> mutex );
3200
+ mutex_unlock (& sport -> mutex );
3195
3201
3196
3202
return count ;
3197
3203
}
0 commit comments