Skip to content

Commit

Permalink
Return the object path for user requested dumps.
Browse files Browse the repository at this point in the history
Return the object path to a dump entry for the user requested
dump. A dump entry will be created when the user request for
the dump and that will be used for tracking the progress.
 The dump details like size etc  will be empty and the complete
details will be filled once the dump creation is completed.

Executed current BMC and system dump test cases on a test build
- Create BMC dump
- List All dumps
- Offload BMC dump
- Delete BMC dump
- Create manual system dump.
- Attempt to offload dump.

Signed-off-by: Dhruvaraj Subhashchandran <dhruvaraj@in.ibm.com>
Change-Id: I89b252e2731f4f1fb924d26c7ac05999341fc691
  • Loading branch information
dhruvibm authored and Jayanth Othayoth committed Dec 16, 2020
1 parent ff9c452 commit 6ccb50e
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 17 deletions.
14 changes: 14 additions & 0 deletions bmc_dump_entry.hpp
Expand Up @@ -68,6 +68,20 @@ class Entry : virtual public EntryIfaces, virtual public phosphor::dump::Entry
*/
void initiateOffload(std::string uri) override;

/** @brief Method to update an existing dump entry, once the dump creation
* is completed this function will be used to update the entry which got
* created during the dump request.
* @param[in] timeStamp - Dump creation timestamp
* @param[in] fileSize - Dump file size in bytes.
* @param[in] file - Name of dump file.
*/
void update(uint64_t timeStamp, uint64_t fileSize, const fs::path& filePath)
{
elapsed(timeStamp);
size(fileSize);
file = filePath;
}

private:
/** @Dump file name */
fs::path file;
Expand Down
67 changes: 62 additions & 5 deletions dump-extensions/openpower-dumps/dump_manager_system.cpp
Expand Up @@ -3,7 +3,9 @@
#include "dump_manager_system.hpp"

#include "system_dump_entry.hpp"
#include "xyz/openbmc_project/Common/error.hpp"

#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/elog.hpp>

namespace phosphor
Expand All @@ -14,6 +16,7 @@ namespace system
{

using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;

void Manager::notify(NewDump::DumpType dumpType, uint32_t dumpId, uint64_t size)
{
Expand All @@ -28,17 +31,50 @@ void Manager::notify(NewDump::DumpType dumpType, uint32_t dumpId, uint64_t size)
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now().time_since_epoch())
.count();

// System dump can get created due to a fault in server
// or by request from user. A system dump by fault is
// first reported here, but for a user requested dump an
// entry will be created first with invalid source id.
// Since there can be only one system dump creation at a time,
// if there is an entry with invalid sourceId update that.
for (auto& entry : entries)
{
phosphor::dump::system::Entry* sysEntry =
dynamic_cast<phosphor::dump::system::Entry*>(entry.second.get());
if (sysEntry->sourceDumpId() == INVALID_SOURCE_ID)
{
sysEntry->update(ms, size, dumpId);
return;
}
}

// Get the id
auto id = lastEntryId + 1;
auto idString = std::to_string(id);
auto objPath = fs::path(baseEntryPath) / idString;
entries.insert(std::make_pair(
id, std::make_unique<system::Entry>(bus, objPath.c_str(), id, ms, size,
dumpId, *this)));

try
{
entries.insert(std::make_pair(
id, std::make_unique<system::Entry>(bus, objPath.c_str(), id, ms,
size, dumpId, *this)));
}
catch (const std::invalid_argument& e)
{
log<level::ERR>(e.what());
log<level::ERR>("Error in creating system dump entry",
entry("OBJECTPATH=%s", objPath.c_str()),
entry("ID=%d", id), entry("TIMESTAMP=%ull", ms),
entry("SIZE=%d", size), entry("SOURCEID=%d", dumpId));
report<InternalFailure>();
return;
}
lastEntryId++;
return;
}

uint32_t Manager::createDump()
sdbusplus::message::object_path Manager::createDump()
{
constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
Expand All @@ -50,7 +86,28 @@ uint32_t Manager::createDump()
method.append(DIAG_MOD_TARGET); // unit to activate
method.append("replace");
bus.call_noreply(method);
return ++lastEntryId;

auto id = lastEntryId + 1;
auto idString = std::to_string(id);
auto objPath = fs::path(baseEntryPath) / idString;

try
{
entries.insert(std::make_pair(
id, std::make_unique<system::Entry>(bus, objPath.c_str(), id, 0, 0,
INVALID_SOURCE_ID, *this)));
}
catch (const std::invalid_argument& e)
{
log<level::ERR>(e.what());
log<level::ERR>("Error in creating system dump entry",
entry("OBJECTPATH=%s", objPath.c_str()),
entry("ID=%d", id));
elog<InternalFailure>();
return std::string();
}
lastEntryId++;
return objPath.string();
}

} // namespace system
Expand Down
8 changes: 5 additions & 3 deletions dump-extensions/openpower-dumps/dump_manager_system.hpp
Expand Up @@ -15,6 +15,7 @@ namespace dump
namespace system
{

constexpr uint32_t INVALID_SOURCE_ID = 0xFFFFFFFF;
using NotifyIface = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Dump::server::Create,
sdbusplus::xyz::openbmc_project::Dump::server::NewDump>;
Expand Down Expand Up @@ -63,11 +64,12 @@ class Manager : virtual public NotifyIface,
uint64_t size) override;

/** @brief Implementation for CreateDump
* Method to create Dump.
* Method to create a new system dump entry when user
* requests for a new system dump.
*
* @return id - The Dump entry id number.
* @return object_path - The path to the new dump entry.
*/
uint32_t createDump() override;
sdbusplus::message::object_path createDump() override;
};

} // namespace system
Expand Down
12 changes: 12 additions & 0 deletions dump-extensions/openpower-dumps/system_dump_entry.hpp
Expand Up @@ -61,6 +61,18 @@ class Entry : virtual public EntryIfaces, virtual public phosphor::dump::Entry
* @param[in] uri - URI to offload dump.
*/
void initiateOffload(std::string uri);

/** @brief Method to update an existing dump entry
* @param[in] timeStamp - Dump creation timestamp
* @param[in] dumpSize - Dump size in bytes.
* @param[in] sourceId - DumpId provided by the source.
*/
void update(uint64_t timeStamp, uint64_t dumpSize, const uint32_t sourceId)
{
elapsed(timeStamp);
size(dumpSize);
sourceDumpId(sourceId);
}
};

} // namespace system
Expand Down
48 changes: 42 additions & 6 deletions dump_manager_bmc.cpp
Expand Up @@ -34,10 +34,30 @@ void Manager::create(Type type, std::vector<std::string> fullPaths)

} // namespace internal

uint32_t Manager::createDump()
sdbusplus::message::object_path Manager::createDump()
{
std::vector<std::string> paths;
return captureDump(Type::UserRequested, paths);
auto id = captureDump(Type::UserRequested, paths);

// Entry Object path.
auto objPath = fs::path(baseEntryPath) / std::to_string(id);

try
{
entries.insert(std::make_pair(
id, std::make_unique<bmc::Entry>(bus, objPath.c_str(), id, 0, 0,
std::string(), *this)));
}
catch (const std::invalid_argument& e)
{
log<level::ERR>(e.what());
log<level::ERR>("Error in creating dump entry",
entry("OBJECTPATH=%s", objPath.c_str()),
entry("ID=%d", id));
elog<InternalFailure>();
}

return objPath.string();
}

uint32_t Manager::captureDump(Type type,
Expand Down Expand Up @@ -110,12 +130,22 @@ void Manager::createEntry(const fs::path& file)
auto idString = match[ID_POS];
auto msString = match[EPOCHTIME_POS];

try
auto id = stoul(idString);

// If there is an existing entry update it and return.
auto dumpEntry = entries.find(id);
if (dumpEntry != entries.end())
{
auto id = stoul(idString);
// Entry Object path.
auto objPath = fs::path(baseEntryPath) / std::to_string(id);
dynamic_cast<phosphor::dump::bmc::Entry*>(dumpEntry->second.get())
->update(stoull(msString), fs::file_size(file), file);
return;
}

// Entry Object path.
auto objPath = fs::path(baseEntryPath) / std::to_string(id);

try
{
entries.insert(
std::make_pair(id, std::make_unique<bmc::Entry>(
bus, objPath.c_str(), id, stoull(msString),
Expand All @@ -124,6 +154,12 @@ void Manager::createEntry(const fs::path& file)
catch (const std::invalid_argument& e)
{
log<level::ERR>(e.what());
log<level::ERR>("Error in creating dump entry",
entry("OBJECTPATH=%s", objPath.c_str()),
entry("ID=%d", id),
entry("TIMESTAMP=%ull", stoull(msString)),
entry("SIZE=%d", fs::file_size(file)),
entry("FILENAME=%s", file.c_str()));
return;
}
}
Expand Down
6 changes: 3 additions & 3 deletions dump_manager_bmc.hpp
Expand Up @@ -90,11 +90,11 @@ class Manager : virtual public CreateIface,
void restore() override;

/** @brief Implementation for CreateDump
* Method to create Dump.
* Method to create a BMC dump entry when user requests for a new BMC dump
*
* @return id - The Dump entry id number.
* @return object_path - The object path of the new dump entry.
*/
uint32_t createDump() override;
sdbusplus::message::object_path createDump() override;

private:
/** @brief Create Dump entry d-bus object
Expand Down

0 comments on commit 6ccb50e

Please sign in to comment.