1 #include "dump_utils.hpp" 2 3 #include <phosphor-logging/lg2.hpp> 4 #include <phosphor-logging/log.hpp> 5 6 namespace phosphor 7 { 8 namespace dump 9 { 10 11 using namespace phosphor::logging; 12 13 std::string getService(sdbusplus::bus_t& bus, const std::string& path, 14 const std::string& interface) 15 { 16 constexpr auto objectMapperName = "xyz.openbmc_project.ObjectMapper"; 17 constexpr auto objectMapperPath = "/xyz/openbmc_project/object_mapper"; 18 19 auto method = bus.new_method_call(objectMapperName, objectMapperPath, 20 objectMapperName, "GetObject"); 21 22 method.append(path); 23 method.append(std::vector<std::string>({interface})); 24 25 std::vector<std::pair<std::string, std::vector<std::string>>> response; 26 27 try 28 { 29 auto reply = bus.call(method); 30 reply.read(response); 31 if (response.empty()) 32 { 33 lg2::error( 34 "Error in mapper response for getting service name, PATH: " 35 "{PATH}, INTERFACE: {INTERFACE}", 36 "PATH", path, "INTERFACE", interface); 37 return std::string{}; 38 } 39 } 40 catch (const sdbusplus::exception_t& e) 41 { 42 lg2::error("Error in mapper method call, errormsg: {ERROR}, " 43 "PATH: {PATH}, INTERFACE: {INTERFACE}", 44 "ERROR", e, "PATH", path, "INTERFACE", interface); 45 return std::string{}; 46 } 47 return response[0].first; 48 } 49 50 BootProgress getBootProgress() 51 { 52 constexpr auto bootProgressInterface = 53 "xyz.openbmc_project.State.Boot.Progress"; 54 // TODO Need to change host instance if multiple instead "0" 55 constexpr auto hostStateObjPath = "/xyz/openbmc_project/state/host0"; 56 57 BootProgress bootProgessStage; 58 59 try 60 { 61 auto bus = sdbusplus::bus::new_default(); 62 auto service = getService(bus, hostStateObjPath, bootProgressInterface); 63 64 auto method = bus.new_method_call(service.c_str(), hostStateObjPath, 65 "org.freedesktop.DBus.Properties", 66 "Get"); 67 68 method.append(bootProgressInterface, "BootProgress"); 69 70 auto reply = bus.call(method); 71 72 using DBusValue_t = 73 std::variant<std::string, bool, std::vector<uint8_t>, 74 std::vector<std::string>>; 75 DBusValue_t propertyVal; 76 77 reply.read(propertyVal); 78 79 // BootProgress property type is string 80 std::string bootPgs(std::get<std::string>(propertyVal)); 81 82 bootProgessStage = sdbusplus::xyz::openbmc_project::State::Boot:: 83 server::Progress::convertProgressStagesFromString(bootPgs); 84 } 85 catch (const sdbusplus::exception_t& e) 86 { 87 lg2::error("D-Bus call exception, OBJPATH: {OBJ_PATH}, " 88 "INTERFACE: {INTERFACE}, EXCEPTION: {ERROR}", 89 "OBJ_PATH", hostStateObjPath, "INTERFACE", 90 bootProgressInterface, "ERROR", e); 91 throw std::runtime_error("Failed to get BootProgress stage"); 92 } 93 catch (const std::bad_variant_access& e) 94 { 95 lg2::error("Exception raised while read BootProgress property value, " 96 "OBJPATH: {OBJ_PATH}, INTERFACE: {INTERFACE}, " 97 "EXCEPTION: {ERROR}", 98 "OBJ_PATH", hostStateObjPath, "INTERFACE", 99 bootProgressInterface, "ERROR", e); 100 throw std::runtime_error("Failed to get BootProgress stage"); 101 } 102 103 return bootProgessStage; 104 } 105 106 bool isHostRunning() 107 { 108 // TODO #ibm-openbmc/dev/2858 Revisit the method for finding whether host 109 // is running. 110 BootProgress bootProgressStatus = phosphor::dump::getBootProgress(); 111 if ((bootProgressStatus == BootProgress::SystemInitComplete) || 112 (bootProgressStatus == BootProgress::SystemSetup) || 113 (bootProgressStatus == BootProgress::OSStart) || 114 (bootProgressStatus == BootProgress::OSRunning) || 115 (bootProgressStatus == BootProgress::PCIInit)) 116 { 117 return true; 118 } 119 return false; 120 } 121 } // namespace dump 122 } // namespace phosphor 123