Whamcloud - gitweb
LU-13970 llite: add option to disable Lustre inode cache
[fs/lustre-release.git] / lustre / llite / super25.c
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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #define DEBUG_SUBSYSTEM S_LLITE
33
34 #define D_MOUNT (D_SUPER | D_CONFIG/*|D_WARNING */)
35
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>
42 #include <linux/fs.h>
43 #include <linux/random.h>
44 #include <lprocfs_status.h>
45 #include "llite_internal.h"
46 #include "vvp_internal.h"
47
48 static struct kmem_cache *ll_inode_cachep;
49
50 static struct inode *ll_alloc_inode(struct super_block *sb)
51 {
52         struct ll_inode_info *lli;
53         OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
54         if (lli == NULL)
55                 return NULL;
56
57         inode_init_once(&lli->lli_vfs_inode);
58         return &lli->lli_vfs_inode;
59 }
60
61 static void ll_inode_destroy_callback(struct rcu_head *head)
62 {
63         struct inode *inode = container_of(head, struct inode, i_rcu);
64         struct ll_inode_info *ptr = ll_i2info(inode);
65         llcrypt_free_inode(inode);
66         OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
67 }
68
69 static void ll_destroy_inode(struct inode *inode)
70 {
71         call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
72 }
73
74 static int ll_drop_inode(struct inode *inode)
75 {
76         struct ll_sb_info *sbi = ll_i2sbi(inode);
77         int drop;
78
79         if (!sbi->ll_inode_cache_enabled)
80                 return 1;
81
82         drop = generic_drop_inode(inode);
83         if (!drop)
84                 drop = llcrypt_drop_inode(inode);
85
86         return drop;
87 }
88
89 /* exported operations */
90 const struct super_operations lustre_super_operations =
91 {
92         .alloc_inode   = ll_alloc_inode,
93         .destroy_inode = ll_destroy_inode,
94         .drop_inode    = ll_drop_inode,
95         .evict_inode   = ll_delete_inode,
96         .put_super     = ll_put_super,
97         .statfs        = ll_statfs,
98         .umount_begin  = ll_umount_begin,
99         .remount_fs    = ll_remount_fs,
100         .show_options  = ll_show_options,
101 };
102
103 /**
104  * This is the entry point for the mount call into Lustre.
105  * This is called when a client is mounted, and this is
106  * where we start setting things up.
107  *
108  * @lmd2data data Mount options (e.g. -o flock,abort_recov)
109  */
110 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
111                              int silent)
112 {
113         struct lustre_mount_data *lmd;
114         struct lustre_sb_info *lsi;
115         int rc;
116
117         ENTRY;
118
119         CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
120
121         lsi = lustre_init_lsi(sb);
122         if (!lsi)
123                 RETURN(-ENOMEM);
124         lmd = lsi->lsi_lmd;
125
126         /*
127          * Disable lockdep during mount, because mount locking patterns are
128          * 'special'.
129          */
130         lockdep_off();
131
132         /*
133          * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
134          */
135         obd_zombie_barrier();
136
137         /* Figure out the lmd from the mount options */
138         if (lmd_parse(lmd2_data, lmd)) {
139                 lustre_put_lsi(sb);
140                 GOTO(out, rc = -EINVAL);
141         }
142
143         if (!lmd_is_client(lmd)) {
144 #ifdef HAVE_SERVER_SUPPORT
145 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 15, 51, 0)
146                 static bool printed;
147
148                 if (!printed) {
149                         LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
150                                       lmd->lmd_profile);
151                         printed = true;
152                 }
153 #endif
154                 rc = server_fill_super(sb);
155 #else
156                 rc = -ENODEV;
157                 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
158                        lmd->lmd_profile, rc);
159                 lustre_put_lsi(sb);
160 #endif
161                 GOTO(out, rc);
162         }
163
164         CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
165         /* filename encryption is disabled by default */
166         lsi->lsi_flags &= ~LSI_FILENAME_ENC;
167         rc = lustre_start_mgc(sb);
168         if (rc) {
169                 lustre_common_put_super(sb);
170                 GOTO(out, rc);
171         }
172         /* Connect and start */
173         rc = ll_fill_super(sb);
174         /* ll_file_super will call lustre_common_put_super on failure,
175          * which takes care of the module reference.
176          *
177          * If error happens in fill_super() call, @lsi will be killed there.
178          * This is why we do not put it here.
179          */
180 out:
181         if (rc) {
182                 CERROR("llite: Unable to mount %s: rc = %d\n",
183                        s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
184         } else {
185                 CDEBUG(D_SUPER, "%s: Mount complete\n",
186                        lmd->lmd_dev);
187         }
188         lockdep_on();
189         return rc;
190 }
191
192 /***************** FS registration ******************/
193 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
194                                    const char *devname, void *data)
195 {
196         return mount_nodev(fs_type, flags, data, lustre_fill_super);
197 }
198
199 static void lustre_kill_super(struct super_block *sb)
200 {
201         struct lustre_sb_info *lsi = s2lsi(sb);
202
203         if (lsi && !IS_SERVER(lsi))
204                 ll_kill_super(sb);
205
206         kill_anon_super(sb);
207 }
208
209 /** Register the "lustre" fs type
210  */
211 static struct file_system_type lustre_fs_type = {
212         .owner          = THIS_MODULE,
213         .name           = "lustre",
214         .mount          = lustre_mount,
215         .kill_sb        = lustre_kill_super,
216         .fs_flags       = FS_RENAME_DOES_D_MOVE,
217 };
218 MODULE_ALIAS_FS("lustre");
219
220 static int __init lustre_init(void)
221 {
222         struct lnet_processid lnet_id;
223         int i, rc;
224         unsigned long lustre_inode_cache_flags;
225
226         BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
227                      LUSTRE_VOLATILE_HDR_LEN + 1);
228
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.*/
232         CDEBUG(D_INFO, "Lustre client module (%p).\n",
233                &lustre_super_operations);
234
235         lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
236                                    SLAB_MEM_SPREAD;
237 #ifdef SLAB_ACCOUNT
238         lustre_inode_cache_flags |= SLAB_ACCOUNT;
239 #endif
240
241         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
242                                             sizeof(struct ll_inode_info),
243                                             0, lustre_inode_cache_flags, NULL);
244         if (ll_inode_cachep == NULL)
245                 GOTO(out_cache, rc = -ENOMEM);
246
247         ll_file_data_slab = kmem_cache_create("ll_file_data",
248                                                  sizeof(struct ll_file_data), 0,
249                                                  SLAB_HWCACHE_ALIGN, NULL);
250         if (ll_file_data_slab == NULL)
251                 GOTO(out_cache, rc = -ENOMEM);
252
253         pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
254                                            sizeof(struct pcc_inode), 0,
255                                            SLAB_HWCACHE_ALIGN, NULL);
256         if (pcc_inode_slab == NULL)
257                 GOTO(out_cache, rc = -ENOMEM);
258
259         rc = llite_tunables_register();
260         if (rc)
261                 GOTO(out_cache, rc);
262
263         /* Nodes with small feet have little entropy. The NID for this
264          * node gives the most entropy in the low bits. */
265         for (i = 0;; i++) {
266                 if (LNetGetId(i, &lnet_id) == -ENOENT)
267                         break;
268
269                 add_device_randomness(&lnet_id.nid, sizeof(lnet_id.nid));
270         }
271
272         rc = vvp_global_init();
273         if (rc != 0)
274                 GOTO(out_tunables, rc);
275
276         cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
277                                          LCT_REMEMBER | LCT_NOREF);
278         if (IS_ERR(cl_inode_fini_env))
279                 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
280
281         cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
282
283         rc = ll_xattr_init();
284         if (rc != 0)
285                 GOTO(out_inode_fini_env, rc);
286
287         rc = register_filesystem(&lustre_fs_type);
288         if (rc)
289                 GOTO(out_xattr, rc);
290
291         RETURN(0);
292
293 out_xattr:
294         ll_xattr_fini();
295 out_inode_fini_env:
296         cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
297 out_vvp:
298         vvp_global_fini();
299 out_tunables:
300         llite_tunables_unregister();
301 out_cache:
302         kmem_cache_destroy(ll_inode_cachep);
303         kmem_cache_destroy(ll_file_data_slab);
304         kmem_cache_destroy(pcc_inode_slab);
305         return rc;
306 }
307
308 static void __exit lustre_exit(void)
309 {
310         unregister_filesystem(&lustre_fs_type);
311
312         llite_tunables_unregister();
313
314         ll_xattr_fini();
315         cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
316         vvp_global_fini();
317
318         /*
319          * Make sure all delayed rcu free inodes are flushed before we
320          * destroy cache.
321          */
322         rcu_barrier();
323
324         kmem_cache_destroy(ll_inode_cachep);
325         kmem_cache_destroy(ll_file_data_slab);
326         kmem_cache_destroy(pcc_inode_slab);
327 }
328
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");
333
334 module_init(lustre_init);
335 module_exit(lustre_exit);