Skip to content

Commit

Permalink
Remove duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Dec 10, 2024
1 parent 913349d commit 565c7da
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 67 deletions.
61 changes: 1 addition & 60 deletions cpp/s2pdump/s2pdump_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ set<int> S2pDumpExecutor::ReportLuns()
{
vector<uint8_t> buffer(512);
vector<uint8_t> cdb(12);
cdb[8] = static_cast<uint8_t>(buffer.size() >> 8);
cdb[9] = static_cast<uint8_t>(buffer.size());
SetInt16(cdb, 8, buffer.size());

// Assume 8 LUNs in case REPORT LUNS is not available
if (initiator_executor->Execute(scsi_command::report_luns, cdb, buffer, static_cast<int>(buffer.size()))) {
Expand All @@ -77,61 +76,3 @@ set<int> S2pDumpExecutor::ReportLuns()

return luns;
}

void S2pDumpExecutor::Rewind()
{
vector<uint8_t> cdb(6);

initiator_executor->Execute(scsi_command::rewind, cdb, { }, 0, 300);
}

int S2pDumpExecutor::ReadWriteTape(span<uint8_t> buffer, bool is_write)
{
vector<uint8_t> cdb(6);
cdb[2] = static_cast<uint8_t>(default_length >> 16);
cdb[3] = static_cast<uint8_t>(default_length >> 8);
cdb[4] = static_cast<uint8_t>(default_length);

int status = initiator_executor->Execute(is_write ? scsi_command::write_6 : scsi_command::read_6, cdb, buffer,
default_length, 300);
if (!status) {
return default_length;
}

fill_n(cdb.begin(), cdb.size(), 0);
cdb[4] = 14;
initiator_executor->Execute(scsi_command::request_sense, cdb, buffer, 14, 3);

if (buffer[2] & 0x80) {
debug("Hit filemark");
return 0;
}

if (!(buffer[0] & 0x80)) {
error("VALID is not set");
return -1;
}

default_length -= GetInt32(buffer, 3);

debug("Found block with {} byte(s)", default_length);

cdb[2] = static_cast<uint8_t>(default_length >> 16);
cdb[3] = static_cast<uint8_t>(default_length >> 8);
cdb[4] = static_cast<uint8_t>(default_length);

status = initiator_executor->Execute(is_write ? scsi_command::write_6 : scsi_command::read_6, cdb, buffer,
default_length, 300);
if (!status) {
return default_length;
}

fill_n(cdb.begin(), cdb.size(), 0);
cdb[4] = 14;
initiator_executor->Execute(scsi_command::request_sense, cdb, buffer, 14, 3);
spdlog::error(buffer[2] & 0x0f);
spdlog::error(buffer[12]);
// TODO Print sense data

return -1;
}
7 changes: 0 additions & 7 deletions cpp/s2pdump/s2pdump_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ class S2pDumpExecutor
bool ModeSense6(span<uint8_t>);
set<int> ReportLuns();

void Rewind();
int ReadWriteTape(span<uint8_t>, bool);

void SetTarget(int id, int lun, bool sasi)
{
initiator_executor->SetTarget(id, lun, sasi);
Expand All @@ -39,8 +36,4 @@ class S2pDumpExecutor
protected:

unique_ptr<InitiatorExecutor> initiator_executor;

private:

int default_length = 0xffffff;
};

0 comments on commit 565c7da

Please sign in to comment.