Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 1 | #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> |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 6 | #include <util/trace.hpp> |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 7 | |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 8 | constexpr uint64_t dumpTimeout = 3600000000; // microseconds |
| 9 | |
| 10 | constexpr auto operationStatusInProgress = |
| 11 | "xyz.openbmc_project.Common.Progress.OperationStatus.InProgress"; |
| 12 | |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 13 | namespace 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 Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 20 | * @param[out] o_dumpStatus Dump status dbus response string |
| 21 | * @return Always non-zero indicating no error, no cascading callbacks |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 22 | */ |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 23 | uint dumpStatusChanged(sdbusplus::message::message& i_msg, |
| 24 | std::string& o_dumpStatus) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 25 | { |
| 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 Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 40 | if (nullptr != status) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 41 | { |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 42 | o_dumpStatus = *status; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 43 | } |
| 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 | */ |
| 54 | void monitorDump(const std::string& i_path) |
| 55 | { |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 56 | // 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 Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 60 | // monitor dump status change property, will update dumpStatus |
| 61 | std::string dumpStatus = "requested"; |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 62 | 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 Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 67 | [&](auto& msg) { return dumpStatusChanged(msg, dumpStatus); }); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 68 | |
| 69 | // wait for dump status to be completed (complete == true) |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 70 | 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 Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 81 | { |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 82 | 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 Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 91 | bus.process_discard(); |
| 92 | } |
Ben Tyner | e38a90b | 2022-03-02 19:30:35 -0600 | [diff] [blame] | 93 | |
| 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 Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** Request a dump from the dump manager */ |
Zane Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 104 | void requestDump(uint32_t i_logId, const DumpParameters& i_dumpParameters) |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 105 | { |
| 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 Shelley | 611b344 | 2021-11-19 16:02:01 -0600 | [diff] [blame] | 120 | uint64_t(i_logId); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 121 | 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 Tyner | 7f6ce6a | 2021-08-17 19:40:00 -0500 | [diff] [blame] | 134 | 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 Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 142 | 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 | { |
austinfcui | bfa831a | 2022-01-26 15:37:07 -0600 | [diff] [blame] | 157 | trace::err("requestDump exception"); |
| 158 | trace::err(e.what()); |
Ben Tyner | 7029e52 | 2021-08-09 19:18:24 -0500 | [diff] [blame] | 159 | } |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | } // namespace attn |