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