2021-10-06 21:25:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-12-05 17:58:23 +00:00
|
|
|
// SCSI Target Emulator PiSCSI
|
2021-10-06 21:25:43 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
2022-09-07 14:38:42 +00:00
|
|
|
// Copyright (C) 2021-2022 Uwe Seimet
|
2021-10-06 21:25:43 +00:00
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2022-11-10 06:44:06 +00:00
|
|
|
#include "shared/protobuf_util.h"
|
2022-12-05 17:58:23 +00:00
|
|
|
#include "generated/piscsi_interface.pb.h"
|
|
|
|
#include "scsictl_display.h"
|
2022-10-08 17:26:04 +00:00
|
|
|
#include <sstream>
|
2021-10-06 21:25:43 +00:00
|
|
|
#include <list>
|
2022-10-08 17:26:04 +00:00
|
|
|
#include <iomanip>
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
using namespace std;
|
2022-12-05 17:58:23 +00:00
|
|
|
using namespace piscsi_interface;
|
2022-11-10 06:44:06 +00:00
|
|
|
using namespace protobuf_util;
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayDevicesInfo(const PbDevicesInfo& devices_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
const list<PbDevice>& devices = { devices_info.devices().begin(), devices_info.devices().end() };
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << ListDevices(devices);
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayDeviceInfo(const PbDevice& pb_device) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << " " << pb_device.id() << ":" << pb_device.unit() << " " << PbDeviceType_Name(pb_device.type())
|
2021-10-06 21:25:43 +00:00
|
|
|
<< " " << pb_device.vendor() << ":" << pb_device.product() << ":" << pb_device.revision();
|
|
|
|
|
|
|
|
if (pb_device.block_size()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << pb_device.block_size() << " bytes per sector";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.block_count()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << pb_device.block_size() * pb_device.block_count() << " bytes capacity";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pb_device.properties().supports_file() && !pb_device.file().name().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << pb_device.file().name();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
bool hasProperty = false;
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().read_only()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "read-only";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().protectable() && pb_device.status().protected_()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "protected";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().stoppable() && pb_device.status().stopped()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "stopped";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().removable() && pb_device.status().removed()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "removed";
|
2021-10-06 21:25:43 +00:00
|
|
|
hasProperty = true;
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (pb_device.properties().lockable() && pb_device.status().locked()) {
|
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "locked";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (hasProperty) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayParams(s, pb_device);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayVersionInfo(const PbVersionInfo& version_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "piscsi server version: " << setw(2) << setfill('0') << version_info.major_version() << "."
|
2022-10-08 17:26:04 +00:00
|
|
|
<< setw(2) << setfill('0') << version_info.minor_version();
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (version_info.patch_version() > 0) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "." << version_info.patch_version();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else if (version_info.patch_version() < 0) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " (development version)";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayLogLevelInfo(const PbLogLevelInfo& log_level_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (!log_level_info.log_levels_size()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " No log level settings available\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "piscsi log levels, sorted by severity:\n";
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
for (const auto& log_level : log_level_info.log_levels()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << log_level << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "Current piscsi log level: " << log_level_info.current_log_level() << '\n';
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_types_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Supported device types and their properties:";
|
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
for (const auto& device_type_info : device_types_info.properties()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "\n " << PbDeviceType_Name(device_type_info.type()) << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
const PbDeviceProperties& properties = device_type_info.properties();
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayAttributes(s, properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
if (properties.supports_file()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "Image file support\n ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
if (properties.supports_params()) {
|
|
|
|
s << "Parameter support\n ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayDefaultParameters(s, properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
DisplayBlockSizes(s, properties);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2022-10-12 20:10:56 +00:00
|
|
|
s << '\n';
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayReservedIdsInfo(const PbReservedIdsInfo& reserved_ids_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (reserved_ids_info.ids_size()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "Reserved device IDs: ";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
for (int i = 0; i < reserved_ids_info.ids_size(); i++) {
|
|
|
|
if(i) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << reserved_ids_info.ids(i);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << '\n';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s << "No reserved device IDs\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayImageFile(const PbImageFile& image_file_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << image_file_info.name() << " " << image_file_info.size() << " bytes";
|
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (image_file_info.read_only()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " read-only";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
if (image_file_info.type() != UNDEFINED) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << PbDeviceType_Name(image_file_info.type());
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayImageFilesInfo(const PbImageFilesInfo& image_files_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Default image file folder: " << image_files_info.default_image_folder() << '\n';
|
|
|
|
s << "Supported folder depth: " << image_files_info.depth() << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
if (image_files_info.image_files().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " No image files available\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-11-14 01:36:35 +00:00
|
|
|
list<PbImageFile> image_files = { image_files_info.image_files().begin(), image_files_info.image_files().end() };
|
|
|
|
image_files.sort([](const auto& a, const auto& b) { return a.name() < b.name(); });
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
s << "Available image files:\n";
|
2021-11-14 01:36:35 +00:00
|
|
|
for (const auto& image_file : image_files) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
|
|
|
|
|
|
|
s << DisplayImageFile(image_file);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayNetworkInterfaces(const PbNetworkInterfacesInfo& network_interfaces_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Available (up) network interfaces:\n";
|
|
|
|
|
|
|
|
const list<string> sorted_interfaces = { network_interfaces_info.name().begin(), network_interfaces_info.name().end() };
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
bool isFirst = true;
|
2022-10-08 17:26:04 +00:00
|
|
|
for (const auto& interface : sorted_interfaces) {
|
2021-10-06 21:25:43 +00:00
|
|
|
if (!isFirst) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << ", ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
else {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " ";
|
SASI code removal, error handling update, bug fixes, code cleanup (#806)
Summary ov most important changes triggered by the SASI code removal:
- Removed the SASI controller code
- New controller management. There is a new controller base class AbstractController and a class ControllerManager managing the controller lifecycle. The lifecycle management was removed from rasci.cpp and is covered by unit tests.
- New device management. The DeviceFactory manages the device lifecycle instead of rascsi.cpp. The new code is covered by unit tests.
- The lifecycle managment uses C++ collections with variable size instead of arrays with hard-coded sizes.
- The ScsiController method contains most of what was previously contained in scsidev_ctrl.cpp plus the code from sasidev_ctrl.cpp that was relevant for SCSI.
- scsi_command_util contains helper methods used for identical SCSI command implementations of more than one device
- Devices know their controllers, so that the controller instance does not need to be passed to each SCSI command. This change helps to decouple the devices from the controller. The phase_handler interface is also part of this decoupling.
- Use scsi_command_exception for propagating SCSI command execution errors, This resolves issues with the previous error handling, which was based on return values and often on magic numbers.
- Removed legacy SCSI error codes, all errors are now encoded by sense_key::, asc:: and status::.
- Fixed various warnings reported with -Wextra, -Weffc++ and -Wpedantic.
- Use constructor member initialization lists (recommended for ISO C++)
- Consistently use new/delete instead of malloc/free (recommended for ISO C++), resulting in better type safety and error handling
- Replaced variable sized arrays on the stack (violates ISO C++ and can cause a stack overflow)
- Replaced NULL by nullptr (recommended for C++), resulting in better type safety
- Use more const member functions in order to avoid side effects
- The format device page can now also be changed for hard disk drives (Fujitsu M2624S supports this, for instance), not just for MOs.
- Better encapsulation, updated access specifiers in many places
- Removed unused methods and method arguments
- Fixed a number of TODOs
- Added/updated unit tests for a lot of non-legacy classes
- Makefile support for creating HTML coverage reports with lcov/genhtml
2022-09-03 14:53:53 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
2021-10-06 21:25:43 +00:00
|
|
|
isFirst = false;
|
2022-10-08 17:26:04 +00:00
|
|
|
s << interface;
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info) const
|
2021-10-06 21:25:43 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
s << "Supported image file extension to device type mappings:\n";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2022-10-08 17:26:04 +00:00
|
|
|
const map<string, PbDeviceType, less<>> sorted_mappings = { mapping_info.mapping().begin(), mapping_info.mapping().end() };
|
|
|
|
|
|
|
|
for (const auto& [extension, type] : sorted_mappings) {
|
|
|
|
s << " " << extension << "->" << PbDeviceType_Name(type) << '\n';
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
|
|
|
|
return s.str();
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
2021-12-21 07:43:21 +00:00
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
string ScsictlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info) const
|
2021-12-21 07:43:21 +00:00
|
|
|
{
|
2022-10-08 17:26:04 +00:00
|
|
|
ostringstream s;
|
|
|
|
|
|
|
|
const map<int, PbOperationMetaData, less<>> operations = { operation_info.operations().begin(), operation_info.operations().end() };
|
2021-12-21 07:43:21 +00:00
|
|
|
|
|
|
|
// Copies result into a map sorted by operation name
|
2022-10-08 17:26:04 +00:00
|
|
|
auto unknown_operation = make_unique<PbOperationMetaData>();
|
|
|
|
map<string, PbOperationMetaData, less<>> sorted_operations;
|
|
|
|
|
2022-09-07 14:38:42 +00:00
|
|
|
for (const auto& [ordinal, meta_data] : operations) {
|
|
|
|
if (PbOperation_IsValid(static_cast<PbOperation>(ordinal))) {
|
|
|
|
sorted_operations[PbOperation_Name(static_cast<PbOperation>(ordinal))] = meta_data;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// If the server-side operation is unknown for the client use the server-provided operation name
|
|
|
|
// No further operation information is available in this case
|
2022-09-07 14:38:42 +00:00
|
|
|
sorted_operations[meta_data.server_side_name()] = *unknown_operation;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
s << "Operations supported by piscsi server and their parameters:\n";
|
2022-09-07 14:38:42 +00:00
|
|
|
for (const auto& [name, meta_data] : sorted_operations) {
|
|
|
|
if (!meta_data.server_side_name().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << name;
|
2022-09-07 14:38:42 +00:00
|
|
|
if (!meta_data.description().empty()) {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " (" << meta_data.description() << ")";
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
DisplayParameters(s, meta_data);
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
else {
|
2022-10-08 17:26:04 +00:00
|
|
|
s << " " << name << " (Unknown server-side operation)\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
void ScsictlDisplay::DisplayParams(ostringstream& s, const PbDevice& pb_device) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
|
|
|
const map<string, string, less<>> sorted_params = { pb_device.params().begin(), pb_device.params().end() };
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& [key, value] : sorted_params) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << ":";
|
|
|
|
}
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
s << key << "=" << value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
void ScsictlDisplay::DisplayAttributes(ostringstream& s, const PbDeviceProperties& properties) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
|
|
|
if (properties.read_only() || properties.protectable() || properties.stoppable() || properties.lockable()) {
|
|
|
|
s << "Properties: ";
|
|
|
|
|
|
|
|
bool has_property = false;
|
|
|
|
|
|
|
|
if (properties.read_only()) {
|
|
|
|
s << "read-only";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.protectable()) {
|
|
|
|
s << (has_property ? ", " : "") << "protectable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.stoppable()) {
|
|
|
|
s << (has_property ? ", " : "") << "stoppable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.removable()) {
|
|
|
|
s << (has_property ? ", " : "") << "removable";
|
|
|
|
has_property = true;
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
2022-10-08 17:26:04 +00:00
|
|
|
if (properties.lockable()) {
|
|
|
|
s << (has_property ? ", " : "") << "lockable";
|
|
|
|
}
|
|
|
|
|
|
|
|
s << "\n ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
void ScsictlDisplay::DisplayDefaultParameters(ostringstream& s, const PbDeviceProperties& properties) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
|
|
|
if (properties.supports_params() && properties.default_params_size()) {
|
|
|
|
s << "Default parameters: ";
|
|
|
|
|
|
|
|
const map<string, string, less<>> sorted_params = { properties.default_params().begin(), properties.default_params().end() };
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& [key, value] : sorted_params) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << "\n ";
|
|
|
|
}
|
|
|
|
s << key << "=" << value;
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
void ScsictlDisplay::DisplayBlockSizes(ostringstream& s, const PbDeviceProperties& properties) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
|
|
|
if (properties.block_sizes_size()) {
|
|
|
|
s << "Configurable block sizes in bytes: ";
|
|
|
|
|
|
|
|
const set<uint32_t> sorted_sizes = { properties.block_sizes().begin(), properties.block_sizes().end() };
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& size : sorted_sizes) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
s << size;
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
void ScsictlDisplay::DisplayParameters(ostringstream& s, const PbOperationMetaData& meta_data) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
|
|
|
list<PbOperationParameter> sorted_parameters = { meta_data.parameters().begin(), meta_data.parameters().end() };
|
|
|
|
sorted_parameters.sort([](const auto& a, const auto& b) { return a.name() < b.name(); });
|
|
|
|
|
|
|
|
for (const auto& parameter : sorted_parameters) {
|
|
|
|
s << " " << parameter.name() << ": "
|
|
|
|
<< (parameter.is_mandatory() ? "mandatory" : "optional");
|
|
|
|
|
|
|
|
if (!parameter.description().empty()) {
|
|
|
|
s << " (" << parameter.description() << ")";
|
|
|
|
}
|
|
|
|
s << '\n';
|
|
|
|
|
|
|
|
DisplayPermittedValues(s, parameter);
|
|
|
|
|
|
|
|
if (!parameter.default_value().empty()) {
|
|
|
|
s << " Default value: " << parameter.default_value() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:58:23 +00:00
|
|
|
void ScsictlDisplay::DisplayPermittedValues(ostringstream& s, const PbOperationParameter& parameter) const
|
2022-10-08 17:26:04 +00:00
|
|
|
{
|
|
|
|
if (parameter.permitted_values_size()) {
|
|
|
|
s << " Permitted values: ";
|
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
|
|
|
|
for (const auto& permitted_value : parameter.permitted_values()) {
|
|
|
|
if (!isFirst) {
|
|
|
|
s << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
s << permitted_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
s << '\n';
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
}
|