blob: 40fa9090ca14d953f53d1d4b531430bfecc90dd4 [file] [log] [blame]
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -06001#include "resource_dump_entry.hpp"
2
3#include "dump_utils.hpp"
4#include "host_transport_exts.hpp"
Dhruvaraj Subhashchandranad50d422022-01-18 05:54:02 -06005#include "op_dump_consts.hpp"
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -06006
Dhruvaraj Subhashchandranb5a75472022-02-03 03:52:01 -06007#include <fmt/core.h>
8
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -06009#include <phosphor-logging/elog-errors.hpp>
10#include <xyz/openbmc_project/Common/error.hpp>
11
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060012namespace openpower
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060013{
14namespace dump
15{
16namespace resource
17{
Dhruvaraj Subhashchandran4c63ce52020-12-18 02:07:22 -060018// 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 Subhashchandran0c782d62021-03-24 13:27:13 -050021constexpr auto TRANSPORT_DUMP_TYPE_IDENTIFIER = 9;
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060022using namespace phosphor::logging;
23
24void 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 Subhashchandranc1778da2022-02-04 01:46:49 -060029 log<level::INFO>(
30 fmt::format(
Dhruvaraj Subhashchandranf5e53852022-03-03 02:05:49 -060031 "Resource dump offload request id({}) uri({}) source dumpid({})",
32 id, uri, sourceDumpId())
Dhruvaraj Subhashchandranc1778da2022-02-04 01:46:49 -060033 .c_str());
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060034
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 Subhashchandran4c63ce52020-12-18 02:07:22 -060045void Entry::delete_()
46{
47 auto srcDumpID = sourceDumpId();
Dhruvaraj Subhashchandranb5a75472022-02-03 03:52:01 -060048 auto dumpId = id;
Dhruvaraj Subhashchandran1112bdf2022-03-23 04:38:02 -050049
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 Subhashchandranb5a75472022-02-03 03:52:01 -060062 log<level::INFO>(fmt::format("Resource dump delete id({}) srcdumpid({})",
63 dumpId, srcDumpID)
64 .c_str());
Dhruvaraj Subhashchandran4c63ce52020-12-18 02:07:22 -060065 // Remove Dump entry D-bus object
66 phosphor::dump::Entry::delete_();
67
68 // Remove resource dump when host is up by using source dump id
69 // which is present in resource dump entry dbus object as a property.
Dhruvaraj Subhashchandranad50d422022-01-18 05:54:02 -060070 if ((phosphor::dump::isHostRunning()) && (srcDumpID != INVALID_SOURCE_ID))
Dhruvaraj Subhashchandran4c63ce52020-12-18 02:07:22 -060071 {
72 phosphor::dump::host::requestDelete(srcDumpID,
73 TRANSPORT_DUMP_TYPE_IDENTIFIER);
74 }
75}
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060076} // namespace resource
77} // namespace dump
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060078} // namespace openpower