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/
32 #define DEBUG_SUBSYSTEM S_LLITE
34 #define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */)
36 #include <linux/module.h>
37 #include <linux/types.h>
38 #include <linux/version.h>
39 #include <lustre_ha.h>
40 #include <lustre_dlm.h>
41 #include <linux/init.h>
43 #include <linux/random.h>
44 #include <lprocfs_status.h>
45 #include "llite_internal.h"
46 #include "vvp_internal.h"
48 static struct kmem_cache *ll_inode_cachep;
50 static struct inode *ll_alloc_inode(struct super_block *sb)
52 struct ll_inode_info *lli;
53 #ifdef HAVE_ALLOC_INODE_SB
54 lli = alloc_inode_sb(sb, ll_inode_cachep, GFP_NOFS);
57 OBD_ALLOC_POST(lli, sizeof(*lli), "slab-alloced");
58 memset(lli, 0, sizeof(*lli));
60 OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
64 inode_init_once(&lli->lli_vfs_inode);
65 lli->lli_open_thrsh_count = UINT_MAX;
67 return &lli->lli_vfs_inode;
70 static void ll_inode_destroy_callback(struct rcu_head *head)
72 struct inode *inode = container_of(head, struct inode, i_rcu);
73 struct ll_inode_info *ptr = ll_i2info(inode);
74 llcrypt_free_inode(inode);
75 OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
78 static void ll_destroy_inode(struct inode *inode)
80 call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
83 static int ll_drop_inode(struct inode *inode)
85 struct ll_sb_info *sbi = ll_i2sbi(inode);
88 if (!sbi->ll_inode_cache_enabled)
91 drop = generic_drop_inode(inode);
93 drop = llcrypt_drop_inode(inode);
98 /* exported operations */
99 const struct super_operations lustre_super_operations =
101 .alloc_inode = ll_alloc_inode,
102 .destroy_inode = ll_destroy_inode,
103 .drop_inode = ll_drop_inode,
104 .evict_inode = ll_delete_inode,
105 .put_super = ll_put_super,
107 .umount_begin = ll_umount_begin,
108 .remount_fs = ll_remount_fs,
109 .show_options = ll_show_options,
113 * This is the entry point for the mount call into Lustre.
114 * This is called when a client is mounted, and this is
115 * where we start setting things up.
117 * @lmd2data data Mount options (e.g. -o flock,abort_recov)
119 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
122 struct lustre_mount_data *lmd;
123 struct lustre_sb_info *lsi;
128 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
130 lsi = lustre_init_lsi(sb);
136 * Disable lockdep during mount, because mount locking patterns are
142 * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
144 obd_zombie_barrier();
146 /* Figure out the lmd from the mount options */
147 if (lmd_parse(lmd2_data, lmd)) {
149 GOTO(out, rc = -EINVAL);
152 if (!lmd_is_client(lmd)) {
153 #ifdef HAVE_SERVER_SUPPORT
157 LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
161 rc = server_fill_super(sb);
164 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
165 lmd->lmd_profile, rc);
171 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
172 rc = lustre_start_mgc(sb);
174 lustre_common_put_super(sb);
177 /* Connect and start */
178 rc = ll_fill_super(sb);
179 /* ll_file_super will call lustre_common_put_super on failure,
180 * which takes care of the module reference.
182 * If error happens in fill_super() call, @lsi will be killed there.
183 * This is why we do not put it here.
187 CERROR("llite: Unable to mount %s: rc = %d\n",
188 s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
190 CDEBUG(D_SUPER, "%s: Mount complete\n",
197 /***************** FS registration ******************/
198 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
199 const char *devname, void *data)
201 return mount_nodev(fs_type, flags, data, lustre_fill_super);
204 static void lustre_kill_super(struct super_block *sb)
206 struct lustre_sb_info *lsi = s2lsi(sb);
208 if (lsi && !IS_SERVER(lsi))
214 /** Register the "lustre" fs type
216 static struct file_system_type lustre_fs_type = {
217 .owner = THIS_MODULE,
219 .mount = lustre_mount,
220 .kill_sb = lustre_kill_super,
221 .fs_flags = FS_RENAME_DOES_D_MOVE,
223 MODULE_ALIAS_FS("lustre");
225 static int __init lustre_init(void)
228 unsigned long lustre_inode_cache_flags;
230 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
231 LUSTRE_VOLATILE_HDR_LEN + 1);
233 /* print an address of _any_ initialized kernel symbol from this
234 * module, to allow debugging with gdb that doesn't support data
235 * symbols from modules.*/
236 CDEBUG(D_INFO, "Lustre client module (%p).\n",
237 &lustre_super_operations);
239 lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
242 lustre_inode_cache_flags |= SLAB_ACCOUNT;
245 ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
246 sizeof(struct ll_inode_info),
247 0, lustre_inode_cache_flags, NULL);
248 if (ll_inode_cachep == NULL)
249 GOTO(out_cache, rc = -ENOMEM);
251 ll_file_data_slab = kmem_cache_create("ll_file_data",
252 sizeof(struct ll_file_data), 0,
253 SLAB_HWCACHE_ALIGN, NULL);
254 if (ll_file_data_slab == NULL)
255 GOTO(out_cache, rc = -ENOMEM);
257 pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
258 sizeof(struct pcc_inode), 0,
259 SLAB_HWCACHE_ALIGN, NULL);
260 if (pcc_inode_slab == NULL)
261 GOTO(out_cache, rc = -ENOMEM);
263 rc = llite_tunables_register();
267 rc = vvp_global_init();
269 GOTO(out_tunables, rc);
271 cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
272 LCT_REMEMBER | LCT_NOREF);
273 if (IS_ERR(cl_inode_fini_env))
274 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
276 cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
278 rc = ll_xattr_init();
280 GOTO(out_inode_fini_env, rc);
282 rc = register_filesystem(&lustre_fs_type);
291 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
295 llite_tunables_unregister();
297 kmem_cache_destroy(ll_inode_cachep);
298 kmem_cache_destroy(ll_file_data_slab);
299 kmem_cache_destroy(pcc_inode_slab);
303 static void __exit lustre_exit(void)
305 unregister_filesystem(&lustre_fs_type);
307 llite_tunables_unregister();
310 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
314 * Make sure all delayed rcu free inodes are flushed before we
319 kmem_cache_destroy(ll_inode_cachep);
320 kmem_cache_destroy(ll_file_data_slab);
321 kmem_cache_destroy(pcc_inode_slab);
324 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
325 MODULE_DESCRIPTION("Lustre Client File System");
326 MODULE_VERSION(LUSTRE_VERSION_STRING);
327 MODULE_LICENSE("GPL");
329 module_init(lustre_init);
330 module_exit(lustre_exit);