aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nilfs2/super.c
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 /fs/nilfs2/super.c
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>
Diffstat (limited to 'fs/nilfs2/super.c')
-rw-r--r--fs/nilfs2/super.c134
1 files changed, 74 insertions, 60 deletions
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