Linux: Remove use of undefined AFS_LINUX_ENV
[openafs.git] / src / afs / afs_osi.c
index 490f970..b446e8b 100644 (file)
@@ -34,22 +34,18 @@ lock_t afs_event_lock;
 flid_t osi_flid;
 #endif
 
-struct AFS_UCRED *afs_osi_credp;
+afs_ucred_t *afs_osi_credp;
 
 #if defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
 kmutex_t afs_global_lock;
-kmutex_t afs_rxglobal_lock;
 #endif
 
 #if defined(AFS_SGI_ENV) && !defined(AFS_SGI64_ENV)
 long afs_global_owner;
 #endif
 
-#if defined(AFS_OSF_ENV)
-simple_lock_data_t afs_global_lock;
-#endif
-
-#if defined(AFS_DARWIN_ENV) 
+#if defined(AFS_DARWIN_ENV)
+thread_t afs_global_owner;
 #ifdef AFS_DARWIN80_ENV
 lck_mtx_t  *afs_global_lock;
 #else
@@ -57,18 +53,18 @@ struct lock__bsd__ afs_global_lock;
 #endif
 #endif
 
-#if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD50_ENV)
+#if defined(AFS_XBSD_ENV) && !defined(AFS_FBSD_ENV)
+# if defined(AFS_NBSD50_ENV)
+kmutex_t afs_global_mtx;
+# else
 struct lock afs_global_lock;
-struct proc *afs_global_owner;
-#endif
-#ifdef AFS_FBSD50_ENV
+afs_proc_t *afs_global_owner;
+# endif
+#elif defined(AFS_FBSD_ENV)
 struct mtx afs_global_mtx;
+struct thread *afs_global_owner;
 #endif
 
-#if defined(AFS_OSF_ENV) || defined(AFS_DARWIN_ENV)
-thread_t afs_global_owner;
-#endif /* AFS_OSF_ENV */
-
 #if defined(AFS_AIX41_ENV)
 simple_lock_data afs_global_lock;
 #endif
@@ -79,36 +75,8 @@ osi_Init(void)
     static int once = 0;
     if (once++ > 0)            /* just in case */
        return;
-#if    defined(AFS_HPUX_ENV)
+
     osi_InitGlock();
-#else /* AFS_HPUX_ENV */
-#if defined(AFS_GLOBAL_SUNLOCK)
-#if defined(AFS_SGI62_ENV)
-    mutex_init(&afs_global_lock, MUTEX_DEFAULT, "afs_global_lock");
-#elif defined(AFS_OSF_ENV)
-    usimple_lock_init(&afs_global_lock);
-    afs_global_owner = (thread_t) 0;
-#elif defined(AFS_FBSD50_ENV)
-#if defined(AFS_FBSD80_ENV) && defined(WITNESS)
-    /* "lock_initalized" (sic) can panic, checks a flag bit
-     * is unset _before_ init */
-    memset(&afs_global_mtx, 0, sizeof(struct mtx));
-#endif
-    mtx_init(&afs_global_mtx, "AFS global lock", NULL, MTX_DEF);
-#elif defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
-#if !defined(AFS_DARWIN80_ENV)
-    lockinit(&afs_global_lock, PLOCK, "afs global lock", 0, 0);
-#endif
-    afs_global_owner = 0;
-#elif defined(AFS_AIX41_ENV)
-    lock_alloc((void *)&afs_global_lock, LOCK_ALLOC_PIN, 1, 1);
-    simple_lock_init((void *)&afs_global_lock);
-#elif !defined(AFS_LINUX22_ENV)
-    /* Linux initialization in osi directory. Should move the others. */
-    mutex_init(&afs_global_lock, "afs_global_lock", MUTEX_DEFAULT, NULL);
-#endif
-#endif /* AFS_GLOBAL_SUNLOCK */
-#endif /* AFS_HPUX_ENV */
 
     if (!afs_osicred_initialized) {
 #if defined(AFS_DARWIN80_ENV)
@@ -118,16 +86,19 @@ osi_Init(void)
 #endif
 #if defined(AFS_XBSD_ENV)
        /* Can't just invent one, must use crget() because of mutex */
-       afs_osi_credp = crdup(osi_curcred());
+       afs_osi_credp =
+         crdup(osi_curcred());
 #else
-       memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
+       memset(&afs_osi_cred, 0, sizeof(afs_ucred_t));
 #if defined(AFS_LINUX26_ENV)
-        afs_osi_cred.cr_group_info = groups_alloc(0);
+        afs_set_cr_group_info(&afs_osi_cred, groups_alloc(0));
 #endif
 #if defined(AFS_DARWIN80_ENV)
         afs_osi_cred.cr_ref = 1; /* kauth_cred_get_ref needs 1 existing ref */
 #else
-       crhold(&afs_osi_cred);  /* don't let it evaporate */
+# if !(defined(AFS_LINUX26_ENV) && defined(STRUCT_TASK_STRUCT_HAS_CRED))
+       crhold(&afs_osi_cred);  /* don't let it evaporate */
+# endif
 #endif
 
        afs_osi_credp = &afs_osi_cred;
@@ -157,8 +128,8 @@ afs_osi_UnmaskRxkSignals(void)
 }
 
 /* Two hacks to try and fix afsdb */
-void 
-afs_osi_MaskUserLoop()
+void
+afs_osi_MaskUserLoop(void)
 {
 #ifdef AFS_DARWIN_ENV
     afs_osi_Invisible();
@@ -168,7 +139,7 @@ afs_osi_MaskUserLoop()
 #endif
 }
 
-void 
+void
 afs_osi_UnmaskUserLoop(void)
 {
 #ifdef AFS_DARWIN_ENV
@@ -196,6 +167,8 @@ afs_osi_Invisible(void)
 #elif defined(AFS_DARWIN_ENV)
     /* maybe call init_process instead? */
     current_proc()->p_flag |= P_SYSTEM;
+#elif defined(AFS_NBSD50_ENV)
+    /* XXX in netbsd a system thread is more than invisible */
 #elif defined(AFS_XBSD_ENV)
     curproc->p_flag |= P_SYSTEM;
 #elif defined(AFS_SGI_ENV)
@@ -214,6 +187,8 @@ afs_osi_Visible(void)
 #elif defined(AFS_DARWIN_ENV)
     /* maybe call init_process instead? */
     current_proc()->p_flag &= ~P_SYSTEM;
+#elif defined(AFS_NBSD50_ENV)
+    /* XXX in netbsd a system thread is more than invisible */
 #elif defined(AFS_XBSD_ENV)
     curproc->p_flag &= ~P_SYSTEM;
 #endif
@@ -230,21 +205,8 @@ afs_osi_SetTime(osi_timeval_t * atv)
     t.tv_sec = atv->tv_sec;
     t.tv_nsec = atv->tv_usec * 1000;
     ksettimer(&t);             /*  Was -> settimer(TIMEOFDAY, &t); */
-#elif defined(AFS_SUN55_ENV)
-    stime(atv->tv_sec);
 #elif defined(AFS_SUN5_ENV)
-    /*
-     * To get more than second resolution we can use adjtime. The problem
-     * is that the usecs from the server are wrong (by now) so it isn't
-     * worth complicating the following code.
-     */
-    struct stimea {
-       time_t time;
-    } sta;
-
-    sta.time = atv->tv_sec;
-
-    stime(&sta, NULL);
+    stime(atv->tv_sec);
 #elif defined(AFS_SGI_ENV)
     struct stimea {
        sysarg_t time;
@@ -271,7 +233,7 @@ afs_osi_SetTime(osi_timeval_t * atv)
        /* drop the setting of the clock for now. spl7 is not
         * known on hpux11.22
         */
-       register ulong_t s;
+       ulong_t s;
        struct timeval t;
        t.tv_sec = atv->tv_sec;
        t.tv_usec = atv->tv_usec;
@@ -283,7 +245,7 @@ afs_osi_SetTime(osi_timeval_t * atv)
     }
 #else
     {
-       register int s;
+       int s;
        s = splclock();
        time = *atv;
        (void)splx(s);
@@ -309,6 +271,9 @@ shutdown_osi(void)
        afs_osi_ctxtp = NULL;
        afs_osi_ctxtp_initialized = 0;
     }
+#endif
+#if !defined(AFS_HPUX_ENV) && !defined(UKERNEL) && !defined(AFS_DFBSD_ENV) && !defined(AFS_LINUX26_ENV)
+    /* LINUX calls this from afs_cleanup() which hooks into module_exit */
     shutdown_osisleep();
 #endif
     if (afs_cold_shutdown) {
@@ -316,7 +281,38 @@ shutdown_osi(void)
     }
 }
 
-#ifndef AFS_OBSD_ENV
+#if !defined(AFS_HPUX_ENV) && !defined(UKERNEL) && !defined(AFS_DFBSD_ENV) && !defined(AFS_DARWIN_ENV)
+/* DARWIN uses locking, and so must provide its own */
+void
+shutdown_osisleep(void)
+{
+    afs_event_t *tmp;
+    int i;
+
+    for (i=0;i<AFS_EVHASHSIZE;i++) {
+       while ((tmp = afs_evhasht[i]) != NULL) {
+           afs_evhasht[i] = tmp->next;
+           if (tmp->refcount > 0) {
+               afs_warn("nonzero refcount in shutdown_osisleep()\n");
+           } else {
+#if defined(AFS_AIX_ENV)
+               xmfree(tmp);
+#elif defined(AFS_FBSD_ENV)
+               afs_osi_Free(tmp, sizeof(*tmp));
+#elif defined(AFS_SGI_ENV) || defined(AFS_XBSD_ENV) || defined(AFS_SOLARIS_ENV)
+               osi_FreeSmallSpace(tmp);
+#elif defined(AFS_LINUX26_ENV)
+               kfree(tmp);
+#elif defined(AFS_LINUX20_ENV)
+               osi_linux_free(tmp);
+#endif
+           }
+       }
+    }
+}
+#endif
+
+#if !defined(AFS_OBSD_ENV) && !defined(AFS_NBSD40_ENV)
 int
 afs_osi_suser(void *cr)
 {