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

[win-pv-devel] [PATCH] Remove PDO set/is-missing logic from XENFILT



It's all completely unnecessary for a filter driver

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenfilt/fdo.c | 74 ++++++++++++++-----------------------------------------
 src/xenfilt/pdo.c | 67 ++++++++-----------------------------------------
 src/xenfilt/pdo.h | 16 ------------
 3 files changed, 29 insertions(+), 128 deletions(-)

diff --git a/src/xenfilt/fdo.c b/src/xenfilt/fdo.c
index cff179b..25b3dc2 100644
--- a/src/xenfilt/fdo.c
+++ b/src/xenfilt/fdo.c
@@ -536,43 +536,22 @@ FdoEnumerate(
         PLIST_ENTRY     Next = ListEntry->Flink;
         PXENFILT_DX     Dx = CONTAINING_RECORD(ListEntry, XENFILT_DX, 
ListEntry);
         PXENFILT_PDO    Pdo = Dx->Pdo;
-        BOOLEAN         Missing;
 
-        Missing = TRUE;
         for (Index = 0; Index < Count; Index++) {
             if (PdoGetPhysicalDeviceObject(Pdo) == 
PhysicalDeviceObject[Index]) {
-                Missing = FALSE;
-#pragma prefast(suppress:6387)  // PhysicalDeviceObject[Index] could be NULL
-                ObDereferenceObject(PhysicalDeviceObject[Index]);
                 PhysicalDeviceObject[Index] = NULL; // avoid duplication
                 break;
             }
         }
 
-        if (Missing &&
-            !PdoIsMissing(Pdo) &&
-            PdoGetDevicePnpState(Pdo) != Deleted) {
-            PdoSetMissing(Pdo, "device disappeared");
-
-            // If the PDO has not yet been enumerated then we can go ahead
-            // and mark it as deleted, otherwise we need to notify PnP manager 
and
-            // wait for the REMOVE_DEVICE IRP.
-            if (PdoGetDevicePnpState(Pdo) == Present) {
-                PdoSetDevicePnpState(Pdo, Deleted);
-                PdoDestroy(Pdo);
-            }
-        }
-
         ListEntry = Next;
     }
 
     // Walk the list and create PDO filters for any new devices
     for (Index = 0; Index < Count; Index++) {
 #pragma warning(suppress:6385)  // Reading invalid data from 
'PhysicalDeviceObject'
-        if (PhysicalDeviceObject[Index] != NULL) {
+        if (PhysicalDeviceObject[Index] != NULL)
             (VOID) FdoAddDevice(Fdo, PhysicalDeviceObject[Index]);
-            ObDereferenceObject(PhysicalDeviceObject[Index]);
-        }
     }
     
     __FdoReleaseMutex(Fdo);
@@ -1101,8 +1080,8 @@ FdoQueryDeviceRelations(
     KEVENT                  Event;
     PIO_STACK_LOCATION      StackLocation;
     ULONG                   Size;
+    PDEVICE_RELATIONS       LowerRelations;
     PDEVICE_RELATIONS       Relations;
-    PLIST_ENTRY             ListEntry;
     XENFILT_FILTER_STATE    State;
     ULONG                   Count;
     NTSTATUS                status;
@@ -1140,24 +1119,14 @@ FdoQueryDeviceRelations(
     if (StackLocation->Parameters.QueryDeviceRelations.Type != BusRelations)
         goto done;
 
-    Relations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
-
-    if (Relations->Count != 0)
-        FdoEnumerate(Fdo, Relations);
+    LowerRelations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
 
-    ExFreePool(Relations);
-
-    __FdoAcquireMutex(Fdo);
+    if (LowerRelations->Count != 0)
+        FdoEnumerate(Fdo, LowerRelations);
 
     State = DriverGetFilterState();
-    Count = 0;
 
-    if (State == XENFILT_FILTER_DISABLED) {
-        for (ListEntry = Fdo->List.Flink;
-             ListEntry != &Fdo->List;
-             ListEntry = ListEntry->Flink)
-            Count++;
-    }
+    Count = (State == XENFILT_FILTER_DISABLED) ? LowerRelations->Count : 0;
 
     Size = FIELD_OFFSET(DEVICE_RELATIONS, Objects) +
            (sizeof (PDEVICE_OBJECT) * __max(Count, 1));
@@ -1169,35 +1138,26 @@ FdoQueryDeviceRelations(
         goto fail3;
 
     if (State == XENFILT_FILTER_DISABLED) {
-        for (ListEntry = Fdo->List.Flink;
-             ListEntry != &Fdo->List;
-             ListEntry = ListEntry->Flink) {
-            PXENFILT_DX     Dx = CONTAINING_RECORD(ListEntry, XENFILT_DX, 
ListEntry);
-            PXENFILT_PDO    Pdo = Dx->Pdo;
-
-            ASSERT3U(Dx->Type, ==, PHYSICAL_DEVICE_OBJECT);
-
-            if (PdoGetDevicePnpState(Pdo) == Present)
-                PdoSetDevicePnpState(Pdo, Enumerated);
-
-            ObReferenceObject(PdoGetPhysicalDeviceObject(Pdo));
-            Relations->Objects[Relations->Count++] = 
PdoGetPhysicalDeviceObject(Pdo);
-        }
-
-        ASSERT3U(Relations->Count, <=, Count);
+        ASSERT3U(Count, ==, LowerRelations->Count);
+        RtlCopyMemory(Relations, LowerRelations, Size);
 
         Trace("%s: %d PDO(s)\n",
               __FdoGetName(Fdo),
               Relations->Count);
     } else {
+        ULONG   Index;
+
         Trace("%s: FILTERED\n",
               __FdoGetName(Fdo));
 
+        for (Index = 0; Index < LowerRelations->Count; Index++)
+            ObDereferenceObject(LowerRelations->Objects[Index]);
+
         IoInvalidateDeviceRelations(__FdoGetPhysicalDeviceObject(Fdo),
                                     BusRelations);
     }
 
-    __FdoReleaseMutex(Fdo);
+    ExFreePool(LowerRelations);
 
     Irp->IoStatus.Information = (ULONG_PTR)Relations;
     status = STATUS_SUCCESS;
@@ -1211,12 +1171,16 @@ done:
     return status;
 
 fail3:
-    __FdoReleaseMutex(Fdo);
+    Error("fail3\n");
 
 fail2:
+    Error("fail2\n");
+
     IoReleaseRemoveLock(&Fdo->Dx->RemoveLock, Irp);
 
 fail1:
+    Error("fail1 (%08x)\n", status);
+
     Irp->IoStatus.Status = status;
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
diff --git a/src/xenfilt/pdo.c b/src/xenfilt/pdo.c
index 893c76d..230fdf0 100644
--- a/src/xenfilt/pdo.c
+++ b/src/xenfilt/pdo.c
@@ -62,8 +62,6 @@ struct _XENFILT_PDO {
     PIRP                            DevicePowerIrp;
 
     PXENFILT_FDO                    Fdo;
-    BOOLEAN                         Missing;
-    const CHAR                      *Reason;
 
     XENFILT_EMULATED_OBJECT_TYPE    Type;
     PXENFILT_EMULATED_OBJECT        EmulatedObject;
@@ -189,41 +187,6 @@ PdoGetPhysicalDeviceObject(
     return Pdo->PhysicalDeviceObject;
 }
 
-static FORCEINLINE VOID
-__PdoSetMissing(
-    IN  PXENFILT_PDO    Pdo,
-    IN  const CHAR      *Reason
-    )
-{
-    Pdo->Reason = Reason;
-    Pdo->Missing = TRUE;
-}
-
-VOID
-PdoSetMissing(
-    IN  PXENFILT_PDO    Pdo,
-    IN  const CHAR      *Reason
-    )
-{
-    __PdoSetMissing(Pdo, Reason);
-}
-
-static FORCEINLINE BOOLEAN
-__PdoIsMissing(
-    IN  PXENFILT_PDO    Pdo
-    )
-{
-    return Pdo->Missing;
-}
-
-BOOLEAN
-PdoIsMissing(
-    IN  PXENFILT_PDO    Pdo
-    )
-{
-    return __PdoIsMissing(Pdo);
-}
-
 static FORCEINLINE PDEVICE_OBJECT
 __PdoGetDeviceObject(
     IN  PXENFILT_PDO    Pdo
@@ -817,22 +780,18 @@ PdoRemoveDevice(
     __PdoSetDevicePowerState(Pdo, PowerDeviceD3);
 
 done:
-    if (__PdoIsMissing(Pdo)) {
-        __PdoSetDevicePnpState(Pdo, Deleted);
-        IoReleaseRemoveLockAndWait(&Pdo->Dx->RemoveLock, Irp);
-    } else {
-        __PdoSetDevicePnpState(Pdo, Enumerated);
-        IoReleaseRemoveLock(&Pdo->Dx->RemoveLock, Irp);
-    }
+    FdoAcquireMutex(Fdo);
+    __PdoSetDevicePnpState(Pdo, Deleted);
+    FdoReleaseMutex(Fdo);
+
+    IoReleaseRemoveLockAndWait(&Pdo->Dx->RemoveLock, Irp);
 
     status = PdoForwardIrpSynchronously(Pdo, Irp);
     IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-    if (__PdoIsMissing(Pdo)) {
-        FdoAcquireMutex(Fdo);
-        PdoDestroy(Pdo);
-        FdoReleaseMutex(Fdo);
-    }
+    FdoAcquireMutex(Fdo);
+    PdoDestroy(Pdo);
+    FdoReleaseMutex(Fdo);
 
     return status;
 
@@ -1086,7 +1045,6 @@ PdoEject(
     PXENFILT_FDO        Fdo = __PdoGetFdo(Pdo);
     NTSTATUS            status;
 
-    __PdoSetMissing(Pdo, "Ejected");
     __PdoSetDevicePnpState(Pdo, Deleted);
 
     status = PdoForwardIrpSynchronously(Pdo, Irp);
@@ -2072,18 +2030,13 @@ PdoDestroy(
 
     ASSERT3U(__PdoGetDevicePnpState(Pdo), ==, Deleted);
 
-    ASSERT(__PdoIsMissing(Pdo));
-    Pdo->Missing = FALSE;
-
     FdoRemovePhysicalDeviceObject(Fdo, Pdo);
 
     Dx->Pdo = NULL;
 
-    Info("%p (%s) (%s)\n",
+    Info("%p (%s)\n",
          FilterDeviceObject,
-         __PdoGetName(Pdo),
-         Pdo->Reason);
-    Pdo->Reason = NULL;
+         __PdoGetName(Pdo));
 
     RtlZeroMemory(Pdo->Name, sizeof (Pdo->Name));
 
diff --git a/src/xenfilt/pdo.h b/src/xenfilt/pdo.h
index f44278e..05ca049 100644
--- a/src/xenfilt/pdo.h
+++ b/src/xenfilt/pdo.h
@@ -56,22 +56,6 @@ PdoGetPhysicalDeviceObject(
     IN  PXENFILT_PDO    Pdo
     );
 
-extern BOOLEAN
-PdoIsMissing(
-    IN  PXENFILT_PDO    Pdo
-    );
-
-extern VOID
-PdoSetMissing(
-    IN  PXENFILT_PDO    Pdo,
-    IN  const CHAR      *Reason
-    );
-
-extern BOOLEAN
-PdoIsMasked(
-    IN  PXENFILT_PDO    Pdo
-    );
-
 extern PDEVICE_OBJECT
 PdoGetDeviceObject(
     IN  PXENFILT_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®.