volser-cache-more-ips-20030114
[openafs.git] / src / volser / vsutils.c
index 3a5d1e3..765d637 100644 (file)
@@ -26,6 +26,15 @@ RCSID("$Header$");
 #ifdef AFS_AIX_ENV
 #include <sys/statfs.h>
 #endif
+
+#ifdef HAVE_STRING_H
+#include <string.h>
+#else
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#endif
+
 #include <errno.h>
 #include <lock.h>
 #include <rx/xdr.h>
@@ -265,7 +274,13 @@ struct cacheips {
     afs_int32 count;
     afs_uint32 addrs[16];
 };
-struct cacheips cacheips[16];
+/*
+ * Increase cache size.  This avoids high CPU usage by the vlserver
+ * in environments where there are more than 16 fileservers in the
+ * cell.
+ */
+#define GETADDRUCACHESIZE             64
+struct cacheips cacheips[GETADDRUCACHESIZE];
 int cacheip_index=0;
 extern int VL_GetAddrsU();
 VLDB_IsSameAddrs(serv1, serv2, errorp)
@@ -286,14 +301,14 @@ VLDB_IsSameAddrs(serv1, serv2, errorp)
        return 0;
     }
     if (!initcache) {
-       for (i=0; i<16; i++) {
+       for (i=0; i < GETADDRUCACHESIZE; i++) {
           cacheips[i].server = cacheips[i].count = 0;
        }
        initcache = 1;
     }
 
     /* See if it's cached */
-    for (i=0; i<16; i++) {
+    for (i=0; i < GETADDRUCACHESIZE; i++) {
        f1 = f2 = 0;
        for (j=0; j < cacheips[i].count; j++) {
          if      (serv1 == cacheips[i].addrs[j]) f1 = 1;
@@ -304,6 +319,8 @@ VLDB_IsSameAddrs(serv1, serv2, errorp)
        }       
        if (f1 || f2)
          return 0;
+       if (cacheips[i].server == serv1)
+          return 0;
   }
 
     memset(&attrs, 0, sizeof(attrs));
@@ -328,7 +345,8 @@ VLDB_IsSameAddrs(serv1, serv2, errorp)
     }
 
     code = 0;
-    if (++cacheip_index >= 16) cacheip_index = 0;
+    if (nentries > GETADDRUCACHESIZE) nentries = GETADDRUCACHESIZE;  /* safety check; should not happen */
+    if (++cacheip_index >= GETADDRUCACHESIZE) cacheip_index = 0;
     cacheips[cacheip_index].server = serv1;
     cacheips[cacheip_index].count = nentries;
     addrp = addrs.bulkaddrs_val;
@@ -461,7 +479,7 @@ afs_int32 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc
             strcpy(sname.cell, info.name);
             sname.instance[0] = 0;
             strcpy(sname.name, "afs");
-            code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), (char *)0);
+            code = ktc_GetToken(&sname, &ttoken, sizeof(ttoken), NULL);
             if (code) {   /* did not get ticket */
                 fprintf(STDERR, "vsu_ClientInit: Could not get afs tokens, running unauthenticated.\n");
                 scIndex = 0;
@@ -477,10 +495,10 @@ afs_int32 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc
 
         switch (scIndex) {
           case 0 :
-            sc = (struct rx_securityClass *) rxnull_NewClientSecurityObject();
+            sc = rxnull_NewClientSecurityObject();
             break;
           case 2:
-            sc = (struct rx_securityClass *)rxkad_NewClientSecurityObject(
+            sc = rxkad_NewClientSecurityObject(
                  vsu_rxkad_level, &ttoken.sessionKey, ttoken.kvno,
                  ttoken.ticketLen, ttoken.ticket);
             break;
@@ -492,6 +510,8 @@ afs_int32 vsu_ClientInit(noAuthFlag, confDir, cellName, sauth, uclientp, secproc
         }
     }
 
+    afsconf_Close(tdir);
+
     if (secproc)     /* tell UV module about default authentication */
         (*secproc) (sc, scIndex);
     if (info.numServers > VLDB_MAXSERVERS) {