Initial integration with Entity Manager
This commit changes eStoraged so that it doesn't take a specific device
as an argument. Instead, it looks for a config object from Entity
Manager and creates a D-Bus object corresponding to the config object.
The config objects need to expose the following interface:
"xyz.openbmc_project.Configuration.EmmcDevice"
To support more types of storage devices in the future, we can introduce
a new interface for each one.
In addition, eStoraged currently only supports 1 eMMC device. If we want
to support more than one in the future, we will need to add more
information to the Entity Manager config, to distinguish between them.
Assuming the eMMC is located on a FRU-detectable board, an "Exposes"
entry can be added to that board's Entity Manager config, for example:
{
"Name": "example_emmc",
"Type": "EmmcDevice"
}
Doing so will tell Entity Manager to create a config object with the
EmmcDevice interface mentioned above. Then, eStoraged will find the
config object with that interface and create its own D-Bus object that
can be used to manage the eMMC.
Tested:
Updated the Entity Manager config (as described above), started
eStoraged, then tested most of its methods and properties using busctl.
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume FormatLuks ays 3 1 2 3 \
xyz.openbmc_project.Inventory.Item.Volume.FilesystemType.ext4 \
--timeout=60
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Lock
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Unlock ay 3 1 2 3
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Locked
$ busctl get-property xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Drive Capacity
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Erase s \
xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.VerifyGeometry
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Erase s \
xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.LogicalOverWrite \
--timeout=1200
$ busctl call xyz.openbmc_project.eStoraged \
/xyz/openbmc_project/inventory/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Erase s \
xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.LogicalVerify \
--timeout=1200
Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: If137d02e185c366f4a1437076512b4883ba6d595
diff --git a/src/getConfig.cpp b/src/getConfig.cpp
new file mode 100644
index 0000000..1046416
--- /dev/null
+++ b/src/getConfig.cpp
@@ -0,0 +1,88 @@
+
+#include "getConfig.hpp"
+
+#include <phosphor-logging/lg2.hpp>
+#include <sdbusplus/asio/connection.hpp>
+
+#include <cstdlib>
+#include <memory>
+#include <string>
+#include <utility>
+#include <variant>
+#include <vector>
+
+namespace estoraged
+{
+
+namespace mapper
+{
+constexpr const char* busName = "xyz.openbmc_project.ObjectMapper";
+constexpr const char* path = "/xyz/openbmc_project/object_mapper";
+constexpr const char* interface = "xyz.openbmc_project.ObjectMapper";
+constexpr const char* subtree = "GetSubTree";
+} // namespace mapper
+
+using GetSubTreeType = std::vector<
+ std::pair<std::string,
+ std::vector<std::pair<std::string, std::vector<std::string>>>>>;
+
+void GetStorageConfiguration::getStorageInfo(const std::string& path,
+ const std::string& owner)
+{
+ std::shared_ptr<GetStorageConfiguration> self = shared_from_this();
+ self->dbusConnection->async_method_call(
+ [self, path, owner](
+ const boost::system::error_code ec,
+ boost::container::flat_map<std::string, BasicVariantType>& data) {
+ if (ec)
+ {
+ lg2::error("Error getting properties for {PATH}", "PATH", path,
+ "REDFISH_MESSAGE_ID",
+ std::string("OpenBMC.0.1.GetStorageInfoFail"));
+ return;
+ }
+
+ self->respData[path] = std::move(data);
+ },
+ owner, path, "org.freedesktop.DBus.Properties", "GetAll",
+ emmcConfigInterface);
+}
+
+void GetStorageConfiguration::getConfiguration()
+{
+ std::shared_ptr<GetStorageConfiguration> self = shared_from_this();
+ dbusConnection->async_method_call(
+ [self](const boost::system::error_code ec, const GetSubTreeType& ret) {
+ if (ec)
+ {
+ lg2::error("Error calling mapper");
+ return;
+ }
+ for (const auto& [objPath, objDict] : ret)
+ {
+ if (objDict.empty())
+ {
+ return;
+ }
+ const std::string& objOwner = objDict.begin()->first;
+ /* Look for the config interface exposed by this object. */
+ for (const std::string& interface : objDict.begin()->second)
+ {
+ if (interface.compare(emmcConfigInterface) == 0)
+ {
+ /* Get the properties exposed by this interface. */
+ self->getStorageInfo(objPath, objOwner);
+ }
+ }
+ }
+ },
+ mapper::busName, mapper::path, mapper::interface, mapper::subtree, "/",
+ 0, std::vector<const char*>(1, emmcConfigInterface));
+}
+
+GetStorageConfiguration::~GetStorageConfiguration()
+{
+ callback(respData);
+}
+
+} // namespace estoraged