blob: 37cd8f785d35bdf374ca4e57a89ff7e21190dc4a [file] [log] [blame]
Dhruvaraj Subhashchandran9e905372021-08-20 04:06:06 -05001#include "op_dump_util.hpp"
2
Dhruvaraj Subhashchandran1ddb0062022-05-06 06:21:11 -05003#include "dump_utils.hpp"
Dhruvaraj Subhashchandran9e905372021-08-20 04:06:06 -05004#include "xyz/openbmc_project/Common/error.hpp"
5#include "xyz/openbmc_project/Dump/Create/error.hpp"
6
7#include <unistd.h>
8
9#include <phosphor-logging/elog-errors.hpp>
10#include <phosphor-logging/elog.hpp>
11#include <phosphor-logging/lg2.hpp>
12
13#include <filesystem>
14
15namespace openpower
16{
17namespace dump
18{
19namespace util
20{
21
Patrick Williams8098ca62023-06-24 03:07:54 -050022bool isOPDumpsEnabled(sdbusplus::bus_t& bus)
Dhruvaraj Subhashchandran9e905372021-08-20 04:06:06 -050023{
24 // Set isEnabled as true by default. In a field deployment, the system dump
25 // feature is usually enabled to facilitate effective debugging in the event
26 // of a failure. If due to some error, the settings service couldn't provide
27 // the actual value, the system assumes that the dump is enabled.
28 // This approach aligns with the principle of collecting as much data as
29 // possible for debugging in case of a system failure.
30 auto isEnabled = true;
31
32 constexpr auto enable = "xyz.openbmc_project.Object.Enable";
33 constexpr auto policy = "/xyz/openbmc_project/dump/system_dump_policy";
34 constexpr auto property = "org.freedesktop.DBus.Properties";
35
36 try
37 {
38 auto service = phosphor::dump::getService(bus, policy, enable);
39
40 auto method = bus.new_method_call(service.c_str(), policy, property,
41 "Get");
42 method.append(enable, "Enabled");
43 auto reply = bus.call(method);
44 std::variant<bool> v;
45 reply.read(v);
46 isEnabled = std::get<bool>(v);
47 }
48 catch (const sdbusplus::exception::SdBusError& e)
49 {
50 lg2::error("Error: {ERROR} in getting dump policy, default is enabled",
51 "ERROR", e);
52 }
53 return isEnabled;
54}
55
Dhruvaraj Subhashchandran1ddb0062022-05-06 06:21:11 -050056BIOSAttrValueType readBIOSAttribute(const std::string& attrName,
Patrick Williams8098ca62023-06-24 03:07:54 -050057 sdbusplus::bus_t& bus)
Dhruvaraj Subhashchandran1ddb0062022-05-06 06:21:11 -050058{
59 std::tuple<std::string, BIOSAttrValueType, BIOSAttrValueType> attrVal;
60 auto method = bus.new_method_call(
61 "xyz.openbmc_project.BIOSConfigManager",
62 "/xyz/openbmc_project/bios_config/manager",
63 "xyz.openbmc_project.BIOSConfig.Manager", "GetAttribute");
64 method.append(attrName);
65 try
66 {
67 auto result = bus.call(method);
68 result.read(std::get<0>(attrVal), std::get<1>(attrVal),
69 std::get<2>(attrVal));
70 }
71 catch (const sdbusplus::exception::SdBusError& e)
72 {
73 lg2::error("Failed to read BIOS Attribute: {ATTRIBUTE_NAME}",
74 "ATTRIBUTE_NAME", attrName);
75 throw;
76 }
77 return std::get<1>(attrVal);
78}
79
Patrick Williams8098ca62023-06-24 03:07:54 -050080bool isSystemDumpInProgress(sdbusplus::bus_t& bus)
Dhruvaraj Subhashchandran1ddb0062022-05-06 06:21:11 -050081{
82 try
83 {
84 auto dumpInProgress = std::get<std::string>(
Dhruvaraj Subhashchandrana72daf52023-06-21 13:41:42 -050085 readBIOSAttribute("pvm_sys_dump_active", bus));
Dhruvaraj Subhashchandran1ddb0062022-05-06 06:21:11 -050086 if (dumpInProgress == "Enabled")
87 {
88 lg2::info("A system dump is already in progress");
89 return true;
90 }
91 }
92 catch (const std::bad_variant_access& ex)
93 {
94 lg2::error("Failed to read pvm_sys_dump_active property value due "
95 "to bad variant access error:{ERROR}",
96 "ERROR", ex);
97 return false;
98 }
99 catch (const std::exception& ex)
100 {
101 lg2::error("Failed to read pvm_sys_dump_active error:{ERROR}", "ERROR",
102 ex);
103 return false;
104 }
105
106 lg2::info("Another system dump is not in progress");
107 return false;
108}
109
Dhruvaraj Subhashchandran9e905372021-08-20 04:06:06 -0500110} // namespace util
111} // namespace dump
112} // namespace openpower