1 /* cf-main.c: network filesystem caching backend to use cache files on a
2 * premounted filesystem
4 * Copyright (C) 2006 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
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>
19 #include <linux/file.h>
20 #include <linux/namei.h>
21 #include <linux/mount.h>
22 #include <linux/statfs.h>
23 #include <linux/proc_fs.h>
24 #include <linux/sysctl.h>
27 unsigned long cachefiles_debug;
29 static int cachefiles_init(void);
30 static void cachefiles_exit(void);
32 fs_initcall(cachefiles_init);
33 module_exit(cachefiles_exit);
35 MODULE_DESCRIPTION("Mounted-filesystem based cache");
36 MODULE_AUTHOR("Red Hat, Inc.");
37 MODULE_LICENSE("GPL");
39 kmem_cache_t *cachefiles_object_jar;
41 static void cachefiles_object_init_once(void *_object, kmem_cache_t *cachep,
44 struct cachefiles_object *object = _object;
46 switch (flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) {
47 case SLAB_CTOR_CONSTRUCTOR:
48 memset(object, 0, sizeof(*object));
49 fscache_object_init(&object->fscache);
50 init_rwsem(&object->sem);
51 spin_lock_init(&object->work_lock);
52 INIT_LIST_HEAD(&object->read_list);
53 INIT_LIST_HEAD(&object->read_pend_list);
54 INIT_WORK(&object->read_work, &cachefiles_read_copier_work,
56 INIT_LIST_HEAD(&object->write_list);
57 INIT_WORK(&object->write_work, &cachefiles_write_work, object);
65 /*****************************************************************************/
67 * initialise the fs caching module
69 static int __init cachefiles_init(void)
71 struct proc_dir_entry *pde;
74 /* create a proc entry to use as a handle for the userspace daemon */
77 pde = create_proc_entry("cachefiles", 0600, proc_root_fs);
79 kerror("Unable to create /proc/fs/cachefiles");
83 if (cachefiles_sysctl_init() < 0) {
84 kerror("Unable to create sysctl parameters");
85 goto error_object_jar;
88 pde->owner = THIS_MODULE;
89 pde->proc_fops = &cachefiles_proc_fops;
90 cachefiles_proc = pde;
92 /* create an object jar */
93 cachefiles_object_jar =
94 kmem_cache_create("cachefiles_object_jar",
95 sizeof(struct cachefiles_object),
98 cachefiles_object_init_once,
100 if (!cachefiles_object_jar) {
102 "CacheFiles: Failed to allocate an object jar\n");
106 printk(KERN_INFO "CacheFiles: Loaded\n");
110 cachefiles_sysctl_cleanup();
112 remove_proc_entry("cachefiles", proc_root_fs);
114 kerror("failed to register: %d", ret);
118 /*****************************************************************************/
120 * clean up on module removal
122 static void __exit cachefiles_exit(void)
124 printk(KERN_INFO "CacheFiles: Unloading\n");
126 kmem_cache_destroy(cachefiles_object_jar);
127 remove_proc_entry("cachefiles", proc_root_fs);
128 cachefiles_sysctl_cleanup();