Module Name: src
Committed By: rmind
Date: Thu May 19 03:21:24 UTC 2011
Modified Files:
src/sys/fs/tmpfs: tmpfs.h tmpfs_mem.c tmpfs_vfsops.c
Log Message:
- tmpfs: do not create dirent/node pools per-mount, there is no need to.
- tmpfs_mount: fix a leak of mount structures in error path.
To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/fs/tmpfs/tmpfs.h
cvs rdiff -u -r1.2 -r1.3 src/sys/fs/tmpfs/tmpfs_mem.c
cvs rdiff -u -r1.47 -r1.48 src/sys/fs/tmpfs/tmpfs_vfsops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/fs/tmpfs/tmpfs.h
diff -u src/sys/fs/tmpfs/tmpfs.h:1.39 src/sys/fs/tmpfs/tmpfs.h:1.40
--- src/sys/fs/tmpfs/tmpfs.h:1.39 Thu Jan 13 13:35:11 2011
+++ src/sys/fs/tmpfs/tmpfs.h Thu May 19 03:21:23 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs.h,v 1.39 2011/01/13 13:35:11 pooka Exp $ */
+/* $NetBSD: tmpfs.h,v 1.40 2011/05/19 03:21:23 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -298,11 +298,6 @@
/* Node list. */
kmutex_t tm_lock;
struct tmpfs_node_list tm_nodes;
-
- char tm_dwchan[32];
- struct pool tm_dirent_pool;
- char tm_nwchan[32];
- struct pool tm_node_pool;
};
/* --------------------------------------------------------------------- */
Index: src/sys/fs/tmpfs/tmpfs_mem.c
diff -u src/sys/fs/tmpfs/tmpfs_mem.c:1.2 src/sys/fs/tmpfs/tmpfs_mem.c:1.3
--- src/sys/fs/tmpfs/tmpfs_mem.c:1.2 Mon Jun 28 19:32:43 2010
+++ src/sys/fs/tmpfs/tmpfs_mem.c Thu May 19 03:21:23 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_mem.c,v 1.2 2010/06/28 19:32:43 rmind Exp $ */
+/* $NetBSD: tmpfs_mem.c,v 1.3 2011/05/19 03:21:23 rmind Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.2 2010/06/28 19:32:43 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_mem.c,v 1.3 2011/05/19 03:21:23 rmind Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@@ -42,18 +42,13 @@
#include <fs/tmpfs/tmpfs.h>
+extern struct pool tmpfs_dirent_pool;
+extern struct pool tmpfs_node_pool;
+
void
tmpfs_mntmem_init(struct tmpfs_mount *mp, uint64_t memlimit)
{
- sprintf(mp->tm_dwchan, "tmpfs_dirent_%p", mp);
- pool_init(&mp->tm_dirent_pool, sizeof(struct tmpfs_dirent), 0, 0, 0,
- mp->tm_dwchan, &pool_allocator_nointr, IPL_NONE);
-
- sprintf(mp->tm_nwchan, "tmpfs_node_%p", mp);
- pool_init(&mp->tm_node_pool, sizeof(struct tmpfs_node), 0, 0, 0,
- mp->tm_dwchan, &pool_allocator_nointr, IPL_NONE);
-
mutex_init(&mp->tm_acc_lock, MUTEX_DEFAULT, IPL_NONE);
mp->tm_mem_limit = memlimit;
mp->tm_bytes_used = 0;
@@ -65,8 +60,6 @@
KASSERT(mp->tm_bytes_used == 0);
mutex_destroy(&mp->tm_acc_lock);
- pool_destroy(&mp->tm_dirent_pool);
- pool_destroy(&mp->tm_node_pool);
}
/*
@@ -153,7 +146,7 @@
if (!tmpfs_mem_incr(mp, sizeof(struct tmpfs_dirent))) {
return NULL;
}
- return pool_get(&mp->tm_dirent_pool, PR_WAITOK);
+ return pool_get(&tmpfs_dirent_pool, PR_WAITOK);
}
void
@@ -161,7 +154,7 @@
{
tmpfs_mem_decr(mp, sizeof(struct tmpfs_dirent));
- pool_put(&mp->tm_dirent_pool, de);
+ pool_put(&tmpfs_dirent_pool, de);
}
struct tmpfs_node *
@@ -171,7 +164,7 @@
if (!tmpfs_mem_incr(mp, sizeof(struct tmpfs_node))) {
return NULL;
}
- return pool_get(&mp->tm_node_pool, PR_WAITOK);
+ return pool_get(&tmpfs_node_pool, PR_WAITOK);
}
void
@@ -179,7 +172,7 @@
{
tmpfs_mem_decr(mp, sizeof(struct tmpfs_node));
- pool_put(&mp->tm_node_pool, tn);
+ pool_put(&tmpfs_node_pool, tn);
}
/*
Index: src/sys/fs/tmpfs/tmpfs_vfsops.c
diff -u src/sys/fs/tmpfs/tmpfs_vfsops.c:1.47 src/sys/fs/tmpfs/tmpfs_vfsops.c:1.48
--- src/sys/fs/tmpfs/tmpfs_vfsops.c:1.47 Sat Apr 2 14:24:53 2011
+++ src/sys/fs/tmpfs/tmpfs_vfsops.c Thu May 19 03:21:23 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: tmpfs_vfsops.c,v 1.47 2011/04/02 14:24:53 hannken Exp $ */
+/* $NetBSD: tmpfs_vfsops.c,v 1.48 2011/05/19 03:21:23 rmind Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.47 2011/04/02 14:24:53 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.48 2011/05/19 03:21:23 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -60,7 +60,8 @@
MODULE(MODULE_CLASS_VFS, tmpfs, NULL);
-/* --------------------------------------------------------------------- */
+struct pool tmpfs_dirent_pool;
+struct pool tmpfs_node_pool;
static int tmpfs_mount(struct mount *, const char *, void *, size_t *);
static int tmpfs_start(struct mount *, int);
@@ -76,7 +77,23 @@
static int tmpfs_snapshot(struct mount *, struct vnode *,
struct timespec *);
-/* --------------------------------------------------------------------- */
+static void
+tmpfs_init(void)
+{
+
+ pool_init(&tmpfs_dirent_pool, sizeof(struct tmpfs_dirent), 0, 0, 0,
+ "tmpfs_dirent", &pool_allocator_nointr, IPL_NONE);
+ pool_init(&tmpfs_node_pool, sizeof(struct tmpfs_node), 0, 0, 0,
+ "tmpfs_node", &pool_allocator_nointr, IPL_NONE);
+}
+
+static void
+tmpfs_done(void)
+{
+
+ pool_destroy(&tmpfs_dirent_pool);
+ pool_destroy(&tmpfs_node_pool);
+}
static int
tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
@@ -169,8 +186,12 @@
mp->mnt_iflag |= IMNT_MPSAFE;
vfs_getnewfsid(mp);
- return set_statvfs_info(path, UIO_USERSPACE, "tmpfs", UIO_SYSSPACE,
+ error = set_statvfs_info(path, UIO_USERSPACE, "tmpfs", UIO_SYSSPACE,
mp->mnt_op->vfs_name, mp, curlwp);
+ if (error) {
+ (void)tmpfs_unmount(mp, MNT_FORCE);
+ }
+ return error;
}
/* --------------------------------------------------------------------- */
@@ -182,16 +203,12 @@
return 0;
}
-/* --------------------------------------------------------------------- */
-
-/* ARGSUSED2 */
static int
tmpfs_unmount(struct mount *mp, int mntflags)
{
- int error;
- int flags = 0;
struct tmpfs_mount *tmp;
struct tmpfs_node *node;
+ int error, flags = 0;
/* Handle forced unmounts. */
if (mntflags & MNT_FORCE)
@@ -360,24 +377,6 @@
return 0;
}
-/* --------------------------------------------------------------------- */
-
-static void
-tmpfs_init(void)
-{
-
-}
-
-/* --------------------------------------------------------------------- */
-
-static void
-tmpfs_done(void)
-{
-
-}
-
-/* --------------------------------------------------------------------- */
-
static int
tmpfs_snapshot(struct mount *mp, struct vnode *vp,
struct timespec *ctime)