aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Hong <lihong.hi@gmail.com>2010-04-05 12:54:11 -0400
committerRyusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>2010-05-09 22:32:30 -0400
commit41c88bd74d372db5102996a4ea6167a725c24b5e (patch)
tree98b8e208d41f7760458e82569e297843415bbe7d
parentaaed1d5bfac459ead9aaad324e7fe3326250f50a (diff)
nilfs2: cleanup multi kmem_cache_{create,destroy} code
This cleanup patch gives several improvements: - Moving all kmem_cache_{create_destroy} calls into one place, which removes some small function calls, cleans up error check code and clarify the logic. - Mark all initial code in __init section. - Remove some very obvious comments. - Adjust some declarations. - Fix some space-tab issues. Signed-off-by: Li Hong <lihong.hi@gmail.com> Signed-off-by: Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>
-rw-r--r--fs/nilfs2/btree.c40
-rw-r--r--fs/nilfs2/btree.h23
-rw-r--r--fs/nilfs2/segbuf.c25
-rw-r--r--fs/nilfs2/segbuf.h1
-rw-r--r--fs/nilfs2/segment.c36
-rw-r--r--fs/nilfs2/segment.h2
-rw-r--r--fs/nilfs2/super.c134
7 files changed, 97 insertions, 164 deletions
diff --git a/fs/nilfs2/btree.c b/fs/nilfs2/btree.c
index dcd4e1c4deaa..b27a342c5af6 100644
--- a/fs/nilfs2/btree.c
+++ b/fs/nilfs2/btree.c
@@ -31,46 +31,6 @@
31#include "alloc.h" 31#include "alloc.h"
32#include "dat.h" 32#include "dat.h"
33 33
34/**
35 * struct nilfs_btree_path - A path on which B-tree operations are executed
36 * @bp_bh: buffer head of node block
37 * @bp_sib_bh: buffer head of sibling node block
38 * @bp_index: index of child node
39 * @bp_oldreq: ptr end request for old ptr
40 * @bp_newreq: ptr alloc request for new ptr
41 * @bp_op: rebalance operation
42 */
43struct nilfs_btree_path {
44 struct buffer_head *bp_bh;
45 struct buffer_head *bp_sib_bh;
46 int bp_index;
47 union nilfs_bmap_ptr_req bp_oldreq;
48 union nilfs_bmap_ptr_req bp_newreq;
49 struct nilfs_btnode_chkey_ctxt bp_ctxt;
50 void (*bp_op)(struct nilfs_btree *, struct nilfs_btree_path *,
51 int, __u64 *, __u64 *);
52};
53
54/*
55 * B-tree path operations
56 */
57
58static struct kmem_cache *nilfs_btree_path_cache;
59
60int __init nilfs_btree_path_cache_init(void)
61{
62 nilfs_btree_path_cache =
63 kmem_cache_create("nilfs2_btree_path_cache",
64 sizeof(struct nilfs_btree_path) *
65 NILFS_BTREE_LEVEL_MAX, 0, 0, NULL);
66 return (nilfs_btree_path_cache != NULL) ? 0 : -ENOMEM;
67}
68
69void nilfs_btree_path_cache_destroy(void)
70{
71 kmem_cache_destroy(nilfs_btree_path_cache);
72}
73
74static struct nilfs_btree_path *nilfs_btree_alloc_path(void) 34static struct nilfs_btree_path *nilfs_btree_alloc_path(void)
75{ 35{
76 struct nilfs_btree_path *path; 36 struct nilfs_btree_path *path;
diff --git a/fs/nilfs2/btree.h b/fs/nilfs2/btree.h
index 4b82d84ade75..af638d59e3bf 100644
--- a/fs/nilfs2/btree.h
+++ b/fs/nilfs2/btree.h
@@ -30,9 +30,6 @@
30#include "btnode.h" 30#include "btnode.h"
31#include "bmap.h" 31#include "bmap.h"
32 32
33struct nilfs_btree;
34struct nilfs_btree_path;
35
36/** 33/**
37 * struct nilfs_btree - B-tree structure 34 * struct nilfs_btree - B-tree structure
38 * @bt_bmap: bmap base structure 35 * @bt_bmap: bmap base structure
@@ -41,6 +38,25 @@ struct nilfs_btree {
41 struct nilfs_bmap bt_bmap; 38 struct nilfs_bmap bt_bmap;
42}; 39};
43 40
41/**
42 * struct nilfs_btree_path - A path on which B-tree operations are executed
43 * @bp_bh: buffer head of node block
44 * @bp_sib_bh: buffer head of sibling node block
45 * @bp_index: index of child node
46 * @bp_oldreq: ptr end request for old ptr
47 * @bp_newreq: ptr alloc request for new ptr
48 * @bp_op: rebalance operation
49 */
50struct nilfs_btree_path {
51 struct buffer_head *bp_bh;
52 struct buffer_head *bp_sib_bh;
53 int bp_index;
54 union nilfs_bmap_ptr_req bp_oldreq;
55 union nilfs_bmap_ptr_req bp_newreq;
56 struct nilfs_btnode_chkey_ctxt bp_ctxt;
57 void (*bp_op)(struct nilfs_btree *, struct nilfs_btree_path *,
58 int, __u64 *, __u64 *);
59};
44 60
45#define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE 61#define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE
46#define NILFS_BTREE_ROOT_NCHILDREN_MAX \ 62#define NILFS_BTREE_ROOT_NCHILDREN_MAX \
@@ -57,6 +73,7 @@ struct nilfs_btree {
57#define NILFS_BTREE_KEY_MIN ((__u64)0) 73#define NILFS_BTREE_KEY_MIN ((__u64)0)
58#define NILFS_BTREE_KEY_MAX (~(__u64)0) 74#define NILFS_BTREE_KEY_MAX (~(__u64)0)
59 75
76extern struct kmem_cache *nilfs_btree_path_cache;
60 77
61int nilfs_btree_path_cache_init(void); 78int nilfs_btree_path_cache_init(void);
62void nilfs_btree_path_cache_destroy(void); 79void nilfs_btree_path_cache_destroy(void);
diff --git a/fs/nilfs2/segbuf.c b/fs/nilfs2/segbuf.c
index 6bf3b1f3406e..9f83bc02593c 100644
--- a/fs/nilfs2/segbuf.c
+++ b/fs/nilfs2/segbuf.c
@@ -40,35 +40,10 @@ struct nilfs_write_info {
40 sector_t blocknr; 40 sector_t blocknr;
41}; 41};
42 42
43
44static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf, 43static int nilfs_segbuf_write(struct nilfs_segment_buffer *segbuf,
45 struct the_nilfs *nilfs); 44 struct the_nilfs *nilfs);
46static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf); 45static int nilfs_segbuf_wait(struct nilfs_segment_buffer *segbuf);
47 46
48
49static struct kmem_cache *nilfs_segbuf_cachep;
50
51static void nilfs_segbuf_init_once(void *obj)
52{
53 memset(obj, 0, sizeof(struct nilfs_segment_buffer));
54}
55
56int __init nilfs_init_segbuf_cache(void)
57{
58 nilfs_segbuf_cachep =
59 kmem_cache_create("nilfs2_segbuf_cache",
60 sizeof(struct nilfs_segment_buffer),
61 0, SLAB_RECLAIM_ACCOUNT,
62 nilfs_segbuf_init_once);
63
64 return (nilfs_segbuf_cachep == NULL) ? -ENOMEM : 0;
65}
66
67void nilfs_destroy_segbuf_cache(void)
68{
69 kmem_cache_destroy(nilfs_segbuf_cachep);
70}
71
72struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb) 47struct nilfs_segment_buffer *nilfs_segbuf_new(struct super_block *sb)
73{ 48{
74 struct nilfs_segment_buffer *segbuf; 49 struct nilfs_segment_buffer *segbuf;
diff --git a/fs/nilfs2/segbuf.h b/fs/nilfs2/segbuf.h
index ae12c2c3e370..e21497f61b0c 100644
--- a/fs/nilfs2/segbuf.h
+++ b/fs/nilfs2/segbuf.h
@@ -123,6 +123,7 @@ struct nilfs_segment_buffer {
123 b_assoc_buffers)) 123 b_assoc_buffers))
124#define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head) 124#define NILFS_SEGBUF_BH_IS_LAST(bh, head) ((bh)->b_assoc_buffers.next == head)
125 125
126extern struct kmem_cache *nilfs_segbuf_cachep;
126 127
127int __init nilfs_init_segbuf_cache(void); 128int __init nilfs_init_segbuf_cache(void);
128void nilfs_destroy_segbuf_cache(void); 129void nilfs_destroy_segbuf_cache(void);
diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c
index f649f0189589..a17bfa193e3f 100644
--- a/fs/nilfs2/segment.c
+++ b/fs/nilfs2/segment.c
@@ -116,42 +116,6 @@ static void nilfs_dispose_list(struct nilfs_sb_info *, struct list_head *,
116#define nilfs_cnt32_lt(a, b) nilfs_cnt32_gt(b, a) 116#define nilfs_cnt32_lt(a, b) nilfs_cnt32_gt(b, a)
117#define nilfs_cnt32_le(a, b) nilfs_cnt32_ge(b, a) 117#define nilfs_cnt32_le(a, b) nilfs_cnt32_ge(b, a)
118 118
119/*
120 * Transaction
121 */
122static struct kmem_cache *nilfs_transaction_cachep;
123
124/**
125 * nilfs_init_transaction_cache - create a cache for nilfs_transaction_info
126 *
127 * nilfs_init_transaction_cache() creates a slab cache for the struct
128 * nilfs_transaction_info.
129 *
130 * Return Value: On success, it returns 0. On error, one of the following
131 * negative error code is returned.
132 *
133 * %-ENOMEM - Insufficient memory available.
134 */
135int nilfs_init_transaction_cache(void)
136{
137 nilfs_transaction_cachep =
138 kmem_cache_create("nilfs2_transaction_cache",
139 sizeof(struct nilfs_transaction_info),
140 0, SLAB_RECLAIM_ACCOUNT, NULL);
141 return (nilfs_transaction_cachep == NULL) ? -ENOMEM : 0;
142}
143
144/**
145 * nilfs_destroy_transaction_cache - destroy the cache for transaction info
146 *
147 * nilfs_destroy_transaction_cache() frees the slab cache for the struct
148 * nilfs_transaction_info.
149 */
150void nilfs_destroy_transaction_cache(void)
151{
152 kmem_cache_destroy(nilfs_transaction_cachep);
153}
154
155static int nilfs_prepare_segment_lock(struct nilfs_transaction_info *ti) 119static int nilfs_prepare_segment_lock(struct nilfs_transaction_info *ti)
156{ 120{
157 struct nilfs_transaction_info *cur_ti = current->journal_info; 121 struct nilfs_transaction_info *cur_ti = current->journal_info;
diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h
index e61fc797383e..7aca76532683 100644
--- a/fs/nilfs2/segment.h
+++ b/fs/nilfs2/segment.h
@@ -217,6 +217,8 @@ enum {
217 */ 217 */
218#define NILFS_SC_DEFAULT_WATERMARK 3600 218#define NILFS_SC_DEFAULT_WATERMARK 3600
219 219
220/* super.c */
221extern struct kmem_cache *nilfs_transaction_cachep;
220 222
221/* segment.c */ 223/* segment.c */
222extern int nilfs_init_transaction_cache(void); 224extern int nilfs_init_transaction_cache(void);
diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c
index 0b1758bf0726..5a08c82e7e25 100644
--- a/fs/nilfs2/super.c
+++ b/fs/nilfs2/super.c
@@ -67,6 +67,11 @@ MODULE_DESCRIPTION("A New Implementation of the Log-structured Filesystem "
67 "(NILFS)"); 67 "(NILFS)");
68MODULE_LICENSE("GPL"); 68MODULE_LICENSE("GPL");
69 69
70struct kmem_cache *nilfs_inode_cachep;
71struct kmem_cache *nilfs_transaction_cachep;
72struct kmem_cache *nilfs_segbuf_cachep;
73struct kmem_cache *nilfs_btree_path_cache;
74
70static int nilfs_remount(struct super_block *sb, int *flags, char *data); 75static int nilfs_remount(struct super_block *sb, int *flags, char *data);
71 76
72/** 77/**
@@ -129,7 +134,6 @@ void nilfs_warning(struct super_block *sb, const char *function,
129 va_end(args); 134 va_end(args);
130} 135}
131 136
132static struct kmem_cache *nilfs_inode_cachep;
133 137
134struct inode *nilfs_alloc_inode_common(struct the_nilfs *nilfs) 138struct inode *nilfs_alloc_inode_common(struct the_nilfs *nilfs)
135{ 139{
@@ -155,34 +159,6 @@ void nilfs_destroy_inode(struct inode *inode)
155 kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode)); 159 kmem_cache_free(nilfs_inode_cachep, NILFS_I(inode));
156} 160}
157 161
158static void init_once(void *obj)
159{
160 struct nilfs_inode_info *ii = obj;
161
162 INIT_LIST_HEAD(&ii->i_dirty);
163#ifdef CONFIG_NILFS_XATTR
164 init_rwsem(&ii->xattr_sem);
165#endif
166 nilfs_btnode_cache_init_once(&ii->i_btnode_cache);
167 ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union;
168 inode_init_once(&ii->vfs_inode);
169}
170
171static int nilfs_init_inode_cache(void)
172{
173 nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache",
174 sizeof(struct nilfs_inode_info),
175 0, SLAB_RECLAIM_ACCOUNT,
176 init_once);
177
178 return (nilfs_inode_cachep == NULL) ? -ENOMEM : 0;
179}
180
181static inline void nilfs_destroy_inode_cache(void)
182{
183 kmem_cache_destroy(nilfs_inode_cachep);
184}
185
186static void nilfs_clear_inode(struct inode *inode) 162static void nilfs_clear_inode(struct inode *inode)
187{ 163{
188 struct nilfs_inode_info *ii = NILFS_I(inode); 164 struct nilfs_inode_info *ii = NILFS_I(inode);
@@ -1139,54 +1115,92 @@ struct file_system_type nilfs_fs_type = {
1139 .fs_flags = FS_REQUIRES_DEV, 1115 .fs_flags = FS_REQUIRES_DEV,
1140}; 1116};
1141 1117
1142static int __init init_nilfs_fs(void) 1118static void nilfs_inode_init_once(void *obj)
1143{ 1119{
1144 int err; 1120 struct nilfs_inode_info *ii = obj;
1145
1146 err = nilfs_init_inode_cache();
1147 if (err)
1148 goto failed;
1149 1121
1150 err = nilfs_init_transaction_cache(); 1122 INIT_LIST_HEAD(&ii->i_dirty);
1151 if (err) 1123#ifdef CONFIG_NILFS_XATTR
1152 goto failed_inode_cache; 1124 init_rwsem(&ii->xattr_sem);
1125#endif
1126 nilfs_btnode_cache_init_once(&ii->i_btnode_cache);
1127 ii->i_bmap = (struct nilfs_bmap *)&ii->i_bmap_union;
1128 inode_init_once(&ii->vfs_inode);
1129}
1153 1130
1154 err = nilfs_init_segbuf_cache(); 1131static void nilfs_segbuf_init_once(void *obj)
1155 if (err) 1132{
1156 goto failed_transaction_cache; 1133 memset(obj, 0, sizeof(struct nilfs_segment_buffer));
1134}
1157 1135
1158 err = nilfs_btree_path_cache_init(); 1136static void nilfs_destroy_cachep(void)
1159 if (err) 1137{
1160 goto failed_segbuf_cache; 1138 if (nilfs_inode_cachep)
1139 kmem_cache_destroy(nilfs_inode_cachep);
1140 if (nilfs_transaction_cachep)
1141 kmem_cache_destroy(nilfs_transaction_cachep);
1142 if (nilfs_segbuf_cachep)
1143 kmem_cache_destroy(nilfs_segbuf_cachep);
1144 if (nilfs_btree_path_cache)
1145 kmem_cache_destroy(nilfs_btree_path_cache);
1146}
1161 1147
1162 err = register_filesystem(&nilfs_fs_type); 1148static int __init nilfs_init_cachep(void)
1163 if (err) 1149{
1164 goto failed_btree_path_cache; 1150 nilfs_inode_cachep = kmem_cache_create("nilfs2_inode_cache",
1151 sizeof(struct nilfs_inode_info), 0,
1152 SLAB_RECLAIM_ACCOUNT, nilfs_inode_init_once);
1153 if (!nilfs_inode_cachep)
1154 goto fail;
1155
1156 nilfs_transaction_cachep = kmem_cache_create("nilfs2_transaction_cache",
1157 sizeof(struct nilfs_transaction_info), 0,
1158 SLAB_RECLAIM_ACCOUNT, NULL);
1159 if (!nilfs_transaction_cachep)
1160 goto fail;
1161
1162 nilfs_segbuf_cachep = kmem_cache_create("nilfs2_segbuf_cache",
1163 sizeof(struct nilfs_segment_buffer), 0,
1164 SLAB_RECLAIM_ACCOUNT, nilfs_segbuf_init_once);
1165 if (!nilfs_segbuf_cachep)
1166 goto fail;
1167
1168 nilfs_btree_path_cache = kmem_cache_create("nilfs2_btree_path_cache",
1169 sizeof(struct nilfs_btree_path) * NILFS_BTREE_LEVEL_MAX,
1170 0, 0, NULL);
1171 if (!nilfs_btree_path_cache)
1172 goto fail;
1165 1173
1166 return 0; 1174 return 0;
1167 1175
1168 failed_btree_path_cache: 1176fail:
1169 nilfs_btree_path_cache_destroy(); 1177 nilfs_destroy_cachep();
1178 return -ENOMEM;
1179}
1180
1181static int __init init_nilfs_fs(void)
1182{
1183 int err;
1170 1184
1171 failed_segbuf_cache: 1185 err = nilfs_init_cachep();
1172 nilfs_destroy_segbuf_cache(); 1186 if (err)
1187 goto fail;
1173 1188
1174 failed_transaction_cache: 1189 err = register_filesystem(&nilfs_fs_type);
1175 nilfs_destroy_transaction_cache(); 1190 if (err)
1191 goto free_cachep;
1176 1192
1177 failed_inode_cache: 1193 return 0;
1178 nilfs_destroy_inode_cache();
1179 1194
1180 failed: 1195free_cachep:
1196 nilfs_destroy_cachep();
1197fail:
1181 return err; 1198 return err;
1182} 1199}
1183 1200
1184static void __exit exit_nilfs_fs(void) 1201static void __exit exit_nilfs_fs(void)
1185{ 1202{
1186 nilfs_destroy_segbuf_cache(); 1203 nilfs_destroy_cachep();
1187 nilfs_destroy_transaction_cache();
1188 nilfs_destroy_inode_cache();
1189 nilfs_btree_path_cache_destroy();
1190 unregister_filesystem(&nilfs_fs_type); 1204 unregister_filesystem(&nilfs_fs_type);
1191} 1205}
1192 1206