blob: aa7d8f91e622da365c598dc91536e1c802f60113 [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
Matt Spinler3fb83b32019-07-26 11:22:44 -050023using CreateIface = sdbusplus::xyz::openbmc_project::Logging::server::Create;
24using DeleteAllIface =
25 sdbusplus::xyz::openbmc_project::Collection::server::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 =
33 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
34
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,
187 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
188 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,
206 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
207 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 Synchronize unwritten journal messages to disk.
263 * @details This is the same implementation as the systemd command
264 * "journalctl --sync".
265 */
266 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500267
Patrick Venturef18bf832018-10-26 18:14:00 -0700268 /** @brief Reads the BMC code level
269 *
270 * @return std::string - the version string
271 */
272 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500273
Matt Spinler99c2b402019-05-23 14:29:16 -0500274 /** @brief Call any create() functions provided by any extensions.
275 * This is called right after an event log is created to allow
276 * extensions to create their own log based on this one.
277 *
278 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500279 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500280 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500281 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500282
Matt Spinlerb60e7552019-07-24 15:28:08 -0500283 /** @brief Common wrapper for creating an Entry object
284 *
285 * @param[in] errMsg - The error exception message associated with the
286 * error log to be committed.
287 * @param[in] errLvl - level of the error
288 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500289 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
290 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500291 */
292 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500293 std::vector<std::string> additionalData,
294 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500295
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500296 /** @brief Notified on entry property changes
297 *
298 * If an entry is blocking, this callback will be registered to monitor for
299 * the entry having it's Resolved field set to true. If it is then remove
300 * the blocking object.
301 *
302 * @param[in] msg - sdbusplus dbusmessage
303 */
Patrick Williams45e83522022-07-22 19:26:52 -0500304 void onEntryResolve(sdbusplus::message_t& msg);
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500305
306 /** @brief Remove block objects for any resolved entries */
307 void findAndRemoveResolvedBlocks();
308
Andrew Geisslerf6126a72020-05-08 10:41:09 -0500309 /** @brief Quiesce host if it is running
310 *
311 * This is called when the user has requested the system be quiesced
312 * if a log with a callout is created
313 */
314 void checkAndQuiesceHost();
315
Patrick Venturef18bf832018-10-26 18:14:00 -0700316 /** @brief Persistent sdbusplus DBus bus connection. */
Patrick Williams45e83522022-07-22 19:26:52 -0500317 sdbusplus::bus_t& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600318
Patrick Venturef18bf832018-10-26 18:14:00 -0700319 /** @brief List of error ids for high severity errors */
320 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600321
Patrick Venturef18bf832018-10-26 18:14:00 -0700322 /** @brief List of error ids for Info(and below) severity */
323 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500324
Patrick Venturef18bf832018-10-26 18:14:00 -0700325 /** @brief Id of last error log entry */
326 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500327
Patrick Venturef18bf832018-10-26 18:14:00 -0700328 /** @brief The BMC firmware version */
329 const std::string fwVersion;
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500330
331 /** @brief Array of blocking errors */
332 std::vector<std::unique_ptr<Block>> blockingErrors;
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500333
334 /** @brief Map of entry id to call back object on properties changed */
Patrick Williams45e83522022-07-22 19:26:52 -0500335 std::map<uint32_t, std::unique_ptr<sdbusplus::bus::match_t>>
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500336 propChangedEntryCallback;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600337};
338
Patrick Venturef18bf832018-10-26 18:14:00 -0700339} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500340
341/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500342 * @brief Implementation for deleting all error log entries and
343 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500344 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500345 * xyz.openbmc_project.Collection.DeleteAll and
346 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500347 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500348class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500349{
Patrick Venturef18bf832018-10-26 18:14:00 -0700350 public:
351 Manager() = delete;
352 Manager(const Manager&) = delete;
353 Manager& operator=(const Manager&) = delete;
354 Manager(Manager&&) = delete;
355 Manager& operator=(Manager&&) = delete;
356 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500357
Patrick Venturef18bf832018-10-26 18:14:00 -0700358 /** @brief Constructor to put object onto bus at a dbus path.
359 * Defer signal registration (pass true for deferSignal to the
360 * base class) until after the properties are set.
361 * @param[in] bus - Bus to attach to.
362 * @param[in] path - Path to attach at.
363 * @param[in] manager - Reference to internal manager object.
364 */
Patrick Williams45e83522022-07-22 19:26:52 -0500365 Manager(sdbusplus::bus_t& bus, const std::string& path,
Patrick Venturef18bf832018-10-26 18:14:00 -0700366 internal::Manager& manager) :
Patrick Williams6ef6b252022-03-30 14:28:27 -0500367 details::ServerObject<DeleteAllIface, CreateIface>(
368 bus, path.c_str(),
369 details::ServerObject<DeleteAllIface,
370 CreateIface>::action::defer_emit),
Patrick Venturef18bf832018-10-26 18:14:00 -0700371 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500372
Patrick Venturef18bf832018-10-26 18:14:00 -0700373 /** @brief Delete all d-bus objects.
374 */
Patrick Williamsec4eaea2021-08-28 15:10:15 -0500375 void deleteAll() override
Patrick Venturef18bf832018-10-26 18:14:00 -0700376 {
Matt Spinlerf6f51232022-03-09 10:11:53 -0600377 log<level::INFO>("Deleting all log entries");
Patrick Venturef18bf832018-10-26 18:14:00 -0700378 manager.eraseAll();
379 }
380
Matt Spinler3fb83b32019-07-26 11:22:44 -0500381 /** @brief D-Bus method call implementation to create an event log.
382 *
383 * @param[in] errMsg - The error exception message associated with the
384 * error log to be committed.
385 * @param[in] severity - Level of the error
386 * @param[in] additionalData - The AdditionalData property for the error
387 */
388 void create(
389 std::string message,
390 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
391 std::map<std::string, std::string> additionalData) override
392 {
393 manager.create(message, severity, additionalData);
394 }
395
Matt Spinlerc64b7122020-03-26 10:55:01 -0500396 /** @brief D-Bus method call implementation to create an event log with FFDC
397 *
398 * The same as create(), but takes an extra FFDC argument.
399 *
400 * @param[in] errMsg - The error exception message associated with the
401 * error log to be committed.
402 * @param[in] severity - Level of the error
403 * @param[in] additionalData - The AdditionalData property for the error
404 * @param[in] ffdc - A vector of FFDC file info
405 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500406 void createWithFFDCFiles(
407 std::string message,
408 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
409 std::map<std::string, std::string> additionalData,
410 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
411 sdbusplus::message::unix_fd>>
412 ffdc) override
413 {
Matt Spinlerc64b7122020-03-26 10:55:01 -0500414 manager.createWithFFDC(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500415 }
416
Patrick Venturef18bf832018-10-26 18:14:00 -0700417 private:
418 /** @brief This is a reference to manager object */
419 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500420};
421
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600422} // namespace logging
423} // namespace phosphor