rx: Remove RX_CALL_BUSY
[openafs.git] / src / WINNT / afsd / afsd_init.c
index 3db3f32..bac4678 100644 (file)
@@ -76,6 +76,12 @@ int cm_readonlyVolumeVersioning = 0;
 int cm_logChunkSize;
 int cm_chunkSize;
 int cm_virtualCache = 0;
+afs_int32 cm_verifyData = 0;
+int cm_shortNames = 1;
+int cm_directIO = 1;
+int cm_volumeInfoReadOnlyFlag = 0;
+
+afs_uint32 rdr_ReparsePointPolicy = 0;
 
 int smb_UseV3 = 1;
 afs_uint32 smb_Enabled = 1;
@@ -103,9 +109,10 @@ BOOL reportSessionStartups = FALSE;
 
 cm_initparams_v1 cm_initParams;
 
-clientchar_t *cm_sysName = 0;
 unsigned int  cm_sysNameCount = 0;
 clientchar_t *cm_sysNameList[MAXNUMSYSNAMES];
+unsigned int  cm_sysName64Count = 0;
+clientchar_t *cm_sysName64List[MAXNUMSYSNAMES];
 
 DWORD TraceOption = 0;
 
@@ -310,9 +317,9 @@ static void afsd_InitServerPreferences(void)
             if ( tsp )         /* an existing server - ref count increased */
             {
                 lock_ObtainMutex(&tsp->mx);
-                tsp->ipRank = (USHORT)dwRank;
+                tsp->adminRank = (USHORT)dwRank;
                 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_PREF_SET);
-               tsp->adminRank = tsp->ipRank;
+                cm_RankServer(tsp);
                 lock_ReleaseMutex(&tsp->mx);
 
                 /* set preferences for an existing vlserver */
@@ -323,9 +330,9 @@ static void afsd_InitServerPreferences(void)
             {
                 tsp = cm_NewServer(&saddr, CM_SERVER_VLDB, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
                 lock_ObtainMutex(&tsp->mx);
-                tsp->ipRank = (USHORT)dwRank;
+                tsp->adminRank = (USHORT)dwRank;
                 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_PREF_SET);
-               tsp->adminRank = tsp->ipRank;
+                cm_RankServer(tsp);
                 lock_ReleaseMutex(&tsp->mx);
             }
         }
@@ -386,9 +393,9 @@ static void afsd_InitServerPreferences(void)
             if ( tsp )         /* an existing server - ref count increased */
             {
                 lock_ObtainMutex(&tsp->mx);
-                tsp->ipRank = (USHORT)dwRank;
+                tsp->adminRank = (USHORT)dwRank;
                _InterlockedOr(&tsp->flags, CM_SERVERFLAG_PREF_SET);
-               tsp->adminRank = tsp->ipRank;
+                cm_RankServer(tsp);
                 lock_ReleaseMutex(&tsp->mx);
 
                 /* find volumes which might have RO copy
@@ -402,9 +409,9 @@ static void afsd_InitServerPreferences(void)
             {
                 tsp = cm_NewServer(&saddr, CM_SERVER_FILE, NULL, NULL, CM_FLAG_NOPROBE); /* refcount = 1 */
                 lock_ObtainMutex(&tsp->mx);
-                tsp->ipRank = (USHORT)dwRank;
+                tsp->adminRank = (USHORT)dwRank;
                 _InterlockedOr(&tsp->flags, CM_SERVERFLAG_PREF_SET);
-               tsp->adminRank = tsp->ipRank;
+                cm_RankServer(tsp);
                 lock_ReleaseMutex(&tsp->mx);
             }
         }
@@ -478,7 +485,7 @@ afsd_InitRoot(char **reasonP)
         cm_SetFid(&cm_data.rootFid, cm_data.rootCellp->cellID, cm_GetROVolumeID(cm_data.rootVolumep), 1, 1);
     }
 
-    code = cm_GetSCache(&cm_data.rootFid, &cm_data.rootSCachep, cm_rootUserp, &req);
+    code = cm_GetSCache(&cm_data.rootFid, NULL, &cm_data.rootSCachep, cm_rootUserp, &req);
     afsi_log("cm_GetSCache code %x scache %x", code,
              (code ? (cm_scache_t *)-1 : cm_data.rootSCachep));
     if (code != 0) {
@@ -526,12 +533,13 @@ afsd_InitCM(char **reasonP)
     /*int freelanceEnabled;*/
     WSADATA WSAjunk;
     int i;
-    int cm_noIPAddr;         /* number of client network interfaces */
-    int cm_IPAddr[CM_MAXINTERFACE_ADDR];    /* client's IP address in host order */
-    int cm_SubnetMask[CM_MAXINTERFACE_ADDR];/* client's subnet mask in host order*/
-    int cm_NetMtu[CM_MAXINTERFACE_ADDR];    /* client's MTU sizes */
-    int cm_NetFlags[CM_MAXINTERFACE_ADDR];  /* network flags */
     DWORD dwPriority;
+    OSVERSIONINFO osVersion;
+
+    /* Get the version of Windows */
+    memset(&osVersion, 0x00, sizeof(osVersion));
+    osVersion.dwOSVersionInfoSize = sizeof(osVersion);
+    GetVersionEx(&osVersion);
 
     WSAStartup(0x0101, &WSAjunk);
 
@@ -609,7 +617,11 @@ afsd_InitCM(char **reasonP)
     dummyLen = sizeof(maxcpus);
     code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL,
                             (BYTE *) &maxcpus, &dummyLen);
-    if (code == ERROR_SUCCESS) {
+    if (code != ERROR_SUCCESS) {
+        maxcpus = 2;
+    }
+
+    {
         HANDLE hProcess;
         DWORD_PTR processAffinityMask, systemAffinityMask;
 
@@ -618,7 +630,7 @@ afsd_InitCM(char **reasonP)
         if ( hProcess != NULL &&
              GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) )
         {
-            int i, n, bits;
+            int i, n, bits, cpu_count = 0;
             DWORD_PTR mask, newAffinityMask;
 
 #if defined(_WIN64)
@@ -626,19 +638,26 @@ afsd_InitCM(char **reasonP)
 #else
             bits = 32;
 #endif
-            for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits && n<maxcpus; i++ ) {
+            for ( i=0, n=0, mask=1, newAffinityMask=0; i<bits; i++ ) {
                 if ( processAffinityMask & mask ) {
-                    newAffinityMask |= mask;
-                    n++;
+                    cpu_count++;
+                    if (n<maxcpus) {
+                        newAffinityMask |= mask;
+                        n++;
+                    }
                 }
                 mask *= 2;
             }
 
-            SetProcessAffinityMask(hProcess, newAffinityMask);
+            if (maxcpus == 0) {
+                afsi_log("No CPU Restrictions; %d cpu(s) available", cpu_count);
+            } else {
+                SetProcessAffinityMask(hProcess, newAffinityMask);
+            }
             CloseHandle(hProcess);
-            afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, n);
+            afsi_log("CPU Restrictions set to %d cpu(s); %d cpu(s) available", maxcpus, cpu_count);
         } else {
-            afsi_log("CPU Restrictions set to %d cpu(s); unable to access process information", maxcpus);
+            afsi_log("CPU Restrictions requested %d cpu(s); unable to access process information", maxcpus);
         }
     }
 
@@ -708,6 +727,19 @@ afsd_InitCM(char **reasonP)
     if (code != ERROR_SUCCESS)
         cacheSize = CM_CONFIGDEFAULT_CACHESIZE;
 
+#if defined(_X86)
+    /*
+     * For 32-bit systems the max process space is 2GB and the
+     * max cache size is the max contiguous free address space.
+     * Since it is too hard to calculate what that is simply
+     * cap the value at 716800.
+     */
+    if (cacheSize > 716800) {
+       afsi_log("Requested Cache size %u", cacheSize);
+       cacheSize = 716800;
+    }
+#endif
+
     if (cm_virtualCache) {
         MEMORYSTATUSEX memStatus;
         DWORD maxCacheSize;
@@ -847,6 +879,17 @@ afsd_InitCM(char **reasonP)
     smb_LogoffTransferTimeout = ltto;
     afsi_log("Logoff token transfer timeout %d seconds", ltto);
 
+    dummyLen = sizeof(cm_NetbiosName);
+    code = RegQueryValueEx(parmKey, "NetbiosName", NULL, NULL,
+                            (LPBYTE) cm_NetbiosName, &dummyLen);
+    if (code == ERROR_SUCCESS)
+        afsi_log("NetbiosName %s", cm_NetbiosName);
+    else {
+        cm_FsStrCpy(cm_NetbiosName, lengthof(cm_NetbiosName), "AFS");
+        afsi_log("Default NetbiosName AFS");
+    }
+    cm_Utf8ToClientString(cm_NetbiosName, -1, cm_NetbiosNameC, MAX_NB_NAME_LENGTH);
+
     dummyLen = sizeof(cm_rootVolumeName);
     code = RegQueryValueEx(parmKey, "RootVolume", NULL, NULL,
                             (LPBYTE) cm_rootVolumeName, &dummyLen);
@@ -917,12 +960,15 @@ afsd_InitCM(char **reasonP)
     for ( i=0; i < MAXNUMSYSNAMES; i++ ) {
         cm_sysNameList[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
         cm_sysNameList[i][0] = '\0';
+        cm_sysName64List[i] = osi_Alloc(MAXSYSNAME * sizeof(clientchar_t));
+        cm_sysName64List[i][0] = '\0';
     }
-    cm_sysName = cm_sysNameList[0];
 
+    /* Process SysName lists from the registry */
     {
         clientchar_t *p, *q;
         clientchar_t * cbuf = (clientchar_t *) buf;
+
         dummyLen = sizeof(buf);
         code = RegQueryValueExW(parmKey, L"SysName", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
         if (code != ERROR_SUCCESS || !cbuf[0]) {
@@ -934,7 +980,7 @@ afsd_InitCM(char **reasonP)
             cm_ClientStrCpy(cbuf, lengthof(buf), _C("x86_win32 i386_w2k i386_nt40"));
 #endif
         }
-        afsi_log("Sys name %S", cbuf);
+        afsi_log("Sys name list: %S", cbuf);
 
         /* breakup buf into individual search string entries */
         for (p = q = cbuf; p < cbuf + dummyLen; p++) {
@@ -944,16 +990,49 @@ afsd_InitCM(char **reasonP)
                 cm_sysNameCount++;
                 do {
                     if (*p == '\0')
-                        goto done_sysname;
+                        goto done_sysname32;
                     p++;
                 } while (*p == '\0' || isspace(*p));
                 q = p;
                 p--;
             }
         }
+      done_sysname32:
+        ;
+
+#ifdef _WIN64
+        /*
+         * If there is a 64-bit list, process it.  Otherwise, we will leave
+         * it undefined which implies that the 32-bit list be used for both.
+         * The 64-bit list is only used for the native file system driver.
+         * The SMB redirector interface does not provide any means of indicating
+         * the source of the request.
+         */
+        dummyLen = sizeof(buf);
+        code = RegQueryValueExW(parmKey, L"SysName64", NULL, NULL, (LPBYTE) cbuf, &dummyLen);
+        if (code == ERROR_SUCCESS && cbuf[0]) {
+            afsi_log("Sys name 64 list: %S", cbuf);
+
+            /* breakup buf into individual search string entries */
+            for (p = q = cbuf; p < cbuf + dummyLen; p++) {
+                if (*p == '\0' || iswspace(*p)) {
+                    memcpy(cm_sysName64List[cm_sysName64Count],q,(p-q) * sizeof(clientchar_t));
+                    cm_sysName64List[cm_sysName64Count][p-q] = '\0';
+                    cm_sysName64Count++;
+                    do {
+                        if (*p == '\0')
+                            goto done_sysname64;
+                        p++;
+                    } while (*p == '\0' || isspace(*p));
+                    q = p;
+                    p--;
+                }
+            }
+        }
+      done_sysname64:
+        ;
+#endif
     }
-  done_sysname:
-    cm_ClientStrCpy(cm_sysName, MAXSYSNAME, cm_sysNameList[0]);
 
     dummyLen = sizeof(cryptall);
     code = RegQueryValueEx(parmKey, "SecurityLevel", NULL, NULL,
@@ -972,7 +1051,12 @@ afsd_InitCM(char **reasonP)
     else
        LogEvent(EVENTLOG_INFORMATION_TYPE, MSG_CRYPT_OFF);
 
-    dummyLen = sizeof(cryptall);
+    dummyLen = sizeof(cm_verifyData);
+    code = RegQueryValueEx(parmKey, "VerifyData", NULL, NULL,
+                           (BYTE *) &cm_verifyData, &dummyLen);
+    afsi_log("VerifyData is %s", cm_verifyData?"on":"off");
+
+    dummyLen = sizeof(cm_anonvldb);
     code = RegQueryValueEx(parmKey, "ForceAnonVLDB", NULL, NULL,
                             (BYTE *) &cm_anonvldb, &dummyLen);
     afsi_log("CM ForceAnonVLDB is %s", cm_anonvldb ? "on" : "off");
@@ -1001,6 +1085,13 @@ afsd_InitCM(char **reasonP)
                             (BYTE *) &cm_freelanceImportCellServDB, &dummyLen);
     afsi_log("Freelance client %s import CellServDB",
               cm_freelanceImportCellServDB ? "does" : "does not");
+
+    dummyLen = sizeof(cm_freelanceDiscovery);
+    code = RegQueryValueEx(parmKey, "FreelanceDiscovery", NULL, NULL,
+                            (BYTE *) &cm_freelanceDiscovery, &dummyLen);
+    afsi_log("Freelance client discovery is %s",
+              cm_freelanceDiscovery ? "on" : "off");
+
 #endif /* AFS_FREELANCE_CLIENT */
 
     dummyLen = sizeof(smb_UseUnicode);
@@ -1291,16 +1382,64 @@ afsd_InitCM(char **reasonP)
     }
     afsi_log("CM ReadOnlyVolumeVersioning is %u", cm_readonlyVolumeVersioning);
 
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "ShortNames", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_shortNames = (unsigned short) dwValue;
+    } else {
+        /* disable by default on Win7, Win 8, Server 2008 R2 and Server 2012 */
+        if (osVersion.dwMajorVersion > 6 ||
+            osVersion.dwMajorVersion == 6 &&
+            osVersion.dwMinorVersion >= 1)
+            cm_shortNames = 0;
+        else
+            cm_shortNames = 1;
+    }
+    afsi_log("CM ShortNames is %u", cm_shortNames);
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "VolumeInfoReadOnlyFlag", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_volumeInfoReadOnlyFlag = (unsigned short) dwValue;
+    } else {
+        /* enable by default on Win 8 and Server 2012 */
+        if (osVersion.dwMajorVersion > 6 ||
+            osVersion.dwMajorVersion == 6 &&
+            osVersion.dwMinorVersion >= 2)
+            cm_volumeInfoReadOnlyFlag = 1;
+        else
+            cm_volumeInfoReadOnlyFlag = 0;
+    }
+    afsi_log("CM VolumeInfoReadOnlyFlag is %u", cm_volumeInfoReadOnlyFlag);
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "DirectIO", NULL, NULL,
+                           (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+        cm_directIO = (unsigned short) dwValue;
+    } else {
+        cm_directIO = 1;
+    }
+    afsi_log("CM DirectIO is %u", cm_directIO);
+
+    dummyLen = sizeof(DWORD);
+    code = RegQueryValueEx(parmKey, "ReparsePointPolicy", NULL, NULL,
+                          (BYTE *) &dwValue, &dummyLen);
+    if (code == ERROR_SUCCESS) {
+       rdr_ReparsePointPolicy = (unsigned short) dwValue;
+    } else {
+       rdr_ReparsePointPolicy = 0;
+    }
+    afsi_log("RDR ReparsePointPolicy is 0x%x", rdr_ReparsePointPolicy);
+
     RegCloseKey (parmKey);
 
     cacheBlocks = ((afs_uint64)cacheSize * 1024) / blockSize;
 
     /* get network related info */
-    cm_noIPAddr = CM_MAXINTERFACE_ADDR;
-    code = syscfg_GetIFInfo(&cm_noIPAddr,
-                             cm_IPAddr, cm_SubnetMask,
-                             cm_NetMtu, cm_NetFlags);
-
+    code = cm_UpdateIFInfo();
     if ( (cm_noIPAddr <= 0) || (code <= 0 ) )
         afsi_log("syscfg_GetIFInfo error code %d", code);
     else
@@ -1308,7 +1447,7 @@ afsd_InitCM(char **reasonP)
                   cm_IPAddr[0], cm_SubnetMask[0]);
 
     /*
-     * Save client configuration for GetCacheConfig requests
+     * Save client configuration for GetCacheConf\eig requests
      */
     cm_initParams.nChunkFiles = 0;
     cm_initParams.nStatCaches = stats;
@@ -1342,6 +1481,9 @@ afsd_InitCM(char **reasonP)
         return -1;
     }
 
+    /* Must be called after cm_InitMappedMemory. */
+    cm_EAccesInitCache();
+
 #if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0500)
     if (cm_InitDNS(cm_dnsEnabled) == -1)
         cm_dnsEnabled = 0;  /* init failed, so deactivate */
@@ -1355,8 +1497,6 @@ afsd_InitCM(char **reasonP)
     }
 
     if ( rx_mtu != -1 ) {
-        extern void rx_SetMaxMTU(int);
-
         rx_SetMaxMTU(rx_mtu);
         afsi_log("rx_SetMaxMTU %d successful", rx_mtu);
     }
@@ -1366,8 +1506,6 @@ afsd_InitCM(char **reasonP)
         afsi_log("rx_SetUdpBufSize %d", rx_udpbufsize);
     }
 
-    rx_SetBusyChannelError(CM_RX_RETRY_BUSY_CALL);
-
     /* initialize RX, and tell it to listen to the callbackport,
      * which is used for callback RPC messages.
      */
@@ -1527,12 +1665,18 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc)
     }
 
     if ( smb_Enabled ) {
-    /* Do this last so that we don't handle requests before init is done.
-     * Here we initialize the SMB listener.
-     */
-    smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
-    afsi_log("smb_Init complete");
+        /* Do this last so that we don't handle requests before init is done.
+         * Here we initialize the SMB listener.
+         */
+        smb_Init(afsd_logp, smb_UseV3, numSvThreads, aMBfunc);
+        afsi_log("smb_Init complete");
     } else {
+        smb_configureBackConnectionHostNames(FALSE);
+
+        if (msftSMBRedirectorSupportsExtendedTimeouts()) {
+            afsi_log("Microsoft SMB Redirector supports Extended Timeouts");
+            smb_configureExtendedSMBSessionTimeouts(FALSE);
+        }
         afsi_log("smb_Init skipped");
     }