diff options
author | Dan Kruchinin <dkruchinin@acm.org> | 2010-07-14 06:34:15 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2010-07-19 01:50:20 -0400 |
commit | a3fb1e330dd21d96c2e07dda513ad7e9af8b6ccf (patch) | |
tree | c60e79c7039a0e91e20d13d5e28a64f9de92b59d | |
parent | 5e017dc3f8bc9e4a28983666e6bc00114a2018bb (diff) |
pcrypt: Added sysfs interface to pcrypt
Added sysfs interface to pcrypt. Now pcrypt subsystem creates two
sysfs directories with corresponding padata sysfs objects:
/sys/kernel/pcrypt/[pencrypt|pdecrypt]
Signed-off-by: Dan Kruchinin <dkruchinin@acm.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/pcrypt.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c index c9662e25595e..7153a50bce27 100644 --- a/crypto/pcrypt.c +++ b/crypto/pcrypt.c | |||
@@ -25,9 +25,11 @@ | |||
25 | #include <linux/module.h> | 25 | #include <linux/module.h> |
26 | #include <linux/slab.h> | 26 | #include <linux/slab.h> |
27 | #include <linux/notifier.h> | 27 | #include <linux/notifier.h> |
28 | #include <linux/kobject.h> | ||
28 | #include <crypto/pcrypt.h> | 29 | #include <crypto/pcrypt.h> |
29 | 30 | ||
30 | struct pcrypt_instance { | 31 | struct pcrypt_instance { |
32 | const char *name; | ||
31 | struct padata_instance *pinst; | 33 | struct padata_instance *pinst; |
32 | struct workqueue_struct *wq; | 34 | struct workqueue_struct *wq; |
33 | 35 | ||
@@ -55,7 +57,7 @@ struct pcrypt_instance { | |||
55 | 57 | ||
56 | static struct pcrypt_instance pencrypt; | 58 | static struct pcrypt_instance pencrypt; |
57 | static struct pcrypt_instance pdecrypt; | 59 | static struct pcrypt_instance pdecrypt; |
58 | 60 | static struct kset *pcrypt_kset; | |
59 | 61 | ||
60 | struct pcrypt_instance_ctx { | 62 | struct pcrypt_instance_ctx { |
61 | struct crypto_spawn spawn; | 63 | struct crypto_spawn spawn; |
@@ -429,12 +431,25 @@ static int pcrypt_cpumask_change_notify(struct notifier_block *self, | |||
429 | return 0; | 431 | return 0; |
430 | } | 432 | } |
431 | 433 | ||
434 | static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name) | ||
435 | { | ||
436 | int ret; | ||
437 | |||
438 | pinst->kobj.kset = pcrypt_kset; | ||
439 | ret = kobject_add(&pinst->kobj, NULL, name); | ||
440 | if (!ret) | ||
441 | kobject_uevent(&pinst->kobj, KOBJ_ADD); | ||
442 | |||
443 | return ret; | ||
444 | } | ||
445 | |||
432 | static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt, | 446 | static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt, |
433 | const char *name) | 447 | const char *name) |
434 | { | 448 | { |
435 | int ret = -ENOMEM; | 449 | int ret = -ENOMEM; |
436 | struct pcrypt_cpumask *mask; | 450 | struct pcrypt_cpumask *mask; |
437 | 451 | ||
452 | pcrypt->name = name; | ||
438 | pcrypt->wq = create_workqueue(name); | 453 | pcrypt->wq = create_workqueue(name); |
439 | if (!pcrypt->wq) | 454 | if (!pcrypt->wq) |
440 | goto err; | 455 | goto err; |
@@ -459,7 +474,13 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt, | |||
459 | if (ret) | 474 | if (ret) |
460 | goto err_free_cpumask; | 475 | goto err_free_cpumask; |
461 | 476 | ||
477 | ret = pcrypt_sysfs_add(pcrypt->pinst, name); | ||
478 | if (ret) | ||
479 | goto err_unregister_notifier; | ||
480 | |||
462 | return ret; | 481 | return ret; |
482 | err_unregister_notifier: | ||
483 | padata_unregister_cpumask_notifier(pcrypt->pinst, &pcrypt->nblock); | ||
463 | err_free_cpumask: | 484 | err_free_cpumask: |
464 | free_cpumask_var(mask->mask); | 485 | free_cpumask_var(mask->mask); |
465 | kfree(mask); | 486 | kfree(mask); |
@@ -473,6 +494,7 @@ err: | |||
473 | 494 | ||
474 | static void __pcrypt_deinit_instance(struct pcrypt_instance *pcrypt) | 495 | static void __pcrypt_deinit_instance(struct pcrypt_instance *pcrypt) |
475 | { | 496 | { |
497 | kobject_put(&pcrypt->pinst->kobj); | ||
476 | free_cpumask_var(pcrypt->cb_cpumask->mask); | 498 | free_cpumask_var(pcrypt->cb_cpumask->mask); |
477 | kfree(pcrypt->cb_cpumask); | 499 | kfree(pcrypt->cb_cpumask); |
478 | 500 | ||
@@ -491,11 +513,15 @@ static struct crypto_template pcrypt_tmpl = { | |||
491 | 513 | ||
492 | static int __init pcrypt_init(void) | 514 | static int __init pcrypt_init(void) |
493 | { | 515 | { |
494 | int err; | 516 | int err = -ENOMEM; |
517 | |||
518 | pcrypt_kset = kset_create_and_add("pcrypt", NULL, kernel_kobj); | ||
519 | if (!pcrypt_kset) | ||
520 | goto err; | ||
495 | 521 | ||
496 | err = __pcrypt_init_instance(&pencrypt, "pencrypt"); | 522 | err = __pcrypt_init_instance(&pencrypt, "pencrypt"); |
497 | if (err) | 523 | if (err) |
498 | goto err; | 524 | goto err_unreg_kset; |
499 | 525 | ||
500 | err = __pcrypt_init_instance(&pdecrypt, "pdecrypt"); | 526 | err = __pcrypt_init_instance(&pdecrypt, "pdecrypt"); |
501 | if (err) | 527 | if (err) |
@@ -508,6 +534,8 @@ static int __init pcrypt_init(void) | |||
508 | 534 | ||
509 | err_deinit_pencrypt: | 535 | err_deinit_pencrypt: |
510 | __pcrypt_deinit_instance(&pencrypt); | 536 | __pcrypt_deinit_instance(&pencrypt); |
537 | err_unreg_kset: | ||
538 | kset_unregister(pcrypt_kset); | ||
511 | err: | 539 | err: |
512 | return err; | 540 | return err; |
513 | } | 541 | } |
@@ -517,6 +545,7 @@ static void __exit pcrypt_exit(void) | |||
517 | __pcrypt_deinit_instance(&pencrypt); | 545 | __pcrypt_deinit_instance(&pencrypt); |
518 | __pcrypt_deinit_instance(&pdecrypt); | 546 | __pcrypt_deinit_instance(&pdecrypt); |
519 | 547 | ||
548 | kset_unregister(pcrypt_kset); | ||
520 | crypto_unregister_template(&pcrypt_tmpl); | 549 | crypto_unregister_template(&pcrypt_tmpl); |
521 | } | 550 | } |
522 | 551 | ||