blob: 14904a9b8d5d5e56ea3a7505b5b4db6dd16562e6 [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 Spinlerf60ac272019-12-11 13:47:50 -06006#include "host_notifier.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -05007#include "log_manager.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -05008#include "paths.hpp"
Matt Spinler367144c2019-09-19 15:33:52 -05009#include "registry.hpp"
Matt Spinler89fa0822019-07-17 13:54:30 -050010#include "repository.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -050011
Matt Spinlera34ab722019-12-16 10:39:32 -060012#include <org/open_power/Logging/PEL/server.hpp>
13#include <sdbusplus/server.hpp>
Matt Spinler6b1a5c82020-01-07 08:48:53 -060014#include <sdeventplus/event.hpp>
15#include <sdeventplus/source/event.hpp>
Matt Spinlera34ab722019-12-16 10:39:32 -060016
Matt Spinler4e8078c2019-07-09 13:22:32 -050017namespace openpower
18{
19namespace pels
20{
21
Matt Spinlera34ab722019-12-16 10:39:32 -060022using PELInterface = sdbusplus::server::object::object<
23 sdbusplus::org::open_power::Logging::server::PEL>;
24
Matt Spinler4e8078c2019-07-09 13:22:32 -050025/**
26 * @brief PEL manager object
27 */
Matt Spinlera34ab722019-12-16 10:39:32 -060028class Manager : public PELInterface
Matt Spinler4e8078c2019-07-09 13:22:32 -050029{
30 public:
31 Manager() = delete;
32 ~Manager() = default;
33 Manager(const Manager&) = default;
34 Manager& operator=(const Manager&) = default;
35 Manager(Manager&&) = default;
36 Manager& operator=(Manager&&) = default;
37
38 /**
39 * @brief constructor
40 *
41 * @param[in] logManager - internal::Manager object
Matt Spinlerf60ac272019-12-11 13:47:50 -060042 * @param[in] dataIface - The data interface object
Matt Spinler4e8078c2019-07-09 13:22:32 -050043 */
Matt Spinlerf60ac272019-12-11 13:47:50 -060044 Manager(phosphor::logging::internal::Manager& logManager,
45 std::unique_ptr<DataInterfaceBase> dataIface) :
Matt Spinlera34ab722019-12-16 10:39:32 -060046 PELInterface(logManager.getBus(), OBJ_LOGGING),
47 _logManager(logManager), _repo(getPELRepoPath()),
Matt Spinler367144c2019-09-19 15:33:52 -050048 _registry(getMessageRegistryPath() / message::registryFileName),
49 _dataIface(std::move(dataIface))
Matt Spinler4e8078c2019-07-09 13:22:32 -050050 {
51 }
52
53 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -060054 * @brief constructor that enables host notification
55 *
56 * @param[in] logManager - internal::Manager object
57 * @param[in] dataIface - The data interface object
58 * @param[in] hostIface - The hostInterface object
59 */
60 Manager(phosphor::logging::internal::Manager& logManager,
61 std::unique_ptr<DataInterfaceBase> dataIface,
62 std::unique_ptr<HostInterface> hostIface) :
63 Manager(logManager, std::move(dataIface))
64 {
65 _hostNotifier = std::make_unique<HostNotifier>(
66 _repo, *(_dataIface.get()), std::move(hostIface));
67 }
68
69 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -050070 * @brief Creates a PEL based on the OpenBMC event log contents. If
71 * a PEL was passed in via the RAWPEL specifier in the
72 * additionalData parameter, use that instead.
73 *
74 * @param[in] message - the event log message property
75 * @param[in] obmcLogID - the corresponding OpenBMC event log id
76 * @param[in] timestamp - the Timestamp property
77 * @param[in] severity - the event log severity
78 * @param[in] additionalData - the AdditionalData property
79 * @param[in] associations - the Associations property
80 */
81 void create(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -050082 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -050083 const std::vector<std::string>& additionalData,
84 const std::vector<std::string>& associations);
85
86 /**
87 * @brief Erase a PEL based on its OpenBMC event log ID
88 *
89 * @param[in] obmcLogID - the corresponding OpenBMC event log id
90 */
91 void erase(uint32_t obmcLogID);
92
93 /** @brief Says if an OpenBMC event log may not be manually deleted at this
94 * time because its corresponding PEL cannot be.
95 *
96 * There are PEL retention policies that can prohibit the manual deletion
97 * of PELs (and therefore OpenBMC event logs).
98 *
99 * @param[in] obmcLogID - the OpenBMC event log ID
100 * @return bool - true if prohibited
101 */
102 bool isDeleteProhibited(uint32_t obmcLogID);
103
Matt Spinlera34ab722019-12-16 10:39:32 -0600104 /**
105 * @brief Return a file descriptor to the raw PEL data
106 *
107 * Throws InvalidArgument if the PEL ID isn't found,
108 * and InternalFailure if anything else fails.
109 *
110 * @param[in] pelID - The PEL ID to get the data for
111 *
112 * @return unix_fd - File descriptor to the file that contains the PEL
113 */
114 sdbusplus::message::unix_fd getPEL(uint32_t pelID) override;
115
116 /**
117 * @brief Returns data for the PEL corresponding to an OpenBMC
118 * event log.
119 *
120 * @param[in] obmcLogID - The OpenBMC event log ID
121 *
122 * @return vector<uint8_t> - The raw PEL data
123 */
124 std::vector<uint8_t> getPELFromOBMCID(uint32_t obmcLogID) override;
125
126 /**
127 * @brief The D-Bus method called when a host successfully processes
128 * a PEL.
129 *
130 * This D-Bus method is called from the PLDM daemon when they get an
131 * 'Ack PEL' PLDM message from the host, which indicates the host
132 * firmware successfully sent it to the OS and this code doesn't need
133 * to send it to the host again.
134 *
135 * @param[in] pelID - The PEL ID
136 */
137 void hostAck(uint32_t pelID) override;
138
139 /**
140 * @brief D-Bus method called when the host rejects a PEL.
141 *
142 * This D-Bus method is called from the PLDM daemon when they get an
143 * 'Ack PEL' PLDM message from the host with a payload that says
144 * something when wrong.
145 *
146 * The choices are either:
147 * * Host Full - The host's staging area is full - try again later
148 * * Malrformed PEL - The host received an invalid PEL
149 *
150 * @param[in] pelID - The PEL ID
151 * @param[in] reason - One of the above two reasons
152 */
153 void hostReject(uint32_t pelID, RejectionReason reason) override;
154
Matt Spinler4e8078c2019-07-09 13:22:32 -0500155 private:
156 /**
157 * @brief Adds a received raw PEL to the PEL repository
158 *
159 * @param[in] rawPelPath - The path to the file that contains the
160 * raw PEL.
161 * @param[in] obmcLogID - the corresponding OpenBMC event log id
162 */
163 void addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID);
164
165 /**
166 * @brief Creates a PEL based on the OpenBMC event log contents.
167 *
168 * @param[in] message - The event log message property
169 * @param[in] obmcLogID - the corresponding OpenBMC event log id
170 * @param[in] timestamp - The timestamp property
171 * @param[in] severity - The event log severity
172 * @param[in] additionalData - The AdditionalData property
173 * @param[in] associations - The associations property
174 */
175 void createPEL(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -0500176 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -0500177 const std::vector<std::string>& additionalData,
178 const std::vector<std::string>& associations);
179
180 /**
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600181 * @brief Schedules a close of the file descriptor to occur from
182 * the event loop.
183 *
184 * Uses sd_event_add_defer
185 *
186 * @param[in] fd - The file descriptor to close
187 */
188 void scheduleFDClose(int fd);
189
190 /**
191 * @brief Closes the file descriptor passed in.
192 *
193 * This is called from the event loop to close FDs returned
194 * from getPEL().
195 *
196 * @param[in] fd - The file descriptor to close
197 * @param[in] source - The event source object used
198 */
199 void closeFD(int fd, sdeventplus::source::EventBase& source);
200
201 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -0500202 * @brief Reference to phosphor-logging's Manager class
203 */
Matt Spinler367144c2019-09-19 15:33:52 -0500204 phosphor::logging::internal::Manager& _logManager;
Matt Spinler89fa0822019-07-17 13:54:30 -0500205
206 /**
207 * @brief The PEL repository object
208 */
209 Repository _repo;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500210
211 /**
Matt Spinler367144c2019-09-19 15:33:52 -0500212 * @brief The PEL message registry object
213 */
214 message::Registry _registry;
215
216 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -0500217 * @brief The API the PEL sections use to gather data
218 */
219 std::unique_ptr<DataInterfaceBase> _dataIface;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600220
221 /**
222 * @brief The HostNotifier object used for telling the
223 * host about new PELs
224 */
225 std::unique_ptr<HostNotifier> _hostNotifier;
Matt Spinler6b1a5c82020-01-07 08:48:53 -0600226
227 /**
228 * @brief The event source for closing a PEL file descriptor after
229 * it has been returned from the getPEL D-Bus method.
230 */
231 std::unique_ptr<sdeventplus::source::Defer> _fdCloserEventSource;
Matt Spinler4e8078c2019-07-09 13:22:32 -0500232};
233
234} // namespace pels
235} // namespace openpower