1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Network filesystem caching backend to use cache files on a premounted
5 * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
6 * Written by David Howells (dhowells@redhat.com)
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>
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 #include <linux/netfs.h>
22 #include <trace/events/netfs.h>
23 #define CREATE_TRACE_POINTS
26 unsigned cachefiles_debug
;
27 module_param_named(debug
, cachefiles_debug
, uint
, S_IWUSR
| S_IRUGO
);
28 MODULE_PARM_DESC(cachefiles_debug
, "CacheFiles debugging mask");
30 MODULE_DESCRIPTION("Mounted-filesystem based cache");
31 MODULE_AUTHOR("Red Hat, Inc.");
32 MODULE_LICENSE("GPL");
34 struct kmem_cache
*cachefiles_object_jar
;
36 static struct miscdevice cachefiles_dev
= {
37 .minor
= MISC_DYNAMIC_MINOR
,
39 .fops
= &cachefiles_daemon_fops
,
43 * initialise the fs caching module
45 static int __init
cachefiles_init(void)
49 ret
= cachefiles_register_error_injection();
52 ret
= misc_register(&cachefiles_dev
);
56 /* create an object jar */
58 cachefiles_object_jar
=
59 kmem_cache_create("cachefiles_object_jar",
60 sizeof(struct cachefiles_object
),
61 0, SLAB_HWCACHE_ALIGN
, NULL
);
62 if (!cachefiles_object_jar
) {
63 pr_notice("Failed to allocate an object jar\n");
64 goto error_object_jar
;
71 misc_deregister(&cachefiles_dev
);
73 cachefiles_unregister_error_injection();
75 pr_err("failed to register: %d\n", ret
);
79 fs_initcall(cachefiles_init
);
82 * clean up on module removal
84 static void __exit
cachefiles_exit(void)
86 pr_info("Unloading\n");
88 kmem_cache_destroy(cachefiles_object_jar
);
89 misc_deregister(&cachefiles_dev
);
90 cachefiles_unregister_error_injection();
93 module_exit(cachefiles_exit
);