summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>2017-04-26 07:13:35 -0500
committerDhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>2017-05-15 01:28:19 -0500
commit18b0786a93964c2f30ada2e5405b103d4d3b82e5 (patch)
tree90ec5a75eddea54c00c350532f8333015a8bf112
parent2de0cfa71ec1c2a3717ea607f8b16fcc63b237c3 (diff)
downloadopenpower-proc-control-18b0786a93964c2f30ada2e5405b103d4d3b82e5.tar.gz
openpower-proc-control-18b0786a93964c2f30ada2e5405b103d4d3b82e5.zip
Replace error strings with logging errors in device operations
Change-Id: I0fc1c23e51a0233c18775ee712132dba7e4c7d7e Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
-rw-r--r--cfam_access.cpp47
-rw-r--r--filedescriptor.cpp12
-rw-r--r--proc_control.cpp23
-rw-r--r--targeting.cpp39
4 files changed, 75 insertions, 46 deletions
diff --git a/cfam_access.cpp b/cfam_access.cpp
index 83afdc7..d1d5c8f 100644
--- a/cfam_access.cpp
+++ b/cfam_access.cpp
@@ -16,6 +16,8 @@
#include <unistd.h>
#include "cfam_access.hpp"
#include "targeting.hpp"
+#include <phosphor-logging/elog.hpp>
+#include "elog-errors.hpp"
namespace openpower
{
@@ -44,15 +46,15 @@ void writeReg(const std::unique_ptr<Target>& target,
cfam_address_t address,
cfam_data_t data)
{
+ using namespace phosphor::logging;
int rc = lseek(target->getCFAMFD(), makeOffset(address), SEEK_SET);
if (rc < 0)
{
- //Future: use a different exception to create an error log
- char msg[100];
- sprintf(msg, "writeCFAMReg: Failed seek for address 0x%X, "
- "processor %d. errno = %d",
- address, static_cast<int>(target->getPos()), errno);
- throw std::runtime_error(msg);
+ elog<org::open_power::Proc::CFAM::SeekFailure>(
+ org::open_power::Proc::CFAM::SeekFailure::ERRNO(errno),
+ org::open_power::Proc::CFAM::SeekFailure::ADDRESS(address),
+ org::open_power::Proc::CFAM::SeekFailure::OFFSET(makeOffset(address)),
+ org::open_power::Proc::CFAM::SeekFailure::PATH(target->getCFAMPath().c_str()));
}
data = target->swapEndian(data);
@@ -60,12 +62,10 @@ void writeReg(const std::unique_ptr<Target>& target,
rc = write(target->getCFAMFD(), &data, cfamRegSize);
if (rc < 0)
{
- //Future: use a different exception to create an error log
- char msg[100];
- sprintf(msg, "writeCFAMReg: Failed write to address 0x%X, "
- "processor %d. errno = %d",
- address, static_cast<int>(target->getPos()), errno);
- throw std::runtime_error(msg);
+ elog<org::open_power::Proc::CFAM::WriteFailure>(
+ org::open_power::Proc::CFAM::WriteFailure::CALLOUT_ERRNO(errno),
+ org::open_power::Proc::CFAM::WriteFailure::CALLOUT_DEVICE_PATH(
+ target->getCFAMPath().c_str()));
}
}
@@ -73,28 +73,27 @@ void writeReg(const std::unique_ptr<Target>& target,
cfam_data_t readReg(const std::unique_ptr<Target>& target,
cfam_address_t address)
{
+ using namespace phosphor::logging;
+
cfam_data_t data = 0;
int rc = lseek(target->getCFAMFD(), makeOffset(address), SEEK_SET);
if (rc < 0)
{
- //Future: use a different exception to create an error log
- char msg[100];
- sprintf(msg, "readCFAMReg: Failed seek for address 0x%X, "
- "processor %d. errno = %d",
- address, static_cast<int>(target->getPos()), errno);
- throw std::runtime_error(msg);
+ elog<org::open_power::Proc::CFAM::SeekFailure>(
+ org::open_power::Proc::CFAM::SeekFailure::ERRNO(errno),
+ org::open_power::Proc::CFAM::SeekFailure::ADDRESS(address),
+ org::open_power::Proc::CFAM::SeekFailure::OFFSET(makeOffset(address)),
+ org::open_power::Proc::CFAM::SeekFailure::PATH(target->getCFAMPath().c_str()));
}
rc = read(target->getCFAMFD(), &data, cfamRegSize);
if (rc < 0)
{
- //Future: use a different exception to create an error log
- char msg[100];
- sprintf(msg, "readCFAMReg: Failed read for address 0x%X, "
- "processor %d. errno = %d",
- address, static_cast<int>(target->getPos()), errno);
- throw std::runtime_error(msg);
+ elog<org::open_power::Proc::CFAM::ReadFailure>(
+ org::open_power::Proc::CFAM::WriteFailure::CALLOUT_ERRNO(errno),
+ org::open_power::Proc::CFAM::WriteFailure::CALLOUT_DEVICE_PATH(
+ target->getCFAMPath().c_str()));
}
return target->swapEndian(data);
diff --git a/filedescriptor.cpp b/filedescriptor.cpp
index c8bcab0..9354d6e 100644
--- a/filedescriptor.cpp
+++ b/filedescriptor.cpp
@@ -16,6 +16,8 @@
#include <stdexcept>
#include <unistd.h>
#include "filedescriptor.hpp"
+#include <phosphor-logging/elog.hpp>
+#include "elog-errors.hpp"
namespace openpower
{
@@ -24,15 +26,15 @@ namespace util
FileDescriptor::FileDescriptor(const std::string& path)
{
+ using namespace phosphor::logging;
+
fd = open(path.c_str(), O_RDWR | O_SYNC);
if (fd < 0)
{
- //Future: use a different exception to create an error log
- char msg[200];
- sprintf(msg, "Failed to open FSI device path %s. errno = %d",
- path.c_str(), errno);
- throw std::runtime_error(msg);
+ elog<org::open_power::Proc::CFAM::OpenFailure>(
+ org::open_power::Proc::CFAM::OpenFailure::ERRNO(errno),
+ org::open_power::Proc::CFAM::OpenFailure::PATH(path.c_str()));
}
}
diff --git a/proc_control.cpp b/proc_control.cpp
index 10c3ffa..a86b354 100644
--- a/proc_control.cpp
+++ b/proc_control.cpp
@@ -17,7 +17,9 @@
#include <functional>
#include <iostream>
#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/elog.hpp>
#include "registration.hpp"
+#include "elog-errors.hpp"
using namespace openpower::util;
@@ -34,6 +36,7 @@ void usage(char** argv, const ProcedureMap& procedures)
int main(int argc, char** argv)
{
+ using namespace phosphor::logging;
const ProcedureMap& procedures = Registration::getProcedures();
if (argc != 2)
@@ -56,10 +59,24 @@ int main(int argc, char** argv)
{
procedure->second();
}
- catch (std::exception& e)
+ catch (org::open_power::Proc::CFAM::SeekFailure& e)
{
- //TODO: commit an actual error that does a callout
- phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+ commit<org::open_power::Proc::CFAM::SeekFailure>();
+ return -1;
+ }
+ catch (org::open_power::Proc::CFAM::OpenFailure& e)
+ {
+ commit<org::open_power::Proc::CFAM::OpenFailure>();
+ return -1;
+ }
+ catch (org::open_power::Proc::CFAM::WriteFailure& e)
+ {
+ commit<org::open_power::Proc::CFAM::WriteFailure>();
+ return -1;
+ }
+ catch (org::open_power::Proc::CFAM::ReadFailure& e)
+ {
+ commit<org::open_power::Proc::CFAM::ReadFailure>();
return -1;
}
diff --git a/targeting.cpp b/targeting.cpp
index 1237025..ce3fc67 100644
--- a/targeting.cpp
+++ b/targeting.cpp
@@ -18,8 +18,11 @@
#include <experimental/filesystem>
#include <phosphor-logging/log.hpp>
#include <regex>
+#include <phosphor-logging/elog.hpp>
+#include "elog-errors.hpp"
#include "targeting.hpp"
+
namespace openpower
{
namespace targeting
@@ -91,27 +94,35 @@ Targeting::Targeting(const std::string& fsiMasterDev,
//Always create P0, the FSI master.
targets.push_back(std::make_unique<Target>(0, fsiMasterPath, swapper));
-
- //Find the the remaining P9s dynamically based on which files show up
- for (auto& file : fs::directory_iterator(fsiSlaveBasePath))
+ try
{
- std::smatch match;
- std::string path = file.path();
- if (std::regex_search(path, match, exp))
+ //Find the the remaining P9s dynamically based on which files show up
+ for (auto& file : fs::directory_iterator(fsiSlaveBasePath))
{
- auto pos = atoi(match[1].str().c_str());
- if (pos == 0)
+ std::smatch match;
+ std::string path = file.path();
+ if (std::regex_search(path, match, exp))
{
- log<level::ERR>("Unexpected FSI slave device name found",
- entry("DEVICE_NAME=%s", path.c_str()));
- continue;
- }
+ auto pos = atoi(match[1].str().c_str());
+ if (pos == 0)
+ {
+ log<level::ERR>("Unexpected FSI slave device name found",
+ entry("DEVICE_NAME=%s", path.c_str()));
+ continue;
+ }
- path += "/raw";
+ path += "/raw";
- targets.push_back(std::make_unique<Target>(pos, path, swapper));
+ targets.push_back(std::make_unique<Target>(pos, path, swapper));
+ }
}
}
+ catch (fs::filesystem_error& e)
+ {
+ elog<org::open_power::Proc::CFAM::OpenFailure>(
+ org::open_power::Proc::CFAM::OpenFailure::ERRNO(e.code().value()),
+ org::open_power::Proc::CFAM::OpenFailure::PATH(e.path1().c_str()));
+ }
auto sortTargets = [](const std::unique_ptr<Target>& left,
const std::unique_ptr<Target>& right)
OpenPOWER on IntegriCloud