blob: 321f90fdeb1eff437fce1627b2940cf5e3753d6d [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>
Dhruvaraj Subhashchandran0b566d52023-06-14 09:47:38 -05006#include <sdbusplus/bus.hpp>
George Liuff92ffe2021-02-09 15:01:53 +08007#include <sdbusplus/exception.hpp>
8
George Liu2a6835d2021-10-11 18:59:09 +08009#include <filesystem>
Dhruvaraj Subhashchandran0b566d52023-06-14 09:47:38 -050010#include <set>
George Liu2a6835d2021-10-11 18:59:09 +080011
George Liuff92ffe2021-02-09 15:01:53 +080012namespace phosphor
13{
14namespace dump
15{
16namespace ramoops
17{
18
19Manager::Manager(const std::string& filePath)
20{
George Liu2a6835d2021-10-11 18:59:09 +080021 namespace fs = std::filesystem;
22
23 fs::path dir(filePath);
24 if (!fs::exists(dir) || fs::is_empty(dir))
25 {
26 return;
27 }
28
George Liuff92ffe2021-02-09 15:01:53 +080029 std::vector<std::string> files;
30 files.push_back(filePath);
31
32 createHelper(files);
33}
34
35void Manager::createHelper(const std::vector<std::string>& files)
36{
George Liuff92ffe2021-02-09 15:01:53 +080037 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
38 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
39 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
40 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
41 constexpr auto RAMOOPS =
42 "xyz.openbmc_project.Dump.Internal.Create.Type.Ramoops";
43
44 auto b = sdbusplus::bus::new_default();
45 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
46 MAPPER_INTERFACE, "GetObject");
47 mapper.append(OBJ_INTERNAL, std::set<std::string>({IFACE_INTERNAL}));
48
George Liuff92ffe2021-02-09 15:01:53 +080049 std::map<std::string, std::set<std::string>> mapperResponse;
50 try
51 {
George Liuf4694d72021-08-16 13:49:09 +080052 auto mapperResponseMsg = b.call(mapper);
George Liuff92ffe2021-02-09 15:01:53 +080053 mapperResponseMsg.read(mapperResponse);
54 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050055 catch (const sdbusplus::exception_t& e)
George Liuff92ffe2021-02-09 15:01:53 +080056 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050057 lg2::error("Failed to parse dump create message, error: {ERROR}",
58 "ERROR", e);
George Liuff92ffe2021-02-09 15:01:53 +080059 return;
60 }
61 if (mapperResponse.empty())
62 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050063 lg2::error("Error reading mapper response");
George Liuff92ffe2021-02-09 15:01:53 +080064 return;
65 }
66
67 const auto& host = mapperResponse.cbegin()->first;
Patrick Williams78e88402023-05-10 07:50:48 -050068 auto m = b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL,
69 "Create");
George Liuff92ffe2021-02-09 15:01:53 +080070 m.append(RAMOOPS, files);
George Liuf4694d72021-08-16 13:49:09 +080071 try
72 {
73 b.call_noreply(m);
74 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050075 catch (const sdbusplus::exception_t& e)
George Liuf4694d72021-08-16 13:49:09 +080076 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050077 lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR",
78 e);
George Liuf4694d72021-08-16 13:49:09 +080079 }
George Liuff92ffe2021-02-09 15:01:53 +080080}
81
82} // namespace ramoops
83} // namespace dump
84} // namespace phosphor