xref: /openbmc/phosphor-debug-collector/dump-extensions/openpower-dumps/resource_dump_entry.cpp (revision d73a663c79943ae97194347ca1ee3f8d454f6bfa)
1 #include "resource_dump_entry.hpp"
2 
3 #include "dump_utils.hpp"
4 #include "host_transport_exts.hpp"
5 #include "op_dump_consts.hpp"
6 
7 #include <phosphor-logging/elog-errors.hpp>
8 #include <phosphor-logging/lg2.hpp>
9 #include <xyz/openbmc_project/Common/error.hpp>
10 
11 namespace openpower
12 {
13 namespace dump
14 {
15 namespace resource
16 {
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,
20 constexpr auto TRANSPORT_DUMP_TYPE_IDENTIFIER = 9;
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;
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());
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 
42 void Entry::delete_()
43 {
44     auto srcDumpID = sourceDumpId();
45     auto dumpId = id;
46 
47     if ((!offloadUri().empty()) && (phosphor::dump::isHostRunning()))
48     {
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);
52         elog<sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed>(
53             xyz::openbmc_project::Common::NotAllowed::REASON(
54                 "Dump offload is in progress"));
55     }
56 
57     lg2::info("Resource dump delete id: {DUMP_ID} srcdumpid: {SRC_DUMP_ID}",
58               "DUMP_ID", dumpId, "SRC_DUMP_ID", srcDumpID);
59 
60     // Remove resource dump when host is up by using source dump id
61 
62     // which is present in resource dump entry dbus object as a property.
63     if ((phosphor::dump::isHostRunning()) && (srcDumpID != INVALID_SOURCE_ID))
64     {
65         try
66         {
67             phosphor::dump::host::requestDelete(srcDumpID,
68                                                 TRANSPORT_DUMP_TYPE_IDENTIFIER);
69         }
70         catch (const std::exception& e)
71         {
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);
75             elog<sdbusplus::xyz::openbmc_project::Common::Error::Unavailable>();
76         }
77     }
78 
79     // Remove Dump entry D-bus object
80     phosphor::dump::Entry::delete_();
81 }
82 } // namespace resource
83 } // namespace dump
84 } // namespace openpower
85