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