blob: c5b6eb078176b6aa7a15cda48b55882bd2bef271 [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"
Patrick Venturef18bf832018-10-26 18:14:00 -07005#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
6
Patrick Venturef18bf832018-10-26 18:14:00 -07007#include <phosphor-logging/log.hpp>
8#include <sdbusplus/bus.hpp>
Patrick Williams9ca4d132024-10-31 17:02:47 -04009#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
10#include <xyz/openbmc_project/Logging/Create/server.hpp>
11#include <xyz/openbmc_project/Logging/Entry/server.hpp>
12#include <xyz/openbmc_project/Logging/event.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;
Patrick Williams9ca4d132024-10-31 17:02:47 -040029using LoggingCleared = sdbusplus::event::xyz::openbmc_project::Logging::Cleared;
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +080030
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060031namespace details
32{
Matt Spinler3fb83b32019-07-26 11:22:44 -050033template <typename... T>
Patrick Williams45e83522022-07-22 19:26:52 -050034using ServerObject = typename sdbusplus::server::object_t<T...>;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060035
36using ManagerIface =
Willy Tu6ddbf692023-09-05 10:54:16 -070037 sdbusplus::server::xyz::openbmc_project::logging::internal::Manager;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060038
39} // namespace details
40
Matt Spinlerc64b7122020-03-26 10:55:01 -050041constexpr size_t ffdcFormatPos = 0;
42constexpr size_t ffdcSubtypePos = 1;
43constexpr size_t ffdcVersionPos = 2;
44constexpr size_t ffdcFDPos = 3;
45
46using FFDCEntry = std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
47 sdbusplus::message::unix_fd>;
48
49using FFDCEntries = std::vector<FFDCEntry>;
50
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050051namespace internal
52{
53
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060054/** @class Manager
55 * @brief OpenBMC logging manager implementation.
56 * @details A concrete implementation for the
57 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
58 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060059class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060060{
Patrick Venturef18bf832018-10-26 18:14:00 -070061 public:
62 Manager() = delete;
63 Manager(const Manager&) = delete;
64 Manager& operator=(const Manager&) = delete;
65 Manager(Manager&&) = delete;
66 Manager& operator=(Manager&&) = delete;
67 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060068
Patrick Venturef18bf832018-10-26 18:14:00 -070069 /** @brief Constructor to put object onto bus at a dbus path.
70 * @param[in] bus - Bus to attach to.
71 * @param[in] path - Path to attach at.
72 */
Patrick Williams45e83522022-07-22 19:26:52 -050073 Manager(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Venturef18bf832018-10-26 18:14:00 -070074 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
Patrick Williams075c7922024-08-16 15:19:49 -040075 entryId(0), fwVersion(readFWVersion()) {};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060076
Patrick Venturef18bf832018-10-26 18:14:00 -070077 /*
78 * @fn commit()
79 * @brief sd_bus Commit method implementation callback.
80 * @details Create an error/event log based on transaction id and
81 * error message.
82 * @param[in] transactionId - Unique identifier of the journal entries
83 * to be committed.
84 * @param[in] errMsg - The error exception message associated with the
85 * error log to be committed.
86 */
Lei YUb50c7052021-01-21 16:02:26 +080087 uint32_t commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060088
Patrick Venturef18bf832018-10-26 18:14:00 -070089 /*
90 * @fn commit()
91 * @brief sd_bus CommitWithLvl method implementation callback.
92 * @details Create an error/event log based on transaction id and
93 * error message.
94 * @param[in] transactionId - Unique identifier of the journal entries
95 * to be committed.
96 * @param[in] errMsg - The error exception message associated with the
97 * error log to be committed.
98 * @param[in] errLvl - level of the error
99 */
Lei YUb50c7052021-01-21 16:02:26 +0800100 uint32_t commitWithLvl(uint64_t transactionId, std::string errMsg,
101 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600102
Patrick Venturef18bf832018-10-26 18:14:00 -0700103 /** @brief Erase specified entry d-bus object
104 *
105 * @param[in] entryId - unique identifier of the entry
106 */
107 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -0500108
Patrick Venturef18bf832018-10-26 18:14:00 -0700109 /** @brief Construct error d-bus objects from their persisted
110 * representations.
111 */
112 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500113
Patrick Venturef18bf832018-10-26 18:14:00 -0700114 /** @brief Erase all error log entries
115 *
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800116 * @return size_t - count of erased entries
Patrick Venturef18bf832018-10-26 18:14:00 -0700117 */
harsh-agarwal1d763db32024-09-03 09:18:50 -0500118 size_t eraseAll();
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500119
Patrick Venturef18bf832018-10-26 18:14:00 -0700120 /** @brief Returns the count of high severity errors
121 *
122 * @return int - count of real errors
123 */
124 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500125
Patrick Venturef18bf832018-10-26 18:14:00 -0700126 /** @brief Returns the count of Info errors
127 *
128 * @return int - count of info errors
129 */
130 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500131
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500132 /** @brief Returns the number of blocking errors
133 *
134 * @return int - count of blocking errors
135 */
136 int getBlockingErrSize()
137 {
138 return blockingErrors.size();
139 }
140
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500141 /** @brief Returns the number of property change callback objects
142 *
143 * @return int - count of property callback entries
144 */
145 int getEntryCallbackSize()
146 {
147 return propChangedEntryCallback.size();
148 }
149
Matt Spinler44893cc2020-08-26 11:34:17 -0500150 /**
151 * @brief Returns the sdbusplus bus object
152 *
Patrick Williams45e83522022-07-22 19:26:52 -0500153 * @return sdbusplus::bus_t&
Matt Spinler44893cc2020-08-26 11:34:17 -0500154 */
Patrick Williams45e83522022-07-22 19:26:52 -0500155 sdbusplus::bus_t& getBus()
Matt Spinler8ebfd312019-06-03 12:43:59 -0500156 {
157 return busLog;
158 }
159
Matt Spinler44893cc2020-08-26 11:34:17 -0500160 /**
161 * @brief Returns the ID of the last created entry
162 *
163 * @return uint32_t - The ID
164 */
165 uint32_t lastEntryID() const
166 {
167 return entryId;
168 }
169
Matt Spinler3fb83b32019-07-26 11:22:44 -0500170 /** @brief Creates an event log
171 *
172 * This is an alternative to the _commit() API. It doesn't use
173 * the journal to look up event log metadata like _commit does.
174 *
175 * @param[in] errMsg - The error exception message associated with the
176 * error log to be committed.
177 * @param[in] severity - level of the error
178 * @param[in] additionalData - The AdditionalData property for the error
Paul Fertser221b79b2024-03-04 15:40:23 +0000179 * @param[in] ffdc - A vector of tuples that allows one to pass in file
180 * descriptors for files that contain FFDC (First
181 * Failure Data Capture). These will be passed to any
182 * event logging extensions.
Matt Spinler3fb83b32019-07-26 11:22:44 -0500183 */
Patrick Williams597f24a2024-09-27 14:47:42 -0400184 auto create(const std::string& message, Severity severity,
Paul Fertser221b79b2024-03-04 15:40:23 +0000185 const std::map<std::string, std::string>& additionalData,
Patrick Williams597f24a2024-09-27 14:47:42 -0400186 const FFDCEntries& ffdc = FFDCEntries{})
187 -> sdbusplus::message::object_path;
Matt Spinlerc64b7122020-03-26 10:55:01 -0500188
Patrick Williams9ca4d132024-10-31 17:02:47 -0400189 /** @brief Create an internal event log from the sdbusplus generated event
190 *
191 * @param[in] event - The event to create.
192 */
193 auto createFromEvent(sdbusplus::exception::generated_event_base&& event)
194 -> sdbusplus::message::object_path;
195
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500196 /** @brief Common wrapper for creating an Entry object
197 *
198 * @return true if quiesce on error setting is enabled, false otherwise
199 */
200 bool isQuiesceOnErrorEnabled();
201
Andrew Geissler32874542020-07-09 09:17:03 -0500202 /** @brief Create boot block association and quiesce host if running
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500203 *
Andrew Geissler32874542020-07-09 09:17:03 -0500204 * @param[in] entryId - The ID of the phosphor logging error
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500205 */
Andrew Geissler32874542020-07-09 09:17:03 -0500206 void quiesceOnError(const uint32_t entryId);
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500207
Andrew Geisslere4960ee2020-03-30 14:31:52 -0500208 /** @brief Check if inventory callout present in input entry
209 *
210 * @param[in] entry - The error to check for callouts
211 *
212 * @return true if inventory item in associations, false otherwise
213 */
214 bool isCalloutPresent(const Entry& entry);
215
Andrew Geisslerced6e2a2020-04-07 16:15:29 -0500216 /** @brief Check (and remove) entry being erased from blocking errors
217 *
218 * @param[in] entryId - The entry that is being erased
219 */
220 void checkAndRemoveBlockingError(uint32_t entryId);
221
Adriana Kobylake7d271a2020-12-07 14:32:44 -0600222 /** @brief Persistent map of Entry dbus objects and their ID */
223 std::map<uint32_t, std::unique_ptr<Entry>> entries;
224
Patrick Venturef18bf832018-10-26 18:14:00 -0700225 private:
226 /*
227 * @fn _commit()
228 * @brief commit() helper
229 * @param[in] transactionId - Unique identifier of the journal entries
230 * to be committed.
231 * @param[in] errMsg - The error exception message associated with the
232 * error log to be committed.
233 * @param[in] errLvl - level of the error
234 */
235 void _commit(uint64_t transactionId, std::string&& errMsg,
236 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500237
Patrick Venturef18bf832018-10-26 18:14:00 -0700238 /** @brief Call metadata handler(s), if any. Handlers may create
239 * associations.
240 * @param[in] errorName - name of the error
241 * @param[in] additionalData - list of metadata (in key=value format)
242 * @param[out] objects - list of error's association objects
243 */
244 void processMetadata(const std::string& errorName,
245 const std::vector<std::string>& additionalData,
246 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600247
Patrick Venturef18bf832018-10-26 18:14:00 -0700248 /** @brief Reads the BMC code level
249 *
250 * @return std::string - the version string
251 */
252 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500253
Matt Spinler99c2b402019-05-23 14:29:16 -0500254 /** @brief Call any create() functions provided by any extensions.
255 * This is called right after an event log is created to allow
256 * extensions to create their own log based on this one.
257 *
258 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500259 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500260 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500261 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500262
Matt Spinlerb60e7552019-07-24 15:28:08 -0500263 /** @brief Common wrapper for creating an Entry object
264 *
265 * @param[in] errMsg - The error exception message associated with the
266 * error log to be committed.
267 * @param[in] errLvl - level of the error
268 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500269 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
270 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500271 */
Patrick Williams597f24a2024-09-27 14:47:42 -0400272 auto createEntry(std::string errMsg, Entry::Level errLvl,
Patrick Williamsea21d992024-11-22 17:06:35 -0500273 std::map<std::string, std::string> additionalData,
Patrick Williams597f24a2024-09-27 14:47:42 -0400274 const FFDCEntries& ffdc = FFDCEntries{})
275 -> sdbusplus::message::object_path;
Matt Spinlerb60e7552019-07-24 15:28:08 -0500276
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500277 /** @brief Notified on entry property changes
278 *
279 * If an entry is blocking, this callback will be registered to monitor for
280 * the entry having it's Resolved field set to true. If it is then remove
281 * the blocking object.
282 *
283 * @param[in] msg - sdbusplus dbusmessage
284 */
Patrick Williams45e83522022-07-22 19:26:52 -0500285 void onEntryResolve(sdbusplus::message_t& msg);
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500286
287 /** @brief Remove block objects for any resolved entries */
288 void findAndRemoveResolvedBlocks();
289
Andrew Geisslerf6126a72020-05-08 10:41:09 -0500290 /** @brief Quiesce host if it is running
291 *
292 * This is called when the user has requested the system be quiesced
293 * if a log with a callout is created
294 */
295 void checkAndQuiesceHost();
296
Patrick Venturef18bf832018-10-26 18:14:00 -0700297 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williams45e83522022-07-22 19:26:52 -0500298 sdbusplus::bus_t& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600299
Patrick Venturef18bf832018-10-26 18:14:00 -0700300 /** @brief List of error ids for high severity errors */
301 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600302
Patrick Venturef18bf832018-10-26 18:14:00 -0700303 /** @brief List of error ids for Info(and below) severity */
304 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500305
Patrick Venturef18bf832018-10-26 18:14:00 -0700306 /** @brief Id of last error log entry */
307 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500308
Patrick Venturef18bf832018-10-26 18:14:00 -0700309 /** @brief The BMC firmware version */
310 const std::string fwVersion;
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500311
312 /** @brief Array of blocking errors */
313 std::vector<std::unique_ptr<Block>> blockingErrors;
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500314
315 /** @brief Map of entry id to call back object on properties changed */
Patrick Williams45e83522022-07-22 19:26:52 -0500316 std::map<uint32_t, std::unique_ptr<sdbusplus::bus::match_t>>
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500317 propChangedEntryCallback;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600318};
319
Patrick Venturef18bf832018-10-26 18:14:00 -0700320} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500321
322/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500323 * @brief Implementation for deleting all error log entries and
324 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500325 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500326 * xyz.openbmc_project.Collection.DeleteAll and
327 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500328 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500329class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500330{
Patrick Venturef18bf832018-10-26 18:14:00 -0700331 public:
332 Manager() = delete;
333 Manager(const Manager&) = delete;
334 Manager& operator=(const Manager&) = delete;
335 Manager(Manager&&) = delete;
336 Manager& operator=(Manager&&) = delete;
337 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500338
Patrick Venturef18bf832018-10-26 18:14:00 -0700339 /** @brief Constructor to put object onto bus at a dbus path.
340 * Defer signal registration (pass true for deferSignal to the
341 * base class) until after the properties are set.
342 * @param[in] bus - Bus to attach to.
343 * @param[in] path - Path to attach at.
344 * @param[in] manager - Reference to internal manager object.
345 */
Patrick Williams45e83522022-07-22 19:26:52 -0500346 Manager(sdbusplus::bus_t& bus, const std::string& path,
Patrick Venturef18bf832018-10-26 18:14:00 -0700347 internal::Manager& manager) :
Patrick Williams6ef6b252022-03-30 14:28:27 -0500348 details::ServerObject<DeleteAllIface, CreateIface>(
349 bus, path.c_str(),
350 details::ServerObject<DeleteAllIface,
351 CreateIface>::action::defer_emit),
Patrick Williams075c7922024-08-16 15:19:49 -0400352 manager(manager) {};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500353
Patrick Venturef18bf832018-10-26 18:14:00 -0700354 /** @brief Delete all d-bus objects.
355 */
Patrick Williamsec4eaea2021-08-28 15:10:15 -0500356 void deleteAll() override
Patrick Venturef18bf832018-10-26 18:14:00 -0700357 {
Matt Spinlerf6f51232022-03-09 10:11:53 -0600358 log<level::INFO>("Deleting all log entries");
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800359 auto numbersOfLogs = manager.eraseAll();
Patrick Williams9ca4d132024-10-31 17:02:47 -0400360 manager.createFromEvent(
361 LoggingCleared("NUMBER_OF_LOGS", numbersOfLogs));
Patrick Venturef18bf832018-10-26 18:14:00 -0700362 }
363
Matt Spinler3fb83b32019-07-26 11:22:44 -0500364 /** @brief D-Bus method call implementation to create an event log.
365 *
366 * @param[in] errMsg - The error exception message associated with the
367 * error log to be committed.
368 * @param[in] severity - Level of the error
369 * @param[in] additionalData - The AdditionalData property for the error
370 */
Patrick Williams597f24a2024-09-27 14:47:42 -0400371 auto create(std::string message, Severity severity,
372 std::map<std::string, std::string> additionalData)
373 -> sdbusplus::message::object_path override
Matt Spinler3fb83b32019-07-26 11:22:44 -0500374 {
Patrick Williams597f24a2024-09-27 14:47:42 -0400375 return manager.create(message, severity, additionalData);
Matt Spinler3fb83b32019-07-26 11:22:44 -0500376 }
377
Matt Spinlerc64b7122020-03-26 10:55:01 -0500378 /** @brief D-Bus method call implementation to create an event log with FFDC
379 *
380 * The same as create(), but takes an extra FFDC argument.
381 *
382 * @param[in] errMsg - The error exception message associated with the
383 * error log to be committed.
384 * @param[in] severity - Level of the error
385 * @param[in] additionalData - The AdditionalData property for the error
386 * @param[in] ffdc - A vector of FFDC file info
387 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500388 void createWithFFDCFiles(
BonnieLo-wiwynn6f533662023-04-27 13:41:44 +0800389 std::string message, Severity severity,
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500390 std::map<std::string, std::string> additionalData,
391 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
392 sdbusplus::message::unix_fd>>
393 ffdc) override
394 {
Paul Fertser221b79b2024-03-04 15:40:23 +0000395 manager.create(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500396 }
397
Patrick Venturef18bf832018-10-26 18:14:00 -0700398 private:
399 /** @brief This is a reference to manager object */
400 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500401};
402
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600403} // namespace logging
404} // namespace phosphor