Commit 1984bb763c2e50d0ebfb0cf56d1b319bd7afe63a
Committed by
Linus Torvalds
1 parent
f4d79ca2fa
Exists in
master
and in
7 other branches
jbd: tidy up revoke cache initialisation and destruction
Make revocation cache destruction safe to call if initialisation fails partially or entirely. This allows it to be used to cleanup in the case of initialisation failure, simplifying that code slightly. Signed-off-by: Duane Griffin <duaneg@dghda.com> Cc: <linux-ext4@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 23 additions and 13 deletions Side-by-side Diff
fs/jbd/revoke.c
... | ... | @@ -166,33 +166,43 @@ |
166 | 166 | return NULL; |
167 | 167 | } |
168 | 168 | |
169 | +void journal_destroy_revoke_caches(void) | |
170 | +{ | |
171 | + if (revoke_record_cache) { | |
172 | + kmem_cache_destroy(revoke_record_cache); | |
173 | + revoke_record_cache = NULL; | |
174 | + } | |
175 | + if (revoke_table_cache) { | |
176 | + kmem_cache_destroy(revoke_table_cache); | |
177 | + revoke_table_cache = NULL; | |
178 | + } | |
179 | +} | |
180 | + | |
169 | 181 | int __init journal_init_revoke_caches(void) |
170 | 182 | { |
183 | + J_ASSERT(!revoke_record_cache); | |
184 | + J_ASSERT(!revoke_table_cache); | |
185 | + | |
171 | 186 | revoke_record_cache = kmem_cache_create("revoke_record", |
172 | 187 | sizeof(struct jbd_revoke_record_s), |
173 | 188 | 0, |
174 | 189 | SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, |
175 | 190 | NULL); |
176 | 191 | if (!revoke_record_cache) |
177 | - return -ENOMEM; | |
192 | + goto record_cache_failure; | |
178 | 193 | |
179 | 194 | revoke_table_cache = kmem_cache_create("revoke_table", |
180 | 195 | sizeof(struct jbd_revoke_table_s), |
181 | 196 | 0, SLAB_TEMPORARY, NULL); |
182 | - if (!revoke_table_cache) { | |
183 | - kmem_cache_destroy(revoke_record_cache); | |
184 | - revoke_record_cache = NULL; | |
185 | - return -ENOMEM; | |
186 | - } | |
197 | + if (!revoke_table_cache) | |
198 | + goto table_cache_failure; | |
199 | + | |
187 | 200 | return 0; |
188 | -} | |
189 | 201 | |
190 | -void journal_destroy_revoke_caches(void) | |
191 | -{ | |
192 | - kmem_cache_destroy(revoke_record_cache); | |
193 | - revoke_record_cache = NULL; | |
194 | - kmem_cache_destroy(revoke_table_cache); | |
195 | - revoke_table_cache = NULL; | |
202 | +table_cache_failure: | |
203 | + journal_destroy_revoke_caches(); | |
204 | +record_cache_failure: | |
205 | + return -ENOMEM; | |
196 | 206 | } |
197 | 207 | |
198 | 208 | static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size) |