summaryrefslogtreecommitdiff
path: root/include/linux/time_namespace.h
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@openvz.org>2019-11-12 04:26:53 +0300
committerThomas Gleixner <tglx@linutronix.de>2020-01-14 14:20:49 +0300
commitaf993f58d69ee9c1f421dfc87c3ed231c113989c (patch)
treec482a7253674ae00aad86b3907661912efc7a897 /include/linux/time_namespace.h
parent769071ac9f20b6a447410c7eaa55d1a5233ef40c (diff)
downloadlinux-af993f58d69ee9c1f421dfc87c3ed231c113989c.tar.xz
time: Add timens_offsets to be used for tasks in time namespace
Introduce offsets for time namespace. They will contain an adjustment needed to convert clocks to/from host's. A new namespace is created with the same offsets as the time namespace of the current process. Co-developed-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Andrei Vagin <avagin@openvz.org> Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20191112012724.250792-5-dima@arista.com
Diffstat (limited to 'include/linux/time_namespace.h')
-rw-r--r--include/linux/time_namespace.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/include/linux/time_namespace.h b/include/linux/time_namespace.h
index 8c74cc12ad24..d7e3b4994e31 100644
--- a/include/linux/time_namespace.h
+++ b/include/linux/time_namespace.h
@@ -12,11 +12,17 @@
struct user_namespace;
extern struct user_namespace init_user_ns;
+struct timens_offsets {
+ struct timespec64 monotonic;
+ struct timespec64 boottime;
+};
+
struct time_namespace {
struct kref kref;
struct user_namespace *user_ns;
struct ucounts *ucounts;
struct ns_common ns;
+ struct timens_offsets offsets;
} __randomize_layout;
extern struct time_namespace init_time_ns;
@@ -39,6 +45,20 @@ static inline void put_time_ns(struct time_namespace *ns)
kref_put(&ns->kref, free_time_ns);
}
+static inline void timens_add_monotonic(struct timespec64 *ts)
+{
+ struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;
+
+ *ts = timespec64_add(*ts, ns_offsets->monotonic);
+}
+
+static inline void timens_add_boottime(struct timespec64 *ts)
+{
+ struct timens_offsets *ns_offsets = &current->nsproxy->time_ns->offsets;
+
+ *ts = timespec64_add(*ts, ns_offsets->boottime);
+}
+
#else
static inline struct time_namespace *get_time_ns(struct time_namespace *ns)
{
@@ -66,6 +86,8 @@ static inline int timens_on_fork(struct nsproxy *nsproxy,
return 0;
}
+static inline void timens_add_monotonic(struct timespec64 *ts) { }
+static inline void timens_add_boottime(struct timespec64 *ts) { }
#endif
#endif /* _LINUX_TIMENS_H */