forked from ibm-openbmc/phosphor-debug-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ramoops_manager.cpp
86 lines (72 loc) · 2.17 KB
/
ramoops_manager.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
#include "config.h"
#include "ramoops_manager.hpp"
#include <fmt/core.h>
#include <sdbusplus/exception.hpp>
#include <filesystem>
namespace phosphor
{
namespace dump
{
namespace ramoops
{
Manager::Manager(const std::string& filePath)
{
namespace fs = std::filesystem;
fs::path dir(filePath);
if (!fs::exists(dir) || fs::is_empty(dir))
{
return;
}
std::vector<std::string> files;
files.push_back(filePath);
createHelper(files);
}
void Manager::createHelper(const std::vector<std::string>& files)
{
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
constexpr auto RAMOOPS =
"xyz.openbmc_project.Dump.Internal.Create.Type.Ramoops";
auto b = sdbusplus::bus::new_default();
auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_INTERFACE, "GetObject");
mapper.append(OBJ_INTERNAL, std::set<std::string>({IFACE_INTERNAL}));
std::map<std::string, std::set<std::string>> mapperResponse;
try
{
auto mapperResponseMsg = b.call(mapper);
mapperResponseMsg.read(mapperResponse);
}
catch (const sdbusplus::exception::exception& e)
{
log<level::ERR>(
fmt::format("Failed to parse dump create message, error({})",
e.what())
.c_str());
return;
}
if (mapperResponse.empty())
{
log<level::ERR>("Error reading mapper response");
return;
}
const auto& host = mapperResponse.cbegin()->first;
auto m =
b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create");
m.append(RAMOOPS, files);
try
{
b.call_noreply(m);
}
catch (const sdbusplus::exception::exception& e)
{
log<level::ERR>(
fmt::format("Failed to create ramoops dump, errormsg({})", e.what())
.c_str());
}
}
} // namespace ramoops
} // namespace dump
} // namespace phosphor