Whamcloud - gitweb
merge b_devel into HEAD, which will become 0.7.3
[fs/lustre-release.git] / lustre / llite / super25.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light Super operations
5  *
6  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LLITE
25
26 #include <linux/module.h>
27 #include <linux/random.h>
28 #include <linux/version.h>
29 #include <linux/lustre_lite.h>
30 #include <linux/lustre_ha.h>
31 #include <linux/lustre_dlm.h>
32 #include <linux/init.h>
33 #include <linux/fs.h>
34 #include <linux/lprocfs_status.h>
35 #include "llite_internal.h"
36
37 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
38
39 struct super_block * ll_get_sb(struct file_system_type *fs_type,
40                                int flags, const char *devname, void * data)
41 {
42         /* calls back in fill super */
43         return get_sb_nodev(fs_type, flags, data, ll_fill_super);
44 }
45
46 static kmem_cache_t *ll_inode_cachep;
47
48 static struct inode *ll_alloc_inode(struct super_block *sb)
49 {
50         struct ll_inode_info *lli;
51         lprocfs_counter_incr((ll_s2sbi(sb))->ll_stats, LPROC_LL_ALLOC_INODE);
52         OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
53         if (lli == NULL)
54                 return NULL;
55
56         inode_init_once(&lli->lli_vfs_inode);
57         ll_lli_init(lli);
58
59         return &lli->lli_vfs_inode;
60 }
61
62 static void ll_destroy_inode(struct inode *inode)
63 {
64         struct ll_inode_info *ptr = ll_i2info(inode);
65         OBD_SLAB_FREE(ptr, ll_inode_cachep, sizeof(*ptr));
66 }
67
68 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
69 {
70         struct ll_inode_info *lli = foo;
71
72         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
73             SLAB_CTOR_CONSTRUCTOR)
74                 inode_init_once(&lli->lli_vfs_inode);
75 }
76
77 int ll_init_inodecache(void)
78 {
79         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
80                                             sizeof(struct ll_inode_info),
81                                             0, SLAB_HWCACHE_ALIGN,
82                                             init_once, NULL);
83         if (ll_inode_cachep == NULL)
84                 return -ENOMEM;
85         return 0;
86 }
87
88 void ll_destroy_inodecache(void)
89 {
90         if (kmem_cache_destroy(ll_inode_cachep))
91                 CERROR("ll_inode_cache: not all structures were freed\n");
92 }
93
94 /* exported operations */
95 struct super_operations ll_super_operations =
96 {
97         alloc_inode: ll_alloc_inode,
98         destroy_inode: ll_destroy_inode,
99         clear_inode: ll_clear_inode,
100         put_super: ll_put_super,
101         statfs: ll_statfs,
102         umount_begin: ll_umount_begin
103 };
104
105
106 struct file_system_type lustre_lite_fs_type = {
107         .owner  = THIS_MODULE,
108         .name =   "lustre_lite",
109         .get_sb = ll_get_sb,
110         .kill_sb = kill_anon_super,
111 };
112
113 static int __init init_lustre_lite(void)
114 {
115         int rc;
116         printk(KERN_INFO "Lustre Lite Client File System; "
117                "info@clusterfs.com\n");
118         rc = ll_init_inodecache();
119         if (rc)
120                 return -ENOMEM;
121         ll_file_data_slab = kmem_cache_create("ll_file_data",
122                                               sizeof(struct ll_file_data), 0,
123                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
124         if (ll_file_data_slab == NULL) {
125                 ll_destroy_inodecache();
126                 return -ENOMEM;
127         }
128
129         proc_lustre_fs_root = proc_lustre_root ?
130                               proc_mkdir("llite", proc_lustre_root) : NULL;
131
132         return register_filesystem(&lustre_lite_fs_type);
133 }
134
135 static void __exit exit_lustre_lite(void)
136 {
137         unregister_filesystem(&lustre_lite_fs_type);
138         ll_destroy_inodecache();
139         kmem_cache_destroy(ll_file_data_slab);
140         if (proc_lustre_fs_root) {
141                 lprocfs_remove(proc_lustre_fs_root);
142                 proc_lustre_fs_root = NULL;
143         }
144 }
145
146 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
147 MODULE_DESCRIPTION("Lustre Lite Client File System");
148 MODULE_LICENSE("GPL");
149
150 module_init(init_lustre_lite);
151 module_exit(exit_lustre_lite);
152 #endif