]> xenbits.xensource.com Git - pvdrivers/win/xenvbd.git/commitdiff
Interpret "removable" and "info" flags correctly
authorOwen Smith <owen.smith@citrix.com>
Tue, 30 Nov 2021 16:06:22 +0000 (16:06 +0000)
committerPaul Durrant <pdurrant@amazon.com>
Mon, 6 Dec 2021 15:06:10 +0000 (15:06 +0000)
"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@citrix.com>
src/xenvbd/adapter.c
src/xenvbd/target.c
src/xenvbd/target.h

index 5b17a6b317249a55f802de3823453227e5273680..8a13af95d05e8b6042b8121df5f04a1473ddef8b 100644 (file)
@@ -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,
index 7935fa0a14a4c80c13835f9b71e037eb197d88e1..e71200f5e78a0956f7f8542c8d0dd8f72abf2499 100644 (file)
@@ -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)
 
index 6feecc11943d8ded94b707604cf8b0d37bd0199e..c6c027a7c708b3da9f613ae7c65043d6a8bd0c67 100644 (file)
@@ -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)