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