Skip to content

Commit

Permalink
Add support for time namespace
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Kenta Tada authored and Kenta Tada committed Jan 24, 2023
1 parent d438e29 commit 5210ede
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
16 changes: 16 additions & 0 deletions config-linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The following parameters can be specified to set up namespaces:
* **`uts`** the container will be able to have its own hostname and domain name.
* **`user`** the container will be able to remap user and group IDs from the host to local users and groups within the container.
* **`cgroup`** the container will have an isolated view of the cgroup hierarchy.
* **`time`** the container will be able to have its own clocks.
* **`path`** *(string, OPTIONAL)* - namespace file.
This value MUST be an absolute path in the [runtime mount namespace](glossary.md#runtime-namespace).
The runtime MUST place the container process in the namespace associated with that `path`.
Expand Down Expand Up @@ -70,6 +71,9 @@ If a `namespaces` field contains duplicated namespaces with same `type`, the run
},
{
"type": "cgroup"
},
{
"type": "time"
}
]
```
Expand Down Expand Up @@ -107,6 +111,17 @@ Note that the number of mapping entries MAY be limited by the [kernel][user-name
]
```

## <a name="configLinuxTimeOffset" />Offset for Time Namespace

**`timeOffsets`** (object, OPTIONAL) sets the offset for Time Namespace. For more information
see the [time_namespaces](time_namespaces.7).

The name of the clock is the entry key.
Entry values are objects with the following properties:

* **`secs`** *(int64, OPTIONAL)* - is the offset of clock (in seconds) in the container.
* **`nanosecs`** *(int64, OPTIONAL)* - is the offset of clock (in nanoseconds) in the container.

## <a name="configLinuxDevices" />Devices

**`devices`** (array of objects, OPTIONAL) lists devices that MUST be available in the container.
Expand Down Expand Up @@ -770,3 +785,4 @@ subset of the available options.
[zero.4]: http://man7.org/linux/man-pages/man4/zero.4.html
[user-namespaces]: http://man7.org/linux/man-pages/man7/user_namespaces.7.html
[intel-rdt-cat-kernel-interface]: https://www.kernel.org/doc/Documentation/x86/intel_rdt_ui.txt
[time_namespaces.7]: https://man7.org/linux/man-pages/man7/time_namespaces.7.html
13 changes: 13 additions & 0 deletions config.md
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,16 @@ Here is a full example `config.json` for reference.
}
]
},
"timeOffsets": {
"monotonic": {
"secs": 172800,
"nanosecs": 0
},
"boottime": {
"secs": 604800,
"nanosecs": 0
}
},
"namespaces": [
{
"type": "pid"
Expand All @@ -926,6 +936,9 @@ Here is a full example `config.json` for reference.
},
{
"type": "cgroup"
},
{
"type": "time"
}
],
"maskedPaths": [
Expand Down
6 changes: 6 additions & 0 deletions schema/config-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@
"personality": {
"type": "object",
"$ref": "defs-linux.json#/definitions/Personality"
},
"timeOffsets": {
"type": "object",
"additionalProperties": {
"$ref": "defs-linux.json#/definitions/TimeOffsets"
}
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion schema/defs-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@
"uts",
"ipc",
"user",
"cgroup"
"cgroup",
"time"
]
},
"NamespaceReference": {
Expand All @@ -308,6 +309,17 @@
"required": [
"type"
]
},
"TimeOffsets": {
"type": "object",
"properties": {
"secs": {
"$ref": "defs.json#/definitions/int64"
},
"nanosecs": {
"$ref": "defs.json#/definitions/int64"
}
}
}
}
}
13 changes: 13 additions & 0 deletions schema/test/config/good/spec-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,16 @@
}
]
},
"timeOffsets": {
"monotonic": {
"secs": 172800,
"nanosecs": 0
},
"boottime": {
"secs": 604800,
"nanosecs": 0
}
},
"namespaces": [
{
"type": "pid"
Expand All @@ -370,6 +380,9 @@
},
{
"type": "cgroup"
},
{
"type": "time"
}
],
"maskedPaths": [
Expand Down
12 changes: 12 additions & 0 deletions specs-go/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ type Linux struct {
IntelRdt *LinuxIntelRdt `json:"intelRdt,omitempty"`
// Personality contains configuration for the Linux personality syscall
Personality *LinuxPersonality `json:"personality,omitempty"`
// TimeOffsets specifies the offset for supporting time namespaces.
TimeOffsets map[string]LinuxTimeOffset `json:"timeOffsets,omitempty"`
}

// LinuxNamespace is the configuration for a Linux namespace
Expand Down Expand Up @@ -211,6 +213,8 @@ const (
UserNamespace LinuxNamespaceType = "user"
// CgroupNamespace for isolating cgroup hierarchies
CgroupNamespace LinuxNamespaceType = "cgroup"
// TimeNamespace for isolating the clocks
TimeNamespace LinuxNamespaceType = "time"
)

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

// LinuxTimeOffset specifies the offset for Time Namespace
type LinuxTimeOffset struct {
// Secs is the offset of clock (in secs) in the container
Secs int64 `json:"secs,omitempty"`
// Nanosecs is the additional offset for Secs (in nanosecs)
Nanosecs int64 `json:"nanosecs,omitempty"`
}

// POSIXRlimit type and restrictions
type POSIXRlimit struct {
// Type of the rlimit to set
Expand Down

0 comments on commit 5210ede

Please sign in to comment.