blob: a57f1ab90b16ba7c6a4de63c33c55e28f0a80dc3 [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
Patrick Venturef18bf832018-10-26 18:14:00 -0700186 private:
187 /*
188 * @fn _commit()
189 * @brief commit() helper
190 * @param[in] transactionId - Unique identifier of the journal entries
191 * to be committed.
192 * @param[in] errMsg - The error exception message associated with the
193 * error log to be committed.
194 * @param[in] errLvl - level of the error
195 */
196 void _commit(uint64_t transactionId, std::string&& errMsg,
197 Entry::Level errLvl);
Deepak Kodihalli6fd9dc42018-04-03 02:08:42 -0500198
Patrick Venturef18bf832018-10-26 18:14:00 -0700199 /** @brief Call metadata handler(s), if any. Handlers may create
200 * associations.
201 * @param[in] errorName - name of the error
202 * @param[in] additionalData - list of metadata (in key=value format)
203 * @param[out] objects - list of error's association objects
204 */
205 void processMetadata(const std::string& errorName,
206 const std::vector<std::string>& additionalData,
207 AssociationList& objects) const;
Deepak Kodihallia87c1572017-02-28 07:40:34 -0600208
Patrick Venturef18bf832018-10-26 18:14:00 -0700209 /** @brief Synchronize unwritten journal messages to disk.
210 * @details This is the same implementation as the systemd command
211 * "journalctl --sync".
212 */
213 void journalSync();
Adriana Kobylak5f4247f2018-03-15 10:27:05 -0500214
Patrick Venturef18bf832018-10-26 18:14:00 -0700215 /** @brief Reads the BMC code level
216 *
217 * @return std::string - the version string
218 */
219 static std::string readFWVersion();
Matt Spinler1275bd12018-05-01 15:13:53 -0500220
Matt Spinler99c2b402019-05-23 14:29:16 -0500221 /** @brief Call any create() functions provided by any extensions.
222 * This is called right after an event log is created to allow
223 * extensions to create their own log based on this one.
224 *
225 * @param[in] entry - the new event log entry
Matt Spinlerc64b7122020-03-26 10:55:01 -0500226 * @param[in] ffdc - A vector of FFDC file info
Matt Spinler99c2b402019-05-23 14:29:16 -0500227 */
Matt Spinlerc64b7122020-03-26 10:55:01 -0500228 void doExtensionLogCreate(const Entry& entry, const FFDCEntries& ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -0500229
Matt Spinlerb60e7552019-07-24 15:28:08 -0500230 /** @brief Common wrapper for creating an Entry object
231 *
232 * @param[in] errMsg - The error exception message associated with the
233 * error log to be committed.
234 * @param[in] errLvl - level of the error
235 * @param[in] additionalData - The AdditionalData property for the error
Matt Spinlerc64b7122020-03-26 10:55:01 -0500236 * @param[in] ffdc - A vector of FFDC file info. Defaults to an empty
237 * vector.
Matt Spinlerb60e7552019-07-24 15:28:08 -0500238 */
239 void createEntry(std::string errMsg, Entry::Level errLvl,
Matt Spinlerc64b7122020-03-26 10:55:01 -0500240 std::vector<std::string> additionalData,
241 const FFDCEntries& ffdc = FFDCEntries{});
Matt Spinlerb60e7552019-07-24 15:28:08 -0500242
Patrick Venturef18bf832018-10-26 18:14:00 -0700243 /** @brief Persistent sdbusplus DBus bus connection. */
244 sdbusplus::bus::bus& busLog;
Adriana Kobylakdf995fa2017-01-08 15:14:02 -0600245
Patrick Venturef18bf832018-10-26 18:14:00 -0700246 /** @brief Persistent map of Entry dbus objects and their ID */
247 std::map<uint32_t, std::unique_ptr<Entry>> entries;
Adriana Kobylak4ea7f312017-01-10 12:52:34 -0600248
Patrick Venturef18bf832018-10-26 18:14:00 -0700249 /** @brief List of error ids for high severity errors */
250 std::list<uint32_t> realErrors;
Nagaraju Gorugantie4b0b772017-11-30 02:12:45 -0600251
Patrick Venturef18bf832018-10-26 18:14:00 -0700252 /** @brief List of error ids for Info(and below) severity */
253 std::list<uint32_t> infoErrors;
Nagaraju Gorugantif8a5a792017-10-13 08:09:52 -0500254
Patrick Venturef18bf832018-10-26 18:14:00 -0700255 /** @brief Id of last error log entry */
256 uint32_t entryId;
Matt Spinler1275bd12018-05-01 15:13:53 -0500257
Patrick Venturef18bf832018-10-26 18:14:00 -0700258 /** @brief The BMC firmware version */
259 const std::string fwVersion;
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600260};
261
Patrick Venturef18bf832018-10-26 18:14:00 -0700262} // namespace internal
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500263
264/** @class Manager
Matt Spinler3fb83b32019-07-26 11:22:44 -0500265 * @brief Implementation for deleting all error log entries and
266 * creating new logs.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500267 * @details A concrete implementation for the
Matt Spinler3fb83b32019-07-26 11:22:44 -0500268 * xyz.openbmc_project.Collection.DeleteAll and
269 * xyz.openbmc_project.Logging.Create interfaces.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500270 */
Matt Spinler3fb83b32019-07-26 11:22:44 -0500271class Manager : public details::ServerObject<DeleteAllIface, CreateIface>
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500272{
Patrick Venturef18bf832018-10-26 18:14:00 -0700273 public:
274 Manager() = delete;
275 Manager(const Manager&) = delete;
276 Manager& operator=(const Manager&) = delete;
277 Manager(Manager&&) = delete;
278 Manager& operator=(Manager&&) = delete;
279 virtual ~Manager() = default;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500280
Patrick Venturef18bf832018-10-26 18:14:00 -0700281 /** @brief Constructor to put object onto bus at a dbus path.
282 * Defer signal registration (pass true for deferSignal to the
283 * base class) until after the properties are set.
284 * @param[in] bus - Bus to attach to.
285 * @param[in] path - Path to attach at.
286 * @param[in] manager - Reference to internal manager object.
287 */
288 Manager(sdbusplus::bus::bus& bus, const std::string& path,
289 internal::Manager& manager) :
Matt Spinler3fb83b32019-07-26 11:22:44 -0500290 details::ServerObject<DeleteAllIface, CreateIface>(bus, path.c_str(),
291 true),
Patrick Venturef18bf832018-10-26 18:14:00 -0700292 manager(manager){};
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500293
Patrick Venturef18bf832018-10-26 18:14:00 -0700294 /** @brief Delete all d-bus objects.
295 */
296 void deleteAll()
297 {
298 manager.eraseAll();
299 }
300
Matt Spinler3fb83b32019-07-26 11:22:44 -0500301 /** @brief D-Bus method call implementation to create an event log.
302 *
303 * @param[in] errMsg - The error exception message associated with the
304 * error log to be committed.
305 * @param[in] severity - Level of the error
306 * @param[in] additionalData - The AdditionalData property for the error
307 */
308 void create(
309 std::string message,
310 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
311 std::map<std::string, std::string> additionalData) override
312 {
313 manager.create(message, severity, additionalData);
314 }
315
Matt Spinlerc64b7122020-03-26 10:55:01 -0500316 /** @brief D-Bus method call implementation to create an event log with FFDC
317 *
318 * The same as create(), but takes an extra FFDC argument.
319 *
320 * @param[in] errMsg - The error exception message associated with the
321 * error log to be committed.
322 * @param[in] severity - Level of the error
323 * @param[in] additionalData - The AdditionalData property for the error
324 * @param[in] ffdc - A vector of FFDC file info
325 */
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500326 void createWithFFDCFiles(
327 std::string message,
328 sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level severity,
329 std::map<std::string, std::string> additionalData,
330 std::vector<std::tuple<CreateIface::FFDCFormat, uint8_t, uint8_t,
331 sdbusplus::message::unix_fd>>
332 ffdc) override
333 {
Matt Spinlerc64b7122020-03-26 10:55:01 -0500334 manager.createWithFFDC(message, severity, additionalData, ffdc);
Matt Spinlerfcbaf3e2020-03-23 09:22:45 -0500335 }
336
Patrick Venturef18bf832018-10-26 18:14:00 -0700337 private:
338 /** @brief This is a reference to manager object */
339 internal::Manager& manager;
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -0500340};
341
Adriana Kobylak8f7941e2016-11-14 14:46:23 -0600342} // namespace logging
343} // namespace phosphor