Switch to new D-Bus interface
Now that the eStoraged interface is in phosphor-dbus-interfaces, we can
remove the yaml files from this repo and switch to the new interface in
phosphor-dbus-interfaces. Note that the new interface is slightly
different. Some functions have different arguments, and the
eStoraged-specific errors were removed.
Also, the new interface allows for the caller to specify the filesystem
type, but for now, only ext4 is supported.
Tested:
$ /usr/bin/eStoraged -b /dev/mmcblk0 &
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
/xyz/openbmc_project/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume FormatLuks ays 3 1 2 3 \
xyz.openbmc_project.Inventory.Item.Volume.FilesystemType.ext4
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
/xyz/openbmc_project/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Lock
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
/xyz/openbmc_project/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Unlock ay 3 1 2 3
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
/xyz/openbmc_project/storage/mmcblk0 \
xyz.openbmc_project.Inventory.Item.Volume Erase s \
xyz.openbmc_project.Inventory.Item.Volume.EraseMethod.VerifyGeometry
Signed-off-by: John Wedig <johnwedig@google.com>
Change-Id: I5477b313ac5342409e2cf53ca70259c17da6269c
diff --git a/src/erase/erase.cpp b/src/erase/erase.cpp
index 3b6ce17..5de96d6 100644
--- a/src/erase/erase.cpp
+++ b/src/erase/erase.cpp
@@ -6,9 +6,9 @@
#include <stdplus/fd/create.hpp>
#include <stdplus/fd/managed.hpp>
#include <stdplus/handle/managed.hpp>
-#include <xyz/openbmc_project/eStoraged/error.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
+using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
using stdplus::fd::ManagedFd;
uint64_t Erase::findSizeOfBlockDevice()
@@ -27,7 +27,7 @@
lg2::error("erase unable to open blockdev", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.DriveEraseFailure"),
"REDFISH_MESSAGE_ARGS", std::to_string(fd.get()));
- throw EraseError();
+ throw InternalFailure();
}
return bytes;
}
diff --git a/src/erase/meson.build b/src/erase/meson.build
index 3c90ab9..6aaf3a3 100644
--- a/src/erase/meson.build
+++ b/src/erase/meson.build
@@ -4,7 +4,10 @@
'erase.cpp',
include_directories : eStoraged_headers,
implicit_include_directories: false,
- dependencies: [eStoraged_dbus, dependency('stdplus'),],
+ dependencies: [
+ dependency('phosphor-dbus-interfaces'),
+ dependency('stdplus'),
+ ],
)
libeStoragedErase_dep = declare_dependency(
diff --git a/src/erase/verifyDriveGeometry.cpp b/src/erase/verifyDriveGeometry.cpp
index 2996912..ea6c76f 100644
--- a/src/erase/verifyDriveGeometry.cpp
+++ b/src/erase/verifyDriveGeometry.cpp
@@ -3,11 +3,11 @@
#include "estoraged_conf.hpp"
#include <phosphor-logging/lg2.hpp>
-#include <xyz/openbmc_project/eStoraged/error.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
#include <string>
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
+using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
void VerifyDriveGeometry::geometryOkay(uint64_t bytes)
{
@@ -18,7 +18,7 @@
"REDFISH_MESSAGE_ARGS",
std::to_string(bytes) + ">" +
std::to_string(ERASE_MAX_GEOMETRY));
- throw EraseError();
+ throw InternalFailure();
}
else if (bytes < ERASE_MIN_GEOMETRY)
{
@@ -27,7 +27,7 @@
std::string("OpenBMC.0.1.DriveEraseFailure"),
"REDFISH_MESSAGE_ARGS",
std::to_string(bytes) + "<" + std::to_string(ERASE_MIN_GEOMETRY));
- throw EraseError();
+ throw InternalFailure();
}
else
{
diff --git a/src/estoraged.cpp b/src/estoraged.cpp
index 18e4248..91a7f12 100644
--- a/src/estoraged.cpp
+++ b/src/estoraged.cpp
@@ -9,32 +9,38 @@
#include <stdlib.h>
#include <phosphor-logging/lg2.hpp>
-#include <xyz/openbmc_project/eStoraged/error.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
#include <filesystem>
#include <iostream>
#include <string_view>
#include <vector>
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
-
namespace estoraged
{
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::EncryptionError;
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::FilesystemError;
+using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+using sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound;
+using sdbusplus::xyz::openbmc_project::Common::Error::UnsupportedRequest;
-void eStoraged::format(std::vector<uint8_t> password)
+void eStoraged::formatLuks(std::vector<uint8_t> password, FilesystemType type)
{
std::string msg = "OpenBMC.0.1.DriveFormat";
lg2::info("Starting format", "REDFISH_MESSAGE_ID", msg);
+ if (type != FilesystemType::ext4)
+ {
+ lg2::error("Only ext4 filesystems are supported currently",
+ "REDFISH_MESSAGE_ID", std::string("OpenBMC.0.1.FormatFail"));
+ throw UnsupportedRequest();
+ }
+
CryptHandle cryptHandle(devPath.c_str());
if (cryptHandle.get() == nullptr)
{
lg2::error("Failed to initialize crypt device", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.FormatFail"));
- throw EncryptionError();
+ throw ResourceNotFound();
}
formatLuksDev(cryptHandle.get(), password);
@@ -44,7 +50,7 @@
mountFilesystem();
}
-void eStoraged::erase(std::vector<uint8_t>, EraseMethod inEraseMethod)
+void eStoraged::erase(EraseMethod inEraseMethod)
{
std::cerr << "Erasing encrypted eMMC" << std::endl;
lg2::info("Starting erase", "REDFISH_MESSAGE_ID",
@@ -89,7 +95,7 @@
}
}
-void eStoraged::lock(std::vector<uint8_t>)
+void eStoraged::lock()
{
std::string msg = "OpenBMC.0.1.DriveLock";
lg2::info("Starting lock", "REDFISH_MESSAGE_ID", msg);
@@ -108,7 +114,7 @@
{
lg2::error("Failed to initialize crypt device", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.UnlockFail"));
- throw EncryptionError();
+ throw ResourceNotFound();
}
activateLuksDev(cryptHandle.get(), password);
@@ -145,7 +151,7 @@
{
lg2::error("Failed to create volume key", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.FormatLuksDevFail"));
- throw EncryptionError();
+ throw InternalFailure();
}
/* Format the LUKS encrypted device. */
int retval =
@@ -157,7 +163,7 @@
lg2::error("Failed to format encrypted device: {RETVAL}", "RETVAL",
retval, "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.FormatLuksDevFail"));
- throw EncryptionError();
+ throw InternalFailure();
}
/* Device is now encrypted. */
@@ -172,7 +178,7 @@
{
lg2::error("Failed to set encryption password", "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.FormatLuksDevFail"));
- throw EncryptionError();
+ throw InternalFailure();
}
lg2::info("Encrypted device {DEV} successfully formatted", "DEV", devPath,
@@ -192,7 +198,7 @@
lg2::error("Failed to load LUKS header: {RETVAL}", "RETVAL", retval,
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.ActivateLuksDevFail"));
- throw EncryptionError();
+ throw InternalFailure();
}
retval = cryptIface->cryptActivateByPassphrase(
@@ -204,7 +210,7 @@
lg2::error("Failed to activate LUKS dev: {RETVAL}", "RETVAL", retval,
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.ActivateLuksDevFail"));
- throw EncryptionError();
+ throw InternalFailure();
}
/* Device is now unlocked. */
@@ -224,7 +230,7 @@
lg2::error("Failed to create filesystem: {RETVAL}", "RETVAL", retval,
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.CreateFilesystemFail"));
- throw FilesystemError();
+ throw InternalFailure();
}
lg2::info("Successfully created filesystem for /dev/mapper/{CONTAINER}",
"CONTAINER", containerName, "REDFISH_MESSAGE_ID",
@@ -240,7 +246,7 @@
lg2::error("Failed to create mount point: {DIR}", "DIR", mountPoint,
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.MountFilesystemFail"));
- throw FilesystemError();
+ throw InternalFailure();
}
/* Run the command to mount the filesystem. */
@@ -260,7 +266,7 @@
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.MountFilesystemFail"));
}
- throw FilesystemError();
+ throw InternalFailure();
}
lg2::info("Successfully mounted filesystem at {DIR}", "DIR", mountPoint,
@@ -276,7 +282,7 @@
lg2::error("Failed to unmount filesystem: {RETVAL}", "RETVAL", retval,
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.UnmountFilesystemFail"));
- throw FilesystemError();
+ throw InternalFailure();
}
/* Remove the mount point. */
@@ -286,7 +292,7 @@
lg2::error("Failed to remove mount point {DIR}", "DIR", mountPoint,
"REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.UnmountFilesystemFail"));
- throw FilesystemError();
+ throw InternalFailure();
}
lg2::info("Successfully unmounted filesystem at {DIR}", "DIR", mountPoint,
@@ -306,7 +312,7 @@
lg2::error("Failed to deactivate crypt device: {RETVAL}", "RETVAL",
retval, "REDFISH_MESSAGE_ID",
std::string("OpenBMC.0.1.DeactivateLuksDevFail"));
- throw EncryptionError();
+ throw InternalFailure();
}
/* Device is now locked. */
diff --git a/src/meson.build b/src/meson.build
index 1390536..a85b3bc 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -7,10 +7,10 @@
fallback: ['phosphor-logging',
'phosphor_logging_dep'],
),
- eStoraged_dbus,
dependency('openssl'),
dependency('libcryptsetup'),
dependency('stdplus'),
+ dependency('phosphor-dbus-interfaces'),
]
libeStoraged_lib = static_library(
diff --git a/src/test/erase/verifyGeometry_test.cpp b/src/test/erase/verifyGeometry_test.cpp
index 1731e75..de4d3fa 100644
--- a/src/test/erase/verifyGeometry_test.cpp
+++ b/src/test/erase/verifyGeometry_test.cpp
@@ -1,23 +1,26 @@
#include "estoraged_conf.hpp"
#include "verifyDriveGeometry.hpp"
-#include <xyz/openbmc_project/eStoraged/error.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
#include <gmock/gmock-matchers.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
+
+using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
TEST(VerifyGeometry, TooBigFail)
{
VerifyDriveGeometry maxVerify("");
- EXPECT_THROW(maxVerify.geometryOkay(ERASE_MAX_GEOMETRY + 1), EraseError);
+ EXPECT_THROW(maxVerify.geometryOkay(ERASE_MAX_GEOMETRY + 1),
+ InternalFailure);
}
TEST(VerifyGeometry, TooSmallFail)
{
VerifyDriveGeometry minVerify("");
- EXPECT_THROW(minVerify.geometryOkay(ERASE_MIN_GEOMETRY - 1), EraseError);
+ EXPECT_THROW(minVerify.geometryOkay(ERASE_MIN_GEOMETRY - 1),
+ InternalFailure);
}
TEST(VerifyGeometry, pass)
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index f293ffc..6b93a88 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -7,7 +7,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/test/sdbus_mock.hpp>
-#include <xyz/openbmc_project/eStoraged/error.hpp>
+#include <xyz/openbmc_project/Common/error.hpp>
#include <exception>
#include <filesystem>
@@ -72,8 +72,9 @@
(struct crypt_device * cd, const char* name), (override));
};
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::EncryptionError;
-using sdbusplus::xyz::openbmc_project::eStoraged::Error::FilesystemError;
+using sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
+using sdbusplus::xyz::openbmc_project::Common::Error::ResourceNotFound;
+using sdbusplus::xyz::openbmc_project::Inventory::Item::server::Volume;
using std::filesystem::path;
using ::testing::_;
using ::testing::ContainsRegex;
@@ -96,7 +97,8 @@
std::ofstream testFile;
std::unique_ptr<estoraged::eStoraged> esObject;
static constexpr auto TEST_PATH = "/test/openbmc_project/storage/test_dev";
- static constexpr auto ESTORAGED_INTERFACE = "xyz.openbmc_project.eStoraged";
+ static constexpr auto ESTORAGED_INTERFACE =
+ "xyz.openbmc_project.Inventory.Item.Volume";
sdbusplus::bus::bus bus;
std::string passwordString;
std::vector<uint8_t> password;
@@ -188,10 +190,10 @@
EXPECT_CALL(*mockCryptIface, cryptDeactivate(_, _)).Times(1);
/* Format the encrypted device. */
- esObject->format(password);
+ esObject->formatLuks(password, Volume::FilesystemType::ext4);
EXPECT_FALSE(esObject->isLocked());
- esObject->lock(password);
+ esObject->lock();
EXPECT_TRUE(esObject->isLocked());
}
@@ -201,7 +203,8 @@
/* Delete the test file. */
EXPECT_EQ(0, unlink(testFileName));
- EXPECT_THROW(esObject->format(password), EncryptionError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ ResourceNotFound);
EXPECT_FALSE(esObject->isLocked());
/* Create the test file again, so that the TearDown function works. */
@@ -216,7 +219,8 @@
EXPECT_CALL(*mockCryptIface, cryptFormat(_, _, _, _, _, _, _, _))
.WillOnce(Return(-1));
- EXPECT_THROW(esObject->format(password), EncryptionError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}
@@ -233,7 +237,8 @@
EXPECT_CALL(*mockCryptIface, cryptKeyslotAddByVolumeKey(_, _, _, _, _, _))
.WillOnce(Return(-1));
- EXPECT_THROW(esObject->format(password), EncryptionError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_TRUE(esObject->isLocked());
}
@@ -252,7 +257,8 @@
EXPECT_CALL(*mockCryptIface, cryptLoad(_, _, _)).WillOnce(Return(-1));
- EXPECT_THROW(esObject->format(password), EncryptionError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_TRUE(esObject->isLocked());
}
@@ -274,7 +280,8 @@
EXPECT_CALL(*mockCryptIface, cryptActivateByPassphrase(_, _, _, _, _, _))
.WillOnce(Return(-1));
- EXPECT_THROW(esObject->format(password), EncryptionError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_TRUE(esObject->isLocked());
}
@@ -298,7 +305,8 @@
EXPECT_CALL(*mockFsIface, runMkfs(testLuksDevName)).WillOnce(Return(-1));
- EXPECT_THROW(esObject->format(password), FilesystemError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}
@@ -325,7 +333,8 @@
EXPECT_CALL(*mockFsIface, createDirectory(path(esObject->getMountPoint())))
.WillOnce(Return(false));
- EXPECT_THROW(esObject->format(password), FilesystemError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}
@@ -360,7 +369,8 @@
EXPECT_CALL(*mockFsIface, removeDirectory(path(esObject->getMountPoint())))
.WillOnce(Return(true));
- EXPECT_THROW(esObject->format(password), FilesystemError);
+ EXPECT_THROW(esObject->formatLuks(password, Volume::FilesystemType::ext4),
+ InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}
@@ -395,10 +405,10 @@
EXPECT_CALL(*mockFsIface, doUnmount(StrEq(esObject->getMountPoint())))
.WillOnce(Return(-1));
- esObject->format(password);
+ esObject->formatLuks(password, Volume::FilesystemType::ext4);
EXPECT_FALSE(esObject->isLocked());
- EXPECT_THROW(esObject->lock(password), FilesystemError);
+ EXPECT_THROW(esObject->lock(), InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}
@@ -436,11 +446,11 @@
EXPECT_CALL(*mockFsIface, removeDirectory(path(esObject->getMountPoint())))
.WillOnce(Return(false));
- esObject->format(password);
+ esObject->formatLuks(password, Volume::FilesystemType::ext4);
EXPECT_FALSE(esObject->isLocked());
/* This will fail to remove the mount point. */
- EXPECT_THROW(esObject->lock(password), FilesystemError);
+ EXPECT_THROW(esObject->lock(), InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}
@@ -481,10 +491,10 @@
EXPECT_CALL(*mockCryptIface, cryptDeactivate(_, _)).WillOnce(Return(-1));
/* Format the encrypted device. */
- esObject->format(password);
+ esObject->formatLuks(password, Volume::FilesystemType::ext4);
EXPECT_FALSE(esObject->isLocked());
- EXPECT_THROW(esObject->lock(password), EncryptionError);
+ EXPECT_THROW(esObject->lock(), InternalFailure);
EXPECT_FALSE(esObject->isLocked());
}