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

[PATCH] Interpret "removable" and "info" flags correctly


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Owen Smith <owen.smith@xxxxxxxxxx>
  • Date: Tue, 30 Nov 2021 16:06:22 +0000
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Owen Smith <owen.smith@xxxxxxxxxx>
  • Delivery-date: Tue, 30 Nov 2021 16:06:38 +0000
  • Ironport-data: A9a23:56myOa+6ExTuWCGvjvqcDrUDrXmTJUtcMsCJ2f8bNWPcYEJGY0x3m mBLWGmFP62LNzb8KN5/aY7k9k0Bv5CEyt9qQFZpq388E34SpcT7XtnIdU2Y0wF+jyHgoOCLy +1EN7Es+ehtFie0Si9AttENlFEkvU2ybuOU5NXsZ2YhGmeIdA970Ug6wrdi2tYy6TSEK1jlV e3a8pW31GCNg1aYAkpMg05UgEoy1BhakGpwUm0WPZinjneH/5UmJMt3yZWKB2n5WuFp8tuSH I4v+l0bElTxpH/BAvv9+lryn9ZjrrT6ZWBigVIOM0Sub4QrSoXfHc/XOdJFAXq7hQllkPhX5 d9t7a6aTD4RP6yRmLwFA0FcTD5xaPguFL/veRBTsOSWxkzCNXDt3+9vHAc9OohwFuRfWD8Us 6ZCcXZUM07F17neLLGTE4GAguwkM8Ttepgau21g5TrYEewnUdbIRKCiCdpwgm9h25gVQaa2i 8wxe2p3dAiDcj52NQlLIr4SleizuGXyWmgNwL6SjfVuuDWCpOBr65DyMdyQYsLPSchLk0Kwo mPd43+/EhwcLMaYyzeO7jSrnOCnoM/gcNtMTvvirKcs2QDNgDxIYPELabelid+UgG7mafhaE nQV+3cu9bBirEj0UdaoCnVUv0W4lhIbXtNRFcgz5weM1rfY7m6lO4QUctJSQId47ZFrHFTGw nfMxoq0XmI37NV5XFrEru/MxQ5eLxT5OoPricUsaQIeq+fur4go5v4kZoYySfXl5jEZ9NyZ/ txrkMTcr+lD5SL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4H9KTZpzW6kfBSq8kY5xyLHaOLZppcA5BdGCf9HnDNrCrM4nFpiBGN22XcDl36bfn+4iIr81BF 8Wcu2B7mV3qh0X1qMNcRe0SzOZKUHR4w6CPHWgyO53o76Z65i3wFByQczkwNlGOOs2chf5vQoI U9mrAOPhrF6urvxt7MbfR5wB
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

"removable" relates to the ability to remove the device (not media)

  "removable" = "1" is used to indicate the device can be hot unplugged, as
  PV devices should support hot plug/unplug in the majority of cases.
  "removable" = "0" is used to indicate that the device is being prevented
  from hot unplug by the tool stack. This will allow XenVbd to report the
  correct device capabilities to the OS to indicate that this disk is not
  capable of being removed. This will allow certain policies to be applied
  which restrict access to removable disks (for security and to prevent data
  exfiltration)

"info" contains various flags for the media (not device)

  VDISK_CDROM implies RemovableMedia (a specific case of VDISK_REMOVABLE)
  VDISK_REMOVABLE imples RemovableMedia (underlying disk has GENHD_FL_REMOVABLE)
  VDISK_READONLY implies a READ_ONLY_DIRECT_ACCESS_DEVICE

  'Standard' disks usually set no flags (i.e. media is RW and not removable)
  A CDROM will set VDISK_CDROM | VDISK_READONLY, to indicate the media is RO
  and removable.

STOR_FEATURE_FULL_PNP_DEVICE_CAPABILITIES must be set, otherwise StorPort will
not use the values provided for EjectSupported and SurpriseRemovalOK in the
STOR_DEVICE_CAPABILITIES_EX structure. Without this, CM_DEVCAP_EJECTSUPPORTED
and CM_DEVCAP_SURPRISEREMOVALOK are left unchanged, and prevents a non-removable
device from identifying correctly as non-removable.

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/xenvbd/adapter.c |  7 ++++---
 src/xenvbd/target.c  | 16 +++++++++++++---
 src/xenvbd/target.h  |  1 +
 3 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/xenvbd/adapter.c b/src/xenvbd/adapter.c
index 5b17a6b..8a13af9 100644
--- a/src/xenvbd/adapter.c
+++ b/src/xenvbd/adapter.c
@@ -1927,10 +1927,10 @@ __AdapterSrbPnp(
 
     switch (Srb->PnPAction) {
     case StorQueryCapabilities: {
-        PSTOR_DEVICE_CAPABILITIES Caps = Srb->DataBuffer;
+        PSTOR_DEVICE_CAPABILITIES_EX Caps = Srb->DataBuffer;
 
-        Caps->Removable = 1;
-        Caps->EjectSupported = 1;
+        Caps->Removable = TargetGetRemovable(Target);
+        Caps->EjectSupported = TargetGetRemovable(Target);
         Caps->SurpriseRemovalOK = 1;
         Caps->UniqueID = 1;
 
@@ -2280,6 +2280,7 @@ AdapterDriverEntry(
     InitData.MultipleRequestPerLu       = TRUE;
     InitData.HwAdapterControl           = AdapterHwAdapterControl;
     InitData.HwBuildIo                  = AdapterHwBuildIo;
+    InitData.FeatureSupport             = 
STOR_FEATURE_FULL_PNP_DEVICE_CAPABILITIES;
 
     status = StorPortInitialize(DriverObject,
                                 RegistryPath,
diff --git a/src/xenvbd/target.c b/src/xenvbd/target.c
index 7935fa0..e71200f 100644
--- a/src/xenvbd/target.c
+++ b/src/xenvbd/target.c
@@ -641,7 +641,6 @@ TargetInquiryStd(
     IN  PSCSI_REQUEST_BLOCK Srb
     )
 {
-    PXENVBD_FEATURES        Features =  FrontendGetFeatures(Target->Frontend);
     PXENVBD_DISKINFO        DiskInfo = FrontendGetDiskInfo(Target->Frontend);
     PINQUIRYDATA            Data = Srb->DataBuffer;
     ULONG                   Length = Srb->DataTransferLength;
@@ -656,9 +655,11 @@ TargetInquiryStd(
         return;
 
     RtlZeroMemory(Data, Length);
-    Data->DeviceType            = DIRECT_ACCESS_DEVICE;
+    Data->DeviceType            = (DiskInfo->DiskInfo & VDISK_READONLY) ?
+                                  READ_ONLY_DIRECT_ACCESS_DEVICE :
+                                  DIRECT_ACCESS_DEVICE;
     Data->DeviceTypeQualifier   = DEVICE_CONNECTED;
-    Data->RemovableMedia        = Features->Removable ||
+    Data->RemovableMedia        = (DiskInfo->DiskInfo & VDISK_CDROM) ||
                                   (DiskInfo->DiskInfo & VDISK_REMOVABLE);
     Data->Versions              = 4;
     Data->ResponseDataFormat    = 2;
@@ -1475,6 +1476,15 @@ TargetGetDeviceId(
     return FrontendGetDeviceId(Target->Frontend);
 }
 
+//TARGET_GET_PROPERTY(Removable, BOOLEAN)
+BOOLEAN
+TargetGetRemovable(
+    IN  PXENVBD_TARGET  Target
+    )
+{
+    return FrontendGetFeatures(Target->Frontend)->Removable;
+}
+
 TARGET_GET_PROPERTY(DevicePnpState, DEVICE_PNP_STATE)
 //TARGET_GET_PROPERTY(Missing, BOOLEAN)
 
diff --git a/src/xenvbd/target.h b/src/xenvbd/target.h
index 6feecc1..c6c027a 100644
--- a/src/xenvbd/target.h
+++ b/src/xenvbd/target.h
@@ -132,6 +132,7 @@ TARGET_GET_PROPERTY(Adapter, PXENVBD_ADAPTER)
 TARGET_GET_PROPERTY(DeviceObject, PDEVICE_OBJECT)
 TARGET_GET_PROPERTY(TargetId, ULONG)
 TARGET_GET_PROPERTY(DeviceId, ULONG)
+TARGET_GET_PROPERTY(Removable, BOOLEAN)
 TARGET_GET_PROPERTY(DevicePnpState, DEVICE_PNP_STATE)
 TARGET_GET_PROPERTY(Missing, BOOLEAN)
 
-- 
2.33.0.windows.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.