1 #include "config.h" 2 3 #include "dump_manager_system.hpp" 4 5 #include "system_dump_entry.hpp" 6 #include "xyz/openbmc_project/Common/error.hpp" 7 8 #include <phosphor-logging/elog-errors.hpp> 9 #include <phosphor-logging/elog.hpp> 10 11 namespace phosphor 12 { 13 namespace dump 14 { 15 namespace system 16 { 17 18 using namespace phosphor::logging; 19 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 20 21 void Manager::notify(NewDump::DumpType dumpType, uint32_t dumpId, uint64_t size) 22 { 23 24 if (dumpType != NewDump::DumpType::System) 25 { 26 log<level::ERR>("Only system dump is supported", 27 entry("DUMPTYPE=%d", dumpType)); 28 return; 29 } 30 // Get the timestamp 31 std::time_t timeStamp = std::time(nullptr); 32 33 // System dump can get created due to a fault in server 34 // or by request from user. A system dump by fault is 35 // first reported here, but for a user requested dump an 36 // entry will be created first with invalid source id. 37 // Since there can be only one system dump creation at a time, 38 // if there is an entry with invalid sourceId update that. 39 for (auto& entry : entries) 40 { 41 phosphor::dump::system::Entry* sysEntry = 42 dynamic_cast<phosphor::dump::system::Entry*>(entry.second.get()); 43 if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID) 44 { 45 sysEntry->update(timeStamp, size, dumpId); 46 return; 47 } 48 } 49 50 // Get the id 51 auto id = lastEntryId + 1; 52 auto idString = std::to_string(id); 53 auto objPath = fs::path(baseEntryPath) / idString; 54 55 try 56 { 57 entries.insert(std::make_pair( 58 id, std::make_unique<system::Entry>( 59 bus, objPath.c_str(), id, timeStamp, size, dumpId, 60 phosphor::dump::OperationStatus::Completed, *this))); 61 } 62 catch (const std::invalid_argument& e) 63 { 64 log<level::ERR>(e.what()); 65 log<level::ERR>("Error in creating system dump entry", 66 entry("OBJECTPATH=%s", objPath.c_str()), 67 entry("ID=%d", id), entry("TIMESTAMP=%ull", timeStamp), 68 entry("SIZE=%d", size), entry("SOURCEID=%d", dumpId)); 69 report<InternalFailure>(); 70 return; 71 } 72 lastEntryId++; 73 return; 74 } 75 76 sdbusplus::message::object_path Manager::createDump() 77 { 78 constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; 79 constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; 80 constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; 81 constexpr auto DIAG_MOD_TARGET = "obmc-host-diagnostic-mode@0.target"; 82 auto b = sdbusplus::bus::new_default(); 83 auto method = bus.new_method_call(SYSTEMD_SERVICE, SYSTEMD_OBJ_PATH, 84 SYSTEMD_INTERFACE, "StartUnit"); 85 method.append(DIAG_MOD_TARGET); // unit to activate 86 method.append("replace"); 87 bus.call_noreply(method); 88 89 auto id = lastEntryId + 1; 90 auto idString = std::to_string(id); 91 auto objPath = fs::path(baseEntryPath) / idString; 92 std::time_t timeStamp = std::time(nullptr); 93 94 try 95 { 96 entries.insert(std::make_pair( 97 id, std::make_unique<system::Entry>( 98 bus, objPath.c_str(), id, timeStamp, 0, INVALID_SOURCE_ID, 99 phosphor::dump::OperationStatus::InProgress, *this))); 100 } 101 catch (const std::invalid_argument& e) 102 { 103 log<level::ERR>(e.what()); 104 log<level::ERR>("Error in creating system dump entry", 105 entry("OBJECTPATH=%s", objPath.c_str()), 106 entry("ID=%d", id)); 107 elog<InternalFailure>(); 108 return std::string(); 109 } 110 lastEntryId++; 111 return objPath.string(); 112 } 113 114 } // namespace system 115 } // namespace dump 116 } // namespace phosphor 117