Add Erase verifyGeometry
This confirms specified amount of the drive is accessible. The min and
max expected drive size are set as a build configuration, and compared
against the drive size (found by using the linux ioctl). Also adds
testing build files, testing options, and verifyGeometry test.
Tested: Ran eStoraged on a machine with an eMMC, using the following
$ ./eStoraged -b /dev/mmcblk0 &
$ busctl call xyz.openbmc_project.eStoraged.mmcblk0 \
/xyz/openbmc_project/storage/mmcblk0 \
xyz.openbmc_project.eStoraged Erase ays 1 1 \
xyz.openbmc_project.eStoraged.EraseMethod.VerifyGeometry
Signed-off-by: John Edward Broadbent <jebr@google.com>
Change-Id: Ie47f8666996a6085a115d1b86f2643bc278638c5
diff --git a/src/erase/erase.cpp b/src/erase/erase.cpp
new file mode 100644
index 0000000..3b6ce17
--- /dev/null
+++ b/src/erase/erase.cpp
@@ -0,0 +1,33 @@
+#include "erase.hpp"
+
+#include <linux/fs.h>
+
+#include <phosphor-logging/lg2.hpp>
+#include <stdplus/fd/create.hpp>
+#include <stdplus/fd/managed.hpp>
+#include <stdplus/handle/managed.hpp>
+#include <xyz/openbmc_project/eStoraged/error.hpp>
+
+using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
+using stdplus::fd::ManagedFd;
+
+uint64_t Erase::findSizeOfBlockDevice()
+{
+ ManagedFd fd;
+ uint64_t bytes;
+ try
+ {
+ // open block dev
+ fd = stdplus::fd::open(devPath, stdplus::fd::OpenAccess::ReadOnly);
+ // get block size
+ fd.ioctl(BLKGETSIZE64, &bytes);
+ }
+ catch (...)
+ {
+ 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();
+ }
+ return bytes;
+}
diff --git a/src/erase/meson.build b/src/erase/meson.build
new file mode 100644
index 0000000..3c90ab9
--- /dev/null
+++ b/src/erase/meson.build
@@ -0,0 +1,14 @@
+libeStoragedErase_lib = static_library(
+ 'libeStoragedErase-lib',
+ 'verifyDriveGeometry.cpp',
+ 'erase.cpp',
+ include_directories : eStoraged_headers,
+ implicit_include_directories: false,
+ dependencies: [eStoraged_dbus, dependency('stdplus'),],
+)
+
+libeStoragedErase_dep = declare_dependency(
+ include_directories: eStoraged_headers,
+ link_with: libeStoragedErase_lib,
+)
+
diff --git a/src/erase/verifyDriveGeometry.cpp b/src/erase/verifyDriveGeometry.cpp
new file mode 100644
index 0000000..2996912
--- /dev/null
+++ b/src/erase/verifyDriveGeometry.cpp
@@ -0,0 +1,38 @@
+#include "verifyDriveGeometry.hpp"
+
+#include "estoraged_conf.hpp"
+
+#include <phosphor-logging/lg2.hpp>
+#include <xyz/openbmc_project/eStoraged/error.hpp>
+
+#include <string>
+
+using sdbusplus::xyz::openbmc_project::eStoraged::Error::EraseError;
+
+void VerifyDriveGeometry::geometryOkay(uint64_t bytes)
+{
+ if (bytes > ERASE_MAX_GEOMETRY)
+ {
+ lg2::error("Erase verify Geometry too large", "REDFISH_MESSAGE_ID",
+ std::string("OpenBMC.0.1.DriveEraseFailure"),
+ "REDFISH_MESSAGE_ARGS",
+ std::to_string(bytes) + ">" +
+ std::to_string(ERASE_MAX_GEOMETRY));
+ throw EraseError();
+ }
+ else if (bytes < ERASE_MIN_GEOMETRY)
+ {
+ lg2::error(
+ "eStorageD erase verify Geometry too small", "REDFISH_MESSAGE_ID",
+ std::string("OpenBMC.0.1.DriveEraseFailure"),
+ "REDFISH_MESSAGE_ARGS",
+ std::to_string(bytes) + "<" + std::to_string(ERASE_MIN_GEOMETRY));
+ throw EraseError();
+ }
+ else
+ {
+ lg2::info("eStorageD erase verify Geometry in range",
+ "REDFISH_MESSAGE_ID",
+ std::string("OpenBMC.0.1.DriveEraseSuccess"));
+ }
+}