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

[win-pv-devel] [PATCH 1/4] Allow PdoResume() to fail



At the moment FrontendResume() can fail, but PdoResume() cannot and hence
the error status is ignored. This is problematic because it is not safe to
call FrontendSuspend() if FrontendResume() did not complete successfully.
This patch, therefore, wires through the failure of FrontendResume() into
PdoResume() and on into FdoAddPhysicalDeviceObject().

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/fdo.c | 37 +++++++++++++++++++++++++++----------
 src/xenvif/fdo.h |  2 +-
 src/xenvif/pdo.c | 47 +++++++++++++++++++++++++++++------------------
 src/xenvif/pdo.h |  2 +-
 4 files changed, 58 insertions(+), 30 deletions(-)

diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c
index 4b40777..3f6713b 100644
--- a/src/xenvif/fdo.c
+++ b/src/xenvif/fdo.c
@@ -614,7 +614,7 @@ FdoForwardIrpSynchronously(
     return status;
 }
 
-VOID
+NTSTATUS
 FdoAddPhysicalDeviceObject(
     IN  PXENVIF_FDO     Fdo,
     IN  PXENVIF_PDO     Pdo
@@ -622,17 +622,30 @@ FdoAddPhysicalDeviceObject(
 {
     PDEVICE_OBJECT      DeviceObject;
     PXENVIF_DX          Dx;
+    NTSTATUS            status;
 
     DeviceObject = PdoGetDeviceObject(Pdo);
     Dx = (PXENVIF_DX)DeviceObject->DeviceExtension;
     ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
 
+    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD3)
+        goto done;
+
+    status = PdoResume(Pdo);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+done:
     InsertTailList(&Fdo->Dx->ListEntry, &Dx->ListEntry);
     ASSERT3U(Fdo->References, !=, 0);
     Fdo->References++;
 
-    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD0)
-        PdoResume(Pdo);
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
 }
 
 VOID
@@ -648,9 +661,12 @@ FdoRemovePhysicalDeviceObject(
     Dx = (PXENVIF_DX)DeviceObject->DeviceExtension;
     ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
 
-    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD0)
-        PdoSuspend(Pdo);
+    if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD3)
+        goto done;
 
+    PdoSuspend(Pdo);
+
+done:
     RemoveEntryList(&Dx->ListEntry);
     ASSERT3U(Fdo->References, !=, 0);
     --Fdo->References;
@@ -1176,7 +1192,8 @@ FdoD3ToD0(
 
         ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
 
-        PdoResume(Pdo);
+        status = PdoResume(Pdo);
+        ASSERT(NT_SUCCESS(status));
     }
 
     __FdoReleaseMutex(Fdo);
@@ -2881,6 +2898,8 @@ FdoCreate(
     if (!NT_SUCCESS(status))
         goto fail13;
 
+    Dx->Fdo = Fdo;
+
     InitializeMutex(&Fdo->Mutex);
     InitializeListHead(&Dx->ListEntry);
     Fdo->References = 1;
@@ -2889,9 +2908,7 @@ FdoCreate(
          FunctionDeviceObject,
          __FdoGetName(Fdo));
 
-    Dx->Fdo = Fdo;
     FunctionDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
-
     return STATUS_SUCCESS;
 
 fail13:
@@ -2996,10 +3013,10 @@ FdoDestroy(
          FunctionDeviceObject,
          __FdoGetName(Fdo));
 
-    Dx->Fdo = NULL;
-
     RtlZeroMemory(&Fdo->Mutex, sizeof (MUTEX));
 
+    Dx->Fdo = NULL;
+
     RtlZeroMemory(&Fdo->GnttabInterface,
                   sizeof (XENBUS_GNTTAB_INTERFACE));
 
diff --git a/src/xenvif/fdo.h b/src/xenvif/fdo.h
index 78cfbfb..68d7b4a 100644
--- a/src/xenvif/fdo.h
+++ b/src/xenvif/fdo.h
@@ -55,7 +55,7 @@ FdoGetName(
     IN  PXENVIF_FDO Fdo
     );
 
-extern VOID
+extern NTSTATUS
 FdoAddPhysicalDeviceObject(
     IN  PXENVIF_FDO     Fdo,
     IN  PXENVIF_PDO     Pdo
diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c
index 9352594..dc7eacd 100644
--- a/src/xenvif/pdo.c
+++ b/src/xenvif/pdo.c
@@ -2552,16 +2552,12 @@ PdoDispatch(
     return status;
 }
 
-VOID
+NTSTATUS
 PdoResume(
-    IN  PXENVIF_PDO     Pdo
+    IN  PXENVIF_PDO Pdo
     )
 {
-    Trace("====>\n");
-
-    FrontendResume(__PdoGetFrontend(Pdo));
-
-    Trace("<====\n");
+    return FrontendResume(__PdoGetFrontend(Pdo));
 }
 
 VOID
@@ -2569,11 +2565,7 @@ PdoSuspend(
     IN  PXENVIF_PDO     Pdo
     )
 {
-    Trace("====>\n");
-
     FrontendSuspend(__PdoGetFrontend(Pdo));
-
-    Trace("<====\n");
 }
 
 NTSTATUS
@@ -2654,6 +2646,14 @@ PdoCreate(
 
     FdoGetSuspendInterface(Fdo,&Pdo->SuspendInterface);
 
+    Dx->Pdo = Pdo;
+
+    KeInitializeSpinLock(&Pdo->EjectLock);
+
+    status = FdoAddPhysicalDeviceObject(Fdo, Pdo);
+    if (!NT_SUCCESS(status))
+        goto fail11;
+
     for (Index = 0; Index < Pdo->Count; Index++) {
         Info("%p (%s %08X)\n",
              PhysicalDeviceObject,
@@ -2661,14 +2661,22 @@ PdoCreate(
              Pdo->Revision[Index]);
     }
 
-    Dx->Pdo = Pdo;
     PhysicalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
+    return STATUS_SUCCESS;
 
-    KeInitializeSpinLock(&Pdo->EjectLock);
+fail11:
+    Error("fail11\n");
 
-    FdoAddPhysicalDeviceObject(Fdo, Pdo);
+    (VOID) __PdoClearEjectRequested(Pdo);
+    RtlZeroMemory(&Pdo->EjectLock, sizeof (KSPIN_LOCK));
 
-    return STATUS_SUCCESS;
+    Dx->Pdo = NULL;
+
+    RtlZeroMemory(&Pdo->SuspendInterface,
+                  sizeof (XENBUS_SUSPEND_INTERFACE));
+
+    FrontendTeardown(__PdoGetFrontend(Pdo));
+    Pdo->Frontend = NULL;
 
 fail10:
     Error("fail10\n");
@@ -2762,17 +2770,20 @@ PdoDestroy(
 
     FdoRemovePhysicalDeviceObject(Fdo, Pdo);
 
+    (VOID) __PdoClearEjectRequested(Pdo);
+    RtlZeroMemory(&Pdo->EjectLock, sizeof (KSPIN_LOCK));
+
     Dx->Pdo = NULL;
 
     RtlZeroMemory(&Pdo->SuspendInterface,
                   sizeof (XENBUS_SUSPEND_INTERFACE));
 
-    VifTeardown(Pdo->VifContext);
-    Pdo->VifContext = NULL;
-    
     FrontendTeardown(__PdoGetFrontend(Pdo));
     Pdo->Frontend = NULL;    
 
+    VifTeardown(Pdo->VifContext);
+    Pdo->VifContext = NULL;
+
     BusTeardown(&Pdo->BusInterface);
 
     for (Index = 0; Index < Pdo->Count; Index++)
diff --git a/src/xenvif/pdo.h b/src/xenvif/pdo.h
index 76ff3a4..13dbe81 100644
--- a/src/xenvif/pdo.h
+++ b/src/xenvif/pdo.h
@@ -144,7 +144,7 @@ PdoCreate(
     IN  PCHAR       Address
     );
 
-extern VOID
+extern NTSTATUS
 PdoResume(
     IN  PXENVIF_PDO Pdo
     );
-- 
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®.