Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Jan 2, 2025
1 parent 0f53a17 commit bd0ef4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions cpp/devices/scsi_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ vector<uint8_t> ScsiGeneric::InquiryInternal() const

int ScsiGeneric::ReadData(data_in_t buf)
{
return ReadWriteData(buf, GetController()->GetChunkSize(), true);
return ReadWriteData(buf, GetController()->GetChunkSize());
}

int ScsiGeneric::WriteData(cdb_t, data_out_t buf, int, int length)
Expand All @@ -167,10 +167,10 @@ int ScsiGeneric::WriteData(cdb_t, data_out_t buf, int, int length)
}
}

return ReadWriteData(span((uint8_t*)buf.data(), buf.size()), length, true); // NOSONAR Cast required for SG driver API
return ReadWriteData(span((uint8_t*)buf.data(), buf.size()), length); // NOSONAR Cast required for SG driver API
}

int ScsiGeneric::ReadWriteData(span<uint8_t> buf, int chunk_size, bool enable_log)
int ScsiGeneric::ReadWriteData(span<uint8_t> buf, int chunk_size)
{
int length = remaining_count < chunk_size ? remaining_count : chunk_size;
length = length < MAX_TRANSFER_LENGTH ? length : MAX_TRANSFER_LENGTH;
Expand Down Expand Up @@ -204,11 +204,11 @@ int ScsiGeneric::ReadWriteData(span<uint8_t> buf, int chunk_size, bool enable_lo
TIMEOUT_FORMAT_SECONDS : TIMEOUT_DEFAULT_SECONDS) * 1000;

// Check the log level in order to avoid an unnecessary time-consuming string construction
if (enable_log && GetLogger().level() <= level::debug) {
if (GetController() && GetLogger().level() <= level::debug) {
LogDebug(command_meta_data.LogCdb(local_cdb, "SG driver"));
}

if (enable_log && write && GetLogger().level() == level::trace) {
if (write && GetController() && GetLogger().level() == level::trace) {
LogTrace(fmt::format("Transferring {0} byte(s) to SG driver{1}", length,
length ? fmt::format(":\n{}", GetController()->FormatBytes(buf, length)) : ""));
}
Expand All @@ -221,7 +221,7 @@ int ScsiGeneric::ReadWriteData(span<uint8_t> buf, int chunk_size, bool enable_lo

const int transferred_length = length - io_hdr.resid;

if (enable_log && !write && GetLogger().level() == level::trace) {
if (!write && GetController() && GetLogger().level() == level::trace) {
LogTrace(fmt::format("Transferred {0} byte(s) from SG driver{1}", transferred_length,
transferred_length ? fmt::format(":\n{}", GetController()->FormatBytes(buf, transferred_length)) : ""));
}
Expand All @@ -238,7 +238,7 @@ int ScsiGeneric::ReadWriteData(span<uint8_t> buf, int chunk_size, bool enable_lo
remaining_count = 0;
}

if (enable_log) {
if (GetController()) {
LogTrace(fmt::format("{0} byte(s) transferred, {1} byte(s) remaining", transferred_length, remaining_count));
}

Expand Down Expand Up @@ -309,7 +309,7 @@ string ScsiGeneric::GetDeviceData()
local_cdb[4] = static_cast<uint8_t>(byte_count);

try {
ReadWriteData(buf, byte_count, false);
ReadWriteData(buf, byte_count);
}
catch (const ScsiException &e) {
return e.what();
Expand Down Expand Up @@ -337,7 +337,7 @@ void ScsiGeneric::GetBlockSize()

try {
// Trigger a block size update
ReadWriteData(buf, byte_count, false);
ReadWriteData(buf, byte_count);
}
catch (const ScsiException&) { // NOSONAR The exception details do not matter, this might not be a block device
// Fall through
Expand Down
2 changes: 1 addition & 1 deletion cpp/devices/scsi_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ScsiGeneric : public PrimaryDevice

private:

int ReadWriteData(span<uint8_t>, int, bool);
int ReadWriteData(span<uint8_t>, int);

void EvaluateStatus(int, span<uint8_t>, span<uint8_t>, bool);

Expand Down

0 comments on commit bd0ef4a

Please sign in to comment.