| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 1 | #include "config.h" | 
|  | 2 |  | 
|  | 3 | #include "ramoops_manager.hpp" | 
|  | 4 |  | 
| Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame^] | 5 | #include "dump_manager.hpp" | 
|  | 6 |  | 
| Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/lg2.hpp> | 
| Dhruvaraj Subhashchandran | 0b566d5 | 2023-06-14 09:47:38 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 9 | #include <sdbusplus/exception.hpp> | 
| Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame^] | 10 | #include <xyz/openbmc_project/Dump/Create/common.hpp> | 
|  | 11 | #include <xyz/openbmc_project/Dump/Create/server.hpp> | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 12 |  | 
| George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 13 | #include <filesystem> | 
| Dhruvaraj Subhashchandran | 0b566d5 | 2023-06-14 09:47:38 -0500 | [diff] [blame] | 14 | #include <set> | 
| George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 15 |  | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 16 | namespace phosphor | 
|  | 17 | { | 
|  | 18 | namespace dump | 
|  | 19 | { | 
|  | 20 | namespace ramoops | 
|  | 21 | { | 
|  | 22 |  | 
|  | 23 | Manager::Manager(const std::string& filePath) | 
|  | 24 | { | 
| George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 25 | 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 Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 33 | std::vector<std::string> files; | 
|  | 34 | files.push_back(filePath); | 
|  | 35 |  | 
|  | 36 | createHelper(files); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | void Manager::createHelper(const std::vector<std::string>& files) | 
|  | 40 | { | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 41 | 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 Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame^] | 44 | constexpr auto DUMP_CREATE_IFACE = "xyz.openbmc_project.Dump.Create"; | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 45 |  | 
|  | 46 | auto b = sdbusplus::bus::new_default(); | 
|  | 47 | auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, | 
|  | 48 | MAPPER_INTERFACE, "GetObject"); | 
| Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame^] | 49 | mapper.append(BMC_DUMP_OBJPATH, std::set<std::string>({DUMP_CREATE_IFACE})); | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 50 |  | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 51 | std::map<std::string, std::set<std::string>> mapperResponse; | 
|  | 52 | try | 
|  | 53 | { | 
| George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 54 | auto mapperResponseMsg = b.call(mapper); | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 55 | mapperResponseMsg.read(mapperResponse); | 
|  | 56 | } | 
| Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 57 | catch (const sdbusplus::exception_t& e) | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 58 | { | 
| Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 59 | lg2::error("Failed to parse dump create message, error: {ERROR}", | 
|  | 60 | "ERROR", e); | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 61 | return; | 
|  | 62 | } | 
|  | 63 | if (mapperResponse.empty()) | 
|  | 64 | { | 
| Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 65 | lg2::error("Error reading mapper response"); | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 66 | return; | 
|  | 67 | } | 
|  | 68 |  | 
|  | 69 | const auto& host = mapperResponse.cbegin()->first; | 
| Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame^] | 70 | 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 Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 84 | try | 
|  | 85 | { | 
|  | 86 | b.call_noreply(m); | 
|  | 87 | } | 
| Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 88 | catch (const sdbusplus::exception_t& e) | 
| George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 89 | { | 
| Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 90 | lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR", | 
|  | 91 | e); | 
| George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 92 | } | 
| George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 93 | } | 
|  | 94 |  | 
|  | 95 | } // namespace ramoops | 
|  | 96 | } // namespace dump | 
|  | 97 | } // namespace phosphor |