Whamcloud - gitweb
71b45b9a50a1bcd4516c6ecc9214e5666f1cfb5a
[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 #ifdef HAVE_ALLOC_INODE_SB
54         lli = alloc_inode_sb(sb, ll_inode_cachep, GFP_NOFS);
55         if (!lli)
56                 return NULL;
57         OBD_ALLOC_POST(lli, sizeof(*lli), "slab-alloced");
58         memset(lli, 0, sizeof(*lli));
59 #else
60         OBD_SLAB_ALLOC_PTR_GFP(lli, ll_inode_cachep, GFP_NOFS);
61         if (!lli)
62                 return NULL;
63 #endif
64         inode_init_once(&lli->lli_vfs_inode);
65         return &lli->lli_vfs_inode;
66 }
67
68 static void ll_inode_destroy_callback(struct rcu_head *head)
69 {
70         struct inode *inode = container_of(head, struct inode, i_rcu);
71         struct ll_inode_info *ptr = ll_i2info(inode);
72         llcrypt_free_inode(inode);
73         OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
74 }
75
76 static void ll_destroy_inode(struct inode *inode)
77 {
78         call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
79 }
80
81 static int ll_drop_inode(struct inode *inode)
82 {
83         struct ll_sb_info *sbi = ll_i2sbi(inode);
84         int drop;
85
86         if (!sbi->ll_inode_cache_enabled)
87                 return 1;
88
89         drop = generic_drop_inode(inode);
90         if (!drop)
91                 drop = llcrypt_drop_inode(inode);
92
93         return drop;
94 }
95
96 /* exported operations */
97 const struct super_operations lustre_super_operations =
98 {
99         .alloc_inode   = ll_alloc_inode,
100         .destroy_inode = ll_destroy_inode,
101         .drop_inode    = ll_drop_inode,
102         .evict_inode   = ll_delete_inode,
103         .put_super     = ll_put_super,
104         .statfs        = ll_statfs,
105         .umount_begin  = ll_umount_begin,
106         .remount_fs    = ll_remount_fs,
107         .show_options  = ll_show_options,
108 };
109
110 /**
111  * This is the entry point for the mount call into Lustre.
112  * This is called when a client is mounted, and this is
113  * where we start setting things up.
114  *
115  * @lmd2data data Mount options (e.g. -o flock,abort_recov)
116  */
117 static int lustre_fill_super(struct super_block *sb, void *lmd2_data,
118                              int silent)
119 {
120         struct lustre_mount_data *lmd;
121         struct lustre_sb_info *lsi;
122         int rc;
123
124         ENTRY;
125
126         CDEBUG(D_MOUNT|D_VFSTRACE, "VFS Op: sb %p\n", sb);
127
128         lsi = lustre_init_lsi(sb);
129         if (!lsi)
130                 RETURN(-ENOMEM);
131         lmd = lsi->lsi_lmd;
132
133         /*
134          * Disable lockdep during mount, because mount locking patterns are
135          * 'special'.
136          */
137         lockdep_off();
138
139         /*
140          * LU-639: the OBD cleanup of last mount may not finish yet, wait here.
141          */
142         obd_zombie_barrier();
143
144         /* Figure out the lmd from the mount options */
145         if (lmd_parse(lmd2_data, lmd)) {
146                 lustre_put_lsi(sb);
147                 GOTO(out, rc = -EINVAL);
148         }
149
150         if (!lmd_is_client(lmd)) {
151 #ifdef HAVE_SERVER_SUPPORT
152                 static bool printed;
153
154                 if (!printed) {
155                         LCONSOLE_WARN("%s: mounting server target with '-t lustre' deprecated, use '-t lustre_tgt'\n",
156                                       lmd->lmd_profile);
157                         printed = true;
158                 }
159                 rc = server_fill_super(sb);
160 #else
161                 rc = -ENODEV;
162                 CERROR("%s: This is client-side-only module, cannot handle server mount: rc = %d\n",
163                        lmd->lmd_profile, rc);
164                 lustre_put_lsi(sb);
165 #endif
166                 GOTO(out, rc);
167         }
168
169         CDEBUG(D_MOUNT, "Mounting client %s\n", lmd->lmd_profile);
170         rc = lustre_start_mgc(sb);
171         if (rc) {
172                 lustre_common_put_super(sb);
173                 GOTO(out, rc);
174         }
175         /* Connect and start */
176         rc = ll_fill_super(sb);
177         /* ll_file_super will call lustre_common_put_super on failure,
178          * which takes care of the module reference.
179          *
180          * If error happens in fill_super() call, @lsi will be killed there.
181          * This is why we do not put it here.
182          */
183 out:
184         if (rc) {
185                 CERROR("llite: Unable to mount %s: rc = %d\n",
186                        s2lsi(sb) ? lmd->lmd_dev : "<unknown>", rc);
187         } else {
188                 CDEBUG(D_SUPER, "%s: Mount complete\n",
189                        lmd->lmd_dev);
190         }
191         lockdep_on();
192         return rc;
193 }
194
195 /***************** FS registration ******************/
196 static struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
197                                    const char *devname, void *data)
198 {
199         return mount_nodev(fs_type, flags, data, lustre_fill_super);
200 }
201
202 static void lustre_kill_super(struct super_block *sb)
203 {
204         struct lustre_sb_info *lsi = s2lsi(sb);
205
206         if (lsi && !IS_SERVER(lsi))
207                 ll_kill_super(sb);
208
209         kill_anon_super(sb);
210 }
211
212 /** Register the "lustre" fs type
213  */
214 static struct file_system_type lustre_fs_type = {
215         .owner          = THIS_MODULE,
216         .name           = "lustre",
217         .mount          = lustre_mount,
218         .kill_sb        = lustre_kill_super,
219         .fs_flags       = FS_RENAME_DOES_D_MOVE,
220 };
221 MODULE_ALIAS_FS("lustre");
222
223 static int __init lustre_init(void)
224 {
225         int rc;
226         unsigned long lustre_inode_cache_flags;
227
228         BUILD_BUG_ON(sizeof(LUSTRE_VOLATILE_HDR) !=
229                      LUSTRE_VOLATILE_HDR_LEN + 1);
230
231         /* print an address of _any_ initialized kernel symbol from this
232          * module, to allow debugging with gdb that doesn't support data
233          * symbols from modules.*/
234         CDEBUG(D_INFO, "Lustre client module (%p).\n",
235                &lustre_super_operations);
236
237         lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
238                                    SLAB_MEM_SPREAD;
239 #ifdef SLAB_ACCOUNT
240         lustre_inode_cache_flags |= SLAB_ACCOUNT;
241 #endif
242
243         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
244                                             sizeof(struct ll_inode_info),
245                                             0, lustre_inode_cache_flags, NULL);
246         if (ll_inode_cachep == NULL)
247                 GOTO(out_cache, rc = -ENOMEM);
248
249         ll_file_data_slab = kmem_cache_create("ll_file_data",
250                                                  sizeof(struct ll_file_data), 0,
251                                                  SLAB_HWCACHE_ALIGN, NULL);
252         if (ll_file_data_slab == NULL)
253                 GOTO(out_cache, rc = -ENOMEM);
254
255         pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
256                                            sizeof(struct pcc_inode), 0,
257                                            SLAB_HWCACHE_ALIGN, NULL);
258         if (pcc_inode_slab == NULL)
259                 GOTO(out_cache, rc = -ENOMEM);
260
261         rc = llite_tunables_register();
262         if (rc)
263                 GOTO(out_cache, rc);
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);