[Devel] [PATCH rh7 2/2] syslog: Virtualize timestamps in the data reported

Konstantin Khorenko khorenko at virtuozzo.com
Thu Feb 2 23:17:13 MSK 2023


Internally log messages contain the timestamps relative to the Host boot
time, while Container could start much later than the Host boots and the
timestamps should be shifted accordingly.

Otherwise syslog() syscall reports incorrect timestamps.

https://jira.sw.ru/browse/PSBM-145263

Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 kernel/printk.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/printk.c b/kernel/printk.c
index 27221d15590a..747383d21569 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -960,11 +960,18 @@ module_param_named(time, printk_time, bool, S_IRUGO | S_IWUSR);
 
 static size_t print_time(u64 ts, char *buf)
 {
+	struct ve_struct *ve;
 	unsigned long rem_nsec;
 
 	if (!printk_time)
 		return 0;
 
+	/* shift the timestamp on the Container uptime value */
+	ve = get_exec_env();
+	if (!ve_is_super(ve)) {
+		ts -= ve->real_start_timespec.tv_sec * NSEC_PER_SEC;
+		ts -= ve->real_start_timespec.tv_nsec;
+	}
 	rem_nsec = do_div(ts, 1000000000);
 
 	if (!buf)
-- 
2.24.3



More information about the Devel mailing list