FBSD: remove vestiges of Giant
[openafs.git] / src / afs / FBSD / osi_misc.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  * osi_misc.c
12  *
13  */
14
15 #include <afsconfig.h>
16 #include "afs/param.h"
17
18
19 #include "afs/sysincludes.h"    /* Standard vendor system headers */
20 #include "afsincludes.h"        /* Afs-based standard headers */
21 #include <sys/namei.h>
22
23 int
24 osi_lookupname(char *aname, enum uio_seg seg, int followlink,
25                struct vnode **vpp)
26 {
27     struct nameidata n;
28     int flags, error, glocked;
29
30     glocked = ISAFS_GLOCK();
31     if (glocked)
32         AFS_GUNLOCK();
33
34     flags = 0;
35     flags = LOCKLEAF;
36     if (followlink)
37         flags |= FOLLOW;
38     else
39         flags |= NOFOLLOW;
40     flags |= MPSAFE; /* namei must take Giant if needed */
41     NDINIT(&n, LOOKUP, flags, seg, aname, curthread);
42     if ((error = namei(&n)) != 0) {
43         if (glocked)
44             AFS_GLOCK();
45         return error;
46     }
47     *vpp = n.ni_vp;
48     /* XXX should we do this?  Usually NOT (matt) */
49 #if defined(AFS_FBSD80_ENV)
50     /*VOP_UNLOCK(n.ni_vp, 0);*/
51 #else
52     VOP_UNLOCK(n.ni_vp, 0, curthread);
53 #endif
54     NDFREE(&n, NDF_ONLY_PNBUF);
55     if (glocked)
56         AFS_GLOCK();
57     return 0;
58 }
59
60 /*
61  * does not implement security features of kern_time.c:settime()
62  */
63 void
64 afs_osi_SetTime(osi_timeval_t * atv)
65 {
66     printf("afs attempted to set clock; use \"afsd -nosettime\"\n");
67 }
68
69 /*
70  * Replace all of the bogus special-purpose memory allocators...
71  */
72 void *
73 osi_fbsd_alloc(size_t size, int dropglobal)
74 {
75         void *rv;
76         int glocked;
77
78         if (dropglobal) {
79             glocked = ISAFS_GLOCK();
80             if (glocked)
81                 AFS_GUNLOCK();
82             rv = malloc(size, M_AFS, M_WAITOK);
83             if (glocked)
84                 AFS_GLOCK();
85         } else
86             rv = malloc(size, M_AFS, M_NOWAIT);
87
88         return (rv);
89 }
90
91 void
92 osi_fbsd_free(void *p)
93 {
94        free(p, M_AFS);
95 }