blob: 7cc7bba18a1c47b4b4d77156ce289b6b28217774 [file] [log] [blame]
George Liuff92ffe2021-02-09 15:01:53 +08001#include "config.h"
2
3#include "ramoops_manager.hpp"
4
George Liu858fbb22021-07-01 12:25:44 +08005#include <fmt/core.h>
6
George Liuff92ffe2021-02-09 15:01:53 +08007#include <sdbusplus/exception.hpp>
8
George Liu2a6835d2021-10-11 18:59:09 +08009#include <filesystem>
10
George Liuff92ffe2021-02-09 15:01:53 +080011namespace phosphor
12{
13namespace dump
14{
15namespace ramoops
16{
17
18Manager::Manager(const std::string& filePath)
19{
George Liu2a6835d2021-10-11 18:59:09 +080020 namespace fs = std::filesystem;
21
22 fs::path dir(filePath);
23 if (!fs::exists(dir) || fs::is_empty(dir))
24 {
25 return;
26 }
27
George Liuff92ffe2021-02-09 15:01:53 +080028 std::vector<std::string> files;
29 files.push_back(filePath);
30
31 createHelper(files);
32}
33
34void Manager::createHelper(const std::vector<std::string>& files)
35{
George Liuff92ffe2021-02-09 15:01:53 +080036 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
37 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
38 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
39 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
40 constexpr auto RAMOOPS =
41 "xyz.openbmc_project.Dump.Internal.Create.Type.Ramoops";
42
43 auto b = sdbusplus::bus::new_default();
44 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
45 MAPPER_INTERFACE, "GetObject");
46 mapper.append(OBJ_INTERNAL, std::set<std::string>({IFACE_INTERNAL}));
47
George Liuff92ffe2021-02-09 15:01:53 +080048 std::map<std::string, std::set<std::string>> mapperResponse;
49 try
50 {
George Liuf4694d72021-08-16 13:49:09 +080051 auto mapperResponseMsg = b.call(mapper);
George Liuff92ffe2021-02-09 15:01:53 +080052 mapperResponseMsg.read(mapperResponse);
53 }
Patrick Williams52ac69c2021-09-02 09:37:16 -050054 catch (const sdbusplus::exception::exception& e)
George Liuff92ffe2021-02-09 15:01:53 +080055 {
56 log<level::ERR>(
George Liuf4694d72021-08-16 13:49:09 +080057 fmt::format("Failed to parse dump create message, error({})",
58 e.what())
George Liu858fbb22021-07-01 12:25:44 +080059 .c_str());
George Liuff92ffe2021-02-09 15:01:53 +080060 return;
61 }
62 if (mapperResponse.empty())
63 {
64 log<level::ERR>("Error reading mapper response");
65 return;
66 }
67
68 const auto& host = mapperResponse.cbegin()->first;
69 auto m =
70 b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create");
71 m.append(RAMOOPS, files);
George Liuf4694d72021-08-16 13:49:09 +080072 try
73 {
74 b.call_noreply(m);
75 }
Patrick Williams52ac69c2021-09-02 09:37:16 -050076 catch (const sdbusplus::exception::exception& e)
George Liuf4694d72021-08-16 13:49:09 +080077 {
78 log<level::ERR>(
79 fmt::format("Failed to create ramoops dump, errormsg({})", e.what())
80 .c_str());
81 }
George Liuff92ffe2021-02-09 15:01:53 +080082}
83
84} // namespace ramoops
85} // namespace dump
86} // namespace phosphor