]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
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. | |
11 | * | |
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 | |
18 | * under the License. | |
19 | * | |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
23 | /* | |
24 | * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995 | |
25 | * The Regents of the University of California. All rights reserved. | |
26 | * | |
27 | * Redistribution and use in source and binary forms, with or without | |
28 | * modification, are permitted provided that the following conditions | |
29 | * are met: | |
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. | |
42 | * | |
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 | |
53 | * SUCH DAMAGE. | |
54 | * | |
55 | * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95 | |
56 | */ | |
57 | ||
58 | #include <sys/param.h> | |
59 | #include <sys/systm.h> | |
60 | #include <sys/vnode.h> | |
61 | #include <sys/malloc.h> | |
62 | #include <sys/proc.h> | |
63 | ||
64 | #include <ufs/ufs/quota.h> | |
65 | #include <ufs/ufs/inode.h> | |
66 | #include <ufs/ufs/ufs_extern.h> | |
67 | ||
68 | /* | |
69 | * Structures associated with inode cacheing. | |
70 | */ | |
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; | |
75 | ||
76 | /* | |
77 | * Initialize inode hash table. | |
78 | */ | |
79 | void | |
80 | ufs_ihashinit() | |
81 | { | |
82 | ||
83 | ihashtbl = hashinit(desiredvnodes, M_UFSMNT, &ihash); | |
84 | simple_lock_init(&ufs_ihash_slock); | |
85 | } | |
86 | ||
87 | /* | |
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. | |
90 | */ | |
91 | struct vnode * | |
92 | ufs_ihashlookup(dev, inum) | |
93 | dev_t dev; | |
94 | ino_t inum; | |
95 | { | |
96 | struct inode *ip; | |
97 | ||
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) | |
101 | break; | |
102 | simple_unlock(&ufs_ihash_slock); | |
103 | ||
104 | if (ip) | |
105 | return (ITOV(ip)); | |
106 | return (NULLVP); | |
107 | } | |
108 | ||
109 | /* | |
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. | |
112 | */ | |
113 | struct vnode * | |
114 | ufs_ihashget(dev, inum) | |
115 | dev_t dev; | |
116 | ino_t inum; | |
117 | { | |
118 | struct proc *p = current_proc(); /* XXX */ | |
119 | struct inode *ip; | |
120 | struct vnode *vp; | |
121 | ||
122 | loop: | |
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) { | |
126 | vp = ITOV(ip); | |
7b1edb79 A |
127 | if (ISSET(ip->i_flag, IN_ALLOC)) { |
128 | /* | |
129 | * inode is being created. Wait for it | |
130 | * to finish creation | |
131 | */ | |
132 | SET(ip->i_flag, IN_WALLOC); | |
133 | simple_unlock(&ufs_ihash_slock); | |
134 | (void)tsleep((caddr_t)ip, PINOD, "ufs_ihashget", 0); | |
135 | goto loop; | |
136 | } | |
137 | ||
138 | if (ISSET(ip->i_flag, IN_TRANSIT)) { | |
139 | /* | |
140 | * inode is getting reclaimed wait till | |
0b4e3aa0 A |
141 | * the operation is complete and return |
142 | * error | |
143 | */ | |
7b1edb79 | 144 | SET(ip->i_flag, IN_WTRANSIT); |
0b4e3aa0 | 145 | simple_unlock(&ufs_ihash_slock); |
7b1edb79 | 146 | (void)tsleep((caddr_t)ip, PINOD, "ufs_ihashget1", 0); |
0b4e3aa0 A |
147 | goto loop; |
148 | } | |
1c79356b A |
149 | simple_lock(&vp->v_interlock); |
150 | simple_unlock(&ufs_ihash_slock); | |
151 | if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p)) | |
152 | goto loop; | |
153 | return (vp); | |
154 | } | |
155 | } | |
156 | simple_unlock(&ufs_ihash_slock); | |
157 | return (NULL); | |
158 | } | |
159 | ||
160 | /* | |
7b1edb79 A |
161 | * Insert the inode into the hash table, |
162 | * inode is assumed to be locked by the caller | |
1c79356b A |
163 | */ |
164 | void | |
165 | ufs_ihashins(ip) | |
166 | struct inode *ip; | |
167 | { | |
7b1edb79 | 168 | struct proc *p = current_proc(); |
1c79356b A |
169 | struct ihashhead *ipp; |
170 | ||
1c79356b A |
171 | simple_lock(&ufs_ihash_slock); |
172 | ipp = INOHASH(ip->i_dev, ip->i_number); | |
173 | LIST_INSERT_HEAD(ipp, ip, i_hash); | |
174 | simple_unlock(&ufs_ihash_slock); | |
175 | } | |
176 | ||
177 | /* | |
178 | * Remove the inode from the hash table. | |
179 | */ | |
180 | void | |
181 | ufs_ihashrem(ip) | |
182 | struct inode *ip; | |
183 | { | |
184 | struct inode *iq; | |
185 | ||
186 | simple_lock(&ufs_ihash_slock); | |
187 | LIST_REMOVE(ip, i_hash); | |
188 | #if DIAGNOSTIC | |
189 | ip->i_hash.le_next = NULL; | |
190 | ip->i_hash.le_prev = NULL; | |
191 | #endif | |
192 | simple_unlock(&ufs_ihash_slock); | |
193 | } |