Whamcloud - gitweb
LU-14487 modules: remove references to Sun Trademark.
[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         int drop = generic_drop_inode(inode);
77
78         if (!drop)
79                 drop = llcrypt_drop_inode(inode);
80
81         return drop;
82 }
83
84 /* exported operations */
85 const struct super_operations lustre_super_operations =
86 {
87         .alloc_inode   = ll_alloc_inode,
88         .destroy_inode = ll_destroy_inode,
89         .drop_inode    = ll_drop_inode,
90         .evict_inode   = ll_delete_inode,
91         .put_super     = ll_put_super,
92         .statfs        = ll_statfs,
93         .umount_begin  = ll_umount_begin,
94         .remount_fs    = ll_remount_fs,
95         .show_options  = ll_show_options,
96 };
97
98 /**
99  * This is the entry point for the mount call into Lustre.
100  * This is called when a client is mounted, and this is
101  * where we start setting things up.
102  *
103  * @lmd2data data Mount options (e.g. -o flock,abort_recov)
104  */
105 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
106                              int silent)
107 {
108         struct lustre_mount_data *lmd;
109         struct lustre_sb_info *lsi;
110         int rc;
111
112         ENTRY;
113
114         CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
115
116         lsi = lustre_init_lsi(sb);
117         if (!lsi)
118                 RETURN(-ENOMEM);
119         lmd = lsi->lsi_lmd;
120
121         /*
122          * Disable lockdep during mount, because mount locking patterns are
123          * 'special'.
124          */
125         lockdep_off();
126
127         /*
128          * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
129          */
130         obd_zombie_barrier();
131
132         /* Figure out the lmd from the mount options */
133         if (lmd_parse(lmd2_data, lmd)) {
134                 lustre_put_lsi(sb);
135                 GOTO(out, rc = -EINVAL);
136         }
137
138         if (!lmd_is_client(lmd)) {
139 #ifdef HAVE_SERVER_SUPPORT
140 #if LUSTRE_VERSION_CODE > OBD_OCD_VERSION(2, 15, 51, 0)
141                 static bool printed;
142
143                 if (!printed) {
144                         LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
145                                       lmd->lmd_profile);
146                         printed = true;
147                 }
148 #endif
149                 rc = server_fill_super(sb);
150 #else
151                 rc = -ENODEV;
152                 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
153                        lmd->lmd_profile, rc);
154                 lustre_put_lsi(sb);
155 #endif
156                 GOTO(out, rc);
157         }
158
159         CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
160         rc = lustre_start_mgc(sb);
161         if (rc) {
162                 lustre_common_put_super(sb);
163                 GOTO(out, rc);
164         }
165         /* Connect and start */
166         rc = ll_fill_super(sb);
167         /* ll_file_super will call lustre_common_put_super on failure,
168          * which takes care of the module reference.
169          *
170          * If error happens in fill_super() call, @lsi will be killed there.
171          * This is why we do not put it here.
172          */
173 out:
174         if (rc) {
175                 CERROR("llite: Unable to mount %s: rc = %d\n",
176                        s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
177         } else {
178                 CDEBUG(D_SUPER, "%s: Mount complete\n",
179                        lmd->lmd_dev);
180         }
181         lockdep_on();
182         return rc;
183 }
184
185 /***************** FS registration ******************/
186 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
187                                    const char *devname, void *data)
188 {
189         return mount_nodev(fs_type, flags, data, lustre_fill_super);
190 }
191
192 static void lustre_kill_super(struct super_block *sb)
193 {
194         struct lustre_sb_info *lsi = s2lsi(sb);
195
196         if (lsi && !IS_SERVER(lsi))
197                 ll_kill_super(sb);
198
199         kill_anon_super(sb);
200 }
201
202 /** Register the "lustre" fs type
203  */
204 static struct file_system_type lustre_fs_type = {
205         .owner          = THIS_MODULE,
206         .name           = "lustre",
207         .mount          = lustre_mount,
208         .kill_sb        = lustre_kill_super,
209         .fs_flags       = FS_RENAME_DOES_D_MOVE,
210 };
211 MODULE_ALIAS_FS("lustre");
212
213 static int __init lustre_init(void)
214 {
215         struct lnet_process_id lnet_id;
216         int i, rc;
217         unsigned long lustre_inode_cache_flags;
218
219         BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
220                      LUSTRE_VOLATILE_HDR_LEN + 1);
221
222         /* print an address of _any_ initialized kernel symbol from this
223          * module, to allow debugging with gdb that doesn't support data
224          * symbols from modules.*/
225         CDEBUG(D_INFO, "Lustre client module (%p).\n",
226                &lustre_super_operations);
227
228         lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
229                                    SLAB_MEM_SPREAD;
230 #ifdef SLAB_ACCOUNT
231         lustre_inode_cache_flags |= SLAB_ACCOUNT;
232 #endif
233
234         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
235                                             sizeof(struct ll_inode_info),
236                                             0, lustre_inode_cache_flags, NULL);
237         if (ll_inode_cachep == NULL)
238                 GOTO(out_cache, rc = -ENOMEM);
239
240         ll_file_data_slab = kmem_cache_create("ll_file_data",
241                                                  sizeof(struct ll_file_data), 0,
242                                                  SLAB_HWCACHE_ALIGN, NULL);
243         if (ll_file_data_slab == NULL)
244                 GOTO(out_cache, rc = -ENOMEM);
245
246         pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
247                                            sizeof(struct pcc_inode), 0,
248                                            SLAB_HWCACHE_ALIGN, NULL);
249         if (pcc_inode_slab == NULL)
250                 GOTO(out_cache, rc = -ENOMEM);
251
252         rc = llite_tunables_register();
253         if (rc)
254                 GOTO(out_cache, rc);
255
256         /* Nodes with small feet have little entropy. The NID for this
257          * node gives the most entropy in the low bits. */
258         for (i = 0;; i++) {
259                 if (LNetGetId(i, &lnet_id) == -ENOENT)
260                         break;
261
262                 add_device_randomness(&lnet_id.nid, sizeof(lnet_id.nid));
263         }
264
265         rc = vvp_global_init();
266         if (rc != 0)
267                 GOTO(out_tunables, rc);
268
269         cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
270                                          LCT_REMEMBER | LCT_NOREF);
271         if (IS_ERR(cl_inode_fini_env))
272                 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
273
274         cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
275
276         rc = ll_xattr_init();
277         if (rc != 0)
278                 GOTO(out_inode_fini_env, rc);
279
280         rc = register_filesystem(&lustre_fs_type);
281         if (rc)
282                 GOTO(out_xattr, rc);
283
284         RETURN(0);
285
286 out_xattr:
287         ll_xattr_fini();
288 out_inode_fini_env:
289         cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
290 out_vvp:
291         vvp_global_fini();
292 out_tunables:
293         llite_tunables_unregister();
294 out_cache:
295         kmem_cache_destroy(ll_inode_cachep);
296         kmem_cache_destroy(ll_file_data_slab);
297         kmem_cache_destroy(pcc_inode_slab);
298         return rc;
299 }
300
301 static void __exit lustre_exit(void)
302 {
303         unregister_filesystem(&lustre_fs_type);
304
305         llite_tunables_unregister();
306
307         ll_xattr_fini();
308         cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
309         vvp_global_fini();
310
311         /*
312          * Make sure all delayed rcu free inodes are flushed before we
313          * destroy cache.
314          */
315         rcu_barrier();
316
317         kmem_cache_destroy(ll_inode_cachep);
318         kmem_cache_destroy(ll_file_data_slab);
319         kmem_cache_destroy(pcc_inode_slab);
320 }
321
322 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
323 MODULE_DESCRIPTION("Lustre Client File System");
324 MODULE_VERSION(LUSTRE_VERSION_STRING);
325 MODULE_LICENSE("GPL");
326
327 module_init(lustre_init);
328 module_exit(lustre_exit);