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 |
| 31 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 32 | std::chrono::system_clock::now().time_since_epoch()) |
| 33 | .count(); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame^] | 34 | |
| 35 | // System dump can get created due to a fault in server |
| 36 | // or by request from user. A system dump by fault is |
| 37 | // first reported here, but for a user requested dump an |
| 38 | // entry will be created first with invalid source id. |
| 39 | // Since there can be only one system dump creation at a time, |
| 40 | // if there is an entry with invalid sourceId update that. |
| 41 | for (auto& entry : entries) |
| 42 | { |
| 43 | phosphor::dump::system::Entry* sysEntry = |
| 44 | dynamic_cast<phosphor::dump::system::Entry*>(entry.second.get()); |
| 45 | if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID) |
| 46 | { |
| 47 | sysEntry->update(ms, size, dumpId); |
| 48 | return; |
| 49 | } |
| 50 | } |
| 51 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 52 | // Get the id |
| 53 | auto id = lastEntryId + 1; |
| 54 | auto idString = std::to_string(id); |
| 55 | auto objPath = fs::path(baseEntryPath) / idString; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame^] | 56 | |
| 57 | try |
| 58 | { |
| 59 | entries.insert(std::make_pair( |
| 60 | id, std::make_unique<system::Entry>(bus, objPath.c_str(), id, ms, |
| 61 | size, dumpId, *this))); |
| 62 | } |
| 63 | catch (const std::invalid_argument& e) |
| 64 | { |
| 65 | log<level::ERR>(e.what()); |
| 66 | log<level::ERR>("Error in creating system dump entry", |
| 67 | entry("OBJECTPATH=%s", objPath.c_str()), |
| 68 | entry("ID=%d", id), entry("TIMESTAMP=%ull", ms), |
| 69 | entry("SIZE=%d", size), entry("SOURCEID=%d", dumpId)); |
| 70 | report<InternalFailure>(); |
| 71 | return; |
| 72 | } |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 73 | lastEntryId++; |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame^] | 74 | return; |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 75 | } |
| 76 | |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame^] | 77 | sdbusplus::message::object_path Manager::createDump() |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 78 | { |
| 79 | constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; |
| 80 | constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; |
| 81 | constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; |
| 82 | constexpr auto DIAG_MOD_TARGET = "obmc-host-diagnostic-mode@0.target"; |
| 83 | auto b = sdbusplus::bus::new_default(); |
| 84 | auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, |
| 85 | SYSTEMD_INTERFACE, "StartUnit"); |
| 86 | method.append(DIAG_MOD_TARGET); // unit to activate |
| 87 | method.append("replace"); |
| 88 | bus.call_noreply(method); |
Dhruvaraj Subhashchandran | 6ccb50e | 2020-10-29 09:33:18 -0500 | [diff] [blame^] | 89 | |
| 90 | auto id = lastEntryId + 1; |
| 91 | auto idString = std::to_string(id); |
| 92 | auto objPath = fs::path(baseEntryPath) / idString; |
| 93 | |
| 94 | try |
| 95 | { |
| 96 | entries.insert(std::make_pair( |
| 97 | id, std::make_unique<system::Entry>(bus, objPath.c_str(), id, 0, 0, |
| 98 | INVALID_SOURCE_ID, *this))); |
| 99 | } |
| 100 | catch (const std::invalid_argument& e) |
| 101 | { |
| 102 | log<level::ERR>(e.what()); |
| 103 | log<level::ERR>("Error in creating system dump entry", |
| 104 | entry("OBJECTPATH=%s", objPath.c_str()), |
| 105 | entry("ID=%d", id)); |
| 106 | elog<InternalFailure>(); |
| 107 | return std::string(); |
| 108 | } |
| 109 | lastEntryId++; |
| 110 | return objPath.string(); |
Dhruvaraj Subhashchandran | 7040bce | 2020-09-16 00:50:19 -0500 | [diff] [blame] | 111 | } |
| 112 | |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 113 | } // namespace system |
| 114 | } // namespace dump |
| 115 | } // namespace phosphor |