From dd6a274d00b1f911cdd64f28ae60ac6c7855c437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 11 Oct 2023 13:53:46 +0000 Subject: [PATCH] cptofs: remount as read-only prior to exiting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit also umount returns and /proc/self/mounts no longer lists the filesystem, ext4 seems to only flush the filesystem properly after a certain delay. To work around this, we now remount the filesystem as read-only to ensure that it is actually finished by the time we exited Signed-off-by: Jörg Thalheim --- tools/lkl/cptofs.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/tools/lkl/cptofs.c b/tools/lkl/cptofs.c index 533e71406510df..cf34ab212c52f4 100644 --- a/tools/lkl/cptofs.c +++ b/tools/lkl/cptofs.c @@ -675,6 +675,27 @@ int main(int argc, char **argv) break; } + /* FIXME: Remouting as readonly seems to be required to make sure the filessytem is cleanly umounted. Otherwise the journal will be still dirty... */ + char dev_str[] = { "/dev/xxxxxxxx" }; + + snprintf(dev_str, sizeof(dev_str), "/dev/%08x", disk_id); + for (;;) { + ret = lkl_sys_mount(dev_str, mpoint, (char *)cla.fsimg_type, LKL_MS_RDONLY|LKL_MS_REMOUNT, NULL); + if (ret == 0) + break; + if (ret == -EBUSY) { + struct lkl_timespec ts = { + .tv_sec = 1, + .tv_nsec = 0, + }; + lkl_sys_nanosleep((struct __lkl__kernel_timespec *)&ts, NULL); + continue; + } else if (ret < 0) { + fprintf(stderr, "cannot remount mount disk read-only: %s\n", lkl_strerror(ret)); + break; + } + } + umount_ret = lkl_umount_dev(disk_id, cla.part, 0, 1000); if (ret == 0) ret = umount_ret;