From 5cee5af52c8488784c3cae44109010f589502759 Mon Sep 17 00:00:00 2001 From: rmind Date: Mon, 23 May 2011 22:00:30 +0000 Subject: [PATCH] Convert some simple_lock(9) uses to mutex(9) and malloc(9) to kmem(9). --- 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 | 44 ++++++++++++++--------------- sys/fs/filecorefs/filecore_vfsops.c | 15 +++------- sys/fs/filecorefs/filecore_vnops.c | 8 +++--- 6 files changed, 58 insertions(+), 77 deletions(-) diff --git a/sys/fs/adosfs/adutil.c b/sys/fs/adosfs/adutil.c index 5118f1e6f161..5303cd0bddc3 100644 --- a/sys/fs/adosfs/adutil.c +++ b/sys/fs/adosfs/adutil.c @@ -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 -__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 #include #include #include #include -#include #include #include #include -#include #include /* @@ -52,7 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: adutil.c,v 1.13 2010/07/21 17:52:09 hannken Exp $"); #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 @@ adosfs_ahashget(struct mount *mp, ino_t an) 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 @@ adosfs_ainshash(struct adosfsmount *amp, struct anode *ap) { 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 --git a/sys/fs/adosfs/advfsops.c b/sys/fs/adosfs/advfsops.c index b35c1096c9aa..dd53a60447cb 100644 --- a/sys/fs/adosfs/advfsops.c +++ b/sys/fs/adosfs/advfsops.c @@ -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 -__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 @@ __KERNEL_RCSID(0, "$NetBSD: advfsops.c,v 1.60 2010/06/24 13:03:08 hannken Exp $" #include #include #include -#include #include #include @@ -70,13 +69,11 @@ static struct sysctllog *adosfs_sysctl_log; 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 @@ adosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) 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 @@ adosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) 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 @@ adosfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) 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 @@ fail: (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 @@ adosfs_unmount(struct mount *mp, int mntflags) 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 @@ void 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 @@ adosfs_done(void) { 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 --git a/sys/fs/filecorefs/filecore_extern.h b/sys/fs/filecorefs/filecore_extern.h index f63cdd23fcbf..b019bbecbdb9 100644 --- a/sys/fs/filecorefs/filecore_extern.h +++ b/sys/fs/filecorefs/filecore_extern.h @@ -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 - -MALLOC_DECLARE(M_FILECOREMNT); -MALLOC_DECLARE(M_FILECORETMP); - struct filecore_mnt { struct mount *fc_mountp; dev_t fc_dev; diff --git a/sys/fs/filecorefs/filecore_node.c b/sys/fs/filecorefs/filecore_node.c index 4e6435e131f0..04d26da48441 100644 --- a/sys/fs/filecorefs/filecore_node.c +++ b/sys/fs/filecorefs/filecore_node.c @@ -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 -__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 #include @@ -78,10 +78,9 @@ __KERNEL_RCSID(0, "$NetBSD: filecore_node.c,v 1.23 2011/05/19 03:11:56 rmind Exp #include #include #include -#include #include #include -#include +#include #include #include @@ -91,12 +90,13 @@ __KERNEL_RCSID(0, "$NetBSD: filecore_node.c,v 1.23 2011/05/19 03:11:56 rmind Exp /* * Structures associated with filecore_node caching. */ -LIST_HEAD(ihashhead, filecore_node) *filecorehashtbl; -u_long filecorehash; -#define INOHASH(device, inum) (((device) + ((inum)>>12)) & filecorehash) -struct simplelock filecore_ihash_slock; +static LIST_HEAD(ihashhead, filecore_node) *filecorehashtbl; +static u_long filecorehash; -struct pool filecore_node_pool; +#define INOHASH(device, inum) (((device) + ((inum)>>12)) & filecorehash) + +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 @@ void 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 @@ filecore_reinit(void) hash = hashinit(desiredvnodes, HASH_LIST, true, &mask); - simple_lock(&filecore_ihash_slock); + mutex_enter(&filecore_ihash_lock); oldhash = filecorehashtbl; oldmask = filecorehash; filecorehashtbl = hash; @@ -141,7 +139,7 @@ filecore_reinit(void) LIST_INSERT_HEAD(&hash[val], ip, i_hash); } } - simple_unlock(&filecore_ihash_slock); + mutex_exit(&filecore_ihash_lock); hashdone(oldhash, HASH_LIST, oldmask); } @@ -151,10 +149,10 @@ filecore_reinit(void) void filecore_done(void) { + hashdone(filecorehashtbl, HASH_LIST, filecorehash); pool_destroy(&filecore_node_pool); - malloc_type_detach(M_FILECORETMP); - malloc_type_detach(M_FILECOREMNT); + mutex_destroy(&filecore_ihash_lock); } /* @@ -168,18 +166,18 @@ filecore_ihashget(dev_t dev, ino_t inum) struct vnode *vp; loop: - simple_lock(&filecore_ihash_slock); + mutex_enter(&filecore_ihash_lock); LIST_FOREACH(ip, &filecorehashtbl[INOHASH(dev, inum)], i_hash) { if (inum == ip->i_number && dev == ip->i_dev) { vp = ITOV(ip); mutex_enter(&vp->v_interlock); - simple_unlock(&filecore_ihash_slock); + mutex_exit(&filecore_ihash_lock); if (vget(vp, LK_EXCLUSIVE)) goto loop; return (vp); } } - simple_unlock(&filecore_ihash_slock); + mutex_exit(&filecore_ihash_lock); return (NULL); } @@ -191,10 +189,10 @@ filecore_ihashins(struct filecore_node *ip) { struct ihashhead *ipp; - simple_lock(&filecore_ihash_slock); + mutex_enter(&filecore_ihash_lock); ipp = &filecorehashtbl[INOHASH(ip->i_dev, ip->i_number)]; LIST_INSERT_HEAD(ipp, ip, i_hash); - simple_unlock(&filecore_ihash_slock); + mutex_exit(&filecore_ihash_lock); VOP_LOCK(ITOV(ip), LK_EXCLUSIVE); } @@ -205,9 +203,9 @@ filecore_ihashins(struct filecore_node *ip) void filecore_ihashrem(struct filecore_node *ip) { - simple_lock(&filecore_ihash_slock); + mutex_enter(&filecore_ihash_lock); LIST_REMOVE(ip, i_hash); - simple_unlock(&filecore_ihash_slock); + mutex_exit(&filecore_ihash_lock); } /* diff --git a/sys/fs/filecorefs/filecore_vfsops.c b/sys/fs/filecorefs/filecore_vfsops.c index b2db78faceb7..fe5f9be42378 100644 --- a/sys/fs/filecorefs/filecore_vfsops.c +++ b/sys/fs/filecorefs/filecore_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecore_vfsops.c,v 1.64 2010/06/24 13:03:09 hannken Exp $ */ +/* $NetBSD: filecore_vfsops.c,v 1.65 2011/05/23 22:00:31 rmind Exp $ */ /*- * Copyright (c) 1994 The Regents of the University of California. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.64 2010/06/24 13:03:09 hannken Exp $"); +__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.65 2011/05/23 22:00:31 rmind Exp $"); #if defined(_KERNEL_OPT) #include "opt_compat_netbsd.h" @@ -84,7 +84,6 @@ __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.64 2010/06/24 13:03:09 hannken #include #include #include -#include #include #include #include @@ -98,11 +97,6 @@ __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.64 2010/06/24 13:03:09 hannken MODULE(MODULE_CLASS_VFS, filecore, NULL); -MALLOC_JUSTDEFINE(M_FILECOREMNT, - "filecore mount", "Filecore FS mount structures"); -MALLOC_JUSTDEFINE(M_FILECORETMP, - "filecore temp", "Filecore FS temporary structures"); - static struct sysctllog *filecore_sysctl_log; extern const struct vnodeopv_desc filecore_vnodeop_opv_desc; @@ -373,8 +367,7 @@ filecore_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l, struct fi if (error != 0) goto out; fcdr = (struct filecore_disc_record *)((char *)(bp->b_data) + 4); - fcmp = malloc(sizeof *fcmp, M_FILECOREMNT, M_WAITOK); - memset(fcmp, 0, sizeof *fcmp); + fcmp = kmem_zalloc(sizeof(*fcmp), KM_SLEEP); if (fcdr->log2bpmb > fcdr->log2secsize) fcmp->log2bsize = fcdr->log2bpmb; else fcmp->log2bsize = fcdr->log2secsize; @@ -464,7 +457,7 @@ filecore_unmount(struct mount *mp, int mntflags) vn_lock(fcmp->fc_devvp, LK_EXCLUSIVE | LK_RETRY); error = VOP_CLOSE(fcmp->fc_devvp, FREAD, NOCRED); vput(fcmp->fc_devvp); - free(fcmp, M_FILECOREMNT); + kmem_free(fcmp, sizeof(*fcmp)); mp->mnt_data = NULL; mp->mnt_flag &= ~MNT_LOCAL; return (error); diff --git a/sys/fs/filecorefs/filecore_vnops.c b/sys/fs/filecorefs/filecore_vnops.c index a99ae155dc1f..e28783a900fb 100644 --- a/sys/fs/filecorefs/filecore_vnops.c +++ b/sys/fs/filecorefs/filecore_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: filecore_vnops.c,v 1.32 2009/07/03 21:17:40 elad Exp $ */ +/* $NetBSD: filecore_vnops.c,v 1.33 2011/05/23 22:00:31 rmind Exp $ */ /*- * Copyright (c) 1994 The Regents of the University of California. @@ -66,7 +66,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.32 2009/07/03 21:17:40 elad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: filecore_vnops.c,v 1.33 2011/05/23 22:00:31 rmind Exp $"); #include #include @@ -333,7 +333,7 @@ filecore_readdir(void *v) cookies = malloc(ncookies * sizeof(off_t), M_TEMP, M_WAITOK); } - de = malloc(sizeof(struct dirent), M_FILECORETMP, M_WAITOK | M_ZERO); + de = kmem_zalloc(sizeof(struct dirent), KM_SLEEP); for (; ; i++) { switch (i) { @@ -397,7 +397,7 @@ out: #endif brelse (bp, 0); - free(de, M_FILECORETMP); + kmem_free(de, sizeof(*de)); return (error); }