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

[win-pv-devel] [PATCH 6/8] Move reboot request code into driver.c



It doesn't really belong in pdo.c

Also this patch adds a check in PdoStartDevice() to fail if a reboot has
already been requested. This is because Windows 10 apparently has a couple
of goes at starting the PDO even after it failed to start the first time
(because we requested a reboot).

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/driver.c | 22 +++++++++++++++++---
 src/xenvif/driver.h |  9 ++++++--
 src/xenvif/pdo.c    | 59 +++++++++++++++++++++--------------------------------
 3 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/src/xenvif/driver.c b/src/xenvif/driver.c
index 46fe7f1..95a56e3 100644
--- a/src/xenvif/driver.c
+++ b/src/xenvif/driver.c
@@ -48,6 +48,7 @@ typedef struct _XENVIF_DRIVER {
     PDRIVER_OBJECT      DriverObject;
     HANDLE              ParametersKey;
     HANDLE              StatusKey;
+    BOOLEAN             NeedReboot;
 } XENVIF_DRIVER, *PXENVIF_DRIVER;
 
 static XENVIF_DRIVER    Driver;
@@ -116,12 +117,27 @@ __DriverGetStatusKey(
     return Driver.StatusKey;
 }
 
-HANDLE
-DriverGetStatusKey(
+VOID
+DriverRequestReboot(
+    VOID
+    )
+{
+    Info("<===>\n");
+
+    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
+
+    (VOID) RegistryUpdateDwordValue(__DriverGetStatusKey(),
+                                    "NeedReboot",
+                                    1);
+    Driver.NeedReboot = TRUE;
+}
+
+BOOLEAN
+DriverIsRebootRequested(
     VOID
     )
 {
-    return __DriverGetStatusKey();
+    return Driver.NeedReboot;
 }
 
 DRIVER_UNLOAD       DriverUnload;
diff --git a/src/xenvif/driver.h b/src/xenvif/driver.h
index cecefd0..53b85af 100644
--- a/src/xenvif/driver.h
+++ b/src/xenvif/driver.h
@@ -42,8 +42,13 @@ DriverGetParametersKey(
     VOID
     );
 
-extern HANDLE
-DriverGetStatusKey(
+extern VOID
+DriverRequestReboot(
+    VOID
+    );
+
+BOOLEAN
+DriverIsRebootRequested(
     VOID
     );
 
diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c
index 0cf83b9..9e3003e 100644
--- a/src/xenvif/pdo.c
+++ b/src/xenvif/pdo.c
@@ -1113,26 +1113,6 @@ PdoS3ToS4(
     Trace("(%s) <====\n", __PdoGetName(Pdo));
 }
 
-static VOID
-PdoRequestReboot(
-    IN  PXENVIF_PDO     Pdo
-    )
-{
-    HANDLE              StatusKey;
-
-    UNREFERENCED_PARAMETER(Pdo);
-
-    Info("<===>\n");
-
-    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
-
-    StatusKey = DriverGetStatusKey();
-
-    (VOID) RegistryUpdateDwordValue(StatusKey,
-                                    "NeedReboot",
-                                    1);
-}
-
 static DECLSPEC_NOINLINE NTSTATUS
 PdoStartDevice(
     IN  PXENVIF_PDO     Pdo,
@@ -1147,35 +1127,39 @@ PdoStartDevice(
     HANDLE              Key;
     NTSTATUS            status;
 
+    status = STATUS_UNSUCCESSFUL;
+    if (DriverIsRebootRequested())
+        goto fail1;
+
     status = RegistryOpenSoftwareKey(__PdoGetDeviceObject(Pdo),
                                      KEY_ALL_ACCESS,
                                      &Key);
     if (!NT_SUCCESS(status))
-        goto fail1;
+        goto fail2;
 
     status = __PdoSetCurrentAddress(Pdo, Key);
     if (!NT_SUCCESS(status))
-        goto fail2;
+        goto fail3;
 
     status = __PdoSetLuid(Pdo, Key);
     if (!NT_SUCCESS(status))
-        goto fail3;
+        goto fail4;
 
     status = LinkGetRoutineAddress("netio.sys",
                                    "GetIfTable2",
                                    (PVOID *)&__GetIfTable2);
     if (!NT_SUCCESS(status))
-        goto fail4;
+        goto fail5;
 
     status = LinkGetRoutineAddress("netio.sys",
                                    "FreeMibTable",
                                    (PVOID *)&__FreeMibTable);
     if (!NT_SUCCESS(status))
-        goto fail5;
+        goto fail6;
 
     status = __GetIfTable2(&Table);
     if (!NT_SUCCESS(status))
-        goto fail6;
+        goto fail7;
 
     for (Index = 0; Index < Table->NumEntries; Index++) {
         PMIB_IF_ROW2    Row = &Table->Table[Index];
@@ -1194,14 +1178,14 @@ PdoStartDevice(
         if (memcmp(Row->PhysicalAddress,
                    &Pdo->PermanentAddress,
                    sizeof (ETHERNET_ADDRESS)) == 0)
-            goto fail7;
+            goto fail8;
     }
 
     StackLocation = IoGetCurrentIrpStackLocation(Irp);
 
     status = PdoD3ToD0(Pdo);
     if (!NT_SUCCESS(status))
-        goto fail8;
+        goto fail9;
 
     __PdoSetDevicePnpState(Pdo, Started);
 
@@ -1214,39 +1198,42 @@ PdoStartDevice(
 
     return STATUS_SUCCESS;
 
+fail9:
+    Error("fail9\n");
+
+    __FreeMibTable(Table);
+    goto fail6;
+
 fail8:
     Error("fail8\n");
 
+    DriverRequestReboot();
     __FreeMibTable(Table);
-    goto fail6;
 
 fail7:
     Error("fail7\n");
 
-    PdoRequestReboot(Pdo);
-    __FreeMibTable(Table);
-
 fail6:
     Error("fail6\n");
 
 fail5:
     Error("fail5\n");
 
+    RtlZeroMemory(&Pdo->Luid, sizeof (NET_LUID));
+
 fail4:
     Error("fail4\n");
 
-    RtlZeroMemory(&Pdo->Luid, sizeof (NET_LUID));
+    RtlZeroMemory(&Pdo->CurrentAddress, sizeof (ETHERNET_ADDRESS));
 
 fail3:
     Error("fail3\n");
 
-    RtlZeroMemory(&Pdo->CurrentAddress, sizeof (ETHERNET_ADDRESS));
+    RegistryCloseKey(Key);
 
 fail2:
     Error("fail2\n");
 
-    RegistryCloseKey(Key);
-
 fail1:
     Error("fail1 (%08x)\n", status);
 
-- 
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®.