-/* $OpenBSD: ufs_ihash.c,v 1.14 2010/04/23 19:57:43 oga Exp $ */
+/* $OpenBSD: ufs_ihash.c,v 1.15 2010/07/19 20:58:21 oga Exp $ */
/* $NetBSD: ufs_ihash.c,v 1.3 1996/02/09 22:36:04 christos Exp $ */
/*
#include <sys/systm.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
#include <ufs/ufs/quota.h>
LIST_HEAD(ihashhead, inode) *ihashtbl;
u_long ihash; /* size of hash table - 1 */
#define INOHASH(device, inum) (&ihashtbl[((device) + (inum)) & ihash])
+struct mutex ihash_mtx = MUTEX_INITIALIZER(IPL_NONE);
/*
* Initialize inode hash table.
{
struct inode *ip;
- /* XXXLOCKING lock hash list */
+ mtx_enter(&ihash_mtx);
LIST_FOREACH(ip, INOHASH(dev, inum), i_hash)
if (inum == ip->i_number && dev == ip->i_dev)
break;
- /* XXXLOCKING unlock hash list? */
+ mtx_leave(&ihash_mtx);
if (ip)
return (ITOV(ip));
struct inode *ip;
struct vnode *vp;
loop:
- /* XXXLOCKING lock hash list */
+ mtx_enter(&ihash_mtx);
LIST_FOREACH(ip, INOHASH(dev, inum), i_hash) {
if (inum == ip->i_number && dev == ip->i_dev) {
vp = ITOV(ip);
- /* XXXLOCKING unlock hash list? */
+ mtx_leave(&ihash_mtx);
if (vget(vp, LK_EXCLUSIVE, p))
goto loop;
return (vp);
}
}
- /* XXXLOCKING unlock hash list? */
+ mtx_leave(&ihash_mtx);
return (NULL);
}
/* lock the inode, then put it on the appropriate hash list */
lockmgr(&ip->i_lock, LK_EXCLUSIVE, NULL);
- /* XXXLOCKING lock hash list */
+ mtx_enter(&ihash_mtx);
LIST_FOREACH(curip, INOHASH(dev, inum), i_hash) {
if (inum == curip->i_number && dev == curip->i_dev) {
- /* XXXLOCKING unlock hash list? */
+ mtx_leave(&ihash_mtx);
lockmgr(&ip->i_lock, LK_RELEASE, NULL);
return (EEXIST);
}
ipp = INOHASH(dev, inum);
LIST_INSERT_HEAD(ipp, ip, i_hash);
- /* XXXLOCKING unlock hash list? */
+ mtx_leave(&ihash_mtx);
return (0);
}
void
ufs_ihashrem(struct inode *ip)
{
- /* XXXLOCKING lock hash list */
+ mtx_enter(&ihash_mtx);
if (ip->i_hash.le_prev == NULL)
return;
ip->i_hash.le_next = NULL;
ip->i_hash.le_prev = NULL;
#endif
- /* XXXLOCKING unlock hash list? */
+ mtx_leave(&ihash_mtx);
}