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