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