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