OpenAFS
OpenAFS distributed network file system
/cygdrive/c/src/openafs/openafs.git/repo/src/afs/OBSD/osi_machdep.h
00001 /*
00002  * Copyright 2000, International Business Machines Corporation and others.
00003  * All Rights Reserved.
00004  *
00005  * This software has been released under the terms of the IBM Public
00006  * License.  For details, see the LICENSE file in the top-level source
00007  * directory or online at http://www.openafs.org/dl/license10.html
00008  */
00009 
00010 /*
00011  *
00012  * OpenBSD OSI header file. Extends afs_osi.h.
00013  *
00014  * afs_osi.h includes this file, which is the only way this file should
00015  * be included in a source file. This file can redefine macros declared in
00016  * afs_osi.h.
00017  */
00018 
00019 /* $Id$ */
00020 
00021 #ifndef _OSI_MACHDEP_H_
00022 #define _OSI_MACHDEP_H_
00023 
00024 #include <sys/lock.h>
00025 
00026 #if defined(M_IP6OPT)
00027 #define M_AFSFID        (M_IP6OPT-1)
00028 #else
00029 #define M_AFSFID        (M_TEMP-1)
00030 #endif
00031 
00032 #define M_AFSBUFHDR     (M_AFSFID-1)
00033 #define M_AFSBUFFER     (M_AFSFID-2)
00034 #define M_AFSGENERIC    (M_AFSFID-3)
00035 
00036 /* vfs */
00037 #define osi_vfs         mount
00038 #define osi_vfs_bsize   mnt_stat.f_bsize
00039 #define osi_vfs_fsid    mnt_stat.f_fsid
00040 #define vfs_bsize       mnt_stat.f_bsize
00041 #define vfs_fsid        mnt_stat.f_fsid
00042 #define vfs_vnodecovered mnt_vnodecovered
00043 #define v_vfsp          v_mount
00044 
00045 /* vnode */
00046 #define VN_HOLD(vp)     afs_vget((vp), 0)
00047 #define VN_RELE(vp)     vrele(vp)
00048 #define osi_vnhold(avc, r) afs_vget(AFSTOV(avc), 0)
00049 #define va_nodeid       va_fileid
00050 #define vnode_t         struct vnode
00051 
00052 /* uio */
00053 #define afsio_iov       uio_iov
00054 #define afsio_iovcnt    uio_iovcnt
00055 #define afsio_offset    uio_offset
00056 #define afsio_resid     uio_resid
00057 #define afsio_seg       uio_segflg
00058 #define AFS_UIOSYS      UIO_SYSSPACE
00059 #define AFS_UIOUSER     UIO_USERSPACE
00060 
00061 /* malloc */
00062 inline void afs_osi_Free(void *buf, size_t asize);
00063 inline void afs_osi_FreeStr(char *x);
00064 extern void *osi_obsd_Alloc(size_t asize, int cansleep);
00065 extern void osi_obsd_Free(void *p, size_t asize);
00066 
00067 #ifdef AFS_KALLOC
00068 #undef AFS_KALLOC
00069 #endif
00070 #define AFS_KALLOC(s) osi_obsd_Alloc((s), 1 /* cansleep */)
00071 
00072 #ifdef AFS_KFREE
00073 #undef AFS_KFREE
00074 #endif
00075 #define AFS_KFREE(p, s) (osi_obsd_Free((p), (s)))
00076 
00077 #ifdef AFS_OBSD42_ENV
00078 /* removed, live with it */
00079 #define BSD_KMALLOC(p, ptype, msize, mtype, mflags)     \
00080   (p) = malloc((msize), (mtype), (mflags))
00081 
00082 #define BSD_KFREE(p, mflags) \
00083   free((p), (mflags))
00084 #else
00085 #define BSD_KMALLOC MALLOC
00086 #define BSD_KFREE FREE
00087 #endif /* AFS_OBSD42_ENV */
00088 
00089 /* proc, cred */
00090 typedef struct proc afs_proc_t;
00091 typedef struct ucred afs_ucred_t;
00092 
00093 #define afs_suser(x)    afs_osi_suser(osi_curcred())
00094 #define getpid()        curproc
00095 #define osi_curcred()   (curproc->p_cred->pc_ucred)
00096 #define osi_curproc()   curproc
00097 #define p_rcred         p_ucred
00098 
00099 /* time */
00100 #define afs_hz          hz
00101 #define osi_GetTime(x)  microtime(x)
00102 extern time_t osi_Time();
00103 
00104 /* str */
00105 #define afs_strcasecmp(s1, s2)  strncasecmp((s1), (s2), 65535)
00106 #ifdef AFS_OBSD34_ENV
00107 #define strcpy(s1, s2)          afs_strcpy((s1), (s2))
00108 #define strcat(s1, s2)          afs_strcat((s1), (s2))
00109 #else
00110 #define afs_strcat(s1, s2)      strcat((s1), (s2))
00111 #endif
00112 
00113 /* other */
00114 #define afs_bufferpages bufpages
00115 #ifndef iodone
00116 #define iodone biodone
00117 #endif
00118 #define printk          printf  /* for RX version of xdr_* */
00119 #define setgroups       sys_setgroups
00120 #define UVM
00121 
00122 /* This is not always in scope yet */
00123 struct vcache;
00124 
00125 extern int afs_obsd_lookupname(char *fnamep, enum uio_seg segflg,
00126                                int followlink, struct vnode **compvpp);
00127 extern void afs_obsd_getnewvnode(struct vcache *tvc);
00128 extern void *afs_obsd_Alloc(size_t asize);
00129 extern void afs_obsd_Free(void *p, size_t asize);
00130 extern int afs_vget();
00131 
00132 #undef gop_lookupname
00133 #define gop_lookupname(fnamep, segflg, followlink, compvpp) \
00134         afs_obsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
00135 
00136 #undef gop_lookupname_user
00137 #define gop_lookupname_user(fnamep, segflg, followlink, compvpp) \
00138         afs_obsd_lookupname((fnamep), (segflg), (followlink), (compvpp))
00139 
00140 #ifdef AFS_OBSD39_ENV
00141 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i))
00142 #else
00143 #define afs_osi_lockmgr(l, f, i, p) lockmgr((l), (f), (i), (p))
00144 #endif
00145 
00146 #ifdef AFS_OBSD44_ENV
00147 /* Revert to classical, BSD locks */
00148 
00149 extern struct lock afs_global_lock;
00150 extern struct proc *afs_global_owner;
00151 
00152 # ifdef AFS_GLOBAL_SUNLOCK
00153 
00154 #  if defined(LOCKDEBUG)
00155 
00156 #   define AFS_GLOCK() \
00157   do { \
00158   _lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL, __FILE__, __LINE__); \
00159   } while(0);
00160 #   define AFS_GUNLOCK() \
00161   do { \
00162   _lockmgr(&afs_global_lock, LK_RELEASE, NULL, __FILE__, __LINE__); \
00163   } while(0);
00164 
00165 #  else /* LOCKDEBUG */
00166 
00167 #   define AFS_GLOCK() \
00168   do { \
00169   lockmgr(&afs_global_lock, LK_EXCLUSIVE, NULL); \
00170   } while(0);
00171 #   define AFS_GUNLOCK() \
00172   do { \
00173   lockmgr(&afs_global_lock, LK_RELEASE, NULL); \
00174   } while(0);
00175 #  endif /* LOCKDEBUG */
00176 #  define ISAFS_GLOCK() (lockstatus(&afs_global_lock) == LK_EXCLUSIVE)
00177 # else /* AFS_GLOBAL_SUNLOCK */
00178 extern struct lock afs_global_lock;
00179 #  define AFS_GLOCK()
00180 #  define AFS_GUNLOCK()
00181 #  define AFS_ASSERT_GLOCK()
00182 #  define ISAFS_GLOCK() 1
00183 # endif
00184 
00185 #else /* AFS_OBSD44_ENV */
00186 /* I don't see doing locks this way for older kernels, either,
00187  * but, smart folks wrote this
00188  */
00189 #define AFS_GLOCK() AFS_GLOCKP(curproc)
00190 #define AFS_GUNLOCK() AFS_GUNLOCKP(curproc)
00191 # ifdef AFS_GLOBAL_SUNLOCK
00192 extern struct proc *afs_global_owner;
00193 extern struct lock afs_global_lock;
00194 #  define AFS_GLOCKP(p) \
00195     do { \
00196         osi_Assert(p); \
00197         afs_osi_lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, (p)); \
00198         osi_Assert(afs_global_owner == NULL); \
00199         afs_global_owner = (p); \
00200     } while (0)
00201 #  define AFS_GUNLOCKP(p) \
00202     do { \
00203         osi_Assert(p); \
00204         osi_Assert(afs_global_owner == (p)); \
00205         afs_global_owner = NULL; \
00206         afs_osi_lockmgr(&afs_global_lock, LK_RELEASE, 0, (p)); \
00207     } while(0)
00208 #  define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
00209 # else /* AFS_GLOBAL_SUNLOCK */
00210 extern struct lock afs_global_lock;
00211 #  define AFS_GLOCKP(p)
00212 #  define AFS_GUNLOCKP(p)
00213 #  define AFS_ASSERT_GLOCK()
00214 #  define ISAFS_GLOCK() 1
00215 # endif
00216 
00217 #endif /* AFS_OBSD44_ENV */
00218 
00219 #undef SPLVAR
00220 #define SPLVAR int splvar
00221 #undef NETPRI
00222 #define NETPRI splvar=splnet()
00223 #undef USERPRI
00224 #define USERPRI splx(splvar)
00225 
00226 #define osi_InitGlock() \
00227     do { \
00228         lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0); \
00229         afs_global_owner = 0; \
00230     } while (0)
00231 
00232 /* vnodes */
00233 extern int (**afs_vnodeop_p) ();
00234 #define vType(vc)               AFSTOV(vc)->v_type
00235 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
00236 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
00237 #define IsAfsVnode(v)      ((v)->v_op == afs_vnodeop_p)
00238 #define SetAfsVnode(v)     /* nothing; done in getnewvnode() */
00239 
00240 #define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
00241 
00242 #endif /* _OSI_MACHDEP_H_ */
 All Data Structures Files Functions Variables