Skip to content

Commit

Permalink
Initial persist implementatoin for stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Mar 26, 2024
1 parent 4ddbcbb commit f80dfb9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions cpp/command/command_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
//---------------------------------------------------------------------------

#include <fstream>
#include <spdlog/spdlog.h>
#include "controllers/controller_factory.h"
#include "shared/shared_exceptions.h"
Expand Down Expand Up @@ -144,6 +145,9 @@ bool CommandDispatcher::DispatchCommand(const CommandContext &context, PbResult
case RESERVE_IDS:
return executor.ProcessCmd(context);

case PERSIST_CONFIGURATION:
return Persist(context);

default:
// The remaining commands may only be executed when the target is idle
if (!ExecuteWithLock(context)) {
Expand Down Expand Up @@ -281,3 +285,12 @@ bool CommandDispatcher::SetLogLevel(const string &log_level)

return true;
}

bool CommandDispatcher::Persist(const CommandContext &context) const
{
for (const auto& [key, value] : PropertyHandler::Instance().GetProperties()) {
cout << key << "=" << value << endl;
}

return context.ReturnSuccessStatus();
}
1 change: 1 addition & 0 deletions cpp/command/command_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CommandDispatcher
bool ExecuteWithLock(const CommandContext&);
bool HandleDeviceListChange(const CommandContext&, PbOperation) const;
bool ShutDown(const CommandContext&, const string&) const;
bool Persist(const CommandContext&) const;

[[no_unique_address]] CommandResponse response;

Expand Down
6 changes: 6 additions & 0 deletions cpp/s2pctl/sp2ctl_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ int S2pCtl::ParseArguments(const vector<char*> &args) // NOSONAR Acceptable comp
const int OPT_LOCALE = 7;
const int OPT_SCSI_LEVEL = 8;
const int OPT_LIST_EXTENSIONS = 9;
const int OPT_PERSIST = 10;

const vector<option> options = {
{ "prompt", no_argument, nullptr, OPT_PROMPT },
Expand Down Expand Up @@ -164,6 +165,7 @@ int S2pCtl::ParseArguments(const vector<char*> &args) // NOSONAR Acceptable comp
{ "locale", required_argument, nullptr, OPT_LOCALE },
{ "log-level", required_argument, nullptr, 'L' },
{ "name", required_argument, nullptr, 'n' },
{ "persist", no_argument, nullptr, OPT_PERSIST },
{ "port", required_argument, nullptr, 'p' },
{ "rename", required_argument, nullptr, 'R' },
{ "reserve-ids", optional_argument, nullptr, 'r' },
Expand Down Expand Up @@ -328,6 +330,10 @@ int S2pCtl::ParseArguments(const vector<char*> &args) // NOSONAR Acceptable comp
command.set_operation(PROPERTIES_INFO);
break;

case OPT_PERSIST:
command.set_operation(PERSIST_CONFIGURATION);
break;

case 't':
device->set_type(ParseDeviceType(optarg));
if (device->type() == UNDEFINED) {
Expand Down
8 changes: 6 additions & 2 deletions doc/s2pctl.1
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ s2pctl \- SCSI2Pi Server Controller Tool
[\fB\--list-settings/-s\fR \fI[FOLDER_PATTERN:FILE_PATTERN:OPERATIONS]\fR] |
[\fB\--type/-t\fR \fITYPE\fR] |
[\fB\--copy/-x\fR \fICURRENT_NAME:NEW_NAME\fR] |
[\fB\--persist\fR]
[\fB\--locale\fR \fILOCALE\fR]
.SH DESCRIPTION
.B s2pctl
Expand Down Expand Up @@ -113,10 +114,10 @@ Comma-separated list of IDs to reserve. Pass an empty list in order to not reser
Display all s2p settings. Filenames are optionally filtered by folder and file patterns.
OPERATIONS is an optional comma-seperated list of server operations to take into account, in order to limit the amount of output.
.TP
.BR --list-statistics/-S\fI
.BR --list-statistics/-S\fI " " \fI
Display s2p statistics.
.TP
.BR --list-device-types/-T\fI
.BR --list-device-types/-T\fI " " \fI
Display available device types and their properties.
.TP
.BR --help/-h\fI " " \fI
Expand Down Expand Up @@ -146,6 +147,9 @@ Do not send the command to s2p but write it to a protobuf JSON file.
.BR --text-protobuf\fI " "\fIFILENAME
Do not send the command to s2p but write it to a protobuf text format file.
.TP
.BR --persist\fI " " \fI
Write the current configuration to /etc/s2p.conf. The old configuration, if any, is saved to /etc/s2p.conf.old.
.TP
.BR --locale\fI " "\fILOCALE
Overrides the default locale (language) for client-facing error messages.
.TP
Expand Down
3 changes: 3 additions & 0 deletions proto/s2p_interface.proto
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ enum PbOperation {

// Get properties (PbPropertiesInfo)
PROPERTIES_INFO = 100;

// Persist configuration in /etc/s2p.conf
PERSIST_CONFIGURATION = 101;
}

// The operation parameter meta data. The parameter data type is provided by the protobuf API.
Expand Down

0 comments on commit f80dfb9

Please sign in to comment.