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/estoraged.cpp b/src/estoraged.cpp
index 28290c4..fe2636f 100644
--- a/src/estoraged.cpp
+++ b/src/estoraged.cpp
@@ -429,6 +429,18 @@
void EStoraged::mountFilesystem()
{
/*
+ * Before mounting, run fsck to check for and resolve any filesystem errors.
+ */
+ int retval = fsIface->runFsck(cryptDevicePath, "-t ext4 -p");
+ if (retval != 0)
+ {
+ lg2::error("The fsck command failed: {RETVAL}", "RETVAL", retval,
+ "REDFISH_MESSAGE_ID",
+ std::string("OpenBMC.0.1.FixFilesystemFail"));
+ /* We'll still try to mount the filesystem, though. */
+ }
+
+ /*
* Create directory for the filesystem, if it's not already present. It
* might already exist if, for example, the BMC reboots after creating the
* directory.
@@ -447,8 +459,8 @@
}
/* Run the command to mount the filesystem. */
- int retval = fsIface->doMount(cryptDevicePath.c_str(), mountPoint.c_str(),
- "ext4", 0, nullptr);
+ retval = fsIface->doMount(cryptDevicePath.c_str(), mountPoint.c_str(),
+ "ext4", 0, nullptr);
if (retval != 0)
{
lg2::error("Failed to mount filesystem: {RETVAL}", "RETVAL", retval,