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