Commit 9fa27c85 authored by Duane Griffin's avatar Duane Griffin Committed by Theodore Ts'o

jbd2: 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 the code slightly.
Signed-off-by: default avatarDuane Griffin <duaneg@dghda.com>
Signed-off-by: default avatarMingming Cao <cmm@us.ibm.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
parent 418f6e9e
...@@ -167,33 +167,41 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal, ...@@ -167,33 +167,41 @@ static struct jbd2_revoke_record_s *find_revoke_record(journal_t *journal,
return NULL; return NULL;
} }
void jbd2_journal_destroy_revoke_caches(void)
{
if (jbd2_revoke_record_cache) {
kmem_cache_destroy(jbd2_revoke_record_cache);
jbd2_revoke_record_cache = NULL;
}
if (jbd2_revoke_table_cache) {
kmem_cache_destroy(jbd2_revoke_table_cache);
jbd2_revoke_table_cache = NULL;
}
}
int __init jbd2_journal_init_revoke_caches(void) int __init jbd2_journal_init_revoke_caches(void)
{ {
J_ASSERT(!jbd2_revoke_record_cache);
J_ASSERT(!jbd2_revoke_table_cache);
jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record", jbd2_revoke_record_cache = kmem_cache_create("jbd2_revoke_record",
sizeof(struct jbd2_revoke_record_s), sizeof(struct jbd2_revoke_record_s),
0, 0,
SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY,
NULL); NULL);
if (!jbd2_revoke_record_cache) if (!jbd2_revoke_record_cache)
return -ENOMEM; goto record_cache_failure;
jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table", jbd2_revoke_table_cache = kmem_cache_create("jbd2_revoke_table",
sizeof(struct jbd2_revoke_table_s), sizeof(struct jbd2_revoke_table_s),
0, SLAB_TEMPORARY, NULL); 0, SLAB_TEMPORARY, NULL);
if (!jbd2_revoke_table_cache) { if (!jbd2_revoke_table_cache)
kmem_cache_destroy(jbd2_revoke_record_cache); goto table_cache_failure;
jbd2_revoke_record_cache = NULL;
return -ENOMEM;
}
return 0; return 0;
} table_cache_failure:
jbd2_journal_destroy_revoke_caches();
void jbd2_journal_destroy_revoke_caches(void) record_cache_failure:
{ return -ENOMEM;
kmem_cache_destroy(jbd2_revoke_record_cache);
jbd2_revoke_record_cache = NULL;
kmem_cache_destroy(jbd2_revoke_table_cache);
jbd2_revoke_table_cache = NULL;
} }
/* Initialise the revoke table for a given journal to a given size. */ /* Initialise the revoke table for a given journal to a given size. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment