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

Re: [win-pv-devel] [PATCH 3/6] Refactor Wmi header, split initialize/teardown and register/deregister



> -----Original Message-----
> From: win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx [mailto:win-pv-devel-
> bounces@xxxxxxxxxxxxxxxxxxxx] On Behalf Of Owen Smith
> Sent: 29 October 2015 14:50
> To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Owen Smith
> Subject: [win-pv-devel] [PATCH 3/6] Refactor Wmi header, split
> initialize/teardown and register/deregister
> 
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>

Acked-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

> ---
>  src/xeniface/fdo.c |  44 +++++++++++++------
>  src/xeniface/wmi.c | 124 +++++++++++++++++++++++++++++++++++------
> ------------
>  src/xeniface/wmi.h |  47 ++++++++++++--------
>  3 files changed, 143 insertions(+), 72 deletions(-)
> 
> diff --git a/src/xeniface/fdo.c b/src/xeniface/fdo.c
> index b32e506..10ead15 100644
> --- a/src/xeniface/fdo.c
> +++ b/src/xeniface/fdo.c
> @@ -896,7 +896,7 @@ FdoStartDevice(
> 
> 
>      if (__FdoGetDevicePnpState(Fdo) != Stopped) {
> -        status = WmiInit(Fdo);
> +        status = WmiRegister(Fdo);
>          if (!NT_SUCCESS(status))
>              goto fail5;
>      }
> @@ -1046,7 +1046,7 @@ FdoSurpriseRemoval(
>      Irp->IoStatus.Status = STATUS_SUCCESS;
>  #pragma warning(suppress : 6031)
>      IoSetDeviceInterfaceState(&Fdo->InterfaceName, FALSE);
> -    WmiFinalise(Fdo);
> +    WmiDeregister(Fdo);
> 
>      IoSkipCurrentIrpStackLocation(Irp);
>      status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
> @@ -1081,7 +1081,7 @@ done:
>      Irp->IoStatus.Status = STATUS_SUCCESS;
>  #pragma warning(suppress : 6031)
>      IoSetDeviceInterfaceState(&Fdo->InterfaceName, FALSE);
> -    WmiFinalise(Fdo);
> +    WmiDeregister(Fdo);
> 
>      IoSkipCurrentIrpStackLocation(Irp);
>      status = IoCallDriver(Fdo->LowerDeviceObject, Irp);
> @@ -1335,7 +1335,7 @@ __FdoSetDevicePowerUp(
> 
>      ASSERT3U(DeviceState, ==, PowerDeviceD0);
>      status = FdoD3ToD0(Fdo);
> -    SessionsResumeAll(Fdo);
> +    WmiSessionsResumeAll(Fdo);
>      ASSERT(NT_SUCCESS(status));
> 
>  done:
> @@ -1368,7 +1368,7 @@ __FdoSetDevicePowerDown(
>      ASSERT3U(DeviceState, ==, PowerDeviceD3);
> 
>      if (__FdoGetDevicePowerState(Fdo) == PowerDeviceD0){
> -        SessionsSuspendAll(Fdo);
> +        WmiSessionsSuspendAll(Fdo);
>          FdoD0ToD3(Fdo);
>      }
> 
> @@ -2322,6 +2322,10 @@ FdoCreate(
>      if (!NT_SUCCESS(status))
>          goto fail13;
> 
> +    status = WmiInitialize(Fdo);
> +    if (!NT_SUCCESS(status))
> +        goto fail14;
> +
>      KeInitializeSpinLock(&Fdo->StoreWatchLock);
>      InitializeListHead(&Fdo->StoreWatchList);
> 
> @@ -2341,7 +2345,7 @@ FdoCreate(
>                                 CsqReleaseLock,
>                                 CsqCompleteCanceledIrp);
>      if (!NT_SUCCESS(status))
> -        goto fail14;
> +        goto fail15;
> 
>  #if (NTDDI_VERSION >= NTDDI_WIN7)
>      ProcessorCount =
> KeQueryMaximumProcessorCountEx(ALL_PROCESSOR_GROUPS);
> @@ -2352,7 +2356,7 @@ FdoCreate(
>      status = STATUS_NO_MEMORY;
>      Fdo->EvtchnDpc = __FdoAllocate(sizeof (KDPC) * ProcessorCount);
>      if (Fdo->EvtchnDpc == NULL)
> -        goto fail15;
> +        goto fail16;
> 
>      for (Index = 0; Index < ProcessorCount; Index++) {
>  #if (NTDDI_VERSION >= NTDDI_WIN7)
> @@ -2379,9 +2383,29 @@ FdoCreate(
> 
>      return STATUS_SUCCESS;
> 
> +fail16:
> +    Error("fail6\n");
> +
> +    RtlZeroMemory(&Fdo->IrpQueue, sizeof (IO_CSQ));
> +
>  fail15:
>      Error("fail15\n");
> 
> +    RtlZeroMemory(&Fdo->GnttabCacheLock, sizeof (KSPIN_LOCK));
> +    ASSERT(IsListEmpty(&Fdo->IrpList));
> +    RtlZeroMemory(&Fdo->IrpList, sizeof (LIST_ENTRY));
> +    RtlZeroMemory(&Fdo->IrpQueueLock, sizeof (KSPIN_LOCK));
> +
> +    ASSERT(IsListEmpty(&Fdo->EvtchnList));
> +    RtlZeroMemory(&Fdo->EvtchnList, sizeof (LIST_ENTRY));
> +    RtlZeroMemory(&Fdo->EvtchnLock, sizeof (KSPIN_LOCK));
> +
> +    ASSERT(IsListEmpty(&Fdo->StoreWatchList));
> +    RtlZeroMemory(&Fdo->StoreWatchList, sizeof (LIST_ENTRY));
> +    RtlZeroMemory(&Fdo->StoreWatchLock, sizeof (KSPIN_LOCK));
> +
> +    WmiTeardown(Fdo);
> +
>  fail14:
>      Error("fail14\n");
> 
> @@ -2468,9 +2492,6 @@ fail1:
>      return status;
>  }
> 
> -
> -
> -
>  VOID
>  FdoDestroy(
>      IN  PXENIFACE_FDO     Fdo
> @@ -2552,8 +2573,7 @@ FdoDestroy(
>      Fdo->PhysicalDeviceObject = NULL;
>      Fdo->Dx = NULL;
> 
> -    RtlZeroMemory(&Fdo->SessionLock, sizeof(FAST_MUTEX));
> -    RtlZeroMemory(&Fdo->SessionHead, sizeof(LIST_ENTRY));
> +    WmiTeardown(Fdo);
>      RtlZeroMemory(&Fdo->registryWriteEvent, sizeof(KEVENT));
> 
>      RtlFreeUnicodeString(&Fdo->InterfaceName);
> diff --git a/src/xeniface/wmi.c b/src/xeniface/wmi.c
> index 0ae87d4..1ae84e1 100644
> --- a/src/xeniface/wmi.c
> +++ b/src/xeniface/wmi.c
> @@ -1255,20 +1255,23 @@ void SuspendSessionLocked(XENIFACE_FDO
> *fdoData,
>      }
>  }
> 
> -
> -void SessionsSuspendAll(XENIFACE_FDO *fdoData) {
> +VOID
> +WmiSessionsSuspendAll(
> +    IN  PXENIFACE_FDO   Fdo
> +    )
> +{
>      XenStoreSession *session;
> -    LockSessions(fdoData);
> +
> +    LockSessions(Fdo);
>      XenIfaceDebugPrint(TRACE,"Suspend all sessions\n");
> -    session = (XenStoreSession *)fdoData->SessionHead.Flink;
> -    while (session != (XenStoreSession *)&fdoData->SessionHead) {
> -        SuspendSessionLocked(fdoData, session);
> +    session = (XenStoreSession *)Fdo->SessionHead.Flink;
> +    while (session != (XenStoreSession *)&Fdo->SessionHead) {
> +        SuspendSessionLocked(Fdo, session);
>          session = (XenStoreSession *)session->listentry.Flink;
>      }
> -    UnlockSessions(fdoData);
> +    UnlockSessions(Fdo);
>  }
> 
> -
>  void SessionRenewWatchesLocked(XenStoreSession *session) {
>      int i;
>      XenStoreWatch *watch;
> @@ -1300,61 +1303,61 @@ void ResumeSessionLocked(XENIFACE_FDO
> *fdoData,
>      SessionRenewWatchesLocked(session);
>  }
> 
> -void SessionsResumeAll(XENIFACE_FDO *fdoData) {
> +VOID
> +WmiSessionsResumeAll(
> +    IN  PXENIFACE_FDO   Fdo
> +    )
> +{
>      XenStoreSession *session;
> 
> -    LockSessions(fdoData);
> +    LockSessions(Fdo);
>      XenIfaceDebugPrint(TRACE,"Resume all sessions\n");
> -    session = (XenStoreSession *)fdoData->SessionHead.Flink;
> -    while (session != (XenStoreSession *)&fdoData->SessionHead) {
> -        ResumeSessionLocked(fdoData, session );
> -        session=(XenStoreSession *)session->listentry.Flink;
> +    session = (XenStoreSession *)Fdo->SessionHead.Flink;
> +    while (session != (XenStoreSession *)&Fdo->SessionHead) {
> +        ResumeSessionLocked(Fdo, session);
> +        session = (XenStoreSession *)session->listentry.Flink;
>      }
> -    UnlockSessions(fdoData);
> +    UnlockSessions(Fdo);
>  }
> 
> -
>  NTSTATUS
> -WmiInit(
> -        PXENIFACE_FDO FdoData
> +WmiRegister(
> +    IN  PXENIFACE_FDO   Fdo
>      )
>  {
> -    NTSTATUS status = STATUS_SUCCESS;
> +    NTSTATUS            status;
> +
>      XenIfaceDebugPrint(TRACE,"%s\n",__FUNCTION__);
>      XenIfaceDebugPrint(INFO,"DRV: XenIface WMI Initialisation\n");
> 
> +    status = IoWMIRegistrationControl(Fdo->Dx->DeviceObject,
> +                                      WMIREG_ACTION_REGISTER);
> +    if (!NT_SUCCESS(status))
> +        goto fail1;
> 
> +    Fdo->WmiReady = 1;
> +    return STATUS_SUCCESS;
> 
> -
> -    IoWMISuggestInstanceName(FdoData->PhysicalDeviceObject, NULL,
> FALSE,
> -                             &FdoData->SuggestedInstanceName);
> -    InitializeListHead(&FdoData->SessionHead);
> -    FdoData->Sessions = 0;
> -    ExInitializeFastMutex(&FdoData->SessionLock);
> -
> -    status = IoWMIRegistrationControl(FdoData->Dx->DeviceObject,
> WMIREG_ACTION_REGISTER);
> -    FdoData->WmiReady = 1;
> +fail1:
> +    Error("fail1 (%08x)\n", status);
>      return status;
>  }
> 
> -NTSTATUS
> -WmiFinalise(
> -    PXENIFACE_FDO FdoData
> +VOID
> +WmiDeregister(
> +    IN  PXENIFACE_FDO   Fdo
>      )
>  {
> -    NTSTATUS status = STATUS_SUCCESS;
> -    if (FdoData->WmiReady) {
> -        XenIfaceDebugPrint(INFO,"DRV: XenIface WMI Finalisation\n");
> -        XenIfaceDebugPrint(TRACE,"%s\n",__FUNCTION__);
> -        SessionsRemoveAll(FdoData);
> +    if (!Fdo->WmiReady)
> +        return;
> 
> -        status =IoWMIRegistrationControl(FdoData->Dx->DeviceObject,
> WMIREG_ACTION_DEREGISTER);
> -        RtlFreeUnicodeString(&FdoData->SuggestedInstanceName);
> -        RtlZeroBytes(&FdoData->SuggestedInstanceName,
> sizeof(UNICODE_STRING));
> +    XenIfaceDebugPrint(INFO,"DRV: XenIface WMI Finalisation\n");
> +    XenIfaceDebugPrint(TRACE,"%s\n",__FUNCTION__);
> 
> -        FdoData->WmiReady = 0;
> -    }
> -    return status;
> +    SessionsRemoveAll(Fdo);
> +    (VOID) IoWMIRegistrationControl(Fdo->Dx->DeviceObject,
> +                                    WMIREG_ACTION_DEREGISTER);
> +    Fdo->WmiReady = 0;
>  }
> 
>  NTSTATUS
> @@ -3090,4 +3093,41 @@ Updated Routine Description:
>      }
>  }
> 
> +NTSTATUS
> +WmiInitialize(
> +    IN  PXENIFACE_FDO   Fdo
> +    )
> +{
> +    NTSTATUS            status;
> +
> +    status = IoWMISuggestInstanceName(Fdo->PhysicalDeviceObject,
> +                                      NULL,
> +                                      FALSE,
> +                                      &Fdo->SuggestedInstanceName);
> +    if (!NT_SUCCESS(status))
> +        goto fail1;
> +
> +    Fdo->Sessions = 0;
> +    InitializeListHead(&Fdo->SessionHead);
> +    ExInitializeFastMutex(&Fdo->SessionLock);
> +
> +    return STATUS_SUCCESS;
> +
> +fail1:
> +    Error("fail1 (%08x)\n", status);
> +    return status;
> +}
> +
> +VOID
> +WmiTeardown(
> +    IN  PXENIFACE_FDO   Fdo
> +    )
> +{
> +    ASSERT(Fdo->Sessions == 0);
> +
> +    RtlZeroMemory(&Fdo->SessionLock, sizeof(FAST_MUTEX));
> +    RtlZeroMemory(&Fdo->SessionHead, sizeof(LIST_ENTRY));
> 
> +    RtlFreeUnicodeString(&Fdo->SuggestedInstanceName);
> +    RtlZeroMemory(&Fdo->SuggestedInstanceName,
> sizeof(UNICODE_STRING));
> +}
> diff --git a/src/xeniface/wmi.h b/src/xeniface/wmi.h
> index b9dd256..2656b46 100644
> --- a/src/xeniface/wmi.h
> +++ b/src/xeniface/wmi.h
> @@ -38,33 +38,44 @@
>  #include "wmi_generated.h"
> 
>  extern NTSTATUS
> -WmiProcessMinorFunction(
> -    IN  PXENIFACE_FDO   Fdo,
> -    IN  PIRP            Irp
> +WmiInitialize(
> +    IN  PXENIFACE_FDO   Fdo
>      );
> 
>  extern VOID
> -WmiFireSuspendEvent(
> +WmiTeardown(
>      IN  PXENIFACE_FDO   Fdo
>      );
> 
> -NTSTATUS
> -WmiInit(
> -    PXENIFACE_FDO FdoData
> -);
> +extern NTSTATUS
> +WmiRegister(
> +    IN  PXENIFACE_FDO   Fdo
> +    );
> 
> +extern VOID
> +WmiDeregister(
> +    IN  PXENIFACE_FDO   Fdo
> +    );
> 
> -NTSTATUS
> -WmiFinalise(
> -    PXENIFACE_FDO FdoData
> -);
> +extern VOID
> +WmiSessionsResumeAll(
> +    IN  PXENIFACE_FDO   Fdo
> +    );
> 
> -void SessionsResumeAll(
> -    XENIFACE_FDO *fdoData
> -);
> +extern VOID
> +WmiSessionsSuspendAll(
> +    IN  PXENIFACE_FDO   Fdo
> +    );
> 
> -void SessionsSuspendAll(
> -    XENIFACE_FDO *fdoData
> -);
> +extern NTSTATUS
> +WmiProcessMinorFunction(
> +    IN  PXENIFACE_FDO   Fdo,
> +    IN  PIRP            Irp
> +    );
> +
> +extern VOID
> +WmiFireSuspendEvent(
> +    IN  PXENIFACE_FDO   Fdo
> +    );
> 
>  #endif
> --
> 1.9.4.msysgit.1
> 
> 
> _______________________________________________
> win-pv-devel mailing list
> win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

_______________________________________________
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®.