rx: Remove RX_CALL_BUSY
[openafs.git] / src / WINNT / afsd / afsd_init.c
index dcf1004..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;
@@ -311,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 */
@@ -324,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);
             }
         }
@@ -387,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
@@ -403,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);
             }
         }
@@ -479,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) {
@@ -527,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);
 
@@ -610,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;
 
@@ -619,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)
@@ -627,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);
         }
     }
 
@@ -709,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;
@@ -848,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);
@@ -1009,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");
@@ -1038,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);
@@ -1328,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
@@ -1345,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;
@@ -1379,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 */
@@ -1392,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);
     }
@@ -1403,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.
      */
@@ -1570,6 +1671,12 @@ int afsd_InitSMB(char **reasonP, void *aMBfunc)
         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");
     }