George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "ramoops_manager.hpp" |
| 4 | |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 5 | #include <fmt/core.h> |
| 6 | |
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> |
| 10 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 11 | namespace phosphor |
| 12 | { |
| 13 | namespace dump |
| 14 | { |
| 15 | namespace ramoops |
| 16 | { |
| 17 | |
| 18 | Manager::Manager(const std::string& filePath) |
| 19 | { |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 20 | 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 Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 28 | std::vector<std::string> files; |
| 29 | files.push_back(filePath); |
| 30 | |
| 31 | createHelper(files); |
| 32 | } |
| 33 | |
| 34 | void Manager::createHelper(const std::vector<std::string>& files) |
| 35 | { |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 36 | 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 Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 48 | std::map<std::string, std::set<std::string>> mapperResponse; |
| 49 | try |
| 50 | { |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 51 | auto mapperResponseMsg = b.call(mapper); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 52 | mapperResponseMsg.read(mapperResponse); |
| 53 | } |
Patrick Williams | 52ac69c | 2021-09-02 09:37:16 -0500 | [diff] [blame] | 54 | catch (const sdbusplus::exception::exception& e) |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 55 | { |
| 56 | log<level::ERR>( |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 57 | fmt::format("Failed to parse dump create message, error({})", |
| 58 | e.what()) |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 59 | .c_str()); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 60 | 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 Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 72 | try |
| 73 | { |
| 74 | b.call_noreply(m); |
| 75 | } |
Patrick Williams | 52ac69c | 2021-09-02 09:37:16 -0500 | [diff] [blame] | 76 | catch (const sdbusplus::exception::exception& e) |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 77 | { |
| 78 | log<level::ERR>( |
| 79 | fmt::format("Failed to create ramoops dump, errormsg({})", e.what()) |
| 80 | .c_str()); |
| 81 | } |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | } // namespace ramoops |
| 85 | } // namespace dump |
| 86 | } // namespace phosphor |