From ab812ec5e2113d34b2ec912337f02ac2775a6f10 Mon Sep 17 00:00:00 2001 From: Uwe Seimet Date: Wed, 15 Nov 2023 17:34:16 +0100 Subject: [PATCH] Cleanup --- cpp/scsisend/scsi_executor.cpp | 10 ++++------ cpp/scsisend/scsi_executor.h | 5 +++-- cpp/scsisend/scsisend_core.cpp | 21 +++++++-------------- cpp/scsisend/scsisend_core.h | 7 ++----- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/cpp/scsisend/scsi_executor.cpp b/cpp/scsisend/scsi_executor.cpp index c6ba8ac0..db24b6ab 100644 --- a/cpp/scsisend/scsi_executor.cpp +++ b/cpp/scsisend/scsi_executor.cpp @@ -23,13 +23,11 @@ using namespace spdlog; using namespace scsi_defs; using namespace piscsi_interface; -void ScsiExecutor::Execute(bool binary) +void ScsiExecutor::Execute(const string& filename, bool binary) { - const string file = binary ? "test.bin" : "test.json"; - int size = 0; if (!binary) { - ifstream in(file); + ifstream in(filename); assert(!in.fail()); stringstream buf; buf << in.rdbuf(); @@ -38,9 +36,9 @@ void ScsiExecutor::Execute(bool binary) size = json.size(); } else { - ifstream in(file, ios::binary); + ifstream in(filename, ios::binary); assert(!in.fail()); - vector b(file_size(file)); + vector b(file_size(filename)); in.read(b.data(), b.size()); memcpy(buffer.data(), b.data(), b.size()); size = b.size(); diff --git a/cpp/scsisend/scsi_executor.h b/cpp/scsisend/scsi_executor.h index 71dce5c0..a0b1d5fd 100644 --- a/cpp/scsisend/scsi_executor.h +++ b/cpp/scsisend/scsi_executor.h @@ -9,10 +9,11 @@ #pragma once +#include "scsisend/phase_executor.h" #include #include #include -#include "scsisend/phase_executor.h" +#include using namespace std; @@ -27,7 +28,7 @@ public: } ~ScsiExecutor() = default; - void Execute(bool); + void Execute(const string&, bool); void SetTarget(int id, int lun) { diff --git a/cpp/scsisend/scsisend_core.cpp b/cpp/scsisend/scsisend_core.cpp index 35157e74..1adb9bad 100644 --- a/cpp/scsisend/scsisend_core.cpp +++ b/cpp/scsisend/scsisend_core.cpp @@ -50,15 +50,12 @@ bool ScsiSend::Banner(span args) const cout << piscsi_util::Banner("(SCSI Action Trigger Utility)"); if (args.size() < 2 || string(args[1]) == "-h" || string(args[1]) == "--help") { - cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] [-f FILE] [-a] [-r] [-b BUFFER_SIZE]" - << " [-L log_level] [-p] [-I] [-s]\n" + cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] -f FILENAME [-L log_level] [-b] \n" << " ID is the target device ID (0-" << (ControllerManager::GetScsiIdMax() - 1) << ").\n" << " LUN is the optional target device LUN (0-" << (ControllerManager::GetScsiLunMax() - 1) << ")." << " Default is 0.\n" << " BID is the PiSCSI board ID (0-7). Default is 7.\n" - << " FILE is the protobuf input data path.\n" - << " BUFFER_SIZE is the transfer buffer size in bytes, at least " << MINIMUM_BUFFER_SIZE - << " bytes. Default is 1 MiB.\n" + << " FILENAME is the protobuf input data path.\n" << flush; return false; @@ -67,7 +64,7 @@ bool ScsiSend::Banner(span args) const return true; } -bool ScsiSend::Init(bool in_process) +bool ScsiSend::Init(bool) { instance = this; // Signal handler for cleaning up @@ -93,7 +90,7 @@ void ScsiSend::ParseArguments(span args) optind = 1; opterr = 0; int opt; - while ((opt = getopt(static_cast(args.size()), args.data(), "i:f:b:t:L:arspI")) != -1) { + while ((opt = getopt(static_cast(args.size()), args.data(), "i:f:t:bL:")) != -1) { switch (opt) { case 'i': if (!GetAsUnsignedInt(optarg, initiator_id) || initiator_id > 7) { @@ -106,11 +103,7 @@ void ScsiSend::ParseArguments(span args) break; case 'b': -// if (!GetAsUnsignedInt(optarg, buffer_size) || buffer_size < MINIMUM_BUFFER_SIZE) { -// throw parser_exception( -// "Buffer size must be at least " + to_string(MINIMUM_BUFFER_SIZE / 1024) + " KiB"); -// } - + binary = true; break; case 't': @@ -131,8 +124,6 @@ void ScsiSend::ParseArguments(span args) if (target_lun == -1) { target_lun = 0; } - - scsi_executor->Execute(false); } int ScsiSend::run(span args, bool in_process) @@ -169,6 +160,8 @@ int ScsiSend::run(span args, bool in_process) return EXIT_FAILURE; } + scsi_executor->Execute(filename, binary); + CleanUp(); return EXIT_SUCCESS; diff --git a/cpp/scsisend/scsisend_core.h b/cpp/scsisend/scsisend_core.h index 38eb1827..510d60c7 100644 --- a/cpp/scsisend/scsisend_core.h +++ b/cpp/scsisend/scsisend_core.h @@ -54,13 +54,10 @@ private: string filename; - string log_level = "info"; + bool binary = false; - bool restore = false; + string log_level = "info"; // Required for the termination handler static inline ScsiSend *instance; - - static const int MINIMUM_BUFFER_SIZE = 1024 * 64; - static const int DEFAULT_BUFFER_SIZE = 1024 * 1024; };