Whamcloud - gitweb
land b_v26 (20040316_1603)
[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 struct super_block * ll_get_sb(struct file_system_type *fs_type,
38                                int flags, const char *devname, void * data)
39 {
40         /* calls back in fill super */
41         return get_sb_nodev(fs_type, flags, data, ll_fill_super);
42 }
43
44 struct super_block * lustre_get_sb(struct file_system_type *fs_type,
45                                int flags, const char *devname, void * data)
46 {
47         /* calls back in fill super */
48         return get_sb_nodev(fs_type, flags, data, lustre_fill_super);
49 }
50
51 static kmem_cache_t *ll_inode_cachep;
52
53 static struct inode *ll_alloc_inode(struct super_block *sb)
54 {
55         struct ll_inode_info *lli;
56         lprocfs_counter_incr((ll_s2sbi(sb))->ll_stats, LPROC_LL_ALLOC_INODE);
57         OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
58         if (lli == NULL)
59                 return NULL;
60
61         inode_init_once(&lli->lli_vfs_inode);
62         ll_lli_init(lli);
63
64         return &lli->lli_vfs_inode;
65 }
66
67 static void ll_destroy_inode(struct inode *inode)
68 {
69         struct ll_inode_info *ptr = ll_i2info(inode);
70         OBD_SLAB_FREE(ptr, ll_inode_cachep, sizeof(*ptr));
71 }
72
73 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
74 {
75         struct ll_inode_info *lli = foo;
76
77         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
78             SLAB_CTOR_CONSTRUCTOR)
79                 inode_init_once(&lli->lli_vfs_inode);
80 }
81
82 int ll_init_inodecache(void)
83 {
84         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
85                                             sizeof(struct ll_inode_info),
86                                             0, SLAB_HWCACHE_ALIGN,
87                                             init_once, NULL);
88         if (ll_inode_cachep == NULL)
89                 return -ENOMEM;
90         return 0;
91 }
92
93 void ll_destroy_inodecache(void)
94 {
95         if (kmem_cache_destroy(ll_inode_cachep))
96                 CERROR("ll_inode_cache: not all structures were freed\n");
97 }
98
99 /* exported operations */
100 struct super_operations lustre_super_operations =
101 {
102         alloc_inode: ll_alloc_inode,
103         destroy_inode: ll_destroy_inode,
104         clear_inode: ll_clear_inode,
105         put_super: ll_put_super,
106         statfs: ll_statfs,
107         umount_begin: ll_umount_begin
108 };
109
110
111 struct file_system_type lustre_lite_fs_type = {
112         .owner  = THIS_MODULE,
113         .name =   "lustre_lite",
114         .get_sb = ll_get_sb,
115         .kill_sb = kill_anon_super,
116 };
117
118 struct file_system_type lustre_fs_type = {
119         .owner  = THIS_MODULE,
120         .name =   "lustre",
121         .get_sb = lustre_get_sb,
122         .kill_sb = kill_anon_super,
123 };
124
125 static int __init init_lustre_lite(void)
126 {
127         int rc;
128         printk(KERN_INFO "Lustre: Lustre Lite Client File System; "
129                "info@clusterfs.com\n");
130         rc = ll_init_inodecache();
131         if (rc)
132                 return -ENOMEM;
133         ll_file_data_slab = kmem_cache_create("ll_file_data",
134                                               sizeof(struct ll_file_data), 0,
135                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
136         if (ll_file_data_slab == NULL) {
137                 ll_destroy_inodecache();
138                 return -ENOMEM;
139         }
140
141         proc_lustre_fs_root = proc_lustre_root ?
142                               proc_mkdir("llite", proc_lustre_root) : NULL;
143
144         rc = register_filesystem(&lustre_lite_fs_type);
145         if (!rc) {
146                 rc = register_filesystem(&lustre_fs_type);
147                 if (rc)
148                         unregister_filesystem(&lustre_fs_type);
149         }
150         return rc;
151 }
152
153 static void __exit exit_lustre_lite(void)
154 {
155         unregister_filesystem(&lustre_fs_type);
156         unregister_filesystem(&lustre_lite_fs_type);
157         ll_destroy_inodecache();
158         kmem_cache_destroy(ll_file_data_slab);
159         if (proc_lustre_fs_root) {
160                 lprocfs_remove(proc_lustre_fs_root);
161                 proc_lustre_fs_root = NULL;
162         }
163 }
164
165 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
166 MODULE_DESCRIPTION("Lustre Lite Client File System");
167 MODULE_LICENSE("GPL");
168
169 module_init(init_lustre_lite);
170 module_exit(exit_lustre_lite);