blob: a3df8373fd9a6159a0df9bbafb94a39abb186b32 [file] [log] [blame]
George Liuff92ffe2021-02-09 15:01:53 +08001#include "config.h"
2
3#include "ramoops_manager.hpp"
4
Dhruvaraj Subhashchandran7d7e0012023-06-29 05:35:07 -05005#include "dump_manager.hpp"
6
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05007#include <phosphor-logging/lg2.hpp>
Dhruvaraj Subhashchandran0b566d52023-06-14 09:47:38 -05008#include <sdbusplus/bus.hpp>
George Liuff92ffe2021-02-09 15:01:53 +08009#include <sdbusplus/exception.hpp>
Dhruvaraj Subhashchandran7d7e0012023-06-29 05:35:07 -050010#include <xyz/openbmc_project/Dump/Create/common.hpp>
11#include <xyz/openbmc_project/Dump/Create/server.hpp>
George Liuff92ffe2021-02-09 15:01:53 +080012
George Liu2a6835d2021-10-11 18:59:09 +080013#include <filesystem>
Dhruvaraj Subhashchandran0b566d52023-06-14 09:47:38 -050014#include <set>
George Liu2a6835d2021-10-11 18:59:09 +080015
George Liuff92ffe2021-02-09 15:01:53 +080016namespace phosphor
17{
18namespace dump
19{
20namespace ramoops
21{
22
23Manager::Manager(const std::string& filePath)
24{
George Liu2a6835d2021-10-11 18:59:09 +080025 namespace fs = std::filesystem;
26
27 fs::path dir(filePath);
28 if (!fs::exists(dir) || fs::is_empty(dir))
29 {
30 return;
31 }
32
George Liuff92ffe2021-02-09 15:01:53 +080033 std::vector<std::string> files;
34 files.push_back(filePath);
35
36 createHelper(files);
37}
38
39void Manager::createHelper(const std::vector<std::string>& files)
40{
George Liuff92ffe2021-02-09 15:01:53 +080041 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
42 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
43 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
Dhruvaraj Subhashchandran7d7e0012023-06-29 05:35:07 -050044 constexpr auto DUMP_CREATE_IFACE = "xyz.openbmc_project.Dump.Create";
George Liuff92ffe2021-02-09 15:01:53 +080045
46 auto b = sdbusplus::bus::new_default();
47 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
48 MAPPER_INTERFACE, "GetObject");
Dhruvaraj Subhashchandran7d7e0012023-06-29 05:35:07 -050049 mapper.append(BMC_DUMP_OBJPATH, std::set<std::string>({DUMP_CREATE_IFACE}));
George Liuff92ffe2021-02-09 15:01:53 +080050
George Liuff92ffe2021-02-09 15:01:53 +080051 std::map<std::string, std::set<std::string>> mapperResponse;
52 try
53 {
George Liuf4694d72021-08-16 13:49:09 +080054 auto mapperResponseMsg = b.call(mapper);
George Liuff92ffe2021-02-09 15:01:53 +080055 mapperResponseMsg.read(mapperResponse);
56 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050057 catch (const sdbusplus::exception_t& e)
George Liuff92ffe2021-02-09 15:01:53 +080058 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050059 lg2::error("Failed to parse dump create message, error: {ERROR}",
60 "ERROR", e);
George Liuff92ffe2021-02-09 15:01:53 +080061 return;
62 }
63 if (mapperResponse.empty())
64 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050065 lg2::error("Error reading mapper response");
George Liuff92ffe2021-02-09 15:01:53 +080066 return;
67 }
68
69 const auto& host = mapperResponse.cbegin()->first;
Dhruvaraj Subhashchandran7d7e0012023-06-29 05:35:07 -050070 auto m = b.new_method_call(host.c_str(), BMC_DUMP_OBJPATH,
71 DUMP_CREATE_IFACE, "CreateDump");
72 phosphor::dump::DumpCreateParams params;
73 using CreateParameters =
74 sdbusplus::common::xyz::openbmc_project::dump::Create::CreateParameters;
75 using DumpType =
76 sdbusplus::common::xyz::openbmc_project::dump::Create::DumpType;
77 using DumpIntr = sdbusplus::common::xyz::openbmc_project::dump::Create;
78 params[DumpIntr::convertCreateParametersToString(
79 CreateParameters::DumpType)] =
80 DumpIntr::convertDumpTypeToString(DumpType::Ramoops);
81 params[DumpIntr::convertCreateParametersToString(
82 CreateParameters::FilePath)] = files.front();
83 m.append(params);
George Liuf4694d72021-08-16 13:49:09 +080084 try
85 {
86 b.call_noreply(m);
87 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050088 catch (const sdbusplus::exception_t& e)
George Liuf4694d72021-08-16 13:49:09 +080089 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050090 lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR",
91 e);
George Liuf4694d72021-08-16 13:49:09 +080092 }
George Liuff92ffe2021-02-09 15:01:53 +080093}
94
95} // namespace ramoops
96} // namespace dump
97} // namespace phosphor