blob: 891326b65172750ebf0215c5ad88289126b59e07 [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
31 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
32 std::chrono::system_clock::now().time_since_epoch())
33 .count();
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050034
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 Subhashchandranfef66a92020-09-06 13:10:59 -050052 // Get the id
53 auto id = lastEntryId + 1;
54 auto idString = std::to_string(id);
55 auto objPath = fs::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050056
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 Subhashchandranfef66a92020-09-06 13:10:59 -050073 lastEntryId++;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050074 return;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050075}
76
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050077sdbusplus::message::object_path Manager::createDump()
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";
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 Subhashchandran6ccb50e2020-10-29 09:33:18 -050089
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 Subhashchandran7040bce2020-09-16 00:50:19 -0500111}
112
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500113} // namespace system
114} // namespace dump
115} // namespace phosphor