blob: bec67ca45b484e5b41b854079b1121b78790e8e9 [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 Spinler367144c2019-09-19 15:33:52 -050010#include "registry.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -050011#include "repository.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -050012
Matt Spinlera34ab722019-12-16 10:39:32 -060013#include <org/open_power/Logging/PEL/server.hpp>
14#include <sdbusplus/server.hpp>
Matt Spinler6b1a5c82020-01-07 08:48:53 -060015#include <sdeventplus/event.hpp>
16#include <sdeventplus/source/event.hpp>
Matt Spinlera34ab722019-12-16 10:39:32 -060017
Matt Spinler4e8078c2019-07-09 13:22:32 -050018namespace openpower
19{
20namespace pels
21{
22
Matt Spinlera34ab722019-12-16 10:39:32 -060023using PELInterface = sdbusplus::server::object::object<
24 sdbusplus::org::open_power::Logging::server::PEL>;
25
Matt Spinler4e8078c2019-07-09 13:22:32 -050026/**
27 * @brief PEL manager object
28 */
Matt Spinlera34ab722019-12-16 10:39:32 -060029class Manager : public PELInterface
Matt Spinler4e8078c2019-07-09 13:22:32 -050030{
31 public:
32 Manager() = delete;
33 ~Manager() = default;
34 Manager(const Manager&) = default;
35 Manager& operator=(const Manager&) = default;
36 Manager(Manager&&) = default;
37 Manager& operator=(Manager&&) = default;
38
39 /**
40 * @brief constructor
41 *
42 * @param[in] logManager - internal::Manager object
Matt Spinlerf60ac272019-12-11 13:47:50 -060043 * @param[in] dataIface - The data interface object
Matt Spinlerf682b402019-12-18 13:48:08 -060044 * @param[in] creatorFunc - The function that EventLogger will
45 * use for creating event logs
Matt Spinler4e8078c2019-07-09 13:22:32 -050046 */
Matt Spinlerf60ac272019-12-11 13:47:50 -060047 Manager(phosphor::logging::internal::Manager& logManager,
Matt Spinlerf682b402019-12-18 13:48:08 -060048 std::unique_ptr<DataInterfaceBase> dataIface,
49 EventLogger::LogFunction creatorFunc) :
Matt Spinlera34ab722019-12-16 10:39:32 -060050 PELInterface(logManager.getBus(), OBJ_LOGGING),
Matt Spinlerf682b402019-12-18 13:48:08 -060051 _logManager(logManager),
52 _eventLogger(logManager.getBus().get_event(), std::move(creatorFunc)),
53 _repo(getPELRepoPath()),
Matt Spinler367144c2019-09-19 15:33:52 -050054 _registry(getMessageRegistryPath() / message::registryFileName),
55 _dataIface(std::move(dataIface))
Matt Spinler4e8078c2019-07-09 13:22:32 -050056 {
57 }
58
59 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -060060 * @brief constructor that enables host notification
61 *
62 * @param[in] logManager - internal::Manager object
63 * @param[in] dataIface - The data interface object
Matt Spinlerf682b402019-12-18 13:48:08 -060064 * @param[in] creatorFunc - The function that EventLogger will
65 * use for creating event logs
Matt Spinlerf60ac272019-12-11 13:47:50 -060066 * @param[in] hostIface - The hostInterface object
67 */
68 Manager(phosphor::logging::internal::Manager& logManager,
69 std::unique_ptr<DataInterfaceBase> dataIface,
Matt Spinlerf682b402019-12-18 13:48:08 -060070 EventLogger::LogFunction creatorFunc,
Matt Spinlerf60ac272019-12-11 13:47:50 -060071 std::unique_ptr<HostInterface> hostIface) :
Matt Spinlerf682b402019-12-18 13:48:08 -060072 Manager(logManager, std::move(dataIface), std::move(creatorFunc))
Matt Spinlerf60ac272019-12-11 13:47:50 -060073 {
74 _hostNotifier = std::make_unique<HostNotifier>(
75 _repo, *(_dataIface.get()), std::move(hostIface));
76 }
77
78 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -050079 * @brief Creates a PEL based on the OpenBMC event log contents. If
80 * a PEL was passed in via the RAWPEL specifier in the
81 * additionalData parameter, use that instead.
82 *
83 * @param[in] message - the event log message property
84 * @param[in] obmcLogID - the corresponding OpenBMC event log id
85 * @param[in] timestamp - the Timestamp property
86 * @param[in] severity - the event log severity
87 * @param[in] additionalData - the AdditionalData property
88 * @param[in] associations - the Associations property
89 */
90 void create(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -050091 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -050092 const std::vector<std::string>& additionalData,
93 const std::vector<std::string>& associations);
94
95 /**
96 * @brief Erase a PEL based on its OpenBMC event log ID
97 *
98 * @param[in] obmcLogID - the corresponding OpenBMC event log id
99 */
100 void erase(uint32_t obmcLogID);
101
102 /** @brief Says if an OpenBMC event log may not be manually deleted at this
103 * time because its corresponding PEL cannot be.
104 *
105 * There are PEL retention policies that can prohibit the manual deletion
106 * of PELs (and therefore OpenBMC event logs).
107 *
108 * @param[in] obmcLogID - the OpenBMC event log ID
109 * @return bool - true if prohibited
110 */
111 bool isDeleteProhibited(uint32_t obmcLogID);
112
Matt Spinlera34ab722019-12-16 10:39:32 -0600113 /**
114 * @brief Return a file descriptor to the raw PEL data
115 *
116 * Throws InvalidArgument if the PEL ID isn't found,
117 * and InternalFailure if anything else fails.
118 *
119 * @param[in] pelID - The PEL ID to get the data for
120 *
121 * @return unix_fd - File descriptor to the file that contains the PEL
122 */
123 sdbusplus::message::unix_fd getPEL(uint32_t pelID) override;
124
125 /**
126 * @brief Returns data for the PEL corresponding to an OpenBMC
127 * event log.
128 *
129 * @param[in] obmcLogID - The OpenBMC event log ID
130 *
131 * @return vector<uint8_t> - The raw PEL data
132 */
133 std::vector<uint8_t> getPELFromOBMCID(uint32_t obmcLogID) override;
134
135 /**
136 * @brief The D-Bus method called when a host successfully processes
137 * a PEL.
138 *
139 * This D-Bus method is called from the PLDM daemon when they get an
140 * 'Ack PEL' PLDM message from the host, which indicates the host
141 * firmware successfully sent it to the OS and this code doesn't need
142 * to send it to the host again.
143 *
144 * @param[in] pelID - The PEL ID
145 */
146 void hostAck(uint32_t pelID) override;
147
148 /**
149 * @brief D-Bus method called when the host rejects a PEL.
150 *
151 * This D-Bus method is called from the PLDM daemon when they get an
152 * 'Ack PEL' PLDM message from the host with a payload that says
153 * something when wrong.
154 *
155 * The choices are either:
156 * * Host Full - The host's staging area is full - try again later
157 * * Malrformed PEL - The host received an invalid PEL
158 *
159 * @param[in] pelID - The PEL ID
160 * @param[in] reason - One of the above two reasons
161 */
162 void hostReject(uint32_t pelID, RejectionReason reason) override;
163
Matt Spinler4e8078c2019-07-09 13:22:32 -0500164 private:
165 /**
166 * @brief Adds a received raw PEL to the PEL repository
167 *
168 * @param[in] rawPelPath - The path to the file that contains the
169 * raw PEL.
170 * @param[in] obmcLogID - the corresponding OpenBMC event log id
171 */
172 void addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID);
173
174 /**
175 * @brief Creates a PEL based on the OpenBMC event log contents.
176 *
177 * @param[in] message - The event log message property
178 * @param[in] obmcLogID - the corresponding OpenBMC event log id
179 * @param[in] timestamp - The timestamp property
180 * @param[in] severity - The event log severity
181 * @param[in] additionalData - The AdditionalData property
182 * @param[in] associations - The associations property
183 */
184 void createPEL(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -0500185 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -0500186 const std::vector<std::string>& additionalData,
187 const std::vector<std::string>& associations);
188
189 /**
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600190 * @brief Schedules a close of the file descriptor to occur from
191 * the event loop.
192 *
193 * Uses sd_event_add_defer
194 *
195 * @param[in] fd - The file descriptor to close
196 */
197 void scheduleFDClose(int fd);
198
199 /**
200 * @brief Closes the file descriptor passed in.
201 *
202 * This is called from the event loop to close FDs returned
203 * from getPEL().
204 *
205 * @param[in] fd - The file descriptor to close
206 * @param[in] source - The event source object used
207 */
208 void closeFD(int fd, sdeventplus::source::EventBase& source);
209
210 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -0500211 * @brief Reference to phosphor-logging's Manager class
212 */
Matt Spinler367144c2019-09-19 15:33:52 -0500213 phosphor::logging::internal::Manager& _logManager;
Matt Spinler89fa0822019-07-17 13:54:30 -0500214
215 /**
Matt Spinlerf682b402019-12-18 13:48:08 -0600216 * @brief Handles creating event logs/PELs from within
217 * the PEL extension code
218 */
219 EventLogger _eventLogger;
220
221 /**
Matt Spinler89fa0822019-07-17 13:54:30 -0500222 * @brief The PEL repository object
223 */
224 Repository _repo;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500225
226 /**
Matt Spinler367144c2019-09-19 15:33:52 -0500227 * @brief The PEL message registry object
228 */
229 message::Registry _registry;
230
231 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -0500232 * @brief The API the PEL sections use to gather data
233 */
234 std::unique_ptr<DataInterfaceBase> _dataIface;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600235
236 /**
237 * @brief The HostNotifier object used for telling the
238 * host about new PELs
239 */
240 std::unique_ptr<HostNotifier> _hostNotifier;
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600241
242 /**
243 * @brief The event source for closing a PEL file descriptor after
244 * it has been returned from the getPEL D-Bus method.
245 */
246 std::unique_ptr<sdeventplus::source::Defer> _fdCloserEventSource;
Matt Spinler4e8078c2019-07-09 13:22:32 -0500247};
248
249} // namespace pels
250} // namespace openpower