Whamcloud - gitweb
LU-17081 build: Prefer folio_batch to pagevec
[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         llcrypt_free_inode(inode);
76         OBD_SLAB_FREE_PTR(ptr, ll_inode_cachep);
77 }
78
79 static void ll_destroy_inode(struct inode *inode)
80 {
81         call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
82 }
83
84 static int ll_drop_inode(struct inode *inode)
85 {
86         struct ll_sb_info *sbi = ll_i2sbi(inode);
87         int drop;
88
89         if (!sbi->ll_inode_cache_enabled)
90                 return 1;
91
92         drop = generic_drop_inode(inode);
93         if (!drop)
94                 drop = llcrypt_drop_inode(inode);
95
96         return drop;
97 }
98
99 /* exported operations */
100 const struct super_operations lustre_super_operations =
101 {
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         CDEBUG(D_INFO, "Lustre client module (%p).\n",
242                &lustre_super_operations);
243
244         lustre_inode_cache_flags = SLAB_HWCACHE_ALIGN | SLAB_RECLAIM_ACCOUNT |
245                                    SLAB_MEM_SPREAD;
246 #ifdef SLAB_ACCOUNT
247         lustre_inode_cache_flags |= SLAB_ACCOUNT;
248 #endif
249
250         ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
251                                             sizeof(struct ll_inode_info),
252                                             0, lustre_inode_cache_flags, NULL);
253         if (ll_inode_cachep == NULL)
254                 GOTO(out_cache, rc = -ENOMEM);
255
256         ll_file_data_slab = kmem_cache_create("ll_file_data",
257                                                  sizeof(struct ll_file_data), 0,
258                                                  SLAB_HWCACHE_ALIGN, NULL);
259         if (ll_file_data_slab == NULL)
260                 GOTO(out_cache, rc = -ENOMEM);
261
262         pcc_inode_slab = kmem_cache_create("ll_pcc_inode",
263                                            sizeof(struct pcc_inode), 0,
264                                            SLAB_HWCACHE_ALIGN, NULL);
265         if (pcc_inode_slab == NULL)
266                 GOTO(out_cache, rc = -ENOMEM);
267
268         quota_iter_slab = kmem_cache_create("ll_quota_iter",
269                                            sizeof(struct if_quotactl_iter), 0,
270                                            SLAB_HWCACHE_ALIGN, NULL);
271         if (quota_iter_slab == NULL)
272                 GOTO(out_cache, rc = -ENOMEM);
273
274         rc = llite_tunables_register();
275         if (rc)
276                 GOTO(out_cache, rc);
277
278         rc = vvp_global_init();
279         if (rc != 0)
280                 GOTO(out_tunables, rc);
281
282         cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
283                                          LCT_REMEMBER | LCT_NOREF);
284         if (IS_ERR(cl_inode_fini_env))
285                 GOTO(out_vvp, rc = PTR_ERR(cl_inode_fini_env));
286
287         cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
288
289         rc = ll_xattr_init();
290         if (rc != 0)
291                 GOTO(out_inode_fini_env, rc);
292
293         rc = register_filesystem(&lustre_fs_type);
294         if (rc)
295                 GOTO(out_xattr, rc);
296
297         RETURN(0);
298
299 out_xattr:
300         ll_xattr_fini();
301 out_inode_fini_env:
302         cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
303 out_vvp:
304         vvp_global_fini();
305 out_tunables:
306         llite_tunables_unregister();
307 out_cache:
308         kmem_cache_destroy(ll_inode_cachep);
309         kmem_cache_destroy(ll_file_data_slab);
310         kmem_cache_destroy(pcc_inode_slab);
311         kmem_cache_destroy(quota_iter_slab);
312         return rc;
313 }
314
315 static void __exit lustre_exit(void)
316 {
317         unregister_filesystem(&lustre_fs_type);
318
319         llite_tunables_unregister();
320
321         ll_xattr_fini();
322         cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
323         vvp_global_fini();
324
325         /*
326          * Make sure all delayed rcu free inodes are flushed before we
327          * destroy cache.
328          */
329         rcu_barrier();
330
331         kmem_cache_destroy(ll_inode_cachep);
332         kmem_cache_destroy(ll_file_data_slab);
333         kmem_cache_destroy(pcc_inode_slab);
334         kmem_cache_destroy(quota_iter_slab);
335 }
336
337 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
338 MODULE_DESCRIPTION("Lustre Client File System");
339 MODULE_VERSION(LUSTRE_VERSION_STRING);
340 MODULE_LICENSE("GPL");
341
342 module_init(lustre_init);
343 module_exit(lustre_exit);