22 #include <linux/list.h>
23 #include <linux/bitmap.h>
37 spin_lock(&active_ts_lock);
40 spin_unlock(&active_ts_lock);
45 spin_lock(&inactive_ts_lock);
48 spin_unlock(&inactive_ts_lock);
53 spin_lock(&active_ts_lock);
56 spin_unlock(&active_ts_lock);
63 spin_lock(&inactive_ts_lock);
64 if (list_empty(&inactive_ts_list)) {
65 spin_unlock(&inactive_ts_lock);
74 spin_unlock(&inactive_ts_lock);
81 int allocated_thread_pair_count = 0,
i,
thread_id;
84 for (
i = 0;
i < thread_pair_count;
i++) {
87 pr_err(
"Unable to allocate memory for"
89 return allocated_thread_pair_count;
94 spin_lock(&ts_bitmap_lock);
97 spin_unlock(&ts_bitmap_lock);
99 pr_err(
"bitmap_find_free_region() failed for"
100 " thread_set_bitmap\n");
102 return allocated_thread_pair_count;
121 pr_err(
"Unable to start iscsi_target_tx_thread\n");
129 pr_err(
"Unable to start iscsi_target_rx_thread\n");
134 iscsi_add_ts_to_inactive_list(ts);
135 allocated_thread_pair_count++;
138 pr_debug(
"Spawned %d thread set(s) (%d total threads).\n",
139 allocated_thread_pair_count, allocated_thread_pair_count * 2);
140 return allocated_thread_pair_count;
145 u32 released_count = 0;
148 while ((ts = iscsi_get_ts_from_inactive_list())) {
165 spin_lock(&ts_bitmap_lock);
168 spin_unlock(&ts_bitmap_lock);
175 pr_debug(
"Stopped %d thread set(s) (%d total threads)."
176 "\n", released_count, released_count * 2);
179 static void iscsi_deallocate_extra_thread_sets(
void)
181 u32 orig_count, released_count = 0;
187 ts = iscsi_get_ts_from_inactive_list();
206 spin_lock(&ts_bitmap_lock);
209 spin_unlock(&ts_bitmap_lock);
215 if (released_count) {
216 pr_debug(
"Stopped %d thread set(s) (%d total threads)."
217 "\n", released_count, released_count * 2);
223 iscsi_add_ts_to_active_list(ts);
250 ts = iscsi_get_ts_from_inactive_list();
252 if (allocate_ts == 2)
255 init_completion(&comp);
276 pr_err(
"struct iscsi_conn->thread_set is NULL\n");
298 pr_err(
"struct iscsi_conn->thread_set is NULL\n");
310 int thread_called = 0;
314 pr_err(
"connection or thread set pointer is NULL\n");
390 static void iscsi_check_to_add_additional_sets(
void)
394 spin_lock(&inactive_ts_lock);
396 spin_unlock(&inactive_ts_lock);
397 if (thread_sets_add == 1)
427 iscsi_del_ts_from_active_list(ts);
430 iscsi_deallocate_extra_thread_sets();
432 iscsi_add_ts_to_inactive_list(ts);
447 if (iscsi_signal_thread_pre_handler(ts) < 0)
451 pr_err(
"struct iscsi_thread_set->conn is NULL for"
452 " thread_id: %d, going back to sleep\n", ts->
thread_id);
455 iscsi_check_to_add_additional_sets();
480 iscsi_del_ts_from_active_list(ts);
483 iscsi_deallocate_extra_thread_sets();
485 iscsi_add_ts_to_inactive_list(ts);
499 if (iscsi_signal_thread_pre_handler(ts) < 0)
503 pr_err(
"struct iscsi_thread_set->conn is NULL for "
504 " thread_id: %d, going back to sleep\n",
509 iscsi_check_to_add_additional_sets();
535 pr_err(
"Unable to allocate iscsit_global->ts_bitmap\n");