#include <sys/lock.h>
#include <sys/time.h>
-/* #include <kern/sched_prim.h> */
-/* #include <sys/unix_defs.h> */
-
-extern struct simplelock afs_rxglobal_lock;
+#include <sys/mutex.h>
+#include <sys/vnode.h>
+#if defined(AFS_FBSD80_ENV)
+#include <sys/priv.h>
+#endif
/*
* Time related macros
#define osi_Time() time_second
#define afs_hz hz
-#define PAGESIZE 8192
-
-#define AFS_UCRED ucred
-#define AFS_PROC struct proc
+typedef struct ucred afs_ucred_t;
+typedef struct proc afs_proc_t;
#define afs_bufferpages bufpages
#ifndef iodone
#define iodone biodone
#endif
-#define osi_vnhold(avc,r) do { VN_HOLD((struct vnode *)(avc)); } while (0)
+#define VSUID S_ISUID
+#define VSGID S_ISGID
+
+#define osi_vnhold(avc,r) vref(AFSTOV(avc))
+
+#define vType(vc) AFSTOV(vc)->v_type
+#define vSetVfsp(vc, vfsp) AFSTOV(vc)->v_mount = (vfsp)
+#define vSetType(vc, type) AFSTOV(vc)->v_type = (type)
+#if defined(AFS_FBSD60_ENV) && defined(KERNEL)
+extern struct vop_vector afs_vnodeops;
+# define IsAfsVnode(v) ((v)->v_op == &afs_vnodeops)
+#else
+extern int (**afs_vnodeop_p) ();
+# define IsAfsVnode(v) ((v)->v_op == afs_vnodeop_p)
+#endif
+#define SetAfsVnode(v) /* nothing; done in getnewvnode() */
+
+#if defined(AFS_FBSD80_ENV)
+#define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
+ vinvalbuf((vp), (flags), (slpflag), (slptimeo))
+#else
+#define osi_vinvalbuf(vp, flags, slpflag, slptimeo) \
+ vinvalbuf((vp), (flags), (curthread), (slpflag), (slptimeo))
+#define osi_curproc() (curthread)
+#endif
#undef gop_lookupname
#define gop_lookupname osi_lookupname
-#undef afs_suser
+#undef gop_lookupname_user
+#define gop_lookupname_user osi_lookupname
#define afs_strcat(s1, s2) strcat((s1), (s2))
-#ifdef KERNEL
-extern struct lock afs_global_lock;
+/* malloc */
+extern void *osi_fbsd_alloc(size_t size, int dropglobal);
+extern void osi_fbsd_free(void *p);
+
+#undef afs_osi_Alloc_NoSleep
+#define afs_osi_Alloc_NoSleep(size) osi_fbsd_alloc((size), 0)
+
+#ifdef AFS_FBSD80_ENV
+#define VN_RELE(vp) \
+ do { \
+ vrele(vp); \
+ } while(0);
+#else
+#define VN_RELE(vp) vrele(vp)
+#endif
+#define VN_HOLD(vp) VREF(vp)
+
+#undef afs_suser
+#if defined(AFS_FBSD80_ENV)
+/* OpenAFS-specific privileges negotiated for FreeBSD, thanks due to
+ * Ben Kaduk */
+#define osi_suser_client_settings(x) (!priv_check(curthread, PRIV_AFS_ADMIN))
+#define osi_suser_afs_daemon(x) (!priv_check(curthread, PRIV_AFS_DAEMON))
+#define afs_suser(x) (osi_suser_client_settings((x)) && osi_suser_afs_daemon((x)))
+#else
+#define afs_suser(x) (!suser(curthread))
+#endif
-#if defined(AFS_FBSD50_ENV)
+#undef osi_getpid
#define VT_AFS "afs"
#define VROOT VV_ROOT
#define v_flag v_vflag
#define osi_curcred() (curthread->td_ucred)
-#define afs_suser() (!suser(curthread))
+#define osi_curproc() (curthread)
+#define osi_getpid() (curthread->td_proc->p_pid)
#define simple_lock(x) mtx_lock(x)
#define simple_unlock(x) mtx_unlock(x)
#define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(cred),(aresid), curthread)
+extern struct mtx afs_global_mtx;
extern struct thread *afs_global_owner;
#define AFS_GLOCK() \
do { \
- osi_Assert(curthread); \
- lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curthread); \
- osi_Assert(afs_global_owner == 0); \
- afs_global_owner = curthread; \
+ mtx_assert(&afs_global_mtx, (MA_NOTOWNED)); \
+ mtx_lock(&afs_global_mtx); \
+ mtx_assert(&afs_global_mtx, (MA_OWNED|MA_NOTRECURSED)); \
} while (0)
#define AFS_GUNLOCK() \
do { \
- osi_Assert(curthread); \
- osi_Assert(afs_global_owner == curthread); \
- afs_global_owner = 0; \
- lockmgr(&afs_global_lock, LK_RELEASE, 0, curthread); \
- } while(0)
-#define ISAFS_GLOCK() (afs_global_owner == curthread && curthread)
-
-#else /* FBSD50 */
-
-#define osi_curcred() (curproc->p_cred->pc_ucred)
-#define getpid() curproc
-#define gop_rdwr(rw,gp,base,len,offset,segflg,unit,cred,aresid) \
- vn_rdwr((rw),(gp),(base),(len),(offset),(segflg),(unit),(cred),(aresid), curproc)
-extern struct proc *afs_global_owner;
-#define AFS_GLOCK() \
- do { \
- osi_Assert(curproc); \
- lockmgr(&afs_global_lock, LK_EXCLUSIVE, 0, curproc); \
- osi_Assert(afs_global_owner == 0); \
- afs_global_owner = curproc; \
+ mtx_assert(&afs_global_mtx, (MA_OWNED|MA_NOTRECURSED)); \
+ mtx_unlock(&afs_global_mtx); \
} while (0)
-#define AFS_GUNLOCK() \
+#define ISAFS_GLOCK() (mtx_owned(&afs_global_mtx))
+# if defined(AFS_FBSD80_ENV) && defined(WITNESS)
+# define osi_InitGlock() \
+ do { \
+ memset(&afs_global_mtx, 0, sizeof(struct mtx)); \
+ mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
+ afs_global_owner = 0; \
+ } while(0)
+# else
+# define osi_InitGlock() \
do { \
- osi_Assert(curproc); \
- osi_Assert(afs_global_owner == curproc); \
- afs_global_owner = 0; \
- lockmgr(&afs_global_lock, LK_RELEASE, 0, curproc); \
- } while(0)
-#define ISAFS_GLOCK() (afs_global_owner == curproc && curproc)
-#endif /* FBSD50 */
-
-#define AFS_RXGLOCK()
-#define AFS_RXGUNLOCK()
-#define ISAFS_RXGLOCK() 1
+ mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF); \
+ afs_global_owner = 0; \
+ } while (0)
+# endif
#undef SPLVAR
#define SPLVAR int splvar
#define NETPRI splvar=splnet()
#undef USERPRI
#define USERPRI splx(splvar)
-#endif /* KERNEL */
+
+#define osi_procname(procname, size) strncpy(procname, curproc->p_comm, size)
#endif /* _OSI_MACHDEP_H_ */