blob: 7f1fcda6b19a20a3007eac84e826faaa1ff65589 [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>
14
Matt Spinler4e8078c2019-07-09 13:22:32 -050015namespace openpower
16{
17namespace pels
18{
19
Matt Spinlera34ab722019-12-16 10:39:32 -060020using PELInterface = sdbusplus::server::object::object<
21 sdbusplus::org::open_power::Logging::server::PEL>;
22
Matt Spinler4e8078c2019-07-09 13:22:32 -050023/**
24 * @brief PEL manager object
25 */
Matt Spinlera34ab722019-12-16 10:39:32 -060026class Manager : public PELInterface
Matt Spinler4e8078c2019-07-09 13:22:32 -050027{
28 public:
29 Manager() = delete;
30 ~Manager() = default;
31 Manager(const Manager&) = default;
32 Manager& operator=(const Manager&) = default;
33 Manager(Manager&&) = default;
34 Manager& operator=(Manager&&) = default;
35
36 /**
37 * @brief constructor
38 *
39 * @param[in] logManager - internal::Manager object
Matt Spinlerf60ac272019-12-11 13:47:50 -060040 * @param[in] dataIface - The data interface object
Matt Spinler4e8078c2019-07-09 13:22:32 -050041 */
Matt Spinlerf60ac272019-12-11 13:47:50 -060042 Manager(phosphor::logging::internal::Manager& logManager,
43 std::unique_ptr<DataInterfaceBase> dataIface) :
Matt Spinlera34ab722019-12-16 10:39:32 -060044 PELInterface(logManager.getBus(), OBJ_LOGGING),
45 _logManager(logManager), _repo(getPELRepoPath()),
Matt Spinler367144c2019-09-19 15:33:52 -050046 _registry(getMessageRegistryPath() / message::registryFileName),
47 _dataIface(std::move(dataIface))
Matt Spinler4e8078c2019-07-09 13:22:32 -050048 {
49 }
50
51 /**
Matt Spinlerf60ac272019-12-11 13:47:50 -060052 * @brief constructor that enables host notification
53 *
54 * @param[in] logManager - internal::Manager object
55 * @param[in] dataIface - The data interface object
56 * @param[in] hostIface - The hostInterface object
57 */
58 Manager(phosphor::logging::internal::Manager& logManager,
59 std::unique_ptr<DataInterfaceBase> dataIface,
60 std::unique_ptr<HostInterface> hostIface) :
61 Manager(logManager, std::move(dataIface))
62 {
63 _hostNotifier = std::make_unique<HostNotifier>(
64 _repo, *(_dataIface.get()), std::move(hostIface));
65 }
66
67 /**
Matt Spinler4e8078c2019-07-09 13:22:32 -050068 * @brief Creates a PEL based on the OpenBMC event log contents. If
69 * a PEL was passed in via the RAWPEL specifier in the
70 * additionalData parameter, use that instead.
71 *
72 * @param[in] message - the event log message property
73 * @param[in] obmcLogID - the corresponding OpenBMC event log id
74 * @param[in] timestamp - the Timestamp property
75 * @param[in] severity - the event log severity
76 * @param[in] additionalData - the AdditionalData property
77 * @param[in] associations - the Associations property
78 */
79 void create(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -050080 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -050081 const std::vector<std::string>& additionalData,
82 const std::vector<std::string>& associations);
83
84 /**
85 * @brief Erase a PEL based on its OpenBMC event log ID
86 *
87 * @param[in] obmcLogID - the corresponding OpenBMC event log id
88 */
89 void erase(uint32_t obmcLogID);
90
91 /** @brief Says if an OpenBMC event log may not be manually deleted at this
92 * time because its corresponding PEL cannot be.
93 *
94 * There are PEL retention policies that can prohibit the manual deletion
95 * of PELs (and therefore OpenBMC event logs).
96 *
97 * @param[in] obmcLogID - the OpenBMC event log ID
98 * @return bool - true if prohibited
99 */
100 bool isDeleteProhibited(uint32_t obmcLogID);
101
Matt Spinlera34ab722019-12-16 10:39:32 -0600102 /**
103 * @brief Return a file descriptor to the raw PEL data
104 *
105 * Throws InvalidArgument if the PEL ID isn't found,
106 * and InternalFailure if anything else fails.
107 *
108 * @param[in] pelID - The PEL ID to get the data for
109 *
110 * @return unix_fd - File descriptor to the file that contains the PEL
111 */
112 sdbusplus::message::unix_fd getPEL(uint32_t pelID) override;
113
114 /**
115 * @brief Returns data for the PEL corresponding to an OpenBMC
116 * event log.
117 *
118 * @param[in] obmcLogID - The OpenBMC event log ID
119 *
120 * @return vector<uint8_t> - The raw PEL data
121 */
122 std::vector<uint8_t> getPELFromOBMCID(uint32_t obmcLogID) override;
123
124 /**
125 * @brief The D-Bus method called when a host successfully processes
126 * a PEL.
127 *
128 * This D-Bus method is called from the PLDM daemon when they get an
129 * 'Ack PEL' PLDM message from the host, which indicates the host
130 * firmware successfully sent it to the OS and this code doesn't need
131 * to send it to the host again.
132 *
133 * @param[in] pelID - The PEL ID
134 */
135 void hostAck(uint32_t pelID) override;
136
137 /**
138 * @brief D-Bus method called when the host rejects a PEL.
139 *
140 * This D-Bus method is called from the PLDM daemon when they get an
141 * 'Ack PEL' PLDM message from the host with a payload that says
142 * something when wrong.
143 *
144 * The choices are either:
145 * * Host Full - The host's staging area is full - try again later
146 * * Malrformed PEL - The host received an invalid PEL
147 *
148 * @param[in] pelID - The PEL ID
149 * @param[in] reason - One of the above two reasons
150 */
151 void hostReject(uint32_t pelID, RejectionReason reason) override;
152
Matt Spinler4e8078c2019-07-09 13:22:32 -0500153 private:
154 /**
155 * @brief Adds a received raw PEL to the PEL repository
156 *
157 * @param[in] rawPelPath - The path to the file that contains the
158 * raw PEL.
159 * @param[in] obmcLogID - the corresponding OpenBMC event log id
160 */
161 void addRawPEL(const std::string& rawPelPath, uint32_t obmcLogID);
162
163 /**
164 * @brief Creates a PEL based on the OpenBMC event log contents.
165 *
166 * @param[in] message - The event log message property
167 * @param[in] obmcLogID - the corresponding OpenBMC event log id
168 * @param[in] timestamp - The timestamp property
169 * @param[in] severity - The event log severity
170 * @param[in] additionalData - The AdditionalData property
171 * @param[in] associations - The associations property
172 */
173 void createPEL(const std::string& message, uint32_t obmcLogID,
Matt Spinler367144c2019-09-19 15:33:52 -0500174 uint64_t timestamp, phosphor::logging::Entry::Level severity,
Matt Spinler4e8078c2019-07-09 13:22:32 -0500175 const std::vector<std::string>& additionalData,
176 const std::vector<std::string>& associations);
177
178 /**
179 * @brief Reference to phosphor-logging's Manager class
180 */
Matt Spinler367144c2019-09-19 15:33:52 -0500181 phosphor::logging::internal::Manager& _logManager;
Matt Spinler89fa0822019-07-17 13:54:30 -0500182
183 /**
184 * @brief The PEL repository object
185 */
186 Repository _repo;
Matt Spinlerc8705e22019-09-11 12:36:07 -0500187
188 /**
Matt Spinler367144c2019-09-19 15:33:52 -0500189 * @brief The PEL message registry object
190 */
191 message::Registry _registry;
192
193 /**
Matt Spinlerc8705e22019-09-11 12:36:07 -0500194 * @brief The API the PEL sections use to gather data
195 */
196 std::unique_ptr<DataInterfaceBase> _dataIface;
Matt Spinlerf60ac272019-12-11 13:47:50 -0600197
198 /**
199 * @brief The HostNotifier object used for telling the
200 * host about new PELs
201 */
202 std::unique_ptr<HostNotifier> _hostNotifier;
Matt Spinler4e8078c2019-07-09 13:22:32 -0500203};
204
205} // namespace pels
206} // namespace openpower