Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 1 | #include "resource_dump_entry.hpp" |
| 2 | |
| 3 | #include "dump_utils.hpp" |
| 4 | #include "host_transport_exts.hpp" |
Dhruvaraj Subhashchandran | ad50d42 | 2022-01-18 05:54:02 -0600 | [diff] [blame] | 5 | #include "op_dump_consts.hpp" |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 6 | |
| 7 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 8 | #include <phosphor-logging/lg2.hpp> |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 9 | #include <xyz/openbmc_project/Common/error.hpp> |
| 10 | |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 11 | namespace openpower |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 12 | { |
| 13 | namespace dump |
| 14 | { |
| 15 | namespace resource |
| 16 | { |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 17 | // TODO #ibm-openbmc/issues/2859 |
| 18 | // Revisit host transport impelementation |
| 19 | // This value is used to identify the dump in the transport layer to host, |
Dhruvaraj Subhashchandran | 0c782d6 | 2021-03-24 13:27:13 -0500 | [diff] [blame] | 20 | constexpr auto TRANSPORT_DUMP_TYPE_IDENTIFIER = 9; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 21 | using namespace phosphor::logging; |
| 22 | |
| 23 | void Entry::initiateOffload(std::string uri) |
| 24 | { |
| 25 | using NotAllowed = |
| 26 | sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 27 | using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 28 | lg2::info("Resource dump offload request id: {ID} uri: {URI} " |
| 29 | "source dumpid: {SOURCE_DUMP_ID}", |
| 30 | "ID", id, "URI", uri, "SOURCE_DUMP_ID", sourceDumpId()); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 31 | |
| 32 | if (!phosphor::dump::isHostRunning()) |
| 33 | { |
| 34 | elog<NotAllowed>( |
| 35 | Reason("This dump can be offloaded only when the host is up")); |
| 36 | return; |
| 37 | } |
| 38 | phosphor::dump::Entry::initiateOffload(uri); |
| 39 | phosphor::dump::host::requestOffload(sourceDumpId()); |
| 40 | } |
| 41 | |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 42 | void Entry::delete_() |
| 43 | { |
| 44 | auto srcDumpID = sourceDumpId(); |
Dhruvaraj Subhashchandran | b5a7547 | 2022-02-03 03:52:01 -0600 | [diff] [blame] | 45 | auto dumpId = id; |
Dhruvaraj Subhashchandran | 1112bdf | 2022-03-23 04:38:02 -0500 | [diff] [blame] | 46 | |
| 47 | if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning())) |
| 48 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 49 | lg2::error("Dump offload is in progress, cannot delete dump, " |
| 50 | "id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}", |
| 51 | "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID); |
Dhruvaraj Subhashchandran | 1112bdf | 2022-03-23 04:38:02 -0500 | [diff] [blame] | 52 | elog<sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed>( |
| 53 | xyz::openbmc_project::Common::NotAllowed::REASON( |
| 54 | "Dump offload is in progress")); |
| 55 | } |
| 56 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 57 | lg2::info("Resource dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}", |
| 58 | "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID); |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 59 | |
| 60 | // Remove resource dump when host is up by using source dump id |
Dhruvaraj Subhashchandran | 345e56b | 2022-05-17 01:53:19 -0500 | [diff] [blame] | 61 | |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 62 | // which is present in resource dump entry dbus object as a property. |
Dhruvaraj Subhashchandran | ad50d42 | 2022-01-18 05:54:02 -0600 | [diff] [blame] | 63 | if ((phosphor::dump::isHostRunning()) && (srcDumpID != INVALID_SOURCE_ID)) |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 64 | { |
Dhruvaraj Subhashchandran | 345e56b | 2022-05-17 01:53:19 -0500 | [diff] [blame] | 65 | try |
| 66 | { |
| 67 | phosphor::dump::host::requestDelete(srcDumpID, |
| 68 | TRANSPORT_DUMP_TYPE_IDENTIFIER); |
| 69 | } |
| 70 | catch (const std::exception& e) |
| 71 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 72 | lg2::error("Error deleting dump from host id: {DUMP_ID} " |
| 73 | "host id: {SRC_DUMP_ID} error: {ERROR}", |
| 74 | "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID, "ERROR", e); |
Dhruvaraj Subhashchandran | 345e56b | 2022-05-17 01:53:19 -0500 | [diff] [blame] | 75 | elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>(); |
| 76 | } |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 77 | } |
Dhruvaraj Subhashchandran | 345e56b | 2022-05-17 01:53:19 -0500 | [diff] [blame] | 78 | |
| 79 | // Remove Dump entry D-bus object |
| 80 | phosphor::dump::Entry::delete_(); |
Dhruvaraj Subhashchandran | 4c63ce5 | 2020-12-18 02:07:22 -0600 | [diff] [blame] | 81 | } |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 82 | } // namespace resource |
| 83 | } // namespace dump |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 84 | } // namespace openpower |