Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "log_manager.hpp" |
| 4 | |
| 5 | #include "elog_entry.hpp" |
| 6 | #include "elog_meta.hpp" |
| 7 | #include "elog_serialize.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 8 | #include "extensions.hpp" |
Patrick Williams | 9ca4d13 | 2024-10-31 17:02:47 -0400 | [diff] [blame] | 9 | #include "lib/lg2_commit.hpp" |
Patrick Williams | fa2d962 | 2024-09-30 16:25:43 -0400 | [diff] [blame] | 10 | #include "paths.hpp" |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 11 | #include "util.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 12 | |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 13 | #include <systemd/sd-bus.h> |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 14 | #include <systemd/sd-journal.h> |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 15 | #include <unistd.h> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 16 | |
Patrick Williams | 2544b41 | 2022-10-04 08:41:06 -0500 | [diff] [blame] | 17 | #include <phosphor-logging/lg2.hpp> |
| 18 | #include <sdbusplus/vtable.hpp> |
| 19 | #include <xyz/openbmc_project/State/Host/server.hpp> |
| 20 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 21 | #include <cassert> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 22 | #include <chrono> |
| 23 | #include <cstdio> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 24 | #include <cstring> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 25 | #include <fstream> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 26 | #include <functional> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 27 | #include <future> |
| 28 | #include <iostream> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 29 | #include <map> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 30 | #include <set> |
| 31 | #include <string> |
Patrick Williams | b01a5b4 | 2021-08-28 15:11:45 -0500 | [diff] [blame] | 32 | #include <string_view> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 33 | #include <vector> |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 34 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 35 | using namespace std::chrono; |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 36 | extern const std::map< |
| 37 | phosphor::logging::metadata::Metadata, |
| 38 | std::function<phosphor::logging::metadata::associations::Type>> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 39 | meta; |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 40 | |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 41 | namespace phosphor |
| 42 | { |
| 43 | namespace logging |
| 44 | { |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 45 | namespace internal |
| 46 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 47 | inline auto getLevel(const std::string& errMsg) |
| 48 | { |
| 49 | auto reqLevel = Entry::Level::Error; // Default to Error |
| 50 | |
| 51 | auto levelmap = g_errLevelMap.find(errMsg); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 52 | if (levelmap != g_errLevelMap.end()) |
Marri Devender Rao | 7656fba | 2017-08-06 05:42:52 -0500 | [diff] [blame] | 53 | { |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 54 | reqLevel = static_cast<Entry::Level>(levelmap->second); |
Marri Devender Rao | 7656fba | 2017-08-06 05:42:52 -0500 | [diff] [blame] | 55 | } |
| 56 | |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 57 | return reqLevel; |
| 58 | } |
| 59 | |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 60 | int Manager::getRealErrSize() |
| 61 | { |
| 62 | return realErrors.size(); |
| 63 | } |
| 64 | |
| 65 | int Manager::getInfoErrSize() |
| 66 | { |
| 67 | return infoErrors.size(); |
| 68 | } |
| 69 | |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 70 | uint32_t Manager::commit(uint64_t transactionId, std::string errMsg) |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 71 | { |
| 72 | auto level = getLevel(errMsg); |
| 73 | _commit(transactionId, std::move(errMsg), level); |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 74 | return entryId; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 77 | uint32_t Manager::commitWithLvl(uint64_t transactionId, std::string errMsg, |
| 78 | uint32_t errLvl) |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 79 | { |
| 80 | _commit(transactionId, std::move(errMsg), |
| 81 | static_cast<Entry::Level>(errLvl)); |
Lei YU | b50c705 | 2021-01-21 16:02:26 +0800 | [diff] [blame] | 82 | return entryId; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 83 | } |
| 84 | |
Patrick Williams | a517197 | 2021-04-16 20:10:01 -0500 | [diff] [blame] | 85 | void Manager::_commit(uint64_t transactionId [[maybe_unused]], |
| 86 | std::string&& errMsg, Entry::Level errLvl) |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 87 | { |
Patrick Williams | a517197 | 2021-04-16 20:10:01 -0500 | [diff] [blame] | 88 | std::vector<std::string> additionalData{}; |
| 89 | |
| 90 | // When running as a test-case, the system may have a LOT of journal |
| 91 | // data and we may not have permissions to do some of the journal sync |
| 92 | // operations. Just skip over them. |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 93 | if (!IS_UNIT_TEST) |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 94 | { |
Patrick Williams | b01a5b4 | 2021-08-28 15:11:45 -0500 | [diff] [blame] | 95 | static constexpr auto transactionIdVar = |
| 96 | std::string_view{"TRANSACTION_ID"}; |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 97 | // Length of 'TRANSACTION_ID' string. |
Patrick Williams | b01a5b4 | 2021-08-28 15:11:45 -0500 | [diff] [blame] | 98 | static constexpr auto transactionIdVarSize = transactionIdVar.size(); |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 99 | // Length of 'TRANSACTION_ID=' string. |
Patrick Williams | b01a5b4 | 2021-08-28 15:11:45 -0500 | [diff] [blame] | 100 | static constexpr auto transactionIdVarOffset = transactionIdVarSize + 1; |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 101 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 102 | // Flush all the pending log messages into the journal |
Matt Spinler | 271d143 | 2023-01-18 13:58:05 -0600 | [diff] [blame] | 103 | util::journalSync(); |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 104 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 105 | sd_journal* j = nullptr; |
| 106 | int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 107 | if (rc < 0) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 108 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 109 | lg2::error("Failed to open journal: {ERROR}", "ERROR", |
| 110 | strerror(-rc)); |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 111 | return; |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 112 | } |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 113 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 114 | std::string transactionIdStr = std::to_string(transactionId); |
| 115 | std::set<std::string> metalist; |
| 116 | auto metamap = g_errMetaMap.find(errMsg); |
| 117 | if (metamap != g_errMetaMap.end()) |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 118 | { |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 119 | metalist.insert(metamap->second.begin(), metamap->second.end()); |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 120 | } |
| 121 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 122 | // Add _PID field information in AdditionalData. |
| 123 | metalist.insert("_PID"); |
| 124 | |
| 125 | // Read the journal from the end to get the most recent entry first. |
| 126 | // The result from the sd_journal_get_data() is of the form |
| 127 | // VARIABLE=value. |
| 128 | SD_JOURNAL_FOREACH_BACKWARDS(j) |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 129 | { |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 130 | const char* data = nullptr; |
| 131 | size_t length = 0; |
| 132 | |
| 133 | // Look for the transaction id metadata variable |
Patrick Williams | b01a5b4 | 2021-08-28 15:11:45 -0500 | [diff] [blame] | 134 | rc = sd_journal_get_data(j, transactionIdVar.data(), |
| 135 | (const void**)&data, &length); |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 136 | if (rc < 0) |
| 137 | { |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 138 | // This journal entry does not have the TRANSACTION_ID |
| 139 | // metadata variable. |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 140 | continue; |
| 141 | } |
| 142 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 143 | // journald does not guarantee that sd_journal_get_data() returns |
| 144 | // NULL terminated strings, so need to specify the size to use to |
| 145 | // compare, use the returned length instead of anything that relies |
| 146 | // on NULL terminators like strlen(). The data variable is in the |
| 147 | // form of 'TRANSACTION_ID=1234'. Remove the TRANSACTION_ID |
| 148 | // characters plus the (=) sign to do the comparison. 'data + |
| 149 | // transactionIdVarOffset' will be in the form of '1234'. 'length - |
| 150 | // transactionIdVarOffset' will be the length of '1234'. |
| 151 | if ((length <= (transactionIdVarOffset)) || |
| 152 | (transactionIdStr.compare( |
| 153 | 0, transactionIdStr.size(), data + transactionIdVarOffset, |
| 154 | length - transactionIdVarOffset) != 0)) |
| 155 | { |
| 156 | // The value of the TRANSACTION_ID metadata is not the requested |
| 157 | // transaction id number. |
| 158 | continue; |
| 159 | } |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 160 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 161 | // Search for all metadata variables in the current journal entry. |
| 162 | for (auto i = metalist.cbegin(); i != metalist.cend();) |
| 163 | { |
| 164 | rc = sd_journal_get_data(j, (*i).c_str(), (const void**)&data, |
| 165 | &length); |
| 166 | if (rc < 0) |
| 167 | { |
| 168 | // Metadata variable not found, check next metadata |
| 169 | // variable. |
| 170 | i++; |
| 171 | continue; |
| 172 | } |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 173 | |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 174 | // Metadata variable found, save it and remove it from the set. |
| 175 | additionalData.emplace_back(data, length); |
| 176 | i = metalist.erase(i); |
| 177 | } |
| 178 | if (metalist.empty()) |
| 179 | { |
| 180 | // All metadata variables found, break out of journal loop. |
| 181 | break; |
| 182 | } |
| 183 | } |
| 184 | if (!metalist.empty()) |
| 185 | { |
| 186 | // Not all the metadata variables were found in the journal. |
| 187 | for (auto& metaVarStr : metalist) |
| 188 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 189 | lg2::info("Failed to find metadata: {META_FIELD}", "META_FIELD", |
| 190 | metaVarStr); |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
| 194 | sd_journal_close(j); |
| 195 | } |
Patrick Williams | ea21d99 | 2024-11-22 17:06:35 -0500 | [diff] [blame^] | 196 | createEntry(errMsg, errLvl, util::additional_data::parse(additionalData)); |
Matt Spinler | b60e755 | 2019-07-24 15:28:08 -0500 | [diff] [blame] | 197 | } |
| 198 | |
Patrick Williams | 597f24a | 2024-09-27 14:47:42 -0400 | [diff] [blame] | 199 | auto Manager::createEntry( |
| 200 | std::string errMsg, Entry::Level errLvl, |
Patrick Williams | ea21d99 | 2024-11-22 17:06:35 -0500 | [diff] [blame^] | 201 | std::map<std::string, std::string> additionalData, |
Patrick Williams | 597f24a | 2024-09-27 14:47:42 -0400 | [diff] [blame] | 202 | const FFDCEntries& ffdc) -> sdbusplus::message::object_path |
Matt Spinler | b60e755 | 2019-07-24 15:28:08 -0500 | [diff] [blame] | 203 | { |
| 204 | if (!Extensions::disableDefaultLogCaps()) |
| 205 | { |
| 206 | if (errLvl < Entry::sevLowerLimit) |
| 207 | { |
| 208 | if (realErrors.size() >= ERROR_CAP) |
| 209 | { |
| 210 | erase(realErrors.front()); |
| 211 | } |
| 212 | } |
| 213 | else |
| 214 | { |
| 215 | if (infoErrors.size() >= ERROR_INFO_CAP) |
| 216 | { |
| 217 | erase(infoErrors.front()); |
| 218 | } |
| 219 | } |
| 220 | } |
| 221 | |
Adriana Kobylak | 4ea7f31 | 2017-01-10 12:52:34 -0600 | [diff] [blame] | 222 | entryId++; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 223 | if (errLvl >= Entry::sevLowerLimit) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 224 | { |
| 225 | infoErrors.push_back(entryId); |
| 226 | } |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 227 | else |
| 228 | { |
| 229 | realErrors.push_back(entryId); |
| 230 | } |
Adriana Kobylak | c5f0bbd | 2017-01-22 14:56:04 -0600 | [diff] [blame] | 231 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 232 | std::chrono::system_clock::now().time_since_epoch()) |
| 233 | .count(); |
| 234 | auto objPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entryId); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 235 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 236 | AssociationList objects{}; |
Patrick Williams | ea21d99 | 2024-11-22 17:06:35 -0500 | [diff] [blame^] | 237 | auto additionalDataVec = util::additional_data::combine(additionalData); |
| 238 | processMetadata(errMsg, additionalDataVec, objects); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 239 | |
Matt Spinler | fb978da | 2022-01-21 08:42:24 -0600 | [diff] [blame] | 240 | auto e = std::make_unique<Entry>( |
| 241 | busLog, objPath, entryId, |
| 242 | ms, // Milliseconds since 1970 |
| 243 | errLvl, std::move(errMsg), std::move(additionalData), |
| 244 | std::move(objects), fwVersion, getEntrySerializePath(entryId), *this); |
| 245 | |
| 246 | serialize(*e); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 247 | |
Matt Spinler | 601b811 | 2022-01-26 13:18:04 -0600 | [diff] [blame] | 248 | if (isQuiesceOnErrorEnabled() && (errLvl < Entry::sevLowerLimit) && |
| 249 | isCalloutPresent(*e)) |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 250 | { |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 251 | quiesceOnError(entryId); |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 252 | } |
| 253 | |
Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 254 | // Add entry before calling the extensions so that they have access to it |
| 255 | entries.insert(std::make_pair(entryId, std::move(e))); |
| 256 | |
| 257 | doExtensionLogCreate(*entries.find(entryId)->second, ffdc); |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 258 | |
| 259 | // Note: No need to close the file descriptors in the FFDC. |
Patrick Williams | 597f24a | 2024-09-27 14:47:42 -0400 | [diff] [blame] | 260 | |
| 261 | return objPath; |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 262 | } |
| 263 | |
Patrick Williams | 9ca4d13 | 2024-10-31 17:02:47 -0400 | [diff] [blame] | 264 | auto Manager::createFromEvent(sdbusplus::exception::generated_event_base&& |
| 265 | event) -> sdbusplus::message::object_path |
| 266 | { |
| 267 | auto [msg, level, data] = lg2::details::extractEvent(std::move(event)); |
| 268 | return this->createEntry(msg, level, std::move(data)); |
| 269 | } |
| 270 | |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 271 | bool Manager::isQuiesceOnErrorEnabled() |
| 272 | { |
Patrick Williams | a517197 | 2021-04-16 20:10:01 -0500 | [diff] [blame] | 273 | // When running under tests, the Logging.Settings service will not be |
| 274 | // present. Assume false. |
William A. Kennington III | b6b2557 | 2021-05-19 17:09:41 -0700 | [diff] [blame] | 275 | if (IS_UNIT_TEST) |
| 276 | { |
| 277 | return false; |
| 278 | } |
Patrick Williams | a517197 | 2021-04-16 20:10:01 -0500 | [diff] [blame] | 279 | |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 280 | std::variant<bool> property; |
| 281 | |
| 282 | auto method = this->busLog.new_method_call( |
| 283 | "xyz.openbmc_project.Settings", "/xyz/openbmc_project/logging/settings", |
| 284 | "org.freedesktop.DBus.Properties", "Get"); |
| 285 | |
| 286 | method.append("xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError"); |
| 287 | |
| 288 | try |
| 289 | { |
| 290 | auto reply = this->busLog.call(method); |
| 291 | reply.read(property); |
| 292 | } |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 293 | catch (const sdbusplus::exception_t& e) |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 294 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 295 | lg2::error("Error reading QuiesceOnHwError property: {ERROR}", "ERROR", |
| 296 | e); |
Matt Spinler | 7ba17c3 | 2023-06-12 09:20:15 -0500 | [diff] [blame] | 297 | return false; |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | return std::get<bool>(property); |
| 301 | } |
| 302 | |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 303 | bool Manager::isCalloutPresent(const Entry& entry) |
| 304 | { |
| 305 | for (const auto& c : entry.additionalData()) |
| 306 | { |
| 307 | if (c.find("CALLOUT_") != std::string::npos) |
| 308 | { |
| 309 | return true; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | return false; |
| 314 | } |
| 315 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 316 | void Manager::findAndRemoveResolvedBlocks() |
| 317 | { |
| 318 | for (auto& entry : entries) |
| 319 | { |
| 320 | if (entry.second->resolved()) |
| 321 | { |
| 322 | checkAndRemoveBlockingError(entry.first); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 327 | void Manager::onEntryResolve(sdbusplus::message_t& msg) |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 328 | { |
| 329 | using Interface = std::string; |
| 330 | using Property = std::string; |
| 331 | using Value = std::string; |
Patrick Williams | 25acc6c | 2020-06-02 11:05:34 -0500 | [diff] [blame] | 332 | using Properties = std::map<Property, std::variant<Value>>; |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 333 | |
| 334 | Interface interface; |
| 335 | Properties properties; |
| 336 | |
| 337 | msg.read(interface, properties); |
| 338 | |
| 339 | for (const auto& p : properties) |
| 340 | { |
| 341 | if (p.first == "Resolved") |
| 342 | { |
| 343 | findAndRemoveResolvedBlocks(); |
| 344 | return; |
| 345 | } |
| 346 | } |
| 347 | } |
| 348 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 349 | void Manager::checkAndQuiesceHost() |
| 350 | { |
Willy Tu | 6ddbf69 | 2023-09-05 10:54:16 -0700 | [diff] [blame] | 351 | using Host = sdbusplus::server::xyz::openbmc_project::state::Host; |
Patrick Williams | a144a27 | 2021-07-16 17:03:55 -0500 | [diff] [blame] | 352 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 353 | // First check host state |
Patrick Williams | a144a27 | 2021-07-16 17:03:55 -0500 | [diff] [blame] | 354 | std::variant<Host::HostState> property; |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 355 | |
| 356 | auto method = this->busLog.new_method_call( |
| 357 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", |
| 358 | "org.freedesktop.DBus.Properties", "Get"); |
| 359 | |
| 360 | method.append("xyz.openbmc_project.State.Host", "CurrentHostState"); |
| 361 | |
| 362 | try |
| 363 | { |
| 364 | auto reply = this->busLog.call(method); |
| 365 | reply.read(property); |
| 366 | } |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 367 | catch (const sdbusplus::exception_t& e) |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 368 | { |
| 369 | // Quiescing the host is a "best effort" type function. If unable to |
| 370 | // read the host state or it comes back empty, just return. |
| 371 | // The boot block object will still be created and the associations to |
| 372 | // find the log will be present. Don't want a dependency with |
| 373 | // phosphor-state-manager service |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 374 | lg2::info("Error reading QuiesceOnHwError property: {ERROR}", "ERROR", |
| 375 | e); |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 376 | return; |
| 377 | } |
| 378 | |
Patrick Williams | a144a27 | 2021-07-16 17:03:55 -0500 | [diff] [blame] | 379 | auto hostState = std::get<Host::HostState>(property); |
| 380 | if (hostState != Host::HostState::Running) |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 381 | { |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | auto quiesce = this->busLog.new_method_call( |
| 386 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 387 | "org.freedesktop.systemd1.Manager", "StartUnit"); |
| 388 | |
Andrew Geissler | 86a60e9 | 2022-04-15 14:36:02 -0500 | [diff] [blame] | 389 | quiesce.append("obmc-host-graceful-quiesce@0.target"); |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 390 | quiesce.append("replace"); |
| 391 | |
| 392 | this->busLog.call_noreply(quiesce); |
| 393 | } |
| 394 | |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 395 | void Manager::quiesceOnError(const uint32_t entryId) |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 396 | { |
Andrew Geissler | 72a1cca | 2020-09-10 16:49:09 -0500 | [diff] [blame] | 397 | // Verify we don't already have this entry blocking |
Matt Spinler | 4a37595 | 2022-07-01 11:15:33 -0500 | [diff] [blame] | 398 | auto it = find_if(this->blockingErrors.begin(), this->blockingErrors.end(), |
| 399 | [&](const std::unique_ptr<Block>& obj) { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 400 | return obj->entryId == entryId; |
| 401 | }); |
Andrew Geissler | 72a1cca | 2020-09-10 16:49:09 -0500 | [diff] [blame] | 402 | if (it != this->blockingErrors.end()) |
| 403 | { |
| 404 | // Already recorded so just return |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 405 | lg2::debug( |
Andrew Geissler | 72a1cca | 2020-09-10 16:49:09 -0500 | [diff] [blame] | 406 | "QuiesceOnError set and callout present but entry already logged"); |
| 407 | return; |
| 408 | } |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 409 | |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 410 | lg2::info("QuiesceOnError set and callout present"); |
Andrew Geissler | 6a0ef6f | 2020-04-06 15:06:31 -0500 | [diff] [blame] | 411 | |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 412 | auto blockPath = |
| 413 | std::string(OBJ_LOGGING) + "/block" + std::to_string(entryId); |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 414 | auto blockObj = std::make_unique<Block>(this->busLog, blockPath, entryId); |
Andrew Geissler | 6a0ef6f | 2020-04-06 15:06:31 -0500 | [diff] [blame] | 415 | this->blockingErrors.push_back(std::move(blockObj)); |
| 416 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 417 | // Register call back if log is resolved |
| 418 | using namespace sdbusplus::bus::match::rules; |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 419 | auto entryPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entryId); |
Patrick Williams | 45e8352 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 420 | auto callback = std::make_unique<sdbusplus::bus::match_t>( |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 421 | this->busLog, |
| 422 | propertiesChanged(entryPath, "xyz.openbmc_project.Logging.Entry"), |
| 423 | std::bind(std::mem_fn(&Manager::onEntryResolve), this, |
| 424 | std::placeholders::_1)); |
| 425 | |
| 426 | propChangedEntryCallback.insert( |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 427 | std::make_pair(entryId, std::move(callback))); |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 428 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 429 | checkAndQuiesceHost(); |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 430 | } |
| 431 | |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 432 | void Manager::doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 433 | { |
| 434 | // Make the association <endpointpath>/<endpointtype> paths |
| 435 | std::vector<std::string> assocs; |
| 436 | for (const auto& [forwardType, reverseType, endpoint] : |
| 437 | entry.associations()) |
| 438 | { |
| 439 | std::string e{endpoint}; |
| 440 | e += '/' + reverseType; |
| 441 | assocs.push_back(e); |
| 442 | } |
| 443 | |
| 444 | for (auto& create : Extensions::getCreateFunctions()) |
| 445 | { |
| 446 | try |
| 447 | { |
| 448 | create(entry.message(), entry.id(), entry.timestamp(), |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 449 | entry.severity(), entry.additionalData(), assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 450 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 451 | catch (const std::exception& e) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 452 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 453 | lg2::error( |
| 454 | "An extension's create function threw an exception: {ERROR}", |
| 455 | "ERROR", e); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
Patrick Williams | f40323d | 2021-04-16 15:35:17 -0500 | [diff] [blame] | 460 | void Manager::processMetadata(const std::string& /*errorName*/, |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 461 | const std::vector<std::string>& additionalData, |
| 462 | AssociationList& objects) const |
| 463 | { |
| 464 | // additionalData is a list of "metadata=value" |
| 465 | constexpr auto separator = '='; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 466 | for (const auto& entryItem : additionalData) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 467 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 468 | auto found = entryItem.find(separator); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 469 | if (std::string::npos != found) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 470 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 471 | auto metadata = entryItem.substr(0, found); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 472 | auto iter = meta.find(metadata); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 473 | if (meta.end() != iter) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 474 | { |
| 475 | (iter->second)(metadata, additionalData, objects); |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 481 | void Manager::checkAndRemoveBlockingError(uint32_t entryId) |
| 482 | { |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 483 | // First look for blocking object and remove |
Matt Spinler | 4a37595 | 2022-07-01 11:15:33 -0500 | [diff] [blame] | 484 | auto it = find_if(blockingErrors.begin(), blockingErrors.end(), |
| 485 | [&](const std::unique_ptr<Block>& obj) { |
Patrick Williams | 075c792 | 2024-08-16 15:19:49 -0400 | [diff] [blame] | 486 | return obj->entryId == entryId; |
| 487 | }); |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 488 | if (it != blockingErrors.end()) |
| 489 | { |
| 490 | blockingErrors.erase(it); |
| 491 | } |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 492 | |
| 493 | // Now remove the callback looking for the error to be resolved |
| 494 | auto resolveFind = propChangedEntryCallback.find(entryId); |
| 495 | if (resolveFind != propChangedEntryCallback.end()) |
| 496 | { |
| 497 | propChangedEntryCallback.erase(resolveFind); |
| 498 | } |
| 499 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 500 | return; |
| 501 | } |
| 502 | |
harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 503 | size_t Manager::eraseAll() |
| 504 | { |
| 505 | std::vector<uint32_t> logIDWithHwIsolation; |
| 506 | for (auto& func : Extensions::getLogIDWithHwIsolationFunctions()) |
| 507 | { |
| 508 | try |
| 509 | { |
| 510 | func(logIDWithHwIsolation); |
| 511 | } |
| 512 | catch (const std::exception& e) |
| 513 | { |
| 514 | lg2::error("An extension's LogIDWithHwIsolation function threw an " |
| 515 | "exception: {ERROR}", |
| 516 | "ERROR", e); |
| 517 | } |
| 518 | } |
| 519 | size_t entriesSize = entries.size(); |
| 520 | auto iter = entries.begin(); |
| 521 | if (logIDWithHwIsolation.empty()) |
| 522 | { |
| 523 | while (iter != entries.end()) |
| 524 | { |
| 525 | auto e = iter->first; |
| 526 | ++iter; |
| 527 | erase(e); |
| 528 | } |
| 529 | entryId = 0; |
| 530 | } |
| 531 | else |
| 532 | { |
| 533 | while (iter != entries.end()) |
| 534 | { |
| 535 | auto e = iter->first; |
| 536 | ++iter; |
| 537 | try |
| 538 | { |
| 539 | if (!std::ranges::contains(logIDWithHwIsolation, e)) |
| 540 | { |
| 541 | erase(e); |
| 542 | } |
| 543 | else |
| 544 | { |
| 545 | entriesSize--; |
| 546 | } |
| 547 | } |
| 548 | catch (const sdbusplus::xyz::openbmc_project::Common::Error:: |
| 549 | Unavailable& e) |
| 550 | { |
| 551 | entriesSize--; |
| 552 | } |
| 553 | } |
| 554 | if (!entries.empty()) |
| 555 | { |
| 556 | entryId = std::ranges::max_element(entries, [](const auto& a, |
| 557 | const auto& b) { |
| 558 | return a.first < b.first; |
| 559 | })->first; |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | entryId = 0; |
| 564 | } |
| 565 | } |
| 566 | return entriesSize; |
| 567 | } |
| 568 | |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 569 | void Manager::erase(uint32_t entryId) |
| 570 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 571 | auto entryFound = entries.find(entryId); |
| 572 | if (entries.end() != entryFound) |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 573 | { |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 574 | for (auto& func : Extensions::getDeleteProhibitedFunctions()) |
| 575 | { |
| 576 | try |
| 577 | { |
| 578 | bool prohibited = false; |
| 579 | func(entryId, prohibited); |
| 580 | if (prohibited) |
| 581 | { |
harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 582 | throw sdbusplus::xyz::openbmc_project::Common::Error:: |
| 583 | Unavailable(); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 584 | } |
| 585 | } |
harsh-agarwal1 | d763db3 | 2024-09-03 09:18:50 -0500 | [diff] [blame] | 586 | catch (const sdbusplus::xyz::openbmc_project::Common::Error:: |
| 587 | Unavailable& e) |
| 588 | { |
| 589 | throw; |
| 590 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 591 | catch (const std::exception& e) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 592 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 593 | lg2::error("An extension's deleteProhibited function threw an " |
| 594 | "exception: {ERROR}", |
| 595 | "ERROR", e); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | |
Deepak Kodihalli | 3388799 | 2017-06-13 07:06:49 -0500 | [diff] [blame] | 599 | // Delete the persistent representation of this error. |
Patrick Williams | fa2d962 | 2024-09-30 16:25:43 -0400 | [diff] [blame] | 600 | fs::path errorPath(paths::error()); |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 601 | errorPath /= std::to_string(entryId); |
Deepak Kodihalli | 3388799 | 2017-06-13 07:06:49 -0500 | [diff] [blame] | 602 | fs::remove(errorPath); |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 603 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 604 | auto removeId = [](std::list<uint32_t>& ids, uint32_t id) { |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 605 | auto it = std::find(ids.begin(), ids.end(), id); |
| 606 | if (it != ids.end()) |
| 607 | { |
| 608 | ids.erase(it); |
| 609 | } |
| 610 | }; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 611 | if (entryFound->second->severity() >= Entry::sevLowerLimit) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 612 | { |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 613 | removeId(infoErrors, entryId); |
| 614 | } |
| 615 | else |
| 616 | { |
| 617 | removeId(realErrors, entryId); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 618 | } |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 619 | entries.erase(entryFound); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 620 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 621 | checkAndRemoveBlockingError(entryId); |
| 622 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 623 | for (auto& remove : Extensions::getDeleteFunctions()) |
| 624 | { |
| 625 | try |
| 626 | { |
| 627 | remove(entryId); |
| 628 | } |
Patrick Williams | 66491c6 | 2021-10-06 12:23:37 -0500 | [diff] [blame] | 629 | catch (const std::exception& e) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 630 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 631 | lg2::error("An extension's delete function threw an exception: " |
| 632 | "{ERROR}", |
| 633 | "ERROR", e); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 634 | } |
| 635 | } |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 636 | } |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 637 | else |
| 638 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 639 | lg2::error("Invalid entry ID ({ID}) to delete", "ID", entryId); |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 640 | } |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 643 | void Manager::restore() |
| 644 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 645 | auto sanity = [](const auto& id, const auto& restoredId) { |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 646 | return id == restoredId; |
| 647 | }; |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 648 | |
Patrick Williams | fa2d962 | 2024-09-30 16:25:43 -0400 | [diff] [blame] | 649 | fs::path dir(paths::error()); |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 650 | if (!fs::exists(dir) || fs::is_empty(dir)) |
| 651 | { |
| 652 | return; |
| 653 | } |
| 654 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 655 | for (auto& file : fs::directory_iterator(dir)) |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 656 | { |
| 657 | auto id = file.path().filename().c_str(); |
| 658 | auto idNum = std::stol(id); |
| 659 | auto e = std::make_unique<Entry>( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 660 | busLog, std::string(OBJ_ENTRY) + '/' + id, idNum, *this); |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 661 | if (deserialize(file.path(), *e)) |
| 662 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 663 | // validate the restored error entry id |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 664 | if (sanity(static_cast<uint32_t>(idNum), e->id())) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 665 | { |
Matt Spinler | ef952af | 2021-08-19 10:23:05 -0500 | [diff] [blame] | 666 | e->path(file.path(), true); |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 667 | if (e->severity() >= Entry::sevLowerLimit) |
| 668 | { |
| 669 | infoErrors.push_back(idNum); |
| 670 | } |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 671 | else |
| 672 | { |
| 673 | realErrors.push_back(idNum); |
| 674 | } |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 675 | |
| 676 | entries.insert(std::make_pair(idNum, std::move(e))); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 677 | } |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 678 | else |
| 679 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 680 | lg2::error( |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 681 | "Failed in sanity check while restoring error entry. " |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 682 | "Ignoring error entry {ID_NUM}/{ENTRY_ID}.", |
| 683 | "ID_NUM", idNum, "ENTRY_ID", e->id()); |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 684 | } |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | |
Lei YU | 01bf5c4 | 2022-05-23 15:33:23 +0800 | [diff] [blame] | 688 | if (!entries.empty()) |
Vishwanatha Subbanna | 37af9ba | 2017-09-28 16:33:53 +0530 | [diff] [blame] | 689 | { |
Lei YU | 01bf5c4 | 2022-05-23 15:33:23 +0800 | [diff] [blame] | 690 | entryId = entries.rbegin()->first; |
Vishwanatha Subbanna | 37af9ba | 2017-09-28 16:33:53 +0530 | [diff] [blame] | 691 | } |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 692 | } |
| 693 | |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 694 | std::string Manager::readFWVersion() |
| 695 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 696 | auto version = util::getOSReleaseValue("VERSION_ID"); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 697 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 698 | if (!version) |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 699 | { |
Patrick Williams | 5f285c5 | 2021-07-27 21:25:38 -0500 | [diff] [blame] | 700 | lg2::error("Unable to read BMC firmware version"); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 701 | } |
| 702 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 703 | return version.value_or(""); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 704 | } |
| 705 | |
Patrick Williams | 597f24a | 2024-09-27 14:47:42 -0400 | [diff] [blame] | 706 | auto Manager::create(const std::string& message, Entry::Level severity, |
Paul Fertser | 221b79b | 2024-03-04 15:40:23 +0000 | [diff] [blame] | 707 | const std::map<std::string, std::string>& additionalData, |
Patrick Williams | 597f24a | 2024-09-27 14:47:42 -0400 | [diff] [blame] | 708 | const FFDCEntries& ffdc) -> sdbusplus::message::object_path |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 709 | { |
Patrick Williams | ea21d99 | 2024-11-22 17:06:35 -0500 | [diff] [blame^] | 710 | return createEntry(message, severity, additionalData, ffdc); |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 711 | } |
| 712 | |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 713 | } // namespace internal |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 714 | } // namespace logging |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 715 | } // namespace phosphor |