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" |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 9 | #include "util.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 10 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 11 | #include <poll.h> |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 12 | #include <sys/inotify.h> |
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 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 17 | #include <cassert> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 18 | #include <chrono> |
| 19 | #include <cstdio> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 20 | #include <cstring> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 21 | #include <fstream> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 22 | #include <functional> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 23 | #include <future> |
| 24 | #include <iostream> |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 25 | #include <map> |
Saqib Khan | 2bb1519 | 2017-02-13 13:19:55 -0600 | [diff] [blame] | 26 | #include <phosphor-logging/log.hpp> |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 27 | #include <sdbusplus/vtable.hpp> |
| 28 | #include <set> |
| 29 | #include <string> |
| 30 | #include <vector> |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 31 | #include <xyz/openbmc_project/State/Host/server.hpp> |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 32 | |
| 33 | using namespace phosphor::logging; |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 34 | using namespace std::chrono; |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 35 | using sdbusplus::exception::SdBusError; |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 36 | extern const std::map<metadata::Metadata, |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 37 | std::function<metadata::associations::Type>> |
| 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 | |
| 84 | void Manager::_commit(uint64_t transactionId, std::string&& errMsg, |
| 85 | Entry::Level errLvl) |
| 86 | { |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 87 | constexpr const auto transactionIdVar = "TRANSACTION_ID"; |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 88 | // Length of 'TRANSACTION_ID' string. |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 89 | constexpr const auto transactionIdVarSize = std::strlen(transactionIdVar); |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 90 | // Length of 'TRANSACTION_ID=' string. |
| 91 | constexpr const auto transactionIdVarOffset = transactionIdVarSize + 1; |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 92 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 93 | // Flush all the pending log messages into the journal |
| 94 | journalSync(); |
Adriana Kobylak | cfd9a7d | 2017-06-07 11:57:31 -0500 | [diff] [blame] | 95 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 96 | sd_journal* j = nullptr; |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 97 | int rc = sd_journal_open(&j, SD_JOURNAL_LOCAL_ONLY); |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 98 | if (rc < 0) |
| 99 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 100 | logging::log<logging::level::ERR>( |
| 101 | "Failed to open journal", |
| 102 | logging::entry("DESCRIPTION=%s", strerror(-rc))); |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 103 | return; |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 106 | std::string transactionIdStr = std::to_string(transactionId); |
Adriana Kobylak | d722b3a | 2017-02-28 12:10:44 -0600 | [diff] [blame] | 107 | std::set<std::string> metalist; |
| 108 | auto metamap = g_errMetaMap.find(errMsg); |
| 109 | if (metamap != g_errMetaMap.end()) |
| 110 | { |
| 111 | metalist.insert(metamap->second.begin(), metamap->second.end()); |
| 112 | } |
Adriana Kobylak | 7298dc2 | 2017-01-24 12:21:50 -0600 | [diff] [blame] | 113 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 114 | // Add _PID field information in AdditionalData. |
Jayanth Othayoth | db18ebe | 2017-09-04 00:48:02 -0500 | [diff] [blame] | 115 | metalist.insert("_PID"); |
| 116 | |
Tom Joseph | 7a33ee4 | 2017-07-25 00:04:20 +0530 | [diff] [blame] | 117 | std::vector<std::string> additionalData; |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 118 | |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 119 | // Read the journal from the end to get the most recent entry first. |
| 120 | // The result from the sd_journal_get_data() is of the form VARIABLE=value. |
| 121 | SD_JOURNAL_FOREACH_BACKWARDS(j) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 122 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 123 | const char* data = nullptr; |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 124 | size_t length = 0; |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 125 | |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 126 | // Look for the transaction id metadata variable |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 127 | rc = sd_journal_get_data(j, transactionIdVar, (const void**)&data, |
| 128 | &length); |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 129 | if (rc < 0) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 130 | { |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 131 | // This journal entry does not have the TRANSACTION_ID |
| 132 | // metadata variable. |
| 133 | continue; |
| 134 | } |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 135 | |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 136 | // journald does not guarantee that sd_journal_get_data() returns NULL |
| 137 | // terminated strings, so need to specify the size to use to compare, |
| 138 | // use the returned length instead of anything that relies on NULL |
| 139 | // terminators like strlen(). |
| 140 | // The data variable is in the form of 'TRANSACTION_ID=1234'. Remove |
| 141 | // the TRANSACTION_ID characters plus the (=) sign to do the comparison. |
| 142 | // 'data + transactionIdVarOffset' will be in the form of '1234'. |
| 143 | // 'length - transactionIdVarOffset' will be the length of '1234'. |
| 144 | if ((length <= (transactionIdVarOffset)) || |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 145 | (transactionIdStr.compare(0, transactionIdStr.size(), |
Adriana Kobylak | 27c87d9 | 2017-03-06 12:45:09 -0600 | [diff] [blame] | 146 | data + transactionIdVarOffset, |
| 147 | length - transactionIdVarOffset) != 0)) |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 148 | { |
| 149 | // The value of the TRANSACTION_ID metadata is not the requested |
| 150 | // transaction id number. |
| 151 | continue; |
| 152 | } |
| 153 | |
| 154 | // Search for all metadata variables in the current journal entry. |
| 155 | for (auto i = metalist.cbegin(); i != metalist.cend();) |
| 156 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 157 | rc = sd_journal_get_data(j, (*i).c_str(), (const void**)&data, |
| 158 | &length); |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 159 | if (rc < 0) |
| 160 | { |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 161 | // Metadata variable not found, check next metadata variable. |
| 162 | i++; |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 163 | continue; |
| 164 | } |
| 165 | |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 166 | // Metadata variable found, save it and remove it from the set. |
| 167 | additionalData.emplace_back(data, length); |
| 168 | i = metalist.erase(i); |
| 169 | } |
| 170 | if (metalist.empty()) |
| 171 | { |
| 172 | // All metadata variables found, break out of journal loop. |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 173 | break; |
| 174 | } |
Adriana Kobylak | fbe8872 | 2017-02-22 16:49:59 -0600 | [diff] [blame] | 175 | } |
| 176 | if (!metalist.empty()) |
| 177 | { |
| 178 | // Not all the metadata variables were found in the journal. |
| 179 | for (auto& metaVarStr : metalist) |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 180 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 181 | logging::log<logging::level::INFO>( |
| 182 | "Failed to find metadata", |
| 183 | logging::entry("META_FIELD=%s", metaVarStr.c_str())); |
Adriana Kobylak | 9aa7d78 | 2017-02-18 09:20:49 -0600 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
Adriana Kobylak | d311bc8 | 2016-10-16 09:54:40 -0500 | [diff] [blame] | 187 | sd_journal_close(j); |
| 188 | |
Matt Spinler | b60e755 | 2019-07-24 15:28:08 -0500 | [diff] [blame] | 189 | createEntry(errMsg, errLvl, additionalData); |
| 190 | } |
| 191 | |
| 192 | void Manager::createEntry(std::string errMsg, Entry::Level errLvl, |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 193 | std::vector<std::string> additionalData, |
| 194 | const FFDCEntries& ffdc) |
Matt Spinler | b60e755 | 2019-07-24 15:28:08 -0500 | [diff] [blame] | 195 | { |
| 196 | if (!Extensions::disableDefaultLogCaps()) |
| 197 | { |
| 198 | if (errLvl < Entry::sevLowerLimit) |
| 199 | { |
| 200 | if (realErrors.size() >= ERROR_CAP) |
| 201 | { |
| 202 | erase(realErrors.front()); |
| 203 | } |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | if (infoErrors.size() >= ERROR_INFO_CAP) |
| 208 | { |
| 209 | erase(infoErrors.front()); |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
Adriana Kobylak | 4ea7f31 | 2017-01-10 12:52:34 -0600 | [diff] [blame] | 214 | entryId++; |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 215 | if (errLvl >= Entry::sevLowerLimit) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 216 | { |
| 217 | infoErrors.push_back(entryId); |
| 218 | } |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 219 | else |
| 220 | { |
| 221 | realErrors.push_back(entryId); |
| 222 | } |
Adriana Kobylak | c5f0bbd | 2017-01-22 14:56:04 -0600 | [diff] [blame] | 223 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 224 | std::chrono::system_clock::now().time_since_epoch()) |
| 225 | .count(); |
| 226 | auto objPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entryId); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 227 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 228 | AssociationList objects{}; |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 229 | processMetadata(errMsg, additionalData, objects); |
| 230 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 231 | auto e = std::make_unique<Entry>(busLog, objPath, entryId, |
| 232 | ms, // Milliseconds since 1970 |
| 233 | errLvl, std::move(errMsg), |
| 234 | std::move(additionalData), |
| 235 | std::move(objects), fwVersion, *this); |
Adriana Kobylak | 1ff95ef | 2020-12-03 13:52:19 -0600 | [diff] [blame] | 236 | auto path = serialize(*e); |
| 237 | e->path(path); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 238 | |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 239 | if (isQuiesceOnErrorEnabled() && isCalloutPresent(*e)) |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 240 | { |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 241 | quiesceOnError(entryId); |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 242 | } |
| 243 | |
Adriana Kobylak | e7d271a | 2020-12-07 14:32:44 -0600 | [diff] [blame] | 244 | // Add entry before calling the extensions so that they have access to it |
| 245 | entries.insert(std::make_pair(entryId, std::move(e))); |
| 246 | |
| 247 | doExtensionLogCreate(*entries.find(entryId)->second, ffdc); |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 248 | |
| 249 | // Note: No need to close the file descriptors in the FFDC. |
Adriana Kobylak | 1db1bd3 | 2016-10-10 11:39:20 -0500 | [diff] [blame] | 250 | } |
| 251 | |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 252 | bool Manager::isQuiesceOnErrorEnabled() |
| 253 | { |
| 254 | std::variant<bool> property; |
| 255 | |
| 256 | auto method = this->busLog.new_method_call( |
| 257 | "xyz.openbmc_project.Settings", "/xyz/openbmc_project/logging/settings", |
| 258 | "org.freedesktop.DBus.Properties", "Get"); |
| 259 | |
| 260 | method.append("xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError"); |
| 261 | |
| 262 | try |
| 263 | { |
| 264 | auto reply = this->busLog.call(method); |
| 265 | reply.read(property); |
| 266 | } |
| 267 | catch (const SdBusError& e) |
| 268 | { |
| 269 | log<level::ERR>("Error reading QuiesceOnHwError property", |
| 270 | entry("ERROR=%s", e.what())); |
| 271 | throw; |
| 272 | } |
| 273 | |
| 274 | return std::get<bool>(property); |
| 275 | } |
| 276 | |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 277 | bool Manager::isCalloutPresent(const Entry& entry) |
| 278 | { |
| 279 | for (const auto& c : entry.additionalData()) |
| 280 | { |
| 281 | if (c.find("CALLOUT_") != std::string::npos) |
| 282 | { |
| 283 | return true; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | return false; |
| 288 | } |
| 289 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 290 | void Manager::findAndRemoveResolvedBlocks() |
| 291 | { |
| 292 | for (auto& entry : entries) |
| 293 | { |
| 294 | if (entry.second->resolved()) |
| 295 | { |
| 296 | checkAndRemoveBlockingError(entry.first); |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | void Manager::onEntryResolve(sdbusplus::message::message& msg) |
| 302 | { |
| 303 | using Interface = std::string; |
| 304 | using Property = std::string; |
| 305 | using Value = std::string; |
Patrick Williams | 25acc6c | 2020-06-02 11:05:34 -0500 | [diff] [blame] | 306 | using Properties = std::map<Property, std::variant<Value>>; |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 307 | |
| 308 | Interface interface; |
| 309 | Properties properties; |
| 310 | |
| 311 | msg.read(interface, properties); |
| 312 | |
| 313 | for (const auto& p : properties) |
| 314 | { |
| 315 | if (p.first == "Resolved") |
| 316 | { |
| 317 | findAndRemoveResolvedBlocks(); |
| 318 | return; |
| 319 | } |
| 320 | } |
| 321 | } |
| 322 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 323 | void Manager::checkAndQuiesceHost() |
| 324 | { |
| 325 | // First check host state |
| 326 | std::variant<std::string> property; |
| 327 | |
| 328 | auto method = this->busLog.new_method_call( |
| 329 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", |
| 330 | "org.freedesktop.DBus.Properties", "Get"); |
| 331 | |
| 332 | method.append("xyz.openbmc_project.State.Host", "CurrentHostState"); |
| 333 | |
| 334 | try |
| 335 | { |
| 336 | auto reply = this->busLog.call(method); |
| 337 | reply.read(property); |
| 338 | } |
| 339 | catch (const SdBusError& e) |
| 340 | { |
| 341 | // Quiescing the host is a "best effort" type function. If unable to |
| 342 | // read the host state or it comes back empty, just return. |
| 343 | // The boot block object will still be created and the associations to |
| 344 | // find the log will be present. Don't want a dependency with |
| 345 | // phosphor-state-manager service |
| 346 | log<level::INFO>("Error reading QuiesceOnHwError property", |
| 347 | entry("ERROR=%s", e.what())); |
| 348 | return; |
| 349 | } |
| 350 | |
| 351 | std::string hostState = std::get<std::string>(property); |
| 352 | |
| 353 | // If host state is empty, do nothing |
| 354 | if (hostState.empty()) |
| 355 | { |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | using Host = sdbusplus::xyz::openbmc_project::State::server::Host; |
| 360 | auto state = Host::convertHostStateFromString(hostState); |
| 361 | if (state != Host::HostState::Running) |
| 362 | { |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | auto quiesce = this->busLog.new_method_call( |
| 367 | "org.freedesktop.systemd1", "/org/freedesktop/systemd1", |
| 368 | "org.freedesktop.systemd1.Manager", "StartUnit"); |
| 369 | |
| 370 | quiesce.append("obmc-host-quiesce@0.target"); |
| 371 | quiesce.append("replace"); |
| 372 | |
| 373 | this->busLog.call_noreply(quiesce); |
| 374 | } |
| 375 | |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 376 | void Manager::quiesceOnError(const uint32_t entryId) |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 377 | { |
Andrew Geissler | 72a1cca | 2020-09-10 16:49:09 -0500 | [diff] [blame] | 378 | // Verify we don't already have this entry blocking |
| 379 | auto it = find_if( |
| 380 | this->blockingErrors.begin(), this->blockingErrors.end(), |
| 381 | [&](std::unique_ptr<Block>& obj) { return obj->entryId == entryId; }); |
| 382 | if (it != this->blockingErrors.end()) |
| 383 | { |
| 384 | // Already recorded so just return |
| 385 | logging::log<logging::level::DEBUG>( |
| 386 | "QuiesceOnError set and callout present but entry already logged"); |
| 387 | return; |
| 388 | } |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 389 | |
Andrew Geissler | e4960ee | 2020-03-30 14:31:52 -0500 | [diff] [blame] | 390 | logging::log<logging::level::INFO>( |
| 391 | "QuiesceOnError set and callout present"); |
Andrew Geissler | 6a0ef6f | 2020-04-06 15:06:31 -0500 | [diff] [blame] | 392 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 393 | auto blockPath = |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 394 | std::string(OBJ_LOGGING) + "/block" + std::to_string(entryId); |
| 395 | auto blockObj = std::make_unique<Block>(this->busLog, blockPath, entryId); |
Andrew Geissler | 6a0ef6f | 2020-04-06 15:06:31 -0500 | [diff] [blame] | 396 | this->blockingErrors.push_back(std::move(blockObj)); |
| 397 | |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 398 | // Register call back if log is resolved |
| 399 | using namespace sdbusplus::bus::match::rules; |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 400 | auto entryPath = std::string(OBJ_ENTRY) + '/' + std::to_string(entryId); |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 401 | auto callback = std::make_unique<sdbusplus::bus::match::match>( |
| 402 | this->busLog, |
| 403 | propertiesChanged(entryPath, "xyz.openbmc_project.Logging.Entry"), |
| 404 | std::bind(std::mem_fn(&Manager::onEntryResolve), this, |
| 405 | std::placeholders::_1)); |
| 406 | |
| 407 | propChangedEntryCallback.insert( |
Andrew Geissler | 3287454 | 2020-07-09 09:17:03 -0500 | [diff] [blame] | 408 | std::make_pair(entryId, std::move(callback))); |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 409 | |
Andrew Geissler | f6126a7 | 2020-05-08 10:41:09 -0500 | [diff] [blame] | 410 | checkAndQuiesceHost(); |
Andrew Geissler | c0c500e | 2020-03-26 11:08:56 -0500 | [diff] [blame] | 411 | } |
| 412 | |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 413 | void Manager::doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 414 | { |
| 415 | // Make the association <endpointpath>/<endpointtype> paths |
| 416 | std::vector<std::string> assocs; |
| 417 | for (const auto& [forwardType, reverseType, endpoint] : |
| 418 | entry.associations()) |
| 419 | { |
| 420 | std::string e{endpoint}; |
| 421 | e += '/' + reverseType; |
| 422 | assocs.push_back(e); |
| 423 | } |
| 424 | |
| 425 | for (auto& create : Extensions::getCreateFunctions()) |
| 426 | { |
| 427 | try |
| 428 | { |
| 429 | create(entry.message(), entry.id(), entry.timestamp(), |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 430 | entry.severity(), entry.additionalData(), assocs, ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 431 | } |
| 432 | catch (std::exception& e) |
| 433 | { |
| 434 | log<level::ERR>("An extension's create function threw an exception", |
| 435 | phosphor::logging::entry("ERROR=%s", e.what())); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | |
Patrick Williams | f40323d | 2021-04-16 15:35:17 -0500 | [diff] [blame] | 440 | void Manager::processMetadata(const std::string& /*errorName*/, |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 441 | const std::vector<std::string>& additionalData, |
| 442 | AssociationList& objects) const |
| 443 | { |
| 444 | // additionalData is a list of "metadata=value" |
| 445 | constexpr auto separator = '='; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 446 | for (const auto& entryItem : additionalData) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 447 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 448 | auto found = entryItem.find(separator); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 449 | if (std::string::npos != found) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 450 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 451 | auto metadata = entryItem.substr(0, found); |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 452 | auto iter = meta.find(metadata); |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 453 | if (meta.end() != iter) |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 454 | { |
| 455 | (iter->second)(metadata, additionalData, objects); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 461 | void Manager::checkAndRemoveBlockingError(uint32_t entryId) |
| 462 | { |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 463 | // First look for blocking object and remove |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 464 | auto it = find_if( |
| 465 | blockingErrors.begin(), blockingErrors.end(), |
| 466 | [&](std::unique_ptr<Block>& obj) { return obj->entryId == entryId; }); |
| 467 | if (it != blockingErrors.end()) |
| 468 | { |
| 469 | blockingErrors.erase(it); |
| 470 | } |
Andrew Geissler | 7f6d4bc | 2020-04-16 14:47:34 -0500 | [diff] [blame] | 471 | |
| 472 | // Now remove the callback looking for the error to be resolved |
| 473 | auto resolveFind = propChangedEntryCallback.find(entryId); |
| 474 | if (resolveFind != propChangedEntryCallback.end()) |
| 475 | { |
| 476 | propChangedEntryCallback.erase(resolveFind); |
| 477 | } |
| 478 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 479 | return; |
| 480 | } |
| 481 | |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 482 | void Manager::erase(uint32_t entryId) |
| 483 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 484 | auto entryFound = entries.find(entryId); |
| 485 | if (entries.end() != entryFound) |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 486 | { |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 487 | for (auto& func : Extensions::getDeleteProhibitedFunctions()) |
| 488 | { |
| 489 | try |
| 490 | { |
| 491 | bool prohibited = false; |
| 492 | func(entryId, prohibited); |
| 493 | if (prohibited) |
| 494 | { |
| 495 | // Future work remains to throw an error here. |
| 496 | return; |
| 497 | } |
| 498 | } |
| 499 | catch (std::exception& e) |
| 500 | { |
| 501 | log<level::ERR>( |
| 502 | "An extension's deleteProhibited function threw " |
| 503 | "an exception", |
| 504 | entry("ERROR=%s", e.what())); |
| 505 | } |
| 506 | } |
| 507 | |
Deepak Kodihalli | 3388799 | 2017-06-13 07:06:49 -0500 | [diff] [blame] | 508 | // Delete the persistent representation of this error. |
| 509 | fs::path errorPath(ERRLOG_PERSIST_PATH); |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 510 | errorPath /= std::to_string(entryId); |
Deepak Kodihalli | 3388799 | 2017-06-13 07:06:49 -0500 | [diff] [blame] | 511 | fs::remove(errorPath); |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 512 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 513 | auto removeId = [](std::list<uint32_t>& ids, uint32_t id) { |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 514 | auto it = std::find(ids.begin(), ids.end(), id); |
| 515 | if (it != ids.end()) |
| 516 | { |
| 517 | ids.erase(it); |
| 518 | } |
| 519 | }; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 520 | if (entryFound->second->severity() >= Entry::sevLowerLimit) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 521 | { |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 522 | removeId(infoErrors, entryId); |
| 523 | } |
| 524 | else |
| 525 | { |
| 526 | removeId(realErrors, entryId); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 527 | } |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 528 | entries.erase(entryFound); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 529 | |
Andrew Geissler | ced6e2a | 2020-04-07 16:15:29 -0500 | [diff] [blame] | 530 | checkAndRemoveBlockingError(entryId); |
| 531 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 532 | for (auto& remove : Extensions::getDeleteFunctions()) |
| 533 | { |
| 534 | try |
| 535 | { |
| 536 | remove(entryId); |
| 537 | } |
| 538 | catch (std::exception& e) |
| 539 | { |
| 540 | log<level::ERR>("An extension's delete function threw an " |
| 541 | "exception", |
| 542 | entry("ERROR=%s", e.what())); |
| 543 | } |
| 544 | } |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 545 | } |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 546 | else |
| 547 | { |
| 548 | logging::log<level::ERR>("Invalid entry ID to delete", |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 549 | logging::entry("ID=%d", entryId)); |
Marri Devender Rao | 8959efc | 2017-11-17 00:13:41 -0600 | [diff] [blame] | 550 | } |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 551 | } |
| 552 | |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 553 | void Manager::restore() |
| 554 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 555 | auto sanity = [](const auto& id, const auto& restoredId) { |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 556 | return id == restoredId; |
| 557 | }; |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 558 | std::vector<uint32_t> errorIds; |
| 559 | |
| 560 | fs::path dir(ERRLOG_PERSIST_PATH); |
| 561 | if (!fs::exists(dir) || fs::is_empty(dir)) |
| 562 | { |
| 563 | return; |
| 564 | } |
| 565 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 566 | for (auto& file : fs::directory_iterator(dir)) |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 567 | { |
| 568 | auto id = file.path().filename().c_str(); |
| 569 | auto idNum = std::stol(id); |
| 570 | auto e = std::make_unique<Entry>( |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 571 | busLog, std::string(OBJ_ENTRY) + '/' + id, idNum, *this); |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 572 | if (deserialize(file.path(), *e)) |
| 573 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 574 | // validate the restored error entry id |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 575 | if (sanity(static_cast<uint32_t>(idNum), e->id())) |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 576 | { |
Adriana Kobylak | 1ff95ef | 2020-12-03 13:52:19 -0600 | [diff] [blame] | 577 | e->path(file.path()); |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 578 | e->emit_object_added(); |
| 579 | if (e->severity() >= Entry::sevLowerLimit) |
| 580 | { |
| 581 | infoErrors.push_back(idNum); |
| 582 | } |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 583 | else |
| 584 | { |
| 585 | realErrors.push_back(idNum); |
| 586 | } |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 587 | |
| 588 | entries.insert(std::make_pair(idNum, std::move(e))); |
| 589 | errorIds.push_back(idNum); |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 590 | } |
Marri Devender Rao | 979ed1c | 2017-11-17 05:06:25 -0600 | [diff] [blame] | 591 | else |
| 592 | { |
| 593 | logging::log<logging::level::ERR>( |
| 594 | "Failed in sanity check while restoring error entry. " |
| 595 | "Ignoring error entry", |
| 596 | logging::entry("ID_NUM=%d", idNum), |
| 597 | logging::entry("ENTRY_ID=%d", e->id())); |
| 598 | } |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Vishwanatha Subbanna | 37af9ba | 2017-09-28 16:33:53 +0530 | [diff] [blame] | 602 | if (!errorIds.empty()) |
| 603 | { |
| 604 | entryId = *(std::max_element(errorIds.begin(), errorIds.end())); |
| 605 | } |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 606 | } |
| 607 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 608 | void Manager::journalSync() |
| 609 | { |
| 610 | bool syncRequested = false; |
| 611 | auto fd = -1; |
| 612 | auto rc = -1; |
| 613 | auto wd = -1; |
| 614 | auto bus = sdbusplus::bus::new_default(); |
| 615 | |
| 616 | auto start = |
| 617 | duration_cast<microseconds>(steady_clock::now().time_since_epoch()) |
| 618 | .count(); |
| 619 | |
Matthew Barth | 5991389 | 2019-08-27 15:43:48 -0500 | [diff] [blame] | 620 | // Each time an error log is committed, a request to sync the journal |
| 621 | // must occur and block that error log commit until it completes. A 5sec |
| 622 | // block is done to allow sufficient time for the journal to be synced. |
| 623 | // |
| 624 | // Number of loop iterations = 3 for the following reasons: |
| 625 | // Iteration #1: Requests a journal sync by killing the journald service. |
| 626 | // Iteration #2: Setup an inotify watch to monitor the synced file that |
| 627 | // journald updates with the timestamp the last time the |
| 628 | // journal was flushed. |
| 629 | // Iteration #3: Poll to wait until inotify reports an event which blocks |
| 630 | // the error log from being commited until the sync completes. |
| 631 | constexpr auto maxRetry = 3; |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 632 | for (int i = 0; i < maxRetry; i++) |
| 633 | { |
| 634 | // Read timestamp from synced file |
| 635 | constexpr auto syncedPath = "/run/systemd/journal/synced"; |
| 636 | std::ifstream syncedFile(syncedPath); |
| 637 | if (syncedFile.fail()) |
| 638 | { |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 639 | // If the synced file doesn't exist, a sync request will create it. |
| 640 | if (errno != ENOENT) |
| 641 | { |
| 642 | log<level::ERR>("Failed to open journal synced file", |
| 643 | entry("FILENAME=%s", syncedPath), |
| 644 | entry("ERRNO=%d", errno)); |
| 645 | return; |
| 646 | } |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 647 | } |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 648 | else |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 649 | { |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 650 | // Only read the synced file if it exists. |
| 651 | // See if a sync happened by now |
| 652 | std::string timestampStr; |
| 653 | std::getline(syncedFile, timestampStr); |
Patrick Venture | 30047bf | 2018-11-01 18:52:15 -0700 | [diff] [blame] | 654 | auto timestamp = std::stoll(timestampStr); |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 655 | if (timestamp >= start) |
| 656 | { |
Troy Lee | b7f392a | 2019-11-19 14:34:56 +0800 | [diff] [blame] | 657 | break; |
Adriana Kobylak | 7d111a8 | 2018-09-04 10:14:24 -0500 | [diff] [blame] | 658 | } |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | // Let's ask for a sync, but only once |
| 662 | if (!syncRequested) |
| 663 | { |
| 664 | syncRequested = true; |
| 665 | |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 666 | constexpr auto JOURNAL_UNIT = "systemd-journald.service"; |
| 667 | auto signal = SIGRTMIN + 1; |
| 668 | |
| 669 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 670 | SYSTEMD_INTERFACE, "KillUnit"); |
| 671 | method.append(JOURNAL_UNIT, "main", signal); |
| 672 | bus.call(method); |
| 673 | if (method.is_method_error()) |
| 674 | { |
| 675 | log<level::ERR>("Failed to kill journal service"); |
Troy Lee | b7f392a | 2019-11-19 14:34:56 +0800 | [diff] [blame] | 676 | break; |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 677 | } |
| 678 | continue; |
| 679 | } |
| 680 | |
| 681 | // Let's install the inotify watch, if we didn't do that yet. This watch |
| 682 | // monitors the syncedFile for when journald updates it with a newer |
| 683 | // timestamp. This means the journal has been flushed. |
| 684 | if (fd < 0) |
| 685 | { |
| 686 | fd = inotify_init1(IN_NONBLOCK | IN_CLOEXEC); |
| 687 | if (fd < 0) |
| 688 | { |
| 689 | log<level::ERR>("Failed to create inotify watch", |
| 690 | entry("ERRNO=%d", errno)); |
| 691 | return; |
| 692 | } |
| 693 | |
| 694 | constexpr auto JOURNAL_RUN_PATH = "/run/systemd/journal"; |
| 695 | wd = inotify_add_watch(fd, JOURNAL_RUN_PATH, |
| 696 | IN_MOVED_TO | IN_DONT_FOLLOW | IN_ONLYDIR); |
| 697 | if (wd < 0) |
| 698 | { |
| 699 | log<level::ERR>("Failed to watch journal directory", |
| 700 | entry("PATH=%s", JOURNAL_RUN_PATH), |
| 701 | entry("ERRNO=%d", errno)); |
| 702 | close(fd); |
| 703 | return; |
| 704 | } |
| 705 | continue; |
| 706 | } |
| 707 | |
| 708 | // Let's wait until inotify reports an event |
| 709 | struct pollfd fds = { |
| 710 | .fd = fd, |
| 711 | .events = POLLIN, |
Patrick Williams | f40323d | 2021-04-16 15:35:17 -0500 | [diff] [blame] | 712 | .revents = 0, |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 713 | }; |
| 714 | constexpr auto pollTimeout = 5; // 5 seconds |
| 715 | rc = poll(&fds, 1, pollTimeout * 1000); |
| 716 | if (rc < 0) |
| 717 | { |
| 718 | log<level::ERR>("Failed to add event", entry("ERRNO=%d", errno), |
| 719 | entry("ERR=%s", strerror(-rc))); |
| 720 | inotify_rm_watch(fd, wd); |
| 721 | close(fd); |
| 722 | return; |
| 723 | } |
| 724 | else if (rc == 0) |
| 725 | { |
| 726 | log<level::INFO>("Poll timeout, no new journal synced data", |
| 727 | entry("TIMEOUT=%d", pollTimeout)); |
| 728 | break; |
| 729 | } |
| 730 | |
| 731 | // Read from the specified file descriptor until there is no new data, |
| 732 | // throwing away everything read since the timestamp will be read at the |
| 733 | // beginning of the loop. |
| 734 | constexpr auto maxBytes = 64; |
| 735 | uint8_t buffer[maxBytes]; |
| 736 | while (read(fd, buffer, maxBytes) > 0) |
| 737 | ; |
| 738 | } |
| 739 | |
Adriana Kobylak | 4a029f2 | 2018-05-23 12:58:19 -0500 | [diff] [blame] | 740 | if (fd != -1) |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 741 | { |
Adriana Kobylak | 4a029f2 | 2018-05-23 12:58:19 -0500 | [diff] [blame] | 742 | if (wd != -1) |
| 743 | { |
| 744 | inotify_rm_watch(fd, wd); |
| 745 | } |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 746 | close(fd); |
| 747 | } |
| 748 | |
| 749 | return; |
| 750 | } |
| 751 | |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 752 | std::string Manager::readFWVersion() |
| 753 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 754 | auto version = util::getOSReleaseValue("VERSION_ID"); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 755 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 756 | if (!version) |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 757 | { |
| 758 | log<level::ERR>("Unable to read BMC firmware version"); |
| 759 | } |
| 760 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 761 | return version.value_or(""); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 762 | } |
| 763 | |
Matt Spinler | 3fb83b3 | 2019-07-26 11:22:44 -0500 | [diff] [blame] | 764 | void Manager::create(const std::string& message, Entry::Level severity, |
| 765 | const std::map<std::string, std::string>& additionalData) |
| 766 | { |
| 767 | // Convert the map into a vector of "key=value" strings |
| 768 | std::vector<std::string> ad; |
| 769 | metadata::associations::combine(additionalData, ad); |
| 770 | |
| 771 | createEntry(message, severity, ad); |
| 772 | } |
| 773 | |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 774 | void Manager::createWithFFDC( |
| 775 | const std::string& message, Entry::Level severity, |
| 776 | const std::map<std::string, std::string>& additionalData, |
| 777 | const FFDCEntries& ffdc) |
| 778 | { |
| 779 | // Convert the map into a vector of "key=value" strings |
| 780 | std::vector<std::string> ad; |
| 781 | metadata::associations::combine(additionalData, ad); |
| 782 | |
| 783 | createEntry(message, severity, ad, ffdc); |
| 784 | } |
| 785 | |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 786 | } // namespace internal |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 787 | } // namespace logging |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 788 | } // namespace phosphor |