dnlc-optimize-20041102
authorJeffrey Altman <jaltman@mit.edu>
Tue, 2 Nov 2004 06:10:29 +0000 (06:10 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Tue, 2 Nov 2004 06:10:29 +0000 (06:10 +0000)
 * Optimize calls to the DNLC.  Do not search if the FID is the Freelance
   root.afs volume.  Do not search if we are looking for the magic
   _._AFS_IOCTL_._ name.

 * Enable Buffer Trace logs in debug builds.

src/WINNT/afsd/afsd.c
src/WINNT/afsd/afsd95.c
src/WINNT/afsd/afsd_service.c
src/WINNT/afsd/cm_buf.c
src/WINNT/afsd/cm_buf.h
src/WINNT/afsd/cm_ioctl.c
src/WINNT/afsd/cm_vnodeops.c
src/WINNT/afsd/smb.c
src/WINNT/afsd/smb3.c

index 8e29f67..d8661eb 100644 (file)
@@ -53,6 +53,7 @@ void afsd_notifier(char *msgp, char *filep, long line)
        MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);
 
        afsd_ForceTrace(TRUE);
+        buf_ForceTrace(TRUE);
 
        if (traceOnPanic) {
                _asm int 3h;
index 75cd53a..2b77da3 100644 (file)
@@ -52,6 +52,7 @@ void afsd_notifier(char *msgp, char *filep, long line)
        /*MessageBox(NULL, tbuffer, msgp, MB_OK|MB_ICONSTOP|MB_SETFOREGROUND);*/
 
        afsd_ForceTrace(TRUE);
+        buf_ForceTrace(TRUE);
 
        if (traceOnPanic) {
                /*asm("int 3");*/
index 43fcb78..d9236c3 100644 (file)
@@ -82,6 +82,7 @@ static void afsd_notifier(char *msgp, char *filep, long line)
     osi_LogEnable(afsd_logp);
 
     afsd_ForceTrace(TRUE);
+    buf_ForceTrace(TRUE);
 
     afsi_log("--- begin dump ---");
     cm_DumpSCache(afsi_file, "a");
@@ -176,8 +177,10 @@ afsd_ServiceControlHandler(DWORD ctrlCode)
         RegCloseKey (parmKey);
         if (code != ERROR_SUCCESS)
             doTrace = 0;
-        if (doTrace)
+        if (doTrace) {
             afsd_ForceTrace(FALSE);
+            buf_ForceTrace(FALSE);
+        }
 
       doneTrace:
         ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
@@ -239,8 +242,10 @@ afsd_ServiceControlHandlerEx(
         RegCloseKey (parmKey);
         if (code != ERROR_SUCCESS)
             doTrace = 0;
-        if (doTrace)
+        if (doTrace) {
             afsd_ForceTrace(FALSE);
+            buf_ForceTrace(FALSE);
+        }
 
       doneTrace:
         ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
index 9fef57d..06c9cc1 100644 (file)
 #include <malloc.h>
 #include <stdio.h>
 #include <assert.h>
+#include <strsafe.h>
 
 #include "afsd.h"
 
+#ifdef DEBUG
+#define TRACE_BUFFER 1
+#endif
+
 extern void afsi_log(char *pattern, ...);
 
 /* This module implements the buffer package used by the local transaction
@@ -306,12 +311,12 @@ long buf_Init(cm_buf_ops_t *opsp)
                              OPEN_ALWAYS,
                              FILE_ATTRIBUTE_NORMAL,
                              NULL);
+            FreeCacheFileSA(psa);
             if (hf == INVALID_HANDLE_VALUE) {
                 afsi_log("Error creating cache file \"%s\" error %d", 
                           cm_CachePath, GetLastError());
                 return CM_ERROR_INVAL;
             }
-            FreeCacheFileSA(psa);
         } else { /* buf_cacheType == CM_BUF_CACHETYPE_VIRTUAL */
             hf = INVALID_HANDLE_VALUE;
         }
@@ -378,8 +383,11 @@ long buf_Init(cm_buf_ops_t *opsp)
         /* just for safety's sake */
         buf_maxReservedBufs = buf_nbuffers - 3;
 
+#ifdef TRACE_BUFFER
         /* init the buffer trace log */
-        buf_logp = osi_LogCreate("buffer", 10);
+        buf_logp = osi_LogCreate("buffer", 1000);
+        osi_LogEnable(buf_logp);
+#endif
 
         osi_EndOnce(&once);
 
@@ -532,7 +540,7 @@ void buf_WaitIO(cm_buf_t *bp)
         bp->flags |= CM_BUF_WAITING;
         osi_SleepM((long) bp, &bp->mx);
         lock_ObtainMutex(&bp->mx);
-               osi_Log1(buf_logp, "buf_WaitIO conflict wait done for 0x%x", bp);
+        osi_Log1(buf_logp, "buf_WaitIO conflict wait done for 0x%x", bp);
     }
         
     /* if we get here, the IO is done, but we may have to wakeup people waiting for
@@ -1481,3 +1489,24 @@ int cm_DumpBufHashTable(FILE *outputFile, char *cookie)
     return 0;
 }
 
+void buf_ForceTrace(BOOL flush)
+{
+    HANDLE handle;
+    int len;
+    char buf[256];
+
+    if (!buf_logp) 
+        return;
+
+    len = GetTempPath(sizeof(buf)-10, buf);
+    StringCbCopyA(&buf[len], sizeof(buf)-len, "/afs-buffer.log");
+    handle = CreateFile(buf, GENERIC_WRITE, FILE_SHARE_READ,
+                           NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+    if (handle == INVALID_HANDLE_VALUE) {
+        osi_panic("Cannot create log file", __FILE__, __LINE__);
+    }
+    osi_LogPrint(buf_logp, handle);
+    if (flush)
+        FlushFileBuffers(handle);
+    CloseHandle(handle);
+}
index 4ca977a..1f1bc42 100644 (file)
@@ -195,6 +195,8 @@ extern long buf_FlushCleanPages(cm_scache_t *scp, cm_user_t *userp,
 
 extern long buf_SetNBuffers(long nbuffers);
 
+extern void buf_ForceTrace(BOOL flush);
+
 /* error codes */
 #define CM_BUF_EXISTS  1       /* buffer exists, and shouldn't */
 #define CM_ERROR_BASEBUF       0x33333333
index 89973b9..bb60b77 100644 (file)
@@ -996,6 +996,7 @@ long cm_IoctlTraceControl(struct smb_ioctl *ioctlp, struct cm_user *userp)
     /* print trace */
     if (inValue & 8) {
         afsd_ForceTrace(FALSE);
+        buf_ForceTrace(FALSE);
     }
         
     if (inValue & 2) {
index dcb48f0..e14de57 100644 (file)
@@ -427,6 +427,9 @@ long cm_CheckNTDelete(cm_scache_t *dscp, cm_scache_t *scp, cm_user_t *userp,
  * Iterate through all entries in a directory.
  * When the function funcp is called, the buffer is locked but the
  * directory vnode is not.
+ *
+ * If the retscp parameter is not NULL, the parmp must be a 
+ * cm_lookupSearch_t object.  
  */
 long cm_ApplyDir(cm_scache_t *scp, cm_DirFuncp_t funcp, void *parmp,
                   osi_hyper_t *startOffsetp, cm_user_t *userp, cm_req_t *reqp,
@@ -465,17 +468,26 @@ long cm_ApplyDir(cm_scache_t *scp, cm_DirFuncp_t funcp, void *parmp,
     if (retscp)                        /* if this is a lookup call */
     {
         cm_lookupSearch_t*     sp = parmp;
-        int casefold = sp->caseFold;
-
-        sp->caseFold = 0; /* we have a strong preference for exact matches */
-        if ( *retscp = cm_dnlcLookup(scp, sp)) /* dnlc hit */
-        {
-            sp->caseFold = casefold;
-            lock_ReleaseMutex(&scp->mx);
-            return 0;
-        }
 
-        sp->caseFold = casefold;
+#ifdef AFS_FREELANCE_CLIENT
+       /* Freelance entries never end up in the DNLC because they
+        * do not have an associated cm_server_t
+        */
+    if ( !(cm_freelanceEnabled &&
+                       sp->fid.cell==AFS_FAKE_ROOT_CELL_ID &&
+                       sp->fid.volume==AFS_FAKE_ROOT_VOL_ID ) )
+#endif /* AFS_FREELANCE_CLIENT */
+               {
+               int casefold = sp->caseFold;
+                       sp->caseFold = 0; /* we have a strong preference for exact matches */
+                       if ( *retscp = cm_dnlcLookup(scp, sp))  /* dnlc hit */
+                       {
+                               sp->caseFold = casefold;
+                               lock_ReleaseMutex(&scp->mx);
+                               return 0;
+                       }
+               sp->caseFold = casefold;
+               }
     }  
 
     /*
@@ -1097,6 +1109,13 @@ long cm_Lookup(cm_scache_t *dscp, char *namep, long flags, cm_user_t *userp,
     int sysNameIndex = 0;
     cm_scache_t *scp = 0;
 
+    if ( stricmp(namep,SMB_IOCTL_FILENAME_NOSLASH) == 0 ) {
+        if (flags & CM_FLAG_CHECKPATH)
+            return CM_ERROR_NOSUCHPATH;
+        else
+            return CM_ERROR_NOSUCHFILE;
+    }
+
     for ( sysNameIndex = 0; sysNameIndex < MAXNUMSYSNAMES; sysNameIndex++) {
         code = cm_ExpandSysName(namep, tname, sizeof(tname), sysNameIndex);
         if (code > 0) {
@@ -1660,11 +1679,10 @@ void cm_TryBulkStat(cm_scache_t *dscp, osi_hyper_t *offsetp, cm_user_t *userp,
     bb.counter = 0;
     bb.bufOffset = *offsetp;
 
-       lock_ReleaseMutex(&dscp->mx);
+    lock_ReleaseMutex(&dscp->mx);
     /* first, assemble the file IDs we need to stat */
-    code = cm_ApplyDir(dscp, cm_TryBulkProc, (void *) &bb, offsetp, userp,
-                        reqp, NULL);
-       lock_ObtainMutex(&dscp->mx);
+    code = cm_ApplyDir(dscp, cm_TryBulkProc, (void *) &bb, offsetp, userp, reqp, NULL);
+    lock_ObtainMutex(&dscp->mx);
 
     /* if we failed, bail out early */
     if (code && code != CM_ERROR_STOPNOW) return;
index feb941e..ebea271 100644 (file)
@@ -1311,7 +1311,7 @@ long smb_FindShareProc(cm_scache_t *scp, cm_dirEntry_t *dep, void *rockp,
 {
     int matchType = 0;
     smb_findShare_rock_t * vrock = (smb_findShare_rock_t *) rockp;
-    if(!strnicmp(dep->name, vrock->shareName, 12)) {
+    if (!strnicmp(dep->name, vrock->shareName, 12)) {
         if(!stricmp(dep->name, vrock->shareName))
             matchType = SMB_FINDSHARE_EXACT_MATCH;
         else
@@ -1475,7 +1475,7 @@ int smb_FindShare(smb_vc_t *vcp, smb_user_t *uidp, char *shareName,
             (uidp? (uidp->unp ? uidp->unp->userp : NULL) : NULL), &req, NULL);
         cm_ReleaseSCache(cm_rootSCachep);
 
-        if(vrock.matchType) {
+        if (vrock.matchType) {
             sprintf(pathName,"/%s/",vrock.match);
             *pathNamep = strdup(strlwr(pathName));
             free(vrock.match);
@@ -4950,8 +4950,7 @@ void smb_FullName(cm_scache_t *dscp, cm_scache_t *scp, char *pathp,
     rock.name = pathp;
     rock.vnode = scp;
 
-    code = cm_ApplyDir(dscp, smb_FullNameProc, &rock, NULL, 
-                       userp, reqp, NULL); 
+    code = cm_ApplyDir(dscp, smb_FullNameProc, &rock, NULL, userp, reqp, NULL); 
     if (code == CM_ERROR_STOPNOW)
         *newPathp = rock.fullName;
     else
@@ -6965,6 +6964,7 @@ DWORD smb_ServerExceptionFilter(void) {
     }
 
     afsd_ForceTrace(TRUE);
+    buf_ForceTrace(TRUE);
     return EXCEPTION_CONTINUE_SEARCH;
 }       
 #endif
index ea89009..980da2c 100644 (file)
@@ -2488,8 +2488,7 @@ long cm_GetShortName(char *pathp, cm_user_t *userp, cm_req_t *reqp,
     rock.shortName = shortName;
     rock.vnode = vnode;
     rock.maskp = lastNamep;
-    code = cm_ApplyDir(dscp, cm_GetShortNameProc, &rock, &thyper, userp,
-                        reqp, NULL);
+    code = cm_ApplyDir(dscp, cm_GetShortNameProc, &rock, &thyper, userp, reqp, NULL);
 
     cm_ReleaseSCache(dscp);