|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 4/4] Remove StartOverride from all storage adapters
Its possible to install non-Microsoft NVMe drivers on the emulated
NVMe device. During upgrades, the VM requires a reboot using the emulated
devices, but if the driver assigned for the emulated device has a StartOverride
setting, then its likely not started which results in a 0x7B bugcheck.
Also reports SERVICE_STOPPED after clearing any StartOverride values
Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
src/monitor/monitor.c | 64 +++++++++++++++++---
vs2019/xenbus_monitor/xenbus_monitor.vcxproj | 2 +-
vs2022/xenbus_monitor/xenbus_monitor.vcxproj | 2 +-
3 files changed, 56 insertions(+), 12 deletions(-)
diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
index c568d54..9bfb1f6 100644
--- a/src/monitor/monitor.c
+++ b/src/monitor/monitor.c
@@ -42,6 +42,8 @@
#include <assert.h>
#include <TraceLoggingProvider.h>
#include <winmeta.h>
+#include <setupapi.h>
+#include <devguid.h>
#include <version.h>
@@ -1326,7 +1328,7 @@ fail1:
return FALSE;
}
-static BOOL
+static VOID
RemoveStartOverride(
_In_ PTSTR DriverName
)
@@ -1334,17 +1336,61 @@ RemoveStartOverride(
TCHAR KeyName[MAX_PATH];
HRESULT Error;
+ LogInfo("%s", DriverName);
+
Error = StringCchPrintf(KeyName,
MAX_PATH,
_T(SERVICES_KEY "\\%s\\StartOverride"),
DriverName);
assert(SUCCEEDED(Error));
- Error = RegDeleteKey(HKEY_LOCAL_MACHINE, KeyName);
- if (Error != ERROR_SUCCESS)
+ (VOID) RegDeleteKey(HKEY_LOCAL_MACHINE, KeyName);
+}
+
+static VOID
+RemoveStartOverrideForClass(
+ _In_ const GUID* Guid
+ )
+{
+ HRESULT Error;
+ HDEVINFO DevInfo;
+ DWORD Index;
+ SP_DEVINFO_DATA DevInfoData;
+
+ DevInfo = SetupDiGetClassDevs(Guid,
+ NULL,
+ NULL,
+ 0);
+ if (DevInfo == INVALID_HANDLE_VALUE)
goto fail1;
- return TRUE;
+ memset(&DevInfoData, 0, sizeof(DevInfoData));
+ DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+
+ for (Index = 0;
+ SetupDiEnumDeviceInfo(DevInfo, Index, &DevInfoData);
+ ++Index) {
+ TCHAR Buffer[MAX_PATH];
+ memset(Buffer, 0, sizeof(Buffer));
+
+ if (SetupDiGetDeviceRegistryProperty(DevInfo,
+ &DevInfoData,
+ SPDRP_SERVICE,
+ NULL,
+ (PBYTE)Buffer,
+ sizeof(Buffer),
+ NULL)) {
+ Buffer[MAX_PATH - 1] = _T('\0');
+ RemoveStartOverride(Buffer);
+ }
+
+ memset(&DevInfoData, 0, sizeof(DevInfoData));
+ DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+ }
+
+ SetupDiDestroyDeviceInfoList(DevInfo);
+
+ return;
fail1:
Error = GetLastError();
@@ -1355,8 +1401,6 @@ fail1:
LogError("fail1 (%s)", Message);
LocalFree(Message);
}
-
- return FALSE;
}
VOID WINAPI
@@ -1379,7 +1423,7 @@ MonitorMain(
LogInfo("====>");
- (VOID) RemoveStartOverride(_T("stornvme"));
+ RemoveStartOverrideForClass(&GUID_DEVCLASS_SCSIADAPTER);
Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
_T(PARAMETERS_KEY(__MODULE__)),
@@ -1523,10 +1567,10 @@ done:
CloseHandle(Context->RequestEvent);
CloseHandle(Context->StopEvent);
- ReportStatus(SERVICE_STOPPED, NO_ERROR, 0);
-
RegCloseKey(Context->ParametersKey);
- (VOID) RemoveStartOverride(_T("stornvme"));
+ RemoveStartOverrideForClass(&GUID_DEVCLASS_SCSIADAPTER);
+
+ ReportStatus(SERVICE_STOPPED, NO_ERROR, 0);
LogInfo("<====");
diff --git a/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
b/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
index 3b44e29..df1fd58 100644
--- a/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
+++ b/vs2019/xenbus_monitor/xenbus_monitor.vcxproj
@@ -34,7 +34,7 @@
<RuntimeLibrary
Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
-
<AdditionalDependencies>powrprof.lib;wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+
<AdditionalDependencies>powrprof.lib;wtsapi32.lib;cfgmgr32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<CETCompat>true</CETCompat>
<GenerateMapFile>true</GenerateMapFile>
<MapExports>true</MapExports>
diff --git a/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
b/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
index 484fa1c..196a744 100644
--- a/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
+++ b/vs2022/xenbus_monitor/xenbus_monitor.vcxproj
@@ -34,7 +34,7 @@
<RuntimeLibrary
Condition="'$(UseDebugLibraries)'=='false'">MultiThreaded</RuntimeLibrary>
</ClCompile>
<Link>
-
<AdditionalDependencies>powrprof.lib;wtsapi32.lib;cfgmgr32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+
<AdditionalDependencies>powrprof.lib;wtsapi32.lib;cfgmgr32.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<CETCompat>true</CETCompat>
<GenerateMapFile>true</GenerateMapFile>
<MapExports>true</MapExports>
--
2.51.2.windows.1
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |