blob: 4aa30499eba6112055d9d3cdc67885c9b874839f [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
Claire Weinanc0ab9d42022-08-17 23:01:07 -070029 uint64_t timeStamp =
30 std::chrono::duration_cast<std::chrono::microseconds>(
31 std::chrono::system_clock::now().time_since_epoch())
32 .count();
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050033
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 Subhashchandran341d6832021-01-15 06:28:04 -060042 openpower::dump::system::Entry* sysEntry =
43 dynamic_cast<openpower::dump::system::Entry*>(entry.second.get());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050044 if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID)
45 {
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050046 sysEntry->update(timeStamp, size, dumpId);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050047 return;
48 }
49 }
50
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050051 // Get the id
52 auto id = lastEntryId + 1;
53 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050054 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050055
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050056 // TODO: Get the originator Id, Type from the persisted file.
57 // For now replacing it with null
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050058 try
59 {
60 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050061 id, std::make_unique<system::Entry>(
62 bus, objPath.c_str(), id, timeStamp, size, dumpId,
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050063 phosphor::dump::OperationStatus::Completed, std::string(),
64 originatorTypes::Internal, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050065 }
66 catch (const std::invalid_argument& e)
67 {
George Liu858fbb22021-07-01 12:25:44 +080068 log<level::ERR>(
69 fmt::format(
70 "Error in creating system dump entry, errormsg({}), "
71 "OBJECTPATH({}), ID({}), TIMESTAMP({}),SIZE({}), SOURCEID({})",
George Liu363af242021-07-16 17:52:36 +080072 e.what(), objPath.c_str(), id, timeStamp, size, dumpId)
George Liu858fbb22021-07-01 12:25:44 +080073 .c_str());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050074 report<InternalFailure>();
75 return;
76 }
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050077 lastEntryId++;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050078 return;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050079}
80
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050081sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -050082 Manager::createDump(phosphor::dump::DumpCreateParams params)
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050083{
84 constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
85 constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
86 constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
Andrew Geissler24e0c592021-01-19 16:47:27 -060087 constexpr auto DIAG_MOD_TARGET = "obmc-host-crash@0.target";
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050088
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050089 if (params.size() > CREATE_DUMP_MAX_PARAMS)
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050090 {
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050091 log<level::WARNING>(
92 "System dump accepts not more than 2 additional parameters");
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050093 }
94
Dhruvaraj Subhashchandran6a54d9a2020-12-17 22:24:37 -060095 using NotAllowed =
96 sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
97 using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
98
99 // Allow creating system dump only when the host is up.
100 if (!phosphor::dump::isHostRunning())
101 {
102 elog<NotAllowed>(
103 Reason("System dump can be initiated only when the host is up"));
104 return std::string();
105 }
106
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -0500107 // Get the originator id and type from params
108 std::string originatorId;
109 originatorTypes originatorType;
110
111 phosphor::dump::extractOriginatorProperties(params, originatorId,
112 originatorType);
113
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500114 auto b = sdbusplus::bus::new_default();
115 auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
116 SYSTEMD_INTERFACE, "StartUnit");
117 method.append(DIAG_MOD_TARGET); // unit to activate
118 method.append("replace");
119 bus.call_noreply(method);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500120
121 auto id = lastEntryId + 1;
122 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500123 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Claire Weinanc0ab9d42022-08-17 23:01:07 -0700124 uint64_t timeStamp =
125 std::chrono::duration_cast<std::chrono::microseconds>(
126 std::chrono::system_clock::now().time_since_epoch())
127 .count();
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500128
129 try
130 {
131 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -0500132 id, std::make_unique<system::Entry>(
133 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -0500134 phosphor::dump::OperationStatus::InProgress, originatorId,
135 originatorType, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500136 }
137 catch (const std::invalid_argument& e)
138 {
George Liu858fbb22021-07-01 12:25:44 +0800139 log<level::ERR>(
140 fmt::format("Error in creating system dump entry, errormsg({}), "
141 "OBJECTPATH({}), ID({})",
George Liu363af242021-07-16 17:52:36 +0800142 e.what(), objPath.c_str(), id)
George Liu858fbb22021-07-01 12:25:44 +0800143 .c_str());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500144 elog<InternalFailure>();
145 return std::string();
146 }
147 lastEntryId++;
148 return objPath.string();
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500149}
150
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500151} // namespace system
152} // namespace dump
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -0600153} // namespace openpower