blob: af8972a2272e628d5f7aac61396dfe89a9299a1e [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
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050010#include <phosphor-logging/elog-errors.hpp>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050011#include <phosphor-logging/elog.hpp>
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050012#include <phosphor-logging/lg2.hpp>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050013
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060014namespace openpower
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050015{
16namespace dump
17{
18namespace system
19{
20
21using namespace phosphor::logging;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050022using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050023
Dhruvaraj Subhashchandranf37c5c32020-12-17 22:08:19 -060024void Manager::notify(uint32_t dumpId, uint64_t size)
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050025{
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050026 // Get the timestamp
Claire Weinanc0ab9d42022-08-17 23:01:07 -070027 uint64_t timeStamp =
28 std::chrono::duration_cast<std::chrono::microseconds>(
29 std::chrono::system_clock::now().time_since_epoch())
30 .count();
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050031
32 // System dump can get created due to a fault in server
33 // or by request from user. A system dump by fault is
34 // first reported here, but for a user requested dump an
35 // entry will be created first with invalid source id.
36 // Since there can be only one system dump creation at a time,
37 // if there is an entry with invalid sourceId update that.
38 for (auto& entry : entries)
39 {
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -060040 openpower::dump::system::Entry* sysEntry =
41 dynamic_cast<openpower::dump::system::Entry*>(entry.second.get());
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050042 if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID)
43 {
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050044 sysEntry->update(timeStamp, size, dumpId);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050045 return;
46 }
47 }
48
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050049 // Get the id
50 auto id = lastEntryId + 1;
51 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050052 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050053
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050054 // TODO: Get the originator Id, Type from the persisted file.
55 // For now replacing it with null
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050056 try
57 {
58 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050059 id, std::make_unique<system::Entry>(
60 bus, objPath.c_str(), id, timeStamp, size, dumpId,
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050061 phosphor::dump::OperationStatus::Completed, std::string(),
62 originatorTypes::Internal, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050063 }
64 catch (const std::invalid_argument& e)
65 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050066 lg2::error(
67 "Error in creating system dump entry, errormsg: {ERROR}, "
68 "OBJECTPATH: {OBJECT_PATH}, ID: {ID}, TIMESTAMP: {TIMESTAMP}, "
69 "SIZE: {SIZE}, SOURCEID: {SOURCE_ID}",
70 "ERROR", e, "OBJECT_PATH", objPath, "ID", id, "TIMESTAMP",
71 timeStamp, "SIZE", size, "SOURCE_ID", dumpId);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050072 report<InternalFailure>();
73 return;
74 }
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050075 lastEntryId++;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050076 return;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050077}
78
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050079sdbusplus::message::object_path
Dhruvaraj Subhashchandranddc33662021-07-19 09:28:42 -050080 Manager::createDump(phosphor::dump::DumpCreateParams params)
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050081{
82 constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
83 constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
84 constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
Andrew Geissler24e0c592021-01-19 16:47:27 -060085 constexpr auto DIAG_MOD_TARGET = "obmc-host-crash@0.target";
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050086
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050087 if (params.size() > CREATE_DUMP_MAX_PARAMS)
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050088 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050089 lg2::warning(
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -050090 "System dump accepts not more than 2 additional parameters");
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050091 }
92
Dhruvaraj Subhashchandran6a54d9a2020-12-17 22:24:37 -060093 using NotAllowed =
94 sdbusplus::xyz::openbmc_project::Common::Error::NotAllowed;
95 using Reason = xyz::openbmc_project::Common::NotAllowed::REASON;
96
97 // Allow creating system dump only when the host is up.
98 if (!phosphor::dump::isHostRunning())
99 {
100 elog<NotAllowed>(
101 Reason("System dump can be initiated only when the host is up"));
102 return std::string();
103 }
104
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -0500105 // Get the originator id and type from params
106 std::string originatorId;
107 originatorTypes originatorType;
108
109 phosphor::dump::extractOriginatorProperties(params, originatorId,
110 originatorType);
111
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500112 auto b = sdbusplus::bus::new_default();
113 auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
114 SYSTEMD_INTERFACE, "StartUnit");
115 method.append(DIAG_MOD_TARGET); // unit to activate
116 method.append("replace");
117 bus.call_noreply(method);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500118
119 auto id = lastEntryId + 1;
120 auto idString = std::to_string(id);
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -0500121 auto objPath = std::filesystem::path(baseEntryPath) / idString;
Claire Weinanc0ab9d42022-08-17 23:01:07 -0700122 uint64_t timeStamp =
123 std::chrono::duration_cast<std::chrono::microseconds>(
124 std::chrono::system_clock::now().time_since_epoch())
125 .count();
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500126
127 try
128 {
129 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -0500130 id, std::make_unique<system::Entry>(
131 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
Asmitha Karunanithi74a1f392021-10-27 03:23:59 -0500132 phosphor::dump::OperationStatus::InProgress, originatorId,
133 originatorType, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500134 }
135 catch (const std::invalid_argument& e)
136 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -0500137 lg2::error("Error in creating system dump entry, errormsg: {ERROR}, "
138 "OBJECTPATH: {OBJECT_PATH}, ID: {ID}",
139 "ERROR", e, "OBJECT_PATH", objPath, "ID", id);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500140 elog<InternalFailure>();
141 return std::string();
142 }
143 lastEntryId++;
144 return objPath.string();
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500145}
146
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500147} // namespace system
148} // namespace dump
Dhruvaraj Subhashchandran341d6832021-01-15 06:28:04 -0600149} // namespace openpower