linux-lock-tracking-20070208
[openafs.git] / src / afs / afs_osi.h
index 99ce313..c66ece8 100644 (file)
@@ -41,7 +41,6 @@ struct osi_socket {
 
 struct osi_stat {
     afs_int32 size;            /* file size in bytes */
-    afs_int32 blksize;         /* optimal transfer size in bytes */
     afs_int32 mtime;           /* modification date */
     afs_int32 atime;           /* access time */
 };
@@ -123,6 +122,14 @@ struct afs_osi_WaitHandle {
 /*
  * Vnode related macros
  */
+#if defined(AFS_DARWIN80_ENV)
+#define vType(vc)               vnode_vtype(AFSTOV(vc))
+#define vSetVfsp(vc, vfsp)      
+#define vSetType(vc, type)      (vc)->m.Type = (type)
+extern int afs_vfs_typenum;
+#define SetAfsVnode(vn)         /* nothing; done in getnewvnode() */
+#define IsAfsVnode(v) (vfs_typenum(vnode_mount((v))) == afs_vfs_typenum)
+#else
 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_LINUX22_ENV)
 #define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
 #define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
@@ -132,7 +139,6 @@ struct afs_osi_WaitHandle {
 #define        vSetType(vc,type)   (vc)->v.v_type = (type)
 #define        vSetVfsp(vc,vfsp)   (vc)->v.v_vfsp = (vfsp)
 #endif
-
 #if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 extern int (**afs_vnodeop_p) ();
 #define IsAfsVnode(v)      ((v)->v_op == afs_vnodeop_p)
@@ -142,6 +148,7 @@ extern struct vnodeops *afs_ops;
 #define        IsAfsVnode(v)       ((v)->v_op == afs_ops)
 #define        SetAfsVnode(v)      (v)->v_op = afs_ops
 #endif
+#endif
 
 #ifdef AFS_SGI65_ENV
 #define        gop_lookupname(fnamep,segflg,followlink,compvpp) \
@@ -180,18 +187,21 @@ extern struct vnodeops *afs_ops;
   * In 64 bit HP-UX the timeval structure has a 64 bit member.
   */
 
-
-#if defined(AFS_HPUX_ENV) || (defined(AFS_SUN57_ENV) && !defined(AFS_SUN510_ENV)) || defined(AFS_LINUX_64BIT_KERNEL) || (defined(AFS_SGI61_ENV) && defined(KERNEL) && defined(_K64U64))
+#if defined(AFS_HPUX_ENV) || defined(AFS_LINUX_64BIT_KERNEL) || (defined(AFS_SGI61_ENV) && defined(KERNEL) && defined(_K64U64))
 typedef struct {
     afs_int32 tv_sec;
     afs_int32 tv_usec;
 } osi_timeval_t;
+#elif defined(AFS_SUN57_ENV)
+typedef struct timeval32 osi_timeval_t;
 #else
 typedef struct timeval osi_timeval_t;
 #endif /* AFS_SGI61_ENV */
 
 #define osi_getpid()           getpid()
 
+#define osi_getpid()           getpid()
+
 /*
  * osi_ThreadUnique() should yield a value that can be found in ps
  * output in order to draw correspondences between ICL traces and what
@@ -202,14 +212,18 @@ typedef struct timeval osi_timeval_t;
 /* should use curthread, but 'ps' can't display it */
 #define osi_ThreadUnique()     curproc
 #else
+#ifdef AFS_LINUX_ENV
+#define osi_ThreadUnique()     (current->pid)
+#else
 #define osi_ThreadUnique()     getpid()
 #endif
+#endif
 
 
 
 #ifdef AFS_GLOBAL_SUNLOCK
 #define AFS_ASSERT_GLOCK() \
-    (ISAFS_GLOCK() || (osi_Panic("afs global lock not held at %s:%d\n", __FILE__, __LINE__), 0))
+    do { if (!ISAFS_GLOCK()) osi_Panic("afs global lock not held at %s:%d\n", __FILE__, __LINE__); } while (0)
 #endif /* AFS_GLOBAL_SUNLOCK */
 
 #ifdef RX_ENABLE_LOCKS
@@ -272,6 +286,11 @@ typedef struct timeval osi_timeval_t;
  * and kernel space. Call these to avoid taking page faults while
  * holding the global lock.
  */
+#ifdef CAST_USER_ADDR_T
+#define __U(X) CAST_USER_ADDR_T((X))
+#else
+#define __U(X) (X)
+#endif
 #ifdef AFS_GLOBAL_SUNLOCK
 
 #define AFS_COPYIN(SRC,DST,LEN,CODE)                           \
@@ -279,7 +298,7 @@ typedef struct timeval osi_timeval_t;
            int haveGlock = ISAFS_GLOCK();                      \
            if (haveGlock)                                      \
                AFS_GUNLOCK();                                  \
-           CODE = copyin((SRC),(DST),(LEN));                   \
+           CODE = copyin(__U((SRC)),(DST),(LEN));                      \
            if (haveGlock)                                      \
                AFS_GLOCK();                                    \
        } while(0)
@@ -289,7 +308,7 @@ typedef struct timeval osi_timeval_t;
            int haveGlock = ISAFS_GLOCK();                      \
            if (haveGlock)                                      \
                AFS_GUNLOCK();                                  \
-           CODE = copyinstr((SRC),(DST),(LEN),(CNT));          \
+           CODE = copyinstr(__U((SRC)),(DST),(LEN),(CNT));             \
            if (haveGlock)                                      \
                AFS_GLOCK();                                    \
        } while(0)
@@ -299,11 +318,23 @@ typedef struct timeval osi_timeval_t;
            int haveGlock = ISAFS_GLOCK();                      \
            if (haveGlock)                                      \
                AFS_GUNLOCK();                                  \
-           CODE = copyout((SRC),(DST),(LEN));                  \
+           CODE = copyout((SRC),__U((DST)),(LEN));                     \
            if (haveGlock)                                      \
                AFS_GLOCK();                                    \
        } while(0)
 
+#if defined(AFS_DARWIN80_ENV)
+#define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
+       do {                                                    \
+           int haveGlock = ISAFS_GLOCK();                      \
+           if (haveGlock)                                      \
+               AFS_GUNLOCK();                                  \
+           uio_setrw((UIO),(RW));                              \
+           CODE = uiomove((SRC),(LEN),(UIO));                  \
+           if (haveGlock)                                      \
+               AFS_GLOCK();                                    \
+       } while(0)
+#else
 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
        do {                                                    \
@@ -326,24 +357,32 @@ typedef struct timeval osi_timeval_t;
                AFS_GLOCK();                                    \
        } while(0)
 #endif
+#endif /* AFS_DARWIN80_ENV */
 
 #else /* AFS_GLOBAL_SUNLOCK */
 
 #define AFS_COPYIN(SRC,DST,LEN,CODE)                           \
        do {                                                    \
-           CODE = copyin((SRC),(DST),(LEN));                   \
+           CODE = copyin(__U((SRC)),(DST),(LEN));                      \
        } while(0)
 
 #define AFS_COPYINSTR(SRC,DST,LEN,CNT,CODE)                    \
        do {                                                    \
-           CODE = copyinstr((SRC),(DST),(LEN),(CNT));          \
+           CODE = copyinstr(__U((SRC)),(DST),(LEN),(CNT));             \
        } while(0)
 
 #define AFS_COPYOUT(SRC,DST,LEN,CODE)                          \
        do {                                                    \
-           CODE = copyout((SRC),(DST),(LEN));                  \
+           CODE = copyout((SRC),__U((DST)),(LEN));                     \
        } while(0)
 
+#if defined(AFS_DARWIN80_ENV)
+#define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
+       do {                                                    \
+           uio_setrw((UIO),(RW));                              \
+           CODE = uiomove((SRC),(LEN),(UIO));                  \
+       } while(0)
+#else /* AFS_OSF_ENV || AFS_FBSD_ENV */
 #if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
        do {                                                    \
@@ -356,9 +395,23 @@ typedef struct timeval osi_timeval_t;
            CODE = uiomove((SRC),(LEN),(RW),(UIO));             \
        } while(0)
 #endif /* AFS_OSF_ENV || AFS_FBSD_ENV */
+#endif /* AFS_DARWIN80_ENV */
 
 #endif /* AFS_GLOBAL_SUNLOCK */
 
+#ifdef AFS_DARWIN80_ENV
+#define AFS_UIO_OFFSET(uio) uio_offset(uio)
+#define AFS_UIO_RESID(uio) (int)uio_resid(uio)
+#define AFS_UIO_SETOFFSET(uio, off) uio_setoffset(uio, off)
+#define AFS_UIO_SETRESID(uio, val) uio_setresid(uio, val)
+#else
+#define AFS_UIO_OFFSET(uio) (uio)->uio_offset
+#define AFS_UIO_RESID(uio) (uio)->uio_resid
+#define AFS_UIO_SETOFFSET(uio, off) (uio)->uio_offset = off
+#define AFS_UIO_SETRESID(uio, val) (uio)->uio_resid = val
+#endif
+
+
 /*
  * encapsulation of kernel data structure accesses
  */