blk-mq: add callback of .cleanup_rq
[linux/fpc-iii.git] / fs / cachefiles / main.c
blobddf0cd58d60cce416b1c00b5bc2d69eca8dc79bb
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Network filesystem caching backend to use cache files on a premounted
3 * filesystem
5 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
6 * Written by David Howells (dhowells@redhat.com)
7 */
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"
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");
28 MODULE_DESCRIPTION("Mounted-filesystem based cache");
29 MODULE_AUTHOR("Red Hat, Inc.");
30 MODULE_LICENSE("GPL");
32 struct kmem_cache *cachefiles_object_jar;
34 static struct miscdevice cachefiles_dev = {
35 .minor = MISC_DYNAMIC_MINOR,
36 .name = "cachefiles",
37 .fops = &cachefiles_daemon_fops,
40 static void cachefiles_object_init_once(void *_object)
42 struct cachefiles_object *object = _object;
44 memset(object, 0, sizeof(*object));
45 spin_lock_init(&object->work_lock);
49 * initialise the fs caching module
51 static int __init cachefiles_init(void)
53 int ret;
55 ret = misc_register(&cachefiles_dev);
56 if (ret < 0)
57 goto error_dev;
59 /* create an object jar */
60 ret = -ENOMEM;
61 cachefiles_object_jar =
62 kmem_cache_create("cachefiles_object_jar",
63 sizeof(struct cachefiles_object),
65 SLAB_HWCACHE_ALIGN,
66 cachefiles_object_init_once);
67 if (!cachefiles_object_jar) {
68 pr_notice("Failed to allocate an object jar\n");
69 goto error_object_jar;
72 ret = cachefiles_proc_init();
73 if (ret < 0)
74 goto error_proc;
76 pr_info("Loaded\n");
77 return 0;
79 error_proc:
80 kmem_cache_destroy(cachefiles_object_jar);
81 error_object_jar:
82 misc_deregister(&cachefiles_dev);
83 error_dev:
84 pr_err("failed to register: %d\n", ret);
85 return ret;
88 fs_initcall(cachefiles_init);
91 * clean up on module removal
93 static void __exit cachefiles_exit(void)
95 pr_info("Unloading\n");
97 cachefiles_proc_cleanup();
98 kmem_cache_destroy(cachefiles_object_jar);
99 misc_deregister(&cachefiles_dev);
102 module_exit(cachefiles_exit);