mirror of
https://github.com/akuker/RASCSI.git
synced 2024-05-28 09:41:33 +00:00
Add shutdown support
This commit is contained in:
parent
89d777fabf
commit
11e4eb29c2
|
@ -59,6 +59,7 @@ bool ScsiExecutor::Execute(const string& filename, bool binary, string& result)
|
|||
cdb[6] = static_cast<uint8_t>(input_length);
|
||||
cdb[7] = static_cast<uint8_t>(buffer.size() >> 8);
|
||||
cdb[8] = static_cast<uint8_t>(buffer.size());
|
||||
|
||||
phase_executor->Execute(scsi_command::eCmdExecute, cdb, buffer, input_length, buffer.size());
|
||||
|
||||
const int length = phase_executor->GetByteCount();
|
||||
|
@ -78,3 +79,13 @@ bool ScsiExecutor::Execute(const string& filename, bool binary, string& result)
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ScsiExecutor::ShutDown()
|
||||
{
|
||||
vector<uint8_t> cdb(6);
|
||||
cdb[4] = 0x02;
|
||||
|
||||
phase_executor->Execute(scsi_command::eCmdStartStop, cdb, buffer, 0, 0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
~ScsiExecutor() = default;
|
||||
|
||||
bool Execute(const string&, bool, string&);
|
||||
bool ShutDown();
|
||||
|
||||
void SetTarget(int id, int lun)
|
||||
{
|
||||
|
|
|
@ -45,14 +45,15 @@ bool ScsiExec::Banner(span<char*> args) const
|
|||
cout << piscsi_util::Banner("(SCSI Action Execution Tool)");
|
||||
|
||||
if (args.size() < 2 || string(args[1]) == "-h" || string(args[1]) == "--help") {
|
||||
cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] -f FILE [-L LOG_LEVEL] [-b]\n"
|
||||
cout << "Usage: " << args[0] << " -t ID[:LUN] [-i BID] -f FILE [-L LOG_LEVEL] [-b] [-X]\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"
|
||||
<< " FILENAME is the protobuf input data path.\n"
|
||||
<< " LOG_LEVEL is the log level {trace|debug|info|warn|err|off}, default is 'info'.\n"
|
||||
<< " -b signals that the input file is in binary protobuf format instead of JSON format.\n"
|
||||
<< " -b Signal that the input file is in binary protobuf format instead of JSON format.\n"
|
||||
<< " -X Shut down piscsi.\n"
|
||||
<< flush;
|
||||
|
||||
return false;
|
||||
|
@ -87,7 +88,7 @@ void ScsiExec::ParseArguments(span<char*> args)
|
|||
optind = 1;
|
||||
opterr = 0;
|
||||
int opt;
|
||||
while ((opt = getopt(static_cast<int>(args.size()), args.data(), "i:f:t:bL:")) != -1) {
|
||||
while ((opt = getopt(static_cast<int>(args.size()), args.data(), "i:f:t:bL:X")) != -1) {
|
||||
switch (opt) {
|
||||
case 'i':
|
||||
if (!GetAsUnsignedInt(optarg, initiator_id) || initiator_id > 7) {
|
||||
|
@ -113,11 +114,19 @@ void ScsiExec::ParseArguments(span<char*> args)
|
|||
log_level = optarg;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
shut_down = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (shut_down) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (filename.empty()) {
|
||||
throw parser_exception("Missing filename");
|
||||
}
|
||||
|
@ -167,13 +176,19 @@ int ScsiExec::run(span<char*> args, bool in_process)
|
|||
|
||||
scsi_executor->SetTarget(target_id, target_lun);
|
||||
|
||||
string result;
|
||||
const bool status = scsi_executor->Execute(filename, binary, result);
|
||||
if (status) {
|
||||
cout << result << '\n' << flush;
|
||||
bool status = false;
|
||||
if (shut_down) {
|
||||
status = scsi_executor->ShutDown();
|
||||
}
|
||||
else {
|
||||
cerr << "Error: " << result << endl;
|
||||
string result;
|
||||
status = scsi_executor->Execute(filename, binary, result);
|
||||
if (status) {
|
||||
cout << result << '\n' << flush;
|
||||
}
|
||||
else {
|
||||
cerr << "Error: " << result << endl;
|
||||
}
|
||||
}
|
||||
|
||||
CleanUp();
|
||||
|
|
|
@ -50,6 +50,8 @@ private:
|
|||
|
||||
bool binary = false;
|
||||
|
||||
bool shut_down = false;
|
||||
|
||||
string log_level = "info";
|
||||
|
||||
// Required for the termination handler
|
||||
|
|
|
@ -9,6 +9,7 @@ scsidump \- SCSI action execution tool for PiSCSI
|
|||
[\fB\-b\fR]
|
||||
[\fB\-t\tR] ID[:LUN]
|
||||
[\fB\-L\fR \fILOG_LEVEL\fR]
|
||||
[\fB\-X\fR]
|
||||
.SH DESCRIPTION
|
||||
.B scsiexec
|
||||
wraps JSON or binary input data in protobuf format into a custom PiSCSI SCSI command, has piscsi execute it and display the results in JSON format. The input data must be legal commands for the PiSCSi protobuf interface. See the file piscsi_interface.proto for details.
|
||||
|
@ -35,6 +36,9 @@ Signals that the inout file is a binary file and not a JSON file.
|
|||
.TP
|
||||
.BR \-L\fI " " \fILOG_LEVEL
|
||||
The scsiexec log level (trace, debug, info, warning, error, off). The default log level is 'info'.
|
||||
.TP
|
||||
.BR \-X\fI
|
||||
Shut down piscsi.
|
||||
|
||||
.SH SEE ALSO
|
||||
scsictl(1), piscsi(1), scsidump(1), scsimon(1)
|
||||
|
|
|
@ -7,7 +7,7 @@ NAME
|
|||
|
||||
SYNOPSIS
|
||||
scsidump -t ID[:LUN] [-i BID] -f FILENAME [-b] [-tR] ID[:LUN] [-L
|
||||
LOG_LEVEL]
|
||||
LOG_LEVEL] [-X]
|
||||
|
||||
DESCRIPTION
|
||||
scsiexec wraps JSON or binary input data in protobuf format into a cus‐
|
||||
|
@ -40,6 +40,8 @@ OPTIONS
|
|||
The scsiexec log level (trace, debug, info, warning, error,
|
||||
off). The default log level is 'info'.
|
||||
|
||||
-X Shut down piscsi.
|
||||
|
||||
SEE ALSO
|
||||
scsictl(1), piscsi(1), scsidump(1), scsimon(1)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user