blob: 106cd00910a7e34b5cf45a8918393bca3e37cdc5 [file] [log] [blame]
Peng Taod7e09d02013-05-02 16:46:55 +08001/*
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
Oleg Drokin6a5b99a2016-06-14 23:33:40 -040018 * http://www.gnu.org/licenses/gpl-2.0.html
Peng Taod7e09d02013-05-02 16:46:55 +080019 *
Peng Taod7e09d02013-05-02 16:46:55 +080020 * 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, Intel Corporation.
27 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32
33#define DEBUG_SUBSYSTEM S_LLITE
34
35#include <linux/module.h>
36#include <linux/types.h>
Greg Kroah-Hartman67a235f2014-07-11 21:51:41 -070037#include "../include/lustre_ha.h"
38#include "../include/lustre_dlm.h"
Peng Taod7e09d02013-05-02 16:46:55 +080039#include <linux/init.h>
40#include <linux/fs.h>
Greg Kroah-Hartman67a235f2014-07-11 21:51:41 -070041#include "../include/lprocfs_status.h"
Peng Taod7e09d02013-05-02 16:46:55 +080042#include "llite_internal.h"
43
44static struct kmem_cache *ll_inode_cachep;
45
46static struct inode *ll_alloc_inode(struct super_block *sb)
47{
48 struct ll_inode_info *lli;
Mike Rapoport50ffcb72015-10-13 16:03:40 +030049
Peng Taod7e09d02013-05-02 16:46:55 +080050 ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_ALLOC_INODE, 1);
Amitoj Kaur Chawla21068c42016-02-26 14:25:09 +053051 lli = kmem_cache_zalloc(ll_inode_cachep, GFP_NOFS);
Oleg Drokin6e168182016-02-16 00:46:46 -050052 if (!lli)
Peng Taod7e09d02013-05-02 16:46:55 +080053 return NULL;
54
55 inode_init_once(&lli->lli_vfs_inode);
56 return &lli->lli_vfs_inode;
57}
58
59static void ll_inode_destroy_callback(struct rcu_head *head)
60{
61 struct inode *inode = container_of(head, struct inode, i_rcu);
62 struct ll_inode_info *ptr = ll_i2info(inode);
Mike Rapoport50ffcb72015-10-13 16:03:40 +030063
Mike Rapoport50d30362015-10-20 12:39:51 +030064 kmem_cache_free(ll_inode_cachep, ptr);
Peng Taod7e09d02013-05-02 16:46:55 +080065}
66
67static void ll_destroy_inode(struct inode *inode)
68{
69 call_rcu(&inode->i_rcu, ll_inode_destroy_callback);
70}
71
Peng Taod7e09d02013-05-02 16:46:55 +080072/* exported operations */
Greg Donald9d0b2b72014-08-22 09:06:15 -050073struct super_operations lustre_super_operations = {
Peng Taod7e09d02013-05-02 16:46:55 +080074 .alloc_inode = ll_alloc_inode,
75 .destroy_inode = ll_destroy_inode,
76 .evict_inode = ll_delete_inode,
77 .put_super = ll_put_super,
78 .statfs = ll_statfs,
79 .umount_begin = ll_umount_begin,
80 .remount_fs = ll_remount_fs,
81 .show_options = ll_show_options,
82};
Peng Tao69d19382013-06-03 21:58:16 +080083MODULE_ALIAS_FS("lustre");
Peng Taod7e09d02013-05-02 16:46:55 +080084
Andreas Dilgere0f94112016-02-26 11:36:05 -050085static int __init lustre_init(void)
Peng Taod7e09d02013-05-02 16:46:55 +080086{
Peng Taod7e09d02013-05-02 16:46:55 +080087 lnet_process_id_t lnet_id;
Arnd Bergmann1f4fc342015-09-27 16:45:14 -040088 struct timespec64 ts;
John L. Hammond081fa9d2015-02-01 21:52:08 -050089 int i, rc, seed[2];
Peng Taod7e09d02013-05-02 16:46:55 +080090
91 CLASSERT(sizeof(LUSTRE_VOLATILE_HDR) == LUSTRE_VOLATILE_HDR_LEN + 1);
92
93 /* print an address of _any_ initialized kernel symbol from this
94 * module, to allow debugging with gdb that doesn't support data
Oleg Drokinc0894c62016-02-24 22:00:30 -050095 * symbols from modules.
96 */
Peng Taod7e09d02013-05-02 16:46:55 +080097 CDEBUG(D_INFO, "Lustre client module (%p).\n",
98 &lustre_super_operations);
99
John L. Hammond081fa9d2015-02-01 21:52:08 -0500100 rc = -ENOMEM;
101 ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
Oleg Drokincd94f232016-08-21 18:04:34 -0400102 sizeof(struct ll_inode_info), 0,
103 SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT,
Vladimir Davydov5d097052016-01-14 15:18:21 -0800104 NULL);
Oleg Drokin6e168182016-02-16 00:46:46 -0500105 if (!ll_inode_cachep)
John L. Hammond081fa9d2015-02-01 21:52:08 -0500106 goto out_cache;
107
Peng Taod7e09d02013-05-02 16:46:55 +0800108 ll_file_data_slab = kmem_cache_create("ll_file_data",
Oleg Drokine15ba452016-02-26 01:49:49 -0500109 sizeof(struct ll_file_data), 0,
110 SLAB_HWCACHE_ALIGN, NULL);
Oleg Drokin6e168182016-02-16 00:46:46 -0500111 if (!ll_file_data_slab)
John L. Hammond081fa9d2015-02-01 21:52:08 -0500112 goto out_cache;
Peng Taod7e09d02013-05-02 16:46:55 +0800113
Oleg Drokinae7c0f42015-05-30 23:27:00 -0400114 llite_root = debugfs_create_dir("llite", debugfs_lustre_root);
115 if (IS_ERR_OR_NULL(llite_root)) {
116 rc = llite_root ? PTR_ERR(llite_root) : -ENOMEM;
117 llite_root = NULL;
John L. Hammond081fa9d2015-02-01 21:52:08 -0500118 goto out_cache;
Peng Taod7e09d02013-05-02 16:46:55 +0800119 }
120
Oleg Drokinfd0d04b2015-05-21 15:31:37 -0400121 llite_kset = kset_create_and_add("llite", NULL, lustre_kobj);
122 if (!llite_kset) {
123 rc = -ENOMEM;
Oleg Drokinae7c0f42015-05-30 23:27:00 -0400124 goto out_debugfs;
Oleg Drokinfd0d04b2015-05-21 15:31:37 -0400125 }
126
Peng Taod7e09d02013-05-02 16:46:55 +0800127 cfs_get_random_bytes(seed, sizeof(seed));
128
John L. Hammond081fa9d2015-02-01 21:52:08 -0500129 /* Nodes with small feet have little entropy. The NID for this
Oleg Drokinc0894c62016-02-24 22:00:30 -0500130 * node gives the most entropy in the low bits
131 */
John L. Hammond081fa9d2015-02-01 21:52:08 -0500132 for (i = 0;; i++) {
133 if (LNetGetId(i, &lnet_id) == -ENOENT)
Peng Taod7e09d02013-05-02 16:46:55 +0800134 break;
John L. Hammond081fa9d2015-02-01 21:52:08 -0500135
136 if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND)
Peng Taod7e09d02013-05-02 16:46:55 +0800137 seed[0] ^= LNET_NIDADDR(lnet_id.nid);
Peng Taod7e09d02013-05-02 16:46:55 +0800138 }
139
Arnd Bergmann1f4fc342015-09-27 16:45:14 -0400140 ktime_get_ts64(&ts);
141 cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]);
Peng Taod7e09d02013-05-02 16:46:55 +0800142
John L. Hammond081fa9d2015-02-01 21:52:08 -0500143 rc = vvp_global_init();
144 if (rc != 0)
Oleg Drokinef2e0f52015-09-27 16:45:46 -0400145 goto out_sysfs;
John L. Hammond081fa9d2015-02-01 21:52:08 -0500146
John Hammonda37bec72016-03-30 19:48:58 -0400147 cl_inode_fini_env = cl_env_alloc(&cl_inode_fini_refcheck,
148 LCT_REMEMBER | LCT_NOREF);
149 if (IS_ERR(cl_inode_fini_env)) {
150 rc = PTR_ERR(cl_inode_fini_env);
151 goto out_vvp;
152 }
153
154 cl_inode_fini_env->le_ctx.lc_cookie = 0x4;
155
John L. Hammond081fa9d2015-02-01 21:52:08 -0500156 rc = ll_xattr_init();
157 if (rc != 0)
John Hammonda37bec72016-03-30 19:48:58 -0400158 goto out_inode_fini_env;
John L. Hammond081fa9d2015-02-01 21:52:08 -0500159
160 lustre_register_client_fill_super(ll_fill_super);
161 lustre_register_kill_super_cb(ll_kill_super);
162 lustre_register_client_process_config(ll_process_config);
163
164 return 0;
165
John Hammonda37bec72016-03-30 19:48:58 -0400166out_inode_fini_env:
167 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
John L. Hammond081fa9d2015-02-01 21:52:08 -0500168out_vvp:
169 vvp_global_fini();
Oleg Drokinfd0d04b2015-05-21 15:31:37 -0400170out_sysfs:
171 kset_unregister(llite_kset);
Oleg Drokinae7c0f42015-05-30 23:27:00 -0400172out_debugfs:
173 debugfs_remove(llite_root);
John L. Hammond081fa9d2015-02-01 21:52:08 -0500174out_cache:
Julia Lawallce85ed42015-09-13 14:15:06 +0200175 kmem_cache_destroy(ll_inode_cachep);
176 kmem_cache_destroy(ll_file_data_slab);
Peng Taod7e09d02013-05-02 16:46:55 +0800177 return rc;
178}
179
Andreas Dilgere0f94112016-02-26 11:36:05 -0500180static void __exit lustre_exit(void)
Peng Taod7e09d02013-05-02 16:46:55 +0800181{
John L. Hammond081fa9d2015-02-01 21:52:08 -0500182 lustre_register_client_fill_super(NULL);
183 lustre_register_kill_super_cb(NULL);
184 lustre_register_client_process_config(NULL);
185
Oleg Drokinae7c0f42015-05-30 23:27:00 -0400186 debugfs_remove(llite_root);
Oleg Drokinfd0d04b2015-05-21 15:31:37 -0400187 kset_unregister(llite_kset);
John L. Hammond081fa9d2015-02-01 21:52:08 -0500188
Andrew Perepechko7fc1f832013-12-03 21:58:49 +0800189 ll_xattr_fini();
John Hammonda37bec72016-03-30 19:48:58 -0400190 cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck);
Peng Taod7e09d02013-05-02 16:46:55 +0800191 vvp_global_fini();
Peng Taod7e09d02013-05-02 16:46:55 +0800192
John L. Hammond081fa9d2015-02-01 21:52:08 -0500193 kmem_cache_destroy(ll_inode_cachep);
Peng Taod7e09d02013-05-02 16:46:55 +0800194 kmem_cache_destroy(ll_file_data_slab);
Peng Taod7e09d02013-05-02 16:46:55 +0800195}
196
James Simmonsa0455472015-11-04 13:40:02 -0500197MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
Andreas Dilger57878e12016-02-26 11:36:04 -0500198MODULE_DESCRIPTION("Lustre Client File System");
James Simmons5b0e50b2016-02-26 11:36:03 -0500199MODULE_VERSION(LUSTRE_VERSION_STRING);
Peng Taod7e09d02013-05-02 16:46:55 +0800200MODULE_LICENSE("GPL");
201
Andreas Dilgere0f94112016-02-26 11:36:05 -0500202module_init(lustre_init);
203module_exit(lustre_exit);