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