4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LLITE
35 #define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */)
37 #include <linux/module.h>
38 #include <linux/types.h>
39 #include <linux/version.h>
40 #include <lustre_ha.h>
41 #include <lustre_dlm.h>
42 #include <linux/init.h>
44 #include <linux/random.h>
45 #include <lprocfs_status.h>
46 #include "llite_internal.h"
47 #include "vvp_internal.h"
49 static struct kmem_cache *ll_inode_cachep;
51 static struct inode *ll_alloc_inode(struct super_block *sb)
53 struct ll_inode_info *lli;
54 OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
58 inode_init_once(&lli->lli_vfs_inode);
59 return &lli->lli_vfs_inode;
62 static void ll_inode_destroy_callback(struct rcu_head *head)
64 struct inode *inode = container_of(head, struct inode, i_rcu);
65 struct ll_inode_info *ptr = ll_i2info(inode);
66 llcrypt_free_inode(inode);
67 OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
70 static void ll_destroy_inode(struct inode *inode)
72 call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
75 static int ll_drop_inode(struct inode *inode)
77 int drop = generic_drop_inode(inode);
80 drop = llcrypt_drop_inode(inode);
85 /* exported operations */
86 const struct super_operations lustre_super_operations =
88 .alloc_inode = ll_alloc_inode,
89 .destroy_inode = ll_destroy_inode,
90 .drop_inode = ll_drop_inode,
91 .evict_inode = ll_delete_inode,
92 .put_super = ll_put_super,
94 .umount_begin = ll_umount_begin,
95 .remount_fs = ll_remount_fs,
96 .show_options = ll_show_options,
100 * This is the entry point for the mount call into Lustre.
101 * This is called when a client is mounted, and this is
102 * where we start setting things up.
104 * @lmd2data data Mount options (e.g. -o flock,abort_recov)
106 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
109 struct lustre_mount_data *lmd;
110 struct lustre_sb_info *lsi;
115 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
117 lsi = lustre_init_lsi(sb);
123 * Disable lockdep during mount, because mount locking patterns are
129 * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
131 obd_zombie_barrier();
133 /* Figure out the lmd from the mount options */
134 if (lmd_parse(lmd2_data, lmd)) {
136 GOTO(out, rc = -EINVAL);
139 if (!lmd_is_client(lmd)) {
140 #ifdef HAVE_SERVER_SUPPORT
141 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 15, 51, 0)
145 LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
150 rc = server_fill_super(sb);
153 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
154 lmd->lmd_profile, rc);
160 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
161 rc = lustre_start_mgc(sb);
163 lustre_common_put_super(sb);
166 /* Connect and start */
167 rc = ll_fill_super(sb);
168 /* ll_file_super will call lustre_common_put_super on failure,
169 * which takes care of the module reference.
171 * If error happens in fill_super() call, @lsi will be killed there.
172 * This is why we do not put it here.
176 CERROR("llite: Unable to mount %s: rc = %d\n",
177 s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
179 CDEBUG(D_SUPER, "%s: Mount complete\n",
186 /***************** FS registration ******************/
187 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
188 const char *devname, void *data)
190 return mount_nodev(fs_type, flags, data, lustre_fill_super);
193 static void lustre_kill_super(struct super_block *sb)
195 struct lustre_sb_info *lsi = s2lsi(sb);
197 if (lsi && !IS_SERVER(lsi))
203 /** Register the "lustre" fs type
205 static struct file_system_type lustre_fs_type = {
206 .owner = THIS_MODULE,
208 .mount = lustre_mount,
209 .kill_sb = lustre_kill_super,
210 .fs_flags = FS_RENAME_DOES_D_MOVE,
212 MODULE_ALIAS_FS("lustre");
214 static int __init lustre_init(void)
216 struct lnet_process_id lnet_id;
218 unsigned long lustre_inode_cache_flags;
220 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
221 LUSTRE_VOLATILE_HDR_LEN + 1);
223 /* print an address of _any_ initialized kernel symbol from this
224 * module, to allow debugging with gdb that doesn't support data
225 * symbols from modules.*/
226 CDEBUG(D_INFO, "Lustre client module (%p).\n",
227 &lustre_super_operations);
229 lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
232 lustre_inode_cache_flags |= SLAB_ACCOUNT;
235 ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
236 sizeof(struct ll_inode_info),
237 0, lustre_inode_cache_flags, NULL);
238 if (ll_inode_cachep == NULL)
239 GOTO(out_cache, rc = -ENOMEM);
241 ll_file_data_slab = kmem_cache_create("ll_file_data",
242 sizeof(struct ll_file_data), 0,
243 SLAB_HWCACHE_ALIGN, NULL);
244 if (ll_file_data_slab == NULL)
245 GOTO(out_cache, rc = -ENOMEM);
247 pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
248 sizeof(struct pcc_inode), 0,
249 SLAB_HWCACHE_ALIGN, NULL);
250 if (pcc_inode_slab == NULL)
251 GOTO(out_cache, rc = -ENOMEM);
253 rc = llite_tunables_register();
257 /* Nodes with small feet have little entropy. The NID for this
258 * node gives the most entropy in the low bits. */
260 if (LNetGetId(i, &lnet_id) == -ENOENT)
263 add_device_randomness(&lnet_id.nid, sizeof(lnet_id.nid));
266 rc = vvp_global_init();
268 GOTO(out_tunables, rc);
270 cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
271 LCT_REMEMBER | LCT_NOREF);
272 if (IS_ERR(cl_inode_fini_env))
273 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
275 cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
277 rc = ll_xattr_init();
279 GOTO(out_inode_fini_env, rc);
281 rc = register_filesystem(&lustre_fs_type);
290 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
294 llite_tunables_unregister();
296 kmem_cache_destroy(ll_inode_cachep);
297 kmem_cache_destroy(ll_file_data_slab);
298 kmem_cache_destroy(pcc_inode_slab);
302 static void __exit lustre_exit(void)
304 unregister_filesystem(&lustre_fs_type);
306 llite_tunables_unregister();
309 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
313 * Make sure all delayed rcu free inodes are flushed before we
318 kmem_cache_destroy(ll_inode_cachep);
319 kmem_cache_destroy(ll_file_data_slab);
320 kmem_cache_destroy(pcc_inode_slab);
323 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
324 MODULE_DESCRIPTION("Lustre Client File System");
325 MODULE_VERSION(LUSTRE_VERSION_STRING);
326 MODULE_LICENSE("GPL");
328 module_init(lustre_init);
329 module_exit(lustre_exit);