[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 4/7] Maintain a global list of FDOs in XENBUS
...similar to that in XENFILT. Also add a missing mutex acquisition around FdoCreate() in XENFILT. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- src/xenbus/driver.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++- src/xenbus/driver.h | 18 ++++++++--- src/xenbus/fdo.c | 32 +++++++++++++++++-- src/xenbus/fdo.h | 5 +++ src/xenfilt/driver.c | 6 ++++ 5 files changed, 141 insertions(+), 7 deletions(-) diff --git a/src/xenbus/driver.c b/src/xenbus/driver.c index 6135400..3409270 100644 --- a/src/xenbus/driver.c +++ b/src/xenbus/driver.c @@ -38,6 +38,7 @@ #include "pdo.h" #include "driver.h" #include "names.h" +#include "mutex.h" #include "dbg_print.h" #include "assert.h" #include "util.h" @@ -49,6 +50,10 @@ typedef struct _XENBUS_DRIVER { PDRIVER_OBJECT DriverObject; HANDLE ParametersKey; HANDLE StatusKey; + + MUTEX Mutex; + LIST_ENTRY List; + ULONG References; } XENBUS_DRIVER, *PXENBUS_DRIVER; static XENBUS_DRIVER Driver; @@ -149,6 +154,71 @@ DriverRequestReboot( 1); } +static FORCEINLINE VOID +__DriverAcquireMutex( + VOID + ) +{ + AcquireMutex(&Driver.Mutex); +} + +VOID +DriverAcquireMutex( + VOID + ) +{ + __DriverAcquireMutex(); +} + +static FORCEINLINE VOID +__DriverReleaseMutex( + VOID + ) +{ + ReleaseMutex(&Driver.Mutex); +} + +VOID +DriverReleaseMutex( + VOID + ) +{ + __DriverReleaseMutex(); +} + +VOID +DriverAddFunctionDeviceObject( + IN PXENBUS_FDO Fdo + ) +{ + PDEVICE_OBJECT DeviceObject; + PXENBUS_DX Dx; + + DeviceObject = FdoGetDeviceObject(Fdo); + Dx = (PXENBUS_DX)DeviceObject->DeviceExtension; + ASSERT3U(Dx->Type, ==, FUNCTION_DEVICE_OBJECT); + + InsertTailList(&Driver.List, &Dx->ListEntry); + Driver.References++; +} + +VOID +DriverRemoveFunctionDeviceObject( + IN PXENBUS_FDO Fdo + ) +{ + PDEVICE_OBJECT DeviceObject; + PXENBUS_DX Dx; + + DeviceObject = FdoGetDeviceObject(Fdo); + Dx = (PXENBUS_DX)DeviceObject->DeviceExtension; + ASSERT3U(Dx->Type, ==, FUNCTION_DEVICE_OBJECT); + + RemoveEntryList(&Dx->ListEntry); + ASSERT3U(Driver.References, !=, 0); + --Driver.References; +} + DRIVER_UNLOAD DriverUnload; VOID @@ -166,6 +236,13 @@ DriverUnload( if (*InitSafeBootMode > 0) goto done; + ASSERT(IsListEmpty(&Driver.List)); + ASSERT3U(Driver.References, ==, 1); + --Driver.References; + + RtlZeroMemory(&Driver.List, sizeof (LIST_ENTRY)); + RtlZeroMemory(&Driver.Mutex, sizeof (MUTEX)); + StatusKey = __DriverGetStatusKey(); __DriverSetStatusKey(NULL); @@ -210,16 +287,20 @@ DriverAddDevice( Trace("====>\n"); + __DriverAcquireMutex(); + status = FdoCreate(DeviceObject); if (!NT_SUCCESS(status)) goto fail1; + __DriverReleaseMutex(); + Trace("<====\n"); return STATUS_SUCCESS; fail1: - Error("fail1 (%08x)\n", status); + __DriverReleaseMutex(); return status; } @@ -352,6 +433,10 @@ DriverEntry( DriverObject->MajorFunction[Index] = DriverDispatch; } + InitializeMutex(&Driver.Mutex); + InitializeListHead(&Driver.List); + Driver.References = 1; + done: Trace("<====\n"); diff --git a/src/xenbus/driver.h b/src/xenbus/driver.h index 0208f9c..78b1b25 100644 --- a/src/xenbus/driver.h +++ b/src/xenbus/driver.h @@ -48,14 +48,14 @@ DriverRequestReboot( ); extern VOID -DriverAddFilters( +DriverAcquireMutex( VOID - ); + ); extern VOID -DriverRemoveFilters( +DriverReleaseMutex( VOID - ); + ); typedef struct _XENBUS_FDO XENBUS_FDO, *PXENBUS_FDO; typedef struct _XENBUS_PDO XENBUS_PDO, *PXENBUS_PDO; @@ -65,6 +65,16 @@ typedef struct _XENBUS_PDO XENBUS_PDO, *PXENBUS_PDO; #define MAX_DEVICE_ID_LEN 200 +extern VOID +DriverAddFunctionDeviceObject( + IN PXENBUS_FDO Fdo + ); + +extern VOID +DriverRemoveFunctionDeviceObject( + IN PXENBUS_FDO Fdo + ); + #pragma warning(push) #pragma warning(disable:4201) // nonstandard extension used : nameless struct/union diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c index 28ccb36..5d03f8c 100644 --- a/src/xenbus/fdo.c +++ b/src/xenbus/fdo.c @@ -250,6 +250,24 @@ __FdoGetSystemPowerState( } static FORCEINLINE PDEVICE_OBJECT +__FdoGetDeviceObject( + IN PXENBUS_FDO Fdo + ) +{ + PXENBUS_DX Dx = Fdo->Dx; + + return Dx->DeviceObject; +} + +PDEVICE_OBJECT +FdoGetDeviceObject( + IN PXENBUS_FDO Fdo + ) +{ + return __FdoGetDeviceObject(Fdo); +} + +static FORCEINLINE PDEVICE_OBJECT __FdoGetPhysicalDeviceObject( IN PXENBUS_FDO Fdo ) @@ -1015,8 +1033,11 @@ FdoReleaseMutex( { __FdoReleaseMutex(Fdo); - if (Fdo->References == 0) + if (Fdo->References == 0) { + DriverAcquireMutex(); FdoDestroy(Fdo); + DriverReleaseMutex(); + } } static BOOLEAN @@ -3513,8 +3534,11 @@ done: --Fdo->References; __FdoReleaseMutex(Fdo); - if (Fdo->References == 0) + if (Fdo->References == 0) { + DriverAcquireMutex(); FdoDestroy(Fdo); + DriverReleaseMutex(); + } return status; } @@ -4923,6 +4947,8 @@ done: Dx->Fdo = Fdo; FunctionDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; + DriverAddFunctionDeviceObject(Fdo); + return STATUS_SUCCESS; fail19: @@ -5053,6 +5079,8 @@ FdoDestroy( ASSERT3U(Fdo->References, ==, 0); ASSERT3U(__FdoGetDevicePnpState(Fdo), ==, Deleted); + DriverRemoveFunctionDeviceObject(Fdo); + Fdo->NotDisableable = FALSE; Info("%p (%s)\n", diff --git a/src/xenbus/fdo.h b/src/xenbus/fdo.h index 96a2250..9e9b599 100644 --- a/src/xenbus/fdo.h +++ b/src/xenbus/fdo.h @@ -78,6 +78,11 @@ FdoReleaseMutex( ); extern PDEVICE_OBJECT +FdoGetDeviceObject( + IN PXENBUS_FDO Fdo + ); + +extern PDEVICE_OBJECT FdoGetPhysicalDeviceObject( IN PXENBUS_FDO Fdo ); diff --git a/src/xenfilt/driver.c b/src/xenfilt/driver.c index 77f719a..84766dd 100644 --- a/src/xenfilt/driver.c +++ b/src/xenfilt/driver.c @@ -572,6 +572,8 @@ DriverAddDevice( DeviceID, &Type); if (NT_SUCCESS(status)) { + __DriverAcquireMutex(); + status = FdoCreate(PhysicalDeviceObject, DeviceID, InstanceID, @@ -580,12 +582,16 @@ DriverAddDevice( if (!NT_SUCCESS(status)) goto fail3; + __DriverReleaseMutex(); + RegistryFreeSzValue(Type); } return STATUS_SUCCESS; fail3: + __DriverReleaseMutex(); + fail2: fail1: return status; -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |