Skip to content

Commit 7301c34

Browse files
authored
Merge pull request #1151 from KentaTada/add-time-namespac
Add support for time namespace
2 parents 0ff8cd9 + 36bb632 commit 7301c34

File tree

6 files changed

+73
-1
lines changed

6 files changed

+73
-1
lines changed

config-linux.md

+16
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.
@@ -939,3 +954,4 @@ subset of the available options.
939954
[zero.4]: http://man7.org/linux/man-pages/man4/zero.4.html
940955
[user-namespaces]: http://man7.org/linux/man-pages/man7/user_namespaces.7.html
941956
[intel-rdt-cat-kernel-interface]: https://www.kernel.org/doc/Documentation/x86/intel_rdt_ui.txt
957+
[time_namespaces.7]: https://man7.org/linux/man-pages/man7/time_namespaces.7.html

config.md

+13
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,16 @@ Here is a full example `config.json` for reference.
928928
}
929929
]
930930
},
931+
"timeOffsets": {
932+
"monotonic": {
933+
"secs": 172800,
934+
"nanosecs": 0
935+
},
936+
"boottime": {
937+
"secs": 604800,
938+
"nanosecs": 0
939+
}
940+
},
931941
"namespaces": [
932942
{
933943
"type": "pid"
@@ -949,6 +959,9 @@ Here is a full example `config.json` for reference.
949959
},
950960
{
951961
"type": "cgroup"
962+
},
963+
{
964+
"type": "time"
952965
}
953966
],
954967
"maskedPaths": [

schema/config-linux.json

+6
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@
280280
"personality": {
281281
"type": "object",
282282
"$ref": "defs-linux.json#/definitions/Personality"
283+
},
284+
"timeOffsets": {
285+
"type": "object",
286+
"additionalProperties": {
287+
"$ref": "defs-linux.json#/definitions/TimeOffsets"
288+
}
283289
}
284290
}
285291
}

schema/defs-linux.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@
295295
"uts",
296296
"ipc",
297297
"user",
298-
"cgroup"
298+
"cgroup",
299+
"time"
299300
]
300301
},
301302
"NamespaceReference": {
@@ -311,6 +312,17 @@
311312
"required": [
312313
"type"
313314
]
315+
},
316+
"TimeOffsets": {
317+
"type": "object",
318+
"properties": {
319+
"secs": {
320+
"$ref": "defs.json#/definitions/int64"
321+
},
322+
"nanosecs": {
323+
"$ref": "defs.json#/definitions/uint32"
324+
}
325+
}
314326
}
315327
}
316328
}

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

+13
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@
352352
}
353353
]
354354
},
355+
"timeOffsets": {
356+
"monotonic": {
357+
"secs": 172800,
358+
"nanosecs": 0
359+
},
360+
"boottime": {
361+
"secs": 604800,
362+
"nanosecs": 0
363+
}
364+
},
355365
"namespaces": [
356366
{
357367
"type": "pid"
@@ -373,6 +383,9 @@
373383
},
374384
{
375385
"type": "cgroup"
386+
},
387+
{
388+
"type": "time"
376389
}
377390
],
378391
"maskedPaths": [

specs-go/config.go

+12
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ type Linux struct {
191191
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
192192
// Personality contains configuration for the Linux personality syscall
193193
Personality *LinuxPersonality `json:"personality,omitempty"`
194+
// TimeOffsets specifies the offset for supporting time namespaces.
195+
TimeOffsets map[string]LinuxTimeOffset `json:"timeOffsets,omitempty"`
194196
}
195197

196198
// LinuxNamespace is the configuration for a Linux namespace
@@ -220,6 +222,8 @@ const (
220222
UserNamespace LinuxNamespaceType = "user"
221223
// CgroupNamespace for isolating cgroup hierarchies
222224
CgroupNamespace LinuxNamespaceType = "cgroup"
225+
// TimeNamespace for isolating the clocks
226+
TimeNamespace LinuxNamespaceType = "time"
223227
)
224228

225229
// LinuxIDMapping specifies UID/GID mappings
@@ -232,6 +236,14 @@ type LinuxIDMapping struct {
232236
Size uint32 `json:"size"`
233237
}
234238

239+
// LinuxTimeOffset specifies the offset for Time Namespace
240+
type LinuxTimeOffset struct {
241+
// Secs is the offset of clock (in secs) in the container
242+
Secs int64 `json:"secs,omitempty"`
243+
// Nanosecs is the additional offset for Secs (in nanosecs)
244+
Nanosecs uint32 `json:"nanosecs,omitempty"`
245+
}
246+
235247
// POSIXRlimit type and restrictions
236248
type POSIXRlimit struct {
237249
// Type of the rlimit to set

0 commit comments

Comments
 (0)