This source file includes following definitions.
- LIST_HEAD
- ufs_ihashlookup
- ufs_ihashget
- ufs_ihashins
- ufs_ihashrem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/vnode.h>
38 #include <sys/malloc.h>
39 #include <sys/proc.h>
40
41 #include <ufs/ufs/quota.h>
42 #include <ufs/ufs/inode.h>
43 #include <ufs/ufs/ufs_extern.h>
44
45
46
47
48 LIST_HEAD(ihashhead, inode) *ihashtbl;
49 u_long ihash;
50 #define INOHASH(device, inum) (&ihashtbl[((device) + (inum)) & ihash])
51 struct simplelock ufs_ihash_slock;
52
53
54
55
56 void
57 ufs_ihashinit(void)
58 {
59 ihashtbl = hashinit(desiredvnodes, M_UFSMNT, M_WAITOK, &ihash);
60 simple_lock_init(&ufs_ihash_slock);
61 }
62
63
64
65
66
67 struct vnode *
68 ufs_ihashlookup(dev_t dev, ino_t inum)
69 {
70 struct inode *ip;
71
72 simple_lock(&ufs_ihash_slock);
73 LIST_FOREACH(ip, INOHASH(dev, inum), i_hash)
74 if (inum == ip->i_number && dev == ip->i_dev)
75 break;
76 simple_unlock(&ufs_ihash_slock);
77
78 if (ip)
79 return (ITOV(ip));
80
81 return (NULLVP);
82 }
83
84
85
86
87
88 struct vnode *
89 ufs_ihashget(dev_t dev, ino_t inum)
90 {
91 struct proc *p = curproc;
92 struct inode *ip;
93 struct vnode *vp;
94 loop:
95 simple_lock(&ufs_ihash_slock);
96 LIST_FOREACH(ip, INOHASH(dev, inum), i_hash) {
97 if (inum == ip->i_number && dev == ip->i_dev) {
98 vp = ITOV(ip);
99 simple_unlock(&ufs_ihash_slock);
100 if (vget(vp, LK_EXCLUSIVE, p))
101 goto loop;
102 return (vp);
103 }
104 }
105 simple_unlock(&ufs_ihash_slock);
106 return (NULL);
107 }
108
109
110
111
112 int
113 ufs_ihashins(struct inode *ip)
114 {
115 struct inode *curip;
116 struct ihashhead *ipp;
117 dev_t dev = ip->i_dev;
118 ino_t inum = ip->i_number;
119
120
121 lockmgr(&ip->i_lock, LK_EXCLUSIVE, NULL);
122
123 simple_lock(&ufs_ihash_slock);
124
125 LIST_FOREACH(curip, INOHASH(dev, inum), i_hash) {
126 if (inum == curip->i_number && dev == curip->i_dev) {
127 simple_unlock(&ufs_ihash_slock);
128 lockmgr(&ip->i_lock, LK_RELEASE, NULL);
129 return (EEXIST);
130 }
131 }
132
133 ipp = INOHASH(dev, inum);
134 LIST_INSERT_HEAD(ipp, ip, i_hash);
135 simple_unlock(&ufs_ihash_slock);
136
137 return (0);
138 }
139
140
141
142
143 void
144 ufs_ihashrem(struct inode *ip)
145 {
146 simple_lock(&ufs_ihash_slock);
147
148 if (ip->i_hash.le_prev == NULL)
149 return;
150
151 LIST_REMOVE(ip, i_hash);
152 #ifdef DIAGNOSTIC
153 ip->i_hash.le_next = NULL;
154 ip->i_hash.le_prev = NULL;
155 #endif
156 simple_unlock(&ufs_ihash_slock);
157
158 }