Skip to content

Commit 36bb632

Browse files
Kenta TadaKenta Tada
authored andcommitted
Add support for time namespace
The time namespace is a new kernel feature available in 5.6+ to isolate the system monotonic and boot-time clocks. Signed-off-by: Kenta Tada <[email protected]>
1 parent d438e29 commit 36bb632

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

config-linux.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The following parameters can be specified to set up namespaces:
3434
* **`uts`** the container will be able to have its own hostname and domain name.
3535
* **`user`** the container will be able to remap user and group IDs from the host to local users and groups within the container.
3636
* **`cgroup`** the container will have an isolated view of the cgroup hierarchy.
37+
* **`time`** the container will be able to have its own clocks.
3738
* **`path`** *(string, OPTIONAL)* - namespace file.
3839
This value MUST be an absolute path in the [runtime mount namespace](glossary.md#runtime-namespace).
3940
The runtime MUST place the container process in the namespace associated with that `path`.
@@ -70,6 +71,9 @@ If a `namespaces` field contains duplicated namespaces with same `type`, the run
7071
},
7172
{
7273
"type": "cgroup"
74+
},
75+
{
76+
"type": "time"
7377
}
7478
]
7579
```
@@ -107,6 +111,17 @@ Note that the number of mapping entries MAY be limited by the [kernel][user-name
107111
]
108112
```
109113

114+
## <a name="configLinuxTimeOffset" />Offset for Time Namespace
115+
116+
**`timeOffsets`** (object, OPTIONAL) sets the offset for Time Namespace. For more information
117+
see the [time_namespaces](time_namespaces.7).
118+
119+
The name of the clock is the entry key.
120+
Entry values are objects with the following properties:
121+
122+
* **`secs`** *(int64, OPTIONAL)* - is the offset of clock (in seconds) in the container.
123+
* **`nanosecs`** *(uint32, OPTIONAL)* - is the offset of clock (in nanoseconds) in the container.
124+
110125
## <a name="configLinuxDevices" />Devices
111126

112127
**`devices`** (array of objects, OPTIONAL) lists devices that MUST be available in the container.
@@ -770,3 +785,4 @@ subset of the available options.
770785
[zero.4]: http://man7.org/linux/man-pages/man4/zero.4.html
771786
[user-namespaces]: http://man7.org/linux/man-pages/man7/user_namespaces.7.html
772787
[intel-rdt-cat-kernel-interface]: https://www.kernel.org/doc/Documentation/x86/intel_rdt_ui.txt
788+
[time_namespaces.7]: https://man7.org/linux/man-pages/man7/time_namespaces.7.html

config.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,16 @@ Here is a full example `config.json` for reference.
905905
}
906906
]
907907
},
908+
"timeOffsets": {
909+
"monotonic": {
910+
"secs": 172800,
911+
"nanosecs": 0
912+
},
913+
"boottime": {
914+
"secs": 604800,
915+
"nanosecs": 0
916+
}
917+
},
908918
"namespaces": [
909919
{
910920
"type": "pid"
@@ -926,6 +936,9 @@ Here is a full example `config.json` for reference.
926936
},
927937
{
928938
"type": "cgroup"
939+
},
940+
{
941+
"type": "time"
929942
}
930943
],
931944
"maskedPaths": [

schema/config-linux.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,12 @@
253253
"personality": {
254254
"type": "object",
255255
"$ref": "defs-linux.json#/definitions/Personality"
256+
},
257+
"timeOffsets": {
258+
"type": "object",
259+
"additionalProperties": {
260+
"$ref": "defs-linux.json#/definitions/TimeOffsets"
261+
}
256262
}
257263
}
258264
}

schema/defs-linux.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@
292292
"uts",
293293
"ipc",
294294
"user",
295-
"cgroup"
295+
"cgroup",
296+
"time"
296297
]
297298
},
298299
"NamespaceReference": {
@@ -308,6 +309,17 @@
308309
"required": [
309310
"type"
310311
]
312+
},
313+
"TimeOffsets": {
314+
"type": "object",
315+
"properties": {
316+
"secs": {
317+
"$ref": "defs.json#/definitions/int64"
318+
},
319+
"nanosecs": {
320+
"$ref": "defs.json#/definitions/uint32"
321+
}
322+
}
311323
}
312324
}
313325
}

schema/test/config/good/spec-example.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,16 @@
349349
}
350350
]
351351
},
352+
"timeOffsets": {
353+
"monotonic": {
354+
"secs": 172800,
355+
"nanosecs": 0
356+
},
357+
"boottime": {
358+
"secs": 604800,
359+
"nanosecs": 0
360+
}
361+
},
352362
"namespaces": [
353363
{
354364
"type": "pid"
@@ -370,6 +380,9 @@
370380
},
371381
{
372382
"type": "cgroup"
383+
},
384+
{
385+
"type": "time"
373386
}
374387
],
375388
"maskedPaths": [

specs-go/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ type Linux struct {
182182
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
183183
// Personality contains configuration for the Linux personality syscall
184184
Personality *LinuxPersonality `json:"personality,omitempty"`
185+
// TimeOffsets specifies the offset for supporting time namespaces.
186+
TimeOffsets map[string]LinuxTimeOffset `json:"timeOffsets,omitempty"`
185187
}
186188

187189
// LinuxNamespace is the configuration for a Linux namespace
@@ -211,6 +213,8 @@ const (
211213
UserNamespace LinuxNamespaceType = "user"
212214
// CgroupNamespace for isolating cgroup hierarchies
213215
CgroupNamespace LinuxNamespaceType = "cgroup"
216+
// TimeNamespace for isolating the clocks
217+
TimeNamespace LinuxNamespaceType = "time"
214218
)
215219

216220
// LinuxIDMapping specifies UID/GID mappings
@@ -223,6 +227,14 @@ type LinuxIDMapping struct {
223227
Size uint32 `json:"size"`
224228
}
225229

230+
// LinuxTimeOffset specifies the offset for Time Namespace
231+
type LinuxTimeOffset struct {
232+
// Secs is the offset of clock (in secs) in the container
233+
Secs int64 `json:"secs,omitempty"`
234+
// Nanosecs is the additional offset for Secs (in nanosecs)
235+
Nanosecs uint32 `json:"nanosecs,omitempty"`
236+
}
237+
226238
// POSIXRlimit type and restrictions
227239
type POSIXRlimit struct {
228240
// Type of the rlimit to set

0 commit comments

Comments
 (0)