diff options
author | Patrick Venture <venture@google.com> | 2018-08-31 11:55:55 -0700 |
---|---|---|
committer | Patrick Venture <venture@google.com> | 2018-09-07 23:45:41 +0000 |
commit | 0b02be925a29357f69abbc9e9a58e7c5aaed2eab (patch) | |
tree | c1b39f817d98ffda7b987f9e3f864f576e3bf9ea /storageaddsel.cpp | |
parent | 26f80ab2cc41deadc913190d906f71266c4ed224 (diff) | |
download | phosphor-host-ipmid-0b02be925a29357f69abbc9e9a58e7c5aaed2eab.tar.gz phosphor-host-ipmid-0b02be925a29357f69abbc9e9a58e7c5aaed2eab.zip |
add .clang-format
Change-Id: I7c2a527b4751a560703a61fcbe9638b150546af5
Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'storageaddsel.cpp')
-rw-r--r-- | storageaddsel.cpp | 176 |
1 files changed, 93 insertions, 83 deletions
diff --git a/storageaddsel.cpp b/storageaddsel.cpp index ec33b1a..95fcddf 100644 --- a/storageaddsel.cpp +++ b/storageaddsel.cpp @@ -1,22 +1,24 @@ +#include "elog-errors.hpp" +#include "error-HostEvent.hpp" +#include "types.hpp" + +#include <mapper.h> #include <stdint.h> +#include <systemd/sd-bus.h> + +#include <algorithm> #include <cstdlib> #include <cstring> #include <fstream> #include <iostream> -#include <algorithm> -#include <vector> #include <memory> -#include <systemd/sd-bus.h> -#include <mapper.h> #include <phosphor-logging/elog.hpp> +#include <vector> +#include <xyz/openbmc_project/Logging/Entry/server.hpp> + #include "host-ipmid/ipmid-api.h" -#include "elog-errors.hpp" -#include "error-HostEvent.hpp" #include "sensorhandler.h" #include "storagehandler.h" -#include "types.hpp" -#include "xyz/openbmc_project/Logging/Entry/server.hpp" - using namespace std; using namespace phosphor::logging; @@ -24,7 +26,8 @@ using namespace sdbusplus::xyz::openbmc_project::Logging::server; extern const ipmi::sensor::InvObjectIDMap invSensors; ////////////////////////// -struct esel_section_headers_t { +struct esel_section_headers_t +{ uint8_t sectionid[2]; uint8_t sectionlength[2]; uint8_t version; @@ -32,118 +35,128 @@ struct esel_section_headers_t { uint8_t compid; }; -struct severity_values_t { +struct severity_values_t +{ uint8_t type; Entry::Level level; }; - const std::vector<severity_values_t> g_sev_desc = { {0x10, Entry::Level::Warning}, // recoverable error {0x20, Entry::Level::Warning}, // predictive error - // TODO via github issue 3066 : map level below to Level::Unrecoverable - {0x40, Entry::Level::Error}, // unrecoverable error - // TODO via github issue 3066 : map level below to Level::Critical - {0x50, Entry::Level::Error}, // critical error - {0x60, Entry::Level::Error}, // error from a diagnostic test + // TODO via github issue 3066 : map level + // below to Level::Unrecoverable + {0x40, Entry::Level::Error}, // unrecoverable error + // TODO via github issue 3066 : map level below + // to Level::Critical + {0x50, Entry::Level::Error}, // critical error + {0x60, Entry::Level::Error}, // error from a diagnostic test {0x70, Entry::Level::Warning}, // recoverable symptom - {0xFF, Entry::Level::Error}, //unknown error + {0xFF, Entry::Level::Error}, // unknown error }; -Entry::Level sev_lookup(uint8_t n) { - auto i = std::find_if(std::begin(g_sev_desc), std::end(g_sev_desc), - [n](auto p){ return p.type == n || p.type == 0xFF; }); +Entry::Level sev_lookup(uint8_t n) +{ + auto i = + std::find_if(std::begin(g_sev_desc), std::end(g_sev_desc), + [n](auto p) { return p.type == n || p.type == 0xFF; }); return i->level; } - - - -int find_sensor_type_string(uint8_t sensor_number, char **s) { +int find_sensor_type_string(uint8_t sensor_number, char** s) +{ dbus_interface_t a; - const char *p; + const char* p; int r; r = find_openbmc_path(sensor_number, &a); - if ((r < 0) || (a.bus[0] == 0)) { + if ((r < 0) || (a.bus[0] == 0)) + { // Just make a generic message for errors that // occur on sensors that don't exist r = asprintf(s, "Unknown Sensor (0x%02x)", sensor_number); - } else { + } + else + { - if ((p = strrchr (a.path, '/')) == NULL) { + if ((p = strrchr(a.path, '/')) == NULL) + { p = "/Unknown Sensor"; } - *s = strdup(p+1); + *s = strdup(p + 1); } return 0; } +size_t getfilestream(const char* fn, uint8_t** buffer) +{ -size_t getfilestream(const char *fn, uint8_t **buffer) { - - FILE *fp; + FILE* fp; ssize_t size = 0; int r; - if ((fp = fopen(fn, "rb")) != NULL) { + if ((fp = fopen(fn, "rb")) != NULL) + { r = fseek(fp, 0, SEEK_END); - if (r) { + if (r) + { log<level::ERR>("Fseek failed"); goto fclose_fp; } size = ftell(fp); - if (size == -1L) { - log<level::ERR>("Ftell failed", - entry("ERROR=%s", strerror(errno))); + if (size == -1L) + { + log<level::ERR>("Ftell failed", entry("ERROR=%s", strerror(errno))); size = 0; goto fclose_fp; } r = fseek(fp, 0, SEEK_SET); - if (r) { + if (r) + { log<level::ERR>("Fseek failed"); size = 0; goto fclose_fp; } - *buffer = new uint8_t [size]; + *buffer = new uint8_t[size]; r = fread(*buffer, 1, size, fp); - if ( r != size) { + if (r != size) + { size = 0; log<level::ERR>("Fread failed\n"); } -fclose_fp: + fclose_fp: fclose(fp); } return static_cast<size_t>(size); } - -Entry::Level create_esel_severity(const uint8_t *buffer) { +Entry::Level create_esel_severity(const uint8_t* buffer) +{ uint8_t severity; // Dive in to the IBM log to find the severity - severity = (0xF0 & buffer[0x4A]); + severity = (0xF0 & buffer[0x4A]); return sev_lookup(severity); } -int create_esel_association(const uint8_t *buffer, std::string& inventoryPath) +int create_esel_association(const uint8_t* buffer, std::string& inventoryPath) { - ipmi_add_sel_request_t *p; + ipmi_add_sel_request_t* p; uint8_t sensor; - p = ( ipmi_add_sel_request_t *) buffer; + p = (ipmi_add_sel_request_t*)buffer; sensor = p->sensornumber; @@ -153,7 +166,7 @@ int create_esel_association(const uint8_t *buffer, std::string& inventoryPath) * Search the sensor number to inventory path mapping to figure out the * inventory associated with the ESEL. */ - for (auto const &iter : invSensors) + for (auto const& iter : invSensors) { if (iter.second.sensorID == sensor) { @@ -165,23 +178,22 @@ int create_esel_association(const uint8_t *buffer, std::string& inventoryPath) return 0; } +int create_esel_description(const uint8_t* buffer, Entry::Level level, + char** message) +{ - -int create_esel_description(const uint8_t *buffer, Entry::Level level, - char **message) { - - - ipmi_add_sel_request_t *p; - char *m; + ipmi_add_sel_request_t* p; + char* m; int r; - p = ( ipmi_add_sel_request_t *) buffer; + p = (ipmi_add_sel_request_t*)buffer; - find_sensor_type_string(p->sensornumber,&m); + find_sensor_type_string(p->sensornumber, &m); - r = asprintf(message, "A %s has experienced an error of level %d", - m, static_cast<uint32_t>(level) ); - if (r == -1) { + r = asprintf(message, "A %s has experienced an error of level %d", m, + static_cast<uint32_t>(level)); + if (r == -1) + { log<level::ERR>("Failed to allocate memory for ESEL description"); } @@ -190,45 +202,42 @@ int create_esel_description(const uint8_t *buffer, Entry::Level level, return 0; } - -int send_esel_to_dbus(const char *desc, - Entry::Level level, - const std::string& inventoryPath, - uint8_t *debug, +int send_esel_to_dbus(const char* desc, Entry::Level level, + const std::string& inventoryPath, uint8_t* debug, size_t debuglen) { // Allocate enough space to represent the data in hex separated by spaces, // to mimic how IPMI would display the data. - unique_ptr<char[]> selData(new char[(debuglen*3) + 1]()); + unique_ptr<char[]> selData(new char[(debuglen * 3) + 1]()); uint32_t i = 0; - for(i = 0; i < debuglen; i++) + for (i = 0; i < debuglen; i++) { - sprintf(&selData[i*3], "%02x ", 0xFF & ((char*)debug)[i]); + sprintf(&selData[i * 3], "%02x ", 0xFF & ((char*)debug)[i]); } - selData[debuglen*3] = '\0'; + selData[debuglen * 3] = '\0'; - using error = sdbusplus::org::open_power::Host::Error::Event; + using error = sdbusplus::org::open_power::Host::Error::Event; using metadata = org::open_power::Host::Event; - report<error>(level, - metadata::ESEL(selData.get()), + report<error>(level, metadata::ESEL(selData.get()), metadata::CALLOUT_INVENTORY_PATH(inventoryPath.c_str())); return 0; } - -void send_esel(uint16_t recordid) { - char *desc; - uint8_t *buffer = NULL; - const char *path = "/tmp/esel"; +void send_esel(uint16_t recordid) +{ + char* desc; + uint8_t* buffer = NULL; + const char* path = "/tmp/esel"; ssize_t sz; int r; std::string inventoryPath; sz = getfilestream(path, &buffer); - if (sz == 0) { + if (sz == 0) + { log<level::ERR>("Error file does not exist", entry("FILENAME=%s", path)); return; @@ -239,7 +248,8 @@ void send_esel(uint16_t recordid) { create_esel_description(buffer, sev, &desc); r = send_esel_to_dbus(desc, sev, inventoryPath, buffer, sz); - if (r < 0) { + if (r < 0) + { log<level::ERR>("Failed to send esel to dbus"); } @@ -278,8 +288,8 @@ void createProcedureLogEntry(uint8_t procedureNum) // Each byte in eSEL is formatted as %02x with a space between bytes and // insert '/0' at the end of the character array. static constexpr auto byteSeparator = 3; - std::unique_ptr<char[]> data(new char[ - (eSELData.size() * byteSeparator) + 1]()); + std::unique_ptr<char[]> data( + new char[(eSELData.size() * byteSeparator) + 1]()); for (size_t i = 0; i < eSELData.size(); i++) { @@ -287,7 +297,7 @@ void createProcedureLogEntry(uint8_t procedureNum) } data[eSELData.size() * byteSeparator] = '\0'; - using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure; + using error = sdbusplus::org::open_power::Host::Error::MaintenanceProcedure; using metadata = org::open_power::Host::MaintenanceProcedure; report<error>(metadata::ESEL(data.get()), |