diff --git a/cpp/initiator/initiator_util.cpp b/cpp/initiator/initiator_util.cpp index d98eb255..cd4a2de5 100644 --- a/cpp/initiator/initiator_util.cpp +++ b/cpp/initiator/initiator_util.cpp @@ -20,7 +20,7 @@ string initiator_util::GetSenseData(InitiatorExecutor &executor, bool sasi) array < uint8_t, 6 > cdb = { }; cdb[4] = static_cast(buf.size()); - if (!executor.Execute(scsi_command::cmd_request_sense, cdb, buf, static_cast(buf.size()), sasi)) { + if (executor.Execute(scsi_command::cmd_request_sense, cdb, buf, static_cast(buf.size()), sasi)) { return "Can't execute REQUEST SENSE"; } @@ -32,6 +32,17 @@ string initiator_util::GetSenseData(InitiatorExecutor &executor, bool sasi) buf[13]); } +void initiator_util::LogStatus(int status) +{ + if (const auto &it_status = STATUS_MAPPING.find(static_cast(status)); it_status + != STATUS_MAPPING.end()) { + warn("Device reported status {0} (status code ${1:02x})", it_status->second, status); + } + else { + warn("Device reported status code ${0:02x}", status); + } +} + bool initiator_util::SetLogLevel(const string &log_level) { const level::level_enum l = level::from_str(log_level); diff --git a/cpp/initiator/initiator_util.h b/cpp/initiator/initiator_util.h index d86e3c45..aa17aa92 100644 --- a/cpp/initiator/initiator_util.h +++ b/cpp/initiator/initiator_util.h @@ -15,5 +15,6 @@ using namespace std; namespace initiator_util { string GetSenseData(InitiatorExecutor&, bool); +void LogStatus(int); bool SetLogLevel(const string&); } diff --git a/cpp/s2pexec/s2pexec_executor.cpp b/cpp/s2pexec/s2pexec_executor.cpp index 94ae58a3..ede1839e 100644 --- a/cpp/s2pexec/s2pexec_executor.cpp +++ b/cpp/s2pexec/s2pexec_executor.cpp @@ -6,23 +6,17 @@ // //--------------------------------------------------------------------------- -#include +#include "initiator/initiator_util.h" #include "s2pexec_executor.h" using namespace std; -using namespace spdlog; +using namespace initiator_util; int S2pExecExecutor::ExecuteCommand(scsi_command cmd, vector &cdb, vector &buffer, bool sasi) { const int status = initiator_executor->Execute(cmd, cdb, buffer, buffer.size(), sasi); - if (const auto &it_status = STATUS_MAPPING.find(static_cast(status)); it_status - != STATUS_MAPPING.end()) { - warn("Device reported status {0} (status code ${1:02x})", it_status->second, status); - } - else { - warn("Device reported status code ${0:02x}", status); - } + LogStatus(status); return status; }