blob: e8e89534b7725441445c7c6f462c007b06928346 [file] [log] [blame]
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05001#include "config.h"
2
3#include "dump_manager_system.hpp"
4
Dhruvaraj Subhashchandran6a54d9a2020-12-17 22:24:37 -06005#include "dump_utils.hpp"
Dhruvaraj Subhashchandranad50d422022-01-18 05:54:02 -06006#include "op_dump_consts.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05007#include "system_dump_entry.hpp"
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -05008#include "xyz/openbmc_project/Common/error.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05009
George Liu858fbb22021-07-01 12:25:44 +080010#include <fmt/core.h>
11
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050012#include <phosphor-logging/elog-errors.hpp>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050013#include <phosphor-logging/elog.hpp>
14
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060015namespace openpower
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050016{
17namespace dump
18{
19namespace system
20{
21
22using namespace phosphor::logging;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050023using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050024
Dhruvaraj Subhashchandranf37c5c32020-12-17 22:08:19 -060025void Manager::notify(uint32_t dumpId, uint64_t size)
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050026{
27
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050028 // Get the timestamp
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050029 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050030
31 // System dump can get created due to a fault in server
32 // or by request from user. A system dump by fault is
33 // first reported here, but for a user requested dump an
34 // entry will be created first with invalid source id.
35 // Since there can be only one system dump creation at a time,
36 // if there is an entry with invalid sourceId update that.
37 for (auto& entry : entries)
38 {
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060039 openpower::dump::system::Entry* sysEntry =
40 dynamic_cast<openpower::dump::system::Entry*>(entry.second.get());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050041 if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID)
42 {
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050043 sysEntry->update(timeStamp, size, dumpId);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050044 return;
45 }
46 }
47
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050048 // Get the id
49 auto id = lastEntryId + 1;
50 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050051 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050052
53 try
54 {
55 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050056 id, std::make_unique<system::Entry>(
57 bus, objPath.c_str(), id, timeStamp, size, dumpId,
58 phosphor::dump::OperationStatus::Completed, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050059 }
60 catch (const std::invalid_argument& e)
61 {
George Liu858fbb22021-07-01 12:25:44 +080062 log<level::ERR>(
63 fmt::format(
64 "Error in creating system dump entry, errormsg({}), "
65 "OBJECTPATH({}), ID({}), TIMESTAMP({}),SIZE({}), SOURCEID({})",
George Liu363af242021-07-16 17:52:36 +080066 e.what(), objPath.c_str(), id, timeStamp, size, dumpId)
George Liu858fbb22021-07-01 12:25:44 +080067 .c_str());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050068 report<InternalFailure>();
69 return;
70 }
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050071 lastEntryId++;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050072 return;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050073}
74
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050075sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -050076 Manager::createDump(phosphor::dump::DumpCreateParams params)
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050077{
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";
Andrew Geissler24e0c592021-01-19 16:47:27 -060081 constexpr auto DIAG_MOD_TARGET = "obmc-host-crash@0.target";
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050082
83 if (!params.empty())
84 {
85 log<level::WARNING>("System dump accepts no additional parameters");
86 }
87
Dhruvaraj Subhashchandran6a54d9a2020-12-17 22:24:37 -060088 using NotAllowed =
89 sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
90 using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
91
92 // Allow creating system dump only when the host is up.
93 if (!phosphor::dump::isHostRunning())
94 {
95 elog<NotAllowed>(
96 Reason("System dump can be initiated only when the host is up"));
97 return std::string();
98 }
99
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500100 auto b = sdbusplus::bus::new_default();
101 auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
102 SYSTEMD_INTERFACE, "StartUnit");
103 method.append(DIAG_MOD_TARGET); // unit to activate
104 method.append("replace");
105 bus.call_noreply(method);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500106
107 auto id = lastEntryId + 1;
108 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500109 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -0500110 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500111
112 try
113 {
114 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -0500115 id, std::make_unique<system::Entry>(
116 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
117 phosphor::dump::OperationStatus::InProgress, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500118 }
119 catch (const std::invalid_argument& e)
120 {
George Liu858fbb22021-07-01 12:25:44 +0800121 log<level::ERR>(
122 fmt::format("Error in creating system dump entry, errormsg({}), "
123 "OBJECTPATH({}), ID({})",
George Liu363af242021-07-16 17:52:36 +0800124 e.what(), objPath.c_str(), id)
George Liu858fbb22021-07-01 12:25:44 +0800125 .c_str());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500126 elog<InternalFailure>();
127 return std::string();
128 }
129 lastEntryId++;
130 return objPath.string();
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500131}
132
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500133} // namespace system
134} // namespace dump
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -0600135} // namespace openpower