lkml.org 
[lkml]   [2008]   [Mar]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 3/5] hugetlbfs: use call_once()
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;

\
 
 \ /
  Last update: 2008-03-10 16:13    [W:0.182 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site