Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/fs Convert some simple_lock(9) uses to mutex(9) and mall...
details: https://anonhg.NetBSD.org/src/rev/745ac39bbf90
branches: trunk
changeset: 765274:745ac39bbf90
user: rmind <rmind%NetBSD.org@localhost>
date: Mon May 23 22:00:30 2011 +0000
description:
Convert some simple_lock(9) uses to mutex(9) and malloc(9) to kmem(9).
diffstat:
sys/fs/adosfs/adutil.c | 22 ++++++++----------
sys/fs/adosfs/advfsops.c | 39 +++++++++++++++------------------
sys/fs/filecorefs/filecore_extern.h | 7 +-----
sys/fs/filecorefs/filecore_node.c | 42 +++++++++++++++++-------------------
sys/fs/filecorefs/filecore_vfsops.c | 15 +++---------
sys/fs/filecorefs/filecore_vnops.c | 8 +++---
6 files changed, 57 insertions(+), 76 deletions(-)
diffs (truncated from 468 to 300 lines):
diff -r 106d21237087 -r 745ac39bbf90 sys/fs/adosfs/adutil.c
--- a/sys/fs/adosfs/adutil.c Mon May 23 21:59:23 2011 +0000
+++ b/sys/fs/adosfs/adutil.c Mon May 23 22:00:30 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: adutil.c,v 1.13 2010/07/21 17:52:09 hannken Exp $ */
+/* $NetBSD: adutil.c,v 1.14 2011/05/23 22:00:30 rmind Exp $ */
/*
* Copyright (c) 1994 Christian E. Hopps
@@ -32,18 +32,16 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adutil.c,v 1.13 2010/07/21 17:52:09 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adutil.c,v 1.14 2011/05/23 22:00:30 rmind Exp $");
#include <sys/param.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#include <sys/proc.h>
#include <sys/systm.h>
-#include <sys/malloc.h>
#include <sys/time.h>
#include <sys/queue.h>
#include <sys/buf.h>
-#include <sys/simplelock.h>
#include <fs/adosfs/adosfs.h>
/*
@@ -52,7 +50,7 @@
#define AHASH(an) ((an) & (ANODEHASHSZ - 1))
static int CapitalChar(int, int);
-extern struct simplelock adosfs_hashlock;
+extern kmutex_t adosfs_hashlock;
struct vnode *
adosfs_ahashget(struct mount *mp, ino_t an)
@@ -64,18 +62,18 @@
hp = &VFSTOADOSFS(mp)->anodetab[AHASH(an)];
start_over:
- simple_lock(&adosfs_hashlock);
+ mutex_enter(&adosfs_hashlock);
for (ap = hp->lh_first; ap != NULL; ap = ap->link.le_next) {
if (ap->block == an) {
vp = ATOV(ap);
mutex_enter(&vp->v_interlock);
- simple_unlock(&adosfs_hashlock);
+ mutex_exit(&adosfs_hashlock);
if (vget(vp, LK_EXCLUSIVE))
goto start_over;
return (ATOV(ap));
}
}
- simple_unlock(&adosfs_hashlock);
+ mutex_exit(&adosfs_hashlock);
return (NULL);
}
@@ -89,17 +87,17 @@
{
VOP_LOCK(ATOV(ap), LK_EXCLUSIVE);
- simple_lock(&adosfs_hashlock);
+ mutex_enter(&adosfs_hashlock);
LIST_INSERT_HEAD(&->anodetab[AHASH(ap->block)], ap, link);
- simple_unlock(&adosfs_hashlock);
+ mutex_exit(&adosfs_hashlock);
}
void
adosfs_aremhash(struct anode *ap)
{
- simple_lock(&adosfs_hashlock);
+ mutex_enter(&adosfs_hashlock);
LIST_REMOVE(ap, link);
- simple_unlock(&adosfs_hashlock);
+ mutex_exit(&adosfs_hashlock);
}
int
diff -r 106d21237087 -r 745ac39bbf90 sys/fs/adosfs/advfsops.c
--- a/sys/fs/adosfs/advfsops.c Mon May 23 21:59:23 2011 +0000
+++ b/sys/fs/adosfs/advfsops.c Mon May 23 22:00:30 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: advfsops.c,v 1.60 2010/06/24 13:03:08 hannken Exp $ */
+/* $NetBSD: advfsops.c,v 1.61 2011/05/23 22:00:30 rmind Exp $ */
/*
* Copyright (c) 1994 Christian E. Hopps
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.60 2010/06/24 13:03:08 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.61 2011/05/23 22:00:30 rmind Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@@ -57,7 +57,6 @@
#include <sys/buf.h>
#include <sys/conf.h>
#include <sys/kauth.h>
-#include <sys/simplelock.h>
#include <sys/module.h>
#include <fs/adosfs/adosfs.h>
@@ -70,13 +69,11 @@
int adosfs_mountfs(struct vnode *, struct mount *, struct lwp *);
int adosfs_loadbitmap(struct adosfsmount *);
-struct simplelock adosfs_hashlock;
+kmutex_t adosfs_hashlock;
struct pool adosfs_node_pool;
-MALLOC_JUSTDEFINE(M_ADOSFSMNT, "adosfs mount", "adosfs mount structures");
MALLOC_JUSTDEFINE(M_ANODE, "adosfs anode","adosfs anode structures and tables");
-MALLOC_JUSTDEFINE(M_ADOSFSBITMAP, "adosfs bitmap", "adosfs bitmap");
static const struct genfs_ops adosfs_genfsops = {
.gop_size = genfs_size,
@@ -167,6 +164,7 @@
struct adosfsmount *amp;
struct buf *bp;
struct vnode *rvp;
+ size_t bitmap_sz = 0;
int error, part, i;
part = DISKPART(devvp->v_rdev);
@@ -185,8 +183,7 @@
goto fail;
parp = &dl.d_partitions[part];
- amp = malloc(sizeof(struct adosfsmount), M_ADOSFSMNT, M_WAITOK);
- memset((char *)amp, 0, (u_long)sizeof(struct adosfsmount));
+ amp = kmem_zalloc(sizeof(struct adosfsmount), KM_SLEEP);
amp->mp = mp;
if (dl.d_type == DTYPE_FLOPPY) {
amp->bsize = dl.d_secsize;
@@ -246,15 +243,15 @@
if ((error = VFS_ROOT(mp, &rvp)) != 0)
goto fail;
/* allocate and load bitmap, set free space */
- amp->bitmap = malloc(((amp->numblks + 31) / 32) * sizeof(*amp->bitmap),
- M_ADOSFSBITMAP, M_WAITOK);
+ bitmap_sz = ((amp->numblks + 31) / 32) * sizeof(*amp->bitmap);
+ amp->bitmap = kmem_alloc(bitmap_sz, KM_SLEEP);
if (amp->bitmap)
adosfs_loadbitmap(amp);
if (mp->mnt_flag & MNT_RDONLY && amp->bitmap) {
/*
* Don't need the bitmap any more if it's read-only.
*/
- free(amp->bitmap, M_ADOSFSBITMAP);
+ kmem_free(amp->bitmap, bitmap_sz);
amp->bitmap = NULL;
}
vput(rvp);
@@ -266,9 +263,9 @@
(void) VOP_CLOSE(devvp, FREAD, NOCRED);
VOP_UNLOCK(devvp);
if (amp && amp->bitmap)
- free(amp->bitmap, M_ADOSFSBITMAP);
+ kmem_free(amp->bitmap, bitmap_sz);
if (amp)
- free(amp, M_ADOSFSMNT);
+ kmem_free(amp, sizeof(*amp));
return (error);
}
@@ -296,9 +293,12 @@
vn_lock(amp->devvp, LK_EXCLUSIVE | LK_RETRY);
error = VOP_CLOSE(amp->devvp, FREAD, NOCRED);
vput(amp->devvp);
- if (amp->bitmap)
- free(amp->bitmap, M_ADOSFSBITMAP);
- free(amp, M_ADOSFSMNT);
+ if (amp->bitmap) {
+ size_t bitmap_sz = ((amp->numblks + 31) / 32) *
+ sizeof(*amp->bitmap);
+ kmem_free(amp->bitmap, bitmap_sz);
+ }
+ kmem_free(amp, sizeof(*amp));
mp->mnt_data = NULL;
mp->mnt_flag &= ~MNT_LOCAL;
return (error);
@@ -731,12 +731,10 @@
adosfs_init(void)
{
- malloc_type_attach(M_ADOSFSMNT);
malloc_type_attach(M_ANODE);
- malloc_type_attach(M_ADOSFSBITMAP);
+ mutex_init(&adosfs_hashlock, MUTEX_DEFAULT, IPL_NONE);
pool_init(&adosfs_node_pool, sizeof(struct anode), 0, 0, 0, "adosndpl",
&pool_allocator_nointr, IPL_NONE);
- simple_lock_init(&adosfs_hashlock);
}
void
@@ -744,9 +742,8 @@
{
pool_destroy(&adosfs_node_pool);
- malloc_type_detach(M_ADOSFSBITMAP);
+ mutex_destroy(&adosfs_hashlock);
malloc_type_detach(M_ANODE);
- malloc_type_detach(M_ADOSFSMNT);
}
/*
diff -r 106d21237087 -r 745ac39bbf90 sys/fs/filecorefs/filecore_extern.h
--- a/sys/fs/filecorefs/filecore_extern.h Mon May 23 21:59:23 2011 +0000
+++ b/sys/fs/filecorefs/filecore_extern.h Mon May 23 22:00:30 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: filecore_extern.h,v 1.19 2009/03/14 14:46:09 dsl Exp $ */
+/* $NetBSD: filecore_extern.h,v 1.20 2011/05/23 22:00:30 rmind Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@@ -76,11 +76,6 @@
#define FILECOREMNT_ROOT 0
#endif
-#include <sys/mallocvar.h>
-
-MALLOC_DECLARE(M_FILECOREMNT);
-MALLOC_DECLARE(M_FILECORETMP);
-
struct filecore_mnt {
struct mount *fc_mountp;
dev_t fc_dev;
diff -r 106d21237087 -r 745ac39bbf90 sys/fs/filecorefs/filecore_node.c
--- a/sys/fs/filecorefs/filecore_node.c Mon May 23 21:59:23 2011 +0000
+++ b/sys/fs/filecorefs/filecore_node.c Mon May 23 22:00:30 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: filecore_node.c,v 1.23 2011/05/19 03:11:56 rmind Exp $ */
+/* $NetBSD: filecore_node.c,v 1.24 2011/05/23 22:00:31 rmind Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1994
@@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: filecore_node.c,v 1.23 2011/05/19 03:11:56 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: filecore_node.c,v 1.24 2011/05/23 22:00:31 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -78,10 +78,9 @@
#include <sys/vnode.h>
#include <sys/namei.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
#include <sys/pool.h>
#include <sys/stat.h>
-#include <sys/simplelock.h>
+#include <sys/mutex.h>
#include <fs/filecorefs/filecore.h>
#include <fs/filecorefs/filecore_extern.h>
@@ -91,12 +90,13 @@
/*
* Structures associated with filecore_node caching.
*/
-LIST_HEAD(ihashhead, filecore_node) *filecorehashtbl;
-u_long filecorehash;
+static LIST_HEAD(ihashhead, filecore_node) *filecorehashtbl;
+static u_long filecorehash;
+
#define INOHASH(device, inum) (((device) + ((inum)>>12)) & filecorehash)
-struct simplelock filecore_ihash_slock;
-struct pool filecore_node_pool;
+static kmutex_t filecore_ihash_lock;
+struct pool filecore_node_pool;
extern int prtactive; /* 1 => print out reclaim of active vnodes */
@@ -107,13 +107,11 @@
filecore_init(void)
{
- malloc_type_attach(M_FILECOREMNT);
- malloc_type_attach(M_FILECORETMP);
+ mutex_init(&filecore_ihash_lock, MUTEX_DEFAULT, IPL_NONE);
pool_init(&filecore_node_pool, sizeof(struct filecore_node), 0, 0, 0,
"filecrnopl", &pool_allocator_nointr, IPL_NONE);
filecorehashtbl = hashinit(desiredvnodes, HASH_LIST, true,
&filecorehash);
- simple_lock_init(&filecore_ihash_slock);
}
/*
@@ -129,7 +127,7 @@
hash = hashinit(desiredvnodes, HASH_LIST, true, &mask);
Home |
Main Index |
Thread Index |
Old Index