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 | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
Dhruvaraj Subhashchandran | 0b566d5 | 2023-06-14 09:47:38 -0500 | [diff] [blame] | 6 | #include <sdbusplus/bus.hpp> |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 7 | #include <sdbusplus/exception.hpp> |
| 8 | |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 9 | #include <filesystem> |
Dhruvaraj Subhashchandran | 0b566d5 | 2023-06-14 09:47:38 -0500 | [diff] [blame] | 10 | #include <set> |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 11 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 12 | namespace phosphor |
| 13 | { |
| 14 | namespace dump |
| 15 | { |
| 16 | namespace ramoops |
| 17 | { |
| 18 | |
| 19 | Manager::Manager(const std::string& filePath) |
| 20 | { |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 21 | 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 Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 29 | std::vector<std::string> files; |
| 30 | files.push_back(filePath); |
| 31 | |
| 32 | createHelper(files); |
| 33 | } |
| 34 | |
| 35 | void Manager::createHelper(const std::vector<std::string>& files) |
| 36 | { |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 37 | 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 Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 49 | std::map<std::string, std::set<std::string>> mapperResponse; |
| 50 | try |
| 51 | { |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 52 | auto mapperResponseMsg = b.call(mapper); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 53 | mapperResponseMsg.read(mapperResponse); |
| 54 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 55 | catch (const sdbusplus::exception_t& e) |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 56 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 57 | lg2::error("Failed to parse dump create message, error: {ERROR}", |
| 58 | "ERROR", e); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 59 | return; |
| 60 | } |
| 61 | if (mapperResponse.empty()) |
| 62 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 63 | lg2::error("Error reading mapper response"); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 64 | return; |
| 65 | } |
| 66 | |
| 67 | const auto& host = mapperResponse.cbegin()->first; |
Patrick Williams | 78e8840 | 2023-05-10 07:50:48 -0500 | [diff] [blame] | 68 | auto m = b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, |
| 69 | "Create"); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 70 | m.append(RAMOOPS, files); |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 71 | try |
| 72 | { |
| 73 | b.call_noreply(m); |
| 74 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 75 | catch (const sdbusplus::exception_t& e) |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 76 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 77 | lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR", |
| 78 | e); |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 79 | } |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | } // namespace ramoops |
| 83 | } // namespace dump |
| 84 | } // namespace phosphor |