1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2011, 2016, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
14 #define DEBUG_SUBSYSTEM S_LLITE
16 #define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */)
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/version.h>
21 #include <lustre_ha.h>
22 #include <lustre_dlm.h>
23 #include <lustre_quota.h>
24 #include <linux/init.h>
26 #include <linux/random.h>
27 #include <lprocfs_status.h>
28 #include "llite_internal.h"
29 #include "vvp_internal.h"
31 static struct kmem_cache *ll_inode_cachep;
33 static struct inode *ll_alloc_inode(struct super_block *sb)
35 struct ll_inode_info *lli;
36 #ifdef HAVE_ALLOC_INODE_SB
37 lli = alloc_inode_sb(sb, ll_inode_cachep, GFP_NOFS);
40 OBD_ALLOC_POST(lli, sizeof(*lli), "slab-alloced");
41 memset(lli, 0, sizeof(*lli));
43 OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
47 inode_init_once(&lli->lli_vfs_inode);
48 lli->lli_open_thrsh_count = UINT_MAX;
50 return &lli->lli_vfs_inode;
53 static void ll_inode_destroy_callback(struct rcu_head *head)
55 struct inode *inode = container_of(head, struct inode, i_rcu);
56 struct ll_inode_info *ptr = ll_i2info(inode);
58 llcrypt_free_inode(inode);
59 OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
62 static void ll_destroy_inode(struct inode *inode)
64 call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
67 static int ll_drop_inode(struct inode *inode)
69 struct ll_sb_info *sbi = ll_i2sbi(inode);
72 if (!sbi->ll_inode_cache_enabled)
75 drop = generic_drop_inode(inode);
77 drop = llcrypt_drop_inode(inode);
82 /* exported operations */
83 const struct super_operations lustre_super_operations = {
84 .alloc_inode = ll_alloc_inode,
85 .destroy_inode = ll_destroy_inode,
86 .drop_inode = ll_drop_inode,
87 .evict_inode = ll_delete_inode,
88 .put_super = ll_put_super,
90 .umount_begin = ll_umount_begin,
91 .remount_fs = ll_remount_fs,
92 .show_options = ll_show_options,
96 * lustre_fill_super() - set up the superblock with lustre info
98 * @sb: setup superblock struct with lustre info
99 * @lmd2_data: data Mount options provided during mount
100 * (e.g. -o flock,abort_recov)
103 * This is the entry point for the mount call into Lustre.
104 * This is called when a client is mounted, and this is
105 * where we start setting things up.
112 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
115 struct lustre_mount_data *lmd;
116 struct lustre_sb_info *lsi;
121 CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
123 lsi = lustre_init_lsi(sb);
129 * Disable lockdep during mount, because mount locking patterns are
135 * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
137 obd_zombie_barrier();
139 /* Figure out the lmd from the mount options */
140 if (lmd_parse(lmd2_data, lmd)) {
142 GOTO(out, rc = -EINVAL);
145 if (!lmd_is_client(lmd)) {
146 #ifdef HAVE_SERVER_SUPPORT
150 LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
154 rc = server_fill_super(sb);
157 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
158 lmd->lmd_profile, rc);
164 CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
165 rc = lustre_start_mgc(sb);
167 lustre_common_put_super(sb);
170 /* Connect and start */
171 rc = ll_fill_super(sb);
172 /* ll_file_super will call lustre_common_put_super on failure,
173 * which takes care of the module reference.
175 * If error happens in fill_super() call, @lsi will be killed there.
176 * This is why we do not put it here.
180 CERROR("llite: Unable to mount %s: rc = %d\n",
181 s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
183 CDEBUG(D_SUPER, "%s: Mount complete\n",
190 /***************** FS registration ******************/
191 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
192 const char *devname, void *data)
194 return mount_nodev(fs_type, flags, data, lustre_fill_super);
197 static void lustre_kill_super(struct super_block *sb)
199 struct lustre_sb_info *lsi = s2lsi(sb);
201 if (lsi && !IS_SERVER(lsi))
207 /* Register the "lustre" fs type */
208 static struct file_system_type lustre_fs_type = {
209 .owner = THIS_MODULE,
211 .mount = lustre_mount,
212 .kill_sb = lustre_kill_super,
213 .fs_flags = FS_RENAME_DOES_D_MOVE,
215 MODULE_ALIAS_FS("lustre");
217 static int __init lustre_init(void)
220 unsigned long lustre_inode_cache_flags;
222 BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
223 LUSTRE_VOLATILE_HDR_LEN + 1);
229 /* print an address of _any_ initialized kernel symbol from this
230 * module, to allow debugging with gdb that doesn't support data
231 * symbols from modules.
233 CDEBUG(D_INFO, "Lustre client module (%p).\n",
234 &lustre_super_operations);
236 lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
239 lustre_inode_cache_flags |= SLAB_ACCOUNT;
242 ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
243 sizeof(struct ll_inode_info),
244 0, lustre_inode_cache_flags, NULL);
245 if (ll_inode_cachep == NULL)
246 GOTO(out_cache, rc = -ENOMEM);
248 ll_file_data_slab = kmem_cache_create("ll_file_data",
249 sizeof(struct ll_file_data), 0,
250 SLAB_HWCACHE_ALIGN, NULL);
251 if (ll_file_data_slab == NULL)
252 GOTO(out_cache, rc = -ENOMEM);
254 pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
255 sizeof(struct pcc_inode), 0,
256 SLAB_HWCACHE_ALIGN, NULL);
257 if (pcc_inode_slab == NULL)
258 GOTO(out_cache, rc = -ENOMEM);
260 quota_iter_slab = kmem_cache_create("ll_quota_iter",
261 sizeof(struct if_quotactl_iter), 0,
262 SLAB_HWCACHE_ALIGN, NULL);
263 if (quota_iter_slab == NULL)
264 GOTO(out_cache, rc = -ENOMEM);
266 rc = llite_tunables_register();
270 rc = vvp_global_init();
272 GOTO(out_tunables, rc);
274 cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
275 LCT_REMEMBER | LCT_NOREF);
276 if (IS_ERR(cl_inode_fini_env))
277 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
279 cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
281 rc = ll_xattr_init();
283 GOTO(out_inode_fini_env, rc);
285 rc = register_filesystem(&lustre_fs_type);
294 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
298 llite_tunables_unregister();
300 kmem_cache_destroy(ll_inode_cachep);
301 kmem_cache_destroy(ll_file_data_slab);
302 kmem_cache_destroy(pcc_inode_slab);
303 kmem_cache_destroy(quota_iter_slab);
307 static void __exit lustre_exit(void)
309 unregister_filesystem(&lustre_fs_type);
311 llite_tunables_unregister();
314 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
318 * Make sure all delayed rcu free inodes are flushed before we
323 kmem_cache_destroy(ll_inode_cachep);
324 kmem_cache_destroy(ll_file_data_slab);
325 kmem_cache_destroy(pcc_inode_slab);
326 kmem_cache_destroy(quota_iter_slab);
329 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
330 MODULE_DESCRIPTION("Lustre Client File System");
331 MODULE_VERSION(LUSTRE_VERSION_STRING);
332 MODULE_LICENSE("GPL");
334 module_init(lustre_init);
335 module_exit(lustre_exit);