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