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