[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/4] Remove StartOverride from all storage adapters



On 13/02/2026 14:50, Owen Smith wrote:
> 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>

Reviewed-by: Tu Dinh <ngoc-tu.dinh@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>



--
Ngoc Tu Dinh | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.