* [PATCH 0/3] jbd: jbd versions of queued jbd2 patches @ 2008-05-03 16:47 Duane Griffin 2008-05-03 16:47 ` [PATCH 1/3] jbd: eliminate duplicated code in revocation table init/destroy functions Duane Griffin 0 siblings, 1 reply; 6+ messages in thread From: Duane Griffin @ 2008-05-03 16:47 UTC (permalink / raw) To: akpm; +Cc: Eric Sandeen, cmm, sct, linux-ext4 These are jbd versions of the following patches in the ext4 queue: patches/jbd2-eliminate-duplicated-code-in-revocation-table-init-destroy-functions.patch patches/jbd2-tidy-up-revoke-cache-initialization-and-destruction.patch patches/jbd2-replace-potentially-false-assertion-with-if-block.patch Patches are against v2.6.25-rc8-mm2. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] jbd: eliminate duplicated code in revocation table init/destroy functions 2008-05-03 16:47 [PATCH 0/3] jbd: jbd versions of queued jbd2 patches Duane Griffin @ 2008-05-03 16:47 ` Duane Griffin 2008-05-03 16:47 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Duane Griffin 0 siblings, 1 reply; 6+ messages in thread From: Duane Griffin @ 2008-05-03 16:47 UTC (permalink / raw) To: akpm; +Cc: Eric Sandeen, cmm, sct, linux-ext4, Duane Griffin The revocation table initialisation/destruction code is repeated for each of the two revocation tables stored in the journal. Refactoring the duplicated code into functions is tidier, simplifies the logic in initialisation in particular, and slightly reduces the code size. There should not be any functional change. Signed-off-by: Duane Griffin <duaneg@dghda.com> --- fs/jbd/revoke.c | 127 ++++++++++++++++++++++--------------------------------- 1 files changed, 51 insertions(+), 76 deletions(-) diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c index 1bb43e9..8ff5a7b 100644 --- a/fs/jbd/revoke.c +++ b/fs/jbd/revoke.c @@ -195,109 +195,84 @@ void journal_destroy_revoke_caches(void) revoke_table_cache = NULL; } -/* Initialise the revoke table for a given journal to a given size. */ - -int journal_init_revoke(journal_t *journal, int hash_size) +static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size) { - int shift, tmp; + int shift = 0; + int tmp = hash_size; + struct jbd_revoke_table_s *table; - J_ASSERT (journal->j_revoke_table[0] == NULL); + table = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL); + if (!table) + goto out; - shift = 0; - tmp = hash_size; while((tmp >>= 1UL) != 0UL) shift++; - journal->j_revoke_table[0] = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL); - if (!journal->j_revoke_table[0]) - return -ENOMEM; - journal->j_revoke = journal->j_revoke_table[0]; - - /* Check that the hash_size is a power of two */ - J_ASSERT(is_power_of_2(hash_size)); - - journal->j_revoke->hash_size = hash_size; - - journal->j_revoke->hash_shift = shift; - - journal->j_revoke->hash_table = + table->hash_size = hash_size; + table->hash_shift = shift; + table->hash_table = kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); - if (!journal->j_revoke->hash_table) { - kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]); - journal->j_revoke = NULL; - return -ENOMEM; + if (!table->hash_table) { + kmem_cache_free(revoke_table_cache, table); + table = NULL; + goto out; } for (tmp = 0; tmp < hash_size; tmp++) - INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); + INIT_LIST_HEAD(&table->hash_table[tmp]); - journal->j_revoke_table[1] = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL); - if (!journal->j_revoke_table[1]) { - kfree(journal->j_revoke_table[0]->hash_table); - kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]); - return -ENOMEM; +out: + return table; +} + +static void journal_destroy_revoke_table(struct jbd_revoke_table_s *table) +{ + int i; + struct list_head *hash_list; + + for (i = 0; i < table->hash_size; i++) { + hash_list = &table->hash_table[i]; + J_ASSERT(list_empty(hash_list)); } - journal->j_revoke = journal->j_revoke_table[1]; + kfree(table->hash_table); + kmem_cache_free(revoke_table_cache, table); +} - /* Check that the hash_size is a power of two */ +/* Initialise the revoke table for a given journal to a given size. */ +int journal_init_revoke(journal_t *journal, int hash_size) +{ + J_ASSERT(journal->j_revoke_table[0] == NULL); J_ASSERT(is_power_of_2(hash_size)); - journal->j_revoke->hash_size = hash_size; + journal->j_revoke_table[0] = journal_init_revoke_table(hash_size); + if (!journal->j_revoke_table[0]) + goto fail0; - journal->j_revoke->hash_shift = shift; + journal->j_revoke_table[1] = journal_init_revoke_table(hash_size); + if (!journal->j_revoke_table[1]) + goto fail1; - journal->j_revoke->hash_table = - kmalloc(hash_size * sizeof(struct list_head), GFP_KERNEL); - if (!journal->j_revoke->hash_table) { - kfree(journal->j_revoke_table[0]->hash_table); - kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]); - kmem_cache_free(revoke_table_cache, journal->j_revoke_table[1]); - journal->j_revoke = NULL; - return -ENOMEM; - } - - for (tmp = 0; tmp < hash_size; tmp++) - INIT_LIST_HEAD(&journal->j_revoke->hash_table[tmp]); + journal->j_revoke = journal->j_revoke_table[1]; spin_lock_init(&journal->j_revoke_lock); return 0; -} -/* Destoy a journal's revoke table. The table must already be empty! */ +fail1: + journal_destroy_revoke_table(journal->j_revoke_table[0]); +fail0: + return -ENOMEM; +} +/* Destroy a journal's revoke table. The table must already be empty! */ void journal_destroy_revoke(journal_t *journal) { - struct jbd_revoke_table_s *table; - struct list_head *hash_list; - int i; - - table = journal->j_revoke_table[0]; - if (!table) - return; - - for (i=0; i<table->hash_size; i++) { - hash_list = &table->hash_table[i]; - J_ASSERT (list_empty(hash_list)); - } - - kfree(table->hash_table); - kmem_cache_free(revoke_table_cache, table); - journal->j_revoke = NULL; - - table = journal->j_revoke_table[1]; - if (!table) - return; - - for (i=0; i<table->hash_size; i++) { - hash_list = &table->hash_table[i]; - J_ASSERT (list_empty(hash_list)); - } ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction 2008-05-03 16:47 ` [PATCH 1/3] jbd: eliminate duplicated code in revocation table init/destroy functions Duane Griffin @ 2008-05-03 16:47 ` Duane Griffin 2008-05-03 16:47 ` [PATCH 3/3] jbd: replace potentially false assertion with if block Duane Griffin 2008-05-10 0:42 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Andrew Morton 0 siblings, 2 replies; 6+ messages in thread From: Duane Griffin @ 2008-05-03 16:47 UTC (permalink / raw) To: akpm; +Cc: Eric Sandeen, cmm, sct, linux-ext4, Duane Griffin 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> --- fs/jbd/revoke.c | 36 ++++++++++++++++++++++-------------- 1 files changed, 22 insertions(+), 14 deletions(-) diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c index 8ff5a7b..c99f4bf 100644 --- a/fs/jbd/revoke.c +++ b/fs/jbd/revoke.c @@ -166,33 +166,41 @@ static struct jbd_revoke_record_s *find_revoke_record(journal_t *journal, 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) { + J_ASSERT(!revoke_record_cache); + J_ASSERT(!revoke_table_cache); + revoke_record_cache = kmem_cache_create("revoke_record", sizeof(struct jbd_revoke_record_s), 0, SLAB_HWCACHE_ALIGN|SLAB_TEMPORARY, NULL); if (!revoke_record_cache) - return -ENOMEM; + goto record_cache_failure; revoke_table_cache = kmem_cache_create("revoke_table", sizeof(struct jbd_revoke_table_s), 0, SLAB_TEMPORARY, NULL); - if (!revoke_table_cache) { - kmem_cache_destroy(revoke_record_cache); - revoke_record_cache = NULL; - return -ENOMEM; - } - return 0; -} + if (!revoke_table_cache) + goto table_cache_failure; -void journal_destroy_revoke_caches(void) -{ - kmem_cache_destroy(revoke_record_cache); - revoke_record_cache = NULL; - kmem_cache_destroy(revoke_table_cache); - revoke_table_cache = NULL; +table_cache_failure: + journal_destroy_revoke_caches(); +record_cache_failure: + return -ENOMEM; } static struct jbd_revoke_table_s *journal_init_revoke_table(int hash_size) -- 1.5.3.7 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] jbd: replace potentially false assertion with if block 2008-05-03 16:47 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Duane Griffin @ 2008-05-03 16:47 ` Duane Griffin 2008-05-10 0:42 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Andrew Morton 1 sibling, 0 replies; 6+ messages in thread From: Duane Griffin @ 2008-05-03 16:47 UTC (permalink / raw) To: akpm; +Cc: Eric Sandeen, cmm, sct, linux-ext4, Duane Griffin If an error occurs during jbd cache initialisation it is possible for the journal_head_cache to be NULL when journal_destroy_journal_head_cache is called. Replace the J_ASSERT with an if block to handle the situation correctly. Note that even with this fix things will break badly if jbd is statically compiled in and cache initialisation fails. Signed-off-by: Duane Griffin <duaneg@dghda.com --- fs/jbd/journal.c | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/jbd/journal.c b/fs/jbd/journal.c index 1ecd005..f6a7c93 100644 --- a/fs/jbd/journal.c +++ b/fs/jbd/journal.c @@ -1641,9 +1641,10 @@ static int journal_init_journal_head_cache(void) static void journal_destroy_journal_head_cache(void) { - J_ASSERT(journal_head_cache != NULL); - kmem_cache_destroy(journal_head_cache); - journal_head_cache = NULL; + if (journal_head_cache) { + kmem_cache_destroy(journal_head_cache); + journal_head_cache = NULL; + } } /* -- 1.5.3.7 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction 2008-05-03 16:47 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Duane Griffin 2008-05-03 16:47 ` [PATCH 3/3] jbd: replace potentially false assertion with if block Duane Griffin @ 2008-05-10 0:42 ` Andrew Morton 2008-05-12 16:11 ` Duane Griffin 1 sibling, 1 reply; 6+ messages in thread From: Andrew Morton @ 2008-05-10 0:42 UTC (permalink / raw) To: Duane Griffin; +Cc: sandeen, cmm, sct, linux-ext4, duaneg On Sat, 3 May 2008 17:47:14 +0100 "Duane Griffin" <duaneg@dghda.com> wrote: > 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. This crashes the kernel early in boot. Too early to catch via netconsole, which is a bit odd. I also have a feeling that [patch 1/3] causes problems too but I've run out of time to bisect it further. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction 2008-05-10 0:42 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Andrew Morton @ 2008-05-12 16:11 ` Duane Griffin 0 siblings, 0 replies; 6+ messages in thread From: Duane Griffin @ 2008-05-12 16:11 UTC (permalink / raw) To: Andrew Morton; +Cc: sandeen, cmm, sct, linux-ext4 2008/5/10 Andrew Morton <akpm@linux-foundation.org>: > On Sat, 3 May 2008 17:47:14 +0100 > "Duane Griffin" <duaneg@dghda.com> wrote: > > > 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. > > This crashes the kernel early in boot. Too early to catch via netconsole, > which is a bit odd. Eeek, yes, an extremely silly bug. Sorry about that. I'll send a revised version of the patch-set shortly, and this time I'll make sure it is properly tested. > I also have a feeling that [patch 1/3] causes problems too but I've run out > of time to bisect it further. Was there something in particular that worried you about it? I've gone back and done some more testing with just that one, including testing each of the error cases manually, and all looks fine. Cheers, Duane. -- "I never could learn to drink that blood and call it wine" - Bob Dylan ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-05-12 16:11 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-05-03 16:47 [PATCH 0/3] jbd: jbd versions of queued jbd2 patches Duane Griffin 2008-05-03 16:47 ` [PATCH 1/3] jbd: eliminate duplicated code in revocation table init/destroy functions Duane Griffin 2008-05-03 16:47 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Duane Griffin 2008-05-03 16:47 ` [PATCH 3/3] jbd: replace potentially false assertion with if block Duane Griffin 2008-05-10 0:42 ` [PATCH 2/3] jbd: tidy up revoke cache initialisation and destruction Andrew Morton 2008-05-12 16:11 ` Duane Griffin
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).