Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM Corporation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 16 | #include "manager.hpp" |
| 17 | |
| 18 | #include "additional_data.hpp" |
Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 19 | #include "json_utils.hpp" |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 20 | #include "pel.hpp" |
Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 21 | #include "pel_entry.hpp" |
Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 22 | #include "service_indicators.hpp" |
Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 23 | #include "severity.hpp" |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 24 | |
Matt Spinler | 22421b9 | 2020-07-17 09:41:08 -0500 | [diff] [blame] | 25 | #include <fmt/format.h> |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 26 | #include <sys/inotify.h> |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 27 | #include <unistd.h> |
| 28 | |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 29 | #include <filesystem> |
| 30 | #include <fstream> |
Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 31 | #include <locale> |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 32 | #include <xyz/openbmc_project/Common/error.hpp> |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 33 | #include <xyz/openbmc_project/Logging/Create/server.hpp> |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 34 | |
| 35 | namespace openpower |
| 36 | { |
| 37 | namespace pels |
| 38 | { |
| 39 | |
| 40 | using namespace phosphor::logging; |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 41 | namespace fs = std::filesystem; |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 42 | namespace rg = openpower::pels::message; |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 43 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 44 | namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error; |
| 45 | |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 46 | using Create = sdbusplus::xyz::openbmc_project::Logging::server::Create; |
| 47 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 48 | namespace additional_data |
| 49 | { |
| 50 | constexpr auto rawPEL = "RAWPEL"; |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 51 | constexpr auto esel = "ESEL"; |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 52 | constexpr auto error = "ERROR_NAME"; |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 53 | } // namespace additional_data |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 54 | |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 55 | constexpr auto defaultLogMessage = "xyz.openbmc_project.Logging.Error.Default"; |
| 56 | |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 57 | Manager::~Manager() |
| 58 | { |
| 59 | if (_pelFileDeleteFD != -1) |
| 60 | { |
| 61 | if (_pelFileDeleteWatchFD != -1) |
| 62 | { |
| 63 | inotify_rm_watch(_pelFileDeleteFD, _pelFileDeleteWatchFD); |
| 64 | } |
| 65 | close(_pelFileDeleteFD); |
| 66 | } |
| 67 | } |
| 68 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 69 | void Manager::create(const std::string& message, uint32_t obmcLogID, |
| 70 | uint64_t timestamp, Entry::Level severity, |
| 71 | const std::vector<std::string>& additionalData, |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 72 | const std::vector<std::string>& associations, |
| 73 | const FFDCEntries& ffdc) |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 74 | { |
| 75 | AdditionalData ad{additionalData}; |
| 76 | |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 77 | // If a PEL was passed in via a filename or in an ESEL, |
| 78 | // use that. Otherwise, create one. |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 79 | auto rawPelPath = ad.getValue(additional_data::rawPEL); |
| 80 | if (rawPelPath) |
| 81 | { |
| 82 | addRawPEL(*rawPelPath, obmcLogID); |
| 83 | } |
| 84 | else |
| 85 | { |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 86 | auto esel = ad.getValue(additional_data::esel); |
| 87 | if (esel) |
| 88 | { |
| 89 | addESELPEL(*esel, obmcLogID); |
| 90 | } |
| 91 | else |
| 92 | { |
| 93 | createPEL(message, obmcLogID, timestamp, severity, additionalData, |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 94 | associations, ffdc); |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 95 | } |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 96 | } |
Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 97 | |
| 98 | setEntryPath(obmcLogID); |
Vijay Lobo | cbc93a4 | 2021-05-20 19:04:07 -0500 | [diff] [blame] | 99 | setServiceProviderNotifyFlag(obmcLogID); |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void Manager::addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID) |
| 103 | { |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 104 | if (fs::exists(rawPelPath)) |
| 105 | { |
| 106 | std::ifstream file(rawPelPath, std::ios::in | std::ios::binary); |
| 107 | |
| 108 | auto data = std::vector<uint8_t>(std::istreambuf_iterator<char>(file), |
| 109 | std::istreambuf_iterator<char>()); |
| 110 | if (file.fail()) |
| 111 | { |
| 112 | log<level::ERR>("Filesystem error reading a raw PEL", |
| 113 | entry("PELFILE=%s", rawPelPath.c_str()), |
| 114 | entry("OBMCLOGID=%d", obmcLogID)); |
| 115 | // TODO, Decide what to do here. Maybe nothing. |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | file.close(); |
| 120 | |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 121 | addPEL(data, obmcLogID); |
Matt Spinler | 6741692 | 2021-07-19 12:34:57 -0600 | [diff] [blame] | 122 | |
| 123 | std::error_code ec; |
| 124 | fs::remove(rawPelPath, ec); |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 125 | } |
| 126 | else |
| 127 | { |
| 128 | log<level::ERR>("Raw PEL file from BMC event log does not exist", |
| 129 | entry("PELFILE=%s", (rawPelPath).c_str()), |
| 130 | entry("OBMCLOGID=%d", obmcLogID)); |
| 131 | } |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 132 | } |
| 133 | |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 134 | void Manager::addPEL(std::vector<uint8_t>& pelData, uint32_t obmcLogID) |
| 135 | { |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 136 | auto pel = std::make_unique<openpower::pels::PEL>(pelData, obmcLogID); |
| 137 | if (pel->valid()) |
| 138 | { |
Sumit Kumar | 8ec4156 | 2021-10-29 05:39:37 -0500 | [diff] [blame] | 139 | // PELs created by others still need this field set by us. |
| 140 | pel->setCommitTime(); |
| 141 | |
Sumit Kumar | a1e4084 | 2021-06-23 09:52:25 -0500 | [diff] [blame] | 142 | // Assign Id other than to Hostbot PEL |
| 143 | if ((pel->privateHeader()).creatorID() != |
| 144 | static_cast<uint8_t>(CreatorID::hostboot)) |
| 145 | { |
| 146 | pel->assignID(); |
| 147 | } |
Sumit Kumar | 2ccdcef | 2021-07-31 10:04:58 -0500 | [diff] [blame] | 148 | else |
| 149 | { |
| 150 | const Repository::LogID id{Repository::LogID::Pel(pel->id())}; |
| 151 | auto result = _repo.hasPEL(id); |
| 152 | if (result) |
| 153 | { |
| 154 | log<level::WARNING>( |
| 155 | fmt::format("Duplicate HostBoot PEL Id {:#X} found; " |
| 156 | "moving it to archive folder", |
| 157 | pel->id()) |
| 158 | .c_str()); |
| 159 | |
| 160 | _repo.archivePEL(*pel); |
Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 161 | |
| 162 | // No need to keep around the openBMC event log entry |
| 163 | scheduleObmcLogDelete(obmcLogID); |
Sumit Kumar | 2ccdcef | 2021-07-31 10:04:58 -0500 | [diff] [blame] | 164 | return; |
| 165 | } |
| 166 | } |
Sumit Kumar | a1e4084 | 2021-06-23 09:52:25 -0500 | [diff] [blame] | 167 | |
Sumit Kumar | 3160a54 | 2021-04-26 08:07:04 -0500 | [diff] [blame] | 168 | // Update System Info to Extended User Data |
| 169 | pel->updateSysInfoInExtendedUserDataSection(*_dataIface); |
| 170 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 171 | // Check for severity 0x51 and update boot progress SRC |
| 172 | updateProgressSRC(pel); |
| 173 | |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 174 | try |
| 175 | { |
Matt Spinler | d0ab1cf | 2021-02-10 13:26:18 -0600 | [diff] [blame] | 176 | log<level::DEBUG>( |
Matt Spinler | 6321ba3 | 2020-07-17 09:58:19 -0500 | [diff] [blame] | 177 | fmt::format("Adding external PEL {:#x} (BMC ID {}) to repo", |
| 178 | pel->id(), obmcLogID) |
| 179 | .c_str()); |
Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 180 | |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 181 | _repo.add(pel); |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 182 | |
| 183 | if (_repo.sizeWarning()) |
| 184 | { |
| 185 | scheduleRepoPrune(); |
| 186 | } |
Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 187 | |
| 188 | // Activate any resulting service indicators if necessary |
| 189 | auto policy = service_indicators::getPolicy(*_dataIface); |
| 190 | policy->activate(*pel); |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 191 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 192 | catch (const std::exception& e) |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 193 | { |
| 194 | // Probably a full or r/o filesystem, not much we can do. |
| 195 | log<level::ERR>("Unable to add PEL to Repository", |
| 196 | entry("PEL_ID=0x%X", pel->id())); |
| 197 | } |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 198 | |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 199 | updateEventId(pel); |
Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 200 | updateResolution(*pel); |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 201 | createPELEntry(obmcLogID); |
Matt Spinler | df5cb83 | 2022-07-12 12:47:26 -0500 | [diff] [blame] | 202 | |
| 203 | // Check if firmware should quiesce system due to error |
| 204 | checkPelAndQuiesce(pel); |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 205 | } |
| 206 | else |
| 207 | { |
| 208 | log<level::ERR>("Invalid PEL received from the host", |
| 209 | entry("OBMCLOGID=%d", obmcLogID)); |
| 210 | |
| 211 | AdditionalData ad; |
| 212 | ad.add("PLID", getNumberString("0x%08X", pel->plid())); |
| 213 | ad.add("OBMC_LOG_ID", std::to_string(obmcLogID)); |
| 214 | ad.add("PEL_SIZE", std::to_string(pelData.size())); |
| 215 | |
| 216 | std::string asciiString; |
| 217 | auto src = pel->primarySRC(); |
| 218 | if (src) |
| 219 | { |
| 220 | asciiString = (*src)->asciiString(); |
| 221 | } |
| 222 | |
| 223 | ad.add("SRC", asciiString); |
| 224 | |
| 225 | _eventLogger.log("org.open_power.Logging.Error.BadHostPEL", |
| 226 | Entry::Level::Error, ad); |
Matt Spinler | fe72189 | 2020-04-02 10:28:08 -0500 | [diff] [blame] | 227 | |
| 228 | // Save it to a file for debug in the lab. Just keep the latest. |
| 229 | // Not adding it to the PEL because it could already be max size |
| 230 | // and don't want to truncate an already invalid PEL. |
| 231 | std::ofstream pelFile{getPELRepoPath() / "badPEL"}; |
| 232 | pelFile.write(reinterpret_cast<const char*>(pelData.data()), |
| 233 | pelData.size()); |
Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 234 | |
| 235 | // No need to keep around the openBMC event log entry |
| 236 | scheduleObmcLogDelete(obmcLogID); |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 237 | } |
| 238 | } |
| 239 | |
| 240 | void Manager::addESELPEL(const std::string& esel, uint32_t obmcLogID) |
| 241 | { |
| 242 | std::vector<uint8_t> data; |
| 243 | |
Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 244 | log<level::DEBUG>("Adding PEL from ESEL", |
| 245 | entry("OBMC_LOG_ID=%d", obmcLogID)); |
| 246 | |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 247 | try |
| 248 | { |
| 249 | data = std::move(eselToRawData(esel)); |
| 250 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 251 | catch (const std::exception& e) |
Matt Spinler | 19e7290 | 2020-01-24 11:05:20 -0600 | [diff] [blame] | 252 | { |
| 253 | // Try to add it below anyway, so it follows the usual bad data path. |
| 254 | log<level::ERR>("Problems converting ESEL string to a byte vector"); |
| 255 | } |
| 256 | |
| 257 | addPEL(data, obmcLogID); |
| 258 | } |
| 259 | |
| 260 | std::vector<uint8_t> Manager::eselToRawData(const std::string& esel) |
| 261 | { |
| 262 | std::vector<uint8_t> data; |
| 263 | std::string byteString; |
| 264 | |
| 265 | // As the eSEL string looks like: "50 48 00 ab ..." there are 3 |
| 266 | // characters per raw byte, and since the actual PEL data starts |
| 267 | // at the 16th byte, the code will grab the PEL data starting at |
| 268 | // offset 48 in the string. |
| 269 | static constexpr size_t pelStart = 16 * 3; |
| 270 | |
| 271 | if (esel.size() <= pelStart) |
| 272 | { |
| 273 | log<level::ERR>("ESEL data too short", |
| 274 | entry("ESEL_SIZE=%d", esel.size())); |
| 275 | |
| 276 | throw std::length_error("ESEL data too short"); |
| 277 | } |
| 278 | |
| 279 | for (size_t i = pelStart; i < esel.size(); i += 3) |
| 280 | { |
| 281 | if (i + 1 < esel.size()) |
| 282 | { |
| 283 | byteString = esel.substr(i, 2); |
| 284 | data.push_back(std::stoi(byteString, nullptr, 16)); |
| 285 | } |
| 286 | else |
| 287 | { |
| 288 | log<level::ERR>("ESEL data too short", |
| 289 | entry("ESEL_SIZE=%d", esel.size())); |
| 290 | throw std::length_error("ESEL data too short"); |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | return data; |
| 295 | } |
| 296 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 297 | void Manager::erase(uint32_t obmcLogID) |
| 298 | { |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 299 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 300 | |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 301 | auto path = std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID); |
| 302 | _pelEntries.erase(path); |
Matt Spinler | 475e574 | 2019-07-18 16:09:49 -0500 | [diff] [blame] | 303 | _repo.remove(id); |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 304 | } |
| 305 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 306 | bool Manager::isDeleteProhibited(uint32_t /*obmcLogID*/) |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 307 | { |
| 308 | return false; |
| 309 | } |
| 310 | |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 311 | PelFFDC Manager::convertToPelFFDC(const FFDCEntries& ffdc) |
| 312 | { |
| 313 | PelFFDC pelFFDC; |
| 314 | |
| 315 | std::for_each(ffdc.begin(), ffdc.end(), [&pelFFDC](const auto& f) { |
| 316 | PelFFDCfile pf; |
| 317 | pf.subType = std::get<ffdcSubtypePos>(f); |
| 318 | pf.version = std::get<ffdcVersionPos>(f); |
| 319 | pf.fd = std::get<ffdcFDPos>(f); |
| 320 | |
| 321 | switch (std::get<ffdcFormatPos>(f)) |
| 322 | { |
| 323 | case Create::FFDCFormat::JSON: |
| 324 | pf.format = UserDataFormat::json; |
| 325 | break; |
| 326 | case Create::FFDCFormat::CBOR: |
| 327 | pf.format = UserDataFormat::cbor; |
| 328 | break; |
| 329 | case Create::FFDCFormat::Text: |
| 330 | pf.format = UserDataFormat::text; |
| 331 | break; |
| 332 | case Create::FFDCFormat::Custom: |
| 333 | pf.format = UserDataFormat::custom; |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | pelFFDC.push_back(pf); |
| 338 | }); |
| 339 | |
| 340 | return pelFFDC; |
| 341 | } |
| 342 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 343 | void Manager::createPEL(const std::string& message, uint32_t obmcLogID, |
| 344 | uint64_t timestamp, |
| 345 | phosphor::logging::Entry::Level severity, |
| 346 | const std::vector<std::string>& additionalData, |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 347 | const std::vector<std::string>& /*associations*/, |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 348 | const FFDCEntries& ffdc) |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 349 | { |
Harisuddin Mohamed Isa | 0f717e1 | 2020-01-15 20:05:33 +0800 | [diff] [blame] | 350 | auto entry = _registry.lookup(message, rg::LookupType::name); |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 351 | auto pelFFDC = convertToPelFFDC(ffdc); |
| 352 | AdditionalData ad{additionalData}; |
Matt Spinler | 1d4c74a | 2019-12-16 14:40:21 -0600 | [diff] [blame] | 353 | std::string msg; |
Matt Spinler | 67456c2 | 2019-10-21 12:22:49 -0500 | [diff] [blame] | 354 | |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 355 | if (!entry) |
Matt Spinler | 67456c2 | 2019-10-21 12:22:49 -0500 | [diff] [blame] | 356 | { |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 357 | // Instead, get the default entry that means there is no |
| 358 | // other matching entry. This error will still use the |
| 359 | // AdditionalData values of the original error, and this |
| 360 | // code will add the error message value that wasn't found |
| 361 | // to this AD. This way, there will at least be a PEL, |
| 362 | // possibly with callouts, to allow users to debug the |
| 363 | // issue that caused the error even without its own PEL. |
Matt Spinler | 1d4c74a | 2019-12-16 14:40:21 -0600 | [diff] [blame] | 364 | msg = "Event not found in PEL message registry: " + message; |
| 365 | log<level::INFO>(msg.c_str()); |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 366 | |
| 367 | entry = _registry.lookup(defaultLogMessage, rg::LookupType::name); |
| 368 | if (!entry) |
| 369 | { |
| 370 | log<level::ERR>("Default event not found in PEL message registry"); |
| 371 | return; |
| 372 | } |
| 373 | |
| 374 | ad.add(additional_data::error, message); |
| 375 | } |
| 376 | |
| 377 | auto pel = std::make_unique<openpower::pels::PEL>( |
| 378 | *entry, obmcLogID, timestamp, severity, ad, pelFFDC, *_dataIface); |
| 379 | |
| 380 | _repo.add(pel); |
| 381 | |
| 382 | if (_repo.sizeWarning()) |
| 383 | { |
| 384 | scheduleRepoPrune(); |
| 385 | } |
| 386 | |
| 387 | auto src = pel->primarySRC(); |
| 388 | if (src) |
| 389 | { |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 390 | auto m = |
Matt Spinler | 22421b9 | 2020-07-17 09:41:08 -0500 | [diff] [blame] | 391 | fmt::format("Created PEL {:#x} (BMC ID {}) with SRC {}", pel->id(), |
| 392 | pel->obmcLogID(), (*src)->asciiString()); |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 393 | while (m.back() == ' ') |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 394 | { |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 395 | m.pop_back(); |
Matt Spinler | 30ddc9f | 2020-07-16 15:39:59 -0500 | [diff] [blame] | 396 | } |
Matt Spinler | 45796e8 | 2022-07-01 11:25:27 -0500 | [diff] [blame] | 397 | log<level::INFO>(m.c_str()); |
Matt Spinler | 1d4c74a | 2019-12-16 14:40:21 -0600 | [diff] [blame] | 398 | } |
Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 399 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 400 | // Check for severity 0x51 and update boot progress SRC |
| 401 | updateProgressSRC(pel); |
| 402 | |
Matt Spinler | 1962e08 | 2020-08-05 13:44:53 -0500 | [diff] [blame] | 403 | // Activate any resulting service indicators if necessary |
| 404 | auto policy = service_indicators::getPolicy(*_dataIface); |
| 405 | policy->activate(*pel); |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 406 | |
Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 407 | updateDBusSeverity(*pel); |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 408 | updateEventId(pel); |
Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 409 | updateResolution(*pel); |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 410 | createPELEntry(obmcLogID); |
Matt Spinler | df5cb83 | 2022-07-12 12:47:26 -0500 | [diff] [blame] | 411 | |
| 412 | // Check if firmware should quiesce system due to error |
| 413 | checkPelAndQuiesce(pel); |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 414 | } |
| 415 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 416 | sdbusplus::message::unix_fd Manager::getPEL(uint32_t pelID) |
| 417 | { |
| 418 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 419 | std::optional<int> fd; |
| 420 | |
Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 421 | log<level::DEBUG>("getPEL", entry("PEL_ID=0x%X", pelID)); |
| 422 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 423 | try |
| 424 | { |
| 425 | fd = _repo.getPELFD(id); |
| 426 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 427 | catch (const std::exception& e) |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 428 | { |
| 429 | throw common_error::InternalFailure(); |
| 430 | } |
| 431 | |
| 432 | if (!fd) |
| 433 | { |
| 434 | throw common_error::InvalidArgument(); |
| 435 | } |
| 436 | |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 437 | scheduleFDClose(*fd); |
| 438 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 439 | return *fd; |
| 440 | } |
| 441 | |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 442 | void Manager::scheduleFDClose(int fd) |
| 443 | { |
| 444 | _fdCloserEventSource = std::make_unique<sdeventplus::source::Defer>( |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 445 | _event, std::bind(std::mem_fn(&Manager::closeFD), this, fd, |
| 446 | std::placeholders::_1)); |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 447 | } |
| 448 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 449 | void Manager::closeFD(int fd, sdeventplus::source::EventBase& /*source*/) |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 450 | { |
| 451 | close(fd); |
| 452 | _fdCloserEventSource.reset(); |
| 453 | } |
| 454 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 455 | std::vector<uint8_t> Manager::getPELFromOBMCID(uint32_t obmcLogID) |
| 456 | { |
| 457 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 458 | std::optional<std::vector<uint8_t>> data; |
| 459 | |
Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 460 | log<level::DEBUG>("getPELFromOBMCID", entry("OBMC_LOG_ID=%d", obmcLogID)); |
| 461 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 462 | try |
| 463 | { |
| 464 | data = _repo.getPELData(id); |
| 465 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 466 | catch (const std::exception& e) |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 467 | { |
| 468 | throw common_error::InternalFailure(); |
| 469 | } |
| 470 | |
| 471 | if (!data) |
| 472 | { |
| 473 | throw common_error::InvalidArgument(); |
| 474 | } |
| 475 | |
| 476 | return *data; |
| 477 | } |
| 478 | |
| 479 | void Manager::hostAck(uint32_t pelID) |
| 480 | { |
| 481 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 482 | |
Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 483 | log<level::DEBUG>("HostAck", entry("PEL_ID=0x%X", pelID)); |
| 484 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 485 | if (!_repo.hasPEL(id)) |
| 486 | { |
| 487 | throw common_error::InvalidArgument(); |
| 488 | } |
| 489 | |
| 490 | if (_hostNotifier) |
| 491 | { |
| 492 | _hostNotifier->ackPEL(pelID); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | void Manager::hostReject(uint32_t pelID, RejectionReason reason) |
| 497 | { |
| 498 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 499 | |
Matt Spinler | 5f5352e | 2020-03-05 16:23:27 -0600 | [diff] [blame] | 500 | log<level::DEBUG>("HostReject", entry("PEL_ID=0x%X", pelID), |
| 501 | entry("REASON=%d", static_cast<int>(reason))); |
| 502 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 503 | if (!_repo.hasPEL(id)) |
| 504 | { |
| 505 | throw common_error::InvalidArgument(); |
| 506 | } |
| 507 | |
Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 508 | if (reason == RejectionReason::BadPEL) |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 509 | { |
Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 510 | AdditionalData data; |
| 511 | data.add("BAD_ID", getNumberString("0x%08X", pelID)); |
| 512 | _eventLogger.log("org.open_power.Logging.Error.SentBadPELToHost", |
| 513 | Entry::Level::Informational, data); |
| 514 | if (_hostNotifier) |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 515 | { |
| 516 | _hostNotifier->setBadPEL(pelID); |
| 517 | } |
Matt Spinler | 05c2c6c | 2019-12-18 14:02:09 -0600 | [diff] [blame] | 518 | } |
| 519 | else if ((reason == RejectionReason::HostFull) && _hostNotifier) |
| 520 | { |
| 521 | _hostNotifier->setHostFull(pelID); |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 525 | void Manager::scheduleRepoPrune() |
| 526 | { |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 527 | _repoPrunerEventSource = std::make_unique<sdeventplus::source::Defer>( |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 528 | _event, std::bind(std::mem_fn(&Manager::pruneRepo), this, |
| 529 | std::placeholders::_1)); |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 530 | } |
| 531 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 532 | void Manager::pruneRepo(sdeventplus::source::EventBase& /*source*/) |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 533 | { |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 534 | auto idsWithHwIsoEntry = _dataIface->getLogIDWithHwIsolation(); |
| 535 | |
| 536 | auto idsToDelete = _repo.prune(idsWithHwIsoEntry); |
Matt Spinler | 7e727a3 | 2020-07-07 15:00:17 -0500 | [diff] [blame] | 537 | |
| 538 | // Remove the OpenBMC event logs for the PELs that were just removed. |
| 539 | std::for_each(idsToDelete.begin(), idsToDelete.end(), |
| 540 | [this](auto id) { this->_logManager.erase(id); }); |
| 541 | |
| 542 | _repoPrunerEventSource.reset(); |
| 543 | } |
| 544 | |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 545 | void Manager::setupPELDeleteWatch() |
| 546 | { |
| 547 | _pelFileDeleteFD = inotify_init1(IN_NONBLOCK); |
| 548 | if (-1 == _pelFileDeleteFD) |
| 549 | { |
| 550 | auto e = errno; |
| 551 | std::string msg = |
| 552 | "inotify_init1 failed with errno " + std::to_string(e); |
| 553 | log<level::ERR>(msg.c_str()); |
| 554 | abort(); |
| 555 | } |
| 556 | |
| 557 | _pelFileDeleteWatchFD = inotify_add_watch( |
| 558 | _pelFileDeleteFD, _repo.repoPath().c_str(), IN_DELETE); |
| 559 | if (-1 == _pelFileDeleteWatchFD) |
| 560 | { |
| 561 | auto e = errno; |
| 562 | std::string msg = |
| 563 | "inotify_add_watch failed with error " + std::to_string(e); |
| 564 | log<level::ERR>(msg.c_str()); |
| 565 | abort(); |
| 566 | } |
| 567 | |
| 568 | _pelFileDeleteEventSource = std::make_unique<sdeventplus::source::IO>( |
| 569 | _event, _pelFileDeleteFD, EPOLLIN, |
| 570 | std::bind(std::mem_fn(&Manager::pelFileDeleted), this, |
| 571 | std::placeholders::_1, std::placeholders::_2, |
| 572 | std::placeholders::_3)); |
| 573 | } |
| 574 | |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 575 | void Manager::pelFileDeleted(sdeventplus::source::IO& /*io*/, int /*fd*/, |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 576 | uint32_t revents) |
| 577 | { |
| 578 | if (!(revents & EPOLLIN)) |
| 579 | { |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | // An event for 1 PEL uses 48B. When all PELs are deleted at once, |
| 584 | // as many events as there is room for can be handled in one callback. |
| 585 | // A size of 2000 will allow 41 to be processed, with additional |
| 586 | // callbacks being needed to process the remaining ones. |
Matt Spinler | 9d59d58 | 2021-05-19 07:57:10 -0600 | [diff] [blame] | 587 | std::array<uint8_t, 2000> data{}; |
Matt Spinler | ff9cec2 | 2020-07-15 13:06:35 -0500 | [diff] [blame] | 588 | auto bytesRead = read(_pelFileDeleteFD, data.data(), data.size()); |
| 589 | if (bytesRead < 0) |
| 590 | { |
| 591 | auto e = errno; |
| 592 | std::string msg = "Failed reading data from inotify event, errno = " + |
| 593 | std::to_string(e); |
| 594 | log<level::ERR>(msg.c_str()); |
| 595 | abort(); |
| 596 | } |
| 597 | |
| 598 | auto offset = 0; |
| 599 | while (offset < bytesRead) |
| 600 | { |
| 601 | auto event = reinterpret_cast<inotify_event*>(&data[offset]); |
| 602 | if (event->mask & IN_DELETE) |
| 603 | { |
| 604 | std::string filename{event->name}; |
| 605 | |
| 606 | // Get the PEL ID from the filename and tell the |
| 607 | // repo it's been removed, and then delete the BMC |
| 608 | // event log if it's there. |
| 609 | auto pos = filename.find_first_of('_'); |
| 610 | if (pos != std::string::npos) |
| 611 | { |
| 612 | try |
| 613 | { |
| 614 | auto idString = filename.substr(pos + 1); |
| 615 | auto pelID = std::stoul(idString, nullptr, 16); |
| 616 | |
| 617 | Repository::LogID id{Repository::LogID::Pel(pelID)}; |
| 618 | auto removedLogID = _repo.remove(id); |
| 619 | if (removedLogID) |
| 620 | { |
| 621 | _logManager.erase(removedLogID->obmcID.id); |
| 622 | } |
| 623 | } |
| 624 | catch (const std::exception& e) |
| 625 | { |
| 626 | log<level::INFO>("Could not find PEL ID from its filename", |
| 627 | entry("FILENAME=%s", filename.c_str())); |
| 628 | } |
| 629 | } |
| 630 | } |
| 631 | |
| 632 | offset += offsetof(inotify_event, name) + event->len; |
| 633 | } |
| 634 | } |
Matt Spinler | 9cc3007 | 2020-09-16 15:39:34 -0500 | [diff] [blame] | 635 | |
| 636 | std::tuple<uint32_t, uint32_t> Manager::createPELWithFFDCFiles( |
| 637 | std::string message, Entry::Level severity, |
| 638 | std::map<std::string, std::string> additionalData, |
| 639 | std::vector<std::tuple< |
| 640 | sdbusplus::xyz::openbmc_project::Logging::server::Create::FFDCFormat, |
| 641 | uint8_t, uint8_t, sdbusplus::message::unix_fd>> |
| 642 | fFDC) |
| 643 | { |
Matt Spinler | 44893cc | 2020-08-26 11:34:17 -0500 | [diff] [blame] | 644 | _logManager.createWithFFDC(message, severity, additionalData, fFDC); |
| 645 | |
| 646 | return {_logManager.lastEntryID(), _repo.lastPelID()}; |
Matt Spinler | 9cc3007 | 2020-09-16 15:39:34 -0500 | [diff] [blame] | 647 | } |
| 648 | |
Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 649 | std::string Manager::getPELJSON(uint32_t obmcLogID) |
Matt Spinler | aa85a07 | 2022-03-23 11:26:41 -0500 | [diff] [blame] | 650 | { |
Matt Spinler | 8bd4ca4 | 2022-04-01 16:06:06 -0500 | [diff] [blame] | 651 | // Throws InvalidArgument if not found |
| 652 | auto pelID = getPELIdFromBMCLogId(obmcLogID); |
| 653 | |
| 654 | auto cmd = fmt::format("/usr/bin/peltool -i {:#x}", pelID); |
| 655 | |
| 656 | FILE* pipe = popen(cmd.c_str(), "r"); |
| 657 | if (!pipe) |
| 658 | { |
| 659 | log<level::ERR>(fmt::format("Error running {}", cmd).c_str()); |
| 660 | throw common_error::InternalFailure(); |
| 661 | } |
| 662 | |
| 663 | std::string output; |
| 664 | std::array<char, 1024> buffer; |
| 665 | while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) |
| 666 | { |
| 667 | output.append(buffer.data()); |
| 668 | } |
| 669 | |
| 670 | int rc = pclose(pipe); |
| 671 | if (WEXITSTATUS(rc) != 0) |
| 672 | { |
| 673 | log<level::ERR>( |
| 674 | fmt::format("Error running {}, rc = {}", cmd, rc).c_str()); |
| 675 | throw common_error::InternalFailure(); |
| 676 | } |
| 677 | |
| 678 | return output; |
Matt Spinler | aa85a07 | 2022-03-23 11:26:41 -0500 | [diff] [blame] | 679 | } |
| 680 | |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 681 | void Manager::checkPelAndQuiesce(std::unique_ptr<openpower::pels::PEL>& pel) |
| 682 | { |
Matt Spinler | b2abc04 | 2021-05-17 15:32:50 -0600 | [diff] [blame] | 683 | if ((pel->userHeader().severity() == |
| 684 | static_cast<uint8_t>(SeverityType::nonError)) || |
| 685 | (pel->userHeader().severity() == |
| 686 | static_cast<uint8_t>(SeverityType::recovered))) |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 687 | { |
Matt Spinler | b2abc04 | 2021-05-17 15:32:50 -0600 | [diff] [blame] | 688 | log<level::DEBUG>( |
| 689 | "PEL severity informational or recovered. no quiesce needed"); |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 690 | return; |
| 691 | } |
| 692 | if (!_logManager.isQuiesceOnErrorEnabled()) |
| 693 | { |
| 694 | log<level::DEBUG>("QuiesceOnHwError not enabled, no quiesce needed"); |
| 695 | return; |
| 696 | } |
| 697 | |
Matt Spinler | 845c624 | 2022-03-01 16:45:08 -0600 | [diff] [blame] | 698 | CreatorID creatorID{pel->privateHeader().creatorID()}; |
| 699 | |
| 700 | if ((creatorID != CreatorID::openBMC) && |
| 701 | (creatorID != CreatorID::hostboot) && |
| 702 | (creatorID != CreatorID::ioDrawer) && (creatorID != CreatorID::occ) && |
| 703 | (creatorID != CreatorID::phyp)) |
| 704 | { |
| 705 | return; |
| 706 | } |
| 707 | |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 708 | // Now check if it has any type of callout |
Andrew Geissler | f8e750d | 2022-01-14 14:56:13 -0600 | [diff] [blame] | 709 | if (pel->isHwCalloutPresent()) |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 710 | { |
Matt Spinler | b2abc04 | 2021-05-17 15:32:50 -0600 | [diff] [blame] | 711 | log<level::INFO>( |
| 712 | "QuiesceOnHwError enabled, PEL severity not nonError or recovered, " |
| 713 | "and callout is present"); |
Andrew Geissler | 44fc316 | 2020-07-09 09:21:31 -0500 | [diff] [blame] | 714 | |
| 715 | _logManager.quiesceOnError(pel->obmcLogID()); |
| 716 | } |
| 717 | } |
| 718 | |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 719 | std::string Manager::getEventId(const openpower::pels::PEL& pel) const |
| 720 | { |
| 721 | std::string str; |
| 722 | auto src = pel.primarySRC(); |
| 723 | if (src) |
| 724 | { |
| 725 | const auto& hexwords = (*src)->hexwordData(); |
| 726 | |
| 727 | std::string refcode = (*src)->asciiString(); |
| 728 | size_t pos = refcode.find_last_not_of(0x20); |
| 729 | if (pos != std::string::npos) |
| 730 | { |
| 731 | refcode.erase(pos + 1); |
| 732 | } |
| 733 | str = refcode; |
| 734 | |
| 735 | for (auto& value : hexwords) |
| 736 | { |
| 737 | str += " "; |
| 738 | str += getNumberString("%08X", value); |
| 739 | } |
| 740 | } |
Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 741 | return sanitizeFieldForDBus(str); |
Vijay Lobo | d354a39 | 2021-06-01 16:21:02 -0500 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | void Manager::updateEventId(std::unique_ptr<openpower::pels::PEL>& pel) |
| 745 | { |
| 746 | std::string eventIdStr = getEventId(*pel); |
| 747 | |
| 748 | auto entryN = _logManager.entries.find(pel->obmcLogID()); |
| 749 | if (entryN != _logManager.entries.end()) |
| 750 | { |
| 751 | entryN->second->eventId(eventIdStr); |
| 752 | } |
| 753 | } |
| 754 | |
Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 755 | std::string Manager::sanitizeFieldForDBus(std::string field) |
| 756 | { |
| 757 | std::for_each(field.begin(), field.end(), [](char& ch) { |
| 758 | if (((ch < ' ') || (ch > '~')) && (ch != '\n') && (ch != '\t')) |
| 759 | { |
| 760 | ch = ' '; |
| 761 | } |
| 762 | }); |
| 763 | return field; |
| 764 | } |
| 765 | |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 766 | std::string Manager::getResolution(const openpower::pels::PEL& pel) const |
| 767 | { |
| 768 | std::string str; |
| 769 | std::string resolution; |
| 770 | auto src = pel.primarySRC(); |
| 771 | if (src) |
| 772 | { |
| 773 | // First extract the callout pointer and then go through |
| 774 | const auto& callouts = (*src)->callouts(); |
| 775 | namespace pv = openpower::pels::pel_values; |
| 776 | // All PELs dont have callout, check before parsing callout data |
| 777 | if (callouts) |
| 778 | { |
| 779 | const auto& entries = callouts->callouts(); |
| 780 | // Entry starts with index 1 |
| 781 | uint8_t index = 1; |
| 782 | for (auto& entry : entries) |
| 783 | { |
| 784 | resolution += std::to_string(index) + ". "; |
| 785 | // Adding Location code to resolution |
| 786 | if (!entry->locationCode().empty()) |
| 787 | resolution += |
| 788 | "Location Code: " + entry->locationCode() + ", "; |
| 789 | if (entry->fruIdentity()) |
| 790 | { |
| 791 | // Get priority and set the resolution string |
| 792 | str = pv::getValue(entry->priority(), |
| 793 | pel_values::calloutPriorityValues, |
| 794 | pel_values::registryNamePos); |
| 795 | str[0] = toupper(str[0]); |
| 796 | resolution += "Priority: " + str + ", "; |
| 797 | if (entry->fruIdentity()->getPN().has_value()) |
| 798 | { |
| 799 | resolution += |
| 800 | "PN: " + entry->fruIdentity()->getPN().value() + |
| 801 | ", "; |
| 802 | } |
| 803 | if (entry->fruIdentity()->getSN().has_value()) |
| 804 | { |
| 805 | resolution += |
| 806 | "SN: " + entry->fruIdentity()->getSN().value() + |
| 807 | ", "; |
| 808 | } |
| 809 | if (entry->fruIdentity()->getCCIN().has_value()) |
| 810 | { |
| 811 | resolution += |
| 812 | "CCIN: " + entry->fruIdentity()->getCCIN().value() + |
| 813 | ", "; |
| 814 | } |
| 815 | // Add the maintenance procedure |
| 816 | if (entry->fruIdentity()->getMaintProc().has_value()) |
| 817 | { |
| 818 | resolution += |
| 819 | "Procedure: " + |
| 820 | entry->fruIdentity()->getMaintProc().value() + ", "; |
| 821 | } |
| 822 | } |
| 823 | resolution.resize(resolution.size() - 2); |
| 824 | resolution += "\n"; |
| 825 | index++; |
| 826 | } |
| 827 | } |
| 828 | } |
Matt Spinler | 0003af1 | 2022-06-08 10:46:17 -0500 | [diff] [blame] | 829 | return sanitizeFieldForDBus(resolution); |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 830 | } |
| 831 | |
Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 832 | bool Manager::updateResolution(const openpower::pels::PEL& pel) |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 833 | { |
Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 834 | std::string callouts = getResolution(pel); |
| 835 | auto entryN = _logManager.entries.find(pel.obmcLogID()); |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 836 | if (entryN != _logManager.entries.end()) |
| 837 | { |
Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 838 | entryN->second->resolution(callouts, true); |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 839 | } |
Matt Spinler | 28d6ae2 | 2022-03-18 11:18:27 -0500 | [diff] [blame] | 840 | |
| 841 | return false; |
Vijay Lobo | 593a4c6 | 2021-06-16 14:25:26 -0500 | [diff] [blame] | 842 | } |
| 843 | |
Matt Spinler | 8b81ec0 | 2022-07-12 13:25:37 -0500 | [diff] [blame] | 844 | void Manager::updateDBusSeverity(const openpower::pels::PEL& pel) |
| 845 | { |
| 846 | // The final severity of the PEL may not agree with the |
| 847 | // original severity of the D-Bus event log. Update the |
| 848 | // D-Bus property to match in some cases. This is to |
| 849 | // ensure there isn't a Critical or Warning Redfish event |
| 850 | // log for an informational or recovered PEL (or vice versa). |
| 851 | // This doesn't make an explicit call to serialize the new |
| 852 | // event log property value because updateEventId() is called |
| 853 | // right after this and will do it. |
| 854 | auto sevType = |
| 855 | static_cast<SeverityType>(pel.userHeader().severity() & 0xF0); |
| 856 | |
| 857 | auto entryN = _logManager.entries.find(pel.obmcLogID()); |
| 858 | if (entryN != _logManager.entries.end()) |
| 859 | { |
| 860 | auto newSeverity = |
| 861 | fixupLogSeverity(entryN->second->severity(), sevType); |
| 862 | if (newSeverity) |
| 863 | { |
| 864 | log<level::INFO>( |
| 865 | fmt::format( |
| 866 | "Changing event log {} severity from {} " |
| 867 | "to {} to match PEL", |
| 868 | entryN->second->id(), |
| 869 | Entry::convertLevelToString(entryN->second->severity()), |
| 870 | Entry::convertLevelToString(*newSeverity)) |
| 871 | .c_str()); |
| 872 | |
| 873 | entryN->second->severity(*newSeverity, true); |
| 874 | } |
| 875 | } |
| 876 | } |
| 877 | |
Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 878 | void Manager::setEntryPath(uint32_t obmcLogID) |
| 879 | { |
| 880 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 881 | if (auto attributes = _repo.getPELAttributes(id); attributes) |
| 882 | { |
| 883 | auto& attr = attributes.value().get(); |
| 884 | auto entry = _logManager.entries.find(obmcLogID); |
| 885 | if (entry != _logManager.entries.end()) |
| 886 | { |
Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 887 | entry->second->path(attr.path, true); |
Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
Vijay Lobo | cbc93a4 | 2021-05-20 19:04:07 -0500 | [diff] [blame] | 892 | void Manager::setServiceProviderNotifyFlag(uint32_t obmcLogID) |
| 893 | { |
| 894 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 895 | if (auto attributes = _repo.getPELAttributes(id); attributes) |
| 896 | { |
| 897 | auto& attr = attributes.value().get(); |
| 898 | auto entry = _logManager.entries.find(obmcLogID); |
| 899 | if (entry != _logManager.entries.end()) |
| 900 | { |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 901 | entry->second->serviceProviderNotify( |
Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 902 | attr.actionFlags.test(callHomeFlagBit), true); |
Vijay Lobo | cbc93a4 | 2021-05-20 19:04:07 -0500 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | } |
| 906 | |
Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 907 | void Manager::createPELEntry(uint32_t obmcLogID, bool skipIaSignal) |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 908 | { |
| 909 | std::map<std::string, PropertiesVariant> varData; |
| 910 | Repository::LogID id{Repository::LogID::Obmc(obmcLogID)}; |
| 911 | if (auto attributes = _repo.getPELAttributes(id); attributes) |
| 912 | { |
| 913 | namespace pv = openpower::pels::pel_values; |
| 914 | auto& attr = attributes.value().get(); |
Vijay Lobo | b2e541e | 2021-08-31 23:12:47 -0500 | [diff] [blame] | 915 | |
| 916 | // get the hidden flag values |
| 917 | auto sevType = static_cast<SeverityType>(attr.severity & 0xF0); |
| 918 | auto isHidden = true; |
| 919 | if (((sevType != SeverityType::nonError) && |
| 920 | attr.actionFlags.test(reportFlagBit) && |
| 921 | !attr.actionFlags.test(hiddenFlagBit)) || |
| 922 | ((sevType == SeverityType::nonError) && |
| 923 | attr.actionFlags.test(serviceActionFlagBit))) |
| 924 | { |
| 925 | isHidden = false; |
| 926 | } |
| 927 | varData.emplace(std::string("Hidden"), isHidden); |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 928 | varData.emplace( |
| 929 | std::string("Subsystem"), |
| 930 | pv::getValue(attr.subsystem, pel_values::subsystemValues)); |
Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 931 | |
| 932 | varData.emplace( |
| 933 | std::string("ManagementSystemAck"), |
| 934 | (attr.hmcState == TransmissionState::acked ? true : false)); |
| 935 | |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 936 | // Path to create PELEntry Interface is same as PEL |
| 937 | auto path = std::string(OBJ_ENTRY) + '/' + std::to_string(obmcLogID); |
| 938 | // Create Interface for PELEntry and set properties |
Vijay Lobo | 2fb1021 | 2021-08-22 23:24:16 -0500 | [diff] [blame] | 939 | auto pelEntry = std::make_unique<PELEntry>(_logManager.getBus(), path, |
| 940 | varData, obmcLogID, &_repo); |
Matt Spinler | 734ed2b | 2022-01-21 09:31:46 -0600 | [diff] [blame] | 941 | if (!skipIaSignal) |
| 942 | { |
| 943 | pelEntry->emit_added(); |
| 944 | } |
Vijay Lobo | afb1b46 | 2021-07-21 23:29:13 -0500 | [diff] [blame] | 945 | _pelEntries.emplace(std::move(path), std::move(pelEntry)); |
| 946 | } |
| 947 | } |
| 948 | |
Ramesh Iyyar | f4203c4 | 2021-06-24 06:09:23 -0500 | [diff] [blame] | 949 | uint32_t Manager::getPELIdFromBMCLogId(uint32_t bmcLogId) |
| 950 | { |
| 951 | Repository::LogID id{Repository::LogID::Obmc(bmcLogId)}; |
| 952 | if (auto logId = _repo.getLogID(id); !logId.has_value()) |
| 953 | { |
| 954 | throw common_error::InvalidArgument(); |
| 955 | } |
| 956 | else |
| 957 | { |
| 958 | return logId->pelID.id; |
| 959 | } |
| 960 | } |
| 961 | |
Ramesh Iyyar | 530efbf | 2021-06-24 06:22:22 -0500 | [diff] [blame] | 962 | uint32_t Manager::getBMCLogIdFromPELId(uint32_t pelId) |
| 963 | { |
| 964 | Repository::LogID id{Repository::LogID::Pel(pelId)}; |
| 965 | if (auto logId = _repo.getLogID(id); !logId.has_value()) |
| 966 | { |
| 967 | throw common_error::InvalidArgument(); |
| 968 | } |
| 969 | else |
| 970 | { |
| 971 | return logId->obmcID.id; |
| 972 | } |
| 973 | } |
| 974 | |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 975 | void Manager::updateProgressSRC( |
| 976 | std::unique_ptr<openpower::pels::PEL>& pel) const |
| 977 | { |
| 978 | // Check for pel severity of type - 0x51 = critical error, system |
| 979 | // termination |
| 980 | if (pel->userHeader().severity() == 0x51) |
| 981 | { |
| 982 | auto src = pel->primarySRC(); |
| 983 | if (src) |
| 984 | { |
| 985 | std::vector<uint8_t> asciiSRC = (*src)->getSrcStruct(); |
| 986 | uint64_t srcRefCode = 0; |
| 987 | |
| 988 | // Read bytes from offset [40-47] e.g. BD8D1001 |
| 989 | for (int i = 0; i < 8; i++) |
| 990 | { |
| 991 | srcRefCode |= |
| 992 | (static_cast<uint64_t>(asciiSRC[40 + i]) << (8 * i)); |
| 993 | } |
| 994 | |
| 995 | try |
| 996 | { |
| 997 | _dataIface->createProgressSRC(srcRefCode, asciiSRC); |
| 998 | } |
| 999 | catch (std::exception& e) |
| 1000 | { |
| 1001 | // Exception - may be no boot progress interface on dbus |
| 1002 | } |
| 1003 | } |
| 1004 | } |
| 1005 | } |
| 1006 | |
Matt Spinler | d8fb5ba | 2022-01-25 13:01:14 -0600 | [diff] [blame] | 1007 | void Manager::scheduleObmcLogDelete(uint32_t obmcLogID) |
| 1008 | { |
| 1009 | _obmcLogDeleteEventSource = std::make_unique<sdeventplus::source::Defer>( |
| 1010 | _event, std::bind(std::mem_fn(&Manager::deleteObmcLog), this, |
| 1011 | std::placeholders::_1, obmcLogID)); |
| 1012 | } |
| 1013 | |
| 1014 | void Manager::deleteObmcLog(sdeventplus::source::EventBase&, uint32_t obmcLogID) |
| 1015 | { |
| 1016 | log<level::INFO>( |
| 1017 | fmt::format("Removing event log with no PEL: {}", obmcLogID).c_str()); |
| 1018 | _logManager.erase(obmcLogID); |
| 1019 | _obmcLogDeleteEventSource.reset(); |
| 1020 | } |
| 1021 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 1022 | } // namespace pels |
| 1023 | } // namespace openpower |