[Devel] [PATCH rh7] timers should not get negative argument

Cyrill Gorcunov gorcunov at virtuozzo.com
Fri Jun 17 09:22:05 PDT 2016


From: Vasily Averin <vvs at virtuozzo.com>

This patch fixes 25-sec delay on login into systemd based containers.

Userspace application can set timer for past
and expect that the timer will be expired immediately.

This can do not work as expected inside migrated containers.
Translated argument provided to timer can become negative,
and according timer will sleep a very long time.

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

CC: Vladimir Davydov <vdavydov at virtuozzo.com>
CC: Konstantin Khorenko <khorenko at virtuozzo.com>
Signed-off-by: Vasily Averin <vvs at virtuozzo.com>
Acked-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 kernel/posix-timers.c |    6 ++++++
 1 file changed, 6 insertions(+)

Index: linux-pcs7.git/kernel/posix-timers.c
===================================================================
--- linux-pcs7.git.orig/kernel/posix-timers.c
+++ linux-pcs7.git/kernel/posix-timers.c
@@ -133,6 +133,8 @@ static struct k_clock posix_clocks[MAX_C
 	 (which_clock) == CLOCK_MONOTONIC_COARSE)
 
 #ifdef CONFIG_VE
+static struct timespec zero_time;
+
 void monotonic_abs_to_ve(clockid_t which_clock, struct timespec *tp)
 {
 	struct ve_struct *ve = get_exec_env();
@@ -151,6 +153,10 @@ void monotonic_ve_to_abs(clockid_t which
 		set_normalized_timespec(tp,
 				tp->tv_sec + ve->start_timespec.tv_sec,
 				tp->tv_nsec + ve->start_timespec.tv_nsec);
+	if (timespec_compare(tp, &zero_time) <= 0) {
+		tp->tv_sec =  0;
+		tp->tv_nsec = 1;
+	}
 }
 #endif
 


More information about the Devel mailing list