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>
This commit is contained in:
Duane Griffin 2008-07-25 01:46:21 -07:00 committed by Linus Torvalds
parent f4d79ca2fa
commit 1984bb763c

View file

@ -166,33 +166,43 @@ static struct jbd_revoke_record_s *find_revoke_record(journal_t *journal,
return NULL; return NULL;
} }
void journal_destroy_revoke_caches(void)
{
if (revoke_record_cache) {
kmem_cache_destroy(revoke_record_cache);
revoke_record_cache = NULL;
}
if (revoke_table_cache) {
kmem_cache_destroy(revoke_table_cache);
revoke_table_cache = NULL;
}
}
int __init journal_init_revoke_caches(void) int __init journal_init_revoke_caches(void)
{ {
J_ASSERT(!revoke_record_cache);
J_ASSERT(!revoke_table_cache);
revoke_record_cache = kmem_cache_create("revoke_record", revoke_record_cache = kmem_cache_create("revoke_record",
sizeof(struct jbd_revoke_record_s), sizeof(struct jbd_revoke_record_s),
0, 0,
SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
NULL); NULL);
if (!revoke_record_cache) if (!revoke_record_cache)
return -ENOMEM; goto record_cache_failure;
revoke_table_cache = kmem_cache_create("revoke_table", revoke_table_cache = kmem_cache_create("revoke_table",
sizeof(struct jbd_revoke_table_s), sizeof(struct jbd_revoke_table_s),
0, SLAB_TEMPORARY, NULL); 0, SLAB_TEMPORARY, NULL);
if (!revoke_table_cache) { if (!revoke_table_cache)
kmem_cache_destroy(revoke_record_cache); goto table_cache_failure;
revoke_record_cache = NULL;
return -ENOMEM;
}
return 0;
}
void journal_destroy_revoke_caches(void) return 0;
{
kmem_cache_destroy(revoke_record_cache); table_cache_failure:
revoke_record_cache = NULL; journal_destroy_revoke_caches();
kmem_cache_destroy(revoke_table_cache); record_cache_failure:
revoke_table_cache = NULL; return -ENOMEM;
} }
static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size) static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size)