blob: 3f9d97324812032c45a2e5b6c2aba777873b8730 [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 Subhashchandran6ccb50e2020-10-29 09:33:18 -050076sdbusplus::message::object_path Manager::createDump()
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";
81 constexpr auto DIAG_MOD_TARGET = "obmc-host-diagnostic-mode@0.target";
82 auto b = sdbusplus::bus::new_default();
83 auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH,
84 SYSTEMD_INTERFACE, "StartUnit");
85 method.append(DIAG_MOD_TARGET); // unit to activate
86 method.append("replace");
87 bus.call_noreply(method);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050088
89 auto id = lastEntryId + 1;
90 auto idString = std::to_string(id);
91 auto objPath = fs::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050092 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050093
94 try
95 {
96 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050097 id, std::make_unique<system::Entry>(
98 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
99 phosphor::dump::OperationStatus::InProgress, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500100 }
101 catch (const std::invalid_argument& e)
102 {
103 log<level::ERR>(e.what());
104 log<level::ERR>("Error in creating system dump entry",
105 entry("OBJECTPATH=%s", objPath.c_str()),
106 entry("ID=%d", id));
107 elog<InternalFailure>();
108 return std::string();
109 }
110 lastEntryId++;
111 return objPath.string();
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500112}
113
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500114} // namespace system
115} // namespace dump
116} // namespace phosphor