From 71ef8cc48940b8d104353e2d7e2e5280f7facaa3 Mon Sep 17 00:00:00 2001 From: David Disseldorp Date: Thu, 30 May 2024 05:48:05 +0200 Subject: [PATCH] lklfuse: set lkl clock time to the host walltime This ensures that file times aren't stuck around Epoch. Signed-off-by: David Disseldorp --- tools/lkl/lklfuse.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/lkl/lklfuse.c b/tools/lkl/lklfuse.c index 6561bb638ccb28..347ec24910adb1 100644 --- a/tools/lkl/lklfuse.c +++ b/tools/lkl/lklfuse.c @@ -509,6 +509,8 @@ static int start_lkl(void) { long ret; char mpoint[32]; + struct timespec walltime; + struct lkl_timespec ts; ret = lkl_start_kernel("mem=%dM", lklfuse.mb); if (ret) { @@ -516,6 +518,21 @@ static int start_lkl(void) goto out; } + /* forward host walltime to lkl */ + ret = clock_gettime(CLOCK_REALTIME, &walltime); + if (ret < 0) + goto out_halt; + + ts = (struct lkl_timespec){ tv_sec: walltime.tv_sec, + tv_nsec: walltime.tv_nsec }; + ret = lkl_sys_clock_settime(LKL_CLOCK_REALTIME, + (struct __lkl__kernel_timespec *)&ts); + if (ret < 0) { + fprintf(stderr, "lkl_sys_clock_settime() failed: %s\n", + lkl_strerror(ret)); + goto out_halt; + } + ret = lkl_mount_dev(lklfuse.disk_id, lklfuse.part, lklfuse.type, lklfuse.ro ? LKL_MS_RDONLY : 0, lklfuse.opts, mpoint, sizeof(mpoint));