blob: 0649e7e6013410d47e0b11ba3b90a4aff253f052 [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
David Howells9ae326a2009-04-03 16:42:41 +01002/* 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 ([email protected])
David Howells9ae326a2009-04-03 16:42:41 +01007 */
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>
David Howellsa18feb52018-04-04 13:41:27 +010021#define CREATE_TRACE_POINTS
David Howells9ae326a2009-04-03 16:42:41 +010022#include "internal.h"
23
24unsigned cachefiles_debug;
25module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
26MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
27
28MODULE_DESCRIPTION("Mounted-filesystem based cache");
29MODULE_AUTHOR("Red Hat, Inc.");
30MODULE_LICENSE("GPL");
Greg Kroah-Hartmand483eed2020-07-02 12:51:03 +020031MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
David Howells9ae326a2009-04-03 16:42:41 +010032
33struct kmem_cache *cachefiles_object_jar;
34
35static struct miscdevice cachefiles_dev = {
36 .minor = MISC_DYNAMIC_MINOR,
37 .name = "cachefiles",
38 .fops = &cachefiles_daemon_fops,
39};
40
41static 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 */
52static 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) {
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070069 pr_notice("Failed to allocate an object jar\n");
David Howells9ae326a2009-04-03 16:42:41 +010070 goto error_object_jar;
71 }
72
73 ret = cachefiles_proc_init();
74 if (ret < 0)
75 goto error_proc;
76
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070077 pr_info("Loaded\n");
David Howells9ae326a2009-04-03 16:42:41 +010078 return 0;
79
80error_proc:
81 kmem_cache_destroy(cachefiles_object_jar);
82error_object_jar:
83 misc_deregister(&cachefiles_dev);
84error_dev:
Fabian Frederick6ff66ac2014-09-25 16:05:27 -070085 pr_err("failed to register: %d\n", ret);
David Howells9ae326a2009-04-03 16:42:41 +010086 return ret;
87}
88
89fs_initcall(cachefiles_init);
90
91/*
92 * clean up on module removal
93 */
94static void __exit cachefiles_exit(void)
95{
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070096 pr_info("Unloading\n");
David Howells9ae326a2009-04-03 16:42:41 +010097
98 cachefiles_proc_cleanup();
99 kmem_cache_destroy(cachefiles_object_jar);
100 misc_deregister(&cachefiles_dev);
101}
102
103module_exit(cachefiles_exit);