PATCH 1/4 - Time virtualization : namespace
Subsystems (2)
RFC 1/1 PATCH 1/4 - Time virtualization : namespace
Add time namespace, which contains an offset from the system time. In a namespace, gettimeofday gets the system time and adds the namespace offset to it. settimeofday, which is unprivileged in a namespace, calculates the difference between the system time and the new namespace time and sets that as the namespace offset.
kernel/time.c +17 -0
@@ -103,6 +103,11 @@ asmlinkage long sys_gettimeofday(structif (likely (tv !=NULL )) {struct timeval ktv;do_gettimeofday (&ktv); +if (current->time_ns !=NULL ){ +s64 now =timeval_to_ns (&ktv); + now += current->time_ns->offset; + ktv =ns_to_timeval (now); + }if (copy_to_user (tv, &ktv,sizeof (ktv)))return -EFAULT ; }
@@ -158,6 +163,18 @@ int do_sys_settimeofday(struct timespecif (tv && !timespec_valid (tv))return -EINVAL ; +if (current->time_ns !=NULL ){ +struct timeval now; +s64 old, new; + +do_gettimeofday (&now); + old =timeval_to_ns (&now); + new =timespec_to_ns (tv); + current->time_ns->offset = new - old; + +return 0 ; + } + error =security_settime (tv, tz);if (error)return error;
include/linux/sched.h +6 -0
@@ -715,6 +715,11 @@ enum sleep_type { SLEEP_INTERRUPTED, }; +struct time_ns { +atomic_t counter; +s64 offset; +}; +struct task_struct {volatile long state;/* -1 unrunnable, 0 runnable, >0 stopped */ struct thread_info *thread_info;
@@ -838,6 +843,7 @@ struct task_struct {/* signal handlers */ struct signal_struct *signal;struct sighand_struct *sighand; +struct time_ns *time_ns;sigset_t blocked, real_blocked;sigset_t saved_sigmask;/* To be restored with TIF_RESTORE_SIGMASK */
include/linux/init_task.h +1 -0
@@ -98,6 +98,7 @@ extern struct group_info init_groups; .tasks = LIST_HEAD_INIT(tsk.tasks), \ .ptrace_children= LIST_HEAD_INIT(tsk.ptrace_children), \ .ptrace_list = LIST_HEAD_INIT(tsk.ptrace_list), \ + .time_ns = NULL, \ .real_parent = &tsk, \ .parent = &tsk, \ .children = LIST_HEAD_INIT(tsk.children), \
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel