162337a92SDhruvaraj Subhashchandran #include "resource_dump_entry.hpp"
262337a92SDhruvaraj Subhashchandran
362337a92SDhruvaraj Subhashchandran #include "dump_utils.hpp"
462337a92SDhruvaraj Subhashchandran #include "host_transport_exts.hpp"
5ad50d422SDhruvaraj Subhashchandran #include "op_dump_consts.hpp"
662337a92SDhruvaraj Subhashchandran
762337a92SDhruvaraj Subhashchandran #include <phosphor-logging/elog-errors.hpp>
8d1f670feSDhruvaraj Subhashchandran #include <phosphor-logging/lg2.hpp>
962337a92SDhruvaraj Subhashchandran #include <xyz/openbmc_project/Common/error.hpp>
1062337a92SDhruvaraj Subhashchandran
11341d683dSDhruvaraj Subhashchandran namespace openpower
1262337a92SDhruvaraj Subhashchandran {
1362337a92SDhruvaraj Subhashchandran namespace dump
1462337a92SDhruvaraj Subhashchandran {
1562337a92SDhruvaraj Subhashchandran namespace resource
1662337a92SDhruvaraj Subhashchandran {
174c63ce5eSDhruvaraj Subhashchandran // TODO #ibm-openbmc/issues/2859
184c63ce5eSDhruvaraj Subhashchandran // Revisit host transport impelementation
194c63ce5eSDhruvaraj Subhashchandran // This value is used to identify the dump in the transport layer to host,
200c782d64SDhruvaraj Subhashchandran constexpr auto TRANSPORT_DUMP_TYPE_IDENTIFIER = 9;
2162337a92SDhruvaraj Subhashchandran using namespace phosphor::logging;
2262337a92SDhruvaraj Subhashchandran
initiateOffload(std::string uri)2362337a92SDhruvaraj Subhashchandran void Entry::initiateOffload(std::string uri)
2462337a92SDhruvaraj Subhashchandran {
2562337a92SDhruvaraj Subhashchandran using NotAllowed =
2662337a92SDhruvaraj Subhashchandran sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
2762337a92SDhruvaraj Subhashchandran using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
28d1f670feSDhruvaraj Subhashchandran lg2::info("Resource dump offload request id: {ID} uri: {URI} "
29d1f670feSDhruvaraj Subhashchandran "source dumpid: {SOURCE_DUMP_ID}",
30d1f670feSDhruvaraj Subhashchandran "ID", id, "URI", uri, "SOURCE_DUMP_ID", sourceDumpId());
3162337a92SDhruvaraj Subhashchandran
3262337a92SDhruvaraj Subhashchandran if (!phosphor::dump::isHostRunning())
3362337a92SDhruvaraj Subhashchandran {
3462337a92SDhruvaraj Subhashchandran elog<NotAllowed>(
3562337a92SDhruvaraj Subhashchandran Reason("This dump can be offloaded only when the host is up"));
3662337a92SDhruvaraj Subhashchandran return;
3762337a92SDhruvaraj Subhashchandran }
3862337a92SDhruvaraj Subhashchandran phosphor::dump::Entry::initiateOffload(uri);
3962337a92SDhruvaraj Subhashchandran phosphor::dump::host::requestOffload(sourceDumpId());
4062337a92SDhruvaraj Subhashchandran }
4162337a92SDhruvaraj Subhashchandran
delete_()424c63ce5eSDhruvaraj Subhashchandran void Entry::delete_()
434c63ce5eSDhruvaraj Subhashchandran {
444c63ce5eSDhruvaraj Subhashchandran auto srcDumpID = sourceDumpId();
45b5a7547fSDhruvaraj Subhashchandran auto dumpId = id;
461112bdfcSDhruvaraj Subhashchandran
471112bdfcSDhruvaraj Subhashchandran if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning()))
481112bdfcSDhruvaraj Subhashchandran {
49d1f670feSDhruvaraj Subhashchandran lg2::error("Dump offload is in progress, cannot delete dump, "
50d1f670feSDhruvaraj Subhashchandran "id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
51d1f670feSDhruvaraj Subhashchandran "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
52*7e4edab9SDhruvaraj Subhashchandran elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
531112bdfcSDhruvaraj Subhashchandran }
541112bdfcSDhruvaraj Subhashchandran
55d1f670feSDhruvaraj Subhashchandran lg2::info("Resource dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
56d1f670feSDhruvaraj Subhashchandran "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
574c63ce5eSDhruvaraj Subhashchandran
584c63ce5eSDhruvaraj Subhashchandran // Remove resource dump when host is up by using source dump id
59345e56b0SDhruvaraj Subhashchandran
604c63ce5eSDhruvaraj Subhashchandran // which is present in resource dump entry dbus object as a property.
61ad50d422SDhruvaraj Subhashchandran if ((phosphor::dump::isHostRunning()) && (srcDumpID != INVALID_SOURCE_ID))
624c63ce5eSDhruvaraj Subhashchandran {
63345e56b0SDhruvaraj Subhashchandran try
64345e56b0SDhruvaraj Subhashchandran {
654c63ce5eSDhruvaraj Subhashchandran phosphor::dump::host::requestDelete(srcDumpID,
664c63ce5eSDhruvaraj Subhashchandran TRANSPORT_DUMP_TYPE_IDENTIFIER);
674c63ce5eSDhruvaraj Subhashchandran }
68345e56b0SDhruvaraj Subhashchandran catch (const std::exception& e)
69345e56b0SDhruvaraj Subhashchandran {
70d1f670feSDhruvaraj Subhashchandran lg2::error("Error deleting dump from host id: {DUMP_ID} "
71d1f670feSDhruvaraj Subhashchandran "host id: {SRC_DUMP_ID} error: {ERROR}",
72d1f670feSDhruvaraj Subhashchandran "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID, "ERROR", e);
73345e56b0SDhruvaraj Subhashchandran elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
74345e56b0SDhruvaraj Subhashchandran }
75345e56b0SDhruvaraj Subhashchandran }
76345e56b0SDhruvaraj Subhashchandran
77345e56b0SDhruvaraj Subhashchandran // Remove Dump entry D-bus object
78345e56b0SDhruvaraj Subhashchandran phosphor::dump::Entry::delete_();
794c63ce5eSDhruvaraj Subhashchandran }
8062337a92SDhruvaraj Subhashchandran } // namespace resource
8162337a92SDhruvaraj Subhashchandran } // namespace dump
82341d683dSDhruvaraj Subhashchandran } // namespace openpower
83