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