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 | |
| 10 | #include <phosphor-logging/elog-errors.hpp> |
| 11 | #include <phosphor-logging/elog.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 12 | #include <phosphor-logging/lg2.hpp> |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 13 | |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 14 | namespace openpower |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 15 | { |
| 16 | namespace dump |
| 17 | { |
| 18 | namespace resource |
| 19 | { |
| 20 | |
| 21 | using namespace phosphor::logging; |
| 22 | using InternalFailure = |
| 23 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 24 | |
| 25 | void Manager::notify(uint32_t dumpId, uint64_t size) |
| 26 | { |
| 27 | // Get the timestamp |
Claire Weinan | c0ab9d4 | 2022-08-17 23:01:07 -0700 | [diff] [blame] | 28 | uint64_t timeStamp = |
| 29 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 30 | std::chrono::system_clock::now().time_since_epoch()) |
| 31 | .count(); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 32 | |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 33 | // If there is an entry with invalid id update that. |
| 34 | // If there a completed one with same source id ignore it |
| 35 | // if there is no invalid id, create new entry |
| 36 | openpower::dump::resource::Entry* upEntry = NULL; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 37 | for (auto& entry : entries) |
| 38 | { |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 39 | openpower::dump::resource::Entry* resEntry = |
| 40 | dynamic_cast<openpower::dump::resource::Entry*>(entry.second.get()); |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 41 | |
| 42 | // If there is already a completed entry with input source id then |
| 43 | // ignore this notification. |
| 44 | if ((resEntry->sourceDumpId() == dumpId) && |
| 45 | (resEntry->status() == phosphor::dump::OperationStatus::Completed)) |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 46 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 47 | lg2::info("Resource dump entry with source dump id: {DUMP_ID} " |
| 48 | "is already present with entry id: {ENTRY_ID}", |
| 49 | "DUMP_ID", dumpId, "ENTRY_ID", resEntry->getDumpId()); |
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 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 66 | lg2::info("Resource Dump Notify: Updating dumpId: {DUMP_ID} with " |
| 67 | "source Id: {SOURCE_ID} Size: {SIZE}", |
| 68 | "DUMP_ID", upEntry->getDumpId(), "SOURCE_ID", dumpId, "SIZE", |
| 69 | size); |
Dhruvaraj Subhashchandran | 583ebc0 | 2022-02-01 03:02:35 -0600 | [diff] [blame] | 70 | upEntry->update(timeStamp, size, dumpId); |
| 71 | return; |
| 72 | } |
| 73 | |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 74 | // Get the id |
| 75 | auto id = lastEntryId + 1; |
| 76 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 77 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 78 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 79 | // TODO: Get the originator Id, type from the persisted file. |
| 80 | // For now replacing it with null |
| 81 | |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 82 | try |
| 83 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 84 | lg2::info( |
| 85 | "Resouce Dump Notify: creating new dump entry dumpId: {DUMP_ID} " |
| 86 | "Id: {ID} Size: {SIZE}", |
| 87 | "DUMP_ID", id, "ID", dumpId, "SIZE", size); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 88 | entries.insert(std::make_pair( |
| 89 | id, std::make_unique<resource::Entry>( |
| 90 | bus, objPath.c_str(), id, timeStamp, size, dumpId, |
| 91 | std::string(), std::string(), |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 92 | phosphor::dump::OperationStatus::Completed, std::string(), |
| 93 | originatorTypes::Internal, *this))); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 94 | } |
| 95 | catch (const std::invalid_argument& e) |
| 96 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 97 | lg2::error( |
| 98 | "Error in creating resource dump entry, errormsg: {ERROR}, " |
| 99 | "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, " |
| 100 | "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}", |
| 101 | "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP", |
| 102 | timeStamp, "SIZE", size, "SOURCE_ID", dumpId); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 103 | report<InternalFailure>(); |
| 104 | return; |
| 105 | } |
| 106 | lastEntryId++; |
| 107 | } |
| 108 | |
| 109 | sdbusplus::message::object_path |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 110 | Manager::createDump(phosphor::dump::DumpCreateParams params) |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 111 | { |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 112 | using NotAllowed = |
| 113 | sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 114 | using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
| 115 | |
| 116 | // Allow creating resource dump only when the host is up. |
| 117 | if (!phosphor::dump::isHostRunning()) |
| 118 | { |
| 119 | elog<NotAllowed>( |
| 120 | Reason("Resource dump can be initiated only when the host is up")); |
| 121 | return std::string(); |
| 122 | } |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 123 | |
| 124 | using InvalidArgument = |
| 125 | sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument; |
| 126 | using Argument = xyz::openbmc_project::Common::InvalidArgument; |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 127 | using CreateParameters = |
| 128 | sdbusplus::com::ibm::Dump::server::Create::CreateParameters; |
| 129 | |
| 130 | auto id = lastEntryId + 1; |
| 131 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 132 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Claire Weinan | c0ab9d4 | 2022-08-17 23:01:07 -0700 | [diff] [blame] | 133 | uint64_t timeStamp = |
| 134 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 135 | std::chrono::system_clock::now().time_since_epoch()) |
| 136 | .count(); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 137 | |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 138 | std::string vspString; |
| 139 | auto iter = params.find( |
| 140 | sdbusplus::com::ibm::Dump::server::Create:: |
| 141 | convertCreateParametersToString(CreateParameters::VSPString)); |
| 142 | if (iter == params.end()) |
| 143 | { |
| 144 | // Host will generate a default dump if no resource selector string |
| 145 | // is provided. The default dump will be a non-disruptive system dump. |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 146 | lg2::info( |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 147 | "VSP string is not provided, a non-disruptive system dump will be " |
| 148 | "generated by the host"); |
| 149 | } |
| 150 | else |
| 151 | { |
| 152 | try |
| 153 | { |
| 154 | vspString = std::get<std::string>(iter->second); |
| 155 | } |
| 156 | catch (const std::bad_variant_access& e) |
| 157 | { |
| 158 | // Exception will be raised if the input is not string |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 159 | lg2::error("An invalid vsp string is passed, errormsg: {ERROR}", |
| 160 | "ERROR", e); |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 161 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("VSP_STRING"), |
| 162 | Argument::ARGUMENT_VALUE("INVALID INPUT")); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | std::string pwd; |
| 167 | iter = params.find( |
| 168 | sdbusplus::com::ibm::Dump::server::Create:: |
| 169 | convertCreateParametersToString(CreateParameters::Password)); |
| 170 | if (iter == params.end()) |
| 171 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 172 | lg2::info("Password is not provided for resource dump"); |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 173 | } |
Dhruvaraj Subhashchandran | a5097b9 | 2022-03-08 12:33:41 -0600 | [diff] [blame] | 174 | else |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 175 | { |
Dhruvaraj Subhashchandran | a5097b9 | 2022-03-08 12:33:41 -0600 | [diff] [blame] | 176 | try |
| 177 | { |
| 178 | pwd = std::get<std::string>(iter->second); |
| 179 | } |
| 180 | catch (const std::bad_variant_access& e) |
| 181 | { |
| 182 | // Exception will be raised if the input is not string |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 183 | lg2::error( |
| 184 | "An invalid password string is passed, errormsg: {ERROR}", |
| 185 | "ERROR", e); |
Dhruvaraj Subhashchandran | a5097b9 | 2022-03-08 12:33:41 -0600 | [diff] [blame] | 186 | elog<InvalidArgument>(Argument::ARGUMENT_NAME("PASSWORD"), |
| 187 | Argument::ARGUMENT_VALUE("INVALID INPUT")); |
| 188 | } |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 189 | } |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 190 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 191 | // Get the originator id and type from params |
| 192 | std::string originatorId; |
| 193 | originatorTypes originatorType; |
| 194 | |
| 195 | phosphor::dump::extractOriginatorProperties(params, originatorId, |
| 196 | originatorType); |
| 197 | |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 198 | try |
| 199 | { |
| 200 | entries.insert(std::make_pair( |
| 201 | id, std::make_unique<resource::Entry>( |
| 202 | bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID, |
| 203 | vspString, pwd, phosphor::dump::OperationStatus::InProgress, |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 204 | originatorId, originatorType, *this))); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 205 | } |
| 206 | catch (const std::invalid_argument& e) |
| 207 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame^] | 208 | lg2::error( |
| 209 | "Error in creating resource dump entry, errormsg: {ERROR}, " |
| 210 | "OBJECTPATH: {OBJECT_PATH}, VSPSTRING: {VSP_STRING}, ID: {ID}", |
| 211 | "ERROR", e, "OBJECT_PATH", objPath, "VSP_STRING", vspString, "ID", |
| 212 | id); |
Dhruvaraj Subhashchandran | 62337a9 | 2020-11-22 21:24:30 -0600 | [diff] [blame] | 213 | elog<InternalFailure>(); |
| 214 | return std::string(); |
| 215 | } |
| 216 | lastEntryId++; |
| 217 | return objPath.string(); |
| 218 | } |
| 219 | |
| 220 | } // namespace resource |
| 221 | } // namespace dump |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 222 | } // namespace openpower |