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