[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH] Move interface subscription code into co-installer
Interface subscription is better handled at package installation time and therefore the co-installer is the right place for it to live. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- src/coinst/coinst.c | 174 +++++++++++++++++++++++++++++ src/xenbus/fdo.c | 87 ++------------- vs2012/xenbus_coinst/xenbus_coinst.vcxproj | 2 +- vs2013/xenbus_coinst/xenbus_coinst.vcxproj | 4 +- 4 files changed, 184 insertions(+), 83 deletions(-) diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c index 59726f5..bc33182 100644 --- a/src/coinst/coinst.c +++ b/src/coinst/coinst.c @@ -1901,6 +1901,176 @@ fail1: return FALSE; } +static HKEY +OpenInterfacesKey( + IN PTCHAR ProviderName + ) +{ + HRESULT Result; + TCHAR KeyName[MAX_PATH]; + HKEY Key; + HRESULT Error; + + Result = StringCbPrintf(KeyName, + MAX_PATH, + "%s\\%s\\Interfaces", + SERVICES_KEY, + ProviderName); + if (!SUCCEEDED(Result)) { + SetLastError(ERROR_BUFFER_OVERFLOW); + goto fail1; + } + + Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE, + KeyName, + 0, + KEY_ALL_ACCESS, + &Key); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail2; + } + + return Key; + +fail2: + Log("fail2"); + +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return NULL; +} + +static BOOLEAN +SubscribeInterface( + IN PTCHAR ProviderName, + IN PTCHAR SubscriberName, + IN PTCHAR InterfaceName, + IN DWORD InterfaceVersion + ) +{ + HKEY Key; + HKEY InterfacesKey; + HRESULT Error; + + InterfacesKey = OpenInterfacesKey(ProviderName); + if (InterfacesKey == NULL) + goto fail1; + + Error = RegCreateKeyEx(InterfacesKey, + SubscriberName, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + KEY_ALL_ACCESS, + NULL, + &Key, + NULL); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail2; + } + + Error = RegSetValueEx(Key, + InterfaceName, + 0, + REG_DWORD, + (const BYTE *)&InterfaceVersion, + sizeof(DWORD)); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail3; + } + + Log("%s: %s_%s_INTERFACE_VERSION %u", + SubscriberName, + ProviderName, + InterfaceName, + InterfaceVersion); + + RegCloseKey(Key); + RegCloseKey(InterfacesKey); + + return TRUE; + +fail3: + RegCloseKey(Key); + +fail2: + RegCloseKey(InterfacesKey); + +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return FALSE; +} + +#define SUBSCRIBE_INTERFACE(_ProviderName, _SubscriberName, _InterfaceName) \ + do { \ + (VOID) SubscribeInterface(#_ProviderName, \ + #_SubscriberName, \ + #_InterfaceName, \ + _ProviderName ## _ ## _InterfaceName ## _INTERFACE_VERSION_MAX); \ + } while (FALSE); + +static BOOLEAN +UnsubscribeInterfaces( + IN PTCHAR ProviderName, + IN PTCHAR SubscriberName + ) +{ + HKEY InterfacesKey; + HRESULT Error; + + Log("%s: %s", SubscriberName, ProviderName); + + InterfacesKey = OpenInterfacesKey(ProviderName); + if (InterfacesKey == NULL) { + goto fail1; + } + + Error = RegDeleteTree(InterfacesKey, + SubscriberName); + if (Error != ERROR_SUCCESS) { + SetLastError(Error); + goto fail2; + } + + RegCloseKey(InterfacesKey); + + return TRUE; + +fail2: + RegCloseKey(InterfacesKey); + +fail1: + Error = GetLastError(); + + { + PTCHAR Message; + Message = GetErrorMessage(Error); + Log("fail1 (%s)", Message); + LocalFree(Message); + } + + return FALSE; +} + static HRESULT DifInstallPreProcess( IN HDEVINFO DeviceInfoSet, @@ -2031,6 +2201,8 @@ DifInstallPostProcess( } if (Active) { + SUBSCRIBE_INTERFACE(XENFILT, XENBUS, UNPLUG); + (VOID) InstallFilter(&GUID_DEVCLASS_SYSTEM, "XENFILT"); (VOID) InstallFilter(&GUID_DEVCLASS_HDC, "XENFILT"); } @@ -2167,6 +2339,8 @@ DifRemovePreProcess( (VOID) RemoveFilter(&GUID_DEVCLASS_HDC, "XENFILT"); (VOID) RemoveFilter(&GUID_DEVCLASS_SYSTEM, "XENFILT"); + + UnsubscribeInterfaces("XENFILT", "XENBUS"); } free(DeviceID); diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c index cc0c775..1a122c0 100644 --- a/src/xenbus/fdo.c +++ b/src/xenbus/fdo.c @@ -4341,13 +4341,9 @@ FdoReleaseLowerBusInterface( RtlZeroMemory(BusInterface, sizeof (BUS_INTERFACE_STANDARD)); } -#define SERVICES_KEY L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services" - static NTSTATUS FdoQueryInterface( IN PXENBUS_FDO Fdo, - IN const WCHAR *ProviderName, - IN const CHAR *InterfaceName, IN const GUID *Guid, IN ULONG Version, OUT PINTERFACE Interface, @@ -4355,9 +4351,6 @@ FdoQueryInterface( IN BOOLEAN Optional ) { - UNICODE_STRING Unicode; - HANDLE InterfacesKey; - HANDLE SubscriberKey; KEVENT Event; IO_STATUS_BLOCK StatusBlock; PIRP Irp; @@ -4366,38 +4359,6 @@ FdoQueryInterface( ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL); - Unicode.MaximumLength = (USHORT)((wcslen(SERVICES_KEY) + - 1 + - wcslen(ProviderName) + - 1 + - wcslen(L"Interfaces") + - 1) * sizeof (WCHAR)); - - Unicode.Buffer = __FdoAllocate(Unicode.MaximumLength); - - status = STATUS_NO_MEMORY; - if (Unicode.Buffer == NULL) - goto fail1; - - status = RtlStringCbPrintfW(Unicode.Buffer, - Unicode.MaximumLength, - SERVICES_KEY L"\\%ws\\Interfaces", - ProviderName); - ASSERT(NT_SUCCESS(status)); - - Unicode.Length = (USHORT)(wcslen(Unicode.Buffer) * sizeof (WCHAR)); - - status = RegistryOpenKey(NULL, &Unicode, KEY_READ, &InterfacesKey); - if (!NT_SUCCESS(status)) - goto fail2; - - status = RegistryCreateSubKey(InterfacesKey, - "XENBUS", - REG_OPTION_NON_VOLATILE, - &SubscriberKey); - if (!NT_SUCCESS(status)) - goto fail3; - KeInitializeEvent(&Event, NotificationEvent, FALSE); RtlZeroMemory(&StatusBlock, sizeof(IO_STATUS_BLOCK)); @@ -4411,7 +4372,7 @@ FdoQueryInterface( status = STATUS_UNSUCCESSFUL; if (Irp == NULL) - goto fail4; + goto fail1; StackLocation = IoGetNextIrpStackLocation(Irp); StackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE; @@ -4437,45 +4398,15 @@ FdoQueryInterface( if (status == STATUS_NOT_SUPPORTED && Optional) goto done; - goto fail5; + goto fail2; } - status = RegistryUpdateDwordValue(SubscriberKey, - (PCHAR)InterfaceName, - Version); - if (!NT_SUCCESS(status)) - goto fail6; - done: - RegistryCloseKey(SubscriberKey); - - RegistryCloseKey(InterfacesKey); - - __FdoFree(Unicode.Buffer); - return STATUS_SUCCESS; -fail6: - Error("fail6\n"); - -fail5: - Error("fail5\n"); - -fail4: - Error("fail4\n"); - - RegistryCloseKey(SubscriberKey); - -fail3: - Error("fail3\n"); - - RegistryCloseKey(InterfacesKey); - fail2: Error("fail2\n"); - __FdoFree(Unicode.Buffer); - fail1: Error("fail1 (%08x)\n", status); @@ -4486,18 +4417,15 @@ fail1: _Fdo, \ _ProviderName, \ _InterfaceName, \ - _Version, \ _Interface, \ _Size, \ _Optional) \ FdoQueryInterface((_Fdo), \ - L ## #_ProviderName, \ - #_InterfaceName, \ - &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \ - (_Version), \ - (_Interface), \ - (_Size), \ - (_Optional)) + &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \ + _ProviderName ## _ ## _InterfaceName ## _INTERFACE_VERSION_MAX, \ + (_Interface), \ + (_Size), \ + (_Optional)) VOID FdoGetUnplugInterface( @@ -4695,7 +4623,6 @@ FdoCreate( status = FDO_QUERY_INTERFACE(Fdo, XENFILT, UNPLUG, - XENFILT_UNPLUG_INTERFACE_VERSION_MAX, (PINTERFACE)&Fdo->UnplugInterface, sizeof (Fdo->UnplugInterface), TRUE); diff --git a/vs2012/xenbus_coinst/xenbus_coinst.vcxproj b/vs2012/xenbus_coinst/xenbus_coinst.vcxproj index 97654ad..e2cfeb9 100644 --- a/vs2012/xenbus_coinst/xenbus_coinst.vcxproj +++ b/vs2012/xenbus_coinst/xenbus_coinst.vcxproj @@ -34,7 +34,7 @@ <AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <PreprocessorDefinitions>__MODULE__="XENBUS_COINST";%(PreprocessorDefinitions)</PreprocessorDefinitions> <WarningLevel>EnableAllWarnings</WarningLevel> - <DisableSpecificWarnings>4711;4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings> + <DisableSpecificWarnings>4127;4711;4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings> <MultiProcessorCompilation>true</MultiProcessorCompilation> <EnablePREfast>true</EnablePREfast> <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='true'">MultiThreadedDebug</RuntimeLibrary> diff --git a/vs2013/xenbus_coinst/xenbus_coinst.vcxproj b/vs2013/xenbus_coinst/xenbus_coinst.vcxproj index 4ab2c20..48ed05b 100644 --- a/vs2013/xenbus_coinst/xenbus_coinst.vcxproj +++ b/vs2013/xenbus_coinst/xenbus_coinst.vcxproj @@ -1,4 +1,4 @@ -ï<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="..\configs.props" /> <PropertyGroup Label="PropertySheets"> @@ -63,7 +63,7 @@ <AdditionalIncludeDirectories>$(SolutionDir)..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <PreprocessorDefinitions>__MODULE__="XENBUS_COINST";%(PreprocessorDefinitions)</PreprocessorDefinitions> <WarningLevel>EnableAllWarnings</WarningLevel> - <DisableSpecificWarnings>4711;4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings> + <DisableSpecificWarnings>4127;4711;4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings> <MultiProcessorCompilation>true</MultiProcessorCompilation> <EnablePREfast>true</EnablePREfast> <RuntimeLibrary Condition="'$(UseDebugLibraries)'=='true'">MultiThreadedDebug</RuntimeLibrary> -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |