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