Solaris: prevent AFS umount while busy
[openafs.git] / src / afs / SOLARIS / osi_machdep.h
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  * Solaris OSI header file. Extends afs_osi.h.
12  *
13  * afs_osi.h includes this file, which is the only way this file should
14  * be included in a source file. This file can redefine macros declared in
15  * afs_osi.h.
16  */
17
18 #ifndef _OSI_MACHDEP_H_
19 #define _OSI_MACHDEP_H_
20
21 #ifdef AFS_SUN57_64BIT_ENV
22 #include <sys/model.h>          /* for get_udatamodel() */
23 #endif
24
25 #define getpid()                curproc->p_pid
26
27 /**
28   * The location of the NFSSRV module
29   * Used in osi_vfsops.c when checking to see if the nfssrv module is
30   * loaded
31   */
32 #define NFSSRV          "/kernel/misc/nfssrv"
33 #define NFSSRV_V9       "/kernel/misc/sparcv9/nfssrv"
34
35 typedef struct cred afs_ucred_t;
36 typedef struct proc afs_proc_t;
37
38 /* 
39  * Time related macros
40  */
41 #define afs_hz      hz
42 #ifdef AFS_SUN59_ENV
43 #define osi_Time() local_osi_Time()
44 extern void gethrestime(timespec_t *);
45 static int
46 local_osi_Time()
47 {
48     timespec_t start;
49     gethrestime(&start);
50     return start.tv_sec;
51 }
52 #else
53 #define osi_Time() (hrestime.tv_sec)
54 #endif
55
56 #undef afs_osi_Alloc_NoSleep
57 extern void *afs_osi_Alloc_NoSleep(size_t size);
58
59 #ifdef AFS_SUN58_ENV
60 # define osi_vnhold(avc, r)  do {    \
61     struct vnode *vp = AFSTOV(avc); \
62     uint_t prevcount;               \
63                                     \
64     mutex_enter(&vp->v_lock);       \
65     prevcount = vp->v_count++;      \
66     mutex_exit(&vp->v_lock);        \
67                                     \
68     if (prevcount == 0) {           \
69         VFS_HOLD(afs_globalVFS);    \
70     }                               \
71 } while(0)
72 #else /* !AFS_SUN58_ENV */
73 # define osi_vnhold(avc, r)  do { VN_HOLD(AFSTOV(avc)); } while(0)
74 #endif /* !AFS_SUN58_ENV */
75
76 #define gop_rdwr(rw,gp,base,len,offset,segflg,ioflag,ulimit,cr,aresid) \
77   vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(ioflag),(ulimit),(cr),(aresid))
78 #define gop_lookupname(fnamep,segflg,followlink,compvpp) \
79   lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
80 #define gop_lookupname_user(fnamep,segflg,followlink,compvpp) \
81   lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
82
83
84 #if defined(AFS_SUN510_ENV)
85 #define afs_suser(x)        afs_osi_suser(x)
86 #else
87 #define afs_suser(x)        suser(x)
88 #endif
89
90 /*
91  * Global lock support. 
92  */
93 #include <sys/mutex.h>
94 extern kmutex_t afs_global_lock;
95
96 #define AFS_GLOCK()     mutex_enter(&afs_global_lock);
97 #define AFS_GUNLOCK()   mutex_exit(&afs_global_lock);
98 #define ISAFS_GLOCK()   mutex_owned(&afs_global_lock)
99 #define osi_InitGlock() \
100         mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
101 #endif
102
103
104 /* Associate the Berkley signal equivalent lock types to System V's */
105 #define LOCK_SH 1               /* F_RDLCK */
106 #define LOCK_EX 2               /* F_WRLCK */
107 #define LOCK_NB 4               /* XXX */
108 #define LOCK_UN 8               /* F_UNLCK */
109
110 #ifndef IO_APPEND
111 #define IO_APPEND       FAPPEND
112 #endif
113
114 #ifndef IO_SYNC
115 #define IO_SYNC         FSYNC
116 #endif
117
118 #if     defined(AFS_SUN56_ENV)
119 /*
120 ** Macro returns 1 if file is larger than 2GB; else returns 0 
121 */
122 #undef AfsLargeFileUio
123 #define AfsLargeFileUio(uio)       ( (uio)->_uio_offset._p._u ? 1 : 0 )
124 #undef AfsLargeFileSize
125 #define AfsLargeFileSize(pos, off) ( ((offset_t)(pos)+(offset_t)(off) > (offset_t)0x7fffffff)?1:0)
126 #endif
127
128 #if defined(AFS_SUN510_ENV)
129 #include "h/sunddi.h"
130 extern ddi_taskq_t *afs_taskq;
131 extern krwlock_t afsifinfo_lock;
132
133 /* this should be in rx/SOLARIS/rx_knet.c accessed via accessor functions,
134    eventually */
135 #include "net/if.h"
136 /* Global interface info struct */
137 struct afs_ifinfo {
138   char        ifname[LIFNAMSIZ];
139   ipaddr_t    ipaddr;
140   ipaddr_t    netmask;
141   uint_t      mtu;
142   uint64_t    flags;
143   int         metric;
144   ipaddr_t    dstaddr;
145 };
146
147 #define osi_procname(procname, size) strncpy(procname, PTOU(ttoproc(curthread))->u_comm, size)
148
149 #endif /* _OSI_MACHDEP_H_ */