Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 3 | #include "config.h" |
| 4 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 5 | #include "data_interface.hpp" |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 6 | #include "host_notifier.hpp" |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 7 | #include "log_manager.hpp" |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 8 | #include "paths.hpp" |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 9 | #include "registry.hpp" |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 10 | #include "repository.hpp" |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 11 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 12 | #include <org/open_power/Logging/PEL/server.hpp> |
| 13 | #include <sdbusplus/server.hpp> |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 14 | #include <sdeventplus/event.hpp> |
| 15 | #include <sdeventplus/source/event.hpp> |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 16 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 17 | namespace openpower |
| 18 | { |
| 19 | namespace pels |
| 20 | { |
| 21 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 22 | using PELInterface = sdbusplus::server::object::object< |
| 23 | sdbusplus::org::open_power::Logging::server::PEL>; |
| 24 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 25 | /** |
| 26 | * @brief PEL manager object |
| 27 | */ |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 28 | class Manager : public PELInterface |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 29 | { |
| 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 Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 42 | * @param[in] dataIface - The data interface object |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 43 | */ |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 44 | Manager(phosphor::logging::internal::Manager& logManager, |
| 45 | std::unique_ptr<DataInterfaceBase> dataIface) : |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 46 | PELInterface(logManager.getBus(), OBJ_LOGGING), |
| 47 | _logManager(logManager), _repo(getPELRepoPath()), |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 48 | _registry(getMessageRegistryPath() / message::registryFileName), |
| 49 | _dataIface(std::move(dataIface)) |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 50 | { |
| 51 | } |
| 52 | |
| 53 | /** |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 54 | * @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 Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 70 | * @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 Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 82 | uint64_t timestamp, phosphor::logging::Entry::Level severity, |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 83 | 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 Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame] | 104 | /** |
| 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 Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 155 | 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 Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 176 | uint64_t timestamp, phosphor::logging::Entry::Level severity, |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 177 | const std::vector<std::string>& additionalData, |
| 178 | const std::vector<std::string>& associations); |
| 179 | |
| 180 | /** |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 181 | * @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 Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 202 | * @brief Reference to phosphor-logging's Manager class |
| 203 | */ |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 204 | phosphor::logging::internal::Manager& _logManager; |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 205 | |
| 206 | /** |
| 207 | * @brief The PEL repository object |
| 208 | */ |
| 209 | Repository _repo; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 210 | |
| 211 | /** |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 212 | * @brief The PEL message registry object |
| 213 | */ |
| 214 | message::Registry _registry; |
| 215 | |
| 216 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 217 | * @brief The API the PEL sections use to gather data |
| 218 | */ |
| 219 | std::unique_ptr<DataInterfaceBase> _dataIface; |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 220 | |
| 221 | /** |
| 222 | * @brief The HostNotifier object used for telling the |
| 223 | * host about new PELs |
| 224 | */ |
| 225 | std::unique_ptr<HostNotifier> _hostNotifier; |
Matt Spinler | 6b1a5c8 | 2020-01-07 08:48:53 -0600 | [diff] [blame] | 226 | |
| 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 Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 232 | }; |
| 233 | |
| 234 | } // namespace pels |
| 235 | } // namespace openpower |