Skip to content

Commit

Permalink
Update status code handling in initiator tools
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 6, 2025
1 parent 0bfaaf0 commit 0db591a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
17 changes: 1 addition & 16 deletions cpp/initiator/initiator_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ int InitiatorExecutor::Execute(span<uint8_t> cdb, span<uint8_t> buffer, int leng
}

if (enable_log) {
LogStatus();
initiator_logger.warn(GetStatusString(status_code));
}

return status_code;
Expand Down Expand Up @@ -337,18 +337,3 @@ void InitiatorExecutor::SetTarget(int id, int lun, bool s)
sasi = s;
}

void InitiatorExecutor::LogStatus() const
{
if (status_code) {
if (const auto &it = STATUS_MAPPING.find(static_cast<StatusCode>(status_code)); it != STATUS_MAPPING.end()) {
initiator_logger.warn("Device reported {0} (status code ${1:02x})", it->second, status_code);
}
else if (status_code != 0xff) {
initiator_logger.warn("Device reported an unknown status (status code ${:02x})", status_code);
}
else {
initiator_logger.warn("Device did not respond");
}
}
}

2 changes: 0 additions & 2 deletions cpp/initiator/initiator_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ class InitiatorExecutor
bool WaitForFree() const;
bool WaitForBusy() const;

void LogStatus() const;

void Sleep(const timespec &ns) const
{
nanosleep(&ns, nullptr);
Expand Down
8 changes: 3 additions & 5 deletions cpp/s2pexec/s2pexec_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,11 @@ tuple<SenseKey, Asc, int> S2pExec::ExecuteCommand()
return executor->GetSenseData();
}

if (status == 0x02) {
throw execution_exception("Device reported CHECK CONDITION");
}
throw execution_exception(GetStatusString(status));
}
else {
throw execution_exception(fmt::format("Can't execute command {}",
CommandMetaData::Instance().GetCommandName(static_cast<ScsiCommand>(cdb[0]))));
throw execution_exception(fmt::format("Can't execute command {0} (${1:2x})",
CommandMetaData::Instance().GetCommandName(static_cast<ScsiCommand>(cdb[0])), cdb[0]));
}
}

Expand Down
13 changes: 13 additions & 0 deletions cpp/shared/s2p_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,19 @@ string s2p_util::GetScsiLevel(int scsi_level)
}
}

string s2p_util::GetStatusString(int status_code)
{
if (const auto &it = STATUS_MAPPING.find(static_cast<StatusCode>(status_code)); it != STATUS_MAPPING.end()) {
return fmt::format("Device reported {0} (status code ${1:02x})", it->second, status_code);
}
else if (status_code != 0xff) {
return fmt::format("Device reported an unknown status (status code ${:02x})", status_code);
}
else {
return "Device did not respond";
}
}

string s2p_util::FormatSenseData(span<const byte> sense_data)
{
const auto flags = static_cast<int>(sense_data[2]);
Expand Down
2 changes: 2 additions & 0 deletions cpp/shared/s2p_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ tuple<string, string, string> GetInquiryProductData(span<const uint8_t>);

string GetScsiLevel(int);

string GetStatusString(int);

string FormatSenseData(span<const byte>);
string FormatSenseData(SenseKey, Asc, int = 0);

Expand Down

0 comments on commit 0db591a

Please sign in to comment.