On 2.02.23 22:17, Konstantin Khorenko wrote:
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 "dmesg -H" reports data from the future.

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

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

diff --git a/kernel/printk.c b/kernel/printk.c
index 5380594d231f..27221d15590a 100644
--- a/kernel/printk.c
+++ b/kernel/printk.c
@@ -555,6 +555,7 @@ static ssize_t devkmsg_writev(struct kiocb *iocb, const 
struct iovec *iv,
  static ssize_t devkmsg_read(struct file *file, char __user *buf,
                            size_t count, loff_t *ppos)
  {
+       struct ve_struct *ve;
        struct log_state *log = ve_log_state();
        struct devkmsg_user *user = file->private_data;
        struct log *msg;
@@ -597,6 +598,13 @@ static ssize_t devkmsg_read(struct file *file, char __user 
*buf,
msg = log_from_idx(log, user->idx);
        ts_usec = msg->ts_nsec;
+
+       /* shift the timestamp on the Container uptime value */
+       ve = get_exec_env();
+       if (!ve_is_super(ve)) {
+               ts_usec -= ve->real_start_timespec.tv_sec * NSEC_PER_SEC;
+               ts_usec -= ve->real_start_timespec.tv_nsec;
+       }
        do_div(ts_usec, 1000);
/*


We digged into the possibility of ts to overflow so it is less than real_start_timespec which stays constant but what we found is
that we have 580+ years to fix it.

Acked-by: Alexander Atanasov <alexander.atana...@virtuozzo.com>

--
Regards,
Alexander Atanasov

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to