]> xenbits.xensource.com Git - pvdrivers/win/xenbus.git/commitdiff
Update XENFILT_EMULATED IsDiskPresent() method...
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 2 Oct 2019 11:14:45 +0000 (12:14 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Wed, 2 Oct 2019 11:14:45 +0000 (12:14 +0100)
...to match how XENVBD actually uses it.

XENVBD erroneously passes the disk number of the PV disk as the target
number, which is incorrect for disk numbers more than 1. E.g. disk 3 should
equate to controller 1, target 1.
This patch adapts the method to that use by dropping the extraneous
Controller and Lun parameters and properly interpreting the Target
parameter.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
include/emulated_interface.h
include/revision.h
src/xenfilt/emulated.c

index 9361f8d470ff8854610cdfc6d5fd7c5ae74a5ee4..fe93d72544790f3a58aa4ba4b3ad371793071595 100644 (file)
@@ -78,22 +78,26 @@ typedef BOOLEAN
     IN  PCHAR   InstanceID OPTIONAL
     );
 
+typedef BOOLEAN
+(*XENFILT_EMULATED_IS_DISK_PRESENT_V1)(
+    IN  PVOID   Context,
+    IN  ULONG   Controller,
+    IN  ULONG   Target,
+    IN  ULONG   Lun
+    );
 /*! \typedef XENFILT_EMULATED_IS_DISK_PRESENT
-    \brief Determine whether a given disk is present in the VM
+    \brief Determine whether a given emulated 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
+    \param Index The disk number of the paravirtual disk which the
+                 emulated device is aliasing
+    \return TRUE if an emulated disk aliasing the specified paravirtual
+    disk index is present in the system or FALSE if not
 */  
 typedef BOOLEAN
 (*XENFILT_EMULATED_IS_DISK_PRESENT)(
     IN  PVOID   Context,
-    IN  ULONG   Controller,
-    IN  ULONG   Target,
-    IN  ULONG   Lun
+    IN  ULONG   Index
     );
 
 // {959027A1-FCCE-4E78-BCF4-637384F499C5}
@@ -105,6 +109,18 @@ DEFINE_GUID(GUID_XENFILT_EMULATED_INTERFACE,
     \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_V1 EmulatedIsDiskPresentVersion1;
+};
+
+/*! \struct _XENFILT_EMULATED_INTERFACE_V2
+    \brief EMULATED interface version 2
+    \ingroup interfaces
+*/
+struct _XENFILT_EMULATED_INTERFACE_V2 {
     INTERFACE                           Interface;
     XENFILT_EMULATED_ACQUIRE            EmulatedAcquire;
     XENFILT_EMULATED_RELEASE            EmulatedRelease;
@@ -112,7 +128,7 @@ struct _XENFILT_EMULATED_INTERFACE_V1 {
     XENFILT_EMULATED_IS_DISK_PRESENT    EmulatedIsDiskPresent;
 };
 
-typedef struct _XENFILT_EMULATED_INTERFACE_V1 XENFILT_EMULATED_INTERFACE, *PXENFILT_EMULATED_INTERFACE;
+typedef struct _XENFILT_EMULATED_INTERFACE_V2 XENFILT_EMULATED_INTERFACE, *PXENFILT_EMULATED_INTERFACE;
 
 /*! \def XENFILT_EMULATED
     \brief Macro at assist in method invocation
@@ -123,7 +139,7 @@ typedef struct _XENFILT_EMULATED_INTERFACE_V1 XENFILT_EMULATED_INTERFACE, *PXENF
 #endif  // _WINDLL
 
 #define XENFILT_EMULATED_INTERFACE_VERSION_MIN  1
-#define XENFILT_EMULATED_INTERFACE_VERSION_MAX  1
+#define XENFILT_EMULATED_INTERFACE_VERSION_MAX  2
 
 #endif  // _XENFILT_EMULATED_INTERFACE_H
 
index b214152a114974ab4a70b64f25eb8e1b337acc1e..01b6737223742ed1bc484e0ce67635bf045cea3d 100644 (file)
@@ -56,6 +56,7 @@
     DEFINE_REVISION(0x09000003,  1,  2,  8,  1,  2,  1,  1,  2,  1,  1,  1), \
     DEFINE_REVISION(0x09000004,  1,  2,  8,  1,  2,  1,  1,  3,  1,  1,  1), \
     DEFINE_REVISION(0x09000005,  1,  2,  8,  1,  2,  1,  2,  4,  1,  1,  1), \
-    DEFINE_REVISION(0x09000006,  1,  3,  8,  1,  2,  1,  2,  4,  1,  1,  1)
+    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)
 
 #endif  // _REVISION_H
index 7491afd034d7576daa577dfb3b655545468ac1a0..827c9058fe5d6dc6eaf1c2bb6c52634146f41b3a 100644 (file)
@@ -49,9 +49,7 @@ typedef struct _XENFILT_EMULATED_DEVICE_DATA {
 } XENFILT_EMULATED_DEVICE_DATA, *PXENFILT_EMULATED_DEVICE_DATA;
 
 typedef struct _XENFILT_EMULATED_DISK_DATA {
-    ULONG   Controller;
-    ULONG   Target;
-    ULONG   Lun;
+    ULONG   Index;
 } XENFILT_EMULATED_DISK_DATA, *PXENFILT_EMULATED_DISK_DATA;
 
 typedef union _XENFILT_EMULATED_OBJECT_DATA {
@@ -146,7 +144,7 @@ EmulatedSetObjectDiskData(
     Controller = strtol(InstanceID, &End, 10);
 
     status = STATUS_INVALID_PARAMETER;
-    if (*End != '.')
+    if (*End != '.' || Controller > 1)
         goto fail2;
 
     End++;
@@ -154,7 +152,7 @@ EmulatedSetObjectDiskData(
     Target = strtol(End, &End, 10);
 
     status = STATUS_INVALID_PARAMETER;
-    if (*End != '.')
+    if (*End != '.' || Target > 1)
         goto fail3;
 
     End++;
@@ -165,12 +163,17 @@ EmulatedSetObjectDiskData(
     if (*End != '\0')
         goto fail4;
 
-    EmulatedObject->Data.Disk.Controller = Controller;
-    EmulatedObject->Data.Disk.Target = Target;
-    EmulatedObject->Data.Disk.Lun = Lun;
+    status = STATUS_NOT_SUPPORTED;
+    if (Lun != 0)
+        goto fail5;
+
+    EmulatedObject->Data.Disk.Index = Controller << 1 | Target;
 
     return STATUS_SUCCESS;
 
+fail5:
+    Error("fail5\n");
+
 fail4:
     Error("fail4\n");
 
@@ -311,16 +314,14 @@ EmulatedIsDevicePresent(
 static BOOLEAN
 EmulatedIsDiskPresent(
     IN  PINTERFACE              Interface,
-    IN  ULONG                   Controller,
-    IN  ULONG                   Target,
-    IN  ULONG                   Lun
+    IN  ULONG                   Index
     )
 {
     PXENFILT_EMULATED_CONTEXT   Context = Interface->Context;
     KIRQL                       Irql;
     PLIST_ENTRY                 ListEntry;
 
-    Trace("====> (%02X:%02X:%02X)\n", Controller, Target, Lun);
+    Trace("====> (%02X)\n", Index);
 
     KeAcquireSpinLock(&Context->Lock, &Irql);
 
@@ -333,9 +334,7 @@ EmulatedIsDiskPresent(
                                            ListEntry);
 
         if (EmulatedObject->Type == XENFILT_EMULATED_OBJECT_TYPE_IDE &&
-            Controller == EmulatedObject->Data.Disk.Controller &&
-            Target == EmulatedObject->Data.Disk.Target &&
-            Lun == EmulatedObject->Data.Disk.Lun) {
+            Index == EmulatedObject->Data.Disk.Index) {
             Trace("FOUND\n");
             break;
         }
@@ -350,6 +349,26 @@ EmulatedIsDiskPresent(
     return (ListEntry != &Context->List) ? TRUE : FALSE;
 }
 
+static BOOLEAN
+EmulatedIsDiskPresentVersion1(
+    IN  PINTERFACE              Interface,
+    IN  ULONG                   Controller,
+    IN  ULONG                   Target,
+    IN  ULONG                   Lun
+    )
+{
+    UNREFERENCED_PARAMETER(Controller);
+    UNREFERENCED_PARAMETER(Lun);
+
+    //
+    // XENVBD erroneously passes the disk number of the PV disk as
+    // the IDE target number (i.e. in can pass a value > 1), with
+    // Controller always set to 0. So, simply treat the Target argument
+    // as the PV disk number and call the new method.
+    //
+    return EmulatedIsDiskPresent(Interface, Target);
+}
+
 NTSTATUS
 EmulatedAcquire(
     IN  PINTERFACE              Interface
@@ -395,9 +414,17 @@ static struct _XENFILT_EMULATED_INTERFACE_V1 EmulatedInterfaceVersion1 = {
     EmulatedAcquire,
     EmulatedRelease,
     EmulatedIsDevicePresent,
-    EmulatedIsDiskPresent
+    EmulatedIsDiskPresentVersion1
 };
                      
+static struct _XENFILT_EMULATED_INTERFACE_V2 EmulatedInterfaceVersion2 = {
+    { sizeof (struct _XENFILT_EMULATED_INTERFACE_V2), 2, NULL, NULL, NULL },
+    EmulatedAcquire,
+    EmulatedRelease,
+    EmulatedIsDevicePresent,
+    EmulatedIsDiskPresent
+};
+
 NTSTATUS
 EmulatedInitialize(
     OUT PXENFILT_EMULATED_CONTEXT   *Context
@@ -456,6 +483,23 @@ EmulatedGetInterface(
         status = STATUS_SUCCESS;
         break;
     }
+    case 2: {
+        struct _XENFILT_EMULATED_INTERFACE_V2   *EmulatedInterface;
+
+        EmulatedInterface = (struct _XENFILT_EMULATED_INTERFACE_V2 *)Interface;
+
+        status = STATUS_BUFFER_OVERFLOW;
+        if (Size < sizeof (struct _XENFILT_EMULATED_INTERFACE_V2))
+            break;
+
+        *EmulatedInterface = EmulatedInterfaceVersion2;
+
+        ASSERT3U(Interface->Version, ==, Version);
+        Interface->Context = Context;
+
+        status = STATUS_SUCCESS;
+        break;
+    }
     default:
         status = STATUS_NOT_SUPPORTED;
         break;