blob: 5d5890da1067e0b4541244c1e96a3673d7034eda [file] [log] [blame]
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05001#include "config.h"
2
3#include "dump_manager_system.hpp"
4
5#include "system_dump_entry.hpp"
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -05006#include "xyz/openbmc_project/Common/error.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05007
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -05008#include <phosphor-logging/elog-errors.hpp>
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05009#include <phosphor-logging/elog.hpp>
10
11namespace phosphor
12{
13namespace dump
14{
15namespace system
16{
17
18using namespace phosphor::logging;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050019using namespace sdbusplus::xyz::openbmc_project::Common::Error;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050020
21void 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 Subhashchandrana6ab8062020-10-29 15:29:10 -050031 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050032
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 Subhashchandrana6ab8062020-10-29 15:29:10 -050045 sysEntry->update(timeStamp, size, dumpId);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050046 return;
47 }
48 }
49
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050050 // Get the id
51 auto id = lastEntryId + 1;
52 auto idString = std::to_string(id);
53 auto objPath = fs::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050054
55 try
56 {
57 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050058 id, std::make_unique<system::Entry>(
59 bus, objPath.c_str(), id, timeStamp, size, dumpId,
60 phosphor::dump::OperationStatus::Completed, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050061 }
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 Subhashchandrana6ab8062020-10-29 15:29:10 -050067 entry("ID=%d", id), entry("TIMESTAMP=%ull", timeStamp),
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050068 entry("SIZE=%d", size), entry("SOURCEID=%d", dumpId));
69 report<InternalFailure>();
70 return;
71 }
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050072 lastEntryId++;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050073 return;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050074}
75
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050076sdbusplus::message::object_path
77 Manager::createDump(std::map<std::string, std::string> params)
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050078{
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";
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050083
84 if (!params.empty())
85 {
86 log<level::WARNING>("System dump accepts no additional parameters");
87 }
88
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050089 auto b = sdbusplus::bus::new_default();
90 auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
91 SYSTEMD_INTERFACE, "StartUnit");
92 method.append(DIAG_MOD_TARGET); // unit to activate
93 method.append("replace");
94 bus.call_noreply(method);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050095
96 auto id = lastEntryId + 1;
97 auto idString = std::to_string(id);
98 auto objPath = fs::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050099 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500100
101 try
102 {
103 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -0500104 id, std::make_unique<system::Entry>(
105 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
106 phosphor::dump::OperationStatus::InProgress, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500107 }
108 catch (const std::invalid_argument& e)
109 {
110 log<level::ERR>(e.what());
111 log<level::ERR>("Error in creating system dump entry",
112 entry("OBJECTPATH=%s", objPath.c_str()),
113 entry("ID=%d", id));
114 elog<InternalFailure>();
115 return std::string();
116 }
117 lastEntryId++;
118 return objPath.string();
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500119}
120
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500121} // namespace system
122} // namespace dump
123} // namespace phosphor