mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Initialize Kernel.Timekeeper before network NS
PiperOrigin-RevId: 375843579
This commit is contained in:
committed by
gVisor bot
parent
a54cb9d8a2
commit
b63e61828d
@@ -88,6 +88,7 @@ func Boot() (*kernel.Kernel, error) {
|
||||
return nil, fmt.Errorf("creating timekeeper: %v", err)
|
||||
}
|
||||
tk.SetClocks(time.NewCalibratedClocks())
|
||||
k.SetTimekeeper(tk)
|
||||
|
||||
creds := auth.NewRootCredentials(auth.NewRootUserNamespace())
|
||||
|
||||
@@ -96,7 +97,6 @@ func Boot() (*kernel.Kernel, error) {
|
||||
if err = k.Init(kernel.InitKernelArgs{
|
||||
ApplicationCores: uint(runtime.GOMAXPROCS(-1)),
|
||||
FeatureSet: cpuid.HostFeatureSet(),
|
||||
Timekeeper: tk,
|
||||
RootUserNamespace: creds.UserNamespace,
|
||||
Vdso: vdso,
|
||||
RootUTSNamespace: kernel.NewUTSNamespace("hostname", "domain", creds.UserNamespace),
|
||||
|
||||
+12
-10
@@ -306,9 +306,6 @@ type InitKernelArgs struct {
|
||||
// FeatureSet is the emulated CPU feature set.
|
||||
FeatureSet *cpuid.FeatureSet
|
||||
|
||||
// Timekeeper manages time for all tasks in the system.
|
||||
Timekeeper *Timekeeper
|
||||
|
||||
// RootUserNamespace is the root user namespace.
|
||||
RootUserNamespace *auth.UserNamespace
|
||||
|
||||
@@ -348,18 +345,24 @@ type InitKernelArgs struct {
|
||||
PIDNamespace *PIDNamespace
|
||||
}
|
||||
|
||||
// SetTimekeeper sets Kernel.timekeeper. SetTimekeeper must be called before
|
||||
// Init.
|
||||
func (k *Kernel) SetTimekeeper(tk *Timekeeper) {
|
||||
k.timekeeper = tk
|
||||
}
|
||||
|
||||
// Init initialize the Kernel with no tasks.
|
||||
//
|
||||
// Callers must manually set Kernel.Platform and call Kernel.SetMemoryFile
|
||||
// before calling Init.
|
||||
// and Kernel.SetTimekeeper before calling Init.
|
||||
func (k *Kernel) Init(args InitKernelArgs) error {
|
||||
if args.FeatureSet == nil {
|
||||
return fmt.Errorf("args.FeatureSet is nil")
|
||||
}
|
||||
if args.Timekeeper == nil {
|
||||
return fmt.Errorf("args.Timekeeper is nil")
|
||||
if k.timekeeper == nil {
|
||||
return fmt.Errorf("timekeeper is nil")
|
||||
}
|
||||
if args.Timekeeper.clocks == nil {
|
||||
if k.timekeeper.clocks == nil {
|
||||
return fmt.Errorf("must call Timekeeper.SetClocks() before Kernel.Init()")
|
||||
}
|
||||
if args.RootUserNamespace == nil {
|
||||
@@ -370,7 +373,6 @@ func (k *Kernel) Init(args InitKernelArgs) error {
|
||||
}
|
||||
|
||||
k.featureSet = args.FeatureSet
|
||||
k.timekeeper = args.Timekeeper
|
||||
k.tasks = newTaskSet(args.PIDNamespace)
|
||||
k.rootUserNamespace = args.RootUserNamespace
|
||||
k.rootUTSNamespace = args.RootUTSNamespace
|
||||
@@ -395,8 +397,8 @@ func (k *Kernel) Init(args InitKernelArgs) error {
|
||||
}
|
||||
k.extraAuxv = args.ExtraAuxv
|
||||
k.vdso = args.Vdso
|
||||
k.realtimeClock = &timekeeperClock{tk: args.Timekeeper, c: sentrytime.Realtime}
|
||||
k.monotonicClock = &timekeeperClock{tk: args.Timekeeper, c: sentrytime.Monotonic}
|
||||
k.realtimeClock = &timekeeperClock{tk: k.timekeeper, c: sentrytime.Realtime}
|
||||
k.monotonicClock = &timekeeperClock{tk: k.timekeeper, c: sentrytime.Monotonic}
|
||||
k.futexes = futex.NewManager()
|
||||
k.netlinkPorts = port.New()
|
||||
k.ptraceExceptions = make(map[*Task]*Task)
|
||||
|
||||
@@ -287,6 +287,7 @@ func New(args Args) (*Loader, error) {
|
||||
return nil, fmt.Errorf("creating timekeeper: %w", err)
|
||||
}
|
||||
tk.SetClocks(time.NewCalibratedClocks())
|
||||
k.SetTimekeeper(tk)
|
||||
|
||||
if err := enableStrace(args.Conf); err != nil {
|
||||
return nil, fmt.Errorf("enabling strace: %w", err)
|
||||
@@ -335,7 +336,6 @@ func New(args Args) (*Loader, error) {
|
||||
// to createVFS in order to mount (among other things) procfs.
|
||||
if err = k.Init(kernel.InitKernelArgs{
|
||||
FeatureSet: cpuid.HostFeatureSet(),
|
||||
Timekeeper: tk,
|
||||
RootUserNamespace: creds.UserNamespace,
|
||||
RootNetworkNamespace: netns,
|
||||
ApplicationCores: uint(args.NumCPU),
|
||||
|
||||
Reference in New Issue
Block a user