blob: 52bb956115a8899d6a16437bde08cf8ebdeff90e [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
Dhruvaraj Subhashchandranf37c5c32020-12-17 22:08:19 -060021void Manager::notify(uint32_t dumpId, uint64_t size)
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050022{
23
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050024 // Get the timestamp
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050025 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050026
27 // System dump can get created due to a fault in server
28 // or by request from user. A system dump by fault is
29 // first reported here, but for a user requested dump an
30 // entry will be created first with invalid source id.
31 // Since there can be only one system dump creation at a time,
32 // if there is an entry with invalid sourceId update that.
33 for (auto& entry : entries)
34 {
35 phosphor::dump::system::Entry* sysEntry =
36 dynamic_cast<phosphor::dump::system::Entry*>(entry.second.get());
37 if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID)
38 {
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050039 sysEntry->update(timeStamp, size, dumpId);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050040 return;
41 }
42 }
43
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050044 // Get the id
45 auto id = lastEntryId + 1;
46 auto idString = std::to_string(id);
47 auto objPath = fs::path(baseEntryPath) / idString;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050048
49 try
50 {
51 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050052 id, std::make_unique<system::Entry>(
53 bus, objPath.c_str(), id, timeStamp, size, dumpId,
54 phosphor::dump::OperationStatus::Completed, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050055 }
56 catch (const std::invalid_argument& e)
57 {
58 log<level::ERR>(e.what());
59 log<level::ERR>("Error in creating system dump entry",
60 entry("OBJECTPATH=%s", objPath.c_str()),
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050061 entry("ID=%d", id), entry("TIMESTAMP=%ull", timeStamp),
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050062 entry("SIZE=%d", size), entry("SOURCEID=%d", dumpId));
63 report<InternalFailure>();
64 return;
65 }
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050066 lastEntryId++;
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050067 return;
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050068}
69
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050070sdbusplus::message::object_path
71 Manager::createDump(std::map<std::string, std::string> params)
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050072{
73 constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
74 constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
75 constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
76 constexpr auto DIAG_MOD_TARGET = "obmc-host-diagnostic-mode@0.target";
Dhruvaraj Subhashchandran969f9a52020-10-30 01:42:39 -050077
78 if (!params.empty())
79 {
80 log<level::WARNING>("System dump accepts no additional parameters");
81 }
82
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -050083 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;
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050093 std::time_t timeStamp = std::time(nullptr);
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -050094
95 try
96 {
97 entries.insert(std::make_pair(
Dhruvaraj Subhashchandrana6ab8062020-10-29 15:29:10 -050098 id, std::make_unique<system::Entry>(
99 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID,
100 phosphor::dump::OperationStatus::InProgress, *this)));
Dhruvaraj Subhashchandran6ccb50e2020-10-29 09:33:18 -0500101 }
102 catch (const std::invalid_argument& e)
103 {
104 log<level::ERR>(e.what());
105 log<level::ERR>("Error in creating system dump entry",
106 entry("OBJECTPATH=%s", objPath.c_str()),
107 entry("ID=%d", id));
108 elog<InternalFailure>();
109 return std::string();
110 }
111 lastEntryId++;
112 return objPath.string();
Dhruvaraj Subhashchandran7040bce2020-09-16 00:50:19 -0500113}
114
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -0500115} // namespace system
116} // namespace dump
117} // namespace phosphor