virtual-cache-file-20040729
authorAsanka Herath <asanka@mit.edu>
Thu, 29 Jul 2004 15:34:21 +0000 (15:34 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Thu, 29 Jul 2004 15:34:21 +0000 (15:34 +0000)
This is a variation of Joe Buehler's request.
New registry key "NonPersistentCache" places the cache file into the
Windows paging file.  One limitation of doing so is that the page file
cannot be grown with "fs setcachesize" and the associated ioctl.

src/WINNT/afsd/afsd_init.c
src/WINNT/afsd/cm_buf.c
src/WINNT/afsd/cm_buf.h

index a72fd81..a3d3671 100644 (file)
@@ -369,6 +369,7 @@ int afsd_InitCM(char **reasonP)
     long maxcpus;
        long ltt, ltto;
     long rx_mtu, rx_nojumbo;
+    long virtualCache;
        char rootCellName[256];
        struct rx_service *serverp;
        static struct rx_securityClass *nullServerSecurityClassp;
@@ -599,6 +600,16 @@ int afsd_InitCM(char **reasonP)
                afsi_log("Default cache path %s", cm_CachePath);
        }
 
+    dummyLen = sizeof(virtualCache);
+    code = RegQueryValueEx(parmKey, "NonPersistentCaching", NULL, NULL,
+        &virtualCache, &dummyLen);
+    if (code == ERROR_SUCCESS && virtualCache) {
+        buf_cacheType = CM_BUF_CACHETYPE_VIRTUAL;
+    } else {
+        buf_cacheType = CM_BUF_CACHETYPE_FILE;
+    }
+    afsi_log("Cache type is %s", ((buf_cacheType == CM_BUF_CACHETYPE_FILE)?"FILE":"VIRTUAL"));
+
        dummyLen = sizeof(traceOnPanic);
        code = RegQueryValueEx(parmKey, "TrapOnPanic", NULL, NULL,
                                (BYTE *) &traceOnPanic, &dummyLen);
index 389c7f6..e858033 100644 (file)
@@ -75,6 +75,7 @@ long buf_nbuffers = CM_BUF_BUFFERS;
 long buf_nOrigBuffers;
 long buf_bufferSize = CM_BUF_SIZE;
 long buf_hashSize = CM_BUF_HASHSIZE;
+int buf_cacheType = CM_BUF_CACHETYPE_FILE;
 
 #ifndef DJGPP
 static
@@ -295,6 +296,7 @@ long buf_Init(cm_buf_ops_t *opsp)
                sectorSize = 1;
 
 #ifndef DJGPP
+        if(buf_cacheType == CM_BUF_CACHETYPE_FILE) {
                /* Reserve buffer space by mapping cache file */
                psa = CreateCacheFileSA();
                hf = CreateFile(cm_CachePath,
@@ -309,6 +311,9 @@ long buf_Init(cm_buf_ops_t *opsp)
                        return CM_ERROR_INVAL;
                }
                FreeCacheFileSA(psa);
+        } else { /* buf_cacheType == CM_BUF_CACHETYPE_VIRTUAL */
+            hf = INVALID_HANDLE_VALUE;
+        }
                CacheHandle = hf;
                hm = CreateFileMapping(hf,
                        NULL,
@@ -327,7 +332,7 @@ long buf_Init(cm_buf_ops_t *opsp)
                        0, 0,
                        buf_nbuffers * buf_bufferSize);
                if (data == NULL) {
-                       CloseHandle(hf);
+                       if(hf != INVALID_HANDLE_VALUE) CloseHandle(hf);
                        CloseHandle(hm);
                        return CM_ERROR_INVAL;
                }
@@ -404,6 +409,15 @@ long buf_AddBuffers(long nbuffers)
     afsi_log("%d buffers being added to the existing cache of size %d",
               nbuffers, buf_nbuffers);
 
+    if (buf_cacheType == CM_BUF_CACHETYPE_VIRTUAL) {
+        /* The size of a virtual cache cannot be changed after it has
+         * been created.  Subsequent calls to MapViewofFile() with
+         * an existing mapping object name would not allow the 
+         * object to be resized.  Return failure immediately.
+        */
+        return CM_ERROR_INVAL;
+    }
+
        /*
         * Cache file mapping constrained by
         * system allocation granularity;
index f37094f..8840aae 100644 (file)
@@ -32,6 +32,11 @@ extern long buf_bufferSize;
 #define CM_BUF_HASHSIZE        1024
 extern long buf_hashSize;
 
+/* cache type */
+#define CM_BUF_CACHETYPE_FILE 1
+#define CM_BUF_CACHETYPE_VIRTUAL 2
+extern int buf_cacheType;
+
 /* force it to be signed so that mod comes out positive or 0 */
 #define BUF_HASH(fidp,offsetp) ((((fidp)->vnode+((fidp)->unique << 5)  \
                                +(fidp)->volume+(fidp)->cell            \