getpid-20050429
[openafs.git] / src / afs / afs_osi_pag.c
index db1e7b4..eb51996 100644 (file)
@@ -139,6 +139,44 @@ getpag(void)
  * activates tokens repeatedly) for that entire period.
  */
 
+static int afs_pag_sleepcnt = 0;
+
+static int
+afs_pag_sleep(struct AFS_UCRED **acred)
+{
+    int rv = 0;
+
+    if (!afs_suser(acred)) {
+       if(osi_Time() - pag_epoch < pagCounter) {
+           rv = 1;
+       }
+    }
+
+    return rv;
+}
+
+static int
+afs_pag_wait(struct AFS_UCRED **acred)
+{
+    if (afs_pag_sleep(acred)) {
+       if (!afs_pag_sleepcnt) {
+           printf("%s() PAG throttling triggered, pid %d... sleeping.  sleepcnt %d\n",
+                  "afs_pag_wait", osi_getpid(), afs_pag_sleepcnt);
+       }
+
+       afs_pag_sleepcnt++;
+
+       do {
+           /* XXX spins on EINTR */
+           afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0);
+       } while (afs_pag_sleep(acred));
+
+       afs_pag_sleepcnt--;
+    }
+
+    return 0;
+}
+
 int
 #if    defined(AFS_SUN5_ENV)
 afs_setpag(struct AFS_UCRED **credpp)
@@ -148,6 +186,15 @@ afs_setpag(struct proc *p, void *args, int *retval)
 afs_setpag(void)
 #endif
 {
+
+#if     defined(AFS_SUN5_ENV)
+    struct AFS_UCRED **acred = *credpp;
+#elif  defined(AFS_OBSD_ENV)
+    struct AFS_UCRED **acred = &p->p_ucred;
+#else
+    struct AFS_UCRED **acred = NULL;
+#endif
+
     int code = 0;
 
 #if defined(AFS_SGI53_ENV) && defined(MP)
@@ -156,18 +203,10 @@ afs_setpag(void)
 #endif /* defined(AFS_SGI53_ENV) && defined(MP) */
 
     AFS_STATCNT(afs_setpag);
-#if    defined(AFS_SUN5_ENV)
-    if (!afs_suser(*credpp))
-#elif  defined(AFS_OBSD_ENV)
-    if (!afs_osi_suser(p->p_ucred))
-#else
-    if (!afs_suser())
-#endif
-    {
-       while (osi_Time() - pag_epoch < pagCounter) {
-           afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0);
-       }
-    }
+
+    afs_pag_wait(acred);
+
+
 #if    defined(AFS_SUN5_ENV)
     code = AddPag(genpag(), credpp);
 #elif  defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV)
@@ -213,13 +252,16 @@ afs_setpag(void)
 #endif
 
     afs_Trace1(afs_iclSetp, CM_TRACE_SETPAG, ICL_TYPE_INT32, code);
+
 #if defined(KERNEL_HAVE_UERROR)
     if (!getuerror())
        setuerror(code);
 #endif
+
 #if defined(AFS_SGI53_ENV) && defined(MP)
     AFS_GUNLOCK();
 #endif /* defined(AFS_SGI53_ENV) && defined(MP) */
+
     return (code);
 }
 
@@ -240,6 +282,15 @@ afs_setpag_val(struct proc *p, void *args, int *retval, int pagval)
 afs_setpag_val(int pagval)
 #endif
 {
+
+#if     defined(AFS_SUN5_ENV)
+    struct AFS_UCRED **acred = *credp;
+#elif  defined(AFS_OBSD_ENV)
+    struct AFS_UCRED **acred = &p->p_ucred;
+#else
+    struct AFS_UCRED **acred = NULL;
+#endif
+
     int code = 0;
 
 #if defined(AFS_SGI53_ENV) && defined(MP)
@@ -248,16 +299,9 @@ afs_setpag_val(int pagval)
 #endif /* defined(AFS_SGI53_ENV) && defined(MP) */
 
     AFS_STATCNT(afs_setpag);
-#ifdef AFS_SUN5_ENV
-    if (!afs_suser(*credpp))
-#else
-    if (!afs_suser())
-#endif
-    {
-       while (osi_Time() - pag_epoch < pagCounter) {
-           afs_osi_Wait(1000, (struct afs_osi_WaitHandle *)0, 0);
-       }
-    }
+
+    afs_pag_wait(acred);
+
 #if    defined(AFS_SUN5_ENV)
     code = AddPag(pagval, credpp);
 #elif  defined(AFS_OSF_ENV) || defined(AFS_XBSD_ENV)
@@ -450,25 +494,27 @@ PagInCred(const struct AFS_UCRED *cred)
     g0 = cred->cr_groups[1];
     g1 = cred->cr_groups[2];
 #else
-#ifdef AFS_AIX_ENV
-#ifdef AFS_AIX51_ENV
+#if defined(AFS_AIX51_ENV)
     if (kcred_getpag(cred, PAG_AFS, &pag) < 0 || pag == 0)
        pag = NOPAG;
     return pag;
-#else
+#elif defined(AFS_AIX_ENV)
     if (cred->cr_ngrps < 2) {
        return NOPAG;
     }
-#endif
-#else
-#if defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DUX40_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_XBSD_ENV)
+#elif defined(AFS_LINUX26_ENV)
+    if (cred->cr_group_info->ngroups < 2)
+       return NOPAG;
+#elif defined(AFS_SGI_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_DUX40_ENV) || defined(AFS_LINUX20_ENV) || defined(AFS_XBSD_ENV)
     if (cred->cr_ngroups < 2)
        return NOPAG;
 #endif
-#endif
-#ifdef AFS_AIX51_ENV
+#if defined(AFS_AIX51_ENV)
     g0 = cred->cr_groupset.gs_union.un_groups[0];
     g1 = cred->cr_groupset.gs_union.un_groups[1];
+#elif defined(AFS_LINUX26_ENV)
+    g0 = GROUP_AT(cred->cr_group_info, 0);
+    g1 = GROUP_AT(cred->cr_group_info, 1);
 #else
     g0 = cred->cr_groups[0];
     g1 = cred->cr_groups[1];