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> |
| 14 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 15 | namespace openpower |
| 16 | { |
| 17 | namespace pels |
| 18 | { |
| 19 | |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame^] | 20 | using PELInterface = sdbusplus::server::object::object< |
| 21 | sdbusplus::org::open_power::Logging::server::PEL>; |
| 22 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 23 | /** |
| 24 | * @brief PEL manager object |
| 25 | */ |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame^] | 26 | class Manager : public PELInterface |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 27 | { |
| 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 Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 40 | * @param[in] dataIface - The data interface object |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 41 | */ |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 42 | Manager(phosphor::logging::internal::Manager& logManager, |
| 43 | std::unique_ptr<DataInterfaceBase> dataIface) : |
Matt Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame^] | 44 | PELInterface(logManager.getBus(), OBJ_LOGGING), |
| 45 | _logManager(logManager), _repo(getPELRepoPath()), |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 46 | _registry(getMessageRegistryPath() / message::registryFileName), |
| 47 | _dataIface(std::move(dataIface)) |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 48 | { |
| 49 | } |
| 50 | |
| 51 | /** |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 52 | * @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 Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 68 | * @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 Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 80 | uint64_t timestamp, phosphor::logging::Entry::Level severity, |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 81 | 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 Spinler | a34ab72 | 2019-12-16 10:39:32 -0600 | [diff] [blame^] | 102 | /** |
| 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 Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 153 | 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 Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 174 | uint64_t timestamp, phosphor::logging::Entry::Level severity, |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 175 | 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 Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 181 | phosphor::logging::internal::Manager& _logManager; |
Matt Spinler | 89fa082 | 2019-07-17 13:54:30 -0500 | [diff] [blame] | 182 | |
| 183 | /** |
| 184 | * @brief The PEL repository object |
| 185 | */ |
| 186 | Repository _repo; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 187 | |
| 188 | /** |
Matt Spinler | 367144c | 2019-09-19 15:33:52 -0500 | [diff] [blame] | 189 | * @brief The PEL message registry object |
| 190 | */ |
| 191 | message::Registry _registry; |
| 192 | |
| 193 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 194 | * @brief The API the PEL sections use to gather data |
| 195 | */ |
| 196 | std::unique_ptr<DataInterfaceBase> _dataIface; |
Matt Spinler | f60ac27 | 2019-12-11 13:47:50 -0600 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * @brief The HostNotifier object used for telling the |
| 200 | * host about new PELs |
| 201 | */ |
| 202 | std::unique_ptr<HostNotifier> _hostNotifier; |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | } // namespace pels |
| 206 | } // namespace openpower |