Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 25, 2024
1 parent 582f0b5 commit f71ad6a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 33 deletions.
29 changes: 17 additions & 12 deletions cpp/devices/mode_page_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ void mode_page_util::ModeSelect(scsi_command cmd, cdb_t cdb, span<const uint8_t>
// With this page the sector size for a subsequent FORMAT can be selected, but only very few
// drives support this, e.g FUJITSU M2624S
// We are fine as long as the current sector size remains unchanged
if (GetInt16(buf, offset + 12) != sector_size) {
const int requested_size = GetInt16(buf, offset + 12);
if (requested_size != sector_size) {
// It is not possible to permanently (e.g. by formatting) change the sector size.
// The sector size is an externally configurable setting only.
warn(
"Sector size change from {} to {} bytes per sector requested. Configure the requested sector size in the s2p settings.",
sector_size, GetInt16(buf, offset + 12));
sector_size, requested_size);
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}

Expand Down Expand Up @@ -102,11 +103,13 @@ int mode_page_util::EvaluateBlockDescriptors(scsi_command cmd, span<const uint8_
throw scsi_exception(sense_key::illegal_request, asc::parameter_list_length_error);
}

if (block_descriptor_length && length >= 16 && GetInt16(buf, 14) != sector_size) {
warn(
"Sector size change from {} to {} bytes per sector requested. Configure the requested sector size in the s2p settings.",
sector_size, GetInt16(buf, 14));
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
if (block_descriptor_length && length >= 16) {
if (const int requested_size = GetInt16(buf, 14); requested_size != sector_size) {
warn(
"Sector size change from {} to {} bytes per sector requested. Configure the requested sector size in the s2p settings.",
sector_size, requested_size);
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}
}

offset = 8 + block_descriptor_length;
Expand All @@ -121,11 +124,13 @@ int mode_page_util::EvaluateBlockDescriptors(scsi_command cmd, span<const uint8_
throw scsi_exception(sense_key::illegal_request, asc::parameter_list_length_error);
}

if (block_descriptor_length && length >= 12 && GetInt16(buf, 10) != sector_size) {
warn(
"Sector size change from {} to {} bytes per sector requested. Configure the requested sector size in the s2p settings.",
sector_size, GetInt16(buf, 10));
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
if (block_descriptor_length && length >= 12) {
if (const int requested_size = GetInt16(buf, 10); requested_size != sector_size) {
warn(
"Sector size change from {} to {} bytes per sector requested. Configure the requested sector size in the s2p settings.",
sector_size, requested_size);
throw scsi_exception(sense_key::illegal_request, asc::invalid_field_in_parameter_list);
}
}

offset = 4 + block_descriptor_length;
Expand Down
2 changes: 1 addition & 1 deletion cpp/s2p/s2p_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void S2p::LogProperties() const
{
trace("Effective startup properties:");
for (const auto& [k, v] : property_handler.GetProperties()) {
trace(fmt::format(" {0}={1}", k, v));
trace(" {0}={1}", k, v);
}
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/s2pexec/s2pexec_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ string S2pExec::ExecuteCommand()
return error;
}

debug(fmt::format("Sending {} data bytes", buffer.size()));
debug("Sending {} data bytes", buffer.size());
}

const bool status = scsi_executor->ExecuteCommand(static_cast<scsi_command>(cdb[0]), cdb, buffer, sasi);
Expand All @@ -320,7 +320,7 @@ string S2pExec::ExecuteCommand()
if (binary_input_filename.empty() && hex_input_filename.empty()) {
const int count = scsi_executor->GetByteCount();

debug(fmt::format("Received {} data bytes", count));
debug("Received {} data bytes", count);

if (count) {
if (const string &error = WriteData(count); !error.empty()) {
Expand Down
3 changes: 0 additions & 3 deletions cpp/s2pexec/s2pexec_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
//
//---------------------------------------------------------------------------

#include <fstream>
#include <sstream>
#include <filesystem>
#include "shared/s2p_util.h"
#include "s2pexec_executor.h"

Expand Down
2 changes: 0 additions & 2 deletions cpp/s2pexec/s2pexec_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,5 @@ class S2pExecExecutor

private:

array<uint8_t, BUFFER_SIZE> buffer;

unique_ptr<PhaseExecutor> phase_executor;
};
25 changes: 12 additions & 13 deletions cpp/shared_initiator/phase_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ bool PhaseExecutor::Execute(scsi_command cmd, span<uint8_t> cdb, span<uint8_t> b
byte_count = 0;

if (const auto &command = COMMAND_MAPPING.find(cmd); command != COMMAND_MAPPING.end()) {
trace(fmt::format("Executing command {0} for target {1}:{2}", command->second.second, target_id, target_lun));
trace("Executing command {0} for target {1}:{2}", command->second.second, target_id, target_lun);
}
else {
trace(
fmt::format("Executing command ${0:02x} for target {1}:{2}", static_cast<int>(cmd), target_id, target_lun));
trace("Executing command ${0:02x} for target {1}:{2}", static_cast<int>(cmd), target_id, target_lun);
}

// There is no arbitration phase with SASI
Expand Down Expand Up @@ -75,7 +74,7 @@ bool PhaseExecutor::Dispatch(scsi_command cmd, span<uint8_t> cdb, span<uint8_t>
{
const phase_t phase = bus.GetPhase();

trace(fmt::format("Handling {} phase", Bus::GetPhaseName(phase)));
trace("Handling {} phase", Bus::GetPhaseName(phase));

switch (phase) {
case phase_t::command:
Expand Down Expand Up @@ -104,7 +103,7 @@ bool PhaseExecutor::Dispatch(scsi_command cmd, span<uint8_t> cdb, span<uint8_t>
break;

default:
warn(fmt::format("Ignoring {} phase", Bus::GetPhaseName(phase)));
warn("Ignoring {} phase", Bus::GetPhaseName(phase));
return false;
}

Expand All @@ -127,7 +126,7 @@ bool PhaseExecutor::Arbitration() const
Sleep(ARBITRATION_DELAY);

if (bus.GetDAT() > (1 << initiator_id)) {
trace(fmt::format("Lost ARBITRATION, competing initiator ID is {}", bus.GetDAT() - (1 << initiator_id)));
trace("Lost arbitration, winning initiator ID is {}", bus.GetDAT() - (1 << initiator_id));
return false;
}

Expand Down Expand Up @@ -182,10 +181,10 @@ void PhaseExecutor::Command(scsi_command cmd, span<uint8_t> cdb) const
if (static_cast<int>(cdb.size()) != bus.SendHandShake(cdb.data(), static_cast<int>(cdb.size()))) {
const auto &command = COMMAND_MAPPING.find(cmd);
if (command != COMMAND_MAPPING.end()) {
error(fmt::format("Command {} failed", command->second.second));
error("Command {} failed", command->second.second);
}
else {
error(fmt::format("Command ${:02x} failed", static_cast<int>(cmd)));
error("Command ${:02x} failed", static_cast<int>(cmd));
}
}
}
Expand All @@ -206,21 +205,21 @@ void PhaseExecutor::DataIn(span<uint8_t> buffer, int length)
{
byte_count = bus.ReceiveHandShake(buffer.data(), length);
if (byte_count > length) {
warn(fmt::format("Received {0} byte(s) in DATA IN phase, provided size was {0} bytes", byte_count, length));
warn("Received {0} byte(s) in DATA IN phase, provided size was {0} bytes", byte_count, length);
}
else {
trace(fmt::format("Received {0} byte(s) in DATA IN phase, provided size was {0} bytes", byte_count, length));
trace("Received {0} byte(s) in DATA IN phase, provided size was {0} bytes", byte_count, length);
}
}

void PhaseExecutor::DataOut(span<uint8_t> buffer, int length)
{
byte_count = bus.SendHandShake(buffer.data(), length);
if (byte_count > length) {
warn(fmt::format("Sent {0} byte(s) in DATA OUT phase, provided size was {0} bytes", byte_count, length));
warn("Sent {0} byte(s) in DATA OUT phase, provided size was {0} bytes", byte_count, length);
}
else {
trace(fmt::format("Sent {0} byte(s) in DATA OUT phase, provided size was {0} bytes", byte_count, length));
trace("Sent {0} byte(s) in DATA OUT phase, provided size was {0} bytes", byte_count, length);
}
}

Expand All @@ -232,7 +231,7 @@ void PhaseExecutor::MsgIn()
error("MESSAGE IN phase failed");
}
else if (buf[0]) {
warn(fmt::format("MESSAGE IN did not report COMMAND COMPLETE, rejecting unsupported message ${:02x}", buf[0]));
warn("MESSAGE IN did not report COMMAND COMPLETE, rejecting unsupported message ${:02x}", buf[0]);

reject = true;

Expand Down

0 comments on commit f71ad6a

Please sign in to comment.