]> xenbits.xensource.com Git - people/pauldu/xenvif.git/commitdiff
Use XENBUS_MONITOR service to request reboot rather than SetupAPI
authorPaul Durrant <paul.durrant@citrix.com>
Thu, 21 Jul 2016 10:58:31 +0000 (11:58 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Thu, 21 Jul 2016 10:58:31 +0000 (11:58 +0100)
This means more code can be removed from XENNET's co-installer and we get a
more meaningful message displayed to the user.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenvif/driver.c

index 8e614200aefd125ad6a7fe65c426bdc6c55f2431..27d4911802c33407fe3eb6447a45285cc8745f2d 100644 (file)
@@ -45,7 +45,6 @@
 typedef struct _XENVIF_DRIVER {
     PDRIVER_OBJECT      DriverObject;
     HANDLE              ParametersKey;
-    HANDLE              StatusKey;
     BOOLEAN             NeedReboot;
 } XENVIF_DRIVER, *PXENVIF_DRIVER;
 
@@ -117,20 +116,58 @@ DriverGetParametersKey(
     return __DriverGetParametersKey();
 }
 
-static FORCEINLINE VOID
-__DriverSetStatusKey(
-    IN  HANDLE  Key
-    )
-{
-    Driver.StatusKey = Key;
-}
+#define SERVICES_PATH "\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services"
 
-static FORCEINLINE HANDLE
-__DriverGetStatusKey(
+#define SERVICE_KEY(_Name) \
+        SERVICES_PATH ## "\\" ## #_Name
+
+#define REQUEST_KEY \
+        SERVICE_KEY(XENBUS_MONITOR) ## "\\Request"
+
+static FORCEINLINE VOID
+__DriverRequestReboot(
     VOID
     )
 {
-    return Driver.StatusKey;
+    HANDLE      RequestKey;
+    ANSI_STRING Ansi[2];
+    NTSTATUS    status;
+
+    Info("====>\n");
+
+    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
+
+    status = RegistryOpenSubKey(NULL,
+                                REQUEST_KEY,
+                                KEY_ALL_ACCESS,
+                                &RequestKey);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+    RtlZeroMemory(Ansi, sizeof (Ansi));
+
+    RtlInitAnsiString(&Ansi[0], "XENVIF");
+
+    status = RegistryUpdateSzValue(RequestKey,
+                                   "Reboot",
+                                   REG_SZ,
+                                   Ansi);
+    if (!NT_SUCCESS(status))
+        goto fail2;
+
+    RegistryCloseKey(RequestKey);
+
+    Info("<====\n");
+
+    return;
+
+fail2:
+    Error("fail2\n");
+
+    RegistryCloseKey(RequestKey);
+
+fail1:
+    Error("fail1 (%08x)\n", status);
 }
 
 VOID
@@ -138,16 +175,11 @@ DriverRequestReboot(
     VOID
     )
 {
-    Info("<===>\n");
-
-    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
-
     if (Driver.NeedReboot)
         return;
 
-    (VOID) RegistryUpdateDwordValue(__DriverGetStatusKey(),
-                                    "NeedReboot",
-                                    1);
+    __DriverRequestReboot();
+
     Driver.NeedReboot = TRUE;
 }
 
@@ -159,7 +191,6 @@ DriverUnload(
     )
 {
     HANDLE              ParametersKey;
-    HANDLE              StatusKey;
 
     ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
 
@@ -167,11 +198,6 @@ DriverUnload(
 
     Driver.NeedReboot = FALSE;
 
-    StatusKey = __DriverGetStatusKey();
-    __DriverSetStatusKey(NULL);
-
-    RegistryCloseKey(StatusKey);
-
     ParametersKey = __DriverGetParametersKey();
     __DriverSetParametersKey(NULL);
 
@@ -278,7 +304,6 @@ DriverEntry(
 {
     HANDLE              ServiceKey;
     HANDLE              ParametersKey;
-    HANDLE              StatusKey;
     ULONG               Index;
     NTSTATUS            status;
 
@@ -319,15 +344,6 @@ DriverEntry(
 
     __DriverSetParametersKey(ParametersKey);
 
-    status = RegistryCreateSubKey(ServiceKey,
-                                  "Status",
-                                  REG_OPTION_VOLATILE,
-                                  &StatusKey);
-    if (!NT_SUCCESS(status))
-        goto fail4;
-
-    __DriverSetStatusKey(StatusKey);
-
     RegistryCloseKey(ServiceKey);
 
     DriverObject->DriverExtension->AddDevice = AddDevice;
@@ -342,13 +358,6 @@ DriverEntry(
 
     return STATUS_SUCCESS;
 
-fail4:
-    Error("fail4\n");
-
-    __DriverSetParametersKey(NULL);
-
-    RegistryCloseKey(ParametersKey);
-
 fail3:
     Error("fail3\n");