Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "dump_manager_resource.hpp" |
| 4 | |
| 5 | #include "dump_utils.hpp" |
Dhruvaraj Subhashchandran | ad50d42 | 2022-01-18 05:54:02 -0600 | [diff] [blame] | 6 | #include "op_dump_consts.hpp" |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 7 | #include "resource_dump_entry.hpp" |
| 8 | #include "xyz/openbmc_project/Common/error.hpp" |
| 9 | |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 10 | #include <fmt/core.h> |
| 11 | |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 12 | #include <phosphor-logging/elog-errors.hpp> |
| 13 | #include <phosphor-logging/elog.hpp> |
| 14 | |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 15 | namespace openpower |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 16 | { |
| 17 | namespace dump |
| 18 | { |
| 19 | namespace resource |
| 20 | { |
| 21 | |
| 22 | using namespace phosphor::logging; |
| 23 | using InternalFailure = |
| 24 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 25 | |
| 26 | void Manager::notify(uint32_t dumpId, uint64_t size) |
| 27 | { |
| 28 | // Get the timestamp |
| 29 | std::time_t timeStamp = std::time(nullptr); |
| 30 | |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 31 | // If there is an entry with invalid id update that. |
| 32 | // If there a completed one with same source id ignore it |
| 33 | // if there is no invalid id, create new entry |
| 34 | openpower::dump::resource::Entry* upEntry = NULL; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 35 | for (auto& entry : entries) |
| 36 | { |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 37 | openpower::dump::resource::Entry* resEntry = |
| 38 | dynamic_cast<openpower::dump::resource::Entry*>(entry.second.get()); |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 39 | |
| 40 | // If there is already a completed entry with input source id then |
| 41 | // ignore this notification. |
| 42 | if ((resEntry->sourceDumpId() == dumpId) && |
| 43 | (resEntry->status() == phosphor::dump::OperationStatus::Completed)) |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 44 | { |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 45 | log<level::INFO>( |
| 46 | fmt::format("Resource dump entry with source dump id({}) is " |
| 47 | "already present with entry id({})", |
| 48 | dumpId, resEntry->getDumpId()) |
| 49 | .c_str()); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 50 | return; |
| 51 | } |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 52 | |
| 53 | // Save the first entry with INVALID_SOURCE_ID |
| 54 | // but continue in the loop to make sure the |
| 55 | // new entry is not duplicate |
| 56 | if ((resEntry->status() == |
| 57 | phosphor::dump::OperationStatus::InProgress) && |
| 58 | (resEntry->sourceDumpId() == INVALID_SOURCE_ID) && |
| 59 | (upEntry == NULL)) |
| 60 | { |
| 61 | upEntry = resEntry; |
| 62 | } |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 63 | } |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 64 | if (upEntry != NULL) |
| 65 | { |
| 66 | log<level::INFO>( |
| 67 | fmt::format("Resource Dump Notify: Updating dumpId({}) " |
| 68 | "with source Id({}) Size({})", |
| 69 | upEntry->getDumpId(), dumpId, size) |
| 70 | .c_str()); |
| 71 | upEntry->update(timeStamp, size, dumpId); |
| 72 | return; |
| 73 | } |
| 74 | |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 75 | // Get the id |
| 76 | auto id = lastEntryId + 1; |
| 77 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 78 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 79 | |
| 80 | try |
| 81 | { |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 82 | log<level::INFO>(fmt::format("Resouce Dump Notify: creating new dump " |
| 83 | "entry dumpId({}) Id({}) Size({})", |
| 84 | id, dumpId, size) |
| 85 | .c_str()); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 86 | entries.insert(std::make_pair( |
| 87 | id, std::make_unique<resource::Entry>( |
| 88 | bus, objPath.c_str(), id, timeStamp, size, dumpId, |
| 89 | std::string(), std::string(), |
| 90 | phosphor::dump::OperationStatus::Completed, *this))); |
| 91 | } |
| 92 | catch (const std::invalid_argument& e) |
| 93 | { |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 94 | log<level::ERR>(fmt::format("Error in creating resource dump entry, " |
| 95 | "errormsg({}),OBJECTPATH({}),ID({})," |
| 96 | "TIMESTAMP({}),SIZE({}),SOURCEID({})", |
George Liu | 363af24 | 2021-07-16 17:52:36 +0800 | [diff] [blame] | 97 | e.what(), objPath.c_str(), id, timeStamp, |
| 98 | size, dumpId) |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 99 | .c_str()); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 100 | report<InternalFailure>(); |
| 101 | return; |
| 102 | } |
| 103 | lastEntryId++; |
| 104 | } |
| 105 | |
| 106 | sdbusplus::message::object_path |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 107 | Manager::createDump(phosphor::dump::DumpCreateParams params) |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 108 | { |
| 109 | |
| 110 | using NotAllowed = |
| 111 | sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 112 | using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
| 113 | |
| 114 | // Allow creating resource dump only when the host is up. |
| 115 | if (!phosphor::dump::isHostRunning()) |
| 116 | { |
| 117 | elog<NotAllowed>( |
| 118 | Reason("Resource dump can be initiated only when the host is up")); |
| 119 | return std::string(); |
| 120 | } |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 121 | |
| 122 | using InvalidArgument = |
| 123 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 124 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 125 | using CreateParameters = |
| 126 | sdbusplus::com::ibm::Dump::server::Create::CreateParameters; |
| 127 | |
| 128 | auto id = lastEntryId + 1; |
| 129 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 130 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 131 | std::time_t timeStamp = std::time(nullptr); |
| 132 | |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 133 | std::string vspString; |
| 134 | auto iter = params.find( |
| 135 | sdbusplus::com::ibm::Dump::server::Create:: |
| 136 | convertCreateParametersToString(CreateParameters::VSPString)); |
| 137 | if (iter == params.end()) |
| 138 | { |
| 139 | // Host will generate a default dump if no resource selector string |
| 140 | // is provided. The default dump will be a non-disruptive system dump. |
| 141 | log<level::INFO>( |
| 142 | "VSP string is not provided, a non-disruptive system dump will be " |
| 143 | "generated by the host"); |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | try |
| 148 | { |
| 149 | vspString = std::get<std::string>(iter->second); |
| 150 | } |
| 151 | catch (const std::bad_variant_access& e) |
| 152 | { |
| 153 | // Exception will be raised if the input is not string |
| 154 | log<level::ERR>( |
| 155 | fmt::format("An invalid vsp string is passed errormsg({})", |
| 156 | e.what()) |
| 157 | .c_str()); |
| 158 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("VSP_STRING"), |
| 159 | Argument::ARGUMENT_VALUE("INVALID INPUT")); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | std::string pwd; |
| 164 | iter = params.find( |
| 165 | sdbusplus::com::ibm::Dump::server::Create:: |
| 166 | convertCreateParametersToString(CreateParameters::Password)); |
| 167 | if (iter == params.end()) |
| 168 | { |
Dhruvaraj Subhashchandran | a5097b9 | 2022-03-08 12:33:41 -0600 | [diff] [blame] | 169 | log<level::INFO>("Password is not provided for resource dump"); |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 170 | } |
Dhruvaraj Subhashchandran | a5097b9 | 2022-03-08 12:33:41 -0600 | [diff] [blame] | 171 | else |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 172 | { |
Dhruvaraj Subhashchandran | a5097b9 | 2022-03-08 12:33:41 -0600 | [diff] [blame] | 173 | try |
| 174 | { |
| 175 | pwd = std::get<std::string>(iter->second); |
| 176 | } |
| 177 | catch (const std::bad_variant_access& e) |
| 178 | { |
| 179 | // Exception will be raised if the input is not string |
| 180 | log<level::ERR>( |
| 181 | fmt::format("An invalid password string is passed errormsg({})", |
| 182 | e.what()) |
| 183 | .c_str()); |
| 184 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("PASSWORD"), |
| 185 | Argument::ARGUMENT_VALUE("INVALID INPUT")); |
| 186 | } |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 187 | } |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 188 | |
| 189 | try |
| 190 | { |
| 191 | entries.insert(std::make_pair( |
| 192 | id, std::make_unique<resource::Entry>( |
| 193 | bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID, |
| 194 | vspString, pwd, phosphor::dump::OperationStatus::InProgress, |
| 195 | *this))); |
| 196 | } |
| 197 | catch (const std::invalid_argument& e) |
| 198 | { |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 199 | log<level::ERR>( |
| 200 | fmt::format( |
| 201 | "Error in creating resource dump " |
| 202 | "entry,errormsg({}),OBJECTPATH({}), VSPSTRING({}), ID({})", |
George Liu | 363af24 | 2021-07-16 17:52:36 +0800 | [diff] [blame] | 203 | e.what(), objPath.c_str(), vspString, id) |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 204 | .c_str()); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 205 | elog<InternalFailure>(); |
| 206 | return std::string(); |
| 207 | } |
| 208 | lastEntryId++; |
| 209 | return objPath.string(); |
| 210 | } |
| 211 | |
| 212 | } // namespace resource |
| 213 | } // namespace dump |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 214 | } // namespace openpower |