Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "elog_watch.hpp" |
| 4 | |
| 5 | #include "dump_internal.hpp" |
| 6 | #include "dump_serialize.hpp" |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame^] | 7 | #include "dump_types.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Dump/Create/error.hpp" |
| 9 | |
Vishwanatha Subbanna | 3108597 | 2017-10-05 17:06:37 +0530 | [diff] [blame] | 10 | #include <cereal/cereal.hpp> |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/elog.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 12 | #include <phosphor-logging/lg2.hpp> |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 13 | #include <sdbusplus/exception.hpp> |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 14 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 15 | #include <fstream> |
| 16 | |
Vishwanatha Subbanna | 3108597 | 2017-10-05 17:06:37 +0530 | [diff] [blame] | 17 | // Register class version with Cereal |
Ramesh Iyyar | bb410df | 2020-08-03 03:13:04 -0500 | [diff] [blame] | 18 | CEREAL_CLASS_VERSION(phosphor::dump::elog::Watch, CLASS_VERSION) |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 19 | |
| 20 | namespace phosphor |
| 21 | { |
| 22 | namespace dump |
| 23 | { |
| 24 | namespace elog |
| 25 | { |
| 26 | |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 27 | constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 28 | using Message = std::string; |
Patrick Williams | 984a98f | 2020-05-13 17:53:32 -0500 | [diff] [blame] | 29 | using Attributes = std::variant<Message>; |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 30 | using AttributeName = std::string; |
| 31 | using AttributeMap = std::map<AttributeName, Attributes>; |
| 32 | using PropertyName = std::string; |
| 33 | using PropertyMap = std::map<PropertyName, AttributeMap>; |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 34 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 35 | Watch::Watch(sdbusplus::bus_t& bus, IMgr& iMgr) : |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 36 | iMgr(iMgr), |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 37 | addMatch(bus, |
| 38 | sdbusplus::bus::match::rules::interfacesAdded() + |
| 39 | sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING), |
| 40 | std::bind(std::mem_fn(&Watch::addCallback), this, |
| 41 | std::placeholders::_1)), |
| 42 | delMatch(bus, |
| 43 | sdbusplus::bus::match::rules::interfacesRemoved() + |
| 44 | sdbusplus::bus::match::rules::path_namespace(OBJ_LOGGING), |
| 45 | std::bind(std::mem_fn(&Watch::delCallback), this, |
| 46 | std::placeholders::_1)) |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 47 | { |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 48 | std::filesystem::path file(ELOG_ID_PERSIST_PATH); |
| 49 | if (std::filesystem::exists(file)) |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 50 | { |
| 51 | if (!deserialize(ELOG_ID_PERSIST_PATH, elogList)) |
| 52 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 53 | lg2::error("Error occurred during error id deserialize"); |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 58 | void Watch::addCallback(sdbusplus::message_t& msg) |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 59 | { |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 60 | using QuotaExceeded = |
| 61 | sdbusplus::xyz::openbmc_project::Dump::Create::Error::QuotaExceeded; |
| 62 | |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 63 | sdbusplus::message::object_path objectPath; |
| 64 | PropertyMap propertyMap; |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 65 | try |
| 66 | { |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 67 | msg.read(objectPath, propertyMap); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 68 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 69 | catch (const sdbusplus::exception_t& e) |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 70 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 71 | lg2::error("Failed to parse elog add signal, errormsg: {ERROR}, " |
| 72 | "REPLY_SIG: {REPLY_SIG}", |
| 73 | "ERROR", e, "REPLY_SIG", msg.get_signature()); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 74 | return; |
| 75 | } |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 76 | |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 77 | std::size_t found = objectPath.str.find("entry"); |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 78 | if (found == std::string::npos) |
| 79 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 80 | // Not a new error entry skip |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 84 | auto eId = getEid(objectPath); |
| 85 | |
| 86 | auto search = elogList.find(eId); |
| 87 | if (search != elogList.end()) |
| 88 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 89 | // elog exists in the list, Skip the dump |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 90 | return; |
| 91 | } |
| 92 | |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 93 | auto iter = propertyMap.find("xyz.openbmc_project.Logging.Entry"); |
| 94 | if (iter == propertyMap.end()) |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 95 | { |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | auto attr = iter->second.find("Message"); |
| 100 | if (attr == iter->second.end()) |
| 101 | { |
| 102 | return; |
| 103 | } |
| 104 | |
Patrick Williams | 07f0f46 | 2020-05-13 11:58:11 -0500 | [diff] [blame] | 105 | auto& data = std::get<PropertyName>(attr->second); |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 106 | if (data.empty()) |
| 107 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 108 | // No Message skip |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 109 | return; |
| 110 | } |
| 111 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame^] | 112 | auto etype = findErrorType(data); |
| 113 | if (!etype.has_value()) |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 114 | { |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame^] | 115 | // error not supported in the configuration |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 116 | return; |
| 117 | } |
| 118 | |
Dhruvaraj Subhashchandran | aa0937f | 2023-07-22 23:50:40 -0500 | [diff] [blame^] | 119 | auto errorType = etype.value(); |
| 120 | |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 121 | std::vector<std::string> fullPaths; |
| 122 | fullPaths.push_back(objectPath); |
| 123 | |
| 124 | try |
| 125 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 126 | // Save the elog information. This is to avoid dump requests |
| 127 | // in elog restore path. |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 128 | elogList.insert(eId); |
| 129 | |
| 130 | phosphor::dump::elog::serialize(elogList); |
| 131 | |
Patrick Williams | 78e8840 | 2023-05-10 07:50:48 -0500 | [diff] [blame] | 132 | auto item = std::find_if(phosphor::dump::bmc::TypeMap.begin(), |
| 133 | phosphor::dump::bmc::TypeMap.end(), |
| 134 | [errorType](const auto& err) { |
| 135 | return (err.second == errorType); |
| 136 | }); |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 137 | if (item != phosphor::dump::bmc::TypeMap.end()) |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 138 | { |
| 139 | iMgr.IMgr::create((*item).first, fullPaths); |
| 140 | } |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 141 | } |
Patrick Williams | 9d2d722 | 2021-10-06 12:44:44 -0500 | [diff] [blame] | 142 | catch (const QuotaExceeded& e) |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 143 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 144 | // No action now |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 145 | } |
| 146 | return; |
| 147 | } |
| 148 | |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 149 | void Watch::delCallback(sdbusplus::message_t& msg) |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 150 | { |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 151 | sdbusplus::message::object_path objectPath; |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 152 | try |
| 153 | { |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 154 | msg.read(objectPath); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 155 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 156 | catch (const sdbusplus::exception_t& e) |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 157 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 158 | lg2::error("Failed to parse elog del signal, errormsg: {ERROR}, " |
| 159 | "REPLY_SIG: {REPLY_SIG}", |
| 160 | "ERROR", e, "REPLY_SIG", msg.get_signature()); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 161 | return; |
| 162 | } |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 163 | |
Andrew Geissler | 638b43f | 2020-04-16 13:33:33 -0500 | [diff] [blame] | 164 | std::size_t found = objectPath.str.find("entry"); |
| 165 | if (found == std::string::npos) |
| 166 | { |
| 167 | // Not a error entry so skip |
| 168 | return; |
| 169 | } |
| 170 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 171 | // Get elog id |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 172 | auto eId = getEid(objectPath); |
| 173 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 174 | // Delete the elog entry from the list and serialize |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 175 | auto search = elogList.find(eId); |
| 176 | if (search != elogList.end()) |
| 177 | { |
| 178 | elogList.erase(search); |
| 179 | phosphor::dump::elog::serialize(elogList); |
| 180 | } |
| 181 | } |
| 182 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 183 | } // namespace elog |
| 184 | } // namespace dump |
| 185 | } // namespace phosphor |