1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/random.h>
29 #include <linux/version.h>
30 #include <lustre_lite.h>
31 #include <lustre_ha.h>
32 #include <lustre_dlm.h>
33 #include <linux/init.h>
35 #include <lprocfs_status.h>
36 #include "llite_internal.h"
38 static kmem_cache_t *ll_inode_cachep;
40 static struct inode *ll_alloc_inode(struct super_block *sb)
42 struct ll_inode_info *lli;
43 lprocfs_counter_incr((ll_s2sbi(sb))->ll_stats, LPROC_LL_ALLOC_INODE);
44 OBD_SLAB_ALLOC(lli, ll_inode_cachep, SLAB_KERNEL, sizeof *lli);
48 inode_init_once(&lli->lli_vfs_inode);
51 return &lli->lli_vfs_inode;
54 static void ll_destroy_inode(struct inode *inode)
56 struct ll_inode_info *ptr = ll_i2info(inode);
57 OBD_SLAB_FREE(ptr, ll_inode_cachep, sizeof(*ptr));
60 static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
62 struct ll_inode_info *lli = foo;
64 if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
65 SLAB_CTOR_CONSTRUCTOR)
66 inode_init_once(&lli->lli_vfs_inode);
69 int ll_init_inodecache(void)
71 ll_inode_cachep = kmem_cache_create("lustre_inode_cache",
72 sizeof(struct ll_inode_info),
73 0, SLAB_HWCACHE_ALIGN,
75 if (ll_inode_cachep == NULL)
80 void ll_destroy_inodecache(void)
83 rc = kmem_cache_destroy(ll_inode_cachep);
84 LASSERTF(rc == 0, "ll_inode_cache: not all structures were freed\n");
87 /* exported operations */
88 struct super_operations lustre_super_operations =
90 .alloc_inode = ll_alloc_inode,
91 .destroy_inode = ll_destroy_inode,
92 .clear_inode = ll_clear_inode,
93 .delete_inode = ll_delete_inode,
94 .put_super = ll_put_super,
96 .umount_begin = ll_umount_begin,
97 .remount_fs = ll_remount_fs,
101 void lustre_register_client_process_config(int (*cpc)(struct lustre_cfg *lcfg));
103 static int __init init_lustre_lite(void)
107 rc = ll_init_inodecache();
110 ll_file_data_slab = kmem_cache_create("ll_file_data",
111 sizeof(struct ll_file_data), 0,
112 SLAB_HWCACHE_ALIGN, NULL, NULL);
113 if (ll_file_data_slab == NULL) {
114 ll_destroy_inodecache();
118 LASSERT(ll_remote_perm_cachep == NULL);
119 ll_remote_perm_cachep = kmem_cache_create("ll_remote_perm_cache",
120 sizeof(struct ll_remote_perm),
122 if (!ll_remote_perm_cachep) {
123 kmem_cache_destroy(ll_file_data_slab);
124 ll_file_data_slab = NULL;
128 LASSERT(ll_rmtperm_hash_cachep == NULL);
129 ll_rmtperm_hash_cachep = kmem_cache_create("ll_rmtperm_hash_cache",
130 REMOTE_PERM_HASHSIZE *
131 sizeof(struct list_head),
133 if (!ll_rmtperm_hash_cachep) {
134 kmem_cache_destroy(ll_remote_perm_cachep);
135 kmem_cache_destroy(ll_file_data_slab);
136 ll_remote_perm_cachep = NULL;
137 ll_file_data_slab = NULL;
141 proc_lustre_fs_root = proc_lustre_root ?
142 proc_mkdir("llite", proc_lustre_root) : NULL;
144 ll_register_cache(&ll_cache_definition);
146 lustre_register_client_fill_super(ll_fill_super);
147 lustre_register_client_process_config(ll_process_config);
149 get_random_bytes(seed, sizeof(seed));
150 ll_srand(seed[0], seed[1]);
152 init_timer(&ll_capa_timer);
153 ll_capa_timer.function = ll_capa_timer_callback;
154 rc = ll_capa_thread_start();
158 static void __exit exit_lustre_lite(void)
162 del_timer(&ll_capa_timer);
163 ll_capa_thread_stop();
164 LASSERTF(capa_count[CAPA_SITE_CLIENT] == 0,
165 "client remaining capa count %d\n",
166 capa_count[CAPA_SITE_CLIENT]);
168 lustre_register_client_fill_super(NULL);
169 lustre_register_client_process_config(NULL);
171 ll_unregister_cache(&ll_cache_definition);
173 ll_destroy_inodecache();
175 rc = kmem_cache_destroy(ll_rmtperm_hash_cachep);
176 LASSERTF(rc == 0, "couldn't destroy ll_rmtperm_hash_cachep\n");
177 ll_rmtperm_hash_cachep = NULL;
179 rc = kmem_cache_destroy(ll_remote_perm_cachep);
180 LASSERTF(rc == 0, "couldn't destroy ll_remote_perm_cachep\n");
181 ll_remote_perm_cachep = NULL;
183 rc = kmem_cache_destroy(ll_file_data_slab);
184 LASSERTF(rc == 0, "couldn't destroy ll_file_data slab\n");
185 if (ll_async_page_slab) {
186 rc = kmem_cache_destroy(ll_async_page_slab);
187 LASSERTF(rc == 0, "couldn't destroy ll_async_page slab\n");
190 if (proc_lustre_fs_root) {
191 lprocfs_remove(proc_lustre_fs_root);
192 proc_lustre_fs_root = NULL;
196 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
197 MODULE_DESCRIPTION("Lustre Lite Client File System");
198 MODULE_LICENSE("GPL");
200 module_init(init_lustre_lite);
201 module_exit(exit_lustre_lite);