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