[WinOF] Streamline driver uninstall and cleanup to play nicely with MSFT PNP; believe...
authorstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 15 Sep 2009 23:25:25 +0000 (23:25 +0000)
committerstansmith <stansmith@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Tue, 15 Sep 2009 23:25:25 +0000 (23:25 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2433 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

WinOF/WIX/CustomActions.vbs
WinOF/WIX/common/InstallExecuteSeq.inc

index 1abca36..60fe506 100644 (file)
@@ -47,6 +47,46 @@ Const UseDPinst                      = "501" ' use DPinst.exe to install drivers for
 ' Global debug flag: Session.Property from msiexec.exe cmd line DBG=1\r
 Dim sDBG\r
 \r
+\r
+' Write string to MSI log file\r
+\r
+Function MsiLogInfo(msg)\r
+    Dim rec\r
+    Set rec = Session.Installer.CreateRecord(1) \r
+    rec.StringData(0) = msg\r
+    MsiLogInfo = Session.Message(&H04000000, rec)\r
+End Function\r
+\r
+\r
+Sub ShowError()\r
+    If Err.Number = 0 Then\r
+        Exit Sub\r
+    End if\r
+       strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _\r
+                Err.Description & vbCrLf & vbCrLf\r
+       msgbox strMsg\r
+       MsiLogInfo strMsg\r
+\r
+End Sub\r
+\r
+\r
+Sub ErrMsg(msg)\r
+    If Err.Number <> 0 Then\r
+           msgbox msg & vbCrLf & "Err # " & Err.Number & vbCrLf & Err.Description\r
+       Err.clear\r
+    End if\r
+End Sub\r
+\r
+Function ShowErr2(msg)\r
+    If Err.Number <> 0 Then\r
+           strMsg = vbCrLf & "Err # " & Err.Number & vbCrLf & _\r
+                    Err.Description & vbCrLf\r
+           msgbox msg & strMsg\r
+    End if\r
+    ShowErr2=Err.Number\r
+End Function\r
+\r
+\r
 Function Architecture()\r
       Dim Arch,item\r
       For Each item In GetObject("winmgmts:root/cimv2").ExecQuery("SELECT Architecture FROM Win32_Processor")\r
@@ -76,7 +116,6 @@ Function Architecture()
 End Function\r
 \r
 \r
-\r
 ' A CustomAction (CA) that runs after SetupInitialize which sets up\r
 ' CustomAction Data for the defered action DriverInstall().\r
 ' A CA can only see Installer properties through pre-loaded 'CustomActionData'\r
@@ -776,6 +815,7 @@ Function DriverInstall()
                If sDBG >= "1" Then\r
                        msgbox "Local Subnet Management Service [OpenSM] started.",,_\r
                                        "DriverInstall"\r
+                       MsiLogInfo "[DriverInstall] Local Subnet Management Service [OpenSM] started."\r
                End If\r
        End If\r
 \r
@@ -787,12 +827,54 @@ End Function
 \r
 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\r
 \r
-' Find IBA devices using devman.exe\r
+' called from WIX src to Disable/Remove IB devices so actual driver removal\r
+' can proceed correctly.\r
+' Actual driver file cleanup is handled after DIFxApp processing.\r
+' shutdown NetworkDirect & Winsock Direct providers in\r
+' order to remove their references to the rest of the IB stack such that the\r
+' IB stack/drivers can be removed.\r
+\r
+Sub Remove_IB_Devices()  \r
+       Dim WshShell, fso, sInstalldir, sVersionNT, rc\r
+\r
+       Set WshShell = CreateObject("WScript.Shell")\r
+       Set fso = CreateObject("Scripting.FileSystemObject")\r
+\r
+       ' Check if install was done with NODRV=1, if so then nothing to do, exit\r
+       If Session.Property("NODRV") = "1" Then\r
+               Exit Sub\r
+       End If\r
+\r
+       sInstalldir = Session.Property("INSTALLDIR")\r
+       sVersionNT = Session.Property("VersionNT")\r
+\r
+       If fso.FileExists(sInstalldir & "Drivers\net\ndinstall.exe") Then\r
+           rc = WshShell.Run ("cmd.exe /c cd /d " & sInstalldir & _\r
+                              "Drivers\net & ndinstall.exe -q -r", 0, true)\r
+       End If\r
+       \r
+       ' WSD is not supported on XP and should NOT have been installed.\r
+       ' otherwise, remove the WinSock Direct service.\r
+\r
+       If sVersionNT <> WindowsXP Then\r
+               If fso.FileExists(sInstalldir & "installsp.exe") Then\r
+                       rc = WshShell.Run ("cmd.exe /c cd /d " & sInstalldir & _\r
+                                      " & installsp.exe -r", 0, true)\r
+               End If\r
+       End If\r
+\r
+       Uninstall_IB_Devices fso,WshShell,sInstalldir,sVersionNT\r
+\r
+End Sub\r
+\r
+\r
+' Find all IBA devices [IBA,PCI\VEN_15B3,MLX4] using devman.exe\r
+' In devman.exe output, Device tags all start in col #1.\r
 \r
 Function Find_IBA_Devices(WshShell,sInstalldir) \r
        Dim dev\r
 \r
-       Set ibaDevicesExec = WshShell.Exec ("cmd.exe /c cd " & sInstalldir & "Drivers & devman.exe findall * | FIND ""IBA""")\r
+       Set ibaDevicesExec = WshShell.Exec ("cmd.exe /c cd /D " & sInstalldir & "Drivers & devman.exe findall * ")\r
 \r
        ibaDevices = split(ibaDevicesExec.StdOut.ReadAll, vbCrLF)\r
 \r
@@ -800,7 +882,11 @@ Function Find_IBA_Devices(WshShell,sInstalldir)
        dim arrSize\r
        arrSize = 0\r
        For each dev in ibaDevices\r
-               if (Instr(dev,"IBA\") = 1) Then\r
+               If (Instr(dev,"IBA\") = 1) Then\r
+                       arrSize = arrSize + 1\r
+               ElseIf (Instr(dev,"PCI\VEN_15B3") = 1) Then\r
+                       arrSize = arrSize + 1\r
+               ElseIf (Instr(dev,"MLX4") = 1) Then\r
                        arrSize = arrSize + 1\r
                End if\r
        Next\r
@@ -815,7 +901,13 @@ Function Find_IBA_Devices(WshShell,sInstalldir)
        Redim ibaDev(arrSize - 1)\r
        index = 0\r
        For each dev in ibaDevices\r
-               if (Instr(dev,"IBA\") = 1) Then\r
+               If (Instr(dev,"IBA\") = 1) Then\r
+                       ibaDev(index) = dev\r
+                       index = index + 1\r
+               ElseIf (Instr(dev,"PCI\VEN_15B3") = 1) Then\r
+                       ibaDev(index) = dev\r
+                       index = index + 1\r
+               ElseIf (Instr(dev,"MLX4") = 1) Then\r
                        ibaDev(index) = dev\r
                        index = index + 1\r
                End if\r
@@ -976,7 +1068,6 @@ Sub remove_INF_file(WshShell,exe,file)
 End Sub\r
 \r
 \r
-\r
 Sub cleanup_driver_files(fso,WshShell,sInstalldir,tool,VersionNT,devInfo)\r
 \r
        Dim i,Flist,udfCnt\r
@@ -1113,16 +1204,9 @@ End Function
 ' remove IB I/O Unit driver\r
 \r
 Sub    Uninstall_IOU(fso,WshShell,devList,sInstalldir,VersionNT)\r
-       Dim tool\r
 \r
        RemoveDevice fso,WshShell,sInstalldir,devList,"InfiniBand I/O Unit",VersionNT\r
 \r
-       tool = "cmd.exe /c cd /d " & sInstalldir & "Drivers & dpinst.exe "\r
-\r
-       ' dpinst (loads the driver store) not load the driver (no srp/vnic)\r
-\r
-       find_remove_INF_file WshShell,tool,"ib_iou.cat"\r
-\r
 End Sub\r
 \r
 \r
@@ -1158,16 +1242,6 @@ Sub Uninstall_VNIC(fso,WshShell,devices,sInstalldir,VersionNT)
            End if\r
        Next\r
 \r
-       ' use dpinst.exe instead of devman.exe for Windows LongHorn++\r
-       tool = replace(devman,"devman","dpinst")\r
-\r
-       If IsNull(devInfo) Then\r
-               find_remove_INF_file WshShell,tool,"netvnic.cat"\r
-               Exit Sub\r
-       End If\r
-\r
-       cleanup_driver_files fso,WshShell,sInstalldir,tool,VersionNT,devInfo\r
-\r
 End Sub\r
 \r
 \r
@@ -1227,17 +1301,6 @@ Sub Uninstall_SRP(fso,WshShell,devices,sInstalldir,VersionNT)
                Next\r
        Next\r
 \r
-       ' use dpinst.exe instead of devman.exe for Windows LongHorn++\r
-       tool = replace(devman,"devman","dpinst")\r
-\r
-       'No SRP device - check/clear to be safe.\r
-       If IsNull(devInfo) Then\r
-               find_remove_INF_file WshShell,tool,"ibsrp.cat"\r
-               Exit Sub\r
-       End If\r
-\r
-       cleanup_driver_files fso,WshShell,sInstalldir,tool,VersionNT,devInfo\r
-\r
 End Sub\r
 \r
 \r
@@ -1272,45 +1335,6 @@ Sub RemoveDevice(fso,WshShell,sInstalldir,devList,DeviceTag,VersionNT)
            End if\r
        Next\r
 \r
-       ' Only if a device was found\r
-       If IsNull(devInfo) Then\r
-               Exit Sub\r
-       End If\r
-\r
-       ' use dpinst.exe instead of devman.exe for Windows LongHorn++\r
-       tool = replace(devman,"devman","dpinst")\r
-\r
-       cleanup_driver_files fso,WshShell,sInstalldir,tool,VersionNT,devInfo\r
-\r
-End Sub\r
-\r
-\r
-\r
-Sub remove_all_HCA_devices(fso,WshShell,sInstalldir,VersionNT)\r
-\r
-       Dim devman,tool\r
-\r
-       devman = "cmd.exe /c cd /d " & sInstalldir & "Drivers & devman.exe "\r
-\r
-       ' Old (CoInstaller version) ibbus GUID - just in case.\r
-       Return = WshShell.Run (devman & "remove {94F41CED-78EB-407C-B5DF-958040AF0FD8",0,true)\r
-\r
-       RemoveDevice fso,WshShell,sInstalldir,Null,"MLX4\CONNECTX_HCA",VersionNT\r
-\r
-       ' VEN_15B3 covers devices: mthca & mlx4_bus\r
-       RemoveDevice fso,WshShell,sInstalldir,Null,"PCI\VEN_15B3",VersionNT\r
-\r
-       ' use dpinst.exe instead of devman.exe for Windows LongHorn++\r
-       tool = "cmd.exe /c cd /d " & sInstalldir & "Drivers & dpinst.exe "\r
-\r
-       find_remove_INF_file WshShell,tool,"mthca"\r
-       find_remove_INF_file WshShell,tool,"mlx4_hca"\r
-       find_remove_INF_file WshShell,tool,"mlx4_bus"\r
-\r
-       ' catch-all cleanup.\r
-       find_remove_INF_file WshShell,devman,"Mellanox"\r
-       find_remove_INF_file WshShell,devman,"InfiniBand"\r
-\r
 End Sub\r
 \r
 \r
@@ -1319,6 +1343,8 @@ Sub Uninstall_IB_Devices(fso,WshShell,sInstalldir,VersionNT)
        Dim devList\r
 \r
        If (fso.FileExists(sInstalldir & "Drivers\dpinst.exe") = False) Then\r
+        msgbox "Uninstall_IB_Devices() Error " & sInstalldir & _\r
+                               "Drivers\dpinst.exe Not Found?"\r
            Exit Sub ' no reason to continue without the tool.\r
        End if\r
 \r
@@ -1329,7 +1355,7 @@ Sub Uninstall_IB_Devices(fso,WshShell,sInstalldir,VersionNT)
        ' create a list of IBA\* devices via "devcon find"\r
 \r
        devList = Find_IBA_Devices(WshShell,sInstalldir)\r
-       If Not IsNull(devices) Then\r
+       If Not IsNull(devList) Then\r
 \r
                Uninstall_SRP fso,WshShell,devList,sInstalldir,VersionNT\r
 \r
@@ -1341,7 +1367,9 @@ Sub Uninstall_IB_Devices(fso,WshShell,sInstalldir,VersionNT)
                ' remove IPoIB devices\r
                RemoveDevice fso,WshShell,sInstalldir,devList,"IBA\IPOIB",VersionNT\r
 \r
-       End If\r
+       Else\r
+        msgbox "Uninstall_IB_Devices() <NULL> devList?"\r
+    End If\r
 \r
        ' stop the openSM service in case it was started.\r
        Return = WshShell.Run ("cmd.exe /c sc.exe stop opensm", 0, true)\r
@@ -1349,16 +1377,24 @@ Sub Uninstall_IB_Devices(fso,WshShell,sInstalldir,VersionNT)
        ' delete opensm service from registry\r
        Return = WshShell.Run ("cmd.exe /c sc.exe delete opensm", 0, true)\r
 \r
-       remove_all_HCA_devices fso,WshShell,sInstalldir,VersionNT\r
+       ' remove HCA devices\r
+\r
+       RemoveDevice fso,WshShell,sInstalldir,devList,"MLX4\CONNECTX_HCA",VersionNT\r
+\r
+       ' VEN_15B3 covers devices: mthca & mlx4_bus\r
+       RemoveDevice fso,WshShell,sInstalldir,devList,"PCI\VEN_15B3",VersionNT\r
 \r
 End Sub\r
 \r
 \r
 \r
-''''''''''' Driver Uninstall ''''''''''''\r
+''''''''''' Driver Cleanup ''''''''''''\r
+' called from WIX src to cleanup after IB driver uninstall.\r
+' Assumption is NetworkDirect and Winsock Direct have been shutdown to remove\r
+' their IB stack references.\r
 \r
-Sub DriverUninstall()  \r
-       Dim sInstalldir, WshShell, fso, sVersionNT\r
+Sub IB_DriverCleanup()  \r
+       Dim sInstalldir, WshShell, fso, sVersionNT, sRemove,devman, tool\r
 \r
        sInstalldir = Session.Property("INSTALLDIR")\r
 \r
@@ -1378,21 +1414,6 @@ Sub DriverUninstall()
                sRemove = "ALL"\r
        End If\r
 \r
-       If fso.FileExists(sInstalldir & "Drivers\net\ndinstall.exe") Then\r
-           Return = WshShell.Run ("cmd.exe /c cd /d " & sInstalldir & _\r
-                                  "Drivers\net & ndinstall.exe -q -r", 0, true)\r
-       End If\r
-       \r
-       ' WSD is not supported on XP and should NOT have been installed.\r
-       ' otherwise, remove the service: ND (Network Direct) then WinSock Direct.\r
-\r
-       If sVersionNT <> WindowsXP AND fso.FileExists(sInstalldir & "installsp.exe") Then\r
-               Return = WshShell.Run ("cmd.exe /c cd /d " & sInstalldir & _\r
-                                  " & installsp.exe -r", 0, true)\r
-       End If\r
-\r
-       Uninstall_IB_Devices fso,WshShell,sInstalldir,sVersionNT\r
-\r
        ' Remove Service entries from the registry\r
 \r
        DeleteRegKey "System\CurrentControlSet\Services\ibbus"\r
@@ -1457,7 +1478,7 @@ Sub DriverUninstall()
 '      Return = WshShell.Run ("reg.exe delete HKLM\Software\Microsoft\Windows\currentVersion\DIFx\DriverStore\ipoib_* /f", 0, true)\r
 '\r
 \r
-       ' Remove all Local Area Connection registry entries which were constructed\r
+       ' Remove all Local Area Connection Registry entries which were constructed\r
        ' for IPoIB. Next WinOF install gets same IPoIB local area connection\r
        ' assignment.\r
 \r
@@ -1471,11 +1492,33 @@ Sub DriverUninstall()
                End if\r
        Next\r
 \r
+       Session.Property("REBOOT") = "FORCE"\r
+       err.clear \r
+\r
+       ' cleanup INF files\r
+\r
+       If (fso.FileExists(sInstalldir & "Drivers\dpinst.exe") = False) Then\r
+           Exit Sub ' no reason to continue without the tool.\r
+       End if\r
+\r
+       devman = "cmd.exe /c cd /d " & sInstalldir & "Drivers & devman.exe "\r
+\r
+       ' use dpinst.exe instead of devman.exe for Windows LongHorn++\r
+       tool = "cmd.exe /c cd /d " & sInstalldir & "Drivers & dpinst.exe "\r
+\r
+       find_remove_INF_file WshShell,tool,"mthca"\r
+       find_remove_INF_file WshShell,tool,"mlx4_hca"\r
+       find_remove_INF_file WshShell,tool,"mlx4_bus"\r
+\r
+       ' catch-all cleanup.\r
+       find_remove_INF_file WshShell,devman,"Mellanox"\r
+       find_remove_INF_file WshShell,devman,"InfiniBand"\r
+\r
        ' remove driver installed files\r
        RemoveDriverFiles fso,WshShell,sVersionNT \r
        \r
-       Session.Property("REBOOT") = "FORCE"      \r
        err.clear \r
+\r
 End Sub\r
 \r
 \r
@@ -1501,7 +1544,6 @@ Sub WSDEnable()
                Return = WshShell.Run ("cmd.exe /c cd /d " & sInstalldir _\r
                                  & " & installsp.exe -i", 0, true)\r
        End If\r
-       If Err Then ShowError\r
 \r
 End Sub\r
 \r
@@ -1528,32 +1570,6 @@ Sub ND_StartMeUp()
 End Sub\r
 \r
 \r
-Sub ShowError()\r
-    If Err.Number = 0 Then\r
-        Exit Sub\r
-    End if\r
-       strMsg = vbCrLf & "Error # " & Err.Number & vbCrLf & _\r
-                Err.Description & vbCrLf & vbCrLf\r
-       msgbox strMsg\r
-End Sub\r
-\r
-\r
-Sub ErrMsg(msg)\r
-    If Err.Number <> 0 Then\r
-           msgbox msg & vbCrLf & "Err # " & Err.Number & vbCrLf & Err.Description\r
-       Err.clear\r
-    End if\r
-End Sub\r
-\r
-Function ShowErr2(msg)\r
-    If Err.Number <> 0 Then\r
-           strMsg = vbCrLf & "Err # " & Err.Number & vbCrLf & _\r
-                    Err.Description & vbCrLf\r
-           msgbox msg & strMsg\r
-    End if\r
-    ShowErr2=Err.Number\r
-End Function\r
-\r
 \r
 ' Convert the disabled OpenSM Windows service to an 'auto' startup on next boot.\r
 ' OpenSM service was created by WIX installer directives - see WOF.wxs file.\r
@@ -1602,7 +1618,7 @@ End Sub
 ' uninstall.\r
 ' Called in immediate mode, condition: INSTALL=1\r
 \r
-Function ChkInstallAndReboot()\r
+Function ChkPreviousInstall()\r
 \r
     Set fso = CreateObject("Scripting.FileSystemObject")    \r
     Set WshShell = CreateObject("WScript.Shell")\r
@@ -1617,7 +1633,7 @@ Function ChkInstallAndReboot()
        ' remove any lingering driver installed files\r
        RemoveDriverFiles fso,WshShell,VersionNT \r
        \r
-       ChkInstallAndReboot = 0\r
+       ChkPreviousInstall = 0\r
 \r
 End Function\r
 \r
@@ -1704,7 +1720,9 @@ Sub HammerTime
         rc = wshShell.Run(cmd,0,true)\r
     End if\r
 \r
-    RemoveFolder "C:\IBSDK"\r
+    If fso.FolderExists("C:\IBSDK") Then\r
+       RemoveFolder "C:\IBSDK"\r
+    End if\r
 \r
 End Sub\r
 \r
index f8bb552..e7dd4c5 100644 (file)
@@ -7,19 +7,24 @@
          VBScriptCall="WinOF_setup" Return="check" />\r
 \r
     <CustomAction Id="ChkPreviousInstall" BinaryKey="CA"\r
-         VBScriptCall="ChkInstallAndReboot" Return="check" />\r
+         VBScriptCall="ChkPreviousInstall" Return="check" />\r
 \r
     <CustomAction Id="DriverInstall" BinaryKey="CA"\r
          VBScriptCall="DriverInstall" Return="check" Execute="deferred" />\r
 \r
-    <CustomAction Id="DriverUninstall" BinaryKey="CA"\r
-         VBScriptCall="DriverUninstall" Return="check" />\r
+    <CustomAction Id="Remove_IB_Devices" BinaryKey="CA"\r
+         VBScriptCall="Remove_IB_Devices" Return="check" />\r
+\r
+    <CustomAction Id="IB_DriverCleanup" BinaryKey="CA"\r
+         VBScriptCall="IB_DriverCleanup" Return="check" />\r
 \r
     <CustomAction Id="WSDStart" BinaryKey="CA"\r
          VBScriptCall="WSDEnable" Return="check" />\r
 \r
+<?if $(var.ARCHP) != "ia64" ?>\r
     <CustomAction Id="ND_start" BinaryKey="CA"\r
          VBScriptCall="ND_StartMeUp" Return="check" />\r
+<?endif?>\r
 \r
     <CustomAction Id="HammerTime" BinaryKey="CA"\r
          VBScriptCall="HammerTime" Return="check" />\r
        <Custom Action="ChkPreviousInstall" After='WinOF_setup'>\r
                NOT Installed AND Not NODRV </Custom>\r
 \r
-       <ScheduleReboot After='ChkPreviousInstall'>\r
-               REBOOT="FORCE"</ScheduleReboot>\r
-\r
        <Custom Action="DriverInstall" After='InstallServices'>\r
                Not Installed AND Not NODRV </Custom>\r
 \r
        <Custom Action="WSDStart" After="InstallFinalize">\r
                Not Installed AND Not NODRV </Custom>\r
 \r
+<?if $(var.ARCHP) != "ia64" ?>\r
        <Custom Action="ND_start" After="WSDStart">\r
           ($cNetworkDirect = 3) AND Not Installed AND Not NODRV </Custom>\r
 \r
        <Custom Action="BcastRegChanged" After="ND_start">\r
                Not Installed</Custom>\r
+<?else?>\r
+       <Custom Action="BcastRegChanged" After="WSDStart">\r
+               Not Installed</Custom>\r
+<?endif?>\r
 \r
        <!--> CHANGE ONLY </!-->\r
        <Custom Action="InstallChanged" After="InstallFinalize">\r
            Installed </Custom>\r
 \r
        <!--> REMOVE ONLY </!-->\r
-       <Custom Action="DriverUninstall" After="PublishProduct">\r
+       <Custom Action="Remove_IB_Devices" Before="MsiProcessDrivers">\r
+               REMOVE="ALL" AND Not NODRV </Custom>\r
+\r
+       <Custom Action="IB_DriverCleanup" After="MsiCleanupOnSuccess">\r
                REMOVE="ALL" AND Not NODRV </Custom>\r
 \r
-       <Custom Action="HammerTime" After="InstallFinalize">REMOVE="ALL"</Custom>\r
+       <Custom Action="HammerTime" After="IB_DriverCleanup">\r
+               REMOVE="ALL" </Custom>\r
 \r
     </InstallExecuteSequence>\r
 \r