Whamcloud - gitweb
land b1_5 onto HEAD
[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 <lustre_lite.h>
31 #include <lustre_ha.h>
32 #include <lustre_dlm.h>
33 #include <linux/init.h>
34 #include <linux/fs.h>
35 #include <lprocfs_status.h>
36 #include "llite_internal.h"
37
38 static kmem_cache_t *ll_inode_cachep;
39
40 static struct inode *ll_alloc_inode(struct super_block *sb)
41 {
42         struct ll_inode_info *lli;
43         lprocfs_counter_incr((ll_s2sbi(sb))->ll_stats, LPROC_LL_ALLOC_INODE);
44         OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
45         if (lli == NULL)
46                 return NULL;
47
48         inode_init_once(&lli->lli_vfs_inode);
49         ll_lli_init(lli);
50
51         return &lli->lli_vfs_inode;
52 }
53
54 static void ll_destroy_inode(struct inode *inode)
55 {
56         struct ll_inode_info *ptr = ll_i2info(inode);
57         OBD_SLAB_FREE(ptr, ll_inode_cachep, sizeof(*ptr));
58 }
59
60 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
61 {
62         struct ll_inode_info *lli = foo;
63
64         if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
65             SLAB_CTOR_CONSTRUCTOR)
66                 inode_init_once(&lli->lli_vfs_inode);
67 }
68
69 int ll_init_inodecache(void)
70 {
71         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
72                                             sizeof(struct ll_inode_info),
73                                             0, SLAB_HWCACHE_ALIGN,
74                                             init_once, NULL);
75         if (ll_inode_cachep == NULL)
76                 return -ENOMEM;
77         return 0;
78 }
79
80 void ll_destroy_inodecache(void)
81 {
82 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
83         int rc;
84  
85         rc = kmem_cache_destroy(ll_inode_cachep);
86         LASSERTF(rc == 0, "ll_inode_cache: not all structures were freed\n");
87 #else
88         kmem_cache_destroy(ll_inode_cachep);
89 #endif
90 }
91
92 /* exported operations */
93 struct super_operations lustre_super_operations =
94 {
95         .alloc_inode   = ll_alloc_inode,
96         .destroy_inode = ll_destroy_inode,
97         .clear_inode   = ll_clear_inode,
98         .put_super     = ll_put_super,
99         .statfs        = ll_statfs,
100         .umount_begin  = ll_umount_begin,
101         .remount_fs    = ll_remount_fs,
102 };
103
104
105 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
106
107 static int __init init_lustre_lite(void)
108 {
109         int i, rc, seed[2];
110         struct timeval tv;
111         lnet_process_id_t lnet_id;
112
113         printk(KERN_INFO "Lustre: Lustre Client File System; "
114                "info@clusterfs.com\n");
115         rc = ll_init_inodecache();
116         if (rc)
117                 return -ENOMEM;
118         ll_file_data_slab = kmem_cache_create("ll_file_data",
119                                               sizeof(struct ll_file_data), 0,
120                                               SLAB_HWCACHE_ALIGN, NULL, NULL);
121         if (ll_file_data_slab == NULL) {
122                 ll_destroy_inodecache();
123                 return -ENOMEM;
124         }
125
126         proc_lustre_fs_root = proc_lustre_root ?
127                               proc_mkdir("llite", proc_lustre_root) : NULL;
128
129         ll_register_cache(&ll_cache_definition);
130
131         lustre_register_client_fill_super(ll_fill_super);
132         lustre_register_client_process_config(ll_process_config);
133
134         get_random_bytes(seed, sizeof(seed));
135
136         /* Nodes with small feet have little entropy
137          * the NID for this node gives the most entropy in the low bits */
138         for (i=0; ; i++) {
139                 if (LNetGetId(i, &lnet_id) == -ENOENT) {
140                         break;
141                 }
142                 if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) {
143                         seed[0] ^= LNET_NIDADDR(lnet_id.nid);
144                 }
145         }
146
147         do_gettimeofday(&tv);
148         ll_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
149
150         return rc;
151 }
152
153 static void __exit exit_lustre_lite(void)
154 {
155 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
156         int rc;
157 #endif
158
159         lustre_register_client_fill_super(NULL);
160         lustre_register_client_process_config(NULL);
161
162         ll_unregister_cache(&ll_cache_definition);
163
164         ll_destroy_inodecache();
165 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
166         rc = kmem_cache_destroy(ll_file_data_slab);
167         LASSERTF(rc == 0, "couldn't destroy ll_file_data slab\n");
168 #else
169         kmem_cache_destroy(ll_file_data_slab);
170 #endif
171         if (ll_async_page_slab) {
172 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
173                 rc = kmem_cache_destroy(ll_async_page_slab);
174                 LASSERTF(rc == 0, "couldn't destroy ll_async_page slab\n");
175 #else
176                 kmem_cache_destroy(ll_async_page_slab);
177 #endif
178         }
179
180         if (proc_lustre_fs_root) 
181                 lprocfs_remove(&proc_lustre_fs_root);
182 }
183
184 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
185 MODULE_DESCRIPTION("Lustre Lite Client File System");
186 MODULE_LICENSE("GPL");
187
188 module_init(init_lustre_lite);
189 module_exit(exit_lustre_lite);