blob: e04c6b72cf01492d35f6cf60a1b878b5caea80ba [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
10#include <list>
11#include <phosphor-logging/log.hpp>
12#include <sdbusplus/bus.hpp>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060013
14namespace phosphor
15{
16namespace logging
17{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060018
Patrick Venturef18bf832018-10-26 18:14:00 -070019extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
20extern const std::map<std::string, level> g_errLevelMap;
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060021
Matt Spinler3fb83b32019-07-26 11:22:44 -050022using CreateIface = sdbusplus::xyz::openbmc_project::Logging::server::Create;
23using DeleteAllIface =
24 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050025
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060026namespace details
27{
Matt Spinler3fb83b32019-07-26 11:22:44 -050028template <typename... T>
29using ServerObject = typename sdbusplus::server::object::object<T...>;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060030
31using ManagerIface =
32 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
33
34} // namespace details
35
Matt Spinlerc64b7122020-03-26 10:55:01 -050036constexpr size_t ffdcFormatPos = 0;
37constexpr size_t ffdcSubtypePos = 1;
38constexpr size_t ffdcVersionPos = 2;
39constexpr size_t ffdcFDPos = 3;
40
41using FFDCEntry = std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
42 sdbusplus::message::unix_fd>;
43
44using FFDCEntries = std::vector<FFDCEntry>;
45
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050046namespace internal
47{
48
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060049/** @class Manager
50 * @brief OpenBMC logging manager implementation.
51 * @details A concrete implementation for the
52 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
53 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060054class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060055{
Patrick Venturef18bf832018-10-26 18:14:00 -070056 public:
57 Manager() = delete;
58 Manager(const Manager&) = delete;
59 Manager& operator=(const Manager&) = delete;
60 Manager(Manager&&) = delete;
61 Manager& operator=(Manager&&) = delete;
62 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060063
Patrick Venturef18bf832018-10-26 18:14:00 -070064 /** @brief Constructor to put object onto bus at a dbus path.
65 * @param[in] bus - Bus to attach to.
66 * @param[in] path - Path to attach at.
67 */
68 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
69 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
70 entryId(0), fwVersion(readFWVersion()){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060071
Patrick Venturef18bf832018-10-26 18:14:00 -070072 /*
73 * @fn commit()
74 * @brief sd_bus Commit method implementation callback.
75 * @details Create an error/event log based on transaction id and
76 * error message.
77 * @param[in] transactionId - Unique identifier of the journal entries
78 * to be committed.
79 * @param[in] errMsg - The error exception message associated with the
80 * error log to be committed.
81 */
Lei YUb50c7052021-01-21 16:02:26 +080082 uint32_t commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060083
Patrick Venturef18bf832018-10-26 18:14:00 -070084 /*
85 * @fn commit()
86 * @brief sd_bus CommitWithLvl method implementation callback.
87 * @details Create an error/event log based on transaction id and
88 * error message.
89 * @param[in] transactionId - Unique identifier of the journal entries
90 * to be committed.
91 * @param[in] errMsg - The error exception message associated with the
92 * error log to be committed.
93 * @param[in] errLvl - level of the error
94 */
Lei YUb50c7052021-01-21 16:02:26 +080095 uint32_t commitWithLvl(uint64_t transactionId, std::string errMsg,
96 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060097
Patrick Venturef18bf832018-10-26 18:14:00 -070098 /** @brief Erase specified entry d-bus object
99 *
100 * @param[in] entryId - unique identifier of the entry
101 */
102 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -0500103
Patrick Venturef18bf832018-10-26 18:14:00 -0700104 /** @brief Construct error d-bus objects from their persisted
105 * representations.
106 */
107 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500108
Patrick Venturef18bf832018-10-26 18:14:00 -0700109 /** @brief Erase all error log entries
110 *
111 */
112 void eraseAll()
113 {
114 auto iter = entries.begin();
115 while (iter != entries.end())
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500116 {
Patrick Venture34438962018-10-30 13:17:37 -0700117 auto e = iter->first;
Patrick Venturef18bf832018-10-26 18:14:00 -0700118 ++iter;
Patrick Venture34438962018-10-30 13:17:37 -0700119 erase(e);
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500120 }
Patrick Venturef18bf832018-10-26 18:14:00 -0700121 }
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500122
Patrick Venturef18bf832018-10-26 18:14:00 -0700123 /** @brief Returns the count of high severity errors
124 *
125 * @return int - count of real errors
126 */
127 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500128
Patrick Venturef18bf832018-10-26 18:14:00 -0700129 /** @brief Returns the count of Info errors
130 *
131 * @return int - count of info errors
132 */
133 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500134
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500135 /** @brief Returns the number of blocking errors
136 *
137 * @return int - count of blocking errors
138 */
139 int getBlockingErrSize()
140 {
141 return blockingErrors.size();
142 }
143
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500144 /** @brief Returns the number of property change callback objects
145 *
146 * @return int - count of property callback entries
147 */
148 int getEntryCallbackSize()
149 {
150 return propChangedEntryCallback.size();
151 }
152
Matt Spinler44893cc2020-08-26 11:34:17 -0500153 /**
154 * @brief Returns the sdbusplus bus object
155 *
156 * @return sdbusplus::bus::bus&
157 */
Matt Spinler8ebfd312019-06-03 12:43:59 -0500158 sdbusplus::bus::bus& getBus()
159 {
160 return busLog;
161 }
162
Matt Spinler44893cc2020-08-26 11:34:17 -0500163 /**
164 * @brief Returns the ID of the last created entry
165 *
166 * @return uint32_t - The ID
167 */
168 uint32_t lastEntryID() const
169 {
170 return entryId;
171 }
172
Matt Spinler3fb83b32019-07-26 11:22:44 -0500173 /** @brief Creates an event log
174 *
175 * This is an alternative to the _commit() API. It doesn't use
176 * the journal to look up event log metadata like _commit does.
177 *
178 * @param[in] errMsg - The error exception message associated with the
179 * error log to be committed.
180 * @param[in] severity - level of the error
181 * @param[in] additionalData - The AdditionalData property for the error
182 */
183 void create(
184 const std::string& message,
185 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
186 const std::map<std::string, std::string>& additionalData);
187
Matt Spinlerc64b7122020-03-26 10:55:01 -0500188 /** @brief Creates an event log, and accepts FFDC files
189 *
190 * This is the same as create(), but also takes an FFDC argument.
191 *
192 * The FFDC argument is a vector of tuples that allows one to pass in file
193 * descriptors for files that contain FFDC (First Failure Data Capture).
194 * These will be passed to any event logging extensions.
195 *
196 * @param[in] errMsg - The error exception message associated with the
197 * error log to be committed.
198 * @param[in] severity - level of the error
199 * @param[in] additionalData - The AdditionalData property for the error
200 * @param[in] ffdc - A vector of FFDC file info
201 */
202 void createWithFFDC(
203 const std::string& message,
204 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
205 const std::map<std::string, std::string>& additionalData,
206 const FFDCEntries& ffdc);
207
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500208 /** @brief Common wrapper for creating an Entry object
209 *
210 * @return true if quiesce on error setting is enabled, false otherwise
211 */
212 bool isQuiesceOnErrorEnabled();
213
Andrew Geissler32874542020-07-09 09:17:03 -0500214 /** @brief Create boot block association and quiesce host if running
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500215 *
Andrew Geissler32874542020-07-09 09:17:03 -0500216 * @param[in] entryId - The ID of the phosphor logging error
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500217 */
Andrew Geissler32874542020-07-09 09:17:03 -0500218 void quiesceOnError(const uint32_t entryId);
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500219
Andrew Geisslere4960ee2020-03-30 14:31:52 -0500220 /** @brief Check if inventory callout present in input entry
221 *
222 * @param[in] entry - The error to check for callouts
223 *
224 * @return true if inventory item in associations, false otherwise
225 */
226 bool isCalloutPresent(const Entry& entry);
227
Andrew Geisslerced6e2a2020-04-07 16:15:29 -0500228 /** @brief Check (and remove) entry being erased from blocking errors
229 *
230 * @param[in] entryId - The entry that is being erased
231 */
232 void checkAndRemoveBlockingError(uint32_t entryId);
233
Adriana Kobylake7d271a2020-12-07 14:32:44 -0600234 /** @brief Persistent map of Entry dbus objects and their ID */
235 std::map<uint32_t, std::unique_ptr<Entry>> entries;
236
Patrick Venturef18bf832018-10-26 18:14:00 -0700237 private:
238 /*
239 * @fn _commit()
240 * @brief commit() helper
241 * @param[in] transactionId - Unique identifier of the journal entries
242 * to be committed.
243 * @param[in] errMsg - The error exception message associated with the
244 * error log to be committed.
245 * @param[in] errLvl - level of the error
246 */
247 void _commit(uint64_t transactionId, std::string&& errMsg,
248 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500249
Patrick Venturef18bf832018-10-26 18:14:00 -0700250 /** @brief Call metadata handler(s), if any. Handlers may create
251 * associations.
252 * @param[in] errorName - name of the error
253 * @param[in] additionalData - list of metadata (in key=value format)
254 * @param[out] objects - list of error's association objects
255 */
256 void processMetadata(const std::string& errorName,
257 const std::vector<std::string>& additionalData,
258 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600259
Patrick Venturef18bf832018-10-26 18:14:00 -0700260 /** @brief Synchronize unwritten journal messages to disk.
261 * @details This is the same implementation as the systemd command
262 * "journalctl --sync".
263 */
264 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500265
Patrick Venturef18bf832018-10-26 18:14:00 -0700266 /** @brief Reads the BMC code level
267 *
268 * @return std::string - the version string
269 */
270 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500271
Matt Spinler99c2b402019-05-23 14:29:16 -0500272 /** @brief Call any create() functions provided by any extensions.
273 * This is called right after an event log is created to allow
274 * extensions to create their own log based on this one.
275 *
276 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500277 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500278 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500279 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500280
Matt Spinlerb60e7552019-07-24 15:28:08 -0500281 /** @brief Common wrapper for creating an Entry object
282 *
283 * @param[in] errMsg - The error exception message associated with the
284 * error log to be committed.
285 * @param[in] errLvl - level of the error
286 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500287 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
288 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500289 */
290 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500291 std::vector<std::string> additionalData,
292 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500293
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500294 /** @brief Notified on entry property changes
295 *
296 * If an entry is blocking, this callback will be registered to monitor for
297 * the entry having it's Resolved field set to true. If it is then remove
298 * the blocking object.
299 *
300 * @param[in] msg - sdbusplus dbusmessage
301 */
302 void onEntryResolve(sdbusplus::message::message& msg);
303
304 /** @brief Remove block objects for any resolved entries */
305 void findAndRemoveResolvedBlocks();
306
Andrew Geisslerf6126a72020-05-08 10:41:09 -0500307 /** @brief Quiesce host if it is running
308 *
309 * This is called when the user has requested the system be quiesced
310 * if a log with a callout is created
311 */
312 void checkAndQuiesceHost();
313
Patrick Venturef18bf832018-10-26 18:14:00 -0700314 /** @brief Persistent sdbusplus DBus bus connection. */
315 sdbusplus::bus::bus& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600316
Patrick Venturef18bf832018-10-26 18:14:00 -0700317 /** @brief List of error ids for high severity errors */
318 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600319
Patrick Venturef18bf832018-10-26 18:14:00 -0700320 /** @brief List of error ids for Info(and below) severity */
321 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500322
Patrick Venturef18bf832018-10-26 18:14:00 -0700323 /** @brief Id of last error log entry */
324 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500325
Patrick Venturef18bf832018-10-26 18:14:00 -0700326 /** @brief The BMC firmware version */
327 const std::string fwVersion;
Andrew Geissler6a0ef6f2020-04-06 15:06:31 -0500328
329 /** @brief Array of blocking errors */
330 std::vector<std::unique_ptr<Block>> blockingErrors;
Andrew Geissler7f6d4bc2020-04-16 14:47:34 -0500331
332 /** @brief Map of entry id to call back object on properties changed */
333 std::map<uint32_t, std::unique_ptr<sdbusplus::bus::match::match>>
334 propChangedEntryCallback;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600335};
336
Patrick Venturef18bf832018-10-26 18:14:00 -0700337} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500338
339/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500340 * @brief Implementation for deleting all error log entries and
341 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500342 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500343 * xyz.openbmc_project.Collection.DeleteAll and
344 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500345 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500346class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500347{
Patrick Venturef18bf832018-10-26 18:14:00 -0700348 public:
349 Manager() = delete;
350 Manager(const Manager&) = delete;
351 Manager& operator=(const Manager&) = delete;
352 Manager(Manager&&) = delete;
353 Manager& operator=(Manager&&) = delete;
354 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500355
Patrick Venturef18bf832018-10-26 18:14:00 -0700356 /** @brief Constructor to put object onto bus at a dbus path.
357 * Defer signal registration (pass true for deferSignal to the
358 * base class) until after the properties are set.
359 * @param[in] bus - Bus to attach to.
360 * @param[in] path - Path to attach at.
361 * @param[in] manager - Reference to internal manager object.
362 */
363 Manager(sdbusplus::bus::bus& bus, const std::string& path,
364 internal::Manager& manager) :
Matt Spinler3fb83b32019-07-26 11:22:44 -0500365 details::ServerObject<DeleteAllIface, CreateIface>(bus, path.c_str(),
366 true),
Patrick Venturef18bf832018-10-26 18:14:00 -0700367 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500368
Patrick Venturef18bf832018-10-26 18:14:00 -0700369 /** @brief Delete all d-bus objects.
370 */
371 void deleteAll()
372 {
373 manager.eraseAll();
374 }
375
Matt Spinler3fb83b32019-07-26 11:22:44 -0500376 /** @brief D-Bus method call implementation to create an event log.
377 *
378 * @param[in] errMsg - The error exception message associated with the
379 * error log to be committed.
380 * @param[in] severity - Level of the error
381 * @param[in] additionalData - The AdditionalData property for the error
382 */
383 void create(
384 std::string message,
385 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
386 std::map<std::string, std::string> additionalData) override
387 {
388 manager.create(message, severity, additionalData);
389 }
390
Matt Spinlerc64b7122020-03-26 10:55:01 -0500391 /** @brief D-Bus method call implementation to create an event log with FFDC
392 *
393 * The same as create(), but takes an extra FFDC argument.
394 *
395 * @param[in] errMsg - The error exception message associated with the
396 * error log to be committed.
397 * @param[in] severity - Level of the error
398 * @param[in] additionalData - The AdditionalData property for the error
399 * @param[in] ffdc - A vector of FFDC file info
400 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500401 void createWithFFDCFiles(
402 std::string message,
403 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
404 std::map<std::string, std::string> additionalData,
405 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
406 sdbusplus::message::unix_fd>>
407 ffdc) override
408 {
Matt Spinlerc64b7122020-03-26 10:55:01 -0500409 manager.createWithFFDC(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500410 }
411
Patrick Venturef18bf832018-10-26 18:14:00 -0700412 private:
413 /** @brief This is a reference to manager object */
414 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500415};
416
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600417} // namespace logging
418} // namespace phosphor