Commit | Line | Data |
---|---|---|
805e021f CE |
1 | /* |
2 | * Copyright 2000, International Business Machines Corporation and others. | |
3 | * All Rights Reserved. | |
4 | * | |
5 | * This software has been released under the terms of the IBM Public | |
6 | * License. For details, see the LICENSE file in the top-level source | |
7 | * directory or online at http://www.openafs.org/dl/license10.html | |
8 | */ | |
9 | ||
10 | /* | |
11 | * Implements: | |
12 | * afs_config | |
13 | * mem_getbytes | |
14 | * mem_freebytes | |
15 | * kmem_alloc | |
16 | * kmem_free | |
17 | * VN_RELE | |
18 | * VN_HOLD | |
19 | * kludge_init | |
20 | * ufdalloc | |
21 | * ufdfree | |
22 | * ffree | |
23 | * iptovp | |
24 | * dev_ialloc | |
25 | * iget | |
26 | * iput | |
27 | * commit | |
28 | * fs_simple_lock | |
29 | * fs_read_lock | |
30 | * fs_write_lock | |
31 | * fs_complex_unlock | |
32 | * ksettimer | |
33 | * | |
34 | */ | |
35 | ||
36 | #include <afsconfig.h> | |
37 | #include "afs/param.h" | |
38 | ||
39 | ||
40 | #include "sys/limits.h" | |
41 | #include "sys/types.h" | |
42 | #include "sys/user.h" | |
43 | #include "sys/vnode.h" | |
44 | #include "sys/conf.h" | |
45 | #include "sys/errno.h" | |
46 | #include "sys/device.h" | |
47 | #include "sys/vfs.h" | |
48 | #include "sys/vmount.h" | |
49 | #include "sys/gfs.h" | |
50 | #include "sys/uio.h" | |
51 | #include "sys/pri.h" | |
52 | #include "sys/priv.h" /* XXX */ | |
53 | #include "sys/lockl.h" | |
54 | #include "sys/malloc.h" | |
55 | #include <sys/syspest.h> /* to define the assert and ASSERT macros */ | |
56 | #include <sys/timer.h> /* For the timer related defines */ | |
57 | #include <sys/intr.h> /* for the serialization defines */ | |
58 | #include <sys/malloc.h> /* for the parameters to xmalloc() */ | |
59 | #include "afs/afs_osi.h" /* pick up osi_timeval_t for afs_stats.h */ | |
60 | #include "afs/afs_stats.h" | |
61 | #include "../export.h" | |
62 | ||
63 | #ifdef KOFF | |
64 | #define KOFF_PRESENT 1 | |
65 | #else | |
66 | #define KOFF_PRESENT 0 | |
67 | #endif | |
68 | ||
69 | #if !KOFF_PRESENT | |
70 | _db_trace() | |
71 | {; | |
72 | } | |
73 | ||
74 | long db_tflags = 0; | |
75 | #endif | |
76 | ||
77 | extern struct gfs afs_gfs; | |
78 | extern struct vnodeops locked_afs_gn_vnodeops; | |
79 | ||
80 | #ifdef __64BIT__ | |
81 | afs_uint64 get_toc(); | |
82 | #else | |
83 | afs_uint32 get_toc(); | |
84 | #endif | |
85 | ||
86 | #define AFS_CALLOUT_TBL_SIZE 256 | |
87 | ||
88 | #include <sys/lock_alloc.h> | |
89 | extern Simple_lock afs_callout_lock; | |
90 | ||
91 | /* | |
92 | * afs_config - handle AFS configuration requests | |
93 | * | |
94 | * Input: | |
95 | * cmd - add/delete command | |
96 | * uiop - uio vector describing any config params | |
97 | */ | |
98 | afs_config(cmd, uiop) | |
99 | struct uio *uiop; | |
100 | { | |
101 | int err; | |
102 | extern struct vnodeops *afs_ops; | |
103 | ||
104 | AFS_STATCNT(afs_config); | |
105 | ||
106 | err = 0; | |
107 | AFS_GLOCK(); | |
108 | if (cmd == CFG_INIT) { /* add AFS gfs */ | |
109 | /* | |
110 | * init any vrmix mandated kluges | |
111 | */ | |
112 | if (err = kluge_init()) | |
113 | goto out; | |
114 | /* | |
115 | * make sure that we pin everything | |
116 | */ | |
117 | if (err = pincode(afs_config)) | |
118 | goto out; | |
119 | err = gfsadd(AFS_MOUNT_AFS, &afs_gfs); | |
120 | /* | |
121 | * ok, if already installed | |
122 | */ | |
123 | if (err == EBUSY) | |
124 | err = 0; | |
125 | if (!err) { | |
126 | pin(&afs_callout_lock, sizeof(afs_callout_lock)); | |
127 | lock_alloc(&afs_callout_lock, LOCK_ALLOC_PIN, 0, 5); | |
128 | simple_lock_init(&afs_callout_lock); | |
129 | afs_ops = &locked_afs_gn_vnodeops; | |
130 | timeoutcf(AFS_CALLOUT_TBL_SIZE); | |
131 | } else { | |
132 | unpincode(afs_config); | |
133 | goto out; | |
134 | } | |
135 | if (KOFF_PRESENT) { | |
136 | extern void *db_syms[]; | |
137 | extern db_nsyms; | |
138 | ||
139 | koff_addsyms(db_syms, db_nsyms); | |
140 | } | |
141 | } else if (cmd == CFG_TERM) { /* delete AFS gfs */ | |
142 | err = gfsdel(AFS_MOUNT_AFS); | |
143 | /* | |
144 | * ok, if already deleted | |
145 | */ | |
146 | if (err == ENOENT) | |
147 | err = 0; | |
148 | #ifndef AFS_AIX51_ENV | |
149 | else | |
150 | #endif | |
151 | if (!err) { | |
152 | #ifdef AFS_AIX51_ENV | |
153 | if (err = unpin(&afs_callout_lock)) | |
154 | err = 0; | |
155 | #endif | |
156 | if (err = unpincode(afs_config)) | |
157 | err = 0; | |
158 | ||
159 | timeoutcf(-AFS_CALLOUT_TBL_SIZE); | |
160 | } | |
161 | } else /* unknown command */ | |
162 | err = EINVAL; | |
163 | ||
164 | out: | |
165 | AFS_GUNLOCK(); | |
166 | if (!err && (cmd == CFG_INIT)) | |
167 | osi_Init(); | |
168 | ||
169 | return err; | |
170 | } | |
171 | ||
172 | /* | |
173 | * The following stuff is (hopefully) temporary. | |
174 | */ | |
175 | ||
176 | ||
177 | /* | |
178 | * mem_getbytes - memory allocator | |
179 | * | |
180 | * Seems we can't make up our mind what to call these | |
181 | */ | |
182 | char * | |
183 | mem_getbytes(size) | |
184 | { | |
185 | ||
186 | return malloc(size); | |
187 | } | |
188 | ||
189 | /* | |
190 | * mem_freebytes - memory deallocator | |
191 | */ | |
192 | mem_freebytes(p, size) | |
193 | char *p; | |
194 | { | |
195 | ||
196 | free(p); | |
197 | } | |
198 | ||
199 | char * | |
200 | kmem_alloc(size) | |
201 | { | |
202 | ||
203 | return malloc(size); | |
204 | } | |
205 | ||
206 | kmem_free(p, size) | |
207 | char *p; | |
208 | { | |
209 | ||
210 | free(p); | |
211 | } | |
212 | ||
213 | VN_RELE(vp) | |
214 | struct vnode *vp; | |
215 | { | |
216 | ||
217 | VNOP_RELE(vp); | |
218 | } | |
219 | ||
220 | VN_HOLD(vp) | |
221 | struct vnode *vp; | |
222 | { | |
223 | ||
224 | VNOP_HOLD(vp); | |
225 | } | |
226 | ||
227 | /* | |
228 | * The following stuff is to account for the fact that stuff we need exported | |
229 | * from the kernel isn't, so we must be devious. | |
230 | */ | |
231 | ||
232 | int (*kluge_ufdalloc) (); | |
233 | int (*kluge_fpalloc) (); | |
234 | void *(*kluge_ufdfree) (); | |
235 | void *(*kluge_ffree) (); | |
236 | int (*kluge_iptovp) (); | |
237 | int (*kluge_dev_ialloc) (); | |
238 | int (*kluge_iget) (); | |
239 | int (*kluge_iput) (); | |
240 | int (*kluge_commit) (); | |
241 | void *(*kluge_ksettimer) (); | |
242 | void *(*kluge_fsSimpleLock) (); | |
243 | void *(*kluge_fsSimpleUnlock) (); | |
244 | void *(*kluge_fsReadLock) (); | |
245 | void *(*kluge_fsWriteLock) (); | |
246 | void *(*kluge_fsCxUnlock) (); | |
247 | ||
248 | /* | |
249 | * kernel function import list | |
250 | */ | |
251 | ||
252 | struct k_func kfuncs[] = { | |
253 | {(void *(**)())&kluge_ufdalloc, ".ufdalloc"}, | |
254 | {(void *(**)())&kluge_fpalloc, ".fpalloc"}, | |
255 | {&kluge_ufdfree, ".ufdfree"}, | |
256 | {&kluge_ffree, ".ffree"}, | |
257 | {(void *(**)())&kluge_iptovp, ".iptovp"}, | |
258 | {(void *(**)())&kluge_dev_ialloc, ".dev_ialloc"}, | |
259 | {(void *(**)())&kluge_iget, ".iget"}, | |
260 | {(void *(**)())&kluge_iput, ".iput"}, | |
261 | {(void *(**)())&kluge_commit, ".commit"}, | |
262 | {&kluge_ksettimer, ".ksettimer"}, | |
263 | #ifdef _FSDEBUG | |
264 | {&kluge_fsSimpleLock, ".fs_simple_lock"}, | |
265 | {&kluge_fsSimpleUnlock, ".fs_simple_unlock"}, | |
266 | {&kluge_fsReadLock, ".fs_read_lock"}, | |
267 | {&kluge_fsWriteLock, ".fs_write_lock"}, | |
268 | {&kluge_fsCxUnlock, ".fs_complex_unlock"}, | |
269 | #endif | |
270 | {0, 0}, | |
271 | }; | |
272 | ||
273 | void *vnodefops; /* dummy vnodeops */ | |
274 | struct ifnet *ifnet; | |
275 | Simple_lock jfs_icache_lock; | |
276 | Simple_lock proc_tbl_lock; | |
277 | ||
278 | /* | |
279 | * kernel variable import list | |
280 | */ | |
281 | struct k_var kvars[] = { | |
282 | {(void *)&vnodefops, "vnodefops"}, | |
283 | {(void *)&ifnet, "ifnet"}, | |
284 | {(void *)&jfs_icache_lock, "jfs_icache_lock"}, | |
285 | #ifndef AFS_AIX51_ENV | |
286 | {(void *)&proc_tbl_lock, "proc_tbl_lock"}, | |
287 | #endif | |
288 | {0, 0}, | |
289 | }; | |
290 | ||
291 | /* | |
292 | * kluge_init - initialise the kernel imports kluge | |
293 | */ | |
294 | kluge_init() | |
295 | { | |
296 | struct k_func *kf; | |
297 | struct k_var *kv; | |
298 | #ifdef __64BIT__ | |
299 | afs_uint64 toc; | |
300 | #else | |
301 | afs_uint32 toc; | |
302 | #endif | |
303 | int err = 0; | |
304 | ||
305 | toc = get_toc(); | |
306 | for (kf = kfuncs; !err && kf->name; ++kf) { | |
307 | err = import_kfunc(kf); | |
308 | } | |
309 | for (kv = kvars; !err && kv->name; ++kv) { | |
310 | err = import_kvar(kv, toc); | |
311 | } | |
312 | ||
313 | return err; | |
314 | } | |
315 | ||
316 | ufdalloc(i, fdp) | |
317 | int *fdp; | |
318 | { | |
319 | ||
320 | return (*kluge_ufdalloc) (i, fdp); | |
321 | } | |
322 | ||
323 | fpalloc(vp, flag, type, ops, fpp) | |
324 | struct vnode *vp; | |
325 | struct fileops *ops; | |
326 | struct file **fpp; | |
327 | { | |
328 | ||
329 | return (*kluge_fpalloc) (vp, flag, type, ops, fpp); | |
330 | } | |
331 | ||
332 | void | |
333 | ufdfree(fd) | |
334 | { | |
335 | ||
336 | (void)(*kluge_ufdfree) (fd); | |
337 | } | |
338 | ||
339 | void | |
340 | ffree(fp) | |
341 | struct file *fp; | |
342 | { | |
343 | ||
344 | (void)(*kluge_ffree) (fp); | |
345 | } | |
346 | ||
347 | iptovp(vfsp, ip, vpp) | |
348 | struct vfs *vfsp; | |
349 | struct inode *ip, **vpp; | |
350 | { | |
351 | ||
352 | return (*kluge_iptovp) (vfsp, ip, vpp); | |
353 | } | |
354 | ||
355 | dev_ialloc(pip, ino, mode, vfsp, ipp) | |
356 | struct inode *pip; | |
357 | ino_t ino; | |
358 | mode_t mode; | |
359 | struct vfs *vfsp; | |
360 | struct inode **ipp; | |
361 | { | |
362 | ||
363 | return (*kluge_dev_ialloc) (pip, ino, mode, vfsp, ipp); | |
364 | ||
365 | } | |
366 | ||
367 | iget(dev, ino, ipp, doscan, vfsp) | |
368 | dev_t dev; | |
369 | ino_t ino; | |
370 | #ifdef __64BIT__ | |
371 | afs_size_t doscan; | |
372 | #endif | |
373 | struct vfs *vfsp; | |
374 | struct inode **ipp; | |
375 | { | |
376 | #ifdef __64BIT__ | |
377 | afs_int64 dummy[10]; | |
378 | dummy[0] = doscan; | |
379 | ||
380 | return (*kluge_iget) (dev, ino, ipp, (afs_size_t) doscan, vfsp, &dummy); | |
381 | #else | |
382 | return (*kluge_iget) (dev, ino, ipp, doscan, vfsp); | |
383 | #endif | |
384 | } | |
385 | ||
386 | iput(ip, vfsp) | |
387 | struct vfs *vfsp; | |
388 | struct inode *ip; | |
389 | { | |
390 | return (*kluge_iput) (ip, vfsp); | |
391 | } | |
392 | ||
393 | commit(n, i0, i1, i2) | |
394 | struct inode *i0, *i1, *i2; | |
395 | { | |
396 | ||
397 | return (*kluge_commit) (n, i0, i1, i2); | |
398 | } | |
399 | ||
400 | ||
401 | #ifdef _FSDEBUG | |
402 | fs_simple_lock(void *lp, int type) | |
403 | { | |
404 | return (*kluge_fsSimpleLock) (lp, type); | |
405 | } | |
406 | ||
407 | fs_simple_unlock(void *lp, int type) | |
408 | { | |
409 | return (*kluge_fsSimpleUnlock) (lp, type); | |
410 | } | |
411 | ||
412 | fs_read_lock(complex_lock_t lp, int type) | |
413 | { | |
414 | return (*kluge_fsReadLock) (lp, type); | |
415 | } | |
416 | ||
417 | fs_write_lock(complex_lock_t lp, int type) | |
418 | { | |
419 | return (*kluge_fsWriteLock) (lp, type); | |
420 | } | |
421 | ||
422 | fs_complex_unlock(complex_lock_t lp, int type) | |
423 | { | |
424 | return (*kluge_fsCxUnlock) (lp, type); | |
425 | } | |
426 | #endif |