blob: f54d3f5b2e40d077b2137db1f12d65d0683d9882 [file] [log] [blame]
David Howells9ae326a2009-04-03 16:42:41 +01001/* Network filesystem caching backend to use cache files on a premounted
2 * filesystem
3 *
4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/sched.h>
16#include <linux/completion.h>
17#include <linux/slab.h>
18#include <linux/fs.h>
19#include <linux/file.h>
20#include <linux/namei.h>
21#include <linux/mount.h>
22#include <linux/statfs.h>
23#include <linux/sysctl.h>
24#include <linux/miscdevice.h>
David Howellsa18feb52018-04-04 13:41:27 +010025#define CREATE_TRACE_POINTS
David Howells9ae326a2009-04-03 16:42:41 +010026#include "internal.h"
27
28unsigned cachefiles_debug;
29module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
30MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
31
32MODULE_DESCRIPTION("Mounted-filesystem based cache");
33MODULE_AUTHOR("Red Hat, Inc.");
34MODULE_LICENSE("GPL");
35
36struct kmem_cache *cachefiles_object_jar;
37
38static struct miscdevice cachefiles_dev = {
39 .minor = MISC_DYNAMIC_MINOR,
40 .name = "cachefiles",
41 .fops = &cachefiles_daemon_fops,
42};
43
44static void cachefiles_object_init_once(void *_object)
45{
46 struct cachefiles_object *object = _object;
47
48 memset(object, 0, sizeof(*object));
49 spin_lock_init(&object->work_lock);
50}
51
52/*
53 * initialise the fs caching module
54 */
55static int __init cachefiles_init(void)
56{
57 int ret;
58
59 ret = misc_register(&cachefiles_dev);
60 if (ret < 0)
61 goto error_dev;
62
63 /* create an object jar */
64 ret = -ENOMEM;
65 cachefiles_object_jar =
66 kmem_cache_create("cachefiles_object_jar",
67 sizeof(struct cachefiles_object),
68 0,
69 SLAB_HWCACHE_ALIGN,
70 cachefiles_object_init_once);
71 if (!cachefiles_object_jar) {
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070072 pr_notice("Failed to allocate an object jar\n");
David Howells9ae326a2009-04-03 16:42:41 +010073 goto error_object_jar;
74 }
75
76 ret = cachefiles_proc_init();
77 if (ret < 0)
78 goto error_proc;
79
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070080 pr_info("Loaded\n");
David Howells9ae326a2009-04-03 16:42:41 +010081 return 0;
82
83error_proc:
84 kmem_cache_destroy(cachefiles_object_jar);
85error_object_jar:
86 misc_deregister(&cachefiles_dev);
87error_dev:
Fabian Frederick6ff66ac2014-09-25 16:05:27 -070088 pr_err("failed to register: %d\n", ret);
David Howells9ae326a2009-04-03 16:42:41 +010089 return ret;
90}
91
92fs_initcall(cachefiles_init);
93
94/*
95 * clean up on module removal
96 */
97static void __exit cachefiles_exit(void)
98{
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070099 pr_info("Unloading\n");
David Howells9ae326a2009-04-03 16:42:41 +0100100
101 cachefiles_proc_cleanup();
102 kmem_cache_destroy(cachefiles_object_jar);
103 misc_deregister(&cachefiles_dev);
104}
105
106module_exit(cachefiles_exit);