Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions OWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@
# data within them will be kept sorted.

owners:
- asmitk01@in.ibm.com
- pavithrabarithaya07@gmail.com

reviewers:
- asmitk01@in.ibm.com
- pavithrabarithaya07@gmail.com

openbmc:
- name: Asmitha Karunanithi
email: asmitk01@in.ibm.com
discord: asmitha
- name: Pavithra Barithaya
email: pavithrabarithaya07@gmail.com
discord: Pavithra B
40 changes: 40 additions & 0 deletions include/cm_object.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <sdbusplus/async/context.hpp>
#include <sdbusplus/bus.hpp>

#include <string>

namespace concurrent_maintenance
{

class CMObject
{
public:
CMObject(sdbusplus::async::context& ctx, const std::string& path);

CMObject(const CMObject&) = delete;
CMObject& operator=(const CMObject&) = delete;
CMObject(CMObject&&) = delete;
CMObject& operator=(CMObject&&) = delete;

~CMObject() = default;

// Get the object path
const std::string& getPath() const
{
return objectPath;
}

private:
std::string objectPath;

// TODO: Add progress interface when implementing progress tracking
// When adding the progress interface, use sdbusplus::server::object_t:
// Example:
// sdbusplus::server::object_t<xyz::openbmc_project::Common::Progress::server::Progress>
// dbusObject(bus, path.c_str(), action::defer_emit);
// Then call: dbusObject.emit_object_added();
};

} // namespace concurrent_maintenance
52 changes: 52 additions & 0 deletions include/fru_identifier.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#pragma once

#include <string>

namespace concurrent_maintenance
{

/**
* @brief FRU (Field Replaceable Unit) types supported by Concurrent
* Maintenance
*/
enum class FRUType
{
FSI, // FSI card (PCIe card with FSI interface)
BMC, // Baseboard Management Controller
SWITCHBOARD, // Switchboard
UNKNOWN // Unknown or unsupported FRU type
};

/**
* @brief Utility class to identify FRU type from inventory object path
*/
class FRUIdentifier
{
public:
/**
* @brief Parse FRU object path and identify the FRU type
*
* This API parses the inventory object path received from property change
* signals and determines whether the FRU is an FSI card, BMC, or
* Switchboard.
*
* @param objectPath The D-Bus object path from inventory manager
* Example:
* /xyz/openbmc_project/inventory/system/chassis/motherboard/fsi_card0
*
* @return FRUType The identified FRU type (FSI, BMC, SWITCHBOARD, or
* UNKNOWN)
*/
static FRUType identifyType(const std::string& objectPath);

/**
* @brief Convert FRU type enum to string representation
*
* @param type The FRU type enum value
* @return std::string String representation of the FRU type
*/
static std::string typeToString(FRUType type);
};

} // namespace concurrent_maintenance

20 changes: 20 additions & 0 deletions include/manager.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#pragma once

#include "cm_object.hpp"
#include "fru_identifier.hpp"

#include <sdbusplus/async/context.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>

#include <memory>
#include <string>

namespace concurrent_maintenance
{
Expand All @@ -19,6 +27,18 @@ class Manager

private:
sdbusplus::async::context& ctx;

// "ReadyToRemove" Property change signal match
std::unique_ptr<sdbusplus::bus::match_t> readyToRemoveMatch;

// Callback for ReadyToRemove property change
void handleReadyToRemoveChange(sdbusplus::message_t& msg);

// Create/remove CM object based on ReadyToRemove value, FRU type, and FRU path
void manageCMObject(bool readyToRemove, FRUType fruType,
const std::string& fruPath);

std::unique_ptr<CMObject> currentCMObject;
};

} // namespace concurrent_maintenance
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ inc = include_directories('include')

executable(
'ibm-concurrent-maintenance',
['src/main.cpp', 'src/manager.cpp'],
['src/main.cpp', 'src/manager.cpp', 'src/cm_object.cpp', 'src/fru_identifier.cpp'],
include_directories: inc,
dependencies: [sdbusplus_dep, phosphor_logging_dep],
install: true,
Expand Down
25 changes: 25 additions & 0 deletions src/cm_object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "cm_object.hpp"

#include <phosphor-logging/lg2.hpp>

#include <chrono>

namespace concurrent_maintenance
{

CMObject::CMObject(sdbusplus::async::context& /*ctx*/,
const std::string& path) : objectPath(path)
{
lg2::info("Creating CM object at path: {PATH}", "PATH", path);

// TODO: When implementing progress interface, create the actual D-Bus
// object here Example: auto& bus = ctx.get_bus(); dbusObject =
// std::make_unique<sdbusplus::server::object_t<...>>(
// bus, path.c_str(),
// sdbusplus::server::object_t<...>::action::defer_emit);
// dbusObject->emit_object_added();

lg2::info("CM object created at path: {PATH}", "PATH", path);
}

} // namespace concurrent_maintenance
74 changes: 74 additions & 0 deletions src/fru_identifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "fru_identifier.hpp"

#include <algorithm>
#include <cctype>

namespace concurrent_maintenance
{

FRUType FRUIdentifier::identifyType(const std::string& objectPath)
{
// Convert path to lowercase for case-insensitive matching
std::string lowerPath = objectPath;
std::transform(lowerPath.begin(), lowerPath.end(), lowerPath.begin(),
[](unsigned char c) { return std::tolower(c); });

// Check for FSI card patterns
// FSI cards typically have "fsi" in their path or are PCIe cards
// Examples:
// - /xyz/openbmc_project/inventory/system/chassis/motherboard/fsi_card0
// - /xyz/openbmc_project/inventory/system/chassis/motherboard/pcie_card1
if (lowerPath.find("fsi") != std::string::npos ||
lowerPath.find("pcie_card") != std::string::npos ||
lowerPath.find("pcie-card") != std::string::npos)
{
return FRUType::FSI;
}

// Check for BMC patterns
// BMC typically has "bmc" in its path (but not as part of "motherboard")
// Examples:
// - /xyz/openbmc_project/inventory/system/chassis/motherboard/bmc
// - /xyz/openbmc_project/inventory/system/chassis/motherboard/ebmc_card
// - /xyz/openbmc_project/inventory/system/bmc
if (lowerPath.find("/bmc") != std::string::npos ||
lowerPath.find("_bmc") != std::string::npos ||
lowerPath.find("ebmc") != std::string::npos)
{
return FRUType::BMC;
}

// Check for Switchboard patterns
// Switchboard typically has "switchboard" or "switch_board" in its path
// Examples:
// - /xyz/openbmc_project/inventory/system/chassis/switchboard0
// - /xyz/openbmc_project/inventory/system/chassis/switch_board0
if (lowerPath.find("switchboard") != std::string::npos ||
lowerPath.find("switch_board") != std::string::npos ||
lowerPath.find("switch-board") != std::string::npos)
{
return FRUType::SWITCHBOARD;
}

// If no pattern matches, return UNKNOWN
return FRUType::UNKNOWN;
}

std::string FRUIdentifier::typeToString(FRUType type)
{
switch (type)
{
case FRUType::FSI:
return "FSI";
case FRUType::BMC:
return "BMC";
case FRUType::SWITCHBOARD:
return "SWITCHBOARD";
case FRUType::UNKNOWN:
default:
return "UNKNOWN";
}
}

} // namespace concurrent_maintenance

5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/async/context.hpp>
#include <sdbusplus/server/manager.hpp>

int main()
{
sdbusplus::async::context ctx;

// Create ObjectManager for concurrent maintenance
constexpr auto objManagerPath = "/com/ibm/concurrent_maintenance";
sdbusplus::server::manager_t objManager(ctx, objManagerPath);

ctx.request_name("com.ibm.ConcurrentMaintenance");

concurrent_maintenance::Manager manager(ctx);
Expand Down
108 changes: 107 additions & 1 deletion src/manager.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,119 @@
#include "manager.hpp"
#include "fru_identifier.hpp"

#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/message.hpp>

namespace concurrent_maintenance
{

Manager::Manager(sdbusplus::async::context& ctx) : ctx(ctx)
Manager::Manager(sdbusplus::async::context& ctx) :
ctx(ctx), currentCMObject(nullptr)
{
lg2::info("Concurrent Maintenance manager initialized");

// Create property change signal match for ReadyToRemove property
// TODO:
// Currently, this will match all child objects under
// /xyz/openbmc_project/inventory and checks for "Availabile" property
// change until ReadyToRemove property is advertised. This should be changed
// to "ReadyToRemove" property change under the right interface
auto& bus = ctx.get_bus();

readyToRemoveMatch = std::make_unique<sdbusplus::bus::match_t>(
bus,
sdbusplus::bus::match::rules::propertiesChangedNamespace(
"/xyz/openbmc_project/inventory",
"xyz.openbmc_project.State.Decorator.Availability"),
[this](sdbusplus::message_t& msg) {
this->handleReadyToRemoveChange(msg);
});

lg2::info(
"ReadyToRemove property watcher registered for all inventory objects");
}

void Manager::handleReadyToRemoveChange(sdbusplus::message_t& msg)
{
std::string interface;
std::map<std::string, std::variant<bool>> changedProperties;

try
{
msg.read(interface, changedProperties);

// TODO: Change back to "ReadyToRemove" when backend is ready
// auto it = changedProperties.find("ReadyToRemove");
// Temporarily using "Available" property for testing
auto it = changedProperties.find("Available");
if (it != changedProperties.end())
{
bool readyToRemove = std::get<bool>(it->second);
std::string objectPath = msg.get_path();

// Identify FRU type from object path
FRUType fruType = FRUIdentifier::identifyType(objectPath);
std::string fruTypeStr = FRUIdentifier::typeToString(fruType);

lg2::info("ReadyToRemove property changed on {PATH}: {VALUE}, FRU Type: {TYPE}",
"PATH", objectPath, "VALUE", readyToRemove, "TYPE", fruTypeStr);

// Manage CM object based on property value and FRU type
manageCMObject(readyToRemove, fruType, objectPath);
}
}
catch (const std::exception& e)
{
lg2::error("Error handling ReadyToRemove property change: {ERROR}",
"ERROR", e.what());
}
}

void Manager::manageCMObject(bool readyToRemove, FRUType fruType,
const std::string& fruPath)
{
try
{
std::string cmObjectPath;
std::string fruTypeStr = FRUIdentifier::typeToString(fruType);

// When readyToRemove=true, the device is ready to be removed
// (create "remove" object)
// When readyToRemove=false, device has been added back
// (create "add" object)
if (readyToRemove)
{
cmObjectPath = "/com/ibm/concurrent_maintenance/remove";
}
else
{
cmObjectPath = "/com/ibm/concurrent_maintenance/add";
}

// Check if a CM object already exists
if (currentCMObject)
{
lg2::error(
"CM is already in progress. Object already exists at path: {PATH}.",
"PATH", currentCMObject->getPath());
return;
}

lg2::info("Creating CM object at path: {PATH} for FRU type: {TYPE}, FRU path: {FRUPATH}",
"PATH", cmObjectPath, "TYPE", fruTypeStr, "FRUPATH", fruPath);

// Create the actual D-Bus object
// The ObjectManager in main.cpp will automatically detect and manage it
currentCMObject = std::make_unique<CMObject>(ctx, cmObjectPath);

lg2::info("CM object created at {PATH} for {TYPE} FRU",
"PATH", cmObjectPath, "TYPE", fruTypeStr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On rebasing, cmObjectPath will change to currentCMObject->getPath()

}
catch (const std::exception& e)
{
lg2::error("Error managing CM object: {ERROR}", "ERROR", e.what());
}
}

} // namespace concurrent_maintenance
Loading