Whamcloud - gitweb
8ff81e963d5fe4ba2d6003de1a200e7bdefd7ee6
[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/types.h>
28 #include <linux/random.h>
29 #include <linux/version.h>
30 #include <linux/lustre_lite.h>
31 #include <linux/lustre_ha.h>
32 #include <linux/lustre_dlm.h>
33 #include <linux/init.h>
34 #include <linux/fs.h>
35 #include <linux/lprocfs_status.h>
36 #include <linux/obd_support.h>
37 #include "llite_internal.h"
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 struct super_block * lustre_get_sb(struct file_system_type *fs_type,
47                                int flags, const char *devname, void * data)
48 {
49         /* calls back in fill super */
50         return get_sb_nodev(fs_type, flags, data, lustre_fill_super);
51 }
52
53 static kmem_cache_t *ll_inode_cachep;
54
55 static struct inode *ll_alloc_inode(struct super_block *sb)
56 {
57         struct ll_inode_info *lli;
58         lprocfs_counter_incr((ll_s2sbi(sb))->ll_stats, LPROC_LL_ALLOC_INODE);
59         OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
60         if (lli == NULL)
61                 return NULL;
62
63         inode_init_once(&lli->lli_vfs_inode);
64         ll_lli_init(lli);
65
66         return &lli->lli_vfs_inode;
67 }
68
69 static void ll_destroy_inode(struct inode *inode)
70 {
71         struct ll_inode_info *ptr = ll_i2info(inode);
72         OBD_SLAB_FREE(ptr, ll_inode_cachep, sizeof(*ptr));
73 }
74
75 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
76 {
77         struct ll_inode_info *lli = foo;
78
79         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
80             SLAB_CTOR_CONSTRUCTOR)
81                 inode_init_once(&lli->lli_vfs_inode);
82 }
83
84 int ll_init_inodecache(void)
85 {
86         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
87                                             sizeof(struct ll_inode_info),
88                                             0, SLAB_HWCACHE_ALIGN,
89                                             init_once, NULL);
90         if (ll_inode_cachep == NULL)
91                 return -ENOMEM;
92         return 0;
93 }
94
95 void ll_destroy_inodecache(void)
96 {
97         LASSERTF(kmem_cache_destroy(ll_inode_cachep) == 0,
98                  "ll_inode_cache: not all structures were freed\n");
99 }
100
101 /* exported operations */
102 struct super_operations lustre_super_operations =
103 {
104         .alloc_inode   = ll_alloc_inode,
105         .destroy_inode = ll_destroy_inode,
106         .clear_inode   = ll_clear_inode,
107         .put_super     = lustre_put_super,
108         .statfs        = ll_statfs,
109         .umount_begin  = ll_umount_begin
110 };
111
112 struct file_system_type lustre_lite_fs_type = {
113         .owner        = THIS_MODULE,
114         .name         = "lustre_lite",
115         .get_sb       = ll_get_sb,
116         .kill_sb      = kill_anon_super,
117         .fs_flags     = FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
118 };
119
120 struct file_system_type lustre_fs_type = {
121         .owner        = THIS_MODULE,
122         .name         = "lustre",
123         .get_sb       = lustre_get_sb,
124         .kill_sb      = kill_anon_super,
125         .fs_flags     = FS_REVAL_DOT|FS_BINARY_MOUNTDATA,
126 };
127
128 static int __init init_lustre_lite(void)
129 {
130         int rc, cleanup = 0;
131
132         printk(KERN_INFO "Lustre: Lustre Lite Client File System; "
133                "info@clusterfs.com\n");
134
135         rc = ll_init_inodecache();
136         if (rc)
137                 return -ENOMEM;
138
139         ll_file_data_slab = kmem_cache_create("ll_file_data",
140                                               sizeof(struct ll_file_data), 0,
141                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
142         if (ll_file_data_slab == NULL) {
143                 rc = -ENOMEM;
144                 goto out;
145         }
146         ll_intent_slab = kmem_cache_create("lustre_intent_data",
147                                               sizeof(struct lustre_intent_data),
148                                               0, SLAB_HWCACHE_ALIGN, NULL,
149                                               NULL);
150         if (ll_intent_slab == NULL) {
151                 kmem_cache_destroy(ll_file_data_slab);
152                 ll_destroy_inodecache();
153                 return -ENOMEM;
154         }
155
156
157         proc_lustre_fs_root = proc_lustre_root ?
158                               proc_mkdir("llite", proc_lustre_root) : NULL;
159
160         rc = register_filesystem(&lustre_lite_fs_type);
161         if (rc)
162                 goto out;
163         cleanup = 1;
164
165         rc = register_filesystem(&lustre_fs_type);
166         if (rc)
167                 goto out;
168         cleanup = 2;
169
170         rc = ll_gns_start_thread();
171         if (rc)
172                 goto out;
173         return 0;
174 out:
175         switch (cleanup) {
176         case 2:
177                 unregister_filesystem(&lustre_fs_type);
178         case 1:
179                 unregister_filesystem(&lustre_lite_fs_type);
180         case 0:
181                ll_destroy_inodecache();
182         }
183         return rc;
184 }
185
186 static void __exit exit_lustre_lite(void)
187 {
188         unregister_filesystem(&lustre_fs_type);
189         unregister_filesystem(&lustre_lite_fs_type);
190
191         ll_gns_stop_thread();
192         ll_destroy_inodecache();
193         
194         LASSERTF(kmem_cache_destroy(ll_file_data_slab) == 0,
195                  "couldn't destroy ll_file_data slab\n");
196         LASSERTF(kmem_cache_destroy(ll_intent_slab) == 0,
197                  "couldn't destroy ll_intent_slab slab\n");
198         if (proc_lustre_fs_root) {
199                 lprocfs_remove(proc_lustre_fs_root);
200                 proc_lustre_fs_root = NULL;
201         }
202 }
203
204 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
205 MODULE_DESCRIPTION("Lustre Lite Client File System");
206 MODULE_LICENSE("GPL");
207
208 module_init(init_lustre_lite);
209 module_exit(exit_lustre_lite);