blob: 711f13d8c2deac9df76f3fca0bc2522b6096bf53 [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>
25#include "internal.h"
26
27unsigned cachefiles_debug;
28module_param_named(debug, cachefiles_debug, uint, S_IWUSR | S_IRUGO);
29MODULE_PARM_DESC(cachefiles_debug, "CacheFiles debugging mask");
30
31MODULE_DESCRIPTION("Mounted-filesystem based cache");
32MODULE_AUTHOR("Red Hat, Inc.");
33MODULE_LICENSE("GPL");
34
35struct kmem_cache *cachefiles_object_jar;
36
37static struct miscdevice cachefiles_dev = {
38 .minor = MISC_DYNAMIC_MINOR,
39 .name = "cachefiles",
40 .fops = &cachefiles_daemon_fops,
41};
42
43static void cachefiles_object_init_once(void *_object)
44{
45 struct cachefiles_object *object = _object;
46
47 memset(object, 0, sizeof(*object));
48 spin_lock_init(&object->work_lock);
49}
50
51/*
52 * initialise the fs caching module
53 */
54static int __init cachefiles_init(void)
55{
56 int ret;
57
58 ret = misc_register(&cachefiles_dev);
59 if (ret < 0)
60 goto error_dev;
61
62 /* create an object jar */
63 ret = -ENOMEM;
64 cachefiles_object_jar =
65 kmem_cache_create("cachefiles_object_jar",
66 sizeof(struct cachefiles_object),
67 0,
68 SLAB_HWCACHE_ALIGN,
69 cachefiles_object_init_once);
70 if (!cachefiles_object_jar) {
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070071 pr_notice("Failed to allocate an object jar\n");
David Howells9ae326a2009-04-03 16:42:41 +010072 goto error_object_jar;
73 }
74
75 ret = cachefiles_proc_init();
76 if (ret < 0)
77 goto error_proc;
78
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070079 pr_info("Loaded\n");
David Howells9ae326a2009-04-03 16:42:41 +010080 return 0;
81
82error_proc:
83 kmem_cache_destroy(cachefiles_object_jar);
84error_object_jar:
85 misc_deregister(&cachefiles_dev);
86error_dev:
Fabian Frederick6ff66ac2014-09-25 16:05:27 -070087 pr_err("failed to register: %d\n", ret);
David Howells9ae326a2009-04-03 16:42:41 +010088 return ret;
89}
90
91fs_initcall(cachefiles_init);
92
93/*
94 * clean up on module removal
95 */
96static void __exit cachefiles_exit(void)
97{
Fabian Frederick0227d6ab2014-06-06 14:37:33 -070098 pr_info("Unloading\n");
David Howells9ae326a2009-04-03 16:42:41 +010099
100 cachefiles_proc_cleanup();
101 kmem_cache_destroy(cachefiles_object_jar);
102 misc_deregister(&cachefiles_dev);
103}
104
105module_exit(cachefiles_exit);