dm-crypt: add a variable num_threads Add a variable num_threads. Later, it could be set when parsing the arguments. Signed-off-by: Mikulas Patocka --- drivers/md/dm-crypt.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) Index: linux-3.2-fast/drivers/md/dm-crypt.c =================================================================== --- linux-3.2-fast.orig/drivers/md/dm-crypt.c 2012-01-31 02:30:30.000000000 +0100 +++ linux-3.2-fast/drivers/md/dm-crypt.c 2012-01-31 02:30:35.000000000 +0100 @@ -1634,6 +1634,7 @@ static int crypt_ctr(struct dm_target *t struct dm_arg_set as; const char *opt_string; int i; + unsigned num_threads = num_online_cpus(); static struct dm_arg _args[] = { {0, 1, "Invalid number of feature args"}, @@ -1751,9 +1752,15 @@ static int crypt_ctr(struct dm_target *t goto bad; } - for (i = 0; i < NR_CPUS; i++) - if (cpu_online(i)) - cc->crypt_threads_size = i + 1; + if (num_threads == num_online_cpus()) { + for (i = 0; i < NR_CPUS; i++) + if (cpu_online(i)) + cc->crypt_threads_size = i + 1; + } else { + if (num_threads > INT_MAX / sizeof(struct task_struct *)) + num_threads = INT_MAX / sizeof(struct task_struct *); + cc->crypt_threads_size = num_threads; + } init_waitqueue_head(&cc->crypt_thread_wait); INIT_LIST_HEAD(&cc->crypt_thread_list); @@ -1765,18 +1772,31 @@ static int crypt_ctr(struct dm_target *t goto bad; } - for (i = 0; i < cc->crypt_threads_size; i++) { - if (cpu_online(i)) { - cc->crypt_threads[i] = kthread_create_on_node( - dmcrypt_thread, cc, cpu_to_node(i), - "dmcryptd/%d", i); + if (num_threads == num_online_cpus()) + for (i = 0; i < cc->crypt_threads_size; i++) { + if (cpu_online(i)) { + cc->crypt_threads[i] = kthread_create_on_node( + dmcrypt_thread, cc, cpu_to_node(i), + "dmcryptd/%d", i); + if (IS_ERR(cc->crypt_threads[i])) { + ret = PTR_ERR(cc->crypt_threads[i]); + cc->crypt_threads[i] = NULL; + ti->error = "Couldn't spawn thread"; + goto bad; + } + kthread_bind(cc->crypt_threads[i], i); + wake_up_process(cc->crypt_threads[i]); + } + } else { + for (i = 0; i < cc->crypt_threads_size; i++) { + cc->crypt_threads[i] = kthread_create( + dmcrypt_thread, cc, "dmcryptd/%d", i); if (IS_ERR(cc->crypt_threads[i])) { ret = PTR_ERR(cc->crypt_threads[i]); cc->crypt_threads[i] = NULL; ti->error = "Couldn't spawn thread"; goto bad; } - kthread_bind(cc->crypt_threads[i], i); wake_up_process(cc->crypt_threads[i]); } }