From mboxrd@z Thu Jan 1 00:00:00 1970 From: Akinobu Mita Subject: [PATCH 5/5] tiny-shmem: use call_once() Date: Tue, 11 Mar 2008 00:05:37 +0900 Message-ID: <20080310150531.GD6407@APFDCB5C> References: <20080310145704.GA6396@APFDCB5C> <20080310150026.GA6407@APFDCB5C> <20080310150148.GB6407@APFDCB5C> <20080310150308.GC6407@APFDCB5C> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org To: linux-kernel@vger.kernel.org Return-path: Received: from rv-out-0910.google.com ([209.85.198.191]:48586 "EHLO rv-out-0910.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751055AbYCJPNL (ORCPT ); Mon, 10 Mar 2008 11:13:11 -0400 Received: by rv-out-0910.google.com with SMTP id k20so1157425rvb.1 for ; Mon, 10 Mar 2008 08:13:10 -0700 (PDT) Content-Disposition: inline In-Reply-To: <20080310150308.GC6407@APFDCB5C> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: This patch defers mounting tmpfs till shmem_file_setup() is called first time by using call_once(). Signed-off-by: Akinobu Mita --- mm/tiny-shmem.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) Index: 2.6-rc/mm/tiny-shmem.c =================================================================== --- 2.6-rc.orig/mm/tiny-shmem.c +++ 2.6-rc/mm/tiny-shmem.c @@ -19,6 +19,7 @@ #include #include #include +#include static struct file_system_type tmpfs_fs_type = { .name = "tmpfs", @@ -26,19 +27,23 @@ static struct file_system_type tmpfs_fs_ .kill_sb = kill_litter_super, }; -static struct vfsmount *shm_mnt; - static int __init init_tmpfs(void) { BUG_ON(register_filesystem(&tmpfs_fs_type) != 0); - shm_mnt = kern_mount(&tmpfs_fs_type); - BUG_ON(IS_ERR(shm_mnt)); - return 0; } module_init(init_tmpfs) +static struct vfsmount *shm_mnt; + +static int init_shm_mnt(void) +{ + shm_mnt = kern_mount(&tmpfs_fs_type); + + return IS_ERR(shm_mnt) ? PTR_ERR(shm_mnt) : 0; +} + /* * shmem_file_setup - get an unlinked file living in tmpfs * @@ -53,9 +58,11 @@ struct file *shmem_file_setup(char *name struct inode *inode; struct dentry *dentry, *root; struct qstr this; + static DEFINE_ONCE(once); - if (IS_ERR(shm_mnt)) - return (void *)shm_mnt; + error = call_once(&once, init_shm_mnt); + if (error) + return ERR_PTR(error); error = -ENOMEM; this.name = name;