[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 4/4] Use new unplug mechanism
Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- include/emulated_interface.h | 129 ------------------------------------------- include/unplug_interface.h | 116 ++++++++++++++++++++++++++++++++++++++ src/xenvif.inf | 6 +- src/xenvif/fdo.c | 22 +++++++- src/xenvif/fdo.h | 4 +- src/xenvif/pdo.c | 69 +++++++++++++++++------ 6 files changed, 195 insertions(+), 151 deletions(-) delete mode 100644 include/emulated_interface.h create mode 100644 include/unplug_interface.h diff --git a/include/emulated_interface.h b/include/emulated_interface.h deleted file mode 100644 index 9361f8d..0000000 --- a/include/emulated_interface.h +++ /dev/null @@ -1,129 +0,0 @@ -/* Copyright (c) Citrix Systems Inc. - * All rights reserved. - * - * Redistribution and use in source and binary forms, - * with or without modification, are permitted provided - * that the following conditions are met: - * - * * Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/*! \file emulated_interface.h - \brief XENFILT EMULATED Interface - - This interface provides primitives to determine whether emulated - devices or disks are present in the VM -*/ - -#ifndef _XENFILT_EMULATED_INTERFACE_H -#define _XENFILT_EMULATED_INTERFACE_H - -#ifndef _WINDLL - -/*! \typedef XENFILT_EMULATED_ACQUIRE - \brief Acquire a reference to the EMULATED interface - - \param Interface The interface header -*/ -typedef NTSTATUS -(*XENFILT_EMULATED_ACQUIRE)( - IN PINTERFACE Interface - ); - -/*! \typedef XENFILT_EMULATED_RELEASE - \brief Release a reference to the EMULATED interface - - \param Interface The interface header -*/ -typedef VOID -(*XENFILT_EMULATED_RELEASE)( - IN PINTERFACE Interface - ); - -/*! \typedef XENFILT_EMULATED_IS_DEVICE_PRESENT - \brief Determine whether a given device is present in the VM - - \param Interface The interface header - \param DeviceID The DeviceID of the device - \param InstanceID The (un-prefixed) InstanceID of the device or - NULL to match any device instance - \return TRUE if the specified device is present in the system or - FALSE if it is not -*/ -typedef BOOLEAN -(*XENFILT_EMULATED_IS_DEVICE_PRESENT)( - IN PVOID Context, - IN PCHAR DeviceID, - IN PCHAR InstanceID OPTIONAL - ); - -/*! \typedef XENFILT_EMULATED_IS_DISK_PRESENT - \brief Determine whether a given disk is present in the VM - - \param Interface The interface header - \param Controller The controller index of the HBA - \param Target The target index of the disk - \param Lun The Logical Unit Number of the disk within the target - \return TRUE if the specified disk is present in the system or - FALSE if it is not -*/ -typedef BOOLEAN -(*XENFILT_EMULATED_IS_DISK_PRESENT)( - IN PVOID Context, - IN ULONG Controller, - IN ULONG Target, - IN ULONG Lun - ); - -// {959027A1-FCCE-4E78-BCF4-637384F499C5} -DEFINE_GUID(GUID_XENFILT_EMULATED_INTERFACE, -0x959027a1, 0xfcce, 0x4e78, 0xbc, 0xf4, 0x63, 0x73, 0x84, 0xf4, 0x99, 0xc5); - -/*! \struct _XENFILT_EMULATED_INTERFACE_V1 - \brief EMULATED interface version 1 - \ingroup interfaces -*/ -struct _XENFILT_EMULATED_INTERFACE_V1 { - INTERFACE Interface; - XENFILT_EMULATED_ACQUIRE EmulatedAcquire; - XENFILT_EMULATED_RELEASE EmulatedRelease; - XENFILT_EMULATED_IS_DEVICE_PRESENT EmulatedIsDevicePresent; - XENFILT_EMULATED_IS_DISK_PRESENT EmulatedIsDiskPresent; -}; - -typedef struct _XENFILT_EMULATED_INTERFACE_V1 XENFILT_EMULATED_INTERFACE, *PXENFILT_EMULATED_INTERFACE; - -/*! \def XENFILT_EMULATED - \brief Macro at assist in method invocation -*/ -#define XENFILT_EMULATED(_Method, _Interface, ...) \ - (_Interface)->Emulated ## _Method((PINTERFACE)(_Interface), __VA_ARGS__) - -#endif // _WINDLL - -#define XENFILT_EMULATED_INTERFACE_VERSION_MIN 1 -#define XENFILT_EMULATED_INTERFACE_VERSION_MAX 1 - -#endif // _XENFILT_EMULATED_INTERFACE_H - diff --git a/include/unplug_interface.h b/include/unplug_interface.h new file mode 100644 index 0000000..6f45975 --- /dev/null +++ b/include/unplug_interface.h @@ -0,0 +1,116 @@ +/* Copyright (c) Citrix Systems Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, + * with or without modification, are permitted provided + * that the following conditions are met: + * + * * Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the + * following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*! \file unplug_interface.h + \brief XENBUS UNPLUG Interface + + This interface provides a method to request emulated device unplug +*/ + +#ifndef _XENBUS_UNPLUG_INTERFACE_H +#define _XENBUS_UNPLUG_INTERFACE_H + +#ifndef _WINDLL + +/*! \typedef XENBUS_UNPLUG_ACQUIRE + \brief Acquire a reference to the UNPLUG interface + + \param Interface The interface header +*/ +typedef NTSTATUS +(*XENBUS_UNPLUG_ACQUIRE)( + IN PINTERFACE Interface + ); + +/*! \typedef XENBUS_UNPLUG_RELEASE + \brief Release a reference to the UNPLUG interface + + \param Interface The interface header +*/ +typedef VOID +(*XENBUS_UNPLUG_RELEASE)( + IN PINTERFACE Interface + ); + +/*! \enum _XENBUS_UNPLUG_DEVICE_TYPE + \brief Type of device to be unplugged +*/ +typedef enum _XENBUS_UNPLUG_DEVICE_TYPE { + XENBUS_UNPLUG_DEVICE_TYPE_INVALID = 0, + XENBUS_UNPLUG_DEVICE_TYPE_NICS, /*!< NICs */ + XENBUS_UNPLUG_DEVICE_TYPE_DISKS, /*!< Disks */ +} XENBUS_UNPLUG_DEVICE_TYPE, *PXENBUS_UNPLUG_DEVICE_TYPE; + +/*! \typedef XENBUS_UNPLUG_REQUEST + \brief Request unplug of a type of emulated device + + \param Interface The interface header + \param Type The type of device + \param Make Set to TRUE if the request is being made, FALSE if it is + being revoked. +*/ +typedef VOID +(*XENBUS_UNPLUG_REQUEST)( + IN PINTERFACE Interface, + IN XENBUS_UNPLUG_DEVICE_TYPE Type, + IN BOOLEAN Make + ); + +// {73db6517-3d06-4937-989f-199b7501e229} +DEFINE_GUID(GUID_XENBUS_UNPLUG_INTERFACE, +0x73db6517, 0x3d06, 0x4937, 0x98, 0x9f, 0x19, 0x9b, 0x75, 0x01, 0xe2, 0x29); + +/*! \struct _XENBUS_UNPLUG_INTERFACE_V1 + \brief UNPLUG interface version 1 + \ingroup interfaces +*/ +struct _XENBUS_UNPLUG_INTERFACE_V1 { + INTERFACE Interface; + XENBUS_UNPLUG_ACQUIRE UnplugAcquire; + XENBUS_UNPLUG_RELEASE UnplugRelease; + XENBUS_UNPLUG_REQUEST UnplugRequest; +}; + +typedef struct _XENBUS_UNPLUG_INTERFACE_V1 XENBUS_UNPLUG_INTERFACE, *PXENBUS_UNPLUG_INTERFACE; + +/*! \def XENBUS_UNPLUG + \brief Macro at assist in method invocation +*/ +#define XENBUS_UNPLUG(_Method, _Interface, ...) \ + (_Interface)->Unplug ## _Method((PINTERFACE)(_Interface), __VA_ARGS__) + +#endif // _WINDLL + +#define XENBUS_UNPLUG_INTERFACE_VERSION_MIN 1 +#define XENBUS_UNPLUG_INTERFACE_VERSION_MAX 1 + +#endif // _XENBUS_UNPLUG_INTERFACE_H + diff --git a/src/xenvif.inf b/src/xenvif.inf index ab1fd36..727fbcc 100644 --- a/src/xenvif.inf +++ b/src/xenvif.inf @@ -58,9 +58,9 @@ xenvif_coinst_@MAJOR_VERSION@_@MINOR_VERSION@_@MICRO_VERSION@_@BUILD_NUMBER@.dll ; DisplayName Section DeviceID ; ----------- ------- -------- -%XenVifDesc% =XenVif_Inst, XENBUS\VEN_XSC000&DEV_VIF&REV_08000008 -%XenVifDesc% =XenVif_Inst, XENBUS\VEN_XS0001&DEV_VIF&REV_08000008 -%XenVifDesc% =XenVif_Inst, XENBUS\VEN_XS0002&DEV_VIF&REV_08000008 +%XenVifDesc% =XenVif_Inst, XENBUS\VEN_XSC000&DEV_VIF&REV_08000009 +%XenVifDesc% =XenVif_Inst, XENBUS\VEN_XS0001&DEV_VIF&REV_08000009 +%XenVifDesc% =XenVif_Inst, XENBUS\VEN_XS0002&DEV_VIF&REV_08000009 [XenVif_Inst] CopyFiles=XenVif_Copyfiles diff --git a/src/xenvif/fdo.c b/src/xenvif/fdo.c index aabc9c1..65d1b55 100644 --- a/src/xenvif/fdo.c +++ b/src/xenvif/fdo.c @@ -41,7 +41,7 @@ #include <store_interface.h> #include <gnttab_interface.h> #include <suspend_interface.h> -#include <emulated_interface.h> +#include <unplug_interface.h> #include "driver.h" #include "registry.h" @@ -101,6 +101,7 @@ struct _XENVIF_FDO { XENBUS_RANGE_SET_INTERFACE RangeSetInterface; XENBUS_CACHE_INTERFACE CacheInterface; XENBUS_GNTTAB_INTERFACE GnttabInterface; + XENBUS_UNPLUG_INTERFACE UnplugInterface; PXENBUS_SUSPEND_CALLBACK SuspendCallbackLate; }; @@ -2772,6 +2773,7 @@ DEFINE_FDO_GET_INTERFACE(Store, PXENBUS_STORE_INTERFACE) DEFINE_FDO_GET_INTERFACE(RangeSet, PXENBUS_RANGE_SET_INTERFACE) DEFINE_FDO_GET_INTERFACE(Cache, PXENBUS_CACHE_INTERFACE) DEFINE_FDO_GET_INTERFACE(Gnttab, PXENBUS_GNTTAB_INTERFACE) +DEFINE_FDO_GET_INTERFACE(Unplug, PXENBUS_UNPLUG_INTERFACE) NTSTATUS FdoCreate( @@ -2901,6 +2903,15 @@ FdoCreate( if (!NT_SUCCESS(status)) goto fail13; + status = FDO_QUERY_INTERFACE(Fdo, + XENBUS, + UNPLUG, + (PINTERFACE)&Fdo->UnplugInterface, + sizeof (Fdo->UnplugInterface), + FALSE); + if (!NT_SUCCESS(status)) + goto fail14; + Dx->Fdo = Fdo; InitializeMutex(&Fdo->Mutex); @@ -2914,6 +2925,12 @@ FdoCreate( FunctionDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; return STATUS_SUCCESS; +fail14: + Error("fail14\n"); + + RtlZeroMemory(&Fdo->UnplugInterface, + sizeof (XENBUS_UNPLUG_INTERFACE)); + fail13: Error("fail13\n"); @@ -3020,6 +3037,9 @@ FdoDestroy( Dx->Fdo = NULL; + RtlZeroMemory(&Fdo->UnplugInterface, + sizeof (XENBUS_UNPLUG_INTERFACE)); + RtlZeroMemory(&Fdo->GnttabInterface, sizeof (XENBUS_GNTTAB_INTERFACE)); diff --git a/src/xenvif/fdo.h b/src/xenvif/fdo.h index 68d7b4a..23f07cb 100644 --- a/src/xenvif/fdo.h +++ b/src/xenvif/fdo.h @@ -40,7 +40,7 @@ #include <range_set_interface.h> #include <cache_interface.h> #include <gnttab_interface.h> -#include <emulated_interface.h> +#include <unplug_interface.h> #include "driver.h" #include "types.h" @@ -142,7 +142,7 @@ DECLARE_FDO_GET_INTERFACE(Store, PXENBUS_STORE_INTERFACE) DECLARE_FDO_GET_INTERFACE(RangeSet, PXENBUS_RANGE_SET_INTERFACE) DECLARE_FDO_GET_INTERFACE(Cache, PXENBUS_CACHE_INTERFACE) DECLARE_FDO_GET_INTERFACE(Gnttab, PXENBUS_GNTTAB_INTERFACE) -DECLARE_FDO_GET_INTERFACE(Emulated, PXENFILT_EMULATED_INTERFACE) +DECLARE_FDO_GET_INTERFACE(Unplug, PXENBUS_UNPLUG_INTERFACE) extern NTSTATUS FdoCreate( diff --git a/src/xenvif/pdo.c b/src/xenvif/pdo.c index 1470c8a..c61f7e8 100644 --- a/src/xenvif/pdo.c +++ b/src/xenvif/pdo.c @@ -40,8 +40,8 @@ #include <bcrypt.h> #include <xen.h> -#include <store_interface.h> -#include <emulated_interface.h> +#include <suspend_interface.h> +#include <unplug_interface.h> #include "names.h" #include "fdo.h" @@ -85,6 +85,8 @@ struct _XENVIF_PDO { XENBUS_SUSPEND_INTERFACE SuspendInterface; PXENBUS_SUSPEND_CALLBACK SuspendCallbackLate; + XENBUS_UNPLUG_INTERFACE UnplugInterface; + PXENVIF_FRONTEND Frontend; PXENVIF_VIF_CONTEXT VifContext; @@ -947,6 +949,11 @@ PdoD3ToD0( KeLowerIrql(Irql); + XENBUS_UNPLUG(Request, + &Pdo->UnplugInterface, + XENBUS_UNPLUG_DEVICE_TYPE_NICS, + TRUE); + return STATUS_SUCCESS; fail3: @@ -977,6 +984,11 @@ PdoD0ToD3( ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL); + XENBUS_UNPLUG(Request, + &Pdo->UnplugInterface, + XENBUS_UNPLUG_DEVICE_TYPE_NICS, + FALSE); + KeRaiseIrql(DISPATCH_LEVEL, &Irql); XENBUS_SUSPEND(Deregister, @@ -1092,31 +1104,35 @@ PdoStartDevice( if (DriverIsRebootRequested()) goto fail1; + status = XENBUS_UNPLUG(Acquire, &Pdo->UnplugInterface); + if (!NT_SUCCESS(status)) + goto fail2; + status = RegistryOpenSoftwareKey(__PdoGetDeviceObject(Pdo), KEY_ALL_ACCESS, &Key); if (!NT_SUCCESS(status)) - goto fail2; + goto fail3; status = __PdoSetCurrentAddress(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; // // Look for a network interface with the same permanent address @@ -1142,7 +1158,7 @@ PdoStartDevice( continue; status = STATUS_UNSUCCESSFUL; - goto fail7; + goto fail8; } // @@ -1170,7 +1186,7 @@ PdoStartDevice( status = PdoD3ToD0(Pdo); if (!NT_SUCCESS(status)) - goto fail8; + goto fail9; __PdoSetDevicePnpState(Pdo, Started); @@ -1183,15 +1199,15 @@ PdoStartDevice( return STATUS_SUCCESS; -fail8: - Error("fail8\n"); +fail9: + Error("fail9\n"); __FreeMibTable(Table); goto fail6; -fail7: - Error("fail7\n"); +fail8: + Error("fail8\n"); (VOID) SettingsSave(Key, Row->Alias, @@ -1199,24 +1215,34 @@ fail7: &Row->InterfaceGuid, &Row->InterfaceLuid); + XENBUS_UNPLUG(Request, + &Pdo->UnplugInterface, + XENBUS_UNPLUG_DEVICE_TYPE_NICS, + TRUE); + DriverRequestReboot(); __FreeMibTable(Table); +fail7: + Error("fail7\n"); + fail6: Error("fail6\n"); fail5: Error("fail5\n"); + RtlZeroMemory(&Pdo->CurrentAddress, sizeof (ETHERNET_ADDRESS)); + fail4: Error("fail4\n"); - RtlZeroMemory(&Pdo->CurrentAddress, sizeof (ETHERNET_ADDRESS)); + RegistryCloseKey(Key); fail3: Error("fail3\n"); - RegistryCloseKey(Key); + XENBUS_UNPLUG(Release, &Pdo->UnplugInterface); fail2: Error("fail2\n"); @@ -1277,6 +1303,8 @@ PdoStopDevice( RtlZeroMemory(&Pdo->CurrentAddress, sizeof (ETHERNET_ADDRESS)); + XENBUS_UNPLUG(Release, &Pdo->UnplugInterface); + __PdoSetDevicePnpState(Pdo, Stopped); status = STATUS_SUCCESS; @@ -1361,6 +1389,8 @@ PdoRemoveDevice( done: RtlZeroMemory(&Pdo->CurrentAddress, sizeof (ETHERNET_ADDRESS)); + XENBUS_UNPLUG(Release, &Pdo->UnplugInterface); + NeedInvalidate = FALSE; FdoAcquireMutex(Fdo); @@ -2536,7 +2566,8 @@ PdoCreate( if (!NT_SUCCESS(status)) goto fail9; - FdoGetSuspendInterface(Fdo,&Pdo->SuspendInterface); + FdoGetSuspendInterface(Fdo, &Pdo->SuspendInterface); + FdoGetUnplugInterface(Fdo, &Pdo->UnplugInterface); Dx->Pdo = Pdo; @@ -2569,6 +2600,9 @@ fail10: Dx->Pdo = NULL; + RtlZeroMemory(&Pdo->UnplugInterface, + sizeof (XENBUS_UNPLUG_INTERFACE)); + RtlZeroMemory(&Pdo->SuspendInterface, sizeof (XENBUS_SUSPEND_INTERFACE)); @@ -2658,6 +2692,9 @@ PdoDestroy( Dx->Pdo = NULL; + RtlZeroMemory(&Pdo->UnplugInterface, + sizeof (XENBUS_UNPLUG_INTERFACE)); + RtlZeroMemory(&Pdo->SuspendInterface, sizeof (XENBUS_SUSPEND_INTERFACE)); -- 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 |