use loop counter for initializing/destroying a pair of the revoke tables.
Signed-off-by: Akinobu Mita <[email protected]>
---
revoke.c | 116 ++++++++++++++++++++++-----------------------------------------
1 files changed, 42 insertions(+), 74 deletions(-)
diff -X 2.6.13-mm1/Documentation/dontdiff -Nurp 2.6.13-mm1.old/fs/jbd/revoke.c 2.6.13-mm1/fs/jbd/revoke.c
--- 2.6.13-mm1.old/fs/jbd/revoke.c 2005-09-05 03:21:00.000000000 +0900
+++ 2.6.13-mm1/fs/jbd/revoke.c 2005-09-05 11:16:04.000000000 +0900
@@ -193,108 +193,76 @@ void journal_destroy_revoke_caches(void)
int journal_init_revoke(journal_t *journal, int hash_size)
{
- int shift, tmp;
+ int shift = 0;
+ int tmp = hash_size;
+ int i;
+ /* Check that the hash_size is a power of two */
+ J_ASSERT ((hash_size & (hash_size-1)) == 0);
J_ASSERT (journal->j_revoke_table[0] == NULL);
- shift = 0;
- tmp = hash_size;
- while((tmp >>= 1UL) != 0UL)
+ 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 ((hash_size & (hash_size-1)) == 0);
+ for (i = 0; i < 2; i++) {
+ struct jbd_revoke_table_s *table;
- journal->j_revoke->hash_size = hash_size;
+ table = kmem_cache_alloc(revoke_table_cache, GFP_KERNEL);
+ if (!table)
+ goto nomem;
+
+ table->hash_size = hash_size;
+ table->hash_shift = shift;
+ table->hash_table = kmalloc(hash_size * sizeof(struct hlist_head), GFP_KERNEL);
+ if (!table->hash_table) {
+ kmem_cache_free(revoke_table_cache, table);
+ goto nomem;
+ }
- journal->j_revoke->hash_shift = shift;
+ for (tmp = 0; tmp < hash_size; tmp++)
+ INIT_HLIST_HEAD(&table->hash_table[tmp]);
- journal->j_revoke->hash_table =
- kmalloc(hash_size * sizeof(struct hlist_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;
- }
-
- for (tmp = 0; tmp < hash_size; tmp++)
- INIT_HLIST_HEAD(&journal->j_revoke->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;
+ journal->j_revoke_table[i] = table;
}
-
journal->j_revoke = journal->j_revoke_table[1];
+ spin_lock_init(&journal->j_revoke_lock);
- /* Check that the hash_size is a power of two */
- J_ASSERT ((hash_size & (hash_size-1)) == 0);
-
- journal->j_revoke->hash_size = hash_size;
-
- journal->j_revoke->hash_shift = shift;
+ return 0;
- journal->j_revoke->hash_table =
- kmalloc(hash_size * sizeof(struct hlist_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;
+nomem:
+ while (i--) {
+ kfree(journal->j_revoke_table[i]->hash_table);
+ kmem_cache_free(revoke_table_cache, journal->j_revoke_table[i]);
}
- for (tmp = 0; tmp < hash_size; tmp++)
- INIT_HLIST_HEAD(&journal->j_revoke->hash_table[tmp]);
-
- spin_lock_init(&journal->j_revoke_lock);
-
- return 0;
+ return -ENOMEM;
}
/* Destoy 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 hlist_head *hash_list;
- int i;
+ int j;
- table = journal->j_revoke_table[0];
- if (!table)
- return;
+ journal->j_revoke = NULL;
- for (i=0; i<table->hash_size; i++) {
- hash_list = &table->hash_table[i];
- J_ASSERT (hlist_empty(hash_list));
- }
+ for (j = 0; j < 2; j++) {
+ int i;
+ struct jbd_revoke_table_s *table = journal->j_revoke_table[j];
- kfree(table->hash_table);
- kmem_cache_free(revoke_table_cache, table);
- journal->j_revoke = NULL;
+ if (!table)
+ return;
- table = journal->j_revoke_table[1];
- if (!table)
- return;
+ for (i = 0; i < table->hash_size; i++) {
+ struct hlist_head *hash_list = &table->hash_table[i];
+ J_ASSERT (hlist_empty(hash_list));
+ }
- for (i=0; i<table->hash_size; i++) {
- hash_list = &table->hash_table[i];
- J_ASSERT (hlist_empty(hash_list));
+ kfree(table->hash_table);
+ kmem_cache_free(revoke_table_cache, table);
}
-
- kfree(table->hash_table);
- kmem_cache_free(revoke_table_cache, table);
- journal->j_revoke = NULL;
}
-
#ifdef __KERNEL__
/*
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[Index of Archives]
[Kernel Newbies]
[Netfilter]
[Bugtraq]
[Photo]
[Gimp]
[Yosemite News]
[MIPS Linux]
[ARM Linux]
[Linux Security]
[Linux RAID]
[Video 4 Linux]
[Linux for the blind]
|
|