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 <lustre_quota.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 #ifdef HAVE_ALLOC_INODE_SB
55 lli = alloc_inode_sb(sb, ll_inode_cachep, GFP_NOFS);
58 OBD_ALLOC_POST(lli, sizeof(*lli), "slab-alloced");
59 memset(lli, 0, sizeof(*lli));
61 OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
65 inode_init_once(&lli->lli_vfs_inode);
66 lli->lli_open_thrsh_count = UINT_MAX;
68 return &lli->lli_vfs_inode;
71 static void ll_inode_destroy_callback(struct rcu_head *head)
73 struct inode *inode = container_of(head, struct inode, i_rcu);
74 struct ll_inode_info *ptr = ll_i2info(inode);
76 llcrypt_free_inode(inode);
77 OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
80 static void ll_destroy_inode(struct inode *inode)
82 call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
85 static int ll_drop_inode(struct inode *inode)
87 struct ll_sb_info *sbi = ll_i2sbi(inode);
90 if (!sbi->ll_inode_cache_enabled)
93 drop = generic_drop_inode(inode);
95 drop = llcrypt_drop_inode(inode);
100 /* exported operations */
101 const struct super_operations lustre_super_operations = {
102 .alloc_inode = ll_alloc_inode,
103 .destroy_inode = ll_destroy_inode,
104 .drop_inode = ll_drop_inode,
105 .evict_inode = ll_delete_inode,
106 .put_super = ll_put_super,
108 .umount_begin = ll_umount_begin,
109 .remount_fs = ll_remount_fs,
110 .show_options = ll_show_options,
114 * This is the entry point for the mount call into Lustre.
115 * This is called when a client is mounted, and this is
116 * where we start setting things up.
118 * @lmd2data data Mount options (e.g. -o flock,abort_recov)
120 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
123 struct lustre_mount_data *lmd;
124 struct lustre_sb_info *lsi;
129 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
131 lsi = lustre_init_lsi(sb);
137 * Disable lockdep during mount, because mount locking patterns are
143 * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
145 obd_zombie_barrier();
147 /* Figure out the lmd from the mount options */
148 if (lmd_parse(lmd2_data, lmd)) {
150 GOTO(out, rc = -EINVAL);
153 if (!lmd_is_client(lmd)) {
154 #ifdef HAVE_SERVER_SUPPORT
158 LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
162 rc = server_fill_super(sb);
165 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
166 lmd->lmd_profile, rc);
172 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
173 rc = lustre_start_mgc(sb);
175 lustre_common_put_super(sb);
178 /* Connect and start */
179 rc = ll_fill_super(sb);
180 /* ll_file_super will call lustre_common_put_super on failure,
181 * which takes care of the module reference.
183 * If error happens in fill_super() call, @lsi will be killed there.
184 * This is why we do not put it here.
188 CERROR("llite: Unable to mount %s: rc = %d\n",
189 s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
191 CDEBUG(D_SUPER, "%s: Mount complete\n",
198 /***************** FS registration ******************/
199 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
200 const char *devname, void *data)
202 return mount_nodev(fs_type, flags, data, lustre_fill_super);
205 static void lustre_kill_super(struct super_block *sb)
207 struct lustre_sb_info *lsi = s2lsi(sb);
209 if (lsi && !IS_SERVER(lsi))
215 /** Register the "lustre" fs type
217 static struct file_system_type lustre_fs_type = {
218 .owner = THIS_MODULE,
220 .mount = lustre_mount,
221 .kill_sb = lustre_kill_super,
222 .fs_flags = FS_RENAME_DOES_D_MOVE,
224 MODULE_ALIAS_FS("lustre");
226 static int __init lustre_init(void)
229 unsigned long lustre_inode_cache_flags;
231 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
232 LUSTRE_VOLATILE_HDR_LEN + 1);
238 /* print an address of _any_ initialized kernel symbol from this
239 * module, to allow debugging with gdb that doesn't support data
240 * symbols from modules.
242 CDEBUG(D_INFO, "Lustre client module (%p).\n",
243 &lustre_super_operations);
245 lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
248 lustre_inode_cache_flags |= SLAB_ACCOUNT;
251 ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
252 sizeof(struct ll_inode_info),
253 0, lustre_inode_cache_flags, NULL);
254 if (ll_inode_cachep == NULL)
255 GOTO(out_cache, rc = -ENOMEM);
257 ll_file_data_slab = kmem_cache_create("ll_file_data",
258 sizeof(struct ll_file_data), 0,
259 SLAB_HWCACHE_ALIGN, NULL);
260 if (ll_file_data_slab == NULL)
261 GOTO(out_cache, rc = -ENOMEM);
263 pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
264 sizeof(struct pcc_inode), 0,
265 SLAB_HWCACHE_ALIGN, NULL);
266 if (pcc_inode_slab == NULL)
267 GOTO(out_cache, rc = -ENOMEM);
269 quota_iter_slab = kmem_cache_create("ll_quota_iter",
270 sizeof(struct if_quotactl_iter), 0,
271 SLAB_HWCACHE_ALIGN, NULL);
272 if (quota_iter_slab == NULL)
273 GOTO(out_cache, rc = -ENOMEM);
275 rc = llite_tunables_register();
279 rc = vvp_global_init();
281 GOTO(out_tunables, rc);
283 cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
284 LCT_REMEMBER | LCT_NOREF);
285 if (IS_ERR(cl_inode_fini_env))
286 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
288 cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
290 rc = ll_xattr_init();
292 GOTO(out_inode_fini_env, rc);
294 rc = register_filesystem(&lustre_fs_type);
303 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
307 llite_tunables_unregister();
309 kmem_cache_destroy(ll_inode_cachep);
310 kmem_cache_destroy(ll_file_data_slab);
311 kmem_cache_destroy(pcc_inode_slab);
312 kmem_cache_destroy(quota_iter_slab);
316 static void __exit lustre_exit(void)
318 unregister_filesystem(&lustre_fs_type);
320 llite_tunables_unregister();
323 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
327 * Make sure all delayed rcu free inodes are flushed before we
332 kmem_cache_destroy(ll_inode_cachep);
333 kmem_cache_destroy(ll_file_data_slab);
334 kmem_cache_destroy(pcc_inode_slab);
335 kmem_cache_destroy(quota_iter_slab);
338 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
339 MODULE_DESCRIPTION("Lustre Client File System");
340 MODULE_VERSION(LUSTRE_VERSION_STRING);
341 MODULE_LICENSE("GPL");
343 module_init(lustre_init);
344 module_exit(lustre_exit);