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

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



On 11/02/2026 11:08, 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.
> 
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
> ---
>   src/monitor/monitor.c                        | 67 +++++++++++++++++---
>   vs2019/xenbus_monitor/xenbus_monitor.vcxproj |  2 +-
>   vs2022/xenbus_monitor/xenbus_monitor.vcxproj |  2 +-
>   3 files changed, 59 insertions(+), 12 deletions(-)
> 
> diff --git a/src/monitor/monitor.c b/src/monitor/monitor.c
> index 700f196..eb1be91 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>
>   
> @@ -1328,7 +1330,7 @@ fail1:
>       return FALSE;
>   }
>   
> -static BOOL
> +static VOID
>   RemoveStartOverride(
>       _In_ PTSTR          DriverName
>       )
> @@ -1336,17 +1338,61 @@ RemoveStartOverride(
>       TCHAR               KeyName[MAX_PATH];
>       HRESULT             Error;
>   
> +    LogInfo("%s", DriverName);
> +
>       Error = StringCbPrintf(KeyName,
>                              MAX_PATH,
>                              SERVICES_KEY "\\%s\\StartOverride",

As this is new code, could you wrap this in _T please?

>                              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            hDevInfo;
> +    DWORD               Index;
> +    SP_DEVINFO_DATA     devInfoData;

Nit: DevInfo and DevInfoData would better fit the naming convention

> +
> +    hDevInfo = SetupDiGetClassDevs(Guid,
> +                                   NULL,
> +                                   NULL,
> +                                   0);
> +    if (hDevInfo == INVALID_HANDLE_VALUE)
>           goto fail1;
>   
> -    return TRUE;
> +    memset(&devInfoData, 0, sizeof(devInfoData));
> +    devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
> +
> +    for (Index = 0;
> +         SetupDiEnumDeviceInfo(hDevInfo, Index, &devInfoData);
> +         ++Index) {
> +        TCHAR           Buffer[MAX_PATH];
> +        memset(Buffer, 0, sizeof(Buffer));
> +
> +        if (SetupDiGetDeviceRegistryProperty(hDevInfo,
> +                                             &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(hDevInfo);
> +
> +    return;
>   
>   fail1:
>       Error = GetLastError();
> @@ -1357,8 +1403,6 @@ fail1:
>           LogError("fail1 (%s)", Message);
>           LocalFree(Message);
>       }
> -
> -    return FALSE;
>   }
>   
>   VOID WINAPI
> @@ -1381,7 +1425,8 @@ MonitorMain(
>   
>       LogInfo("====>");
>   
> -    (VOID) RemoveStartOverride("stornvme");
> +    RemoveStartOverride("stornvme");
> +    RemoveStartOverrideForClass(&GUID_DEVCLASS_SCSIADAPTER);
>   
>       Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
>                            PARAMETERS_KEY(__MODULE__),
> @@ -1525,10 +1570,12 @@ done:
>       CloseHandle(Context->RequestEvent);
>       CloseHandle(Context->StopEvent);
>   
> -    ReportStatus(SERVICE_STOPPED, NO_ERROR, 0);
> -
>       RegCloseKey(Context->ParametersKey);
> -    (VOID) RemoveStartOverride("stornvme");
> +
> +    RemoveStartOverride("stornvme");

I don't think RemoveStartOverride("stornvme") is still explicitly needed 
since it's already covered by the SCSIAdapter class even in native NVMe 
mode.

> +    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®.