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