Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 3 | #include "elog_entry.hpp" |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 4 | #include "xyz/openbmc_project/Collection/DeleteAll/server.hpp" |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 5 | #include "xyz/openbmc_project/Logging/Internal/Manager/server.hpp" |
| 6 | |
| 7 | #include <list> |
| 8 | #include <phosphor-logging/log.hpp> |
| 9 | #include <sdbusplus/bus.hpp> |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace logging |
| 14 | { |
Adriana Kobylak | d722b3a | 2017-02-28 12:10:44 -0600 | [diff] [blame] | 15 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 16 | extern const std::map<std::string, std::vector<std::string>> g_errMetaMap; |
| 17 | extern const std::map<std::string, level> g_errLevelMap; |
Adriana Kobylak | d722b3a | 2017-02-28 12:10:44 -0600 | [diff] [blame] | 18 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 19 | using DeleteAllIface = sdbusplus::server::object::object< |
| 20 | sdbusplus::xyz::openbmc_project::Collection::server::DeleteAll>; |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 21 | |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 22 | namespace details |
| 23 | { |
| 24 | |
| 25 | template <typename T> |
| 26 | using ServerObject = typename sdbusplus::server::object::object<T>; |
| 27 | |
| 28 | using ManagerIface = |
| 29 | sdbusplus::xyz::openbmc_project::Logging::Internal::server::Manager; |
| 30 | |
| 31 | } // namespace details |
| 32 | |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 33 | namespace internal |
| 34 | { |
| 35 | |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 36 | /** @class Manager |
| 37 | * @brief OpenBMC logging manager implementation. |
| 38 | * @details A concrete implementation for the |
| 39 | * xyz.openbmc_project.Logging.Internal.Manager DBus API. |
| 40 | */ |
Adriana Kobylak | f477fe2 | 2017-01-06 11:56:41 -0600 | [diff] [blame] | 41 | class Manager : public details::ServerObject<details::ManagerIface> |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 42 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 43 | public: |
| 44 | Manager() = delete; |
| 45 | Manager(const Manager&) = delete; |
| 46 | Manager& operator=(const Manager&) = delete; |
| 47 | Manager(Manager&&) = delete; |
| 48 | Manager& operator=(Manager&&) = delete; |
| 49 | virtual ~Manager() = default; |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 50 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 51 | /** @brief Constructor to put object onto bus at a dbus path. |
| 52 | * @param[in] bus - Bus to attach to. |
| 53 | * @param[in] path - Path to attach at. |
| 54 | */ |
| 55 | Manager(sdbusplus::bus::bus& bus, const char* objPath) : |
| 56 | details::ServerObject<details::ManagerIface>(bus, objPath), busLog(bus), |
| 57 | entryId(0), fwVersion(readFWVersion()){}; |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 58 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 59 | /* |
| 60 | * @fn commit() |
| 61 | * @brief sd_bus Commit method implementation callback. |
| 62 | * @details Create an error/event log based on transaction id and |
| 63 | * error message. |
| 64 | * @param[in] transactionId - Unique identifier of the journal entries |
| 65 | * to be committed. |
| 66 | * @param[in] errMsg - The error exception message associated with the |
| 67 | * error log to be committed. |
| 68 | */ |
| 69 | void commit(uint64_t transactionId, std::string errMsg) override; |
Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 70 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 71 | /* |
| 72 | * @fn commit() |
| 73 | * @brief sd_bus CommitWithLvl method implementation callback. |
| 74 | * @details Create an error/event log based on transaction id and |
| 75 | * error message. |
| 76 | * @param[in] transactionId - Unique identifier of the journal entries |
| 77 | * to be committed. |
| 78 | * @param[in] errMsg - The error exception message associated with the |
| 79 | * error log to be committed. |
| 80 | * @param[in] errLvl - level of the error |
| 81 | */ |
| 82 | void commitWithLvl(uint64_t transactionId, std::string errMsg, |
| 83 | uint32_t errLvl) override; |
Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 84 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 85 | /** @brief Erase specified entry d-bus object |
| 86 | * |
| 87 | * @param[in] entryId - unique identifier of the entry |
| 88 | */ |
| 89 | void erase(uint32_t entryId); |
Deepak Kodihalli | 99a8549 | 2017-03-31 06:01:57 -0500 | [diff] [blame] | 90 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 91 | /** @brief Construct error d-bus objects from their persisted |
| 92 | * representations. |
| 93 | */ |
| 94 | void restore(); |
Deepak Kodihalli | 72654f1 | 2017-06-12 04:33:29 -0500 | [diff] [blame] | 95 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 96 | /** @brief Erase all error log entries |
| 97 | * |
| 98 | */ |
| 99 | void eraseAll() |
| 100 | { |
| 101 | auto iter = entries.begin(); |
| 102 | while (iter != entries.end()) |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 103 | { |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 104 | auto e = iter->first; |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 105 | ++iter; |
Patrick Venture | 3443896 | 2018-10-30 13:17:37 -0700 | [diff] [blame] | 106 | erase(e); |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 107 | } |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 108 | } |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 109 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 110 | /** @brief Returns the count of high severity errors |
| 111 | * |
| 112 | * @return int - count of real errors |
| 113 | */ |
| 114 | int getRealErrSize(); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 115 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 116 | /** @brief Returns the count of Info errors |
| 117 | * |
| 118 | * @return int - count of info errors |
| 119 | */ |
| 120 | int getInfoErrSize(); |
Nagaraju Goruganti | 477b731 | 2018-06-25 23:28:58 -0500 | [diff] [blame] | 121 | |
Matt Spinler | 8ebfd31 | 2019-06-03 12:43:59 -0500 | [diff] [blame] | 122 | sdbusplus::bus::bus& getBus() |
| 123 | { |
| 124 | return busLog; |
| 125 | } |
| 126 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 127 | private: |
| 128 | /* |
| 129 | * @fn _commit() |
| 130 | * @brief commit() helper |
| 131 | * @param[in] transactionId - Unique identifier of the journal entries |
| 132 | * to be committed. |
| 133 | * @param[in] errMsg - The error exception message associated with the |
| 134 | * error log to be committed. |
| 135 | * @param[in] errLvl - level of the error |
| 136 | */ |
| 137 | void _commit(uint64_t transactionId, std::string&& errMsg, |
| 138 | Entry::Level errLvl); |
Deepak Kodihalli | 6fd9dc4 | 2018-04-03 02:08:42 -0500 | [diff] [blame] | 139 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 140 | /** @brief Call metadata handler(s), if any. Handlers may create |
| 141 | * associations. |
| 142 | * @param[in] errorName - name of the error |
| 143 | * @param[in] additionalData - list of metadata (in key=value format) |
| 144 | * @param[out] objects - list of error's association objects |
| 145 | */ |
| 146 | void processMetadata(const std::string& errorName, |
| 147 | const std::vector<std::string>& additionalData, |
| 148 | AssociationList& objects) const; |
Deepak Kodihalli | a87c157 | 2017-02-28 07:40:34 -0600 | [diff] [blame] | 149 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 150 | /** @brief Synchronize unwritten journal messages to disk. |
| 151 | * @details This is the same implementation as the systemd command |
| 152 | * "journalctl --sync". |
| 153 | */ |
| 154 | void journalSync(); |
Adriana Kobylak | 5f4247f | 2018-03-15 10:27:05 -0500 | [diff] [blame] | 155 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 156 | /** @brief Reads the BMC code level |
| 157 | * |
| 158 | * @return std::string - the version string |
| 159 | */ |
| 160 | static std::string readFWVersion(); |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 161 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 162 | /** @brief Call any create() functions provided by any extensions. |
| 163 | * This is called right after an event log is created to allow |
| 164 | * extensions to create their own log based on this one. |
| 165 | * |
| 166 | * @param[in] entry - the new event log entry |
| 167 | */ |
| 168 | void doExtensionLogCreate(const Entry& entry); |
| 169 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 170 | /** @brief Persistent sdbusplus DBus bus connection. */ |
| 171 | sdbusplus::bus::bus& busLog; |
Adriana Kobylak | df995fa | 2017-01-08 15:14:02 -0600 | [diff] [blame] | 172 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 173 | /** @brief Persistent map of Entry dbus objects and their ID */ |
| 174 | std::map<uint32_t, std::unique_ptr<Entry>> entries; |
Adriana Kobylak | 4ea7f31 | 2017-01-10 12:52:34 -0600 | [diff] [blame] | 175 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 176 | /** @brief List of error ids for high severity errors */ |
| 177 | std::list<uint32_t> realErrors; |
Nagaraju Goruganti | e4b0b77 | 2017-11-30 02:12:45 -0600 | [diff] [blame] | 178 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 179 | /** @brief List of error ids for Info(and below) severity */ |
| 180 | std::list<uint32_t> infoErrors; |
Nagaraju Goruganti | f8a5a79 | 2017-10-13 08:09:52 -0500 | [diff] [blame] | 181 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 182 | /** @brief Id of last error log entry */ |
| 183 | uint32_t entryId; |
Matt Spinler | 1275bd1 | 2018-05-01 15:13:53 -0500 | [diff] [blame] | 184 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 185 | /** @brief The BMC firmware version */ |
| 186 | const std::string fwVersion; |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 187 | }; |
| 188 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 189 | } // namespace internal |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 190 | |
| 191 | /** @class Manager |
| 192 | * @brief Implementation for delete all error log entries. |
| 193 | * @details A concrete implementation for the |
| 194 | * xyz.openbmc_project.Collection.DeleteAll |
| 195 | */ |
| 196 | class Manager : public DeleteAllIface |
| 197 | { |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 198 | public: |
| 199 | Manager() = delete; |
| 200 | Manager(const Manager&) = delete; |
| 201 | Manager& operator=(const Manager&) = delete; |
| 202 | Manager(Manager&&) = delete; |
| 203 | Manager& operator=(Manager&&) = delete; |
| 204 | virtual ~Manager() = default; |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 205 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 206 | /** @brief Constructor to put object onto bus at a dbus path. |
| 207 | * Defer signal registration (pass true for deferSignal to the |
| 208 | * base class) until after the properties are set. |
| 209 | * @param[in] bus - Bus to attach to. |
| 210 | * @param[in] path - Path to attach at. |
| 211 | * @param[in] manager - Reference to internal manager object. |
| 212 | */ |
| 213 | Manager(sdbusplus::bus::bus& bus, const std::string& path, |
| 214 | internal::Manager& manager) : |
| 215 | DeleteAllIface(bus, path.c_str(), true), |
| 216 | manager(manager){}; |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 217 | |
Patrick Venture | f18bf83 | 2018-10-26 18:14:00 -0700 | [diff] [blame] | 218 | /** @brief Delete all d-bus objects. |
| 219 | */ |
| 220 | void deleteAll() |
| 221 | { |
| 222 | manager.eraseAll(); |
| 223 | } |
| 224 | |
| 225 | private: |
| 226 | /** @brief This is a reference to manager object */ |
| 227 | internal::Manager& manager; |
Nagaraju Goruganti | 05aae8b | 2017-08-30 07:56:12 -0500 | [diff] [blame] | 228 | }; |
| 229 | |
Adriana Kobylak | 8f7941e | 2016-11-14 14:46:23 -0600 | [diff] [blame] | 230 | } // namespace logging |
| 231 | } // namespace phosphor |