Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 1 | #include <phosphor-logging/lg2.hpp> |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 2 | #include <sdbusplus/bus.hpp> |
| 3 | #include <sdbusplus/bus/match.hpp> |
| 4 | #include <watchdog_dbus.hpp> |
| 5 | #include <watchdog_handler.hpp> |
| 6 | #include <watchdog_logging.hpp> |
| 7 | |
| 8 | namespace watchdog |
| 9 | { |
| 10 | namespace dump |
| 11 | { |
| 12 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 13 | /** |
| 14 | * @brief Callback for dump request properties change signal monitor |
| 15 | * |
| 16 | * @param msg - dbus message from the dbus match infrastructure |
| 17 | * @param path - the object path we are monitoring |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 18 | * @param progressStatus - dump progress status |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 19 | * @return Always non-zero indicating no error, no cascading callbacks |
| 20 | */ |
Patrick Williams | fc43756 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 21 | uint dumpStatusChanged(sdbusplus::message_t& msg, std::string path, |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 22 | DumpProgressStatus& progressStatus) |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 23 | { |
| 24 | // reply (msg) will be a property change message |
| 25 | std::string interface; |
| 26 | std::map<std::string, std::variant<std::string, uint8_t>> property; |
| 27 | msg.read(interface, property); |
| 28 | |
| 29 | // looking for property Status changes |
| 30 | std::string propertyType = "Status"; |
| 31 | auto dumpStatus = property.find(propertyType); |
| 32 | |
| 33 | if (dumpStatus != property.end()) |
| 34 | { |
| 35 | const std::string* status = |
| 36 | std::get_if<std::string>(&(dumpStatus->second)); |
| 37 | |
| 38 | if ((nullptr != status) && ("xyz.openbmc_project.Common.Progress." |
| 39 | "OperationStatus.InProgress" != *status)) |
| 40 | { |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 41 | // dump is not in InProgress state, trace some info and change in |
| 42 | // progress status |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 43 | lg2::info("{PATH}", "PATH", path); |
| 44 | lg2::info("{STATUS}", "STATUS", *status); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 45 | |
| 46 | if ("xyz.openbmc_project.Common.Progress.OperationStatus." |
| 47 | "Completed" == *status) |
| 48 | { |
| 49 | // Dump completed successfully |
| 50 | progressStatus = DumpProgressStatus::Completed; |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | // Dump Failed |
| 55 | progressStatus = DumpProgressStatus::Failed; |
| 56 | } |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | return 1; // non-negative return code for successful callback |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * @brief Register a callback for dump progress status changes |
| 65 | * |
| 66 | * @param path - the object path of the dump to monitor |
| 67 | * @param timeout - timeout - timeout interval in seconds |
| 68 | */ |
| 69 | void monitorDump(const std::string& path, const uint32_t timeout) |
| 70 | { |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 71 | // callback will update progressStatus |
| 72 | DumpProgressStatus progressStatus = DumpProgressStatus::InProgress; |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 73 | |
| 74 | // setup the signal match rules and callback |
| 75 | std::string matchInterface = "xyz.openbmc_project.Common.Progress"; |
| 76 | auto bus = sdbusplus::bus::new_system(); |
| 77 | |
| 78 | std::unique_ptr<sdbusplus::bus::match_t> match = |
| 79 | std::make_unique<sdbusplus::bus::match_t>( |
| 80 | bus, |
| 81 | sdbusplus::bus::match::rules::propertiesChanged( |
| 82 | path.c_str(), matchInterface.c_str()), |
| 83 | [&](auto& msg) { |
Patrick Williams | 540521e | 2024-08-16 15:20:03 -0400 | [diff] [blame^] | 84 | return dumpStatusChanged(msg, path, progressStatus); |
| 85 | }); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 86 | |
| 87 | // wait for dump status to be completed (complete == true) |
| 88 | // or until timeout interval |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 89 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 90 | bool timedOut = false; |
| 91 | uint32_t secondsCount = 0; |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 92 | while ((DumpProgressStatus::InProgress == progressStatus) && !timedOut) |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 93 | { |
| 94 | bus.wait(std::chrono::seconds(1)); |
| 95 | bus.process_discard(); |
| 96 | |
| 97 | if (++secondsCount == timeout) |
| 98 | { |
| 99 | timedOut = true; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if (timedOut) |
| 104 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 105 | lg2::error("Dump progress status did not change to " |
| 106 | "complete within the timeout interval, exiting..."); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 107 | } |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 108 | else if (DumpProgressStatus::Completed == progressStatus) |
| 109 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 110 | lg2::info("dump collection completed"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 111 | } |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 112 | else |
| 113 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 114 | lg2::info("dump collection failed"); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 118 | void requestDump(const DumpParameters& dumpParameters) |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 119 | { |
Dhruvaraj Subhashchandran | d48f8e3 | 2024-06-01 11:16:26 -0500 | [diff] [blame] | 120 | constexpr auto path = "/xyz/openbmc_project/dump/system"; |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 121 | constexpr auto interface = "xyz.openbmc_project.Dump.Create"; |
| 122 | constexpr auto function = "CreateDump"; |
| 123 | |
Patrick Williams | fc43756 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 124 | sdbusplus::message_t method; |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 125 | |
| 126 | if (0 == dbusMethod(path, interface, function, method)) |
| 127 | { |
| 128 | try |
| 129 | { |
| 130 | // dbus call arguments |
| 131 | std::map<std::string, std::variant<std::string, uint64_t>> |
| 132 | createParams; |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 133 | createParams["com.ibm.Dump.Create.CreateParameters.ErrorLogId"] = |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 134 | uint64_t(dumpParameters.logId); |
| 135 | if (DumpType::Hostboot == dumpParameters.dumpType) |
| 136 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 137 | lg2::info("hostboot dump requested"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 138 | createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] = |
| 139 | "com.ibm.Dump.Create.DumpType.Hostboot"; |
| 140 | } |
| 141 | else if (DumpType::SBE == dumpParameters.dumpType) |
| 142 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 143 | lg2::info("SBE dump requested"); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 144 | createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] = |
| 145 | "com.ibm.Dump.Create.DumpType.SBE"; |
| 146 | createParams |
| 147 | ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] = |
| 148 | dumpParameters.unitId; |
| 149 | } |
| 150 | |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 151 | method.append(createParams); |
| 152 | |
| 153 | // using system dbus |
| 154 | auto bus = sdbusplus::bus::new_system(); |
| 155 | auto response = bus.call(method); |
| 156 | |
| 157 | // reply will be type dbus::ObjectPath |
| 158 | sdbusplus::message::object_path reply; |
| 159 | response.read(reply); |
| 160 | |
| 161 | // monitor dump progress |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 162 | monitorDump(reply, dumpParameters.timeout); |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 163 | } |
Patrick Williams | fc43756 | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 164 | catch (const sdbusplus::exception_t& e) |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 165 | { |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 166 | constexpr auto ERROR_DUMP_DISABLED = |
| 167 | "xyz.openbmc_project.Dump.Create.Error.Disabled"; |
| 168 | if (e.name() == ERROR_DUMP_DISABLED) |
| 169 | { |
| 170 | // Dump is disabled, Skip the dump collection. |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 171 | lg2::info("Dump is disabled on({UNIT}), " |
| 172 | "skipping dump collection", |
| 173 | "UNIT", dumpParameters.unitId); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 174 | } |
| 175 | else |
| 176 | { |
Dhruvaraj Subhashchandran | ca9236c | 2024-04-17 01:56:04 -0500 | [diff] [blame] | 177 | lg2::error("D-Bus call createDump exception OBJPATH={OBJPATH}, " |
| 178 | "INTERFACE={INTERFACE}, EXCEPTION={ERROR}", |
| 179 | "OBJPATH", path, "INTERFACE", interface, "ERROR", e); |
Shantappa Teekappanavar | 41d507e | 2021-10-05 12:17:55 -0500 | [diff] [blame] | 180 | } |
Shantappa Teekappanavar | 1ac6162 | 2021-06-22 19:07:29 -0500 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | } // namespace dump |
| 186 | } // namespace watchdog |