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