blob: b24a7f3e391d400e4e2c5add668cd406160f9c5a [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#pragma once
2
Adriana Kobylakdf995fa2017-01-08 15:14:02 -06003#include "elog_entry.hpp"
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -05004#include "xyz/openbmc_project/Collection/DeleteAll/server.hpp"
Matt Spinler3fb83b32019-07-26 11:22:44 -05005#include "xyz/openbmc_project/Logging/Create/server.hpp"
6#include "xyz/openbmc_project/Logging/Entry/server.hpp"
Patrick Venturef18bf832018-10-26 18:14:00 -07007#include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp"
8
9#include <list>
10#include <phosphor-logging/log.hpp>
11#include <sdbusplus/bus.hpp>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060012
13namespace phosphor
14{
15namespace logging
16{
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060017
Patrick Venturef18bf832018-10-26 18:14:00 -070018extern const std::map<std::string, std::vector<std::string>> g_errMetaMap;
19extern const std::map<std::string, level> g_errLevelMap;
Adriana Kobylakd722b3a2017-02-28 12:10:44 -060020
Matt Spinler3fb83b32019-07-26 11:22:44 -050021using CreateIface = sdbusplus::xyz::openbmc_project::Logging::server::Create;
22using DeleteAllIface =
23 sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050024
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060025namespace details
26{
Matt Spinler3fb83b32019-07-26 11:22:44 -050027template <typename... T>
28using ServerObject = typename sdbusplus::server::object::object<T...>;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060029
30using ManagerIface =
31 sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager;
32
33} // namespace details
34
Matt Spinlerc64b7122020-03-26 10:55:01 -050035constexpr size_t ffdcFormatPos = 0;
36constexpr size_t ffdcSubtypePos = 1;
37constexpr size_t ffdcVersionPos = 2;
38constexpr size_t ffdcFDPos = 3;
39
40using FFDCEntry = std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
41 sdbusplus::message::unix_fd>;
42
43using FFDCEntries = std::vector<FFDCEntry>;
44
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050045namespace internal
46{
47
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060048/** @class Manager
49 * @brief OpenBMC logging manager implementation.
50 * @details A concrete implementation for the
51 * xyz.openbmc_project.Logging.Internal.Manager DBus API.
52 */
Adriana Kobylakf477fe22017-01-06 11:56:41 -060053class Manager : public details::ServerObject<details::ManagerIface>
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060054{
Patrick Venturef18bf832018-10-26 18:14:00 -070055 public:
56 Manager() = delete;
57 Manager(const Manager&) = delete;
58 Manager& operator=(const Manager&) = delete;
59 Manager(Manager&&) = delete;
60 Manager& operator=(Manager&&) = delete;
61 virtual ~Manager() = default;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060062
Patrick Venturef18bf832018-10-26 18:14:00 -070063 /** @brief Constructor to put object onto bus at a dbus path.
64 * @param[in] bus - Bus to attach to.
65 * @param[in] path - Path to attach at.
66 */
67 Manager(sdbusplus::bus::bus& bus, const char* objPath) :
68 details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus),
69 entryId(0), fwVersion(readFWVersion()){};
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060070
Patrick Venturef18bf832018-10-26 18:14:00 -070071 /*
72 * @fn commit()
73 * @brief sd_bus Commit method implementation callback.
74 * @details Create an error/event log based on transaction id and
75 * error message.
76 * @param[in] transactionId - Unique identifier of the journal entries
77 * to be committed.
78 * @param[in] errMsg - The error exception message associated with the
79 * error log to be committed.
80 */
81 void commit(uint64_t transactionId, std::string errMsg) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060082
Patrick Venturef18bf832018-10-26 18:14:00 -070083 /*
84 * @fn commit()
85 * @brief sd_bus CommitWithLvl method implementation callback.
86 * @details Create an error/event log based on transaction id and
87 * error message.
88 * @param[in] transactionId - Unique identifier of the journal entries
89 * to be committed.
90 * @param[in] errMsg - The error exception message associated with the
91 * error log to be committed.
92 * @param[in] errLvl - level of the error
93 */
94 void commitWithLvl(uint64_t transactionId, std::string errMsg,
95 uint32_t errLvl) override;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -060096
Patrick Venturef18bf832018-10-26 18:14:00 -070097 /** @brief Erase specified entry d-bus object
98 *
99 * @param[in] entryId - unique identifier of the entry
100 */
101 void erase(uint32_t entryId);
Deepak Kodihalli99a85492017-03-31 06:01:57 -0500102
Patrick Venturef18bf832018-10-26 18:14:00 -0700103 /** @brief Construct error d-bus objects from their persisted
104 * representations.
105 */
106 void restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -0500107
Patrick Venturef18bf832018-10-26 18:14:00 -0700108 /** @brief Erase all error log entries
109 *
110 */
111 void eraseAll()
112 {
113 auto iter = entries.begin();
114 while (iter != entries.end())
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500115 {
Patrick Venture34438962018-10-30 13:17:37 -0700116 auto e = iter->first;
Patrick Venturef18bf832018-10-26 18:14:00 -0700117 ++iter;
Patrick Venture34438962018-10-30 13:17:37 -0700118 erase(e);
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500119 }
Patrick Venturef18bf832018-10-26 18:14:00 -0700120 }
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500121
Patrick Venturef18bf832018-10-26 18:14:00 -0700122 /** @brief Returns the count of high severity errors
123 *
124 * @return int - count of real errors
125 */
126 int getRealErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500127
Patrick Venturef18bf832018-10-26 18:14:00 -0700128 /** @brief Returns the count of Info errors
129 *
130 * @return int - count of info errors
131 */
132 int getInfoErrSize();
Nagaraju Goruganti477b7312018-06-25 23:28:58 -0500133
Matt Spinler8ebfd312019-06-03 12:43:59 -0500134 sdbusplus::bus::bus& getBus()
135 {
136 return busLog;
137 }
138
Matt Spinler3fb83b32019-07-26 11:22:44 -0500139 /** @brief Creates an event log
140 *
141 * This is an alternative to the _commit() API. It doesn't use
142 * the journal to look up event log metadata like _commit does.
143 *
144 * @param[in] errMsg - The error exception message associated with the
145 * error log to be committed.
146 * @param[in] severity - level of the error
147 * @param[in] additionalData - The AdditionalData property for the error
148 */
149 void create(
150 const std::string& message,
151 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
152 const std::map<std::string, std::string>& additionalData);
153
Matt Spinlerc64b7122020-03-26 10:55:01 -0500154 /** @brief Creates an event log, and accepts FFDC files
155 *
156 * This is the same as create(), but also takes an FFDC argument.
157 *
158 * The FFDC argument is a vector of tuples that allows one to pass in file
159 * descriptors for files that contain FFDC (First Failure Data Capture).
160 * These will be passed to any event logging extensions.
161 *
162 * @param[in] errMsg - The error exception message associated with the
163 * error log to be committed.
164 * @param[in] severity - level of the error
165 * @param[in] additionalData - The AdditionalData property for the error
166 * @param[in] ffdc - A vector of FFDC file info
167 */
168 void createWithFFDC(
169 const std::string& message,
170 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
171 const std::map<std::string, std::string>& additionalData,
172 const FFDCEntries& ffdc);
173
Andrew Geisslerc0c500e2020-03-26 11:08:56 -0500174 /** @brief Common wrapper for creating an Entry object
175 *
176 * @return true if quiesce on error setting is enabled, false otherwise
177 */
178 bool isQuiesceOnErrorEnabled();
179
180 /** @brief Check if error has callout and if so, block boot
181 *
182 * @param[in] entry - The error to check for callouts
183 */
184 void checkQuiesceOnError(const Entry& entry);
185
Andrew Geisslere4960ee2020-03-30 14:31:52 -0500186 /** @brief Check if inventory callout present in input entry
187 *
188 * @param[in] entry - The error to check for callouts
189 *
190 * @return true if inventory item in associations, false otherwise
191 */
192 bool isCalloutPresent(const Entry& entry);
193
Patrick Venturef18bf832018-10-26 18:14:00 -0700194 private:
195 /*
196 * @fn _commit()
197 * @brief commit() helper
198 * @param[in] transactionId - Unique identifier of the journal entries
199 * to be committed.
200 * @param[in] errMsg - The error exception message associated with the
201 * error log to be committed.
202 * @param[in] errLvl - level of the error
203 */
204 void _commit(uint64_t transactionId, std::string&& errMsg,
205 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500206
Patrick Venturef18bf832018-10-26 18:14:00 -0700207 /** @brief Call metadata handler(s), if any. Handlers may create
208 * associations.
209 * @param[in] errorName - name of the error
210 * @param[in] additionalData - list of metadata (in key=value format)
211 * @param[out] objects - list of error's association objects
212 */
213 void processMetadata(const std::string& errorName,
214 const std::vector<std::string>& additionalData,
215 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600216
Patrick Venturef18bf832018-10-26 18:14:00 -0700217 /** @brief Synchronize unwritten journal messages to disk.
218 * @details This is the same implementation as the systemd command
219 * "journalctl --sync".
220 */
221 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500222
Patrick Venturef18bf832018-10-26 18:14:00 -0700223 /** @brief Reads the BMC code level
224 *
225 * @return std::string - the version string
226 */
227 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500228
Matt Spinler99c2b402019-05-23 14:29:16 -0500229 /** @brief Call any create() functions provided by any extensions.
230 * This is called right after an event log is created to allow
231 * extensions to create their own log based on this one.
232 *
233 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500234 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500235 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500236 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500237
Matt Spinlerb60e7552019-07-24 15:28:08 -0500238 /** @brief Common wrapper for creating an Entry object
239 *
240 * @param[in] errMsg - The error exception message associated with the
241 * error log to be committed.
242 * @param[in] errLvl - level of the error
243 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500244 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
245 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500246 */
247 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500248 std::vector<std::string> additionalData,
249 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500250
Patrick Venturef18bf832018-10-26 18:14:00 -0700251 /** @brief Persistent sdbusplus DBus bus connection. */
252 sdbusplus::bus::bus& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600253
Patrick Venturef18bf832018-10-26 18:14:00 -0700254 /** @brief Persistent map of Entry dbus objects and their ID */
255 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600256
Patrick Venturef18bf832018-10-26 18:14:00 -0700257 /** @brief List of error ids for high severity errors */
258 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600259
Patrick Venturef18bf832018-10-26 18:14:00 -0700260 /** @brief List of error ids for Info(and below) severity */
261 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500262
Patrick Venturef18bf832018-10-26 18:14:00 -0700263 /** @brief Id of last error log entry */
264 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500265
Patrick Venturef18bf832018-10-26 18:14:00 -0700266 /** @brief The BMC firmware version */
267 const std::string fwVersion;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600268};
269
Patrick Venturef18bf832018-10-26 18:14:00 -0700270} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500271
272/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500273 * @brief Implementation for deleting all error log entries and
274 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500275 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500276 * xyz.openbmc_project.Collection.DeleteAll and
277 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500278 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500279class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500280{
Patrick Venturef18bf832018-10-26 18:14:00 -0700281 public:
282 Manager() = delete;
283 Manager(const Manager&) = delete;
284 Manager& operator=(const Manager&) = delete;
285 Manager(Manager&&) = delete;
286 Manager& operator=(Manager&&) = delete;
287 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500288
Patrick Venturef18bf832018-10-26 18:14:00 -0700289 /** @brief Constructor to put object onto bus at a dbus path.
290 * Defer signal registration (pass true for deferSignal to the
291 * base class) until after the properties are set.
292 * @param[in] bus - Bus to attach to.
293 * @param[in] path - Path to attach at.
294 * @param[in] manager - Reference to internal manager object.
295 */
296 Manager(sdbusplus::bus::bus& bus, const std::string& path,
297 internal::Manager& manager) :
Matt Spinler3fb83b32019-07-26 11:22:44 -0500298 details::ServerObject<DeleteAllIface, CreateIface>(bus, path.c_str(),
299 true),
Patrick Venturef18bf832018-10-26 18:14:00 -0700300 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500301
Patrick Venturef18bf832018-10-26 18:14:00 -0700302 /** @brief Delete all d-bus objects.
303 */
304 void deleteAll()
305 {
306 manager.eraseAll();
307 }
308
Matt Spinler3fb83b32019-07-26 11:22:44 -0500309 /** @brief D-Bus method call implementation to create an event log.
310 *
311 * @param[in] errMsg - The error exception message associated with the
312 * error log to be committed.
313 * @param[in] severity - Level of the error
314 * @param[in] additionalData - The AdditionalData property for the error
315 */
316 void create(
317 std::string message,
318 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
319 std::map<std::string, std::string> additionalData) override
320 {
321 manager.create(message, severity, additionalData);
322 }
323
Matt Spinlerc64b7122020-03-26 10:55:01 -0500324 /** @brief D-Bus method call implementation to create an event log with FFDC
325 *
326 * The same as create(), but takes an extra FFDC argument.
327 *
328 * @param[in] errMsg - The error exception message associated with the
329 * error log to be committed.
330 * @param[in] severity - Level of the error
331 * @param[in] additionalData - The AdditionalData property for the error
332 * @param[in] ffdc - A vector of FFDC file info
333 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500334 void createWithFFDCFiles(
335 std::string message,
336 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
337 std::map<std::string, std::string> additionalData,
338 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
339 sdbusplus::message::unix_fd>>
340 ffdc) override
341 {
Matt Spinlerc64b7122020-03-26 10:55:01 -0500342 manager.createWithFFDC(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500343 }
344
Patrick Venturef18bf832018-10-26 18:14:00 -0700345 private:
346 /** @brief This is a reference to manager object */
347 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500348};
349
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600350} // namespace logging
351} // namespace phosphor