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> |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 11 | #include <fstream> |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 12 | #include <phosphor-logging/elog.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 | |
Vishwanatha Subbanna | 3108597 | 2017-10-05 17:06:37 +0530 | [diff] [blame] | 15 | // Register class version with Cereal |
| 16 | CEREAL_CLASS_VERSION(phosphor::dump::elog::Watch, CLASS_VERSION); |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 17 | |
| 18 | namespace phosphor |
| 19 | { |
| 20 | namespace dump |
| 21 | { |
| 22 | namespace elog |
| 23 | { |
| 24 | |
| 25 | using namespace phosphor::logging; |
| 26 | constexpr auto LOG_PATH = "/xyz/openbmc_project/logging"; |
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 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 34 | Watch::Watch(sdbusplus::bus::bus& bus, IMgr& iMgr) : |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 35 | iMgr(iMgr), |
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 | { |
| 47 | |
| 48 | fs::path file(ELOG_ID_PERSIST_PATH); |
| 49 | if (fs::exists(file)) |
| 50 | { |
| 51 | if (!deserialize(ELOG_ID_PERSIST_PATH, elogList)) |
| 52 | { |
| 53 | log<level::ERR>("Error occurred during error id deserialize"); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void Watch::addCallback(sdbusplus::message::message& 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 | } |
| 69 | catch (const sdbusplus::exception::SdBusError& e) |
| 70 | { |
| 71 | log<level::ERR>("Failed to parse elog add signal", |
| 72 | entry("ERROR=%s", e.what()), |
| 73 | entry("REPLY_SIG=%s", msg.get_signature())); |
| 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 | |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 112 | EType errorType; |
| 113 | for (const auto& [type, errorList] : errorMap) |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 114 | { |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 115 | auto error = std::find(errorList.begin(), errorList.end(), data); |
| 116 | if (error != errorList.end()) |
| 117 | { |
| 118 | errorType = type; |
| 119 | break; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | // error not supported in the configuration |
| 124 | if (errorType.empty()) |
| 125 | { |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 126 | return; |
| 127 | } |
| 128 | |
| 129 | std::vector<std::string> fullPaths; |
| 130 | fullPaths.push_back(objectPath); |
| 131 | |
| 132 | try |
| 133 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 134 | // Save the elog information. This is to avoid dump requests |
| 135 | // in elog restore path. |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 136 | elogList.insert(eId); |
| 137 | |
| 138 | phosphor::dump::elog::serialize(elogList); |
| 139 | |
Marri Devender Rao | 0deb287 | 2018-11-12 07:45:54 -0600 | [diff] [blame] | 140 | auto item = std::find_if( |
| 141 | TypeMap.begin(), TypeMap.end(), |
| 142 | [errorType](const auto& err) { return (err.second == errorType); }); |
| 143 | if (item != TypeMap.end()) |
| 144 | { |
| 145 | iMgr.IMgr::create((*item).first, fullPaths); |
| 146 | } |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 147 | } |
| 148 | catch (QuotaExceeded& e) |
| 149 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 150 | // No action now |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 151 | } |
| 152 | return; |
| 153 | } |
| 154 | |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 155 | void Watch::delCallback(sdbusplus::message::message& msg) |
| 156 | { |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 157 | sdbusplus::message::object_path objectPath; |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 158 | try |
| 159 | { |
William A. Kennington III | 90d147a | 2018-06-12 16:42:33 -0700 | [diff] [blame] | 160 | msg.read(objectPath); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 161 | } |
| 162 | catch (const sdbusplus::exception::SdBusError& e) |
| 163 | { |
| 164 | log<level::ERR>("Failed to parse elog del signal", |
| 165 | entry("ERROR=%s", e.what()), |
| 166 | entry("REPLY_SIG=%s", msg.get_signature())); |
| 167 | return; |
| 168 | } |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 169 | |
Andrew Geissler | 638b43f | 2020-04-16 13:33:33 -0500 | [diff] [blame] | 170 | std::size_t found = objectPath.str.find("entry"); |
| 171 | if (found == std::string::npos) |
| 172 | { |
| 173 | // Not a error entry so skip |
| 174 | return; |
| 175 | } |
| 176 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 177 | // Get elog id |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 178 | auto eId = getEid(objectPath); |
| 179 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 180 | // Delete the elog entry from the list and serialize |
Jayanth Othayoth | 2496482 | 2017-09-04 22:07:06 -0500 | [diff] [blame] | 181 | auto search = elogList.find(eId); |
| 182 | if (search != elogList.end()) |
| 183 | { |
| 184 | elogList.erase(search); |
| 185 | phosphor::dump::elog::serialize(elogList); |
| 186 | } |
| 187 | } |
| 188 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 189 | } // namespace elog |
| 190 | } // namespace dump |
| 191 | } // namespace phosphor |