blob: d25afbde3a382e6a55a3d0e9492c819bb228cf88 [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 Spinlera34ab722019-12-16 10:39:32 -060018
Matt Spinler4e8078c2019-07-09 13:22:32 -050019namespace openpower
20{
21namespace pels
22{
23
Matt Spinlera34ab722019-12-16 10:39:32 -060024using PELInterface = sdbusplus::server::object::object<
25 sdbusplus::org::open_power::Logging::server::PEL>;
26
Matt Spinler4e8078c2019-07-09 13:22:32 -050027/**
28 * @brief PEL manager object
29 */
Matt Spinlera34ab722019-12-16 10:39:32 -060030class Manager : public PELInterface
Matt Spinler4e8078c2019-07-09 13:22:32 -050031{
32 public:
33 Manager() = delete;
34 ~Manager() = default;
35 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 Spinlerf682b402019-12-18 13:48:08 -060052 _logManager(logManager),
53 _eventLogger(logManager.getBus().get_event(), std::move(creatorFunc)),
54 _repo(getPELRepoPath()),
Matt Spinler367144c2019-09-19 15:33:52 -050055 _registry(getMessageRegistryPath() / message::registryFileName),
56 _dataIface(std::move(dataIface))
Matt Spinler4e8078c2019-07-09 13:22:32 -050057 {
58 }
59
60 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -060061 * @brief constructor that enables host notification
62 *
63 * @param[in] logManager - internal::Manager object
64 * @param[in] dataIface - The data interface object
Matt Spinlerf682b402019-12-18 13:48:08 -060065 * @param[in] creatorFunc - The function that EventLogger will
66 * use for creating event logs
Matt Spinlerf60ac272019-12-11 13:47:50 -060067 * @param[in] hostIface - The hostInterface object
68 */
69 Manager(phosphor::logging::internal::Manager& logManager,
70 std::unique_ptr<DataInterfaceBase> dataIface,
Matt Spinlerf682b402019-12-18 13:48:08 -060071 EventLogger::LogFunction creatorFunc,
Matt Spinlerf60ac272019-12-11 13:47:50 -060072 std::unique_ptr<HostInterface> hostIface) :
Matt Spinlerf682b402019-12-18 13:48:08 -060073 Manager(logManager, std::move(dataIface), std::move(creatorFunc))
Matt Spinlerf60ac272019-12-11 13:47:50 -060074 {
75 _hostNotifier = std::make_unique<HostNotifier>(
76 _repo, *(_dataIface.get()), std::move(hostIface));
77 }
78
79 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -050080 * @brief Creates a PEL based on the OpenBMC event log contents. If
81 * a PEL was passed in via the RAWPEL specifier in the
82 * additionalData parameter, use that instead.
83 *
84 * @param[in] message - the event log message property
85 * @param[in] obmcLogID - the corresponding OpenBMC event log id
86 * @param[in] timestamp - the Timestamp property
87 * @param[in] severity - the event log severity
88 * @param[in] additionalData - the AdditionalData property
89 * @param[in] associations - the Associations property
Matt Spinler56ad2a02020-03-26 14:00:52 -050090 * @param[in] ffdc - A vector of FFDC file information
Matt Spinler4e8078c2019-07-09 13:22:32 -050091 */
92 void create(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -050093 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -050094 const std::vector<std::string>& additionalData,
Matt Spinler56ad2a02020-03-26 14:00:52 -050095 const std::vector<std::string>& associations,
96 const phosphor::logging::FFDCEntries& ffdc =
97 phosphor::logging::FFDCEntries{});
Matt Spinler4e8078c2019-07-09 13:22:32 -050098
99 /**
100 * @brief Erase a PEL based on its OpenBMC event log ID
101 *
102 * @param[in] obmcLogID - the corresponding OpenBMC event log id
103 */
104 void erase(uint32_t obmcLogID);
105
106 /** @brief Says if an OpenBMC event log may not be manually deleted at this
107 * time because its corresponding PEL cannot be.
108 *
109 * There are PEL retention policies that can prohibit the manual deletion
110 * of PELs (and therefore OpenBMC event logs).
111 *
112 * @param[in] obmcLogID - the OpenBMC event log ID
113 * @return bool - true if prohibited
114 */
115 bool isDeleteProhibited(uint32_t obmcLogID);
116
Matt Spinlera34ab722019-12-16 10:39:32 -0600117 /**
118 * @brief Return a file descriptor to the raw PEL data
119 *
120 * Throws InvalidArgument if the PEL ID isn't found,
121 * and InternalFailure if anything else fails.
122 *
123 * @param[in] pelID - The PEL ID to get the data for
124 *
125 * @return unix_fd - File descriptor to the file that contains the PEL
126 */
127 sdbusplus::message::unix_fd getPEL(uint32_t pelID) override;
128
129 /**
130 * @brief Returns data for the PEL corresponding to an OpenBMC
131 * event log.
132 *
133 * @param[in] obmcLogID - The OpenBMC event log ID
134 *
135 * @return vector<uint8_t> - The raw PEL data
136 */
137 std::vector<uint8_t> getPELFromOBMCID(uint32_t obmcLogID) override;
138
139 /**
140 * @brief The D-Bus method called when a host successfully processes
141 * a PEL.
142 *
143 * This D-Bus method is called from the PLDM daemon when they get an
144 * 'Ack PEL' PLDM message from the host, which indicates the host
145 * firmware successfully sent it to the OS and this code doesn't need
146 * to send it to the host again.
147 *
148 * @param[in] pelID - The PEL ID
149 */
150 void hostAck(uint32_t pelID) override;
151
152 /**
153 * @brief D-Bus method called when the host rejects a PEL.
154 *
155 * This D-Bus method is called from the PLDM daemon when they get an
156 * 'Ack PEL' PLDM message from the host with a payload that says
157 * something when wrong.
158 *
159 * The choices are either:
160 * * Host Full - The host's staging area is full - try again later
161 * * Malrformed PEL - The host received an invalid PEL
162 *
163 * @param[in] pelID - The PEL ID
164 * @param[in] reason - One of the above two reasons
165 */
166 void hostReject(uint32_t pelID, RejectionReason reason) override;
167
Matt Spinler19e72902020-01-24 11:05:20 -0600168 /**
169 * @brief Converts the ESEL field in an OpenBMC event log to a
170 * vector of uint8_ts that just contains the PEL data.
171 *
172 * That data string looks like: "50 48 00 ab ..."
173 *
174 * Throws an exception on any failures.
175 *
176 * @param[in] esel - The ESEL string
177 *
178 * @return std::vector<uint8_t> - The contained PEL data
179 */
180 static std::vector<uint8_t> eselToRawData(const std::string& esel);
181
Matt Spinler4e8078c2019-07-09 13:22:32 -0500182 private:
183 /**
184 * @brief Adds a received raw PEL to the PEL repository
185 *
186 * @param[in] rawPelPath - The path to the file that contains the
187 * raw PEL.
188 * @param[in] obmcLogID - the corresponding OpenBMC event log id
189 */
190 void addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID);
191
192 /**
193 * @brief Creates a PEL based on the OpenBMC event log contents.
194 *
195 * @param[in] message - The event log message property
196 * @param[in] obmcLogID - the corresponding OpenBMC event log id
197 * @param[in] timestamp - The timestamp property
198 * @param[in] severity - The event log severity
199 * @param[in] additionalData - The AdditionalData property
200 * @param[in] associations - The associations property
Matt Spinler56ad2a02020-03-26 14:00:52 -0500201 * @param[in] ffdc - A vector of FFDC file information
Matt Spinler4e8078c2019-07-09 13:22:32 -0500202 */
203 void createPEL(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -0500204 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -0500205 const std::vector<std::string>& additionalData,
Matt Spinler56ad2a02020-03-26 14:00:52 -0500206 const std::vector<std::string>& associations,
207 const phosphor::logging::FFDCEntries& ffdc);
Matt Spinler4e8078c2019-07-09 13:22:32 -0500208
209 /**
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600210 * @brief Schedules a close of the file descriptor to occur from
211 * the event loop.
212 *
213 * Uses sd_event_add_defer
214 *
215 * @param[in] fd - The file descriptor to close
216 */
217 void scheduleFDClose(int fd);
218
219 /**
220 * @brief Closes the file descriptor passed in.
221 *
222 * This is called from the event loop to close FDs returned
223 * from getPEL().
224 *
225 * @param[in] fd - The file descriptor to close
226 * @param[in] source - The event source object used
227 */
228 void closeFD(int fd, sdeventplus::source::EventBase& source);
229
230 /**
Matt Spinler19e72902020-01-24 11:05:20 -0600231 * @brief Adds a PEL to the repository given its data
232 *
233 * @param[in] pelData - The PEL to add as a vector of uint8_ts
234 * @param[in] obmcLogID - the OpenBMC event log ID
235 */
236 void addPEL(std::vector<uint8_t>& pelData, uint32_t obmcLogID);
237
238 /**
239 * @brief Adds the PEL stored in the ESEL field of the AdditionalData
240 * property of an OpenBMC event log to the repository.
241 *
242 * @param[in] esel - The ESEL AdditionalData contents
243 * @param[in] obmcLogID - The OpenBMC event log ID
244 */
245 void addESELPEL(const std::string& esel, uint32_t obmcLogID);
246
247 /**
Matt Spinler56ad2a02020-03-26 14:00:52 -0500248 * @brief Converts the D-Bus FFDC method argument into a data
249 * structure understood by the PEL code.
250 *
251 * @param[in] ffdc - A vector of FFDC file information
252 *
253 * @return PelFFDC - The PEL FFDC data structure
254 */
255 PelFFDC convertToPelFFDC(const phosphor::logging::FFDCEntries& ffdc);
256
257 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -0500258 * @brief Reference to phosphor-logging's Manager class
259 */
Matt Spinler367144c2019-09-19 15:33:52 -0500260 phosphor::logging::internal::Manager& _logManager;
Matt Spinler89fa0822019-07-17 13:54:30 -0500261
262 /**
Matt Spinlerf682b402019-12-18 13:48:08 -0600263 * @brief Handles creating event logs/PELs from within
264 * the PEL extension code
265 */
266 EventLogger _eventLogger;
267
268 /**
Matt Spinler89fa0822019-07-17 13:54:30 -0500269 * @brief The PEL repository object
270 */
271 Repository _repo;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500272
273 /**
Matt Spinler367144c2019-09-19 15:33:52 -0500274 * @brief The PEL message registry object
275 */
276 message::Registry _registry;
277
278 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -0500279 * @brief The API the PEL sections use to gather data
280 */
281 std::unique_ptr<DataInterfaceBase> _dataIface;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600282
283 /**
284 * @brief The HostNotifier object used for telling the
285 * host about new PELs
286 */
287 std::unique_ptr<HostNotifier> _hostNotifier;
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600288
289 /**
290 * @brief The event source for closing a PEL file descriptor after
291 * it has been returned from the getPEL D-Bus method.
292 */
293 std::unique_ptr<sdeventplus::source::Defer> _fdCloserEventSource;
Matt Spinler4e8078c2019-07-09 13:22:32 -0500294};
295
296} // namespace pels
297} // namespace openpower