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