blob: 2a2b2458f54dde21eaece171600a83ea631ea78b [file] [log] [blame]
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -05001#include <phosphor-logging/lg2.hpp>
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -05002#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
8namespace watchdog
9{
10namespace dump
11{
12
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050013/**
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 Teekappanavar41d507e2021-10-05 12:17:55 -050018 * @param progressStatus - dump progress status
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050019 * @return Always non-zero indicating no error, no cascading callbacks
20 */
Patrick Williamsfc437562022-07-22 19:26:52 -050021uint dumpStatusChanged(sdbusplus::message_t& msg, std::string path,
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050022 DumpProgressStatus& progressStatus)
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050023{
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 Teekappanavar41d507e2021-10-05 12:17:55 -050041 // dump is not in InProgress state, trace some info and change in
42 // progress status
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -050043 lg2::info("{PATH}", "PATH", path);
44 lg2::info("{STATUS}", "STATUS", *status);
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050045
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 Teekappanavar1ac61622021-06-22 19:07:29 -050057 }
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 */
69void monitorDump(const std::string& path, const uint32_t timeout)
70{
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050071 // callback will update progressStatus
72 DumpProgressStatus progressStatus = DumpProgressStatus::InProgress;
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050073
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 Williams540521e2024-08-16 15:20:03 -040084 return dumpStatusChanged(msg, path, progressStatus);
85 });
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050086
87 // wait for dump status to be completed (complete == true)
88 // or until timeout interval
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050089
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050090 bool timedOut = false;
91 uint32_t secondsCount = 0;
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -050092 while ((DumpProgressStatus::InProgress == progressStatus) && !timedOut)
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -050093 {
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 Subhashchandranca9236c2024-04-17 01:56:04 -0500105 lg2::error("Dump progress status did not change to "
106 "complete within the timeout interval, exiting...");
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500107 }
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500108 else if (DumpProgressStatus::Completed == progressStatus)
109 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -0500110 lg2::info("dump collection completed");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500111 }
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500112 else
113 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -0500114 lg2::info("dump collection failed");
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500115 }
116}
117
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500118void requestDump(const DumpParameters& dumpParameters)
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500119{
Dhruvaraj Subhashchandrand48f8e32024-06-01 11:16:26 -0500120 constexpr auto path = "/xyz/openbmc_project/dump/system";
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500121 constexpr auto interface = "xyz.openbmc_project.Dump.Create";
122 constexpr auto function = "CreateDump";
123
Patrick Williamsfc437562022-07-22 19:26:52 -0500124 sdbusplus::message_t method;
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500125
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 Teekappanavar1ac61622021-06-22 19:07:29 -0500133 createParams["com.ibm.Dump.Create.CreateParameters.ErrorLogId"] =
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500134 uint64_t(dumpParameters.logId);
135 if (DumpType::Hostboot == dumpParameters.dumpType)
136 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -0500137 lg2::info("hostboot dump requested");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500138 createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
139 "com.ibm.Dump.Create.DumpType.Hostboot";
140 }
141 else if (DumpType::SBE == dumpParameters.dumpType)
142 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -0500143 lg2::info("SBE dump requested");
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500144 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 Teekappanavar1ac61622021-06-22 19:07:29 -0500151 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 Teekappanavar41d507e2021-10-05 12:17:55 -0500162 monitorDump(reply, dumpParameters.timeout);
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500163 }
Patrick Williamsfc437562022-07-22 19:26:52 -0500164 catch (const sdbusplus::exception_t& e)
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500165 {
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500166 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 Subhashchandranca9236c2024-04-17 01:56:04 -0500171 lg2::info("Dump is disabled on({UNIT}), "
172 "skipping dump collection",
173 "UNIT", dumpParameters.unitId);
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500174 }
175 else
176 {
Dhruvaraj Subhashchandranca9236c2024-04-17 01:56:04 -0500177 lg2::error("D-Bus call createDump exception OBJPATH={OBJPATH}, "
178 "INTERFACE={INTERFACE}, EXCEPTION={ERROR}",
179 "OBJPATH", path, "INTERFACE", interface, "ERROR", e);
Shantappa Teekappanavar41d507e2021-10-05 12:17:55 -0500180 }
Shantappa Teekappanavar1ac61622021-06-22 19:07:29 -0500181 }
182 }
183}
184
185} // namespace dump
186} // namespace watchdog