blob: 05add0dd771f29ddbe336328c0f1cf1ddfd9787c [file] [log] [blame]
George Liuff92ffe2021-02-09 15:01:53 +08001#include "config.h"
2
3#include "ramoops_manager.hpp"
4
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05005#include <phosphor-logging/lg2.hpp>
George Liuff92ffe2021-02-09 15:01:53 +08006#include <sdbusplus/exception.hpp>
7
George Liu2a6835d2021-10-11 18:59:09 +08008#include <filesystem>
9
George Liuff92ffe2021-02-09 15:01:53 +080010namespace phosphor
11{
12namespace dump
13{
14namespace ramoops
15{
16
17Manager::Manager(const std::string& filePath)
18{
George Liu2a6835d2021-10-11 18:59:09 +080019 namespace fs = std::filesystem;
20
21 fs::path dir(filePath);
22 if (!fs::exists(dir) || fs::is_empty(dir))
23 {
24 return;
25 }
26
George Liuff92ffe2021-02-09 15:01:53 +080027 std::vector<std::string> files;
28 files.push_back(filePath);
29
30 createHelper(files);
31}
32
33void Manager::createHelper(const std::vector<std::string>& files)
34{
George Liuff92ffe2021-02-09 15:01:53 +080035 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
36 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
37 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
38 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
39 constexpr auto RAMOOPS =
40 "xyz.openbmc_project.Dump.Internal.Create.Type.Ramoops";
41
42 auto b = sdbusplus::bus::new_default();
43 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
44 MAPPER_INTERFACE, "GetObject");
45 mapper.append(OBJ_INTERNAL, std::set<std::string>({IFACE_INTERNAL}));
46
George Liuff92ffe2021-02-09 15:01:53 +080047 std::map<std::string, std::set<std::string>> mapperResponse;
48 try
49 {
George Liuf4694d72021-08-16 13:49:09 +080050 auto mapperResponseMsg = b.call(mapper);
George Liuff92ffe2021-02-09 15:01:53 +080051 mapperResponseMsg.read(mapperResponse);
52 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050053 catch (const sdbusplus::exception_t& e)
George Liuff92ffe2021-02-09 15:01:53 +080054 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050055 lg2::error("Failed to parse dump create message, error: {ERROR}",
56 "ERROR", e);
George Liuff92ffe2021-02-09 15:01:53 +080057 return;
58 }
59 if (mapperResponse.empty())
60 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050061 lg2::error("Error reading mapper response");
George Liuff92ffe2021-02-09 15:01:53 +080062 return;
63 }
64
65 const auto& host = mapperResponse.cbegin()->first;
Patrick Williams78e88402023-05-10 07:50:48 -050066 auto m = b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL,
67 "Create");
George Liuff92ffe2021-02-09 15:01:53 +080068 m.append(RAMOOPS, files);
George Liuf4694d72021-08-16 13:49:09 +080069 try
70 {
71 b.call_noreply(m);
72 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050073 catch (const sdbusplus::exception_t& e)
George Liuf4694d72021-08-16 13:49:09 +080074 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050075 lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR",
76 e);
George Liuf4694d72021-08-16 13:49:09 +080077 }
George Liuff92ffe2021-02-09 15:01:53 +080078}
79
80} // namespace ramoops
81} // namespace dump
82} // namespace phosphor