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 | |
Andrew Geissler | 7d06930 | 2023-11-09 13:25:31 -0600 | [diff] [blame] | 7 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
Dhruvaraj Subhashchandran | 0b566d5 | 2023-06-14 09:47:38 -0500 | [diff] [blame] | 9 | #include <sdbusplus/bus.hpp> |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 10 | #include <sdbusplus/exception.hpp> |
Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame] | 11 | #include <xyz/openbmc_project/Dump/Create/common.hpp> |
| 12 | #include <xyz/openbmc_project/Dump/Create/server.hpp> |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 13 | |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 14 | #include <filesystem> |
Dhruvaraj Subhashchandran | 0b566d5 | 2023-06-14 09:47:38 -0500 | [diff] [blame] | 15 | #include <set> |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 16 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 17 | namespace phosphor |
| 18 | { |
| 19 | namespace dump |
| 20 | { |
| 21 | namespace ramoops |
| 22 | { |
| 23 | |
| 24 | Manager::Manager(const std::string& filePath) |
| 25 | { |
George Liu | 2a6835d | 2021-10-11 18:59:09 +0800 | [diff] [blame] | 26 | namespace fs = std::filesystem; |
| 27 | |
| 28 | fs::path dir(filePath); |
| 29 | if (!fs::exists(dir) || fs::is_empty(dir)) |
| 30 | { |
| 31 | return; |
| 32 | } |
| 33 | |
Andrew Geissler | 7d06930 | 2023-11-09 13:25:31 -0600 | [diff] [blame] | 34 | // Create error to notify user that a ramoops has been detected |
| 35 | createError(); |
| 36 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 37 | std::vector<std::string> files; |
| 38 | files.push_back(filePath); |
| 39 | |
| 40 | createHelper(files); |
| 41 | } |
| 42 | |
Andrew Geissler | 7d06930 | 2023-11-09 13:25:31 -0600 | [diff] [blame] | 43 | void Manager::createError() |
| 44 | { |
| 45 | try |
| 46 | { |
| 47 | std::map<std::string, std::string> additionalData; |
| 48 | |
| 49 | // Always add the _PID on for some extra logging debug |
| 50 | additionalData.emplace("_PID", std::to_string(getpid())); |
| 51 | |
| 52 | auto bus = sdbusplus::bus::new_default(); |
| 53 | auto method = bus.new_method_call( |
| 54 | "xyz.openbmc_project.Logging", "/xyz/openbmc_project/logging", |
| 55 | "xyz.openbmc_project.Logging.Create", "Create"); |
| 56 | |
| 57 | method.append("xyz.openbmc_project.Dump.Error.Ramoops", |
| 58 | sdbusplus::server::xyz::openbmc_project::logging::Entry:: |
| 59 | Level::Error, |
| 60 | additionalData); |
| 61 | auto resp = bus.call(method); |
| 62 | } |
| 63 | catch (const sdbusplus::exception_t& e) |
| 64 | { |
| 65 | lg2::error( |
| 66 | "sdbusplus D-Bus call exception, error {ERROR} trying to create " |
| 67 | "an error for ramoops detection", |
| 68 | "ERROR", e); |
| 69 | // This is a best-effort logging situation so don't throw anything |
| 70 | } |
| 71 | catch (const std::exception& e) |
| 72 | { |
| 73 | lg2::error("D-bus call exception: {ERROR}", "ERROR", e); |
| 74 | // This is a best-effort logging situation so don't throw anything |
| 75 | } |
| 76 | } |
| 77 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 78 | void Manager::createHelper(const std::vector<std::string>& files) |
| 79 | { |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 80 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 81 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 82 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame] | 83 | constexpr auto DUMP_CREATE_IFACE = "xyz.openbmc_project.Dump.Create"; |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 84 | |
| 85 | auto b = sdbusplus::bus::new_default(); |
| 86 | auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 87 | MAPPER_INTERFACE, "GetObject"); |
Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame] | 88 | mapper.append(BMC_DUMP_OBJPATH, std::set<std::string>({DUMP_CREATE_IFACE})); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 89 | |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 90 | std::map<std::string, std::set<std::string>> mapperResponse; |
| 91 | try |
| 92 | { |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 93 | auto mapperResponseMsg = b.call(mapper); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 94 | mapperResponseMsg.read(mapperResponse); |
| 95 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 96 | catch (const sdbusplus::exception_t& e) |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 97 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 98 | lg2::error("Failed to parse dump create message, error: {ERROR}", |
| 99 | "ERROR", e); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 100 | return; |
| 101 | } |
| 102 | if (mapperResponse.empty()) |
| 103 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 104 | lg2::error("Error reading mapper response"); |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | |
| 108 | const auto& host = mapperResponse.cbegin()->first; |
Dhruvaraj Subhashchandran | 7d7e001 | 2023-06-29 05:35:07 -0500 | [diff] [blame] | 109 | auto m = b.new_method_call(host.c_str(), BMC_DUMP_OBJPATH, |
| 110 | DUMP_CREATE_IFACE, "CreateDump"); |
| 111 | phosphor::dump::DumpCreateParams params; |
| 112 | using CreateParameters = |
| 113 | sdbusplus::common::xyz::openbmc_project::dump::Create::CreateParameters; |
| 114 | using DumpType = |
| 115 | sdbusplus::common::xyz::openbmc_project::dump::Create::DumpType; |
| 116 | using DumpIntr = sdbusplus::common::xyz::openbmc_project::dump::Create; |
| 117 | params[DumpIntr::convertCreateParametersToString( |
| 118 | CreateParameters::DumpType)] = |
| 119 | DumpIntr::convertDumpTypeToString(DumpType::Ramoops); |
| 120 | params[DumpIntr::convertCreateParametersToString( |
| 121 | CreateParameters::FilePath)] = files.front(); |
| 122 | m.append(params); |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 123 | try |
| 124 | { |
| 125 | b.call_noreply(m); |
| 126 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 127 | catch (const sdbusplus::exception_t& e) |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 128 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 129 | lg2::error("Failed to create ramoops dump, errormsg: {ERROR}", "ERROR", |
| 130 | e); |
George Liu | f4694d7 | 2021-08-16 13:49:09 +0800 | [diff] [blame] | 131 | } |
George Liu | ff92ffe | 2021-02-09 15:01:53 +0800 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | } // namespace ramoops |
| 135 | } // namespace dump |
| 136 | } // namespace phosphor |