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