summaryrefslogtreecommitdiffstats
path: root/occ_pass_through.cpp
diff options
context:
space:
mode:
authorVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-04-18 14:25:26 +0530
committerVishwanatha Subbanna <vishwa@linux.vnet.ibm.com>2017-04-26 16:23:05 +0530
commit9bb065b8fe80b329b4321085523dafbeb64b64f9 (patch)
treeb202fff762662b1a4bbf1fa2b29311ce604cb4ce /occ_pass_through.cpp
parent67d50ad6126f278cd76416e32877b3462abc07dd (diff)
downloadopenpower-occ-control-9bb065b8fe80b329b4321085523dafbeb64b64f9.tar.gz
openpower-occ-control-9bb065b8fe80b329b4321085523dafbeb64b64f9.zip
Commit errorlog and exit the application on error scenarios
This application interacts with OCC driver and hence its good to terminate when there is an error during IO since it would mostly mean a faulty hardware. Fixes openbmc/openbmc#1428 Change-Id: I48bc7b2cf19922a7a53dbab78cdd4f2338a7431b Signed-off-by: Vishwanatha Subbanna <vishwa@linux.vnet.ibm.com>
Diffstat (limited to 'occ_pass_through.cpp')
-rw-r--r--occ_pass_through.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/occ_pass_through.cpp b/occ_pass_through.cpp
index 1b3bffa..60dbf6c 100644
--- a/occ_pass_through.cpp
+++ b/occ_pass_through.cpp
@@ -3,8 +3,11 @@
#include <fcntl.h>
#include <errno.h>
#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
+#include <org/open_power/OCC/PassThrough/error.hpp>
#include "occ_pass_through.hpp"
#include "occ_finder.hpp"
+#include "elog-errors.hpp"
namespace open_power
{
namespace occ
@@ -48,15 +51,21 @@ PassThrough::PassThrough(
int PassThrough::openDevice()
{
+ using namespace phosphor::logging;
+ using namespace sdbusplus::org::open_power::OCC::PassThrough::Error;
+
// Device instance number starts from 1.
devicePath.append(std::to_string((this->path.back() - '0') + 1));
int fd = open(devicePath.c_str(), O_RDWR | O_NONBLOCK);
if (fd < 0)
{
- // This is for completion. This is getting replaced by elog
- // in the next commit
- throw std::runtime_error("Error opening " + devicePath);
+ // This would log and terminate since its not handled.
+ elog<OpenFailure>(
+ phosphor::logging::org::open_power::OCC::PassThrough::
+ OpenFailure::CALLOUT_ERRNO(errno),
+ phosphor::logging::org::open_power::OCC::PassThrough::
+ OpenFailure::CALLOUT_DEVICE_PATH(devicePath.c_str()));
}
return fd;
}
@@ -64,6 +73,7 @@ int PassThrough::openDevice()
std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
{
using namespace phosphor::logging;
+ using namespace sdbusplus::org::open_power::OCC::PassThrough::Error;
std::vector<int32_t> response {};
@@ -72,16 +82,17 @@ std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
auto rc = write((fd)(), command.data(), size);
if (rc < 0 || (rc != size))
{
- log<level::ERR>("Error writing to OCC");
-
- // In the next commit, it will have exceptions.
- return response;
+ // This would log and terminate since its not handled.
+ elog<WriteFailure>(
+ phosphor::logging::org::open_power::OCC::PassThrough::
+ WriteFailure::CALLOUT_ERRNO(errno),
+ phosphor::logging::org::open_power::OCC::PassThrough::
+ WriteFailure::CALLOUT_DEVICE_PATH(devicePath.c_str()));
}
// Now read the response. This would be the content of occ-sram
while(1)
{
- errno = 0;
int32_t data {};
auto len = read((fd)(), &data, sizeof(data));
if (len > 0)
@@ -90,7 +101,8 @@ std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
}
else if (len < 0 && errno == EAGAIN)
{
- // We may have data coming still
+ // We may have data coming still.
+ // This driver does not need a sleep for a retry.
continue;
}
else if (len == 0)
@@ -100,16 +112,18 @@ std::vector<int32_t> PassThrough::send(std::vector<int32_t> command)
}
else
{
- // Will have exception in the next commit.
- log<level::ERR>("Error reading from OCC");
- break;
+ // This would log and terminate since its not handled.
+ elog<ReadFailure>(
+ phosphor::logging::org::open_power::OCC::PassThrough::
+ ReadFailure::CALLOUT_ERRNO(errno),
+ phosphor::logging::org::open_power::OCC::PassThrough::
+ ReadFailure::CALLOUT_DEVICE_PATH(devicePath.c_str()));
}
}
return response;
}
-
} // namespace pass_through
} // namespace occ
} // namespace open_power
OpenPOWER on IntegriCloud