Use more specific ipmi error codes
Most errors in the handler were returning an unsupported code and not a
more specific code articulating the failure. Update the code to use
more specific errors.
Change-Id: I7f517d094245e8e1a6169f43582522889bb895d0
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/cable.cpp b/cable.cpp
index ea362b2..69eb8c9 100644
--- a/cable.cpp
+++ b/cable.cpp
@@ -59,7 +59,7 @@
{
std::fprintf(stderr, "Invalid command length: %u\n",
static_cast<uint32_t>(*dataLen));
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
const auto request =
@@ -70,7 +70,7 @@
{
std::fprintf(stderr, "Invalid string length: %d\n",
request->if_name_len);
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
// Verify the request buffer contains the object and the string.
@@ -78,7 +78,7 @@
{
std::fprintf(stderr, "*dataLen too small: %u\n",
static_cast<uint32_t>(*dataLen));
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
// Maximum length one can specify, plus null terminator.
@@ -96,7 +96,7 @@
if (name.find("/") != std::string::npos)
{
std::fprintf(stderr, "Invalid or illegal name: '%s'\n", nameBuf);
- return IPMI_CC_INVALID;
+ return IPMI_CC_INVALID_FIELD_REQUEST;
}
opath << "/sys/class/net/" << name << "/statistics/rx_packets";
@@ -106,7 +106,7 @@
if (!fs::exists(path, ec))
{
std::fprintf(stderr, "Path: '%s' doesn't exist.\n", path.c_str());
- return IPMI_CC_INVALID;
+ return IPMI_CC_INVALID_FIELD_REQUEST;
}
// We're uninterested in the state of ec.
@@ -121,7 +121,7 @@
}
catch (std::ios_base::failure& fail)
{
- return IPMI_CC_INVALID;
+ return IPMI_CC_UNSPECIFIED_ERROR;
}
struct CableReply reply;
diff --git a/cpld.cpp b/cpld.cpp
index 3a65674..ad874b2 100644
--- a/cpld.cpp
+++ b/cpld.cpp
@@ -56,7 +56,7 @@
{
std::fprintf(stderr, "Invalid command length: %u\n",
static_cast<uint32_t>(*dataLen));
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
// reqBuf[0] is the subcommand.
@@ -77,7 +77,7 @@
{
std::fprintf(stderr, "Path: '%s' doesn't exist.\n",
opath.str().c_str());
- return IPMI_CC_INVALID;
+ return IPMI_CC_INVALID_FIELD_REQUEST;
}
// We're uninterested in the state of ec.
@@ -92,7 +92,7 @@
}
catch (std::ios_base::failure& fail)
{
- return IPMI_CC_INVALID;
+ return IPMI_CC_UNSPECIFIED_ERROR;
}
// If value parses as expected, return version.
@@ -106,7 +106,7 @@
if (num_fields == 0)
{
std::fprintf(stderr, "Invalid version.\n");
- return IPMI_CC_INVALID;
+ return IPMI_CC_UNSPECIFIED_ERROR;
}
// Truncate if the version is too high (documented).
diff --git a/eth.cpp b/eth.cpp
index 2689fab..6dbf077 100644
--- a/eth.cpp
+++ b/eth.cpp
@@ -73,20 +73,20 @@
{
std::fprintf(stderr, "Invalid command length: %u\n",
static_cast<uint32_t>(*dataLen));
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
std::string device = NCSI_IF_NAME_STR;
if (device.length() == 0)
{
std::fprintf(stderr, "Invalid eth string\n");
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
if ((sizeof(struct EthDeviceReply) + device.length()) > MAX_IPMI_BUFFER)
{
std::fprintf(stderr, "Response would overflow response buffer\n");
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQUESTED_TOO_MANY_BYTES;
}
// Fill in the response buffer.
diff --git a/main.cpp b/main.cpp
index 46e9feb..eaa82ab 100644
--- a/main.cpp
+++ b/main.cpp
@@ -49,7 +49,7 @@
{
std::fprintf(stderr, "*dataLen too small: %u\n",
static_cast<uint32_t>(*dataLen));
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
switch (reqBuf[0])
diff --git a/psu.cpp b/psu.cpp
index 1e46adc..7f334ef 100644
--- a/psu.cpp
+++ b/psu.cpp
@@ -53,7 +53,7 @@
{
std::fprintf(stderr, "Invalid command length: %u\n",
static_cast<uint32_t>(*dataLen));
- return IPMI_CC_INVALID;
+ return IPMI_CC_REQ_DATA_LEN_INVALID;
}
std::memcpy(&request, &reqBuf[0], sizeof(struct PsuResetRequest));
@@ -63,7 +63,7 @@
if (!ofs.good())
{
std::fprintf(stderr, "Unable to open file for output.\n");
- return IPMI_CC_INVALID;
+ return IPMI_CC_UNSPECIFIED_ERROR;
}
ofs << "PSU_HARDRESET_DELAY=" << request.delay << std::endl;
@@ -71,7 +71,7 @@
{
std::fprintf(stderr, "Write failed\n");
ofs.close();
- return IPMI_CC_INVALID;
+ return IPMI_CC_UNSPECIFIED_ERROR;
}
// Write succeeded, please continue.
@@ -92,7 +92,7 @@
catch (const sdbusplus::exception::SdBusError& ex)
{
log<level::ERR>("Failed to call PSU hard reset");
- return IPMI_CC_INVALID;
+ return IPMI_CC_UNSPECIFIED_ERROR;
}
replyBuf[0] = SysPsuHardReset;