blob: 42aae88fdf21c9ff1a049bc9766ad1aee4092655 [file] [log] [blame]
Matt Spinler4e8078c2019-07-09 13:22:32 -05001#pragma once
2
Matt Spinlera34ab722019-12-16 10:39:32 -06003#include "config.h"
4
Matt Spinlerc8705e22019-09-11 12:36:07 -05005#include "data_interface.hpp"
Matt Spinlerf682b402019-12-18 13:48:08 -06006#include "event_logger.hpp"
Matt Spinlerf60ac272019-12-11 13:47:50 -06007#include "host_notifier.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -05008#include "log_manager.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -05009#include "paths.hpp"
Matt Spinler56ad2a02020-03-26 14:00:52 -050010#include "pel.hpp"
Matt Spinler367144c2019-09-19 15:33:52 -050011#include "registry.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -050012#include "repository.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -050013
Matt Spinlera34ab722019-12-16 10:39:32 -060014#include <org/open_power/Logging/PEL/server.hpp>
15#include <sdbusplus/server.hpp>
Matt Spinler6b1a5c82020-01-07 08:48:53 -060016#include <sdeventplus/event.hpp>
17#include <sdeventplus/source/event.hpp>
Matt Spinler44893cc2020-08-26 11:34:17 -050018#include <xyz/openbmc_project/Logging/Create/server.hpp>
Matt Spinlera34ab722019-12-16 10:39:32 -060019
Matt Spinler4e8078c2019-07-09 13:22:32 -050020namespace openpower
21{
22namespace pels
23{
24
Matt Spinlera34ab722019-12-16 10:39:32 -060025using PELInterface = sdbusplus::server::object::object<
26 sdbusplus::org::open_power::Logging::server::PEL>;
27
Matt Spinler4e8078c2019-07-09 13:22:32 -050028/**
29 * @brief PEL manager object
30 */
Matt Spinlera34ab722019-12-16 10:39:32 -060031class Manager : public PELInterface
Matt Spinler4e8078c2019-07-09 13:22:32 -050032{
33 public:
34 Manager() = delete;
Matt Spinler4e8078c2019-07-09 13:22:32 -050035 Manager(const Manager&) = default;
36 Manager& operator=(const Manager&) = default;
37 Manager(Manager&&) = default;
38 Manager& operator=(Manager&&) = default;
39
40 /**
41 * @brief constructor
42 *
43 * @param[in] logManager - internal::Manager object
Matt Spinlerf60ac272019-12-11 13:47:50 -060044 * @param[in] dataIface - The data interface object
Matt Spinlerf682b402019-12-18 13:48:08 -060045 * @param[in] creatorFunc - The function that EventLogger will
46 * use for creating event logs
Matt Spinler4e8078c2019-07-09 13:22:32 -050047 */
Matt Spinlerf60ac272019-12-11 13:47:50 -060048 Manager(phosphor::logging::internal::Manager& logManager,
Matt Spinlerf682b402019-12-18 13:48:08 -060049 std::unique_ptr<DataInterfaceBase> dataIface,
50 EventLogger::LogFunction creatorFunc) :
Matt Spinlera34ab722019-12-16 10:39:32 -060051 PELInterface(logManager.getBus(), OBJ_LOGGING),
Matt Spinler104e9362020-04-02 09:34:41 -050052 _logManager(logManager), _eventLogger(std::move(creatorFunc)),
Matt Spinlerf682b402019-12-18 13:48:08 -060053 _repo(getPELRepoPath()),
Matt Spinler0d804ef2020-05-12 16:16:26 -050054 _registry(getPELReadOnlyDataPath() / message::registryFileName),
Matt Spinlerff9cec22020-07-15 13:06:35 -050055 _event(sdeventplus::Event::get_default()),
Matt Spinler367144c2019-09-19 15:33:52 -050056 _dataIface(std::move(dataIface))
Matt Spinler4e8078c2019-07-09 13:22:32 -050057 {
Adriana Kobylake7d271a2020-12-07 14:32:44 -060058 for (const auto& entry : _logManager.entries)
59 {
60 setEntryPath(entry.first);
Vijay Lobocbc93a42021-05-20 19:04:07 -050061 setServiceProviderNotifyFlag(entry.first);
Adriana Kobylake7d271a2020-12-07 14:32:44 -060062 }
Matt Spinlerff9cec22020-07-15 13:06:35 -050063 setupPELDeleteWatch();
Matt Spinler4e8078c2019-07-09 13:22:32 -050064 }
65
66 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -060067 * @brief constructor that enables host notification
68 *
69 * @param[in] logManager - internal::Manager object
70 * @param[in] dataIface - The data interface object
Matt Spinlerf682b402019-12-18 13:48:08 -060071 * @param[in] creatorFunc - The function that EventLogger will
72 * use for creating event logs
Matt Spinlerf60ac272019-12-11 13:47:50 -060073 * @param[in] hostIface - The hostInterface object
74 */
75 Manager(phosphor::logging::internal::Manager& logManager,
76 std::unique_ptr<DataInterfaceBase> dataIface,
Matt Spinlerf682b402019-12-18 13:48:08 -060077 EventLogger::LogFunction creatorFunc,
Matt Spinlerf60ac272019-12-11 13:47:50 -060078 std::unique_ptr<HostInterface> hostIface) :
Matt Spinlerf682b402019-12-18 13:48:08 -060079 Manager(logManager, std::move(dataIface), std::move(creatorFunc))
Matt Spinlerf60ac272019-12-11 13:47:50 -060080 {
81 _hostNotifier = std::make_unique<HostNotifier>(
82 _repo, *(_dataIface.get()), std::move(hostIface));
83 }
84
85 /**
Matt Spinlerff9cec22020-07-15 13:06:35 -050086 * @brief Destructor
87 */
88 ~Manager();
89
90 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -050091 * @brief Creates a PEL based on the OpenBMC event log contents. If
92 * a PEL was passed in via the RAWPEL specifier in the
93 * additionalData parameter, use that instead.
94 *
95 * @param[in] message - the event log message property
96 * @param[in] obmcLogID - the corresponding OpenBMC event log id
97 * @param[in] timestamp - the Timestamp property
98 * @param[in] severity - the event log severity
99 * @param[in] additionalData - the AdditionalData property
100 * @param[in] associations - the Associations property
Matt Spinler56ad2a02020-03-26 14:00:52 -0500101 * @param[in] ffdc - A vector of FFDC file information
Matt Spinler4e8078c2019-07-09 13:22:32 -0500102 */
103 void create(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -0500104 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -0500105 const std::vector<std::string>& additionalData,
Matt Spinler56ad2a02020-03-26 14:00:52 -0500106 const std::vector<std::string>& associations,
107 const phosphor::logging::FFDCEntries& ffdc =
108 phosphor::logging::FFDCEntries{});
Matt Spinler4e8078c2019-07-09 13:22:32 -0500109
110 /**
111 * @brief Erase a PEL based on its OpenBMC event log ID
112 *
113 * @param[in] obmcLogID - the corresponding OpenBMC event log id
114 */
115 void erase(uint32_t obmcLogID);
116
117 /** @brief Says if an OpenBMC event log may not be manually deleted at this
118 * time because its corresponding PEL cannot be.
119 *
120 * There are PEL retention policies that can prohibit the manual deletion
121 * of PELs (and therefore OpenBMC event logs).
122 *
123 * @param[in] obmcLogID - the OpenBMC event log ID
124 * @return bool - true if prohibited
125 */
126 bool isDeleteProhibited(uint32_t obmcLogID);
127
Matt Spinlera34ab722019-12-16 10:39:32 -0600128 /**
129 * @brief Return a file descriptor to the raw PEL data
130 *
131 * Throws InvalidArgument if the PEL ID isn't found,
132 * and InternalFailure if anything else fails.
133 *
134 * @param[in] pelID - The PEL ID to get the data for
135 *
136 * @return unix_fd - File descriptor to the file that contains the PEL
137 */
138 sdbusplus::message::unix_fd getPEL(uint32_t pelID) override;
139
140 /**
141 * @brief Returns data for the PEL corresponding to an OpenBMC
142 * event log.
143 *
144 * @param[in] obmcLogID - The OpenBMC event log ID
145 *
146 * @return vector<uint8_t> - The raw PEL data
147 */
148 std::vector<uint8_t> getPELFromOBMCID(uint32_t obmcLogID) override;
149
150 /**
151 * @brief The D-Bus method called when a host successfully processes
152 * a PEL.
153 *
154 * This D-Bus method is called from the PLDM daemon when they get an
155 * 'Ack PEL' PLDM message from the host, which indicates the host
156 * firmware successfully sent it to the OS and this code doesn't need
157 * to send it to the host again.
158 *
159 * @param[in] pelID - The PEL ID
160 */
161 void hostAck(uint32_t pelID) override;
162
163 /**
164 * @brief D-Bus method called when the host rejects a PEL.
165 *
166 * This D-Bus method is called from the PLDM daemon when they get an
167 * 'Ack PEL' PLDM message from the host with a payload that says
168 * something when wrong.
169 *
170 * The choices are either:
171 * * Host Full - The host's staging area is full - try again later
172 * * Malrformed PEL - The host received an invalid PEL
173 *
174 * @param[in] pelID - The PEL ID
175 * @param[in] reason - One of the above two reasons
176 */
177 void hostReject(uint32_t pelID, RejectionReason reason) override;
178
Matt Spinler44893cc2020-08-26 11:34:17 -0500179 /**
180 * @brief D-Bus method to create a PEL/OpenBMC event log and
181 * return the created OpenBMC and PEL log IDs.
182 *
183 * The same as the CreateWithFFDCFiles method on the
184 * xyz.openbmc_project.Logging.Create interface, except for
185 * the return values.
186 *
187 * @param[in] message - The event log message property
188 * @param[in] severity - The event log severity
189 * @param[in] additionalData - The AdditionalData property
190 * @param[in] ffdc - A vector of FFDC file information
191 */
Matt Spinler9cc30072020-09-16 15:39:34 -0500192 std::tuple<uint32_t, uint32_t> createPELWithFFDCFiles(
193 std::string message, phosphor::logging::Entry::Level severity,
194 std::map<std::string, std::string> additionalData,
195 std::vector<std::tuple<sdbusplus::xyz::openbmc_project::Logging::
196 server::Create::FFDCFormat,
197 uint8_t, uint8_t, sdbusplus::message::unix_fd>>
Matt Spinler44893cc2020-08-26 11:34:17 -0500198 fFDC) override;
Matt Spinler9cc30072020-09-16 15:39:34 -0500199
Matt Spinler19e72902020-01-24 11:05:20 -0600200 /**
201 * @brief Converts the ESEL field in an OpenBMC event log to a
202 * vector of uint8_ts that just contains the PEL data.
203 *
204 * That data string looks like: "50 48 00 ab ..."
205 *
206 * Throws an exception on any failures.
207 *
208 * @param[in] esel - The ESEL string
209 *
210 * @return std::vector<uint8_t> - The contained PEL data
211 */
212 static std::vector<uint8_t> eselToRawData(const std::string& esel);
213
Vijay Lobod354a392021-06-01 16:21:02 -0500214 /**
215 * @brief Generate event ID from the PEL
216 *
217 * @param[in] pel - The PEL to use
218 */
219 std::string getEventId(const openpower::pels::PEL& pel) const;
220
Ramesh Iyyarf4203c42021-06-24 06:09:23 -0500221 /** @brief Implementation for GetPELIdFromBMCLogId
222 *
223 * Returns the PEL Id (aka Entry ID (EID)) based on the given
224 * BMC event log id.
225 *
226 * @param[in] bmcLogId - The BMC event log id of the PEL to retrieve
227 * the PEL id.
228 *
229 * @return uint32_t - The Id of the PEL.
230 * Throw "InvalidArgument" if not found.
231 */
232 uint32_t getPELIdFromBMCLogId(uint32_t bmcLogId) override;
233
Matt Spinler4e8078c2019-07-09 13:22:32 -0500234 private:
235 /**
236 * @brief Adds a received raw PEL to the PEL repository
237 *
238 * @param[in] rawPelPath - The path to the file that contains the
239 * raw PEL.
240 * @param[in] obmcLogID - the corresponding OpenBMC event log id
241 */
242 void addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID);
243
244 /**
245 * @brief Creates a PEL based on the OpenBMC event log contents.
246 *
247 * @param[in] message - The event log message property
248 * @param[in] obmcLogID - the corresponding OpenBMC event log id
249 * @param[in] timestamp - The timestamp property
250 * @param[in] severity - The event log severity
251 * @param[in] additionalData - The AdditionalData property
252 * @param[in] associations - The associations property
Matt Spinler56ad2a02020-03-26 14:00:52 -0500253 * @param[in] ffdc - A vector of FFDC file information
Matt Spinler4e8078c2019-07-09 13:22:32 -0500254 */
255 void createPEL(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -0500256 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -0500257 const std::vector<std::string>& additionalData,
Matt Spinler56ad2a02020-03-26 14:00:52 -0500258 const std::vector<std::string>& associations,
259 const phosphor::logging::FFDCEntries& ffdc);
Matt Spinler4e8078c2019-07-09 13:22:32 -0500260
261 /**
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600262 * @brief Schedules a close of the file descriptor to occur from
263 * the event loop.
264 *
265 * Uses sd_event_add_defer
266 *
267 * @param[in] fd - The file descriptor to close
268 */
269 void scheduleFDClose(int fd);
270
271 /**
272 * @brief Closes the file descriptor passed in.
273 *
274 * This is called from the event loop to close FDs returned
275 * from getPEL().
276 *
277 * @param[in] fd - The file descriptor to close
278 * @param[in] source - The event source object used
279 */
280 void closeFD(int fd, sdeventplus::source::EventBase& source);
281
282 /**
Matt Spinler19e72902020-01-24 11:05:20 -0600283 * @brief Adds a PEL to the repository given its data
284 *
285 * @param[in] pelData - The PEL to add as a vector of uint8_ts
286 * @param[in] obmcLogID - the OpenBMC event log ID
287 */
288 void addPEL(std::vector<uint8_t>& pelData, uint32_t obmcLogID);
289
290 /**
291 * @brief Adds the PEL stored in the ESEL field of the AdditionalData
292 * property of an OpenBMC event log to the repository.
293 *
294 * @param[in] esel - The ESEL AdditionalData contents
295 * @param[in] obmcLogID - The OpenBMC event log ID
296 */
297 void addESELPEL(const std::string& esel, uint32_t obmcLogID);
298
299 /**
Matt Spinler56ad2a02020-03-26 14:00:52 -0500300 * @brief Converts the D-Bus FFDC method argument into a data
301 * structure understood by the PEL code.
302 *
303 * @param[in] ffdc - A vector of FFDC file information
304 *
305 * @return PelFFDC - The PEL FFDC data structure
306 */
307 PelFFDC convertToPelFFDC(const phosphor::logging::FFDCEntries& ffdc);
308
309 /**
Matt Spinler7e727a32020-07-07 15:00:17 -0500310 * @brief Schedules a PEL repository prune to occur from
311 * the event loop.
312 *
313 * Uses sd_event_add_defer
314 */
315 void scheduleRepoPrune();
316
317 /**
318 * @brief Prunes old PELs out of the repository to save space.
319 *
320 * This is called from the event loop.
321 *
322 * @param[in] source - The event source object used
323 */
324 void pruneRepo(sdeventplus::source::EventBase& source);
325
326 /**
Matt Spinlerff9cec22020-07-15 13:06:35 -0500327 * @brief Sets up an inotify watch to watch for deleted PEL
328 * files. Calls pelFileDeleted() when that occurs.
329 */
330 void setupPELDeleteWatch();
331
332 /**
333 * @brief Called when the inotify watch put on the repository directory
334 * detects a PEL file was deleted.
335 *
336 * Will tell the Repository class about the deleted PEL, and then tell
337 * the log manager class to delete the corresponding OpenBMC event log.
338 */
339 void pelFileDeleted(sdeventplus::source::IO& io, int fd, uint32_t revents);
340
341 /**
Andrew Geissler44fc3162020-07-09 09:21:31 -0500342 * @brief Check if the input PEL should cause a quiesce of the system
343 *
344 * If QuiesceOnHwError is enabled within phosphor-settings and the PEL
Matt Spinlerb2abc042021-05-17 15:32:50 -0600345 * from the host has a severity which is not SeverityType::nonError or
346 * recovered then execute the quiesce and boot block logic.
Andrew Geissler44fc3162020-07-09 09:21:31 -0500347 *
348 * @param[in] pel - The PEL to check
349 */
350 void checkPelAndQuiesce(std::unique_ptr<openpower::pels::PEL>& pel);
351
352 /**
Vijay Lobod354a392021-06-01 16:21:02 -0500353 * @brief Update eventId D-bus property for this error log
354 *
355 * Update the eventId property of D-bus with SRC and hexwords from the
356 * PEL created
357 *
358 * @param[in] pel - The PEL to use
359 */
360 void updateEventId(std::unique_ptr<openpower::pels::PEL>& pel);
361
362 /**
Adriana Kobylake7d271a2020-12-07 14:32:44 -0600363 * @brief Sets the FilePath of the specified error log entry to the PEL file
364 * path.
365 *
366 * @param[in] obmcLogID - The OpenBMC entry log ID
367 */
368 void setEntryPath(uint32_t obmcLogID);
369
370 /**
Vijay Lobocbc93a42021-05-20 19:04:07 -0500371 * @brief Sets the serviceProviderNotify D-bus property of PEL.
372 *
373 * @param[in] obmcLogID - The OpenBMC entry log ID
374 */
375 void setServiceProviderNotifyFlag(uint32_t obmcLogID);
376
377 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -0500378 * @brief Reference to phosphor-logging's Manager class
379 */
Matt Spinler367144c2019-09-19 15:33:52 -0500380 phosphor::logging::internal::Manager& _logManager;
Matt Spinler89fa0822019-07-17 13:54:30 -0500381
382 /**
Matt Spinlerf682b402019-12-18 13:48:08 -0600383 * @brief Handles creating event logs/PELs from within
384 * the PEL extension code
385 */
386 EventLogger _eventLogger;
387
388 /**
Matt Spinler89fa0822019-07-17 13:54:30 -0500389 * @brief The PEL repository object
390 */
391 Repository _repo;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500392
393 /**
Matt Spinler367144c2019-09-19 15:33:52 -0500394 * @brief The PEL message registry object
395 */
396 message::Registry _registry;
397
398 /**
Matt Spinlerff9cec22020-07-15 13:06:35 -0500399 * @brief The Event object this class uses
400 */
401 sdeventplus::Event _event;
402
403 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -0500404 * @brief The API the PEL sections use to gather data
405 */
406 std::unique_ptr<DataInterfaceBase> _dataIface;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600407
408 /**
409 * @brief The HostNotifier object used for telling the
410 * host about new PELs
411 */
412 std::unique_ptr<HostNotifier> _hostNotifier;
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600413
414 /**
415 * @brief The event source for closing a PEL file descriptor after
416 * it has been returned from the getPEL D-Bus method.
417 */
418 std::unique_ptr<sdeventplus::source::Defer> _fdCloserEventSource;
Matt Spinler7e727a32020-07-07 15:00:17 -0500419
420 /**
421 * @brief The even source for removing old PELs when the repo is
422 * running out of space to make room for new ones.
423 */
424 std::unique_ptr<sdeventplus::source::Defer> _repoPrunerEventSource;
Matt Spinlerff9cec22020-07-15 13:06:35 -0500425
426 /**
427 * @brief The even source for watching for deleted PEL files.
428 */
429 std::unique_ptr<sdeventplus::source::IO> _pelFileDeleteEventSource;
430
431 /**
432 * @brief The file descriptor returned by inotify_init1() used
433 * for watching for deleted PEL files.
434 */
435 int _pelFileDeleteFD = -1;
436
437 /**
438 * @brief The file descriptor returned by inotify_add_watch().
439 */
440 int _pelFileDeleteWatchFD = -1;
Matt Spinler4e8078c2019-07-09 13:22:32 -0500441};
442
443} // namespace pels
444} // namespace openpower