[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 3/3] 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 | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/xeniface/fdo.c | 95 +++------------------------ 2 files changed, 192 insertions(+), 87 deletions(-) diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c index cd3d1e0..dd1aad1 100644 --- a/src/coinst/coinst.c +++ b/src/coinst/coinst.c @@ -193,6 +193,176 @@ FunctionName( #undef _NAME } +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, @@ -220,7 +390,13 @@ DifInstallPostProcess( UNREFERENCED_PARAMETER(DeviceInfoData); UNREFERENCED_PARAMETER(Context); - Log("<===>"); + Log("====>"); + + SUBSCRIBE_INTERFACE(XENBUS, XENIFACE, SUSPEND); + SUBSCRIBE_INTERFACE(XENBUS, XENIFACE, SHARED_INFO); + SUBSCRIBE_INTERFACE(XENBUS, XENIFACE, STORE); + + Log("<===="); return NO_ERROR; } @@ -292,7 +468,11 @@ DifRemovePreProcess( UNREFERENCED_PARAMETER(DeviceInfoData); UNREFERENCED_PARAMETER(Context); - Log("<===>"); + Log("====>"); + + UnsubscribeInterfaces("XENBUS", "XENIFACE"); + + Log("<===="); return NO_ERROR; } diff --git a/src/xeniface/fdo.c b/src/xeniface/fdo.c index 20fe167..321bfb3 100644 --- a/src/xeniface/fdo.c +++ b/src/xeniface/fdo.c @@ -2109,13 +2109,9 @@ FdoDispatch( return status; } -#define SERVICES_KEY L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services" - -static FORCEINLINE NTSTATUS -__FdoQueryInterface( +static NTSTATUS +FdoQueryInterface( IN PXENIFACE_FDO Fdo, - IN const WCHAR *ProviderName, - IN const CHAR *InterfaceName, IN const GUID *Guid, IN ULONG Version, OUT PINTERFACE Interface, @@ -2123,9 +2119,6 @@ __FdoQueryInterface( IN BOOLEAN Optional ) { - UNICODE_STRING Unicode; - HANDLE InterfacesKey; - HANDLE SubscriberKey; KEVENT Event; IO_STATUS_BLOCK StatusBlock; PIRP Irp; @@ -2134,38 +2127,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, - "XENIFACE", - REG_OPTION_NON_VOLATILE, - &SubscriberKey); - if (!NT_SUCCESS(status)) - goto fail3; - KeInitializeEvent(&Event, NotificationEvent, FALSE); RtlZeroMemory(&StatusBlock, sizeof(IO_STATUS_BLOCK)); @@ -2179,7 +2140,7 @@ __FdoQueryInterface( status = STATUS_UNSUCCESSFUL; if (Irp == NULL) - goto fail4; + goto fail1; StackLocation = IoGetNextIrpStackLocation(Irp); StackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE; @@ -2205,45 +2166,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); @@ -2254,18 +2185,15 @@ fail1: _Fdo, \ _ProviderName, \ _InterfaceName, \ - _Version, \ _Interface, \ _Size, \ _Optional) \ - __FdoQueryInterface((_Fdo), \ - L ## #_ProviderName, \ - #_InterfaceName, \ - &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \ - (_Version), \ - (_Interface), \ - (_Size), \ - (_Optional)) + FdoQueryInterface((_Fdo), \ + &GUID_ ## _ProviderName ## _ ## _InterfaceName ## _INTERFACE, \ + _ProviderName ## _ ## _InterfaceName ## _INTERFACE_VERSION_MAX, \ + (_Interface), \ + (_Size), \ + (_Optional)) NTSTATUS FdoCreate( @@ -2344,7 +2272,6 @@ FdoCreate( status = FDO_QUERY_INTERFACE(Fdo, XENBUS, SUSPEND, - XENBUS_SUSPEND_INTERFACE_VERSION_MAX, (PINTERFACE)&Fdo->SuspendInterface, sizeof (Fdo->SuspendInterface), FALSE); @@ -2354,7 +2281,6 @@ FdoCreate( status = FDO_QUERY_INTERFACE(Fdo, XENBUS, SHARED_INFO, - XENBUS_SHARED_INFO_INTERFACE_VERSION_MAX, (PINTERFACE)&Fdo->SharedInfoInterface, sizeof (Fdo->SharedInfoInterface), FALSE); @@ -2364,7 +2290,6 @@ FdoCreate( status = FDO_QUERY_INTERFACE(Fdo, XENBUS, STORE, - XENBUS_STORE_INTERFACE_VERSION_MAX, (PINTERFACE)&Fdo->StoreInterface, sizeof (Fdo->StoreInterface), FALSE); -- 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 |