summaryrefslogtreecommitdiff
blob: f3769f204a786cb872fd29934facd8229d284f44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
Index: linux-2.6.16/arch/alpha/kernel/osf_sys.c
===================================================================
--- linux-2.6.16.orig/arch/alpha/kernel/osf_sys.c
+++ linux-2.6.16/arch/alpha/kernel/osf_sys.c
@@ -887,7 +887,7 @@ osf_gettimeofday(struct timeval32 __user
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/arch/ia64/ia32/sys_ia32.c
===================================================================
--- linux-2.6.16.orig/arch/ia64/ia32/sys_ia32.c
+++ linux-2.6.16/arch/ia64/ia32/sys_ia32.c
@@ -1191,7 +1191,7 @@ sys32_gettimeofday (struct compat_timeva
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/arch/mips/kernel/linux32.c
===================================================================
--- linux-2.6.16.orig/arch/mips/kernel/linux32.c
+++ linux-2.6.16/arch/mips/kernel/linux32.c
@@ -300,7 +300,7 @@ sys32_gettimeofday(struct compat_timeval
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/arch/parisc/kernel/sys_parisc32.c
===================================================================
--- linux-2.6.16.orig/arch/parisc/kernel/sys_parisc32.c
+++ linux-2.6.16/arch/parisc/kernel/sys_parisc32.c
@@ -203,11 +203,11 @@ static inline long get_ts32(struct times
 asmlinkage int
 sys32_gettimeofday(struct compat_timeval __user *tv, struct timezone __user *tz)
 {
-    extern void do_gettimeofday(struct timeval *tv);
+    extern void vx_gettimeofday(struct timeval *tv);
 
     if (tv) {
 	    struct timeval ktv;
-	    do_gettimeofday(&ktv);
+	    vx_gettimeofday(&ktv);
 	    if (put_compat_timeval(tv, &ktv))
 		    return -EFAULT;
     }
Index: linux-2.6.16/arch/powerpc/kernel/sys_ppc32.c
===================================================================
--- linux-2.6.16.orig/arch/powerpc/kernel/sys_ppc32.c
+++ linux-2.6.16/arch/powerpc/kernel/sys_ppc32.c
@@ -340,7 +340,7 @@ asmlinkage long compat_sys_gettimeofday(
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/arch/s390/kernel/compat_linux.c
===================================================================
--- linux-2.6.16.orig/arch/s390/kernel/compat_linux.c
+++ linux-2.6.16/arch/s390/kernel/compat_linux.c
@@ -595,7 +595,7 @@ asmlinkage long sys32_gettimeofday(struc
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/arch/sparc64/kernel/sys_sparc32.c
===================================================================
--- linux-2.6.16.orig/arch/sparc64/kernel/sys_sparc32.c
+++ linux-2.6.16/arch/sparc64/kernel/sys_sparc32.c
@@ -788,7 +788,7 @@ asmlinkage long sys32_gettimeofday(struc
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/arch/x86_64/ia32/sys_ia32.c
===================================================================
--- linux-2.6.16.orig/arch/x86_64/ia32/sys_ia32.c
+++ linux-2.6.16/arch/x86_64/ia32/sys_ia32.c
@@ -461,7 +461,7 @@ sys32_gettimeofday(struct compat_timeval
 {
 	if (tv) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (put_tv32(tv, &ktv))
 			return -EFAULT;
 	}
Index: linux-2.6.16/fs/exec.c
===================================================================
--- linux-2.6.16.orig/fs/exec.c
+++ linux-2.6.16/fs/exec.c
@@ -1323,7 +1323,7 @@ static void format_corename(char *corena
 			/* UNIX time of coredump */
 			case 't': {
 				struct timeval tv;
-				do_gettimeofday(&tv);
+				vx_gettimeofday(&tv);
 				rc = snprintf(out_ptr, out_end - out_ptr,
 					      "%lu", tv.tv_sec);
 				if (rc > out_end - out_ptr)
Index: linux-2.6.16/include/linux/time.h
===================================================================
--- linux-2.6.16.orig/include/linux/time.h
+++ linux-2.6.16/include/linux/time.h
@@ -147,6 +147,8 @@ extern struct timespec ns_to_timespec(co
  */
 extern struct timeval ns_to_timeval(const nsec_t nsec);
 
+#include <linux/vs_time.h>
+
 #endif /* __KERNEL__ */
 
 #define NFDBITS			__NFDBITS
Index: linux-2.6.16/include/linux/vs_time.h
===================================================================
--- /dev/null
+++ linux-2.6.16/include/linux/vs_time.h
@@ -0,0 +1,19 @@
+#ifndef _VX_VS_TIME_H
+#define _VX_VS_TIME_H
+
+
+/* time faking stuff */
+
+#ifdef CONFIG_VSERVER_VTIME
+
+extern void vx_gettimeofday(struct timeval *tv);
+extern int vx_settimeofday(struct timeval *tv);
+
+#else
+#define	vx_gettimeofday(t)	do_gettimeofday(t)
+#define	vx_settimeofday(t)	do_settimeofday(t)
+#endif
+
+#else
+#warning duplicate inclusion
+#endif
Index: linux-2.6.16/include/linux/vserver/context.h
===================================================================
--- linux-2.6.16.orig/include/linux/vserver/context.h
+++ linux-2.6.16/include/linux/vserver/context.h
@@ -35,6 +35,7 @@
 #define VXF_VIRT_UPTIME		0x00020000
 #define VXF_VIRT_CPU		0x00040000
 #define VXF_VIRT_LOAD		0x00080000
+#define VXF_VIRT_TIME		0x00100000
 
 #define VXF_HIDE_MOUNT		0x01000000
 #define VXF_HIDE_NETIF		0x02000000
Index: linux-2.6.16/include/linux/vserver/cvirt_def.h
===================================================================
--- linux-2.6.16.orig/include/linux/vserver/cvirt_def.h
+++ linux-2.6.16/include/linux/vserver/cvirt_def.h
@@ -43,6 +43,7 @@ struct _vx_cvirt {
 	atomic_t nr_onhold;		/* processes on hold */
 	uint32_t onhold_last;		/* jiffies when put on hold */
 
+	struct timeval bias_tv;		/* time offset to the host */
 	struct timespec bias_idle;
 	struct timespec bias_uptime;	/* context creation point */
 	uint64_t bias_clock;		/* offset in clock_t */
Index: linux-2.6.16/kernel/compat.c
===================================================================
--- linux-2.6.16.orig/kernel/compat.c
+++ linux-2.6.16/kernel/compat.c
@@ -841,7 +841,7 @@ asmlinkage long compat_sys_time(compat_t
 	compat_time_t i;
 	struct timeval tv;
 
-	do_gettimeofday(&tv);
+	vx_gettimeofday(&tv);
 	i = tv.tv_sec;
 
 	if (tloc) {
@@ -865,7 +865,7 @@ asmlinkage long compat_sys_stime(compat_
 	if (err)
 		return err;
 
-	do_settimeofday(&tv);
+	vx_settimeofday(&tv);
 	return 0;
 }
 
Index: linux-2.6.16/kernel/time.c
===================================================================
--- linux-2.6.16.orig/kernel/time.c
+++ linux-2.6.16/kernel/time.c
@@ -61,7 +61,7 @@ asmlinkage long sys_time(time_t __user *
 	time_t i;
 	struct timeval tv;
 
-	do_gettimeofday(&tv);
+	vx_gettimeofday(&tv);
 	i = tv.tv_sec;
 
 	if (tloc) {
@@ -92,7 +92,7 @@ asmlinkage long sys_stime(time_t __user 
 	if (err)
 		return err;
 
-	do_settimeofday(&tv);
+	vx_settimeofday(&tv);
 	return 0;
 }
 
@@ -102,7 +102,7 @@ asmlinkage long sys_gettimeofday(struct 
 {
 	if (likely(tv != NULL)) {
 		struct timeval ktv;
-		do_gettimeofday(&ktv);
+		vx_gettimeofday(&ktv);
 		if (copy_to_user(tv, &ktv, sizeof(ktv)))
 			return -EFAULT;
 	}
@@ -176,7 +176,7 @@ int do_sys_settimeofday(struct timespec 
 		/* SMP safe, again the code in arch/foo/time.c should
 		 * globally block out interrupts when it runs.
 		 */
-		return do_settimeofday(tv);
+		return vx_settimeofday(tv);
 	}
 	return 0;
 }
@@ -558,7 +558,7 @@ void getnstimeofday(struct timespec *tv)
 {
 	struct timeval x;
 
-	do_gettimeofday(&x);
+	vx_gettimeofday(&x);
 	tv->tv_sec = x.tv_sec;
 	tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
 }
Index: linux-2.6.16/kernel/vserver/Kconfig
===================================================================
--- linux-2.6.16.orig/kernel/vserver/Kconfig
+++ linux-2.6.16/kernel/vserver/Kconfig
@@ -66,6 +66,16 @@ config	VSERVER_COWBL
 	  when writing to them (which will implicitely break the
 	  link and create a copy of the unified file)
 
+config	VSERVER_VTIME
+	bool	"Enable Virtualized Guest Time"
+	depends on EXPERIMENTAL
+	default n
+	help
+	  This enables per guest time offsets to allow for
+	  adjusting the system clock individually per guest.
+	  this adds some overhead to the time functions and
+	  therefore should not be enabled without good reason.
+
 config	VSERVER_PROC_SECURE
 	bool	"Enable Proc Security"
 	depends on PROC_FS
Index: linux-2.6.16/kernel/vserver/cvirt.c
===================================================================
--- linux-2.6.16.orig/kernel/vserver/cvirt.c
+++ linux-2.6.16/kernel/vserver/cvirt.c
@@ -255,3 +255,43 @@ out_put:
 	put_vx_info(vxi);
 	return (name ? 0 : -EFAULT);
 }
+
+#ifdef CONFIG_VSERVER_VTIME
+
+/* virtualized time base */
+
+void vx_gettimeofday(struct timeval *tv)
+{
+	do_gettimeofday(tv);
+	if (!vx_flags(VXF_VIRT_TIME, 0))
+		return;
+
+	tv->tv_sec += current->vx_info->cvirt.bias_tv.tv_sec;
+	tv->tv_usec += current->vx_info->cvirt.bias_tv.tv_usec;
+
+	if (tv->tv_usec >= USEC_PER_SEC) {
+		tv->tv_sec++;
+		tv->tv_usec -= USEC_PER_SEC;
+	} else if (tv->tv_usec < 0) {
+		tv->tv_sec--;
+		tv->tv_usec += USEC_PER_SEC;
+	}
+}
+
+int vx_settimeofday(struct timeval *tv)
+{
+	struct timeval tvs;
+
+	if (!vx_flags(VXF_VIRT_TIME, 0))
+		return do_settimeofday(tv);
+
+	do_gettimeofday(&tvs);
+	current->vx_info->cvirt.bias_tv.tv_sec =
+		tv->tv_sec - tvs.tv_sec;
+	current->vx_info->cvirt.bias_tv.tv_usec =
+		tv->tv_usec - tvs.tv_usec;
+	return 0;
+}
+
+#endif
+
Index: linux-2.6.16/kernel/vserver/cvirt_init.h
===================================================================
--- linux-2.6.16.orig/kernel/vserver/cvirt_init.h
+++ linux-2.6.16/kernel/vserver/cvirt_init.h
@@ -11,6 +11,8 @@ static inline void vx_info_init_cvirt(st
 	nsuptime = (unsigned long long)cvirt->bias_uptime.tv_sec
 		* NSEC_PER_SEC + cvirt->bias_uptime.tv_nsec;
 	cvirt->bias_clock = nsec_to_clock_t(nsuptime);
+	cvirt->bias_tv.tv_sec = 0;
+	cvirt->bias_tv.tv_usec = 0;
 
 	jiffies_to_timespec(idle_jiffies, &cvirt->bias_idle);
 	atomic_set(&cvirt->nr_threads, 0);