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, William Irwin <wli@holomorphy.com>,
	linux-fsdevel@vger.kernel.org
Subject: [PATCH 3/5] hugetlbfs: use call_once()
Date: Tue, 11 Mar 2008 00:01:50 +0900	[thread overview]
Message-ID: <20080310150148.GB6407@APFDCB5C> (raw)
In-Reply-To: <20080310150026.GA6407@APFDCB5C>

This patch defers mounting hugetlbfs till hugetlb_file_setup() is
called first time by using call_once().

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: William Irwin <wli@holomorphy.com>
---
 fs/hugetlbfs/inode.c |   30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

Index: 2.6-rc/fs/hugetlbfs/inode.c
===================================================================
--- 2.6-rc.orig/fs/hugetlbfs/inode.c
+++ 2.6-rc/fs/hugetlbfs/inode.c
@@ -31,6 +31,7 @@
 #include <linux/dnotify.h>
 #include <linux/statfs.h>
 #include <linux/security.h>
+#include <linux/once.h>
 
 #include <asm/uaccess.h>
 
@@ -903,6 +904,13 @@ static struct file_system_type hugetlbfs
 
 static struct vfsmount *hugetlbfs_vfsmount;
 
+static int init_hugetlbfs_vfsmount(void)
+{
+	hugetlbfs_vfsmount = kern_mount(&hugetlbfs_fs_type);
+
+	return IS_ERR(hugetlbfs_vfsmount) ? PTR_ERR(hugetlbfs_vfsmount) : 0;
+}
+
 static int can_do_hugetlb_shm(void)
 {
 	return likely(capable(CAP_IPC_LOCK) ||
@@ -912,14 +920,16 @@ static int can_do_hugetlb_shm(void)
 
 struct file *hugetlb_file_setup(const char *name, size_t size)
 {
-	int error = -ENOMEM;
+	int error;
 	struct file *file;
 	struct inode *inode;
 	struct dentry *dentry, *root;
 	struct qstr quick_string;
+	static DEFINE_ONCE(once);
 
-	if (!hugetlbfs_vfsmount)
-		return ERR_PTR(-ENOENT);
+	error = call_once(&once, init_hugetlbfs_vfsmount);
+	if (error)
+		return ERR_PTR(error);
 
 	if (!can_do_hugetlb_shm())
 		return ERR_PTR(-EPERM);
@@ -970,7 +980,6 @@ out_shm_unlock:
 static int __init init_hugetlbfs_fs(void)
 {
 	int error;
-	struct vfsmount *vfsmount;
 
 	error = bdi_init(&hugetlbfs_backing_dev_info);
 	if (error)
@@ -986,18 +995,9 @@ static int __init init_hugetlbfs_fs(void
 	if (error)
 		goto out;
 
-	vfsmount = kern_mount(&hugetlbfs_fs_type);
-
-	if (!IS_ERR(vfsmount)) {
-		hugetlbfs_vfsmount = vfsmount;
-		return 0;
-	}
-
-	error = PTR_ERR(vfsmount);
-
+	return 0;
  out:
-	if (error)
-		kmem_cache_destroy(hugetlbfs_inode_cachep);
+	kmem_cache_destroy(hugetlbfs_inode_cachep);
  out2:
 	bdi_destroy(&hugetlbfs_backing_dev_info);
 	return error;

  reply	other threads:[~2008-03-10 15:09 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   ` Akinobu Mita [this message]
2008-03-10 15:03     ` [PATCH 4/5] shmem: " Akinobu Mita
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=20080310150148.GB6407@APFDCB5C \
    --to=akinobu.mita@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wli@holomorphy.com \
    --subject='Re: [PATCH 3/5] hugetlbfs: 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).