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 | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 7 | #include "system_dump_entry.hpp" |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 8 | #include "xyz/openbmc_project/Common/error.hpp" |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 9 | |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 10 | #include <fmt/core.h> |
| 11 | |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 12 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 13 | #include <phosphor-logging/elog.hpp> |
| 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 | { |
| 27 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 28 | // Get the timestamp |
Claire Weinan | c0ab9d4 | 2022-08-17 23:01:07 -0700 | [diff] [blame] | 29 | uint64_t timeStamp = |
| 30 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 31 | std::chrono::system_clock::now().time_since_epoch()) |
| 32 | .count(); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 33 | |
| 34 | // System dump can get created due to a fault in server |
| 35 | // or by request from user. A system dump by fault is |
| 36 | // first reported here, but for a user requested dump an |
| 37 | // entry will be created first with invalid source id. |
| 38 | // Since there can be only one system dump creation at a time, |
| 39 | // if there is an entry with invalid sourceId update that. |
| 40 | for (auto& entry : entries) |
| 41 | { |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 42 | openpower::dump::system::Entry* sysEntry = |
| 43 | dynamic_cast<openpower::dump::system::Entry*>(entry.second.get()); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 44 | if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID) |
| 45 | { |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 46 | sysEntry->update(timeStamp, size, dumpId); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 47 | return; |
| 48 | } |
| 49 | } |
| 50 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 51 | // Get the id |
| 52 | auto id = lastEntryId + 1; |
| 53 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 54 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 55 | |
| 56 | try |
| 57 | { |
| 58 | entries.insert(std::make_pair( |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 59 | id, std::make_unique<system::Entry>( |
| 60 | bus, objPath.c_str(), id, timeStamp, size, dumpId, |
| 61 | phosphor::dump::OperationStatus::Completed, *this))); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 62 | } |
| 63 | catch (const std::invalid_argument& e) |
| 64 | { |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 65 | log<level::ERR>( |
| 66 | fmt::format( |
| 67 | "Error in creating system dump entry, errormsg({}), " |
| 68 | "OBJECTPATH({}), ID({}), TIMESTAMP({}),SIZE({}), SOURCEID({})", |
George Liu | 363af24 | 2021-07-16 17:52:36 +0800 | [diff] [blame] | 69 | e.what(), objPath.c_str(), id, timeStamp, size, dumpId) |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 70 | .c_str()); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 71 | report<InternalFailure>(); |
| 72 | return; |
| 73 | } |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 74 | lastEntryId++; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 75 | return; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 76 | } |
| 77 | |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 78 | sdbusplus::message::object_path |
Dhruvaraj Subhashchandran | ddc3366 | 2021-07-19 09:28:42 -0500 | [diff] [blame] | 79 | Manager::createDump(phosphor::dump::DumpCreateParams params) |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 80 | { |
| 81 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 82 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 83 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
Andrew Geissler | 24e0c59 | 2021-01-19 16:47:27 -0600 | [diff] [blame] | 84 | constexpr auto DIAG_MOD_TARGET = "obmc-host-crash@0.target"; |
Dhruvaraj Subhashchandran | 969f9a5 | 2020-10-30 01:42:39 -0500 | [diff] [blame] | 85 | |
| 86 | if (!params.empty()) |
| 87 | { |
| 88 | log<level::WARNING>("System dump accepts no additional parameters"); |
| 89 | } |
| 90 | |
Dhruvaraj Subhashchandran | 6a54d9a | 2020-12-17 22:24:37 -0600 | [diff] [blame] | 91 | using NotAllowed = |
| 92 | sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed; |
| 93 | using Reason = xyz::openbmc_project::Common::NotAllowed::REASON; |
| 94 | |
| 95 | // Allow creating system dump only when the host is up. |
| 96 | if (!phosphor::dump::isHostRunning()) |
| 97 | { |
| 98 | elog<NotAllowed>( |
| 99 | Reason("System dump can be initiated only when the host is up")); |
| 100 | return std::string(); |
| 101 | } |
| 102 | |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 103 | auto b = sdbusplus::bus::new_default(); |
| 104 | auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 105 | SYSTEMD_INTERFACE, "StartUnit"); |
| 106 | method.append(DIAG_MOD_TARGET); // unit to activate |
| 107 | method.append("replace"); |
| 108 | bus.call_noreply(method); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 109 | |
| 110 | auto id = lastEntryId + 1; |
| 111 | auto idString = std::to_string(id); |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 112 | auto objPath = std::filesystem::path(baseEntryPath) / idString; |
Claire Weinan | c0ab9d4 | 2022-08-17 23:01:07 -0700 | [diff] [blame] | 113 | uint64_t timeStamp = |
| 114 | std::chrono::duration_cast<std::chrono::microseconds>( |
| 115 | std::chrono::system_clock::now().time_since_epoch()) |
| 116 | .count(); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 117 | |
| 118 | try |
| 119 | { |
| 120 | entries.insert(std::make_pair( |
Dhruvaraj Subhashchandran | a6ab806 | 2020-10-29 15:29:10 -0500 | [diff] [blame] | 121 | id, std::make_unique<system::Entry>( |
| 122 | bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID, |
| 123 | phosphor::dump::OperationStatus::InProgress, *this))); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 124 | } |
| 125 | catch (const std::invalid_argument& e) |
| 126 | { |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 127 | log<level::ERR>( |
| 128 | fmt::format("Error in creating system dump entry, errormsg({}), " |
| 129 | "OBJECTPATH({}), ID({})", |
George Liu | 363af24 | 2021-07-16 17:52:36 +0800 | [diff] [blame] | 130 | e.what(), objPath.c_str(), id) |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 131 | .c_str()); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame] | 132 | elog<InternalFailure>(); |
| 133 | return std::string(); |
| 134 | } |
| 135 | lastEntryId++; |
| 136 | return objPath.string(); |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 137 | } |
| 138 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 139 | } // namespace system |
| 140 | } // namespace dump |
Dhruvaraj Subhashchandran | 341d683 | 2021-01-15 06:28:04 -0600 | [diff] [blame] | 141 | } // namespace openpower |