2 * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
30 * $FreeBSD: src/sys/fs/hpfs/hpfs_hash.c,v 1.1 1999/12/09 19:09:58 semenu Exp $
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
37 #include <sys/vnode.h>
38 #include <sys/mount.h>
39 #include <sys/malloc.h>
44 MALLOC_DEFINE(M_HPFSHASH
, "HPFS hash", "HPFS node hash tables");
47 * Structures associated with hpfsnode cacheing.
49 static LIST_HEAD(hphashhead
, hpfsnode
) *hpfs_hphashtbl
;
50 static u_long hpfs_hphash
; /* size of hash table - 1 */
51 #define HPNOHASH(dev, lsn) (&hpfs_hphashtbl[(minor(dev) + (lsn)) & hpfs_hphash])
52 #ifndef NULL_SIMPLELOCKS
53 static struct lwkt_token hpfs_hphash_token
;
55 struct lock hpfs_hphash_lock
;
58 * Initialize inode hash table.
64 lockinit (&hpfs_hphash_lock
, "hpfs_hphashlock", 0, 0);
65 hpfs_hphashtbl
= hashinit(desiredvnodes
, M_HPFSHASH
, &hpfs_hphash
);
66 lwkt_token_init(&hpfs_hphash_token
, "hpfsihash");
70 * Free the inode hash.
73 hpfs_hphash_uninit(struct vfsconf
*vfc
)
75 lwkt_gettoken(&hpfs_hphash_token
);
77 hashdestroy(hpfs_hphashtbl
, M_HPFSHASH
, hpfs_hphash
);
78 lwkt_reltoken(&hpfs_hphash_token
);
84 * Use the device/inum pair to find the incore inode, and return a pointer
85 * to it. If it is in core, return it, even if it is locked.
88 hpfs_hphashlookup(cdev_t dev
, lsn_t ino
)
92 lwkt_gettoken(&hpfs_hphash_token
);
93 for (hp
= HPNOHASH(dev
, ino
)->lh_first
; hp
; hp
= hp
->h_hash
.le_next
) {
94 if (ino
== hp
->h_no
&& dev
== hp
->h_dev
)
97 lwkt_reltoken(&hpfs_hphash_token
);
103 hpfs_hphashvget(cdev_t dev
, lsn_t ino
)
108 lwkt_gettoken(&hpfs_hphash_token
);
110 for (hp
= HPNOHASH(dev
, ino
)->lh_first
; hp
; hp
= hp
->h_hash
.le_next
) {
111 if (ino
!= hp
->h_no
|| dev
!= hp
->h_dev
)
115 if (vget(vp
, LK_EXCLUSIVE
))
118 * We must check to see if the inode has been ripped
119 * out from under us after blocking.
121 for (hp
= HPNOHASH(dev
, ino
)->lh_first
; hp
; hp
= hp
->h_hash
.le_next
) {
122 if (ino
== hp
->h_no
&& dev
== hp
->h_dev
)
125 if (hp
== NULL
|| vp
!= HPTOV(hp
)) {
131 * Or if the vget fails (due to a race)
133 lwkt_reltoken(&hpfs_hphash_token
);
136 lwkt_reltoken(&hpfs_hphash_token
);
141 * Insert the hpfsnode into the hash table.
144 hpfs_hphashins(struct hpfsnode
*hp
)
146 struct hphashhead
*hpp
;
148 lwkt_gettoken(&hpfs_hphash_token
);
149 hpp
= HPNOHASH(hp
->h_dev
, hp
->h_no
);
150 hp
->h_flag
|= H_HASHED
;
151 LIST_INSERT_HEAD(hpp
, hp
, h_hash
);
152 lwkt_reltoken(&hpfs_hphash_token
);
156 * Remove the inode from the hash table.
159 hpfs_hphashrem(struct hpfsnode
*hp
)
161 lwkt_gettoken(&hpfs_hphash_token
);
162 if (hp
->h_flag
& H_HASHED
) {
163 hp
->h_flag
&= ~H_HASHED
;
164 LIST_REMOVE(hp
, h_hash
);
166 hp
->h_hash
.le_next
= NULL
;
167 hp
->h_hash
.le_prev
= NULL
;
170 lwkt_reltoken(&hpfs_hphash_token
);