blob: e3f6f1844a21471b47003a04dea3c28548f278a8 [file] [log] [blame]
David Teiglandb3b94fa2006-01-16 16:50:04 +00001/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
Steven Whitehouse3a8a9a12006-05-18 15:09:15 -04003 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
David Teiglandb3b94fa2006-01-16 16:50:04 +00004 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
Steven Whitehousee9fc2aa2006-09-01 11:05:15 -04007 * of the GNU General Public License version 2.
David Teiglandb3b94fa2006-01-16 16:50:04 +00008 */
9
David Teiglandb3b94fa2006-01-16 16:50:04 +000010#include <linux/slab.h>
11#include <linux/spinlock.h>
12#include <linux/completion.h>
13#include <linux/buffer_head.h>
14#include <linux/module.h>
15#include <linux/init.h>
Steven Whitehouse5c676f62006-02-27 17:23:27 -050016#include <linux/gfs2_ondisk.h>
Fabio Massimo Di Nitto7d308592006-09-19 07:56:29 +020017#include <linux/lm_interface.h>
Steven Whitehouseec45d9f2006-08-30 10:36:52 -040018#include <asm/atomic.h>
David Teiglandb3b94fa2006-01-16 16:50:04 +000019
20#include "gfs2.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050021#include "incore.h"
Steven Whitehouseb2760582008-10-14 16:05:55 +010022#include "super.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000023#include "sys.h"
Steven Whitehouse5c676f62006-02-27 17:23:27 -050024#include "util.h"
Steven Whitehouse85d1da62006-09-07 14:40:21 -040025#include "glock.h"
David Teiglandb3b94fa2006-01-16 16:50:04 +000026
Alexey Dobriyan51cc5062008-07-25 19:45:34 -070027static void gfs2_init_inode_once(void *foo)
Steven Whitehouse320dd102006-05-18 16:25:27 -040028{
29 struct gfs2_inode *ip = foo;
Christoph Lametera35afb82007-05-16 22:10:57 -070030
31 inode_init_once(&ip->i_inode);
Christoph Lametera35afb82007-05-16 22:10:57 -070032 init_rwsem(&ip->i_rw_mutex);
Steven Whitehouse6dbd8222008-01-10 15:18:55 +000033 ip->i_alloc = NULL;
Steven Whitehouse320dd102006-05-18 16:25:27 -040034}
35
Alexey Dobriyan51cc5062008-07-25 19:45:34 -070036static void gfs2_init_glock_once(void *foo)
Steven Whitehouseec45d9f2006-08-30 10:36:52 -040037{
38 struct gfs2_glock *gl = foo;
Christoph Lametera35afb82007-05-16 22:10:57 -070039
40 INIT_HLIST_NODE(&gl->gl_list);
41 spin_lock_init(&gl->gl_spin);
42 INIT_LIST_HEAD(&gl->gl_holders);
Christoph Lametera35afb82007-05-16 22:10:57 -070043 gl->gl_lvb = NULL;
44 atomic_set(&gl->gl_lvb_count, 0);
45 INIT_LIST_HEAD(&gl->gl_reclaim);
46 INIT_LIST_HEAD(&gl->gl_ail_list);
47 atomic_set(&gl->gl_ail_count, 0);
Steven Whitehouseec45d9f2006-08-30 10:36:52 -040048}
49
David Teiglandb3b94fa2006-01-16 16:50:04 +000050/**
51 * init_gfs2_fs - Register GFS2 as a filesystem
52 *
53 * Returns: 0 on success, error code on failure
54 */
55
56static int __init init_gfs2_fs(void)
57{
58 int error;
59
David Teiglandb3b94fa2006-01-16 16:50:04 +000060 error = gfs2_sys_init();
61 if (error)
62 return error;
63
Steven Whitehouse85d1da62006-09-07 14:40:21 -040064 error = gfs2_glock_init();
65 if (error)
66 goto fail;
David Teiglandb3b94fa2006-01-16 16:50:04 +000067
Steven Whitehouse85d1da62006-09-07 14:40:21 -040068 error = -ENOMEM;
David Teiglandb3b94fa2006-01-16 16:50:04 +000069 gfs2_glock_cachep = kmem_cache_create("gfs2_glock",
70 sizeof(struct gfs2_glock),
Steven Whitehouse907b9bc2006-09-25 09:26:04 -040071 0, 0,
Paul Mundt20c2df82007-07-20 10:11:58 +090072 gfs2_init_glock_once);
David Teiglandb3b94fa2006-01-16 16:50:04 +000073 if (!gfs2_glock_cachep)
74 goto fail;
75
76 gfs2_inode_cachep = kmem_cache_create("gfs2_inode",
77 sizeof(struct gfs2_inode),
Alexey Dobriyaneb1dc332006-10-28 03:03:48 +040078 0, SLAB_RECLAIM_ACCOUNT|
79 SLAB_MEM_SPREAD,
Paul Mundt20c2df82007-07-20 10:11:58 +090080 gfs2_init_inode_once);
David Teiglandb3b94fa2006-01-16 16:50:04 +000081 if (!gfs2_inode_cachep)
82 goto fail;
83
84 gfs2_bufdata_cachep = kmem_cache_create("gfs2_bufdata",
85 sizeof(struct gfs2_bufdata),
Paul Mundt20c2df82007-07-20 10:11:58 +090086 0, 0, NULL);
David Teiglandb3b94fa2006-01-16 16:50:04 +000087 if (!gfs2_bufdata_cachep)
88 goto fail;
89
Bob Peterson6bdd9be2008-01-28 17:20:26 -060090 gfs2_rgrpd_cachep = kmem_cache_create("gfs2_rgrpd",
91 sizeof(struct gfs2_rgrpd),
92 0, 0, NULL);
93 if (!gfs2_rgrpd_cachep)
94 goto fail;
95
Steven Whitehouse37b2c832008-11-17 14:25:37 +000096 gfs2_quotad_cachep = kmem_cache_create("gfs2_quotad",
97 sizeof(struct gfs2_quota_data),
98 0, 0, NULL);
99 if (!gfs2_quotad_cachep)
100 goto fail;
101
David Teiglandb3b94fa2006-01-16 16:50:04 +0000102 error = register_filesystem(&gfs2_fs_type);
103 if (error)
104 goto fail;
105
Steven Whitehouse419c93e02006-03-02 16:33:41 -0500106 error = register_filesystem(&gfs2meta_fs_type);
107 if (error)
108 goto fail_unregister;
109
Robert Peterson7c52b162007-03-16 10:26:37 +0000110 gfs2_register_debugfs();
111
David Teiglandb3b94fa2006-01-16 16:50:04 +0000112 printk("GFS2 (built %s %s) installed\n", __DATE__, __TIME__);
113
114 return 0;
115
Steven Whitehouse419c93e02006-03-02 16:33:41 -0500116fail_unregister:
117 unregister_filesystem(&gfs2_fs_type);
118fail:
Steven Whitehouse8fbbfd22007-08-01 13:57:10 +0100119 gfs2_glock_exit();
120
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000121 if (gfs2_quotad_cachep)
122 kmem_cache_destroy(gfs2_quotad_cachep);
123
Bob Peterson6bdd9be2008-01-28 17:20:26 -0600124 if (gfs2_rgrpd_cachep)
125 kmem_cache_destroy(gfs2_rgrpd_cachep);
126
David Teiglandb3b94fa2006-01-16 16:50:04 +0000127 if (gfs2_bufdata_cachep)
128 kmem_cache_destroy(gfs2_bufdata_cachep);
129
130 if (gfs2_inode_cachep)
131 kmem_cache_destroy(gfs2_inode_cachep);
132
133 if (gfs2_glock_cachep)
134 kmem_cache_destroy(gfs2_glock_cachep);
135
136 gfs2_sys_uninit();
137 return error;
138}
139
140/**
141 * exit_gfs2_fs - Unregister the file system
142 *
143 */
144
145static void __exit exit_gfs2_fs(void)
146{
Steven Whitehouse8fbbfd22007-08-01 13:57:10 +0100147 gfs2_glock_exit();
Robert Peterson7c52b162007-03-16 10:26:37 +0000148 gfs2_unregister_debugfs();
David Teiglandb3b94fa2006-01-16 16:50:04 +0000149 unregister_filesystem(&gfs2_fs_type);
Steven Whitehouse419c93e02006-03-02 16:33:41 -0500150 unregister_filesystem(&gfs2meta_fs_type);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000151
Steven Whitehouse37b2c832008-11-17 14:25:37 +0000152 kmem_cache_destroy(gfs2_quotad_cachep);
Bob Peterson6bdd9be2008-01-28 17:20:26 -0600153 kmem_cache_destroy(gfs2_rgrpd_cachep);
David Teiglandb3b94fa2006-01-16 16:50:04 +0000154 kmem_cache_destroy(gfs2_bufdata_cachep);
155 kmem_cache_destroy(gfs2_inode_cachep);
156 kmem_cache_destroy(gfs2_glock_cachep);
157
158 gfs2_sys_uninit();
159}
160
161MODULE_DESCRIPTION("Global File System");
162MODULE_AUTHOR("Red Hat, Inc.");
163MODULE_LICENSE("GPL");
164
165module_init(init_gfs2_fs);
166module_exit(exit_gfs2_fs);
167