1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 
37 #define DEBUG_SUBSYSTEM S_LLITE
38 
39 #include <linux/module.h>
40 #include <linux/types.h>
41 #include "../include/lustre_lite.h"
42 #include "../include/lustre_ha.h"
43 #include "../include/lustre_dlm.h"
44 #include <linux/init.h>
45 #include <linux/fs.h>
46 #include "../include/lprocfs_status.h"
47 #include "llite_internal.h"
48 
49 static struct kmem_cache *ll_inode_cachep;
50 
ll_alloc_inode(struct super_block * sb)51 static struct inode *ll_alloc_inode(struct super_block *sb)
52 {
53 	struct ll_inode_info *lli;
54 	ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_ALLOC_INODE, 1);
55 	OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
56 	if (lli == NULL)
57 		return NULL;
58 
59 	inode_init_once(&lli->lli_vfs_inode);
60 	return &lli->lli_vfs_inode;
61 }
62 
ll_inode_destroy_callback(struct rcu_head * head)63 static void ll_inode_destroy_callback(struct rcu_head *head)
64 {
65 	struct inode *inode = container_of(head, struct inode, i_rcu);
66 	struct ll_inode_info *ptr = ll_i2info(inode);
67 	OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
68 }
69 
ll_destroy_inode(struct inode * inode)70 static void ll_destroy_inode(struct inode *inode)
71 {
72 	call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
73 }
74 
75 /* exported operations */
76 struct super_operations lustre_super_operations = {
77 	.alloc_inode   = ll_alloc_inode,
78 	.destroy_inode = ll_destroy_inode,
79 	.evict_inode   = ll_delete_inode,
80 	.put_super     = ll_put_super,
81 	.statfs	= ll_statfs,
82 	.umount_begin  = ll_umount_begin,
83 	.remount_fs    = ll_remount_fs,
84 	.show_options  = ll_show_options,
85 };
86 MODULE_ALIAS_FS("lustre");
87 
88 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
89 
init_lustre_lite(void)90 static int __init init_lustre_lite(void)
91 {
92 	struct proc_dir_entry *entry;
93 	lnet_process_id_t lnet_id;
94 	struct timeval tv;
95 	int i, rc, seed[2];
96 
97 	CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1);
98 
99 	/* print an address of _any_ initialized kernel symbol from this
100 	 * module, to allow debugging with gdb that doesn't support data
101 	 * symbols from modules.*/
102 	CDEBUG(D_INFO, "Lustre client module (%p).\n",
103 	       &lustre_super_operations);
104 
105 	rc = -ENOMEM;
106 	ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
107 					    sizeof(struct ll_inode_info),
108 					    0, SLAB_HWCACHE_ALIGN, NULL);
109 	if (ll_inode_cachep == NULL)
110 		goto out_cache;
111 
112 	ll_file_data_slab = kmem_cache_create("ll_file_data",
113 						 sizeof(struct ll_file_data), 0,
114 						 SLAB_HWCACHE_ALIGN, NULL);
115 	if (ll_file_data_slab == NULL)
116 		goto out_cache;
117 
118 	ll_remote_perm_cachep = kmem_cache_create("ll_remote_perm_cache",
119 						  sizeof(struct ll_remote_perm),
120 						      0, 0, NULL);
121 	if (ll_remote_perm_cachep == NULL)
122 		goto out_cache;
123 
124 	ll_rmtperm_hash_cachep = kmem_cache_create("ll_rmtperm_hash_cache",
125 						   REMOTE_PERM_HASHSIZE *
126 						   sizeof(struct list_head),
127 						   0, 0, NULL);
128 	if (ll_rmtperm_hash_cachep == NULL)
129 		goto out_cache;
130 
131 	entry = lprocfs_register("llite", proc_lustre_root, NULL, NULL);
132 	if (IS_ERR(entry)) {
133 		rc = PTR_ERR(entry);
134 		CERROR("cannot register '/proc/fs/lustre/llite': rc = %d\n",
135 		       rc);
136 		goto out_cache;
137 	}
138 
139 	proc_lustre_fs_root = entry;
140 
141 	cfs_get_random_bytes(seed, sizeof(seed));
142 
143 	/* Nodes with small feet have little entropy. The NID for this
144 	 * node gives the most entropy in the low bits */
145 	for (i = 0;; i++) {
146 		if (LNetGetId(i, &lnet_id) == -ENOENT)
147 			break;
148 
149 		if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND)
150 			seed[0] ^= LNET_NIDADDR(lnet_id.nid);
151 	}
152 
153 	do_gettimeofday(&tv);
154 	cfs_srand(tv.tv_sec ^ seed[0], tv.tv_usec ^ seed[1]);
155 	setup_timer(&ll_capa_timer, ll_capa_timer_callback, 0);
156 	rc = ll_capa_thread_start();
157 	if (rc != 0)
158 		goto out_proc;
159 
160 	rc = vvp_global_init();
161 	if (rc != 0)
162 		goto out_capa;
163 
164 	rc = ll_xattr_init();
165 	if (rc != 0)
166 		goto out_vvp;
167 
168 	lustre_register_client_fill_super(ll_fill_super);
169 	lustre_register_kill_super_cb(ll_kill_super);
170 	lustre_register_client_process_config(ll_process_config);
171 
172 	return 0;
173 
174 out_vvp:
175 	vvp_global_fini();
176 out_capa:
177 	del_timer(&ll_capa_timer);
178 	ll_capa_thread_stop();
179 out_proc:
180 	lprocfs_remove(&proc_lustre_fs_root);
181 out_cache:
182 	if (ll_inode_cachep != NULL)
183 		kmem_cache_destroy(ll_inode_cachep);
184 
185 	if (ll_file_data_slab != NULL)
186 		kmem_cache_destroy(ll_file_data_slab);
187 
188 	if (ll_remote_perm_cachep != NULL)
189 		kmem_cache_destroy(ll_remote_perm_cachep);
190 
191 	if (ll_rmtperm_hash_cachep != NULL)
192 		kmem_cache_destroy(ll_rmtperm_hash_cachep);
193 
194 	return rc;
195 }
196 
exit_lustre_lite(void)197 static void __exit exit_lustre_lite(void)
198 {
199 	lustre_register_client_fill_super(NULL);
200 	lustre_register_kill_super_cb(NULL);
201 	lustre_register_client_process_config(NULL);
202 
203 	lprocfs_remove(&proc_lustre_fs_root);
204 
205 	ll_xattr_fini();
206 	vvp_global_fini();
207 	del_timer(&ll_capa_timer);
208 	ll_capa_thread_stop();
209 	LASSERTF(capa_count[CAPA_SITE_CLIENT] == 0,
210 		 "client remaining capa count %d\n",
211 		 capa_count[CAPA_SITE_CLIENT]);
212 
213 	kmem_cache_destroy(ll_inode_cachep);
214 	kmem_cache_destroy(ll_rmtperm_hash_cachep);
215 
216 	kmem_cache_destroy(ll_remote_perm_cachep);
217 
218 	kmem_cache_destroy(ll_file_data_slab);
219 }
220 
221 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
222 MODULE_DESCRIPTION("Lustre Lite Client File System");
223 MODULE_LICENSE("GPL");
224 
225 module_init(init_lustre_lite);
226 module_exit(exit_lustre_lite);
227