]>
git.saurik.com Git - apple/xnu.git/blob - bsd/ufs/ufs/ufs_ihash.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
58 #include <sys/param.h>
59 #include <sys/systm.h>
60 #include <sys/vnode.h>
61 #include <sys/malloc.h>
64 #include <ufs/ufs/quota.h>
65 #include <ufs/ufs/inode.h>
66 #include <ufs/ufs/ufs_extern.h>
69 * Structures associated with inode cacheing.
71 LIST_HEAD(ihashhead
, inode
) *ihashtbl
;
72 u_long ihash
; /* size of hash table - 1 */
73 #define INOHASH(device, inum) (&ihashtbl[((device) + (inum)) & ihash])
74 struct slock ufs_ihash_slock
;
77 * Initialize inode hash table.
83 ihashtbl
= hashinit(desiredvnodes
, M_UFSMNT
, &ihash
);
84 simple_lock_init(&ufs_ihash_slock
);
88 * Use the device/inum pair to find the incore inode, and return a pointer
89 * to it. If it is in core, return it, even if it is locked.
92 ufs_ihashlookup(dev
, inum
)
98 simple_lock(&ufs_ihash_slock
);
99 for (ip
= INOHASH(dev
, inum
)->lh_first
; ip
; ip
= ip
->i_hash
.le_next
)
100 if (inum
== ip
->i_number
&& dev
== ip
->i_dev
)
102 simple_unlock(&ufs_ihash_slock
);
110 * Use the device/inum pair to find the incore inode, and return a pointer
111 * to it. If it is in core, but locked, wait for it.
114 ufs_ihashget(dev
, inum
)
118 struct proc
*p
= current_proc(); /* XXX */
123 simple_lock(&ufs_ihash_slock
);
124 for (ip
= INOHASH(dev
, inum
)->lh_first
; ip
; ip
= ip
->i_hash
.le_next
) {
125 if (inum
== ip
->i_number
&& dev
== ip
->i_dev
) {
127 simple_lock(&vp
->v_interlock
);
128 simple_unlock(&ufs_ihash_slock
);
129 if (vget(vp
, LK_EXCLUSIVE
| LK_INTERLOCK
, p
))
134 simple_unlock(&ufs_ihash_slock
);
139 * Insert the inode into the hash table, and return it locked.
145 struct proc
*p
= current_proc(); /* XXX */
146 struct ihashhead
*ipp
;
148 /* lock the inode, then put it on the appropriate hash list */
149 lockmgr(&ip
->i_lock
, LK_EXCLUSIVE
, (struct slock
*)0, p
);
151 simple_lock(&ufs_ihash_slock
);
152 ipp
= INOHASH(ip
->i_dev
, ip
->i_number
);
153 LIST_INSERT_HEAD(ipp
, ip
, i_hash
);
154 simple_unlock(&ufs_ihash_slock
);
158 * Remove the inode from the hash table.
166 simple_lock(&ufs_ihash_slock
);
167 LIST_REMOVE(ip
, i_hash
);
169 ip
->i_hash
.le_next
= NULL
;
170 ip
->i_hash
.le_prev
= NULL
;
172 simple_unlock(&ufs_ihash_slock
);