• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Network filesystem caching backend to use cache files on a premounted
3  * filesystem
4  *
5  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
6  * Written by David Howells (dhowells@redhat.com)
7  */
8 
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/sched.h>
12 #include <linux/completion.h>
13 #include <linux/slab.h>
14 #include <linux/fs.h>
15 #include <linux/file.h>
16 #include <linux/namei.h>
17 #include <linux/mount.h>
18 #include <linux/statfs.h>
19 #include <linux/sysctl.h>
20 #include <linux/miscdevice.h>
21 #define CREATE_TRACE_POINTS
22 #include "internal.h"
23 
24 unsigned cachefiles_debug;
25 module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
26 MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
27 
28 MODULE_DESCRIPTION("Mounted-filesystem based cache");
29 MODULE_AUTHOR("Red Hat, Inc.");
30 MODULE_LICENSE("GPL");
31 MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
32 
33 struct kmem_cache *cachefiles_object_jar;
34 
35 static struct miscdevice cachefiles_dev = {
36 	.minor	= MISC_DYNAMIC_MINOR,
37 	.name	= "cachefiles",
38 	.fops	= &cachefiles_daemon_fops,
39 };
40 
cachefiles_object_init_once(void * _object)41 static void cachefiles_object_init_once(void *_object)
42 {
43 	struct cachefiles_object *object = _object;
44 
45 	memset(object, 0, sizeof(*object));
46 	spin_lock_init(&object->work_lock);
47 }
48 
49 /*
50  * initialise the fs caching module
51  */
cachefiles_init(void)52 static int __init cachefiles_init(void)
53 {
54 	int ret;
55 
56 	ret = misc_register(&cachefiles_dev);
57 	if (ret < 0)
58 		goto error_dev;
59 
60 	/* create an object jar */
61 	ret = -ENOMEM;
62 	cachefiles_object_jar =
63 		kmem_cache_create("cachefiles_object_jar",
64 				  sizeof(struct cachefiles_object),
65 				  0,
66 				  SLAB_HWCACHE_ALIGN,
67 				  cachefiles_object_init_once);
68 	if (!cachefiles_object_jar) {
69 		pr_notice("Failed to allocate an object jar\n");
70 		goto error_object_jar;
71 	}
72 
73 	pr_info("Loaded\n");
74 	return 0;
75 
76 error_object_jar:
77 	misc_deregister(&cachefiles_dev);
78 error_dev:
79 	pr_err("failed to register: %d\n", ret);
80 	return ret;
81 }
82 
83 fs_initcall(cachefiles_init);
84 
85 /*
86  * clean up on module removal
87  */
cachefiles_exit(void)88 static void __exit cachefiles_exit(void)
89 {
90 	pr_info("Unloading\n");
91 
92 	kmem_cache_destroy(cachefiles_object_jar);
93 	misc_deregister(&cachefiles_dev);
94 }
95 
96 module_exit(cachefiles_exit);
97