Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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, 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-Hartman | 67a235f | 2014-07-11 21:51:41 -0700 | [diff] [blame] | 37 | #include "../include/lustre_ha.h" |
| 38 | #include "../include/lustre_dlm.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 39 | #include <linux/init.h> |
| 40 | #include <linux/fs.h> |
Greg Kroah-Hartman | 67a235f | 2014-07-11 21:51:41 -0700 | [diff] [blame] | 41 | #include "../include/lprocfs_status.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 42 | #include "llite_internal.h" |
| 43 | |
| 44 | static struct kmem_cache *ll_inode_cachep; |
| 45 | |
| 46 | static struct inode *ll_alloc_inode(struct super_block *sb) |
| 47 | { |
| 48 | struct ll_inode_info *lli; |
Mike Rapoport | 50ffcb7 | 2015-10-13 16:03:40 +0300 | [diff] [blame] | 49 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 50 | ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_ALLOC_INODE, 1); |
Amitoj Kaur Chawla | 21068c4 | 2016-02-26 14:25:09 +0530 | [diff] [blame] | 51 | lli = kmem_cache_zalloc(ll_inode_cachep, GFP_NOFS); |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 52 | if (!lli) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 53 | return NULL; |
| 54 | |
| 55 | inode_init_once(&lli->lli_vfs_inode); |
| 56 | return &lli->lli_vfs_inode; |
| 57 | } |
| 58 | |
| 59 | static 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 Rapoport | 50ffcb7 | 2015-10-13 16:03:40 +0300 | [diff] [blame] | 63 | |
Mike Rapoport | 50d3036 | 2015-10-20 12:39:51 +0300 | [diff] [blame] | 64 | kmem_cache_free(ll_inode_cachep, ptr); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static void ll_destroy_inode(struct inode *inode) |
| 68 | { |
| 69 | call_rcu(&inode->i_rcu, ll_inode_destroy_callback); |
| 70 | } |
| 71 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 72 | /* exported operations */ |
Greg Donald | 9d0b2b7 | 2014-08-22 09:06:15 -0500 | [diff] [blame] | 73 | struct super_operations lustre_super_operations = { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 74 | .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 Tao | 69d1938 | 2013-06-03 21:58:16 +0800 | [diff] [blame] | 83 | MODULE_ALIAS_FS("lustre"); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 84 | |
Andreas Dilger | e0f9411 | 2016-02-26 11:36:05 -0500 | [diff] [blame] | 85 | static int __init lustre_init(void) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 86 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 87 | lnet_process_id_t lnet_id; |
Arnd Bergmann | 1f4fc34 | 2015-09-27 16:45:14 -0400 | [diff] [blame] | 88 | struct timespec64 ts; |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 89 | int i, rc, seed[2]; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 90 | |
| 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 Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 95 | * symbols from modules. |
| 96 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 97 | CDEBUG(D_INFO, "Lustre client module (%p).\n", |
| 98 | &lustre_super_operations); |
| 99 | |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 100 | rc = -ENOMEM; |
| 101 | ll_inode_cachep = kmem_cache_create("lustre_inode_cache", |
Oleg Drokin | cd94f23 | 2016-08-21 18:04:34 -0400 | [diff] [blame] | 102 | sizeof(struct ll_inode_info), 0, |
| 103 | SLAB_HWCACHE_ALIGN | SLAB_ACCOUNT, |
Vladimir Davydov | 5d09705 | 2016-01-14 15:18:21 -0800 | [diff] [blame] | 104 | NULL); |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 105 | if (!ll_inode_cachep) |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 106 | goto out_cache; |
| 107 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 108 | ll_file_data_slab = kmem_cache_create("ll_file_data", |
Oleg Drokin | e15ba45 | 2016-02-26 01:49:49 -0500 | [diff] [blame] | 109 | sizeof(struct ll_file_data), 0, |
| 110 | SLAB_HWCACHE_ALIGN, NULL); |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 111 | if (!ll_file_data_slab) |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 112 | goto out_cache; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 113 | |
Oleg Drokin | ae7c0f4 | 2015-05-30 23:27:00 -0400 | [diff] [blame] | 114 | 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. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 118 | goto out_cache; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | } |
| 120 | |
Oleg Drokin | fd0d04b | 2015-05-21 15:31:37 -0400 | [diff] [blame] | 121 | llite_kset = kset_create_and_add("llite", NULL, lustre_kobj); |
| 122 | if (!llite_kset) { |
| 123 | rc = -ENOMEM; |
Oleg Drokin | ae7c0f4 | 2015-05-30 23:27:00 -0400 | [diff] [blame] | 124 | goto out_debugfs; |
Oleg Drokin | fd0d04b | 2015-05-21 15:31:37 -0400 | [diff] [blame] | 125 | } |
| 126 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 127 | cfs_get_random_bytes(seed, sizeof(seed)); |
| 128 | |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 129 | /* Nodes with small feet have little entropy. The NID for this |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 130 | * node gives the most entropy in the low bits |
| 131 | */ |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 132 | for (i = 0;; i++) { |
| 133 | if (LNetGetId(i, &lnet_id) == -ENOENT) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 134 | break; |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 135 | |
| 136 | if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 137 | seed[0] ^= LNET_NIDADDR(lnet_id.nid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 138 | } |
| 139 | |
Arnd Bergmann | 1f4fc34 | 2015-09-27 16:45:14 -0400 | [diff] [blame] | 140 | ktime_get_ts64(&ts); |
| 141 | cfs_srand(ts.tv_sec ^ seed[0], ts.tv_nsec ^ seed[1]); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 142 | |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 143 | rc = vvp_global_init(); |
| 144 | if (rc != 0) |
Oleg Drokin | ef2e0f5 | 2015-09-27 16:45:46 -0400 | [diff] [blame] | 145 | goto out_sysfs; |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 146 | |
John Hammond | a37bec7 | 2016-03-30 19:48:58 -0400 | [diff] [blame] | 147 | 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. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 156 | rc = ll_xattr_init(); |
| 157 | if (rc != 0) |
John Hammond | a37bec7 | 2016-03-30 19:48:58 -0400 | [diff] [blame] | 158 | goto out_inode_fini_env; |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 159 | |
| 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 Hammond | a37bec7 | 2016-03-30 19:48:58 -0400 | [diff] [blame] | 166 | out_inode_fini_env: |
| 167 | cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck); |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 168 | out_vvp: |
| 169 | vvp_global_fini(); |
Oleg Drokin | fd0d04b | 2015-05-21 15:31:37 -0400 | [diff] [blame] | 170 | out_sysfs: |
| 171 | kset_unregister(llite_kset); |
Oleg Drokin | ae7c0f4 | 2015-05-30 23:27:00 -0400 | [diff] [blame] | 172 | out_debugfs: |
| 173 | debugfs_remove(llite_root); |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 174 | out_cache: |
Julia Lawall | ce85ed4 | 2015-09-13 14:15:06 +0200 | [diff] [blame] | 175 | kmem_cache_destroy(ll_inode_cachep); |
| 176 | kmem_cache_destroy(ll_file_data_slab); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 177 | return rc; |
| 178 | } |
| 179 | |
Andreas Dilger | e0f9411 | 2016-02-26 11:36:05 -0500 | [diff] [blame] | 180 | static void __exit lustre_exit(void) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 181 | { |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 182 | lustre_register_client_fill_super(NULL); |
| 183 | lustre_register_kill_super_cb(NULL); |
| 184 | lustre_register_client_process_config(NULL); |
| 185 | |
Oleg Drokin | ae7c0f4 | 2015-05-30 23:27:00 -0400 | [diff] [blame] | 186 | debugfs_remove(llite_root); |
Oleg Drokin | fd0d04b | 2015-05-21 15:31:37 -0400 | [diff] [blame] | 187 | kset_unregister(llite_kset); |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 188 | |
Andrew Perepechko | 7fc1f83 | 2013-12-03 21:58:49 +0800 | [diff] [blame] | 189 | ll_xattr_fini(); |
John Hammond | a37bec7 | 2016-03-30 19:48:58 -0400 | [diff] [blame] | 190 | cl_env_put(cl_inode_fini_env, &cl_inode_fini_refcheck); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 191 | vvp_global_fini(); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 192 | |
John L. Hammond | 081fa9d | 2015-02-01 21:52:08 -0500 | [diff] [blame] | 193 | kmem_cache_destroy(ll_inode_cachep); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 194 | kmem_cache_destroy(ll_file_data_slab); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 195 | } |
| 196 | |
James Simmons | a045547 | 2015-11-04 13:40:02 -0500 | [diff] [blame] | 197 | MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); |
Andreas Dilger | 57878e1 | 2016-02-26 11:36:04 -0500 | [diff] [blame] | 198 | MODULE_DESCRIPTION("Lustre Client File System"); |
James Simmons | 5b0e50b | 2016-02-26 11:36:03 -0500 | [diff] [blame] | 199 | MODULE_VERSION(LUSTRE_VERSION_STRING); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 200 | MODULE_LICENSE("GPL"); |
| 201 | |
Andreas Dilger | e0f9411 | 2016-02-26 11:36:05 -0500 | [diff] [blame] | 202 | module_init(lustre_init); |
| 203 | module_exit(lustre_exit); |