Whamcloud - gitweb
Merge fixes from b1_6 to 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 cfs_mem_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         ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_ALLOC_INODE, 1);
44         OBD_SLAB_ALLOC_PTR(lli, ll_inode_cachep);
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(ptr, ll_inode_cachep);
58 }
59
60 int ll_init_inodecache(void)
61 {
62         ll_inode_cachep = cfs_mem_cache_create("lustre_inode_cache",
63                                                  sizeof(struct ll_inode_info),
64                                                  0, SLAB_HWCACHE_ALIGN);
65         if (ll_inode_cachep == NULL)
66                 return -ENOMEM;
67         return 0;
68 }
69
70 void ll_destroy_inodecache(void)
71 {
72         int rc;
73
74         rc = cfs_mem_cache_destroy(ll_inode_cachep);
75         LASSERTF(rc == 0, "ll_inode_cache: not all structures were freed\n");
76 }
77
78 /* exported operations */
79 struct super_operations lustre_super_operations =
80 {
81         .alloc_inode   = ll_alloc_inode,
82         .destroy_inode = ll_destroy_inode,
83         .clear_inode   = ll_clear_inode,
84         .delete_inode  = ll_delete_inode,
85         .put_super     = ll_put_super,
86         .statfs        = ll_statfs,
87         .umount_begin  = ll_umount_begin,
88         .remount_fs    = ll_remount_fs,
89 };
90
91
92 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
93
94 static int __init init_lustre_lite(void)
95 {
96         int i, rc, seed[2];
97         struct timeval tv;
98         lnet_process_id_t lnet_id;
99  
100         rc = ll_init_inodecache();
101         if (rc)
102                 return -ENOMEM;
103
104         ll_file_data_slab = cfs_mem_cache_create("ll_file_data",
105                                               sizeof(struct ll_file_data), 0,
106                                                   SLAB_HWCACHE_ALIGN);
107         if (ll_file_data_slab == NULL) {
108                 ll_destroy_inodecache();
109                 return -ENOMEM;
110         }
111
112         ll_remote_perm_cachep = cfs_mem_cache_create("ll_remote_perm_cache",
113                                                   sizeof(struct ll_remote_perm),
114                                                       0, 0);
115         if (ll_remote_perm_cachep == NULL) {
116                 cfs_mem_cache_destroy(ll_file_data_slab);
117                 ll_file_data_slab = NULL;
118                 ll_destroy_inodecache();
119                 return -ENOMEM;
120         }
121
122         ll_rmtperm_hash_cachep = cfs_mem_cache_create("ll_rmtperm_hash_cache",
123                                                    REMOTE_PERM_HASHSIZE *
124                                                    sizeof(struct list_head),
125                                                    0, 0);
126         if (ll_rmtperm_hash_cachep == NULL) {
127                 cfs_mem_cache_destroy(ll_remote_perm_cachep);
128                 ll_remote_perm_cachep = NULL;
129                 cfs_mem_cache_destroy(ll_file_data_slab);
130                 ll_file_data_slab = NULL;
131                 ll_destroy_inodecache();
132                 return -ENOMEM;
133         }
134
135         proc_lustre_fs_root = proc_lustre_root ?
136                               proc_mkdir("llite", proc_lustre_root) : NULL;
137
138         ll_register_cache(&ll_cache_definition);
139
140         lustre_register_client_fill_super(ll_fill_super);
141         lustre_register_kill_super_cb(ll_kill_super);
142
143         lustre_register_client_process_config(ll_process_config);
144
145         ll_get_random_bytes(seed, sizeof(seed));
146
147         /* Nodes with small feet have little entropy
148          * the NID for this node gives the most entropy in the low bits */
149         for (i=0; ; i++) {
150                 if (LNetGetId(i, &lnet_id) == -ENOENT) {
151                         break;
152                 }
153                 if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) {
154                         seed[0] ^= LNET_NIDADDR(lnet_id.nid);
155                 }
156         }
157
158         do_gettimeofday(&tv);
159         ll_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
160
161         init_timer(&ll_capa_timer);
162         ll_capa_timer.function = ll_capa_timer_callback;
163         rc = ll_capa_thread_start();
164         return rc;
165 }
166
167 static void __exit exit_lustre_lite(void)
168 {
169 #ifdef HAVE_KMEM_CACHE_DESTROY_INT
170         int rc;
171 #endif
172         del_timer(&ll_capa_timer);
173         ll_capa_thread_stop();
174         LASSERTF(capa_count[CAPA_SITE_CLIENT] == 0,
175                  "client remaining capa count %d\n",
176                  capa_count[CAPA_SITE_CLIENT]);
177
178         lustre_register_client_fill_super(NULL);
179         lustre_register_kill_super_cb(NULL);
180
181         lustre_register_client_process_config(NULL);
182
183         ll_unregister_cache(&ll_cache_definition);
184
185         ll_destroy_inodecache();
186
187         rc = cfs_mem_cache_destroy(ll_rmtperm_hash_cachep);
188         LASSERTF(rc == 0, "couldn't destroy ll_rmtperm_hash_cachep\n");
189         ll_rmtperm_hash_cachep = NULL;
190
191         rc = cfs_mem_cache_destroy(ll_remote_perm_cachep);
192         LASSERTF(rc == 0, "couldn't destroy ll_remote_perm_cachep\n");
193         ll_remote_perm_cachep = NULL;
194
195         rc = cfs_mem_cache_destroy(ll_file_data_slab);
196         LASSERTF(rc == 0, "couldn't destroy ll_file_data slab\n");
197         if (ll_async_page_slab) {
198                 rc = cfs_mem_cache_destroy(ll_async_page_slab);
199                 LASSERTF(rc == 0, "couldn't destroy ll_async_page slab\n");
200         }
201
202         if (proc_lustre_fs_root) {
203                 lprocfs_remove(&proc_lustre_fs_root);
204         }
205 }
206
207 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
208 MODULE_DESCRIPTION("Lustre Lite Client File System");
209 MODULE_LICENSE("GPL");
210
211 module_init(init_lustre_lite);
212 module_exit(exit_lustre_lite);