On Thu, Mar 06, 2008 at 01:59:10AM +0000, Duane Griffin wrote:Actually the whole code surrounding this is far too confusing. The patch below converts it much simpler code with proper goto unwinding for initialization failures: Index: linux-2.6/fs/jbd/journal.c =================================================================== --- linux-2.6.orig/fs/jbd/journal.c 2008-03-08 15:43:41.000000000 +0100 +++ linux-2.6/fs/jbd/journal.c 2008-03-08 15:50:44.000000000 +0100 @@ -1615,31 +1615,6 @@ static struct kmem_cache *journal_head_c static atomic_t nr_journal_heads = ATOMIC_INIT(0); #endif -static int journal_init_journal_head_cache(void) -{ - int retval; - - J_ASSERT(journal_head_cache == 0); - journal_head_cache = kmem_cache_create("journal_head", - sizeof(struct journal_head), - 0, /* offset */ - SLAB_TEMPORARY, /* flags */ - NULL); /* ctor */ - retval = 0; - if (journal_head_cache == 0) { - retval = -ENOMEM; - printk(KERN_EMERG "JBD: no memory for journal_head cache\n"); - } - return retval; -} - -static void journal_destroy_journal_head_cache(void) -{ - J_ASSERT(journal_head_cache != NULL); - kmem_cache_destroy(journal_head_cache); - journal_head_cache = NULL; -} - /* * journal_head splicing and dicing */ @@ -1891,59 +1866,45 @@ static inline void jbd_remove_debugfs_en struct kmem_cache *jbd_handle_cache; -static int __init journal_init_handle_cache(void) -{ - jbd_handle_cache = kmem_cache_create("journal_handle", - sizeof(handle_t), - 0, /* offset */ - SLAB_TEMPORARY, /* flags */ - NULL); /* ctor */ - if (jbd_handle_cache == NULL) { - printk(KERN_EMERG "JBD: failed to create handle cache\n"); - return -ENOMEM; - } - return 0; -} - -static void journal_destroy_handle_cache(void) -{ - if (jbd_handle_cache) - kmem_cache_destroy(jbd_handle_cache); -} - /* * Module startup and shutdown */ -static int __init journal_init_caches(void) +static int __init journal_init(void) { int ret; - ret = journal_init_revoke_caches(); - if (ret == 0) - ret = journal_init_journal_head_cache(); - if (ret == 0) - ret = journal_init_handle_cache(); - return ret; -} + BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024); -static void journal_destroy_caches(void) -{ - journal_destroy_revoke_caches(); - journal_destroy_journal_head_cache(); - journal_destroy_handle_cache(); -} + ret = journal_init_revoke_caches(); + if (ret) + goto out; -static int __init journal_init(void) -{ - int ret; + ret = -ENOMEM; + journal_head_cache = kmem_cache_create("journal_head", + sizeof(struct journal_head), + 0, /* offset */ + SLAB_TEMPORARY, /* flags */ + NULL); /* ctor */ + if (!journal_head_cache) + goto out_destroy_revoke_caches; - BUILD_BUG_ON(sizeof(struct journal_superblock_s) != 1024); + jbd_handle_cache = kmem_cache_create("journal_handle", + sizeof(handle_t), + 0, /* offset */ + SLAB_TEMPORARY, /* flags */ + NULL); /* ctor */ + if (!jbd_handle_cache) + goto out_destroy_head_cache; - ret = journal_init_caches(); - if (ret != 0) - journal_destroy_caches(); jbd_create_debugfs_entry(); + return 0; + + out_destroy_head_cache: + kmem_cache_destroy(journal_head_cache); + out_destroy_revoke_caches: + journal_destroy_revoke_caches(); + out: return ret; } @@ -1955,7 +1916,10 @@ static void __exit journal_exit(void) printk(KERN_EMERG "JBD: leaked %d journal_heads!\n", n); #endif jbd_remove_debugfs_entry(); - journal_destroy_caches(); + + kmem_cache_destroy(jbd_handle_cache); + kmem_cache_destroy(journal_head_cache); + journal_destroy_revoke_caches(); } MODULE_LICENSE("GPL"); --
| Amit K. Arora | [RFC] Heads up on sys_fallocate() |
| Jan Engelhardt | Re: Linux 2.6.21-rc4 |
| Alexey Dobriyan | ext2 reservations (Re: -mm merge plans for 2.6.23) |
| Linus Torvalds | Linux 2.6.27 |
git: | |
| Joakim Tjernlund | git-svn set-tree bug |
| Anatoly Yakovenko | GIT_SSL_NO_VERIFY=1 over http doesn't ignore a different ip address for the signed... |
| Benoit Sigoure | Re: Rebase/cherry-picking idea |
| Sam Song | Fwd: [OT] Re: Git via a proxy server? |
| Theo de Raadt | That whole "Linux stealing our code" thing |
| Richard Stallman | Re: Real men don't attack straw men |
| Marcos Laufer | dmesg IBM x3650 OpenBSD 4.3 |
| Richard Stallman | Real men don't attack straw men |
| Marcel Holtmann | Bluetooth fixes for 2.6.27 |
| Linus Torvalds | Re: tcp bw in 2.6 |
| Theodore Tso | Re: [bug?] tg3: Failed to load firmware "tigon/tg3_tso.bin" |
| Johannes Berg | Re: [PATCH] mac80211: rewrite fragmentation code |
| How to make my PCIE ATA storage device running in Linux | 2 hours ago | Linux general |
| sata/ide timeout errors on asus server-mb | 5 hours ago | Linux kernel |
| Shared swap partition | 6 hours ago | Linux general |
| usb mic not detected | 10 hours ago | Applications and Utilities |
| Problem in Inserting a module | 11 hours ago | Linux kernel |
| Treason Uncloaked | 16 hours ago | Linux kernel |
| high memory | 2 days ago | Linux kernel |
| semaphore access speed | 3 days ago | Applications and Utilities |
| the kernel how to power off the machine | 3 days ago | Linux kernel |
| Easter Eggs in windows XP | 3 days ago | Windows |
