@@ -537,7 +537,7 @@ static struct iscsit_transport iscsi_target_transport = {
537
537
538
538
static int __init iscsi_target_init_module (void )
539
539
{
540
- int ret = 0 ;
540
+ int ret = 0 , size ;
541
541
542
542
pr_debug ("iSCSI-Target " ISCSIT_VERSION "\n" );
543
543
@@ -546,6 +546,7 @@ static int __init iscsi_target_init_module(void)
546
546
pr_err ("Unable to allocate memory for iscsit_global\n" );
547
547
return -1 ;
548
548
}
549
+ spin_lock_init (& iscsit_global -> ts_bitmap_lock );
549
550
mutex_init (& auth_id_lock );
550
551
spin_lock_init (& sess_idr_lock );
551
552
idr_init (& tiqn_idr );
@@ -555,15 +556,11 @@ static int __init iscsi_target_init_module(void)
555
556
if (ret < 0 )
556
557
goto out ;
557
558
558
- ret = iscsi_thread_set_init ();
559
- if (ret < 0 )
559
+ size = BITS_TO_LONGS (ISCSIT_BITMAP_BITS ) * sizeof (long );
560
+ iscsit_global -> ts_bitmap = vzalloc (size );
561
+ if (!iscsit_global -> ts_bitmap ) {
562
+ pr_err ("Unable to allocate iscsit_global->ts_bitmap\n" );
560
563
goto configfs_out ;
561
-
562
- if (iscsi_allocate_thread_sets (TARGET_THREAD_SET_COUNT ) !=
563
- TARGET_THREAD_SET_COUNT ) {
564
- pr_err ("iscsi_allocate_thread_sets() returned"
565
- " unexpected value!\n" );
566
- goto ts_out1 ;
567
564
}
568
565
569
566
lio_qr_cache = kmem_cache_create ("lio_qr_cache" ,
@@ -572,7 +569,7 @@ static int __init iscsi_target_init_module(void)
572
569
if (!lio_qr_cache ) {
573
570
pr_err ("nable to kmem_cache_create() for"
574
571
" lio_qr_cache\n" );
575
- goto ts_out2 ;
572
+ goto bitmap_out ;
576
573
}
577
574
578
575
lio_dr_cache = kmem_cache_create ("lio_dr_cache" ,
@@ -617,10 +614,8 @@ static int __init iscsi_target_init_module(void)
617
614
kmem_cache_destroy (lio_dr_cache );
618
615
qr_out :
619
616
kmem_cache_destroy (lio_qr_cache );
620
- ts_out2 :
621
- iscsi_deallocate_thread_sets ();
622
- ts_out1 :
623
- iscsi_thread_set_free ();
617
+ bitmap_out :
618
+ vfree (iscsit_global -> ts_bitmap );
624
619
configfs_out :
625
620
iscsi_target_deregister_configfs ();
626
621
out :
@@ -630,8 +625,6 @@ static int __init iscsi_target_init_module(void)
630
625
631
626
static void __exit iscsi_target_cleanup_module (void )
632
627
{
633
- iscsi_deallocate_thread_sets ();
634
- iscsi_thread_set_free ();
635
628
iscsit_release_discovery_tpg ();
636
629
iscsit_unregister_transport (& iscsi_target_transport );
637
630
kmem_cache_destroy (lio_qr_cache );
@@ -641,6 +634,7 @@ static void __exit iscsi_target_cleanup_module(void)
641
634
642
635
iscsi_target_deregister_configfs ();
643
636
637
+ vfree (iscsit_global -> ts_bitmap );
644
638
kfree (iscsit_global );
645
639
}
646
640
@@ -3709,17 +3703,16 @@ static int iscsit_send_reject(
3709
3703
3710
3704
void iscsit_thread_get_cpumask (struct iscsi_conn * conn )
3711
3705
{
3712
- struct iscsi_thread_set * ts = conn -> thread_set ;
3713
3706
int ord , cpu ;
3714
3707
/*
3715
- * thread_id is assigned from iscsit_global->ts_bitmap from
3716
- * within iscsi_thread_set.c:iscsi_allocate_thread_sets ()
3708
+ * bitmap_id is assigned from iscsit_global->ts_bitmap from
3709
+ * within iscsit_start_kthreads ()
3717
3710
*
3718
- * Here we use thread_id to determine which CPU that this
3719
- * iSCSI connection's iscsi_thread_set will be scheduled to
3711
+ * Here we use bitmap_id to determine which CPU that this
3712
+ * iSCSI connection's RX/TX threads will be scheduled to
3720
3713
* execute upon.
3721
3714
*/
3722
- ord = ts -> thread_id % cpumask_weight (cpu_online_mask );
3715
+ ord = conn -> bitmap_id % cpumask_weight (cpu_online_mask );
3723
3716
for_each_online_cpu (cpu ) {
3724
3717
if (ord -- == 0 ) {
3725
3718
cpumask_set_cpu (cpu , conn -> conn_cpumask );
@@ -3908,7 +3901,7 @@ iscsit_response_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state)
3908
3901
switch (state ) {
3909
3902
case ISTATE_SEND_LOGOUTRSP :
3910
3903
if (!iscsit_logout_post_handler (cmd , conn ))
3911
- goto restart ;
3904
+ return - ECONNRESET ;
3912
3905
/* fall through */
3913
3906
case ISTATE_SEND_STATUS :
3914
3907
case ISTATE_SEND_ASYNCMSG :
@@ -3936,8 +3929,6 @@ iscsit_response_queue(struct iscsi_conn *conn, struct iscsi_cmd *cmd, int state)
3936
3929
3937
3930
err :
3938
3931
return -1 ;
3939
- restart :
3940
- return - EAGAIN ;
3941
3932
}
3942
3933
3943
3934
static int iscsit_handle_response_queue (struct iscsi_conn * conn )
@@ -3964,21 +3955,13 @@ static int iscsit_handle_response_queue(struct iscsi_conn *conn)
3964
3955
int iscsi_target_tx_thread (void * arg )
3965
3956
{
3966
3957
int ret = 0 ;
3967
- struct iscsi_conn * conn ;
3968
- struct iscsi_thread_set * ts = arg ;
3958
+ struct iscsi_conn * conn = arg ;
3969
3959
/*
3970
3960
* Allow ourselves to be interrupted by SIGINT so that a
3971
3961
* connection recovery / failure event can be triggered externally.
3972
3962
*/
3973
3963
allow_signal (SIGINT );
3974
3964
3975
- restart :
3976
- conn = iscsi_tx_thread_pre_handler (ts );
3977
- if (!conn )
3978
- goto out ;
3979
-
3980
- ret = 0 ;
3981
-
3982
3965
while (!kthread_should_stop ()) {
3983
3966
/*
3984
3967
* Ensure that both TX and RX per connection kthreads
@@ -3987,11 +3970,9 @@ int iscsi_target_tx_thread(void *arg)
3987
3970
iscsit_thread_check_cpumask (conn , current , 1 );
3988
3971
3989
3972
wait_event_interruptible (conn -> queues_wq ,
3990
- !iscsit_conn_all_queues_empty (conn ) ||
3991
- ts -> status == ISCSI_THREAD_SET_RESET );
3973
+ !iscsit_conn_all_queues_empty (conn ));
3992
3974
3993
- if ((ts -> status == ISCSI_THREAD_SET_RESET ) ||
3994
- signal_pending (current ))
3975
+ if (signal_pending (current ))
3995
3976
goto transport_err ;
3996
3977
3997
3978
get_immediate :
@@ -4002,15 +3983,14 @@ int iscsi_target_tx_thread(void *arg)
4002
3983
ret = iscsit_handle_response_queue (conn );
4003
3984
if (ret == 1 )
4004
3985
goto get_immediate ;
4005
- else if (ret == - EAGAIN )
4006
- goto restart ;
3986
+ else if (ret == - ECONNRESET )
3987
+ goto out ;
4007
3988
else if (ret < 0 )
4008
3989
goto transport_err ;
4009
3990
}
4010
3991
4011
3992
transport_err :
4012
3993
iscsit_take_action_for_connection_exit (conn );
4013
- goto restart ;
4014
3994
out :
4015
3995
return 0 ;
4016
3996
}
@@ -4105,20 +4085,14 @@ int iscsi_target_rx_thread(void *arg)
4105
4085
int ret ;
4106
4086
u8 buffer [ISCSI_HDR_LEN ], opcode ;
4107
4087
u32 checksum = 0 , digest = 0 ;
4108
- struct iscsi_conn * conn = NULL ;
4109
- struct iscsi_thread_set * ts = arg ;
4088
+ struct iscsi_conn * conn = arg ;
4110
4089
struct kvec iov ;
4111
4090
/*
4112
4091
* Allow ourselves to be interrupted by SIGINT so that a
4113
4092
* connection recovery / failure event can be triggered externally.
4114
4093
*/
4115
4094
allow_signal (SIGINT );
4116
4095
4117
- restart :
4118
- conn = iscsi_rx_thread_pre_handler (ts );
4119
- if (!conn )
4120
- goto out ;
4121
-
4122
4096
if (conn -> conn_transport -> transport_type == ISCSI_INFINIBAND ) {
4123
4097
struct completion comp ;
4124
4098
int rc ;
@@ -4128,7 +4102,7 @@ int iscsi_target_rx_thread(void *arg)
4128
4102
if (rc < 0 )
4129
4103
goto transport_err ;
4130
4104
4131
- goto out ;
4105
+ goto transport_err ;
4132
4106
}
4133
4107
4134
4108
while (!kthread_should_stop ()) {
@@ -4204,8 +4178,6 @@ int iscsi_target_rx_thread(void *arg)
4204
4178
if (!signal_pending (current ))
4205
4179
atomic_set (& conn -> transport_failed , 1 );
4206
4180
iscsit_take_action_for_connection_exit (conn );
4207
- goto restart ;
4208
- out :
4209
4181
return 0 ;
4210
4182
}
4211
4183
@@ -4261,7 +4233,24 @@ int iscsit_close_connection(
4261
4233
*/
4262
4234
complete (& conn -> conn_logout_comp );
4263
4235
4264
- iscsi_release_thread_set (conn );
4236
+ if (!strcmp (current -> comm , ISCSI_RX_THREAD_NAME )) {
4237
+ if (conn -> tx_thread &&
4238
+ cmpxchg (& conn -> tx_thread_active , true, false)) {
4239
+ send_sig (SIGINT , conn -> tx_thread , 1 );
4240
+ kthread_stop (conn -> tx_thread );
4241
+ }
4242
+ } else if (!strcmp (current -> comm , ISCSI_TX_THREAD_NAME )) {
4243
+ if (conn -> rx_thread &&
4244
+ cmpxchg (& conn -> rx_thread_active , true, false)) {
4245
+ send_sig (SIGINT , conn -> rx_thread , 1 );
4246
+ kthread_stop (conn -> rx_thread );
4247
+ }
4248
+ }
4249
+
4250
+ spin_lock (& iscsit_global -> ts_bitmap_lock );
4251
+ bitmap_release_region (iscsit_global -> ts_bitmap , conn -> bitmap_id ,
4252
+ get_order (1 ));
4253
+ spin_unlock (& iscsit_global -> ts_bitmap_lock );
4265
4254
4266
4255
iscsit_stop_timers_for_cmds (conn );
4267
4256
iscsit_stop_nopin_response_timer (conn );
@@ -4539,29 +4528,26 @@ static void iscsit_logout_post_handler_closesession(
4539
4528
struct iscsi_conn * conn )
4540
4529
{
4541
4530
struct iscsi_session * sess = conn -> sess ;
4542
-
4543
- iscsi_set_thread_clear (conn , ISCSI_CLEAR_TX_THREAD );
4544
- iscsi_set_thread_set_signal (conn , ISCSI_SIGNAL_TX_THREAD );
4531
+ int sleep = cmpxchg (& conn -> tx_thread_active , true, false);
4545
4532
4546
4533
atomic_set (& conn -> conn_logout_remove , 0 );
4547
4534
complete (& conn -> conn_logout_comp );
4548
4535
4549
4536
iscsit_dec_conn_usage_count (conn );
4550
- iscsit_stop_session (sess , 1 , 1 );
4537
+ iscsit_stop_session (sess , sleep , sleep );
4551
4538
iscsit_dec_session_usage_count (sess );
4552
4539
target_put_session (sess -> se_sess );
4553
4540
}
4554
4541
4555
4542
static void iscsit_logout_post_handler_samecid (
4556
4543
struct iscsi_conn * conn )
4557
4544
{
4558
- iscsi_set_thread_clear (conn , ISCSI_CLEAR_TX_THREAD );
4559
- iscsi_set_thread_set_signal (conn , ISCSI_SIGNAL_TX_THREAD );
4545
+ int sleep = cmpxchg (& conn -> tx_thread_active , true, false);
4560
4546
4561
4547
atomic_set (& conn -> conn_logout_remove , 0 );
4562
4548
complete (& conn -> conn_logout_comp );
4563
4549
4564
- iscsit_cause_connection_reinstatement (conn , 1 );
4550
+ iscsit_cause_connection_reinstatement (conn , sleep );
4565
4551
iscsit_dec_conn_usage_count (conn );
4566
4552
}
4567
4553
0 commit comments