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