Run fsck before mounting filesystem
Running fsck should help correct any filesystem errors and make mounting
more reliable. For example, filesystem errors might occur when there's a
power loss while writes are in flight.
Tested:
Below is some example output from eStoraged with fsck.
```
root@wodp1-nfd02:~# systemctl status -l xyz.openbmc_project.eStoraged
● xyz.openbmc_project.eStoraged.service - Storage management daemon for an encrypted storage device
Loaded: loaded (/usr/lib/systemd/system/xyz.openbmc_project.eStoraged.service; enabled; preset: enabled)
Active: active (running) since Thu 2025-12-04 16:38:57 PST; 23min ago
Invocation: ea8275ce96d74cce8036596450060255
Main PID: 812 (eStoraged)
Tasks: 1 (limit: 1965)
Memory: 4.3M
CPU: 5.247s
CGroup: /system.slice/xyz.openbmc_project.eStoraged.service
└─812 /usr/bin/eStoraged
Dec 04 16:38:57 wodp1-nfd02.prod.google.com systemd[1]: Started Storage management daemon for an encrypted storage device.
Dec 04 16:39:10 wodp1-nfd02.prod.google.com eStoraged[812]: Storage management service is running
Dec 04 16:39:24 wodp1-nfd02.prod.google.com eStoraged[812]: Created eStoraged object for path /xyz/openbmc_project/inventory/system/board/eMMC/emmc
Dec 04 16:39:45 wodp1-nfd02.prod.google.com eStoraged[812]: Starting unlock
Dec 04 16:39:45 wodp1-nfd02.prod.google.com eStoraged[812]: Activating LUKS dev /dev/mmcblk0
Dec 04 16:39:48 wodp1-nfd02.prod.google.com eStoraged[812]: Successfully activated LUKS dev /dev/mmcblk0
Dec 04 16:39:48 wodp1-nfd02.prod.google.com eStoraged[3049]: fsck from util-linux 2.39.3
Dec 04 16:39:49 wodp1-nfd02.prod.google.com eStoraged[3074]: /dev/mapper/luks-mmcblk0: recovering journal
Dec 04 16:39:49 wodp1-nfd02.prod.google.com eStoraged[3074]: /dev/mapper/luks-mmcblk0: clean, 34/954720 files, 98720/3812864 blocks
Dec 04 16:39:49 wodp1-nfd02.prod.google.com eStoraged[812]: Successfully mounted filesystem at /mnt/luks-mmcblk0_fs
```
Change-Id: Ie333a7fd9c8af2fe6e07ad52507249f42ca0e8e8
Signed-off-by: John Wedig <johnwedig@google.com>
diff --git a/src/test/estoraged_test.cpp b/src/test/estoraged_test.cpp
index 5ad8f00..cef6e21 100644
--- a/src/test/estoraged_test.cpp
+++ b/src/test/estoraged_test.cpp
@@ -142,6 +142,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(false));
@@ -189,6 +193,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(true));
@@ -329,6 +337,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(false));
@@ -358,6 +370,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(false));
@@ -395,6 +411,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(false));
@@ -434,6 +454,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(false));
@@ -477,6 +501,10 @@
EXPECT_CALL(*mockFsIface, runMkfs(StrEq(esObject->getCryptDevicePath())))
.WillOnce(Return(0));
+ EXPECT_CALL(*mockFsIface, runFsck(StrEq(esObject->getCryptDevicePath()),
+ StrEq("-t ext4 -p")))
+ .WillOnce(Return(0));
+
EXPECT_CALL(*mockFsIface, directoryExists(path(esObject->getMountPoint())))
.WillOnce(Return(false));