Skip to content

Commit

Permalink
Move code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 26, 2024
1 parent 021e886 commit fd6abd1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
13 changes: 12 additions & 1 deletion cpp/initiator/initiator_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ string initiator_util::GetSenseData(InitiatorExecutor &executor, bool sasi)
array < uint8_t, 6 > cdb = { };
cdb[4] = static_cast<uint8_t>(buf.size());

if (!executor.Execute(scsi_command::cmd_request_sense, cdb, buf, static_cast<int>(buf.size()), sasi)) {
if (executor.Execute(scsi_command::cmd_request_sense, cdb, buf, static_cast<int>(buf.size()), sasi)) {
return "Can't execute REQUEST SENSE";
}

Expand All @@ -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<scsi_defs::status>(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);
Expand Down
1 change: 1 addition & 0 deletions cpp/initiator/initiator_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ using namespace std;
namespace initiator_util
{
string GetSenseData(InitiatorExecutor&, bool);
void LogStatus(int);
bool SetLogLevel(const string&);
}
12 changes: 3 additions & 9 deletions cpp/s2pexec/s2pexec_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,17 @@
//
//---------------------------------------------------------------------------

#include <spdlog/spdlog.h>
#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<uint8_t> &cdb, vector<uint8_t> &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<scsi_defs::status>(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;
}

0 comments on commit fd6abd1

Please sign in to comment.