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.1-fast/drivers/md/dm-crypt.c =================================================================== --- linux-3.1-fast.orig/drivers/md/dm-crypt.c 2011-10-24 17:07:31.000000000 +0200 +++ linux-3.1-fast/drivers/md/dm-crypt.c 2011-10-24 17:08:32.000000000 +0200 @@ -1623,6 +1623,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"}, @@ -1740,9 +1741,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); spin_lock_init(&cc->crypt_thread_spinlock); @@ -1755,18 +1762,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]); } }