Skip to content

Commit

Permalink
Extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Feb 7, 2024
1 parent 4fcdaf4 commit a8953c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions cpp/command/command_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<PrimaryDevice> device)
{
const string &identifier = fmt::format("device.{0}:{1}.", device->GetId(), device->GetLun());
Expand Down
2 changes: 1 addition & 1 deletion cpp/command/command_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrimaryDevice>);

Bus &bus;
Expand Down

0 comments on commit a8953c5

Please sign in to comment.