LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 4/5] shmem: use call_once()
Date: Tue, 11 Mar 2008 00:03:10 +0900	[thread overview]
Message-ID: <20080310150308.GC6407@APFDCB5C> (raw)
In-Reply-To: <20080310150148.GB6407@APFDCB5C>

This patch defers mounting tmpfs till shmem_file_setup() is
called first time by using call_once().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
---
 mm/shmem.c |   32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

Index: 2.6-rc/mm/shmem.c
===================================================================
--- 2.6-rc.orig/mm/shmem.c
+++ 2.6-rc/mm/shmem.c
@@ -50,6 +50,7 @@
 #include <linux/migrate.h>
 #include <linux/highmem.h>
 #include <linux/seq_file.h>
+#include <linux/once.h>
 
 #include <asm/uaccess.h>
 #include <asm/div64.h>
@@ -2520,7 +2521,6 @@ static struct file_system_type tmpfs_fs_
 	.get_sb		= shmem_get_sb,
 	.kill_sb	= kill_litter_super,
 };
-static struct vfsmount *shm_mnt;
 
 static int __init init_tmpfs(void)
 {
@@ -2540,27 +2540,29 @@ static int __init init_tmpfs(void)
 		goto out2;
 	}
 
-	shm_mnt = vfs_kern_mount(&tmpfs_fs_type, MS_NOUSER,
-				tmpfs_fs_type.name, NULL);
-	if (IS_ERR(shm_mnt)) {
-		error = PTR_ERR(shm_mnt);
-		printk(KERN_ERR "Could not kern_mount tmpfs\n");
-		goto out1;
-	}
 	return 0;
-
-out1:
-	unregister_filesystem(&tmpfs_fs_type);
 out2:
 	destroy_inodecache();
 out3:
 	bdi_destroy(&shmem_backing_dev_info);
 out4:
-	shm_mnt = ERR_PTR(error);
 	return error;
 }
 module_init(init_tmpfs)
 
+static struct vfsmount *shm_mnt;
+
+static int init_shm_mnt(void)
+{
+	shm_mnt = vfs_kern_mount(&tmpfs_fs_type, MS_NOUSER,
+				tmpfs_fs_type.name, NULL);
+	if (IS_ERR(shm_mnt)) {
+		printk(KERN_ERR "Could not kern_mount tmpfs\n");
+		return PTR_ERR(shm_mnt);
+	}
+	return 0;
+}
+
 /*
  * shmem_file_setup - get an unlinked file living in tmpfs
  *
@@ -2575,9 +2577,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);
 
 	if (size < 0 || size > SHMEM_MAX_BYTES)
 		return ERR_PTR(-EINVAL);

  reply	other threads:[~2008-03-10 15:10 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-10 14:57 [PATCH 1/5] lib: introduce call_once() Akinobu Mita
2008-03-10 15:00 ` [PATCH 2/5] idr: use call_once() Akinobu Mita
2008-03-10 15:01   ` [PATCH 3/5] hugetlbfs: " Akinobu Mita
2008-03-10 15:03     ` Akinobu Mita [this message]
2008-03-10 15:05       ` [PATCH 5/5] tiny-shmem: " Akinobu Mita
2008-03-10 22:15       ` [PATCH 4/5] shmem: " Hugh Dickins
2008-03-11 12:29         ` Akinobu Mita
2008-03-11 13:41           ` Hugh Dickins
2008-03-10 15:29 ` [PATCH 1/5] lib: introduce call_once() Joe Perches
2008-03-11 12:17   ` Akinobu Mita
2008-03-11  3:48 ` Andrew Morton
2008-03-11  4:10   ` Nick Piggin
2008-03-11  4:21     ` Andrew Morton
2008-03-11 12:27       ` Akinobu Mita
2008-03-11 17:35         ` Andrew Morton
2008-03-11 18:56           ` Joe Perches
2008-03-11 19:11             ` Andrew Morton
2008-03-15  4:01           ` Akinobu Mita
2008-03-11 12:41 ` Nick Piggin

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=20080310150308.GC6407@APFDCB5C \
    --to=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --subject='Re: [PATCH 4/5] shmem: use call_once()' \
    /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

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