blob: e47d6b54b7fe27d1932650002d980bc60b654270 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#pragma once
2
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -05003#include "elog_block.hpp"
Adriana Kobylakdf995fa2017-01-08 15:14:02 -06004#include "elog_entry.hpp"
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -05005#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Matt Spinler3fb83b32019-07-26 11:22:44 -05006#include "xyz/openbmc_project/Logging/Create/server.hpp"
7#include "xyz/openbmc_project/Logging/Entry/server.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07008#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +08009#include "xyz/openbmc_project/Logging/error.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -070010
Patrick Venturef18bf832018-10-26 18:14:00 -070011#include <phosphor-logging/log.hpp>
12#include <sdbusplus/bus.hpp>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060013
Patrick Williams2544b412022-10-04 08:41:06 -050014#include <list>
15
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060016namespace phosphor
17{
18namespace logging
19{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060020
Patrick Venturef18bf832018-10-26 18:14:00 -070021extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
22extern const std::map<std::string, level> g_errLevelMap;
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060023
Willy Tu6ddbf692023-09-05 10:54:16 -070024using CreateIface = sdbusplus::server::xyz::openbmc_project::logging::Create;
Matt Spinler3fb83b32019-07-26 11:22:44 -050025using DeleteAllIface =
Willy Tu6ddbf692023-09-05 10:54:16 -070026 sdbusplus::server::xyz::openbmc_project::collection::DeleteAll;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050027
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +080028using Severity = sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level;
29using LogsCleared =
30 sdbusplus::xyz::openbmc_project::Logging::Error::LogsCleared;
31
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060032namespace details
33{
Matt Spinler3fb83b32019-07-26 11:22:44 -050034template <typename... T>
Patrick Williams45e83522022-07-22 19:26:52 -050035using ServerObject = typename sdbusplus::server::object_t<T...>;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060036
37using ManagerIface =
Willy Tu6ddbf692023-09-05 10:54:16 -070038 sdbusplus::server::xyz::openbmc_project::logging::internal::Manager;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060039
40} // namespace details
41
Matt Spinlerc64b7122020-03-26 10:55:01 -050042constexpr size_t ffdcFormatPos = 0;
43constexpr size_t ffdcSubtypePos = 1;
44constexpr size_t ffdcVersionPos = 2;
45constexpr size_t ffdcFDPos = 3;
46
47using FFDCEntry = std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
48 sdbusplus::message::unix_fd>;
49
50using FFDCEntries = std::vector<FFDCEntry>;
51
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050052namespace internal
53{
54
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060055/** @class Manager
56 * @brief OpenBMC logging manager implementation.
57 * @details A concrete implementation for the
58 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
59 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060060class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060061{
Patrick Venturef18bf832018-10-26 18:14:00 -070062 public:
63 Manager() = delete;
64 Manager(const Manager&) = delete;
65 Manager& operator=(const Manager&) = delete;
66 Manager(Manager&&) = delete;
67 Manager& operator=(Manager&&) = delete;
68 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060069
Patrick Venturef18bf832018-10-26 18:14:00 -070070 /** @brief Constructor to put object onto bus at a dbus path.
71 * @param[in] bus - Bus to attach to.
72 * @param[in] path - Path to attach at.
73 */
Patrick Williams45e83522022-07-22 19:26:52 -050074 Manager(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Venturef18bf832018-10-26 18:14:00 -070075 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
76 entryId(0), fwVersion(readFWVersion()){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060077
Patrick Venturef18bf832018-10-26 18:14:00 -070078 /*
79 * @fn commit()
80 * @brief sd_bus Commit method implementation callback.
81 * @details Create an error/event log based on transaction id and
82 * error message.
83 * @param[in] transactionId - Unique identifier of the journal entries
84 * to be committed.
85 * @param[in] errMsg - The error exception message associated with the
86 * error log to be committed.
87 */
Lei YUb50c7052021-01-21 16:02:26 +080088 uint32_t commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060089
Patrick Venturef18bf832018-10-26 18:14:00 -070090 /*
91 * @fn commit()
92 * @brief sd_bus CommitWithLvl method implementation callback.
93 * @details Create an error/event log based on transaction id and
94 * error message.
95 * @param[in] transactionId - Unique identifier of the journal entries
96 * to be committed.
97 * @param[in] errMsg - The error exception message associated with the
98 * error log to be committed.
99 * @param[in] errLvl - level of the error
100 */
Lei YUb50c7052021-01-21 16:02:26 +0800101 uint32_t commitWithLvl(uint64_t transactionId, std::string errMsg,
102 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600103
Patrick Venturef18bf832018-10-26 18:14:00 -0700104 /** @brief Erase specified entry d-bus object
105 *
106 * @param[in] entryId - unique identifier of the entry
107 */
108 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -0500109
Patrick Venturef18bf832018-10-26 18:14:00 -0700110 /** @brief Construct error d-bus objects from their persisted
111 * representations.
112 */
113 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500114
Patrick Venturef18bf832018-10-26 18:14:00 -0700115 /** @brief Erase all error log entries
116 *
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800117 * @return size_t - count of erased entries
Patrick Venturef18bf832018-10-26 18:14:00 -0700118 */
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800119 size_t eraseAll()
Patrick Venturef18bf832018-10-26 18:14:00 -0700120 {
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800121 size_t entriesSize = entries.size();
Patrick Venturef18bf832018-10-26 18:14:00 -0700122 auto iter = entries.begin();
123 while (iter != entries.end())
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500124 {
Patrick Venture34438962018-10-30 13:17:37 -0700125 auto e = iter->first;
Patrick Venturef18bf832018-10-26 18:14:00 -0700126 ++iter;
Patrick Venture34438962018-10-30 13:17:37 -0700127 erase(e);
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500128 }
Lotus Xud091a572021-05-24 13:59:21 +0800129 entryId = 0;
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800130
131 return entriesSize;
Patrick Venturef18bf832018-10-26 18:14:00 -0700132 }
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500133
Patrick Venturef18bf832018-10-26 18:14:00 -0700134 /** @brief Returns the count of high severity errors
135 *
136 * @return int - count of real errors
137 */
138 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500139
Patrick Venturef18bf832018-10-26 18:14:00 -0700140 /** @brief Returns the count of Info errors
141 *
142 * @return int - count of info errors
143 */
144 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500145
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500146 /** @brief Returns the number of blocking errors
147 *
148 * @return int - count of blocking errors
149 */
150 int getBlockingErrSize()
151 {
152 return blockingErrors.size();
153 }
154
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500155 /** @brief Returns the number of property change callback objects
156 *
157 * @return int - count of property callback entries
158 */
159 int getEntryCallbackSize()
160 {
161 return propChangedEntryCallback.size();
162 }
163
Matt Spinler44893cc2020-08-26 11:34:17 -0500164 /**
165 * @brief Returns the sdbusplus bus object
166 *
Patrick Williams45e83522022-07-22 19:26:52 -0500167 * @return sdbusplus::bus_t&
Matt Spinler44893cc2020-08-26 11:34:17 -0500168 */
Patrick Williams45e83522022-07-22 19:26:52 -0500169 sdbusplus::bus_t& getBus()
Matt Spinler8ebfd312019-06-03 12:43:59 -0500170 {
171 return busLog;
172 }
173
Matt Spinler44893cc2020-08-26 11:34:17 -0500174 /**
175 * @brief Returns the ID of the last created entry
176 *
177 * @return uint32_t - The ID
178 */
179 uint32_t lastEntryID() const
180 {
181 return entryId;
182 }
183
Matt Spinler3fb83b32019-07-26 11:22:44 -0500184 /** @brief Creates an event log
185 *
186 * This is an alternative to the _commit() API. It doesn't use
187 * the journal to look up event log metadata like _commit does.
188 *
189 * @param[in] errMsg - The error exception message associated with the
190 * error log to be committed.
191 * @param[in] severity - level of the error
192 * @param[in] additionalData - The AdditionalData property for the error
Paul Fertser221b79b2024-03-04 15:40:23 +0000193 * @param[in] ffdc - A vector of tuples that allows one to pass in file
194 * descriptors for files that contain FFDC (First
195 * Failure Data Capture). These will be passed to any
196 * event logging extensions.
Matt Spinler3fb83b32019-07-26 11:22:44 -0500197 */
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800198 void create(const std::string& message, Severity severity,
Paul Fertser221b79b2024-03-04 15:40:23 +0000199 const std::map<std::string, std::string>& additionalData,
200 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerc64b7122020-03-26 10:55:01 -0500201
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500202 /** @brief Common wrapper for creating an Entry object
203 *
204 * @return true if quiesce on error setting is enabled, false otherwise
205 */
206 bool isQuiesceOnErrorEnabled();
207
Andrew Geissler32874542020-07-09 09:17:03 -0500208 /** @brief Create boot block association and quiesce host if running
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500209 *
Andrew Geissler32874542020-07-09 09:17:03 -0500210 * @param[in] entryId - The ID of the phosphor logging error
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500211 */
Andrew Geissler32874542020-07-09 09:17:03 -0500212 void quiesceOnError(const uint32_t entryId);
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500213
Andrew Geisslere4960ee2020-03-30 14:31:52 -0500214 /** @brief Check if inventory callout present in input entry
215 *
216 * @param[in] entry - The error to check for callouts
217 *
218 * @return true if inventory item in associations, false otherwise
219 */
220 bool isCalloutPresent(const Entry& entry);
221
Andrew Geisslerced6e2a2020-04-07 16:15:29 -0500222 /** @brief Check (and remove) entry being erased from blocking errors
223 *
224 * @param[in] entryId - The entry that is being erased
225 */
226 void checkAndRemoveBlockingError(uint32_t entryId);
227
Adriana Kobylake7d271a2020-12-07 14:32:44 -0600228 /** @brief Persistent map of Entry dbus objects and their ID */
229 std::map<uint32_t, std::unique_ptr<Entry>> entries;
230
Patrick Venturef18bf832018-10-26 18:14:00 -0700231 private:
232 /*
233 * @fn _commit()
234 * @brief commit() helper
235 * @param[in] transactionId - Unique identifier of the journal entries
236 * to be committed.
237 * @param[in] errMsg - The error exception message associated with the
238 * error log to be committed.
239 * @param[in] errLvl - level of the error
240 */
241 void _commit(uint64_t transactionId, std::string&& errMsg,
242 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500243
Patrick Venturef18bf832018-10-26 18:14:00 -0700244 /** @brief Call metadata handler(s), if any. Handlers may create
245 * associations.
246 * @param[in] errorName - name of the error
247 * @param[in] additionalData - list of metadata (in key=value format)
248 * @param[out] objects - list of error's association objects
249 */
250 void processMetadata(const std::string& errorName,
251 const std::vector<std::string>& additionalData,
252 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600253
Patrick Venturef18bf832018-10-26 18:14:00 -0700254 /** @brief Reads the BMC code level
255 *
256 * @return std::string - the version string
257 */
258 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500259
Matt Spinler99c2b402019-05-23 14:29:16 -0500260 /** @brief Call any create() functions provided by any extensions.
261 * This is called right after an event log is created to allow
262 * extensions to create their own log based on this one.
263 *
264 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500265 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500266 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500267 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500268
Matt Spinlerb60e7552019-07-24 15:28:08 -0500269 /** @brief Common wrapper for creating an Entry object
270 *
271 * @param[in] errMsg - The error exception message associated with the
272 * error log to be committed.
273 * @param[in] errLvl - level of the error
274 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500275 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
276 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500277 */
278 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500279 std::vector<std::string> additionalData,
280 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500281
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500282 /** @brief Notified on entry property changes
283 *
284 * If an entry is blocking, this callback will be registered to monitor for
285 * the entry having it's Resolved field set to true. If it is then remove
286 * the blocking object.
287 *
288 * @param[in] msg - sdbusplus dbusmessage
289 */
Patrick Williams45e83522022-07-22 19:26:52 -0500290 void onEntryResolve(sdbusplus::message_t& msg);
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500291
292 /** @brief Remove block objects for any resolved entries */
293 void findAndRemoveResolvedBlocks();
294
Andrew Geisslerf6126a72020-05-08 10:41:09 -0500295 /** @brief Quiesce host if it is running
296 *
297 * This is called when the user has requested the system be quiesced
298 * if a log with a callout is created
299 */
300 void checkAndQuiesceHost();
301
Patrick Venturef18bf832018-10-26 18:14:00 -0700302 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williams45e83522022-07-22 19:26:52 -0500303 sdbusplus::bus_t& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600304
Patrick Venturef18bf832018-10-26 18:14:00 -0700305 /** @brief List of error ids for high severity errors */
306 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600307
Patrick Venturef18bf832018-10-26 18:14:00 -0700308 /** @brief List of error ids for Info(and below) severity */
309 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500310
Patrick Venturef18bf832018-10-26 18:14:00 -0700311 /** @brief Id of last error log entry */
312 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500313
Patrick Venturef18bf832018-10-26 18:14:00 -0700314 /** @brief The BMC firmware version */
315 const std::string fwVersion;
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500316
317 /** @brief Array of blocking errors */
318 std::vector<std::unique_ptr<Block>> blockingErrors;
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500319
320 /** @brief Map of entry id to call back object on properties changed */
Patrick Williams45e83522022-07-22 19:26:52 -0500321 std::map<uint32_t, std::unique_ptr<sdbusplus::bus::match_t>>
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500322 propChangedEntryCallback;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600323};
324
Patrick Venturef18bf832018-10-26 18:14:00 -0700325} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500326
327/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500328 * @brief Implementation for deleting all error log entries and
329 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500330 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500331 * xyz.openbmc_project.Collection.DeleteAll and
332 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500333 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500334class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500335{
Patrick Venturef18bf832018-10-26 18:14:00 -0700336 public:
337 Manager() = delete;
338 Manager(const Manager&) = delete;
339 Manager& operator=(const Manager&) = delete;
340 Manager(Manager&&) = delete;
341 Manager& operator=(Manager&&) = delete;
342 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500343
Patrick Venturef18bf832018-10-26 18:14:00 -0700344 /** @brief Constructor to put object onto bus at a dbus path.
345 * Defer signal registration (pass true for deferSignal to the
346 * base class) until after the properties are set.
347 * @param[in] bus - Bus to attach to.
348 * @param[in] path - Path to attach at.
349 * @param[in] manager - Reference to internal manager object.
350 */
Patrick Williams45e83522022-07-22 19:26:52 -0500351 Manager(sdbusplus::bus_t& bus, const std::string& path,
Patrick Venturef18bf832018-10-26 18:14:00 -0700352 internal::Manager& manager) :
Patrick Williams6ef6b252022-03-30 14:28:27 -0500353 details::ServerObject<DeleteAllIface, CreateIface>(
354 bus, path.c_str(),
355 details::ServerObject<DeleteAllIface,
356 CreateIface>::action::defer_emit),
Patrick Venturef18bf832018-10-26 18:14:00 -0700357 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500358
Patrick Venturef18bf832018-10-26 18:14:00 -0700359 /** @brief Delete all d-bus objects.
360 */
Patrick Williamsec4eaea2021-08-28 15:10:15 -0500361 void deleteAll() override
Patrick Venturef18bf832018-10-26 18:14:00 -0700362 {
Matt Spinlerf6f51232022-03-09 10:11:53 -0600363 log<level::INFO>("Deleting all log entries");
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800364 auto numbersOfLogs = manager.eraseAll();
365 std::map<std::string, std::string> additionalData;
366 additionalData.emplace("NUM_LOGS", std::to_string(numbersOfLogs));
367 manager.create(LogsCleared::errName, Severity::Informational,
368 additionalData);
Patrick Venturef18bf832018-10-26 18:14:00 -0700369 }
370
Matt Spinler3fb83b32019-07-26 11:22:44 -0500371 /** @brief D-Bus method call implementation to create an event log.
372 *
373 * @param[in] errMsg - The error exception message associated with the
374 * error log to be committed.
375 * @param[in] severity - Level of the error
376 * @param[in] additionalData - The AdditionalData property for the error
377 */
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800378 void create(std::string message, Severity severity,
379 std::map<std::string, std::string> additionalData) override
Matt Spinler3fb83b32019-07-26 11:22:44 -0500380 {
381 manager.create(message, severity, additionalData);
382 }
383
Matt Spinlerc64b7122020-03-26 10:55:01 -0500384 /** @brief D-Bus method call implementation to create an event log with FFDC
385 *
386 * The same as create(), but takes an extra FFDC argument.
387 *
388 * @param[in] errMsg - The error exception message associated with the
389 * error log to be committed.
390 * @param[in] severity - Level of the error
391 * @param[in] additionalData - The AdditionalData property for the error
392 * @param[in] ffdc - A vector of FFDC file info
393 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500394 void createWithFFDCFiles(
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800395 std::string message, Severity severity,
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500396 std::map<std::string, std::string> additionalData,
397 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
398 sdbusplus::message::unix_fd>>
399 ffdc) override
400 {
Paul Fertser221b79b2024-03-04 15:40:23 +0000401 manager.create(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500402 }
403
Patrick Venturef18bf832018-10-26 18:14:00 -0700404 private:
405 /** @brief This is a reference to manager object */
406 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500407};
408
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600409} // namespace logging
410} // namespace phosphor