0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/init.h>
0011 #include <linux/sched.h>
0012 #include <linux/completion.h>
0013 #include <linux/slab.h>
0014 #include <linux/fs.h>
0015 #include <linux/file.h>
0016 #include <linux/namei.h>
0017 #include <linux/mount.h>
0018 #include <linux/statfs.h>
0019 #include <linux/sysctl.h>
0020 #include <linux/miscdevice.h>
0021 #include <linux/netfs.h>
0022 #include <trace/events/netfs.h>
0023 #define CREATE_TRACE_POINTS
0024 #include "internal.h"
0025
0026 unsigned cachefiles_debug;
0027 module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
0028 MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
0029
0030 MODULE_DESCRIPTION("Mounted-filesystem based cache");
0031 MODULE_AUTHOR("Red Hat, Inc.");
0032 MODULE_LICENSE("GPL");
0033
0034 struct kmem_cache *cachefiles_object_jar;
0035
0036 static struct miscdevice cachefiles_dev = {
0037 .minor = MISC_DYNAMIC_MINOR,
0038 .name = "cachefiles",
0039 .fops = &cachefiles_daemon_fops,
0040 };
0041
0042
0043
0044
0045 static int __init cachefiles_init(void)
0046 {
0047 int ret;
0048
0049 ret = cachefiles_register_error_injection();
0050 if (ret < 0)
0051 goto error_einj;
0052 ret = misc_register(&cachefiles_dev);
0053 if (ret < 0)
0054 goto error_dev;
0055
0056
0057 ret = -ENOMEM;
0058 cachefiles_object_jar =
0059 kmem_cache_create("cachefiles_object_jar",
0060 sizeof(struct cachefiles_object),
0061 0, SLAB_HWCACHE_ALIGN, NULL);
0062 if (!cachefiles_object_jar) {
0063 pr_notice("Failed to allocate an object jar\n");
0064 goto error_object_jar;
0065 }
0066
0067 pr_info("Loaded\n");
0068 return 0;
0069
0070 error_object_jar:
0071 misc_deregister(&cachefiles_dev);
0072 error_dev:
0073 cachefiles_unregister_error_injection();
0074 error_einj:
0075 pr_err("failed to register: %d\n", ret);
0076 return ret;
0077 }
0078
0079 fs_initcall(cachefiles_init);
0080
0081
0082
0083
0084 static void __exit cachefiles_exit(void)
0085 {
0086 pr_info("Unloading\n");
0087
0088 kmem_cache_destroy(cachefiles_object_jar);
0089 misc_deregister(&cachefiles_dev);
0090 cachefiles_unregister_error_injection();
0091 }
0092
0093 module_exit(cachefiles_exit);