[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                        | 187 +++++++++++++++++++++++++++++
 src/xenvif/fdo.c                           |  99 ++-------------
 vs2012/xenvif_coinst/xenvif_coinst.vcxproj |   2 +-
 vs2013/xenvif_coinst/xenvif_coinst.vcxproj |   2 +-
 4 files changed, 199 insertions(+), 91 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index 0f6fc9f..bc3c214 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -35,6 +35,13 @@
 #include <stdlib.h>
 #include <strsafe.h>
 
+#include <debug_interface.h>
+#include <suspend_interface.h>
+#include <evtchn_interface.h>
+#include <store_interface.h>
+#include <range_set_interface.h>
+#include <cache_interface.h>
+#include <gnttab_interface.h>
 #include <vif_interface.h>
 
 #include <version.h>
@@ -742,6 +749,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 FORCEINLINE HRESULT
 __DifInstallPreProcess(
     IN  HDEVINFO                    DeviceInfoSet,
@@ -793,6 +970,14 @@ __DifInstallPostProcess(
 
     Log("====>");
 
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, DEBUG);
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, SUSPEND);
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, EVTCHN);
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, STORE);
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, RANGE_SET);
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, CACHE);
+    SUBSCRIBE_INTERFACE(XENBUS, XENVIF, GNTTAB);
+
     (VOID) InstallUnplugService("NICS", "XENVIF");
 
     Log("<====");
@@ -871,6 +1056,8 @@ __DifRemovePreProcess(
 
     (VOID) RemoveUnplugService("NICS", "XENVIF");
 
+    UnsubscribeInterfaces("XENBUS", "XENVIF");
+
     Log("<====");
 
     return NO_ERROR; 
diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c
index d57b10d..2f2e6bd 100644
--- a/src/xenvif/fdo.c
+++ b/src/xenvif/fdo.c
@@ -2606,13 +2606,9 @@ __FdoReleaseLowerBusInterface(
     RtlZeroMemory(BusInterface, sizeof (BUS_INTERFACE_STANDARD));
 }
 
-#define SERVICES_KEY        
L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services"
-
-static FORCEINLINE NTSTATUS
-__FdoQueryInterface(
+static NTSTATUS
+FdoQueryInterface(
     IN  PXENVIF_FDO     Fdo,
-    IN  const WCHAR     *ProviderName,
-    IN  const CHAR      *InterfaceName,
     IN  const GUID      *Guid,
     IN  ULONG           Version,
     OUT PINTERFACE      Interface,
@@ -2620,9 +2616,6 @@ __FdoQueryInterface(
     IN  BOOLEAN         Optional
     )
 {
-    UNICODE_STRING      Unicode;
-    HANDLE              InterfacesKey;
-    HANDLE              SubscriberKey;
     KEVENT              Event;
     IO_STATUS_BLOCK     StatusBlock;
     PIRP                Irp;
@@ -2631,38 +2624,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, 
-                                  "XENVIF", 
-                                  REG_OPTION_NON_VOLATILE, 
-                                  &SubscriberKey);
-    if (!NT_SUCCESS(status))
-        goto fail3;
-                   
     KeInitializeEvent(&Event, NotificationEvent, FALSE);
     RtlZeroMemory(&StatusBlock, sizeof(IO_STATUS_BLOCK));
 
@@ -2676,7 +2637,7 @@ __FdoQueryInterface(
 
     status = STATUS_UNSUCCESSFUL;
     if (Irp == NULL)
-        goto fail4;
+        goto fail1;
 
     StackLocation = IoGetNextIrpStackLocation(Irp);
     StackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE;
@@ -2702,45 +2663,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);
 
@@ -2751,18 +2682,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))
 
 #define DEFINE_FDO_GET_INTERFACE(_Interface, _Type)                     \
 VOID                                                                    \
@@ -2854,7 +2782,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  DEBUG,
-                                 XENBUS_DEBUG_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->DebugInterface,
                                  sizeof (Fdo->DebugInterface),
                                  FALSE);
@@ -2864,7 +2791,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  SUSPEND,
-                                 XENBUS_SUSPEND_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->SuspendInterface,
                                  sizeof (Fdo->SuspendInterface),
                                  FALSE);
@@ -2874,7 +2800,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  EVTCHN,
-                                 XENBUS_EVTCHN_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->EvtchnInterface,
                                  sizeof (Fdo->EvtchnInterface),
                                  FALSE);
@@ -2884,7 +2809,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  STORE,
-                                 XENBUS_STORE_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->StoreInterface,
                                  sizeof (Fdo->StoreInterface),
                                  FALSE);
@@ -2894,7 +2818,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  RANGE_SET,
-                                 XENBUS_RANGE_SET_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->RangeSetInterface,
                                  sizeof (Fdo->RangeSetInterface),
                                  FALSE);
@@ -2904,7 +2827,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  CACHE,
-                                 XENBUS_CACHE_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->CacheInterface,
                                  sizeof (Fdo->CacheInterface),
                                  FALSE);
@@ -2914,7 +2836,6 @@ FdoCreate(
     status = FDO_QUERY_INTERFACE(Fdo,
                                  XENBUS,
                                  GNTTAB,
-                                 XENBUS_GNTTAB_INTERFACE_VERSION_MAX,
                                  (PINTERFACE)&Fdo->GnttabInterface,
                                  sizeof (Fdo->GnttabInterface),
                                  FALSE);
diff --git a/vs2012/xenvif_coinst/xenvif_coinst.vcxproj 
b/vs2012/xenvif_coinst/xenvif_coinst.vcxproj
index c95a12f..1eb1ea3 100644
--- a/vs2012/xenvif_coinst/xenvif_coinst.vcxproj
+++ b/vs2012/xenvif_coinst/xenvif_coinst.vcxproj
@@ -36,7 +36,7 @@
                <ClCompile>
                        
<PreprocessorDefinitions>__MODULE__="XENVIF_COINST";%(PreprocessorDefinitions)</PreprocessorDefinitions>
                        <WarningLevel>EnableAllWarnings</WarningLevel>
-                       
<DisableSpecificWarnings>4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+                       
<DisableSpecificWarnings>4127;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/xenvif_coinst/xenvif_coinst.vcxproj 
b/vs2013/xenvif_coinst/xenvif_coinst.vcxproj
index bfc1b4d..5624389 100644
--- a/vs2013/xenvif_coinst/xenvif_coinst.vcxproj
+++ b/vs2013/xenvif_coinst/xenvif_coinst.vcxproj
@@ -68,7 +68,7 @@
     <ClCompile>
       
<PreprocessorDefinitions>__MODULE__="XENVIF_COINST";%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <WarningLevel>EnableAllWarnings</WarningLevel>
-      
<DisableSpecificWarnings>4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings>
+      
<DisableSpecificWarnings>4127;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


 


Rackspace

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