[Devel] [PATCH vz9 03/27] ve: uninline ve_get_monotonic() and ve_get_uptime()

Nikita Yushchenko nikita.yushchenko at virtuozzo.com
Wed Oct 6 11:57:23 MSK 2021


These functions reference put_time_ns() that is not exported.
This turns into link errors when the functions are used in modules.

Also split out ve_get_time_ns() because it is useful elsewhere.
Keep this one inline for now.

Signed-off-by: Nikita Yushchenko <nikita.yushchenko at virtuozzo.com>
---
 include/linux/ve.h | 42 ++++++------------------------------------
 kernel/ve/ve.c     | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 36 deletions(-)

diff --git a/include/linux/ve.h b/include/linux/ve.h
index 959e919633c9..4dde4cb46d52 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -127,52 +127,22 @@ static inline struct ve_struct *css_to_ve(struct cgroup_subsys_state *css)
 
 extern struct cgroup_subsys_state *ve_get_init_css(struct ve_struct *ve, int subsys_id);
 
-static inline u64 ve_get_monotonic(struct ve_struct *ve)
+static inline struct time_namespace *ve_get_time_ns(struct ve_struct *ve)
 {
-	struct timespec64 tp = ns_to_timespec64(0);
-	struct time_namespace *time_ns;
 	struct nsproxy *ve_ns;
-
-	rcu_read_lock();
-	ve_ns = rcu_dereference(ve->ve_ns);
-	if (!ve_ns) {
-		rcu_read_unlock();
-		goto out;
-	}
-
-	time_ns = get_time_ns(ve_ns->time_ns);
-	rcu_read_unlock();
-
-	ktime_get_ts64(&tp);
-	tp = timespec64_add(tp, time_ns->offsets.monotonic);
-	put_time_ns(time_ns);
-out:
-	return timespec64_to_ns(&tp);
-}
-
-static u64 ve_get_uptime(struct ve_struct *ve)
-{
-	struct timespec64 tp = ns_to_timespec64(0);
 	struct time_namespace *time_ns;
-	struct nsproxy *ve_ns;
 
 	rcu_read_lock();
 	ve_ns = rcu_dereference(ve->ve_ns);
-	if (!ve_ns) {
-		rcu_read_unlock();
-		goto out;
-	}
-
-	time_ns = get_time_ns(ve_ns->time_ns);
+	time_ns = ve_ns ? get_time_ns(ve_ns->time_ns) : NULL;
 	rcu_read_unlock();
 
-	ktime_get_boottime_ts64(&tp);
-	tp = timespec64_add(tp, time_ns->offsets.boottime);
-	put_time_ns(time_ns);
-out:
-	return timespec64_to_ns(&tp);
+	return time_ns;
 }
 
+extern u64 ve_get_monotonic(struct ve_struct *ve);
+extern u64 ve_get_uptime(struct ve_struct *ve);
+
 static inline void ve_set_task_start_time(struct ve_struct *ve,
 					  struct task_struct *t)
 {
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index cd4b982cc0da..bd114bd620eb 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -577,6 +577,40 @@ void ve_exit_ns(struct pid_namespace *pid_ns)
 	up_write(&ve->op_sem);
 }
 
+u64 ve_get_monotonic(struct ve_struct *ve)
+{
+	struct time_namespace *time_ns = ve_get_time_ns(ve);
+	struct timespec64 tp;
+
+	if (unlikely(!time_ns)) {
+		/* container not yet started */
+		return 0;
+	}
+
+	ktime_get_ts64(&tp);
+	tp = timespec64_add(tp, time_ns->offsets.monotonic);
+	put_time_ns(time_ns);
+	return timespec64_to_ns(&tp);
+}
+EXPORT_SYMBOL(ve_get_monotonic);
+
+u64 ve_get_uptime(struct ve_struct *ve)
+{
+	struct time_namespace *time_ns = ve_get_time_ns(ve);
+	struct timespec64 tp;
+
+	if (unlikely(!time_ns)) {
+		/* container not yet started */
+		return 0;
+	}
+
+	ktime_get_boottime_ts64(&tp);
+	tp = timespec64_add(tp, time_ns->offsets.boottime);
+	put_time_ns(time_ns);
+	return timespec64_to_ns(&tp);
+}
+EXPORT_SYMBOL(ve_get_uptime);
+
 static int copy_vdso(struct vdso_image **vdso_dst, const struct vdso_image *vdso_src)
 {
 	struct vdso_image *vdso;
-- 
2.30.2



More information about the Devel mailing list