提交 a3fb1e33 编写于 作者: D Dan Kruchinin 提交者: Herbert Xu

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: NDan Kruchinin <dkruchinin@acm.org>
Signed-off-by: NHerbert Xu <herbert@gondor.apana.org.au>
上级 5e017dc3
...@@ -25,9 +25,11 @@ ...@@ -25,9 +25,11 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/kobject.h>
#include <crypto/pcrypt.h> #include <crypto/pcrypt.h>
struct pcrypt_instance { struct pcrypt_instance {
const char *name;
struct padata_instance *pinst; struct padata_instance *pinst;
struct workqueue_struct *wq; struct workqueue_struct *wq;
...@@ -55,7 +57,7 @@ struct pcrypt_instance { ...@@ -55,7 +57,7 @@ struct pcrypt_instance {
static struct pcrypt_instance pencrypt; static struct pcrypt_instance pencrypt;
static struct pcrypt_instance pdecrypt; static struct pcrypt_instance pdecrypt;
static struct kset *pcrypt_kset;
struct pcrypt_instance_ctx { struct pcrypt_instance_ctx {
struct crypto_spawn spawn; struct crypto_spawn spawn;
...@@ -429,12 +431,25 @@ static int pcrypt_cpumask_change_notify(struct notifier_block *self, ...@@ -429,12 +431,25 @@ static int pcrypt_cpumask_change_notify(struct notifier_block *self,
return 0; return 0;
} }
static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
{
int ret;
pinst->kobj.kset = pcrypt_kset;
ret = kobject_add(&pinst->kobj, NULL, name);
if (!ret)
kobject_uevent(&pinst->kobj, KOBJ_ADD);
return ret;
}
static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt, static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
const char *name) const char *name)
{ {
int ret = -ENOMEM; int ret = -ENOMEM;
struct pcrypt_cpumask *mask; struct pcrypt_cpumask *mask;
pcrypt->name = name;
pcrypt->wq = create_workqueue(name); pcrypt->wq = create_workqueue(name);
if (!pcrypt->wq) if (!pcrypt->wq)
goto err; goto err;
...@@ -459,7 +474,13 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt, ...@@ -459,7 +474,13 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
if (ret) if (ret)
goto err_free_cpumask; goto err_free_cpumask;
ret = pcrypt_sysfs_add(pcrypt->pinst, name);
if (ret)
goto err_unregister_notifier;
return ret; return ret;
err_unregister_notifier:
padata_unregister_cpumask_notifier(pcrypt->pinst, &pcrypt->nblock);
err_free_cpumask: err_free_cpumask:
free_cpumask_var(mask->mask); free_cpumask_var(mask->mask);
kfree(mask); kfree(mask);
...@@ -473,6 +494,7 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt, ...@@ -473,6 +494,7 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
static void __pcrypt_deinit_instance(struct pcrypt_instance *pcrypt) static void __pcrypt_deinit_instance(struct pcrypt_instance *pcrypt)
{ {
kobject_put(&pcrypt->pinst->kobj);
free_cpumask_var(pcrypt->cb_cpumask->mask); free_cpumask_var(pcrypt->cb_cpumask->mask);
kfree(pcrypt->cb_cpumask); kfree(pcrypt->cb_cpumask);
...@@ -491,11 +513,15 @@ static struct crypto_template pcrypt_tmpl = { ...@@ -491,11 +513,15 @@ static struct crypto_template pcrypt_tmpl = {
static int __init pcrypt_init(void) static int __init pcrypt_init(void)
{ {
int err; int err = -ENOMEM;
pcrypt_kset = kset_create_and_add("pcrypt", NULL, kernel_kobj);
if (!pcrypt_kset)
goto err;
err = __pcrypt_init_instance(&pencrypt, "pencrypt"); err = __pcrypt_init_instance(&pencrypt, "pencrypt");
if (err) if (err)
goto err; goto err_unreg_kset;
err = __pcrypt_init_instance(&pdecrypt, "pdecrypt"); err = __pcrypt_init_instance(&pdecrypt, "pdecrypt");
if (err) if (err)
...@@ -508,6 +534,8 @@ static int __init pcrypt_init(void) ...@@ -508,6 +534,8 @@ static int __init pcrypt_init(void)
err_deinit_pencrypt: err_deinit_pencrypt:
__pcrypt_deinit_instance(&pencrypt); __pcrypt_deinit_instance(&pencrypt);
err_unreg_kset:
kset_unregister(pcrypt_kset);
err: err:
return err; return err;
} }
...@@ -517,6 +545,7 @@ static void __exit pcrypt_exit(void) ...@@ -517,6 +545,7 @@ static void __exit pcrypt_exit(void)
__pcrypt_deinit_instance(&pencrypt); __pcrypt_deinit_instance(&pencrypt);
__pcrypt_deinit_instance(&pdecrypt); __pcrypt_deinit_instance(&pdecrypt);
kset_unregister(pcrypt_kset);
crypto_unregister_template(&pcrypt_tmpl); crypto_unregister_template(&pcrypt_tmpl);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册