blob: de27c94646ab43547866e311e501d1f94f18f8c4 [file] [log] [blame]
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -06001#include "config.h"
2
3#include "dump_manager_resource.hpp"
4
5#include "dump_utils.hpp"
6#include "resource_dump_entry.hpp"
7#include "xyz/openbmc_project/Common/error.hpp"
8
George Liu858fbb22021-07-01 12:25:44 +08009#include <fmt/core.h>
10
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060011#include <phosphor-logging/elog-errors.hpp>
12#include <phosphor-logging/elog.hpp>
13
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060014namespace openpower
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060015{
16namespace dump
17{
18namespace resource
19{
20
21using namespace phosphor::logging;
22using InternalFailure =
23 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
24
25void Manager::notify(uint32_t dumpId, uint64_t size)
26{
27 // Get the timestamp
28 std::time_t timeStamp = std::time(nullptr);
29
30 // If there is an entry with this sourceId or an invalid id
31 // update that.
32 // If host is sending the source id before the completion
33 // the source id will be updated by the transport layer with host.
34 // if not the source id will stay as invalid one.
35 for (auto& entry : entries)
36 {
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060037 openpower::dump::resource::Entry* resEntry =
38 dynamic_cast<openpower::dump::resource::Entry*>(entry.second.get());
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060039 if ((resEntry->status() ==
40 phosphor::dump::OperationStatus::InProgress) &&
41 ((resEntry->sourceDumpId() == dumpId) ||
42 (resEntry->sourceDumpId() == INVALID_SOURCE_ID)))
43 {
44 resEntry->update(timeStamp, size, dumpId);
45 return;
46 }
47 }
48 // Get the id
49 auto id = lastEntryId + 1;
50 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050051 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060052
53 try
54 {
55 entries.insert(std::make_pair(
56 id, std::make_unique<resource::Entry>(
57 bus, objPath.c_str(), id, timeStamp, size, dumpId,
58 std::string(), std::string(),
59 phosphor::dump::OperationStatus::Completed, *this)));
60 }
61 catch (const std::invalid_argument& e)
62 {
George Liu858fbb22021-07-01 12:25:44 +080063 log<level::ERR>(fmt::format("Error in creating resource dump entry, "
64 "errormsg({}),OBJECTPATH({}),ID({}),"
65 "TIMESTAMP({}),SIZE({}),SOURCEID({})",
George Liu363af242021-07-16 17:52:36 +080066 e.what(), objPath.c_str(), id, timeStamp,
67 size, dumpId)
George Liu858fbb22021-07-01 12:25:44 +080068 .c_str());
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060069 report<InternalFailure>();
70 return;
71 }
72 lastEntryId++;
73}
74
75sdbusplus::message::object_path
76 Manager::createDump(std::map<std::string, std::string> params)
77{
78
79 using NotAllowed =
80 sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
81 using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
82
83 // Allow creating resource dump only when the host is up.
84 if (!phosphor::dump::isHostRunning())
85 {
86 elog<NotAllowed>(
87 Reason("Resource dump can be initiated only when the host is up"));
88 return std::string();
89 }
90 using CreateParameters =
91 sdbusplus::com::ibm::Dump::server::Create::CreateParameters;
92
93 auto id = lastEntryId + 1;
94 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050095 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -060096 std::time_t timeStamp = std::time(nullptr);
97
98 std::string vspString = params[sdbusplus::com::ibm::Dump::server::Create::
99 convertCreateParametersToString(
100 CreateParameters::VSPString)];
101 std::string pwd =
102 params[sdbusplus::com::ibm::Dump::server::Create::
103 convertCreateParametersToString(CreateParameters::Password)];
104
105 try
106 {
107 entries.insert(std::make_pair(
108 id, std::make_unique<resource::Entry>(
109 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
110 vspString, pwd, phosphor::dump::OperationStatus::InProgress,
111 *this)));
112 }
113 catch (const std::invalid_argument& e)
114 {
George Liu858fbb22021-07-01 12:25:44 +0800115 log<level::ERR>(
116 fmt::format(
117 "Error in creating resource dump "
118 "entry,errormsg({}),OBJECTPATH({}), VSPSTRING({}), ID({})",
George Liu363af242021-07-16 17:52:36 +0800119 e.what(), objPath.c_str(), vspString, id)
George Liu858fbb22021-07-01 12:25:44 +0800120 .c_str());
Dhruvaraj Subhashchandran62337a92020-11-22 21:24:30 -0600121 elog<InternalFailure>();
122 return std::string();
123 }
124 lastEntryId++;
125 return objPath.string();
126}
127
128} // namespace resource
129} // namespace dump
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -0600130} // namespace openpower