LINUX 5.6: define osi_timeval32_t for 32-bit Linux
[openafs.git] / src / afs / afs_osi.h
index c616365..1e3e89e 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #define _AFS_OSI_
 
 #include "h/types.h"
+#if !defined(AFS_LINUX26_ENV)
 #include "h/param.h"
+#endif
 
-#ifdef AFS_FBSD50_ENV
+#ifdef AFS_FBSD_ENV
 #include <sys/condvar.h>
 #endif
 
+#ifdef AFS_NBSD_ENV
+#include <sys/lock.h>
+#endif
+
 #ifdef AFS_LINUX20_ENV
 #ifndef _LINUX_CODA_FS_I
 #define _LINUX_CODA_FS_I
@@ -33,6 +39,13 @@ struct xfs_inode_info {
 #include "h/mm.h"
 #endif
 
+#if defined(AFS_NBSD50_ENV)
+# if !defined(DEF_CADDR_T)
+typedef char * caddr_t;
+#define DEF_CADDR_T
+# endif
+#endif
+
 
 /* this is just a dummy type decl, we're really using struct sockets here */
 struct osi_socket {
@@ -41,19 +54,22 @@ 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 */
 };
 
 struct osi_file {
     afs_int32 size;            /* file size in bytes XXX Must be first field XXX */
+#ifdef AFS_LINUX26_ENV
+    struct file *filp;         /* May need this if we really open the file. */
+#else
 #ifdef AFS_LINUX22_ENV
     struct dentry dentry;      /* merely to hold the pointer to the inode. */
     struct file file;          /* May need this if we really open the file. */
 #else
     struct vnode *vnode;
 #endif
+#endif
 #if    defined(AFS_HPUX102_ENV)
     k_off_t offset;
 #else
@@ -65,7 +81,6 @@ struct osi_file {
 #endif
     int (*proc) (struct osi_file * afile, afs_int32 code);     /* proc, which, if not null, is called on writes */
     char *rock;                        /* rock passed to proc */
-    ino_t inum;                        /* guarantee validity of hint */
 #if defined(UKERNEL)
     int fd;                    /* file descriptor for user space files */
 #endif                         /* defined(UKERNEL) */
@@ -83,9 +98,9 @@ struct osi_dev {
 };
 
 struct afs_osi_WaitHandle {
-#ifdef AFS_FBSD50_ENV
+#ifdef AFS_FBSD_ENV
     struct cv wh_condvar;
-    int wh_inited;             /* XXX */
+    int wh_inited;
 #else
     caddr_t proc;              /* process waiting */
 #endif
@@ -97,7 +112,7 @@ struct afs_osi_WaitHandle {
 #define        osi_GetFileRock(x)      ((x)->rock)
 
 #ifdef AFS_TEXT_ENV
-#define osi_FlushText(vp) if (hcmp((vp)->m.DataVersion, (vp)->flushDV) > 0) \
+#define osi_FlushText(vp) if (hcmp((vp)->f.m.DataVersion, (vp)->flushDV) > 0) \
                            osi_FlushText_really(vp)
 #else
 #define osi_FlushText(vp)
@@ -111,45 +126,40 @@ struct afs_osi_WaitHandle {
 
 #define        osi_NPACKETS    20      /* number of cluster pkts to alloc */
 
-/*
- * Alloc declarations.
- */
-#define afs_osi_Alloc_NoSleep afs_osi_Alloc
+
 
 /*
- * Vnode related macros
+ * Default vnode related macros
+ *
+ * Darwin, all of the BSDs, and Linux have their own
  */
-#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-#define vSetVfsp(vc, vfsp)      AFSTOV(vc)->v_mount = (vfsp)
-#define vSetType(vc, type)      AFSTOV(vc)->v_type = (type)
-#define vType(vc)               AFSTOV(vc)->v_type
-#else
-#define        vType(vc)           (vc)->v.v_type
-#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)
-#define SetAfsVnode(v)     (v)->v_op = afs_vnodeop_p
-#else
+#if !defined(AFS_DARWIN_ENV) && !defined(AFS_XBSD_ENV) && !defined(AFS_LINUX20_ENV)
+# define       vType(vc)           AFSTOV(vc)->v_type
+# define       vSetType(vc,type)   AFSTOV(vc)->v_type = (type)
+# define       vSetVfsp(vc,vfsp)   AFSTOV(vc)->v_vfsp = (vfsp)
 extern struct vnodeops *afs_ops;
-#define        IsAfsVnode(v)       ((v)->v_op == afs_ops)
-#define        SetAfsVnode(v)      (v)->v_op = afs_ops
+# define       IsAfsVnode(v)       ((v)->v_op == afs_ops)
+# define       SetAfsVnode(v)      (v)->v_op = afs_ops
 #endif
 
-#ifdef AFS_SGI65_ENV
-#define        gop_lookupname(fnamep,segflg,followlink,compvpp) \
-             lookupname((fnamep),(segflg),(followlink),NULL,(compvpp),\
-                       NULL)
-#else
-#define        gop_lookupname(fnamep,segflg,followlink,compvpp) \
-             lookupname((fnamep),(segflg),(followlink),NULL,(compvpp))
-#endif
+struct vcache;
+extern int osi_TryEvictVCache(struct vcache *, int *, int);
+extern struct vcache *osi_NewVnode(void);
+extern void osi_PrePopulateVCache(struct vcache *);
+extern void osi_PostPopulateVCache(struct vcache *);
+extern void osi_AttachVnode(struct vcache *, int seq);
+
+/**
+ * Increment the refcount on the given vcache.
+ *
+ * @retval 0 Success
+ * @retval nonzero Error obtaining reference; the vcache is no longer valid and
+ *                the caller should act as if it doesn't exist.
+ */
+extern int osi_vnhold(struct vcache *);
 
 /*
- * In IRIX 6.5 we cannot have DEBUG turned on since certain
+ * In IRIX 6.5 and NetBSD we cannot have DEBUG turned on since certain
  * system-defined structures are a different size with DEBUG on, the
  * kernel is compiled without DEBUG on, and the resulting differences
  * would break our ability to interact with the rest of the kernel.
@@ -157,13 +167,13 @@ extern struct vnodeops *afs_ops;
  * Is DEBUG only for turning the ASSERT() macro?  If so, we should
  * be able to eliminate DEBUG entirely.
  */
-#if !defined(AFS_SGI65_ENV)
+#if !defined(AFS_SGI65_ENV) && !defined(AFS_NBSD_ENV)
 #ifndef        DEBUG
 #define        DEBUG   1               /* Default is to enable debugging/logging */
 #endif
 #endif
 
-/* 
+/*
  * Time related macros
  */
 #define osi_GetuTime(x) osi_GetTime(x)
@@ -176,25 +186,38 @@ 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_LINUX26_ENV) && !defined(HAVE_LINUX_TIME_T)) || (defined(AFS_SGI61_ENV) && defined(KERNEL) && defined(_K64U64))
 typedef struct {
     afs_int32 tv_sec;
     afs_int32 tv_usec;
 } osi_timeval_t;
+typedef struct {
+    afs_int32 tv_sec;
+    afs_int32 tv_usec;
+} osi_timeval32_t;
+#elif defined(AFS_SUN5_ENV)
+typedef struct timeval32 osi_timeval_t;
+typedef struct timeval32 osi_timeval32_t;
 #else
 typedef struct timeval osi_timeval_t;
+typedef struct timeval osi_timeval32_t;
 #endif /* AFS_SGI61_ENV */
 
+#ifndef UKERNEL
+#define osi_getpid()           getpid()
+#endif
+
 /*
  * osi_ThreadUnique() should yield a value that can be found in ps
  * output in order to draw correspondences between ICL traces and what
  * is going on in the system.  So if ps cannot show thread IDs it is
  * likely to be the process ID instead.
  */
-#ifdef AFS_FBSD50_ENV
+#ifdef AFS_FBSD_ENV
 /* should use curthread, but 'ps' can't display it */
-#define osi_ThreadUnique()     curproc
+#define osi_ThreadUnique()     (curproc->p_pid)
+#elif defined(UKERNEL)
+#define osi_ThreadUnique()     osi_getpid()
 #else
 #define osi_ThreadUnique()     getpid()
 #endif
@@ -203,7 +226,7 @@ typedef struct timeval osi_timeval_t;
 
 #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
@@ -225,7 +248,7 @@ typedef struct timeval osi_timeval_t;
 
 /* On an MP that uses multithreading, splnet is not sufficient to provide
  * mutual exclusion because the other processors will not see it.  On some
- * early multiprocessors (SunOS413 & SGI5.2) splnet actually obtains a global
+ * early multiprocessors (SGI5.2) splnet actually obtains a global
  * mutex, which this works in the UP expected way, it means that the whole MP
  * can only take one interrupt at a time; a serious performance penalty. */
 
@@ -252,20 +275,22 @@ typedef struct timeval osi_timeval_t;
  * (Also, of course, the vnode is assumed to be one of ours.  Can't use this
  * macro for V-file vnodes.)
  */
-#if defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-/* Bare refcount manipulation would probably work on this platform, but just
-   calling VREF does not */
-#define AFS_FAST_HOLD(vp) osi_vnhold((vp),0)
+#ifdef AFS_AIX_ENV
+#define AFS_FAST_RELE(vp) VREFCOUNT_DEC(vp)
 #else
-#define AFS_FAST_HOLD(vp) VN_HOLD(&(vp)->v)
-#endif
 #define AFS_FAST_RELE(vp) AFS_RELE(AFSTOV(vp))
+#endif
 
 /*
  * MP safe versions of routines to copy memory between user space
  * and kernel space. Call these to avoid taking page faults while
  * holding the global lock.
  */
+#if defined(CAST_USER_ADDR_T) && !defined(UKERNEL) && !defined(AFS_DARWIN100_ENV)
+#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)                           \
@@ -273,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)
@@ -283,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)
@@ -293,12 +318,24 @@ 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_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#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_DARWIN_ENV) || defined(AFS_XBSD_ENV)
 #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
        do {                                                    \
            int haveGlock = ISAFS_GLOCK();                      \
@@ -320,44 +357,66 @@ 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_OSF_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#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)
+#elif defined(AFS_DARWIN_ENV) || (defined(AFS_XBSD_ENV) && !defined(AFS_NBSD40_ENV))
 #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
        do {                                                    \
            (UIO)->uio_rw = (RW);                               \
            CODE = uiomove((SRC),(LEN),(UIO));                  \
        } while(0)
-#else /* AFS_OSF_ENV || AFS_FBSD_ENV */
+#else
 #define AFS_UIOMOVE(SRC,LEN,RW,UIO,CODE)                       \
        do {                                                    \
            CODE = uiomove((SRC),(LEN),(RW),(UIO));             \
        } while(0)
-#endif /* AFS_OSF_ENV || AFS_FBSD_ENV */
+#endif
 
 #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
  */
+#ifndef UKERNEL
 #define setuerror(erval)       u.u_error = (erval)
 #define getuerror()            u.u_error
+#endif
 
 /* Macros for vcache/vnode and vfs arguments to vnode and vfs ops.
  * These are required for IRIX 6.4 and later, which pass behavior pointers.
@@ -376,7 +435,7 @@ typedef struct timeval osi_timeval_t;
 
 
 /*
-** Macro for Solaris 2.6 returns 1 if file is larger than 2GB; else returns 0 
+** Macro for Solaris 2.6 returns 1 if file is larger than 2GB; else returns 0
 */
 #define AfsLargeFileUio(uio)       0
 #define AfsLargeFileSize(pos, off) 0
@@ -389,10 +448,16 @@ typedef struct timeval osi_timeval_t;
 /* Declare any structures which use these macros after the OSI implementation
  * has had the opportunity to redefine them.
  */
-extern struct AFS_UCRED afs_osi_cred, *afs_osi_credp;
+extern afs_ucred_t afs_osi_cred, *afs_osi_credp;
 
 #ifndef osi_curcred
 #define osi_curcred() (u.u_cred)
 #endif
 
+#ifdef AFS_PAG_ONEGROUP_ENV
+#define AFS_NUMPAGGROUPS 1
+#else
+#define AFS_NUMPAGGROUPS 2
+#endif
+
 #endif /* _AFS_OSI_ */