blob: c3dc5b25a252c0c46e6c82ce91bfbd127a912afa [file] [log] [blame]
Ben Tyner7029e522021-08-09 19:18:24 -05001#include <attn/attn_dbus.hpp>
2#include <attn/attn_dump.hpp>
3#include <attn/attn_logging.hpp>
4#include <sdbusplus/bus.hpp>
5#include <sdbusplus/exception.hpp>
austinfcuibfa831a2022-01-26 15:37:07 -06006#include <util/trace.hpp>
Ben Tyner7029e522021-08-09 19:18:24 -05007
Ben Tynere38a90b2022-03-02 19:30:35 -06008constexpr uint64_t dumpTimeout = 3600000000; // microseconds
9
10constexpr auto operationStatusInProgress =
11 "xyz.openbmc_project.Common.Progress.OperationStatus.InProgress";
12
Ben Tyner7029e522021-08-09 19:18:24 -050013namespace attn
14{
15
16/**
17 * Callback for dump request properties change signal monitor
18 *
19 * @param[in] i_msg Dbus message from the dbus match infrastructure
Ben Tynere38a90b2022-03-02 19:30:35 -060020 * @param[out] o_dumpStatus Dump status dbus response string
21 * @return Always non-zero indicating no error, no cascading callbacks
Ben Tyner7029e522021-08-09 19:18:24 -050022 */
Ben Tynere38a90b2022-03-02 19:30:35 -060023uint dumpStatusChanged(sdbusplus::message::message& i_msg,
24 std::string& o_dumpStatus)
Ben Tyner7029e522021-08-09 19:18:24 -050025{
26 // reply (msg) will be a property change message
27 std::string interface;
28 std::map<std::string, std::variant<std::string, uint8_t>> property;
29 i_msg.read(interface, property);
30
31 // looking for property Status changes
32 std::string propertyType = "Status";
33 auto dumpStatus = property.find(propertyType);
34
35 if (dumpStatus != property.end())
36 {
37 const std::string* status =
38 std::get_if<std::string>(&(dumpStatus->second));
39
Ben Tynere38a90b2022-03-02 19:30:35 -060040 if (nullptr != status)
Ben Tyner7029e522021-08-09 19:18:24 -050041 {
Ben Tynere38a90b2022-03-02 19:30:35 -060042 o_dumpStatus = *status;
Ben Tyner7029e522021-08-09 19:18:24 -050043 }
44 }
45
46 return 1; // non-negative return code for successful callback
47}
48
49/**
50 * Register a callback for dump progress status changes
51 *
52 * @param[in] i_path The object path of the dump to monitor
53 */
54void monitorDump(const std::string& i_path)
55{
Ben Tyner7029e522021-08-09 19:18:24 -050056 // setup the signal match rules and callback
57 std::string matchInterface = "xyz.openbmc_project.Common.Progress";
58 auto bus = sdbusplus::bus::new_system();
59
Ben Tynere38a90b2022-03-02 19:30:35 -060060 // monitor dump status change property, will update dumpStatus
61 std::string dumpStatus = "requested";
Ben Tyner7029e522021-08-09 19:18:24 -050062 std::unique_ptr<sdbusplus::bus::match_t> match =
63 std::make_unique<sdbusplus::bus::match_t>(
64 bus,
65 sdbusplus::bus::match::rules::propertiesChanged(
66 i_path.c_str(), matchInterface.c_str()),
Ben Tynere38a90b2022-03-02 19:30:35 -060067 [&](auto& msg) { return dumpStatusChanged(msg, dumpStatus); });
Ben Tyner7029e522021-08-09 19:18:24 -050068
69 // wait for dump status to be completed (complete == true)
Ben Tynere38a90b2022-03-02 19:30:35 -060070 trace::inf("dump requested %s", i_path.c_str());
71
72 // wait for dump status not InProgress or timeout
73 uint64_t timeRemaining = dumpTimeout;
74
75 std::chrono::steady_clock::time_point begin =
76 std::chrono::steady_clock::now();
77
78 while (("requested" == dumpStatus ||
79 operationStatusInProgress == dumpStatus) &&
80 0 != timeRemaining)
Ben Tyner7029e522021-08-09 19:18:24 -050081 {
Ben Tynere38a90b2022-03-02 19:30:35 -060082 bus.wait(timeRemaining);
83 uint64_t timeElapsed =
84 std::chrono::duration_cast<std::chrono::microseconds>(
85 std::chrono::steady_clock::now() - begin)
86 .count();
87
88 timeRemaining =
89 timeElapsed > timeRemaining ? 0 : timeRemaining - timeElapsed;
90
Ben Tyner7029e522021-08-09 19:18:24 -050091 bus.process_discard();
92 }
Ben Tynere38a90b2022-03-02 19:30:35 -060093
94 if (0 == timeRemaining)
95 {
96 trace::err("dump request timed out after %" PRIu64 " microseconds",
97 dumpTimeout);
98 }
99
100 trace::inf("dump status: %s", dumpStatus.c_str());
Ben Tyner7029e522021-08-09 19:18:24 -0500101}
102
103/** Request a dump from the dump manager */
Zane Shelley611b3442021-11-19 16:02:01 -0600104void requestDump(uint32_t i_logId, const DumpParameters& i_dumpParameters)
Ben Tyner7029e522021-08-09 19:18:24 -0500105{
106 constexpr auto path = "/org/openpower/dump";
107 constexpr auto interface = "xyz.openbmc_project.Dump.Create";
108 constexpr auto function = "CreateDump";
109
110 sdbusplus::message::message method;
111
112 if (0 == dbusMethod(path, interface, function, method))
113 {
114 try
115 {
116 // dbus call arguments
117 std::map<std::string, std::variant<std::string, uint64_t>>
118 createParams;
119 createParams["com.ibm.Dump.Create.CreateParameters.ErrorLogId"] =
Zane Shelley611b3442021-11-19 16:02:01 -0600120 uint64_t(i_logId);
Ben Tyner7029e522021-08-09 19:18:24 -0500121 if (DumpType::Hostboot == i_dumpParameters.dumpType)
122 {
123 createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
124 "com.ibm.Dump.Create.DumpType.Hostboot";
125 }
126 else if (DumpType::Hardware == i_dumpParameters.dumpType)
127 {
128 createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
129 "com.ibm.Dump.Create.DumpType.Hardware";
130 createParams
131 ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] =
132 i_dumpParameters.unitId;
133 }
Ben Tyner7f6ce6a2021-08-17 19:40:00 -0500134 else if (DumpType::SBE == i_dumpParameters.dumpType)
135 {
136 createParams["com.ibm.Dump.Create.CreateParameters.DumpType"] =
137 "com.ibm.Dump.Create.DumpType.SBE";
138 createParams
139 ["com.ibm.Dump.Create.CreateParameters.FailingUnitId"] =
140 i_dumpParameters.unitId;
141 }
Ben Tyner7029e522021-08-09 19:18:24 -0500142 method.append(createParams);
143
144 // using system dbus
145 auto bus = sdbusplus::bus::new_system();
146 auto response = bus.call(method);
147
148 // reply will be type dbus::ObjectPath
149 sdbusplus::message::object_path reply;
150 response.read(reply);
151
152 // monitor dump progress
153 monitorDump(reply);
154 }
155 catch (const sdbusplus::exception::SdBusError& e)
156 {
austinfcuibfa831a2022-01-26 15:37:07 -0600157 trace::err("requestDump exception");
158 trace::err(e.what());
Ben Tyner7029e522021-08-09 19:18:24 -0500159 }
160 }
161}
162
163} // namespace attn