2021-10-06 21:25:43 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
2022-08-26 01:01:39 +00:00
|
|
|
// SCSI Target Emulator RaSCSI Reloaded
|
2021-10-06 21:25:43 +00:00
|
|
|
// for Raspberry Pi
|
|
|
|
//
|
|
|
|
// Copyright (C) 2021 Uwe Seimet
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "rascsi_interface.pb.h"
|
|
|
|
#include "rasutil.h"
|
|
|
|
#include "rasctl_display.h"
|
|
|
|
#include <iostream>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace rascsi_interface;
|
2021-10-17 06:51:14 +00:00
|
|
|
using namespace ras_util;
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
void RasctlDisplay::DisplayDevices(const PbDevicesInfo& devices_info)
|
|
|
|
{
|
|
|
|
const list<PbDevice>& devices = { devices_info.devices().begin(), devices_info.devices().end() };
|
|
|
|
cout << ListDevices(devices) << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayDeviceInfo(const PbDevice& pb_device)
|
|
|
|
{
|
|
|
|
cout << " " << pb_device.id() << ":" << pb_device.unit() << " " << PbDeviceType_Name(pb_device.type())
|
|
|
|
<< " " << pb_device.vendor() << ":" << pb_device.product() << ":" << pb_device.revision();
|
|
|
|
|
|
|
|
if (pb_device.block_size()) {
|
|
|
|
cout << " " << pb_device.block_size() << " bytes per sector";
|
|
|
|
if (pb_device.block_count()) {
|
|
|
|
cout << " " << pb_device.block_size() * pb_device.block_count() << " bytes capacity";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pb_device.properties().supports_file() && !pb_device.file().name().empty()) {
|
|
|
|
cout << " " << pb_device.file().name();
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << " ";
|
|
|
|
bool hasProperty = false;
|
|
|
|
if (pb_device.properties().read_only()) {
|
|
|
|
cout << "read-only";
|
|
|
|
hasProperty = true;
|
|
|
|
}
|
|
|
|
if (pb_device.properties().protectable() && pb_device.status().protected_()) {
|
|
|
|
if (hasProperty) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
cout << "protected";
|
|
|
|
hasProperty = true;
|
|
|
|
}
|
|
|
|
if (pb_device.properties().stoppable() && pb_device.status().stopped()) {
|
|
|
|
if (hasProperty) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
cout << "stopped";
|
|
|
|
hasProperty = true;
|
|
|
|
}
|
|
|
|
if (pb_device.properties().removable() && pb_device.status().removed()) {
|
|
|
|
if (hasProperty) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
cout << "removed";
|
|
|
|
hasProperty = true;
|
|
|
|
}
|
|
|
|
if (pb_device.properties().lockable() && pb_device.status().locked()) {
|
|
|
|
if (hasProperty) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
cout << "locked";
|
|
|
|
}
|
|
|
|
if (hasProperty) {
|
|
|
|
cout << " ";
|
|
|
|
}
|
|
|
|
|
2022-02-17 02:04:42 +00:00
|
|
|
// Creates a sorted map
|
|
|
|
map<string, string> params = { pb_device.params().begin(), pb_device.params().end() };
|
2021-10-06 21:25:43 +00:00
|
|
|
bool isFirst = true;
|
2022-02-17 02:04:42 +00:00
|
|
|
for (const auto& param : params) {
|
2021-10-06 21:25:43 +00:00
|
|
|
if (!isFirst) {
|
2022-02-17 02:04:42 +00:00
|
|
|
cout << ":";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
isFirst = false;
|
|
|
|
cout << param.first << "=" << param.second;
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayVersionInfo(const PbVersionInfo& version_info)
|
|
|
|
{
|
|
|
|
cout << "rascsi server version: " << version_info.major_version() << "." << version_info.minor_version();
|
|
|
|
if (version_info.patch_version() > 0) {
|
|
|
|
cout << "." << version_info.patch_version();
|
|
|
|
}
|
|
|
|
else if (version_info.patch_version() < 0) {
|
|
|
|
cout << " (development version)";
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayLogLevelInfo(const PbLogLevelInfo& log_level_info)
|
|
|
|
{
|
|
|
|
if (!log_level_info.log_levels_size()) {
|
|
|
|
cout << " No log level settings available" << endl;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cout << "rascsi log levels, sorted by severity:" << endl;
|
|
|
|
for (const auto& log_level : log_level_info.log_levels()) {
|
|
|
|
cout << " " << log_level << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << "Current rascsi log level: " << log_level_info.current_log_level() << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayDeviceTypesInfo(const PbDeviceTypesInfo& device_types_info)
|
|
|
|
{
|
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
|
|
|
cout << "Supported device types and their properties:";
|
2021-11-14 01:36:35 +00:00
|
|
|
for (const auto& device_type_info : device_types_info.properties()) {
|
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
|
|
|
cout << endl << " " << 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
|
|
|
|
|
|
|
if (properties.read_only() || properties.protectable() || properties.stoppable() || properties.read_only()
|
|
|
|
|| properties.lockable()) {
|
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
|
|
|
cout << "Properties: ";
|
2021-10-06 21:25:43 +00:00
|
|
|
bool has_property = false;
|
|
|
|
if (properties.read_only()) {
|
|
|
|
cout << "read-only";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.protectable()) {
|
|
|
|
cout << (has_property ? ", " : "") << "protectable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.stoppable()) {
|
|
|
|
cout << (has_property ? ", " : "") << "stoppable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.removable()) {
|
|
|
|
cout << (has_property ? ", " : "") << "removable";
|
|
|
|
has_property = true;
|
|
|
|
}
|
|
|
|
if (properties.lockable()) {
|
|
|
|
cout << (has_property ? ", " : "") << "lockable";
|
|
|
|
}
|
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
|
|
|
cout << endl << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.supports_file()) {
|
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
|
|
|
cout << "Image file support" << endl << " ";
|
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
|
|
|
if (properties.supports_params()) {
|
|
|
|
cout << "Parameter support" << endl << " ";
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.supports_params() && properties.default_params_size()) {
|
2021-11-14 01:36:35 +00:00
|
|
|
// Creates a sorted map
|
2021-10-06 21:25:43 +00:00
|
|
|
map<string, string> params = { properties.default_params().begin(), properties.default_params().end() };
|
|
|
|
|
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
|
|
|
cout << "Default parameters: ";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& param : params) {
|
|
|
|
if (!isFirst) {
|
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
|
|
|
cout << endl << " ";
|
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
|
|
|
cout << param.first << "=" << param.second;
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (properties.block_sizes_size()) {
|
2021-11-14 01:36:35 +00:00
|
|
|
// Creates a sorted set
|
2021-10-06 21:25:43 +00:00
|
|
|
set<uint32_t> block_sizes = { properties.block_sizes().begin(), properties.block_sizes().end() };
|
|
|
|
|
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
|
|
|
cout << "Configurable block sizes in bytes: ";
|
2021-10-06 21:25:43 +00:00
|
|
|
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& block_size : block_sizes) {
|
|
|
|
if (!isFirst) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
cout << block_size;
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayReservedIdsInfo(const PbReservedIdsInfo& reserved_ids_info)
|
|
|
|
{
|
|
|
|
if (reserved_ids_info.ids_size()) {
|
|
|
|
cout << "Reserved device IDs: ";
|
|
|
|
for (int i = 0; i < reserved_ids_info.ids_size(); i++) {
|
|
|
|
if(i) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
cout << reserved_ids_info.ids(i);
|
|
|
|
}
|
|
|
|
cout <<endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayImageFile(const PbImageFile& image_file_info)
|
|
|
|
{
|
|
|
|
cout << image_file_info.name() << " " << image_file_info.size() << " bytes";
|
|
|
|
if (image_file_info.read_only()) {
|
|
|
|
cout << " read-only";
|
|
|
|
}
|
|
|
|
if (image_file_info.type() != UNDEFINED) {
|
|
|
|
cout << " " << PbDeviceType_Name(image_file_info.type());
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayImageFiles(const PbImageFilesInfo& image_files_info)
|
|
|
|
{
|
|
|
|
cout << "Default image file folder: " << image_files_info.default_image_folder() << endl;
|
2021-12-22 08:25:05 +00:00
|
|
|
cout << "Supported folder depth: " << image_files_info.depth() << endl;
|
2021-10-06 21:25:43 +00:00
|
|
|
|
2021-11-14 01:36:35 +00:00
|
|
|
if (image_files_info.image_files().empty()) {
|
2021-10-06 21:25:43 +00:00
|
|
|
cout << " No image files available" << endl;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
cout << "Available image files:" << endl;
|
2021-11-14 01:36:35 +00:00
|
|
|
for (const auto& image_file : image_files) {
|
2021-10-06 21:25:43 +00:00
|
|
|
cout << " ";
|
2021-11-14 01:36:35 +00:00
|
|
|
DisplayImageFile(image_file);
|
2021-10-06 21:25:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayNetworkInterfaces(const PbNetworkInterfacesInfo& network_interfaces_info)
|
|
|
|
{
|
2021-11-14 01:36:35 +00:00
|
|
|
// Creates a sorted list
|
2021-10-06 21:25:43 +00:00
|
|
|
const list<string> interfaces = { network_interfaces_info.name().begin(), network_interfaces_info.name().end() };
|
|
|
|
|
|
|
|
cout << "Available (up) network interfaces:" << endl;
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& interface : interfaces) {
|
|
|
|
if (!isFirst) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
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 {
|
|
|
|
cout << " ";
|
|
|
|
}
|
2021-10-06 21:25:43 +00:00
|
|
|
isFirst = false;
|
|
|
|
cout << interface;
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RasctlDisplay::DisplayMappingInfo(const PbMappingInfo& mapping_info)
|
|
|
|
{
|
2021-11-14 01:36:35 +00:00
|
|
|
// Creates a sorted map
|
2021-10-06 21:25:43 +00:00
|
|
|
const map<string, PbDeviceType> mappings = { mapping_info.mapping().begin(), mapping_info.mapping().end() };
|
|
|
|
|
|
|
|
cout << "Supported image file extension to device type mappings:" << endl;
|
|
|
|
for (const auto& mapping : mappings) {
|
|
|
|
cout << " " << mapping.first << "->" << PbDeviceType_Name(mapping.second) << endl;
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 07:43:21 +00:00
|
|
|
|
|
|
|
void RasctlDisplay::DisplayOperationInfo(const PbOperationInfo& operation_info)
|
|
|
|
{
|
|
|
|
const map<int, PbOperationMetaData> operations = { operation_info.operations().begin(), operation_info.operations().end() };
|
|
|
|
|
|
|
|
// Copies result into a map sorted by operation name
|
|
|
|
const PbOperationMetaData *unknown_operation = new PbOperationMetaData();
|
|
|
|
map<string, PbOperationMetaData> sorted_operations;
|
|
|
|
for (const auto& operation : operations) {
|
|
|
|
if (PbOperation_IsValid(static_cast<PbOperation>(operation.first))) {
|
|
|
|
sorted_operations[PbOperation_Name(static_cast<PbOperation>(operation.first))] = operation.second;
|
|
|
|
}
|
|
|
|
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
|
|
|
|
sorted_operations[operation.second.server_side_name()] = *unknown_operation;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 08:25:05 +00:00
|
|
|
cout << "Operations supported by rascsi server and their parameters:" << endl;
|
2021-12-21 07:43:21 +00:00
|
|
|
for (const auto& operation : sorted_operations) {
|
|
|
|
if (!operation.second.server_side_name().empty()) {
|
|
|
|
cout << " " << operation.first;
|
|
|
|
if (!operation.second.description().empty()) {
|
2021-12-22 08:25:05 +00:00
|
|
|
cout << " (" << operation.second.description() << ")";
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
|
2022-02-18 20:06:33 +00:00
|
|
|
list<PbOperationParameter> sorted_parameters = { operation.second.parameters().begin(), operation.second.parameters().end() };
|
|
|
|
sorted_parameters.sort([](const auto& a, const auto& b) { return a.name() < b.name(); });
|
|
|
|
|
|
|
|
for (const auto& parameter : sorted_parameters) {
|
2021-12-21 07:43:21 +00:00
|
|
|
cout << " " << parameter.name() << ": "
|
|
|
|
<< (parameter.is_mandatory() ? "mandatory" : "optional");
|
|
|
|
if (!parameter.description().empty()) {
|
2021-12-22 08:25:05 +00:00
|
|
|
cout << " (" << parameter.description() << ")";
|
2021-12-21 07:43:21 +00:00
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
if (parameter.permitted_values_size()) {
|
|
|
|
cout << " Permitted values: ";
|
|
|
|
bool isFirst = true;
|
|
|
|
for (const auto& permitted_value : parameter.permitted_values()) {
|
|
|
|
if (!isFirst) {
|
|
|
|
cout << ", ";
|
|
|
|
}
|
|
|
|
isFirst = false;
|
|
|
|
cout << permitted_value;
|
|
|
|
}
|
|
|
|
cout << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parameter.default_value().empty()) {
|
|
|
|
cout << " Default value: " << parameter.default_value() << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
cout << " " << operation.first << " (Unknown server-side operation)" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|