blob: 8f5ca4331e3a76087baf8e1673b3b425f3dc94be [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"
9
Patrick Venturef18bf832018-10-26 18:14:00 -070010#include <phosphor-logging/log.hpp>
11#include <sdbusplus/bus.hpp>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060012
Patrick Williams2544b412022-10-04 08:41:06 -050013#include <list>
14
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060015namespace phosphor
16{
17namespace logging
18{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060019
Patrick Venturef18bf832018-10-26 18:14:00 -070020extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
21extern const std::map<std::string, level> g_errLevelMap;
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060022
Willy Tu6ddbf692023-09-05 10:54:16 -070023using CreateIface = sdbusplus::server::xyz::openbmc_project::logging::Create;
Matt Spinler3fb83b32019-07-26 11:22:44 -050024using DeleteAllIface =
Willy Tu6ddbf692023-09-05 10:54:16 -070025 sdbusplus::server::xyz::openbmc_project::collection::DeleteAll;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050026
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060027namespace details
28{
Matt Spinler3fb83b32019-07-26 11:22:44 -050029template <typename... T>
Patrick Williams45e83522022-07-22 19:26:52 -050030using ServerObject = typename sdbusplus::server::object_t<T...>;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060031
32using ManagerIface =
Willy Tu6ddbf692023-09-05 10:54:16 -070033 sdbusplus::server::xyz::openbmc_project::logging::internal::Manager;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060034
35} // namespace details
36
Matt Spinlerc64b7122020-03-26 10:55:01 -050037constexpr size_t ffdcFormatPos = 0;
38constexpr size_t ffdcSubtypePos = 1;
39constexpr size_t ffdcVersionPos = 2;
40constexpr size_t ffdcFDPos = 3;
41
42using FFDCEntry = std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
43 sdbusplus::message::unix_fd>;
44
45using FFDCEntries = std::vector<FFDCEntry>;
46
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050047namespace internal
48{
49
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060050/** @class Manager
51 * @brief OpenBMC logging manager implementation.
52 * @details A concrete implementation for the
53 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
54 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060055class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060056{
Patrick Venturef18bf832018-10-26 18:14:00 -070057 public:
58 Manager() = delete;
59 Manager(const Manager&) = delete;
60 Manager& operator=(const Manager&) = delete;
61 Manager(Manager&&) = delete;
62 Manager& operator=(Manager&&) = delete;
63 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060064
Patrick Venturef18bf832018-10-26 18:14:00 -070065 /** @brief Constructor to put object onto bus at a dbus path.
66 * @param[in] bus - Bus to attach to.
67 * @param[in] path - Path to attach at.
68 */
Patrick Williams45e83522022-07-22 19:26:52 -050069 Manager(sdbusplus::bus_t& bus, const char* objPath) :
Patrick Venturef18bf832018-10-26 18:14:00 -070070 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
71 entryId(0), fwVersion(readFWVersion()){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060072
Patrick Venturef18bf832018-10-26 18:14:00 -070073 /*
74 * @fn commit()
75 * @brief sd_bus Commit method implementation callback.
76 * @details Create an error/event log based on transaction id and
77 * error message.
78 * @param[in] transactionId - Unique identifier of the journal entries
79 * to be committed.
80 * @param[in] errMsg - The error exception message associated with the
81 * error log to be committed.
82 */
Lei YUb50c7052021-01-21 16:02:26 +080083 uint32_t commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060084
Patrick Venturef18bf832018-10-26 18:14:00 -070085 /*
86 * @fn commit()
87 * @brief sd_bus CommitWithLvl method implementation callback.
88 * @details Create an error/event log based on transaction id and
89 * error message.
90 * @param[in] transactionId - Unique identifier of the journal entries
91 * to be committed.
92 * @param[in] errMsg - The error exception message associated with the
93 * error log to be committed.
94 * @param[in] errLvl - level of the error
95 */
Lei YUb50c7052021-01-21 16:02:26 +080096 uint32_t commitWithLvl(uint64_t transactionId, std::string errMsg,
97 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060098
Patrick Venturef18bf832018-10-26 18:14:00 -070099 /** @brief Erase specified entry d-bus object
100 *
101 * @param[in] entryId - unique identifier of the entry
102 */
103 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -0500104
Patrick Venturef18bf832018-10-26 18:14:00 -0700105 /** @brief Construct error d-bus objects from their persisted
106 * representations.
107 */
108 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500109
Patrick Venturef18bf832018-10-26 18:14:00 -0700110 /** @brief Erase all error log entries
111 *
112 */
113 void eraseAll()
114 {
115 auto iter = entries.begin();
116 while (iter != entries.end())
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500117 {
Patrick Venture34438962018-10-30 13:17:37 -0700118 auto e = iter->first;
Patrick Venturef18bf832018-10-26 18:14:00 -0700119 ++iter;
Patrick Venture34438962018-10-30 13:17:37 -0700120 erase(e);
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500121 }
Lotus Xud091a572021-05-24 13:59:21 +0800122 entryId = 0;
Patrick Venturef18bf832018-10-26 18:14:00 -0700123 }
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500124
Patrick Venturef18bf832018-10-26 18:14:00 -0700125 /** @brief Returns the count of high severity errors
126 *
127 * @return int - count of real errors
128 */
129 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500130
Patrick Venturef18bf832018-10-26 18:14:00 -0700131 /** @brief Returns the count of Info errors
132 *
133 * @return int - count of info errors
134 */
135 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500136
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500137 /** @brief Returns the number of blocking errors
138 *
139 * @return int - count of blocking errors
140 */
141 int getBlockingErrSize()
142 {
143 return blockingErrors.size();
144 }
145
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500146 /** @brief Returns the number of property change callback objects
147 *
148 * @return int - count of property callback entries
149 */
150 int getEntryCallbackSize()
151 {
152 return propChangedEntryCallback.size();
153 }
154
Matt Spinler44893cc2020-08-26 11:34:17 -0500155 /**
156 * @brief Returns the sdbusplus bus object
157 *
Patrick Williams45e83522022-07-22 19:26:52 -0500158 * @return sdbusplus::bus_t&
Matt Spinler44893cc2020-08-26 11:34:17 -0500159 */
Patrick Williams45e83522022-07-22 19:26:52 -0500160 sdbusplus::bus_t& getBus()
Matt Spinler8ebfd312019-06-03 12:43:59 -0500161 {
162 return busLog;
163 }
164
Matt Spinler44893cc2020-08-26 11:34:17 -0500165 /**
166 * @brief Returns the ID of the last created entry
167 *
168 * @return uint32_t - The ID
169 */
170 uint32_t lastEntryID() const
171 {
172 return entryId;
173 }
174
Matt Spinler3fb83b32019-07-26 11:22:44 -0500175 /** @brief Creates an event log
176 *
177 * This is an alternative to the _commit() API. It doesn't use
178 * the journal to look up event log metadata like _commit does.
179 *
180 * @param[in] errMsg - The error exception message associated with the
181 * error log to be committed.
182 * @param[in] severity - level of the error
183 * @param[in] additionalData - The AdditionalData property for the error
184 */
185 void create(
186 const std::string& message,
Willy Tu6ddbf692023-09-05 10:54:16 -0700187 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level severity,
Matt Spinler3fb83b32019-07-26 11:22:44 -0500188 const std::map<std::string, std::string>& additionalData);
189
Matt Spinlerc64b7122020-03-26 10:55:01 -0500190 /** @brief Creates an event log, and accepts FFDC files
191 *
192 * This is the same as create(), but also takes an FFDC argument.
193 *
194 * The FFDC argument is a vector of tuples that allows one to pass in file
195 * descriptors for files that contain FFDC (First Failure Data Capture).
196 * These will be passed to any event logging extensions.
197 *
198 * @param[in] errMsg - The error exception message associated with the
199 * error log to be committed.
200 * @param[in] severity - level of the error
201 * @param[in] additionalData - The AdditionalData property for the error
202 * @param[in] ffdc - A vector of FFDC file info
203 */
204 void createWithFFDC(
205 const std::string& message,
Willy Tu6ddbf692023-09-05 10:54:16 -0700206 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level severity,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500207 const std::map<std::string, std::string>& additionalData,
208 const FFDCEntries& ffdc);
209
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500210 /** @brief Common wrapper for creating an Entry object
211 *
212 * @return true if quiesce on error setting is enabled, false otherwise
213 */
214 bool isQuiesceOnErrorEnabled();
215
Andrew Geissler32874542020-07-09 09:17:03 -0500216 /** @brief Create boot block association and quiesce host if running
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500217 *
Andrew Geissler32874542020-07-09 09:17:03 -0500218 * @param[in] entryId - The ID of the phosphor logging error
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500219 */
Andrew Geissler32874542020-07-09 09:17:03 -0500220 void quiesceOnError(const uint32_t entryId);
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500221
Andrew Geisslere4960ee2020-03-30 14:31:52 -0500222 /** @brief Check if inventory callout present in input entry
223 *
224 * @param[in] entry - The error to check for callouts
225 *
226 * @return true if inventory item in associations, false otherwise
227 */
228 bool isCalloutPresent(const Entry& entry);
229
Andrew Geisslerced6e2a2020-04-07 16:15:29 -0500230 /** @brief Check (and remove) entry being erased from blocking errors
231 *
232 * @param[in] entryId - The entry that is being erased
233 */
234 void checkAndRemoveBlockingError(uint32_t entryId);
235
Adriana Kobylake7d271a2020-12-07 14:32:44 -0600236 /** @brief Persistent map of Entry dbus objects and their ID */
237 std::map<uint32_t, std::unique_ptr<Entry>> entries;
238
Patrick Venturef18bf832018-10-26 18:14:00 -0700239 private:
240 /*
241 * @fn _commit()
242 * @brief commit() helper
243 * @param[in] transactionId - Unique identifier of the journal entries
244 * to be committed.
245 * @param[in] errMsg - The error exception message associated with the
246 * error log to be committed.
247 * @param[in] errLvl - level of the error
248 */
249 void _commit(uint64_t transactionId, std::string&& errMsg,
250 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500251
Patrick Venturef18bf832018-10-26 18:14:00 -0700252 /** @brief Call metadata handler(s), if any. Handlers may create
253 * associations.
254 * @param[in] errorName - name of the error
255 * @param[in] additionalData - list of metadata (in key=value format)
256 * @param[out] objects - list of error's association objects
257 */
258 void processMetadata(const std::string& errorName,
259 const std::vector<std::string>& additionalData,
260 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600261
Patrick Venturef18bf832018-10-26 18:14:00 -0700262 /** @brief Reads the BMC code level
263 *
264 * @return std::string - the version string
265 */
266 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500267
Matt Spinler99c2b402019-05-23 14:29:16 -0500268 /** @brief Call any create() functions provided by any extensions.
269 * This is called right after an event log is created to allow
270 * extensions to create their own log based on this one.
271 *
272 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500273 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500274 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500275 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500276
Matt Spinlerb60e7552019-07-24 15:28:08 -0500277 /** @brief Common wrapper for creating an Entry object
278 *
279 * @param[in] errMsg - The error exception message associated with the
280 * error log to be committed.
281 * @param[in] errLvl - level of the error
282 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500283 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
284 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500285 */
286 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500287 std::vector<std::string> additionalData,
288 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500289
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500290 /** @brief Notified on entry property changes
291 *
292 * If an entry is blocking, this callback will be registered to monitor for
293 * the entry having it's Resolved field set to true. If it is then remove
294 * the blocking object.
295 *
296 * @param[in] msg - sdbusplus dbusmessage
297 */
Patrick Williams45e83522022-07-22 19:26:52 -0500298 void onEntryResolve(sdbusplus::message_t& msg);
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500299
300 /** @brief Remove block objects for any resolved entries */
301 void findAndRemoveResolvedBlocks();
302
Andrew Geisslerf6126a72020-05-08 10:41:09 -0500303 /** @brief Quiesce host if it is running
304 *
305 * This is called when the user has requested the system be quiesced
306 * if a log with a callout is created
307 */
308 void checkAndQuiesceHost();
309
Patrick Venturef18bf832018-10-26 18:14:00 -0700310 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williams45e83522022-07-22 19:26:52 -0500311 sdbusplus::bus_t& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600312
Patrick Venturef18bf832018-10-26 18:14:00 -0700313 /** @brief List of error ids for high severity errors */
314 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600315
Patrick Venturef18bf832018-10-26 18:14:00 -0700316 /** @brief List of error ids for Info(and below) severity */
317 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500318
Patrick Venturef18bf832018-10-26 18:14:00 -0700319 /** @brief Id of last error log entry */
320 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500321
Patrick Venturef18bf832018-10-26 18:14:00 -0700322 /** @brief The BMC firmware version */
323 const std::string fwVersion;
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500324
325 /** @brief Array of blocking errors */
326 std::vector<std::unique_ptr<Block>> blockingErrors;
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500327
328 /** @brief Map of entry id to call back object on properties changed */
Patrick Williams45e83522022-07-22 19:26:52 -0500329 std::map<uint32_t, std::unique_ptr<sdbusplus::bus::match_t>>
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500330 propChangedEntryCallback;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600331};
332
Patrick Venturef18bf832018-10-26 18:14:00 -0700333} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500334
335/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500336 * @brief Implementation for deleting all error log entries and
337 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500338 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500339 * xyz.openbmc_project.Collection.DeleteAll and
340 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500341 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500342class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500343{
Patrick Venturef18bf832018-10-26 18:14:00 -0700344 public:
345 Manager() = delete;
346 Manager(const Manager&) = delete;
347 Manager& operator=(const Manager&) = delete;
348 Manager(Manager&&) = delete;
349 Manager& operator=(Manager&&) = delete;
350 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500351
Patrick Venturef18bf832018-10-26 18:14:00 -0700352 /** @brief Constructor to put object onto bus at a dbus path.
353 * Defer signal registration (pass true for deferSignal to the
354 * base class) until after the properties are set.
355 * @param[in] bus - Bus to attach to.
356 * @param[in] path - Path to attach at.
357 * @param[in] manager - Reference to internal manager object.
358 */
Patrick Williams45e83522022-07-22 19:26:52 -0500359 Manager(sdbusplus::bus_t& bus, const std::string& path,
Patrick Venturef18bf832018-10-26 18:14:00 -0700360 internal::Manager& manager) :
Patrick Williams6ef6b252022-03-30 14:28:27 -0500361 details::ServerObject<DeleteAllIface, CreateIface>(
362 bus, path.c_str(),
363 details::ServerObject<DeleteAllIface,
364 CreateIface>::action::defer_emit),
Patrick Venturef18bf832018-10-26 18:14:00 -0700365 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500366
Patrick Venturef18bf832018-10-26 18:14:00 -0700367 /** @brief Delete all d-bus objects.
368 */
Patrick Williamsec4eaea2021-08-28 15:10:15 -0500369 void deleteAll() override
Patrick Venturef18bf832018-10-26 18:14:00 -0700370 {
Matt Spinlerf6f51232022-03-09 10:11:53 -0600371 log<level::INFO>("Deleting all log entries");
Patrick Venturef18bf832018-10-26 18:14:00 -0700372 manager.eraseAll();
373 }
374
Matt Spinler3fb83b32019-07-26 11:22:44 -0500375 /** @brief D-Bus method call implementation to create an event log.
376 *
377 * @param[in] errMsg - The error exception message associated with the
378 * error log to be committed.
379 * @param[in] severity - Level of the error
380 * @param[in] additionalData - The AdditionalData property for the error
381 */
382 void create(
383 std::string message,
Willy Tu6ddbf692023-09-05 10:54:16 -0700384 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level severity,
Matt Spinler3fb83b32019-07-26 11:22:44 -0500385 std::map<std::string, std::string> additionalData) override
386 {
387 manager.create(message, severity, additionalData);
388 }
389
Matt Spinlerc64b7122020-03-26 10:55:01 -0500390 /** @brief D-Bus method call implementation to create an event log with FFDC
391 *
392 * The same as create(), but takes an extra FFDC argument.
393 *
394 * @param[in] errMsg - The error exception message associated with the
395 * error log to be committed.
396 * @param[in] severity - Level of the error
397 * @param[in] additionalData - The AdditionalData property for the error
398 * @param[in] ffdc - A vector of FFDC file info
399 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500400 void createWithFFDCFiles(
401 std::string message,
Willy Tu6ddbf692023-09-05 10:54:16 -0700402 sdbusplus::server::xyz::openbmc_project::logging::Entry::Level severity,
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500403 std::map<std::string, std::string> additionalData,
404 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
405 sdbusplus::message::unix_fd>>
406 ffdc) override
407 {
Matt Spinlerc64b7122020-03-26 10:55:01 -0500408 manager.createWithFFDC(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500409 }
410
Patrick Venturef18bf832018-10-26 18:14:00 -0700411 private:
412 /** @brief This is a reference to manager object */
413 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500414};
415
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600416} // namespace logging
417} // namespace phosphor