linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Duane Griffin" <duaneg@dghda.com>
To: linux-ext4@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Theodore Tso <tytso@mit.edu>,
	sct@redhat.com, akpm@linux-foundation.org, adilger@clusterfs.com,
	Duane Griffin <duaneg@dghda.com>
Subject: [RFC, PATCH 1/6] jbd: eliminate duplicated code in revocation table init/destroy functions
Date: Thu,  6 Mar 2008 01:59:09 +0000	[thread overview]
Message-ID: <1204768754-29655-2-git-send-email-duaneg@dghda.com> (raw)
Message-ID: <a047dfbd7855d5f484ae8a3434f6a073302505be.1204685366.git.duaneg@dghda.com> (raw)
In-Reply-To: <1204768754-29655-1-git-send-email-duaneg@dghda.com>

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>
---

This change is an independent cleanup which is not required by following
patches in this series. Also it should perhaps be two separate patches?

 fs/jbd/revoke.c |  126 +++++++++++++++++++++++--------------------------------
 1 files changed, 52 insertions(+), 74 deletions(-)

diff --git a/fs/jbd/revoke.c b/fs/jbd/revoke.c
index ad2eacf..5f64df4 100644
--- a/fs/jbd/revoke.c
+++ b/fs/jbd/revoke.c
@@ -195,108 +195,86 @@ 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 int journal_init_revoke_table(struct jbd_revoke_table_s *table, int size)
 {
-	int shift, tmp;
-
-	J_ASSERT (journal->j_revoke_table[0] == NULL);
-
-	shift = 0;
-	tmp = hash_size;
+	int shift = 0;
+	int tmp = 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 =
-		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;
+	table->hash_size = size;
+	table->hash_shift = shift;
+	table->hash_table = kmalloc(
+		size * sizeof(struct list_head), GFP_KERNEL);
+	if (!table->hash_table)
 		return -ENOMEM;
-	}
-
-	for (tmp = 0; tmp < hash_size; tmp++)
-		INIT_LIST_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;
-	}
+	for (tmp = 0; tmp < size; tmp++)
+		INIT_LIST_HEAD(&table->hash_table[tmp]);
 
-	journal->j_revoke = journal->j_revoke_table[1];
+	return 0;
+}
 
-	/* 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] = kmem_cache_alloc(
+		revoke_table_cache, GFP_KERNEL);
+	if (!journal->j_revoke_table[0])
+		goto failed_alloc1;
+	if (journal_init_revoke_table(journal->j_revoke_table[0], hash_size))
+		goto failed_init1;
 
-	journal->j_revoke->hash_shift = shift;
+	journal->j_revoke_table[1] = kmem_cache_alloc(
+		revoke_table_cache, GFP_KERNEL);
+	if (!journal->j_revoke_table[1])
+		goto failed_alloc2;
+	if (journal_init_revoke_table(journal->j_revoke_table[1], hash_size))
+		goto failed_init2;
 
-	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! */
+failed_init2:
+	kmem_cache_free(revoke_table_cache, journal->j_revoke_table[1]);
+failed_alloc2:
+	kfree(journal->j_revoke_table[0]->hash_table);
+failed_init1:
+	kmem_cache_free(revoke_table_cache, journal->j_revoke_table[0]);
+failed_alloc1:
+	return -ENOMEM;
+}
 
-void journal_destroy_revoke(journal_t *journal)
+static void journal_destroy_revoke_table(struct jbd_revoke_table_s *table)
 {
-	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++) {
+	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));
+		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)
+/* Destroy a journal's revoke table.  The table must already be empty! */
+void journal_destroy_revoke(journal_t *journal)
+{
+	if (!journal->j_revoke_table[0])
 		return;
+	journal_destroy_revoke_table(journal->j_revoke_table[0]);
+	journal->j_revoke = NULL;
 
-	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);
+	if (!journal->j_revoke_table[1])
+		return;
+	journal_destroy_revoke_table(journal->j_revoke_table[1]);
 	journal->j_revoke = NULL;
 }
 
-- 
1.5.3.7


  reply	other threads:[~2008-03-06  2:06 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-06  1:59 [RFC, PATCH 0/6] ext3: do not modify data on-disk when mounting read-only filesystem Duane Griffin
     [not found] ` <a047dfbd7855d5f484ae8a3434f6a073302505be.1204685366.git.duaneg@dghda.com>
2008-03-06  1:59   ` Duane Griffin [this message]
     [not found]   ` <bd11bfe0ae59094e7a3fbd813dfd877f989f122f.1204685366.git.duaneg@dghda.com>
2008-03-06  1:59     ` [RFC, PATCH 3/6] jbd: only create debugfs entries if cache initialisation is successful Duane Griffin
     [not found]   ` <f4577a0cc4262de0fbff02cae3858d2e2edfaaea.1204685366.git.duaneg@dghda.com>
2008-03-06  1:59     ` [RFC, PATCH 6/6] ext3: do not write to the disk when mounting a dirty read-only filesystem Duane Griffin
2008-03-06  7:17     ` Andreas Dilger
2008-03-06 11:19       ` Duane Griffin
2008-03-11 15:11       ` Jan Kara
2008-03-12  2:42         ` Duane Griffin
2008-03-12 10:53           ` Jan Kara
     [not found]   ` <7fbb2f28dcb417e3173ffacc103932c36683f2f0.1204685366.git.duaneg@dghda.com>
2008-03-06  1:59     ` [RFC, PATCH 2/6] jbd: replace potentially false assertion with if block Duane Griffin
2008-03-08 14:52     ` Christoph Hellwig
     [not found]   ` <8644b32ddec999bbc1da0ac55ad7b66d0b8176de.1204685366.git.duaneg@dghda.com>
2008-03-06  1:59     ` [RFC, PATCH 4/6] jbd: refactor nested journal log recovery loop into separate functions Duane Griffin
2008-03-08 14:53     ` Christoph Hellwig
2008-03-08 18:40       ` Duane Griffin
2008-03-11 14:35     ` Jan Kara
2008-03-12  1:02       ` Duane Griffin
2008-03-12 10:50         ` Jan Kara
     [not found]   ` <7f095bf2403465433796f2f7aab20f1c9a2e0f73.1204685366.git.duaneg@dghda.com>
2008-03-06  1:59     ` [RFC, PATCH 5/6] jbd: add support for read-only log recovery Duane Griffin
2008-03-11 15:05     ` Jan Kara
2008-03-12  1:40       ` Duane Griffin
2008-03-12 10:51         ` Jan Kara
2008-03-06  3:42 ` [RFC, PATCH 0/6] ext3: do not modify data on-disk when mounting read-only filesystem Andrew Morton
2008-03-06 11:20   ` Duane Griffin
2008-03-13  3:22 ` Daniel Phillips
2008-03-13 12:35   ` Duane Griffin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1204768754-29655-2-git-send-email-duaneg@dghda.com \
    --to=duaneg@dghda.com \
    --cc=adilger@clusterfs.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sct@redhat.com \
    --cc=tytso@mit.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).