[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 6/6] Add Unplug v2 interface (REV_0900000A)
I'll send a v2 with UnplugWasRequested()
Owen
[CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments unless you have verified the sender and know the content is safe.
On 31/08/2023 08:29, Owen Smith wrote:
> Unplug v2 adds a query call to determine if a device type has had its unplug issued.
> This is useful during upgrade cases when the Unplug keys have been set to 0, and can
> be used to prevent XenVif from starting whilst emulated devices are present, but those
> emulated devices have not been assigned a valid configuration yet (emulated devices
> will receive valid configuration, but not at this point in the startup sequence during
> upgrade)
>
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxx>
> ---
> include/revision.h | 3 +-
> include/unplug_interface.h | 30 +++++++++++++++++--
> include/xen.h | 7 +++++
> src/xen/unplug.c | 15 ++++++++++
> src/xenbus/unplug.c | 61 ++++++++++++++++++++++++++++++++++++++
> 5 files changed, 113 insertions(+), 3 deletions(-)
>
> diff --git a/include/revision.h b/include/revision.h
> index 4d91927..9577fdb 100644
> --- a/include/revision.h
> +++ b/include/revision.h
> @@ -57,6 +57,7 @@
> DEFINE_REVISION(0x09000006, 1, 3, 8, 1, 2, 1, 2, 4, 1, 1, 1), \
> DEFINE_REVISION(0x09000007, 1, 3, 8, 1, 2, 1, 2, 4, 1, 1, 2), \
> DEFINE_REVISION(0x09000008, 1, 3, 9, 1, 2, 1, 2, 4, 1, 1, 2), \
> - DEFINE_REVISION(0x09000009, 1, 4, 9, 1, 2, 1, 2, 4, 1, 1, 2)
> + DEFINE_REVISION(0x09000009, 1, 4, 9, 1, 2, 1, 2, 4, 1, 1, 2), \
> + DEFINE_REVISION(0x0900000A, 1, 4, 9, 1, 2, 1, 2, 4, 2, 1, 2)
>
> #endif // _REVISION_H
> diff --git a/include/unplug_interface.h b/include/unplug_interface.h
> index e465e2e..82afb63 100644
> --- a/include/unplug_interface.h
> +++ b/include/unplug_interface.h
> @@ -85,6 +85,20 @@ typedef VOID
> IN BOOLEAN Make
> );
>
> +/*! \typedef XENBUS_UNPLUG_GETSTATE
> + \brief Has a type of emulated device been unplugged
> +
> + \param Interface The interface header
> + \param Type The type of device
> +
> + \return TRUE The type of device has been unplugged this boot
> +*/
> +typedef BOOLEAN
> +(*XENBUS_UNPLUG_GETSTATE)(
> + IN PINTERFACE Interface,
> + IN XENBUS_UNPLUG_DEVICE_TYPE Type
> + );
> +
> // {73db6517-3d06-4937-989f-199b7501e229}
> DEFINE_GUID(GUID_XENBUS_UNPLUG_INTERFACE,
> 0x73db6517, 0x3d06, 0x4937, 0x98, 0x9f, 0x19, 0x9b, 0x75, 0x01, 0xe2, 0x29);
> @@ -100,7 +114,19 @@ struct _XENBUS_UNPLUG_INTERFACE_V1 {
> XENBUS_UNPLUG_REQUEST UnplugRequest;
> };
>
> -typedef struct _XENBUS_UNPLUG_INTERFACE_V1 XENBUS_UNPLUG_INTERFACE, *PXENBUS_UNPLUG_INTERFACE;
> +/*! \struct _XENBUS_UNPLUG_INTERFACE_V2
> + \brief UNPLUG interface version 2
> + \ingroup interfaces
> +*/
> +struct _XENBUS_UNPLUG_INTERFACE_V2 {
> + INTERFACE Interface;
> + XENBUS_UNPLUG_ACQUIRE UnplugAcquire;
> + XENBUS_UNPLUG_RELEASE UnplugRelease;
> + XENBUS_UNPLUG_REQUEST UnplugRequest;
> + XENBUS_UNPLUG_GETSTATE UnplugGetState;
> +};
> +
> +typedef struct _XENBUS_UNPLUG_INTERFACE_V2 XENBUS_UNPLUG_INTERFACE, *PXENBUS_UNPLUG_INTERFACE;
>
> /*! \def XENBUS_UNPLUG
> \brief Macro at assist in method invocation
> @@ -111,6 +137,6 @@ typedef struct _XENBUS_UNPLUG_INTERFACE_V1 XENBUS_UNPLUG_INTERFACE, *PXENBUS_UNP
> #endif // _WINDLL
>
> #define XENBUS_UNPLUG_INTERFACE_VERSION_MIN 1
> -#define XENBUS_UNPLUG_INTERFACE_VERSION_MAX 1
> +#define XENBUS_UNPLUG_INTERFACE_VERSION_MAX 2
>
> #endif // _XENBUS_UNPLUG_INTERFACE_H
> diff --git a/include/xen.h b/include/xen.h
> index 132de21..ead5ca0 100644
> --- a/include/xen.h
> +++ b/include/xen.h
> @@ -377,6 +377,13 @@ UnplugDecrementValue(
> IN UNPLUG_TYPE Type
> );
>
> +XEN_API
> +VOID
> +UnplugWasRequested(
> + IN UNPLUG_TYPE Type,
> + OUT PBOOLEAN Requested
> + );
> +
> // LOG
>
> typedef enum _LOG_LEVEL {
> diff --git a/src/xen/unplug.c b/src/xen/unplug.c
> index ab94da5..fa3a4ae 100644
> --- a/src/xen/unplug.c
> +++ b/src/xen/unplug.c
> @@ -344,6 +344,21 @@ fail1:
> return status;
> }
>
> +XEN_API
> +VOID
> +UnplugWasRequested(
> + IN UNPLUG_TYPE Type,
> + OUT PBOOLEAN Requested
> + )
> +{
> + PUNPLUG_CONTEXT Context = &UnplugContext;
> + KIRQL Irql;
> +
> + AcquireHighLock(&Context->Lock, &Irql);
> + *Requested = Context->Request[Type];
> + ReleaseHighLock(&Context->Lock, Irql);
> +}
> +
> XEN_API
> VOID
> UnplugDevices(
> diff --git a/src/xenbus/unplug.c b/src/xenbus/unplug.c
> index f2f13fa..86871d7 100644
> --- a/src/xenbus/unplug.c
> +++ b/src/xenbus/unplug.c
> @@ -110,6 +110,41 @@ UnplugRequest(
> ReleaseMutex(&Context->Mutex);
> }
>
> +__drv_requiresIRQL(PASSIVE_LEVEL)
> +static BOOLEAN
> +UnplugGetState(
Can we just use the UnplugWasRequested() name for actual interface
function? It's more descriptive.
Paul
> + IN PINTERFACE Interface,
> + IN XENBUS_UNPLUG_DEVICE_TYPE Type
> + )
> +{
> + PXENBUS_UNPLUG_CONTEXT Context = Interface->Context;
> + BOOLEAN Requested;
> +
> + ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
> +
> + AcquireMutex(&Context->Mutex);
> +
> + Requested = FALSE;
> + switch (Type) {
> + case XENBUS_UNPLUG_DEVICE_TYPE_NICS:
> + UnplugWasRequested(UNPLUG_NICS, &Requested);
> + break;
> +
> + case XENBUS_UNPLUG_DEVICE_TYPE_DISKS:
> + UnplugWasRequested(UNPLUG_DISKS, &Requested);
> + break;
> +
> + default:
> + ASSERT(FALSE);
> + break;
> + }
> +
> + ReleaseMutex(&Context->Mutex);
> +
> + return Requested;
> +}
> +
> +
> static NTSTATUS
> UnplugAcquire(
> IN PINTERFACE Interface
> @@ -157,6 +192,15 @@ static struct _XENBUS_UNPLUG_INTERFACE_V1 UnplugInterfaceVersion1 = {
> UnplugRequest
> };
>
> +static struct _XENBUS_UNPLUG_INTERFACE_V2 UnplugInterfaceVersion2 = {
> + { sizeof (struct _XENBUS_UNPLUG_INTERFACE_V2), 2, NULL, NULL, NULL },
> + UnplugAcquire,
> + UnplugRelease,
> + UnplugRequest,
> + UnplugGetState
> +};
> +
> +
> NTSTATUS
> UnplugInitialize(
> IN PXENBUS_FDO Fdo,
> @@ -218,6 +262,23 @@ UnplugGetInterface(
> status = STATUS_SUCCESS;
> break;
> }
> + case 2: {
> + struct _XENBUS_UNPLUG_INTERFACE_V2 *UnplugInterface;
> +
> + UnplugInterface = (struct _XENBUS_UNPLUG_INTERFACE_V2 *)Interface;
> +
> + status = STATUS_BUFFER_OVERFLOW;
> + if (Size < sizeof (struct _XENBUS_UNPLUG_INTERFACE_V2))
> + break;
> +
> + *UnplugInterface = UnplugInterfaceVersion2;
> +
> + ASSERT3U(Interface->Version, ==, Version);
> + Interface->Context = Context;
> +
> + status = STATUS_SUCCESS;
> + break;
> + }
> default:
> status = STATUS_NOT_SUPPORTED;
> break;
|