Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "dump_manager_system.hpp" |
| 4 | |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 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 | 1ddb006 | 2022-05-06 06:21:11 -0500 | [diff] [blame] | 7 | #include "op_dump_util.hpp" |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 8 | #include "system_dump_entry.hpp" |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 9 | #include "xyz/openbmc_project/Common/error.hpp" |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 10 | |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 11 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 12 | #include <phosphor-logging/elog.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 13 | #include <phosphor-logging/lg2.hpp> |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 14 | |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 15 | namespace openpower |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 16 | { |
| 17 | namespace dump |
| 18 | { |
| 19 | namespace system |
| 20 | { |
| 21 | |
| 22 | using namespace phosphor::logging; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 23 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 24 | |
Dhruvaraj Subhashchandran | f37c5c3 | 2020-12-17 22:08:19 -0600 | [diff] [blame] | 25 | void Manager::notify(uint32_t dumpId, uint64_t size) |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 26 | { |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 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 | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 32 | |
Dhruvaraj Subhashchandran | 0007b70 | 2022-02-01 03:23:14 -0600 | [diff] [blame] | 33 | // A system dump can be created due to a fault in the server or by a user |
| 34 | // request. A system dump by fault is first reported here, but for a |
| 35 | // user-requested dump, an entry will be created first with an invalid |
| 36 | // source id. Since only one system dump creation is allowed at a time, if |
| 37 | // there's an entry with an invalid sourceId, we will update that entry. |
| 38 | openpower::dump::system::Entry* upEntry = nullptr; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 39 | for (auto& entry : entries) |
| 40 | { |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 41 | openpower::dump::system::Entry* sysEntry = |
| 42 | dynamic_cast<openpower::dump::system::Entry*>(entry.second.get()); |
Dhruvaraj Subhashchandran | 0007b70 | 2022-02-01 03:23:14 -0600 | [diff] [blame] | 43 | |
| 44 | // If there's already a completed entry with the input source id and |
| 45 | // size, ignore this notification |
| 46 | if ((sysEntry->sourceDumpId() == dumpId) && (sysEntry->size() == size)) |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 47 | { |
Dhruvaraj Subhashchandran | 0007b70 | 2022-02-01 03:23:14 -0600 | [diff] [blame] | 48 | if (sysEntry->status() == |
| 49 | phosphor::dump::OperationStatus::Completed) |
| 50 | { |
| 51 | lg2::info( |
| 52 | "System dump entry with source dump id:{SOURCE_ID} and " |
| 53 | "size: {SIZE} is already present with entry id:{ID}", |
| 54 | "SOURCE_ID", dumpId, "SIZE", size, "ID", |
| 55 | sysEntry->getDumpId()); |
| 56 | return; |
| 57 | } |
| 58 | else |
| 59 | { |
| 60 | lg2::error("A duplicate notification for an incomplete dump " |
| 61 | "dump id: {SOURCE_ID} entry id: {ID}", |
| 62 | "SOURCE_D", dumpId, "ID", sysEntry->getDumpId()); |
| 63 | upEntry = sysEntry; |
| 64 | break; |
| 65 | } |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 66 | } |
Dhruvaraj Subhashchandran | 0007b70 | 2022-02-01 03:23:14 -0600 | [diff] [blame] | 67 | else if (sysEntry->sourceDumpId() == dumpId) |
| 68 | { |
| 69 | // If the dump id is the same but the size is different, then this |
| 70 | // is a new dump. So, delete the stale entry and prepare to create a |
| 71 | // new one. |
| 72 | lg2::info("A previous dump entry found with same source id: " |
| 73 | "{SOURCE_ID}, deleting it, entry id: {DUMP_ID}", |
| 74 | "SOURCE_ID", dumpId, "DUMP_ID", sysEntry->getDumpId()); |
| 75 | sysEntry->delete_(); |
| 76 | // No 'break' here, as we need to continue checking other entries. |
| 77 | } |
| 78 | |
| 79 | // Save the first entry with INVALID_SOURCE_ID, but continue in the loop |
| 80 | // to ensure the new entry is not a duplicate. |
| 81 | if ((sysEntry->sourceDumpId() == INVALID_SOURCE_ID) && |
| 82 | (upEntry == nullptr)) |
| 83 | { |
| 84 | upEntry = sysEntry; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | if (upEntry != nullptr) |
| 89 | { |
| 90 | lg2::info( |
| 91 | "System Dump Notify: Updating dumpId:{ID} Source Id:{SOURCE_ID} " |
| 92 | "Size:{SIZE}", |
| 93 | "ID", upEntry->getDumpId(), "SOURCE_ID", dumpId, "SIZE", size); |
| 94 | upEntry->update(timeStamp, size, dumpId); |
| 95 | return; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 96 | } |
| 97 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 98 | // Get the id |
| 99 | auto id = lastEntryId + 1; |
| 100 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 101 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 102 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 103 | // TODO: Get the originator Id, Type from the persisted file. |
| 104 | // For now replacing it with null |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 105 | try |
| 106 | { |
Dhruvaraj Subhashchandran | 0007b70 | 2022-02-01 03:23:14 -0600 | [diff] [blame] | 107 | lg2::info("System Dump Notify: creating new dump " |
| 108 | "entry dumpId:{ID} Source Id:{SOURCE_ID} Size:{SIZE}", |
| 109 | "ID", id, "SOURCE_ID", dumpId, "SIZE", size); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 110 | entries.insert(std::make_pair( |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 111 | id, std::make_unique<system::Entry>( |
| 112 | bus, objPath.c_str(), id, timeStamp, size, dumpId, |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 113 | phosphor::dump::OperationStatus::Completed, std::string(), |
| 114 | originatorTypes::Internal, *this))); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 115 | } |
| 116 | catch (const std::invalid_argument& e) |
| 117 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 118 | lg2::error( |
| 119 | "Error in creating system dump entry, errormsg: {ERROR}, " |
| 120 | "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, " |
| 121 | "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}", |
| 122 | "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP", |
| 123 | timeStamp, "SIZE", size, "SOURCE_ID", dumpId); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 124 | report<InternalFailure>(); |
| 125 | return; |
| 126 | } |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 127 | lastEntryId++; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 128 | return; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 129 | } |
| 130 | |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 131 | sdbusplus::message::object_path |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 132 | Manager::createDump(phosphor::dump::DumpCreateParams params) |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 133 | { |
| 134 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 135 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 136 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
Andrew Geissler | 24e0c59 | 2021-01-19 16:47:27 -0600 | [diff] [blame] | 137 | constexpr auto DIAG_MOD_TARGET = "obmc-host-crash@0.target"; |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 138 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 139 | if (params.size() > CREATE_DUMP_MAX_PARAMS) |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 140 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 141 | lg2::warning( |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 142 | "System dump accepts not more than 2 additional parameters"); |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 143 | } |
Dhruvaraj Subhashchandran | 1ddb006 | 2022-05-06 06:21:11 -0500 | [diff] [blame] | 144 | using Unavailable = |
| 145 | sdbusplus::xyz::openbmc_project::Common::Error::Unavailable; |
| 146 | |
| 147 | if (openpower::dump::util::isSystemDumpInProgress(bus)) |
| 148 | { |
| 149 | lg2::error("Another dump in progress or available to offload"); |
| 150 | elog<Unavailable>(); |
| 151 | } |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 152 | |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 153 | using NotAllowed = |
| 154 | sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 155 | using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
| 156 | |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 157 | auto isHostRunning = false; |
| 158 | phosphor::dump::HostState hostState; |
| 159 | try |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 160 | { |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 161 | isHostRunning = phosphor::dump::isHostRunning(); |
| 162 | hostState = phosphor::dump::getHostState(); |
| 163 | } |
| 164 | catch (const std::exception& e) |
| 165 | { |
| 166 | lg2::error( |
| 167 | "System state cannot be determined, system dump is not allowed: " |
| 168 | "{ERROR}", |
| 169 | "ERROR", e); |
| 170 | return std::string(); |
| 171 | } |
| 172 | bool isHostQuiesced = hostState == phosphor::dump::HostState::Quiesced; |
Dhruvaraj Subhashchandran | ea632b8 | 2022-05-06 06:51:18 -0500 | [diff] [blame] | 173 | bool isHostTransitioningToOff = |
| 174 | hostState == phosphor::dump::HostState::TransitioningToOff; |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 175 | // Allow creating system dump only when the host is up or quiesced |
Dhruvaraj Subhashchandran | ea632b8 | 2022-05-06 06:51:18 -0500 | [diff] [blame] | 176 | // starting to power off |
| 177 | if (!isHostRunning && !isHostQuiesced && !isHostTransitioningToOff) |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 178 | { |
| 179 | lg2::error("System dump can be initiated only when the host is up " |
Dhruvaraj Subhashchandran | ea632b8 | 2022-05-06 06:51:18 -0500 | [diff] [blame] | 180 | "or quiesced or starting to poweroff"); |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 181 | elog<NotAllowed>( |
Dhruvaraj Subhashchandran | 3a25e5b | 2022-03-22 08:06:20 -0500 | [diff] [blame] | 182 | Reason("System dump can be initiated only when the host is up " |
Dhruvaraj Subhashchandran | ea632b8 | 2022-05-06 06:51:18 -0500 | [diff] [blame] | 183 | "or quiesced or starting to poweroff")); |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 184 | return std::string(); |
| 185 | } |
| 186 | |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 187 | // Get the originator id and type from params |
| 188 | std::string originatorId; |
| 189 | originatorTypes originatorType; |
| 190 | |
| 191 | phosphor::dump::extractOriginatorProperties(params, originatorId, |
| 192 | originatorType); |
| 193 | |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 194 | auto b = sdbusplus::bus::new_default(); |
| 195 | auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 196 | SYSTEMD_INTERFACE, "StartUnit"); |
| 197 | method.append(DIAG_MOD_TARGET); // unit to activate |
| 198 | method.append("replace"); |
| 199 | bus.call_noreply(method); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 200 | |
| 201 | auto id = lastEntryId + 1; |
| 202 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 203 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Claire Weinan | c0ab9d4 | 2022-08-17 23:01:07 -0700 | [diff] [blame] | 204 | uint64_t timeStamp = |
| 205 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 206 | std::chrono::system_clock::now().time_since_epoch()) |
| 207 | .count(); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 208 | |
| 209 | try |
| 210 | { |
| 211 | entries.insert(std::make_pair( |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 212 | id, std::make_unique<system::Entry>( |
| 213 | bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID, |
Asmitha Karunanithi | 74a1f39 | 2021-10-27 03:23:59 -0500 | [diff] [blame] | 214 | phosphor::dump::OperationStatus::InProgress, originatorId, |
| 215 | originatorType, *this))); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 216 | } |
| 217 | catch (const std::invalid_argument& e) |
| 218 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 219 | lg2::error("Error in creating system dump entry, errormsg: {ERROR}, " |
| 220 | "OBJECTPATH: {OBJECT_PATH}, ID: {ID}", |
| 221 | "ERROR", e, "OBJECT_PATH", objPath, "ID", id); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 222 | elog<InternalFailure>(); |
| 223 | return std::string(); |
| 224 | } |
| 225 | lastEntryId++; |
| 226 | return objPath.string(); |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 227 | } |
| 228 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 229 | } // namespace system |
| 230 | } // namespace dump |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 231 | } // namespace openpower |