blob: 74450cbb955060ab41edda73b9df8c4d6a5e684b [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
Patrick Venturef18bf832018-10-26 18:14:00 -0700174 private:
175 /*
176 * @fn _commit()
177 * @brief commit() helper
178 * @param[in] transactionId - Unique identifier of the journal entries
179 * to be committed.
180 * @param[in] errMsg - The error exception message associated with the
181 * error log to be committed.
182 * @param[in] errLvl - level of the error
183 */
184 void _commit(uint64_t transactionId, std::string&& errMsg,
185 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500186
Patrick Venturef18bf832018-10-26 18:14:00 -0700187 /** @brief Call metadata handler(s), if any. Handlers may create
188 * associations.
189 * @param[in] errorName - name of the error
190 * @param[in] additionalData - list of metadata (in key=value format)
191 * @param[out] objects - list of error's association objects
192 */
193 void processMetadata(const std::string& errorName,
194 const std::vector<std::string>& additionalData,
195 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600196
Patrick Venturef18bf832018-10-26 18:14:00 -0700197 /** @brief Synchronize unwritten journal messages to disk.
198 * @details This is the same implementation as the systemd command
199 * "journalctl --sync".
200 */
201 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500202
Patrick Venturef18bf832018-10-26 18:14:00 -0700203 /** @brief Reads the BMC code level
204 *
205 * @return std::string - the version string
206 */
207 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500208
Matt Spinler99c2b402019-05-23 14:29:16 -0500209 /** @brief Call any create() functions provided by any extensions.
210 * This is called right after an event log is created to allow
211 * extensions to create their own log based on this one.
212 *
213 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500214 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500215 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500216 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500217
Matt Spinlerb60e7552019-07-24 15:28:08 -0500218 /** @brief Common wrapper for creating an Entry object
219 *
220 * @param[in] errMsg - The error exception message associated with the
221 * error log to be committed.
222 * @param[in] errLvl - level of the error
223 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500224 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
225 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500226 */
227 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500228 std::vector<std::string> additionalData,
229 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500230
Patrick Venturef18bf832018-10-26 18:14:00 -0700231 /** @brief Persistent sdbusplus DBus bus connection. */
232 sdbusplus::bus::bus& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600233
Patrick Venturef18bf832018-10-26 18:14:00 -0700234 /** @brief Persistent map of Entry dbus objects and their ID */
235 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600236
Patrick Venturef18bf832018-10-26 18:14:00 -0700237 /** @brief List of error ids for high severity errors */
238 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600239
Patrick Venturef18bf832018-10-26 18:14:00 -0700240 /** @brief List of error ids for Info(and below) severity */
241 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500242
Patrick Venturef18bf832018-10-26 18:14:00 -0700243 /** @brief Id of last error log entry */
244 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500245
Patrick Venturef18bf832018-10-26 18:14:00 -0700246 /** @brief The BMC firmware version */
247 const std::string fwVersion;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600248};
249
Patrick Venturef18bf832018-10-26 18:14:00 -0700250} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500251
252/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500253 * @brief Implementation for deleting all error log entries and
254 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500255 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500256 * xyz.openbmc_project.Collection.DeleteAll and
257 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500258 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500259class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500260{
Patrick Venturef18bf832018-10-26 18:14:00 -0700261 public:
262 Manager() = delete;
263 Manager(const Manager&) = delete;
264 Manager& operator=(const Manager&) = delete;
265 Manager(Manager&&) = delete;
266 Manager& operator=(Manager&&) = delete;
267 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500268
Patrick Venturef18bf832018-10-26 18:14:00 -0700269 /** @brief Constructor to put object onto bus at a dbus path.
270 * Defer signal registration (pass true for deferSignal to the
271 * base class) until after the properties are set.
272 * @param[in] bus - Bus to attach to.
273 * @param[in] path - Path to attach at.
274 * @param[in] manager - Reference to internal manager object.
275 */
276 Manager(sdbusplus::bus::bus& bus, const std::string& path,
277 internal::Manager& manager) :
Matt Spinler3fb83b32019-07-26 11:22:44 -0500278 details::ServerObject<DeleteAllIface, CreateIface>(bus, path.c_str(),
279 true),
Patrick Venturef18bf832018-10-26 18:14:00 -0700280 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500281
Patrick Venturef18bf832018-10-26 18:14:00 -0700282 /** @brief Delete all d-bus objects.
283 */
284 void deleteAll()
285 {
286 manager.eraseAll();
287 }
288
Matt Spinler3fb83b32019-07-26 11:22:44 -0500289 /** @brief D-Bus method call implementation to create an event log.
290 *
291 * @param[in] errMsg - The error exception message associated with the
292 * error log to be committed.
293 * @param[in] severity - Level of the error
294 * @param[in] additionalData - The AdditionalData property for the error
295 */
296 void create(
297 std::string message,
298 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
299 std::map<std::string, std::string> additionalData) override
300 {
301 manager.create(message, severity, additionalData);
302 }
303
Matt Spinlerc64b7122020-03-26 10:55:01 -0500304 /** @brief D-Bus method call implementation to create an event log with FFDC
305 *
306 * The same as create(), but takes an extra FFDC argument.
307 *
308 * @param[in] errMsg - The error exception message associated with the
309 * error log to be committed.
310 * @param[in] severity - Level of the error
311 * @param[in] additionalData - The AdditionalData property for the error
312 * @param[in] ffdc - A vector of FFDC file info
313 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500314 void createWithFFDCFiles(
315 std::string message,
316 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
317 std::map<std::string, std::string> additionalData,
318 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
319 sdbusplus::message::unix_fd>>
320 ffdc) override
321 {
Matt Spinlerc64b7122020-03-26 10:55:01 -0500322 manager.createWithFFDC(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500323 }
324
Patrick Venturef18bf832018-10-26 18:14:00 -0700325 private:
326 /** @brief This is a reference to manager object */
327 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500328};
329
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600330} // namespace logging
331} // namespace phosphor