-
Notifications
You must be signed in to change notification settings - Fork 3
CM: Add FRU type identification from paths #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RameshaR45
wants to merge
7
commits into
ibm-openbmc:main
Choose a base branch
from
RameshaR45:fru-detection-pr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ac97df2
OWNERS: Add Asmitha Karunanithi as owner & reviewer
asmithakarun 7dd300c
test: Fix Clang Format Issues
asmithakarun 7cdf811
Implement CM object creation on property change
asmithakarun 75512f6
Merge PR #5: Add Asmitha Karunanithi as owner & reviewer
RameshaR45 e17e741
Merge PR #6: Fix Clang Format Issues
RameshaR45 61d53ad
Merge PR #4: Implement CM object creation on property change
RameshaR45 10b1f01
CM: Add FRU type identification from paths
RameshaR45 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| catch (const std::exception& e) | ||
| { | ||
| lg2::error("Error managing CM object: {ERROR}", "ERROR", e.what()); | ||
| } | ||
| } | ||
|
|
||
| } // namespace concurrent_maintenance | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On rebasing,
cmObjectPathwill change tocurrentCMObject->getPath()