-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathdump_utils.cpp
193 lines (167 loc) · 6.4 KB
/
dump_utils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include "dump_utils.hpp"
#include <fmt/core.h>
#include <phosphor-logging/log.hpp>
namespace phosphor
{
namespace dump
{
using namespace phosphor::logging;
std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
const std::string& interface)
{
constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper";
constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper";
auto method = bus.new_method_call(objectMapperName, objectMapperPath,
objectMapperName, "GetObject");
method.append(path);
method.append(std::vector<std::string>({interface}));
std::vector<std::pair<std::string, std::vector<std::string>>> response;
try
{
auto reply = bus.call(method);
reply.read(response);
if (response.empty())
{
log<level::ERR>(fmt::format("Error in mapper response for getting "
"service name, PATH({}), INTERFACE({})",
path, interface)
.c_str());
return std::string{};
}
}
catch (const sdbusplus::exception::exception& e)
{
log<level::ERR>(fmt::format("Error in mapper method call, "
"errormsg({}), PATH({}), INTERFACE({})",
e.what(), path, interface)
.c_str());
return std::string{};
}
return response[0].first;
}
BootProgress getBootProgress()
{
BootProgress bootProgessStage;
constexpr auto bootProgressInterface =
"xyz.openbmc_project.State.Boot.Progress";
// TODO Need to change host instance if multiple instead "0"
constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
std::string value =
getStateValue(bootProgressInterface, hostStateObjPath, "BootProgress");
bootProgessStage = sdbusplus::xyz::openbmc_project::State::Boot::server::
Progress::convertProgressStagesFromString(value);
return bootProgessStage;
}
HostState getHostState()
{
HostState hostState;
constexpr auto hostStateInterface = "xyz.openbmc_project.State.Host";
// TODO Need to change host instance if multiple instead "0"
constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0";
std::string value =
getStateValue(hostStateInterface, hostStateObjPath, "CurrentHostState");
hostState = sdbusplus::xyz::openbmc_project::State::server::Host::
convertHostStateFromString(value);
return hostState;
}
std::string getStateValue(std::string intf, std::string objPath,
std::string state)
{
std::string stateVal;
try
{
auto bus = sdbusplus::bus::new_default();
auto service = getService(bus, objPath, intf);
auto method =
bus.new_method_call(service.c_str(), objPath.c_str(),
"org.freedesktop.DBus.Properties", "Get");
method.append(intf, state);
auto reply = bus.call(method);
using DBusValue_t =
std::variant<std::string, bool, std::vector<uint8_t>,
std::vector<std::string>>;
DBusValue_t propertyVal;
reply.read(propertyVal);
stateVal = std::get<std::string>(propertyVal);
}
catch (const sdbusplus::exception::exception& e)
{
log<level::ERR>(fmt::format("D-Bus call exception, OBJPATH({}), "
"INTERFACE({}), PROPERRT({}) EXCEPTION({})",
objPath, intf, state, e.what())
.c_str());
throw std::runtime_error("Failed to get host state property");
}
catch (const std::bad_variant_access& e)
{
log<level::ERR>(
fmt::format("Exception raised while read host state({}) property "
"value, OBJPATH({}), INTERFACE({}), EXCEPTION({})",
state, objPath, intf, e.what())
.c_str());
throw std::runtime_error("Failed to get host state property");
}
return stateVal;
}
bool isHostRunning()
{
// TODO #ibm-openbmc/dev/2858 Revisit the method for finding whether host
// is running.
BootProgress bootProgressStatus = phosphor::dump::getBootProgress();
if ((bootProgressStatus == BootProgress::SystemInitComplete) ||
(bootProgressStatus == BootProgress::SystemSetup) ||
(bootProgressStatus == BootProgress::OSStart) ||
(bootProgressStatus == BootProgress::OSRunning))
{
return true;
}
return false;
}
bool isHostQuiesced()
{
HostState hostState = phosphor::dump::getHostState();
if (hostState == HostState::Quiesced)
{
return true;
}
return false;
}
void createPEL(const std::string& dumpFilePath, const std::string& dumpFileType,
const int dumpId, const std::string& pelSev,
const std::string& errIntf)
{
try
{
constexpr auto loggerObjectPath = "/xyz/openbmc_project/logging";
constexpr auto loggerCreateInterface =
"xyz.openbmc_project.Logging.Create";
constexpr auto loggerService = "xyz.openbmc_project.Logging";
constexpr auto dumpFileString = "File Name";
constexpr auto dumpFileTypeString = "Dump Type";
constexpr auto dumpIdString = "Dump ID";
sd_bus* pBus = nullptr;
sd_bus_default(&pBus);
// Implies this is a call from Manager. Hence we need to make an async
// call to avoid deadlock with Phosphor-logging.
auto retVal = sd_bus_call_method_async(
pBus, nullptr, loggerService, loggerObjectPath,
loggerCreateInterface, "Create", nullptr, nullptr, "ssa{ss}",
errIntf.c_str(), pelSev.c_str(), 3, dumpIdString,
std::to_string(dumpId).c_str(), dumpFileString,
dumpFilePath.c_str(), dumpFileTypeString, dumpFileType.c_str());
if (retVal < 0)
{
log<level::ERR>("Error calling sd_bus_call_method_async",
entry("retVal=%d", retVal),
entry("MSG=%s", strerror(-retVal)));
}
}
catch (const std::exception& e)
{
log<level::ERR>(
"Error in calling creating PEL. Standard exception caught",
entry("ERROR=%s", e.what()));
}
}
} // namespace dump
} // namespace phosphor