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

[win-pv-devel] [PATCH 4/4] Use new service to request reboot rather than SetupAPI



This means more code can be removed from the co-installer and we get a
more meaningful message displayed to the user.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/coinst/coinst.c | 144 ++--------------------------------------------------
 src/xen/driver.c    |  88 +++++---------------------------
 src/xenbus.inf      |   2 +-
 src/xenbus/driver.c | 102 +++++++++++++++++++------------------
 4 files changed, 70 insertions(+), 266 deletions(-)

diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c
index 66359e0..1241ad1 100644
--- a/src/coinst/coinst.c
+++ b/src/coinst/coinst.c
@@ -1290,133 +1290,6 @@ fail1:
 }
 
 static BOOLEAN
-CheckStatus(
-    IN  PTCHAR      DriverName,
-    OUT PBOOLEAN    NeedReboot
-    )
-{
-    TCHAR           StatusKeyName[MAX_PATH];
-    HKEY            StatusKey;
-    HRESULT         Result;
-    HRESULT         Error;
-    DWORD           ValueLength;
-    DWORD           Value;
-    DWORD           Type;
-
-    Result = StringCbPrintf(StatusKeyName,
-                            MAX_PATH,
-                            SERVICES_KEY "\\%s\\Status",
-                            DriverName);
-    assert(SUCCEEDED(Result));
-
-    Error = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
-                         StatusKeyName,
-                         0,
-                         KEY_READ,
-                         &StatusKey);
-    if (Error != ERROR_SUCCESS) {
-        SetLastError(Error);
-        goto fail1;
-    }
-
-    ValueLength = sizeof (Value);
-
-    Error = RegQueryValueEx(StatusKey,
-                            "NeedReboot",
-                            NULL,
-                            &Type,
-                            (LPBYTE)&Value,
-                            &ValueLength);
-    if (Error != ERROR_SUCCESS) {
-        if (Error == ERROR_FILE_NOT_FOUND) {
-            Type = REG_DWORD;
-            Value = 0;
-        } else {
-            SetLastError(Error);
-            goto fail2;
-        }
-    }
-
-    if (Type != REG_DWORD) {
-        SetLastError(ERROR_BAD_FORMAT);
-        goto fail3;
-    }
-
-    *NeedReboot = (Value != 0) ? TRUE : FALSE;
-
-    if (*NeedReboot)
-        Log("NeedReboot");
-
-    RegCloseKey(StatusKey);
-
-    return TRUE;
-
-fail3:
-    Log("fail3");
-
-fail2:
-    Log("fail2");
-
-    RegCloseKey(StatusKey);
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-        Message = GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
-RequestReboot(
-    IN  HDEVINFO            DeviceInfoSet,
-    IN  PSP_DEVINFO_DATA    DeviceInfoData
-    )
-{
-    SP_DEVINSTALL_PARAMS    DeviceInstallParams;
-    HRESULT                 Error;
-
-    DeviceInstallParams.cbSize = sizeof (DeviceInstallParams);
-
-    if (!SetupDiGetDeviceInstallParams(DeviceInfoSet,
-                                       DeviceInfoData,
-                                       &DeviceInstallParams))
-        goto fail1;
-
-    DeviceInstallParams.Flags |= DI_NEEDREBOOT;
-
-    Log("Flags = %08x", DeviceInstallParams.Flags);
-
-    if (!SetupDiSetDeviceInstallParams(DeviceInfoSet,
-                                       DeviceInfoData,
-                                       &DeviceInstallParams))
-        goto fail2;
-
-    return TRUE;
-
-fail2:
-    Log("fail2");
-
-fail1:
-    Error = GetLastError();
-
-    {
-        PTCHAR  Message;
-
-        Message = GetErrorMessage(Error);
-        Log("fail1 (%s)", Message);
-        LocalFree(Message);
-    }
-
-    return FALSE;
-}
-
-static BOOLEAN
 ClearUnplugRequest(
     IN  PTCHAR      ClassName
     )
@@ -1615,22 +1488,11 @@ DifInstallPostProcess(
     IN  PCOINSTALLER_CONTEXT_DATA   Context
     )
 {
-    BOOLEAN                         NeedReboot;
-
+    UNREFERENCED_PARAMETER(DeviceInfoSet);
+    UNREFERENCED_PARAMETER(DeviceInfoData);
     UNREFERENCED_PARAMETER(Context);
 
-    Log("====>");
-
-    NeedReboot = FALSE;
-
-    (VOID) CheckStatus("XEN", &NeedReboot);
-    if (!NeedReboot)
-        (VOID) CheckStatus("XENBUS", &NeedReboot);
-
-    if (NeedReboot)
-        (VOID) RequestReboot(DeviceInfoSet, DeviceInfoData);
-
-    Log("<====");
+    Log("<===>");
 
     return NO_ERROR;
 }
diff --git a/src/xen/driver.c b/src/xen/driver.c
index 6119c7c..f83cb13 100644
--- a/src/xen/driver.c
+++ b/src/xen/driver.c
@@ -53,7 +53,6 @@ typedef struct _XEN_DRIVER {
     PLOG_DISPOSITION    TraceDisposition;
     PLOG_DISPOSITION    InfoDisposition;
     HANDLE              UnplugKey;
-    HANDLE              StatusKey;
 } XEN_DRIVER, *PXEN_DRIVER;
 
 static XEN_DRIVER   Driver;
@@ -92,44 +91,6 @@ DriverGetUnplugKey(
     return __DriverGetUnplugKey();
 }
 
-static FORCEINLINE VOID
-__DriverSetStatusKey(
-    IN  HANDLE  Key
-    )
-{
-    Driver.StatusKey = Key;
-}
-
-static FORCEINLINE HANDLE
-__DriverGetStatusKey(
-    VOID
-    )
-{
-    return Driver.StatusKey;
-}
-
-HANDLE
-DriverGetStatusKey(
-    VOID
-    )
-{
-    return __DriverGetStatusKey();
-}
-
-static FORCEINLINE VOID
-__DriverRequestReboot(
-    VOID
-    )
-{
-    Info("<===>\n");
-
-    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
-
-    (VOID) RegistryUpdateDwordValue(__DriverGetStatusKey(),
-                                    "NeedReboot",
-                                    1);
-}
-
 XEN_API
 NTSTATUS
 XenTouch(
@@ -173,7 +134,6 @@ done:
 
 fail1:
     Info("MODULE '%s' NOT COMPATIBLE (REBOOT REQUIRED)\n", Name);
-    __DriverRequestReboot();
 
     return STATUS_INCOMPATIBLE_DRIVER_BLOCKED;
 }
@@ -200,7 +160,6 @@ DllInitialize(
 {
     HANDLE              ServiceKey;
     HANDLE              UnplugKey;
-    HANDLE              StatusKey;
     NTSTATUS            status;
 
     ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
@@ -259,42 +218,33 @@ DllInitialize(
 
     __DriverSetUnplugKey(UnplugKey);
 
-    status = RegistryCreateSubKey(ServiceKey,
-                                  "Status",
-                                  REG_OPTION_VOLATILE,
-                                  &StatusKey);
-    if (!NT_SUCCESS(status))
-        goto fail5;
-
-    __DriverSetStatusKey(StatusKey);
-
     status = AcpiInitialize();
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail5;
 
     status = SystemInitialize();
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail6;
 
     status = HypercallInitialize();
     if (!NT_SUCCESS(status))
-        goto fail8;
+        goto fail7;
 
     status = BugCheckInitialize();
     if (!NT_SUCCESS(status))
-        goto fail9;
+        goto fail8;
 
     status = ModuleInitialize();
     if (!NT_SUCCESS(status))
-        goto fail10;
+        goto fail9;
 
     status = ProcessInitialize();
     if (!NT_SUCCESS(status))
-        goto fail11;
+        goto fail10;
 
     status = UnplugInitialize();
     if (!NT_SUCCESS(status))
-        goto fail12;
+        goto fail11;
 
     RegistryCloseKey(ServiceKey);
 
@@ -302,41 +252,35 @@ DllInitialize(
 
     return STATUS_SUCCESS;
 
-fail12:
-    Error("fail12\n");
-
-    ProcessTeardown();
-
 fail11:
     Error("fail11\n");
 
-    ModuleTeardown();
+    ProcessTeardown();
 
 fail10:
     Error("fail10\n");
 
-    BugCheckTeardown();
+    ModuleTeardown();
 
 fail9:
     Error("fail9\n");
 
-    HypercallTeardown();
+    BugCheckTeardown();
 
 fail8:
     Error("fail8\n");
 
-    SystemTeardown();
+    HypercallTeardown();
 
 fail7:
     Error("fail7\n");
 
-    AcpiTeardown();
+    SystemTeardown();
 
 fail6:
     Error("fail6\n");
 
-    RegistryCloseKey(StatusKey);
-    __DriverSetStatusKey(NULL);
+    AcpiTeardown();
 
 fail5:
     Error("fail5\n");
@@ -378,7 +322,6 @@ DllUnload(
     VOID
     )
 {
-    HANDLE  StatusKey;
     HANDLE  UnplugKey;
 
     Trace("====>\n");
@@ -395,11 +338,6 @@ DllUnload(
 
     SystemTeardown();
 
-    StatusKey = __DriverGetStatusKey();
-
-    RegistryCloseKey(StatusKey);
-    __DriverSetStatusKey(NULL);
-
     UnplugKey = __DriverGetUnplugKey();
 
     RegistryCloseKey(UnplugKey);
diff --git a/src/xenbus.inf b/src/xenbus.inf
index ddc1c45..03a3d6b 100644
--- a/src/xenbus.inf
+++ b/src/xenbus.inf
@@ -81,9 +81,9 @@ CopyFiles=XenBus_CopyFiles
 CopyFiles=Monitor_CopyFiles
 
 [XenBus_Inst.Services]
+AddService=xenbus_monitor,%SPSVCSINST_STARTSERVICE%,Monitor_Service,Monitor_EventLog
 AddService=xenbus,%SPSVCINST_ASSOCSERVICE%,XenBus_Service
 AddService=xenfilt,,XenFilt_Service,
-AddService=xenbus_monitor,%SPSVCSINST_STARTSERVICE%,Monitor_Service,Monitor_EventLog
 
 [XenBus_Service] 
 DisplayName=%XenBusDesc%
diff --git a/src/xenbus/driver.c b/src/xenbus/driver.c
index 24f06f5..31388be 100644
--- a/src/xenbus/driver.c
+++ b/src/xenbus/driver.c
@@ -48,7 +48,6 @@
 typedef struct _XENBUS_DRIVER {
     PDRIVER_OBJECT      DriverObject;
     HANDLE              ParametersKey;
-    HANDLE              StatusKey;
 
     MUTEX               Mutex;
     LIST_ENTRY          List;
@@ -123,34 +122,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(
-    VOID
-    )
-{
-    return Driver.StatusKey;
-}
+#define SERVICE_KEY(_Name) \
+        SERVICES_PATH ## "\\" ## #_Name
 
-VOID
-DriverRequestReboot(
+#define REQUEST_KEY \
+        SERVICE_KEY(XENBUS_MONITOR) ## "\\Request"
+
+static FORCEINLINE VOID
+__DriverRequestReboot(
     VOID
     )
 {
-    Info("<===>\n");
+    HANDLE      RequestKey;
+    ANSI_STRING Ansi[2];
+    NTSTATUS    status;
+
+    Info("====>\n");
 
     ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
 
-    (VOID) RegistryUpdateDwordValue(__DriverGetStatusKey(),
-                                    "NeedReboot",
-                                    1);
+    status = RegistryOpenSubKey(NULL,
+                                REQUEST_KEY,
+                                KEY_ALL_ACCESS,
+                                &RequestKey);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+    RtlZeroMemory(Ansi, sizeof (Ansi));
+
+    RtlInitAnsiString(&Ansi[0], "XENBUS");
+
+    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);
 }
 
 static FORCEINLINE VOID
@@ -510,7 +533,6 @@ DriverUnload(
     )
 {
     HANDLE              ParametersKey;
-    HANDLE              StatusKey;
 
     ASSERT3P(DriverObject, ==, __DriverGetDriverObject());
 
@@ -523,11 +545,6 @@ DriverUnload(
     RtlZeroMemory(&Driver.List, sizeof (LIST_ENTRY));
     RtlZeroMemory(&Driver.Mutex, sizeof (MUTEX));
 
-    StatusKey = __DriverGetStatusKey();
-    __DriverSetStatusKey(NULL);
-
-    RegistryCloseKey(StatusKey);
-
     ParametersKey = __DriverGetParametersKey();
 
     RegistryCloseKey(ParametersKey);
@@ -639,7 +656,6 @@ DriverEntry(
 {
     HANDLE              ServiceKey;
     HANDLE              ParametersKey;
-    HANDLE              StatusKey;
     ULONG               Index;
     NTSTATUS            status;
 
@@ -670,34 +686,27 @@ DriverEntry(
                       MINOR_VERSION,
                       MICRO_VERSION,
                       BUILD_NUMBER);
-    if (!NT_SUCCESS(status))
-        goto done;
+    if (!NT_SUCCESS(status)) {
+        __DriverRequestReboot();
+        goto fail1;
+    }
 
     status = RegistryInitialize(RegistryPath);
     if (!NT_SUCCESS(status))
-        goto fail1;
+        goto fail2;
 
     status = RegistryOpenServiceKey(KEY_READ, &ServiceKey);
     if (!NT_SUCCESS(status))
-        goto fail2;
+        goto fail3;
 
     status = RegistryOpenSubKey(ServiceKey,
                                 "Parameters",
                                 KEY_READ,
                                 &ParametersKey);
     if (!NT_SUCCESS(status))
-        goto fail3;
-
-    __DriverSetParametersKey(ParametersKey);
-
-    status = RegistryCreateSubKey(ServiceKey,
-                                  "Status",
-                                  REG_OPTION_VOLATILE,
-                                  &StatusKey);
-    if (!NT_SUCCESS(status))
         goto fail4;
 
-    __DriverSetStatusKey(StatusKey);
+    __DriverSetParametersKey(ParametersKey);
 
     RegistryCloseKey(ServiceKey);
 
@@ -713,7 +722,6 @@ DriverEntry(
     InitializeListHead(&Driver.List);
     Driver.References = 1;
 
-done:
     Trace("<====\n");
 
     return STATUS_SUCCESS;
@@ -721,20 +729,16 @@ done:
 fail4:
     Error("fail4\n");
 
-    __DriverSetParametersKey(NULL);
-
-    RegistryCloseKey(ParametersKey);
+    RegistryCloseKey(ServiceKey);
 
 fail3:
     Error("fail3\n");
 
-    RegistryCloseKey(ServiceKey);
+    RegistryTeardown();
 
 fail2:
     Error("fail2\n");
 
-    RegistryTeardown();
-
 fail1:
     Error("fail1 (%08x)\n", status);
 
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://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®.