macos104-not-yet-20050511
[openafs.git] / src / afs / afs_osi.c
index 04065e0..7b6d260 100644 (file)
@@ -60,7 +60,9 @@ osi_Init(void)
 #elif defined(AFS_FBSD50_ENV)
     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);
@@ -74,13 +76,14 @@ osi_Init(void)
 #endif /* AFS_HPUX_ENV */
 
     if (!afs_osicred_initialized) {
-#if defined(AFS_LINUX26_ENV)
-       afs_osi_credp = crref();
-#elif defined(AFS_XBSD_ENV)
+#if defined(AFS_XBSD_ENV)
        /* Can't just invent one, must use crget() because of mutex */
        afs_osi_credp = crdup(osi_curcred());
 #else
        memset(&afs_osi_cred, 0, sizeof(struct AFS_UCRED));
+#if defined(AFS_LINUX26_ENV)
+        afs_osi_cred.cr_group_info = groups_alloc(0);
+#endif
        crhold(&afs_osi_cred);  /* don't let it evaporate */
        afs_osi_credp = &afs_osi_cred;
 #endif
@@ -97,13 +100,9 @@ int
 osi_Active(register struct vcache *avc)
 {
     AFS_STATCNT(osi_Active);
-#if defined(AFS_SUN_ENV) || defined(AFS_AIX_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || (AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
+#if defined(AFS_AIX_ENV) || defined(AFS_OSF_ENV) || defined(AFS_SUN5_ENV) || (AFS_LINUX20_ENV) || defined(AFS_DARWIN_ENV) || defined(AFS_XBSD_ENV)
     if ((avc->opens > 0) || (avc->states & CMAPPED))
        return 1;               /* XXX: Warning, verify this XXX  */
-#elif  defined(AFS_MACH_ENV)
-    if (avc->opens > 0
-       || ((avc->v.v_flag & VTEXT) && !inode_uncache_try(avc)))
-       return 1;
 #elif defined(AFS_SGI_ENV)
     if ((avc->opens > 0) || AFS_VN_MAPPED(AFSTOV(avc)))
        return 1;
@@ -188,14 +187,6 @@ osi_FlushText_really(register struct vcache *vp)
     if (hcmp(vp->m.DataVersion, vp->flushDV) <= 0)
        return;
 
-#ifdef AFS_DEC_ENV
-    {
-       void afs_gfs_FlushText();
-       afs_gfs_FlushText(vp);
-       return;
-    }
-#else
-
     MObtainWriteLock(&afs_ftf, 317);
     hset(fdv, vp->m.DataVersion);
 
@@ -238,60 +229,7 @@ osi_FlushText_really(register struct vcache *vp)
     hset(vp->flushDV, fdv);
     MReleaseWriteLock(&afs_ftf);
 
-#endif /* AFS_DEC_ENV */
 }
-
-#ifdef AFS_DEC_ENV
-/* I don't really like using xinval() here, because it kills processes
- * a bit aggressively.  Previous incarnations of this functionality
- * used to use xrele() instead of xinval, and didn't invoke
- * cacheinval().  But they would panic.  So it might be worth looking
- * into some middle ground...
- */
-static void
-afs_gfs_FlushText(register struct vcache *vp)
-{
-    afs_hyper_t fdv;           /* version before which we'll flush */
-    register struct text *xp;
-    struct gnode *gp;
-
-    MObtainWriteLock(&afs_ftf, 318);
-    hset(fdv, vp->m.DataVersion);
-    gp = afs_vntogn(vp);
-
-    if (!gp) {
-       /* this happens frequently after cores are created. */
-       MReleaseWriteLock(&afs_ftf);
-       return;
-    }
-
-    if (gp->g_flag & GTEXT) {
-       if (gp->g_textp) {
-           xp = (struct text *)gp->g_textp;
-           /* if text object is locked, give up */
-           if (xp && (xp->x_flag & XLOCK)) {
-               MReleaseWriteLock(&afs_ftf);
-               return;
-           }
-       } else
-           xp = NULL;
-
-       if (gp->g_flag & GTEXT) {       /* still has a text object? */
-           xinval(gp);
-       }
-    }
-
-    /* next do the stuff that need not check for deadlock problems */
-    /*    maybe xinval(gp); here instead of above */
-    binval(NODEV, gp);
-    cacheinval(gp);
-    /* finally, record that we've done it */
-    hset(vp->flushDV, fdv);
-
-    MReleaseWriteLock(&afs_ftf);
-}
-#endif /* AFS_DEC_ENV */
-
 #endif /* AFS_TEXT_ENV */
 
 /* mask signals in afsds */
@@ -309,6 +247,26 @@ afs_osi_UnmaskRxkSignals(void)
 {
 }
 
+/* Two hacks to try and fix afsdb */
+void 
+afs_osi_MaskUserLoop()
+{
+#ifdef AFS_DARWIN_ENV
+    afs_osi_Invisible();
+    afs_osi_fullSigMask();
+#else
+    afs_osi_MaskSignals();
+#endif
+}
+
+void 
+afs_osi_UnmaskUserLoop()
+{
+#ifdef AFS_DARWIN_ENV
+    afs_osi_fullSigRestore();
+#endif
+}
+
 /* register rxk listener proc info */
 void
 afs_osi_RxkRegister(void)
@@ -324,12 +282,11 @@ afs_osi_Invisible(void)
 {
 #ifdef AFS_LINUX22_ENV
     afs_osi_MaskSignals();
-#elif defined(AFS_DEC_ENV)
-    u.u_procp->p_type |= SSYS;
 #elif defined(AFS_SUN5_ENV)
     curproc->p_flag |= SSYS;
 #elif defined(AFS_HPUX101_ENV) && !defined(AFS_HPUX1123_ENV)
     set_system_proc(u.u_procp);
+#elif defined(AFS_DARWIN80_ENV)
 #elif defined(AFS_DARWIN_ENV)
     /* maybe call init_process instead? */
     current_proc()->p_flag |= P_SYSTEM;
@@ -424,8 +381,10 @@ afs_osi_SetTime(osi_timeval_t * atv)
 void *
 afs_osi_Alloc(size_t x)
 {
+#if !defined(AFS_LINUX20_ENV) && !defined(AFS_FBSD_ENV)
     register struct osimem *tm = NULL;
     register int size;
+#endif
 
     AFS_STATCNT(osi_Alloc);
     /* 0-length allocs may return NULL ptr from AFS_KALLOC, so we special-case
@@ -442,7 +401,7 @@ afs_osi_Alloc(size_t x)
 #else
     size = x;
     tm = (struct osimem *)AFS_KALLOC(size);
-#ifdef AFS_SUN_ENV
+#ifdef AFS_SUN5_ENV
     if (!tm)
        osi_Panic("osi_Alloc: Couldn't allocate %d bytes; out of memory!\n",
                  size);
@@ -451,7 +410,7 @@ afs_osi_Alloc(size_t x)
 #endif
 }
 
-#if    defined(AFS_SUN_ENV) || defined(AFS_SGI_ENV)
+#if    defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV)
 
 void *
 afs_osi_Alloc_NoSleep(size_t x)
@@ -554,7 +513,7 @@ osi_VMDirty_p(struct vcache *avc)
 #endif
 #endif /* AFS_AIX32_ENV */
 
-#if defined (AFS_SUN_ENV)
+#if defined (AFS_SUN5_ENV)
     if (avc->states & CMAPPED) {
        struct page *pg;
        for (pg = avc->v.v_s.v_Pages; pg; pg = pg->p_vpnext) {
@@ -616,7 +575,7 @@ afs_osi_suser(void *credp)
 #if defined(AFS_SUN5_ENV)
     return afs_suser(credp);
 #else
-    return afs_suser();
+    return afs_suser(NULL);
 #endif
 }
 #endif
@@ -785,6 +744,12 @@ afs_osi_TraverseProcTable(void)
 #endif
 
 #if defined(AFS_OSF_ENV)
+
+#ifdef AFS_DUX50_ENV
+extern struct pid_entry *pidtab;
+extern int npid; 
+#endif
+
 void
 afs_osi_TraverseProcTable(void)
 {
@@ -803,7 +768,7 @@ afs_osi_TraverseProcTable(void)
 }
 #endif
 
-#if defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
+#if (defined(AFS_DARWIN_ENV) && !defined(AFS_DARWIN80_ENV)) || defined(AFS_FBSD_ENV)
 void
 afs_osi_TraverseProcTable(void)
 {
@@ -821,30 +786,38 @@ afs_osi_TraverseProcTable(void)
 #endif
 
 #if defined(AFS_LINUX22_ENV)
+extern rwlock_t tasklist_lock __attribute__((weak));
 void
 afs_osi_TraverseProcTable()
 {
     struct task_struct *p;
-
-#ifdef EXPORTED_TASKLIST_LOCK
-    read_lock(&tasklist_lock);
-#endif
+    if (&tasklist_lock)
+       read_lock(&tasklist_lock);
 #ifdef DEFINED_FOR_EACH_PROCESS
     for_each_process(p) if (p->pid) {
+#ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE
+       if (p->exit_state)
+           continue;
+#else
        if (p->state & TASK_ZOMBIE)
            continue;
+#endif
        afs_GCPAGs_perproc_func(p);
     }
 #else
     for_each_task(p) if (p->pid) {
+#ifdef STRUCT_TASK_STRUCT_HAS_EXIT_STATE
+       if (p->exit_state)
+           continue;
+#else
        if (p->state & TASK_ZOMBIE)
            continue;
+#endif
        afs_GCPAGs_perproc_func(p);
     }
 #endif
-#ifdef EXPORTED_TASKLIST_LOCK
-    read_unlock(&tasklist_lock);
-#endif
+    if (&tasklist_lock)
+       read_unlock(&tasklist_lock);
 }
 #endif
 
@@ -1019,6 +992,25 @@ afs_osi_proc2cred(AFS_PROC * pr)
 
     return rv;
 }
+#elif defined(AFS_DARWIN80_ENV) 
+const struct AFS_UCRED *
+afs_osi_proc2cred(AFS_PROC * pr)
+{
+    struct AFS_UCRED *rv = NULL;
+    static struct AFS_UCRED cr;
+    struct ucred *pcred;
+
+    if (pr == NULL) {
+       return NULL;
+    }
+    pcred = proc_ucred(pr);
+    cr.cr_ref = 1;
+    cr.cr_uid = pcred->cr_uid;
+    cr.cr_ngroups = pcred->cr_ngroups;
+    memcpy(cr.cr_groups, pcred->cr_groups,
+           NGROUPS * sizeof(gid_t));
+    return &cr;
+}
 #elif defined(AFS_DARWIN_ENV) || defined(AFS_FBSD_ENV)
 const struct AFS_UCRED *
 afs_osi_proc2cred(AFS_PROC * pr)