Skip to content

Commit 5e63903

Browse files
authored
Merge pull request #784 from champtar/time-ns
Add time namespace / TimeOffsets check and helper
2 parents edf4cb3 + 6072004 commit 5e63903

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

generate/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ func (g *Generator) initConfigLinuxIntelRdt() {
6666
}
6767
}
6868

69+
func (g *Generator) initConfigLinuxTimeOffsets() {
70+
g.initConfigLinux()
71+
if g.Config.Linux.TimeOffsets == nil {
72+
g.Config.Linux.TimeOffsets = map[string]rspec.LinuxTimeOffset{}
73+
}
74+
}
75+
6976
func (g *Generator) initConfigLinuxSysctl() {
7077
g.initConfigLinux()
7178
if g.Config.Linux.Sysctl == nil {

generate/generate.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
var (
1919
// Namespaces include the names of supported namespaces.
20-
Namespaces = []string{"network", "pid", "mount", "ipc", "uts", "user", "cgroup"}
20+
Namespaces = []string{"network", "pid", "mount", "ipc", "uts", "user", "cgroup", "time"}
2121

2222
// we don't care about order...and this is way faster...
2323
removeFunc = func(s []string, i int) []string {
@@ -633,6 +633,12 @@ func (g *Generator) SetLinuxIntelRdtL3CacheSchema(schema string) {
633633
g.Config.Linux.IntelRdt.L3CacheSchema = schema
634634
}
635635

636+
// SetLinuxTimeOffset sets g.Config.Linux.TimeOffsets[clock]
637+
func (g *Generator) SetLinuxTimeOffset(clock string, offset rspec.LinuxTimeOffset) {
638+
g.initConfigLinuxTimeOffsets()
639+
g.Config.Linux.TimeOffsets[clock] = offset
640+
}
641+
636642
// SetLinuxMountLabel sets g.Config.Linux.MountLabel.
637643
func (g *Generator) SetLinuxMountLabel(label string) {
638644
g.initConfigLinux()
@@ -1485,6 +1491,8 @@ func mapStrToNamespace(ns string, path string) (rspec.LinuxNamespace, error) {
14851491
return rspec.LinuxNamespace{Type: rspec.UserNamespace, Path: path}, nil
14861492
case "cgroup":
14871493
return rspec.LinuxNamespace{Type: rspec.CgroupNamespace, Path: path}, nil
1494+
case "time":
1495+
return rspec.LinuxNamespace{Type: rspec.TimeNamespace, Path: path}, nil
14881496
default:
14891497
return rspec.LinuxNamespace{}, fmt.Errorf("unrecognized namespace %q", ns)
14901498
}

validate/validate_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func (v *Validator) CheckLinux() (errs error) {
5353
rspec.UTSNamespace: {0, false},
5454
rspec.UserNamespace: {0, false},
5555
rspec.CgroupNamespace: {0, false},
56+
rspec.TimeNamespace: {0, false},
5657
}
5758

5859
for index := 0; index < len(v.spec.Linux.Namespaces); index++ {
@@ -92,6 +93,10 @@ func (v *Validator) CheckLinux() (errs error) {
9293
errs = multierror.Append(errs, fmt.Errorf("on Linux, hostname requires a new UTS namespace to be specified as well"))
9394
}
9495

96+
if !nsTypeList[rspec.TimeNamespace].newExist && len(v.spec.Linux.TimeOffsets) > 0 {
97+
errs = multierror.Append(errs, fmt.Errorf("TimeOffsets requires a new time namespace to be specified as well"))
98+
}
99+
95100
// Linux devices validation
96101
devList := make(map[string]bool)
97102
devTypeList := make(map[string]bool)

0 commit comments

Comments
 (0)