diff --git a/cpp/command/command_executor.cpp b/cpp/command/command_executor.cpp index 534ac2c9..b8669915 100644 --- a/cpp/command/command_executor.cpp +++ b/cpp/command/command_executor.cpp @@ -220,14 +220,9 @@ bool CommandExecutor::Attach(const CommandContext &context, const PbDeviceDefini return false; } - // PiSCSI compatible caching is currently the default - const PbCachingMode caching_mode = - pb_device.caching_mode() == PbCachingMode::DEFAULT ? PbCachingMode::PISCSI : pb_device.caching_mode(); - - // The effective device type is only available after creating the device - if (caching_mode != PbCachingMode::PISCSI && device->GetType() != PbDeviceType::SCHD - && device->GetType() != PbDeviceType::SCRM && device->GetType() != PbDeviceType::SAHD - && device->GetType() != PbDeviceType::SCMO) { + const PbCachingMode caching_mode = GetEffectiveCachingMode(pb_device, *device); + if (caching_mode == PbCachingMode::DEFAULT) { + // The requested caching mode is not available for this device type return false; } @@ -408,6 +403,21 @@ void CommandExecutor::DetachAll() const } } +PbCachingMode CommandExecutor::GetEffectiveCachingMode(const PbDeviceDefinition &pb_device, const PrimaryDevice &device) +{ + // PiSCSI compatible caching is currently the default + const PbCachingMode caching_mode = + pb_device.caching_mode() == PbCachingMode::DEFAULT ? PbCachingMode::PISCSI : pb_device.caching_mode(); + + if (caching_mode != PbCachingMode::PISCSI && device.GetType() != PbDeviceType::SCHD + && device.GetType() != PbDeviceType::SCRM && device.GetType() != PbDeviceType::SAHD + && device.GetType() != PbDeviceType::SCMO) { + return PbCachingMode::DEFAULT; + } + + return caching_mode; +} + void CommandExecutor::SetUpDeviceProperties(const CommandContext &context, shared_ptr device) { const string &identifier = fmt::format("device.{0}:{1}.", device->GetId(), device->GetLun()); diff --git a/cpp/command/command_executor.h b/cpp/command/command_executor.h index 7e07d851..22917236 100644 --- a/cpp/command/command_executor.h +++ b/cpp/command/command_executor.h @@ -69,7 +69,7 @@ class CommandExecutor private: static bool CheckForReservedFile(const CommandContext&, const string&); - + static PbCachingMode GetEffectiveCachingMode(const PbDeviceDefinition&, const PrimaryDevice&); static void SetUpDeviceProperties(const CommandContext&, shared_ptr); Bus &bus;